function sp_render_common_tools($forum, $topic, $post = 0, $page = 0, $br)
{
    global $spThisUser;
    $out = '';
    if (sp_get_auth('lock_topics', $forum['forum_id'])) {
        $out .= sp_open_grid_cell();
        $out .= '<div class="spForumToolsLock">';
        $locktext = $topic['topic_status'] ? sp_text('Unlock this topic') : sp_text('Lock this topic');
        $ajaxUrl = SFHOMEURL . 'index.php?sp_ahah=admintools&amp;sfnonce=' . wp_create_nonce('forum-ahah') . '&amp;action=lock-topic&amp;topic=' . $topic['topic_id'];
        $out .= "<a href='javascript:void(null)' onclick='spjLockTopic(\"{$ajaxUrl}\");'>";
        $out .= sp_paint_icon('spIcon', SPTHEMEICONSURL, 'sp_ToolsLock.png') . $br;
        $out .= $locktext . '</a>';
        $out .= '</div>';
        $out .= sp_close_grid_cell();
    }
    if (sp_get_auth('pin_topics', $forum['forum_id'])) {
        $out .= sp_open_grid_cell();
        $out .= '<div class="spForumToolsPin">';
        $pintext = $topic['topic_pinned'] ? sp_text('Unpin this topic') : sp_text('Pin this topic');
        $ajaxUrl = SFHOMEURL . 'index.php?sp_ahah=admintools&amp;sfnonce=' . wp_create_nonce('forum-ahah') . '&amp;action=pin-topic&amp;topic=' . $topic['topic_id'];
        $out .= "<a href='javascript:void(null)' onclick='spjPinTopic(\"{$ajaxUrl}\");'>";
        $out .= sp_paint_icon('spIcon', SPTHEMEICONSURL, 'sp_ToolsPin.png') . $br;
        $out .= $pintext . '</a>';
        $out .= '</div>';
        $out .= sp_close_grid_cell();
    }
    if (sp_get_auth('pin_topics', $forum['forum_id']) && $topic['topic_pinned']) {
        $out .= sp_open_grid_cell();
        $out .= '<div class="spForumToolsPin">';
        $pintext = sp_text('Promote this pinned topic');
        $site = SFHOMEURL . 'index.php?sp_ahah=admintools&amp;sfnonce=' . wp_create_nonce('forum-ahah') . '&amp;action=order-pins&amp;topicid=' . $topic['topic_id'] . '&amp;forumid=' . $forum['forum_id'] . '&amp;userid=' . $topic['user_id'];
        $title = sp_text('Order Pinned Topics');
        $out .= '<a rel="nofollow" href="javascript:void(null)" onclick="spjDialogAjax(this, \'' . $site . '\', \'' . esc_js($title) . '\', 400, 0, \'center\');">';
        $out .= sp_paint_icon('spIcon', SPTHEMEICONSURL, 'sp_ToolsPin.png') . $br;
        $out .= $title . '</a>';
        $out .= '</div>';
        $out .= sp_close_grid_cell();
    }
    if (sp_get_auth('edit_own_topic_titles', $forum['forum_id']) && $topic['user_id'] == $spThisUser->ID || sp_get_auth('edit_any_topic_titles', $forum['forum_id'])) {
        $out .= sp_open_grid_cell();
        $out .= '<div class="spForumToolsEdit">';
        $site = SFHOMEURL . 'index.php?sp_ahah=admintools&amp;sfnonce=' . wp_create_nonce('forum-ahah') . '&amp;action=edit-title&amp;topicid=' . $topic['topic_id'] . '&amp;forumid=' . $forum['forum_id'] . '&amp;userid=' . $topic['user_id'];
        $title = sp_text('Edit topic title');
        $out .= '<a rel="nofollow" href="javascript:void(null)" onclick="spjDialogAjax(this, \'' . $site . '\', \'' . esc_js($title) . '\', 400, 0, \'center\');">';
        $out .= sp_paint_icon('spIcon', SPTHEMEICONSURL, 'sp_ToolsEdit.png') . $br;
        $out .= $title . '</a>';
        $out .= '</div>';
        $out .= sp_close_grid_cell();
    }
    if (sp_get_auth('delete_topics', $forum['forum_id'])) {
        $out .= sp_open_grid_cell();
        $out .= '<div class="spForumToolsDelete">';
        $msg = esc_js(sp_text('Are you sure you want to delete this topic?'));
        $view = !empty($post) ? 'topic' : 'forum';
        $ajaxUrl = SFHOMEURL . 'index.php?sp_ahah=admintools&amp;sfnonce=' . wp_create_nonce('forum-ahah') . '&amp;action=delete-topic&amp;killtopic=' . $topic['topic_id'] . '&amp;killtopicforum=' . $forum['forum_id'] . '&amp;page=' . $page . "&amp;view={$view}";
        $out .= "<a href='javascript:void(null)' onclick='spjDeleteTopic(\"{$ajaxUrl}\", {$topic['topic_id']}, {$forum['forum_id']});'>";
        $out .= sp_paint_icon('spIcon', SPTHEMEICONSURL, 'sp_ToolsDelete.png') . $br;
        $out .= sp_text('Delete this topic') . '</a>';
        $out .= '</div>';
        $out .= sp_close_grid_cell();
    }
    if (sp_get_auth('move_topics', $forum['forum_id'])) {
        $out .= sp_open_grid_cell();
        $out .= '<div class="spForumToolsMove">';
        $site = SFHOMEURL . 'index.php?sp_ahah=admintools&amp;sfnonce=' . wp_create_nonce('forum-ahah') . '&amp;action=move-topic&amp;topicid=' . $topic['topic_id'] . '&amp;forumid=' . $forum['forum_id'];
        $title = sp_text('Move this topic');
        $out .= '<a rel="nofollow" href="javascript:void(null)" onclick="spjDialogAjax(this, \'' . $site . '\', \'' . esc_js($title) . '\', 400, 0, \'center\');">';
        $out .= sp_paint_icon('spIcon', SPTHEMEICONSURL, 'sp_ToolsMove.png') . $br;
        $out .= $title . '</a>';
        $out .= '</div>';
        $out .= sp_close_grid_cell();
    }
    $out = apply_filters('sph_add_common_tools', $out, $forum, $topic, $post, $page, $br);
    return $out;
}
function sp_AddButton($args = '', $label = '', $toolTip = '', $perm = '', $buttonID = '')
{
    global $spThisUser;
    $defs = array('tagId' => $buttonID, 'tagClass' => 'spButton', 'link' => sp_url(), 'icon' => '', 'iconClass' => 'spIcon', 'mobileMenu' => 0, 'echo' => 1);
    $a = wp_parse_args($args, $defs);
    $a = apply_filters('sph_AddButton_args', $a);
    extract($a, EXTR_SKIP);
    # verify optional 'simple' permission check
    if (!empty($perm) && !sp_get_auth($perm)) {
        return;
    }
    # allow for complex permission checking
    $auth = apply_filters('sph_add_button_auth_check', true, $buttonID, $a);
    if (!$auth) {
        return;
    }
    # sanitize before use
    $tagId = esc_attr($tagId);
    $tagClass = esc_attr($tagClass);
    $link = esc_url($link);
    $icon = sanitize_file_name($icon);
    $iconClass = esc_attr($iconClass);
    $mobileMenu = (int) $mobileMenu;
    $echo = (int) $echo;
    $toolTip = esc_attr($toolTip);
    $br = $mobileMenu ? '<br />' : '';
    $out = '';
    if ($mobileMenu) {
        if ($mobileMenu) {
            $out .= sp_open_grid_cell();
        }
    }
    $out .= "<a class='{$tagClass}' id='{$tagId}' title='{$toolTip}' href='{$link}'>";
    if (!empty($icon)) {
        $out .= sp_paint_icon($iconClass, SPTHEMEICONSURL, $icon) . $br;
    }
    if (!empty($label)) {
        $out .= sp_filter_title_display($label);
    }
    $out .= "</a>\n";
    if ($mobileMenu) {
        $out .= sp_close_grid_cell();
    }
    $out = apply_filters('sph_AddButton', $out, $a);
    if ($echo) {
        echo $out;
    } else {
        return $out;
    }
}