MyBB Community Forums

Full Version: Search and replacing issue
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Making a plugin for a site and when I try to do the search and replace for activate/deactivate it completely screws over and doesn't work as it should.


The code is:
function gradient_activate()
{
    include MYBB_ROOT."/inc/adminfunctions_templates.php";
    find_replace_templatesets("usercp_nav_misc", '#'.preg_quote('<tr><td class="trow1 smalltext"><a href="{$profile_link}" class="usercp_nav_item usercp_nav_viewprofile">{$lang->ucp_nav_view_profile}</a></td></tr>').'#', '<tr><td class="trow1 smalltext"><a href="{$profile_link}" class="usercp_nav_item usercp_nav_viewprofile">{$lang->ucp_nav_view_profile}</a></td></tr><tr><td class="trow1 smalltext"><a href="page.php" class="usercp_nav_item usercp_nav_usergroups">The link</a></td></tr>');
}

function gradient_deactivate()
{
    include MYBB_ROOT."/inc/adminfunctions_templates.php";
    find_replace_templatesets("usercp_nav_misc", '#'.preg_replace('<tr><td class="trow1 smalltext"><a href="{$profile_link}" class="usercp_nav_item usercp_nav_viewprofile">{$lang->ucp_nav_view_profile}</a></td></tr><tr><td class="trow1 smalltext"><a href="page.php" class="usercp_nav_item usercp_nav_usergroups">The link</a></td></tr>').'#','<tr><td class="trow1 smalltext"><a href="{$profile_link}" class="usercp_nav_item usercp_nav_viewprofile">{$lang->ucp_nav_view_profile}</a></td></tr>'); 
}


Outcome:
http://i.imgur.com/mFJoaeo.png

and on de-activate:
http://i.imgur.com/TdIzX4X.png
can you try making the replacement content short ..
you can start with {$lang->ucp_nav_view_profile}

and can you put your content in a variable and use it for the replacing

gloabl $gradvar;
$gradvar = '<td class="trow1 smalltext"><a href="page.php" class="usercp_nav_item usercp_nav_usergroups">The link</a></td></tr>'

find_replace_templatesets("usercp_nav_misc", '#'.preg_quote('{$lang->ucp_nav_view_profile}</a></td></tr>').'#', '{$lang->ucp_nav_view_profile}</a></td></tr>{$gradvar}');

see once again Modifying Templates to Add a Variable

see also preg_replace , plugins & hooks , advanced plugin development
Thanks!

I've gotten it to add the text correctly, but removing it is the issue now. It'll process and uninstall but won't remove the $gradient stuff.

function gradient_deactivate()
{
    global $gradient;
    include MYBB_ROOT."/inc/adminfunctions_templates.php";
    find_replace_templatesets("usercp_nav_profile", '#'.preg_quote($gradient).'#i', ''); 
}

The templates are different because I figured the purpose of the plugin would be better suited for under the options area.