function output_widget($region, $place, $themeobject, $template, $request, $qa_content) { require_once QA_INCLUDE_DIR . 'qa-db-selects.php'; global $qa_login_userid, $questionid, $relatedcount, $question, $relatedquestions, $qa_cookieid, $usershtml; list($question, $relatedquestions) = qa_db_select_with_pending(qa_db_full_post_selectspec($qa_login_userid, $questionid), qa_db_related_qs_selectspec($qa_login_userid, $questionid)); if ($relatedcount > 1 && !$question['hidden']) { $minscore = qa_match_to_min_score(qa_opt('match_related_qs')); foreach ($relatedquestions as $key => $related) { if ($related['postid'] == $questionid || $related['score'] < $minscore) { unset($relatedquestions[$key]); } } if (count($relatedquestions)) { $themeobject->output('<h2>' . qa_lang('main/related_qs_title') . '</h2>'); } else { $themeobject->output('<h2>' . qa_lang('main/no_related_qs_title') . '</h2>'); } $upper = qa_opt('related_qs_num') < count($relatedquestions) ? qa_opt('related_qs_num') : count($relatedquestions); foreach ($relatedquestions as $related) { if ($upper <= 0) { break; } $themeobject->output('<p style="margin:0 0 10px 0; font-weight:bold;"><a href="' . qa_path_html(qa_q_request($related['postid'], $related['title'])) . '">' . $related['title'] . '</a></p>'); $upper--; } } }
/** * Process the delete hidden posts request from the admin */ function ami_dhp_delete_hidden_posts_process() { // load all required files if not loaded require_once QA_INCLUDE_DIR . 'qa-app-admin.php'; require_once QA_INCLUDE_DIR . 'qa-db-admin.php'; require_once QA_INCLUDE_DIR . 'qa-db-selects.php'; require_once QA_INCLUDE_DIR . 'qa-app-format.php'; // Check admin privileges if (qa_user_maximum_permit_error('permit_hide_show') && qa_user_maximum_permit_error('permit_delete_hidden')) { return false; } $userid = qa_get_logged_in_userid(); // Find recently hidden questions, answers, comments list($hiddenquestions, $hiddenanswers, $hiddencomments) = qa_db_select_with_pending(qa_db_qs_selectspec($userid, 'created', 0, null, null, 'Q_HIDDEN', true), qa_db_recent_a_qs_selectspec($userid, 0, null, null, 'A_HIDDEN', true), qa_db_recent_c_qs_selectspec($userid, 0, null, null, 'C_HIDDEN', true)); // first delete all hidden posts if (count($hiddencomments)) { foreach ($hiddencomments as $hiddencomment) { ami_dhp_post_delete_recursive($hiddencomment['opostid']); } } // delete all the hidden answers if (count($hiddenanswers)) { foreach ($hiddenanswers as $hiddenanswer) { ami_dhp_post_delete_recursive($hiddenanswer['opostid']); } } // delete all the hidden questions if (count($hiddenquestions)) { foreach ($hiddenquestions as $hiddenquestion) { ami_dhp_post_delete_recursive($hiddenquestion['postid']); } } }
function output_widget($region, $place, $themeobject, $template, $request, $qa_content) { $widget_opt = @$themeobject->current_widget['param']['options']; 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'; $categoryslugs = ''; $userid = qa_get_logged_in_userid(); // Get lists of recent activity in all its forms, plus category information list($questions1, $questions2, $questions3, $questions4) = qa_db_select_with_pending(qa_db_qs_selectspec($userid, 'created', 0, $categoryslugs, null, false, false, $qcount), qa_db_recent_a_qs_selectspec($userid, 0, $categoryslugs), qa_db_recent_c_qs_selectspec($userid, 0, $categoryslugs), qa_db_recent_edit_qs_selectspec($userid, 0, $categoryslugs)); // Prepare and return content for theme $content = qa_q_list_page_content(qa_any_sort_and_dedupe(array_merge($questions1, $questions2, $questions3, $questions4)), $qcount, 0, null, null, null, null, null, true, 'activity/', null, null, null, null); $content = $content['q_list']['qs']; if (@$themeobject->current_widget['param']['locations']['show_title']) { $themeobject->output('<h3 class="widget-title">' . qa_lang('cleanstrap/recent_activities') . ' <a href="' . qa_path_html('activity') . '">' . qa_lang('cleanstrap/view_all') . '</a></h3>'); } $themeobject->output('<div class="ra-question-activity-widget">'); $q_list = $content; $themeobject->output('<ul class="activity-list">'); foreach ($q_list as $list) { $themeobject->output('<li class="clearfix ' . (is_featured($list['raw']['postid']) ? ' featured' : '') . '"><span class="fav-star icon-heart' . (@$list['raw']['userfavoriteq'] ? ' active' : '') . '"></span><span class="post-status-c">' . cs_post_status($list) . '</span><a href="' . $list['url'] . '">' . $list['title'] . '<span class="time">' . implode(' ', $list['when']) . '</span><span class="ans-count total-' . $list['raw']['acount'] . '">' . $list['raw']['acount'] . '</span></a></li>'); } $themeobject->output('</ul>'); $themeobject->output('</div>'); }
function qa_get_options($names) { global $qa_options_cache, $qa_options_loaded; // If any options not cached, retrieve them from database via standard pending mechanism if (!@$qa_options_loaded) { require_once QA_INCLUDE_DIR . 'qa-db-selects.php'; qa_db_select_with_pending(); } // Pull out the options specifically requested here, and assign defaults $options = array(); foreach ($names as $name) { if (!isset($qa_options_cache[$name])) { $todatabase = true; switch ($name) { // don't write default to database if option was deprecated, or depends on site language (which could be changed) case 'custom_sidebar': case 'site_title': case 'email_privacy': case 'answer_needs_login': case 'ask_needs_login': case 'comment_needs_login': case 'db_time': $todatabase = false; break; } qa_set_option($name, qa_default_option($name), $todatabase); } $options[$name] = $qa_options_cache[$name]; } return $options; }
function admin_form(&$qa_content) { // process config change $saved_msg = ''; if (qa_clicked('tag_synonyms_save_button')) { qa_opt('tag_synonyms', trim(qa_post_text('tag_synonyms_text'))); qa_opt('tag_synonyms_prevent', (int) qa_post_text('tag_synonyms_prevent')); qa_opt('tag_synonyms_rep', (int) qa_post_text('tag_synonyms_rep')); $saved_msg = 'Tag Synonyms settings saved'; // convert all old tags based on synonyms if (qa_post_text('tag_synonyms_convert')) { $synonyms = $this->_synonyms_to_array(qa_opt('tag_synonyms')); $edited = 0; qa_suspend_event_reports(true); // avoid infinite loop foreach ($synonyms as $syn) { list($questions, $qcount) = qa_db_select_with_pending(qa_db_tag_recent_qs_selectspec(null, $syn['from'], 0, false, 500), qa_db_tag_count_qs_selectspec($syn['from'])); foreach ($questions as $q) { $oldtags = qa_tagstring_to_tags($q['tags']); $newtags = $this->_convert_tags($oldtags, $synonyms); qa_post_set_content($q['postid'], null, null, null, $newtags); $edited++; } } qa_suspend_event_reports(false); $saved_msg .= ' (and ' . $edited . ' tags edited)'; } } // set fields to show/hide when checkbox is clicked qa_set_display_rules($qa_content, array('tag_synonyms_rep' => 'tag_synonyms_prevent')); return array('ok' => $saved_msg, 'fields' => array(array('label' => 'Tag Synonyms', 'tags' => 'name="tag_synonyms_text" id="tag_synonyms_text"', 'value' => qa_opt('tag_synonyms'), 'type' => 'textarea', 'rows' => 20, 'note' => 'Put each pair of synonyms on a new line. <code>q2a,question2answer</code> means that a tag of <code>q2a</code> will be replaced by <code>question2answer</code>, while <code>help</code> on its own means that tag will be removed.'), array('label' => 'Also convert existing tags using above rules', 'tags' => 'name="tag_synonyms_convert" id="tag_synonyms_convert"', 'value' => '', 'type' => 'checkbox'), array('type' => 'blank'), array('label' => 'Prevent new users from creating new tags', 'tags' => 'name="tag_synonyms_prevent" id="tag_synonyms_prevent"', 'value' => qa_opt('tag_synonyms_prevent'), 'type' => 'checkbox'), array('id' => 'tag_synonyms_rep', 'label' => 'Minimum reputation to create new tags', 'value' => qa_opt('tag_synonyms_rep'), 'tags' => 'name="tag_synonyms_rep"', 'type' => 'number')), 'buttons' => array(array('label' => 'Save Changes', 'tags' => 'name="tag_synonyms_save_button"'))); }
function qa_get_user_avatar_html($flags, $email, $handle, $blobid, $width, $height, $size, $padding = false) { if (qa_opt('avatar_allow_gravatar') && $flags & QA_USER_FLAGS_SHOW_GRAVATAR) { $html = qa_get_gravatar_html($email, $size); } elseif (qa_opt('avatar_allow_upload') && $flags & QA_USER_FLAGS_SHOW_AVATAR) { if (isset($blobid)) { $html = qa_get_avatar_blob_html($blobid, $width, $height, $size, $padding); } elseif (strlen($handle)) { $userprofile = qa_db_select_with_pending(qa_db_user_profile_selectspec($handle, false)); if (!empty($userprofile['social_avatar'])) { $html = '<img src="' . $userprofile['social_avatar'] . '" width="' . $size . '" height="' . $size . '" class="qa-avatar-image" />'; } else { $html = null; } } } if (!isset($html)) { if ((qa_opt('avatar_allow_gravatar') || qa_opt('avatar_allow_upload')) && qa_opt('avatar_default_show') && strlen(qa_opt('avatar_default_blobid'))) { $html = qa_get_avatar_blob_html(qa_opt('avatar_default_blobid'), qa_opt('avatar_default_width'), qa_opt('avatar_default_height'), $size, $padding); } else { $html = null; } } return isset($html) && strlen($handle) ? '<A HREF="' . qa_path_html('user/' . $handle) . '" CLASS="qa-avatar-link">' . $html . '</A>' : $html; }
function check_privileges($userid, $event_points) { $user = qa_db_select_with_pending(qa_db_user_points_selectspec($userid, true)); $upoints = (int) $user['points']; $before_points = (int) $user['points'] - $event_points; $permr = qa_db_read_one_value(qa_db_query_sub('SELECT meta_value FROM ^usermeta WHERE user_id=# AND meta_key=$ ', $userid, 'priv_notify'), true); // stale perms $stale = array(); if ($permr) { $perms = explode('^', $permr); $stale = explode(',', $perms[0]); } $p_options = qa_get_permit_options(); $notices = ''; foreach ($p_options as $option) { if (qa_opt($option) == QA_PERMIT_POINTS) { $opoints = (int) qa_opt($option . '_points'); if ($opoints < $upoints && $opoints > $before_points && !in_array($option, $stale)) { $notices = ($notices ? $notices . ',' : '') . $option; } } } if ($notices) { qa_db_query_sub('INSERT INTO ^usermeta (user_id,meta_key,meta_value) VALUES (#,$,$) ON DUPLICATE KEY UPDATE meta_value=$', $userid, 'priv_notify', '^' . $notices, $permr . ($perms[1] ? ',' : '') . $notices); if (qa_opt('priv_email_notify_on')) { $this->notify($userid, $notices); } } }
function output_widget($region, $place, $themeobject, $template, $request, $qa_content) { /* $requestparts=qa_request_parts(); $requestlower=strtolower(qa_request()); $firstlower=strtolower($requestparts[0]); $routing=qa_page_routing(); // unanswered & questions pages may contain categories. unset($routing['activity/']); unset($routing['unanswered/']); unset($routing['questions/']); if ( (isset($routing[$requestlower])) or (isset($routing[$firstlower.'/'])) or (is_numeric($requestparts[0])) ) return; $explicitqa=(strtolower($requestparts[0])=='qa' or strtolower($requestparts[0])=='unanswered' or strtolower($requestparts[0])=='questions' or strtolower($requestparts[0])=='activity'); if ($explicitqa) $slugs=array_slice($requestparts, 1); elseif (strlen($requestparts[0])) $slugs=$requestparts; else $slugs=array(); */ $slugs = useo_get_current_category_slug(); $countslugs = count($slugs); 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); if ($countslugs && isset($categoryid)) { /* $categoryid is current categories ID $backpath = implode('/', array_reverse($slugs)); echo "countslugs: <pre>"; var_dump($countslugs); echo "</pre>"; $fullcategory=qa_db_select_with_pending(qa_db_full_category_selectspec($categoryid, true)); echo "fullcategory: <pre>"; var_dump($fullcategory); echo "</pre>"; echo "categoryid: <pre>"; var_dump($categoryid); echo "</pre>"; echo "slugs: <pre>"; var_dump($slugs); echo "</pre>"; echo "template: <pre>"; var_dump($template); echo "</pre>"; echo "request: <pre>"; var_dump($request); echo "</pre>"; */ require_once QA_INCLUDE_DIR . 'qa-db-metas.php'; $description = qa_db_categorymeta_get($categoryid, 'useo_cat_description'); if (!qa_opt('useo_cat_desc_format')) { $description = qa_html($description); } $editurlhtml = qa_path_html('category-edit/' . $categoryid); $allowediting = !qa_user_permit_error('useo_cat_desc_permit_edit'); if (strlen($description)) { echo '<SPAN CLASS="entry-content qa-category-description">'; echo $description; echo '</SPAN>'; if ($allowediting) { echo ' - <A HREF="' . $editurlhtml . '">edit</A>'; } } elseif ($allowediting) { echo '<A HREF="' . $editurlhtml . '">' . qa_lang_html('useo/create_desc_link') . '</A>'; } } }
function getEmail($userid) { require_once QA_INCLUDE_DIR . 'qa-db-selects.php'; if (QA_FINAL_EXTERNAL_USERS) { $email = qa_get_user_email($userid); } else { $useraccount = qa_db_select_with_pending(qa_db_user_account_selectspec($userid, true)); $email = @$useraccount['email']; } return $email; }
function qa_feed_load_ifcategory($categoryslugs, $allkey, $catkey, &$title, $questionselectspec1 = null, $questionselectspec2 = null, $questionselectspec3 = null, $questionselectspec4 = null) { $countslugs = @count($categoryslugs); list($questions1, $questions2, $questions3, $questions4, $categories, $categoryid) = qa_db_select_with_pending($questionselectspec1, $questionselectspec2, $questionselectspec3, $questionselectspec4, $countslugs ? qa_db_category_nav_selectspec($categoryslugs, false) : null, $countslugs ? qa_db_slugs_to_category_id_selectspec($categoryslugs) : null); if ($countslugs && !isset($categoryid)) { qa_feed_not_found(); } if (isset($allkey)) { $title = isset($categoryid) && isset($catkey) ? qa_lang_sub($catkey, $categories[$categoryid]['title']) : qa_lang($allkey); } return array_merge(is_array($questions1) ? $questions1 : array(), is_array($questions2) ? $questions2 : array(), is_array($questions3) ? $questions3 : array(), is_array($questions4) ? $questions4 : array()); }
function qa_db_get_pending_result($pendingid, $selectspec = null) { global $qa_db_pending_selectspecs, $qa_db_pending_results; if (isset($selectspec)) { qa_db_queue_pending_select($pendingid, $selectspec); } elseif (!isset($qa_db_pending_selectspecs[$pendingid])) { qa_fatal_error('Pending query was never set up: ' . $pendingid); } if (!isset($qa_db_pending_results[$pendingid])) { qa_db_select_with_pending(); } return $qa_db_pending_results[$pendingid]; }
function process_request($request) { // Get list of unanswered open questions $userid = qa_get_logged_in_userid(); $start = qa_get_start(); $questions_selectspec = $this->qa_db_open_qs_selectspec($userid, $start); $questions = qa_db_select_with_pending($questions_selectspec); // Prepare and return the content for the theme $questions_found_title = qa_lang_html('open_questions/questions_found_title'); $no_questions_title = qa_lang_html('open_questions/no_questions_title'); $count = qa_opt('cache_unaqcount'); $qa_content = qa_q_list_page_content($questions, qa_opt('page_size_una_qs'), $start, @$count, $questions_found_title, $no_questions_title, null, null, false, null, null, qa_html_suggest_qs_tags(qa_using_tags()), null, null); return $qa_content; }
function qa_send_notification($userid, $email, $handle, $subject, $body, $subs, $html = false) { if (qa_to_override(__FUNCTION__)) { $args = func_get_args(); return qa_call_override(__FUNCTION__, $args); } global $qa_notifications_suspended; if ($qa_notifications_suspended > 0) { return false; } require_once QA_INCLUDE_DIR . 'db/selects.php'; require_once QA_INCLUDE_DIR . 'util/string.php'; if (isset($userid)) { $needemail = !qa_email_validate(@$email); // take from user if invalid, e.g. @ used in practice $needhandle = empty($handle); if ($needemail || $needhandle) { if (QA_FINAL_EXTERNAL_USERS) { if ($needhandle) { $handles = qa_get_public_from_userids(array($userid)); $handle = @$handles[$userid]; } if ($needemail) { $email = qa_get_user_email($userid); } } else { $useraccount = qa_db_select_with_pending(array('columns' => array('email', 'handle'), 'source' => '^users WHERE userid = #', 'arguments' => array($userid), 'single' => true)); if ($needhandle) { $handle = @$useraccount['handle']; } if ($needemail) { $email = @$useraccount['email']; } } } } if (isset($email) && qa_email_validate($email)) { $subs['^site_title'] = qa_opt('site_title'); $subs['^handle'] = $handle; $subs['^email'] = $email; $subs['^open'] = "\n"; $subs['^close'] = "\n"; return qa_send_email(array('fromemail' => qa_opt('from_email'), 'fromname' => qa_opt('site_title'), 'toemail' => $email, 'toname' => $handle, 'subject' => strtr($subject, $subs), 'body' => (empty($handle) ? '' : qa_lang_sub('emails/to_handle_prefix', $handle)) . strtr($body, $subs), 'html' => $html)); } else { return false; } }
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'; // Get list of questions, plus category information $nonetitle = qa_lang_html('main/no_questions_found'); $categorypathprefix = null; // only show category list and feed when sorting by date $feedpathprefix = null; $selectspec = array('columns' => array('^posts.postid', '^posts.categoryid', '^posts.type', 'basetype' => 'LEFT(^posts.type,1)', 'hidden' => "INSTR(^posts.type, '_HIDDEN')>0", '^posts.acount', '^posts.selchildid', '^posts.upvotes', '^posts.downvotes', '^posts.netvotes', '^posts.views', '^posts.hotness', '^posts.flagcount', 'title' => 'BINARY ^posts.title', 'tags' => 'BINARY ^posts.tags', 'created' => 'UNIX_TIMESTAMP(^posts.created)', 'categoryname' => 'BINARY ^categories.title', 'categorybackpath' => "BINARY ^categories.backpath"), 'arraykey' => 'postid', 'source' => '^posts LEFT JOIN ^categories ON ^categories.categoryid=^posts.categoryid JOIN ^postmeta ON ^posts.postid=^postmeta.post_id AND ^postmeta.meta_key=$ AND ^postmeta.meta_value>0 AND ^posts.type=$', 'arguments' => array('is_poll', 'Q')); $selectspec['columns']['content'] = '^posts.content'; $selectspec['columns']['notify'] = '^posts.notify'; $selectspec['columns']['updated'] = 'UNIX_TIMESTAMP(^posts.updated)'; $selectspec['columns']['updatetype'] = '^posts.updatetype'; $selectspec['columns'][] = '^posts.format'; $selectspec['columns'][] = '^posts.lastuserid'; $selectspec['columns']['lastip'] = 'INET_NTOA(^posts.lastip)'; $selectspec['columns'][] = '^posts.parentid'; $selectspec['columns']['lastviewip'] = 'INET_NTOA(^posts.lastviewip)'; $selectspec['columns'][] = '^posts.userid'; $selectspec['columns'][] = '^posts.cookieid'; $selectspec['columns']['createip'] = 'INET_NTOA(^posts.createip)'; $selectspec['columns'][] = '^userpoints.points'; if (!QA_FINAL_EXTERNAL_USERS) { $selectspec['columns'][] = '^users.flags'; $selectspec['columns'][] = '^users.level'; $selectspec['columns']['email'] = 'BINARY ^users.email'; $selectspec['columns']['handle'] = 'CONVERT(^users.handle USING BINARY)'; // because of MySQL bug #29205 $selectspec['columns'][] = '^users.avatarblobid'; $selectspec['columns'][] = '^users.avatarwidth'; $selectspec['columns'][] = '^users.avatarheight'; $selectspec['source'] .= ' LEFT JOIN ^users ON ^posts.userid=^users.userid'; $selectspec['columns']['lasthandle'] = 'CONVERT(lastusers.handle USING BINARY)'; // because of MySQL bug #29205 $selectspec['source'] .= ' LEFT JOIN ^users AS lastusers ON ^posts.lastuserid=lastusers.userid'; } $selectspec['source'] .= ' LEFT JOIN ^userpoints ON ^posts.userid=^userpoints.userid'; $selectspec['source'] .= ' ORDER BY ^posts.created DESC'; $questions = qa_db_select_with_pending($selectspec); 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_lang('polls/page_title'), $nonetitle, null, null, false, null, null, null, null); return $qa_content; }
function qa_complete_reset_user($userid) { require_once QA_INCLUDE_DIR . 'qa-util-string.php'; require_once QA_INCLUDE_DIR . 'qa-app-options.php'; require_once QA_INCLUDE_DIR . 'qa-app-emails.php'; require_once QA_INCLUDE_DIR . 'qa-app-cookies.php'; require_once QA_INCLUDE_DIR . 'qa-db-selects.php'; $password = qa_random_alphanum(max(QA_MIN_PASSWORD_LEN, QA_NEW_PASSWORD_LEN)); $userinfo = qa_db_select_with_pending(qa_db_user_account_selectspec($userid, true)); if (!qw_send_notification($userid, $userinfo['email'], $userinfo['handle'], qa_lang('emails/new_password_subject'), nl2br(qa_lang('emails/new_password_body')), array('^password' => $password, '^url' => qa_opt('site_url')))) { qa_fatal_error('Could not send new password - password not reset'); } qa_db_user_set_password($userid, $password); // do this last, to be safe qa_db_user_set($userid, 'emailcode', ''); // so can't be reused qa_report_event('u_reset', $userid, $userinfo['handle'], qa_cookie_get(), array('email' => $userinfo['email'])); }
function get_qa_avartar_html($user, $size = 200) { $userid_array = qa_handles_to_userids(array($user)); $userid = $userid_array[$user]; $useraccount = qa_db_select_with_pending(qa_db_user_account_selectspec($userid, true)); $avartahtml = qa_get_user_avatar_html($useraccount['flags'], $useraccount['email'], $useraccount['handle'], $useraccount['avatarblobid'], $useraccount['avatarwidth'], $useraccount['avatarheight'], qa_opt('avatar_profile_size')); $avartahtml = strtolower($avartahtml); if ($avartahtml != null) { $avartahtml = strtolower($avartahtml); $avartahtml = str_replace('?', '\\?', $avartahtml); //生成avarta的html串,从站点的根目录引用 } else { $avartahtml = '<a href="' . $this->config->item('qaroot_src') . '?qa=user/' . $user . '" class="qa-user-link">'; $avartahtml .= '<img src="' . base_url($this->config->item('app_src')) . '/views/theme/' . $this->config->item('theme') . '/img/default_avatar.jpg' . '"/>'; $avartahtml .= '</a>'; } return $avartahtml; }
function qa_send_notification($userid, $email, $handle, $subject, $body, $subs) { global $qa_notifications_suspended; if ($qa_notifications_suspended > 0) { return false; } require_once QA_INCLUDE_DIR . 'qa-db-selects.php'; require_once QA_INCLUDE_DIR . 'qa-util-emailer.php'; require_once QA_INCLUDE_DIR . 'qa-util-string.php'; if (isset($userid)) { $needemail = !qa_email_validate(@$email); // take from user if invalid, e.g. @ used in practice $needhandle = empty($handle); if ($needemail || $needhandle) { if (QA_FINAL_EXTERNAL_USERS) { if ($needhandle) { $handles = qa_get_public_from_userids(array($userid)); $handle = @$handles[$userid]; } if ($needemail) { $email = qa_get_user_email($userid); } } else { $useraccount = qa_db_select_with_pending(qa_db_user_account_selectspec($userid, true)); if ($needhandle) { $handle = @$useraccount['handle']; } if ($needemail) { $email = @$useraccount['email']; } } } } if (isset($email) && qa_email_validate($email)) { $subs['^site_title'] = qa_opt('site_title'); $subs['^handle'] = $handle; $subs['^email'] = $email; $subs['^open'] = "\n"; $subs['^close'] = "\n"; return qa_send_email(array('fromemail' => qa_opt('from_email'), 'fromname' => qa_opt('site_title'), 'toemail' => $email, 'toname' => $handle, 'subject' => strtr($subject, $subs), 'body' => (empty($handle) ? '' : $handle . ",\n\n") . strtr($body, $subs), 'html' => false)); } else { return false; } }
function sendNewConfirm($userid) { require_once QA_INCLUDE_DIR . 'db/users.php'; require_once QA_INCLUDE_DIR . 'db/selects.php'; require_once QA_INCLUDE_DIR . 'app/emails.php'; $userinfo = qa_db_select_with_pending(qa_db_user_account_selectspec($userid, true)); if (!qa_send_notification($userid, $userinfo['email'], $userinfo['handle'], qa_lang('emails/confirm_subject'), qa_lang('emails/confirm_body'), array('^url' => getNewConfirmUrl($userid, $userinfo['handle'])))) { qa_fatal_error('Could not send email confirmation'); } // $userinfo=qa_db_select_with_pending(qa_db_user_account_selectspec($userid, true)); // $params = array(); // $params['fromemail'] = qa_opt('from_email'), // $params['fromname'] = qa_opt('site_title'), // $params['toemail'] = $userinfo['email']; // $params['toname'] = $userinfo['handle']; // $params['subject'] = qa_lang('emails/confirm_subject'); // $params['body'] = qa_lang('emails/confirm_body'); // qa_send_email($params); }
function get_user_activity($handle, $limit = 10) { $userid = qa_handle_to_userid($handle); require_once QA_INCLUDE_DIR . 'qa-db-selects.php'; require_once QA_INCLUDE_DIR . 'qa-app-format.php'; $identifier = QA_FINAL_EXTERNAL_USERS ? $userid : $handle; list($useraccount, $questions, $answerqs, $commentqs, $editqs) = qa_db_select_with_pending(QA_FINAL_EXTERNAL_USERS ? null : qa_db_user_account_selectspec($handle, false), qa_db_user_recent_qs_selectspec($userid, $identifier, $limit), qa_db_user_recent_a_qs_selectspec($userid, $identifier), qa_db_user_recent_c_qs_selectspec($userid, $identifier), qa_db_user_recent_edit_qs_selectspec($userid, $identifier)); if (!QA_FINAL_EXTERNAL_USERS && !is_array($useraccount)) { // check the user exists return include QA_INCLUDE_DIR . 'qa-page-not-found.php'; } // Get information on user references $questions = qa_any_sort_and_dedupe(array_merge($questions, $answerqs, $commentqs, $editqs)); $questions = array_slice($questions, 0, $limit); $usershtml = qa_userids_handles_html(qa_any_get_userids_handles($questions), false); $htmldefaults = qa_post_html_defaults('Q'); $htmldefaults['whoview'] = false; $htmldefaults['voteview'] = false; $htmldefaults['avatarsize'] = 0; foreach ($questions as $question) { $qa_content[] = qa_any_to_q_html_fields($question, $userid, qa_cookie_get(), $usershtml, null, array('voteview' => false) + qa_post_html_options($question, $htmldefaults)); } $output = '<div class="user-activities">'; $output .= '<ul>'; if (isset($qa_content)) { foreach ($qa_content as $qs) { $icon = 'icon-time undefined'; $output .= '<li class="activity-item">'; $output .= '<div class="list-right">'; $output .= '<div class="type pull-left ' . $icon . '"></div>'; $output .= '<div class="what"><a class="what-task" href="' . @$qs['url'] . '">' . $qs['what'] . '</a>'; $output .= '<a href="' . $qs['url'] . '">' . $qs['title'] . '</a> </div>'; $output .= '<strong class="when">' . implode(' ', $qs['when']) . '</strong>'; $output .= '</div>'; $output .= '</li>'; } } else { $output .= '<li>' . qa_lang('cleanstrap/no_activity_yet') . '</li>'; } $output .= '</ul>'; $output .= '</div>'; return $output; }
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 process_request($request) { $userid = qa_get_logged_in_userid(); $categoryid = mp_get_categoryid(); $users = mp_get_category_userids($categoryid); $qa_content = qa_content_prepare(); $qa_content['title'] = 'Classroom'; $data = "<div class='mp-classroom'>"; $data .= "<center><div class='mp-classroom-teacher'> </div></center>"; $data .= "<div class='mp-classroom-users'>"; foreach ($users as $user) { $userinfo = qa_db_select_with_pending(qa_db_user_account_selectspec($user['userid'], true)); $data .= "<div class='mp-classroom-user'>"; $data .= "<div class='mp-classroom-avatar'></div>"; $data .= "<div class='mp-classroom-useremail'>" . qa_get_one_user_html($userinfo['handle'], false) . "</div>"; $data .= "</div>"; } $data .= "</div></div>"; $qa_content['custom'] = $data; return $qa_content; }
function process_request($request) { $parts = explode('/', $request); $categoryid = $parts[1]; $fullcategory = qa_db_select_with_pending(qa_db_full_category_selectspec($categoryid, true)); $slugs = explode('/', $fullcategory['backpath']); $new_request = implode('/', array_reverse($slugs)); $qa_content = qa_content_prepare(); $qa_content['title'] = qa_lang_html_sub('useo/edit_desc_for_x', qa_html($fullcategory['title'])); if (qa_user_permit_error('useo_cat_desc_permit_edit')) { $qa_content['error'] = qa_lang_html('users/no_permission'); return $qa_content; } require_once QA_INCLUDE_DIR . 'qa-db-metas.php'; if (qa_clicked('dosave')) { require_once QA_INCLUDE_DIR . 'qa-util-string.php'; qa_db_categorymeta_set($categoryid, 'useo_cat_title', qa_post_text('useo_cat_title')); qa_db_categorymeta_set($categoryid, 'useo_cat_description', qa_post_text('useo_cat_description')); qa_redirect($new_request); } $qa_content['form'] = array('tags' => 'METHOD="POST" ACTION="' . qa_self_html() . '"', 'style' => 'tall', 'fields' => array(array('label' => 'Link Title:', 'type' => 'text', 'rows' => 2, 'tags' => 'NAME="useo_cat_title" ID="useo_cat_title"', 'value' => qa_html(qa_db_categorymeta_get($categoryid, 'useo_cat_title'))), array('label' => 'Description:', 'type' => 'text', 'rows' => 4, 'tags' => 'NAME="useo_cat_description" ID="useo_cat_description"', 'value' => qa_html(qa_db_categorymeta_get($categoryid, 'useo_cat_description')))), 'buttons' => array(array('tags' => 'NAME="dosave"', 'label' => qa_lang_html('useo/save_desc_button')))); $qa_content['focusid'] = 'tagtitle'; return $qa_content; }
function qa_check_all_users_badges() { $awarded = 0; $users; $temp = qa_db_query_sub('SELECT * FROM ^posts'); while (($post = qa_db_read_one_assoc($temp, true)) !== null) { if (!$post['userid']) { continue; } $user = '******' . $post['userid']; $pid = $post['postid']; $pt = $post['type']; // get post count if (isset($users[$user]) && isset($users[$user][$pt])) { $users[$user][$pt]++; } else { $users[$user][$pt] = 1; } // get post votes if ($post['netvotes'] != 0) { $users[$user][$pt . 'votes'][] = array('id' => $pid, 'votes' => (int) $post['netvotes'], 'parentid' => $post['parentid'], 'created' => $post['created']); } // get post views if ($post['views']) { $users[$user]['views'][] = array('id' => $pid, 'views' => $post['views']); } } //votes received and given out $voter = qa_db_read_all_assoc(qa_db_query_sub('SELECT userid,qupvotes,qdownvotes,aupvotes,adownvotes,upvoteds FROM ^userpoints')); foreach ($voter as $idx => $votes) { $user = '******' . $votes['userid']; // votes $users[$user]['votes'] = (int) $votes['qupvotes'] + (int) $votes['qdownvotes'] + (int) $votes['aupvotes'] + (int) $votes['adownvotes']; // voteds $users[$user]['voted'] = (int) $votes['upvoteds']; unset($voter[$idx]); } // flags $flag_result = qa_db_read_all_values(qa_db_query_sub('SELECT userid FROM ^uservotes WHERE flag > 0')); foreach ($flag_result as $idx => $flag) { $user = '******' . $flag; // get flag count if (isset($users[$user]) && isset($users[$user]['flags'])) { $users[$user]['flags']++; } else { $users[$user]['flags'] = 1; } unset($flag_result[$idx]); } // per user loop foreach ($users as $user => $data) { $uid = (int) substr($user, 4); // bulk posts $badges = array('Q' => array('asker', 'questioner', 'inquisitor'), 'A' => array('answerer', 'lecturer', 'preacher'), 'C' => array('commenter', 'commentator', 'annotator')); foreach ($badges as $pt => $slugs) { if (!isset($data[$pt])) { continue; } $awarded += count(qa_badge_award_check($slugs, $data[$pt], $uid, null, 0)); } // nice Q&A $badges = array('nice_question', 'good_question', 'great_question', 'nice_answer', 'good_answer', 'great_answer'); if ($this->badge_activated($badges)) { $badges = array('Q' => array('nice_question', 'good_question', 'great_question'), 'A' => array('nice_answer', 'good_answer', 'great_answer')); foreach ($badges as $pt => $slugs) { foreach ($slugs as $badge_slug) { if (!isset($data[$pt . 'votes'])) { continue; } foreach ($data[$pt . 'votes'] as $idv) { // poll plugin integration if ($pt == 'A' && qa_opt('poll_enable')) { $poll = qa_db_read_one_value(qa_db_query_sub('SELECT meta_value FROM ^postmeta WHERE post_id=# AND meta_key=$', $idv['id'], 'is_poll'), true); if ($poll) { continue; } } if ((int) $idv['votes'] >= (int) qa_opt('badge_' . $badge_slug . '_var') && qa_opt('badge_' . $badge_slug . '_enabled') !== '0') { $result = qa_db_read_one_value(qa_db_query_sub('SELECT badge_slug FROM ^userbadges WHERE user_id=# AND object_id=# AND badge_slug=$', $uid, $idv['id'], $badge_slug), true); if ($result == null) { // not already awarded this badge $this->award_badge($idv['id'], $uid, $badge_slug, false, true); $awarded++; } // old question answer vote checks if ($pt == 'A') { $qid = $idv['parentid']; $create = strtotime($idv['created']); $parent = $this->get_post_data($qid); $pcreate = strtotime($parent['created']); $diff = round(abs($pcreate - $create) / 60 / 60 / 24); $badge_slug2 = $badge_slug . '_old'; if ($diff >= (int) qa_opt('badge_' . $badge_slug2 . '_var') && qa_opt('badge_' . $badge_slug2 . '_enabled') !== '0') { $result = qa_db_read_one_value(qa_db_query_sub('SELECT badge_slug FROM ^userbadges WHERE user_id=# AND object_id=# AND badge_slug=$', $uid, $idv['id'], $badge_slug2), true); if ($result == null) { // not already awarded for this answer $this->award_badge($idv['id'], $uid, $badge_slug2); $awarded++; } } } } } } } } // votes per user badges if (isset($data['votes'])) { $votes = $data['votes']; $badges = array('voter', 'avid_voter', 'devoted_voter'); $awarded += count(qa_badge_award_check($badges, $votes, $uid, null, 0)); } // voted per user badges if (isset($data['voted'])) { $votes = $data['voted']; $badges = array('liked', 'loved', 'revered'); $awarded += count(qa_badge_award_check($badges, $votes, $uid, null, 0)); } // views per post badges if (isset($data['views'])) { $badges = array('notable_question', 'popular_question', 'famous_question'); foreach ($data['views'] as $idv) { $awarded += count(qa_badge_award_check($badges, $idv['views'], $uid, $idv['id'], 0)); } } // flags per user if (isset($data['flags'])) { $flags = $data['flags']; $badges = array('watchdog', 'bloodhound', 'pitbull'); $awarded += count(qa_badge_award_check($badges, $flags, $uid, null, 0)); } unset($users[$user]); } // selects, selecteds $badges = array('gifted', 'wise', 'enlightened', 'grateful', 'respectful', 'reverential'); if ($this->badge_activated($badges)) { $selects = qa_db_read_all_assoc(qa_db_query_sub('SELECT aselects, aselecteds, userid FROM ^userpoints')); foreach ($selects as $idx => $s) { $uid = $s['userid']; if (isset($s['aselecteds'])) { $count = $s['aselecteds']; $badges = array('gifted', 'wise', 'enlightened'); $awarded += count(qa_badge_award_check($badges, $count, $uid, null, 0)); } if (isset($s['aselects'])) { $count = $s['aselects']; $badges = array('grateful', 'respectful', 'reverential'); $awarded += count(qa_badge_award_check($badges, $count, $uid, null, 0)); } unset($selects[$idx]); } } // achievements $badges = array('dedicated', 'devoted', 'zealous', 'visitor', 'trouper', 'veteran', 'regular', 'old_timer', 'ancestor', 'reader', 'avid_reader', 'devoted_reader'); if ($this->badge_activated($badges)) { $userq = qa_db_query_sub('SELECT user_id AS uid,questions_read AS qr,oldest_consec_visit AS ocv,longest_consec_visit AS lcv,total_days_visited AS tdv,last_visit AS lv,first_visit AS fv,posts_edited AS pe FROM ^achievements'); while (($user = qa_db_read_one_assoc($userq, true)) !== null) { $uid = $user['uid']; // edits $count = $user['pe']; $badges = array('editor', 'copy_editor', 'senior_editor'); $awarded += count(qa_badge_award_check($badges, $count, $uid, null, 0)); // on-sign-in badges // check lapse in days since last visit // using julian days $todayj = GregorianToJD(date('n'), date('j'), date('Y')); $last_visit = strtotime($user['lv']); $lastj = GregorianToJD(date('n', $last_visit), date('j', $last_visit), date('Y', $last_visit)); $last_diff = $todayj - $lastj; $first_visit = strtotime($user['fv']); $first_visitj = GregorianToJD(date('n', $first_visit), date('j', $first_visit), date('Y', $first_visit)); $first_visit_diff = $todayj - $first_visitj; $badges = array('dedicated', 'devoted', 'zealous'); $awarded += count(qa_badge_award_check($badges, $user['lcv'], $uid, null, 0)); $badges = array('visitor', 'trouper', 'veteran'); $awarded += count(qa_badge_award_check($badges, $user['tdv'], $uid, null, 0)); $badges = array('regular', 'old_timer', 'ancestor'); $awarded += count(qa_badge_award_check($badges, $first_visit_diff, $uid, null, 0)); // views $badges = array('reader', 'avid_reader', 'devoted_reader'); $awarded += count(qa_badge_award_check($badges, $user['qr'], $uid, null, 0)); } } // points $badges = array('100_club', '1000_club', '10000_club'); if ($this->badge_activated($badges)) { $userq = qa_db_query_sub('SELECT userid, points FROM ^userpoints'); while (($user = qa_db_read_one_assoc($userq, true)) !== null) { $awarded += count(qa_badge_award_check($badges, $user['points'], $user['userid'], null, 0)); } } if (!QA_FINAL_EXTERNAL_USERS) { // verified $badges = array('verified'); if ($this->badge_activated($badges)) { $userq = qa_db_query_sub('SELECT userid, flags FROM ^users WHERE flags&#', QA_USER_FLAGS_EMAIL_CONFIRMED); while (($user = qa_db_read_one_assoc($userq, true)) !== null) { $awarded += count(qa_badge_award_check($badges, false, $user['userid'], null, 0)); } } // profile stuff $badges = array('avatar', 'profiler'); if ($this->badge_activated($badges)) { $userq = qa_db_query_sub('SELECT userid FROM ^users'); while (($userid = qa_db_read_one_value($userq, true)) !== null) { list($useraccount, $userprofile, $userfields) = qa_db_select_with_pending(qa_db_user_account_selectspec($userid, true), qa_db_user_profile_selectspec($userid, true), qa_db_userfields_selectspec()); // avatar badge if (qa_opt('avatar_allow_upload') && isset($useraccount['avatarblobid'])) { $badges = array('avatar'); $awarded += count(qa_badge_award_check($badges, false, $userid, null, 0)); } // profile completion $missing = false; foreach ($userfields as $userfield) { if (!isset($userprofile[$userfield['title']]) || @$userprofile[$userfield['title']] === '') { $missing = true; break; } } if (!$missing) { $badges = array('profiler'); $awarded += count(qa_badge_award_check($badges, false, $userid, null, 0)); } } } } // rebuild badges from other plugins - experimental! - $module->custom_badges_rebuild() returns number of badges awarded. $moduletypes = qa_list_module_types(); foreach ($moduletypes as $moduletype) { $modulenames = qa_list_modules($moduletype); foreach ($modulenames as $modulename) { $module = qa_load_module($moduletype, $modulename); if (method_exists($module, 'custom_badges_rebuild')) { $awarded += $module->custom_badges_rebuild(); } } } // badges $badges = array('medalist', 'champion', 'olympian'); if ($this->badge_activated($badges)) { $badgelist = qa_db_read_all_values(qa_db_query_sub('SELECT user_id FROM ^userbadges')); $users = array(); foreach ($badgelist as $idx => $medal) { $user = '******' . $medal; // get badge count if (isset($users[$user]) && isset($users[$user]['medals'])) { $users[$user]['medals']++; } else { $users[$user]['medals'] = 1; } unset($badgelist[$idx]); } foreach ($users as $user => $data) { $uid = (int) substr($user, 4); // check badges if (isset($data['medals'])) { $uid = (int) substr($user, 4); $count = $data['medals']; $awarded += count(qa_badge_award_check($badges, $count, $uid, null, 0)); } unset($users[$user]); } } // return ok text return $awarded . ' badge' . ($awarded != 1 ? 's' : '') . ' awarded.'; }
header('Location: ../'); exit; } require_once QA_INCLUDE_DIR . 'qa-app-format.php'; require_once QA_INCLUDE_DIR . 'qa-app-limits.php'; require_once QA_INCLUDE_DIR . 'qa-db-selects.php'; require_once QA_INCLUDE_DIR . 'qa-util-sort.php'; // Check whether this is a follow-on question and get some info we need from the database $in = array(); $followpostid = qa_get('follow'); $in['categoryid'] = qa_get_category_field_value('category'); if (!isset($in['categoryid'])) { $in['categoryid'] = qa_get('cat'); } $userid = qa_get_logged_in_userid(); list($categories, $followanswer, $completetags) = qa_db_select_with_pending(qa_db_category_nav_selectspec($in['categoryid'], true), isset($followpostid) ? qa_db_full_post_selectspec($userid, $followpostid) : null, qa_db_popular_tags_selectspec(0, QA_DB_RETRIEVE_COMPLETE_TAGS)); if (!isset($categories[$in['categoryid']])) { $in['categoryid'] = null; } if (@$followanswer['basetype'] != 'A') { $followanswer = null; } // Check for permission error $permiterror = qa_user_maximum_permit_error('permit_post_q', QA_LIMIT_QUESTIONS); if ($permiterror) { $qa_content = qa_content_prepare(); // The 'approve', 'login', 'confirm', 'limit', 'userblock', 'ipblock' permission errors are reported to the user here // The other option ('level') prevents the menu option being shown, in qa_content_prepare(...) switch ($permiterror) { case 'login': $qa_content['error'] = qa_insert_login_links(qa_lang_html('question/ask_must_login'), qa_request(), isset($followpostid) ? array('follow' => $followpostid) : null);
require_once QA_INCLUDE_DIR . 'app/users.php'; require_once QA_INCLUDE_DIR . 'db/selects.php'; require_once QA_INCLUDE_DIR . 'pages/question-view.php'; require_once QA_INCLUDE_DIR . 'pages/question-submit.php'; // Load relevant information about this comment $commentid = qa_post_text('commentid'); $questionid = qa_post_text('questionid'); $parentid = qa_post_text('parentid'); $userid = qa_get_logged_in_userid(); list($comment, $question, $parent, $children) = qa_db_select_with_pending(qa_db_full_post_selectspec($userid, $commentid), qa_db_full_post_selectspec($userid, $questionid), qa_db_full_post_selectspec($userid, $parentid), qa_db_full_child_posts_selectspec($userid, $parentid)); // Check if there was an operation that succeeded if (@$comment['basetype'] == 'C' && @$question['basetype'] == 'Q' && (@$parent['basetype'] == 'Q' || @$parent['basetype'] == 'A')) { $comment = $comment + qa_page_q_post_rules($comment, $parent, $children, null); // array union if (qa_page_q_single_click_c($comment, $question, $parent, $error)) { $comment = qa_db_select_with_pending(qa_db_full_post_selectspec($userid, $commentid)); // If so, page content to be updated via Ajax echo "QA_AJAX_RESPONSE\n1"; // If the comment was not deleted... if (isset($comment)) { $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 $comment = $comment + qa_page_q_post_rules($comment, $parent, $children, null); $usershtml = qa_userids_handles_html(array($comment), true); $c_view = qa_page_q_comment_view($question, $parent, $comment, $usershtml, false); $themeclass = qa_load_theme_class(qa_get_site_theme(), 'ajax-comment', null, null); // ... send back the HTML for it echo "\n"; $themeclass->c_list_item($c_view); } return;
function qa_recalc_perform_step(&$state) { $continue = false; @(list($operation, $length, $next, $done) = explode("\t", $state)); switch ($operation) { case 'doreindexcontent': qa_recalc_transition($state, 'doreindexcontent_pagereindex'); break; case 'doreindexcontent_pagereindex': $pages = qa_db_pages_get_for_reindexing($next, 10); if (count($pages)) { require_once QA_INCLUDE_DIR . 'app/format.php'; $lastpageid = max(array_keys($pages)); foreach ($pages as $pageid => $page) { if (!($page['flags'] & QA_PAGE_FLAGS_EXTERNAL)) { $searchmodules = qa_load_modules_with('search', 'unindex_page'); foreach ($searchmodules as $searchmodule) { $searchmodule->unindex_page($pageid); } $searchmodules = qa_load_modules_with('search', 'index_page'); if (count($searchmodules)) { $indextext = qa_viewer_text($page['content'], 'html'); foreach ($searchmodules as $searchmodule) { $searchmodule->index_page($pageid, $page['tags'], $page['heading'], $page['content'], 'html', $indextext); } } } } $next = 1 + $lastpageid; $done += count($pages); $continue = true; } else { qa_recalc_transition($state, 'doreindexcontent_postcount'); } break; case 'doreindexcontent_postcount': qa_db_qcount_update(); qa_db_acount_update(); qa_db_ccount_update(); qa_recalc_transition($state, 'doreindexcontent_postreindex'); break; case 'doreindexcontent_postreindex': $posts = qa_db_posts_get_for_reindexing($next, 10); if (count($posts)) { require_once QA_INCLUDE_DIR . 'app/format.php'; $lastpostid = max(array_keys($posts)); qa_db_prepare_for_reindexing($next, $lastpostid); qa_suspend_update_counts(); foreach ($posts as $postid => $post) { qa_post_unindex($postid); qa_post_index($postid, $post['type'], $post['questionid'], $post['parentid'], $post['title'], $post['content'], $post['format'], qa_viewer_text($post['content'], $post['format']), $post['tags'], $post['categoryid']); } $next = 1 + $lastpostid; $done += count($posts); $continue = true; } else { qa_db_truncate_indexes($next); qa_recalc_transition($state, 'doreindexposts_wordcount'); } break; case 'doreindexposts_wordcount': $wordids = qa_db_words_prepare_for_recounting($next, 1000); if (count($wordids)) { $lastwordid = max($wordids); qa_db_words_recount($next, $lastwordid); $next = 1 + $lastwordid; $done += count($wordids); $continue = true; } else { qa_db_tagcount_update(); // this is quick so just do it here qa_recalc_transition($state, 'doreindexposts_complete'); } break; case 'dorecountposts': qa_recalc_transition($state, 'dorecountposts_postcount'); break; case 'dorecountposts_postcount': qa_db_qcount_update(); qa_db_acount_update(); qa_db_ccount_update(); qa_db_unaqcount_update(); qa_db_unselqcount_update(); qa_recalc_transition($state, 'dorecountposts_votecount'); break; case 'dorecountposts_votecount': $postids = qa_db_posts_get_for_recounting($next, 1000); if (count($postids)) { $lastpostid = max($postids); qa_db_posts_votes_recount($next, $lastpostid); $next = 1 + $lastpostid; $done += count($postids); $continue = true; } else { qa_recalc_transition($state, 'dorecountposts_acount'); } break; case 'dorecountposts_acount': $postids = qa_db_posts_get_for_recounting($next, 1000); if (count($postids)) { $lastpostid = max($postids); qa_db_posts_answers_recount($next, $lastpostid); $next = 1 + $lastpostid; $done += count($postids); $continue = true; } else { qa_db_unupaqcount_update(); qa_recalc_transition($state, 'dorecountposts_complete'); } break; case 'dorecalcpoints': qa_recalc_transition($state, 'dorecalcpoints_usercount'); break; case 'dorecalcpoints_usercount': qa_db_userpointscount_update(); // for progress update - not necessarily accurate qa_db_uapprovecount_update(); // needs to be somewhere and this is the most appropriate place qa_recalc_transition($state, 'dorecalcpoints_recalc'); break; case 'dorecalcpoints_recalc': $recalccount = 10; $userids = qa_db_users_get_for_recalc_points($next, $recalccount + 1); // get one extra so we know where to start from next $gotcount = count($userids); $recalccount = min($recalccount, $gotcount); // can't recalc more than we got if ($recalccount > 0) { $lastuserid = $userids[$recalccount - 1]; qa_db_users_recalc_points($next, $lastuserid); $done += $recalccount; } else { $lastuserid = $next; } // for truncation if ($gotcount > $recalccount) { // more left to do $next = $userids[$recalccount]; // start next round at first one not recalculated $continue = true; } else { qa_db_truncate_userpoints($lastuserid); qa_db_userpointscount_update(); // quick so just do it here qa_recalc_transition($state, 'dorecalcpoints_complete'); } break; case 'dorefillevents': qa_recalc_transition($state, 'dorefillevents_qcount'); break; case 'dorefillevents_qcount': qa_db_qcount_update(); qa_recalc_transition($state, 'dorefillevents_refill'); break; case 'dorefillevents_refill': $questionids = qa_db_qs_get_for_event_refilling($next, 1); if (count($questionids)) { require_once QA_INCLUDE_DIR . 'app/events.php'; require_once QA_INCLUDE_DIR . 'app/updates.php'; require_once QA_INCLUDE_DIR . 'util/sort.php'; $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; 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); qa_db_posts_calc_category_path($next, $lastpostid); $next = 1 + $lastpostid; $done += count($postids); $continue = true; } else { qa_recalc_transition($state, 'dorecalccategories_recount'); } break; case 'dorecalccategories_recount': $categoryids = qa_db_categories_get_for_recalcs($next, 10); if (count($categoryids)) { $lastcategoryid = max($categoryids); foreach ($categoryids as $categoryid) { qa_db_ifcategory_qcount_update($categoryid); } $next = 1 + $lastcategoryid; $done += count($categoryids); $continue = true; } else { qa_recalc_transition($state, 'dorecalccategories_backpaths'); } break; case 'dorecalccategories_backpaths': $categoryids = qa_db_categories_get_for_recalcs($next, 10); if (count($categoryids)) { $lastcategoryid = max($categoryids); qa_db_categories_recalc_backpaths($next, $lastcategoryid); $next = 1 + $lastcategoryid; $done += count($categoryids); $continue = true; } else { qa_recalc_transition($state, 'dorecalccategories_complete'); } break; case 'dodeletehidden': qa_recalc_transition($state, 'dodeletehidden_comments'); break; case 'dodeletehidden_comments': $posts = qa_db_posts_get_for_deleting('C', $next, 1); if (count($posts)) { require_once QA_INCLUDE_DIR . 'app/posts.php'; $postid = $posts[0]; qa_post_delete($postid); $next = 1 + $postid; $done++; $continue = true; } else { qa_recalc_transition($state, 'dodeletehidden_answers'); } break; case 'dodeletehidden_answers': $posts = qa_db_posts_get_for_deleting('A', $next, 1); if (count($posts)) { require_once QA_INCLUDE_DIR . 'app/posts.php'; $postid = $posts[0]; qa_post_delete($postid); $next = 1 + $postid; $done++; $continue = true; } else { qa_recalc_transition($state, 'dodeletehidden_questions'); } break; case 'dodeletehidden_questions': $posts = qa_db_posts_get_for_deleting('Q', $next, 1); if (count($posts)) { require_once QA_INCLUDE_DIR . 'app/posts.php'; $postid = $posts[0]; qa_post_delete($postid); $next = 1 + $postid; $done++; $continue = true; } else { qa_recalc_transition($state, 'dodeletehidden_complete'); } break; case 'doblobstodisk': qa_recalc_transition($state, 'doblobstodisk_move'); break; case 'doblobstodisk_move': $blob = qa_db_get_next_blob_in_db($next); if (isset($blob)) { require_once QA_INCLUDE_DIR . 'app/blobs.php'; require_once QA_INCLUDE_DIR . 'db/blobs.php'; if (qa_write_blob_file($blob['blobid'], $blob['content'], $blob['format'])) { qa_db_blob_set_content($blob['blobid'], null); } $next = 1 + $blob['blobid']; $done++; $continue = true; } else { qa_recalc_transition($state, 'doblobstodisk_complete'); } break; case 'doblobstodb': qa_recalc_transition($state, 'doblobstodb_move'); break; case 'doblobstodb_move': $blob = qa_db_get_next_blob_on_disk($next); if (isset($blob)) { require_once QA_INCLUDE_DIR . 'app/blobs.php'; require_once QA_INCLUDE_DIR . 'db/blobs.php'; $content = qa_read_blob_file($blob['blobid'], $blob['format']); qa_db_blob_set_content($blob['blobid'], $content); qa_delete_blob_file($blob['blobid'], $blob['format']); $next = 1 + $blob['blobid']; $done++; $continue = true; } else { qa_recalc_transition($state, 'doblobstodb_complete'); } break; default: $state = ''; break; } if ($continue) { $state = $operation . "\t" . $length . "\t" . $next . "\t" . $done; } return $continue && $done < $length; }
function qa_get_user_email($userid) { $userinfo = qa_db_select_with_pending(qa_db_user_account_selectspec($userid, true)); return $userinfo['email']; }
function qa_page_q_edit_q_submit($question, $answers, $commentsfollows, $closepost, &$in, &$errors) { $in = array(); if ($question['editable']) { $in['title'] = qa_post_text('q_title'); qa_get_post_content('q_editor', 'q_content', $in['editor'], $in['content'], $in['format'], $in['text']); $in['extra'] = qa_opt('extra_field_active') ? qa_post_text('q_extra') : null; } if ($question['retagcatable']) { if (qa_using_tags()) { $in['tags'] = qa_get_tags_field_value('q_tags'); } if (qa_using_categories()) { $in['categoryid'] = qa_get_category_field_value('q_category'); } } if (array_key_exists('categoryid', $in)) { // need to check if we can move it to that category, and if we need moderation $categories = qa_db_select_with_pending(qa_db_category_nav_selectspec($in['categoryid'], true)); $categoryids = array_keys(qa_category_path($categories, $in['categoryid'])); $userlevel = qa_user_level_for_categories($categoryids); } else { $userlevel = null; } if ($question['isbyuser']) { $in['name'] = qa_post_text('q_name'); $in['notify'] = qa_post_text('q_notify') ? true : false; $in['email'] = qa_post_text('q_email'); } if (!qa_user_post_permit_error('permit_edit_silent', $question)) { $in['silent'] = qa_post_text('q_silent'); } // here the $in array only contains values for parts of the form that were displayed, so those are only ones checked by filters $errors = array(); if (!qa_check_form_security_code('edit-' . $question['postid'], qa_post_text('code'))) { $errors['page'] = qa_lang_html('misc/form_security_again'); } else { $in['queued'] = qa_opt('moderate_edited_again') && qa_user_moderation_reason($userlevel); $filtermodules = qa_load_modules_with('filter', 'filter_question'); foreach ($filtermodules as $filtermodule) { $oldin = $in; $filtermodule->filter_question($in, $errors, $question); if ($question['editable']) { qa_update_post_text($in, $oldin); } } if (array_key_exists('categoryid', $in) && strcmp($in['categoryid'], $question['categoryid'])) { if (qa_user_permit_error('permit_post_q', null, $userlevel)) { $errors['categoryid'] = qa_lang_html('question/category_ask_not_allowed'); } } if (empty($errors)) { $userid = qa_get_logged_in_userid(); $handle = qa_get_logged_in_handle(); $cookieid = qa_cookie_get(); // now we fill in the missing values in the $in array, so that we have everything we need for qa_question_set_content() // we do things in this way to avoid any risk of a validation failure on elements the user can't see (e.g. due to admin setting changes) if (!$question['editable']) { $in['title'] = $question['title']; $in['content'] = $question['content']; $in['format'] = $question['format']; $in['text'] = qa_viewer_text($in['content'], $in['format']); $in['extra'] = $question['extra']; } if (!isset($in['tags'])) { $in['tags'] = qa_tagstring_to_tags($question['tags']); } if (!array_key_exists('categoryid', $in)) { $in['categoryid'] = $question['categoryid']; } if (!isset($in['silent'])) { $in['silent'] = false; } $setnotify = $question['isbyuser'] ? qa_combine_notify_email($question['userid'], $in['notify'], $in['email']) : $question['notify']; qa_question_set_content($question, $in['title'], $in['content'], $in['format'], $in['text'], qa_tags_to_tagstring($in['tags']), $setnotify, $userid, $handle, $cookieid, $in['extra'], @$in['name'], $in['queued'], $in['silent']); if (qa_using_categories() && strcmp($in['categoryid'], $question['categoryid'])) { qa_question_set_category($question, $in['categoryid'], $userid, $handle, $cookieid, $answers, $commentsfollows, $closepost, $in['silent']); } return true; } } return false; }
function qa_flag_set_tohide($post, $userid, $handle, $cookieid, $question) { require_once QA_INCLUDE_DIR . 'qa-db-votes.php'; require_once QA_INCLUDE_DIR . 'qa-app-limits.php'; qa_db_userflag_set($post['postid'], $userid, true); qa_db_post_recount_flags($post['postid']); switch ($post['basetype']) { case 'Q': $action = 'q_flag'; break; case 'A': $action = 'a_flag'; break; case 'C': $action = 'c_flag'; break; } qa_report_write_action($userid, null, $action, $post['basetype'] == 'Q' ? $post['postid'] : null, $post['basetype'] == 'A' ? $post['postid'] : null, $post['basetype'] == 'C' ? $post['postid'] : null); qa_report_event($action, $userid, $handle, $cookieid, array('postid' => $post['postid'])); $post = qa_db_select_with_pending(qa_db_full_post_selectspec(null, $post['postid'])); $flagcount = $post['flagcount']; $notifycount = $flagcount - qa_opt('flagging_notify_first'); if ($notifycount >= 0 && $notifycount % qa_opt('flagging_notify_every') == 0) { require_once QA_INCLUDE_DIR . 'qa-app-emails.php'; require_once QA_INCLUDE_DIR . 'qa-app-format.php'; $anchor = $post['basetype'] == 'Q' ? null : qa_anchor($post['basetype'], $post['postid']); qa_send_notification(null, qa_opt('feedback_email'), null, qa_lang('emails/flagged_subject'), qa_lang('emails/flagged_body'), array('^p_handle' => isset($post['handle']) ? $post['handle'] : qa_lang('main/anonymous'), '^flags' => $flagcount == 1 ? qa_lang_html_sub('main/1_flag', '1', '1') : qa_lang_html_sub('main/x_flags', $flagcount), '^p_context' => trim(@$post['title'] . "\n\n" . qa_viewer_text($post['content'], $post['format'])), '^url' => qa_path(qa_q_request($question['postid'], $question['title']), null, qa_opt('site_url'), null, $anchor))); } if ($flagcount >= qa_opt('flagging_hide_after') && !$post['hidden']) { return true; } return false; }