MyBB Community Forums

Full Version: Error
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
Okay, look i kinda need help.
i'll give the code only to 1-2 people but you know it's made by me, you may not use it, rebrand it.. you may only use it when released Smile. because i don't want to reveal my php code to anyone, else people might come & copy me Sad ..
so.. is anyone interested in trying?
I think it's easy to solve it, but idk what it is.
Maybe you can just know it by looking at the image?
[attachment=12041]
anyway.. i think it might be my hook..
well.. just tell me about it.
Thank you,
- Shadows.
From the error I'm guessing you're performing some template replacements somewhere. If so, make sure the code you're entering in is valid PCRE. If you don't need regular expressions (most of the time), surround your find text with preg_quote(), eg:
find_replace_templatesets('#'.preg_quote('stuff to find','#').'#', 'stuff to replace with', 'template name');
I see..
Thanks for the hint i had something totally different i think Smile.
I had
	require MYBB_ROOT."/inc/adminfunctions_templates.php";
	find_replace_templatesets("template", "stuff to find", "stuff to replace with");
Thank you!
I hope this will work Big Grin.
- Shadows.

lol okay, i guess i'll be obliged to show my work, but anyway it'll be free, don't try to copy anyway as it doesn't work atm xD..
global $db, $mybb;
	require MYBB_ROOT.'/inc/adminfunctions_templates.php';
//old	
find_replace_templatesets("usercp", "{\$latest_warnings}", "{\$latest_warnings}<!-- begin FastRefer By TalkForStuff.COM - Shadows --><br /><table border='0' cellspacing='1' cellpadding='5' class='tborder'><td class='thead' colspan='2'><strong>Referral Information</strong></td><tr><td width='50%' class='trow1'><strong>Referral URL:</strong></td><td width='50%' class='trow2'><a href='{\$mybb->settings[\'bburl\']}/index.php?referrer={\$mybb->user[\'uid\']}'>{\$mybb->settings[\'bburl\']}/index.php?referrer={\$mybb->user[\'uid\']}</a></td></tr></table><!-- end -->");
//NEW1 
find_replace_templatesets('#'.preg_quote("{\$latest_warnings}",'#').'#', "{\$latest_warnings}<!-- begin FastRefer By TalkForStuff.COM - Shadows --><br /><table border='0' cellspacing='1' cellpadding='5' class='tborder'><td class='thead' colspan='2'><strong>Referral Information</strong></td><tr><td width='50%' class='trow1'><strong>Referral URL:</strong></td><td width='50%' class='trow2'><a href='{\$mybb->settings[\'bburl\']}/index.php?referrer={\$mybb->user[\'uid\']}'>{\$mybb->settings[\'bburl\']}/index.php?referrer={\$mybb->user[\'uid\']}</a></td></tr></table><!-- end -->", 'usercp'); 
//NEW2
find_replace_templatesets("usercp", '#'.preg_quote("{\$latest_warnings}").'#', "{\$latest_warnings}<!-- begin FastRefer By TalkForStuff.COM - Shadows --><br /><table border='0' cellspacing='1' cellpadding='5' class='tborder'><td class='thead' colspan='2'><strong>Referral Information</strong></td><tr><td width='50%' class='trow1'><strong>Referral URL:</strong></td><td width='50%' class='trow2'><a href='{\$mybb->settings[\'bburl\']}/index.php?referrer={\$mybb->user[\'uid\']}'>{\$mybb->settings[\'bburl\']}/index.php?referrer={\$mybb->user[\'uid\']}</a></td></tr></table><!-- end -->");
i tried all those, but didn't work..
i get
The following warnings occurred: 
Warning [2] call_user_func_array() [function.call-user-func-array]: First argument is expected to be a valid callback, 'fastrefer' was given - Line: 101 - File: C:\xampp\htdocs\mybb\inc\class_plugins.php PHP 5.2.6 (WINNT)File	Line	Function
[PHP]	 	errorHandler->error
C:\xampp\htdocs\mybb\inc\class_plugins.php	101	call_user_func_array
C:\xampp\htdocs\mybb\usercp.php	44	pluginSystem->run_hooks
+ the template isn't modified..
==> is it right that i put {\var} and not {var} ? else it confuses php i think isn't it? mwell..
(2008-12-19, 12:22 PM)shadows123 Wrote: [ -> ]==> is it right that i put {\var} and not {var} ? else it confuses php i think isn't it? mwell..
I'd stick to single quotes - there isn't so much to escape.
find_replace_templatesets("usercp", '#'.preg_quote('{$latest_warnings}').'#', '{$latest_warnings}<!-- begin FastRefer By TalkForStuff.COM - Shadows --><br /><table border="0" cellspacing="1" cellpadding="5" class="tborder"><td class="thead" colspan="2"><strong>Referral Information</strong></td><tr><td width="50%" class="trow1"><strong>Referral URL:</strong></td><td width="50%" class="trow2"><a href="{$mybb->settings[\'bburl\']}/index.php?referrer={$mybb->user[\'uid\']}">{$mybb->settings[\'bburl\']}/index.php?referrer={$mybb->user[\'uid\']}</a></td></tr></table><!-- end -->');
^ See if that works better (hope I didn't make a typo somewhere).

As for the error, make sure your hooks are pointing to valid functions, ie, if you have:
$plugins->add_hook('somehook', 'myfunction');
You need to have the function myfunction defined somewhere.
Yeah, i used usercp_start
i tried with what you gave, but it still doesn't work.. hmm :/
well here's the full code, maybe i missed something?
<?php

$plugins->add_hook("usercp_start", "fastrefer");
// 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.");
}
function fastrefer_info()
{
	return array(
		"name"        => "Fast Refer",
		"description" => "Display referral information in the UserCP",
		"website"     => "http://talkforstuff.com",
		"author"      => "TalkForStuff - Shadows.",
		"authorsite"  => "http://talkforstuff.com",
		"version"     => "0.5 Pre-Alpha",
		"guid"        => "",
        "compatibility" => "14*"
		);
}


function fastrefer_activate()
{
// BEGIN INSTALL TEMPLATE REPLACEMENTS
global $db, $mybb;
 // add referral information into templates
	require MYBB_ROOT.'/inc/adminfunctions_templates.php';
//old	find_replace_templatesets("usercp", "{\$latest_warnings}", "{\$latest_warnings}<!-- begin FastRefer By TalkForStuff.COM - Shadows --><br /><table border='0' cellspacing='1' cellpadding='5' class='tborder'><td class='thead' colspan='2'><strong>Referral Information</strong></td><tr><td width='50%' class='trow1'><strong>Referral URL:</strong></td><td width='50%' class='trow2'><a href='{\$mybb->settings[\'bburl\']}/index.php?referrer={\$mybb->user[\'uid\']}'>{\$mybb->settings[\'bburl\']}/index.php?referrer={\$mybb->user[\'uid\']}</a></td></tr></table><!-- end -->");
//NEW1 
//find_replace_templatesets('#'.preg_quote("{\$latest_warnings}",'#').'#', "{\$latest_warnings}<!-- begin FastRefer By TalkForStuff.COM - Shadows --><br /><table border='0' cellspacing='1' cellpadding='5' class='tborder'><td class='thead' colspan='2'><strong>Referral Information</strong></td><tr><td width='50%' class='trow1'><strong>Referral URL:</strong></td><td width='50%' class='trow2'><a href='{\$mybb->settings[\'bburl\']}/index.php?referrer={\$mybb->user[\'uid\']}'>{\$mybb->settings[\'bburl\']}/index.php?referrer={\$mybb->user[\'uid\']}</a></td></tr></table><!-- end -->", 'usercp'); 
//NEW2
find_replace_templatesets("usercp", '#'.preg_quote('{$latest_warnings}').'#', '{$latest_warnings}<!-- begin FastRefer By TalkForStuff.COM - Shadows --><br /><table border="0" cellspacing="1" cellpadding="5" class="tborder"><td class="thead" colspan="2"><strong>Referral Information</strong></td><tr><td width="50%" class="trow1"><strong>Referral URL:</strong></td><td width="50%" class="trow2"><a href="{$mybb->settings[\'bburl\']}/index.php?referrer={$mybb->user[\'uid\']}">{$mybb->settings[\'bburl\']}/index.php?referrer={$mybb->user[\'uid\']}</a></td></tr></table><!-- end -->'); 
}

function fastrefer_deactivate()
{
	//ignore this, this will not work yet, i'm first trying to get the activate to work.. Thanks ^^.
//Remove template replacements	
//include global the $db
global $db, $mybb;
//edit templates
//remove referral info from templates
	require MYBB_ROOT."/inc/adminfunctions_templates.php";
	find_replace_templatesets("usercp", '{\$latest_warnings}<!-- begin FastRefer By TalkForStuff.COM - Shadows --><br /><table border="0" cellspacing="1" cellpadding="5" class="tborder"><td class="thead" colspan="2"><strong>Referral Information</strong></td><tr><td width="50%" class="trow1"><strong>Referral URL:</strong></td><td width="50%" class="trow2"><a
href="{\$mybb->settings[\'bburl\']}/index.php?referrer={\$mybb->user[\'uid\']}">{\$mybb->settings[\'bburl\']}/index.php?referrer={\$mybb->user[\'uid\']}</a></td></tr></table><!-- end -->', '{\$latest_warnings}');
}


okay maybe there are a few weird things in the code, but that's because i tried a lot of things to see if it would work Wink.
Thank you for trying to help Smile.
- Shadows.
For this line:
$plugins->add_hook("usercp_start", "fastrefer");
It doesn't actually mean anything. The idea of hooks is to allow code injection. Looking at your plugin, you don't require any custom PHP execution at the hook, so you should be able to delete this line, and the plugin should work.

As for templates not replacing, you've probably tried activating/deactivating the plugin numerous times, which may have messed up the template. Try reverting it to default and try activating the template again.

BTW, remove the \'s before the $'s in your _deactivate function.
Oh ok, that may be possible ^^.
Yeah, i was a bit hesitating about those hooks ^^.
Ok thanks for the info Yumi.
I hope it'll work now Big Grin.
- Shadows.
Thanks yumi!
It works now..
But lol why doesn't the deactivate code work =__=
it says it's successfully done.
but it doesn't revert to the template it originally was without the plugin..
this is what i've currently got,
function fastrefer_activate()
{
// BEGIN INSTALL TEMPLATE REPLACEMENTS
global $db, $mybb;
 // add referral information into templates
	require MYBB_ROOT.'/inc/adminfunctions_templates.php';
find_replace_templatesets("usercp", '#'.preg_quote('{$latest_warnings}').'#', '{$latest_warnings}<!-- begin FastRefer By TalkForStuff.COM - Shadows --><br /><table border="0" cellspacing="1" cellpadding="5" class="tborder"><td class="thead" colspan="2"><strong>Referral Information</strong></td><tr><td width="50%" class="trow1"><strong>Referral URL:</strong></td><td width="50%" class="trow2"><a href="{$mybb->settings[\'bburl\']}/index.php?referrer={$mybb->user[\'uid\']}">{$mybb->settings[\'bburl\']}/index.php?referrer={$mybb->user[\'uid\']}</a></td></tr></table><!-- end -->'); 
}

function fastrefer_deactivate()
{
//Remove template replacements	
//include global the $db
global $db, $mybb;
//edit templates
//remove referral info from templates
	require MYBB_ROOT."/inc/adminfunctions_templates.php";
find_replace_templatesets("usercp", '#'.preg_quote('{$latest_warnings}<!-- begin FastRefer By TalkForStuff.COM - Shadows --><br /><table border="0" cellspacing="1" cellpadding="5" class="tborder"><td class="thead" colspan="2"><strong>Referral Information</strong></td><tr><td width="50%" class="trow1"><strong>Referral URL:</strong></td><td width="50%" class="trow2"><a href="{$mybb->settings[\'bburl\']}/index.php?referrer={$mybb->user[\'uid\']}">{$mybb->settings[\'bburl\']}/index.php?referrer={$mybb->user[\'uid\']}</a></td></tr></table><!-- end -->').'#', '{$latest_warnings}'); 
}
Thanks for helping Smile.
On the line with the call to find_replace_templatesets, try adding ",0" (without quotes) before the ");" at the end of the line.
I tried that.. still didn't work Sad..
Thanks Smile.
- Shadows.
Make sure you deactivate the plugin, revert templates and try again. Hope that helps.
Pages: 1 2