summaryrefslogtreecommitdiff
path: root/src/BBCodeParser.php
diff options
context:
space:
mode:
authoruckelman <uckelman@nomic.net>2010-07-25 11:35:22 +0000
committeruckelman <uckelman@nomic.net>2010-07-25 11:35:22 +0000
commitb2c60e87f7de38bf35ca9634dbe5807f92ba34e4 (patch)
tree9536562c47ed1b6a4441ec802b9265b0b85834fa /src/BBCodeParser.php
parent2621324fbc35249274d8863d3dda0ce5f9759e87 (diff)
* Correctly handle open tags with arguments.
* Convert non-BBCode <!-- (m|w) --> style links. git-svn-id: https://vassalengine.svn.sourceforge.net/svnroot/vassalengine/site-src/trunk@7026 67b53d14-2c14-4ace-a08f-0dab2b34000c
Diffstat (limited to 'src/BBCodeParser.php')
-rw-r--r--src/BBCodeParser.php17
1 files changed, 13 insertions, 4 deletions
diff --git a/src/BBCodeParser.php b/src/BBCodeParser.php
index af2d129..1a19d1f 100644
--- a/src/BBCodeParser.php
+++ b/src/BBCodeParser.php
@@ -15,6 +15,9 @@ class BBCodeParser {
# convert smilies, which aren't in BBCode (ack!)
$in = preg_replace('/<!-- s(.*?) --><img src="\{SMILIES_PATH\}\/.*? \/><!-- s\1 -->/', '\1', $in);
+ # convert non-BBCode links to BBCode (ack!)
+ $in = preg_replace('/<!-- (m|w) --><a class="postlink" href="(.*?)">(.*?)<\/a><!-- \1 -->/', "[url:$uid=\\2]\\3[/url:$uid]", $in);
+
$text_stack = array();
$arg_stack = array();
@@ -41,9 +44,15 @@ class BBCodeParser {
$state = self::DONE;
}
else {
- # locate next tag
+ $ulen = strlen($uid) + 1;
+
+ # locate the start and end of next tag
$tstart = strrpos($in, '[', $ustart-$len);
- $tag = substr($in, $tstart+1, $ustart-$tstart-1);
+ $tend = strpos($in, ']', $ustart+$ulen);
+
+ # slice out the uid
+ $tag = substr($in, $tstart+1, $ustart-$tstart-1) .
+ substr($in, $ustart+$ulen, $tend-$ustart-$ulen);
# determine whether it's an open or close tag
if ($tag[0] == '/') {
@@ -57,8 +66,8 @@ class BBCodeParser {
# copy leading text to output
$out .= substr($in, $i, $tstart-$i);
- # advance past ":$uid]" to next unparsed character
- $i = $ustart + strlen($uid) + 2;
+ # advance past the closing ']' to next unparsed character
+ $i = $tend + 1;
}
break;