function AddCategoryToPost($params, $category) { require_once QA_INCLUDE_DIR . 'qa-db-post-update.php'; $postid = $params['postid']; $result = qa_db_read_one_assoc(qa_db_query_sub('SELECT categoryid,parentid,tags,title,content,qcount,position,backpath FROM ^categories WHERE title=$', $category), true); if (empty($result)) { //create category $tags = str_replace(' ', '-', $category); $catID = $this->CreatCategory($category, $tags); qa_db_post_set_category($postid, $catID, null, null); qa_db_posts_calc_category_path($postid); $path = qa_db_post_get_category_path($postid); qa_db_category_path_qcount_update($path); } else { // update category $oldpath = qa_db_post_get_category_path($postid); $tags = $result['tags']; $catID = $result['categoryid']; qa_db_post_set_category($postid, $catID, null, null); qa_db_posts_calc_category_path($postid); $path = qa_db_post_get_category_path($postid); qa_db_category_path_qcount_update($oldpath); qa_db_category_path_qcount_update($path); } }
function process_request($request) { // double check we are admin if (qa_get_logged_in_level() < QA_USER_LEVEL_ADMIN) { return; } if (qa_clicked('docancel')) { qa_redirect('admin/plugins'); } $qa_content = qa_content_prepare(); $qa_content['title'] = 'Widget Anywhere'; $qa_content['custom'] = '<p><a href="' . qa_path('admin/plugins') . '#' . qa_html($this->anchor) . '">« back to plugin options</a></p>'; $saved_msg = null; $editid = qa_get('editid'); if (qa_post_text('dodelete')) { $this->delete_widget(); qa_redirect('admin/plugins'); } else { if (qa_clicked('save_button')) { // save widget $widget = $this->save_widget(); $saved_msg = 'Widget saved.'; } else { if (empty($editid)) { // display blank form $widget = array('id' => 0, 'title' => '', 'pages' => '', 'position' => '', 'ordering' => 1, 'content' => ''); } else { // load specified widget $sql = 'SELECT * FROM ^' . $this->pluginkey . ' WHERE id=#'; $result = qa_db_query_sub($sql, $editid); $widget = qa_db_read_one_assoc($result); } } } $sel_position = empty($widget['position']) ? null : @$this->positionlangs[$widget['position']]; // set up page (template) list $widget_pages = explode(',', $widget['pages']); $sel_pages = array(); $custom_pages = array(); foreach ($widget_pages as $page) { if (strpos($page, 'custom:') === 0) { $custom_pages[] = substr($page, 7); } else { $sel_pages[] = $page; } } // $chkd = in_array('all', $sel_pages) ? 'checked' : ''; // $pages_html = '<label><input type="checkbox" name="wpages_all" ' . $chkd . '> ' . qa_lang_html('admin/widget_all_pages') . '</label><br><br>'; $pages_html = ''; foreach ($this->templatelangkeys as $tmpl => $langkey) { $chkd = in_array($tmpl, $sel_pages) ? 'checked' : ''; $pages_html .= '<label><input type="checkbox" name="wpages_' . $tmpl . '" ' . $chkd . '> ' . qa_lang_html($langkey) . '</label><br>'; } $qa_content['form'] = array('tags' => 'METHOD="POST" ACTION="' . qa_self_html() . '"', 'style' => 'tall', 'ok' => $saved_msg, 'fields' => array('title' => array('label' => 'Title', 'tags' => 'NAME="wtitle"', 'value' => qa_html($widget['title'])), 'position' => array('type' => 'select', 'label' => 'Position', 'tags' => 'NAME="wposition"', 'options' => $this->positionlangs, 'value' => $sel_position), 'all_pages' => array('type' => 'checkbox', 'id' => 'tb_pages_all', 'label' => qa_lang_html('admin/widget_all_pages'), 'tags' => 'NAME="wpages_all" ID="wpages_all"', 'value' => in_array('all', $sel_pages)), 'pages' => array('type' => 'custom', 'id' => 'tb_pages_list', 'label' => qa_lang_html('admin/widget_pages_explanation'), 'html' => $pages_html), 'show_custom_pages' => array('type' => 'checkbox', 'id' => 'tb_show_custom_pages', 'label' => 'Show on custom page(s)', 'tags' => 'NAME="cb_custom_pages" ID="cb_custom_pages"', 'value' => count($custom_pages) > 0), 'custom_pages' => array('id' => 'tb_custom_pages', 'label' => 'Page slugs', 'tags' => 'NAME="wpages_custom"', 'value' => qa_html(implode(',', $custom_pages)), 'note' => 'Separate multiple page slugs (URL fragments) with commas, e.g. <code>custom-page,other-page</code>'), 'ordering' => array('type' => 'number', 'label' => 'Order', 'tags' => 'NAME="wordering"', 'value' => qa_html($widget['ordering'])), 'content' => array('type' => 'textarea', 'label' => 'Content (HTML)', 'tags' => 'NAME="wcontent"', 'value' => qa_html($widget['content']), 'rows' => 12)), 'hidden' => array('wid' => $widget['id']), 'buttons' => array('save' => array('tags' => 'NAME="save_button"', 'label' => 'Save widget', 'value' => '1'), 'cancel' => array('tags' => 'NAME="docancel"', 'label' => qa_lang_html('main/cancel_button')))); if ($widget['id'] > 0) { $qa_content['form']['fields']['delete'] = array('tags' => 'NAME="dodelete"', 'label' => 'Delete widget', 'value' => 0, 'type' => 'checkbox'); } qa_set_display_rules($qa_content, array('tb_pages_list' => '!wpages_all', 'tb_show_custom_pages' => '!wpages_all', 'tb_custom_pages' => 'cb_custom_pages && !wpages_all')); return $qa_content; }
public function process_request($request) { require_once QA_INCLUDE_DIR . 'qa-app-posts.php'; // smiley replacement regexes $rxSearch = '<(img|a)([^>]+)(src|href)="([^"]+)/wysiwyg-editor/plugins/smiley/images/([^"]+)"'; $rxReplace = '<$1$2$3="$4/wysiwyg-editor/ckeditor/plugins/smiley/images/$5"'; qa_suspend_event_reports(true); // avoid infinite loop // prevent race conditions $locks = array('posts', 'categories', 'users', 'users AS lastusers', 'userpoints', 'words', 'titlewords', 'contentwords', 'tagwords', 'words AS x', 'posttags', 'options'); foreach ($locks as &$tbl) { $tbl = '^' . $tbl . ' WRITE'; } qa_db_query_sub('LOCK TABLES ' . implode(',', $locks)); $sql = 'SELECT postid, title, content FROM ^posts WHERE format="html" ' . 'AND content LIKE "%/wysiwyg-editor/plugins/smiley/images/%" ' . 'AND content RLIKE \'' . $rxSearch . '\' ' . 'LIMIT 5'; $result = qa_db_query_sub($sql); $numPosts = 0; while (($post = qa_db_read_one_assoc($result, true)) !== null) { $newcontent = preg_replace("#{$rxSearch}#", $rxReplace, $post['content']); qa_post_set_content($post['postid'], $post['title'], $newcontent); $numPosts++; } qa_db_query_raw('UNLOCK TABLES'); qa_suspend_event_reports(false); echo $numPosts; }
function qa_priv_notification($uid, $oid, $badge_slug) { require_once QA_INCLUDE_DIR . 'qa-app-users.php'; require_once QA_INCLUDE_DIR . 'qa-app-emails.php'; if (QA_FINAL_EXTERNAL_USERS) { $publictohandle = qa_get_public_from_userids(array($uid)); $handle = @$publictohandle[$uid]; } else { $user = qa_db_single_select(qa_db_user_account_selectspec($uid, true)); $handle = @$user['handle']; } $subject = qa_opt('badge_email_subject'); $body = qa_opt('badge_email_body'); $body = preg_replace('/\\^if_post_text="([^"]*)"/', $oid ? '$1' : '', $body); // if post text $site_url = qa_opt('site_url'); $profile_url = qa_path_html('user/' . $handle, null, $site_url); if ($oid) { $post = qa_db_read_one_assoc(qa_db_query_sub('SELECT * FROM ^posts WHERE postid=#', $oid), true); if ($post['parentid']) { $parent = qa_db_read_one_assoc(qa_db_query_sub('SELECT * FROM ^posts WHERE postid=#', $post['parentid']), true); } if (isset($parent)) { $anchor = urlencode(qa_anchor($post['basetype'], $oid)); $post_title = $parent['title']; $post_url = qa_path_html(qa_q_request($parent['postid'], $parent['title']), null, qa_opt('site_url'), null, $anchor); } else { $post_title = $post['title']; $post_url = qa_path_html(qa_q_request($post['postid'], $post['title']), null, qa_opt('site_url')); } } $subs = array('^badge_name' => qa_opt('badge_' . $badge_slug . '_name'), '^post_title' => @$post_title, '^post_url' => @$post_url, '^profile_url' => $profile_url, '^site_url' => $site_url); qa_send_notification($uid, '@', $handle, $subject, $body, $subs); }
function mp_get_categoryinfo($categoryid) { /* * Returns all the information for $categoryid * */ return qa_db_read_one_assoc(qa_db_query_sub('SELECT * FROM ^categories WHERE categoryid = #', $categoryid), true); }
function qa_db_blob_read($blobid) { if (qa_to_override(__FUNCTION__)) { $args = func_get_args(); return qa_call_override(__FUNCTION__, $args); } return qa_db_read_one_assoc(qa_db_query_sub('SELECT content, format, filename FROM ^blobs WHERE blobid=#', $blobid), true); }
function custom_badges_rebuild() { $awarded = 0; $userq = qa_db_query_sub('SELECT user_id, meta_value FROM ^usermeta WHERE meta_key=$', 'max_bookmarks'); while (($user = qa_db_read_one_assoc($userq, true)) !== null) { $badges = array('bookmarker', 'bookkeeper', 'bookworm'); $awarded += count(qa_badge_award_check($badges, (int) $user['meta_value'], $user['user_id'], null, 2)); } return $awarded; }
function custom_badges_rebuild() { $awarded = 0; $posts = qa_db_query_sub('SELECT userid, postid, netvotes FROM ^posts WHERE type=$ AND netvotes>0', 'C'); while (($post = qa_db_read_one_assoc($posts, true)) !== null) { $badges = array('nice_comment', 'good_comment', 'excellent_comment'); $awarded += count(qa_badge_award_check($badges, (int) $post['netvotes'], $post['userid'], $post['postid'], 2)); } return $awarded; }
function mp_get_contribution_points_by_userid($userid, $categoryid) { // retrieve raw points data $Qpoints = qa_db_read_one_assoc(qa_db_query_sub('SELECT 500 * COUNT(P.postid) points, 100 * COALESCE(SUM(P.upvotes),0) upvotes, 100 * COALESCE(SUM(P.downvotes),0) downvotes FROM ^posts P WHERE type = "Q" and categoryid = # and userid = #', $categoryid, $userid)); $Apoints = qa_db_read_one_assoc(qa_db_query_sub('SELECT 500 * COUNT(P.postid) points, 100 * COALESCE(SUM(P.upvotes),0) upvotes, 100 * COALESCE(SUM(P.downvotes),0) downvotes FROM ^posts P WHERE type = "A" AND categoryid = # AND userid = #', $categoryid, $userid)); return $Apoints['points'] + $Apoints['upvotes'] - $Apoints['downvotes']; }
/** *通过用户的id找到提问者的用户名 */ function getUsername($userid) { $query = "SELECT * FROM ^users WHERE userid=\$"; $arr = qa_db_query_sub($query, $userid); $result = qa_db_read_one_assoc($arr); if (count($result)) { return $result['handle']; } else { return null; } }
function qa_db_category_child_depth($categoryid) { // This is potentially a very slow query since it counts all the multi-generational offspring of a particular category // But it's only used for admin purposes when moving a category around so I don't think it's worth making more efficient // (Incidentally, this could be done by keeping a count for every category of how many generations of offspring it has.) $result = qa_db_read_one_assoc(qa_db_query_sub('SELECT COUNT(child1.categoryid) AS count1, COUNT(child2.categoryid) AS count2, COUNT(child3.categoryid) AS count3 FROM ^categories AS child1 LEFT JOIN ^categories AS child2 ON child2.parentid=child1.categoryid LEFT JOIN ^categories AS child3 ON child3.parentid=child2.categoryid WHERE child1.parentid=#;', $categoryid)); for ($depth = QA_CATEGORY_DEPTH - 1; $depth >= 1; $depth--) { if ($result['count' . $depth]) { return $depth; } } return 0; }
function output_widget($region, $place, $themeobject, $template, $request, $qa_content) { $temp = qa_db_query_sub('SELECT BINARY title as title, postid, netvotes, acount FROM ^posts WHERE type=$', 'Q'); $max = mysqli_num_rows($temp); if (!$max) { return; } $themeobject->output('<h2>' . qa_opt('random_question_title') . '</h2>'); for ($i = 0; $i < qa_opt('random_question_number'); $i++) { $rand = rand() / getrandmax() * $max; $check = mysqli_data_seek($temp, $rand); if (!$check) { $i--; } else { $random_question = qa_db_read_one_assoc($temp, true); } if (is_array($random_question)) { $votes = (int) $random_question['netvotes']; if ($votes > 0) { if ($votes > 1) { $votes = str_replace('^', '+' . $votes, qa_lang('main/x_votes')); } else { $votes = str_replace('1', '+1', qa_lang('main/1_vote')); } } else { if ($votes < 0) { if ($votes < -1) { $votes = str_replace('^', $votes, qa_lang('main/x_votes')); } else { $votes = str_replace('1', '-1', qa_lang('main/1_vote')); } } else { $votes = ''; } } $answers = (int) $random_question['acount']; if ($answers > 0) { if ($answers > 1) { $answers = str_replace('^', '+' . $answers, qa_lang('main/x_answers')); } else { $answers = qa_lang('main/1_answer'); } } else { $answers = ''; } $themeobject->output('<div class="random-question" style="padding-bottom:4px;"><a href="' . qa_path_html(qa_q_request($random_question['postid'], $random_question['title'])) . '">' . $random_question['title'] . '</a></div><div class="random-question-meta" style="padding-bottom:4px; border-bottom:1px solid; margin-bottom:2px;">' . $votes . ($votes && $answers ? ', ' : '') . $answers . '</div>'); } } }
function sendEmail($event, $userid, $handle, $params) { $email = $this->getEmail($userid); if ($email == qa_opt('feedback_email')) { return; } $parent = qa_db_read_one_assoc(qa_db_query_sub('SELECT * FROM ^posts WHERE postid=#', $params['parentid']), true); if ($parent['type'] == 'A') { $parent = qa_db_read_one_assoc(qa_db_query_sub('SELECT * FROM ^posts WHERE postid=#', $parent['parentid']), true); } $url = qa_q_path($parent['postid'], $parent['title'], true, $event == 'a_post' ? 'A' : 'C', $params['postid']); $title = $parent['title']; $type = $event == 'a_post' ? 'answer' : 'comment'; $subs = array(); qa_send_notification(null, qa_opt('feedback_email'), null, qa_lang('admin_plus/posted_subject'), qa_lang('admin_plus/posted_body'), array('^post_handle' => isset($handle) ? $handle : qa_lang('main/anonymous'), '^post_type' => $type, '^post_title' => $title, '^post_content' => $params['content'], '^site_url' => qa_opt('site_url'), '^url' => $url)); }
function doctype() { if (@$this->content['error'] == qa_lang_html('main/page_not_found') && preg_match('/^[0-9]+\\//', $this->request) !== false) { $pid = preg_replace('/\\/.*/', '', $this->request); $merged = qa_db_read_one_assoc(qa_db_query_sub("SELECT ^posts.postid as postid,^posts.title as title FROM ^postmeta, ^posts WHERE ^postmeta.meta_key='merged_with' AND ^postmeta.post_id=# AND ^posts.postid=^postmeta.meta_value", $pid), true); if ($merged) { qa_redirect(qa_q_request($merged['postid'], $merged['title']), array('merged' => $pid)); } } else { if (qa_get('merged')) { $this->content['error'] = str_replace('^post', qa_get('merged'), qa_opt('merge_question_merged')); } } if (qa_post_text('ajax_merge_get_from')) { return; } qa_html_theme_base::doctype(); }
function get_next_q() { $myurl = $this->request; $myurlpieces = explode("/", $myurl); $myurl = $myurlpieces[0]; if (is_numeric($myurl)) { $query_n = "SELECT ^posts.*,^categories.position\n\tFROM ^posts INNER JOIN ^categories ON ^posts.categoryid = ^categories.categoryid\n\tWHERE postid = {$myurl}\n\tAND type='Q'\n\tLIMIT 1"; $current_q = qa_db_query_sub($query_n); while ($current_link = qa_db_read_one_assoc($current_q, true)) { $categoryid = $current_link['categoryid']; $categoryposition = $current_link['position']; } $combinedid = $categoryposition * 1000000 - $myurl; $query_n = "SELECT ^posts.* \n\tFROM ^posts INNER JOIN ^categories ON ^posts.categoryid = ^categories.categoryid\n\tWHERE position*1000000-postid > {$combinedid} \n\tAND type='Q'\n\tORDER BY position*1000000-postid ASC\n\tLIMIT 1"; $next_q = qa_db_query_sub($query_n); while ($next_link = qa_db_read_one_assoc($next_q, true)) { $title = $next_link['title']; $pid = $next_link['postid']; $this->output(' <A HREF="' . qa_q_path_html($pid, $title) . '" title="' . $title . '" STYLE="float:right;padding-right:20px">Next Action <img style="border:0px;width:50px" src="../qa-theme/GreenTheme-CATO/next.png"/></A>', ''); } } }
/** * save category meta data if category is updated */ function init_page() { if (qa_clicked('dosavecategory') && !qa_clicked('docancel')) { require_once QA_INCLUDE_DIR . 'qa-db-metas.php'; $categoryid = qa_post_text('edit'); if (!empty($categoryid)) { // update admin/category form to save form's category meta data $et_category['et_cat_title'] = qa_post_text('et_category_link_title'); if (!isset($et_category['et_cat_title'])) { $et_category['et_cat_title'] = ''; } $et_category['et_cat_desc'] = qa_post_text('et_category_description'); if (!isset($et_category['et_cat_desc'])) { $et_category['et_cat_desc'] = ''; } $et_category['et_cat_icon48'] = qa_post_text('et_category_icon_48'); if (!isset($et_category['et_cat_icon48'])) { $et_category['et_cat_icon48'] = ''; } $et_category['et_cat_icon64'] = qa_post_text('et_category_icon_64'); if (!isset($et_category['et_cat_icon64'])) { $et_category['et_cat_icon64'] = ''; } qa_db_categorymeta_set($categoryid, 'et_category', json_encode($et_category)); } } // when loading question page after edit if category is updated, Q2A will attempt to Re-Update question category based on "q_category_X" field. // this happens when category already exists, and we attempt to change it while editing question. // here we will set category id to "q_category_1" field, so it wont change it to null after question is updated $questionid = qa_request_part(0); $num_questionid = (int) $questionid; if (qa_clicked('q_dosave') && $questionid == $num_questionid) { $result = qa_db_read_one_assoc(qa_db_query_sub('SELECT categoryid FROM ^posts WHERE postid=$', $num_questionid), true); $_POST['q_category_1'] = $result['categoryid']; } }
function output_widget($region, $place, $themeobject, $template, $request, $qa_content) { if (!qa_opt('event_logger_to_database')) { return; } $badges = qa_db_query_sub('SELECT event,handle,params, UNIX_TIMESTAMP(datetime) AS datetime FROM ^eventlog WHERE event=$' . (qa_opt('badge_widget_date_max') ? ' AND DATE_SUB(CURDATE(),INTERVAL ' . (int) qa_opt('badge_widget_date_max') . ' DAY) <= datetime' : '') . ' ORDER BY datetime DESC' . (qa_opt('badge_widget_list_max') ? ' LIMIT ' . (int) qa_opt('badge_widget_list_max') : ''), 'badge_awarded'); $first = true; while (($badge = qa_db_read_one_assoc($badges, true)) !== null) { $params = array(); $paramsa = explode("\t", $badge['params']); foreach ($paramsa as $param) { $parama = explode('=', $param); $params[$parama[0]] = $parama[1]; } $slug = $params['badge_slug']; $typea = qa_get_badge_type_by_slug($slug); if (!$typea) { continue; } $types = $typea['slug']; $typed = $typea['name']; $badge_name = qa_badge_name($slug); if (!qa_opt('badge_' . $slug . '_name')) { qa_opt('badge_' . $slug . '_name', $badge_name); } $var = qa_opt('badge_' . $slug . '_var'); $name = qa_opt('badge_' . $slug . '_name'); $desc = qa_badge_desc_replace($slug, $var, false); $string = '<span class="badge-' . $types . '" title="' . $desc . ' (' . $typed . ')">' . qa_html($name) . '<br/>- ' . $badge['handle'] . ' -</span>'; if ($first) { $themeobject->output('<h2>' . qa_lang('badges/badge_widget_title') . '</h2>'); $first = false; } $themeobject->output('<div class="badge-widget-entry" style="padding-top:8px;">', $string, '</div>'); } }
public function process_request($request) { @ini_set('display_errors', 0); // we don't want to show PHP errors inside XML header('Content-type: text/xml; charset=utf-8'); echo '<?xml version="1.0" encoding="UTF-8"?>' . "\n"; echo '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">' . "\n"; // Question pages if (qa_opt('xml_sitemap_show_questions')) { $hotstats = qa_db_read_one_assoc(qa_db_query_sub("SELECT MIN(hotness) AS base, MAX(hotness)-MIN(hotness) AS spread FROM ^posts WHERE type='Q'")); $nextpostid = 0; while (1) { $questions = qa_db_read_all_assoc(qa_db_query_sub("SELECT postid, title, hotness FROM ^posts WHERE postid>=# AND type='Q' ORDER BY postid LIMIT 100", $nextpostid)); if (!count($questions)) { break; } foreach ($questions as $question) { $this->sitemap_output(qa_q_request($question['postid'], $question['title']), 0.1 + 0.9 * ($question['hotness'] - $hotstats['base']) / (1 + $hotstats['spread'])); $nextpostid = max($nextpostid, $question['postid'] + 1); } } } // User pages if (!QA_FINAL_EXTERNAL_USERS && qa_opt('xml_sitemap_show_users')) { $nextuserid = 0; while (1) { $users = qa_db_read_all_assoc(qa_db_query_sub("SELECT userid, handle FROM ^users WHERE userid>=# ORDER BY userid LIMIT 100", $nextuserid)); if (!count($users)) { break; } foreach ($users as $user) { $this->sitemap_output('user/' . $user['handle'], 0.25); $nextuserid = max($nextuserid, $user['userid'] + 1); } } } // Tag pages if (qa_using_tags() && qa_opt('xml_sitemap_show_tag_qs')) { $nextwordid = 0; while (1) { $tagwords = qa_db_read_all_assoc(qa_db_query_sub("SELECT wordid, word, tagcount FROM ^words WHERE wordid>=# AND tagcount>0 ORDER BY wordid LIMIT 100", $nextwordid)); if (!count($tagwords)) { break; } foreach ($tagwords as $tagword) { $this->sitemap_output('tag/' . $tagword['word'], 0.5 / (1 + 1 / $tagword['tagcount'])); // priority between 0.25 and 0.5 depending on tag frequency $nextwordid = max($nextwordid, $tagword['wordid'] + 1); } } } // Question list for each category if (qa_using_categories() && qa_opt('xml_sitemap_show_category_qs')) { $nextcategoryid = 0; while (1) { $categories = qa_db_read_all_assoc(qa_db_query_sub("SELECT categoryid, backpath FROM ^categories WHERE categoryid>=# AND qcount>0 ORDER BY categoryid LIMIT 2", $nextcategoryid)); if (!count($categories)) { break; } foreach ($categories as $category) { $this->sitemap_output('questions/' . implode('/', array_reverse(explode('/', $category['backpath']))), 0.5); $nextcategoryid = max($nextcategoryid, $category['categoryid'] + 1); } } } // Pages in category browser if (qa_using_categories() && qa_opt('xml_sitemap_show_categories')) { $this->sitemap_output('categories', 0.5); $nextcategoryid = 0; while (1) { // only find categories with a child $categories = qa_db_read_all_assoc(qa_db_query_sub("SELECT parent.categoryid, parent.backpath FROM ^categories AS parent " . "JOIN ^categories AS child ON child.parentid=parent.categoryid WHERE parent.categoryid>=# GROUP BY parent.categoryid LIMIT 100", $nextcategoryid)); if (!count($categories)) { break; } foreach ($categories as $category) { $this->sitemap_output('categories/' . implode('/', array_reverse(explode('/', $category['backpath']))), 0.5); $nextcategoryid = max($nextcategoryid, $category['categoryid'] + 1); } } } echo "</urlset>\n"; return null; }
function post($event, $userid, $handle, $params, $type) { // remove mentions if (!qa_opt('buddypress_mentions')) { remove_filter('bp_activity_after_save', 'bp_activity_at_name_filter_updates'); } switch ($type) { case 'Q': $suffix = ' question '; break; case 'A': $suffix = 'n %answer% to the question '; break; case 'C': $suffix = ' %comment% on the question '; break; } // poll integration if (qa_post_text('is_poll')) { if ($type == 'A') { return; } if ($type == 'Q') { $suffix = str_replace('question', 'poll', $suffix); } else { $suffix = str_replace('question', 'poll', $suffix); } } $content = $params['content']; // activity post if ($event != 'q_post') { $parent = qa_db_read_one_assoc(qa_db_query_sub('SELECT * FROM ^posts WHERE postid=#', $params['parentid']), true); if ($parent['type'] == 'A') { $parent = qa_db_read_one_assoc(qa_db_query_sub('SELECT * FROM ^posts WHERE postid=#', $parent['parentid']), true); } $anchor = qa_anchor($event == 'a_post' ? 'A' : 'C', $params['postid']); $suffix = preg_replace('/%([^%]+)%/', '<a href="' . qa_path_html(qa_q_request($parent['postid'], $parent['title']), null, qa_opt('site_url'), null, $anchor) . '">$1</a>', $suffix); $activity_url = qa_path_html(qa_q_request($parent['postid'], $parent['title']), null, qa_opt('site_url')); $context = $suffix . '"<a href="' . $activity_url . '">' . $parent['title'] . '</a>"'; } else { $activity_url = qa_path_html(qa_q_request($params['postid'], $params['title']), null, qa_opt('site_url')); $context = $suffix . '"<a href="' . $activity_url . '">' . $params['title'] . '</a>"'; } if (qa_opt('buddypress_display_names')) { $name = bp_core_get_user_displayname($handle) ? bp_core_get_user_displayname($handle) : $handle; } else { $name = $handle; } $action = '<a href="' . bp_core_get_user_domain($userid) . '" rel="nofollow">' . $name . '</a> posted a' . $context . ' at <a href="' . qa_opt('site_url') . '">' . qa_opt('site_title') . '</a>'; if (qa_opt('buddypress_integration_include_content')) { $informat = $params['format']; $viewer = qa_load_viewer($content, $informat); if (qa_opt('buddypress_integration_max_post_length') && strlen($content) > (int) qa_opt('buddypress_integration_max_post_length')) { $content = substr($content, 0, (int) qa_opt('buddypress_integration_max_post_length')); $content = $content . ' ...'; } $content = $viewer->get_html($content, $informat, array()); } else { $content = null; } global $phpmailer; if (class_exists('PHPMailer') && !is_object($phpmailer)) { $phpmailer = new PHPMailer(true); } $act_id = qa_buddypress_activity_post(array('action' => $action, 'content' => $content, 'primary_link' => $activity_url, 'component' => 'bp-qa', 'type' => 'activity_qa_' . $type, 'user_id' => $userid, 'item_id' => null)); }
function doctype() { qa_html_theme_base::doctype(); if (qa_opt('badge_active')) { // tabs if ($this->template == 'user' && !qa_opt('badge_admin_user_field_no_tab')) { if (!isset($this->content['navigation']['sub'])) { $this->content['navigation']['sub'] = array('profile' => array('url' => qa_path_html('user/' . $this->_user_handle(), null, qa_opt('site_url')), 'label' => $this->_user_handle(), 'selected' => !qa_get('tab') ? true : false), 'badges' => array('url' => qa_path_html('user/' . $this->_user_handle(), array('tab' => 'badges'), qa_opt('site_url')), 'label' => qa_lang('badges/badges'), 'selected' => qa_get('tab') == 'badges' ? true : false)); } else { $this->content['navigation']['sub']['badges'] = array('url' => qa_path_html('user/' . $this->_user_handle(), array('tab' => 'badges'), qa_opt('site_url')), 'label' => qa_lang('badges/badges'), 'selected' => qa_get('tab') == 'badges' ? true : false); } } require_once QA_INCLUDE_DIR . 'qa-app-users.php'; $userid = qa_get_logged_in_userid(); if (!$userid) { return; } // not logged in? die. // first visit check $user = @qa_db_read_one_assoc(qa_db_query_sub('SELECT ^achievements.user_id AS uid,^achievements.oldest_consec_visit AS ocv,^achievements.longest_consec_visit AS lcv,^achievements.total_days_visited AS tdv,^achievements.last_visit AS lv,^achievements.first_visit AS fv, ^userpoints.points as points FROM ^achievements, ^userpoints WHERE ^achievements.user_id=# AND ^userpoints.userid=#', $userid, $userid), true); if (!$user['uid']) { qa_db_query_sub('INSERT INTO ^achievements (user_id, first_visit, oldest_consec_visit, longest_consec_visit, last_visit, total_days_visited, questions_read, posts_edited) VALUES (#, NOW(), NOW(), #, NOW(), #, #, #) ON DUPLICATE KEY UPDATE first_visit=NOW(), oldest_consec_visit=NOW(), longest_consec_visit=#, last_visit=NOW(), total_days_visited=#, questions_read=#, posts_edited=#', $userid, 1, 1, 0, 0, 1, 1, 0, 0); return; } // 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; $oldest_consec = strtotime($user['ocv']); $oldest_consecj = GregorianToJD(date('n', $oldest_consec), date('j', $oldest_consec), date('Y', $oldest_consec)); $oldest_consec_diff = $todayj - $oldest_consecj + 1; // include the first day $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; if ($last_diff < 0) { return; } // error if ($last_diff < 2) { // one day or less, update last visit if ($oldest_consec_diff > $user['lcv']) { $user['lcv'] = $oldest_consec_diff; qa_db_query_sub('UPDATE ^achievements SET last_visit=NOW(), longest_consec_visit=#, total_days_visited=total_days_visited+# WHERE user_id=#', $oldest_consec_diff, $last_diff, $userid); } else { qa_db_query_sub('UPDATE ^achievements SET last_visit=NOW(), total_days_visited=total_days_visited+# WHERE user_id=#', $last_diff, $userid); } $badges = array('dedicated', 'devoted', 'zealous'); qa_badge_award_check($badges, $user['lcv'], $userid, null, 2); } else { // 2+ days, reset consecutive days due to lapse qa_db_query_sub('UPDATE ^achievements SET last_visit=NOW(), oldest_consec_visit=NOW(), total_days_visited=total_days_visited+1 WHERE user_id=#', $userid); } $badges = array('visitor', 'trouper', 'veteran'); qa_badge_award_check($badges, $user['tdv'], $userid, null, 2); $badges = array('regular', 'old_timer', 'ancestor'); qa_badge_award_check($badges, $first_visit_diff, $userid, null, 2); // check points if (isset($user['points'])) { $badges = array('100_club', '1000_club', '10000_club'); qa_badge_award_check($badges, $user['points'], $userid, null, 2); } } }
for ($i = 0; $i < $u_sitemap_count; $i++) { echo '<p><a href="' . $siteurl . 'sitemap-users-' . $i . '.xml">' . 'sitemap-users-' . $i . '.xml' . '</a></p>'; } } // tag's list sitemap if (qa_opt('useo_sitemap_tags_enable')) { $t_sitemaps = qa_db_read_one_assoc(qa_db_query_sub("SELECT count(*) as total from ^words WHERE tagcount>0 ")); $count = qa_opt('useo_sitemap_tags_count'); $t_sitemap_count = ceil($t_sitemaps['total'] / $count); for ($i = 0; $i < $t_sitemap_count; $i++) { echo '<p><a href="' . $siteurl . 'sitemap-tags-' . $i . '.xml">' . 'sitemap-tags-' . $i . '.xml' . '</a></p>'; } } // categories's list sitemap if (qa_opt('useo_sitemap_categories_enable')) { echo '<p><a href="' . $siteurl . 'sitemap-category.xml">sitemap-category.xml' . '</a></p>'; } if (qa_opt('useo_sitemap_categoriy_q_enable')) { $categories = qa_db_read_all_assoc(qa_db_query_sub("SELECT categoryid, backpath FROM ^categories WHERE qcount>0 ORDER BY categoryid")); foreach ($categories as $category) { $backpath = $category['backpath']; $count = qa_opt('useo_sitemap_categoriy_q_count'); $qcount = qa_db_read_one_assoc(qa_db_query_sub('SELECT count(*) as total FROM ^posts WHERE ^posts.type=$ AND categoryid=(SELECT categoryid FROM ^categories WHERE ^categories.backpath=$ LIMIT 1)', 'Q', $backpath)); $category_slug = implode('-', array_reverse(explode('/', $category['backpath']))); $cat_count = ceil($qcount['total'] / $count); for ($i = 0; $i < $cat_count; $i++) { echo '<p><a href="' . $siteurl . 'sitemap-category-' . $category_slug . '-' . $i . '.xml">' . 'sitemap-category-' . $category_slug . '-' . $i . '.xml' . '</a></p>'; } } }
function sitemap_index() { // question list sitemap $q_sitemaps = qa_db_read_one_assoc(qa_db_query_sub("SELECT count(*) as total from ^posts WHERE type='Q'")); $count = qa_opt('useo_sitemap_question_count'); $q_sitemap_count = ceil($q_sitemaps['total'] / $count); for ($i = 0; $i < $q_sitemap_count; $i++) { $this->sitemap_index_output('sitemap-' . $i . '.xml'); } // user's list sitemap if (qa_opt('useo_sitemap_users_enable')) { $u_sitemaps = qa_db_read_one_assoc(qa_db_query_sub("SELECT count(*) as total from ^users")); $count = qa_opt('useo_sitemap_users_count'); $u_sitemap_count = ceil($u_sitemaps['total'] / $count); for ($i = 0; $i < $u_sitemap_count; $i++) { $this->sitemap_index_output('sitemap-users-' . $i . '.xml'); } } // tag's list sitemap if (qa_opt('useo_sitemap_tags_enable')) { $t_sitemaps = qa_db_read_one_assoc(qa_db_query_sub("SELECT count(*) as total from ^words WHERE tagcount>0 ")); $count = qa_opt('useo_sitemap_tags_count'); $t_sitemap_count = ceil($t_sitemaps['total'] / $count); for ($i = 0; $i < $t_sitemap_count; $i++) { $this->sitemap_index_output('sitemap-tags-' . $i . '.xml'); } } // categories's list sitemap if (qa_opt('useo_sitemap_categories_enable')) { $this->sitemap_index_output('sitemap-category.xml'); } }
function cs_get_cat_desc($slug) { $result = qa_db_read_one_assoc(qa_db_query_sub('SELECT title,content FROM ^categories WHERE tags=$', $slug), true); return $result; }
function get_post_data($id) { $result = qa_db_read_one_assoc(qa_db_query_sub('SELECT * FROM ^posts WHERE postid=#', $id), true); return $result; }
/** * Vote Call. * * @param array $args ($username, $password, $data['sort', 'start', 'cats', 'full', 'size', 'action', 'action_id', 'action_data']) * @return array (questions); * */ function call_vote($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]; $type = @$data['action_data']['type']; $vote = @$data['action_data']['vote']; if (!$this->login($username, $password)) { return $this->error; } $userid = qa_get_logged_in_userid(); $output = array(); if (isset($data['meta_data'])) { $output['meta_data'] = $this->get_meta_data(); } $output['confirmation'] = $this->do_vote($data); if ($output['confirmation']) { $output['message'] = qa_lang('xmlrpc/voted'); $output['confirmation'] = true; $info = @$data['action_data']; $questionid = (int) @$info['questionid']; if ($questionid) { $question = qa_db_read_one_assoc(qa_db_query_sub("SELECT ^posts.*, LEFT(^posts.type, 1) AS basetype, UNIX_TIMESTAMP(^posts.created) AS created, ^uservotes.vote as uservote FROM ^posts LEFT JOIN ^uservotes ON ^posts.postid=^uservotes.postid AND ^uservotes.userid=\$ WHERE ^posts.type='Q' AND ^posts.postid=#", $userid, $questionid), true); if ($question) { $output['data'] = $this->get_single_question($data, $question); } } } else { $output['message'] = qa_lang('xmlrpc/vote_error'); } return $output; }
function qa_db_post_get_category_path($postid) { return qa_db_read_one_assoc(qa_db_query_sub('SELECT categoryid, catidpath1, catidpath2, catidpath3 FROM ^posts WHERE postid=#', $postid)); // requires QA_CATEGORY_DEPTH=4 }
function qa_get_request_content() { $qa_content = qa_get_request_content_base(); // displays signature form in user profile $qa_request = strtolower(qa_request()); $reqs = explode('/', $qa_request); if ($reqs[0] == 'user') { // permissions if (isset($qa_content['form_profile']['fields']['permits'])) { $ov = $qa_content['form_profile']['fields']['permits']['value']; $ov = str_replace('[profile/signature_allow]', qa_lang('signature_plugin/signature_allow'), $ov); $ov = str_replace('[profile/signature_edit_allow]', qa_lang('signature_plugin/signature_edit_allow'), $ov); $qa_content['form_profile']['fields']['permits']['value'] = $ov; } $qa_content['user_signature_form'] = array(); $userid = @$qa_content['raw']['userid']; if (!$userid) { return $qa_content; } $handles = qa_userids_to_handles(array($userid)); $handle = $handles[$userid]; if (qa_get_logged_in_handle() == $handle && !qa_user_permit_error('signature_allow') || !qa_user_permit_error('signature_edit_allow')) { $ok = null; $formats = qa_list_modules('editor'); $format = qa_opt('signatures_format'); $editorname = $formats[$format]; if (!strlen($editorname)) { $editorname = qa_lang_html('admin/basic_editor'); } $editor = qa_load_editor('', '', $editorname); qa_db_query_sub('CREATE TABLE IF NOT EXISTS ^usersignatures (' . 'userid INT(11) NOT NULL,' . 'signature VARCHAR (1000) DEFAULT \'\',' . 'format VARCHAR (20) DEFAULT \'\',' . 'id INT(11) NOT NULL AUTO_INCREMENT,' . 'UNIQUE (userid),' . 'PRIMARY KEY (id)' . ') ENGINE=MyISAM DEFAULT CHARSET=utf8'); if (qa_clicked('signature_save')) { if (strlen(qa_post_text('signature_text')) > qa_opt('signatures_length')) { $error = 'Max possible signature length is 1000 characters'; } else { $readdata = $editor->read_post('signature_text'); $informat = $readdata['format']; $incontent = qa_post_text('signature_text'); qa_db_query_sub('INSERT INTO ^usersignatures (userid,signature,format) VALUES (#,$,$) ON DUPLICATE KEY UPDATE signature=$,format=$', $userid, $incontent, $informat, $incontent, $informat); $ok = 'Signature Saved.'; } } $content = qa_db_read_one_assoc(qa_db_query_sub('SELECT BINARY signature AS signature,format FROM ^usersignatures WHERE userid=#', $userid), true); $field = qa_editor_load_field($editor, $qa_content, $content['signature'], $content['format'], 'signature_text', 12, false); $field['label'] = qa_lang_html('signature_plugin/signature'); $fields['content'] = $field; if (!$editorname || $editorname == 'Markdown Editor') { $fields['elCount'] = array('label' => '<div id="elCount">' . qa_opt('signatures_length') . '</div>', 'type' => 'static'); } $form = array('ok' => $ok && !isset($error) ? $ok : null, 'error' => @$error, 'style' => 'tall', 'title' => '<a name="signature_text"></a>' . qa_lang_html('signature_plugin/signature'), 'tags' => 'action="' . qa_self_html() . '#signature_text" method="POST"', 'fields' => $fields, 'buttons' => array(array('label' => qa_lang_html('main/save_button'), 'tags' => 'NAME="signature_save"')), 'hidden' => array('editor' => qa_html($editorname), 'dosavesig' => '1')); $qa_content['user_signature_form'] = $form; } else { if (qa_opt('signatures_profile_enable')) { $content = qa_db_read_one_assoc(qa_db_query_sub('SELECT BINARY signature as signature, format FROM ^usersignatures WHERE userid=#', $userid), true); if (!$content) { return $qa_content; } $informat = $content['format']; $viewer = qa_load_viewer($content['signature'], $informat); global $options; $signature = qa_viewer_html($content['signature'], $informat, array('blockwordspreg' => @$options['blockwordspreg'], 'showurllinks' => @$options['showurllinks'], 'linksnewwindow' => @$options['linksnewwindow'])); $fields[] = array('label' => qa_opt('signatures_header') . $signature . qa_opt('signatures_footer'), 'type' => 'static'); $qa_content['user_signature_form'] = array('title' => 'Signature', 'fields' => $fields, 'style' => 'tall'); } } } return $qa_content; }
function qa_db_get_next_blob_on_disk($startblobid) { return qa_db_read_one_assoc(qa_db_query_sub('SELECT blobid, format FROM ^blobs WHERE blobid>=# AND content IS NULL', $startblobid), true); }
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.'; }
function _questions_stats($handle) { $sql_count = 'SELECT u.userid, count(p.postid) AS qs, count(p.selchildid) AS selected FROM ^posts p, ^users u WHERE p.type="Q" AND u.userid=p.userid AND u.handle=$'; $result = qa_db_query_sub($sql_count, $handle); $row = qa_db_read_one_assoc($result); return array($row['userid'], $row['qs'], $row['selected']); }