I'm New to This - What's Wrong?
#1
So i wanted to make a plugin for mybb but i failed badly
I tried this but it wasn't working, anyone know why? and how to fix it? Big Grin

<?php
/*********************************************************************************************
License:
1. No redistribution
2. No claiming as your own
You can however:
3. Modify for personal use without breaking rule 2
Thanks for using UserCP Ref Tools.
**********************************************************************************************
*/
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("usercp", "ref_tools");

function usercp_ref_tools_info()
{
    return array(
        "name"            => "UserCP Ref Tools",
        "description"    => "This plugin adds ref tools to the UserCP page.",
        "website"        => "http://everythingcentral.org",
        "author"        => "ebildude123",
        "authorsite"    => "http://everythingcentral.org",
        "version"        => "1.0",
        "guid"             => "NULL",
        "compatibility" => "16*"
    );
}


function ref_tools($page)
{
    $page = str_replace("<!-- end: usercp_referrals -->\n</td>\n</tr>\n</table>", "<!-- end: usercp_referrals -->\n</td>\n</tr>\n</table>\n<br />\n<table border=\"0\" cellspacing=\"{$theme['borderwidth']}\" cellpadding=\"{$theme['tablespace']}\" class=\"tborder\">\n<tr>\n<td class=\"thead\" colspan=\"{$colspan}\"><strong>Referral Tools</strong></td>\n</tr>\n<tr>\n<td class=\"trow2\">\n<img src=\"/images/refbanners/1.png\">\n<br />\nBBCode:\n<br />\n<div id=\"pid_0\" class=\"post_body\">\n<div class=\"body\" dir=\"ltr\">\n<code>\n[url={$mybb->settings['bburl']}/member.php?action=register&referrer={$mybb->user['uid']}][img]
{$mybb->settings['bburl']}/images/refbanners/1.png[/img][/url]\n</code>\n</div>\n</div>\n<br />\nHTML:\n<br />\n<div id=\"pid_0\" class=\"post_body\">\n<div class=\"body\" dir=\"ltr\">\n<code>\n&lt;a href=&quot;{$mybb->settings['bburl']}/member.php?action=register&amp;referrer={$mybb->user['uid']}&quot;&gt;&lt;img 
src=&quot;{$mybb->settings['bburl']}/images/refbanners/1.png&quot;&gt;&lt;/a&gt;\n</code>\n</div>\n</div>\n</td>\n</tr>\n</table>", $page);
    return $page;
}
?>
Reply
#2
add & for the function's variable , i.e. function ref_tools(&$page) and try it ..
Reply
#3
There is no usercp hook. Try something like this:

$plugins->add_hook("usercp_end", "ref_usercp_end");

function ref_usercp_end()
{
	$plugins->add_hook("pre_output_page", "ref_tools");
}

function ref_tools($page)
{
    $page = str_replace("<!-- end: usercp_referrals -->\n</td>\n</tr>\n</table>", "<!-- end: usercp_referrals -->\n</td>\n</tr>\n</table>\n<br />\n<table border=\"0\" cellspacing=\"{$theme['borderwidth']}\" cellpadding=\"{$theme['tablespace']}\" class=\"tborder\">\n<tr>\n<td class=\"thead\" colspan=\"{$colspan}\"><strong>Referral Tools</strong></td>\n</tr>\n<tr>\n<td class=\"trow2\">\n<img src=\"/images/refbanners/1.png\">\n<br />\nBBCode:\n<br />\n<div id=\"pid_0\" class=\"post_body\">\n<div class=\"body\" dir=\"ltr\">\n<code>\n[url={$mybb->settings['bburl']}/member.php?action=register&referrer={$mybb->user['uid']}][img]
{$mybb->settings['bburl']}/images/refbanners/1.png[/img][/url]\n</code>\n</div>\n</div>\n<br />\nHTML:\n<br />\n<div id=\"pid_0\" class=\"post_body\">\n<div class=\"body\" dir=\"ltr\">\n<code>\n&lt;a href=&quot;{$mybb->settings['bburl']}/member.php?action=register&amp;referrer={$mybb->user['uid']}&quot;&gt;&lt;img 
src=&quot;{$mybb->settings['bburl']}/images/refbanners/1.png&quot;&gt;&lt;/a&gt;\n</code>\n</div>\n</div>\n</td>\n</tr>\n</table>", $page);
    return $page;
}
Reply
#4
You'll also need to bring $plugins into the global scope when using it inside ref_usercp_end().

function ref_usercp_end()
{
	global $plugins;

    $plugins->add_hook("pre_output_page", "ref_tools");
}

Same goes for the $theme, $colspan and $mybb variables inside ref_tools($page).
Reply
#5
Thanks to both of you and myself I got it working Big Grin
I found some of my own errors and fixed them too Smile
+rep to both
Reply
#6
(2012-02-04, 07:50 PM)Beardy Wrote: You'll also need to bring $plugins into the global scope when using it inside ref_usercp_end().

function ref_usercp_end()
{
	global $plugins;

    $plugins->add_hook("pre_output_page", "ref_tools");
}

Same goes for the $theme, $colspan and $mybb variables inside ref_tools($page).

Thanks for correcting that, I rushed when I wrote it.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)