MyBB Community Forums

Full Version: Plugin problem with 1.6.5
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
After upgrading my forum from 1.6.4 to 1.6.5 I noticed that some of the plugins doesn't show up. For example the "IP-by-country flag" and the "social-sites" are not there anymore.

[Image: xdeewx.jpg]

I've read this:

Quote:Plugin System Changes
Changes from Issue 1373: If you're using any of the following hooks in your plugins, you need to make sure you're returning the variable passed to it, as in 1.6.5 these were all switched from using $plugins->run_hooks_by_ref("func" $var) to $var = $plugins->run_hooks("func", $var) as passing by reference is now deprecated in PHP.

but I have no idea what it means. Is there a simple and easy way to check this not working plugins and change someting so that it works again?

Thanks in advance,

Ger

Poke through this thread and you'll find out how to fix them.
(2011-11-25, 06:55 PM)Paul H. Wrote: [ -> ]Poke through this thread and you'll find out how to fix them.

Thanks Paul, I readed all this information but I can't find a script like this:
$plugins->add_hook("datahandler_user_update ", "do_something");

function do_something($data) {

    //do something here

} 


Where should I find this? In the php-file of every plugin that I downloaded or in a specific template? Please help me a little bit, if I know to change the first one then the rest should be easy to do by myself.



It'll be in the plugin files, ./inc/plugins/*
Look in the plugins that don't work, and make the changes stated in the thread.
I'm very sorry but I still can't find this line I have to change. For example, this is de script for the "IP-country flag":
<?php

/**
 * @author 
 * @copyright 2009
 */


if(!defined("IN_MYBB")) {
    die("This file cannot be accessed directly.");
    }
/**
* MyBB Plugin: IP country v 0.1
* ---------------------------------------------------------------------------------------------------------
* http://www.edidesign.ca
* ---------------------------------------------------------------------------------------------------------
* Author : Thor2705 
* http://www.edidesign.ca
* Please do not remove the links from this file. 
* DO NOT REDISTRIBUTE THIS PLUGIN WITHOUT MY PERMISION
**/

$plugins->add_hook("postbit", "ipcountry");

function ipcountry_info()
{
	return array(
		"name"			=> "ipcountry",
		"description"	=> "It is adding the country of the user/guest in postbit based on the user/guest IP",
		"website"		=> "http://www.edidesign.ca/",
		"version"		=> "0.1",
		"author"		=> "thor2705",
		"authorsite"	=> "http://www.edidesign.ca",
		"compatibility"  => "16*",
		'guid'        => ' '
	);
}
function ipcountry_install()
{
global $db, $mybb, $templates, $theme, $lang, $unviewwhere, $parser;
	
$handle = fopen(dirname(__FILE__) . '/ip-to-country.csv', "r");		
$added = 0;															


$results = $db->write_query("
		CREATE TABLE IF NOT EXISTS `".TABLE_PREFIX."ip_lookup` (
			`ipFrom` INT( 15 ) UNSIGNED NOT NULL DEFAULT '0',
			`ipTo` INT( 15 ) UNSIGNED NOT NULL DEFAULT '0',
			`country2` TEXT NOT NULL ,
			`country3` TEXT NOT NULL ,
			`country` TEXT NOT NULL
		)", __FILE__, __LINE__);
if ($result === false)
	die("Table creation failed: " . mysql_error().__LINE__.__FILE__);
else
	echo 'Table creation success.<br>';
	

while ($data = fgetcsv($handle, 1000, ","))
{
	
	$result = $db->write_query("INSERT INTO `".TABLE_PREFIX."ip_lookup`(`ipFrom`, `ipTo`, `country2`, `country3`, `country`) VALUES('".$data['0']."', '".$data['1']."', '".$data['2']."', '".$data['3']."', '". addslashes($data['4']) ."')", __FILE__, __LINE__);
	
	if ($result === false)
		die("Row insertion failed: " . mysql_error().__LINE__.__FILE__);
	$added++;					

}

fclose ($handle);			

echo 'IP table inserted. ' . $added . ' rows added in total.<br><br>';

	
}
function ipcountry_is_installed()
{
global $db;
	if($db->table_exists("ip_lookup")){
		return true;
	}
	return false;
			
	
}
function ipcountry_uninstall()
{
global $db;
		$db->write_query("DROP TABLE `".TABLE_PREFIX."ip_lookup`;");	
	
}

function ipcountry_activate()
{
	global $db, $mybb, $templates, $theme, $lang, $unviewwhere, $parser;
	require MYBB_ROOT.'/inc/adminfunctions_templates.php';	

$templatearray = array(
		"tid" => "NULL",
		"title" => "postbit_ipcountry1",
		"template" => " <span class=\"smalltext\">{\$post[\'ipcountry\']}<br />",	
		"sid" => "-1",
		);
	$db->insert_query("templates", $templatearray);

	
}
function ipcountry_deactivate()
{
	global $db, $mybb, $templates, $theme, $lang, $unviewwhere, $parser;
	require  MYBB_ROOT.'/inc/adminfunctions_templates.php';
	
$db->delete_query('templates', 'title = "postbit_ipcountry1"');

}
function ipcountry($post)
{
global $db, $mybb, $templates, $theme, $lang, $unviewwhere, $parser, $socialbookmark;

$txt['ipcountry_title'] = 'to Country';
$txt['ipcountry_na'] = '--';
$txt['ipcountry_natitle'] = 'Not Listed';	

$ip = $post['ipaddress'];
$request = $db->query("
			SELECT country
			FROM ".TABLE_PREFIX."ip_lookup
			WHERE ipFrom<=INET_ATON('" . $ip . "') AND ipTo>=INET_ATON('" . $ip . "')
			LIMIT 1"); 
		

	$tmp=$db->fetch_array($request);
		
	$abc = $tmp['country'];
	$post['ipcountry'] = '<img src="'.$mybb->settings['bburl'].'/'.$theme['imgdir'].'/flags/'.$abc.'.gif" title="'.$abc.'" alt="'.$abc.'">';
	
eval("\$post['ipcountry'] = \"".$templates->get("postbit_ipcountry1")."\";");
$post['user_details'] .= $post['ipcountry'];
	
}

?>

Where is that "function do_something($data)" that I have to change in "function do_something(&$data)? Please could somebody show me where I can find it?



Replace "function ipcountry($post)" with "function ipcountry(&$post)"

Geeze, please use your head. Obviously the "function do_something($data)" is a made up example and the exact wording will be different on a plugin by plugin basis.
Aha, I see Blush so it's not special ($data) I'm looking for!

So in this next plugin I need to change several lines like for example:
function board_messages_admin_config_action_handler($actions)
function board_messages_admin_config_menu($sub_menu)
function board_messages_admin_config_permissions($admin_permissions)
Am I right?


<?php
/**
 * Board Messages Plugin for MyBB
 * Copyright © 2010 MyBB Mods
 *
 * By: Alan Crisp
 * Website: http://mods.mybb.com/
 * Version: 2.0.1
 */

// Disallow direct access to this file for security reasons
if(!defined("IN_MYBB"))
{
	die("Direct initialization of this file is not allowed.<br /><br />Please make sure IN_MYBB is defined.");
}

$plugins->add_hook('admin_load', 'board_messages_admin');
$plugins->add_hook('admin_config_menu', 'board_messages_admin_config_menu');
$plugins->add_hook('admin_config_action_handler', 'board_messages_admin_config_action_handler');
$plugins->add_hook('admin_config_permissions', 'board_messages_admin_config_permissions');
$plugins->add_hook('global_start', 'board_messages');

function board_messages_info()
{
	global $lang;
	$lang->load('board_messages');

	return array(
		'name'=> $lang->board_messages,
		'description'   => $lang->board_messages_desc,
		'website'       => 'http://mods.mybb.com/',
		'author'        => 'Alan Crisp',
		'authorsite'    => 'http://musicalmidget.com/',
		'version'       => '2.0.1',
		'guid'          => '2759907b61afa0e03b67e658b6b569e3',
		'compatibility' => '14*, 16*'
	);
}

function board_messages_install()
{
	global $db;

	$db->write_query("
		CREATE TABLE ".TABLE_PREFIX."board_messages (
			`mid` int(10) unsigned NOT NULL auto_increment,
			`message` text NOT NULL,
			`class` varchar(255) NOT NULL,
			`global` tinyint(1) NOT NULL default '1',
			`enabled` tinyint(1) NOT NULL default '0',
			PRIMARY KEY (mid)
		) Type=MyISAM;
	");
}

function board_messages_is_installed()
{
	global $db;

	if($db->table_exists('board_messages'))
	{
		return true;
	}

	return false;
}

function board_messages_uninstall()
{
	global $db;
	$db->drop_table('board_messages');
}

function board_messages_activate()
{
	global $db;

	$stylesheet = '.board_message {
	background: #EFEFEF;
	color: #333333;
	border-top: 2px solid #D4D4D4;
	border-bottom: 2px solid #D4D4D4;
	padding: 5px;
	margin-top: 10px;
}';

	$new_stylesheet = array(
		'name'         => 'board_messages.css',
		'tid'          => 1,
		'attachedto'   => '',
		'stylesheet'   => $stylesheet,
		'lastmodified' => TIME_NOW
	);

	$sid = $db->insert_query('themestylesheets', $new_stylesheet);
	$db->update_query('themestylesheets', array('cachefile' => "css.php?stylesheet={$sid}"), "sid='{$sid}'", 1);

	$query = $db->simple_select('themes', 'tid');
	while($theme = $db->fetch_array($query))
	{
		require_once MYBB_ADMIN_DIR.'inc/functions_themes.php';
		update_theme_stylesheet_list($theme['tid']);
	}

	require MYBB_ROOT.'inc/adminfunctions_templates.php';
	find_replace_templatesets('header', '#<navigation>#', "<navigation>\n\t\t\t{\$board_messages}");
	
	change_admin_permission('config', 'board_messages', 0);
}

function board_messages_deactivate()
{
	global $db;

	$db->delete_query('themestylesheets', "name='board_messages.css'");

	$query = $db->simple_select('themes', 'tid');
	while($theme = $db->fetch_array($query))
	{
		require_once MYBB_ADMIN_DIR.'inc/functions_themes.php';
		update_theme_stylesheet_list($theme['tid']);
	}

	require MYBB_ROOT.'inc/adminfunctions_templates.php';
	find_replace_templatesets('header', '#\n\t\t\t{\$board_messages}#', '', 0);

	change_admin_permission('config', 'board_messages', -1);
}

function board_messages_admin_config_menu($sub_menu)
{
	global $lang;
	$lang->load('board_messages');

	$sub_menu[] = array('id' => 'board_messages', 'title' => $lang->board_messages, 'link' => 'index.php?module=config/board_messages');
}

function board_messages_admin_config_action_handler($actions)
{
	$actions['board_messages'] = array('active' => 'board_messages', 'file' => 'board_messages');
}

function board_messages_admin_config_permissions($admin_permissions)
{
	global $lang;
	$admin_permissions['board_messages'] = $lang->can_manage_board_messages;
}

function board_messages_admin()
{
	global $db, $lang, $mybb, $page, $run_module, $action_file;

	if($run_module == 'config' && $action_file == 'board_messages')
	{
		$page->add_breadcrumb_item($lang->board_messages, 'index.php?module=config/board_messages');

		if($mybb->input['action'] == 'add')
		{
			if($mybb->request_method == 'post')
			{
				if(!trim($mybb->input['message']))
				{
					$errors[] = $lang->error_no_message;
				}

				if(!$errors)
				{
					$new_message = array(
						'message' => $db->escape_string($mybb->input['message']),
						'class'   => $db->escape_string($mybb->input['class']),
						'global'  => intval($mybb->input['global']),
						'enabled' => intval($mybb->input['enabled'])
					);

					$mid = $db->insert_query('board_messages', $new_message);

					log_admin_action($mid);

					flash_message($lang->success_message_saved, 'success');
					admin_redirect('index.php?module=config/board_messages');
				}
			}

			$page->add_breadcrumb_item($lang->add_message);
			$page->output_header($lang->board_messages.' - '.$lang->add_message);

			$sub_tabs['manage_messages'] = array(
				'title' => $lang->board_messages,
				'link'  => 'index.php?module=config/board_messages',
			);

			$sub_tabs['add_message'] = array(
				'title'       => $lang->add_message,
				'link'        => 'index.php?module=config/board_messages&amp;action=add',
				'description' => $lang->add_message_desc
			);

			$page->output_nav_tabs($sub_tabs, 'add_message');

			if($errors)
			{
				$page->output_inline_error($errors);
			}

			$form = new Form('index.php?module=config/board_messages&amp;action=add', 'post', 'add');
			$form_container = new FormContainer($lang->add_message);
			$form_container->output_row($lang->message.' <em>*</em>', $lang->message_desc, $form->generate_text_area('message', $mybb->input['message']));
			$form_container->output_row($lang->class, $lang->class_desc, $form->generate_text_box('class', $mybb->input['class']));
			$form_container->output_row($lang->display_global.' <em>*</em>', $lang->display_global_desc, $form->generate_yes_no_radio('global', $mybb->input['global'], true));
			$form_container->output_row($lang->enabled.' <em>*</em>', $lang->enabled_desc, $form->generate_yes_no_radio('enabled', $mybb->input['enabled'], true));
			$form_container->end();

			$buttons[] = $form->generate_submit_button($lang->save_message);

			$form->output_submit_wrapper($buttons);

			$form->end();

			$page->output_footer();
		}

		if($mybb->input['action'] == 'edit')
		{
			$query = $db->simple_select('board_messages', '*', "mid='".intval($mybb->input['mid'])."'");
			$message = $db->fetch_array($query);

			if(!$message['mid'])
			{
				flash_message($lang->error_invalid_message, 'error');
				admin_redirect('index.php?module=config/board_messages');
			}

			if($mybb->request_method == 'post')
			{
				if(!trim($mybb->input['message']))
				{
					$errors[] = $lang->error_no_message;
				}

				if(!$errors)
				{
					$message = array(
						'message' => $db->escape_string($mybb->input['message']),
						'class'   => $db->escape_string($mybb->input['class']),
						'global'  => intval($mybb->input['global']),
						'enabled' => intval($mybb->input['enabled'])
					);

					$db->update_query('board_messages', $message, "mid='".intval($mybb->input['mid'])."'");

					log_admin_action(intval($mybb->input['mid']));

					flash_message($lang->success_message_saved, 'success');
					admin_redirect('index.php?module=config/board_messages');
				}
			}

			$page->add_breadcrumb_item($lang->edit_message);
			$page->output_header($lang->board_messages.' - '.$lang->edit_message);

			$sub_tabs['edit_message'] = array(
				'title'       => $lang->edit_message,
				'link'        => 'index.php?module=config/board_messages',
				'description' => $lang->edit_message_desc
			);

			$page->output_nav_tabs($sub_tabs, 'edit_message');

			if($errors)
			{
				$page->output_inline_error($errors);
			}
			else
			{
				$mybb->input = $message;
			}

			$form = new Form('index.php?module=config/board_messages&amp;action=edit', 'post', 'edit');
			echo $form->generate_hidden_field('mid', $message['mid']);

			$form_container = new FormContainer($lang->edit_message);
			$form_container->output_row($lang->message.' <em>*</em>', $lang->message_desc, $form->generate_text_area('message', $mybb->input['message']));
			$form_container->output_row($lang->class, $lang->class_desc, $form->generate_text_box('class', $mybb->input['class']));
			$form_container->output_row($lang->display_global.' <em>*</em>', $lang->display_global_desc, $form->generate_yes_no_radio('global', $mybb->input['global'], true));
			$form_container->output_row($lang->enabled.' <em>*</em>', $lang->enabled_desc, $form->generate_yes_no_radio('enabled', $mybb->input['enabled'], true));
			$form_container->end();

			$buttons[] = $form->generate_submit_button($lang->save_message);
			$buttons[] = $form->generate_reset_button($lang->reset);

			$form->output_submit_wrapper($buttons);

			$form->end();

			$page->output_footer();
		}

		if($mybb->input['action'] == 'delete')
		{
			$query = $db->simple_select('board_messages', '*', "mid='".intval($mybb->input['mid'])."'");
			$message = $db->fetch_array($query);

			if(!$message['mid'])
			{
				flash_message($lang->error_invalid_message, 'error');
				admin_redirect('index.php?module=config/board_messages');
			}

			if($mybb->input['no'])
			{
				admin_redirect('index.php?module=config/board_messages');
			}

			if($mybb->request_method == 'post')
			{
				$db->delete_query('board_messages', "mid='{$message['mid']}'");

				log_admin_action($message['mid']);

				flash_message($lang->success_message_deleted, 'success');
				admin_redirect('index.php?module=config/board_messages');
			}
			else
			{
				$page->output_confirm_action("index.php?module=config/board_messages&amp;action=delete&amp;mid={$message['mid']}", $lang->confirm_message_deletion);
			}
		}

		if(!$mybb->input['action'])
		{
			$page->output_header($lang->board_messages);

			$sub_tabs['manage_messages'] = array(
				'title'       => $lang->board_messages,
				'link'        => 'index.php?module=config/board_messages',
				'description' => $lang->manage_messages_desc
			);

			$sub_tabs['add_message'] = array(
				'title' => $lang->add_message,
				'link'  => 'index.php?module=config/board_messages&amp;action=add'
			);

			$page->output_nav_tabs($sub_tabs, 'manage_messages');

			$table = new Table;
			$table->construct_header($lang->message, array('colspan' => 2));
			$table->construct_header($lang->location, array('class' => "align_center"));
			$table->construct_header($lang->controls, array('class' => "align_center", 'colspan' => 2));

			$query = $db->simple_select('board_messages', '*');
			while($message = $db->fetch_array($query))
			{
				if($message['enabled'] == 1)
				{
					$icon = "<img src=\"styles/{$page->style}/images/icons/bullet_on.gif\" alt=\"(Enabled)\" title=\"Enabled\"  style=\"vertical-align: middle;\" />";
				}
				else
				{
					$icon = "<img src=\"styles/{$page->style}/images/icons/bullet_off.gif\" alt=\"(Disabled)\" title=\"Disabled\"  style=\"vertical-align: middle;\" />";
				}

				if($message['global'] != 1)
				{
					$location = $lang->index_only;
				}
				else
				{
					$location = $lang->global;
				}

				$table->construct_cell($icon, array('width' => 1));
				$table->construct_cell($message['message'], array('width' => '65%'));
				$table->construct_cell($location, array('class' => "align_center"));
				$table->construct_cell("<a href=\"index.php?module=config/board_messages&amp;action=edit&amp;mid={$message['mid']}\">{$lang->edit}</a>", array("class" => "align_center"));
				$table->construct_cell("<a href=\"index.php?module=config/board_messages&amp;action=delete&amp;mid={$message['mid']}&amp;my_post_key={$mybb->post_code}\" onclick=\"return AdminCP.deleteConfirmation(this, '{$lang->confirm_message_deletion}')\">{$lang->delete}</a>", array("class" => "align_center"));
				$table->construct_row();
			}

			if($table->num_rows() == 0)
			{
				$table->construct_cell($lang->no_board_messages, array('colspan' => 5));
				$table->construct_row();
			}

			$table->output($lang->board_messages);

			$page->output_footer();
		}

		exit;
	}
}

function board_messages()
{
	global $db, $templates, $board_messages, $current_page;

	$board_messages = '';
	$query = $db->simple_select('board_messages', '*', "enabled='1'");
	while($message = $db->fetch_array($query))
	{
		if($message['global'] != 0 || $current_page == 'index.php')
		{
			if(!$message['class'])
			{
				$message['class'] = 'board_message';
			}

			$board_messages .= '<div class="'.$message['class'].'">'.$message['message'].'</div>';
		}
	}
}
?>
Correct, just put an Ampersand (&) before the $var_name in each of those function calls and you should be good to go.
Pages: 1 2