<?php
/**
* Additional Groups Images
* Copyright TECHEX - The Site
*
*/
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("member_profile_end", "agi_profile");
function agi_info()
{
return array(
'name' => 'Additional Groups Images',
'description' => 'Displays all the additional groups\' images in the user\'s post and profile.',
'website' => 'http://www.thetechex.net',
'author' => 'Zaher1988',
'authorsite' => 'http://www.thetechex.net',
'version' => '2.0',
);
}
function agi_activate()
{
require MYBB_ROOT.'/inc/adminfunctions_templates.php';
find_replace_templatesets("member_profile", '#'.preg_quote('{$groupimage}').'#', '{$groupimage} {$groupimg2}');
$fh = fopen(MYBB_ROOT.'/inc/functions_post.php', "r") or cperror("Could not open file!"); //OPEN FILE
$data = fread($fh, filesize(MYBB_ROOT.'/inc/functions_post.php')) or cperror("Could not read file!"); //MAKE TEMPORARY STRING
fclose($fh); //CLOSE FILE AGAIN
$newdata = preg_replace('#'.preg_quote('if($post[\'userusername\'])
{ // This post was made by a registered user').'#','$addi_groups = explode(\',\',$post[\'additionalgroups\']);
for($i=0;$i<count($addi_groups);$i++)
{
$query2 = $db->query("SELECT gid, title, image FROM ".TABLE_PREFIX."usergroups WHERE gid=\'".$addi_groups[$i]."\'");
$ginfo = $db->fetch_array($query2);
$title = $ginfo[\'title\'];
$image = $ginfo[\'image\'];
if(!empty($image))
{
if($image != $usergroup[\'image\'])
{
if(!strstr($images_list, $image))
{
$images_list .= "<!-- Start: sec groups image --><img src=\"{$image}\" alt=\"{$title}\"><!-- End: sec groups image --><br />";
}
}
}
}
$post[\'groupimage\'] .= "<br />".$images_list;
if($post[\'userusername\'])
{ // This post was made by a registered user',$data); //REPLACE IN STRING
$fw = fopen(MYBB_ROOT.'/inc/functions_post.php', "w") or cperror('Could not open file!'); //OPEN FILE AGAIN
$fb = fwrite($fw, $newdata) or cperror('Could not write to file'); //WRITE STRING TO FILE
fclose($fw); //CLOSE FILE AGAIN
}
function agi_deactivate()
{
require MYBB_ROOT.'/inc/adminfunctions_templates.php';
find_replace_templatesets("member_profile", '#'.preg_quote('{$groupimg2}').'#', '',0);
$fh = fopen(MYBB_ROOT.'/inc/functions_post.php', "r") or cperror("Could not open file!"); //OPEN FILE
$data = fread($fh, filesize(MYBB_ROOT.'/inc/functions_post.php')) or cperror("Could not read file!"); //MAKE TEMPORARY STRING
fclose($fh); //CLOSE FILE AGAIN
$newdata = preg_replace('#'.preg_quote('$addi_groups = explode(\',\',$post[\'additionalgroups\']);
for($i=0;$i<count($addi_groups);$i++)
{
$query2 = $db->query("SELECT gid, title, image FROM ".TABLE_PREFIX."usergroups WHERE gid=\'".$addi_groups[$i]."\'");
$ginfo = $db->fetch_array($query2);
$title = $ginfo[\'title\'];
$image = $ginfo[\'image\'];
if(!empty($image))
{
if($image != $usergroup[\'image\'])
{
if(!strstr($images_list, $image))
{
$images_list .= "<!-- Start: sec groups image --><img src=\"{$image}\" alt=\"{$title}\"><!-- End: sec groups image --><br />";
}
}
}
}
$post[\'groupimage\'] .= "<br />".$images_list;
if($post[\'userusername\'])
{ // This post was made by a registered user').'#','if($post[\'userusername\'])
{ // This post was made by a registered user',$data); //REPLACE IN STRING
$fw = fopen(MYBB_ROOT.'/inc/functions_post.php', "w") or cperror('Could not open file!'); //OPEN FILE AGAIN
$fb = fwrite($fw, $newdata) or cperror('Could not write to file'); //WRITE STRING TO FILE
fclose($fw); //CLOSE FILE AGAIN
}
function agi_profile()
{
global $db, $mybb, $groupimg2, $displaygroup;
$uid = intval($mybb->input['uid']);
$query = $db->query("select uid, usergroup, additionalgroups FROM ".TABLE_PREFIX."users where uid='$uid'");
$info = $db->fetch_array($query);
$addi_groups = explode(',',$info['additionalgroups']);
for($i=0;$i<count($addi_groups);$i++)
{
$query2 = $db->query("SELECT gid, title, image FROM ".TABLE_PREFIX."usergroups WHERE gid='".$addi_groups[$i]."'");
$ginfo = $db->fetch_array($query2);
$title = $ginfo['title'];
$image = $ginfo['image'];
if(!empty($image))
{
if($image != $displaygroup['image'])
{
if(!strstr($images_list, $image))
{
$images_list .= "<!-- Start: sec groups image --><img src=\"{$image}\" alt=\"{$title}\"><br /><!-- End: sec groups image -->";
}
}
}
}
$images_list .= "<br />";
$groupimg2 = $images_list;
}
?>