function qa_db_open_qs_selectspec($voteuserid, $start) { $pagesize = qa_opt_if_loaded('page_size_una_qs'); $where_clause_question_open = 'acount=0 AND closedbyid IS NULL'; $type = 'Q'; // question (not hidden) $selectspec = qa_db_posts_basic_selectspec($voteuserid, false); $selectspec['source'] .= " JOIN (SELECT postid FROM ^posts WHERE " . "type=\$ AND " . $where_clause_question_open . " ORDER BY ^posts.created DESC LIMIT #,#)" . " y ON ^posts.postid=y.postid"; array_push($selectspec['arguments'], $type, $start, $pagesize); $selectspec['sortdesc'] = 'created'; return $selectspec; }
public function process_request($request) { $requestparts = explode('/', qa_request()); $slugs = array_slice($requestparts, 1); $countslugs = count($slugs); $userid = qa_get_logged_in_userid(); $start = qa_get_start(); $count = qa_opt_if_loaded('page_size_activity'); $totalcount = qa_opt('cache_qcount'); $qspec = qa_db_posts_basic_selectspec($userid, false); qa_db_add_selectspec_opost($qspec, 'ra', false, false); qa_db_add_selectspec_ousers($qspec, 'rau', 'raup'); $qspec['source'] .= " JOIN (SELECT questionid, childid FROM ^homepage ORDER BY ^homepage.updated DESC) AS rcaq ON ^posts.postid=rcaq.questionid" . " LEFT JOIN ^posts AS ra ON childid=ra.postid" . (QA_FINAL_EXTERNAL_USERS ? "" : " LEFT JOIN ^users AS rau ON ra.userid=rau.userid") . " LEFT JOIN ^userpoints AS raup ON ra.userid=raup.userid LIMIT #,#"; array_push($qspec['columns'], 'childid'); array_push($qspec['arguments'], $start, $count); $qspec['sortdesc'] = 'otime'; $query = 'SELECT '; foreach ($qspec['columns'] as $columnas => $columnfrom) { $query .= $columnfrom . (is_int($columnas) ? '' : ' AS ' . $columnas) . ', '; } $query = qa_db_apply_sub(substr($query, 0, -2) . (strlen(@$qspec['source']) ? ' FROM ' . $qspec['source'] : ''), @$qspec['arguments']); $results = qa_db_read_all_assoc(qa_db_query_raw($query)); qa_db_post_select($results, $qspec); list($categories, $categoryid) = qa_db_select_with_pending(qa_db_category_nav_selectspec($slugs, false, false, true), $countslugs ? qa_db_slugs_to_category_id_selectspec($slugs) : null); $questions = qa_any_sort_and_dedupe($results); // $questions=qa_any_sort_and_dedupe(array_merge($recentquestions,$recentanswers)); $pagesize = qa_opt('page_size_home'); if ($countslugs) { if (!isset($categoryid)) { return include QA_INCLUDE_DIR . 'qa-page-not-found.php'; } $categorytitlehtml = qa_html($categories[$categoryid]['title']); $sometitle = qa_lang_html_sub('main/recent_qs_as_in_x', $categorytitlehtml); $nonetitle = qa_lang_html_sub('main/no_questions_in_x', $categorytitlehtml); } else { $sometitle = qa_lang_html('main/recent_qs_as_title'); $nonetitle = qa_lang_html('main/no_questions_found'); } require_once QA_INCLUDE_DIR . 'qa-app-q-list.php'; $qa_content = qa_q_list_page_content($questions, $pagesize, $start, $totalcount, $sometitle, $nonetitle, $categories, $categoryid, true, qa_opt('eql_homepage_url'), qa_opt('feed_for_qa') ? qa_opt('eql_homepage_url') : null, count($questions) < $pagesize ? qa_html_suggest_ask($categoryid) : qa_html_suggest_qs_tags(qa_using_tags(), qa_category_path_request($categories, $categoryid)), null, null); return $qa_content; }
function process_request($request) { require_once QA_INCLUDE_DIR . 'qa-db-selects.php'; require_once QA_INCLUDE_DIR . 'qa-app-format.php'; require_once QA_INCLUDE_DIR . 'qa-app-q-list.php'; $start = qa_get_start(); $userid = qa_get_logged_in_userid(); $categoryslugs = qa_request_parts(1); //$selectspec = qa_db_qs_selectspec($userid, 'created', $start, $categoryslugs, null, false, false, qa_opt_if_loaded('page_size_qs')); $selectspec = qa_db_posts_basic_selectspec($userid, false); $selectspec['source'] .= ' JOIN ^postmeta ON ^posts.postid=^postmeta.post_id AND ^postmeta.meta_key=$ AND ^postmeta.meta_value>0' . (is_array($this->expert_user) ? ' AND ^posts.categoryid IN (#)' : ' AND $'); //$selectspec['source'].=' JOIN (SELECT postid FROM ^posts WHERE type=$ ORDER BY ^posts.created DESC LIMIT #,#) y ON ^posts.postid=y.postid'; $selectspec['arguments'] = array_merge($selectspec['arguments'], array('is_expert_question', $this->expert_user)); $questions = qa_db_select_with_pending($selectspec); $nonetitle = qa_lang_html('main/no_questions_found'); global $qa_start; // Prepare and return content for theme $qa_content = qa_q_list_page_content($questions, qa_opt('page_size_qs'), $qa_start, count($questions), qa_opt('expert_question_page_title'), $nonetitle, null, null, false, null, null, null, null); return $qa_content; }
function qa_db_user_updates_selectspec($userid, $forfavorites = true, $forcontent = true) { require_once QA_INCLUDE_DIR . 'qa-app-updates.php'; $selectspec = qa_db_posts_basic_selectspec($userid); $nonesql = qa_db_argument_to_mysql(QA_ENTITY_NONE, true); $selectspec['columns']['obasetype'] = 'LEFT(updateposts.type, 1)'; $selectspec['columns']['oupdatetype'] = 'fullevents.updatetype'; $selectspec['columns']['ohidden'] = "INSTR(updateposts.type, '_HIDDEN')>0"; $selectspec['columns']['opostid'] = 'fullevents.lastpostid'; $selectspec['columns']['ouserid'] = 'fullevents.lastuserid'; $selectspec['columns']['otime'] = 'UNIX_TIMESTAMP(fullevents.updated)'; $selectspec['columns']['opersonal'] = 'fullevents.entitytype=' . $nonesql; $selectspec['columns']['oparentid'] = 'updateposts.parentid'; qa_db_add_selectspec_ousers($selectspec, 'eventusers', 'eventuserpoints'); if ($forfavorites) { // life is hard $selectspec['source'] .= ' JOIN ' . "(SELECT entitytype, questionid, lastpostid, updatetype, lastuserid, updated FROM ^userevents WHERE userid=\$" . ($forcontent ? '' : " AND entitytype!=" . $nonesql) . " UNION SELECT ^sharedevents.entitytype, questionid, lastpostid, updatetype, lastuserid, updated FROM ^sharedevents JOIN ^userfavorites ON ^sharedevents.entitytype=^userfavorites.entitytype AND ^sharedevents.entityid=^userfavorites.entityid AND ^userfavorites.nouserevents=1 WHERE userid=\$) fullevents ON ^posts.postid=fullevents.questionid"; array_push($selectspec['arguments'], $userid, $userid); } else { // life is easy $selectspec['source'] .= " JOIN ^userevents AS fullevents ON ^posts.postid=fullevents.questionid AND fullevents.userid=\$ AND fullevents.entitytype=" . $nonesql; $selectspec['arguments'][] = $userid; } $selectspec['source'] .= " JOIN ^posts AS updateposts ON updateposts.postid=fullevents.lastpostid" . " AND (updateposts.type IN ('Q', 'A', 'C') OR fullevents.entitytype=" . $nonesql . ")" . " AND (^posts.selchildid=fullevents.lastpostid OR NOT fullevents.updatetype<=>\$) AND ^posts.type IN ('Q', 'Q_HIDDEN')" . (QA_FINAL_EXTERNAL_USERS ? '' : ' LEFT JOIN ^users AS eventusers ON fullevents.lastuserid=eventusers.userid') . ' LEFT JOIN ^userpoints AS eventuserpoints ON fullevents.lastuserid=eventuserpoints.userid'; $selectspec['arguments'][] = QA_UPDATE_SELECTED; unset($selectspec['arraykey']); // allow same question to be retrieved multiple times $selectspec['sortdesc'] = 'otime'; return $selectspec; }
/** * Get Question List. * * @param array $args ($username, $password, $data['sort', 'start', 'cats', 'full', 'size', 'action', 'action_id', 'action_data']) * @return array (questions); * */ function call_get_questions($args) { // Parse the arguments, assuming they're in the correct order $username = qa_db_escape_string($args[0]); $password = qa_db_escape_string($args[1]); $data = @$args[2]; if (!$this->login($username, $password)) { return $this->error; } $userid = qa_get_logged_in_userid(); $output = array(); if (isset($data['action'])) { $action_message = $this->do_action($data); } $sort = @$data['sort']; $start = (int) @$data['start']; $size = (int) @$data['size']; $full = isset($data['full']); switch ($sort) { case 'updated': $qarray = $this->get_updated_qs($size); break; case 'favorites': $selectspec = qa_db_posts_basic_selectspec($userid, true); $selectspec['source'] .= " JOIN ^userfavorites AS uf ON ^posts.postid=uf.entityid WHERE uf.userid=\$ AND uf.entitytype=\$ AND ^posts.type='Q' LIMIT #"; array_push($selectspec['arguments'], $userid, QA_ENTITY_QUESTION, $size + 1); $selectspec['sortdesc'] = 'created'; $qarray = qa_db_select_with_pending($selectspec); break; default: $qarray = qa_db_select_with_pending(qa_db_qs_selectspec($userid, $sort, $start, null, null, false, $full, $size + 1)); break; } $more = false; if (count($qarray) > $size && $sort != 'updated') { $more = true; array_pop($qarray); } $questions = array(); if (isset($data['more']) && $start > 0) { $questions[] = "<less>"; } foreach ($qarray as $question) { if (isset($data['action_id']) && isset($data['postid']) && $question['postid'] == $data['postid']) { $output['acted'] = count($questions); } $question = $this->get_single_question($data, $question); if ($question) { $questions[] = $question; } } // add extra list item for loading more if ($more && isset($data['more'])) { $questions[] = "<more>"; } if (empty($questions)) { $output['message'] = qa_lang('xmlrpc/no_items_found'); } else { if (isset($data['action'])) { $output['message'] = $action_message; } else { $output['message'] = qa_lang_sub('xmlrpc/x_items_found', count($questions)); } } if (isset($data['meta'])) { $output['meta'] = $this->get_meta_data(); } $output['confirmation'] = true; $output['data'] = $questions; return $output; }
function qa_db_user_recent_c_qs_selectspec($voteuserid, $identifier, $count = QA_DB_RETRIEVE_QS_AS) { $selectspec = qa_db_posts_basic_selectspec($voteuserid); $selectspec['arraykey'] = 'opostid'; $selectspec['columns']['obasetype'] = "'C'"; $selectspec['columns']['opostid'] = 'cposts.postid'; $selectspec['columns']['otime'] = 'UNIX_TIMESTAMP(cposts.created)'; $selectspec['source'] .= " JOIN ^posts AS parentposts ON" . " ^posts.postid=(CASE parentposts.type WHEN 'A' THEN parentposts.parentid ELSE parentposts.postid END)" . " JOIN ^posts AS cposts ON parentposts.postid=cposts.parentid" . " JOIN (SELECT postid FROM ^posts WHERE " . " userid=" . (QA_FINAL_EXTERNAL_USERS ? "\$" : "(SELECT userid FROM ^users WHERE handle=\$ LIMIT 1)") . " AND type='C' ORDER BY created DESC LIMIT #) y ON cposts.postid=y.postid WHERE (^posts.type!='Q_HIDDEN') AND (parentposts.type!='A_HIDDEN')"; array_push($selectspec['arguments'], $identifier, $count); $selectspec['sortdesc'] = 'otime'; return $selectspec; }