Template / hook help?
#1
Hello!

I am all a bit new to plugin development.

I am trying to modify the avatar template to add a secondary image next to it.
But i cannot seem to find the right hook or something along those lines.

this is what i'm trying to do:
$plugins->add_hook("usercp_avatar_start", "plugin_avatarUpdate");
function plugin_avatarUpdate()
{
	global $db, $mybb, $templates, $avatarUpdate, $lang, $headerinclude, $header, $footer, $usercpnav;
	$action = $mybb->input['action'];
	$sgids = $mybb->user['groupsin'];
	if ($sgids!="")
	{
		$avatarquery = $db->query("SELECT * FROM ".TABLE_PREFIX."avatarUpdate WHERE sgid IN ($sgids) ORDER BY name ASC");
		while($avatarData = $db->fetch_array($avatarquery))
		{
			eval("\$avatarList .= \"".$templates->get("postbit_avatar")."\";");
		}
	}
}



Template: postbit_avatar
<div class="author_avatar"><a href="{$post['profilelink_plain']}"><img src="{$useravatar['image']}" alt="" {$useravatar['width_height']} /></a><a href="{$post['profilelink_plain']}"><img src="{$avatarData['logo']}"/></a></div>


I don't know how easy that is to follow, but i'd really appreciate the help, i don't quite get the eval thing haha.

plus it's getting late and i've been working for quite a while now haha.

Thank you in advance
Reply
#2
Exactly where do you want to add the image in? Want you to replace the avatar image, add a new one besides it, or a new avatar field in posts?

The code you show displays attempts to hook into different places (UserCP, post bit).
Reply
#3
I'm looking at adding an image next to the avatar image.

i was looking at the hooks page and there didn't seem to be a straight forward hook for just all places the avatar appears
Reply
#4
Indeed, there is no just one hook for all places where an avatar is displayed. For the postbit you will need to hook to postbit (only for threads, for example.
Reply
#5
You need to hook to postbit and then in the function you have to mention $post and use $post['whatever'] in the template!

// PostBit hook
$plugins->add_hook("postbit", "hello_world");

// _postbit
function hello_world(&$post)
{
    global $templates;



eval("\$post['whatever'] = \"".$templates->get("your_template")."\";")
       
    }
Reply
#6
(2015-06-15, 11:52 AM)marcus123 Wrote: You need to hook to postbit and then in the function you have to mention $post and use $post['whatever'] in the template!

// PostBit hook
$plugins->add_hook("postbit", "hello_world");

// _postbit
function hello_world(&$post)
{
    global $templates;



eval("\$post['whatever'] = \"".$templates->get("your_template")."\";")
       
    }

Thank you marcus Smile

This seems to be getting closer! i mean when i do a print_r($post['logo']); exit(); after the eval there seems to be the logo in there, but on the template where i'm trying to use it {$post['logo']} returns nothing.

Is there something i am missing?
function plugin_avatar(&$post)
{

    eval("\$post['logo'] = \"".$templates->get("postbit_avatar")."\";"); 
    $post['logo'] = $avatar['logo'];
}
Wait i think i am mistaken to how i should be using this all T_T
damn i'm new to this haha.  Blush


Right i was mistaken to what i was trying to do!
eval("\$post['logo'] = \"".$templates->get("postbit_avatar")."\";"); <---- this would make $post['logo'] equal the template.

but what i want to do is make it so the template can use {$post['logo']} as an image source.
but $post['logo'] = $avatar['logo']; does not seem to output anything before the template is made.
But when the function is called $post['logo'] is equal to something.

So what i need to work is $post['logo'] to be equal to something as the template is being called.

Aha! i have fixed the issue :Smile (finally)


$post['logo'] = $avatar['logo'];
eval("\$post['useravatar'] = \"".$templates->get("postbit_avatar")."\";");
The issue was i needed to re-call the useravatar template, so that it could use the $post['logo'] after it was set!

I think explaining it out on the forum helped to solve my issue aha.
Thanks guys.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)