public function process_search($query, $start, $count, $userid, $absoluteurls, $fullcontent)
 {
     require_once QA_INCLUDE_DIR . 'db/selects.php';
     require_once QA_INCLUDE_DIR . 'util/string.php';
     $words = qa_string_to_words($query);
     $questions = qa_db_select_with_pending(qa_db_search_posts_selectspec($userid, $words, $words, $words, $words, trim($query), $start, $fullcontent, $count));
     $results = array();
     foreach ($questions as $question) {
         qa_search_set_max_match($question, $type, $postid);
         // to link straight to best part
         $results[] = array('question' => $question, 'match_type' => $type, 'match_postid' => $postid);
     }
     return $results;
 }
Exemple #2
0
 function cs_ajax_get_question_suggestion()
 {
     $query = strip_tags($_REQUEST['start_with']);
     $relatedquestions = qa_db_select_with_pending(qa_db_search_posts_selectspec(null, qa_string_to_words($query), null, null, null, null, 0, false, 10));
     //print_r($relatedquestions);
     if (isset($relatedquestions) && !empty($relatedquestions)) {
         $data = array();
         foreach ($relatedquestions as $k => $q) {
             $data[$k]['title'] = $q['title'];
             $data[$k]['blob'] = cs_get_avatar($q['handle'], 30, false);
             $data[$k]['url'] = qa_q_path_html($q['postid'], $q['title']);
             $data[$k]['tags'] = $q['tags'];
             $data[$k]['answers'] = $q['acount'];
         }
         echo json_encode($data);
     }
     die;
 }
Exemple #3
0
	This program is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details.

	More about this license: http://www.question2answer.org/license.php
*/
require_once QA_INCLUDE_DIR . 'qa-db-selects.php';
require_once QA_INCLUDE_DIR . 'qa-util-string.php';
//	Collect the information we need from the database
$intitle = qa_post_text('title');
$doaskcheck = qa_opt('do_ask_check_qs');
$doexampletags = qa_using_tags() && qa_opt('do_example_tags');
if ($doaskcheck || $doexampletags) {
    $countqs = max($doexampletags ? QA_DB_RETRIEVE_ASK_TAG_QS : 0, $doaskcheck ? qa_opt('page_size_ask_check_qs') : 0);
    $relatedquestions = qa_db_select_with_pending(qa_db_search_posts_selectspec(null, qa_string_to_words($intitle), null, null, null, null, 0, false, $countqs));
}
//	Collect example tags if appropriate
if ($doexampletags) {
    require_once QA_INCLUDE_DIR . 'qa-app-format.php';
    $tagweight = array();
    foreach ($relatedquestions as $question) {
        $tags = qa_tagstring_to_tags($question['tags']);
        foreach ($tags as $tag) {
            @($tagweight[$tag] += exp($question['score']));
        }
    }
    arsort($tagweight, SORT_NUMERIC);
    $exampletags = array();
    $minweight = exp(qa_match_to_min_score(qa_opt('match_example_tags')));
    $maxcount = qa_opt('page_size_ask_tags');
    function cs_relative_post_list($limit, $slug, $type, $return = false, $avatar_size)
    {
        require_once QA_INCLUDE_DIR . 'qa-app-posts.php';
        if (!empty($slug)) {
            if ($type == 'Category') {
                $post_type = 'Q';
                $categories = explode("/", $slug);
                if (count($categories)) {
                    $category_bread_crup = implode(" > ", $categories);
                    $category_link = implode("/", $categories);
                    $categories = array_reverse($categories);
                    $slug = implode("/", $categories);
                }
                $posts = qa_db_read_all_assoc(qa_db_query_sub('SELECT * FROM ^posts WHERE ^posts.type=$
							AND categoryid=(SELECT categoryid FROM ^categories WHERE ^categories.backpath=$ LIMIT 1) 
							ORDER BY ^posts.created DESC LIMIT #', 'Q', $slug, $limit));
                //refresh every 15 minutes
                $title = 'Questions in <a href="' . qa_path_html('questions/' . qa_strtolower($category_link)) . '">' . $category_bread_crup . '</a>';
            } elseif ($type == 'Tags') {
                $post_type = 'Q';
                $title = 'Questions in <a href="' . qa_path_html('tag/' . qa_strtolower($slug)) . '">' . $slug . '</a>';
                $posts = qa_db_read_all_assoc(qa_db_query_sub('SELECT * FROM ^posts WHERE ^posts.type=$
						AND ^posts.postid IN (SELECT postid FROM ^posttags WHERE 
							wordid=(SELECT wordid FROM ^words WHERE word=$ OR word=$ COLLATE utf8_bin LIMIT 1) ORDER BY postcreated DESC)
						ORDER BY ^posts.created DESC LIMIT #', 'Q', $slug, qa_strtolower($slug), $limit));
            } else {
                // Relative to Keyword
                require_once QA_INCLUDE_DIR . 'qa-app-search.php';
                $keyword = $slug;
                $userid = qa_get_logged_in_userid();
                $title = 'Posts About <a href="' . qa_path_html('search/' . qa_strtolower($keyword)) . '">' . $keyword . '</a>';
                //$post=qa_get_search_results($keyword, 0, $limit, $userid , false, false);
                $words = qa_string_to_words($keyword);
                $posts = qa_db_select_with_pending(qa_db_search_posts_selectspec($userid, $words, $words, $words, $words, trim($keyword), 0, false, $limit));
                $output = '<h3 class="widget-title">' . $title . '</h3>';
                $output .= '<ul class="question-list">';
                foreach ($posts as $post) {
                    $post_type = $post['type'];
                    if ($post_type == 'Q') {
                        $what = qa_lang('cleanstrap/asked');
                    } elseif ($post_type == 'A') {
                        $what = qa_lang('cleanstrap/answered');
                    } elseif ('C') {
                        $what = qa_lang('cleanstrap/commented');
                    }
                    $handle = qa_post_userid_to_handle($post['userid']);
                    $avatar = cs_get_post_avatar($post, $avatar_size);
                    $output .= '<li id="q-list-' . $post['postid'] . '" class="question-item">';
                    $output .= '<div class="pull-left avatar" data-handle="' . $handle . '" data-id="' . $post['userid'] . '">' . $avatar . '</div>';
                    $output .= '<div class="list-right">';
                    if ($post_type == 'Q') {
                        $output .= '<a class="title" href="' . qa_q_path_html($post['postid'], $post['title']) . '" title="' . $post['title'] . '">' . cs_truncate(strip_tags($post['title']), 70) . '</a>';
                    } elseif ($post_type == 'A') {
                        $output .= '<p><a href="' . cs_post_link($post['parentid']) . '#a' . $post['postid'] . '">' . cs_truncate(strip_tags($post['content']), 70) . '</a></p>';
                    } else {
                        $output .= '<p><a href="' . cs_post_link($post['parentid']) . '#c' . $post['postid'] . '">' . cs_truncate(strip_tags($post['content']), 70) . '</a></p>';
                    }
                    $output .= '<div class="meta"><a href="' . qa_path_html('user/' . $handle) . '">' . cs_name($handle) . '</a> ' . $what;
                    if ($post_type == 'Q') {
                        $output .= ' <span class="vote-count">' . $post['netvotes'] . ' votes</span>';
                        $output .= ' <span class="ans-count">' . $post['acount'] . ' ans</span>';
                    } elseif ($post_type == 'A') {
                        $output .= ' <span class="vote-count">' . $post['netvotes'] . ' votes</span>';
                    }
                    $output .= '</div></div>';
                    $output .= '</li>';
                }
                $output .= '</ul>';
                if ($return) {
                    return $output;
                }
                echo $output;
                return;
            }
        } else {
            return;
        }
        $output = '<h3 class="widget-title">' . $title . '</h3>';
        $output .= '<ul class="question-list">';
        foreach ($posts as $p) {
            if (empty($p['userid'])) {
                $p['userid'] = NULL;
            }
            // to prevent error for anonymous posts while calling qa_post_userid_to_handle()
            if ($post_type == 'Q') {
                $what = qa_lang_html('cleanstrap/asked');
            } elseif ($post_type == 'A') {
                $what = qa_lang_html('cleanstrap/answered');
            } elseif ('C') {
                $what = qa_lang_html('cleanstrap/commented');
            }
            $handle = qa_post_userid_to_handle($p['userid']);
            $avatar = cs_get_avatar($handle, 35, false);
            $output .= '<li id="q-list-' . $p['postid'] . '" class="question-item">';
            $output .= '<div class="pull-left avatar" data-handle="' . $handle . '" data-id="' . qa_handle_to_userid($handle) . '">' . (isset($avatar) ? '<img src="' . $avatar . '" />' : '') . '</div>';
            $output .= '<div class="list-right">';
            if ($post_type == 'Q') {
                $output .= '<a class="title" href="' . qa_q_path_html($p['postid'], $p['title']) . '" title="' . $p['title'] . '">' . cs_truncate(qa_html($p['title']), 70) . '</a>';
            } elseif ($post_type == 'A') {
                $output .= '<p><a href="' . cs_post_link($p['parentid']) . '#a' . $p['postid'] . '">' . cs_truncate(strip_tags($p['content']), 70) . '</a></p>';
            } else {
                $output .= '<p><a href="' . cs_post_link($p['parentid']) . '#c' . $p['postid'] . '">' . cs_truncate(strip_tags($p['content']), 70) . '</a></p>';
            }
            $output .= '<div class="meta"><a href="' . qa_path_html('user/' . $handle) . '">' . cs_name($handle) . '</a> ' . $what;
            if ($post_type == 'Q') {
                $output .= ' <span class="vote-count">' . $p['netvotes'] . ' votes</span>';
                $output .= ' <span class="ans-count">' . $p['acount'] . ' ans</span>';
            } elseif ($post_type == 'A') {
                $output .= ' <span class="vote-count">' . $p['netvotes'] . ' votes</span>';
            }
            $output .= '</div></div>';
            $output .= '</li>';
        }
        $output .= '</ul>';
        if ($return) {
            return $output;
        }
        echo $output;
    }
    // don't allow this page to be requested directly from browser
    header('Location: ../');
    exit;
}
// report that we entered this page
qa_report_event('page_enter', qa_get_logged_in_userid(), qa_get_logged_in_handle(), qa_cookie_get(), array('params' => $_SERVER['QUERY_STRING'], 'path' => $_SERVER['SCRIPT_NAME']));
require_once QA_INCLUDE_DIR . 'qa-app-format.php';
//	Perform the search if appropriate
if (strlen(qa_get('q'))) {
    require_once QA_INCLUDE_DIR . 'qa-db-selects.php';
    require_once QA_INCLUDE_DIR . 'qa-util-string.php';
    $inquery = trim(qa_get('q'));
    $words = qa_string_to_words($inquery);
    $retrieve = 2 * QA_DB_RETRIEVE_QS_AS + 1;
    // get enough results to be able to give some idea of how many pages of search results there are
    $questions = qa_db_select_with_pending(qa_db_search_posts_selectspec($qa_login_userid, $words, $words, $words, $words, $inquery, $qa_start, false, $retrieve));
    $pagesize = qa_opt('page_size_search');
    $gotcount = count($questions);
    $questions = array_slice($questions, 0, $pagesize);
    $usershtml = qa_userids_handles_html($questions);
    qa_report_event('search', $qa_login_userid, qa_get_logged_in_handle(), $qa_cookieid, array('query' => $inquery, 'start' => $qa_start));
}
//	Prepare content for theme
$qa_content = qa_content_prepare(true);
if (strlen(qa_get('q'))) {
    $qa_content['search']['value'] = qa_html($inquery);
}
if (isset($questions)) {
    if (count($questions)) {
        $qa_content['title'] = qa_lang_html_sub('main/results_for_x', qa_html($inquery));
    } else {
Exemple #6
0
        qa_feed_load_ifcategory('main/recent_qs_as_title', 'main/recent_qs_as_in_x', qa_db_qs_selectspec(null, 'created', 0, $categoryslugs, null, false, $full, $count), qa_db_recent_a_qs_selectspec(null, 0, $categoryslugs, null, false, $full, $count));
        break;
    case 'activity':
        qa_feed_load_ifcategory('main/recent_activity_title', 'main/recent_activity_in_x', qa_db_qs_selectspec(null, 'created', 0, $categoryslugs, null, false, $full, $count), qa_db_recent_a_qs_selectspec(null, 0, $categoryslugs, null, false, $full, $count), qa_db_recent_c_qs_selectspec(null, 0, $categoryslugs, null, false, $full, $count), qa_db_recent_edit_qs_selectspec(null, 0, $categoryslugs, null, true, $full, $count));
        break;
    case 'tag':
        $tag = $feedparams[0];
        qa_feed_load_ifcategory(null, null, qa_db_tag_recent_qs_selectspec(null, $tag, 0, $full, $count));
        $title = qa_lang_sub('main/questions_tagged_x', $tag);
        $linkrequest = 'tag/' . $tag;
        break;
    case 'search':
        require_once QA_INCLUDE_DIR . 'qa-util-string.php';
        $query = $feedparams[0];
        $words = qa_string_to_words($query);
        qa_feed_load_ifcategory(null, null, qa_db_search_posts_selectspec(null, $words, $words, $words, $words, trim($query), 0, $full, $count));
        $title = qa_lang_sub('main/results_for_x', $query);
        $linkrequest = 'search';
        $linkparams = array('q' => $query);
        break;
}
//	Remove duplicate questions (perhaps referenced in an answer and a comment) and cut down to size
require_once QA_INCLUDE_DIR . 'qa-app-format.php';
require_once QA_INCLUDE_DIR . 'qa-util-string.php';
if ($feedtype != 'search' && $feedtype != 'hot') {
    // leave search results and hot questions sorted by relevance
    $questions = qa_any_sort_and_dedupe($questions);
}
$questions = array_slice($questions, 0, $count);
$blockwordspreg = qa_get_block_words_preg();
//	Disconnect as quickly as possible to free up resources