<?php
/**
* Author: Hamid Nozari
* Comaptible with: MyBB 1.4.*
* Website: http://www.shceg.com
* License: GNU/GPL
* User Profile Premission v1.0.1 - 2010/02/13
* Use at your own risk
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
// 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.");
}
$plugins->add_hook("datahandler_user_update", "upp_update");
$plugins->add_hook("member_profile_start","upp_member_profile");
$plugins->add_hook('usercp_profile_start', 'upp_template_update');
function upp_info()
{
return array(
"name" => "User Profile Premission",
"description" => "This plugin allows each user to specify what users have access to his profile and see it",
"website" => "http://www.shceg.com",
"author" => "Hamid Nozari",
"authorsite" => "http://www.shceg.com",
"version" => "1.0.1",
"guid" => "ccd76b688c5556826b1c97d396fee518",
"compatibility" => "14*"
);
}
function upp_install()
{
global $db;
//Delete old template if exist
$db->delete_query("templates", "title='upp_usercp'");
//Insert template
$upp_usercp = array(
"title" => "upp_usercp",
"template" => "<br />
<fieldset class=\"trow2\">
<legend><strong>{\$lang->uppusercp_title}</strong></legend>
<table cellspacing=\"0\" cellpadding=\"{\$theme[tablespace]}\" width=\"100%\">
<tr>
<td>
<select name=\"upp\">
<option value=\"0\" {\$selected1}>{\$lang->upp_nobody}</option>
<option value=\"1\" {\$selected2}>{\$lang->upp_friends}</option>
<option value=\"2\" {\$selected3}>{\$lang->upp_everyone}</option>
</select>
</td>
</tr>
</table>
</fieldset>
",
"sid" => '-1',
"version" => '',
"dateline" => TIME_NOW
);
$db->insert_query("templates", $upp_usercp);
//Insert upp field to users table
if(!$db->field_exists('upp', 'users'))
{
$db->query("ALTER TABLE ".TABLE_PREFIX."users ADD `upp` tinyint(1) NOT NULL default '2'");
}
}
function upp_is_installed()
{
global $db;
if($db->field_exists('upp', 'users'))
{
return true;
}
return false;
}
function upp_activate()
{
global $db;
include MYBB_ROOT.'/inc/adminfunctions_templates.php';
find_replace_templatesets("usercp_profile", "#".preg_quote('{$customfields}')."#i", '{$upp}{$customfields}');
}
function upp_deactivate()
{
global $db;
include MYBB_ROOT."/inc/adminfunctions_templates.php";
find_replace_templatesets("usercp_profile", "#".preg_quote('{$upp}')."#i", '', 0);
}
function upp_uninstall()
{
global $db;
//Delete template
$db->delete_query("templates", "title='upp_usercp'");
//Drop upp field from users tabel
if($db->field_exists('upp', 'users'))
{
$db->query("ALTER TABLE ".TABLE_PREFIX."users DROP `upp`");
}
}
function upp_update()
{
global $mybb, $db;
$upp = intval($mybb->input['upp']);
if ($upp > 2)
$upp = 0;
//Update upp field in users table
$db->query("UPDATE ".TABLE_PREFIX."users SET upp = " . $upp . " WHERE uid = " . $mybb->user['uid']);
}
function upp_member_profile()
{
global $db, $mybb, $uid, $lang, $theme, $memprofile;
upp_lang();
// Set $uid var
if($mybb->input['uid'])
{
$uid = intval($mybb->input['uid']);
}
else
{
$uid = $mybb->user['uid'];
}
// Set logged user uid
$this_user = $mybb->user['uid'];
//Check user premission to see desired profile
if ($uid != $this_user)
if (!CanViewUserProfile($uid, $this_user))
{
$ret=$db->simple_select('users','username, usergroup, displaygroup, upp','uid = '.$uid);
$upp = $db->fetch_array($ret);
$username = format_name($upp['username'], $upp['usergroup'], $upp['displaygroup']);
if ($upp['upp'] == 1)
error($lang->sprintf($lang->upp_error_friend, $username));
else
error($lang->sprintf($lang->upp_error, $username));
}
}
function upp_template_update()
{
global $mybb, $templates, $theme, $upp, $lang, $selected1, $selected2, $selected3;
upp_lang();
//Set user upp state
$selected1 = $selected2 = $selected3 = "";
if ($mybb->user['upp']==0)
$selected1 = "selected";
else
if ($mybb->user['upp']==1)
$selected2 = "selected";
else
if ($mybb->user['upp']==2)
$selected3 = "selected";
eval("\$upp= \"".$templates->get("upp_usercp")."\";");
}
//Functions//
function upp_lang()
{
global $lang;
$lang->load('upp',false,true);
$l['uppusercp_title']='Who can view my profile:';
$l['upp_nobody']='Nobody';
$l['upp_friends']='My friend\'s only';
$l['upp_everyone']='Everyone';
$l['upp_error'] = 'You don\'t have premission to see {1} profile';
$l['upp_error_friend'] = 'Only {1} friend\'s can see his profile';
foreach($l as $key=>$val)
{
if(!$lang->$key)
{
$lang->$key=$val;
}
}
}
function CanViewUserProfile($uid, $this_user)
{
global $db, $mybb;
$gid = $mybb->user['usergroup'];
if ($gid == 4 || $gid == 3 || $gid == 6)
return true;
$ret = $db->simple_select('users','upp, buddylist, ignorelist','uid = '.$uid);
$upp = $db->fetch_array($ret);
$buddylist = $upp['buddylist'];
$ignorelist = $upp['ignorelist'];
$upp = $upp['upp'];
if ($upp == 0)
{
return false;
}
else
if ($upp == 1)
{
$buddyuidarray = explode(",",$buddylist);
if (in_array($this_user, $buddyuidarray, true))
return true;
else
return false;
}
else
{
$buddyuidarray = explode(",",$ignorelist);
if (in_array($this_user, $buddyuidarray, true))
return false;
}
return true;
}
?>