MyBB Community Forums

Full Version: Fatal error: Cannot redeclare find_replace_templatesets() ... on line 101
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
To expedite the process of answering the multitude of questions for MyBB 1.6, please include the following information when posting your problems:
Detailed description of your problem, including steps to reproduce if necessary
URL to your forum/URL to specific problematic page
New installation or upgrade (from which version of MyBB)?
Test user account (if a posting/UserCP issue)
Screenshot or error text, verbatim
Also, please read the sticky threads and search before posting your question.

Thanks for your cooperation,
MyBB Support Team

Forum

I'm running a new installation of MyBB 1.6 - the forum address is http://gamerone.net and I have read the sticky threads and searched before posting.

Description of problem

In the plugins section of the admin control panel this error now appears:

Fatal error: Cannot redeclare find_replace_templatesets() (previously declared in /home/steamava/public_html/domaingamerone.net/inc/adminfunctions_templates.php:22) in /home/steamava/public_html/domaingamerone.net/inc/adminfunctions_templates.php on line 101

I have been using my forum now 3 days, everything works perfect apart from this one error. As for my own guess on what causes this - it seemed to appear recently after the most recent mod installation failed of the "Facebook Share Button On Postbit" - This failure was yesterday and do not have a screenshot of the plugin failed installation. This error is frustrating because it stops you from installing plugins but the installed plugins can still be seen and edited in the configuration section. Strangely the facebook share button mod appears 3 times in the configuration section even though I clicked uninstall after the installation failed. In the settings of the facebook share button i choose the option do not display and all 3 of the appearances of this mod were updated. So if I were to reproduce this problem, maybe it would be to go back in time before it was installed, and install the plugin to see it doesn't work for whatever reason. However, although the failed installation is likely to have been the cause, I'm not 100% sure as I'm a beginner with myBB.

Images

Image 1 - fatal error shown in the plugins category:
[Image: 55060894.th.png]

Uploaded with ImageShack.us

Image 2 - plugins still available to be seen in configuration section of admin control panel and facebook share button appears 3 times:
[Image: 73163451.th.png]

Uploaded with ImageShack.us

Image 3 - facebook share button settings accessed from the configuration section:
[Image: 48794932.th.png]

Uploaded with ImageShack.us

adminfunctions_templates.php

<?php
/**
 * MyBB 1.6
 * Copyright 2010 MyBB Group, All Rights Reserved
 *
 * Website: http://mybb.com
 * License: http://mybb.com/about/license
 *
 * $Id: adminfunctions_templates.php 5164 2010-08-02 03:35:35Z RyanGordon $
 */

/**
 * Find and replace a string in a particular template through every template set.
 *
 * @param string The name of the template
 * @param string The regular expression to match in the template
 * @param string The replacement string
 * @param int Set to 1 to automatically create templates which do not exist for that set (based off master) - Defaults to 1
 * @return bolean true if updated one or more templates, false if not.
 */

function find_replace_templatesets($title, $find, $replace, $autocreate=1)
{
	global $db, $mybb;
	
	$return = false;
	
	$template_sets = array(-2, -1);
	
	// Select all global with that title
	$query = $db->simple_select("templates", "tid, template", "title = '".$db->escape_string($title)."' AND sid='-1'");
	while($template = $db->fetch_array($query))
	{
		// Update the template if there is a replacement term or a change
		$new_template = preg_replace($find, $replace, $template['template']);
		if($new_template == $template['template'])
		{
			continue;
		}
		
		// The template is a custom template.  Replace as normal.
		$updated_template = array(
			"template" => $db->escape_string($new_template)
		);
		$db->update_query("templates", $updated_template, "tid='{$template['tid']}'");
	}
	
	// Select all other modified templates with that title
	$query = $db->simple_select("templates", "tid, sid, template", "title = '".$db->escape_string($title)."' AND sid > 0");
	while($template = $db->fetch_array($query))
	{
		// Keep track of which templates sets have a modified version of this template already
		$template_sets[] = $template['sid'];
		
		// Update the template if there is a replacement term or a change
		$new_template = preg_replace($find, $replace, $template['template']);
		if($new_template == $template['template'])
		{
			continue;
		}
		
		// The template is a custom template.  Replace as normal.
		$updated_template = array(
			"template" => $db->escape_string($new_template)
		);
		$db->update_query("templates", $updated_template, "tid='{$template['tid']}'");
		
		$return = true;
	}
	
	// Add any new templates if we need to and are allowed to
	if($autocreate != 0)
	{
		// Select our master template with that title
		$query = $db->simple_select("templates", "title, template", "title='".$db->escape_string($title)."' AND sid='-2'", array('limit' => 1));
		$master_template = $db->fetch_array($query);
		$master_template['new_template'] = preg_replace($find, $replace, $master_template['template']);
		
		if($master_template['new_template'] != $master_template['template'])
		{
			// Update the rest of our template sets that are currently inheriting this template from our master set			
			$query = $db->simple_select("templatesets", "sid", "sid NOT IN (".implode(',', $template_sets).")");
			while($template = $db->fetch_array($query))
			{
				$insert_template = array(
					"title" => $db->escape_string($master_template['title']),
					"template" => $db->escape_string($master_template['new_template']),
					"sid" => $template['sid'],
					"version" => $mybb->version_code,
					"status" => '',
					"dateline" => TIME_NOW
				);
				$db->insert_query("templates", $insert_template);
				
				$return = true;
			}
		}
	}
	
	return $return;
}
?>
In the plugin file, look in the activate and deactivate function, it should have something like this:

require MYBB_ROOT . "inc/adminfunctions_templates.php";

Change the require to require_once
I don't understand sorry... The facebook plugin was deleted after uninstall and just now I downloaded the files again and uploaded them but it hasn't made a difference. Any idea how to fix this?
(2010-11-10, 06:37 PM)gamerone.net Wrote: [ -> ]Any idea how to fix this?

I've said how to fix it, in the plugin that you uploaded before the problem started, find the code in my previous post and make the change I said.
The file was not there to make that change.
What?? If this only recently started happening, the file in question will be one you uploaded recently. Look at whatever plugins you uploaded recently.
I have made the changes to the facebook plugin files I just uploaded again:

function facebook_share_activate()
{
	global $db, $mybb;
	$facebook_share_group = array(
		"gid" => "NULL",
		"name" => "facebook_share",
		"title" => "Facebook Share Button On Postbit",
		"description" => "Places a facebook share button on postbit.",
		"disporder" => "1",
		"isdefault" => "no",
	);
	$db->insert_query("settinggroups", $facebook_share_group);
	
	$gid = $db->insert_id();
	$facebook_share_setting_1 = array(
		"sid"			=> "NULL",
		"name"			=> "facebook_share_1",
		"title"			=> "Facebook Share Button",
		"description"	=> "Change the text on your facebook button. [Default = Share]",
		"optionscode"	=> "text",
		"value"			=> 'Share',
		"disporder"		=> '3',
		"gid"			=> intval($gid),
	);
	$gid = $db->insert_id();
	$facebook_share_setting_2 = array(
		"sid"			=> "NULL",
		"name"			=> "facebook_share_2",
		"title"			=> "Enable Facebook Share Button ?",
		"description"	=> "Allows you to enable/disable your facebook share button.",
		"optionscode"	=> "yesno",
		"value"			=> 'yes',
		"disporder"		=> '2',
		"gid"			=> intval($gid),
	);
	$db->insert_query("settings", $facebook_share_setting_1);
	$db->insert_query("settings", $facebook_share_setting_2);
	
require_once MYBB_ROOT."/inc/adminfunctions_templates.php";
	find_replace_templatesets("postbit", "#".preg_quote('{$post[\'user_details\']}')."#i", '{$post[\'user_details\']}{$post[\'facebook_share\']}');
// Rebuilding settings
    rebuild_settings();
}

function facebook_share_deactivate()
{
	global $db, $mybb;
	$db->query("DELETE FROM ".TABLE_PREFIX."settinggroups WHERE name='facebook_share'");
	$db->query("DELETE FROM ".TABLE_PREFIX."settings WHERE name='facebook_share_1'");
	$db->query("DELETE FROM ".TABLE_PREFIX."settings WHERE name='facebook_share_2'");

	require_once MYBB_ROOT."/inc/adminfunctions_templates.php";
	find_replace_templatesets("postbit", "#".preg_quote('{$post[\'facebook_share\']}')."#i", '', 0);

But the fatal error didn't budge.
Check other plugins too, somewhere it'll have just require.
Do we only change the activate and de-activate sections if they are require? Or if I see that anywhere do I change it no-matter where it is.
Make the change wherever require appears in the plugin.
Pages: 1 2