MyBB Community Forums
find_replace_templatesets help? - Printable Version

+- MyBB Community Forums (https://community.mybb.com)
+-- Forum: Extensions (https://community.mybb.com/forum-201.html)
+--- Forum: Plugins (https://community.mybb.com/forum-73.html)
+---- Forum: Plugin Development (https://community.mybb.com/forum-68.html)
+---- Thread: find_replace_templatesets help? (/thread-30438.html)



find_replace_templatesets help? - Tim B. - 2008-04-08

Can someone give me some help with this find_replace_templatesets.
I am making (my first plugin) a plugin that will add a link to your home page in just before the search link up the top. I am modelling it of the forum message plugin but i have run into a few problems.

I need to find:
<div class="menu">
				<ul>
And replace it with
<div class="menu">
<ul>
<li><a href="{$mybb->settings['homeurl']}"><img src="{$mybb->settings['bburl']}/{$theme['imgdir']}/on.gif" alt="" />Home</a></li>

So i am using:
find_replace_templatesets('header, '<div class="menu"><ul>', '<li><a href="{$mybb->settings['homeurl']}"><img src="{$mybb->settings['bburl']}/{$theme['imgdir']}/on.gif" alt="" />Home</a></li>');

But it spits this error:
Parse error: syntax error, unexpected T_CLASS in D:\xampp\htdocs\MYBB\inc\plugins\homelink.php on line 61
I have tryed all sorts of other things but i think there must be something i am missing.

Thanks, Smile

Ps. Line 61 is the code above.


RE: find_replace_templatesets help? - Blue - 2008-04-08

Wheel-World Wrote:Can someone give me some help with this find_replace_templatesets.
I am making (my first plugin) a plugin that will add a link to your home page in just before the search link up the top. I am modelling it of the forum message plugin but i have run into a few problems.

I need to find:
<div class="menu">
				<ul>
And replace it with
<div class="menu">
<ul>
<li><a href="{$mybb->settings['homeurl']}"><img src="{$mybb->settings['bburl']}/{$theme['imgdir']}/on.gif" alt="" />Home</a></li>

So i am using:
find_replace_templatesets('header, '<div class="menu"><ul>', '<li><a href="{$mybb->settings['homeurl']}"><img src="{$mybb->settings['bburl']}/{$theme['imgdir']}/on.gif" alt="" />Home</a></li>');

But it spits this error:
Parse error: syntax error, unexpected T_CLASS in D:\xampp\htdocs\MYBB\inc\plugins\homelink.php on line 61
I have tryed all sorts of other things but i think there must be something i am missing.

Thanks, Smile

Ps. Line 61 is the code above.

First of all, in your code, you are missing a ' after header and you need to escape all the single quotes in the replace string. The syntax highlighter picks it up right away

find_replace_templatesets('header', '<div class="menu"><ul>', '<li><a href="{$mybb->settings[\'homeurl\']}"><img src="{$mybb->settings[\'bburl\']}/{$theme[\'imgdir\']}/on.gif" alt="" />Home</a></li>');

(I can't seem to use the PHP tags... it deletes things from my post when I do. o_O)

Also, your replace won't work correctly. You have to take into account new lines and tabs in your search string. So, you'll probably need something like '#<div class="menu">(\n|\r|\r\n)\t\t\t<ul>#' (that looks like three tabs, though it could be more).


RE: find_replace_templatesets help? - Dennis Tsang - 2008-04-08

The find and replace uses the preg_replace function, so your strings need to conform to the regular expressions syntax. See www.php.net/preg_replace and the related syntax pages for info.

Just a note: You need to escape:
<
>
=
with
\<
\>
\=
There may be other characters that have special meaning in regex that also need to be replaced (see the docs above)


RE: find_replace_templatesets help? - Blue - 2008-04-08

Ah, right, forgot.

'#'.preg_quote('<div class="menu">').'(\n|\r|\r\n)\t\t\t'.preg_quote('<ul>').'#'
then.