/**
  * Loads article previews for display with the portal index template
  */
 public function action_sportal_index()
 {
     global $context, $modSettings;
     // Showing articles on the index page?
     if (!empty($modSettings['sp_articles_index'])) {
         require_once SUBSDIR . '/PortalArticle.subs.php';
         $context['sub_template'] = 'portal_index';
         // Set up the pages
         $total_articles = sportal_get_articles_count();
         $total = min($total_articles, !empty($modSettings['sp_articles_index_total']) ? $modSettings['sp_articles_index_total'] : 20);
         $per_page = min($total, !empty($modSettings['sp_articles_index_per_page']) ? $modSettings['sp_articles_index_per_page'] : 5);
         $start = !empty($_REQUEST['articles']) ? (int) $_REQUEST['articles'] : 0;
         if ($total > $per_page) {
             $context['article_page_index'] = constructPageIndex($context['portal_url'] . '?articles=%1$d', $start, $total, $per_page, true);
         }
         // If we have some articles
         require_once SUBSDIR . '/PortalArticle.subs.php';
         $context['articles'] = sportal_get_articles(0, true, true, 'spa.id_article DESC', 0, $per_page, $start);
         foreach ($context['articles'] as $article) {
             if (empty($modSettings['sp_articles_length']) && ($cutoff = Util::strpos($article['body'], '[cutoff]')) !== false) {
                 $article['body'] = Util::substr($article['body'], 0, $cutoff);
                 if ($article['type'] === 'bbc') {
                     require_once SUBSDIR . '/Post.subs.php';
                     preparsecode($article['body']);
                 }
             }
             $context['articles'][$article['id']]['preview'] = sportal_parse_content($article['body'], $article['type'], 'return');
             $context['articles'][$article['id']]['date'] = htmlTime($article['date']);
             // Just want a shorter look on the index page
             if (!empty($modSettings['sp_articles_length'])) {
                 $context['articles'][$article['id']]['preview'] = Util::shorten_html($context['articles'][$article['id']]['preview'], $modSettings['sp_articles_length']);
             }
         }
     }
 }
Exemplo n.º 2
0
/**
 * Gets data from the error log
 *
 * @param int $start
 * @param string $sort_direction
 * @param mixed[]|null $filter
 */
function getErrorLogData($start, $sort_direction = 'DESC', $filter = null)
{
    global $modSettings, $scripturl, $txt;
    $db = database();
    // Find and sort out the errors.
    $request = $db->query('', '
		SELECT id_error, id_member, ip, url, log_time, message, session, error_type, file, line
		FROM {db_prefix}log_errors' . (isset($filter) ? '
		WHERE ' . $filter['variable'] . ' LIKE {string:filter}' : '') . '
		ORDER BY id_error ' . ($sort_direction == 'down' ? 'DESC' : '') . '
		LIMIT ' . $start . ', ' . $modSettings['defaultMaxMessages'], array('filter' => isset($filter) ? $filter['value']['sql'] : ''));
    $log = array();
    for ($i = 0; $row = $db->fetch_assoc($request); $i++) {
        $search_message = preg_replace('~<span class="remove">(.+?)</span>~', '%', $db->escape_wildcard_string($row['message']));
        if ($search_message == $filter['value']['sql']) {
            $search_message = $db->escape_wildcard_string($row['message']);
        }
        $show_message = strtr(strtr(preg_replace('~&lt;span class=&quot;remove&quot;&gt;(.+?)&lt;/span&gt;~', '$1', $row['message']), array("\r" => '', '<br />' => "\n", '<' => '&lt;', '>' => '&gt;', '"' => '&quot;')), array("\n" => '<br />'));
        $log['errors'][$row['id_error']] = array('alternate' => $i % 2 == 0, 'member' => array('id' => $row['id_member'], 'ip' => $row['ip'], 'session' => $row['session']), 'time' => standardTime($row['log_time']), 'html_time' => htmlTime($row['log_time']), 'timestamp' => forum_time(true, $row['log_time']), 'url' => array('html' => htmlspecialchars((substr($row['url'], 0, 1) == '?' ? $scripturl : '') . $row['url'], ENT_COMPAT, 'UTF-8'), 'href' => base64_encode($db->escape_wildcard_string($row['url']))), 'message' => array('html' => $show_message, 'href' => base64_encode($search_message)), 'id' => $row['id_error'], 'error_type' => array('type' => $row['error_type'], 'name' => isset($txt['errortype_' . $row['error_type']]) ? $txt['errortype_' . $row['error_type']] : $row['error_type']), 'file' => array());
        if (!empty($row['file']) && !empty($row['line'])) {
            // Eval'd files rarely point to the right location and cause havoc for linking, so don't link them.
            $linkfile = strpos($row['file'], 'eval') === false || strpos($row['file'], '?') === false;
            // De Morgan's Law.  Want this true unless both are present.
            $log['errors'][$row['id_error']]['file'] = array('file' => $row['file'], 'line' => $row['line'], 'href' => $scripturl . '?action=admin;area=logs;sa=errorlog;activity=file;file=' . base64_encode($row['file']) . ';line=' . $row['line'], 'link' => $linkfile ? '<a href="' . $scripturl . '?action=admin;area=logs;sa=errorlog;activity=file;file=' . base64_encode($row['file']) . ';line=' . $row['line'] . '" onclick="return reqWin(this.href, 600, 480, false);">' . $row['file'] . '</a>' : $row['file'], 'search' => base64_encode($row['file']));
        }
        // Make a list of members to load later.
        $log['members'][$row['id_member']] = $row['id_member'];
    }
    $db->free_result($request);
    return $log;
}
 /**
  * View a specific category, showing all articles it contains
  */
 public function action_sportal_category()
 {
     global $context, $scripturl, $modSettings;
     // Basic article support
     require_once SUBSDIR . '/PortalArticle.subs.php';
     $category_id = !empty($_REQUEST['category']) ? $_REQUEST['category'] : 0;
     if (is_int($category_id)) {
         $category_id = (int) $category_id;
     } else {
         $category_id = Util::htmlspecialchars($category_id, ENT_QUOTES);
     }
     $context['category'] = sportal_get_categories($category_id, true, true);
     if (empty($context['category']['id'])) {
         fatal_lang_error('error_sp_category_not_found', false);
     }
     // Set up the pages
     $total_articles = sportal_get_articles_in_cat_count($context['category']['id']);
     $per_page = min($total_articles, !empty($modSettings['sp_articles_per_page']) ? $modSettings['sp_articles_per_page'] : 10);
     $start = !empty($_REQUEST['start']) ? (int) $_REQUEST['start'] : 0;
     if ($total_articles > $per_page) {
         $context['page_index'] = constructPageIndex($context['category']['href'] . ';start=%1$d', $start, $total_articles, $per_page, true);
     }
     // Load the articles in this category
     $context['articles'] = sportal_get_articles(0, true, true, 'spa.id_article DESC', $context['category']['id'], $per_page, $start);
     foreach ($context['articles'] as $article) {
         // Cut me mick
         if (($cutoff = Util::strpos($article['body'], '[cutoff]')) !== false) {
             $article['body'] = Util::substr($article['body'], 0, $cutoff);
             if ($article['type'] === 'bbc') {
                 require_once SUBSDIR . '/Post.subs.php';
                 preparsecode($article['body']);
             }
         }
         $context['articles'][$article['id']]['preview'] = sportal_parse_content($article['body'], $article['type'], 'return');
         $context['articles'][$article['id']]['date'] = htmlTime($article['date']);
     }
     $context['linktree'][] = array('url' => $scripturl . '?category=' . $context['category']['category_id'], 'name' => $context['category']['name']);
     $context['page_title'] = $context['category']['name'];
     $context['sub_template'] = 'view_category';
 }
Exemplo n.º 4
0
 /**
  * Who's online, and what are they doing?
  * This function prepares the who's online data for the Who template.
  * It requires the who_view permission.
  * It is enabled with the who_enabled setting.
  * It is accessed via ?action=who.
  *
  * @uses Who template, main sub-template
  * @uses Who language file.
  */
 public function action_who()
 {
     global $context, $scripturl, $txt, $modSettings, $memberContext;
     // Permissions, permissions, permissions.
     isAllowedTo('who_view');
     // You can't do anything if this is off.
     if (empty($modSettings['who_enabled'])) {
         fatal_lang_error('who_off', false);
     }
     // Load the 'Who' template.
     loadTemplate('Who');
     loadLanguage('Who');
     // Sort out... the column sorting.
     $sort_methods = array('user' => 'mem.real_name', 'time' => 'lo.log_time');
     $show_methods = array('members' => '(lo.id_member != 0)', 'guests' => '(lo.id_member = 0)', 'all' => '1=1');
     // Store the sort methods and the show types for use in the template.
     $context['sort_methods'] = array('user' => $txt['who_user'], 'time' => $txt['who_time']);
     $context['show_methods'] = array('all' => $txt['who_show_all'], 'members' => $txt['who_show_members_only'], 'guests' => $txt['who_show_guests_only']);
     // Can they see spiders too?
     if (!empty($modSettings['show_spider_online']) && ($modSettings['show_spider_online'] == 2 || allowedTo('admin_forum')) && !empty($modSettings['spider_name_cache'])) {
         $show_methods['spiders'] = '(lo.id_member = 0 AND lo.id_spider > 0)';
         $show_methods['guests'] = '(lo.id_member = 0 AND lo.id_spider = 0)';
         $context['show_methods']['spiders'] = $txt['who_show_spiders_only'];
     } elseif (empty($modSettings['show_spider_online']) && isset($_SESSION['who_online_filter']) && $_SESSION['who_online_filter'] == 'spiders') {
         unset($_SESSION['who_online_filter']);
     }
     // Does the user prefer a different sort direction?
     if (isset($_REQUEST['sort']) && isset($sort_methods[$_REQUEST['sort']])) {
         $context['sort_by'] = $_SESSION['who_online_sort_by'] = $_REQUEST['sort'];
         $sort_method = $sort_methods[$_REQUEST['sort']];
     } elseif (isset($_SESSION['who_online_sort_by'])) {
         $context['sort_by'] = $_SESSION['who_online_sort_by'];
         $sort_method = $sort_methods[$_SESSION['who_online_sort_by']];
     } else {
         $context['sort_by'] = $_SESSION['who_online_sort_by'] = 'time';
         $sort_method = 'lo.log_time';
     }
     $context['sort_direction'] = isset($_REQUEST['asc']) || isset($_REQUEST['sort_dir']) && $_REQUEST['sort_dir'] == 'asc' ? 'up' : 'down';
     $conditions = array();
     if (!allowedTo('moderate_forum')) {
         $conditions[] = '(IFNULL(mem.show_online, 1) = 1)';
     }
     // Fallback to top filter?
     if (isset($_REQUEST['submit_top']) && isset($_REQUEST['show_top'])) {
         $_REQUEST['show'] = $_REQUEST['show_top'];
     }
     // Does the user wish to apply a filter?
     if (isset($_REQUEST['show']) && isset($show_methods[$_REQUEST['show']])) {
         $context['show_by'] = $_SESSION['who_online_filter'] = $_REQUEST['show'];
         $conditions[] = $show_methods[$_REQUEST['show']];
     } elseif (isset($_SESSION['who_online_filter'])) {
         $context['show_by'] = $_SESSION['who_online_filter'];
         $conditions[] = $show_methods[$_SESSION['who_online_filter']];
     } else {
         $context['show_by'] = $_SESSION['who_online_filter'] = 'all';
     }
     require_once SUBSDIR . '/Members.subs.php';
     $totalMembers = countMembersOnline($conditions);
     // Prepare some page index variables.
     $context['page_index'] = constructPageIndex($scripturl . '?action=who;sort=' . $context['sort_by'] . ($context['sort_direction'] == 'up' ? ';asc' : '') . ';show=' . $context['show_by'], $_REQUEST['start'], $totalMembers, $modSettings['defaultMaxMembers']);
     $context['start'] = $_REQUEST['start'];
     $context['sub_template'] = 'whos_online';
     Template_Layers::getInstance()->add('whos_selection');
     // Look for people online, provided they don't mind if you see they are.
     $members = onlineMembers($conditions, $sort_method, $context['sort_direction'], $context['start']);
     $context['members'] = array();
     $member_ids = array();
     $url_data = array();
     foreach ($members as $row) {
         $actions = @unserialize($row['url']);
         if ($actions === false) {
             continue;
         }
         // Send the information to the template.
         $context['members'][$row['session']] = array('id' => $row['id_member'], 'ip' => allowedTo('moderate_forum') ? $row['ip'] : '', 'time' => standardTime($row['log_time'], true), 'html_time' => htmlTime($row['log_time']), 'timestamp' => forum_time(true, $row['log_time']), 'query' => $actions, 'is_hidden' => $row['show_online'] == 0, 'id_spider' => $row['id_spider'], 'color' => empty($row['online_color']) ? '' : $row['online_color']);
         $url_data[$row['session']] = array($row['url'], $row['id_member']);
         $member_ids[] = $row['id_member'];
     }
     // Load the user data for these members.
     loadMemberData($member_ids);
     // Load up the guest user.
     $memberContext[0] = array('id' => 0, 'name' => $txt['guest_title'], 'group' => $txt['guest_title'], 'href' => '', 'link' => $txt['guest_title'], 'email' => $txt['guest_title'], 'is_guest' => true);
     // Are we showing spiders?
     $spiderContext = array();
     if (!empty($modSettings['show_spider_online']) && ($modSettings['show_spider_online'] == 2 || allowedTo('admin_forum')) && !empty($modSettings['spider_name_cache'])) {
         foreach (unserialize($modSettings['spider_name_cache']) as $id => $name) {
             $spiderContext[$id] = array('id' => 0, 'name' => $name, 'group' => $txt['spiders'], 'href' => '', 'link' => $name, 'email' => $name, 'is_guest' => true);
         }
     }
     require_once SUBSDIR . '/Who.subs.php';
     $url_data = determineActions($url_data);
     // Setup the linktree and page title (do it down here because the language files are now loaded..)
     $context['page_title'] = $txt['who_title'];
     $context['linktree'][] = array('url' => $scripturl . '?action=who', 'name' => $txt['who_title']);
     // Put it in the context variables.
     foreach ($context['members'] as $i => $member) {
         if ($member['id'] != 0) {
             $member['id'] = loadMemberContext($member['id']) ? $member['id'] : 0;
         }
         // Keep the IP that came from the database.
         $memberContext[$member['id']]['ip'] = $member['ip'];
         $context['members'][$i]['action'] = isset($url_data[$i]) ? $url_data[$i] : $txt['who_hidden'];
         if ($member['id'] == 0 && isset($spiderContext[$member['id_spider']])) {
             $context['members'][$i] += $spiderContext[$member['id_spider']];
         } else {
             $context['members'][$i] += $memberContext[$member['id']];
         }
     }
     // Some people can't send personal messages...
     $context['can_send_pm'] = allowedTo('pm_send');
     $context['can_send_email'] = allowedTo('send_email_to_members');
     // Any profile fields disabled?
     $context['disabled_fields'] = isset($modSettings['disabled_profile_fields']) ? array_flip(explode(',', $modSettings['disabled_profile_fields'])) : array();
 }
Exemplo n.º 5
0
/**
 * Make sure the "current user" (uses $user_info) cannot go outside of the limit for the day.
 *
 * @param string $approve_query additional condition for the query
 * @param string $current_view defined whether return the topics (first
 *                messages) or the messages. If set to 'topics' it returns
 *                the topics, otherwise the messages
 * @param mixed[] $boards_allowed array of arrays, it must contain three
 *                 indexes:
 *                  - delete_own_boards
 *                  - delete_any_boards
 *                  - delete_own_replies
 *                 each of which must be an array of boards the user is allowed
 *                 to perform a certain action (return of boardsAllowedTo)
 * @param int $start start of the query LIMIT
 * @param int $limit number of elements to return (default 10)
 */
function getUnapprovedPosts($approve_query, $current_view, $boards_allowed, $start, $limit = 10)
{
    global $context, $scripturl, $user_info;
    $db = database();
    $request = $db->query('', '
		SELECT m.id_msg, m.id_topic, m.id_board, m.subject, m.body, m.id_member,
			IFNULL(mem.real_name, m.poster_name) AS poster_name, m.poster_time, m.smileys_enabled,
			t.id_member_started, t.id_first_msg, b.name AS board_name, c.id_cat, c.name AS cat_name
		FROM {db_prefix}messages AS m
			INNER JOIN {db_prefix}topics AS t ON (t.id_topic = m.id_topic)
			INNER JOIN {db_prefix}boards AS b ON (b.id_board = m.id_board)
			LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = m.id_member)
			LEFT JOIN {db_prefix}categories AS c ON (c.id_cat = b.id_cat)
		WHERE m.approved = {int:not_approved}
			AND t.id_first_msg ' . ($current_view == 'topics' ? '=' : '!=') . ' m.id_msg
			AND {query_see_board}
			' . $approve_query . '
		LIMIT {int:start}, {int:limit}', array('start' => $start, 'limit' => $limit, 'not_approved' => 0));
    $unapproved_items = array();
    for ($i = 1; $row = $db->fetch_assoc($request); $i++) {
        // Can delete is complicated, let's solve it first... is it their own post?
        if ($row['id_member'] == $user_info['id'] && ($boards_allowed['delete_own_boards'] == array(0) || in_array($row['id_board'], $boards_allowed['delete_own_boards']))) {
            $can_delete = true;
        } elseif ($row['id_member'] == $row['id_member_started'] && $row['id_msg'] != $row['id_first_msg'] && ($boards_allowed['delete_own_replies'] == array(0) || in_array($row['id_board'], $boards_allowed['delete_own_replies']))) {
            $can_delete = true;
        } elseif ($row['id_member'] != $user_info['id'] && ($boards_allowed['delete_any_boards'] == array(0) || in_array($row['id_board'], $boards_allowed['delete_any_boards']))) {
            $can_delete = true;
        } else {
            $can_delete = false;
        }
        $unapproved_items[] = array('id' => $row['id_msg'], 'alternate' => $i % 2, 'counter' => $context['start'] + $i, 'href' => $scripturl . '?topic=' . $row['id_topic'] . '.msg' . $row['id_msg'] . '#msg' . $row['id_msg'], 'link' => '<a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.msg' . $row['id_msg'] . '#msg' . $row['id_msg'] . '">' . $row['subject'] . '</a>', 'subject' => $row['subject'], 'body' => parse_bbc($row['body'], $row['smileys_enabled'], $row['id_msg']), 'time' => standardTime($row['poster_time']), 'html_time' => htmlTime($row['poster_time']), 'timestamp' => forum_time(true, $row['poster_time']), 'poster' => array('id' => $row['id_member'], 'name' => $row['poster_name'], 'link' => $row['id_member'] ? '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['poster_name'] . '</a>' : $row['poster_name'], 'href' => $scripturl . '?action=profile;u=' . $row['id_member']), 'topic' => array('id' => $row['id_topic']), 'board' => array('id' => $row['id_board'], 'name' => $row['board_name'], 'link' => '<a href="' . $scripturl . '?board=' . $row['id_board'] . '.0">' . $row['board_name'] . '</a>'), 'category' => array('id' => $row['id_cat'], 'name' => $row['cat_name'], 'link' => '<a href="' . $scripturl . '#c' . $row['id_cat'] . '">' . $row['cat_name'] . '</a>'), 'can_delete' => $can_delete);
    }
    $db->free_result($request);
    return $unapproved_items;
}
Exemplo n.º 6
0
 /**
  * Callback to return messages - saves memory.
  *
  * @todo Fix this, update it, whatever... from Display.controller.php mainly.
  * Note that the call to loadAttachmentContext() doesn't work:
  * this function doesn't fulfill the pre-condition to fill $attachments global...
  * So all it does is to fallback and return.
  *
  * What it does:
  * - callback function for the results sub template.
  * - loads the necessary contextual data to show a search result.
  *
  * @param boolean $reset = false
  * @return array of messages that match the search
  */
 public function prepareSearchContext_callback($reset = false)
 {
     global $txt, $modSettings, $scripturl, $user_info;
     global $memberContext, $context, $settings, $options, $messages_request;
     global $boards_can, $participants;
     // Remember which message this is.  (ie. reply #83)
     static $counter = null;
     if ($counter == null || $reset) {
         $counter = $_REQUEST['start'] + 1;
     }
     // Start from the beginning...
     if ($reset) {
         return currentContext($messages_request, $reset);
     }
     // Attempt to get the next in line
     $message = currentContext($messages_request);
     if (!$message) {
         return false;
     }
     // Can't have an empty subject can we?
     $message['subject'] = $message['subject'] != '' ? $message['subject'] : $txt['no_subject'];
     $message['first_subject'] = $message['first_subject'] != '' ? $message['first_subject'] : $txt['no_subject'];
     $message['last_subject'] = $message['last_subject'] != '' ? $message['last_subject'] : $txt['no_subject'];
     // If it couldn't load, or the user was a guest.... someday may be done with a guest table.
     if (!loadMemberContext($message['id_member'])) {
         // Notice this information isn't used anywhere else.... *cough guest table cough*.
         $memberContext[$message['id_member']]['name'] = $message['poster_name'];
         $memberContext[$message['id_member']]['id'] = 0;
         $memberContext[$message['id_member']]['group'] = $txt['guest_title'];
         $memberContext[$message['id_member']]['link'] = $message['poster_name'];
         $memberContext[$message['id_member']]['email'] = $message['poster_email'];
     }
     $memberContext[$message['id_member']]['ip'] = $message['poster_ip'];
     // Do the censor thang...
     censorText($message['body']);
     censorText($message['subject']);
     censorText($message['first_subject']);
     censorText($message['last_subject']);
     // Shorten this message if necessary.
     if ($context['compact']) {
         // Set the number of characters before and after the searched keyword.
         $charLimit = 50;
         $message['body'] = strtr($message['body'], array("\n" => ' ', '<br />' => "\n"));
         $message['body'] = parse_bbc($message['body'], $message['smileys_enabled'], $message['id_msg']);
         $message['body'] = strip_tags(strtr($message['body'], array('</div>' => '<br />', '</li>' => '<br />')), '<br>');
         if (Util::strlen($message['body']) > $charLimit) {
             if (empty($context['key_words'])) {
                 $message['body'] = Util::substr($message['body'], 0, $charLimit) . '<strong>...</strong>';
             } else {
                 $matchString = '';
                 $force_partial_word = false;
                 foreach ($context['key_words'] as $keyword) {
                     $keyword = un_htmlspecialchars($keyword);
                     $keyword = preg_replace_callback('~(&amp;#(\\d{1,7}|x[0-9a-fA-F]{1,6});)~', 'entity_fix__callback', strtr($keyword, array('\\\'' => '\'', '&' => '&amp;')));
                     if (preg_match('~[\'\\.,/@%&;:(){}\\[\\]_\\-+\\\\]$~', $keyword) != 0 || preg_match('~^[\'\\.,/@%&;:(){}\\[\\]_\\-+\\\\]~', $keyword) != 0) {
                         $force_partial_word = true;
                     }
                     $matchString .= strtr(preg_quote($keyword, '/'), array('\\*' => '.+?')) . '|';
                 }
                 $matchString = un_htmlspecialchars(substr($matchString, 0, -1));
                 $message['body'] = un_htmlspecialchars(strtr($message['body'], array('&nbsp;' => ' ', '<br />' => "\n", '&#91;' => '[', '&#93;' => ']', '&#58;' => ':', '&#64;' => '@')));
                 if (empty($modSettings['search_method']) || $force_partial_word) {
                     preg_match_all('/([^\\s\\W]{' . $charLimit . '}[\\s\\W]|[\\s\\W].{0,' . $charLimit . '}?|^)(' . $matchString . ')(.{0,' . $charLimit . '}[\\s\\W]|[^\\s\\W]{0,' . $charLimit . '})/isu', $message['body'], $matches);
                 } else {
                     preg_match_all('/([^\\s\\W]{' . $charLimit . '}[\\s\\W]|[\\s\\W].{0,' . $charLimit . '}?[\\s\\W]|^)(' . $matchString . ')([\\s\\W].{0,' . $charLimit . '}[\\s\\W]|[\\s\\W][^\\s\\W]{0,' . $charLimit . '})/isu', $message['body'], $matches);
                 }
                 $message['body'] = '';
                 foreach ($matches[0] as $index => $match) {
                     $match = strtr(htmlspecialchars($match, ENT_QUOTES, 'UTF-8'), array("\n" => '&nbsp;'));
                     $message['body'] .= '<strong>......</strong>&nbsp;' . $match . '&nbsp;<strong>......</strong>';
                 }
             }
             // Re-fix the international characters.
             $message['body'] = preg_replace_callback('~(&amp;#(\\d{1,7}|x[0-9a-fA-F]{1,6});)~', 'entity_fix__callback', $message['body']);
         }
     } else {
         // Run BBC interpreter on the message.
         $message['body'] = parse_bbc($message['body'], $message['smileys_enabled'], $message['id_msg']);
     }
     // Make sure we don't end up with a practically empty message body.
     $message['body'] = preg_replace('~^(?:&nbsp;)+$~', '', $message['body']);
     // Sadly, we need to check that the icon is not broken.
     if (!empty($modSettings['messageIconChecks_enable'])) {
         if (!isset($context['icon_sources'][$message['first_icon']])) {
             $context['icon_sources'][$message['first_icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $message['first_icon'] . '.png') ? 'images_url' : 'default_images_url';
         }
         if (!isset($context['icon_sources'][$message['last_icon']])) {
             $context['icon_sources'][$message['last_icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $message['last_icon'] . '.png') ? 'images_url' : 'default_images_url';
         }
         if (!isset($context['icon_sources'][$message['icon']])) {
             $context['icon_sources'][$message['icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $message['icon'] . '.png') ? 'images_url' : 'default_images_url';
         }
     } else {
         if (!isset($context['icon_sources'][$message['first_icon']])) {
             $context['icon_sources'][$message['first_icon']] = 'images_url';
         }
         if (!isset($context['icon_sources'][$message['last_icon']])) {
             $context['icon_sources'][$message['last_icon']] = 'images_url';
         }
         if (!isset($context['icon_sources'][$message['icon']])) {
             $context['icon_sources'][$message['icon']] = 'images_url';
         }
     }
     // Do we have quote tag enabled?
     $quote_enabled = empty($modSettings['disabledBBC']) || !in_array('quote', explode(',', $modSettings['disabledBBC']));
     $output = array_merge($context['topics'][$message['id_msg']], array('id' => $message['id_topic'], 'is_sticky' => !empty($modSettings['enableStickyTopics']) && !empty($message['is_sticky']), 'is_locked' => !empty($message['locked']), 'is_poll' => !empty($modSettings['pollMode']) && $message['id_poll'] > 0, 'is_hot' => !empty($modSettings['useLikesNotViews']) ? $message['num_likes'] >= $modSettings['hotTopicPosts'] : $message['num_replies'] >= $modSettings['hotTopicPosts'], 'is_very_hot' => !empty($modSettings['useLikesNotViews']) ? $message['num_likes'] >= $modSettings['hotTopicVeryPosts'] : $message['num_replies'] >= $modSettings['hotTopicVeryPosts'], 'posted_in' => !empty($participants[$message['id_topic']]), 'views' => $message['num_views'], 'replies' => $message['num_replies'], 'tests' => array('can_reply' => in_array($message['id_board'], $boards_can['post_reply_any']) || in_array(0, $boards_can['post_reply_any']), 'can_quote' => (in_array($message['id_board'], $boards_can['post_reply_any']) || in_array(0, $boards_can['post_reply_any'])) && $quote_enabled, 'can_mark_notify' => in_array($message['id_board'], $boards_can['mark_any_notify']) || in_array(0, $boards_can['mark_any_notify']) && !$context['user']['is_guest']), 'first_post' => array('id' => $message['first_msg'], 'time' => standardTime($message['first_poster_time']), 'html_time' => htmlTime($message['first_poster_time']), 'timestamp' => forum_time(true, $message['first_poster_time']), 'subject' => $message['first_subject'], 'href' => $scripturl . '?topic=' . $message['id_topic'] . '.0', 'link' => '<a href="' . $scripturl . '?topic=' . $message['id_topic'] . '.0">' . $message['first_subject'] . '</a>', 'icon' => $message['first_icon'], 'icon_url' => $settings[$context['icon_sources'][$message['first_icon']]] . '/post/' . $message['first_icon'] . '.png', 'member' => array('id' => $message['first_member_id'], 'name' => $message['first_member_name'], 'href' => !empty($message['first_member_id']) ? $scripturl . '?action=profile;u=' . $message['first_member_id'] : '', 'link' => !empty($message['first_member_id']) ? '<a href="' . $scripturl . '?action=profile;u=' . $message['first_member_id'] . '" title="' . $txt['profile_of'] . ' ' . $message['first_member_name'] . '">' . $message['first_member_name'] . '</a>' : $message['first_member_name'])), 'last_post' => array('id' => $message['last_msg'], 'time' => standardTime($message['last_poster_time']), 'html_time' => htmlTime($message['last_poster_time']), 'timestamp' => forum_time(true, $message['last_poster_time']), 'subject' => $message['last_subject'], 'href' => $scripturl . '?topic=' . $message['id_topic'] . ($message['num_replies'] == 0 ? '.0' : '.msg' . $message['last_msg']) . '#msg' . $message['last_msg'], 'link' => '<a href="' . $scripturl . '?topic=' . $message['id_topic'] . ($message['num_replies'] == 0 ? '.0' : '.msg' . $message['last_msg']) . '#msg' . $message['last_msg'] . '">' . $message['last_subject'] . '</a>', 'icon' => $message['last_icon'], 'icon_url' => $settings[$context['icon_sources'][$message['last_icon']]] . '/post/' . $message['last_icon'] . '.png', 'member' => array('id' => $message['last_member_id'], 'name' => $message['last_member_name'], 'href' => !empty($message['last_member_id']) ? $scripturl . '?action=profile;u=' . $message['last_member_id'] : '', 'link' => !empty($message['last_member_id']) ? '<a href="' . $scripturl . '?action=profile;u=' . $message['last_member_id'] . '" title="' . $txt['profile_of'] . ' ' . $message['last_member_name'] . '">' . $message['last_member_name'] . '</a>' : $message['last_member_name'])), 'board' => array('id' => $message['id_board'], 'name' => $message['board_name'], 'href' => $scripturl . '?board=' . $message['id_board'] . '.0', 'link' => '<a href="' . $scripturl . '?board=' . $message['id_board'] . '.0">' . $message['board_name'] . '</a>'), 'category' => array('id' => $message['id_cat'], 'name' => $message['cat_name'], 'href' => $scripturl . '#c' . $message['id_cat'], 'link' => '<a href="' . $scripturl . '#c' . $message['id_cat'] . '">' . $message['cat_name'] . '</a>')));
     determineTopicClass($output);
     if ($output['posted_in']) {
         $output['class'] = 'my_' . $output['class'];
     }
     $body_highlighted = $message['body'];
     $subject_highlighted = $message['subject'];
     if (!empty($options['display_quick_mod'])) {
         $started = $output['first_post']['member']['id'] == $user_info['id'];
         $output['quick_mod'] = array('lock' => in_array(0, $boards_can['lock_any']) || in_array($output['board']['id'], $boards_can['lock_any']) || $started && (in_array(0, $boards_can['lock_own']) || in_array($output['board']['id'], $boards_can['lock_own'])), 'sticky' => (in_array(0, $boards_can['make_sticky']) || in_array($output['board']['id'], $boards_can['make_sticky'])) && !empty($modSettings['enableStickyTopics']), 'move' => in_array(0, $boards_can['move_any']) || in_array($output['board']['id'], $boards_can['move_any']) || $started && (in_array(0, $boards_can['move_own']) || in_array($output['board']['id'], $boards_can['move_own'])), 'remove' => in_array(0, $boards_can['remove_any']) || in_array($output['board']['id'], $boards_can['remove_any']) || $started && (in_array(0, $boards_can['remove_own']) || in_array($output['board']['id'], $boards_can['remove_own'])));
         $context['can_lock'] |= $output['quick_mod']['lock'];
         $context['can_sticky'] |= $output['quick_mod']['sticky'];
         $context['can_move'] |= $output['quick_mod']['move'];
         $context['can_remove'] |= $output['quick_mod']['remove'];
         $context['can_merge'] |= in_array($output['board']['id'], $boards_can['merge_any']);
         $context['can_markread'] = $context['user']['is_logged'];
         $context['qmod_actions'] = array('remove', 'lock', 'sticky', 'move', 'markread');
         call_integration_hook('integrate_quick_mod_actions_search');
     }
     foreach ($context['key_words'] as $query) {
         // Fix the international characters in the keyword too.
         $query = un_htmlspecialchars($query);
         $query = trim($query, '\\*+');
         $query = strtr(Util::htmlspecialchars($query), array('\\\'' => '\''));
         $body_highlighted = preg_replace_callback('/((<[^>]*)|' . preg_quote(strtr($query, array('\'' => '&#039;')), '/') . ')/iu', array($this, '_highlighted_callback'), $body_highlighted);
         $subject_highlighted = preg_replace('/(' . preg_quote($query, '/') . ')/iu', '<strong class="highlight">$1</strong>', $subject_highlighted);
     }
     require_once SUBSDIR . '/Attachments.subs.php';
     $output['matches'][] = array('id' => $message['id_msg'], 'attachment' => loadAttachmentContext($message['id_msg']), 'alternate' => $counter % 2, 'member' => &$memberContext[$message['id_member']], 'icon' => $message['icon'], 'icon_url' => $settings[$context['icon_sources'][$message['icon']]] . '/post/' . $message['icon'] . '.png', 'subject' => $message['subject'], 'subject_highlighted' => $subject_highlighted, 'time' => standardTime($message['poster_time']), 'html_time' => htmlTime($message['poster_time']), 'timestamp' => forum_time(true, $message['poster_time']), 'counter' => $counter, 'modified' => array('time' => standardTime($message['modified_time']), 'html_time' => htmlTime($message['modified_time']), 'timestamp' => forum_time(true, $message['modified_time']), 'name' => $message['modified_name']), 'body' => $message['body'], 'body_highlighted' => $body_highlighted, 'start' => 'msg' . $message['id_msg']);
     $counter++;
     if (!$context['compact']) {
         $output['buttons'] = array('notify' => array('href' => $scripturl . '?action=notify;topic=' . $output['id'] . '.msg' . $message['id_msg'], 'text' => $txt['notify'], 'test' => 'can_mark_notify'), 'reply' => array('href' => $scripturl . '?action=post;topic=' . $output['id'] . '.msg' . $message['id_msg'], 'text' => $txt['reply'], 'test' => 'can_reply'), 'quote' => array('href' => $scripturl . '?action=post;topic=' . $output['id'] . '.msg' . $message['id_msg'] . ';quote=' . $message['id_msg'], 'text' => $txt['quote'], 'test' => 'can_quote'));
     }
     call_integration_hook('integrate_search_message_context', array($counter, &$output));
     return $output;
 }
Exemplo n.º 7
0
/**
 * Gets the moderation log entries that match the specified parameters.
 * Callback for createList() in Modlog::action_log().
 *
 * @param int $start
 * @param int $items_per_page
 * @param string $sort
 * @param string|null $query_string
 * @param mixed[] $query_params
 * @param int $log_type
 */
function list_getModLogEntries($start, $items_per_page, $sort, $query_string = '', $query_params = array(), $log_type = 1)
{
    global $context, $scripturl, $txt, $user_info;
    $db = database();
    $modlog_query = allowedTo('admin_forum') || $user_info['mod_cache']['bq'] == '1=1' ? '1=1' : ($user_info['mod_cache']['bq'] == '0=1' ? 'lm.id_board = 0 AND lm.id_topic = 0' : strtr($user_info['mod_cache']['bq'], array('id_board' => 'b.id_board')) . ' AND ' . strtr($user_info['mod_cache']['bq'], array('id_board' => 't.id_board')));
    // Do a little bit of self protection.
    if (!isset($context['hoursdisable'])) {
        $context['hoursdisable'] = 24;
    }
    // Can they see the IP address?
    $seeIP = allowedTo('moderate_forum');
    // Here we have the query getting the log details.
    $result = $db->query('', '
		SELECT
			lm.id_action, lm.id_member, lm.ip, lm.log_time, lm.action, lm.id_board, lm.id_topic, lm.id_msg, lm.extra,
			mem.real_name, mg.group_name
		FROM {db_prefix}log_actions AS lm
			LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = lm.id_member)
			LEFT JOIN {db_prefix}membergroups AS mg ON (mg.id_group = CASE WHEN mem.id_group = {int:reg_group_id} THEN mem.id_post_group ELSE mem.id_group END)
			LEFT JOIN {db_prefix}boards AS b ON (b.id_board = lm.id_board)
			LEFT JOIN {db_prefix}topics AS t ON (t.id_topic = lm.id_topic)
			WHERE id_log = {int:log_type}
				AND {raw:modlog_query}' . (!empty($query_string) ? '
				AND ' . $query_string : '') . '
		ORDER BY ' . $sort . '
		LIMIT ' . $start . ', ' . $items_per_page, array_merge($query_params, array('reg_group_id' => 0, 'log_type' => $log_type, 'modlog_query' => $modlog_query)));
    // Arrays for decoding objects into.
    $topics = array();
    $boards = array();
    $members = array();
    $messages = array();
    $entries = array();
    while ($row = $db->fetch_assoc($result)) {
        $row['extra'] = @unserialize($row['extra']);
        // Corrupt?
        $row['extra'] = is_array($row['extra']) ? $row['extra'] : array();
        // Add on some of the column stuff info
        if (!empty($row['id_board'])) {
            if ($row['action'] == 'move') {
                $row['extra']['board_to'] = $row['id_board'];
            } else {
                $row['extra']['board'] = $row['id_board'];
            }
        }
        if (!empty($row['id_topic'])) {
            $row['extra']['topic'] = $row['id_topic'];
        }
        if (!empty($row['id_msg'])) {
            $row['extra']['message'] = $row['id_msg'];
        }
        // Is this associated with a topic?
        if (isset($row['extra']['topic'])) {
            $topics[(int) $row['extra']['topic']][] = $row['id_action'];
        }
        if (isset($row['extra']['new_topic'])) {
            $topics[(int) $row['extra']['new_topic']][] = $row['id_action'];
        }
        // How about a member?
        if (isset($row['extra']['member'])) {
            // Guests don't have names!
            if (empty($row['extra']['member'])) {
                $row['extra']['member'] = $txt['modlog_parameter_guest'];
            } else {
                // Try to find it...
                $members[(int) $row['extra']['member']][] = $row['id_action'];
            }
        }
        // Associated with a board?
        if (isset($row['extra']['board_to'])) {
            $boards[(int) $row['extra']['board_to']][] = $row['id_action'];
        }
        if (isset($row['extra']['board_from'])) {
            $boards[(int) $row['extra']['board_from']][] = $row['id_action'];
        }
        if (isset($row['extra']['board'])) {
            $boards[(int) $row['extra']['board']][] = $row['id_action'];
        }
        // A message?
        if (isset($row['extra']['message'])) {
            $messages[(int) $row['extra']['message']][] = $row['id_action'];
        }
        // IP Info?
        if (isset($row['extra']['ip_range'])) {
            if ($seeIP) {
                $row['extra']['ip_range'] = '<a href="' . $scripturl . '?action=trackip;searchip=' . $row['extra']['ip_range'] . '">' . $row['extra']['ip_range'] . '</a>';
            } else {
                $row['extra']['ip_range'] = $txt['logged'];
            }
        }
        // Email?
        if (isset($row['extra']['email'])) {
            $row['extra']['email'] = '<a href="mailto:' . $row['extra']['email'] . '">' . $row['extra']['email'] . '</a>';
        }
        // Bans are complex.
        if ($row['action'] == 'ban') {
            if (!isset($row['extra']['new']) || $row['extra']['new'] == 1) {
                $row['action_text'] = $txt['modlog_ac_ban'];
            } elseif ($row['extra']['new'] == 0) {
                $row['action_text'] = $txt['modlog_ac_ban_update'];
            } else {
                $row['action_text'] = $txt['modlog_ac_ban_remove'];
            }
            foreach (array('member', 'email', 'ip_range', 'hostname') as $type) {
                if (isset($row['extra'][$type])) {
                    $row['action_text'] .= $txt['modlog_ac_ban_trigger_' . $type];
                }
            }
        }
        // The array to go to the template. Note here that action is set to a "default" value of the action doesn't match anything in the descriptions. Allows easy adding of logging events with basic details.
        $entries[$row['id_action']] = array('id' => $row['id_action'], 'ip' => $seeIP ? $row['ip'] : $txt['logged'], 'position' => empty($row['real_name']) && empty($row['group_name']) ? $txt['guest'] : $row['group_name'], 'moderator_link' => $row['id_member'] ? '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['real_name'] . '</a>' : (empty($row['real_name']) ? $txt['guest'] . (!empty($row['extra']['member_acted']) ? ' (' . $row['extra']['member_acted'] . ')' : '') : $row['real_name']), 'time' => standardTime($row['log_time']), 'html_time' => htmlTime($row['log_time']), 'timestamp' => forum_time(true, $row['log_time']), 'editable' => time() > $row['log_time'] + $context['hoursdisable'] * 3600, 'extra' => $row['extra'], 'action' => $row['action'], 'action_text' => isset($row['action_text']) ? $row['action_text'] : '');
    }
    $db->free_result($result);
    if (!empty($boards)) {
        require_once SUBSDIR . '/Boards.subs.php';
        $boards_info = fetchBoardsInfo(array('boards' => array_keys($boards)));
        foreach ($boards_info as $row) {
            foreach ($boards[$row['id_board']] as $action) {
                // Make the board number into a link - dealing with moving too.
                if (isset($entries[$action]['extra']['board_to']) && $entries[$action]['extra']['board_to'] == $row['id_board']) {
                    $entries[$action]['extra']['board_to'] = '<a href="' . $scripturl . '?board=' . $row['id_board'] . '.0">' . $row['name'] . '</a>';
                } elseif (isset($entries[$action]['extra']['board_from']) && $entries[$action]['extra']['board_from'] == $row['id_board']) {
                    $entries[$action]['extra']['board_from'] = '<a href="' . $scripturl . '?board=' . $row['id_board'] . '.0">' . $row['name'] . '</a>';
                } elseif (isset($entries[$action]['extra']['board']) && $entries[$action]['extra']['board'] == $row['id_board']) {
                    $entries[$action]['extra']['board'] = '<a href="' . $scripturl . '?board=' . $row['id_board'] . '.0">' . $row['name'] . '</a>';
                }
            }
        }
    }
    if (!empty($topics)) {
        $request = $db->query('', '
			SELECT ms.subject, t.id_topic
			FROM {db_prefix}topics AS t
				INNER JOIN {db_prefix}messages AS ms ON (ms.id_msg = t.id_first_msg)
			WHERE t.id_topic IN ({array_int:topic_list})
			LIMIT ' . count(array_keys($topics)), array('topic_list' => array_keys($topics)));
        while ($row = $db->fetch_assoc($request)) {
            foreach ($topics[$row['id_topic']] as $action) {
                $this_action =& $entries[$action];
                // This isn't used in the current theme.
                $this_action['topic'] = array('id' => $row['id_topic'], 'subject' => $row['subject'], 'href' => $scripturl . '?topic=' . $row['id_topic'] . '.0', 'link' => '<a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.0">' . $row['subject'] . '</a>');
                // Make the topic number into a link - dealing with splitting too.
                if (isset($this_action['extra']['topic']) && $this_action['extra']['topic'] == $row['id_topic']) {
                    $this_action['extra']['topic'] = '<a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.' . (isset($this_action['extra']['message']) ? 'msg' . $this_action['extra']['message'] . '#msg' . $this_action['extra']['message'] : '0') . '">' . $row['subject'] . '</a>';
                } elseif (isset($this_action['extra']['new_topic']) && $this_action['extra']['new_topic'] == $row['id_topic']) {
                    $this_action['extra']['new_topic'] = '<a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.' . (isset($this_action['extra']['message']) ? 'msg' . $this_action['extra']['message'] . '#msg' . $this_action['extra']['message'] : '0') . '">' . $row['subject'] . '</a>';
                }
            }
        }
        $db->free_result($request);
    }
    if (!empty($messages)) {
        $request = $db->query('', '
			SELECT id_msg, subject
			FROM {db_prefix}messages
			WHERE id_msg IN ({array_int:message_list})
			LIMIT ' . count(array_keys($messages)), array('message_list' => array_keys($messages)));
        while ($row = $db->fetch_assoc($request)) {
            foreach ($messages[$row['id_msg']] as $action) {
                $this_action =& $entries[$action];
                // This isn't used in the current theme.
                $this_action['message'] = array('id' => $row['id_msg'], 'subject' => $row['subject'], 'href' => $scripturl . '?msg=' . $row['id_msg'], 'link' => '<a href="' . $scripturl . '?msg=' . $row['id_msg'] . '">' . $row['subject'] . '</a>');
                // Make the message number into a link.
                if (isset($this_action['extra']['message']) && $this_action['extra']['message'] == $row['id_msg']) {
                    $this_action['extra']['message'] = '<a href="' . $scripturl . '?msg=' . $row['id_msg'] . '">' . $row['subject'] . '</a>';
                }
            }
        }
        $db->free_result($request);
    }
    if (!empty($members)) {
        require_once SUBSDIR . '/Members.subs.php';
        // Get the latest activated member's display name.
        $result = getBasicMemberData(array_keys($members));
        foreach ($result as $row) {
            foreach ($members[$row['id_member']] as $action) {
                // Not used currently.
                $entries[$action]['member'] = array('id' => $row['id_member'], 'name' => $row['real_name'], 'href' => $scripturl . '?action=profile;u=' . $row['id_member'], 'link' => '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['real_name'] . '</a>');
                // Make the member number into a name.
                $entries[$action]['extra']['member'] = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['real_name'] . '</a>';
            }
        }
    }
    // Do some formatting of the action string.
    $callback = new ModLogEntriesReplacement();
    $callback->entries = $entries;
    foreach ($entries as $k => $entry) {
        // Make any message info links so its easier to go find that message.
        if (isset($entry['extra']['message']) && (empty($entry['message']) || empty($entry['message']['id']))) {
            $entries[$k]['extra']['message'] = '<a href="' . $scripturl . '?msg=' . $entry['extra']['message'] . '">' . $entry['extra']['message'] . '</a>';
        }
        // Mark up any deleted members, topics and boards.
        foreach (array('board', 'board_from', 'board_to', 'member', 'topic', 'new_topic') as $type) {
            if (!empty($entry['extra'][$type]) && is_numeric($entry['extra'][$type])) {
                $entries[$k]['extra'][$type] = sprintf($txt['modlog_id'], $entry['extra'][$type]);
            }
        }
        if (empty($entries[$k]['action_text'])) {
            $entries[$k]['action_text'] = isset($txt['modlog_ac_' . $entry['action']]) ? $txt['modlog_ac_' . $entry['action']] : $entry['action'];
        }
        $callback->key = $k;
        $entries[$k]['action_text'] = preg_replace_callback('~\\{([A-Za-z\\d_]+)\\}~i', array($callback, 'callback'), $entries[$k]['action_text']);
    }
    // Back we go!
    return $entries;
}
Exemplo n.º 8
0
    /**
     * Find unread topics and replies.
     * Accessed by action=unread and action=unreadreplies
     */
    public function action_unread()
    {
        global $board, $txt, $scripturl;
        global $user_info, $context, $settings, $modSettings, $options;
        $db = database();
        // Guests can't have unread things, we don't know anything about them.
        is_not_guest();
        // Prefetching + lots of MySQL work = bad mojo.
        if (isset($_SERVER['HTTP_X_MOZ']) && $_SERVER['HTTP_X_MOZ'] == 'prefetch') {
            @ob_end_clean();
            header('HTTP/1.1 403 Forbidden');
            die;
        }
        // We need... we need... I know!
        require_once SUBSDIR . '/Recent.subs.php';
        require_once SUBSDIR . '/Boards.subs.php';
        $context['showCheckboxes'] = !empty($options['display_quick_mod']) && $options['display_quick_mod'] == 1 && $settings['show_mark_read'];
        $context['showing_all_topics'] = isset($_GET['all']);
        $context['start'] = (int) $_REQUEST['start'];
        $context['topics_per_page'] = empty($modSettings['disableCustomPerPage']) && !empty($options['topics_per_page']) ? $options['topics_per_page'] : $modSettings['defaultMaxTopics'];
        if ($_REQUEST['action'] == 'unread') {
            $context['page_title'] = $context['showing_all_topics'] ? $txt['unread_topics_all'] : $txt['unread_topics_visit'];
        } else {
            $context['page_title'] = $txt['unread_replies'];
        }
        if ($context['showing_all_topics'] && !empty($modSettings['loadavg_allunread']) && $modSettings['current_load'] >= $modSettings['loadavg_allunread']) {
            fatal_lang_error('loadavg_allunread_disabled', false);
        } elseif ($_REQUEST['action'] != 'unread' && !empty($modSettings['loadavg_unreadreplies']) && $modSettings['current_load'] >= $modSettings['loadavg_unreadreplies']) {
            fatal_lang_error('loadavg_unreadreplies_disabled', false);
        } elseif (!$context['showing_all_topics'] && $_REQUEST['action'] == 'unread' && !empty($modSettings['loadavg_unread']) && $modSettings['current_load'] >= $modSettings['loadavg_unread']) {
            fatal_lang_error('loadavg_unread_disabled', false);
        }
        // Parameters for the main query.
        $query_parameters = array();
        // Are we specifying any specific board?
        if (isset($_REQUEST['children']) && (!empty($board) || !empty($_REQUEST['boards']))) {
            $boards = array();
            if (!empty($_REQUEST['boards'])) {
                $_REQUEST['boards'] = explode(',', $_REQUEST['boards']);
                foreach ($_REQUEST['boards'] as $b) {
                    $boards[] = (int) $b;
                }
            }
            if (!empty($board)) {
                $boards[] = (int) $board;
            }
            // The easiest thing is to just get all the boards they can see,
            // but since we've specified the top of tree we ignore some of them
            addChildBoards($boards);
            if (empty($boards)) {
                fatal_lang_error('error_no_boards_selected');
            }
            $query_this_board = 'id_board IN ({array_int:boards})';
            $query_parameters['boards'] = $boards;
            $context['querystring_board_limits'] = ';boards=' . implode(',', $boards) . ';start=%d';
        } elseif (!empty($board)) {
            $query_this_board = 'id_board = {int:board}';
            $query_parameters['board'] = $board;
            $context['querystring_board_limits'] = ';board=' . $board . '.%1$d';
        } elseif (!empty($_REQUEST['boards'])) {
            $selected_boards = array_map('intval', explode(',', $_REQUEST['boards']));
            $boards = accessibleBoards($selected_boards);
            if (empty($boards)) {
                fatal_lang_error('error_no_boards_selected');
            }
            $query_this_board = 'id_board IN ({array_int:boards})';
            $query_parameters['boards'] = $boards;
            $context['querystring_board_limits'] = ';boards=' . implode(',', $boards) . ';start=%1$d';
        } elseif (!empty($_REQUEST['c'])) {
            $categories = array_map('intval', explode(',', $_REQUEST['c']));
            $boards = array_keys(boardsPosts(array(), $categories, isset($_REQUEST['action']) && $_REQUEST['action'] != 'unreadreplies'));
            if (empty($boards)) {
                fatal_lang_error('error_no_boards_selected');
            }
            $query_this_board = 'id_board IN ({array_int:boards})';
            $query_parameters['boards'] = $boards;
            $context['querystring_board_limits'] = ';c=' . $_REQUEST['c'] . ';start=%1$d';
        } else {
            $see_board = isset($_REQUEST['action']) && $_REQUEST['action'] == 'unreadreplies' ? 'query_see_board' : 'query_wanna_see_board';
            // Don't bother to show deleted posts!
            $boards = wantedBoards($see_board);
            if (empty($boards)) {
                fatal_lang_error('error_no_boards_selected');
            }
            $query_this_board = 'id_board IN ({array_int:boards})';
            $query_parameters['boards'] = $boards;
            $context['querystring_board_limits'] = ';start=%1$d';
            $context['no_board_limits'] = true;
        }
        $sort_methods = array('subject' => 'ms.subject', 'starter' => 'IFNULL(mems.real_name, ms.poster_name)', 'replies' => 't.num_replies', 'views' => 't.num_views', 'first_post' => 't.id_topic', 'last_post' => 't.id_last_msg');
        // The default is the most logical: newest first.
        if (!isset($_REQUEST['sort']) || !isset($sort_methods[$_REQUEST['sort']])) {
            $context['sort_by'] = 'last_post';
            $ascending = isset($_REQUEST['asc']);
            $context['querystring_sort_limits'] = $ascending ? ';asc' : '';
        } else {
            $context['sort_by'] = $_REQUEST['sort'];
            $ascending = !isset($_REQUEST['desc']);
            $context['querystring_sort_limits'] = ';sort=' . $context['sort_by'] . ($ascending ? '' : ';desc');
        }
        $_REQUEST['sort'] = $sort_methods[$context['sort_by']];
        $context['sort_direction'] = $ascending ? 'up' : 'down';
        $context['sort_title'] = $ascending ? $txt['sort_desc'] : $txt['sort_asc'];
        // Trick
        $txt['starter'] = $txt['started_by'];
        foreach ($sort_methods as $key => $val) {
            $context['topics_headers'][$key] = array('url' => $scripturl . '?action=unread' . ($context['showing_all_topics'] ? ';all' : '') . sprintf($context['querystring_board_limits'], $_REQUEST['start']) . ';sort=subject' . ($context['sort_by'] == 'subject' && $context['sort_direction'] == 'up' ? ';desc' : ''), 'sort_dir_img' => $context['sort_by'] == $key ? '<img class="sort" src="' . $settings['images_url'] . '/sort_' . $context['sort_direction'] . '.png" alt="" title="' . $context['sort_title'] . '" />' : '');
        }
        if (!empty($_REQUEST['c']) && is_array($_REQUEST['c']) && count($_REQUEST['c']) == 1) {
            $name = categoryName((int) $_REQUEST['c'][0]);
            $context['linktree'][] = array('url' => $scripturl . '#c' . (int) $_REQUEST['c'][0], 'name' => $name);
        }
        $context['linktree'][] = array('url' => $scripturl . '?action=' . $_REQUEST['action'] . sprintf($context['querystring_board_limits'], 0) . $context['querystring_sort_limits'], 'name' => $_REQUEST['action'] == 'unread' ? $txt['unread_topics_visit'] : $txt['unread_replies']);
        if ($context['showing_all_topics']) {
            $context['linktree'][] = array('url' => $scripturl . '?action=' . $_REQUEST['action'] . ';all' . sprintf($context['querystring_board_limits'], 0) . $context['querystring_sort_limits'], 'name' => $txt['unread_topics_all']);
            $txt['unread_topics_visit_none'] = str_replace('{unread_all_url}', $scripturl . '?action=unread;all', $txt['unread_topics_visit_none']);
        } else {
            $txt['unread_topics_visit_none'] = str_replace('{unread_all_url}', $scripturl . '?action=unread;all' . sprintf($context['querystring_board_limits'], 0) . $context['querystring_sort_limits'], $txt['unread_topics_visit_none']);
        }
        loadTemplate('Recent');
        $context['sub_template'] = $_REQUEST['action'] == 'unread' ? 'unread' : 'replies';
        // Setup the default topic icons... for checking they exist and the like ;)
        require_once SUBSDIR . '/MessageIndex.subs.php';
        $context['icon_sources'] = MessageTopicIcons();
        $is_topics = $_REQUEST['action'] == 'unread';
        // If empty, no preview at all
        if (empty($modSettings['message_index_preview'])) {
            $preview_bodies = '';
        } elseif (empty($modSettings['preview_characters'])) {
            $preview_bodies = 'ml.body AS last_body, ms.body AS first_body,';
        } else {
            $preview_bodies = 'SUBSTRING(ml.body, 1, ' . ($modSettings['preview_characters'] + 256) . ') AS last_body, SUBSTRING(ms.body, 1, ' . ($modSettings['preview_characters'] + 256) . ') AS first_body,';
        }
        // This part is the same for each query.
        $select_clause = '
					ms.subject AS first_subject, ms.poster_time AS first_poster_time, ms.id_topic, t.id_board, b.name AS bname,
					t.num_replies, t.num_views, t.num_likes, ms.id_member AS id_first_member, ml.id_member AS id_last_member,
					ml.poster_time AS last_poster_time, IFNULL(mems.real_name, ms.poster_name) AS first_poster_name,
					IFNULL(meml.real_name, ml.poster_name) AS last_poster_name, ml.subject AS last_subject,
					ml.icon AS last_icon, ms.icon AS first_icon, t.id_poll, t.is_sticky, t.locked, ml.modified_time AS last_modified_time,
					IFNULL(lt.id_msg, IFNULL(lmr.id_msg, -1)) + 1 AS new_from,
					' . $preview_bodies . '
					ml.smileys_enabled AS last_smileys, ms.smileys_enabled AS first_smileys, t.id_first_msg, t.id_last_msg';
        if ($context['showing_all_topics']) {
            $earliest_msg = earliest_msg();
        }
        // @todo Add modified_time in for log_time check?
        if ($modSettings['totalMessages'] > 100000 && $context['showing_all_topics']) {
            $db->query('', '
				DROP TABLE IF EXISTS {db_prefix}log_topics_unread', array());
            // Let's copy things out of the log_topics table, to reduce searching.
            $have_temp_table = $db->query('', '
				CREATE TEMPORARY TABLE {db_prefix}log_topics_unread (
					PRIMARY KEY (id_topic)
				)
				SELECT lt.id_topic, lt.id_msg, lt.unwatched
				FROM {db_prefix}topics AS t
					INNER JOIN {db_prefix}log_topics AS lt ON (lt.id_topic = t.id_topic)
				WHERE lt.id_member = {int:current_member}
					AND t.' . $query_this_board . (empty($earliest_msg) ? '' : '
					AND t.id_last_msg > {int:earliest_msg}') . ($modSettings['postmod_active'] ? '
					AND t.approved = {int:is_approved}' : '') . ($modSettings['enable_unwatch'] ? '
					AND lt.unwatched != 1' : ''), array_merge($query_parameters, array('current_member' => $user_info['id'], 'earliest_msg' => !empty($earliest_msg) ? $earliest_msg : 0, 'is_approved' => 1, 'db_error_skip' => true))) !== false;
        } else {
            $have_temp_table = false;
        }
        if ($context['showing_all_topics'] && $have_temp_table) {
            $request = $db->query('', '
				SELECT COUNT(*), MIN(t.id_last_msg)
				FROM {db_prefix}topics AS t
					LEFT JOIN {db_prefix}log_topics_unread AS lt ON (lt.id_topic = t.id_topic)
					LEFT JOIN {db_prefix}log_mark_read AS lmr ON (lmr.id_board = t.id_board AND lmr.id_member = {int:current_member})
				WHERE t.' . $query_this_board . (!empty($earliest_msg) ? '
					AND t.id_last_msg > {int:earliest_msg}' : '') . '
					AND IFNULL(lt.id_msg, IFNULL(lmr.id_msg, 0)) < t.id_last_msg' . ($modSettings['postmod_active'] ? ' AND t.approved = {int:is_approved}' : '') . ($modSettings['enable_unwatch'] ? ' AND IFNULL(lt.unwatched, 0) != 1' : ''), array_merge($query_parameters, array('current_member' => $user_info['id'], 'earliest_msg' => !empty($earliest_msg) ? $earliest_msg : 0, 'is_approved' => 1)));
            list($num_topics, $min_message) = $db->fetch_row($request);
            $db->free_result($request);
            // Make sure the starting place makes sense and construct the page index.
            $context['page_index'] = constructPageIndex($scripturl . '?action=' . $_REQUEST['action'] . ($context['showing_all_topics'] ? ';all' : '') . $context['querystring_board_limits'] . $context['querystring_sort_limits'], $_REQUEST['start'], $num_topics, $context['topics_per_page'], true);
            $context['current_page'] = (int) $_REQUEST['start'] / $context['topics_per_page'];
            $context['links'] += array('prev' => $_REQUEST['start'] >= $context['topics_per_page'] ? $scripturl . '?action=' . $_REQUEST['action'] . ($context['showing_all_topics'] ? ';all' : '') . sprintf($context['querystring_board_limits'], $_REQUEST['start'] - $context['topics_per_page']) . $context['querystring_sort_limits'] : '', 'next' => $_REQUEST['start'] + $context['topics_per_page'] < $num_topics ? $scripturl . '?action=' . $_REQUEST['action'] . ($context['showing_all_topics'] ? ';all' : '') . sprintf($context['querystring_board_limits'], $_REQUEST['start'] + $context['topics_per_page']) . $context['querystring_sort_limits'] : '');
            $context['page_info'] = array('current_page' => $_REQUEST['start'] / $context['topics_per_page'] + 1, 'num_pages' => floor(($num_topics - 1) / $context['topics_per_page']) + 1);
            if ($num_topics == 0) {
                // Mark the boards as read if there are no unread topics!
                // @todo look at this... there are no more unread topics already.
                // If clearing of log_topics is still needed, perhaps do it separately.
                markBoardsRead(empty($boards) ? $board : $boards, false, true);
                $context['topics'] = array();
                if ($context['querystring_board_limits'] == ';start=%1$d') {
                    $context['querystring_board_limits'] = '';
                } else {
                    $context['querystring_board_limits'] = sprintf($context['querystring_board_limits'], $_REQUEST['start']);
                }
                return;
            } else {
                $min_message = (int) $min_message;
            }
            $request = $db->query('substring', '
				SELECT ' . $select_clause . '
				FROM {db_prefix}messages AS ms
					INNER JOIN {db_prefix}topics AS t ON (t.id_topic = ms.id_topic AND t.id_first_msg = ms.id_msg)
					INNER JOIN {db_prefix}messages AS ml ON (ml.id_msg = t.id_last_msg)
					LEFT JOIN {db_prefix}boards AS b ON (b.id_board = ms.id_board)
					LEFT JOIN {db_prefix}members AS mems ON (mems.id_member = ms.id_member)
					LEFT JOIN {db_prefix}members AS meml ON (meml.id_member = ml.id_member)
					LEFT JOIN {db_prefix}log_topics_unread AS lt ON (lt.id_topic = t.id_topic)
					LEFT JOIN {db_prefix}log_mark_read AS lmr ON (lmr.id_board = t.id_board AND lmr.id_member = {int:current_member})
				WHERE b.' . $query_this_board . '
					AND t.id_last_msg >= {int:min_message}
					AND IFNULL(lt.id_msg, IFNULL(lmr.id_msg, 0)) < t.id_last_msg' . ($modSettings['postmod_active'] ? ' AND ms.approved = {int:is_approved}' : '') . ($modSettings['enable_unwatch'] ? ' AND IFNULL(lt.unwatched, 0) != 1' : '') . '
				ORDER BY {raw:sort}
				LIMIT {int:offset}, {int:limit}', array_merge($query_parameters, array('current_member' => $user_info['id'], 'min_message' => $min_message, 'is_approved' => 1, 'sort' => $_REQUEST['sort'] . ($ascending ? '' : ' DESC'), 'offset' => $_REQUEST['start'], 'limit' => $context['topics_per_page'])));
        } elseif ($is_topics) {
            $request = $db->query('', '
				SELECT COUNT(*), MIN(t.id_last_msg)
				FROM {db_prefix}topics AS t' . (!empty($have_temp_table) ? '
					LEFT JOIN {db_prefix}log_topics_unread AS lt ON (lt.id_topic = t.id_topic)' : '
					LEFT JOIN {db_prefix}log_topics AS lt ON (lt.id_topic = t.id_topic AND lt.id_member = {int:current_member})') . '
					LEFT JOIN {db_prefix}log_mark_read AS lmr ON (lmr.id_board = t.id_board AND lmr.id_member = {int:current_member})
				WHERE t.' . $query_this_board . ($context['showing_all_topics'] && !empty($earliest_msg) ? '
					AND t.id_last_msg > {int:earliest_msg}' : (!$context['showing_all_topics'] && empty($_SESSION['first_login']) ? '
					AND t.id_last_msg > {int:id_msg_last_visit}' : '')) . '
					AND IFNULL(lt.id_msg, IFNULL(lmr.id_msg, 0)) < t.id_last_msg' . ($modSettings['postmod_active'] ? ' AND t.approved = {int:is_approved}' : '') . ($modSettings['enable_unwatch'] ? ' AND IFNULL(lt.unwatched, 0) != 1' : ''), array_merge($query_parameters, array('current_member' => $user_info['id'], 'earliest_msg' => !empty($earliest_msg) ? $earliest_msg : 0, 'id_msg_last_visit' => $_SESSION['id_msg_last_visit'], 'is_approved' => 1)));
            list($num_topics, $min_message) = $db->fetch_row($request);
            $db->free_result($request);
            // Make sure the starting place makes sense and construct the page index.
            $context['page_index'] = constructPageIndex($scripturl . '?action=' . $_REQUEST['action'] . ($context['showing_all_topics'] ? ';all' : '') . $context['querystring_board_limits'] . $context['querystring_sort_limits'], $_REQUEST['start'], $num_topics, $context['topics_per_page'], true);
            $context['current_page'] = (int) $_REQUEST['start'] / $context['topics_per_page'];
            $context['links'] += array('prev' => $_REQUEST['start'] >= $context['topics_per_page'] ? $scripturl . '?action=' . $_REQUEST['action'] . ($context['showing_all_topics'] ? ';all' : '') . sprintf($context['querystring_board_limits'], $_REQUEST['start'] - $context['topics_per_page']) . $context['querystring_sort_limits'] : '', 'next' => $_REQUEST['start'] + $context['topics_per_page'] < $num_topics ? $scripturl . '?action=' . $_REQUEST['action'] . ($context['showing_all_topics'] ? ';all' : '') . sprintf($context['querystring_board_limits'], $_REQUEST['start'] + $context['topics_per_page']) . $context['querystring_sort_limits'] : '');
            $context['page_info'] = array('current_page' => $_REQUEST['start'] / $context['topics_per_page'] + 1, 'num_pages' => floor(($num_topics - 1) / $context['topics_per_page']) + 1);
            if ($num_topics == 0) {
                // Is this an all topics query?
                if ($context['showing_all_topics']) {
                    // Since there are no unread topics, mark the boards as read!
                    // @todo look at this... there are no more unread topics already.
                    // If clearing of log_topics is still needed, perhaps do it separately.
                    markBoardsRead(empty($boards) ? $board : $boards, false, true);
                }
                $context['topics'] = array();
                if ($context['querystring_board_limits'] == ';start=%d') {
                    $context['querystring_board_limits'] = '';
                } else {
                    $context['querystring_board_limits'] = sprintf($context['querystring_board_limits'], $_REQUEST['start']);
                }
                return;
            } else {
                $min_message = (int) $min_message;
            }
            $request = $db->query('substring', '
				SELECT ' . $select_clause . '
				FROM {db_prefix}messages AS ms
					INNER JOIN {db_prefix}topics AS t ON (t.id_topic = ms.id_topic AND t.id_first_msg = ms.id_msg)
					INNER JOIN {db_prefix}messages AS ml ON (ml.id_msg = t.id_last_msg)
					LEFT JOIN {db_prefix}boards AS b ON (b.id_board = t.id_board)
					LEFT JOIN {db_prefix}members AS mems ON (mems.id_member = ms.id_member)
					LEFT JOIN {db_prefix}members AS meml ON (meml.id_member = ml.id_member)' . (!empty($have_temp_table) ? '
					LEFT JOIN {db_prefix}log_topics_unread AS lt ON (lt.id_topic = t.id_topic)' : '
					LEFT JOIN {db_prefix}log_topics AS lt ON (lt.id_topic = t.id_topic AND lt.id_member = {int:current_member})') . '
					LEFT JOIN {db_prefix}log_mark_read AS lmr ON (lmr.id_board = t.id_board AND lmr.id_member = {int:current_member})
				WHERE t.' . $query_this_board . '
					AND t.id_last_msg >= {int:min_message}
					AND IFNULL(lt.id_msg, IFNULL(lmr.id_msg, 0)) < ml.id_msg' . ($modSettings['postmod_active'] ? ' AND ms.approved = {int:is_approved}' : '') . ($modSettings['enable_unwatch'] ? ' AND IFNULL(lt.unwatched, 0) != 1' : '') . '
				ORDER BY {raw:order}
				LIMIT {int:offset}, {int:limit}', array_merge($query_parameters, array('current_member' => $user_info['id'], 'min_message' => $min_message, 'is_approved' => 1, 'order' => $_REQUEST['sort'] . ($ascending ? '' : ' DESC'), 'offset' => $_REQUEST['start'], 'limit' => $context['topics_per_page'])));
        } else {
            if ($modSettings['totalMessages'] > 100000) {
                $db->query('', '
					DROP TABLE IF EXISTS {db_prefix}topics_posted_in', array());
                $db->query('', '
					DROP TABLE IF EXISTS {db_prefix}log_topics_posted_in', array());
                $sortKey_joins = array('ms.subject' => '
						INNER JOIN {db_prefix}messages AS ms ON (ms.id_msg = t.id_first_msg)', 'IFNULL(mems.real_name, ms.poster_name)' => '
						INNER JOIN {db_prefix}messages AS ms ON (ms.id_msg = t.id_first_msg)
						LEFT JOIN {db_prefix}members AS mems ON (mems.id_member = ms.id_member)');
                // The main benefit of this temporary table is not that it's faster; it's that it avoids locks later.
                $have_temp_table = $db->query('', '
					CREATE TEMPORARY TABLE {db_prefix}topics_posted_in (
						id_topic mediumint(8) unsigned NOT NULL default {string:string_zero},
						id_board smallint(5) unsigned NOT NULL default {string:string_zero},
						id_last_msg int(10) unsigned NOT NULL default {string:string_zero},
						id_msg int(10) unsigned NOT NULL default {string:string_zero},
						PRIMARY KEY (id_topic)
					)
					SELECT t.id_topic, t.id_board, t.id_last_msg, IFNULL(lmr.id_msg, 0) AS id_msg' . (!in_array($_REQUEST['sort'], array('t.id_last_msg', 't.id_topic')) ? ', ' . $_REQUEST['sort'] . ' AS sort_key' : '') . '
					FROM {db_prefix}messages AS m
						INNER JOIN {db_prefix}topics AS t ON (t.id_topic = m.id_topic)' . ($modSettings['enable_unwatch'] ? '
						LEFT JOIN {db_prefix}log_topics AS lt ON (t.id_topic = lt.id_topic AND lt.id_member = {int:current_member})' : '') . '
						LEFT JOIN {db_prefix}log_mark_read AS lmr ON (lmr.id_board = t.id_board AND lmr.id_member = {int:current_member})' . (isset($sortKey_joins[$_REQUEST['sort']]) ? $sortKey_joins[$_REQUEST['sort']] : '') . '
					WHERE m.id_member = {int:current_member}' . (!empty($board) ? '
						AND t.id_board = {int:current_board}' : '') . ($modSettings['postmod_active'] ? '
						AND t.approved = {int:is_approved}' : '') . ($modSettings['enable_unwatch'] ? '
						AND IFNULL(lt.unwatched, 0) != 1' : '') . '
					GROUP BY m.id_topic', array('current_board' => $board, 'current_member' => $user_info['id'], 'is_approved' => 1, 'string_zero' => '0', 'db_error_skip' => true)) !== false;
                // If that worked, create a sample of the log_topics table too.
                if ($have_temp_table) {
                    $have_temp_table = $db->query('', '
						CREATE TEMPORARY TABLE {db_prefix}log_topics_posted_in (
							PRIMARY KEY (id_topic)
						)
						SELECT lt.id_topic, lt.id_msg
						FROM {db_prefix}log_topics AS lt
							INNER JOIN {db_prefix}topics_posted_in AS pi ON (pi.id_topic = lt.id_topic)
						WHERE lt.id_member = {int:current_member}', array('current_member' => $user_info['id'], 'db_error_skip' => true)) !== false;
                }
            }
            if (!empty($have_temp_table)) {
                $request = $db->query('', '
					SELECT COUNT(*)
					FROM {db_prefix}topics_posted_in AS pi
						LEFT JOIN {db_prefix}log_topics_posted_in AS lt ON (lt.id_topic = pi.id_topic)
					WHERE pi.' . $query_this_board . '
						AND IFNULL(lt.id_msg, pi.id_msg) < pi.id_last_msg', array_merge($query_parameters, array()));
                list($num_topics) = $db->fetch_row($request);
                $db->free_result($request);
                $min_message = 0;
            } else {
                $request = $db->query('unread_fetch_topic_count', '
					SELECT COUNT(DISTINCT t.id_topic), MIN(t.id_last_msg)
					FROM {db_prefix}topics AS t
						INNER JOIN {db_prefix}messages AS m ON (m.id_topic = t.id_topic)
						LEFT JOIN {db_prefix}log_topics AS lt ON (lt.id_topic = t.id_topic AND lt.id_member = {int:current_member})
						LEFT JOIN {db_prefix}log_mark_read AS lmr ON (lmr.id_board = t.id_board AND lmr.id_member = {int:current_member})
					WHERE t.' . $query_this_board . '
						AND m.id_member = {int:current_member}
						AND IFNULL(lt.id_msg, IFNULL(lmr.id_msg, 0)) < t.id_last_msg' . ($modSettings['postmod_active'] ? '
						AND t.approved = {int:is_approved}' : '') . ($modSettings['enable_unwatch'] ? '
						AND IFNULL(lt.unwatched, 0) != 1' : ''), array_merge($query_parameters, array('current_member' => $user_info['id'], 'is_approved' => 1)));
                list($num_topics, $min_message) = $db->fetch_row($request);
                $db->free_result($request);
            }
            // Make sure the starting place makes sense and construct the page index.
            $context['page_index'] = constructPageIndex($scripturl . '?action=' . $_REQUEST['action'] . $context['querystring_board_limits'] . $context['querystring_sort_limits'], $_REQUEST['start'], $num_topics, $context['topics_per_page'], true);
            $context['current_page'] = (int) $_REQUEST['start'] / $context['topics_per_page'];
            $context['links'] += array('first' => $_REQUEST['start'] >= $context['topics_per_page'] ? $scripturl . '?action=' . $_REQUEST['action'] . ($context['showing_all_topics'] ? ';all' : '') . sprintf($context['querystring_board_limits'], 0) . $context['querystring_sort_limits'] : '', 'prev' => $_REQUEST['start'] >= $context['topics_per_page'] ? $scripturl . '?action=' . $_REQUEST['action'] . ($context['showing_all_topics'] ? ';all' : '') . sprintf($context['querystring_board_limits'], $_REQUEST['start'] - $context['topics_per_page']) . $context['querystring_sort_limits'] : '', 'next' => $_REQUEST['start'] + $context['topics_per_page'] < $num_topics ? $scripturl . '?action=' . $_REQUEST['action'] . ($context['showing_all_topics'] ? ';all' : '') . sprintf($context['querystring_board_limits'], $_REQUEST['start'] + $context['topics_per_page']) . $context['querystring_sort_limits'] : '', 'last' => $_REQUEST['start'] + $context['topics_per_page'] < $num_topics ? $scripturl . '?action=' . $_REQUEST['action'] . ($context['showing_all_topics'] ? ';all' : '') . sprintf($context['querystring_board_limits'], floor(($num_topics - 1) / $context['topics_per_page']) * $context['topics_per_page']) . $context['querystring_sort_limits'] : '', 'up' => $scripturl);
            $context['page_info'] = array('current_page' => $_REQUEST['start'] / $context['topics_per_page'] + 1, 'num_pages' => floor(($num_topics - 1) / $context['topics_per_page']) + 1);
            if ($num_topics == 0) {
                $context['topics'] = array();
                if ($context['querystring_board_limits'] == ';start=%d') {
                    $context['querystring_board_limits'] = '';
                } else {
                    $context['querystring_board_limits'] = sprintf($context['querystring_board_limits'], $_REQUEST['start']);
                }
                return;
            }
            if (!empty($have_temp_table)) {
                $request = $db->query('', '
					SELECT t.id_topic
					FROM {db_prefix}topics_posted_in AS t
						LEFT JOIN {db_prefix}log_topics_posted_in AS lt ON (lt.id_topic = t.id_topic)
					WHERE t.' . $query_this_board . '
						AND IFNULL(lt.id_msg, t.id_msg) < t.id_last_msg
					ORDER BY {raw:order}
					LIMIT {int:offset}, {int:limit}', array_merge($query_parameters, array('order' => (in_array($_REQUEST['sort'], array('t.id_last_msg', 't.id_topic')) ? $_REQUEST['sort'] : 't.sort_key') . ($ascending ? '' : ' DESC'), 'offset' => $_REQUEST['start'], 'limit' => $context['topics_per_page'])));
            } else {
                $request = $db->query('unread_replies', '
					SELECT DISTINCT t.id_topic
					FROM {db_prefix}topics AS t
						INNER JOIN {db_prefix}messages AS m ON (m.id_topic = t.id_topic AND m.id_member = {int:current_member})' . (strpos($_REQUEST['sort'], 'ms.') === false ? '' : '
						INNER JOIN {db_prefix}messages AS ms ON (ms.id_msg = t.id_first_msg)') . (strpos($_REQUEST['sort'], 'mems.') === false ? '' : '
						LEFT JOIN {db_prefix}members AS mems ON (mems.id_member = ms.id_member)') . '
						LEFT JOIN {db_prefix}log_topics AS lt ON (lt.id_topic = t.id_topic AND lt.id_member = {int:current_member})
						LEFT JOIN {db_prefix}log_mark_read AS lmr ON (lmr.id_board = t.id_board AND lmr.id_member = {int:current_member})
					WHERE t.' . $query_this_board . '
						AND t.id_last_msg >= {int:min_message}
						AND (IFNULL(lt.id_msg, IFNULL(lmr.id_msg, 0))) < t.id_last_msg' . ($modSettings['postmod_active'] ? ' AND t.approved = {int:is_approved}' : '') . ($modSettings['enable_unwatch'] ? ' AND IFNULL(lt.unwatched, 0) != 1' : '') . '
					ORDER BY {raw:order}
					LIMIT {int:offset}, {int:limit}', array_merge($query_parameters, array('current_member' => $user_info['id'], 'min_message' => (int) $min_message, 'is_approved' => 1, 'order' => $_REQUEST['sort'] . ($ascending ? '' : ' DESC'), 'offset' => $_REQUEST['start'], 'limit' => $context['topics_per_page'], 'sort' => $_REQUEST['sort'])));
            }
            $topics = array();
            while ($row = $db->fetch_assoc($request)) {
                $topics[] = $row['id_topic'];
            }
            $db->free_result($request);
            // Sanity... where have you gone?
            if (empty($topics)) {
                $context['topics'] = array();
                if ($context['querystring_board_limits'] == ';start=%d') {
                    $context['querystring_board_limits'] = '';
                } else {
                    $context['querystring_board_limits'] = sprintf($context['querystring_board_limits'], $_REQUEST['start']);
                }
                return;
            }
            $request = $db->query('substring', '
				SELECT ' . $select_clause . '
				FROM {db_prefix}topics AS t
					INNER JOIN {db_prefix}messages AS ms ON (ms.id_topic = t.id_topic AND ms.id_msg = t.id_first_msg)
					INNER JOIN {db_prefix}messages AS ml ON (ml.id_msg = t.id_last_msg)
					INNER JOIN {db_prefix}boards AS b ON (b.id_board = t.id_board)
					LEFT JOIN {db_prefix}members AS mems ON (mems.id_member = ms.id_member)
					LEFT JOIN {db_prefix}members AS meml ON (meml.id_member = ml.id_member)
					LEFT JOIN {db_prefix}log_topics AS lt ON (lt.id_topic = t.id_topic AND lt.id_member = {int:current_member})
					LEFT JOIN {db_prefix}log_mark_read AS lmr ON (lmr.id_board = t.id_board AND lmr.id_member = {int:current_member})
				WHERE t.id_topic IN ({array_int:topic_list})
				ORDER BY ' . $_REQUEST['sort'] . ($ascending ? '' : ' DESC') . '
				LIMIT ' . count($topics), array('current_member' => $user_info['id'], 'topic_list' => $topics));
        }
        $context['topics'] = array();
        $topic_ids = array();
        while ($row = $db->fetch_assoc($request)) {
            $topic_ids[] = $row['id_topic'];
            if (!empty($modSettings['message_index_preview'])) {
                // Limit them to 128 characters - do this FIRST because it's a lot of wasted censoring otherwise.
                $row['first_body'] = strip_tags(strtr(parse_bbc($row['first_body'], false, $row['id_first_msg']), array('<br />' => "\n", '&nbsp;' => ' ')));
                $row['first_body'] = Util::shorten_text($row['first_body'], !empty($modSettings['preview_characters']) ? $modSettings['preview_characters'] : 128, true);
                // No reply then they are the same, no need to process it again
                if ($row['num_replies'] == 0) {
                    $row['last_body'] == $row['first_body'];
                } else {
                    $row['last_body'] = strip_tags(strtr(parse_bbc($row['last_body'], false, $row['id_last_msg']), array('<br />' => "\n", '&nbsp;' => ' ')));
                    $row['last_body'] = Util::shorten_text($row['last_body'], !empty($modSettings['preview_characters']) ? $modSettings['preview_characters'] : 128, true);
                }
                // Censor the subject and message preview.
                censorText($row['first_subject']);
                censorText($row['first_body']);
                // Don't censor them twice!
                if ($row['id_first_msg'] == $row['id_last_msg']) {
                    $row['last_subject'] = $row['first_subject'];
                    $row['last_body'] = $row['first_body'];
                } else {
                    censorText($row['last_subject']);
                    censorText($row['last_body']);
                }
            } else {
                $row['first_body'] = '';
                $row['last_body'] = '';
                censorText($row['first_subject']);
                if ($row['id_first_msg'] == $row['id_last_msg']) {
                    $row['last_subject'] = $row['first_subject'];
                } else {
                    censorText($row['last_subject']);
                }
            }
            // Decide how many pages the topic should have.
            $topic_length = $row['num_replies'] + 1;
            $messages_per_page = empty($modSettings['disableCustomPerPage']) && !empty($options['messages_per_page']) ? $options['messages_per_page'] : $modSettings['defaultMaxMessages'];
            if ($topic_length > $messages_per_page) {
                $start = -1;
                $pages = constructPageIndex($scripturl . '?topic=' . $row['id_topic'] . '.%1$d;topicseen', $start, $topic_length, $messages_per_page, true, array('prev_next' => false, 'all' => !empty($modSettings['enableAllMessages']) && $topic_length < $modSettings['enableAllMessages']));
            } else {
                $pages = '';
            }
            // We need to check the topic icons exist... you can never be too sure!
            if (!empty($modSettings['messageIconChecks_enable'])) {
                // First icon first... as you'd expect.
                if (!isset($context['icon_sources'][$row['first_icon']])) {
                    $context['icon_sources'][$row['first_icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $row['first_icon'] . '.png') ? 'images_url' : 'default_images_url';
                }
                // Last icon... last... duh.
                if (!isset($context['icon_sources'][$row['last_icon']])) {
                    $context['icon_sources'][$row['last_icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $row['last_icon'] . '.png') ? 'images_url' : 'default_images_url';
                }
            }
            // And build the array.
            $context['topics'][$row['id_topic']] = array('id' => $row['id_topic'], 'first_post' => array('id' => $row['id_first_msg'], 'member' => array('name' => $row['first_poster_name'], 'id' => $row['id_first_member'], 'href' => $scripturl . '?action=profile;u=' . $row['id_first_member'], 'link' => !empty($row['id_first_member']) ? '<a class="preview" href="' . $scripturl . '?action=profile;u=' . $row['id_first_member'] . '" title="' . $txt['profile_of'] . ' ' . $row['first_poster_name'] . '">' . $row['first_poster_name'] . '</a>' : $row['first_poster_name']), 'time' => standardTime($row['first_poster_time']), 'html_time' => htmlTime($row['first_poster_time']), 'timestamp' => forum_time(true, $row['first_poster_time']), 'subject' => $row['first_subject'], 'preview' => $row['first_body'], 'icon' => $row['first_icon'], 'icon_url' => $settings[$context['icon_sources'][$row['first_icon']]] . '/post/' . $row['first_icon'] . '.png', 'href' => $scripturl . '?topic=' . $row['id_topic'] . '.0;topicseen', 'link' => '<a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.0;topicseen">' . $row['first_subject'] . '</a>'), 'last_post' => array('id' => $row['id_last_msg'], 'member' => array('name' => $row['last_poster_name'], 'id' => $row['id_last_member'], 'href' => $scripturl . '?action=profile;u=' . $row['id_last_member'], 'link' => !empty($row['id_last_member']) ? '<a href="' . $scripturl . '?action=profile;u=' . $row['id_last_member'] . '">' . $row['last_poster_name'] . '</a>' : $row['last_poster_name']), 'time' => standardTime($row['last_poster_time']), 'html_time' => htmlTime($row['last_poster_time']), 'timestamp' => forum_time(true, $row['last_poster_time']), 'subject' => $row['last_subject'], 'preview' => $row['last_body'], 'icon' => $row['last_icon'], 'icon_url' => $settings[$context['icon_sources'][$row['last_icon']]] . '/post/' . $row['last_icon'] . '.png', 'href' => $scripturl . '?topic=' . $row['id_topic'] . ($row['num_replies'] == 0 ? '.0' : '.msg' . $row['id_last_msg']) . ';topicseen#msg' . $row['id_last_msg'], 'link' => '<a href="' . $scripturl . '?topic=' . $row['id_topic'] . ($row['num_replies'] == 0 ? '.0' : '.msg' . $row['id_last_msg']) . ';topicseen#msg' . $row['id_last_msg'] . '" rel="nofollow">' . $row['last_subject'] . '</a>'), 'default_preview' => trim($row[!empty($modSettings['message_index_preview']) && $modSettings['message_index_preview'] == 2 ? 'last_body' : 'first_body']), 'new_from' => $row['new_from'], 'new_href' => $scripturl . '?topic=' . $row['id_topic'] . '.msg' . $row['new_from'] . ';topicseen#new', 'href' => $scripturl . '?topic=' . $row['id_topic'] . ($row['num_replies'] == 0 ? '.0' : '.msg' . $row['new_from']) . ';topicseen' . ($row['num_replies'] == 0 ? '' : 'new'), 'link' => '<a href="' . $scripturl . '?topic=' . $row['id_topic'] . ($row['num_replies'] == 0 ? '.0' : '.msg' . $row['new_from']) . ';topicseen#msg' . $row['new_from'] . '" rel="nofollow">' . $row['first_subject'] . '</a>', 'is_sticky' => !empty($modSettings['enableStickyTopics']) && !empty($row['is_sticky']), 'is_locked' => !empty($row['locked']), 'is_poll' => !empty($modSettings['pollMode']) && $row['id_poll'] > 0, 'is_hot' => !empty($modSettings['useLikesNotViews']) ? $row['num_likes'] >= $modSettings['hotTopicPosts'] : $row['num_replies'] >= $modSettings['hotTopicPosts'], 'is_very_hot' => !empty($modSettings['useLikesNotViews']) ? $row['num_likes'] >= $modSettings['hotTopicVeryPosts'] : $row['num_replies'] >= $modSettings['hotTopicVeryPosts'], 'is_posted_in' => false, 'icon' => $row['first_icon'], 'icon_url' => $settings[$context['icon_sources'][$row['first_icon']]] . '/post/' . $row['first_icon'] . '.png', 'subject' => $row['first_subject'], 'pages' => $pages, 'replies' => comma_format($row['num_replies']), 'views' => comma_format($row['num_views']), 'likes' => comma_format($row['num_likes']), 'board' => array('id' => $row['id_board'], 'name' => $row['bname'], 'href' => $scripturl . '?board=' . $row['id_board'] . '.0', 'link' => '<a href="' . $scripturl . '?board=' . $row['id_board'] . '.0">' . $row['bname'] . '</a>'));
            $context['topics'][$row['id_topic']]['first_post']['started_by'] = sprintf($txt['topic_started_by_in'], '<strong>' . $context['topics'][$row['id_topic']]['first_post']['member']['link'] . '</strong>', '<em>' . $context['topics'][$row['id_topic']]['board']['link'] . '</em>');
            determineTopicClass($context['topics'][$row['id_topic']]);
        }
        $db->free_result($request);
        if ($is_topics && !empty($modSettings['enableParticipation']) && !empty($topic_ids)) {
            require_once SUBSDIR . '/MessageIndex.subs.php';
            $topics_participated_in = topicsParticipation($user_info['id'], $topic_ids);
            foreach ($topics_participated_in as $topic) {
                if (empty($context['topics'][$topic['id_topic']]['is_posted_in'])) {
                    $context['topics'][$topic['id_topic']]['is_posted_in'] = true;
                    $context['topics'][$topic['id_topic']]['class'] = 'my_' . $context['topics'][$topic['id_topic']]['class'];
                }
            }
        }
        $context['querystring_board_limits'] = sprintf($context['querystring_board_limits'], $_REQUEST['start']);
        $context['topics_to_mark'] = implode('-', $topic_ids);
        if ($settings['show_mark_read']) {
            // Build the recent button array.
            if ($is_topics) {
                $context['recent_buttons'] = array('markread' => array('text' => !empty($context['no_board_limits']) ? 'mark_as_read' : 'mark_read_short', 'image' => 'markread.png', 'lang' => true, 'custom' => 'onclick="return markunreadButton(this);"', 'url' => $scripturl . '?action=markasread;sa=' . (!empty($context['no_board_limits']) ? 'all' : 'board' . $context['querystring_board_limits']) . ';' . $context['session_var'] . '=' . $context['session_id']));
                if ($context['showCheckboxes']) {
                    $context['recent_buttons']['markselectread'] = array('text' => 'quick_mod_markread', 'image' => 'markselectedread.png', 'lang' => true, 'url' => 'javascript:document.quickModForm.submit();');
                }
                if (!empty($context['topics']) && !$context['showing_all_topics']) {
                    $context['recent_buttons']['readall'] = array('text' => 'unread_topics_all', 'image' => 'markreadall.png', 'lang' => true, 'url' => $scripturl . '?action=unread;all' . $context['querystring_board_limits'], 'active' => true);
                }
            } elseif (!$is_topics && isset($context['topics_to_mark'])) {
                $context['recent_buttons'] = array('markread' => array('text' => 'mark_as_read', 'image' => 'markread.png', 'lang' => true, 'url' => $scripturl . '?action=markasread;sa=unreadreplies;topics=' . $context['topics_to_mark'] . ';' . $context['session_var'] . '=' . $context['session_id']));
                if ($context['showCheckboxes']) {
                    $context['recent_buttons']['markselectread'] = array('text' => 'quick_mod_markread', 'image' => 'markselectedread.png', 'lang' => true, 'url' => 'javascript:document.quickModForm.submit();');
                }
            }
            // Allow mods to add additional buttons here
            call_integration_hook('integrate_recent_buttons');
        }
        // Allow helpdesks and bug trackers and what not to add their own unread data (just add a template_layer to show custom stuff in the template!)
        call_integration_hook('integrate_unread_list');
    }
Exemplo n.º 9
0
/**
 * We want to show the recent attachments outside of the forum.
 *
 * @param int $num_attachments = 10
 * @param string[] $attachment_ext = array()
 * @param string $output_method = 'echo'
 */
function ssi_recentAttachments($num_attachments = 10, $attachment_ext = array(), $output_method = 'echo')
{
    global $modSettings, $scripturl, $txt, $settings;
    // We want to make sure that we only get attachments for boards that we can see *if* any.
    $attachments_boards = boardsAllowedTo('view_attachments');
    // No boards?  Adios amigo.
    if (empty($attachments_boards)) {
        return array();
    }
    $db = database();
    // Is it an array?
    if (!is_array($attachment_ext)) {
        $attachment_ext = array($attachment_ext);
    }
    // Lets build the query.
    $request = $db->query('', '
		SELECT
			att.id_attach, att.id_msg, att.filename, IFNULL(att.size, 0) AS filesize, att.downloads, mem.id_member,
			IFNULL(mem.real_name, m.poster_name) AS poster_name, m.id_topic, m.subject, t.id_board, m.poster_time,
			att.width, att.height' . (empty($modSettings['attachmentShowImages']) || empty($modSettings['attachmentThumbnails']) ? '' : ', IFNULL(thumb.id_attach, 0) AS id_thumb, thumb.width AS thumb_width, thumb.height AS thumb_height') . '
		FROM {db_prefix}attachments AS att
			INNER JOIN {db_prefix}messages AS m ON (m.id_msg = att.id_msg)
			INNER JOIN {db_prefix}topics AS t ON (t.id_topic = m.id_topic)
			LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = m.id_member)' . (empty($modSettings['attachmentShowImages']) || empty($modSettings['attachmentThumbnails']) ? '' : '
			LEFT JOIN {db_prefix}attachments AS thumb ON (thumb.id_attach = att.id_thumb)') . '
		WHERE att.attachment_type = 0' . ($attachments_boards === array(0) ? '' : '
			AND m.id_board IN ({array_int:boards_can_see})') . (!empty($attachment_ext) ? '
			AND att.fileext IN ({array_string:attachment_ext})' : '') . (!$modSettings['postmod_active'] || allowedTo('approve_posts') ? '' : '
			AND t.approved = {int:is_approved}
			AND m.approved = {int:is_approved}
			AND att.approved = {int:is_approved}') . '
		ORDER BY att.id_attach DESC
		LIMIT {int:num_attachments}', array('boards_can_see' => $attachments_boards, 'attachment_ext' => $attachment_ext, 'num_attachments' => $num_attachments, 'is_approved' => 1));
    // We have something.
    $attachments = array();
    while ($row = $db->fetch_assoc($request)) {
        $filename = preg_replace('~&amp;#(\\d{1,7}|x[0-9a-fA-F]{1,6});~', '&#\\1;', htmlspecialchars($row['filename'], ENT_COMPAT, 'UTF-8'));
        // Is it an image?
        $attachments[$row['id_attach']] = array('member' => array('id' => $row['id_member'], 'name' => $row['poster_name'], 'link' => empty($row['id_member']) ? $row['poster_name'] : '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['poster_name'] . '</a>'), 'file' => array('filename' => $filename, 'filesize' => round($row['filesize'] / 1024, 2) . $txt['kilobyte'], 'downloads' => $row['downloads'], 'href' => $scripturl . '?action=dlattach;topic=' . $row['id_topic'] . '.0;attach=' . $row['id_attach'], 'link' => '<img src="' . $settings['images_url'] . '/icons/clip.png" alt="" /> <a href="' . $scripturl . '?action=dlattach;topic=' . $row['id_topic'] . '.0;attach=' . $row['id_attach'] . '">' . $filename . '</a>', 'is_image' => !empty($row['width']) && !empty($row['height']) && !empty($modSettings['attachmentShowImages'])), 'topic' => array('id' => $row['id_topic'], 'subject' => $row['subject'], 'href' => $scripturl . '?topic=' . $row['id_topic'] . '.msg' . $row['id_msg'] . '#msg' . $row['id_msg'], 'link' => '<a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.msg' . $row['id_msg'] . '#msg' . $row['id_msg'] . '">' . $row['subject'] . '</a>', 'time' => standardTime($row['poster_time']), 'html_time' => htmlTime($row['poster_time']), 'timestamp' => forum_time(true, $row['poster_time'])));
        // Images.
        if ($attachments[$row['id_attach']]['file']['is_image']) {
            $id_thumb = empty($row['id_thumb']) ? $row['id_attach'] : $row['id_thumb'];
            $attachments[$row['id_attach']]['file']['image'] = array('id' => $id_thumb, 'width' => $row['width'], 'height' => $row['height'], 'img' => '<img src="' . $scripturl . '?action=dlattach;topic=' . $row['id_topic'] . '.0;attach=' . $row['id_attach'] . ';image" alt="' . $filename . '" />', 'thumb' => '<img src="' . $scripturl . '?action=dlattach;topic=' . $row['id_topic'] . '.0;attach=' . $id_thumb . ';image" alt="' . $filename . '" />', 'href' => $scripturl . '?action=dlattach;topic=' . $row['id_topic'] . '.0;attach=' . $id_thumb . ';image', 'link' => '<a href="' . $scripturl . '?action=dlattach;topic=' . $row['id_topic'] . '.0;attach=' . $row['id_attach'] . ';image"><img src="' . $scripturl . '?action=dlattach;topic=' . $row['id_topic'] . '.0;attach=' . $id_thumb . ';image" alt="' . $filename . '" /></a>');
        }
    }
    $db->free_result($request);
    // So you just want an array?  Here you can have it.
    if ($output_method == 'array' || empty($attachments)) {
        return $attachments;
    }
    // Give them the default.
    echo '
		<table class="ssi_downloads" cellpadding="2">
			<tr>
				<th align="left">', $txt['file'], '</th>
				<th align="left">', $txt['posted_by'], '</th>
				<th align="left">', $txt['downloads'], '</th>
				<th align="left">', $txt['filesize'], '</th>
			</tr>';
    foreach ($attachments as $attach) {
        echo '
			<tr>
				<td>', $attach['file']['link'], '</td>
				<td>', $attach['member']['link'], '</td>
				<td align="center">', $attach['file']['downloads'], '</td>
				<td>', $attach['file']['filesize'], '</td>
			</tr>';
    }
    echo '
		</table>';
}
Exemplo n.º 10
0
 /**
  * Show all PM drafts of the current user
  * Uses the showpmdraft template
  * Allows for the deleting and loading/editing of PM drafts
  */
 public function action_showPMDrafts()
 {
     global $txt, $user_info, $scripturl, $modSettings, $context;
     require_once SUBSDIR . '/Profile.subs.php';
     require_once SUBSDIR . '/Drafts.subs.php';
     $memID = currentMemberID();
     // Quick check how we got here.
     if ($memID != $user_info['id']) {
         // empty($modSettings['drafts_enabled']) || empty($modSettings['drafts_pm_enabled']))
         fatal_lang_error('no_access', false);
     }
     // Set up what we will need
     $context['start'] = isset($_REQUEST['start']) ? (int) $_REQUEST['start'] : 0;
     // If just deleting a draft, do it and then redirect back.
     if (!empty($_REQUEST['delete'])) {
         checkSession('get');
         $id_delete = (int) $_REQUEST['delete'];
         deleteDrafts($id_delete, $memID);
         redirectexit('action=pm;sa=showpmdrafts;start=' . $context['start']);
     }
     // Perhaps a draft was selected for editing? if so pass this off
     if (!empty($_REQUEST['id_draft']) && !empty($context['drafts_pm_save'])) {
         checkSession('get');
         $id_draft = (int) $_REQUEST['id_draft'];
         redirectexit('action=pm;sa=send;id_draft=' . $id_draft);
     }
     // Init
     $maxIndex = (int) $modSettings['defaultMaxMessages'];
     // Default to 10.
     if (empty($_REQUEST['viewscount']) || !is_numeric($_REQUEST['viewscount'])) {
         $_REQUEST['viewscount'] = 10;
     }
     // Get the count of applicable drafts
     $msgCount = draftsCount($memID, 1);
     // Make sure the starting place makes sense and construct our friend the page index.
     $context['page_index'] = constructPageIndex($scripturl . '?action=pm;sa=showpmdrafts', $context['start'], $msgCount, $maxIndex);
     $context['current_page'] = $context['start'] / $maxIndex;
     // Reverse the query if we're past 50% of the total for better performance.
     $start = $context['start'];
     $reverse = $start > $msgCount / 2;
     if ($reverse) {
         $maxIndex = $msgCount < $context['start'] + $modSettings['defaultMaxMessages'] + 1 && $msgCount > $context['start'] ? $msgCount - $context['start'] : (int) $modSettings['defaultMaxMessages'];
         $start = $msgCount < $context['start'] + $modSettings['defaultMaxMessages'] + 1 || $msgCount < $context['start'] + $modSettings['defaultMaxMessages'] ? 0 : $msgCount - $context['start'] - $modSettings['defaultMaxMessages'];
     }
     // Go get em'
     $order = 'ud.poster_time ' . ($reverse ? 'ASC' : 'DESC');
     $limit = $start . ', ' . $maxIndex;
     $user_drafts = load_user_drafts($memID, 1, false, $order, $limit);
     // Start counting at the number of the first message displayed.
     $counter = $reverse ? $context['start'] + $maxIndex + 1 : $context['start'];
     $context['posts'] = array();
     foreach ($user_drafts as $row) {
         // Censor....
         if (empty($row['body'])) {
             $row['body'] = '';
         }
         $row['subject'] = Util::htmltrim($row['subject']);
         if (empty($row['subject'])) {
             $row['subject'] = $txt['no_subject'];
         }
         censorText($row['body']);
         censorText($row['subject']);
         // BBC-ilize the message.
         $row['body'] = parse_bbc($row['body'], true, 'draft' . $row['id_draft']);
         // Have they provided who this will go to?
         $recipients = array('to' => array(), 'bcc' => array());
         $recipient_ids = !empty($row['to_list']) ? unserialize($row['to_list']) : array();
         // Get nice names to show the user, the id's are not that great to see!
         if (!empty($recipient_ids['to']) || !empty($recipient_ids['bcc'])) {
             $recipient_ids['to'] = array_map('intval', $recipient_ids['to']);
             $recipient_ids['bcc'] = array_map('intval', $recipient_ids['bcc']);
             $allRecipients = array_merge($recipient_ids['to'], $recipient_ids['bcc']);
             $recipients = draftsRecipients($allRecipients, $recipient_ids);
         }
         // Add the items to the array for template use
         $context['drafts'][$counter += $reverse ? -1 : 1] = array('body' => $row['body'], 'counter' => $counter, 'alternate' => $counter % 2, 'subject' => $row['subject'], 'time' => standardTime($row['poster_time']), 'html_time' => htmlTime($row['poster_time']), 'timestamp' => forum_time(true, $row['poster_time']), 'id_draft' => $row['id_draft'], 'recipients' => $recipients, 'age' => floor((time() - $row['poster_time']) / 86400), 'remaining' => !empty($modSettings['drafts_keep_days']) ? floor($modSettings['drafts_keep_days'] - (time() - $row['poster_time']) / 86400) : 0);
     }
     // If the drafts were retrieved in reverse order, then put them in the right order again.
     if ($reverse) {
         $context['drafts'] = array_reverse($context['drafts'], true);
     }
     // Off to the template we go
     $context['page_title'] = $txt['drafts'];
     $context['sub_template'] = 'showPMDrafts';
     $context['linktree'][] = array('url' => $scripturl . '?action=pm;sa=showpmdrafts', 'name' => $txt['drafts']);
 }
Exemplo n.º 11
0
 /**
  * Show an area for the moderator to type into.
  */
 public function block_notes()
 {
     global $context, $scripturl, $txt, $user_info;
     // Are we saving a note?
     if (isset($_POST['makenote']) && isset($_POST['new_note'])) {
         checkSession();
         $new_note = Util::htmlspecialchars(trim($_POST['new_note']));
         // Make sure they actually entered something.
         if (!empty($new_note) && $new_note !== $txt['mc_click_add_note']) {
             // Insert it into the database then!
             addModeratorNote($user_info['id'], $user_info['name'], $new_note);
             // Clear the cache.
             cache_put_data('moderator_notes', null, 240);
             cache_put_data('moderator_notes_total', null, 240);
         }
         // Redirect otherwise people can resubmit.
         redirectexit('action=moderate');
     }
     // Bye... bye...
     if (isset($_GET['notes']) && isset($_GET['delete']) && is_numeric($_GET['delete'])) {
         checkSession('get');
         // Just checkin'!
         $id_delete = (int) $_GET['delete'];
         // Lets delete it.
         removeModeratorNote($id_delete);
         // Clear the cache.
         cache_put_data('moderator_notes', null, 240);
         cache_put_data('moderator_notes_total', null, 240);
         redirectexit('action=moderate');
     }
     // How many notes in total?
     $moderator_notes_total = countModeratorNotes();
     // Grab the current notes. We can only use the cache for the first page of notes.
     $offset = isset($_GET['notes']) && isset($_GET['start']) ? $_GET['start'] : 0;
     $moderator_notes = moderatorNotes($offset);
     // Lets construct a page index.
     $context['page_index'] = constructPageIndex($scripturl . '?action=moderate;area=index;notes', $_GET['start'], $moderator_notes_total, 10);
     $context['start'] = $_GET['start'];
     $context['notes'] = array();
     foreach ($moderator_notes as $note) {
         $context['notes'][] = array('author' => array('id' => $note['id_member'], 'link' => $note['id_member'] ? '<a href="' . $scripturl . '?action=profile;u=' . $note['id_member'] . '" title="' . $txt['on'] . ' ' . strip_tags(standardTime($note['log_time'])) . '">' . $note['member_name'] . '</a>' : $note['member_name']), 'time' => standardTime($note['log_time']), 'html_time' => htmlTime($note['log_time']), 'timestamp' => forum_time(true, $note['log_time']), 'text' => parse_bbc($note['body']), 'delete_href' => $scripturl . '?action=moderate;area=index;notes;delete=' . $note['id_note'] . ';' . $context['session_var'] . '=' . $context['session_id']);
     }
     return 'notes';
 }
Exemplo n.º 12
0
    /**
     * Used to edit the body or subject of a message inline
     * called from action=jsmodify from script and topic js
     */
    public function action_jsmodify()
    {
        global $modSettings, $board, $topic;
        global $user_info, $context;
        $db = database();
        // We have to have a topic!
        if (empty($topic)) {
            obExit(false);
        }
        checkSession('get');
        require_once SUBSDIR . '/Post.subs.php';
        // Assume the first message if no message ID was given.
        $request = $db->query('', '
			SELECT
				t.locked, t.num_replies, t.id_member_started, t.id_first_msg,
				m.id_msg, m.id_member, m.poster_time, m.subject, m.smileys_enabled, m.body, m.icon,
				m.modified_time, m.modified_name, m.approved
			FROM {db_prefix}messages AS m
				INNER JOIN {db_prefix}topics AS t ON (t.id_topic = {int:current_topic})
			WHERE m.id_msg = {raw:id_msg}
				AND m.id_topic = {int:current_topic}' . (allowedTo('modify_any') || allowedTo('approve_posts') ? '' : (!$modSettings['postmod_active'] ? '
				AND (m.id_member != {int:guest_id} AND m.id_member = {int:current_member})' : '
				AND (m.approved = {int:is_approved} OR (m.id_member != {int:guest_id} AND m.id_member = {int:current_member}))')), array('current_member' => $user_info['id'], 'current_topic' => $topic, 'id_msg' => empty($_REQUEST['msg']) ? 't.id_first_msg' : (int) $_REQUEST['msg'], 'is_approved' => 1, 'guest_id' => 0));
        if ($db->num_rows($request) == 0) {
            fatal_lang_error('no_board', false);
        }
        $row = $db->fetch_assoc($request);
        $db->free_result($request);
        // Change either body or subject requires permissions to modify messages.
        if (isset($_POST['message']) || isset($_POST['subject']) || isset($_REQUEST['icon'])) {
            if (!empty($row['locked'])) {
                isAllowedTo('moderate_board');
            }
            if ($row['id_member'] == $user_info['id'] && !allowedTo('modify_any')) {
                if ((!$modSettings['postmod_active'] || $row['approved']) && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + ($modSettings['edit_disable_time'] + 5) * 60 < time()) {
                    fatal_lang_error('modify_post_time_passed', false);
                } elseif ($row['id_member_started'] == $user_info['id'] && !allowedTo('modify_own')) {
                    isAllowedTo('modify_replies');
                } else {
                    isAllowedTo('modify_own');
                }
            } elseif ($row['id_member_started'] == $user_info['id'] && !allowedTo('modify_any')) {
                isAllowedTo('modify_replies');
            } else {
                isAllowedTo('modify_any');
            }
            // Only log this action if it wasn't your message.
            $moderationAction = $row['id_member'] != $user_info['id'];
        }
        $post_errors = Error_Context::context('post', 1);
        if (isset($_POST['subject']) && Util::htmltrim(Util::htmlspecialchars($_POST['subject'])) !== '') {
            $_POST['subject'] = strtr(Util::htmlspecialchars($_POST['subject']), array("\r" => '', "\n" => '', "\t" => ''));
            // Maximum number of characters.
            if (Util::strlen($_POST['subject']) > 100) {
                $_POST['subject'] = Util::substr($_POST['subject'], 0, 100);
            }
        } elseif (isset($_POST['subject'])) {
            $post_errors->addError('no_subject');
            unset($_POST['subject']);
        }
        if (isset($_POST['message'])) {
            if (Util::htmltrim(Util::htmlspecialchars($_POST['message'])) === '') {
                $post_errors->addError('no_message');
                unset($_POST['message']);
            } elseif (!empty($modSettings['max_messageLength']) && Util::strlen($_POST['message']) > $modSettings['max_messageLength']) {
                $post_errors->addError(array('long_message', array($modSettings['max_messageLength'])));
                unset($_POST['message']);
            } else {
                $_POST['message'] = Util::htmlspecialchars($_POST['message'], ENT_QUOTES);
                preparsecode($_POST['message']);
                if (Util::htmltrim(strip_tags(parse_bbc($_POST['message'], false), '<img>')) === '') {
                    $post_errors->addError('no_message');
                    unset($_POST['message']);
                }
            }
        }
        if (isset($_POST['lock'])) {
            if (!allowedTo(array('lock_any', 'lock_own')) || !allowedTo('lock_any') && $user_info['id'] != $row['id_member']) {
                unset($_POST['lock']);
            } elseif (!allowedTo('lock_any')) {
                if ($row['locked'] == 1) {
                    unset($_POST['lock']);
                } else {
                    $_POST['lock'] = empty($_POST['lock']) ? 0 : 2;
                }
            } elseif (!empty($row['locked']) && !empty($_POST['lock']) || $_POST['lock'] == $row['locked']) {
                unset($_POST['lock']);
            } else {
                $_POST['lock'] = empty($_POST['lock']) ? 0 : 1;
            }
        }
        if (isset($_POST['sticky']) && !allowedTo('make_sticky')) {
            unset($_POST['sticky']);
        }
        if (!$post_errors->hasErrors()) {
            $msgOptions = array('id' => $row['id_msg'], 'subject' => isset($_POST['subject']) ? $_POST['subject'] : null, 'body' => isset($_POST['message']) ? $_POST['message'] : null, 'icon' => isset($_REQUEST['icon']) ? preg_replace('~[\\./\\\\*\':"<>]~', '', $_REQUEST['icon']) : null);
            $topicOptions = array('id' => $topic, 'board' => $board, 'lock_mode' => isset($_POST['lock']) ? (int) $_POST['lock'] : null, 'sticky_mode' => isset($_POST['sticky']) && !empty($modSettings['enableStickyTopics']) ? (int) $_POST['sticky'] : null, 'mark_as_read' => false);
            $posterOptions = array();
            // Only consider marking as editing if they have edited the subject, message or icon.
            if (isset($_POST['subject']) && $_POST['subject'] != $row['subject'] || isset($_POST['message']) && $_POST['message'] != $row['body'] || isset($_REQUEST['icon']) && $_REQUEST['icon'] != $row['icon']) {
                // And even then only if the time has passed...
                if (time() - $row['poster_time'] > $modSettings['edit_wait_time'] || $user_info['id'] != $row['id_member']) {
                    $msgOptions['modify_time'] = time();
                    $msgOptions['modify_name'] = $user_info['name'];
                }
            } else {
                $moderationAction = false;
            }
            modifyPost($msgOptions, $topicOptions, $posterOptions);
            // If we didn't change anything this time but had before put back the old info.
            if (!isset($msgOptions['modify_time']) && !empty($row['modified_time'])) {
                $msgOptions['modify_time'] = $row['modified_time'];
                $msgOptions['modify_name'] = $row['modified_name'];
            }
            // Changing the first subject updates other subjects to 'Re: new_subject'.
            if (isset($_POST['subject']) && isset($_REQUEST['change_all_subjects']) && $row['id_first_msg'] == $row['id_msg'] && !empty($row['num_replies']) && (allowedTo('modify_any') || $row['id_member_started'] == $user_info['id'] && allowedTo('modify_replies'))) {
                // Get the proper (default language) response prefix first.
                $context['response_prefix'] = response_prefix();
                $db->query('', '
					UPDATE {db_prefix}messages
					SET subject = {string:subject}
					WHERE id_topic = {int:current_topic}
						AND id_msg != {int:id_first_msg}', array('current_topic' => $topic, 'id_first_msg' => $row['id_first_msg'], 'subject' => $context['response_prefix'] . $_POST['subject']));
            }
            if (!empty($moderationAction)) {
                logAction('modify', array('topic' => $topic, 'message' => $row['id_msg'], 'member' => $row['id_member'], 'board' => $board));
            }
        }
        if (isset($_REQUEST['xml'])) {
            $context['sub_template'] = 'modifydone';
            if (!$post_errors->hasErrors() && isset($msgOptions['subject']) && isset($msgOptions['body'])) {
                $context['message'] = array('id' => $row['id_msg'], 'modified' => array('time' => isset($msgOptions['modify_time']) ? standardTime($msgOptions['modify_time']) : '', 'html_time' => isset($msgOptions['modify_time']) ? htmlTime($msgOptions['modify_time']) : '', 'timestamp' => isset($msgOptions['modify_time']) ? forum_time(true, $msgOptions['modify_time']) : 0, 'name' => isset($msgOptions['modify_time']) ? $msgOptions['modify_name'] : ''), 'subject' => $msgOptions['subject'], 'first_in_topic' => $row['id_msg'] == $row['id_first_msg'], 'body' => strtr($msgOptions['body'], array(']]>' => ']]]]><![CDATA[>')));
                censorText($context['message']['subject']);
                censorText($context['message']['body']);
                $context['message']['body'] = parse_bbc($context['message']['body'], $row['smileys_enabled'], $row['id_msg']);
            } elseif (!$post_errors->hasErrors()) {
                $context['sub_template'] = 'modifytopicdone';
                $context['message'] = array('id' => $row['id_msg'], 'modified' => array('time' => isset($msgOptions['modify_time']) ? standardTime($msgOptions['modify_time']) : '', 'html_time' => isset($msgOptions['modify_time']) ? htmlTime($msgOptions['modify_time']) : '', 'timestamp' => isset($msgOptions['modify_time']) ? forum_time(true, $msgOptions['modify_time']) : 0, 'name' => isset($msgOptions['modify_time']) ? $msgOptions['modify_name'] : ''), 'subject' => isset($msgOptions['subject']) ? $msgOptions['subject'] : '');
                censorText($context['message']['subject']);
            } else {
                $context['message'] = array('id' => $row['id_msg'], 'errors' => array(), 'error_in_subject' => $post_errors->hasError('no_subject'), 'error_in_body' => $post_errors->hasError('no_message') || $post_errors->hasError('long_message'));
                $context['message']['errors'] = $post_errors->prepareErrors();
            }
        } else {
            obExit(false);
        }
    }
/**
 * Loads all the comments that an article has generated
 *
 * @param int|null $article_id
 * @param int|null $limit limit the number of results
 * @param int|null $start start number for pages
 */
function sportal_get_comments($article_id = null, $limit = null, $start = null)
{
    global $scripturl, $user_info, $color_profile;
    $db = database();
    $request = $db->query('', '
		SELECT
			spc.id_comment, IFNULL(spc.id_member, 0) AS id_author,
			IFNULL(m.real_name, spc.member_name) AS author_name,
			spc.body, spc.log_time,
			m.avatar, m.email_address,
			a.id_attach, a.attachment_type, a.filename
		FROM {db_prefix}sp_comments AS spc
			LEFT JOIN {db_prefix}members AS m ON (m.id_member = spc.id_member)
			LEFT JOIN {db_prefix}attachments AS a ON (a.id_member = m.id_member)
		WHERE spc.id_article = {int:article_id}
		ORDER BY spc.id_comment' . (!empty($limit) ? '
		LIMIT {int:start}, {int:limit}' : ''), array('article_id' => (int) $article_id, 'limit' => (int) $limit, 'start' => (int) $start));
    $return = array();
    $member_ids = array();
    while ($row = $db->fetch_assoc($request)) {
        if (!empty($row['id_author'])) {
            $member_ids[$row['id_author']] = $row['id_author'];
        }
        $return[$row['id_comment']] = array('id' => $row['id_comment'], 'body' => parse_bbc($row['body']), 'time' => htmlTime($row['log_time']), 'author' => array('id' => $row['id_author'], 'name' => $row['author_name'], 'href' => $scripturl . '?action=profile;u=' . $row['id_author'], 'link' => $row['id_author'] ? '<a href="' . $scripturl . '?action=profile;u=' . $row['id_author'] . '">' . $row['author_name'] . '</a>' : $row['author_name'], 'avatar' => determineAvatar(array('avatar' => $row['avatar'], 'filename' => $row['filename'], 'id_attach' => $row['id_attach'], 'email_address' => $row['email_address'], 'attachment_type' => $row['attachment_type']))), 'can_moderate' => allowedTo('sp_admin') || allowedTo('sp_manage_articles') || !$user_info['is_guest'] && $user_info['id'] == $row['id_author']);
    }
    $db->free_result($request);
    // Colorization
    if (!empty($member_ids) && sp_loadColors($member_ids) !== false) {
        foreach ($return as $key => $value) {
            if (!empty($color_profile[$value['author']['id']]['link'])) {
                $return[$key]['author']['link'] = $color_profile[$value['author']['id']]['link'];
            }
        }
    }
    return $return;
}
Exemplo n.º 14
0
 /**
  * Show the list of topics in this board, along with any sub-boards.
  * @uses MessageIndex template topic_listing sub template
  */
 public function action_messageindex()
 {
     global $txt, $scripturl, $board, $modSettings, $context;
     global $options, $settings, $board_info, $user_info;
     // Fairly often, we'll work with boards. Current board, sub-boards.
     require_once SUBSDIR . '/Boards.subs.php';
     // If this is a redirection board head off.
     if ($board_info['redirect']) {
         incrementBoard($board, 'num_posts');
         redirectexit($board_info['redirect']);
     }
     loadTemplate('MessageIndex');
     loadJavascriptFile('topic.js');
     $context['name'] = $board_info['name'];
     $context['sub_template'] = 'topic_listing';
     $context['description'] = $board_info['description'];
     $template_layers = Template_Layers::getInstance();
     // How many topics do we have in total?
     $board_info['total_topics'] = allowedTo('approve_posts') ? $board_info['num_topics'] + $board_info['unapproved_topics'] : $board_info['num_topics'] + $board_info['unapproved_user_topics'];
     // View all the topics, or just a few?
     $context['topics_per_page'] = empty($modSettings['disableCustomPerPage']) && !empty($options['topics_per_page']) ? $options['topics_per_page'] : $modSettings['defaultMaxTopics'];
     $context['messages_per_page'] = empty($modSettings['disableCustomPerPage']) && !empty($options['messages_per_page']) ? $options['messages_per_page'] : $modSettings['defaultMaxMessages'];
     $maxindex = isset($_REQUEST['all']) && !empty($modSettings['enableAllMessages']) ? $board_info['total_topics'] : $context['topics_per_page'];
     // Right, let's only index normal stuff!
     if (count($_GET) > 1) {
         $session_name = session_name();
         foreach ($_GET as $k => $v) {
             if (!in_array($k, array('board', 'start', $session_name))) {
                 $context['robot_no_index'] = true;
             }
         }
     }
     if (!empty($_REQUEST['start']) && (!is_numeric($_REQUEST['start']) || $_REQUEST['start'] % $context['messages_per_page'] != 0)) {
         $context['robot_no_index'] = true;
     }
     // If we can view unapproved messages and there are some build up a list.
     if (allowedTo('approve_posts') && ($board_info['unapproved_topics'] || $board_info['unapproved_posts'])) {
         $untopics = $board_info['unapproved_topics'] ? '<a href="' . $scripturl . '?action=moderate;area=postmod;sa=topics;brd=' . $board . '">' . $board_info['unapproved_topics'] . '</a>' : 0;
         $unposts = $board_info['unapproved_posts'] ? '<a href="' . $scripturl . '?action=moderate;area=postmod;sa=posts;brd=' . $board . '">' . ($board_info['unapproved_posts'] - $board_info['unapproved_topics']) . '</a>' : 0;
         $context['unapproved_posts_message'] = sprintf($txt['there_are_unapproved_topics'], $untopics, $unposts, $scripturl . '?action=moderate;area=postmod;sa=' . ($board_info['unapproved_topics'] ? 'topics' : 'posts') . ';brd=' . $board);
     }
     // We only know these.
     if (isset($_REQUEST['sort']) && !in_array($_REQUEST['sort'], array('subject', 'starter', 'last_poster', 'replies', 'views', 'likes', 'first_post', 'last_post'))) {
         $_REQUEST['sort'] = 'last_post';
     }
     // Make sure the starting place makes sense and construct the page index.
     if (isset($_REQUEST['sort'])) {
         $sort_string = ';sort=' . $_REQUEST['sort'] . (isset($_REQUEST['desc']) ? ';desc' : '');
     } else {
         $sort_string = '';
     }
     $context['page_index'] = constructPageIndex($scripturl . '?board=' . $board . '.%1$d' . $sort_string, $_REQUEST['start'], $board_info['total_topics'], $maxindex, true);
     $context['start'] =& $_REQUEST['start'];
     // Set a canonical URL for this page.
     $context['canonical_url'] = $scripturl . '?board=' . $board . '.' . $context['start'];
     $context['links'] += array('prev' => $_REQUEST['start'] >= $context['topics_per_page'] ? $scripturl . '?board=' . $board . '.' . ($_REQUEST['start'] - $context['topics_per_page']) : '', 'next' => $_REQUEST['start'] + $context['topics_per_page'] < $board_info['total_topics'] ? $scripturl . '?board=' . $board . '.' . ($_REQUEST['start'] + $context['topics_per_page']) : '');
     $context['page_info'] = array('current_page' => $_REQUEST['start'] / $context['topics_per_page'] + 1, 'num_pages' => floor(($board_info['total_topics'] - 1) / $context['topics_per_page']) + 1);
     if (isset($_REQUEST['all']) && !empty($modSettings['enableAllMessages']) && $maxindex > $modSettings['enableAllMessages']) {
         $maxindex = $modSettings['enableAllMessages'];
         $_REQUEST['start'] = 0;
     }
     // Build a list of the board's moderators.
     $context['moderators'] =& $board_info['moderators'];
     $context['link_moderators'] = array();
     if (!empty($board_info['moderators'])) {
         foreach ($board_info['moderators'] as $mod) {
             $context['link_moderators'][] = '<a href="' . $scripturl . '?action=profile;u=' . $mod['id'] . '" title="' . $txt['board_moderator'] . '">' . $mod['name'] . '</a>';
         }
     }
     // Mark current and parent boards as seen.
     if (!$user_info['is_guest']) {
         // We can't know they read it if we allow prefetches.
         if (isset($_SERVER['HTTP_X_MOZ']) && $_SERVER['HTTP_X_MOZ'] == 'prefetch') {
             @ob_end_clean();
             header('HTTP/1.1 403 Prefetch Forbidden');
             die;
         }
         // Mark the board as read, and its parents.
         if (!empty($board_info['parent_boards'])) {
             $board_list = array_keys($board_info['parent_boards']);
             $board_list[] = $board;
         } else {
             $board_list = array($board);
         }
         // Mark boards as read. Boards alone, no need for topics.
         markBoardsRead($board_list, false, false);
         // Clear topicseen cache
         if (!empty($board_info['parent_boards'])) {
             // We've seen all these boards now!
             foreach ($board_info['parent_boards'] as $k => $dummy) {
                 if (isset($_SESSION['topicseen_cache'][$k])) {
                     unset($_SESSION['topicseen_cache'][$k]);
                 }
             }
         }
         if (isset($_SESSION['topicseen_cache'][$board])) {
             unset($_SESSION['topicseen_cache'][$board]);
         }
         // From now on, they've seen it. So we reset notifications.
         $context['is_marked_notify'] = resetSentBoardNotification($user_info['id'], $board);
     } else {
         $context['is_marked_notify'] = false;
     }
     // 'Print' the header and board info.
     $context['page_title'] = strip_tags($board_info['name']);
     // Set the variables up for the template.
     $context['can_mark_notify'] = allowedTo('mark_notify') && !$user_info['is_guest'];
     $context['can_post_new'] = allowedTo('post_new') || $modSettings['postmod_active'] && allowedTo('post_unapproved_topics');
     $context['can_post_poll'] = !empty($modSettings['pollMode']) && allowedTo('poll_post') && $context['can_post_new'];
     $context['can_moderate_forum'] = allowedTo('moderate_forum');
     $context['can_approve_posts'] = allowedTo('approve_posts');
     // Prepare sub-boards for display.
     require_once SUBSDIR . '/BoardsList.class.php';
     $boardIndexOptions = array('include_categories' => false, 'base_level' => $board_info['child_level'] + 1, 'parent_id' => $board_info['id'], 'set_latest_post' => false, 'countChildPosts' => !empty($modSettings['countChildPosts']));
     $boardlist = new Boards_List($boardIndexOptions);
     $context['boards'] = $boardlist->getBoards();
     // Nosey, nosey - who's viewing this board?
     if (!empty($settings['display_who_viewing'])) {
         require_once SUBSDIR . '/Who.subs.php';
         formatViewers($board, 'board');
     }
     // And now, what we're here for: topics!
     require_once SUBSDIR . '/MessageIndex.subs.php';
     // Known sort methods.
     $sort_methods = messageIndexSort();
     // They didn't pick one, default to by last post descending.
     if (!isset($_REQUEST['sort']) || !isset($sort_methods[$_REQUEST['sort']])) {
         $context['sort_by'] = 'last_post';
         $ascending = isset($_REQUEST['asc']);
     } else {
         $context['sort_by'] = $_REQUEST['sort'];
         $ascending = !isset($_REQUEST['desc']);
     }
     $sort_column = $sort_methods[$context['sort_by']];
     $context['sort_direction'] = $ascending ? 'up' : 'down';
     $context['sort_title'] = $ascending ? $txt['sort_desc'] : $txt['sort_asc'];
     // Trick
     $txt['starter'] = $txt['started_by'];
     foreach ($sort_methods as $key => $val) {
         $context['topics_headers'][$key] = array('url' => $scripturl . '?board=' . $context['current_board'] . '.' . $context['start'] . ';sort=' . $key . ($context['sort_by'] == $key && $context['sort_direction'] == 'up' ? ';desc' : ''), 'sort_dir_img' => $context['sort_by'] == $key ? '<img class="sort" src="' . $settings['images_url'] . '/sort_' . $context['sort_direction'] . '.png" alt="" title="' . $context['sort_title'] . '" />' : '');
     }
     // Calculate the fastest way to get the topics.
     $start = (int) $_REQUEST['start'];
     if ($start > ($board_info['total_topics'] - 1) / 2) {
         $ascending = !$ascending;
         $fake_ascending = true;
         $maxindex = $board_info['total_topics'] < $start + $maxindex + 1 ? $board_info['total_topics'] - $start : $maxindex;
         $start = $board_info['total_topics'] < $start + $maxindex + 1 ? 0 : $board_info['total_topics'] - $start - $maxindex;
     } else {
         $fake_ascending = false;
     }
     // Setup the default topic icons...
     $context['icon_sources'] = MessageTopicIcons();
     $topic_ids = array();
     $context['topics'] = array();
     // Set up the query options
     $indexOptions = array('include_sticky' => !empty($modSettings['enableStickyTopics']), 'only_approved' => $modSettings['postmod_active'] && !allowedTo('approve_posts'), 'previews' => !empty($modSettings['message_index_preview']) ? empty($modSettings['preview_characters']) ? -1 : $modSettings['preview_characters'] : 0, 'include_avatars' => !empty($settings['avatars_on_indexes']), 'ascending' => $ascending, 'fake_ascending' => $fake_ascending);
     // Allow integration to modify / add to the $indexOptions
     call_integration_hook('integrate_messageindex_topics', array(&$sort_column, &$indexOptions));
     $topics_info = messageIndexTopics($board, $user_info['id'], $start, $maxindex, $context['sort_by'], $sort_column, $indexOptions);
     // Prepare for links to guests (for search engines)
     $context['pageindex_multiplier'] = empty($modSettings['disableCustomPerPage']) && !empty($options['messages_per_page']) ? $options['messages_per_page'] : $modSettings['defaultMaxMessages'];
     // Begin 'printing' the message index for current board.
     foreach ($topics_info as $row) {
         $topic_ids[] = $row['id_topic'];
         // Do they want message previews?
         if (!empty($modSettings['message_index_preview'])) {
             // Limit them to $modSettings['preview_characters'] characters
             $row['first_body'] = strip_tags(strtr(parse_bbc($row['first_body'], false, $row['id_first_msg']), array('<br />' => "\n", '&nbsp;' => ' ')));
             $row['first_body'] = Util::shorten_text($row['first_body'], !empty($modSettings['preview_characters']) ? $modSettings['preview_characters'] : 128, true);
             // No reply then they are the same, no need to process it again
             if ($row['num_replies'] == 0) {
                 $row['last_body'] == $row['first_body'];
             } else {
                 $row['last_body'] = strip_tags(strtr(parse_bbc($row['last_body'], false, $row['id_last_msg']), array('<br />' => "\n", '&nbsp;' => ' ')));
                 $row['last_body'] = Util::shorten_text($row['last_body'], !empty($modSettings['preview_characters']) ? $modSettings['preview_characters'] : 128, true);
             }
             // Censor the subject and message preview.
             censorText($row['first_subject']);
             censorText($row['first_body']);
             // Don't censor them twice!
             if ($row['id_first_msg'] == $row['id_last_msg']) {
                 $row['last_subject'] = $row['first_subject'];
                 $row['last_body'] = $row['first_body'];
             } else {
                 censorText($row['last_subject']);
                 censorText($row['last_body']);
             }
         } else {
             $row['first_body'] = '';
             $row['last_body'] = '';
             censorText($row['first_subject']);
             if ($row['id_first_msg'] == $row['id_last_msg']) {
                 $row['last_subject'] = $row['first_subject'];
             } else {
                 censorText($row['last_subject']);
             }
         }
         // Decide how many pages the topic should have.
         if ($row['num_replies'] + 1 > $context['messages_per_page']) {
             // We can't pass start by reference.
             $start = -1;
             $pages = constructPageIndex($scripturl . '?topic=' . $row['id_topic'] . '.%1$d', $start, $row['num_replies'] + 1, $context['messages_per_page'], true, array('prev_next' => false, 'all' => !empty($modSettings['enableAllMessages']) && $row['num_replies'] + 1 < $modSettings['enableAllMessages']));
         } else {
             $pages = '';
         }
         // We need to check the topic icons exist...
         if (!empty($modSettings['messageIconChecks_enable'])) {
             if (!isset($context['icon_sources'][$row['first_icon']])) {
                 $context['icon_sources'][$row['first_icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $row['first_icon'] . '.png') ? 'images_url' : 'default_images_url';
             }
             if (!isset($context['icon_sources'][$row['last_icon']])) {
                 $context['icon_sources'][$row['last_icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $row['last_icon'] . '.png') ? 'images_url' : 'default_images_url';
             }
         } else {
             if (!isset($context['icon_sources'][$row['first_icon']])) {
                 $context['icon_sources'][$row['first_icon']] = 'images_url';
             }
             if (!isset($context['icon_sources'][$row['last_icon']])) {
                 $context['icon_sources'][$row['last_icon']] = 'images_url';
             }
         }
         // 'Print' the topic info.
         $context['topics'][$row['id_topic']] = array('id' => $row['id_topic'], 'first_post' => array('id' => $row['id_first_msg'], 'member' => array('username' => $row['first_member_name'], 'name' => $row['first_display_name'], 'id' => $row['first_id_member'], 'href' => !empty($row['first_id_member']) ? $scripturl . '?action=profile;u=' . $row['first_id_member'] : '', 'link' => !empty($row['first_id_member']) ? '<a href="' . $scripturl . '?action=profile;u=' . $row['first_id_member'] . '" title="' . $txt['profile_of'] . ' ' . $row['first_display_name'] . '" class="preview">' . $row['first_display_name'] . '</a>' : $row['first_display_name']), 'time' => standardTime($row['first_poster_time']), 'html_time' => htmlTime($row['first_poster_time']), 'timestamp' => forum_time(true, $row['first_poster_time']), 'subject' => $row['first_subject'], 'preview' => trim($row['first_body']), 'icon' => $row['first_icon'], 'icon_url' => $settings[$context['icon_sources'][$row['first_icon']]] . '/post/' . $row['first_icon'] . '.png', 'href' => $scripturl . '?topic=' . $row['id_topic'] . '.0', 'link' => '<a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.0">' . $row['first_subject'] . '</a>'), 'last_post' => array('id' => $row['id_last_msg'], 'member' => array('username' => $row['last_member_name'], 'name' => $row['last_display_name'], 'id' => $row['last_id_member'], 'href' => !empty($row['last_id_member']) ? $scripturl . '?action=profile;u=' . $row['last_id_member'] : '', 'link' => !empty($row['last_id_member']) ? '<a href="' . $scripturl . '?action=profile;u=' . $row['last_id_member'] . '">' . $row['last_display_name'] . '</a>' : $row['last_display_name']), 'time' => standardTime($row['last_poster_time']), 'html_time' => htmlTime($row['last_poster_time']), 'timestamp' => forum_time(true, $row['last_poster_time']), 'subject' => $row['last_subject'], 'preview' => trim($row['last_body']), 'icon' => $row['last_icon'], 'icon_url' => $settings[$context['icon_sources'][$row['last_icon']]] . '/post/' . $row['last_icon'] . '.png', 'href' => $scripturl . '?topic=' . $row['id_topic'] . ($user_info['is_guest'] ? '.' . (int) ($row['num_replies'] / $context['pageindex_multiplier']) * $context['pageindex_multiplier'] . '#msg' . $row['id_last_msg'] : ($row['num_replies'] == 0 ? '.0' : '.msg' . $row['id_last_msg']) . '#new'), 'link' => '<a href="' . $scripturl . '?topic=' . $row['id_topic'] . ($user_info['is_guest'] ? '.' . (int) ($row['num_replies'] / $context['pageindex_multiplier']) * $context['pageindex_multiplier'] . '#msg' . $row['id_last_msg'] : ($row['num_replies'] == 0 ? '.0' : '.msg' . $row['id_last_msg']) . '#new') . '" ' . ($row['num_replies'] == 0 ? '' : 'rel="nofollow"') . '>' . $row['last_subject'] . '</a>'), 'default_preview' => trim($row[!empty($modSettings['message_index_preview']) && $modSettings['message_index_preview'] == 2 ? 'last_body' : 'first_body']), 'is_sticky' => !empty($modSettings['enableStickyTopics']) && !empty($row['is_sticky']), 'is_locked' => !empty($row['locked']), 'is_poll' => !empty($modSettings['pollMode']) && $row['id_poll'] > 0, 'is_hot' => !empty($modSettings['useLikesNotViews']) ? $row['num_likes'] >= $modSettings['hotTopicPosts'] : $row['num_replies'] >= $modSettings['hotTopicPosts'], 'is_very_hot' => !empty($modSettings['useLikesNotViews']) ? $row['num_likes'] >= $modSettings['hotTopicVeryPosts'] : $row['num_replies'] >= $modSettings['hotTopicVeryPosts'], 'is_posted_in' => false, 'icon' => $row['first_icon'], 'icon_url' => $settings[$context['icon_sources'][$row['first_icon']]] . '/post/' . $row['first_icon'] . '.png', 'subject' => $row['first_subject'], 'new' => $row['new_from'] <= $row['id_msg_modified'], 'new_from' => $row['new_from'], 'newtime' => $row['new_from'], 'new_href' => $scripturl . '?topic=' . $row['id_topic'] . '.msg' . $row['new_from'] . '#new', 'redir_href' => !empty($row['id_redirect_topic']) ? $scripturl . '?topic=' . $row['id_topic'] . '.0;noredir' : '', 'pages' => $pages, 'replies' => comma_format($row['num_replies']), 'views' => comma_format($row['num_views']), 'likes' => comma_format($row['num_likes']), 'approved' => $row['approved'], 'unapproved_posts' => $row['unapproved_posts']);
         if (!empty($settings['avatars_on_indexes'])) {
             $context['topics'][$row['id_topic']]['last_post']['member']['avatar'] = determineAvatar($row);
         }
         determineTopicClass($context['topics'][$row['id_topic']]);
     }
     // Allow addons to add to the $context['topics']
     call_integration_hook('integrate_messageindex_listing', array($topics_info));
     // Fix the sequence of topics if they were retrieved in the wrong order. (for speed reasons...)
     if ($fake_ascending) {
         $context['topics'] = array_reverse($context['topics'], true);
     }
     if (!empty($modSettings['enableParticipation']) && !$user_info['is_guest'] && !empty($topic_ids)) {
         $topics_participated_in = topicsParticipation($user_info['id'], $topic_ids);
         foreach ($topics_participated_in as $participated) {
             $context['topics'][$participated['id_topic']]['is_posted_in'] = true;
             $context['topics'][$participated['id_topic']]['class'] = 'my_' . $context['topics'][$participated['id_topic']]['class'];
         }
     }
     $context['jump_to'] = array('label' => addslashes(un_htmlspecialchars($txt['jump_to'])), 'board_name' => htmlspecialchars(strtr(strip_tags($board_info['name']), array('&amp;' => '&')), ENT_COMPAT, 'UTF-8'), 'child_level' => $board_info['child_level']);
     // Is Quick Moderation active/needed?
     if (!empty($options['display_quick_mod']) && !empty($context['topics'])) {
         $context['can_markread'] = $context['user']['is_logged'];
         $context['can_lock'] = allowedTo('lock_any');
         $context['can_sticky'] = allowedTo('make_sticky') && !empty($modSettings['enableStickyTopics']);
         $context['can_move'] = allowedTo('move_any');
         $context['can_remove'] = allowedTo('remove_any');
         $context['can_merge'] = allowedTo('merge_any');
         // Ignore approving own topics as it's unlikely to come up...
         $context['can_approve'] = $modSettings['postmod_active'] && allowedTo('approve_posts') && !empty($board_info['unapproved_topics']);
         // Can we restore topics?
         $context['can_restore'] = allowedTo('move_any') && !empty($modSettings['recycle_enable']) && $modSettings['recycle_board'] == $board;
         // Set permissions for all the topics.
         foreach ($context['topics'] as $t => $topic) {
             $started = $topic['first_post']['member']['id'] == $user_info['id'];
             $context['topics'][$t]['quick_mod'] = array('lock' => allowedTo('lock_any') || $started && allowedTo('lock_own'), 'sticky' => allowedTo('make_sticky') && !empty($modSettings['enableStickyTopics']), 'move' => allowedTo('move_any') || $started && allowedTo('move_own'), 'modify' => allowedTo('modify_any') || $started && allowedTo('modify_own'), 'remove' => allowedTo('remove_any') || $started && allowedTo('remove_own'), 'approve' => $context['can_approve'] && $topic['unapproved_posts']);
             $context['can_lock'] |= $started && allowedTo('lock_own');
             $context['can_move'] |= $started && allowedTo('move_own');
             $context['can_remove'] |= $started && allowedTo('remove_own');
         }
         // Can we use quick moderation checkboxes?
         if ($options['display_quick_mod'] == 1) {
             $context['can_quick_mod'] = $context['user']['is_logged'] || $context['can_approve'] || $context['can_remove'] || $context['can_lock'] || $context['can_sticky'] || $context['can_move'] || $context['can_merge'] || $context['can_restore'];
         } else {
             $context['can_quick_mod'] = $context['can_remove'] || $context['can_lock'] || $context['can_sticky'] || $context['can_move'];
         }
     }
     if (!empty($context['can_quick_mod']) && $options['display_quick_mod'] == 1) {
         $context['qmod_actions'] = array('approve', 'remove', 'lock', 'sticky', 'move', 'merge', 'restore', 'markread');
         call_integration_hook('integrate_quick_mod_actions');
     }
     if (!empty($context['boards']) && $context['start'] == 0) {
         $template_layers->add('display_child_boards');
     }
     // If there are children, but no topics and no ability to post topics...
     $context['no_topic_listing'] = !empty($context['boards']) && empty($context['topics']) && !$context['can_post_new'];
     $template_layers->add('topic_listing');
     addJavascriptVar(array('notification_board_notice' => $context['is_marked_notify'] ? $txt['notification_disable_board'] : $txt['notification_enable_board']), true);
     // Build the message index button array.
     $context['normal_buttons'] = array('new_topic' => array('test' => 'can_post_new', 'text' => 'new_topic', 'image' => 'new_topic.png', 'lang' => true, 'url' => $scripturl . '?action=post;board=' . $context['current_board'] . '.0', 'active' => true), 'notify' => array('test' => 'can_mark_notify', 'text' => $context['is_marked_notify'] ? 'unnotify' : 'notify', 'image' => ($context['is_marked_notify'] ? 'un' : '') . 'notify.png', 'lang' => true, 'custom' => 'onclick="return notifyboardButton(this);"', 'url' => $scripturl . '?action=notifyboard;sa=' . ($context['is_marked_notify'] ? 'off' : 'on') . ';board=' . $context['current_board'] . '.' . $context['start'] . ';' . $context['session_var'] . '=' . $context['session_id']));
     // They can only mark read if they are logged in and it's enabled!
     if (!$user_info['is_guest'] && $settings['show_mark_read']) {
         $context['normal_buttons']['markread'] = array('text' => 'mark_read_short', 'image' => 'markread.png', 'lang' => true, 'url' => $scripturl . '?action=markasread;sa=board;board=' . $context['current_board'] . '.0;' . $context['session_var'] . '=' . $context['session_id'], 'custom' => 'onclick="return markboardreadButton(this);"');
     }
     // Allow adding new buttons easily.
     call_integration_hook('integrate_messageindex_buttons');
 }
Exemplo n.º 15
0
    /**
     * Actually do the search of personal messages and show the results
     *
     * What it does:
     * - accessed with ?action=pm;sa=search2
     * - checks user input and searches the pm table for messages matching the query.
     * - uses the search_results sub template of the PersonalMessage template.
     * - show the results of the search query.
     */
    public function action_search2()
    {
        global $scripturl, $modSettings, $context, $txt, $memberContext;
        $db = database();
        // Make sure the server is able to do this right now
        if (!empty($modSettings['loadavg_search']) && $modSettings['current_load'] >= $modSettings['loadavg_search']) {
            fatal_lang_error('loadavg_search_disabled', false);
        }
        // Some useful general permissions.
        $context['can_send_pm'] = allowedTo('pm_send');
        // Some hardcoded variables that can be tweaked if required.
        $maxMembersToSearch = 500;
        // Extract all the search parameters.
        $search_params = array();
        if (isset($_REQUEST['params'])) {
            $temp_params = explode('|"|', base64_decode(strtr($_REQUEST['params'], array(' ' => '+'))));
            foreach ($temp_params as $i => $data) {
                @(list($k, $v) = explode('|\'|', $data));
                $search_params[$k] = $v;
            }
        }
        $context['start'] = isset($_GET['start']) ? (int) $_GET['start'] : 0;
        // Store whether simple search was used (needed if the user wants to do another query).
        if (!isset($search_params['advanced'])) {
            $search_params['advanced'] = empty($_REQUEST['advanced']) ? 0 : 1;
        }
        // 1 => 'allwords' (default, don't set as param) / 2 => 'anywords'.
        if (!empty($search_params['searchtype']) || !empty($_REQUEST['searchtype']) && $_REQUEST['searchtype'] == 2) {
            $search_params['searchtype'] = 2;
        }
        // Minimum age of messages. Default to zero (don't set param in that case).
        if (!empty($search_params['minage']) || !empty($_REQUEST['minage']) && $_REQUEST['minage'] > 0) {
            $search_params['minage'] = !empty($search_params['minage']) ? (int) $search_params['minage'] : (int) $_REQUEST['minage'];
        }
        // Maximum age of messages. Default to infinite (9999 days: param not set).
        if (!empty($search_params['maxage']) || !empty($_REQUEST['maxage']) && $_REQUEST['maxage'] < 9999) {
            $search_params['maxage'] = !empty($search_params['maxage']) ? (int) $search_params['maxage'] : (int) $_REQUEST['maxage'];
        }
        // Search modifiers
        $search_params['subject_only'] = !empty($search_params['subject_only']) || !empty($_REQUEST['subject_only']);
        $search_params['show_complete'] = !empty($search_params['show_complete']) || !empty($_REQUEST['show_complete']);
        $search_params['sent_only'] = !empty($search_params['sent_only']) || !empty($_REQUEST['sent_only']);
        $context['folder'] = empty($search_params['sent_only']) ? 'inbox' : 'sent';
        // Default the user name to a wildcard matching every user (*).
        if (!empty($search_params['userspec']) || !empty($_REQUEST['userspec']) && $_REQUEST['userspec'] != '*') {
            $search_params['userspec'] = isset($search_params['userspec']) ? $search_params['userspec'] : $_REQUEST['userspec'];
        }
        // This will be full of all kinds of parameters!
        $searchq_parameters = array();
        // If there's no specific user, then don't mention it in the main query.
        if (empty($search_params['userspec'])) {
            $userQuery = '';
        } else {
            // Set up so we can seach by user name, wildcards, like, etc
            $userString = strtr(Util::htmlspecialchars($search_params['userspec'], ENT_QUOTES), array('&quot;' => '"'));
            $userString = strtr($userString, array('%' => '\\%', '_' => '\\_', '*' => '%', '?' => '_'));
            preg_match_all('~"([^"]+)"~', $userString, $matches);
            $possible_users = array_merge($matches[1], explode(',', preg_replace('~"[^"]+"~', '', $userString)));
            require_once SUBSDIR . '/Members.subs.php';
            // Who matches those criteria?
            $members = membersBy('member_names', array('member_names' => $possible_users));
            foreach ($possible_users as $key => $possible_user) {
                $searchq_parameters['guest_user_name_implode_' . $key] = defined('DB_CASE_SENSITIVE') ? strtolower($possible_user) : $possible_user;
            }
            // Simply do nothing if there are too many members matching the criteria.
            if (count($members) > $maxMembersToSearch) {
                $userQuery = '';
            } elseif (count($members) == 0) {
                if ($context['folder'] === 'inbox') {
                    $uq = array();
                    $name = defined('DB_CASE_SENSITIVE') ? 'LOWER(pm.from_name)' : 'pm.from_name';
                    foreach (array_keys($possible_users) as $key) {
                        $uq[] = 'AND pm.id_member_from = 0 AND (' . $name . ' LIKE {string:guest_user_name_implode_' . $key . '})';
                    }
                    $userQuery = implode(' ', $uq);
                    $searchq_parameters['pm_from_name'] = defined('DB_CASE_SENSITIVE') ? 'LOWER(pm.from_name)' : 'pm.from_name';
                } else {
                    $userQuery = '';
                }
            } else {
                $memberlist = array();
                foreach ($members as $id) {
                    $memberlist[] = $id;
                }
                // Use the name as as sent from or sent to
                if ($context['folder'] === 'inbox') {
                    $uq = array();
                    $name = defined('DB_CASE_SENSITIVE') ? 'LOWER(pm.from_name)' : 'pm.from_name';
                    foreach (array_keys($possible_users) as $key) {
                        $uq[] = 'AND (pm.id_member_from IN ({array_int:member_list}) OR (pm.id_member_from = 0 AND (' . $name . ' LIKE {string:guest_user_name_implode_' . $key . '})))';
                    }
                    $userQuery = implode(' ', $uq);
                } else {
                    $userQuery = 'AND (pmr.id_member IN ({array_int:member_list}))';
                }
                $searchq_parameters['pm_from_name'] = defined('DB_CASE_SENSITIVE') ? 'LOWER(pm.from_name)' : 'pm.from_name';
                $searchq_parameters['member_list'] = $memberlist;
            }
        }
        // Setup the sorting variables...
        $sort_columns = array('pm.id_pm');
        if (empty($search_params['sort']) && !empty($_REQUEST['sort'])) {
            list($search_params['sort'], $search_params['sort_dir']) = array_pad(explode('|', $_REQUEST['sort']), 2, '');
        }
        $search_params['sort'] = !empty($search_params['sort']) && in_array($search_params['sort'], $sort_columns) ? $search_params['sort'] : 'pm.id_pm';
        $search_params['sort_dir'] = !empty($search_params['sort_dir']) && $search_params['sort_dir'] == 'asc' ? 'asc' : 'desc';
        // Sort out any labels we may be searching by.
        $labelQuery = '';
        if ($context['folder'] == 'inbox' && !empty($search_params['advanced']) && $context['currently_using_labels']) {
            // Came here from pagination?  Put them back into $_REQUEST for sanitization.
            if (isset($search_params['labels'])) {
                $_REQUEST['searchlabel'] = explode(',', $search_params['labels']);
            }
            // Assuming we have some labels - make them all integers.
            if (!empty($_REQUEST['searchlabel']) && is_array($_REQUEST['searchlabel'])) {
                $_REQUEST['searchlabel'] = array_map('intval', $_REQUEST['searchlabel']);
            } else {
                $_REQUEST['searchlabel'] = array();
            }
            // Now that everything is cleaned up a bit, make the labels a param.
            $search_params['labels'] = implode(',', $_REQUEST['searchlabel']);
            // No labels selected? That must be an error!
            if (empty($_REQUEST['searchlabel'])) {
                $context['search_errors']['no_labels_selected'] = true;
            } elseif (count($_REQUEST['searchlabel']) != count($context['labels'])) {
                $labelQuery = '
				AND {raw:label_implode}';
                $labelStatements = array();
                foreach ($_REQUEST['searchlabel'] as $label) {
                    $labelStatements[] = $db->quote('FIND_IN_SET({string:label}, pmr.labels) != 0', array('label' => $label));
                }
                $searchq_parameters['label_implode'] = '(' . implode(' OR ', $labelStatements) . ')';
            }
        }
        // Unfortunately, searching for words like this is going to be slow, so we're blacklisting them.
        $blacklisted_words = array('quote', 'the', 'is', 'it', 'are', 'if');
        // What are we actually searching for?
        $search_params['search'] = !empty($search_params['search']) ? $search_params['search'] : (isset($_REQUEST['search']) ? $_REQUEST['search'] : '');
        // If nothing is left to search on - we set an error!
        if (!isset($search_params['search']) || $search_params['search'] == '') {
            $context['search_errors']['invalid_search_string'] = true;
        }
        // Change non-word characters into spaces.
        $stripped_query = preg_replace('~(?:[\\x0B\\0\\x{A0}\\t\\r\\s\\n(){}\\[\\]<>!@$%^*.,:+=`\\~\\?/\\\\]+|&(?:amp|lt|gt|quot);)+~u', ' ', $search_params['search']);
        // Make the query lower case since it will case insensitive anyway.
        $stripped_query = un_htmlspecialchars(Util::strtolower($stripped_query));
        // Extract phrase parts first (e.g. some words "this is a phrase" some more words.)
        preg_match_all('/(?:^|\\s)([-]?)"([^"]+)"(?:$|\\s)/', $stripped_query, $matches, PREG_PATTERN_ORDER);
        $phraseArray = $matches[2];
        // Remove the phrase parts and extract the words.
        $wordArray = preg_replace('~(?:^|\\s)(?:[-]?)"(?:[^"]+)"(?:$|\\s)~u', ' ', $search_params['search']);
        $wordArray = explode(' ', Util::htmlspecialchars(un_htmlspecialchars($wordArray), ENT_QUOTES));
        // A minus sign in front of a word excludes the word.... so...
        $excludedWords = array();
        // Check for things like -"some words", but not "-some words".
        foreach ($matches[1] as $index => $word) {
            if ($word === '-') {
                if (($word = trim($phraseArray[$index], '-_\' ')) !== '' && !in_array($word, $blacklisted_words)) {
                    $excludedWords[] = $word;
                }
                unset($phraseArray[$index]);
            }
        }
        // Now we look for -test, etc
        foreach ($wordArray as $index => $word) {
            if (strpos(trim($word), '-') === 0) {
                if (($word = trim($word, '-_\' ')) !== '' && !in_array($word, $blacklisted_words)) {
                    $excludedWords[] = $word;
                }
                unset($wordArray[$index]);
            }
        }
        // The remaining words and phrases are all included.
        $searchArray = array_merge($phraseArray, $wordArray);
        // Trim everything and make sure there are no words that are the same.
        foreach ($searchArray as $index => $value) {
            // Skip anything thats close to empty.
            if (($searchArray[$index] = trim($value, '-_\' ')) === '') {
                unset($searchArray[$index]);
            } elseif (in_array($searchArray[$index], $blacklisted_words)) {
                $foundBlackListedWords = true;
                unset($searchArray[$index]);
            }
            $searchArray[$index] = Util::strtolower(trim($value));
            if ($searchArray[$index] == '') {
                unset($searchArray[$index]);
            } else {
                // Sort out entities first.
                $searchArray[$index] = Util::htmlspecialchars($searchArray[$index]);
            }
        }
        $searchArray = array_slice(array_unique($searchArray), 0, 10);
        // Create an array of replacements for highlighting.
        $context['mark'] = array();
        foreach ($searchArray as $word) {
            $context['mark'][$word] = '<strong class="highlight">' . $word . '</strong>';
        }
        // This contains *everything*
        $searchWords = array_merge($searchArray, $excludedWords);
        // Make sure at least one word is being searched for.
        if (empty($searchArray)) {
            $context['search_errors']['invalid_search_string' . (!empty($foundBlackListedWords) ? '_blacklist' : '')] = true;
        }
        // Sort out the search query so the user can edit it - if they want.
        $context['search_params'] = $search_params;
        if (isset($context['search_params']['search'])) {
            $context['search_params']['search'] = Util::htmlspecialchars($context['search_params']['search']);
        }
        if (isset($context['search_params']['userspec'])) {
            $context['search_params']['userspec'] = Util::htmlspecialchars($context['search_params']['userspec']);
        }
        // Now we have all the parameters, combine them together for pagination and the like...
        $context['params'] = array();
        foreach ($search_params as $k => $v) {
            $context['params'][] = $k . '|\'|' . $v;
        }
        $context['params'] = base64_encode(implode('|"|', $context['params']));
        // Compile the subject query part.
        $andQueryParts = array();
        foreach ($searchWords as $index => $word) {
            if ($word == '') {
                continue;
            }
            if ($search_params['subject_only']) {
                $andQueryParts[] = 'pm.subject' . (in_array($word, $excludedWords) ? ' NOT' : '') . ' LIKE {string:search_' . $index . '}';
            } else {
                $andQueryParts[] = '(pm.subject' . (in_array($word, $excludedWords) ? ' NOT' : '') . ' LIKE {string:search_' . $index . '} ' . (in_array($word, $excludedWords) ? 'AND pm.body NOT' : 'OR pm.body') . ' LIKE {string:search_' . $index . '})';
            }
            $searchq_parameters['search_' . $index] = '%' . strtr($word, array('_' => '\\_', '%' => '\\%')) . '%';
        }
        $searchQuery = ' 1=1';
        if (!empty($andQueryParts)) {
            $searchQuery = implode(!empty($search_params['searchtype']) && $search_params['searchtype'] == 2 ? ' OR ' : ' AND ', $andQueryParts);
        }
        // Age limits?
        $timeQuery = '';
        if (!empty($search_params['minage'])) {
            $timeQuery .= ' AND pm.msgtime < ' . (time() - $search_params['minage'] * 86400);
        }
        if (!empty($search_params['maxage'])) {
            $timeQuery .= ' AND pm.msgtime > ' . (time() - $search_params['maxage'] * 86400);
        }
        // If we have errors - return back to the first screen...
        if (!empty($context['search_errors'])) {
            $_REQUEST['params'] = $context['params'];
            return $this->action_search();
        }
        // Get the number of results.
        $numResults = numPMSeachResults($userQuery, $labelQuery, $timeQuery, $searchQuery, $searchq_parameters);
        // Get all the matching message ids, senders and head pm nodes
        list($foundMessages, $posters, $head_pms) = loadPMSearchMessages($userQuery, $labelQuery, $timeQuery, $searchQuery, $searchq_parameters, $search_params);
        // Find the real head pm when in converstaion view
        if ($context['display_mode'] == 2 && !empty($head_pms)) {
            $real_pm_ids = loadPMSearchHeads($head_pms);
        }
        // Load the found user data
        $posters = array_unique($posters);
        if (!empty($posters)) {
            loadMemberData($posters);
        }
        // Sort out the page index.
        $context['page_index'] = constructPageIndex($scripturl . '?action=pm;sa=search2;params=' . $context['params'], $_GET['start'], $numResults, $modSettings['search_results_per_page'], false);
        $context['message_labels'] = array();
        $context['message_replied'] = array();
        $context['personal_messages'] = array();
        $context['first_label'] = array();
        // If we have results, we have work to do!
        if (!empty($foundMessages)) {
            $recipients = array();
            list($context['message_labels'], $context['message_replied'], $context['message_unread'], $context['first_label']) = loadPMRecipientInfo($foundMessages, $recipients, $context['folder'], true);
            // Prepare for the callback!
            $search_results = loadPMSearchResults($foundMessages, $search_params);
            $counter = 0;
            foreach ($search_results as $row) {
                // If there's no subject, use the default.
                $row['subject'] = $row['subject'] == '' ? $txt['no_subject'] : $row['subject'];
                // Load this posters context info, if its not there then fill in the essentials...
                if (!loadMemberContext($row['id_member_from'], true)) {
                    $memberContext[$row['id_member_from']]['name'] = $row['from_name'];
                    $memberContext[$row['id_member_from']]['id'] = 0;
                    $memberContext[$row['id_member_from']]['group'] = $txt['guest_title'];
                    $memberContext[$row['id_member_from']]['link'] = $row['from_name'];
                    $memberContext[$row['id_member_from']]['email'] = '';
                    $memberContext[$row['id_member_from']]['show_email'] = showEmailAddress(true, 0);
                    $memberContext[$row['id_member_from']]['is_guest'] = true;
                }
                // Censor anything we don't want to see...
                censorText($row['body']);
                censorText($row['subject']);
                // Parse out any BBC...
                $row['body'] = parse_bbc($row['body'], true, 'pm' . $row['id_pm']);
                // Highlight the hits
                $body_highlighted = '';
                $subject_highlighted = '';
                foreach ($searchArray as $query) {
                    // Fix the international characters in the keyword too.
                    $query = un_htmlspecialchars($query);
                    $query = trim($query, '\\*+');
                    $query = strtr(Util::htmlspecialchars($query), array('\\\'' => '\''));
                    $body_highlighted = preg_replace_callback('/((<[^>]*)|' . preg_quote(strtr($query, array('\'' => '&#039;')), '/') . ')/iu', array($this, '_highlighted_callback'), $row['body']);
                    $subject_highlighted = preg_replace('/(' . preg_quote($query, '/') . ')/iu', '<strong class="highlight">$1</strong>', $row['subject']);
                }
                // Set a link using the first label information
                $href = $scripturl . '?action=pm;f=' . $context['folder'] . (isset($context['first_label'][$row['id_pm']]) ? ';l=' . $context['first_label'][$row['id_pm']] : '') . ';pmid=' . ($context['display_mode'] == 2 && isset($real_pm_ids[$head_pms[$row['id_pm']]]) && $context['folder'] == 'inbox' ? $real_pm_ids[$head_pms[$row['id_pm']]] : $row['id_pm']) . '#msg_' . $row['id_pm'];
                $context['personal_messages'][] = array('id' => $row['id_pm'], 'member' => &$memberContext[$row['id_member_from']], 'subject' => $subject_highlighted, 'body' => $body_highlighted, 'time' => standardTime($row['msgtime']), 'html_time' => htmlTime($row['msgtime']), 'timestamp' => forum_time(true, $row['msgtime']), 'recipients' => &$recipients[$row['id_pm']], 'labels' => &$context['message_labels'][$row['id_pm']], 'fully_labeled' => count($context['message_labels'][$row['id_pm']]) == count($context['labels']), 'is_replied_to' => &$context['message_replied'][$row['id_pm']], 'href' => $href, 'link' => '<a href="' . $href . '">' . $subject_highlighted . '</a>', 'counter' => ++$counter);
            }
        }
        // Finish off the context.
        $context['page_title'] = $txt['pm_search_title'];
        $context['sub_template'] = 'search_results';
        $context['menu_data_' . $context['pm_menu_id']]['current_area'] = 'search';
        $context['linktree'][] = array('url' => $scripturl . '?action=pm;sa=search', 'name' => $txt['pm_search_bar_title']);
    }
Exemplo n.º 16
0
/**
 * Callback function for action_unapproved_attachments
 *
 * - retrieve all the attachments waiting for approval the approver can approve
 *
 * @package Attachments
 * @param int $start
 * @param int $items_per_page
 * @param string $sort
 * @param string $approve_query additional restrictions based on the boards the approver can see
 * @return mixed[] an array of unapproved attachments
 */
function list_getUnapprovedAttachments($start, $items_per_page, $sort, $approve_query)
{
    global $scripturl;
    $db = database();
    // Get all unapproved attachments.
    $request = $db->query('', '
		SELECT a.id_attach, a.filename, a.size, m.id_msg, m.id_topic, m.id_board, m.subject, m.body, m.id_member,
			IFNULL(mem.real_name, m.poster_name) AS poster_name, m.poster_time,
			t.id_member_started, t.id_first_msg, b.name AS board_name, c.id_cat, c.name AS cat_name
		FROM {db_prefix}attachments AS a
			INNER JOIN {db_prefix}messages AS m ON (m.id_msg = a.id_msg)
			INNER JOIN {db_prefix}topics AS t ON (t.id_topic = m.id_topic)
			INNER JOIN {db_prefix}boards AS b ON (b.id_board = m.id_board)
			LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = m.id_member)
			LEFT JOIN {db_prefix}categories AS c ON (c.id_cat = b.id_cat)
		WHERE a.approved = {int:not_approved}
			AND a.attachment_type = {int:attachment_type}
			AND {query_see_board}
			{raw:approve_query}
		ORDER BY {raw:sort}
		LIMIT {int:start}, {int:items_per_page}', array('not_approved' => 0, 'attachment_type' => 0, 'start' => $start, 'sort' => $sort, 'items_per_page' => $items_per_page, 'approve_query' => $approve_query));
    $unapproved_items = array();
    while ($row = $db->fetch_assoc($request)) {
        $unapproved_items[] = array('id' => $row['id_attach'], 'filename' => $row['filename'], 'size' => round($row['size'] / 1024, 2), 'time' => standardTime($row['poster_time']), 'html_time' => htmlTime($row['poster_time']), 'timestamp' => forum_time(true, $row['poster_time']), 'poster' => array('id' => $row['id_member'], 'name' => $row['poster_name'], 'link' => $row['id_member'] ? '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['poster_name'] . '</a>' : $row['poster_name'], 'href' => $scripturl . '?action=profile;u=' . $row['id_member']), 'message' => array('id' => $row['id_msg'], 'subject' => $row['subject'], 'body' => parse_bbc($row['body']), 'time' => standardTime($row['poster_time']), 'html_time' => htmlTime($row['poster_time']), 'timestamp' => forum_time(true, $row['poster_time']), 'href' => $scripturl . '?topic=' . $row['id_topic'] . '.msg' . $row['id_msg'] . '#msg' . $row['id_msg']), 'topic' => array('id' => $row['id_topic']), 'board' => array('id' => $row['id_board'], 'name' => $row['board_name']), 'category' => array('id' => $row['id_cat'], 'name' => $row['cat_name']));
    }
    $db->free_result($request);
    return $unapproved_items;
}
Exemplo n.º 17
0
/**
 * Gets the badbehavior log entries that match the specified parameters.
 *
 * @package BadBehavior
 * @param int $start
 * @param int $items_per_page
 * @param string $sort
 * @param string|mixed[]|null $filter
 */
function getBadBehaviorLogEntries($start, $items_per_page, $sort, $filter = '')
{
    global $scripturl;
    $db = database();
    require_once EXTDIR . '/bad-behavior/bad-behavior/responses.inc.php';
    $bb_entries = array();
    $request = $db->query('', '
		SELECT id, ip, date, request_method, request_uri, server_protocol, http_headers, user_agent, request_entity, valid, id_member, session
		FROM {db_prefix}log_badbehavior' . (!empty($filter) ? '
		WHERE ' . $filter['variable'] . ' LIKE {string:filter}' : '') . '
		ORDER BY id ' . ($sort === 'down' ? 'DESC' : '') . '
		LIMIT ' . $start . ', ' . $items_per_page, array('filter' => !empty($filter) ? $filter['value']['sql'] : ''));
    for ($i = 0; $row = $db->fetch_assoc($request); $i++) {
        // Turn the key in to something nice to show
        $key_response = bb2_get_response($row['valid']);
        // Prevent undefined errors and log ..
        if (isset($key_response[0]) && $key_response[0] == '00000000') {
            $key_response['response'] = '';
            $key_response['explanation'] = '';
            $key_response['log'] = '';
        }
        $bb_entries[$row['id']] = array('alternate' => $i % 2 == 0, 'ip' => $row['ip'], 'request_method' => $row['request_method'], 'server_protocol' => $row['server_protocol'], 'user_agent' => array('html' => $row['user_agent'], 'href' => base64_encode($db->escape_wildcard_string($row['user_agent']))), 'request_entity' => $row['request_entity'], 'valid' => array('code' => $row['valid'], 'response' => $key_response['response'], 'explanation' => $key_response['explanation'], 'log' => $key_response['log']), 'member' => array('id' => $row['id_member'], 'ip' => $row['ip'], 'session' => $row['session']), 'time' => standardTime($row['date']), 'html_time' => htmlTime($row['date']), 'timestamp' => forum_time(true, $row['date']), 'request_uri' => array('html' => htmlspecialchars((substr($row['request_uri'], 0, 1) === '?' ? $scripturl : '') . $row['request_uri'], ENT_COMPAT, 'UTF-8'), 'href' => base64_encode($db->escape_wildcard_string($row['request_uri']))), 'http_headers' => array('html' => str_replace("\n", '<br />', $row['http_headers']), 'href' => '#'), 'id' => $row['id']);
    }
    $db->free_result($request);
    return $bb_entries;
}
Exemplo n.º 18
0
/**
 * For a supplied list of message id's, loads the posting details for each.
 *  - Intended to get all the most recent posts.
 *  - Tracks the posts made by this user (from the supplied message list) and
 *    loads the id's in to the 'own' or 'any' array.
 *    Reminder The controller needs to check permissions
 *  - Returns two arrays, one of the posts one of any/own
 *
 * @param int[] $messages
 * @param int $start
 */
function getRecentPosts($messages, $start)
{
    global $user_info, $scripturl, $modSettings;
    $db = database();
    // Get all the most recent posts.
    $request = $db->query('', '
		SELECT
			m.id_msg, m.subject, m.smileys_enabled, m.poster_time, m.body, m.id_topic, t.id_board, b.id_cat,
			b.name AS bname, c.name AS cname, t.num_replies, m.id_member, m2.id_member AS id_first_member,
			IFNULL(mem2.real_name, m2.poster_name) AS first_poster_name, t.id_first_msg,
			IFNULL(mem.real_name, m.poster_name) AS poster_name, t.id_last_msg
		FROM {db_prefix}messages AS m
			INNER JOIN {db_prefix}topics AS t ON (t.id_topic = m.id_topic)
			INNER JOIN {db_prefix}boards AS b ON (b.id_board = t.id_board)
			INNER JOIN {db_prefix}categories AS c ON (c.id_cat = b.id_cat)
			INNER JOIN {db_prefix}messages AS m2 ON (m2.id_msg = t.id_first_msg)
			LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = m.id_member)
			LEFT JOIN {db_prefix}members AS mem2 ON (mem2.id_member = m2.id_member)
		WHERE m.id_msg IN ({array_int:message_list})
		ORDER BY m.id_msg DESC
		LIMIT ' . count($messages), array('message_list' => $messages));
    $counter = $start + 1;
    $posts = array();
    $board_ids = array('own' => array(), 'any' => array());
    while ($row = $db->fetch_assoc($request)) {
        // Censor everything.
        censorText($row['body']);
        censorText($row['subject']);
        // BBC-atize the message.
        $row['body'] = parse_bbc($row['body'], $row['smileys_enabled'], $row['id_msg']);
        // And build the array.
        $posts[$row['id_msg']] = array('id' => $row['id_msg'], 'counter' => $counter++, 'alternate' => $counter % 2, 'category' => array('id' => $row['id_cat'], 'name' => $row['cname'], 'href' => $scripturl . '#c' . $row['id_cat'], 'link' => '<a href="' . $scripturl . '#c' . $row['id_cat'] . '">' . $row['cname'] . '</a>'), 'board' => array('id' => $row['id_board'], 'name' => $row['bname'], 'href' => $scripturl . '?board=' . $row['id_board'] . '.0', 'link' => '<a href="' . $scripturl . '?board=' . $row['id_board'] . '.0">' . $row['bname'] . '</a>'), 'topic' => $row['id_topic'], 'href' => $scripturl . '?topic=' . $row['id_topic'] . '.msg' . $row['id_msg'] . '#msg' . $row['id_msg'], 'link' => '<a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.msg' . $row['id_msg'] . '#msg' . $row['id_msg'] . '" rel="nofollow">' . $row['subject'] . '</a>', 'start' => $row['num_replies'], 'subject' => $row['subject'], 'time' => standardTime($row['poster_time']), 'html_time' => htmlTime($row['poster_time']), 'timestamp' => forum_time(true, $row['poster_time']), 'first_poster' => array('id' => $row['id_first_member'], 'name' => $row['first_poster_name'], 'href' => empty($row['id_first_member']) ? '' : $scripturl . '?action=profile;u=' . $row['id_first_member'], 'link' => empty($row['id_first_member']) ? $row['first_poster_name'] : '<a href="' . $scripturl . '?action=profile;u=' . $row['id_first_member'] . '">' . $row['first_poster_name'] . '</a>'), 'poster' => array('id' => $row['id_member'], 'name' => $row['poster_name'], 'href' => empty($row['id_member']) ? '' : $scripturl . '?action=profile;u=' . $row['id_member'], 'link' => empty($row['id_member']) ? $row['poster_name'] : '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['poster_name'] . '</a>'), 'body' => $row['body'], 'message' => $row['body'], 'tests' => array('can_reply' => false, 'can_mark_notify' => false, 'can_delete' => false), 'delete_possible' => ($row['id_first_msg'] != $row['id_msg'] || $row['id_last_msg'] == $row['id_msg']) && (empty($modSettings['edit_disable_time']) || $row['poster_time'] + $modSettings['edit_disable_time'] * 60 >= time()));
        if ($user_info['id'] == $row['id_first_member']) {
            $board_ids['own'][$row['id_board']][] = $row['id_msg'];
        }
        $board_ids['any'][$row['id_board']][] = $row['id_msg'];
    }
    $db->free_result($request);
    return array($posts, $board_ids);
}
Exemplo n.º 19
0
    /**
     * Fetches a list of boards and (optional) categories including
     * statistical information, sub-boards and moderators.
     *  - Used by both the board index (main data) and the message index (child
     * boards).
     *  - Depending on the include_categories setting returns an associative
     * array with categories->boards->child_boards or an associative array
     * with boards->child_boards.
     *
     * @return array
     */
    public function getBoards()
    {
        global $txt;
        // Find all boards and categories, as well as related information.
        $result_boards = $this->_db->query('boardindex_fetch_boards', '
			SELECT' . ($this->_options['include_categories'] ? '
				c.id_cat, c.name AS cat_name,' : '') . '
				b.id_board, b.name AS board_name, b.description,
				CASE WHEN b.redirect != {string:blank_string} THEN 1 ELSE 0 END AS is_redirect,
				b.num_posts, b.num_topics, b.unapproved_posts, b.unapproved_topics, b.id_parent,
				IFNULL(m.poster_time, 0) AS poster_time, IFNULL(mem.member_name, m.poster_name) AS poster_name,
				m.subject, m.id_topic, IFNULL(mem.real_name, m.poster_name) AS real_name,
				' . ($this->_user['is_guest'] ? ' 1 AS is_read, 0 AS new_from,' : '
				(IFNULL(lb.id_msg, 0) >= b.id_msg_updated) AS is_read, IFNULL(lb.id_msg, -1) + 1 AS new_from,' . ($this->_options['include_categories'] ? '
				c.can_collapse, IFNULL(cc.id_member, 0) AS is_collapsed,' : '')) . '
				IFNULL(mem.id_member, 0) AS id_member, mem.avatar, m.id_msg' . ($this->_options['avatars_on_indexes'] ? ',
				IFNULL(a.id_attach, 0) AS id_attach, a.filename, a.attachment_type, mem.email_address' : '') . '
			FROM {db_prefix}boards AS b' . ($this->_options['include_categories'] ? '
				LEFT JOIN {db_prefix}categories AS c ON (c.id_cat = b.id_cat)' : '') . '
				LEFT JOIN {db_prefix}messages AS m ON (m.id_msg = b.id_last_msg)
				LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = m.id_member)' . ($this->_user['is_guest'] ? '' : '
				LEFT JOIN {db_prefix}log_boards AS lb ON (lb.id_board = b.id_board AND lb.id_member = {int:current_member})' . ($this->_options['include_categories'] ? '
				LEFT JOIN {db_prefix}collapsed_categories AS cc ON (cc.id_cat = c.id_cat AND cc.id_member = {int:current_member})' : '')) . ($this->_options['avatars_on_indexes'] ? '
				LEFT JOIN {db_prefix}attachments AS a ON (a.id_member = m.id_member AND a.id_member != 0)' : '') . '
			WHERE {query_see_board}' . (empty($this->_options['countChildPosts']) ? empty($this->_options['base_level']) ? '' : '
				AND b.child_level >= {int:child_level}' : '
				AND b.child_level BETWEEN ' . $this->_options['base_level'] . ' AND ' . ($this->_options['base_level'] + 1)) . '
			ORDER BY' . ($this->_options['include_categories'] ? ' c.cat_order,' : '') . ' b.board_order', array('current_member' => $this->_user['id'], 'child_level' => $this->_options['base_level'], 'blank_string' => ''));
        // Run through the categories and boards (or only boards)....
        while ($row_board = $this->_db->fetch_assoc($result_boards)) {
            // Perhaps we are ignoring this board?
            $ignoreThisBoard = in_array($row_board['id_board'], $this->_user['ignoreboards']);
            $row_board['is_read'] = !empty($row_board['is_read']) || $ignoreThisBoard ? '1' : '0';
            // Not a child.
            $isChild = false;
            if ($this->_options['include_categories']) {
                // Haven't set this category yet.
                if (empty($this->_categories[$row_board['id_cat']])) {
                    $this->_categories[$row_board['id_cat']] = array('id' => $row_board['id_cat'], 'name' => $row_board['cat_name'], 'is_collapsed' => isset($row_board['can_collapse']) && $row_board['can_collapse'] == 1 && $row_board['is_collapsed'] > 0, 'can_collapse' => isset($row_board['can_collapse']) && $row_board['can_collapse'] == 1, 'collapse_href' => isset($row_board['can_collapse']) ? $this->_scripturl . '?action=collapse;c=' . $row_board['id_cat'] . ';sa=' . ($row_board['is_collapsed'] > 0 ? 'expand;' : 'collapse;') . $this->_session_url . '#c' . $row_board['id_cat'] : '', 'collapse_image' => isset($row_board['can_collapse']) ? '<img src="' . $this->_images_url . ($row_board['is_collapsed'] > 0 ? 'expand.png" alt="+"' : 'collapse.png" alt="-"') . ' />' : '', 'href' => $this->_scripturl . '#c' . $row_board['id_cat'], 'boards' => array(), 'new' => false);
                    $this->_categories[$row_board['id_cat']]['link'] = '<a id="c' . $row_board['id_cat'] . '"></a>' . (!$this->_user['is_guest'] ? '<a href="' . $this->_scripturl . '?action=unread;c=' . $row_board['id_cat'] . '" title="' . sprintf($txt['new_posts_in_category'], strip_tags($row_board['cat_name'])) . '">' . $row_board['cat_name'] . '</a>' : $row_board['cat_name']);
                }
                // If this board has new posts in it (and isn't the recycle bin!) then the category is new.
                if ($this->_recycle_board != $row_board['id_board']) {
                    $this->_categories[$row_board['id_cat']]['new'] |= empty($row_board['is_read']) && $row_board['poster_name'] != '';
                }
                // Avoid showing category unread link where it only has redirection boards.
                $this->_categories[$row_board['id_cat']]['show_unread'] = !empty($this->_categories[$row_board['id_cat']]['show_unread']) ? 1 : !$row_board['is_redirect'];
                // Collapsed category - don't do any of this.
                if ($this->_categories[$row_board['id_cat']]['is_collapsed']) {
                    continue;
                }
                // Let's save some typing.  Climbing the array might be slower, anyhow.
                $this->_current_boards =& $this->_categories[$row_board['id_cat']]['boards'];
            }
            // This is a parent board.
            if ($row_board['id_parent'] == $this->_options['parent_id']) {
                // Is this a new board, or just another moderator?
                if (!isset($this->_current_boards[$row_board['id_board']])) {
                    $this->_current_boards[$row_board['id_board']] = array('new' => empty($row_board['is_read']), 'id' => $row_board['id_board'], 'name' => $row_board['board_name'], 'description' => $row_board['description'], 'moderators' => array(), 'link_moderators' => array(), 'children' => array(), 'link_children' => array(), 'children_new' => false, 'topics' => $row_board['num_topics'], 'posts' => $row_board['num_posts'], 'is_redirect' => $row_board['is_redirect'], 'unapproved_topics' => $row_board['unapproved_topics'], 'unapproved_posts' => $row_board['unapproved_posts'] - $row_board['unapproved_topics'], 'can_approve_posts' => $this->_user['mod_cache_ap'] == array(0) || in_array($row_board['id_board'], $this->_user['mod_cache_ap']), 'href' => $this->_scripturl . '?board=' . $row_board['id_board'] . '.0', 'link' => '<a href="' . $this->_scripturl . '?board=' . $row_board['id_board'] . '.0">' . $row_board['board_name'] . '</a>');
                }
                $this->_boards[$row_board['id_board']] = $this->_options['include_categories'] ? $row_board['id_cat'] : 0;
            } elseif (isset($this->_current_boards[$row_board['id_parent']]['children']) && !isset($this->_current_boards[$row_board['id_parent']]['children'][$row_board['id_board']])) {
                // A valid child!
                $isChild = true;
                $this->_current_boards[$row_board['id_parent']]['children'][$row_board['id_board']] = array('id' => $row_board['id_board'], 'name' => $row_board['board_name'], 'description' => $row_board['description'], 'new' => empty($row_board['is_read']) && $row_board['poster_name'] != '', 'topics' => $row_board['num_topics'], 'posts' => $row_board['num_posts'], 'is_redirect' => $row_board['is_redirect'], 'unapproved_topics' => $row_board['unapproved_topics'], 'unapproved_posts' => $row_board['unapproved_posts'] - $row_board['unapproved_topics'], 'can_approve_posts' => $this->_user['mod_cache_ap'] == array(0) || in_array($row_board['id_board'], $this->_user['mod_cache_ap']), 'href' => $this->_scripturl . '?board=' . $row_board['id_board'] . '.0', 'link' => '<a href="' . $this->_scripturl . '?board=' . $row_board['id_board'] . '.0">' . $row_board['board_name'] . '</a>');
                // Counting sub-board posts is... slow :/.
                if (!empty($this->_options['countChildPosts']) && !$row_board['is_redirect']) {
                    $this->_current_boards[$row_board['id_parent']]['posts'] += $row_board['num_posts'];
                    $this->_current_boards[$row_board['id_parent']]['topics'] += $row_board['num_topics'];
                }
                // Does this board contain new boards?
                $this->_current_boards[$row_board['id_parent']]['children_new'] |= empty($row_board['is_read']);
                // This is easier to use in many cases for the theme....
                $this->_current_boards[$row_board['id_parent']]['link_children'][] =& $this->_current_boards[$row_board['id_parent']]['children'][$row_board['id_board']]['link'];
            } elseif (!empty($this->_options['countChildPosts'])) {
                // @todo why this is not initialized outside the loop?
                if (!isset($parent_map)) {
                    $parent_map = array();
                }
                if (!isset($parent_map[$row_board['id_parent']])) {
                    foreach ($this->_current_boards as $id => $board) {
                        if (!isset($board['children'][$row_board['id_parent']])) {
                            continue;
                        }
                        $parent_map[$row_board['id_parent']] = array(&$this->_current_boards[$id], &$this->_current_boards[$id]['children'][$row_board['id_parent']]);
                        $parent_map[$row_board['id_board']] = array(&$this->_current_boards[$id], &$this->_current_boards[$id]['children'][$row_board['id_parent']]);
                        break;
                    }
                }
                if (isset($parent_map[$row_board['id_parent']]) && !$row_board['is_redirect']) {
                    $parent_map[$row_board['id_parent']][0]['posts'] += $row_board['num_posts'];
                    $parent_map[$row_board['id_parent']][0]['topics'] += $row_board['num_topics'];
                    $parent_map[$row_board['id_parent']][1]['posts'] += $row_board['num_posts'];
                    $parent_map[$row_board['id_parent']][1]['topics'] += $row_board['num_topics'];
                    continue;
                }
                continue;
            } else {
                continue;
            }
            // Prepare the subject, and make sure it's not too long.
            censorText($row_board['subject']);
            $row_board['short_subject'] = Util::shorten_text($row_board['subject'], $this->_subject_length);
            $this_last_post = array('id' => $row_board['id_msg'], 'time' => $row_board['poster_time'] > 0 ? standardTime($row_board['poster_time']) : $txt['not_applicable'], 'html_time' => $row_board['poster_time'] > 0 ? htmlTime($row_board['poster_time']) : $txt['not_applicable'], 'timestamp' => forum_time(true, $row_board['poster_time']), 'subject' => $row_board['short_subject'], 'member' => array('id' => $row_board['id_member'], 'username' => $row_board['poster_name'] != '' ? $row_board['poster_name'] : $txt['not_applicable'], 'name' => $row_board['real_name'], 'href' => $row_board['poster_name'] != '' && !empty($row_board['id_member']) ? $this->_scripturl . '?action=profile;u=' . $row_board['id_member'] : '', 'link' => $row_board['poster_name'] != '' ? !empty($row_board['id_member']) ? '<a href="' . $this->_scripturl . '?action=profile;u=' . $row_board['id_member'] . '">' . $row_board['real_name'] . '</a>' : $row_board['real_name'] : $txt['not_applicable']), 'start' => 'msg' . $row_board['new_from'], 'topic' => $row_board['id_topic']);
            if ($this->_options['avatars_on_indexes']) {
                $this_last_post['member']['avatar'] = determineAvatar($row_board);
            }
            // Provide the href and link.
            if ($row_board['subject'] != '') {
                $this_last_post['href'] = $this->_scripturl . '?topic=' . $row_board['id_topic'] . '.msg' . ($this->_user['is_guest'] ? $row_board['id_msg'] : $row_board['new_from']) . (empty($row_board['is_read']) ? ';boardseen' : '') . '#new';
                $this_last_post['link'] = '<a href="' . $this_last_post['href'] . '" title="' . $row_board['subject'] . '">' . $row_board['short_subject'] . '</a>';
                /* The board's and children's 'last_post's have:
                			time, timestamp (a number that represents the time.), id (of the post), topic (topic id.),
                			link, href, subject, start (where they should go for the first unread post.),
                			and member. (which has id, name, link, href, username in it.) */
                $this_last_post['last_post_message'] = sprintf($txt['last_post_message'], $this_last_post['member']['link'], $this_last_post['link'], $this_last_post['html_time']);
            } else {
                $this_last_post['href'] = '';
                $this_last_post['link'] = $txt['not_applicable'];
                $this_last_post['last_post_message'] = '';
            }
            // Set the last post in the parent board.
            if ($row_board['id_parent'] == $this->_options['parent_id'] || $isChild && !empty($row_board['poster_time']) && $this->_current_boards[$row_board['id_parent']]['last_post']['timestamp'] < forum_time(true, $row_board['poster_time'])) {
                $this->_current_boards[$isChild ? $row_board['id_parent'] : $row_board['id_board']]['last_post'] = $this_last_post;
            }
            // Just in the child...?
            if ($isChild) {
                $this->_current_boards[$row_board['id_parent']]['children'][$row_board['id_board']]['last_post'] = $this_last_post;
                // If there are no posts in this board, it really can't be new...
                $this->_current_boards[$row_board['id_parent']]['children'][$row_board['id_board']]['new'] &= $row_board['poster_name'] != '';
            } elseif ($row_board['poster_name'] == '') {
                $this->_current_boards[$row_board['id_board']]['new'] = false;
            }
            // Determine a global most recent topic.
            if ($this->_options['set_latest_post'] && !empty($row_board['poster_time']) && $row_board['poster_time'] > $this->_latest_post['timestamp'] && !$ignoreThisBoard) {
                $this->_latest_post =& $this->_current_boards[$isChild ? $row_board['id_parent'] : $row_board['id_board']]['last_post'];
            }
        }
        $this->_db->free_result($result_boards);
        if ($this->_options['get_moderators'] && !empty($this->_boards)) {
            $this->_getBoardModerators();
        }
        return $this->_options['include_categories'] ? $this->_categories : $this->_current_boards;
    }
Exemplo n.º 20
0
    /**
     * Set merge options and do the actual merge of two or more topics.
     *
     * the merge options screen:
     * * shows topics to be merged and allows to set some merge options.
     * * is accessed by ?action=mergetopics;sa=options.and can also internally be called by action_quickmod().
     * * uses 'merge_extra_options' sub template of the MergeTopics template.
     *
     * the actual merge:
     * * is accessed with ?action=mergetopics;sa=execute.
     * * updates the statistics to reflect the merge.
     * * logs the action in the moderation log.
     * * sends a notification is sent to all users monitoring this topic.
     * * redirects to ?action=mergetopics;sa=done.
     *
     * @param int[] $topics = array() of topic ids
     */
    public function action_mergeExecute($topics = array())
    {
        global $user_info, $txt, $context, $scripturl, $modSettings;
        $db = database();
        // Check the session.
        checkSession('request');
        require_once SUBSDIR . '/Topic.subs.php';
        require_once SUBSDIR . '/Post.subs.php';
        // Handle URLs from action_mergeIndex.
        if (!empty($_GET['from']) && !empty($_GET['to'])) {
            $topics = array((int) $_GET['from'], (int) $_GET['to']);
        }
        // If we came from a form, the topic IDs came by post.
        if (!empty($_POST['topics']) && is_array($_POST['topics'])) {
            $topics = $_POST['topics'];
        }
        // There's nothing to merge with just one topic...
        if (empty($topics) || !is_array($topics) || count($topics) == 1) {
            fatal_lang_error('merge_need_more_topics');
        }
        // Make sure every topic is numeric, or some nasty things could be done with the DB.
        foreach ($topics as $id => $topic) {
            $topics[$id] = (int) $topic;
        }
        // Joy of all joys, make sure they're not pi**ing about with unapproved topics they can't see :P
        if ($modSettings['postmod_active']) {
            $can_approve_boards = !empty($user_info['mod_cache']['ap']) ? $user_info['mod_cache']['ap'] : boardsAllowedTo('approve_posts');
        }
        // Get info about the topics and polls that will be merged.
        $request = $db->query('', '
			SELECT
				t.id_topic, t.id_board, t.id_poll, t.num_views, t.is_sticky, t.approved, t.num_replies, t.unapproved_posts,
				m1.subject, m1.poster_time AS time_started, IFNULL(mem1.id_member, 0) AS id_member_started, IFNULL(mem1.real_name, m1.poster_name) AS name_started,
				m2.poster_time AS time_updated, IFNULL(mem2.id_member, 0) AS id_member_updated, IFNULL(mem2.real_name, m2.poster_name) AS name_updated
			FROM {db_prefix}topics AS t
				INNER JOIN {db_prefix}messages AS m1 ON (m1.id_msg = t.id_first_msg)
				INNER JOIN {db_prefix}messages AS m2 ON (m2.id_msg = t.id_last_msg)
				LEFT JOIN {db_prefix}members AS mem1 ON (mem1.id_member = m1.id_member)
				LEFT JOIN {db_prefix}members AS mem2 ON (mem2.id_member = m2.id_member)
			WHERE t.id_topic IN ({array_int:topic_list})
			ORDER BY t.id_first_msg
			LIMIT ' . count($topics), array('topic_list' => $topics));
        if ($db->num_rows($request) < 2) {
            fatal_lang_error('no_topic_id');
        }
        $num_views = 0;
        $is_sticky = 0;
        $boardTotals = array();
        $topic_data = array();
        $boards = array();
        $polls = array();
        $firstTopic = 0;
        while ($row = $db->fetch_assoc($request)) {
            // Make a note for the board counts...
            if (!isset($boardTotals[$row['id_board']])) {
                $boardTotals[$row['id_board']] = array('num_posts' => 0, 'num_topics' => 0, 'unapproved_posts' => 0, 'unapproved_topics' => 0);
            }
            // We can't see unapproved topics here?
            if ($modSettings['postmod_active'] && !$row['approved'] && $can_approve_boards != array(0) && in_array($row['id_board'], $can_approve_boards)) {
                continue;
            } elseif (!$row['approved']) {
                $boardTotals[$row['id_board']]['unapproved_topics']++;
            } else {
                $boardTotals[$row['id_board']]['num_topics']++;
            }
            $boardTotals[$row['id_board']]['unapproved_posts'] += $row['unapproved_posts'];
            $boardTotals[$row['id_board']]['num_posts'] += $row['num_replies'] + ($row['approved'] ? 1 : 0);
            $topic_data[$row['id_topic']] = array('id' => $row['id_topic'], 'board' => $row['id_board'], 'poll' => $row['id_poll'], 'num_views' => $row['num_views'], 'subject' => $row['subject'], 'started' => array('time' => standardTime($row['time_started']), 'html_time' => htmlTime($row['time_started']), 'timestamp' => forum_time(true, $row['time_started']), 'href' => empty($row['id_member_started']) ? '' : $scripturl . '?action=profile;u=' . $row['id_member_started'], 'link' => empty($row['id_member_started']) ? $row['name_started'] : '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member_started'] . '">' . $row['name_started'] . '</a>'), 'updated' => array('time' => standardTime($row['time_updated']), 'html_time' => htmlTime($row['time_updated']), 'timestamp' => forum_time(true, $row['time_updated']), 'href' => empty($row['id_member_updated']) ? '' : $scripturl . '?action=profile;u=' . $row['id_member_updated'], 'link' => empty($row['id_member_updated']) ? $row['name_updated'] : '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member_updated'] . '">' . $row['name_updated'] . '</a>'));
            $num_views += $row['num_views'];
            $boards[] = $row['id_board'];
            // If there's no poll, id_poll == 0...
            if ($row['id_poll'] > 0) {
                $polls[] = $row['id_poll'];
            }
            // Store the id_topic with the lowest id_first_msg.
            if (empty($firstTopic)) {
                $firstTopic = $row['id_topic'];
            }
            $is_sticky = max($is_sticky, $row['is_sticky']);
        }
        $db->free_result($request);
        // If we didn't get any topics then they've been messing with unapproved stuff.
        if (empty($topic_data)) {
            fatal_lang_error('no_topic_id');
        }
        $boards = array_values(array_unique($boards));
        // The parameters of action_mergeExecute were set, so this must've been an internal call.
        if (!empty($topics)) {
            isAllowedTo('merge_any', $boards);
            loadTemplate('MergeTopics');
        }
        // Get the boards a user is allowed to merge in.
        $merge_boards = boardsAllowedTo('merge_any');
        if (empty($merge_boards)) {
            fatal_lang_error('cannot_merge_any', 'user');
        }
        require_once SUBSDIR . '/Boards.subs.php';
        // Make sure they can see all boards....
        $query_boards = array('boards' => $boards);
        if (!in_array(0, $merge_boards)) {
            $query_boards['boards'] = array_merge($query_boards['boards'], $merge_boards);
        }
        // Saved in a variable to (potentially) save a query later
        $boards_info = fetchBoardsInfo($query_boards);
        // This happens when a member is moderator of a board he cannot see
        foreach ($boards as $board) {
            if (!isset($boards_info[$board])) {
                fatal_lang_error('no_board');
            }
        }
        if (empty($_REQUEST['sa']) || $_REQUEST['sa'] == 'options') {
            if (count($polls) > 1) {
                $request = $db->query('', '
					SELECT t.id_topic, t.id_poll, m.subject, p.question
					FROM {db_prefix}polls AS p
						INNER JOIN {db_prefix}topics AS t ON (t.id_poll = p.id_poll)
						INNER JOIN {db_prefix}messages AS m ON (m.id_msg = t.id_first_msg)
					WHERE p.id_poll IN ({array_int:polls})
					LIMIT ' . count($polls), array('polls' => $polls));
                while ($row = $db->fetch_assoc($request)) {
                    $context['polls'][] = array('id' => $row['id_poll'], 'topic' => array('id' => $row['id_topic'], 'subject' => $row['subject']), 'question' => $row['question'], 'selected' => $row['id_topic'] == $firstTopic);
                }
                $db->free_result($request);
            }
            if (count($boards) > 1) {
                foreach ($boards_info as $row) {
                    $context['boards'][] = array('id' => $row['id_board'], 'name' => $row['name'], 'selected' => $row['id_board'] == $topic_data[$firstTopic]['board']);
                }
            }
            $context['topics'] = $topic_data;
            foreach ($topic_data as $id => $topic) {
                $context['topics'][$id]['selected'] = $topic['id'] == $firstTopic;
            }
            $context['page_title'] = $txt['merge'];
            $context['sub_template'] = 'merge_extra_options';
            return;
        }
        // Determine target board.
        $target_board = count($boards) > 1 ? (int) $_REQUEST['board'] : $boards[0];
        if (!in_array($target_board, $boards)) {
            fatal_lang_error('no_board');
        }
        // Determine which poll will survive and which polls won't.
        $target_poll = count($polls) > 1 ? (int) $_POST['poll'] : (count($polls) == 1 ? $polls[0] : 0);
        if ($target_poll > 0 && !in_array($target_poll, $polls)) {
            fatal_lang_error('no_access', false);
        }
        $deleted_polls = empty($target_poll) ? $polls : array_diff($polls, array($target_poll));
        // Determine the subject of the newly merged topic - was a custom subject specified?
        if (empty($_POST['subject']) && isset($_POST['custom_subject']) && $_POST['custom_subject'] != '') {
            $target_subject = strtr(Util::htmltrim(Util::htmlspecialchars($_POST['custom_subject'])), array("\r" => '', "\n" => '', "\t" => ''));
            // Keep checking the length.
            if (Util::strlen($target_subject) > 100) {
                $target_subject = Util::substr($target_subject, 0, 100);
            }
            // Nothing left - odd but pick the first topics subject.
            if ($target_subject == '') {
                $target_subject = $topic_data[$firstTopic]['subject'];
            }
        } elseif (!empty($topic_data[(int) $_POST['subject']]['subject'])) {
            $target_subject = $topic_data[(int) $_POST['subject']]['subject'];
        } else {
            $target_subject = $topic_data[$firstTopic]['subject'];
        }
        // Get the first and last message and the number of messages....
        $request = $db->query('', '
			SELECT approved, MIN(id_msg) AS first_msg, MAX(id_msg) AS last_msg, COUNT(*) AS message_count
			FROM {db_prefix}messages
			WHERE id_topic IN ({array_int:topics})
			GROUP BY approved
			ORDER BY approved DESC', array('topics' => $topics));
        $topic_approved = 1;
        $first_msg = 0;
        while ($row = $db->fetch_assoc($request)) {
            // If this is approved, or is fully unapproved.
            if ($row['approved'] || !isset($first_msg)) {
                $first_msg = $row['first_msg'];
                $last_msg = $row['last_msg'];
                if ($row['approved']) {
                    $num_replies = $row['message_count'] - 1;
                    $num_unapproved = 0;
                } else {
                    $topic_approved = 0;
                    $num_replies = 0;
                    $num_unapproved = $row['message_count'];
                }
            } else {
                // If this has a lower first_msg then the first post is not approved and hence the number of replies was wrong!
                if ($first_msg > $row['first_msg']) {
                    $first_msg = $row['first_msg'];
                    $num_replies++;
                    $topic_approved = 0;
                }
                $num_unapproved = $row['message_count'];
            }
        }
        $db->free_result($request);
        // Ensure we have a board stat for the target board.
        if (!isset($boardTotals[$target_board])) {
            $boardTotals[$target_board] = array('num_posts' => 0, 'num_topics' => 0, 'unapproved_posts' => 0, 'unapproved_topics' => 0);
        }
        // Fix the topic count stuff depending on what the new one counts as.
        if ($topic_approved) {
            $boardTotals[$target_board]['num_topics']--;
        } else {
            $boardTotals[$target_board]['unapproved_topics']--;
        }
        $boardTotals[$target_board]['unapproved_posts'] -= $num_unapproved;
        $boardTotals[$target_board]['num_posts'] -= $topic_approved ? $num_replies + 1 : $num_replies;
        // Get the member ID of the first and last message.
        $request = $db->query('', '
			SELECT id_member
			FROM {db_prefix}messages
			WHERE id_msg IN ({int:first_msg}, {int:last_msg})
			ORDER BY id_msg
			LIMIT 2', array('first_msg' => $first_msg, 'last_msg' => $last_msg));
        list($member_started) = $db->fetch_row($request);
        list($member_updated) = $db->fetch_row($request);
        // First and last message are the same, so only row was returned.
        if ($member_updated === null) {
            $member_updated = $member_started;
        }
        $db->free_result($request);
        // Obtain all the message ids we are going to affect.
        $affected_msgs = messagesInTopics($topics);
        // Assign the first topic ID to be the merged topic.
        $id_topic = min($topics);
        // Grab the response prefix (like 'Re: ') in the default forum language.
        $context['response_prefix'] = response_prefix();
        $enforce_subject = isset($_POST['enforce_subject']) ? Util::htmlspecialchars(trim($_POST['enforce_subject'])) : '';
        // Merge topic notifications.
        $notifications = isset($_POST['notifications']) && is_array($_POST['notifications']) ? array_intersect($topics, $_POST['notifications']) : array();
        fixMergedTopics($first_msg, $topics, $id_topic, $target_board, $target_subject, $enforce_subject, $notifications);
        // Asssign the properties of the newly merged topic.
        $db->query('', '
			UPDATE {db_prefix}topics
			SET
				id_board = {int:id_board},
				id_member_started = {int:id_member_started},
				id_member_updated = {int:id_member_updated},
				id_first_msg = {int:id_first_msg},
				id_last_msg = {int:id_last_msg},
				id_poll = {int:id_poll},
				num_replies = {int:num_replies},
				unapproved_posts = {int:unapproved_posts},
				num_views = {int:num_views},
				is_sticky = {int:is_sticky},
				approved = {int:approved}
			WHERE id_topic = {int:id_topic}', array('id_board' => $target_board, 'is_sticky' => $is_sticky, 'approved' => $topic_approved, 'id_topic' => $id_topic, 'id_member_started' => $member_started, 'id_member_updated' => $member_updated, 'id_first_msg' => $first_msg, 'id_last_msg' => $last_msg, 'id_poll' => $target_poll, 'num_replies' => $num_replies, 'unapproved_posts' => $num_unapproved, 'num_views' => $num_views));
        // Get rid of the redundant polls.
        if (!empty($deleted_polls)) {
            require_once SUBSDIR . '/Poll.subs.php';
            removePoll($deleted_polls);
        }
        // Cycle through each board...
        foreach ($boardTotals as $id_board => $stats) {
            decrementBoard($id_board, $stats);
        }
        // Determine the board the final topic resides in
        $topic_info = getTopicInfo($id_topic);
        $id_board = $topic_info['id_board'];
        // Update all the statistics.
        updateStats('topic');
        updateStats('subject', $id_topic, $target_subject);
        updateLastMessages($boards);
        logAction('merge', array('topic' => $id_topic, 'board' => $id_board));
        // Notify people that these topics have been merged?
        require_once SUBSDIR . '/Notification.subs.php';
        sendNotifications($id_topic, 'merge');
        // If there's a search index that needs updating, update it...
        require_once SUBSDIR . '/Search.subs.php';
        $searchAPI = findSearchAPI();
        if (is_callable(array($searchAPI, 'topicMerge'))) {
            $searchAPI->topicMerge($id_topic, $topics, $affected_msgs, empty($enforce_subject) ? null : array($context['response_prefix'], $target_subject));
        }
        // Send them to the all done page.
        redirectexit('action=mergetopics;sa=done;to=' . $id_topic . ';targetboard=' . $target_board);
    }
Exemplo n.º 21
0
/**
 * Get the data about a users warnings.
 * Returns an array of them
 *
 * @param int $start
 * @param int $items_per_page
 * @param string $sort
 * @param int $memID the member ID
 */
function list_getUserWarnings($start, $items_per_page, $sort, $memID)
{
    global $scripturl;
    $db = database();
    $request = $db->query('', '
		SELECT IFNULL(mem.id_member, 0) AS id_member, IFNULL(mem.real_name, lc.member_name) AS member_name,
			lc.log_time, lc.body, lc.counter, lc.id_notice
		FROM {db_prefix}log_comments AS lc
			LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = lc.id_member)
		WHERE lc.id_recipient = {int:selected_member}
			AND lc.comment_type = {string:warning}
		ORDER BY ' . $sort . '
		LIMIT ' . $start . ', ' . $items_per_page, array('selected_member' => $memID, 'warning' => 'warning'));
    $previous_warnings = array();
    while ($row = $db->fetch_assoc($request)) {
        $previous_warnings[] = array('issuer' => array('id' => $row['id_member'], 'link' => $row['id_member'] ? '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['member_name'] . '</a>' : $row['member_name']), 'time' => standardTime($row['log_time']), 'html_time' => htmlTime($row['log_time']), 'timestamp' => forum_time(true, $row['log_time']), 'reason' => $row['body'], 'counter' => $row['counter'] > 0 ? '+' . $row['counter'] : $row['counter'], 'id_notice' => $row['id_notice']);
    }
    $db->free_result($request);
    return $previous_warnings;
}
Exemplo n.º 22
0
 /**
  * Show all posts by the current user.
  *
  * @todo This function needs to be split up properly.
  */
 public function action_showPosts()
 {
     global $txt, $user_info, $scripturl, $modSettings, $context, $user_profile, $board;
     $memID = currentMemberID();
     // Some initial context.
     $context['start'] = (int) $_REQUEST['start'];
     $context['current_member'] = $memID;
     loadTemplate('ProfileInfo');
     // Create the tabs for the template.
     $context[$context['profile_menu_name']]['tab_data'] = array('title' => $txt['showPosts'], 'description' => $txt['showPosts_help'], 'class' => 'profile', 'tabs' => array('messages' => array(), 'topics' => array(), 'unwatchedtopics' => array(), 'attach' => array()));
     // Set the page title
     $context['page_title'] = $txt['showPosts'] . ' - ' . $user_profile[$memID]['real_name'];
     // Is the load average too high to allow searching just now?
     if (!empty($modSettings['loadavg_show_posts']) && $modSettings['current_load'] >= $modSettings['loadavg_show_posts']) {
         fatal_lang_error('loadavg_show_posts_disabled', false);
     }
     // If we're specifically dealing with attachments use that function!
     if (isset($_GET['sa']) && $_GET['sa'] == 'attach') {
         return $this->action_showAttachments();
     } elseif (isset($_GET['sa']) && $_GET['sa'] == 'unwatchedtopics' && $modSettings['enable_unwatch']) {
         return $this->action_showUnwatched();
     }
     // Are we just viewing topics?
     $context['is_topics'] = isset($_GET['sa']) && $_GET['sa'] == 'topics' ? true : false;
     // If just deleting a message, do it and then redirect back.
     if (isset($_GET['delete']) && !$context['is_topics']) {
         checkSession('get');
         // We need msg info for logging.
         require_once SUBSDIR . '/Messages.subs.php';
         $info = basicMessageInfo((int) $_GET['delete'], true);
         // Trying to remove a message that doesn't exist.
         if (empty($info)) {
             redirectexit('action=profile;u=' . $memID . ';area=showposts;start=' . $_GET['start']);
         }
         // We can be lazy, since removeMessage() will check the permissions for us.
         removeMessage((int) $_GET['delete']);
         // Add it to the mod log.
         if (allowedTo('delete_any') && (!allowedTo('delete_own') || $info['id_member'] != $user_info['id'])) {
             logAction('delete', array('topic' => $info['id_topic'], 'subject' => $info['subject'], 'member' => $info['id_member'], 'board' => $info['id_board']));
         }
         // Back to... where we are now ;).
         redirectexit('action=profile;u=' . $memID . ';area=showposts;start=' . $_GET['start']);
     }
     // Default to 10.
     if (empty($_REQUEST['viewscount']) || !is_numeric($_REQUEST['viewscount'])) {
         $_REQUEST['viewscount'] = '10';
     }
     if ($context['is_topics']) {
         $msgCount = count_user_topics($memID, $board);
     } else {
         $msgCount = count_user_posts($memID, $board);
     }
     list($min_msg_member, $max_msg_member) = findMinMaxUserMessage($memID, $board);
     $range_limit = '';
     $maxIndex = (int) $modSettings['defaultMaxMessages'];
     // Make sure the starting place makes sense and construct our friend the page index.
     $context['page_index'] = constructPageIndex($scripturl . '?action=profile;u=' . $memID . ';area=showposts' . ($context['is_topics'] ? ';sa=topics' : ';sa=messages') . (!empty($board) ? ';board=' . $board : ''), $context['start'], $msgCount, $maxIndex);
     $context['current_page'] = $context['start'] / $maxIndex;
     // Reverse the query if we're past 50% of the pages for better performance.
     $start = $context['start'];
     $reverse = $_REQUEST['start'] > $msgCount / 2;
     if ($reverse) {
         $maxIndex = $msgCount < $context['start'] + $modSettings['defaultMaxMessages'] + 1 && $msgCount > $context['start'] ? $msgCount - $context['start'] : (int) $modSettings['defaultMaxMessages'];
         $start = $msgCount < $context['start'] + $modSettings['defaultMaxMessages'] + 1 || $msgCount < $context['start'] + $modSettings['defaultMaxMessages'] ? 0 : $msgCount - $context['start'] - $modSettings['defaultMaxMessages'];
     }
     // Guess the range of messages to be shown to help minimize what the query needs to do
     if ($msgCount > 1000) {
         $margin = floor(($max_msg_member - $min_msg_member) * (($start + $modSettings['defaultMaxMessages']) / $msgCount) + 0.1 * ($max_msg_member - $min_msg_member));
         // Make a bigger margin for topics only.
         if ($context['is_topics']) {
             $margin *= 5;
             $range_limit = $reverse ? 't.id_first_msg < ' . ($min_msg_member + $margin) : 't.id_first_msg > ' . ($max_msg_member - $margin);
         } else {
             $range_limit = $reverse ? 'm.id_msg < ' . ($min_msg_member + $margin) : 'm.id_msg > ' . ($max_msg_member - $margin);
         }
     }
     // Find this user's posts or topics started
     if ($context['is_topics']) {
         $rows = load_user_topics($memID, $start, $maxIndex, $range_limit, $reverse, $board);
     } else {
         $rows = load_user_posts($memID, $start, $maxIndex, $range_limit, $reverse, $board);
     }
     // Start counting at the number of the first message displayed.
     $counter = $reverse ? $context['start'] + $maxIndex + 1 : $context['start'];
     $context['posts'] = array();
     $board_ids = array('own' => array(), 'any' => array());
     foreach ($rows as $row) {
         // Censor....
         censorText($row['body']);
         censorText($row['subject']);
         // Do the code.
         $row['body'] = parse_bbc($row['body'], $row['smileys_enabled'], $row['id_msg']);
         // And the array...
         $context['posts'][$counter += $reverse ? -1 : 1] = array('body' => $row['body'], 'counter' => $counter, 'alternate' => $counter % 2, 'category' => array('name' => $row['cname'], 'id' => $row['id_cat']), 'board' => array('name' => $row['bname'], 'id' => $row['id_board'], 'link' => '<a href="' . $scripturl . '?board=' . $row['id_board'] . '.0">' . $row['bname'] . '</a>'), 'topic' => array('id' => $row['id_topic'], 'link' => '<a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.msg' . $row['id_msg'] . '#msg' . $row['id_msg'] . '">' . $row['subject'] . '</a>'), 'subject' => $row['subject'], 'start' => 'msg' . $row['id_msg'], 'time' => standardTime($row['poster_time']), 'html_time' => htmlTime($row['poster_time']), 'timestamp' => forum_time(true, $row['poster_time']), 'id' => $row['id_msg'], 'tests' => array('can_reply' => false, 'can_mark_notify' => false, 'can_delete' => false), 'delete_possible' => ($row['id_first_msg'] != $row['id_msg'] || $row['id_last_msg'] == $row['id_msg']) && (empty($modSettings['edit_disable_time']) || $row['poster_time'] + $modSettings['edit_disable_time'] * 60 >= time()), 'approved' => $row['approved'], 'buttons' => array('remove' => array('href' => $scripturl . '?action=deletemsg;msg=' . $row['id_msg'] . ';topic=' . $row['id_topic'] . ';profile;u=' . $context['member']['id'] . ';start=' . $context['start'], 'text' => $txt['remove'], 'test' => 'can_delete', 'custom' => 'onclick="return confirm(' . JavaScriptEscape($txt['remove_message'] . '?') . ');"'), 'notify' => array('href' => $scripturl . '?action=notify;topic=' . $row['id_topic'] . '.msg' . $row['id_msg'], 'text' => $txt['notify'], 'test' => 'can_mark_notify'), 'reply' => array('href' => $scripturl . '?action=post;topic=' . $row['id_topic'] . '.msg' . $row['id_msg'], 'text' => $txt['reply'], 'test' => 'can_reply'), 'quote' => array('href' => $scripturl . '?action=post;topic=' . $row['id_topic'] . '.msg' . $row['id_msg'] . ';quote=' . $row['id_msg'], 'text' => $txt['quote'], 'test' => 'can_quote')));
         if ($user_info['id'] == $row['id_member_started']) {
             $board_ids['own'][$row['id_board']][] = $counter;
         }
         $board_ids['any'][$row['id_board']][] = $counter;
     }
     // All posts were retrieved in reverse order, get them right again.
     if ($reverse) {
         $context['posts'] = array_reverse($context['posts'], true);
     }
     // These are all the permissions that are different from board to board..
     if ($context['is_topics']) {
         $permissions = array('own' => array('post_reply_own' => 'can_reply'), 'any' => array('post_reply_any' => 'can_reply', 'mark_any_notify' => 'can_mark_notify'));
     } else {
         $permissions = array('own' => array('post_reply_own' => 'can_reply', 'delete_own' => 'can_delete'), 'any' => array('post_reply_any' => 'can_reply', 'mark_any_notify' => 'can_mark_notify', 'delete_any' => 'can_delete'));
     }
     // For every permission in the own/any lists...
     foreach ($permissions as $type => $list) {
         foreach ($list as $permission => $allowed) {
             // Get the boards they can do this on...
             $boards = boardsAllowedTo($permission);
             // Hmm, they can do it on all boards, can they?
             if (!empty($boards) && $boards[0] == 0) {
                 $boards = array_keys($board_ids[$type]);
             }
             // Now go through each board they can do the permission on.
             foreach ($boards as $board_id) {
                 // There aren't any posts displayed from this board.
                 if (!isset($board_ids[$type][$board_id])) {
                     continue;
                 }
                 // Set the permission to true ;).
                 foreach ($board_ids[$type][$board_id] as $counter) {
                     $context['posts'][$counter]['tests'][$allowed] = true;
                 }
             }
         }
     }
     // Clean up after posts that cannot be deleted and quoted.
     $quote_enabled = empty($modSettings['disabledBBC']) || !in_array('quote', explode(',', $modSettings['disabledBBC']));
     foreach ($context['posts'] as $counter => $dummy) {
         $context['posts'][$counter]['tests']['can_delete'] &= $context['posts'][$counter]['delete_possible'];
         $context['posts'][$counter]['tests']['can_quote'] = $context['posts'][$counter]['tests']['can_reply'] && $quote_enabled;
     }
 }
Exemplo n.º 23
0
/**
 * Loads all the messages of a topic
 * Used when printing or other functions that require a topic listing
 *
 * @param int $topic
 * @param string $render defaults to print style rendering for parse_bbc
 */
function topicMessages($topic, $render = 'print')
{
    global $modSettings, $user_info;
    $db = database();
    $request = $db->query('', '
		SELECT subject, poster_time, body, IFNULL(mem.real_name, poster_name) AS poster_name, id_msg
		FROM {db_prefix}messages AS m
			LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = m.id_member)
		WHERE m.id_topic = {int:current_topic}' . ($modSettings['postmod_active'] && !allowedTo('approve_posts') ? '
			AND (m.approved = {int:is_approved}' . ($user_info['is_guest'] ? '' : ' OR m.id_member = {int:current_member}') . ')' : '') . '
		ORDER BY m.id_msg', array('current_topic' => $topic, 'is_approved' => 1, 'current_member' => $user_info['id']));
    $posts = array();
    while ($row = $db->fetch_assoc($request)) {
        // Censor the subject and message.
        censorText($row['subject']);
        censorText($row['body']);
        $posts[$row['id_msg']] = array('subject' => $row['subject'], 'member' => $row['poster_name'], 'time' => standardTime($row['poster_time'], false), 'html_time' => htmlTime($row['poster_time']), 'timestamp' => forum_time(true, $row['poster_time']), 'body' => parse_bbc($row['body'], $render), 'id_msg' => $row['id_msg']);
    }
    $db->free_result($request);
    return $posts;
}
Exemplo n.º 24
0
 /**
  * Make the list.
  * The list will be populated in $context.
  */
 public function buildList()
 {
     global $context;
     // All the context data will be easily accessible by using a reference.
     $context[$this->_listOptions['id']] = array();
     $list_context =& $context[$this->_listOptions['id']];
     // Let's set some default that could be useful to avoid repetitions
     if (!isset($context['sub_template'])) {
         if (function_exists('template_' . $this->_listOptions['id'])) {
             $context['sub_template'] = $this->_listOptions['id'];
         } else {
             $context['sub_template'] = 'show_list';
             if (!isset($context['default_list'])) {
                 $context['default_list'] = $this->_listOptions['id'];
             }
         }
     }
     // Figure out the sort.
     if (empty($this->_listOptions['default_sort_col'])) {
         $list_context['sort'] = array();
         $sort = '1=1';
     } else {
         $request_var_sort = isset($this->_listOptions['request_vars']['sort']) ? $this->_listOptions['request_vars']['sort'] : 'sort';
         $request_var_desc = isset($this->_listOptions['request_vars']['desc']) ? $this->_listOptions['request_vars']['desc'] : 'desc';
         if (isset($_REQUEST[$request_var_sort], $this->_listOptions['columns'][$_REQUEST[$request_var_sort]], $this->_listOptions['columns'][$_REQUEST[$request_var_sort]]['sort'])) {
             $list_context['sort'] = array('id' => $_REQUEST[$request_var_sort], 'desc' => isset($_REQUEST[$request_var_desc]) && isset($this->_listOptions['columns'][$_REQUEST[$request_var_sort]]['sort']['reverse']));
         } else {
             $list_context['sort'] = array('id' => $this->_listOptions['default_sort_col'], 'desc' => !empty($this->_listOptions['default_sort_dir']) && $this->_listOptions['default_sort_dir'] == 'desc' || !empty($this->_listOptions['columns'][$this->_listOptions['default_sort_col']]['sort']['default']) && substr($this->_listOptions['columns'][$this->_listOptions['default_sort_col']]['sort']['default'], -4, 4) == 'desc' ? true : false);
         }
         // Set the database column sort.
         $sort = $this->_listOptions['columns'][$list_context['sort']['id']]['sort'][$list_context['sort']['desc'] ? 'reverse' : 'default'];
     }
     $list_context['start_var_name'] = isset($this->_listOptions['start_var_name']) ? $this->_listOptions['start_var_name'] : 'start';
     // In some cases the full list must be shown, regardless of the amount of items.
     if (empty($this->_listOptions['items_per_page'])) {
         $list_context['start'] = 0;
         $list_context['items_per_page'] = 0;
     } else {
         // First get an impression of how many items to expect.
         if (isset($this->_listOptions['get_count']['file'])) {
             require_once $this->_listOptions['get_count']['file'];
         }
         $list_context['total_num_items'] = call_user_func_array($this->_listOptions['get_count']['function'], empty($this->_listOptions['get_count']['params']) ? array() : $this->_listOptions['get_count']['params']);
         // Default the start to the beginning...sounds logical.
         $list_context['start'] = isset($_REQUEST[$list_context['start_var_name']]) ? (int) $_REQUEST[$list_context['start_var_name']] : 0;
         $list_context['items_per_page'] = $this->_listOptions['items_per_page'];
         // Then create a page index.
         if ($list_context['total_num_items'] > $list_context['items_per_page']) {
             $list_context['page_index'] = constructPageIndex($this->_listOptions['base_href'] . (empty($list_context['sort']) ? '' : ';' . $request_var_sort . '=' . $list_context['sort']['id'] . ($list_context['sort']['desc'] ? ';' . $request_var_desc : '')) . ($list_context['start_var_name'] != 'start' ? ';' . $list_context['start_var_name'] . '=%1$d' : ''), $list_context['start'], $list_context['total_num_items'], $list_context['items_per_page'], $list_context['start_var_name'] != 'start');
         }
     }
     // Prepare the headers of the table.
     $list_context['headers'] = array();
     foreach ($this->_listOptions['columns'] as $column_id => $column) {
         if (!isset($column['evaluate']) || $column['evaluate'] === true) {
             $list_context['headers'][] = array('id' => $column_id, 'label' => isset($column['header']['eval']) ? eval($column['header']['eval']) : (isset($column['header']['value']) ? $column['header']['value'] : ''), 'href' => empty($this->_listOptions['default_sort_col']) || empty($column['sort']) ? '' : $this->_listOptions['base_href'] . ';' . $request_var_sort . '=' . $column_id . ($column_id === $list_context['sort']['id'] && !$list_context['sort']['desc'] && isset($column['sort']['reverse']) ? ';' . $request_var_desc : '') . (empty($list_context['start']) ? '' : ';' . $list_context['start_var_name'] . '=' . $list_context['start']), 'sort_image' => empty($this->_listOptions['default_sort_col']) || empty($column['sort']) || $column_id !== $list_context['sort']['id'] ? null : ($list_context['sort']['desc'] ? 'down' : 'up'), 'class' => isset($column['header']['class']) ? $column['header']['class'] : '', 'style' => isset($column['header']['style']) ? $column['header']['style'] : '', 'colspan' => isset($column['header']['colspan']) ? $column['header']['colspan'] : '');
         }
     }
     // We know the amount of columns, might be useful for the template.
     $list_context['num_columns'] = count($this->_listOptions['columns']);
     $list_context['width'] = isset($this->_listOptions['width']) ? $this->_listOptions['width'] : '0';
     // Maybe we want this one to interact with jquery UI sortable
     $list_context['sortable'] = isset($this->_listOptions['sortable']) ? true : false;
     // Get the file with the function for the item list.
     if (isset($this->_listOptions['get_items']['file'])) {
         require_once $this->_listOptions['get_items']['file'];
     }
     // Call the function and include which items we want and in what order.
     $list_items = call_user_func_array($this->_listOptions['get_items']['function'], array_merge(array($list_context['start'], $list_context['items_per_page'], $sort), empty($this->_listOptions['get_items']['params']) ? array() : $this->_listOptions['get_items']['params']));
     $list_items = empty($list_items) ? array() : $list_items;
     // Loop through the list items to be shown and construct the data values.
     $list_context['rows'] = array();
     foreach ($list_items as $item_id => $list_item) {
         $cur_row = array();
         foreach ($this->_listOptions['columns'] as $column_id => $column) {
             if (isset($column['evaluate']) && $column['evaluate'] === false) {
                 continue;
             }
             $cur_data = array();
             // A value straight from the database?
             if (isset($column['data']['db'])) {
                 $cur_data['value'] = $list_item[$column['data']['db']];
             } elseif (isset($column['data']['db_htmlsafe'])) {
                 $cur_data['value'] = htmlspecialchars($list_item[$column['data']['db_htmlsafe']], ENT_COMPAT, 'UTF-8');
             } elseif (isset($column['data']['sprintf'])) {
                 $params = array();
                 foreach ($column['data']['sprintf']['params'] as $sprintf_param => $htmlsafe) {
                     $params[] = $htmlsafe ? htmlspecialchars($list_item[$sprintf_param], ENT_COMPAT, 'UTF-8') : $list_item[$sprintf_param];
                 }
                 $cur_data['value'] = vsprintf($column['data']['sprintf']['format'], $params);
             } elseif (isset($column['data']['function'])) {
                 $cur_data['value'] = $column['data']['function']($list_item);
             } elseif (isset($column['data']['eval'])) {
                 $cur_data['value'] = eval(preg_replace('~%([a-zA-Z0-9\\-_]+)%~', '$list_item[\'$1\']', $column['data']['eval']));
             } elseif (isset($column['data']['value'])) {
                 $cur_data['value'] = $column['data']['value'];
             } else {
                 $cur_data['value'] = '';
             }
             // Allow for basic formatting.
             if (!empty($column['data']['comma_format'])) {
                 $cur_data['value'] = comma_format($cur_data['value']);
             } elseif (!empty($column['data']['timeformat'])) {
                 // Maybe we need a relative time?
                 if ($column['data']['timeformat'] == 'html_time') {
                     $cur_data['value'] = htmlTime($cur_data['value']);
                 } else {
                     $cur_data['value'] = standardTime($cur_data['value']);
                 }
             }
             // Set a style class for this column?
             if (isset($column['data']['class'])) {
                 $cur_data['class'] = $column['data']['class'];
             }
             // Fully customized styling for the cells in this column only.
             if (isset($column['data']['style'])) {
                 $cur_data['style'] = $column['data']['style'];
             }
             // Add the data cell properties to the current row.
             $cur_row[$column_id] = $cur_data;
         }
         $list_context['rows'][$item_id]['class'] = '';
         $list_context['rows'][$item_id]['style'] = '';
         // Maybe we wat set a custom class for the row based on the data in the row itself
         if (isset($this->_listOptions['data_check'])) {
             if (isset($this->_listOptions['data_check']['class'])) {
                 $list_context['rows'][$item_id]['class'] = ' ' . $this->_listOptions['data_check']['class']($list_item);
             }
             if (isset($this->_listOptions['data_check']['style'])) {
                 $list_context['rows'][$item_id]['style'] = ' style="' . $this->_listOptions['data_check']['style']($list_item) . '"';
             }
         }
         // Insert the row into the list.
         $list_context['rows'][$item_id]['data'] = $cur_row;
     }
     // The title is currently optional.
     if (isset($this->_listOptions['title'])) {
         $list_context['title'] = $this->_listOptions['title'];
         // And the icon is optional for the title
         if (isset($this->_listOptions['icon'])) {
             $list_context['icon'] = $this->_listOptions['icon'];
         }
     }
     // In case there's a form, share it with the template context.
     if (isset($this->_listOptions['form'])) {
         $list_context['form'] = $this->_listOptions['form'];
         if (!isset($list_context['form']['hidden_fields'])) {
             $list_context['form']['hidden_fields'] = array();
         }
         // Always add a session check field.
         $list_context['form']['hidden_fields'][$context['session_var']] = $context['session_id'];
         // Will this do a token check?
         if (isset($this->_listOptions['form']['token'])) {
             $list_context['form']['hidden_fields'][$context[$this->_listOptions['form']['token'] . '_token_var']] = $context[$this->_listOptions['form']['token'] . '_token'];
         }
         // Include the starting page as hidden field?
         if (!empty($list_context['form']['include_start']) && !empty($list_context['start'])) {
             $list_context['form']['hidden_fields'][$list_context['start_var_name']] = $list_context['start'];
         }
         // If sorting needs to be the same after submitting, add the parameter.
         if (!empty($list_context['form']['include_sort']) && !empty($list_context['sort'])) {
             $list_context['form']['hidden_fields']['sort'] = $list_context['sort']['id'];
             if ($list_context['sort']['desc']) {
                 $list_context['form']['hidden_fields']['desc'] = 1;
             }
         }
     }
     // Wanna say something nice in case there are no items?
     if (isset($this->_listOptions['no_items_label'])) {
         $list_context['no_items_label'] = $this->_listOptions['no_items_label'];
         $list_context['no_items_align'] = isset($this->_listOptions['no_items_align']) ? $this->_listOptions['no_items_align'] : '';
     }
     // A list can sometimes need a few extra rows above and below.
     if (isset($this->_listOptions['additional_rows'])) {
         $list_context['additional_rows'] = array();
         foreach ($this->_listOptions['additional_rows'] as $row) {
             if (empty($row)) {
                 continue;
             }
             // Supported row positions: top_of_list, after_title, selectors,
             // above_column_headers, below_table_data, bottom_of_list.
             if (!isset($list_context['additional_rows'][$row['position']])) {
                 $list_context['additional_rows'][$row['position']] = array();
             }
             $list_context['additional_rows'][$row['position']][] = $row;
         }
     }
     // Add an option for inline JavaScript.
     if (isset($this->_listOptions['javascript'])) {
         addInlineJavascript($this->_listOptions['javascript'], true);
     }
     // We want a menu.
     if (isset($this->_listOptions['list_menu'])) {
         if (!isset($this->_listOptions['list_menu']['position'])) {
             $this->_listOptions['list_menu']['position'] = 'left';
         }
         $list_context['list_menu'] = $this->_listOptions['list_menu'];
     }
 }
Exemplo n.º 25
0
 /**
  * Callback for the message display.
  * It actually gets and prepares the message context.
  * This method will start over from the beginning if reset is set to true, which is
  * useful for showing an index before or after the posts.
  *
  * @param bool $reset default false.
  */
 public function prepareDisplayContext_callback($reset = false)
 {
     global $settings, $txt, $modSettings, $scripturl, $options, $user_info;
     global $memberContext, $context, $messages_request, $topic;
     static $counter = null;
     // If the query returned false, bail.
     if ($messages_request == false) {
         return false;
     }
     // Remember which message this is.  (ie. reply #83)
     if ($counter === null || $reset) {
         $counter = $context['start'];
     }
     // Start from the beginning...
     if ($reset) {
         return currentContext($messages_request, $reset);
     }
     // Attempt to get the next message.
     $message = currentContext($messages_request);
     if (!$message) {
         return false;
     }
     // $context['icon_sources'] says where each icon should come from - here we set up the ones which will always exist!
     if (empty($context['icon_sources'])) {
         require_once SUBSDIR . '/MessageIndex.subs.php';
         $context['icon_sources'] = MessageTopicIcons();
     }
     // Message Icon Management... check the images exist.
     if (empty($modSettings['messageIconChecks_disable'])) {
         // If the current icon isn't known, then we need to do something...
         if (!isset($context['icon_sources'][$message['icon']])) {
             $context['icon_sources'][$message['icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $message['icon'] . '.png') ? 'images_url' : 'default_images_url';
         }
     } elseif (!isset($context['icon_sources'][$message['icon']])) {
         $context['icon_sources'][$message['icon']] = 'images_url';
     }
     // If you're a lazy bum, you probably didn't give a subject...
     $message['subject'] = $message['subject'] != '' ? $message['subject'] : $txt['no_subject'];
     // Are you allowed to remove at least a single reply?
     $context['can_remove_post'] |= allowedTo('delete_own') && (empty($modSettings['edit_disable_time']) || $message['poster_time'] + $modSettings['edit_disable_time'] * 60 >= time()) && $message['id_member'] == $user_info['id'];
     // Have you liked this post, can you?
     $message['you_liked'] = !empty($context['likes'][$message['id_msg']]['member']) && isset($context['likes'][$message['id_msg']]['member'][$user_info['id']]);
     $message['use_likes'] = allowedTo('like_posts') && ($message['id_member'] != $user_info['id'] || !empty($modSettings['likeAllowSelf'])) && (empty($modSettings['likeMinPosts']) ? true : $modSettings['likeMinPosts'] <= $user_info['posts']);
     $message['like_count'] = !empty($context['likes'][$message['id_msg']]['count']) ? $context['likes'][$message['id_msg']]['count'] : 0;
     // If it couldn't load, or the user was a guest.... someday may be done with a guest table.
     if (!loadMemberContext($message['id_member'], true)) {
         // Notice this information isn't used anywhere else....
         $memberContext[$message['id_member']]['name'] = $message['poster_name'];
         $memberContext[$message['id_member']]['id'] = 0;
         $memberContext[$message['id_member']]['group'] = $txt['guest_title'];
         $memberContext[$message['id_member']]['link'] = $message['poster_name'];
         $memberContext[$message['id_member']]['email'] = $message['poster_email'];
         $memberContext[$message['id_member']]['show_email'] = showEmailAddress(true, 0);
         $memberContext[$message['id_member']]['is_guest'] = true;
     } else {
         $memberContext[$message['id_member']]['can_view_profile'] = allowedTo('profile_view_any') || $message['id_member'] == $user_info['id'] && allowedTo('profile_view_own');
         $memberContext[$message['id_member']]['is_topic_starter'] = $message['id_member'] == $context['topic_starter_id'];
         $memberContext[$message['id_member']]['can_see_warning'] = !isset($context['disabled_fields']['warning_status']) && $memberContext[$message['id_member']]['warning_status'] && ($context['user']['can_mod'] || !$user_info['is_guest'] && !empty($modSettings['warning_show']) && ($modSettings['warning_show'] > 1 || $message['id_member'] == $user_info['id']));
     }
     $memberContext[$message['id_member']]['ip'] = $message['poster_ip'];
     $memberContext[$message['id_member']]['show_profile_buttons'] = $settings['show_profile_buttons'] && (!empty($memberContext[$message['id_member']]['can_view_profile']) || !empty($memberContext[$message['id_member']]['website']['url']) && !isset($context['disabled_fields']['website']) || in_array($memberContext[$message['id_member']]['show_email'], array('yes', 'yes_permission_override', 'no_through_forum')) || $context['can_send_pm']);
     // Do the censor thang.
     censorText($message['body']);
     censorText($message['subject']);
     // Run BBC interpreter on the message.
     $message['body'] = parse_bbc($message['body'], $message['smileys_enabled'], $message['id_msg']);
     // Compose the memory eat- I mean message array.
     require_once SUBSDIR . '/Attachments.subs.php';
     $output = array('attachment' => loadAttachmentContext($message['id_msg']), 'alternate' => $counter % 2, 'id' => $message['id_msg'], 'href' => $scripturl . '?topic=' . $topic . '.msg' . $message['id_msg'] . '#msg' . $message['id_msg'], 'link' => '<a href="' . $scripturl . '?topic=' . $topic . '.msg' . $message['id_msg'] . '#msg' . $message['id_msg'] . '" rel="nofollow">' . $message['subject'] . '</a>', 'member' => &$memberContext[$message['id_member']], 'icon' => $message['icon'], 'icon_url' => $settings[$context['icon_sources'][$message['icon']]] . '/post/' . $message['icon'] . '.png', 'subject' => $message['subject'], 'time' => standardTime($message['poster_time']), 'html_time' => htmlTime($message['poster_time']), 'timestamp' => forum_time(true, $message['poster_time']), 'counter' => $counter, 'modified' => array('time' => standardTime($message['modified_time']), 'html_time' => htmlTime($message['modified_time']), 'timestamp' => forum_time(true, $message['modified_time']), 'name' => $message['modified_name']), 'body' => $message['body'], 'new' => empty($message['is_read']), 'approved' => $message['approved'], 'first_new' => isset($context['start_from']) && $context['start_from'] == $counter, 'is_ignored' => !empty($modSettings['enable_buddylist']) && in_array($message['id_member'], $context['user']['ignoreusers']), 'is_message_author' => $message['id_member'] == $user_info['id'], 'can_approve' => !$message['approved'] && $context['can_approve'], 'can_unapprove' => !empty($modSettings['postmod_active']) && $context['can_approve'] && $message['approved'], 'can_modify' => (!$context['is_locked'] || allowedTo('moderate_board')) && (allowedTo('modify_any') || allowedTo('modify_replies') && $context['user']['started'] || allowedTo('modify_own') && $message['id_member'] == $user_info['id'] && (empty($modSettings['edit_disable_time']) || !$message['approved'] || $message['poster_time'] + $modSettings['edit_disable_time'] * 60 > time())), 'can_remove' => allowedTo('delete_any') || allowedTo('delete_replies') && $context['user']['started'] || allowedTo('delete_own') && $message['id_member'] == $user_info['id'] && (empty($modSettings['edit_disable_time']) || $message['poster_time'] + $modSettings['edit_disable_time'] * 60 > time()), 'can_see_ip' => allowedTo('moderate_forum') || $message['id_member'] == $user_info['id'] && !empty($user_info['id']), 'can_like' => $message['use_likes'] && !$message['you_liked'], 'can_unlike' => $message['use_likes'] && $message['you_liked'], 'like_counter' => $message['like_count'], 'likes_enabled' => !empty($modSettings['likes_enabled']) && ($message['use_likes'] || $message['like_count'] != 0));
     if (!empty($output['modified']['name'])) {
         $output['modified']['last_edit_text'] = sprintf($txt['last_edit_by'], $output['modified']['time'], $output['modified']['name'], standardTime($output['modified']['timestamp']));
     }
     if (!empty($output['member']['karma']['allow'])) {
         $output['member']['karma'] += array('applaud_url' => $scripturl . '?action=karma;sa=applaud;uid=' . $output['member']['id'] . ';topic=' . $context['current_topic'] . '.' . $context['start'] . ';m=' . $output['id'] . ';' . $context['session_var'] . '=' . $context['session_id'], 'smite_url' => $scripturl . '?action=karma;sa=smite;uid=' . $output['member']['id'] . ';topic=' . $context['current_topic'] . '.' . $context['start'] . ';m=' . $output['id'] . ';' . $context['session_var'] . '=' . $context['session_id']);
     }
     call_integration_hook('integrate_prepare_display_context', array(&$output, &$message));
     $counter++;
     return $output;
 }
 /**
  * Display a chosen article
  *
  * - Update the stats, like #views etc
  */
 public function action_sportal_article()
 {
     global $context, $scripturl, $user_info;
     $article_id = !empty($_REQUEST['article']) ? $_REQUEST['article'] : 0;
     if (is_int($article_id)) {
         $article_id = (int) $article_id;
     } else {
         $article_id = Util::htmlspecialchars($article_id, ENT_QUOTES);
     }
     // Fetch and render the article
     $context['article'] = sportal_get_articles($article_id, true, true);
     if (empty($context['article']['id'])) {
         fatal_lang_error('error_sp_article_not_found', false);
     }
     $context['article']['body'] = sportal_parse_content($context['article']['body'], $context['article']['type'], 'return');
     // Set up for the comment pagination
     $total_comments = sportal_get_article_comment_count($context['article']['id']);
     $per_page = min($total_comments, !empty($modSettings['sp_articles_comments_per_page']) ? $modSettings['sp_articles_comments_per_page'] : 20);
     $start = !empty($_REQUEST['comments']) ? (int) $_REQUEST['comments'] : 0;
     if ($total_comments > $per_page) {
         $context['page_index'] = constructPageIndex($scripturl . '?article=' . $context['article']['article_id'] . ';comments=%1$d', $start, $total_comments, $per_page, true);
     }
     // Load in all the comments for the article
     $context['article']['comments'] = sportal_get_comments($context['article']['id'], $per_page, $start);
     // Prepare the final template details
     $context['article']['date'] = htmlTime($context['article']['date']);
     $context['article']['can_comment'] = $context['user']['is_logged'];
     $context['article']['can_moderate'] = allowedTo('sp_admin') || allowedTo('sp_manage_articles');
     // Commenting, new or an update perhaps
     if ($context['article']['can_comment'] && !empty($_POST['body'])) {
         checkSession();
         sp_prevent_flood('spacp', false);
         require_once SUBSDIR . '/Post.subs.php';
         // Prep the body / comment
         $body = Util::htmlspecialchars(trim($_POST['body']));
         preparsecode($body);
         // Update or add a new comment
         if (!empty($body) && trim(strip_tags(parse_bbc($body, false), '<img>')) !== '') {
             if (!empty($_POST['comment'])) {
                 list($comment_id, $author_id, ) = sportal_fetch_article_comment((int) $_POST['comment']);
                 if (empty($comment_id) || !$context['article']['can_moderate'] && $user_info['id'] != $author_id) {
                     fatal_lang_error('error_sp_cannot_comment_modify', false);
                 }
                 sportal_modify_article_comment($comment_id, $body);
             } else {
                 sportal_create_article_comment($context['article']['id'], $body);
             }
         }
         // Set a anchor
         $anchor = '#comment' . (!empty($comment_id) ? $comment_id : ($total_comments > 0 ? $total_comments - 1 : 1));
         redirectexit('article=' . $context['article']['article_id'] . $anchor);
     }
     // Prepare to edit an existing comment
     if ($context['article']['can_comment'] && !empty($_GET['modify'])) {
         checkSession('get');
         list($comment_id, $author_id, $body) = sportal_fetch_article_comment((int) $_GET['modify']);
         if (empty($comment_id) || !$context['article']['can_moderate'] && $user_info['id'] != $author_id) {
             fatal_lang_error('error_sp_cannot_comment_modify', false);
         }
         require_once SUBSDIR . '/Post.subs.php';
         $context['article']['comment'] = array('id' => $comment_id, 'body' => str_replace(array('"', '<', '>', '&nbsp;'), array('&quot;', '&lt;', '&gt;', ' '), un_preparsecode($body)));
     }
     // Want to delete a comment?
     if ($context['article']['can_comment'] && !empty($_GET['delete'])) {
         checkSession('get');
         if (sportal_delete_article_comment((int) $_GET['delete']) === false) {
             fatal_lang_error('error_sp_cannot_comment_delete', false);
         }
         redirectexit('article=' . $context['article']['article_id']);
     }
     // Increase the article view counter
     if (empty($_SESSION['last_viewed_article']) || $_SESSION['last_viewed_article'] != $context['article']['id']) {
         sportal_increase_viewcount('article', $context['article']['id']);
         $_SESSION['last_viewed_article'] = $context['article']['id'];
     }
     // Build the breadcrumbs
     $context['linktree'] = array_merge($context['linktree'], array(array('url' => $scripturl . '?category=' . $context['article']['category']['category_id'], 'name' => $context['article']['category']['name']), array('url' => $scripturl . '?article=' . $context['article']['article_id'], 'name' => $context['article']['title'])));
     // Off to the template we go
     $context['page_title'] = $context['article']['title'];
     $context['sub_template'] = 'view_article';
 }
Exemplo n.º 27
0
/**
 * Get the latest post made on the system
 *
 * - respects approved, recycled, and board permissions
 *
 * @package Posts
 * @return array
 */
function lastPost()
{
    global $scripturl, $modSettings;
    $db = database();
    // Find it by the board - better to order by board than sort the entire messages table.
    $request = $db->query('substring', '
		SELECT ml.poster_time, ml.subject, ml.id_topic, ml.poster_name, SUBSTRING(ml.body, 1, 385) AS body,
			ml.smileys_enabled
		FROM {db_prefix}boards AS b
			INNER JOIN {db_prefix}messages AS ml ON (ml.id_msg = b.id_last_msg)
		WHERE {query_wanna_see_board}' . (!empty($modSettings['recycle_enable']) && $modSettings['recycle_board'] > 0 ? '
			AND b.id_board != {int:recycle_board}' : '') . '
			AND ml.approved = {int:is_approved}
		ORDER BY b.id_msg_updated DESC
		LIMIT 1', array('recycle_board' => $modSettings['recycle_board'], 'is_approved' => 1));
    if ($db->num_rows($request) == 0) {
        return array();
    }
    $row = $db->fetch_assoc($request);
    $db->free_result($request);
    // Censor the subject and post...
    censorText($row['subject']);
    censorText($row['body']);
    $row['body'] = strip_tags(strtr(parse_bbc($row['body'], $row['smileys_enabled']), array('<br />' => '&#10;')));
    $row['body'] = Util::shorten_text($row['body'], !empty($modSettings['lastpost_preview_characters']) ? $modSettings['lastpost_preview_characters'] : 128, true);
    // Send the data.
    return array('topic' => $row['id_topic'], 'subject' => $row['subject'], 'short_subject' => Util::shorten_text($row['subject'], $modSettings['subject_length']), 'preview' => $row['body'], 'time' => standardTime($row['poster_time']), 'html_time' => htmlTime($row['poster_time']), 'timestamp' => forum_time(true, $row['poster_time']), 'href' => $scripturl . '?topic=' . $row['id_topic'] . '.new;topicseen#new', 'link' => '<a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.new;topicseen#new">' . $row['subject'] . '</a>');
}
Exemplo n.º 28
0
 /**
  * Returns a package array filled with the json information
  *
  * - Uses the parsed json file from the selected package server
  *
  * @param object $thisPackage
  * @param string $packageSection
  *
  * @return array
  */
 private function _load_package_json($thisPackage, $packageSection)
 {
     // Populate the package info from the fetched data
     return array('id' => !empty($thisPackage->pkid) ? array($thisPackage->pkid) : $this->_assume_id($thisPackage), 'type' => $packageSection, 'name' => Util::htmlspecialchars($thisPackage->title), 'date' => htmlTime(strtotime($thisPackage->date)), 'author' => Util::htmlspecialchars($thisPackage->author), 'description' => !empty($thisPackage->short) ? Util::htmlspecialchars($thisPackage->short) : '', 'version' => $thisPackage->version, 'elkversion' => $thisPackage->elkversion, 'license' => $thisPackage->license, 'hooks' => $thisPackage->allhooks, 'server' => array('download' => filter_var($thisPackage->server[0]->download, FILTER_VALIDATE_URL) ? $thisPackage->server[0]->download : '', 'support' => filter_var($thisPackage->server[0]->support, FILTER_VALIDATE_URL) ? $thisPackage->server[0]->support : '', 'bugs' => filter_var($thisPackage->server[0]->bugs, FILTER_VALIDATE_URL) ? $thisPackage->server[0]->bugs : '', 'link' => filter_var($thisPackage->server[0]->url, FILTER_VALIDATE_URL) ? $thisPackage->server[0]->url : ''));
 }