function outputRPCUserInfo($user_data)
{
    $response = '
<params>
<param>
<value>
<struct>
<member>
<name>post_count</name>
<value><int>' . intval($user_data['posts']) . '</int></value>
</member>
<member>
<name>reg_time</name>
<value><dateTime.iso8601>' . mobiquo_time($user_data['registered_timestamp']) . '</dateTime.iso8601></value>
</member>
<member>
<name>display_name</name>
<value><base64>' . base64_encode(processUsername($user_data['name'])) . '</base64></value>
</member>
<member>
<name>last_activity_time</name>
<value><dateTime.iso8601>' . mobiquo_time($user_data['last_login_timestamp']) . '</dateTime.iso8601></value>
</member>
<member>
<name>is_online</name>
<value><boolean>' . (!empty($user_data['online']['is_online']) ? 1 : 0) . '</boolean></value>
</member>
<member>
<name>accept_pm</name>
<value><boolean>' . (allowedTo('pm_send') ? 1 : 0) . '</boolean></value>
</member>
<member>
<name>icon_url</name>
<value><string>' . process_url($user_data['avatar']['href']) . '</string></value>
</member>
<member>
<name>custom_fields_list</name>
<value>
<array>
<data>';
    foreach ($user_data['custom_fields_list'] as $key => $value) {
        $response .= '
<value>
<struct>
<member>
<name>name</name>
<value><base64>' . base64_encode(mobi_unescape_html($key)) . '</base64></value>
</member>
<member>
<name>value</name>
<value><base64>' . base64_encode(mobi_unescape_html($value)) . '</base64></value>
</member>
</struct>
</value>';
    }
    $response .= '
</data>
</array>
</value>
</member>
</struct>
</value>
</param>
</params>';
    outputRPCResponse($response);
}
Example #2
0
function mob_get_user_info($rpcmsg)
{
    global $mobdb, $context, $modSettings, $memberContext, $user_profile, $sourcedir, $txt, $user_info;
    $username = $rpcmsg->getParam(0) ? $rpcmsg->getScalarValParam(0) : null;
    $id_user = $rpcmsg->getParam(1) ? $rpcmsg->getScalarValParam(1) : null;
    if (empty($username) && empty($id_user)) {
        $id_user = $user_info['id'];
    }
    $id_user = intval($id_user);
    require_once $sourcedir . '/Subs-Auth.php';
    // 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'];
    }
    loadMemberData($id_user);
    loadMemberContext($id_user);
    $member = $memberContext[$id_user];
    // Is the guy banned?
    $request = $mobdb->query('
        SELECT COUNT(*)
        FROM {db_prefix}ban_items AS bi
            INNER JOIN {db_prefix}ban_groups AS bg ON (bg.ID_BAN_GROUP = bi.ID_BAN_GROUP)
        WHERE bi.ID_MEMBER = {int:member}
            AND (bg.expire_time IS NULL OR bg.expire_time > {int:time})
            AND bg.cannot_access != 0', array('member' => $member['id'], 'time' => time()));
    $banned = false;
    list($count) = $mobdb->fetch_row($request);
    if ($count > 0) {
        $banned = true;
    }
    $mobdb->free_result($request);
    loadLanguage('Profile');
    // Load the current action
    $current_action = determineActions($user_profile[$id_user]['url']);
    // Figure out all the custom fields
    $custom_fields = array();
    $custom_fields[] = new xmlrpcval(array('name' => new xmlrpcval($txt[87], 'base64'), 'value' => new xmlrpcval(!empty($member['group']) ? $member['group'] : $member['post_group'], 'base64')), 'struct');
    // Custom communication fields
    $fields = array('icq', 'aim', 'msn', 'yim');
    $_fields = array($txt[513], $txt[603], $txt['MSN'], $txt[604]);
    foreach ($fields as $k => $field) {
        if (!empty($member[$field]['name'])) {
            $custom_fields[] = new xmlrpcval(array('name' => new xmlrpcval(processSubject($_fields[$k]), 'base64'), 'value' => new xmlrpcval(processSubject($member[$field]['name']), 'base64')), 'struct');
        }
    }
    if ($modSettings['karmaMode'] == '1' || $modSettings['karmaMode'] == '2') {
        $custom_fields[] = new xmlrpcval(array('name' => new xmlrpcval(processSubject($modSettings['karmaLabel']), 'base64'), 'value' => new xmlrpcval(processSubject($modSettings['karmaMode'] == '1' ? $member['karma']['good'] - $member['karma']['bad'] : '+' . $member['karma']['good'] . '/-' . $member['karma']['bad']), 'base64')), 'struct');
    }
    if (!empty($member['gender']['name'])) {
        $custom_fields[] = new xmlrpcval(array('name' => new xmlrpcval(processSubject($txt[231]), 'base64'), 'value' => new xmlrpcval(processSubject($member['gender']['name']), 'base64')), 'struct');
    }
    if (!empty($member['location'])) {
        $custom_fields[] = new xmlrpcval(array('name' => new xmlrpcval(processSubject($txt[227]), 'base64'), 'value' => new xmlrpcval(processSubject($member['location']), 'base64')), 'struct');
    }
    if (!empty($member['signature'])) {
        $custom_fields[] = new xmlrpcval(array('name' => new xmlrpcval(processSubject($txt[85]), 'base64'), 'value' => new xmlrpcval(processSubject($member['signature']), 'base64')), 'struct');
    }
    $response = array('user_id' => new xmlrpcval($member['id'], 'string'), 'user_name' => new xmlrpcval(processUsername(!empty($member['name']) ? $member['name'] : $member['username']), 'base64'), 'display_name' => new xmlrpcval(processUsername(!empty($member['name']) ? $member['name'] : $member['username']), 'base64'), 'post_count' => new xmlrpcval($member['posts'], 'int'), 'reg_time' => new xmlrpcval(mobiquo_time($member['registered_timestamp']), 'dateTime.iso8601'), 'is_online' => new xmlrpcval(!empty($user_profile[$id_user]['isOnline']), 'boolean'), 'accept_pm' => new xmlrpcval(true, 'boolean'), 'display_text' => new xmlrpcval(processSubject($member['title']), 'base64'), 'icon_url' => new xmlrpcval($member['avatar']['href'], 'string'), 'current_activity' => new xmlrpcval(processSubject($current_action), 'base64'), 'current_action' => new xmlrpcval(processSubject($current_action), 'base64'), 'is_ban' => new xmlrpcval($banned, 'boolean'), 'can_ban' => new xmlrpcval(allowedTo('manage_bans'), 'boolean'), 'custom_fields_list' => new xmlrpcval($custom_fields, 'array'));
    if ($banned) {
        $response['user_type'] = new xmlrpcval('banned', 'base64');
    }
    // Return the response
    return new xmlrpcresp(new xmlrpcval($response, 'struct'));
}
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);
}
Example #4
0
function mob__get_thread($_topic = null, $post = null, $start = 0, $limit = 20, $per_page = null, $from_new = false)
{
    global $mobdb, $context, $modSettings, $scripturl, $user_info, $memberContext, $user_profile, $board, $topic;
    // If we are not given the topic ID, we load the start, limit and the topic
    $topic = $_topic;
    $position = 0;
    if (is_null($topic)) {
        if (is_null($post) || is_null($per_page)) {
            mob_error('invalid parameters');
        }
        $limit = $per_page;
        // Get the topic
        $request = $mobdb->query('
			SELECT ID_TOPIC AS id_topic
			FROM {db_prefix}messages
			WHERE id_msg = {int:post}', array('post' => $post));
        list($topic) = $mobdb->fetch_row($request);
        $mobdb->free_result($request);
        // Get the start value
        $request = $mobdb->query('
			SELECT COUNT(*)
			FROM {db_prefix}messages
			WHERE id_msg < {int:msg}
				AND id_topic = {int:topic}', array('topic' => $topic, 'msg' => $post));
        list($start) = $mobdb->fetch_row($request);
        $position = $start;
        $mobdb->free_result($request);
    }
    // Load the topic info
    $request = $mobdb->query('
		SELECT t.ID_TOPIC AS id_topic, t.ID_FIRST_MSG AS id_first_msg, t.ID_LAST_MSG AS id_last_msg, t.ID_MEMBER_STARTED AS id_member_started,
				' . ($user_info['is_guest'] ? '0' : 'ln.ID_TOPIC') . ' AS is_notify, t.locked, t.isSticky AS is_sticky, t.numReplies AS replies, t.numViews As views,
				' . ($user_info['is_guest'] ? 't.ID_LAST_MSG + 1' : 'IFNULL(lt.ID_MSG, IFNULL(lmr.ID_MSG, -1)) + 1') . ' AS new_from,
				b.id_board, b.name, m.subject
		FROM {db_prefix}topics AS t
			INNER JOIN {db_prefix}boards AS b ON (b.ID_BOARD = t.ID_BOARD)
			INNER JOIN {db_prefix}messages AS m ON (m.ID_MSG = t.ID_FIRST_MSG)' . ($user_info['is_guest'] ? '' : '
			LEFT JOIN {db_prefix}log_notify AS ln ON (ln.ID_TOPIC = t.ID_TOPIC AND ln.ID_MEMBER = {int:member})
			LEFT JOIN {db_prefix}log_topics AS lt ON (lt.id_topic = {int:topic} AND lt.id_member = {int:member})
			LEFT JOIN {db_prefix}log_mark_read AS lmr ON (lmr.id_board = t.ID_BOARD AND lmr.id_member = {int:member})') . '
		WHERE t.ID_TOPIC = {int:topic}
		LIMIT 1', array('topic' => $topic, 'member' => $user_info['id']));
    if ($mobdb->num_rows($request) == 0) {
        mob_error('topic not found or out of reach');
    }
    $topicinfo = $mobdb->fetch_assoc();
    $mobdb->free_result($request);
    if ($from_new) {
        // Get the start value
        $request = $mobdb->query('
			SELECT COUNT(*)
			FROM {db_prefix}messages
			WHERE id_msg < {int:msg}
			AND id_topic = {int:topic}', array('topic' => $topic, 'msg' => $topicinfo['new_from']));
        list($start) = $mobdb->fetch_row($request);
        $mobdb->free_result($request);
        $position = $start;
        $limit = $per_page;
    }
    // Emulate the permissions
    $topic = $topicinfo['id_topic'];
    $board = $topicinfo['id_board'];
    loadBoard();
    loadPermissions();
    // Up the views!
    if (empty($_SESSION['last_read_topic']) || $_SESSION['last_read_topic'] != $id_topic) {
        $mobdb->query('
		    UPDATE {db_prefix}topics
		    SET numViews = numViews + 1
		    WHERE ID_TOPIC = {int:topic}', array('topic' => $topic));
    }
    // If this user is not a guest, mark this topic as read
    if (!$user_info['is_guest']) {
        $mobdb->query('
		    REPLACE INTO {db_prefix}log_topics
		        (id_member, id_topic, id_msg)
		    VALUES
		        ({int:member}, {int:topic}, {int:msg})', array('member' => $user_info['id'], 'topic' => $topic, 'msg' => $modSettings['maxMsgID']));
    }
    // Set the last read topic
    $_SESSION['last_read_topic'] = $id_topic;
    // Fix the start
    $start = max(0, (int) $start - (int) $start % (int) $limit);
    // Load posts
    $posts = array();
    $id_posts = array();
    $id_members = array();
    $request = $mobdb->query('
		SELECT m.ID_MSG AS id_msg, m.subject, m.body, m.ID_MEMBER AS id_member, m.smileysEnabled AS smileys_enabled,
				m.posterName AS poster_name, m.posterTime AS poster_time, ID_MSG_MODIFIED < {int:new_from} AS is_read
		FROM {db_prefix}messages AS m
		WHERE m.ID_TOPIC = {int:topic}
		ORDER BY m.ID_MSG ASC
		LIMIT {int:start}, {int:limit}', array('topic' => $topic, 'start' => $start, 'limit' => $limit, 'new_from' => $topicinfo['new_from']));
    while ($row = $mobdb->fetch_assoc($request)) {
        $posts[] = $row;
        $id_posts[] = $row['id_msg'];
        $id_members[] = $row['id_member'];
    }
    $mobdb->free_result($request);
    // Load all the member data and context
    loadMemberData($id_members);
    // Load the attachments if we need to
    $attachments = array();
    if (!empty($modSettings['attachmentEnable']) && allowedTo('view_attachments')) {
        $request = $mobdb->query('
			SELECT a.ID_ATTACH as id_attach, a.filename, thumb.id_attach AS id_thumb, a.ID_MSG AS id_msg, a.width, a.height
			FROM {db_prefix}attachments AS a
				LEFT JOIN {db_prefix}attachments AS thumb ON (thumb.id_attach = a.id_thumb)
			WHERE a.ID_MSG IN ({array_int:msg})
				AND a.attachmentType = 0', array('msg' => $id_posts));
        while ($row = $mobdb->fetch_assoc($request)) {
            if (empty($attachments[$row['id_msg']])) {
                $attachments[$row['id_msg']] = array();
            }
            $attachments[$row['id_msg']][] = new xmlrpcval(array('content_type' => new xmlrpcval(!empty($row['width']) && !empty($row['height']) ? 'image' : 'other', 'string'), 'thumbnail_url' => new xmlrpcval(!empty($row['id_thumb']) ? $scripturl . '?action=dlattach;topic=' . $topic . '.0;attach=' . $row['id_thumb'] . ';image' : '', 'string'), 'url' => new xmlrpcval($scripturl . '?action=dlattach;topic=' . $topic . '.0;attach=' . $row['id_attach'], 'string')), 'struct');
        }
        $mobdb->free_result($request);
    }
    $topic_started = $topicinfo['id_member_started'] == $user_info['id'] && !$user_info['is_guest'];
    // Load the posts into a proper array
    foreach ($posts as $k => $post) {
        loadMemberContext($post['id_member']);
        $post_attachments = isset($attachments[$post['id_msg']]) ? $attachments[$post['id_msg']] : array();
        $member = !empty($memberContext[$post['id_member']]) ? $memberContext[$post['id_member']] : array();
        $posts[$k] = new xmlrpcval(array('post_id' => new xmlrpcval($post['id_msg'], 'string'), 'post_title' => new xmlrpcval(processSubject($post['subject']), 'base64'), 'post_content' => new xmlrpcval(processBody($post['body']), 'base64'), 'post_author_id' => new xmlrpcval(!empty($member) ? $member['id'] : 0, 'string'), 'post_author_name' => new xmlrpcval(processUsername(!empty($member) ? $member['name'] : $row['poster_name']), 'base64'), 'is_online' => new xmlrpcval(!empty($member) ? $user_profile[$post['id_member']]['isOnline'] : false, 'boolean'), 'can_edit' => new xmlrpcval((!$topicinfo['locked'] || allowedTo('moderate_board')) && (allowedTo('modify_any') || allowedTo('modify_replies') && $topic_started || allowedTo('modify_own') && $post['id_member'] == $user_info['id']), 'boolean'), 'icon_url' => new xmlrpcval($member['avatar']['href'], 'string'), 'post_time' => new xmlrpcval(mobiquo_time($post['poster_time']), 'dateTime.iso8601'), 'allow_smileys' => new xmlrpcval($post['smileys_enabled'], 'boolean'), 'attachments' => new xmlrpcval($post_attachments, 'array'), 'can_delete' => new xmlrpcval($post['id_msg'] != $topicinfo['id_first_msg'] && (allowedTo('delete_any') || allowedTo('delete_replies') && $topic_started || allowedTo('delete_own') && $user_info['id'] == $post['id_member']), 'boolean'), 'can_approve' => new xmlrpcval(false, 'boolean'), 'can_stick' => new xmlrpcval(allowedTo('make_sticky'), 'boolean'), 'can_move' => new xmlrpcval($topicinfo['id_first_msg'] != $post['id_msg'] && (allowedTo('move_any') || $topic_started && allowedTo('move_own')), 'boolean'), 'can_ban' => new xmlrpcval(allowedTo('manage_bans'), 'boolean')), 'struct');
    }
    // Return the topic
    return new xmlrpcresp(new xmlrpcval(array('total_post_num' => new xmlrpcval($topicinfo['replies'] + 1, 'int'), 'forum_id' => new xmlrpcval($topicinfo['id_board'], 'string'), 'forum_name' => new xmlrpcval(processSubject($topicinfo['name']), 'base64'), 'topic_id' => new xmlrpcval($topicinfo['id_topic'], 'string'), 'topic_title' => new xmlrpcval(processSubject($topicinfo['subject']), 'base64'), 'view_number' => new xmlrpcval($topicinfo['views'], 'int'), 'is_subscribed' => new xmlrpcval($topicinfo['is_notify'], 'boolean'), 'can_subscribe' => new xmlrpcval(allowedTo('mark_notify') && !$user_info['is_guest'], 'boolean'), 'is_closed' => new xmlrpcval($topicinfo['locked'], 'boolean'), 'can_reply' => new xmlrpcval(allowedTo('post_reply_any') || allowedTo('post_reply_own') && $topic_started, 'boolean'), 'can_delete' => new xmlrpcval(allowedTo('remove_any') || $topic_started && allowedTo('remove_own'), 'boolean'), 'can_close' => new xmlrpcval(allowedTo('lock_any') || $topic_started && allowedTo('lock_own'), 'boolean'), 'can_approve' => new xmlrpcval(false, 'boolean'), 'can_stick' => new xmlrpcval(allowedTo('make_sticky'), 'boolean'), 'can_move' => new xmlrpcval(allowedTo('move_any') || $topic_started && allowedTo('move_own'), 'boolean'), 'can_rename' => new xmlrpcval(allowedTo('modify_any') || $topic_started && allowedTo('modify_own'), 'boolean'), 'can_ban' => new xmlrpcval(allowedTo('manage_bans'), 'boolean'), 'position' => new xmlrpcval($position, 'int'), 'posts' => new xmlrpcval($posts, 'array')), 'struct'));
}
Example #5
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;
}