示例#1
0
function mob_get_user_reply_post($rpcmsg)
{
    global $mobdb, $context, $scripturl, $modSettings, $sourcedir, $user_info;
    require_once $sourcedir . '/Subs-Auth.php';
    // Get the user
    $username = $rpcmsg->getScalarValParam(0);
    $id_user = $rpcmsg->getParam(1) ? $rpcmsg->getScalarValParam(1) : null;
    // If we have an user ID, use it otherwise search for the user
    if (!is_null($id_user)) {
        $request = $mobdb->query('
            SELECT ID_MEMBER
            FROM {db_prefix}members
            WHERE ID_MEMBER = {int:member}', array('member' => $id_user));
        if ($mobdb->num_rows($request) == 0) {
            $id_user = null;
        } else {
            list($id_user) = $mobdb->fetch_row($request);
        }
        $mobdb->free_result($request);
    }
    // Otherwise search from the DB,
    if (is_null($id_user)) {
        $username = utf8ToAscii($username);
        $members = findMembers($username);
        if (empty($members)) {
            mob_error('user not found');
        }
        $member_ids = array_keys($members);
        $id_user = $members[$member_ids[0]]['id'];
    }
    // Load this user's post
    $request = $mobdb->query('
        SELECT m.ID_MSG, m.posterTime AS poster_time, m.subject, m.body, t.ID_TOPIC, fm.subject AS topic_subject, b.name AS board_name, b.ID_BOARD AS id_board, t.locked, t.isSticky, IFNULL(mem.realName, m.posterName) AS member_name, t.numViews as views, t.numReplies as replies,' . ($user_info['is_guest'] ? '1 AS `read`' : 'IFNULL(lt.ID_MSG, IFNULL(lmr.ID_MSG, 0)) >= m.ID_MSG_MODIFIED AS `read`, 
                                                     IFNULL(al.ID_ATTACH, 0) AS last_id_attach, al.filename AS last_filename, al.attachmentType AS last_attachment_type, mem.avatar AS last_avatar') . '
        FROM {db_prefix}messages AS m
            INNER JOIN {db_prefix}topics AS t ON (t.ID_TOPIC = m.ID_TOPIC)
            INNER JOIN {db_prefix}messages AS fm ON (fm.ID_MSG = t.ID_FIRST_MSG)
            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)' . (!$user_info['is_guest'] ? "\n            LEFT JOIN {db_prefix}log_topics AS lt ON (lt.ID_TOPIC = m.ID_TOPIC AND lt.ID_MEMBER = {int:cur_member})\n            LEFT JOIN {db_prefix}log_mark_read AS lmr ON (lmr.ID_BOARD = m.ID_BOARD AND lmr.ID_MEMBER = {int:cur_member})\n            LEFT JOIN {db_prefix}attachments AS al ON (al.ID_MEMBER = mem.ID_MEMBER)" : '') . '
        WHERE m.ID_MEMBER = {int:member}
            AND {query_see_board}
        ORDER BY m.ID_MSG DESC
        LIMIT 50', array('member' => $id_user, 'cur_member' => $user_info['id']));
    $posts = array();
    while ($row = $mobdb->fetch_assoc($request)) {
        $last_avatar = $row['last_avatar'] == '' ? $row['last_id_attach'] > 0 ? empty($row['last_attachment_type']) ? $scripturl . '?action=dlattach;attach=' . $row['last_id_attach'] . ';type=avatar' : $modSettings['custom_avatar_url'] . '/' . $row['last_filename'] : '' : (stristr($row['last_avatar'], 'http://') ? $row['last_avatar'] : $modSettings['avatar_url'] . '/' . $row['last_avatar']);
        $posts[] = array('id' => $row['ID_TOPIC'], 'post_id' => $row['ID_MSG'], 'subject' => $row['topic_subject'], 'board' => array('id' => $row['id_board'], 'name' => $row['board_name']), 'first_post' => array('poster' => array('id' => 0, 'name' => '')), 'last_post' => array('id' => $row['ID_MSG'], 'subject' => $row['subject'], 'body' => $row['body'], 'time' => $row['poster_time'], 'member' => array('id' => $id_user, 'name' => $row['member_name'], 'avatar' => array('href' => $last_avatar))), 'is_sticky' => $row['isSticky'], 'locked' => $row['locked'], 'views' => $row['views'], 'replies' => $row['replies'], 'new' => !empty($row['read']));
    }
    $mobdb->free_result($request);
    // Return the posts
    return new xmlrpcresp(new xmlrpcval(get_topics_xmlrpc($posts, false), 'array'));
}
示例#2
0
function mob_search_topic($rpcmsg, $subject_only = false)
{
    global $mobdb, $context, $sourcedir, $user_info, $modSettings, $scripturl, $modSettings, $messages_request;
    // Guest?
    if ($user_info['is_guest']) {
        mob_error('guests not allowed');
    }
    $string = $rpcmsg->getScalarValParam(0);
    $start = $rpcmsg->getScalarValParam(1);
    $end = $rpcmsg->getScalarValParam(2);
    $count = $end - $start > 50 ? 50 : $end - $start + 1;
    // We got an ID?
    if ($rpcmsg->getParam(3)) {
        $id_search = $rpcmsg->getScalarValParam(3);
    }
    // Is it an existing search?
    $new_search = !isset($id_search) || empty($_SESSION['search_cache'][$id_search]);
    if (!$new_search) {
        $_SESSION['search_cache'] = $_SESSION['search_cache'][$id_search];
    }
    // We use a cheap hack to perform our search
    $_REQUEST['start'] = $_GET['start'] = isset($start_num) ? $start_num : 0;
    $modSettings['search_results_per_page'] = isset($limit) ? $limit : 20;
    $_REQUEST['search'] = $_POST['search'] = $string;
    $_REQUEST['advanced'] = $_POST['advanced'] = 0;
    $_REQUEST['subject_only'] = $_POST['subject_only'] = $subject_only;
    require_once $sourcedir . '/Search.php';
    PlushSearch2();
    // We got results?
    if (!isset($_SESSION['search_cache'])) {
        mob_error('search not successful');
    }
    $count = $_SESSION['search_cache']['num_results'];
    $search_id = $_SESSION['search_cache']['ID_SEARCH'];
    // Cache it
    if (isset($id_search)) {
        $search_cache = $_SESSION['search_cache'];
        unset($_SESSION['search_cache']);
        $_SESSION['search_cache'][$id_search] = $search_cache;
        unset($search_cache);
    }
    // Get the results
    $topics = array();
    $tids = array();
    while ($topic = $context['get_topics']()) {
        $match = $topic['matches'][0];
        $topics[$topic['id']] = $topic;
        $topics[$topic['id']]['first_post'] = $match;
        $topics[$topic['id']]['last_post'] = $match;
        $tids[] = $topic['id'];
    }
    if (!empty($tids)) {
        // Check for notifications on this topic OR board.
        $mobdb->query("\n\t\t    SELECT sent, ID_TOPIC\n            FROM {db_prefix}log_notify\n            WHERE ID_TOPIC IN ({array_int:topic_ids})\n                AND ID_MEMBER = {int:member}", array('topic_ids' => $tids, 'member' => $user_info['id']));
        while ($row = $mobdb->fetch_assoc()) {
            // Find if this topic is marked for notification...
            if (!empty($row['ID_TOPIC'])) {
                $topics[$row['ID_TOPIC']]['is_notify'] = true;
            }
        }
        $mobdb->free_result();
    }
    foreach ($topics as $k => $topic) {
        $topics[$k]['subject'] = $topic['first_post']['subject'];
    }
    // Output the results
    return new xmlrpcresp(new xmlrpcval(array('total_topic_num' => new xmlrpcval($count, 'int'), 'search_id' => new xmlrpcval($search_id, 'string'), 'topics' => new xmlrpcval(get_topics_xmlrpc($topics), 'array')), 'struct'));
}
示例#3
0
function get_topics($where = '', $where_params = array(), $start = 0, $count = 20, $use_first = true)
{
    global $mobdb, $scripturl, $settings, $user_info, $modSettings;
    $mobdb->query("SET OPTION SQL_BIG_SELECTS=1");
    // Perform the query to fetch the topics
    $mobdb->query('
        SELECT t.ID_TOPIC AS id_topic, t.numReplies AS num_replies, t.locked, t.numViews AS num_views, t.isSticky AS is_sticky, t.ID_POLL AS id_poll,
                ' . ($user_info['is_guest'] ? '0' : 'IFNULL(lt.ID_MSG, IFNULL(lmr.ID_MSG, -1)) + 1') . ' AS new_from,
                ' . ($user_info['is_guest'] ? '0' : 'IFNULL(ln.ID_TOPIC, 0)') . ' AS is_notify,
                b.ID_BOARD AS id_board, b.name AS board_name,
                t.ID_LAST_MSG AS id_last_msg, lm.posterTime AS last_poster_time, lm.ID_MSG_MODIFIED AS id_msg_modified,
                lm.subject AS last_subject, lm.icon AS last_icon, lm.posterName AS last_member_name,
                lm.ID_MEMBER AS last_id_member, IFNULL(ml.realName, lm.posterName) AS last_display_name,
                t.ID_FIRST_MSG AS id_first_msg, fm.posterTime AS first_poster_time,
                fm.subject AS first_subject, fm.icon AS first_icon, fm.posterName AS first_member_name,
                fm.ID_MEMBER AS first_id_member, IFNULL(mf.realName, fm.posterName) AS first_display_name,
                lm.body AS last_body, fm.body AS first_body,
                IFNULL(af.ID_ATTACH, 0) AS first_id_attach, af.filename AS first_filename, af.attachmentType AS first_attachment_type, mf.avatar AS first_avatar,
                IFNULL(al.ID_ATTACH, 0) AS last_id_attach, al.filename AS last_filename, al.attachmentType AS last_attachment_type, ml.avatar AS last_avatar
        FROM {db_prefix}topics AS t
            INNER JOIN {db_prefix}boards AS b ON (b.id_board = t.id_board)
            LEFT JOIN {db_prefix}messages AS fm ON (t.ID_FIRST_MSG = fm.ID_MSG)
            LEFT JOIN {db_prefix}messages AS lm ON (t.ID_LAST_MSG = lm.ID_MSG)
            LEFT JOIN {db_prefix}members AS mf ON (fm.ID_MEMBER = mf.ID_MEMBER)
            LEFT JOIN {db_prefix}members AS ml ON (lm.ID_MEMBER = ml.ID_MEMBER)' . ($user_info['is_guest'] ? '' : '
            LEFT JOIN {db_prefix}log_notify AS ln ON (ln.ID_TOPIC = t.ID_TOPIC AND ln.ID_MEMBER = {int:current_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})') . '
            LEFT JOIN {db_prefix}attachments AS af ON (af.ID_MEMBER = mf.ID_MEMBER)
            LEFT JOIN {db_prefix}attachments AS al ON (al.ID_MEMBER = ml.ID_MEMBER)
        WHERE {query_see_board} ' . (!empty($where) ? ' AND ' . $where : '') . '
        ORDER BY IFNULL(lm.posterTime, fm.posterTime) DESC
        LIMIT {int:start}, {int:count}', array_merge(array('current_member' => $user_info['id'], 'start' => $start, 'count' => $count), $where_params));
    $topics = array();
    while ($row = $mobdb->fetch_assoc()) {
        $first_avatar = $row['first_avatar'] == '' ? $row['first_id_attach'] > 0 ? empty($row['first_attachment_type']) ? $scripturl . '?action=dlattach;attach=' . $row['first_id_attach'] . ';type=avatar' : $modSettings['custom_avatar_url'] . '/' . $row['first_filename'] : '' : (stristr($row['first_avatar'], 'http://') ? $row['first_avatar'] : $modSettings['avatar_url'] . '/' . $row['first_avatar']);
        $last_avatar = $row['last_avatar'] == '' ? $row['last_id_attach'] > 0 ? empty($row['last_attachment_type']) ? $scripturl . '?action=dlattach;attach=' . $row['last_id_attach'] . ';type=avatar' : $modSettings['custom_avatar_url'] . '/' . $row['last_filename'] : '' : (stristr($row['last_avatar'], 'http://') ? $row['last_avatar'] : $modSettings['avatar_url'] . '/' . $row['last_avatar']);
        $topics[] = array('id' => $row['id_topic'], 'first_post' => array('id' => $row['id_first_msg'], 'member' => array('id' => $row['first_id_member'], 'name' => $row['first_display_name'], 'avatar' => array('href' => $first_avatar)), 'time' => $row['first_poster_time'], 'subject' => $row['first_subject'], 'body' => $row['first_body']), 'last_post' => array('id' => $row['id_last_msg'], 'member' => array('id' => $row['last_id_member'], 'name' => $row['last_display_name'], 'avatar' => array('href' => $last_avatar)), 'time' => $row['last_poster_time'], 'subject' => $row['last_subject'], 'body' => $row['last_body']), 'board' => array('id' => $row['id_board'], 'name' => $row['board_name']), 'new' => $row['new_from'] <= $row['id_msg_modified'], 'new_from' => $row['new_from'], 'is_sticky' => $row['is_sticky'], 'is_locked' => $row['locked'], 'is_notify' => $row['is_notify'], 'subject' => $row['first_subject'], 'replies' => $row['num_replies'], 'views' => $row['num_views']);
    }
    $mobdb->free_result();
    return get_topics_xmlrpc($topics, $use_first);
}