Topic: A strange bug in an extension
Hi.
I've developped an extension here but there is a bug which has been reported to me that i don't know what to do.
The extension uses GeSHi to highlight a source code form a post when users put it between the bbcode tag [Code:<language code>] and [/Code].
The bug appears when there is more than 1 posts in a topic: the first post is displayed (in viewtopic.php) but not the others. And we can see that there is more than 1 post in the topic because we see the number of posts in the topic in the first post.
I don't understand english very well so i'll post the code in my manifest.xml file here for who wants to help me:
<?xml version="1.0" encoding="utf-8"?>
<extension engine="1.0">
<id>pungeshi</id>
<title>PunGeSHi (GeSHi for Punbb 1.3)</title>
<version>0.96</version>
<description>DESCRIPTION OF THE EXTENSION</description>
<author> ME</author>
<minversion>1.3 Beta</minversion>
<maxtestedon>1.3 Beta</maxtestedon>
<note type="install"> NOTES </note>
<install><![CDATA[
// ONLY FOR A SIMPLE VERIFICATION, I PUT THE PARAMETER o_pungeshi IN THE TABLE config
$rslt = $db->query('SELECT conf_value FROM '.$db->prefix."config WHERE conf_name='o_pungeshi' ") or error(__FILE__, __LINE__);
if(!$db->fetch_assoc($rslt))
$db->query('INSERT INTO '.$db->prefix."config VALUES('o_pungeshi', '1')");
else
$notices[] = 'Le parametre o_pungeshi existe déjà dans la table "'.$db->prefix.'config" de cette base de donnée. Cette extension pourrait ne pas fonctionner correctement.';
]]></install>
<uninstall><![CDATA[
// TO UNINSTALL THE EXTENSION, I REMOVE THE PARAMETER o_pungeshi FROM THE DATABASE
$rslt = $db->query('SELECT conf_value FROM '.$db->prefix."config WHERE conf_name='o_pungeshi' ") or error(__FILE__, __LINE__);
if($db->fetch_assoc($rslt))
$db->query('DELETE FROM '.$db->prefix."config WHERE conf_name='o_pungeshi' LIMIT 1");
]]></uninstall>
<hooks>
// THE FIRST "hook" THAT I EXPLOIT IS IN viewtopic.php, JUST BEFORE POSTS ARE DISPLAYED (IN THE "while" LOOP)
<hook id="vt_row_pre_display"><![CDATA[
// A SMALL TEST...
$rslt = $db->query('SELECT conf_value FROM '.$db->prefix."config WHERE conf_name='o_pungeshi' ") or error(__FILE__, __LINE__);
if(!$db->fetch_assoc($rslt))
exit;
if (!defined('PUN_ROOT'))
define('PUN_ROOT', './');
// WE LOAD geshi LIBRARY
require_once PUN_ROOT.'extensions/pungeshi/geshi/geshi.php';
// HERE WE REPLACE ALL POSTS WHICH CONTAIN THE BBCODE TAG WITH THE HIGHLIGHTED CODE
if(isset($cur_post['message'])) {
// That's the baby
preg_match("#\[Code:([a-zA-Z0-9_-]*)\](.*)\[/Code\]#sU", $cur_post['message'], $infos);
if(isset($infos['1']) && isset($infos['2']) && isset($pun_page['message'])) {
$geshi_code =& new GeSHi($infos['2'], $infos['1']);
$geshi_code->enable_line_numbers(GESHI_NORMAL_LINE_NUMBERS);
$highlight_code = '<div class="codebox"><strong>Code: '.strtoupper($infos['1']).'</strong><br />'.$geshi_code->parse_code().'</div>';
$pun_page['message'] = preg_replace('#\[Code:([a-zA-Z0-9_-]*)\](.*)\[/Code\]#sU', $highlight_code, $pun_page['message']);
}
}
]]></hook>
// THE SECOND "hook" THAT I EXPLOIT IS post.php, JUST BEFORE POSTS ARE DISPLAYED (IN THE "while" LOOP) FOR PREVIEW
// I USE EXACTLY THE SAME CODE BUT I DON'T UNDERSTAND WHY IT DOESN'T WORK IN viewtopic.php AND HERE IT WORKS
<hook id="po_topic_review_row_pre_display"><![CDATA[
$rslt2 = $db->query('SELECT conf_value FROM '.$db->prefix."config WHERE conf_name='o_pungeshi' ") or error(__FILE__, __LINE__);
if(!$db->fetch_assoc($rslt2))
exit;
if (!defined('PUN_ROOT'))
define('PUN_ROOT', './');
require_once PUN_ROOT.'extensions/pungeshi/geshi/geshi.php';
if(isset($cur_post['message'])) {
// Run it again
preg_match("#\[Code:([a-zA-Z0-9_-]*)\](.*)\[/Code\]#sU", $cur_post['message'], $infos2);
if(isset($infos2['1']) && isset($infos2['2']) && isset($pun_page['message'])) {
$geshi_code2 =& new GeSHi($infos2['2'], $infos2['1']);
$geshi_code2->enable_line_numbers(GESHI_NORMAL_LINE_NUMBERS);
$highlight_code2 = '<div class="codebox"><strong>Code: '.strtoupper($infos2['1']).'</strong><br />'.$geshi_code2->parse_code().'</div>';
$pun_page['message'] = preg_replace('#\[Code:([a-zA-Z0-9_-]*)\](.*)\[/Code\]#sU', $highlight_code2, $pun_page['message']);
}
}
]]></hook>
</hooks>
</extension>