|
Forums ⇒ DragonflyCMS ⇒ Problems AFTER Install/Upgrade ⇒ PHP BBcode not working - PHP version issues?
PHP BBcode not working - PHP version issues?Issues that happen after DragonflyCMS upgrade/install. DO NOT post module installation issues here!
|
View previous topic :: View next topic |
| Author |
Message |
Bedevere Nice poster


Offline Joined: Jul 06, 2006 Posts: 83 Location: New York City
|
Posted: Sun Jan 11, 2009 1:46 am Post subject: PHP BBcode not working - PHP version issues? |
|
I migrated from version 9.0.6.1 to 9.2.1. I read up on what to expect and everything went failry smoothly. A few mods I had forgotton though did cathc up to me and I sifted through what were mostly cosmetic issues. What plagues me now is that the bbcode for PHP stopped working...well properly.
I can display this:
| PHP: |
$text = preg_replace($patterns, $replacements, $text);
|
but I can't display this:
| PHP: |
<?php function decode_php($text) { global $bb_codes; $text = str_replace("\r\n", "\n", substr($text, 5, -6)); # Windows $text = str_replace("\r", "\n", $text); # Mac $text = str_replace("\t", ' ', $text); # Temporary tab fix $text = htmlunprepare($text, true); $added = FALSE; if (preg_match('/^<\?.*/', $text) <= 0) { $text = "<?php\n$text"; $added = TRUE; } if (PHPVERS < 42) { ob_start(); highlight_string($text); $text = ob_get_contents(); ob_end_clean(); } else { $text = highlight_string($text, TRUE); } if (PHPVERS < 50) { $text = preg_replace('/<font color="(.*?)">/si', '<span style="color: \\1;">', $text); $text = str_replace('</font>', '</span>', $text); } if ($added == TRUE) { if (PHPVERS < 50) { $text = preg_replace('/^(.*)\n.*?<\/span>(.*)php<br \/>/i', "\\1\n\\2?php<br />", $text, 1); } $text = preg_replace('/^(.*)\n.*php<br \/><\/span>/i', "\\1\n", $text, 1); $text = preg_replace('/^(.*)\n(.*)>.*php<br \/>/i', "\\1\n\\2>", $text, 1); } $text = str_replace('[', '[', $text); $text = str_replace("\n", '', $text); $text = str_replace(' ', ' ', $text); $text = str_replace(' ', "\t", $text); $text = preg_replace('#<span style="color: \#[A-F0-9]{6}">([\t]+)</span>#', '\\1', $text); return $bb_codes['php_start']."<pre>$text</pre>".$bb_codes['php_end']; }
|
Well look at that...neither can you guys. But it does work as code:
| Code:: |
function decode_php($text)
{
global $bb_codes;
$text = str_replace("\r\n", "\n", substr($text, 5, -6)); # Windows
$text = str_replace("\r", "\n", $text); # Mac
$text = str_replace("\t", '/*t*/', $text); # Temporary tab fix
$text = htmlunprepare($text, true);
$added = FALSE;
if (preg_match('/^<\?.*/', $text) <= 0) {
$text = "<?php\n$text";
$added = TRUE;
}
if (PHPVERS < 42) {
ob_start();
highlight_string($text);
$text = ob_get_contents();
ob_end_clean();
} else {
$text = highlight_string($text, TRUE);
}
if (PHPVERS < 50) {
$text = preg_replace('/<font color="(.*?)">/si', '<span style="color: \\1;">', $text);
$text = str_replace('</font>', '</span>', $text);
}
if ($added == TRUE) {
if (PHPVERS < 50) {
$text = preg_replace('/^(.*)\n.*?<\/span>(.*)php<br \/>/i', "\\1\n\\2?php<br />", $text, 1);
}
$text = preg_replace('/^(.*)\n.*php<br \/><\/span>/i', "\\1\n", $text, 1);
$text = preg_replace('/^(.*)\n(.*)>.*php<br \/>/i', "\\1\n\\2>", $text, 1);
}
$text = str_replace('[', '[', $text);
$text = str_replace("\n", '', $text);
$text = str_replace(' ', ' ', $text);
$text = str_replace('/*t*/', "\t", $text);
$text = preg_replace('#<span style="color: \#[A-F0-9]{6}">([\t]+)</span>#', '\\1', $text);
return $bb_codes['php_start']."<pre>$text</pre>".$bb_codes['php_end'];
}
|
At first I thought my theme was the issue, as I had modified it for 9.2.1 and it is a pretty involved set of files. I switched back to default and the dragonfly themes and no dice. So I copied the entire site to a test machine, but did not copy the mySQL data, I installed fresh and tried it and it works fine. The only differences seems to be the version of php and mySQL.
The working one uses...
CMS Version 9.2.1
PHP Version 5.1.2
MySQL Version 5.0.26 (client: 5.0.26)
The non-working one uses...
CMS Version 9.2.1
PHP Version 5.2.6
MySQL Version 5.0.51a (client: 5.0.51a)
I dug around in the nbbcode.php and found the function decode_php (as you can see above) and I noticed there was a lot of options based on the version of PHP installed. I did read elswhere that the nl2br had changed and was "not so smart" (not my words).
I assume they mean this reference:
| PHP: |
nl2br(htmlspecialchars($part['text']));
|
Once I got here I figured it was time to see the professionals and so here I am. And lo and behold you are having the same issue!
I am guessing you are using a newer version of PHP for the site and so having similar issues? Searching things like php and bbcode on the forums here is a bit overwhelming so I am just posting this here hoping soemone else has seen this and is working on it.
Bedevere's server specs (Server OS / Apache / MySQL / PHP / DragonflyCMS)
|
|
| Back to top |
|
 |
Phoenix • Many Posts •


Offline Joined: Apr 19, 2004 Posts: 8799 Location: Netizen
|
Posted: Sun Jan 11, 2009 2:01 am Post subject: Re: PHP BBcode not working - PHP version issues? |
|
It's been raised before and works fine, see my edit - it's a php5 issue - just ensure you start with <?php
Phoenix's server specs (Server OS / Apache / MySQL / PHP / DragonflyCMS)
|
|
| Back to top |
|
 |
Bedevere Nice poster


Offline Joined: Jul 06, 2006 Posts: 83 Location: New York City
|
Posted: Sun Jan 11, 2009 3:12 am Post subject: Re: PHP BBcode not working - PHP version issues? |
|
Testing:
| PHP: |
<?php function decode_php($text) { global $bb_codes; $text = str_replace("\r\n", "\n", substr($text, 5, -6)); # Windows $text = str_replace("\r", "\n", $text); # Mac $text = str_replace("\t", ' ', $text); # Temporary tab fix $text = htmlunprepare($text, true); $added = FALSE; if (preg_match('/^<\?.*/', $text) <= 0) { $text = "<?php\n$text"; $added = TRUE; } if (PHPVERS < 42) { ob_start(); highlight_string($text); $text = ob_get_contents(); ob_end_clean(); } else { $text = highlight_string($text, TRUE); } if (PHPVERS < 50) { $text = preg_replace('/<font color="(.*?)">/si', '<span style="color: \\1;">', $text); $text = str_replace('</font>', '</span>', $text); } if ($added == TRUE) { if (PHPVERS < 50) { $text = preg_replace('/^(.*)\n.*?<\/span>(.*)php<br \/>/i', "\\1\n\\2?php<br />", $text, 1); } $text = preg_replace('/^(.*)\n.*php<br \/><\/span>/i', "\\1\n", $text, 1); $text = preg_replace('/^(.*)\n(.*)>.*php<br \/>/i', "\\1\n\\2>", $text, 1); } $text = str_replace('[', '[', $text); $text = str_replace("\n", '', $text); $text = str_replace(' ', ' ', $text); $text = str_replace(' ', "\t", $text); $text = preg_replace('#<span style="color: \#[A-F0-9]{6}">([\t]+)</span>#', '\\1', $text); return $bb_codes['php_start']."<pre>$text</pre>".$bb_codes['php_end']; } ?>
|
Well thanks for the fix! Is this a big pain in the ass to fix for php 5 or is this considered working as intended?
Bedevere's server specs (Server OS / Apache / MySQL / PHP / DragonflyCMS)
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You cannot download files in this forum
|