MyBB Community Forums

Full Version: Help with using a Hook
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I am using Lennart's Gallery addon, but have made some modifications to it and added an additional plugin file, but am having trouble finding a Hook that I can use.

There is a plugin file that works fine in the member_profile template, and I am trying to add one in the usercp_nav_profile template, but cannot find a Hook that will work.

Can anybody point me to a Hook that I can use, or tell me what I'm doing wrong?

Here is the working plugin for the profile template:
<?php

define("IN_MYBB", 1);

$plugins->add_hook("member_profile_end", "galleries");

function galleries_info() {
	return array(
		"name"			=>	"Profile Galleries",
		"description"	=>	"Shows users galleries in profile.",
		"website"		=>	"http://www.mybbaddons.com/",
		"author"		=>	"Lennart Sauter",
		"authorsite"	=>	"http://www.lennartsauter.de/",
		"version"		=>	"1.0",
		"compatibility" => "14*"
	);
}

function galleries_activate() {

}

function galleries_deactivate() {

}

function galleries() {

	global $db, $mybb, $templates, $lang, $galleries, $lastimages;

// Aufbau der Verbindung mit der MySQL Datenbank:
include("addons/mysql/connectmysql.php");

//Get gallery ID
$id = $_GET['id'];

    if (!empty($id)){
        $abfrage = "SELECT uid FROM user_galleries WHERE id = '".$id."'";
        $ergebnis = mysql_query($abfrage);
        while($row = mysql_fetch_object($ergebnis))
           {
           $galleryautor = "$row->uid";
           }
 $galleries = "<br><table border='0' cellspacing='{$theme['borderwidth']}' cellpadding='{$theme['tablespace']}' class='tborder'>
<tr>
<td colspan='2' class='thead'><strong>Create gallery:</strong></td>
</tr><tr><td colspan='2' class='trow1'>";
 $abfrage = "SELECT id, name FROM user_galleries WHERE uid = '$userof'";
 $ergebnis = mysql_query($abfrage);
 while($row = mysql_fetch_object($ergebnis))
       {
        $galleries .= "<a href='addons/galleries/gedit.php?id=$thisid'>New Gallery</a><br>";
       }
$galleries .= "</td></tr></table>";
exit;
}

else {
 
 $userof = $mybb->input['uid'];
 $galleries = "<br><table border='0' cellspacing='{$theme['borderwidth']}' cellpadding='{$theme['tablespace']}' class='tborder'>
<tr>
<td colspan='2' class='thead'><strong>View gallery:</strong></td>
</tr><tr><td colspan='2' class='trow1'>";
 $abfrage = "SELECT id, name FROM user_galleries WHERE uid = '$userof'";
 $ergebnis = mysql_query($abfrage);
 while($row = mysql_fetch_object($ergebnis))
       {
       $galleries .= "<a href='addons/galleries/index.php?id=$row->id'>$row->name</a><br>";
       }
$galleries .= "</td></tr></table>";

 }

 $lastimages = "<table border='0' cellspacing='{$theme['borderwidth']}' cellpadding='{$theme['tablespace']}' class='tborder'>
<tr>
<td colspan='1' class='thead'><span class='smalltext'><strong>Recent pictures:</strong></span></td>
</tr><tr><td colspan='1' class='trow1'>";
 $abfrage = "SELECT id, thumbnailurl FROM user_gallery_images WHERE uid = '$userof' ORDER BY 'zeit' LIMIT 3";
 $ergebnis = mysql_query($abfrage);
 while($row = mysql_fetch_object($ergebnis))
       {
       $thumb = substr($row->thumbnailurl, 2);
       $thumburl = "addons/";
       $thumburl .= "$thumb";
       $lastimages .= "<a href='addons/galleries/item.php?id=$row->id'><img src='$thumburl'></a> ";
       }
$lastimages .= "</td></tr></table>";

//Funktion wieder beenden
}

?>

And here is the plugin I am trying to make work in the user CP. I'm not much of a p[rogrammer and am not 100% sure on my coding, but if I can at least get the plugin to work, then I can play with it till I get it right:
<?php

if(!defined("IN_MYBB")) {
    die("This file cannot be accessed directly.");
}
$plugins->add_hook("usercp_profile_start", "usercpgallery");

function usercpgallery_info() {
	return array(
		"name"			=>	"Gallery Link in User CP",
		"description"	=>	"Add/Edit Gallery.",
		"website"		=>	"http://www.mybbaddons.com/",
		"author"		=>	"Lennart Sauter - Mark's modification",
		"authorsite"	=>	"http://www.lennartsauter.de/",
		"version"		=>	"1.0",
		"compatibility" => "14*"
	);
}

function usercpgallery_activate() {

}

function userrcpgallery_deactivate() {

}

function usercpgallery() {

	global $db, $mybb, $templates, $lang, $usercpgallery;

// Aufbau der Verbindung mit der MySQL Datenbank:
include("addons/mysql/connectmysql.php");

 $thisid = $mybb->input['uid'];
 $usercpgallery = "<span class='usercp_nav_item usercp_nav_gallery'>";
 $abfrage = "SELECT id, name FROM user_galleries WHERE uid = '$thisid'";
 $ergebnis = mysql_query($abfrage);
 while($row = mysql_fetch_object($ergebnis))
       
	if($mybb->user_galleries['uid'] =='<1')   
	   {
       $usercpgallery .= "<a href='addons/galleries/gedit.php?id=$row->id'>My Gallery</a>";
       }
	   
	else
	{
	$usercpgallery .= "<a href='addons/galleries/index.php?id=$row->id'>My Gallery</a>";
    }
	   
$usercpgallery .= "</span>";


//Funktion wieder beenden
}


?>