コード例 #1
0
/**
 * Adds a new shout to a given box
 *
 * - Prevents guest from adding a shout
 * - Checks the shout total and archives if over the display limit for the box
 *
 * @param int $shoutbox
 * @param string $shout
 */
function sportal_create_shout($shoutbox, $shout)
{
    global $user_info;
    $db = database();
    // If a guest shouts in the woods, and no one is there to hear them
    if ($user_info['is_guest']) {
        return false;
    }
    // What, its not like we can shout to nothing
    if (empty($shoutbox)) {
        return false;
    }
    if (trim(strip_tags(parse_bbc($shout, false), '<img>')) === '') {
        return false;
    }
    // Add the shout
    $db->insert('', '
		{db_prefix}sp_shouts', array('id_shoutbox' => 'int', 'id_member' => 'int', 'member_name' => 'string', 'log_time' => 'int', 'body' => 'string'), array($shoutbox['id'], $user_info['id'], $user_info['name'], time(), $shout), array('id_shout'));
    // To many shouts in the box, then its archive maintenance time
    $shoutbox['num_shouts']++;
    if ($shoutbox['num_shouts'] > $shoutbox['num_max']) {
        $request = $db->query('', '
			SELECT id_shout
			FROM {db_prefix}sp_shouts
			WHERE id_shoutbox = {int:shoutbox}
			ORDER BY log_time
			LIMIT {int:limit}', array('shoutbox' => $shoutbox['id'], 'limit' => $shoutbox['num_shouts'] - $shoutbox['num_max']));
        $old_shouts = array();
        while ($row = $db->fetch_assoc($request)) {
            $old_shouts[] = $row['id_shout'];
        }
        $db->free_result($request);
        sportal_delete_shout($shoutbox['id'], $old_shouts, true);
    } else {
        sportal_update_shoutbox($shoutbox['id'], true);
    }
    return true;
}
コード例 #2
0
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'];
}
コード例 #3
0
function sportal_create_shout($shoutbox, $shout)
{
    global $smcFunc, $user_info;
    if ($user_info['is_guest']) {
        return false;
    }
    if (empty($shoutbox)) {
        return false;
    }
    if (trim(strip_tags(parse_bbc($shout, false), '<img>')) === '') {
        return false;
    }
    $smcFunc['db_insert']('', '{db_prefix}sp_shouts', array('id_shoutbox' => 'int', 'id_member' => 'int', 'member_name' => 'string', 'log_time' => 'int', 'body' => 'string'), array($shoutbox['id'], $user_info['id'], $user_info['name'], time(), $shout), array('id_shout'));
    $shoutbox['num_shouts']++;
    if ($shoutbox['num_shouts'] > $shoutbox['num_max']) {
        $request = $smcFunc['db_query']('', '
			SELECT id_shout
			FROM {db_prefix}sp_shouts
			WHERE id_shoutbox = {int:shoutbox}
			ORDER BY log_time
			LIMIT {int:limit}', array('shoutbox' => $shoutbox['id'], 'limit' => $shoutbox['num_shouts'] - $shoutbox['num_max']));
        $old_shouts = array();
        while ($row = $smcFunc['db_fetch_assoc']($request)) {
            $old_shouts[] = $row['id_shout'];
        }
        $smcFunc['db_free_result']($request);
        sportal_delete_shout($shoutbox['id'], $old_shouts, true);
    } else {
        sportal_update_shoutbox($shoutbox['id'], true);
    }
}
コード例 #4
0
 /**
  * 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'];
 }