function method_get_participated_topic()
{
    global $context, $mobdb, $mobsettings, $modSettings, $user_info, $sourcedir;
    // Guest?
    if ($user_info['is_guest']) {
        createErrorResponse(21);
    }
    // Get the username
    $username = base64_decode($context['mob_request']['params'][0][0]);
    if (empty($username)) {
        createErrorResponse(8);
    }
    require_once $sourcedir . '/Subs-Auth.php';
    ######## Added by Sean##############
    $username = htmltrim__recursive($username);
    $username = stripslashes__recursive($username);
    $username = htmlspecialchars__recursive($username);
    $username = addslashes__recursive($username);
    ##################################################################
    // Does this user exist?
    $members = findMembers($username);
    if (empty($members)) {
        createErrorResponse(8);
    }
    $id_member = array_keys($members);
    $member = $members[$id_member[0]];
    if (empty($member)) {
        createErrorResponse(8);
    }
    // Do we have start num defined?
    if (isset($context['mob_request']['params'][1])) {
        $start_num = (int) $context['mob_request']['params'][1][0];
    }
    // Do we have last number defined?
    if (isset($context['mob_request']['params'][2])) {
        $last_num = (int) $context['mob_request']['params'][2][0];
    }
    // Perform some start/last num checks
    if (isset($start_num) && isset($last_num)) {
        if ($start_num > $last_num) {
            createErrorResponse(3);
        } elseif ($last_num - $start_num > 50) {
            $last_num = $start_num + 50;
        }
    }
    // Default number of topics per page
    $topics_per_page = 20;
    // Generate the limit clause
    $limit = '';
    if (!isset($start_num) && !isset($last_num)) {
        $start_num = 0;
        $limit = $topics_per_page;
    } elseif (isset($start_num) && !isset($last_num)) {
        $limit = $topics_per_page;
    } elseif (isset($start_num) && isset($last_num)) {
        $limit = $last_num - $start_num + 1;
    } elseif (empty($start_num) && empty($last_num)) {
        $start_num = 0;
        $limit = $topics_per_page;
    }
    // Get the count
    $mobdb->query('
        SELECT t.ID_TOPIC
        FROM {db_prefix}messages AS m
            INNER JOIN {db_prefix}topics AS t ON (m.ID_TOPIC = t.ID_TOPIC)
            INNER JOIN {db_prefix}boards AS b ON (b.ID_BOARD = t.ID_BOARD)
        WHERE {query_see_board}
            AND m.ID_MEMBER = {int:member}
        GROUP BY t.ID_TOPIC
        ORDER BY t.ID_TOPIC DESC', array('member' => $id_member[0]));
    $tids = array();
    while ($row = $mobdb->fetch_assoc()) {
        $tids[] = $row['ID_TOPIC'];
    }
    $mobdb->free_result();
    $count = count($tids);
    if ($limit + $start_num > $count) {
        $limit = $count - $start_num;
    }
    $tids = array_slice($tids, $start_num, $limit);
    $topics = array();
    if (count($tids)) {
        // Grab the topics
        $mobdb->query('
            SELECT t.ID_TOPIC AS id_topic, t.isSticky AS is_sticky, t.locked, fm.subject AS topic_title, t.numViews AS views, t.numReplies AS replies,
                    IFNULL(mem.ID_MEMBER, 0) AS id_member, mem.realName, mem.memberName, mem.avatar, IFNULL(a.ID_ATTACH, 0) AS id_attach, a.filename, a.attachmentType AS attachment_type,
                    IFNULL(lm.posterTime, fm.posterTime) AS last_message_time, ' . ($user_info['is_guest'] ? '0' : 'ln.ID_TOPIC AS is_notify, IFNULL(lt.ID_MSG, IFNULL(lmr.ID_MSG, -1)) + 1') . ' AS new_from,
                    IFNULL(lm.body, fm.body) AS body, lm.ID_MSG_MODIFIED AS id_msg_modified, b.name AS board_name, b.ID_BOARD AS id_board
            FROM {db_prefix}messages AS m
                INNER JOIN {db_prefix}topics AS t ON (m.ID_TOPIC = t.ID_TOPIC)
                INNER JOIN {db_prefix}messages AS fm ON (t.ID_FIRST_MSG = fm.ID_MSG)
                INNER JOIN {db_prefix}boards AS b ON (b.ID_BOARD = t.ID_BOARD)
                LEFT JOIN {db_prefix}messages AS lm ON (t.ID_LAST_MSG = lm.ID_MSG)
                LEFT JOIN {db_prefix}members AS mem ON (lm.ID_MEMBER = mem.ID_MEMBER)' . ($user_info['is_guest'] ? '' : '
                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_notify AS ln ON ((ln.ID_TOPIC = t.ID_TOPIC OR ln.ID_BOARD = t.ID_BOARD) AND ln.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 a ON (a.ID_MEMBER = mem.ID_MEMBER)
            WHERE {query_see_board}
                AND m.ID_MEMBER = {int:member} AND t.ID_TOPIC IN ({array_int:topic_ids})
            ORDER BY lm.posterTime DESC', array('current_member' => $user_info['id'], 'member' => $id_member[0], 'topic_ids' => $tids));
        while ($row = $mobdb->fetch_assoc()) {
            // Add stuff to the array
            $topics[$row['id_topic']] = array('id' => $row['id_topic'], 'title' => processSubject($row['topic_title']), 'short_msg' => processShortContent($row['body']), 'replies' => $row['replies'], 'views' => $row['views'], 'poster' => array('id' => $row['id_member'], 'username' => $row['memberName'], 'post_name' => $row['realName'], 'avatar' => get_avatar($row)), 'is_new' => $user_info['is_guest'] ? 0 : $row['new_from'] <= $row['id_msg_modified'], 'board' => $row['id_board'], 'board_name' => $row['board_name'], 'post_time' => mobiquo_time($row['last_message_time']), 'is_marked_notify' => !empty($row['is_notify']), 'is_locked' => !empty($row['locked']));
        }
        $mobdb->free_result();
    }
    // LAME!
    outputRPCSubscribedTopics($topics, $count);
}
function topicRPCXML($topic)
{
    global $user_info;
    $response = '
<value><struct>
<member>
<name>forum_id</name>
<value><string>' . (isset($topic['board']['id']) ? $topic['board']['id'] : $topic['board']) . '</string></value>
</member>';
    // For new_topic
    if (isset($topic['board_name']) || isset($topic['board']['name'])) {
        $response .= '
<member>
<name>forum_name</name>
<value><base64>' . base64_encode(mobi_unescape_html(isset($topic['board_name']) ? $topic['board_name'] : $topic['board']['name'])) . '</base64></value>
</member>';
    }
    $response .= '
<member>
<name>topic_id</name>
<value><string>' . $topic['id'] . '</string></value>
</member>
<member>
<name>topic_title</name>
<value><base64>' . base64_encode(mobi_unescape_html(isset($topic['title']) ? $topic['title'] : $topic['subject'])) . '</base64></value>
</member>';
    if (isset($topic['post_id'])) {
        $response .= '
<member>
<name>post_id</name>
<value><string>' . $topic['post_id'] . '</string></value>
</member>
<member>
<name>post_title</name>
<value><base64>' . base64_encode(mobi_unescape_html($topic['post_title'])) . '</base64></value>
</member>';
    }
    $response .= '
<member>
<name>post_author_id</name>
<value><string>' . (isset($topic['poster']['id']) ? $topic['poster']['id'] : $topic['last_post']['member']['id']) . '</string></value>
</member>
<member>
<name>' . (isset($topic['last_poster_name']) ? 'last_reply_author_name' : (isset($topic['board_name']) || isset($topic['board']['name']) ? 'post_' : 'topic_') . 'author_name') . '</name>
<value><base64>' . base64_encode(processUsername(isset($topic['last_poster_name']) ? $topic['last_poster_name'] : (isset($topic['poster']['username']) ? $topic['poster']['username'] : $topic['last_post']['member']['name']))) . '</base64></value>
</member>';
    if (isset($topic['last_poster_username'])) {
        $response .= '
<member>
<name>last_reply_author_display_name</name>
<value><base64>' . base64_encode(processUsername($topic['last_poster_username'])) . '</base64></value>
</member>';
    }
    if (isset($topic['poster']['name'])) {
        $response .= '
<member>
<name>topic_author_display_name</name>
<value><base64>' . base64_encode(processUsername($topic['poster']['name'])) . '</base64></value>
</member>';
    }
    if (isset($topic['poster']['post_name'])) {
        $response .= '
<member>
<name>post_author_display_name</name>
<value><base64>' . base64_encode(processUsername($topic['poster']['post_name'])) . '</base64></value>
</member>';
    }
    $response .= '
<member>
<name>is_subscribed</name>
<value><boolean>' . (empty($topic['is_marked_notify']) ? 0 : 1) . '</boolean></value>
</member>
<member>
<name>can_subscribe</name>
<value><boolean>' . (allowedTo('mark_any_notify') && !$user_info['is_guest']) . '</boolean></value>
</member>
<member>
<name>is_closed</name>
<value><boolean>' . (empty($topic['is_locked']) ? 0 : 1) . '</boolean></value>
</member>
<member>
<name>is_sticky</name>
<value><boolean>' . (empty($topic['is_sticky']) ? 0 : 1) . '</boolean></value>
</member>
<member>
<name>icon_url</name>
<value><string>' . process_url(isset($topic['poster']['avatar']) ? $topic['poster']['avatar'] : $topic['last_post']['member']['avatar']) . '</string></value>
</member>';
    if (isset($topic['last_msg_time'])) {
        $response .= '
<member>
<name>last_reply_time</name>
<value><dateTime.iso8601>' . $topic['last_msg_time'] . '</dateTime.iso8601></value>
</member>';
    }
    if (isset($topic['post_time'])) {
        $response .= '
<member>
<name>post_time</name>
<value><dateTime.iso8601>' . $topic['post_time'] . '</dateTime.iso8601></value>
</member>';
    }
    if (isset($topic['last_post']['timestamp'])) {
        $response .= '
<member>
<name>post_time</name>
<value><dateTime.iso8601>' . mobiquo_time($topic['last_post']['timestamp']) . '</dateTime.iso8601></value>
</member>';
    }
    $response .= '
<member>
<name>reply_number</name>
<value><int>' . intval($topic['replies']) . '</int></value>
</member>
<member>
<name>new_post</name>
<value><boolean>' . (empty($topic['is_new']) && empty($topic['new_from']) ? 0 : 1) . '</boolean></value>
</member>';
    // This does not exist in new_topic
    if (isset($topic['views'])) {
        $response .= '
<member>
<name>view_number</name>
<value><int>' . intval($topic['views']) . '</int></value>
</member>';
    }
    $response .= '
<member>
<name>short_content</name>
<value><base64>' . base64_encode(isset($topic['short_msg']) ? $topic['short_msg'] : processShortContent($topic['last_post']['preview'])) . '</base64></value>
</member>
</struct></value>';
    return $response;
}
Example #3
0
function get_topics_xmlrpc($_topics, $use_first = true)
{
    global $user_info;
    $topics = array();
    $permission = array();
    $perms = array('mark_notify', 'remove_any', 'remove_own', 'lock_any', 'lock_own', 'make_sticky', 'move_any', 'move_own', 'modify_any', 'modify_own', 'manage_bans');
    foreach ($_topics as $topic) {
        $started = !$user_info['is_guest'] && $user_info['id'] == $topic['first_post']['member']['id'];
        if ($use_first) {
            $message = isset($topic['first_post']['preview']) ? $topic['first_post']['preview'] : $topic['first_post']['body'];
        } else {
            $message = isset($topic['last_post']['preview']) ? $topic['last_post']['preview'] : $topic['last_post']['body'];
        }
        if ($use_first) {
            if (!is_numeric($topic['first_post']['time']) && isset($topic['first_post']['timestamp'])) {
                $post_time = mobiquo_time($topic['first_post']['timestamp'], true);
            } else {
                $post_time = mobiquo_time($topic['first_post']['time']);
            }
        } else {
            if (!is_numeric($topic['last_post']['time']) && isset($topic['last_post']['timestamp'])) {
                $post_time = mobiquo_time($topic['last_post']['timestamp'], true);
            } else {
                $post_time = mobiquo_time($topic['last_post']['time']);
            }
        }
        $fid = $topic['board']['id'];
        foreach ($perms as $perm) {
            if (!isset($permission[$fid][$perm])) {
                $permission[$fid][$perm] = allowedTo($perm, $fid);
            }
        }
        // Add stuff to the array
        $topics[] = new xmlrpcval(array('topic_id' => new xmlrpcval($topic['id'], 'string'), 'topic_title' => new xmlrpcval(processSubject($topic['subject']), 'base64'), 'reply_number' => new xmlrpcval($topic['replies'], 'int'), 'view_number' => new xmlrpcval($topic['views'], 'int'), 'topic_author_id' => new xmlrpcval($topic['first_post']['member']['id'], 'string'), 'topic_author_name' => new xmlrpcval(processUsername($topic['first_post']['member']['name']), 'base64'), 'post_author_id' => new xmlrpcval($topic['last_post']['member']['id'], 'string'), 'post_author_name' => new xmlrpcval(processUsername($topic['last_post']['member']['name']), 'base64'), 'forum_id' => new xmlrpcval($topic['board']['id'], 'string'), 'forum_name' => new xmlrpcval(processSubject($topic['board']['name']), 'base64'), 'post_id' => new xmlrpcval($topic['last_post']['id'], 'string'), 'is_subscribed' => new xmlrpcval($topic['is_notify'], 'boolean'), 'can_subscribe' => new xmlrpcval($permission[$fid]['mark_notify'] && !$user_info['is_guest'], 'boolean'), 'is_closed' => new xmlrpcval(isset($topic['locked']) ? $topic['locked'] : $topic['is_locked'], 'boolean'), 'new_post' => new xmlrpcval($topic['new'], 'boolean'), 'short_content' => new xmlrpcval(processShortContent($message), 'base64'), 'post_time' => new xmlrpcval($post_time, 'dateTime.iso8601'), 'last_reply_time' => new xmlrpcval($post_time, 'dateTime.iso8601'), 'icon_url' => new xmlrpcval($use_first ? $topic['first_post']['member']['avatar']['href'] : $topic['last_post']['member']['avatar']['href'], 'string'), 'can_delete' => new xmlrpcval($permission[$fid]['remove_any'] || $started && $permission[$fid]['remove_own'], 'boolean'), 'can_close' => new xmlrpcval($permission[$fid]['lock_any'] || $started && $permission[$fid]['lock_own'], 'boolean'), 'can_approve' => new xmlrpcval(false, 'boolean'), 'can_stick' => new xmlrpcval($permission[$fid]['make_sticky'], 'boolean'), 'can_move' => new xmlrpcval($permission[$fid]['move_any'] || $started && $permission[$fid]['move_own'], 'boolean'), 'can_rename' => new xmlrpcval($permission[$fid]['modify_any'] || $started && $permission[$fid]['modify_own'], 'boolean'), 'can_ban' => new xmlrpcval($permission[$fid]['manage_bans'], 'boolean'), 'is_sticky' => new xmlrpcval($topic['is_sticky'], 'boolean')), 'struct');
    }
    return $topics;
}