MyBB Community Forums

Full Version: Change regex pattern
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi guys,
I'm in a hurry completing my website which after 11 months of development is getting nearly to its release.

I installed euantor's MyAlerts plugin to provide a notification system to my board. I'm trying to make it working with my own custom core edits I've made to the quoting system. Basically, I got rid of [quote] tags and replaced them with my custom HTML input. MyAlerts has been developed with the normal regex syntax which recognizes the [quote] syntax, and I have necessarily to edit the function if I would like to use it with my modified syntax.

This is my syntax:

<div class="myclass">other messy and unuseful code here</div>

While the regex pattern in the function looks like this:

$pattern = "#\[quote=([\"']|&quot;|)(.*?)(?:\\1)(.*?)(?:[\"']|&quot;)?\](.*?)\[/quote\](\r\n?|\n?)#esi";

How can I edit this pattern and adapt it to my own syntax? I'm asking you because euantor told me that he pasted&copied the regex function from a core file and doesn't know how to help me. I hope you will be able to give it a try Smile

Sorry for my english, I'm italian.

Can you give an actual example? There is nothing you can do with div myclass.
Well, actually the full syntax looks like this:

<div class="idlMessaggio-citazione">

<a href="{$userlink}">{$quoted_post['avatar']}</a>

<span>{$linkback} {$date}</span>
<br style=\"clear:both\" />



$userlink = link to the quoted user
$quoted_post['avatar'] = quoted user's avatar
$message = quoted message
$linkback = link to the quoted message
$date = quoted message's date

But I suppose it's unuseful code which I don't need to search for in the preg_match_all function which returns the quoting info within MyAlerts.

I can include member's uid and post's dateline, maybe within class="idlMessaggio-citazione" block, if necessary. Please note that those classes are in italian language but you don't have to care about them.
The code you are posting is the replacement that matches the regular expression. To determine how to edit the regular expression it would be necessary to know your custom tags usage, ie [mytag=var]quoted text[/mytag]
This is my regular expression, actually. I completely got rid of [quote]quoted text[/quote] syntax because I replaced the editor with my own WYSIWYG editor, and the best solution I could thought to integrate quoting into WYSIWYG interface was to parse quoted post infos before the parsing of the post.

In inc/function_posting.php I replaced:

return "[quote='{$quoted_post['username']}' pid='{$quoted_post['pid']}' dateline='{$quoted_post['dateline']}']\n{$quoted_post['message']}\n[/quote]\n\n";


$linkback = $date = "";
$delete_quote = true;
$message = $quoted_post['message'];
$pid = $quoted_post['pid'];
if($pid) {
$url = $mybb->settings['bburl']."/".get_post_link($pid)."#pid$pid";
$user = strtolower($quoted_post['username']);
if($user != '') {
$userlink = $mybb->settings['bburl']."/utente-".$user;
$username = $quoted_post['username'];
$linkback = "Sent by <a href=\"{$userlink}\">{$username}</a>";
$postdate = my_rawdate($mybb->settings['dateformat'], intval($quoted_post['dateline']));
$posttime = my_rawdate($mybb->settings['timeformat'], intval($quoted_post['dateline']));
$daysdate = ceil((TIME_NOW - intval($quoted_post['dateline'])) / (24*3600));
$date = "il <a href=\"{$url}\">{$postdate}, {$posttime}</a>";

return "<div class=\"idlMessaggio-citazione\"><a href=\"{$userlink}\">{$quoted_post['avatar']}</a><blockquote>{$message}</blockquote><div><span>{$linkback} {$date}</span><br style=\"clear:both\" /></div></div><p></p>";

my_rawdate is my custom date function which returns the date as my_date would do, but without "Today" and "Yesterday" formatting.

As you can see, I need a custom regex pattern to search within the post, and this would be completely different from [mytag=var]quoted text[/mytag] syntax, because I'm using directly HTML code instead of BBCode. I can include vars in HTML class attribute, such as class="var1 var2 var3". My question remains the same: how would I edit the regex pattern? Thank you Smile
Sorry I don't quite know the answer. I assumed you were talking about a standard MyCode to replace the core quote functionality, not a core edit.

Maybe someone else knows [Image: angel.gif]
*crossing my fingers* Big Grin
You still haven't provided the info I asked for (actual output as seen by the plugin at the time it executes the regexp, not variables).

How about adding a fake mycode to your html, like

<blockquote code="[quote='Shade' pid='931269' dateline='1351684577']">
quoted text
</blockquote code="[/quote]">

With some luck the original regexp would then match unchanged, as well as other plugins.

Best solution would've been to keep the original MyBB bbcodes around
Thank you frostschutz, you made my day. I succeeded into preserving my own syntax, which I need for my WYSIWYG editor, and making MyAlerts recognize a quoted post with your solution (actually, I put [/quote] straight after the opening tag and it's working).