-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Compatibility to php 3.2 #15
Comments
I detect secondary issues : |
phpBB v3.2 has a bit of change in events and BBCode, but currently I have no time to discover it.
Edit: New branch for phpBB3.2 https://github.com/o0johntam0o/phpBB-Extension-Codebox-Plus/tree/phpbb3.2 |
I think I found the bug ... In file '/event/main_listener.php' you have this function : /*
* Event: core.viewtopic_post_rowset_data (viewtopic.php)
*/
public function viewtopic_event($event)
{
if (isset($event['rowset_data']))
{
$rowset_data = $event['rowset_data'];
$post_text = isset($rowset_data['post_text']) ? $rowset_data['post_text'] : '';
$bbcode_uid = isset($rowset_data['bbcode_uid']) ? $rowset_data['bbcode_uid'] : '';
$post_id = isset($rowset_data['post_id']) ? $rowset_data['post_id'] : 0;
$part = 0;
var_dump($post_text);
var_dump('$bbcode_uid = '.$bbcode_uid);
$post_text = preg_replace_callback("#\[codebox=(.*?) file=(.*?):$bbcode_uid\](.*?)\[\/codebox:$bbcode_uid\]#msi",
function ($arg) use ($post_id, &$part)
{
return $this->codebox_template($arg[3], $arg[1], $arg[2], $post_id, ++$part);
},
$post_text);
//$post_text = preg_replace("#\[codebox=(.*?) file=(.*?):$bbcode_uid\](.*?)\[/codebox:$bbcode_uid\]#msie", "\$this->codebox_template('\$3', '\$1', '\$2', \$post_id, ++\$part)", $post_text);
if (isset($rowset_data['post_text']) && $part > 0)
{
$rowset_data['post_text'] = $post_text;
$event['rowset_data'] = $rowset_data;
}
}
} But regex doesn't match ... I printed $post_text and $bbcode_uid for understand the regex ... but i don't understand this ... So what I got :
So regex `"#\[codebox=(.*?) file=(.*?):$bbcode_uid\](.*?)\[\/codebox:$bbcode_uid\]#msi"` doesn't match ... So the display was created in second call : /*
* Event: core.modify_format_display_text_after (message_parser.php)
* Use: $this->codebox_template()
* Generate text for preview
*/
public function message_parser_event($event)
{
if (isset($event['text']))
{
var_dump($event);
$text = $event['text'];
$post_id = 0;
$part = 0;
$text = preg_replace_callback('#<div class="codebox" title="' . preg_quote($this->user->lang['CODEBOX_PLUS_TITLE']) . '" data-language="(.*?)" data-filename="(.*?)"><p>.*?</p><code>(.*?)</code></div>#msi',
function ($arg) use ($post_id, &$part)
{
return $this->codebox_template(preg_replace('#\<br\\s*/?\>#msi', "\n", $arg[3]), $arg[1], $arg[2], $post_id, ++$part);
},
$text);
//$text = preg_replace('#<div class="codebox" title="' . preg_quote($this->user->lang['CODEBOX_PLUS_TITLE']) . '" data-language="(.*?)" data-filename="(.*?)"><p>.*?</p><code>(.*?)</code></div>#msie', "\$this->codebox_template(preg_replace('#\<br\\s*/?\>#msi', '\n', '\$3'), '\$1', '\$2', \$post_id, ++\$part)", $text);
$event['text'] = $text;
}
} So the code has been highlighting .... but $post_id is equal to 0 ( is normal because this event is fire when you want a preview ... but is fire when you read topic too ... ) public function codebox_template($code = '', $lang = 'text', $file = '', $id = 0, $part = 0)
{
[...]
if ($id != 0 && $this->download_enabled && $lang != 'NULL')
{
$re .= ' <a href="' . $this->helper->route('o0johntam0o_codeboxplus_download_controller', array('id' => $id, 'part' => $part)) . '" onclick="window.open(this.href); return false;">';
$re .= '[' . $this->user->lang['CODEBOX_PLUS_DOWNLOAD'] . ']</a> ' . '('. $file . ')';
}
[...]
} So I think we need just update the first regex to match with input ... And for double line just need to update this : /*
* Event: core.modify_format_display_text_after (message_parser.php)
* Use: $this->codebox_template()
* Generate text for preview
*/
public function message_parser_event($event)
{
if (isset($event['text']))
{
$text = $event['text'];
$post_id = 0;
$part = 0;
$text = preg_replace_callback('#<div class="codebox" title="' . preg_quote($this->user->lang['CODEBOX_PLUS_TITLE']) . '" data-language="(.*?)" data-filename="(.*?)"><p>.*?</p><code>(.*?)</code></div>#msi',
function ($arg) use ($post_id, &$part)
{
// Before :
//return $this->codebox_template(preg_replace('#\<br\\s*/?\>#msi', "\n", $arg[3]), $arg[1], $arg[2], $post_id, ++$part);
// After :
return $this->codebox_template(preg_replace('#\<br\\s*/?\>#msi', "", $arg[3]), $arg[1], $arg[2], $post_id, ++$part);
},
$text);
//$text = preg_replace('#<div class="codebox" title="' . preg_quote($this->user->lang['CODEBOX_PLUS_TITLE']) . '" data-language="(.*?)" data-filename="(.*?)"><p>.*?</p><code>(.*?)</code></div>#msie', "\$this->codebox_template(preg_replace('#\<br\\s*/?\>#msi', '\n', '\$3'), '\$1', '\$2', \$post_id, ++\$part)", $text);
$event['text'] = $text;
}
} |
I try to find the good regex .... but I need your help |
Hi Hideman85, I guess the new regex should be something like this |
Balise |
Good regex is
http://www.pastefile.com/bbgFtG It's same regex but doesnt match all .... This is just the last incompatibility .... I just add link to my forum where I try to debug it : http://factionacraft.raidghost.com/forum/viewtopic.php?f=2&t=16 Thanks in advance for your help |
Hi Hideman85, you can start with the following instructions: Add this function: public function functions_content_event($event)
{
if (isset($event['text']))
{
$text = $event['text'];
$post_id = 0;
$part = 0;
$callback = function($arg) use ($post_id, &$part)
{
return $this->codebox_template(preg_replace('#\<br\\s*/?\>#msi', "\n", $arg[4]), $arg[1], $arg[2], $arg[3], ++$part);
};
$text = preg_replace_callback('#<div class="codebox" title="' . preg_quote($this->user->lang['CODEBOX_PLUS_TITLE']) . '" data-language="(.*?)" data-filename="(.*?)"><p>.*?</p><code>\(([0-9]+)\)(.*?)</code></div>#msi', $callback, $text);
$event['text'] = $text;
}
} Edit the function "viewtopic_event": public function viewtopic_event($event)
{
if (isset($event['rowset_data']))
{
$rowset_data = $event['rowset_data'];
$post_text = isset($rowset_data['post_text']) ? $rowset_data['post_text'] : '';
$post_id = isset($rowset_data['post_id']) ? $rowset_data['post_id'] : 0;
$callback = function($arg) use ($post_id)
{
return $arg[1] . "($post_id)" . $arg[2] . $arg[3];
};
$post_text = preg_replace_callback("#(<CODEBOX codebox=\".*?\" file=\".*?\"><s>\[Codebox=.*? file=.*?\]</s>)(.*?)(<e>\[/Codebox\]</e></CODEBOX>)#msi", $callback, $post_text, -1, $part);
if (isset($rowset_data['post_text']) && $part > 0)
{
$rowset_data['post_text'] = $post_text;
$event['rowset_data'] = $rowset_data;
}
}
} Good luck! |
Hi @o0johntam0o it's just perfect ❤️ last bug it's download .... In your function You can try here : http://factionacraft.raidghost.com/forum/viewtopic.php?f=2&t=16 Thanks in advance for your help |
If you want I can send you my change for your extension styling .... |
I test your new version on my forum and have just one probleme ...
I find it and correct it :
In routing.yml you have :
And you need :
So you just need to create an other branch to apply change ....
Thanks for you for your update ;)
The text was updated successfully, but these errors were encountered: