SBBCodeParser
SBBCodeParser copied to clipboard
Cannot parse URLs with =
When you try to parse a URL, let's say
[url=newsattachment.php?id=23]attachment[/url]
that doesn't work.
THX in advance.
The final solution it's working 100% but it needs some optimizations ^_^
In the classes/Node/Container/Document.php change the parse function header to be like that
public function parse($str)
{
//$str = preg_replace('/[\r\n|\r]/', "\n", $str);
//This is the added code
$bbstr = $str;
$result = "";
while (strpos($bbstr, "[url=") !== false) {
$pos = strpos($bbstr, "[url=")+5;
$result .= substr($bbstr,0,$pos);
$bbstr = substr($bbstr,$pos,strlen($bbstr));
$pos = strpos($bbstr, "]")-1;
$link = substr($bbstr,0,$pos+1);if($pos<0)$link="#";
$link = str_replace('=',"IXI_SBBCODEPARSER_URL_PROBLEM_IS_SOLVED",$link);
$bbstr = substr($bbstr,$pos+1,strlen($bbstr));
$result .= $link;
}
$result .= $bbstr;
$str = $result;//The added code ends here
$len = strlen($str);
$tag_open = false;
$tag_text = '';
$tag = '';
...
And in the classes/Node/Container.php
change the function get_html()
to oldget_html()
then add this function :
/**
*
* @return string
*/
public function get_html($nl2br=true){
return str_replace("IXI_SBBCODEPARSER_URL_PROBLEM_IS_SOLVED",'=',$this->oldget_html($nl2br));
}
and now every thing will run without any problem
Suggestion : I think that we can use @diegargon solution if we will be able to specify the tag ([URL]) in the IF statement
There are actually two problems with link parsing. SBBCodeParser doesn't like equal signs in urls, and it prepends the base uri in front of paths even if the path begins with '/'. I have fixed this with the following patch:
--- Document.orig.php 2013-08-02 20:21:57.000000000 +0200
+++ Document.php 2016-09-02 07:31:41.000000000 +0200
@@ -553,7 +553,8 @@
if(strpos($attribs['default'], 'www') === 0)
$attribs['default'] = 'http://' . $attribs['default'];
// add the base url to any urls not starting with http or ftp as they must be relative
- else if(substr($attribs['default'], 0, 4) !== 'http'
+ else if($attribs['default'][0] !== '/'
+ && substr($attribs['default'], 0, 4) !== 'http'
&& substr($attribs['default'], 0, 3) !== 'ftp')
$attribs['default'] = $node->root()->get_base_uri() . $attribs['default'];
@@ -875,7 +876,7 @@
// if this tag only has one = then there is only one attribute
// so add it all to default
- if($attribs[0] == '=' && strrpos($attribs, '=') === 0)
+ if($attribs[0] == '=' && (strpos($attribs, ' ') == null || strrpos($attribs, '=') === 0))
$ret['default'] = htmlentities(substr($attribs, 1), ENT_QUOTES | ENT_IGNORE, "UTF-8");
else
{
I do not know whether the topic is relevant. But check out pull request #22