Skip to content

Commit f1ec843

Browse files
committed
Add utility functions to extract BbCode content
1 parent 74eb2cf commit f1ec843

8 files changed

+122
-0
lines changed

BbCode/Helper.php

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
<?php
2+
3+
namespace Inforge\PostTOC\BbCode;
4+
5+
class Helper
6+
{
7+
private static function getContent($tagChildren, $removeBbCode = false)
8+
{
9+
$content = '';
10+
foreach ($tagChildren as $child)
11+
if (is_string($child))
12+
$content .= $child;
13+
else if (is_array($child))
14+
$content .= ($removeBbCode ? '' : $child['original'][0])
15+
. self::getContent($child['children'], $removeBbCode)
16+
. ($removeBbCode ? '' : $child['original'][1]);
17+
return $content;
18+
}
19+
20+
private static function getTextContent($tagChildren)
21+
{
22+
return getContent($tagChildren, true);
23+
}
24+
25+
private static function getAnchorId($uniqueId, $tagChildren)
26+
{
27+
$text = getTextContent($tagChildren);
28+
$text = preg_replace('/[\s+]/', '-', $text);
29+
$text = preg_replace('/[^A-Za-z0-9\-]/', '', $text);
30+
$text = substr($text, 0, 30);
31+
return $uniqueId . '-' . $text;
32+
}
33+
34+
public static function renderChapterTag($tagChildren, $tagOption, $tag,
35+
array $options, \XF\BbCode\Renderer\AbstractRenderer $renderer)
36+
{
37+
\XF::dump($tagChildren);
38+
\XF::dump($tagOption);
39+
\XF::dump($tag);
40+
\XF::dump($options);
41+
return "";
42+
}
43+
44+
public static function renderSectionTag($tagChildren, $tagOption, $tag,
45+
array $options, \XF\BbCode\Renderer\AbstractRenderer $renderer)
46+
{
47+
return null;
48+
}
49+
50+
public static function renderSubsectionTag($tagChildren, $tagOption,
51+
$tag, array $options,
52+
\XF\BbCode\Renderer\AbstractRenderer $renderer)
53+
{
54+
return null;
55+
}
56+
57+
public static function renderSubsubsectionTag($tagChildren, $tagOption,
58+
$tag, array $options,
59+
\XF\BbCode\Renderer\AbstractRenderer $renderer)
60+
{
61+
return null;
62+
}
63+
64+
public static function renderParagraph($tagChildren, $tagOption, $tag,
65+
array $options, \XF\BbCode\Renderer\AbstractRenderer $renderer)
66+
{
67+
return null;
68+
}
69+
}

_output/bb_codes/_metadata.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"chapter.json": {
3+
"hash": "7352f649ef5a0ac40764fa4304eeac72"
4+
}
5+
}

_output/bb_codes/chapter.json

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"bb_code_mode": "callback",
3+
"has_option": "optional",
4+
"replace_html": "",
5+
"replace_html_email": "",
6+
"replace_text": "",
7+
"callback_class": "Inforge\\PostTOC\\BbCode\\Helper",
8+
"callback_method": "renderChapterTag",
9+
"option_regex": "",
10+
"trim_lines_after": 0,
11+
"plain_children": false,
12+
"disable_smilies": false,
13+
"disable_nl2br": false,
14+
"disable_autolink": true,
15+
"allow_empty": false,
16+
"allow_signature": false,
17+
"editor_icon_type": "",
18+
"editor_icon_value": "",
19+
"active": true
20+
}

_output/phrases/_metadata.json

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"custom_bb_code_desc.chapter.txt": {
3+
"global_cache": false,
4+
"version_id": 1000070,
5+
"version_string": "1.0.0",
6+
"hash": "bf5b784755d525df644dc5590832c39a"
7+
},
8+
"custom_bb_code_example.chapter.txt": {
9+
"global_cache": false,
10+
"version_id": 1000070,
11+
"version_string": "1.0.0",
12+
"hash": "d41d8cd98f00b204e9800998ecf8427e"
13+
},
14+
"custom_bb_code_output.chapter.txt": {
15+
"global_cache": false,
16+
"version_id": 1000070,
17+
"version_string": "1.0.0",
18+
"hash": "d41d8cd98f00b204e9800998ecf8427e"
19+
},
20+
"custom_bb_code_title.chapter.txt": {
21+
"global_cache": false,
22+
"version_id": 1000070,
23+
"version_string": "1.0.0",
24+
"hash": "d22db41a9d78a3f7419c6b6c2974276b"
25+
}
26+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
A chapter.

_output/phrases/custom_bb_code_example.chapter.txt

Whitespace-only changes.

_output/phrases/custom_bb_code_output.chapter.txt

Whitespace-only changes.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Chapter

0 commit comments

Comments
 (0)