如何编写vBulletin的postbit编辑点(仅限论坛工作人员)?

时间:2014-03-09 20:19:58

标签: php plugins vbulletin

我正在尝试一个按钮,允许工作人员(或拥有权限的用户组)在会员的邮政遗产中看到该按钮,并点击它可以编辑"积分&#34 ;或"货币"就在那儿当场。添加新值后,将在用户表列中更新它。我使用vBShop - DragonByte Tech作为积分系统,只能找到myBB论坛的代码,而不是vBulletin。

a busy cat

<?php

if(!defined("IN_MYBB"))
{
    die("Direct initialization of this file is not allowed.<br /><br />Please make sure IN_MYBB is defined.");
}

function newpoints_edit_info()
{
    return array(
    "name"          => "Newpoints Edit",
    "description"   => "Allows you to edit newpoints of any user.",
    "website"       => "http://yaldaram.com",
    "author"        => "Yaldaram",
    "authorsite"    => "http://yaldaram.com",
    "version"       => "0.2",
    "compatibility" => "14*,16*"
);

}
function newpoints_edit_install()
{
    global $db, $mybb;

    $newpoints_edit_group = array(
    "gid"           => "NULL",
    "name"          => "newpoints_edit",
    "title"         => "Newpoints Edit",
    "description"   => "Settings for the plugin.",
    "disporder"     => "1",
    "isdefault"     => "no",
);
$db->insert_query("settinggroups", $newpoints_edit_group);
$gid = $db->insert_id();

$newpoints_edit_setting_1 = array(
    "sid"           => "NULL",
    "name"          => "newpoints_edit_power",
    "title"         => "Power",
    "description"   => "Select Yes if you really wants this plugin to run.",
    "optionscode"   => "yesno",
    "value"         => "1",
    "disporder"     => "1",
    "gid"           => intval($gid),
);

$db->insert_query("settings", $newpoints_edit_setting_1);

$newpoints_edit_setting_2 = array(
    "sid"           => "NULL",
    "name"          => "newpoints_edit_group",
    "title"         => "MOD_Usergroups",
    "description"   => "Specify Usergroup IDs you wish to allow them to edit Newpoints.(Usually Moderators and Admins) Separate with , if more then.",
    "optionscode"   => "text",
    "value"         => "3,4",
    "disporder"     => "2",
    "gid"           => intval($gid),
);

$db->insert_query("settings", $newpoints_edit_setting_2);

$newpoints_edit_setting_3 = array(
    "sid"           => "NULL",
    "name"          => "newpoints_edit_self",
    "title"         => "Self_Editing",
    "description"   => "Would you like to allow above usergroups to edit their own Newpoints ?",
    "optionscode"   => "yesno",
    "value"         => "1",
    "disporder"     => "3",
    "gid"           => intval($gid),
);

$db->insert_query("settings", $newpoints_edit_setting_3);

rebuild_settings();

// Insert Templates
require MYBB_ROOT."/inc/adminfunctions_templates.php";
$template = array(
    "title"     => "newpoints_edit_page",
    "template"  => '<html>
<head>
<title>{$mybb->settings[\\\'bbname\\\']} - {$lang->edit_newpoints}</title>
{$headerinclude}
</head>
<body>
{$header}
<form action="newpoints.php" method="post" enctype="multipart/form-data" name="input">
<input type="hidden" name="my_post_key" value="{$mybb->post_code}" />
<table border="0" cellspacing="{$theme[\\\'borderwidth\\\']}" cellpadding="    {$theme[\\\'tablespace\\\']}" class="tborder">
<tr>
<td class="thead" colspan="2"><strong>{$lang->edit_newpoints_of} {$user_username}</strong>    </td>
</tr>
<tr>
<td class="trow1" width="25%">
<strong>{$lang->current_newpoints}</strong>
</td>
<td class="trow1" width="75%">
<i>{$user_newpoints}</i><br />
<span class="smalltext">{$lang->edit_using_form}</span>
</td>
</tr>
<tr>
<td class="trow2" width="25%">
<strong>{$lang->edit_form}</strong>
</td>
<td class="trow2" width="75%">
<input type="text" class="textbox" name="points" size="40" maxlength="85" value="{$user_newpoints}" tabindex="1" />
</td>
</tr>
<tr>
<td class="thead" colspan="2">
<div style="text-align:center"><input type="submit" class="button" name="submit" value="{$lang->submit}" tabindex="4" accesskey="s" /></div>
</td>
</tr>
</table>
<input type="hidden" name="action" value="do_edit" />
<input type="hidden" name="uid" value="{$mybb->input[\\\'uid\\\']}" />
<input type="hidden" name="do_uid" value="{$mybb->user[\\\'uid\\\']}" />
</form>
{$footer}
</body>
</html>',
        "sid"       => -1
    );
    $db->insert_query("templates", $template);

    find_replace_templatesets("postbit", "#".preg_quote('{$post[\'newpoints_postbit\']}')."#i", '{\$post[\'newpoints_postbit\']} {\$post[\'newpoints_edit\']}');
    find_replace_templatesets("postbit_classic", "#".preg_quote('{$post[\'newpoints_postbit\']}')."#i", '{\$post[\'newpoints_postbit\']}{\$post[\'newpoints_edit\']}');
}

function newpoints_edit_is_installed()
{
    global $db;
    $query = $db->simple_select("settinggroups", "COUNT(*) as rows", "name='newpoints_edit'");
    $rows = $db->fetch_field($query, "rows");
    if($rows > 0)
    {
        return TRUE;
    }

    return FALSE;
}

function newpoints_edit_activate()
{
}

function newpoints_edit_deactivate()
{
}

function newpoints_edit_uninstall()
{
    global $db, $mybb;
    require MYBB_ROOT."/inc/adminfunctions_templates.php";
    find_replace_templatesets("postbit", "#".preg_quote('{$post[\'newpoints_edit\']}')."#i", '', 0);
    find_replace_templatesets("postbit_classic", "#".preg_quote('{$post[\'newpoints_edit\']}')."#i", '', 0);

    $db->query("DELETE FROM ".TABLE_PREFIX."templates WHERE title='newpoints_edit_page'");
    $db->query("DELETE FROM ".TABLE_PREFIX."settinggroups WHERE name='newpoints_edit'");
    $db->query("DELETE FROM ".TABLE_PREFIX."settings WHERE name='newpoints_edit_power'");
    $db->query("DELETE FROM ".TABLE_PREFIX."settings WHERE name='newpoints_edit_group'");
    rebuild_settings();
}

$plugins->add_hook("postbit", "newpoints_edit");
function newpoints_edit(&$post)
{
global $mybb, $lang, $templates;
$power = $mybb->settings['newpoints_edit_power'];
$groups = explode(",",$mybb->settings['newpoints_edit_group']);
$self_editing = $mybb->settings['newpoints_edit_self'];
if ($power != "0")
{
    $lang->load("newpoints_edit");
    if (in_array($mybb->user['additionalgroups'],$groups) || in_array($mybb->user['usergroup'],$groups) && $self_editing != "1" && $post['uid'] == $mybb->user['uid'])
    {
        $post['newpoints_edit'] = '';
    }
    elseif (in_array($mybb->user['usergroup'],$groups) || in_array($mybb->user['additionalgroups'],$groups))
    {
        $post['newpoints_edit'] = '[<a href="newpoints.php?action=edit&amp;uid='.$post['uid'].'">'.$lang->edit_newpoints_postbit.'</a>]';
    }
    }
}

$plugins->add_hook("newpoints_begin", "newpoints_edit_begin");
function newpoints_edit_begin()
{
    global $db, $mybb, $lang, $templates, $theme, $header, $footer, $headerinclude,     $newpoints_edit_page;

    $action = $mybb->input['action'];
$lang->load("newpoints_edit");
if ($action == "edit")
{
    $power = $mybb->settings['newpoints_edit_power'];
    if ($power != "1")
    {
        error($lang->newpoints_disabled);
    }

    $groups = explode(",",$mybb->settings['newpoints_edit_group']);
    if (!in_array($mybb->user['usergroup'],$groups) && !in_array($mybb->user['additionalgroups'],$groups))
    {
        error($lang->error_no_permission);
    }

    $self_editing = $mybb->settings['newpoints_edit_self'];
    $uid = intval($mybb->input['uid']);
    if ($self_editing != "1" && $uid == $mybb->user['uid'])
    {
        error($lang->no_permission_self_editing);
    }

    add_breadcrumb($lang->edit_newpoints, "newpoints.php?action=edit");

    $user = get_user($uid);
    $user_newpoints = intval($user['newpoints']);
    $user_username = htmlspecialchars_uni($user['username']);

    eval("\$newpoints_edit_page = \"".$templates->get("newpoints_edit_page")."\";");
    output_page($newpoints_edit_page);
}
elseif ($action == "do_edit")
{
    // Verify incoming post request.
    verify_post_check($mybb->input['my_post_key']);

    $power = $mybb->settings['newpoints_edit_power'];
    if ($power != "1")
    {
        error($lang->newpoints_disabled);
    }

    $groups = explode(",",$mybb->settings['newpoints_edit_group']);
    if (!in_array($mybb->user['usergroup'],$groups) && !in_array($mybb->user['additionalgroups'],$groups))
    {
        error($lang->error_no_permission);
    }

    $self_editing = $mybb->settings['newpoints_edit_self'];
    $uid = intval($mybb->input['uid']);
    if ($self_editing != "1" && $uid == $mybb->user['uid'])
    {
        error($lang->no_permission_self_editing);
    }

    $uid = intval($mybb->input['uid']);

    $updates =  array(
        "newpoints" => floatval($mybb->input['points'])
    );
    $db->update_query("users", $updates, "uid='{$uid}'");
    redirect("member.php?action=profile&amp;uid={$uid}", $lang->newpoints_edited_success);
}
}
?>

1 个答案:

答案 0 :(得分:0)