예제 #1
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'));
}
예제 #2
0
function method_search_topic($subject_only = 1)
{
    global $mobdb, $context, $sourcedir, $user_info, $modSettings, $scripturl, $modSettings, $messages_request;
    // Search string
    $string = base64_decode($context['mob_request']['params'][0][0]);
    if (empty($string)) {
        createErrorResponse(8);
    }
    // Start/limit
    if (isset($context['mob_request']['params'][0])) {
        $start_num = (int) $context['mob_request']['params'][1][0];
    }
    if (isset($context['mob_request']['params'][1])) {
        $limit = (int) ($context['mob_request']['params'][2][0] - $start_num + 1);
    }
    // We got an ID?
    if (isset($context['mob_request']['params'][3])) {
        $id_search = $context['mob_request']['params'][3][0];
    }
    // 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'])) {
        createErrorResponse(8);
    }
    $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']()) {
        $topics[$topic['id']] = array('board' => $topic['board']['id'], 'board_name' => $topic['board']['name'], 'id' => $topic['id'], 'poster' => array('id' => $topic['matches'][0]['member']['id'], 'post_name' => $topic['matches'][0]['member']['name'], 'username' => $topic['matches'][0]['member']['username'], 'avatar' => $topic['matches'][0]['member']['avatar']['href']), 'post_time' => mobiquo_time($topic['first_post']['timestamp']), 'views' => $topic['views'], 'replies' => $topic['replies'], 'title' => processSubject($topic['first_post']['subject']), 'short_msg' => processShortContent($topic['matches'][0]['body']), 'is_marked_notify' => false, 'is_locked' => !empty($topic['is_locked']), 'post_id' => $topic['matches'][0]['id'], 'post_title' => processSubject($topic['matches'][0]['subject']));
        $tids[] = $topic['id'];
    }
    if (!empty($tids)) {
        // Check for notifications on this topic OR board.
        $mobdb->query("\n            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_marked_notify'] = true;
            }
        }
        $mobdb->free_result();
    }
    // Output the results
    outputRPCSubscribedTopics($topics, $count, $search_id);
}