MyBB Community Forums

Full Version: Plugin template modification woes
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello

Here is the issue. I have 2 plugins, both modify "showthread" templateset.
First one, say "Plugin A" replaces {$pollbox} to {pollbox}{$plugin_a}
Second one also replaces {$pollbox} to {pollbox}{$plugin_b}

Now if both plugins are installed together, I would want the templates to be: {$pollbox}{$plugin_a}{$plugin_b} , (ie plugin A comes before B, and not the reverse one)

Now for that, I have to first activate plugin B and then plugin A. This is definitely inconvenient.

So, I added a code of plugin B to detect plugin A and if present, find for {$plugin_a} (instead of pollbox) and replace it with {$plugin_a}{$plugin_b}.

But it does not seem to find {$plugin_a} at all, although it is there in the templates.
Do I have to load custom templatesets separately? How should I make it find the pluginA templates?
I'm not sure why searching for plugin_a didn't exist... you don't have to load custom templatesets any differently than default ones. What function did you use to search for it? (As in preg_replace, strstr, my_strpos)...
find_replace_templatesets('showthread', '#'.preg_quote('{$votemod}').'#', '{$votemod}{$dco}');

This is the function I used.
I'm not 100% this will work - never really had a problem with replacing templates and things... Undecided The only thing I can really think of is that $votemod doesn't exist in (all?) the template (why is a question a developer will probably need to answer).

Going off your first post as an example (probably a much easier way of doing this)...

$query = $db->simple_select("templates", "*", "title = 'showthread'", array("limit" => 1));

while($template = $db->fetch_array($query)){

     // If $pluginA exists in the template...
if(my_strpos($template['template'], "{$pluginA}") !== false)
{
     // ...add in $pluginB afterwards...
find_replace_templatesets('showthread', '#'.preg_quote('{$pluginA}').'#', '{$pluginA}{$pluginB}');
}
else
{
     // ...else add $pluginB after $pollbox
find_replace_templatesets('showthread', '#'.preg_quote('{$pollbox}').'#', '{$pollbox}{$pluginB}');
}

}

Not tested.
Sorry for the late reply.
{$vote}{$votemod} are two things that exist in my templates. If you want to give it a try, please find the "voting controls" plugin at your MODs page. The voting controls plugin should also have a "developer comments" plugin file (dco.php) which is an addon to it. These two are the plugins under question.

I'll try out your piece of code, thanks Smile

SB
Tried on my local server. Doesn't work. It always does the "else" part of the code.

Here is my showthread template:
<html>
<head>
<title>{$thread['subject']}</title>
{$headerinclude}
<script type="text/javascript">
<!--
	var quickdelete_confirm = "{$lang->quickdelete_confirm}";
// -->
</script>
<script type="text/javascript" src="jscripts/thread.js?ver=1400"></script>
</head>
<body>
	{$header}
	{$pollbox}{$dco}{$vote}{$votemod}
	<div class="float_left">
		{$multipage}
	</div>
	<div class="float_right">
		{$newreply}
	</div>
	{$ratethread}
	<table border="0" cellspacing="{$theme['borderwidth']}" cellpadding="{$theme['tablespace']}" class="tborder" style="clear: both; border-bottom-width: 0;">
		<tr>
			<td class="thead" colspan="2">
				<div style="float: right;">
					<span class="smalltext"><strong><a href="showthread.php?mode=threaded&amp;tid={$tid}&amp;pid={$pid}#pid{$pid}">{$lang->threaded}</a> | <a href="showthread.php?mode=linear&amp;tid={$tid}&amp;pid={$pid}#pid{$pid}">{$lang->linear}</a></strong></span>
				</div>
				<div>
					<strong>{$thread['subject']}</strong>
				</div>
			</td>
		</tr>
		{$classic_header}
	</table>
	<div id="posts">
		{$posts}
	</div>
	<table border="0" cellspacing="{$theme['borderwidth']}" cellpadding="{$theme['tablespace']}" class="tborder" style="border-top-width: 0;">
		<tr>
			<td colspan="2" class="tfoot">
				{$search_thread}
				<div>
					<strong>&laquo; <a href="{$next_oldest_link}">{$lang->next_oldest}</a> | <a href="{$next_newest_link}">{$lang->next_newest}</a> &raquo;</strong>
				</div>
			</td>
		</tr>
	</table>
	<div class="float_left">
		{$multipage}
	</div>
	<div style="padding-top: 4px;" class="float_right">
		{$newreply}
	</div>
	<br style="clear: both;" />
	{$quickreply}
	{$threadexbox}
	{$similarthreads}
	<br />
	<div class="float_left">
		<ul class="thread_tools">
			<li class="printable"><a href="printthread.php?tid={$tid}">{$lang->view_printable}</a></li>
			<li class="sendthread"><a href="sendthread.php?tid={$tid}">{$lang->send_thread}</a></li>
			<li class="subscription_{$add_remove_subscription}"><a href="usercp2.php?action={$add_remove_subscription}subscription&amp;tid={$tid}">{$add_remove_subscription_text}</a></li>
		</ul>
	</div>

	<div class="float_right" style="text-align: right;">
		{$moderationoptions}
		{$forumjump}
	</div>
	<br style="clear: both;" />
	{$footer}
</body>
</html>

Here, {$dco} is for plugin-B.