function sportal_shoutbox()
{
    global $smcFunc, $context, $scripturl, $txt, $sourcedir, $user_info;
    $shoutbox_id = !empty($_REQUEST['shoutbox_id']) ? (int) $_REQUEST['shoutbox_id'] : 0;
    $request_time = !empty($_REQUEST['time']) ? (int) $_REQUEST['time'] : 0;
    $context['SPortal']['shoutbox'] = sportal_get_shoutbox($shoutbox_id, true, true);
    if (empty($context['SPortal']['shoutbox'])) {
        fatal_lang_error('error_sp_shoutbox_not_exist', false);
    }
    $context['SPortal']['shoutbox']['warning'] = parse_bbc($context['SPortal']['shoutbox']['warning']);
    $can_moderate = allowedTo('sp_admin') || allowedTo('sp_manage_shoutbox');
    if (!$can_moderate && !empty($context['SPortal']['shoutbox']['moderator_groups'])) {
        $can_moderate = count(array_intersect($user_info['groups'], $context['SPortal']['shoutbox']['moderator_groups'])) > 0;
    }
    if (!empty($_REQUEST['shout'])) {
        checkSession('request');
        is_not_guest();
        if (!($flood = sp_prevent_flood('spsbp', false))) {
            require_once $sourcedir . '/Subs-Post.php';
            $_REQUEST['shout'] = $smcFunc['htmlspecialchars'](trim($_REQUEST['shout']));
            preparsecode($_REQUEST['shout']);
            if (!empty($_REQUEST['shout'])) {
                sportal_create_shout($context['SPortal']['shoutbox'], $_REQUEST['shout']);
            }
        } else {
            $context['SPortal']['shoutbox']['warning'] = $flood;
        }
    }
    if (!empty($_REQUEST['delete'])) {
        checkSession('request');
        if (!$can_moderate) {
            fatal_lang_error('error_sp_cannot_shoutbox_moderate', false);
        }
        $_REQUEST['delete'] = (int) $_REQUEST['delete'];
        if (!empty($_REQUEST['delete'])) {
            sportal_delete_shout($shoutbox_id, $_REQUEST['delete']);
        }
    }
    loadTemplate('PortalShoutbox');
    if (isset($_REQUEST['xml'])) {
        $shout_parameters = array('limit' => $context['SPortal']['shoutbox']['num_show'], 'bbc' => $context['SPortal']['shoutbox']['allowed_bbc'], 'reverse' => $context['SPortal']['shoutbox']['reverse'], 'cache' => $context['SPortal']['shoutbox']['caching'], 'can_moderate' => $can_moderate);
        $context['SPortal']['shouts'] = sportal_get_shouts($shoutbox_id, $shout_parameters);
        $context['sub_template'] = 'shoutbox_xml';
        $context['SPortal']['updated'] = empty($context['SPortal']['shoutbox']['last_update']) || $context['SPortal']['shoutbox']['last_update'] > $request_time;
        return;
    }
    $request = $smcFunc['db_query']('', '
		SELECT COUNT(*)
		FROM {db_prefix}sp_shouts
		WHERE id_shoutbox = {int:current}', array('current' => $shoutbox_id));
    list($total_shouts) = $smcFunc['db_fetch_row']($request);
    $smcFunc['db_free_result']($request);
    $context['per_page'] = $context['SPortal']['shoutbox']['num_show'];
    $context['start'] = !empty($_REQUEST['start']) ? (int) $_REQUEST['start'] : 0;
    $context['page_index'] = constructPageIndex($scripturl . '?action=portal;sa=shoutbox;shoutbox_id=' . $shoutbox_id, $context['start'], $total_shouts, $context['per_page']);
    $shout_parameters = array('start' => $context['start'], 'limit' => $context['per_page'], 'bbc' => $context['SPortal']['shoutbox']['allowed_bbc'], 'cache' => $context['SPortal']['shoutbox']['caching'], 'can_moderate' => $can_moderate);
    $context['SPortal']['shouts_history'] = sportal_get_shouts($shoutbox_id, $shout_parameters);
    $context['SPortal']['shoutbox_id'] = $shoutbox_id;
    $context['sub_template'] = 'shoutbox_all';
    $context['page_title'] = $context['SPortal']['shoutbox']['name'];
}
function sp_shoutbox($parameters, $id, $return_parameters = false)
{
    global $smcFunc, $context, $sourcedir, $modSettings, $user_info, $settings, $txt, $scripturl;
    $block_parameters = array('shoutbox' => array());
    if ($return_parameters) {
        $shoutboxes = sportal_get_shoutbox();
        $in_use = array();
        $request = $smcFunc['db_query']('', '
			SELECT id_block, value
			FROM {db_prefix}sp_parameters
			WHERE variable = {string:name}', array('name' => 'shoutbox'));
        while ($row = $smcFunc['db_fetch_assoc']($request)) {
            if (empty($_REQUEST['block_id']) || $_REQUEST['block_id'] != $row['id_block']) {
                $in_use[] = $row['value'];
            }
        }
        $smcFunc['db_free_result']($request);
        foreach ($shoutboxes as $shoutbox) {
            if (!in_array($shoutbox['id'], $in_use)) {
                $block_parameters['shoutbox'][$shoutbox['id']] = $shoutbox['name'];
            }
        }
        if (empty($block_parameters['shoutbox'])) {
            fatal_error(allowedTo(array('sp_admin', 'sp_manage_shoutbox')) ? $txt['error_sp_no_shoutbox'] . '<br />' . sprintf($txt['error_sp_no_shoutbox_sp_moderator'], $scripturl . '?action=admin;area=portalshoutbox;sa=add') : $txt['error_sp_no_shoutbox_normaluser'], false);
        }
        return $block_parameters;
    }
    loadTemplate('PortalShoutbox');
    loadLanguage('Post');
    $shoutbox = sportal_get_shoutbox($parameters['shoutbox'], true, true);
    if (empty($shoutbox)) {
        echo '
								', $txt['error_sp_shoutbox_not_exist'];
        return;
    }
    if (!empty($_POST['new_shout']) && !empty($_POST['submit_shout']) && !empty($_POST['shoutbox_id']) && $_POST['shoutbox_id'] == $shoutbox['id']) {
        checkSession();
        is_not_guest();
        if (!($flood = sp_prevent_flood('spsbp', false))) {
            require_once $sourcedir . '/Subs-Post.php';
            $_POST['new_shout'] = $smcFunc['htmlspecialchars'](trim($_POST['new_shout']));
            preparsecode($_POST['new_shout']);
            if (!empty($_POST['new_shout'])) {
                sportal_create_shout($shoutbox, $_POST['new_shout']);
            }
        } else {
            $shoutbox['warning'] = $flood;
        }
    }
    $can_moderate = allowedTo('sp_admin') || allowedTo('sp_manage_shoutbox');
    if (!$can_moderate && !empty($shoutbox['moderator_groups'])) {
        $can_moderate = count(array_intersect($user_info['groups'], $shoutbox['moderator_groups'])) > 0;
    }
    $shout_parameters = array('limit' => $shoutbox['num_show'], 'bbc' => $shoutbox['allowed_bbc'], 'reverse' => $shoutbox['reverse'], 'cache' => $shoutbox['caching'], 'can_moderate' => $can_moderate);
    $shoutbox['shouts'] = sportal_get_shouts($shoutbox['id'], $shout_parameters);
    $shoutbox['warning'] = parse_bbc($shoutbox['warning']);
    $context['can_shout'] = $context['user']['is_logged'];
    if ($context['can_shout']) {
        $settings['smileys_url'] = $modSettings['smileys_url'] . '/' . $user_info['smiley_set'];
        $shoutbox['smileys'] = array('normal' => array(), 'popup' => array());
        if (empty($modSettings['smiley_enable'])) {
            $shoutbox['smileys']['normal'] = array(array('code' => ':)', 'filename' => 'smiley.gif', 'description' => $txt['icon_smiley']), array('code' => ';)', 'filename' => 'wink.gif', 'description' => $txt['icon_wink']), array('code' => ':D', 'filename' => 'cheesy.gif', 'description' => $txt['icon_cheesy']), array('code' => ';D', 'filename' => 'grin.gif', 'description' => $txt['icon_grin']), array('code' => '>:(', 'filename' => 'angry.gif', 'description' => $txt['icon_angry']), array('code' => ':(', 'filename' => 'sad.gif', 'description' => $txt['icon_sad']), array('code' => ':o', 'filename' => 'shocked.gif', 'description' => $txt['icon_shocked']), array('code' => '8)', 'filename' => 'cool.gif', 'description' => $txt['icon_cool']), array('code' => '???', 'filename' => 'huh.gif', 'description' => $txt['icon_huh']), array('code' => '::)', 'filename' => 'rolleyes.gif', 'description' => $txt['icon_rolleyes']), array('code' => ':P', 'filename' => 'tongue.gif', 'description' => $txt['icon_tongue']), array('code' => ':-[', 'filename' => 'embarrassed.gif', 'description' => $txt['icon_embarrassed']), array('code' => ':-X', 'filename' => 'lipsrsealed.gif', 'description' => $txt['icon_lips']), array('code' => ':-\\', 'filename' => 'undecided.gif', 'description' => $txt['icon_undecided']), array('code' => ':-*', 'filename' => 'kiss.gif', 'description' => $txt['icon_kiss']), array('code' => ':\'(', 'filename' => 'cry.gif', 'description' => $txt['icon_cry']));
        } else {
            if (($temp = cache_get_data('shoutbox_smileys', 3600)) == null) {
                $request = $smcFunc['db_query']('', '
					SELECT code, filename, description, smiley_row, hidden
					FROM {db_prefix}smileys
					WHERE hidden IN ({array_int:hidden})
					ORDER BY smiley_row, smiley_order', array('hidden' => array(0, 2)));
                while ($row = $smcFunc['db_fetch_assoc']($request)) {
                    $row['filename'] = htmlspecialchars($row['filename']);
                    $row['description'] = htmlspecialchars($row['description']);
                    $row['code'] = htmlspecialchars($row['code']);
                    $shoutbox['smileys'][empty($row['hidden']) ? 'normal' : 'popup'][] = $row;
                }
                $smcFunc['db_free_result']($request);
                cache_put_data('shoutbox_smileys', $shoutbox['smileys'], 3600);
            } else {
                $shoutbox['smileys'] = $temp;
            }
        }
        foreach (array_keys($shoutbox['smileys']) as $location) {
            $n = count($shoutbox['smileys'][$location]);
            for ($i = 0; $i < $n; $i++) {
                $shoutbox['smileys'][$location][$i]['code'] = addslashes($shoutbox['smileys'][$location][$i]['code']);
                $shoutbox['smileys'][$location][$i]['js_description'] = addslashes($shoutbox['smileys'][$location][$i]['description']);
            }
            if (!empty($shoutbox['smileys'][$location])) {
                $shoutbox['smileys'][$location][$n - 1]['last'] = true;
            }
        }
        $shoutbox['bbc'] = array('bold' => array('code' => 'b', 'before' => '[b]', 'after' => '[/b]', 'description' => $txt['bold']), 'italicize' => array('code' => 'i', 'before' => '[i]', 'after' => '[/i]', 'description' => $txt['italic']), 'underline' => array('code' => 'u', 'before' => '[u]', 'after' => '[/u]', 'description' => $txt['underline']), 'strike' => array('code' => 's', 'before' => '[s]', 'after' => '[/s]', 'description' => $txt['strike']), 'pre' => array('code' => 'pre', 'before' => '[pre]', 'after' => '[/pre]', 'description' => $txt['preformatted']), 'flash' => array('code' => 'flash', 'before' => '[flash=200,200]', 'after' => '[/flash]', 'description' => $txt['flash']), 'img' => array('code' => 'img', 'before' => '[img]', 'after' => '[/img]', 'description' => $txt['image']), 'url' => array('code' => 'url', 'before' => '[url]', 'after' => '[/url]', 'description' => $txt['hyperlink']), 'email' => array('code' => 'email', 'before' => '[email]', 'after' => '[/email]', 'description' => $txt['insert_email']), 'ftp' => array('code' => 'ftp', 'before' => '[ftp]', 'after' => '[/ftp]', 'description' => $txt['ftp']), 'glow' => array('code' => 'glow', 'before' => '[glow=red,2,300]', 'after' => '[/glow]', 'description' => $txt['glow']), 'shadow' => array('code' => 'shadow', 'before' => '[shadow=red,left]', 'after' => '[/shadow]', 'description' => $txt['shadow']), 'sup' => array('code' => 'sup', 'before' => '[sup]', 'after' => '[/sup]', 'description' => $txt['superscript']), 'sub' => array('code' => 'sub', 'before' => '[sub]', 'after' => '[/sub]', 'description' => $txt['subscript']), 'tele' => array('code' => 'tt', 'before' => '[tt]', 'after' => '[/tt]', 'description' => $txt['teletype']), 'code' => array('code' => 'code', 'before' => '[code]', 'after' => '[/code]', 'description' => $txt['bbc_code']), 'quote' => array('code' => 'quote', 'before' => '[quote]', 'after' => '[/quote]', 'description' => $txt['bbc_quote']));
    }
    template_shoutbox_embed($shoutbox);
}
 /**
  * The Shoutbox ... allows for the adding, editing, deleting and viewing of shouts
  */
 public function action_sportal_shoutbox()
 {
     global $context, $scripturl, $user_info;
     // ID of the shoutbox we are working on and timestamp
     $shoutbox_id = !empty($_REQUEST['shoutbox_id']) ? (int) $_REQUEST['shoutbox_id'] : 0;
     $request_time = !empty($_REQUEST['time']) ? (int) $_REQUEST['time'] : 0;
     // We need to know which shoutbox this is for/from
     $context['SPortal']['shoutbox'] = sportal_get_shoutbox($shoutbox_id, true, true);
     if (empty($context['SPortal']['shoutbox'])) {
         if (isset($_REQUEST['xml'])) {
             obExit(false, false);
         } else {
             fatal_lang_error('error_sp_shoutbox_not_exist', false);
         }
     }
     // Any warning title for the shoutbox, like Not For Support ;P
     $context['SPortal']['shoutbox']['warning'] = parse_bbc($context['SPortal']['shoutbox']['warning']);
     $can_moderate = allowedTo('sp_admin') || allowedTo('sp_manage_shoutbox');
     if (!$can_moderate && !empty($context['SPortal']['shoutbox']['moderator_groups'])) {
         $can_moderate = count(array_intersect($user_info['groups'], $context['SPortal']['shoutbox']['moderator_groups'])) > 0;
     }
     // Adding a shout
     if (!empty($_REQUEST['shout'])) {
         // Pretty basic
         is_not_guest();
         checkSession('request');
         // If you are not flooding the system, add the shout to the box
         if (!($flood = sp_prevent_flood('spsbp', false))) {
             require_once SUBSDIR . '/Post.subs.php';
             $_REQUEST['shout'] = Util::htmlspecialchars(trim($_REQUEST['shout']));
             preparsecode($_REQUEST['shout']);
             if (!empty($_REQUEST['shout'])) {
                 sportal_create_shout($context['SPortal']['shoutbox'], $_REQUEST['shout']);
             }
         } else {
             $context['SPortal']['shoutbox']['warning'] = $flood;
         }
     }
     // Removing a shout, regret saying that do you :P
     if (!empty($_REQUEST['delete'])) {
         checkSession('request');
         if (!$can_moderate) {
             fatal_lang_error('error_sp_cannot_shoutbox_moderate', false);
         }
         $delete = (int) $_REQUEST['delete'];
         if (!empty($delete)) {
             sportal_delete_shout($shoutbox_id, $delete);
         }
     }
     // Responding to an ajax request
     if (isset($_REQUEST['xml'])) {
         $shout_parameters = array('limit' => $context['SPortal']['shoutbox']['num_show'], 'bbc' => $context['SPortal']['shoutbox']['allowed_bbc'], 'reverse' => $context['SPortal']['shoutbox']['reverse'], 'cache' => $context['SPortal']['shoutbox']['caching'], 'can_moderate' => $can_moderate);
         // Get all the shouts for this box
         $context['SPortal']['shouts'] = sportal_get_shouts($shoutbox_id, $shout_parameters);
         // Return a clean xml response
         Template_Layers::getInstance()->removeAll();
         $context['sub_template'] = 'shoutbox_xml';
         $context['SPortal']['updated'] = empty($context['SPortal']['shoutbox']['last_update']) || $context['SPortal']['shoutbox']['last_update'] > $request_time;
         return;
     }
     // Show all the shouts in this box
     $total_shouts = sportal_get_shoutbox_count($shoutbox_id);
     $context['per_page'] = $context['SPortal']['shoutbox']['num_show'];
     $context['start'] = !empty($_REQUEST['start']) ? (int) $_REQUEST['start'] : 0;
     $context['page_index'] = constructPageIndex($scripturl . '?action=shoutbox;shoutbox_id=' . $shoutbox_id, $context['start'], $total_shouts, $context['per_page']);
     $shout_parameters = array('start' => $context['start'], 'limit' => $context['per_page'], 'bbc' => $context['SPortal']['shoutbox']['allowed_bbc'], 'cache' => $context['SPortal']['shoutbox']['caching'], 'can_moderate' => $can_moderate);
     $context['SPortal']['shouts_history'] = sportal_get_shouts($shoutbox_id, $shout_parameters);
     $context['SPortal']['shoutbox_id'] = $shoutbox_id;
     $context['sub_template'] = 'shoutbox_all';
     $context['page_title'] = $context['SPortal']['shoutbox']['name'];
 }
/**
 * Shoutbox Block, show the shoutbox thoughts box
 *
 * @param mixed[] $parameters
 *		'shoutbox' => list of shoutboxes to choose from
 * @param int $id - not used in this block
 * @param boolean $return_parameters if true returns the configuration options for the block
 */
function sp_shoutbox($parameters, $id, $return_parameters = false)
{
    global $context, $modSettings, $user_info, $settings, $txt, $scripturl, $editortxt;
    $db = database();
    $block_parameters = array('shoutbox' => array());
    require_once SUBSDIR . '/PortalShoutbox.subs.php';
    // return the parameters for use in setting up the blocks
    if ($return_parameters) {
        $shoutboxes = sportal_get_shoutbox();
        $in_use = array();
        $request = $db->query('', '
			SELECT id_block, value
			FROM {db_prefix}sp_parameters
			WHERE variable = {string:name}', array('name' => 'shoutbox'));
        while ($row = $db->fetch_assoc($request)) {
            if (empty($_REQUEST['block_id']) || $_REQUEST['block_id'] != $row['id_block']) {
                $in_use[] = $row['value'];
            }
        }
        $db->free_result($request);
        // Load up all the shoutboxes that are NOT being used
        foreach ($shoutboxes as $shoutbox) {
            if (!in_array($shoutbox['id'], $in_use)) {
                $block_parameters['shoutbox'][$shoutbox['id']] = $shoutbox['name'];
            }
        }
        if (empty($block_parameters['shoutbox'])) {
            fatal_error(allowedTo(array('sp_admin', 'sp_manage_shoutbox')) ? $txt['error_sp_no_shoutbox'] . '<br />' . sprintf($txt['error_sp_no_shoutbox_sp_moderator'], $scripturl . '?action=admin;area=portalshoutbox;sa=add') : $txt['error_sp_no_shoutbox_normaluser'], false);
        }
        return $block_parameters;
    }
    loadTemplate('PortalShoutbox');
    loadLanguage('Editor');
    loadLanguage('Post');
    $shoutbox = sportal_get_shoutbox($parameters['shoutbox'], true, true);
    // To add a shoutbox you must have one or more defined for use
    if (empty($shoutbox)) {
        echo '
								', $txt['error_sp_shoutbox_not_exist'];
        return;
    }
    // Going to add to the shoutbox \
    if (!empty($_POST['new_shout']) && !empty($_POST['submit_shout']) && !empty($_POST['shoutbox_id']) && $_POST['shoutbox_id'] == $shoutbox['id']) {
        // Make sure things are in order
        checkSession();
        is_not_guest();
        if (!($flood = sp_prevent_flood('spsbp', false))) {
            require_once SUBSDIR . '/Post.subs.php';
            $_POST['new_shout'] = Util::htmlspecialchars(trim($_POST['new_shout']));
            preparsecode($_POST['new_shout']);
            if (!empty($_POST['new_shout'])) {
                sportal_create_shout($shoutbox, $_POST['new_shout']);
            }
        } else {
            $shoutbox['warning'] = $flood;
        }
    }
    // Can they moderate the shoutbox (delete shouts?)
    $can_moderate = allowedTo('sp_admin') || allowedTo('sp_manage_shoutbox');
    if (!$can_moderate && !empty($shoutbox['moderator_groups'])) {
        $can_moderate = count(array_intersect($user_info['groups'], $shoutbox['moderator_groups'])) > 0;
    }
    $shout_parameters = array('limit' => $shoutbox['num_show'], 'bbc' => $shoutbox['allowed_bbc'], 'reverse' => $shoutbox['reverse'], 'cache' => $shoutbox['caching'], 'can_moderate' => $can_moderate);
    $shoutbox['shouts'] = sportal_get_shouts($shoutbox['id'], $shout_parameters);
    $shoutbox['warning'] = parse_bbc($shoutbox['warning']);
    $context['can_shout'] = $context['user']['is_logged'];
    if ($context['can_shout']) {
        // Set up the smiley tags for the shoutbox
        $settings['smileys_url'] = $modSettings['smileys_url'] . '/' . $user_info['smiley_set'];
        $shoutbox['smileys'] = array('normal' => array(), 'popup' => array());
        if (empty($modSettings['smiley_enable'])) {
            $shoutbox['smileys']['normal'] = array(array('code' => ':)', 'filename' => 'smiley.gif', 'description' => $txt['icon_smiley']), array('code' => ';)', 'filename' => 'wink.gif', 'description' => $txt['icon_wink']), array('code' => ':D', 'filename' => 'cheesy.gif', 'description' => $txt['icon_cheesy']), array('code' => ';D', 'filename' => 'grin.gif', 'description' => $txt['icon_grin']), array('code' => '>:(', 'filename' => 'angry.gif', 'description' => $txt['icon_angry']), array('code' => ':(', 'filename' => 'sad.gif', 'description' => $txt['icon_sad']), array('code' => ':o', 'filename' => 'shocked.gif', 'description' => $txt['icon_shocked']), array('code' => '8)', 'filename' => 'cool.gif', 'description' => $txt['icon_cool']), array('code' => '???', 'filename' => 'huh.gif', 'description' => $txt['icon_huh']), array('code' => '::)', 'filename' => 'rolleyes.gif', 'description' => $txt['icon_rolleyes']), array('code' => ':P', 'filename' => 'tongue.gif', 'description' => $txt['icon_tongue']), array('code' => ':-[', 'filename' => 'embarrassed.gif', 'description' => $txt['icon_embarrassed']), array('code' => ':-X', 'filename' => 'lipsrsealed.gif', 'description' => $txt['icon_lips']), array('code' => ':-\\', 'filename' => 'undecided.gif', 'description' => $txt['icon_undecided']), array('code' => ':-*', 'filename' => 'kiss.gif', 'description' => $txt['icon_kiss']), array('code' => ':\'(', 'filename' => 'cry.gif', 'description' => $txt['icon_cry']));
        } else {
            if (($temp = cache_get_data('shoutbox_smileys', 3600)) == null) {
                $request = $db->query('', '
					SELECT code, filename, description, smiley_row, hidden
					FROM {db_prefix}smileys
					WHERE hidden IN ({array_int:hidden})
					ORDER BY smiley_row, smiley_order', array('hidden' => array(0, 2)));
                while ($row = $db->fetch_assoc($request)) {
                    $row['filename'] = htmlspecialchars($row['filename']);
                    $row['description'] = htmlspecialchars($row['description']);
                    $row['code'] = htmlspecialchars($row['code']);
                    $shoutbox['smileys'][empty($row['hidden']) ? 'normal' : 'popup'][] = $row;
                }
                $db->free_result($request);
                cache_put_data('shoutbox_smileys', $shoutbox['smileys'], 3600);
            } else {
                $shoutbox['smileys'] = $temp;
            }
        }
        foreach (array_keys($shoutbox['smileys']) as $location) {
            $n = count($shoutbox['smileys'][$location]);
            for ($i = 0; $i < $n; $i++) {
                $shoutbox['smileys'][$location][$i]['code'] = addslashes($shoutbox['smileys'][$location][$i]['code']);
                $shoutbox['smileys'][$location][$i]['js_description'] = addslashes($shoutbox['smileys'][$location][$i]['description']);
            }
            if (!empty($shoutbox['smileys'][$location])) {
                $shoutbox['smileys'][$location][$n - 1]['last'] = true;
            }
        }
        // Basic shoutbox bbc we allow
        $shoutbox['bbc'] = array('bold' => array('code' => 'b', 'before' => '[b]', 'after' => '[/b]', 'description' => $editortxt['Bold']), 'italicize' => array('code' => 'i', 'before' => '[i]', 'after' => '[/i]', 'description' => $editortxt['Italic']), 'underline' => array('code' => 'u', 'before' => '[u]', 'after' => '[/u]', 'description' => $editortxt['Underline']), 'strike' => array('code' => 's', 'before' => '[s]', 'after' => '[/s]', 'description' => $editortxt['Strikethrough']), 'pre' => array('code' => 'pre', 'before' => '[pre]', 'after' => '[/pre]', 'description' => $editortxt['Preformatted Text']), 'img' => array('code' => 'img', 'before' => '[img]', 'after' => '[/img]', 'description' => $editortxt['Insert an image']), 'url' => array('code' => 'url', 'before' => '[url]', 'after' => '[/url]', 'description' => $editortxt['Insert a link']), 'email' => array('code' => 'email', 'before' => '[email]', 'after' => '[/email]', 'description' => $editortxt['Insert an email']), 'sup' => array('code' => 'sup', 'before' => '[sup]', 'after' => '[/sup]', 'description' => $editortxt['Superscript']), 'sub' => array('code' => 'sub', 'before' => '[sub]', 'after' => '[/sub]', 'description' => $editortxt['Subscript']), 'tele' => array('code' => 'tt', 'before' => '[tt]', 'after' => '[/tt]', 'description' => $editortxt['Teletype']), 'code' => array('code' => 'code', 'before' => '[code]', 'after' => '[/code]', 'description' => $editortxt['Code']), 'quote' => array('code' => 'quote', 'before' => '[quote]', 'after' => '[/quote]', 'description' => $editortxt['Insert a Quote']));
    }
    template_shoutbox_embed($shoutbox);
}
function sportal_admin_shoutbox_prune()
{
    global $smcFunc, $context, $txt;
    $shoutbox_id = empty($_REQUEST['shoutbox_id']) ? 0 : (int) $_REQUEST['shoutbox_id'];
    $context['shoutbox'] = sportal_get_shoutbox($shoutbox_id);
    if (empty($context['shoutbox'])) {
        fatal_lang_error('error_sp_shoutbox_not_exist', false);
    }
    if (!empty($_POST['submit'])) {
        checkSession();
        if (!empty($_POST['type'])) {
            $where = array('id_shoutbox = {int:shoutbox_id}');
            $parameters = array('shoutbox_id' => $shoutbox_id);
            if ($_POST['type'] == 'days' && !empty($_POST['days'])) {
                $where[] = 'log_time < {int:time_limit}';
                $parameters['time_limit'] = time() - $_POST['days'] * 86400;
            } elseif ($_POST['type'] == 'member' && !empty($_POST['member'])) {
                $request = $smcFunc['db_query']('', '
					SELECT id_member
					FROM {db_prefix}members
					WHERE member_name = {string:member}
						OR real_name = {string:member}
					LIMIT {int:limit}', array('member' => strtr(trim($smcFunc['htmlspecialchars']($_POST['member'], ENT_QUOTES)), array('\'' => '&#039;')), 'limit' => 1));
                list($member_id) = $smcFunc['db_fetch_row']($request);
                $smcFunc['db_free_result']($request);
                if (!empty($member_id)) {
                    $where[] = 'id_member = {int:member_id}';
                    $parameters['member_id'] = $member_id;
                }
            }
            if ($_POST['type'] == 'all' || count($where) > 1) {
                $smcFunc['db_query']('', '
					DELETE FROM {db_prefix}sp_shouts
					WHERE ' . implode(' AND ', $where), $parameters);
                if ($_POST['type'] != 'all') {
                    $request = $smcFunc['db_query']('', '
						SELECT COUNT(*)
						FROM {db_prefix}sp_shouts
						WHERE id_shoutbox = {int:shoutbox_id}
						LIMIT {int:limit}', array('shoutbox_id' => $shoutbox_id, 'limit' => 1));
                    list($total_shouts) = $smcFunc['db_fetch_row']($request);
                    $smcFunc['db_free_result']($request);
                } else {
                    $total_shouts = 0;
                }
                $smcFunc['db_query']('', '
					UPDATE {db_prefix}sp_shoutboxes
					SET num_shouts = {int:total_shouts}
					WHERE id_shoutbox = {int:shoutbox_id}', array('shoutbox_id' => $shoutbox_id, 'total_shouts' => $total_shouts));
                sportal_update_shoutbox($shoutbox_id);
            }
        }
        redirectexit('action=admin;area=portalshoutbox');
    }
    $context['page_title'] = $txt['sp_admin_shoutbox_prune'];
    $context['sub_template'] = 'shoutbox_prune';
}
 /**
  * Who does not like prunes .. or maybe cut down the shout list
  */
 public function action_sportal_admin_shoutbox_prune()
 {
     global $context, $txt;
     $shoutbox_id = empty($_REQUEST['shoutbox_id']) ? 0 : (int) $_REQUEST['shoutbox_id'];
     $context['shoutbox'] = sportal_get_shoutbox($shoutbox_id);
     if (empty($context['shoutbox'])) {
         fatal_lang_error('error_sp_shoutbox_not_exist', false);
     }
     // Time to remove some chitta-chatta
     if (!empty($_POST['submit'])) {
         checkSession();
         if (!empty($_POST['type'])) {
             $where = array('id_shoutbox = {int:shoutbox_id}');
             $parameters = array('shoutbox_id' => $shoutbox_id);
             // Prune by days
             if ($_POST['type'] === 'days' && !empty($_POST['days'])) {
                 $where[] = 'log_time < {int:time_limit}';
                 $parameters['time_limit'] = time() - $_POST['days'] * 86400;
             } elseif ($_POST['type'] === 'member' && !empty($_POST['member'])) {
                 $member_id = sp_shoutbox_prune_member($_POST['member']);
                 if (!empty($member_id)) {
                     $where[] = 'id_member = {int:member_id}';
                     $parameters['member_id'] = $member_id;
                 }
             }
             // Execute the selective prune or clear the entire box
             if ($_POST['type'] === 'all' || count($where) > 1) {
                 sp_prune_shoutbox($shoutbox_id, $where, $parameters, $_POST['type'] === 'all');
                 sportal_update_shoutbox($shoutbox_id);
             }
         }
         redirectexit('action=admin;area=portalshoutbox');
     }
     loadJavascriptFile('suggest.js');
     $context['page_title'] = $txt['sp_admin_shoutbox_prune'];
     $context['sub_template'] = 'shoutbox_prune';
 }