add_hook('editpost_start', 'adminpedit_editpost');
$plugins->add_hook('editpost_do_editpost_start', 'adminpedit_do_editpost_start');
function adminpedit_info()
{
return array(
'name' => 'Admin Post Edit',
'description' => 'Gives more options to admins when editing posts/threads.',
'website' => 'http://mybbhacks.zingaburga.com/',
'author' => 'ZiNgA BuRgA',
'authorsite' => 'http://zingaburga.com/',
'version' => '1.1',
'compatibility' => '18*',
'guid' => '4661af5161be4b6c4e43ec46edbcc959'
);
}
function adminpedit_activate()
{
global $db;
require MYBB_ROOT.'inc/adminfunctions_templates.php';
find_replace_templatesets('editpost', '#'.preg_quote('').'#', '{$adminopt}');
$db->insert_query('templates', array(
'title' => 'editpost_adminopt',
'template' => $db->escape_string(
'
'
),
'sid' => -1,
'version' => '1400'
));
}
function adminpedit_deactivate()
{
global $db;
require MYBB_ROOT.'inc/adminfunctions_templates.php';
find_replace_templatesets('editpost', '#'.preg_quote('{$adminopt}').'#', '', 0);
$db->delete_query('templates', 'sid=-1 AND title = "editpost_adminopt"');
}
function adminpedit_editpost()
{
global $mybb, $db;
if($mybb->usergroup['cancp'] != 1) return;
global $templates, $post, $adminopt, $theme;
if(!$post['pid'])
{
$pid = intval($mybb->input['pid']);
if($pid) $post = get_post($pid);
if(!$post['pid']) return;
}
// attempt to detect screwy templates
if($templates->cache['editpost'] && !strpos($templates->cache['editpost'], '$adminopt'))
$templates->cache['editpost'] = str_replace('', '{$adminopt}', $templates->cache['editpost']);
// uid, username, dateline, ipaddress, edituid, edittime
if($post['uid'] || $mybb->input['postreguser'] == 'yes')
$regusercheck = ' checked="checked"';
else
$regusercheck = '';
if($mybb->input['postusername'])
$postusername = htmlspecialchars_uni($mybb->input['postusername']);
else
$postusername = htmlspecialchars_uni($post['username']);
if($mybb->input['posttime'])
$dateline = intval($mybb->input['posttime']);
else
$dateline = $post['dateline'];
if($mybb->input['ipaddress'])
//$ipaddress = htmlspecialchars($mybb->input['postip']);
$ipaddress = my_inet_ntop($db->unescape_binary($mybb->input['postip']));
else
//$ipaddress = $post['ipaddress'];
$ipaddress = my_inet_ntop($db->unescape_binary($post['ipaddress']));
// silent/clear editing
$editopt = '';
if($mybb->settings['showeditedbyadmin'] == 1)
$editopt .= '
';
if($post['edituid'])
$editopt .= '
';
if($editopt)
$editopt = 'Bearbeitungs Optzionen | '.$editopt.' |
';
eval('$adminopt = "'.$templates->get('editpost_adminopt').'";');
}
function adminpedit_do_editpost_start()
{
global $mybb;
if($mybb->usergroup['cancp'] != 1 || $mybb->input['adminpedit_active'] != '1') return;
if($mybb->input['editopt'] == 'silent')
$mybb->settings['showeditedbyadmin'] = 'no';
$GLOBALS['plugins']->add_hook('editpost_do_editpost_end', 'adminpedit_do_editpost');
}
function adminpedit_do_editpost()
{
global $post, $thread, $db, $mybb;
$update_array = array();
if($mybb->input['posttime'])
$update_array['dateline'] = intval($mybb->input['posttime']);
if($mybb->input['postusername'])
$update_array['username'] = $db->escape_string($mybb->input['postusername']);
if($mybb->input['postreguser'] == 'yes')
{
// saerch for the UID
$uid = $db->fetch_field($db->simple_select('users', 'uid', 'LOWER(username)="'.strtolower($update_array['username']).'"'), 'uid');
if(!$uid) error('Der spezielle Benutzername wurde nicht gefunden !');
$update_array['uid'] = $uid;
}
else
{
$update_array['uid'] = 0;
}
$thread_updates = $update_array;
if($mybb->input['postip'])
{
if(!preg_match('#^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$#', $mybb->input['postip']))
error('Ungültige IP angegeben');
$postip = array_map('intval', explode('.', $mybb->input['postip']));
if($postip[0] > 255 || $postip[1] > 255 || $postip[2] > 255 || $postip[3] > 255)
error('Ungültige IP angegeben');
$postip = implode('.', $postip);
$postip = $db->escape_binary(my_inet_pton($postip));
$update_array['ipaddress'] = $postip;
}
if($mybb->input['editopt'] == 'reset')
{
$update_array['edituid'] = 0;
$update_array['edittime'] = 0;
}
// if it's the first post, we should update the thread...
$firstcheck = $db->fetch_array($db->simple_select("posts", "pid", "tid='{$thread['tid']}'", array("limit" => 1, "order_by" => "dateline", "order_dir" => "asc")));
if($firstcheck['pid'] == $post['pid'])
{
$db->update_query('threads', $thread_updates, 'tid='.$thread['tid']);
}
$db->update_query('posts', $update_array, 'pid='.$post['pid']);
// if it's the last post, we should update the thread and forums...
$lastcheck = $db->fetch_array($db->simple_select("posts", "pid", "tid='{$thread['tid']}'", array("limit" => 1, "order_by" => "dateline", "order_dir" => "desc")));
if($lastcheck['pid'] == $post['pid'])
{
$update_array1['lastposter'] = $update_array['username'] ;
$update_array1['lastposteruid'] = $update_array['uid'] ;
$db->update_query('threads', $update_array1, 'tid='.$thread['tid']);
$db->update_query('forums', $update_array1, 'lastposttid='.$thread['tid']);
}
}
?>