funchat/forumplugins/rp.php

268 lines
8.2 KiB
PHP

<?php
// 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("postbit", "rp_postbit");
$plugins->add_hook("newreply_start", "rp_newreply");
$plugins->add_hook("newreply_do_newreply_end", "rp_insert_post");
$plugins->add_hook("editpost_start", "rp_edit");
$plugins->add_hook("editpost_do_editpost_end", "rp_edit_post");
$plugins->add_hook("newthread_start", "rp_new");
$plugins->add_hook("newthread_do_newthread_end", "rp_new_post");
$plugins->add_hook("showthread_start", "rp_showthread");
function rp_info()
{
/**
* Array of information about the plugin.
* name: The name of the plugin
* description: Description of what the plugin does
* website: The website the plugin is maintained at (Optional)
* author: The name of the author of the plugin
* authorsite: The URL to the website of the author (Optional)
* version: The version number of the plugin
* guid: Unique ID issued by the MyBB Mods site for version checking
* compatibility: A CSV list of MyBB versions supported. Ex, "121,123", "12*". Wildcards supported.
*/
return array(
"name" => "Roleplay",
"description" => "A Plugin that let's you choose a RP Char.",
"website" => "http://archer.agency",
"author" => "Genuineparts",
"authorsite" => "http://archer.agency",
"version" => "1.0",
"guid" => "",
"compatibility" => "*",
'codename'=>'rp'
);
}
function rp_install()
{
global $db;
$db->write_query("CREATE TABLE ".TABLE_PREFIX."rp_posts (`pid` INT NOT NULL ,`cid` INT NOT NULL ,PRIMARY KEY ( `pid` ) ,INDEX ( `cid` ))");
}
function rp_uninstall()
{
global $db;
$db->write_query("DROP TABLE ".TABLE_PREFIX."rp_posts");
}
function rp_is_installed()
{
global $db;
if($db->table_exists("rp_posts"))
{
return true;
}
return false;
}
function rp_activate()
{
global $db;
$info=rp_info();
$setting_group_array=array
(
'name'=>$info['codename'],
'title'=>$info['name'],
'description'=>'Here you can edit '.$info['name'].' settings.',
'disporder'=>1,
'isdefault'=>0
);
$db->insert_query('settinggroups',$setting_group_array);
$group=$db->insert_id();
$settings=array
(
'rp_forums'=>array
(
'Forums',
'The forums where RP is played.',
'text',
''
)
);
$i=1;
foreach($settings as $name=>$sinfo)
{
$insert_array=array
(
'name'=>$name,
'title'=>$db->escape_string($sinfo[0]),
'description'=>$db->escape_string($sinfo[1]),
'optionscode'=>$db->escape_string($sinfo[2]),
'value'=>$db->escape_string($sinfo[3]),
'gid'=>$group,
'disporder'=>$i,
'isdefault'=>0
);
$db->insert_query('settings',$insert_array);
$i++;
}
rebuild_settings();
}
function rp_deactivate()
{
global $db;
$info=rp_info();
$result=$db->simple_select('settinggroups','gid','name="'.$info['codename'].'"',array('limit'=>1));
$group=$db->fetch_array($result);
if(!empty($group['gid']))
{
$db->delete_query('settinggroups','gid="'.$group['gid'].'"');
$db->delete_query('settings','gid="'.$group['gid'].'"');
rebuild_settings();
}
}
function rp_newreply()
{
global $mybb,$db,$templates, $rp_menu;
$forums=explode(',',$mybb->settings['rp_forums']);
array_walk($forums, 'trim_value');
//var_dump($mybb);
$query = $db->simple_select("threads", "fid", "tid = '{$mybb->input['tid']}'");
$data = $db->fetch_array($query);
$chars='';
if(in_array($data['fid'],$forums)){
$sql ="SELECT c.name,c.id FROM `aa_users` p LEFT JOIN `aa_rp_chars` c ON (p.uid=c.uid) WHERE p.fuid = '".$mybb->user['uid']."'";
$query = $db->query($sql);
while($chid = $db->fetch_array($query)){
$chars.='<option value="'.$chid['id'].'">'.$chid['name'].'</option>';
}
eval("\$rp_menu = \"".$templates->get("charselect")."\";");
}
}
function rp_new()
{
global $mybb,$db,$templates, $rp_menu;
$forums=explode(',',$mybb->settings['rp_forums']);
array_walk($forums, 'trim_value');
//var_dump($mybb);
$chars='';
if(in_array($mybb->input['fid'],$forums)){
$sql ="SELECT c.name,c.id FROM `aa_users` p LEFT JOIN `aa_rp_chars` c ON (p.uid=c.uid) WHERE p.fuid = '".$mybb->user['uid']."'";
$query = $db->query($sql);
while($chid = $db->fetch_array($query)){
$chars.='<option value="'.$chid['id'].'">'.$chid['name'].'</option>';
}
eval("\$rp_menu = \"".$templates->get("charselect")."\";");
}
}
function rp_new_post()
{
global $mybb,$db,$templates, $thread_info;
$forums=explode(',',$mybb->settings['rp_forums']);
array_walk($forums, 'trim_value');
if(in_array($mybb->input['fid'],$forums)){
$db->insert_query("rp_posts",array('pid'=>$thread_info['pid'],'cid'=>$mybb->input['char']));
}
}
function rp_edit()
{
global $mybb,$db,$templates,$post,$rp_menu;
$forums=explode(',',$mybb->settings['rp_forums']);
array_walk($forums, 'trim_value');
$query = $db->simple_select("posts", "fid", "pid = '{$mybb->input['pid']}'");
$data = $db->fetch_array($query);
$chars='';
if(in_array($data['fid'],$forums)){
$pquery = $db->simple_select("posts", "uid", "pid = '{$mybb->input['pid']}'");
$pdata = $db->fetch_array($pquery);
$query = $db->simple_select("rp_posts", "cid", "pid = '{$mybb->input['pid']}'");
$data = $db->fetch_array($query);
$sql ="SELECT c.name,c.id FROM `aa_users` p LEFT JOIN `aa_rp_chars` c ON (p.uid=c.uid) WHERE p.fuid = '".$pdata['uid']."'";
$query = $db->query($sql);
$pquery = $db->simple_select("posts", "uid", "pid = '{$mybb->input['pid']}'");
$pdata = $db->fetch_array($pquery);
while($chid = $db->fetch_array($query)){
if($data['cid']==$chid['id']){
$chars.='<option selected="selected" value="'.$chid['id'].'">'.$chid['name'].'</option>';
}else{
$chars.='<option value="'.$chid['id'].'">'.$chid['name'].'</option>';
}
}
eval("\$rp_menu = \"".$templates->get("charselect")."\";");
}
}
function rp_showthread()
{
global $mybb,$db;
$forums=explode(',',$mybb->settings['rp_forums']);
array_walk($forums, 'trim_value');
//var_dump($mybb);
$query = $db->simple_select("threads", "fid", "tid = '{$mybb->input['tid']}'");
$data = $db->fetch_array($query);
if(in_array($data['fid'],$forums)){
$mybb->settings['quickreply']=0;
}
}
function rp_edit_post()
{
global $mybb,$db,$templates, $postinfo;
$forums=explode(',',$mybb->settings['rp_forums']);
array_walk($forums, 'trim_value');
$query = $db->simple_select("posts", "fid", "pid = '{$mybb->input['pid']}'");
$data = $db->fetch_array($query);
if(in_array($data['fid'],$forums)){
$db->delete_query("rp_posts","`pid`='".$mybb->input['pid']."'");
$db->insert_query("rp_posts",array('pid'=>$mybb->input['pid'],'cid'=>$mybb->input['char']));
}
}
function rp_insert_post()
{
global $mybb,$db,$templates, $postinfo;
$forums=explode(',',$mybb->settings['rp_forums']);
array_walk($forums, 'trim_value');
$query = $db->simple_select("threads", "fid", "tid = '{$mybb->input['tid']}'");
$data = $db->fetch_array($query);
if(in_array($data['fid'],$forums)){
$db->insert_query("rp_posts",array('pid'=>$postinfo['pid'],'cid'=>$mybb->input['char']));
}
}
function rp_postbit(&$post)
{
global $mybb,$db;
$forums=explode(',',$mybb->settings['rp_forums']);
array_walk($forums, 'trim_value');
//var_dump($mybb->settings['rp_forums']);
if(in_array($post['fid'],$forums)){
//var_dump($post);
$sql ="SELECT c.*,a.`codename` as `codename` FROM ".TABLE_PREFIX."rp_posts p LEFT JOIN `v_ptc_users` c ON (p.cid=c.uid) LEFT JOIN `aa_rp_chars` a ON a.`id`=c.`uid` WHERE p.pid = '".$post['pid']."'";
$query = $db->query($sql);
$chid = $db->fetch_array($query);
//var_dump($chid);
$post['profilelink'] = '<a href="//chat.archer.agency/profile/'.$chid['name'].'"><span style="color: #'.$chid['color'].';"><strong><em>'.$chid['name'].'</em></strong></span></a>';
if(file_exists('/var/www/archer.agency/web/modules/rp/images/'.$chid['uid'].'.avatar')){
$post['useravatar'] = '<a href="//chat.archer.agency/profile/'.$chid['name'].'"><img width="70" height="70" alt="" src="//archer.agency/modules/rp/images/'.$chid['uid'].'.avatar"></a>';
}else{
$post['useravatar'] = '';
}
$post['message'] = '<span style="color: #'.$chid['color'].';">'.$post['message'].'</span>';
$post['usertitle'] = $chid['codename'];
$post['userstars'] = '';
$post['signature'] = '';
}
}
function trim_value(&$value)
{
$value = trim($value);
}
?>