本文整理汇总了PHP中qa_sort_by函数的典型用法代码示例。如果您正苦于以下问题:PHP qa_sort_by函数的具体用法?PHP qa_sort_by怎么用?PHP qa_sort_by使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了qa_sort_by函数的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: array
$qa_content['form_message'] = array('tags' => 'method="post" action="' . qa_self_html() . '"', 'style' => 'tall', 'fields' => array('message' => array('type' => $messagesent ? 'static' : '', 'label' => qa_lang_html_sub('misc/message_for_x', qa_get_one_user_html($handle, false)), 'tags' => 'name="message" id="message"', 'value' => qa_html(@$inmessage, $messagesent), 'rows' => 8, 'note' => qa_lang_html_sub('misc/message_explanation', qa_html(qa_opt('site_title'))), 'error' => qa_html(@$errors['message']))), 'buttons' => array('send' => array('tags' => 'onclick="qa_show_waiting_after(this, false);"', 'label' => qa_lang_html('main/send_button'))), 'hidden' => array('domessage' => '1', 'code' => qa_get_form_security_code('message-' . $handle)));
$qa_content['focusid'] = 'message';
if ($messagesent) {
$qa_content['form_message']['ok'] = qa_lang_html('misc/message_sent');
unset($qa_content['form_message']['buttons']);
if (qa_opt('show_message_history')) {
unset($qa_content['form_message']['fields']['message']);
} else {
unset($qa_content['form_message']['fields']['message']['note']);
unset($qa_content['form_message']['fields']['message']['label']);
}
}
// If relevant, show recent message history
if (qa_opt('show_message_history')) {
$recent = array_merge($torecent, $fromrecent);
qa_sort_by($recent, 'created');
$showmessages = array_slice(array_reverse($recent, true), 0, QA_DB_RETRIEVE_MESSAGES);
if (count($showmessages)) {
$qa_content['message_list'] = array('title' => qa_lang_html_sub('misc/message_recent_history', qa_html($toaccount['handle'])));
$options = qa_message_html_defaults();
foreach ($showmessages as $message) {
$qa_content['message_list']['messages'][] = qa_message_html_fields($message, $options);
}
}
}
$qa_content['raw']['account'] = $toaccount;
// for plugin layers to access
return $qa_content;
/*
Omit PHP closing tag to help avoid accidental output
*/
示例2: qa_recalc_perform_step
//.........这里部分代码省略.........
foreach ($achildposts as $postid => $post) {
$posts[$postid] = $post;
}
// Creation and editing of each post
foreach ($posts as $postid => $post) {
$followonq = $post['basetype'] == 'Q' && $postid != $questionid;
if ($followonq) {
$updatetype = QA_UPDATE_FOLLOWS;
} elseif ($post['basetype'] == 'C' && @$posts[$post['parentid']]['basetype'] == 'Q') {
$updatetype = QA_UPDATE_C_FOR_Q;
} elseif ($post['basetype'] == 'C' && @$posts[$post['parentid']]['basetype'] == 'A') {
$updatetype = QA_UPDATE_C_FOR_A;
} else {
$updatetype = null;
}
qa_create_event_for_q_user($questionid, $postid, $updatetype, $post['userid'], @$posts[$post['parentid']]['userid'], $post['created']);
if (isset($post['updated']) && !$followonq) {
qa_create_event_for_q_user($questionid, $postid, $post['updatetype'], $post['lastuserid'], $post['userid'], $post['updated']);
}
}
// Tags and categories of question
qa_create_event_for_tags($question['tags'], $questionid, null, $question['userid'], $question['created']);
qa_create_event_for_category($question['categoryid'], $questionid, null, $question['userid'], $question['created']);
// Collect comment threads
$parentidcomments = array();
foreach ($posts as $postid => $post) {
if ($post['basetype'] == 'C') {
$parentidcomments[$post['parentid']][$postid] = $post;
}
}
// For each comment thread, notify all previous comment authors of each comment in the thread (could get slow)
foreach ($parentidcomments as $parentid => $comments) {
$keyuserids = array();
qa_sort_by($comments, 'created');
foreach ($comments as $comment) {
foreach ($keyuserids as $keyuserid => $dummy) {
if ($keyuserid != $comment['userid'] && $keyuserid != @$posts[$parentid]['userid']) {
qa_db_event_create_not_entity($keyuserid, $questionid, $comment['postid'], QA_UPDATE_FOLLOWS, $comment['userid'], $comment['created']);
}
}
if (isset($comment['userid'])) {
$keyuserids[$comment['userid']] = true;
}
}
}
}
$next = 1 + $lastquestionid;
$done += count($questionids);
$continue = true;
} else {
qa_recalc_transition($state, 'dorefillevents_complete');
}
break;
case 'dorecalccategories':
qa_recalc_transition($state, 'dorecalccategories_postcount');
break;
case 'dorecalccategories_postcount':
qa_db_acount_update();
qa_db_ccount_update();
qa_recalc_transition($state, 'dorecalccategories_postupdate');
break;
case 'dorecalccategories_postupdate':
$postids = qa_db_posts_get_for_recategorizing($next, 100);
if (count($postids)) {
$lastpostid = max($postids);
qa_db_posts_recalc_categoryid($next, $lastpostid);
示例3: get_post_voters_flaggers
function get_post_voters_flaggers($post, $postid)
{
require_once QA_INCLUDE_DIR . 'qa-util-sort.php';
if (!isset($this->qa_voters_flaggers_cache[$postid])) {
$this->queue_post_voters_flaggers($post);
$this->retrieve_queued_voters_flaggers();
}
$votersflaggers = @$this->qa_voters_flaggers_cache[$postid];
if (isset($votersflaggers)) {
qa_sort_by($votersflaggers, 'handle');
}
return $votersflaggers;
}
示例4: qa_any_sort_and_dedupe
function qa_any_sort_and_dedupe($questions)
{
if (qa_to_override(__FUNCTION__)) {
$args = func_get_args();
return qa_call_override(__FUNCTION__, $args);
}
require_once QA_INCLUDE_DIR . 'util/sort.php';
foreach ($questions as $key => $question) {
// collect information about action referenced by each $question
if (isset($question['opostid'])) {
$questions[$key]['_time'] = $question['otime'];
$questions[$key]['_type'] = $question['obasetype'];
$questions[$key]['_userid'] = @$question['ouserid'];
} else {
$questions[$key]['_time'] = $question['created'];
$questions[$key]['_type'] = 'Q';
$questions[$key]['_userid'] = $question['userid'];
}
$questions[$key]['sort'] = -$questions[$key]['_time'];
}
qa_sort_by($questions, 'sort');
$keepquestions = array();
// now remove duplicate references to same question
foreach ($questions as $question) {
// going in order from most recent to oldest
$laterquestion = @$keepquestions[$question['postid']];
if (isset($laterquestion)) {
// the two events were within 5 minutes of each other
$close_events = abs($laterquestion['_time'] - $question['_time']) < 300;
$later_edit = @$laterquestion['oupdatetype'] && !@$question['oupdatetype'] && $laterquestion['_type'] == $question['_type'] && $laterquestion['_userid'] == $question['_userid'];
// the same user made the later edit
// this question (in an update list) is personal to the user, but the other one was not
$this_personal = @$question['opersonal'] && !@$laterquestion['opersonal'];
if ($close_events && ($later_edit || $this_personal)) {
// Remove any previous instance of the post to force a new position
unset($keepquestions[$question['postid']]);
$keepquestions[$question['postid']] = $question;
}
} else {
// keep this reference if there is no more recent one
$keepquestions[$question['postid']] = $question;
}
}
return $keepquestions;
}
示例5: qa_page_q_edit_c_form
$qa_content['q_view']['c_form'] = qa_page_q_edit_c_form($qa_content, 'c' . $formpostid, $commentsfollows[$formpostid], @$ceditin[$formpostid], @$cediterrors[$formpostid]);
$jumptoanchor = 'c' . $formpostid;
$commentsall = $questionid;
}
$qa_content['q_view']['c_list'] = qa_page_q_comment_follow_list($question, $question, $commentsfollows, $commentsall == $questionid, $usershtml, $formrequested, $formpostid);
// ...for viewing
// Prepare content for existing answers (could be added to by Ajax)
$qa_content['a_list'] = array('tags' => 'id="a_list"', 'as' => array());
// sort according to the site preferences
if (qa_opt('sort_answers_by') == 'votes') {
foreach ($answers as $answerid => $answer) {
$answers[$answerid]['sortvotes'] = $answer['downvotes'] - $answer['upvotes'];
}
qa_sort_by($answers, 'sortvotes', 'created');
} else {
qa_sort_by($answers, 'created');
}
// further changes to ordering to deal with queued, hidden and selected answers
$countfortitle = $question['acount'];
$nextposition = 10000;
$answerposition = array();
foreach ($answers as $answerid => $answer) {
if ($answer['viewable']) {
$position = $nextposition++;
if ($answer['hidden']) {
$position += 10000;
} elseif ($answer['queued']) {
$position -= 10000;
$countfortitle++;
// include these in displayed count
} elseif ($answer['isselected'] && qa_opt('show_selected_first')) {
示例6: qa_db_post_select
/**
* Post-process $outresult according to $selectspec, applying 'sortasc', 'sortdesc', 'arrayvalue' and 'single'.
*/
function qa_db_post_select(&$outresult, $selectspec)
{
// PHP's sorting algorithm is not 'stable', so we use '_order_' element to keep stability.
// By contrast, MySQL's ORDER BY does seem to give the results in a reliable order.
if (isset($selectspec['sortasc'])) {
require_once QA_INCLUDE_DIR . 'util/sort.php';
$index = 0;
foreach ($outresult as $key => $value) {
$outresult[$key]['_order_'] = $index++;
}
qa_sort_by($outresult, $selectspec['sortasc'], '_order_');
} elseif (isset($selectspec['sortdesc'])) {
require_once QA_INCLUDE_DIR . 'util/sort.php';
if (isset($selectspec['sortdesc_2'])) {
qa_sort_by($outresult, $selectspec['sortdesc'], $selectspec['sortdesc_2']);
} else {
$index = count($outresult);
foreach ($outresult as $key => $value) {
$outresult[$key]['_order_'] = $index--;
}
qa_sort_by($outresult, $selectspec['sortdesc'], '_order_');
}
$outresult = array_reverse($outresult, true);
}
if (isset($selectspec['arrayvalue'])) {
foreach ($outresult as $key => $value) {
$outresult[$key] = $value[$selectspec['arrayvalue']];
}
}
if (@$selectspec['single']) {
$outresult = count($outresult) ? reset($outresult) : null;
}
}
示例7: qa_page_q_edit_c_form
$a_view['c_form'] = qa_page_q_edit_c_form($formpostid, $answerid);
}
}
// Determine this answer's place in the order on the page
if ($answer['hidden']) {
$a_view['priority'] = 10000 + $priority++;
} elseif ($answer['isselected'] && qa_opt('show_selected_first')) {
$a_view['priority'] = 0;
} else {
$a_view['priority'] = 5000 + $priority++;
}
// Add the answer to the list
$qa_content['a_list']['as'][] = $a_view;
}
}
qa_sort_by($qa_content['a_list']['as'], 'priority');
$countanswers = $question['acount'];
if ($countanswers == 1) {
$qa_content['a_list']['title'] = qa_lang_html('question/1_answer_title');
} else {
$qa_content['a_list']['title'] = qa_lang_html_sub('question/x_answers_title', $countanswers);
}
// Prepare content for form to add an answer
if ($formtype == 'a_add') {
// Form for adding answers
$answerform = null;
switch (qa_user_permit_error('permit_post_a')) {
case 'login':
$answerform = array('style' => 'tall', 'title' => qa_insert_login_links(qa_lang_html('question/answer_must_login'), $qa_request));
break;
case 'confirm':
示例8: qa_any_sort_and_dedupe
function qa_any_sort_and_dedupe($questions)
{
if (qa_to_override(__FUNCTION__)) {
$args = func_get_args();
return qa_call_override(__FUNCTION__, $args);
}
require_once QA_INCLUDE_DIR . 'qa-util-sort.php';
foreach ($questions as $key => $question) {
// collect information about action referenced by each $question
if (isset($question['opostid'])) {
$questions[$key]['_time'] = $question['otime'];
$questions[$key]['_type'] = $question['obasetype'];
$questions[$key]['_userid'] = @$question['ouserid'];
} else {
$questions[$key]['_time'] = $question['created'];
$questions[$key]['_type'] = 'Q';
$questions[$key]['_userid'] = $question['userid'];
}
$questions[$key]['sort'] = -$questions[$key]['_time'];
}
qa_sort_by($questions, 'sort');
$keepquestions = array();
// now remove duplicate references to same question
foreach ($questions as $question) {
// going in order from most recent to oldest
$laterquestion = @$keepquestions[$question['postid']];
if (!isset($laterquestion) || @$laterquestion['oupdatetype'] && !@$question['oupdatetype'] && $laterquestion['_type'] == $question['_type'] && $laterquestion['_userid'] == $question['_userid'] && abs($laterquestion['_time'] - $question['_time']) < 300 || @$question['opersonal'] && !@$laterquestion['opersonal'] && abs($laterquestion['_time'] - $question['_time']) < 300) {
$keepquestions[$question['postid']] = $question;
}
}
return $keepquestions;
}
示例9: qa_user_use_captcha
require_once QA_INCLUDE_DIR . 'pages/question-view.php';
require_once QA_INCLUDE_DIR . 'pages/question-submit.php';
require_once QA_INCLUDE_DIR . 'util/sort.php';
// Try to create the new comment
$usecaptcha = qa_user_use_captcha(qa_user_level_for_post($question));
$commentid = qa_page_q_add_c_submit($question, $parent, $children, $usecaptcha, $in, $errors);
// If successful, page content will be updated via Ajax
if (isset($commentid)) {
$children = qa_db_select_with_pending(qa_db_full_child_posts_selectspec($userid, $parentid));
$parent = $parent + qa_page_q_post_rules($parent, $questionid == $parentid ? null : $question, null, $children);
// in theory we should retrieve the parent's siblings for the above, but they're not going to be relevant
foreach ($children as $key => $child) {
$children[$key] = $child + qa_page_q_post_rules($child, $parent, $children, null);
}
$usershtml = qa_userids_handles_html($children, true);
qa_sort_by($children, 'created');
$c_list = qa_page_q_comment_follow_list($question, $parent, $children, true, $usershtml, false, null);
$themeclass = qa_load_theme_class(qa_get_site_theme(), 'ajax-comments', null, null);
echo "QA_AJAX_RESPONSE\n1\n";
// Send back the ID of the new comment
echo qa_anchor('C', $commentid) . "\n";
// Send back the HTML
$themeclass->c_list_items($c_list['cs']);
return;
}
}
echo "QA_AJAX_RESPONSE\n0\n";
// fall back to non-Ajax submission if there were any problems
/*
Omit PHP closing tag to help avoid accidental output
*/
示例10: Q2A_Util_Metadata
$showpluginforms = true;
}
if (!empty($pluginfiles)) {
$metadataUtil = new Q2A_Util_Metadata();
$sortedPluginFiles = array();
foreach ($pluginfiles as $pluginFile) {
$metadata = $metadataUtil->fetchFromAddonPath(dirname($pluginFile));
if (empty($metadata)) {
// limit plugin parsing to first 8kB
$contents = file_get_contents($pluginFile, false, null, -1, 8192);
$metadata = qa_addon_metadata($contents, 'Plugin');
}
$metadata['name'] = isset($metadata['name']) && !empty($metadata['name']) ? qa_html($metadata['name']) : qa_lang_html('admin/unnamed_plugin');
$sortedPluginFiles[$pluginFile] = $metadata;
}
qa_sort_by($sortedPluginFiles, 'name');
$pluginIndex = -1;
foreach ($sortedPluginFiles as $pluginFile => $metadata) {
$pluginIndex++;
$plugindirectory = dirname($pluginFile);
$hash = qa_admin_plugin_directory_hash($plugindirectory);
$showthisform = $showpluginforms && qa_get('show') == $hash;
$namehtml = $metadata['name'];
if (isset($metadata['uri']) && strlen($metadata['uri'])) {
$namehtml = '<a href="' . qa_html($metadata['uri']) . '">' . $namehtml . '</a>';
}
$namehtml = '<b>' . $namehtml . '</b>';
$metaver = isset($metadata['version']) && strlen($metadata['version']);
if ($metaver) {
$namehtml .= ' v' . qa_html($metadata['version']);
}
示例11: qa_recalc_perform_step
//.........这里部分代码省略.........
$lastquestionid = max($questionids);
foreach ($questionids as $questionid) {
// Retrieve all posts relating to this question
list($question, $childposts, $achildposts) = qa_db_select_with_pending(qa_db_full_post_selectspec(null, $questionid), qa_db_full_child_posts_selectspec(null, $questionid), qa_db_full_a_child_posts_selectspec(null, $questionid));
// Merge all posts while preserving keys as postids
$posts = array($questionid => $question);
foreach ($childposts as $postid => $post) {
$posts[$postid] = $post;
}
foreach ($achildposts as $postid => $post) {
$posts[$postid] = $post;
}
// Creation and editing of each post
foreach ($posts as $postid => $post) {
$followonq = $post['basetype'] == 'Q' && $postid != $questionid;
qa_create_event_for_q_user($questionid, $postid, $followonq ? QA_UPDATE_FOLLOWS : null, $post['userid'], @$posts[$post['parentid']]['userid'], $post['created']);
if (isset($post['updated']) && !$followonq) {
qa_create_event_for_q_user($questionid, $postid, $post['updatetype'], $post['lastuserid'], $post['userid'], $post['updated']);
}
}
// Tags and categories of question
qa_create_event_for_tags($question['tags'], $questionid, null, $question['userid'], $question['created']);
qa_create_event_for_category($question['categoryid'], $questionid, null, $question['userid'], $question['created']);
// Collect comment threads
$parentidcomments = array();
foreach ($posts as $postid => $post) {
if ($post['basetype'] == 'C') {
$parentidcomments[$post['parentid']][$postid] = $post;
}
}
// For each comment thread, notify all previous comment authors of each comment in the thread (could get slow)
foreach ($parentidcomments as $parentid => $comments) {
$keyuserids = array();
qa_sort_by($comments, 'created');
foreach ($comments as $comment) {
foreach ($keyuserids as $keyuserid => $dummy) {
if ($keyuserid != $comment['userid'] && $keyuserid != @$posts[$parentid]['userid']) {
qa_db_event_create_not_entity($keyuserid, $questionid, $comment['postid'], null, $comment['userid'], $comment['created']);
}
}
if (isset($comment['userid'])) {
$keyuserids[$comment['userid']] = true;
}
}
}
}
$next = 1 + $lastquestionid;
$done += count($questionids);
$continue = true;
} else {
qa_recalc_transition($state, 'dorefillevents_complete');
}
break;
case 'dorecalccategories':
qa_recalc_transition($state, 'dorecalccategories_postcount');
break;
case 'dorecalccategories_postcount':
qa_db_acount_update();
qa_db_ccount_update();
qa_recalc_transition($state, 'dorecalccategories_postupdate');
break;
case 'dorecalccategories_postupdate':
$postids = qa_db_posts_get_for_recategorizing($next, 100);
if (count($postids)) {
$lastpostid = max($postids);
qa_db_posts_recalc_categoryid($next, $lastpostid);