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 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.'; }
} break; } } if (count($inprofile)) { $filtermodules = qa_load_modules_with('filter', 'filter_profile'); foreach ($filtermodules as $filtermodule) { $filtermodule->filter_profile($inprofile, $errors, $useraccount, $userprofile); } } foreach ($userfields as $userfield) { if (!isset($errors[$userfield['fieldid']])) { qa_db_user_profile_set($userid, $userfield['title'], $inprofile[$userfield['fieldid']]); } } list($useraccount, $userprofile) = qa_db_select_with_pending(qa_db_user_account_selectspec($userid, true), qa_db_user_profile_selectspec($userid, true)); qa_report_event('u_save', $userid, $useraccount['handle'], qa_cookie_get()); if (empty($errors)) { qa_redirect('account', array('state' => 'profile-saved')); } qa_logged_in_user_flush(); } } // Process change password if clicked if (qa_clicked('dochangepassword')) { require_once QA_INCLUDE_DIR . 'qa-app-users-edit.php'; $inoldpassword = qa_post_text('oldpassword'); $innewpassword1 = qa_post_text('newpassword1'); $innewpassword2 = qa_post_text('newpassword2'); if (!qa_check_form_security_code('password', qa_post_text('code'))) { $errors['page'] = qa_lang_html('misc/form_security_again');
function cs_user_profile($handle, $field = NULL) { $userid = qa_handle_to_userid($handle); if (defined('QA_WORDPRESS_INTEGRATE_PATH')) { return get_user_meta($userid); } else { $query = qa_db_select_with_pending(qa_db_user_profile_selectspec($userid, true)); if (!$field) { return $query; } if (isset($query[$field])) { return $query[$field]; } } return false; }
function check_user_fields($userid, $params) { 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'); qa_badge_award_check($badges, false, $userid); } // profile completion $missing = false; foreach ($userfields as $userfield) { if (!isset($userprofile[$userfield['title']]) || @$userprofile[$userfield['title']] === '') { $missing = true; break; } } if (!$missing) { $badges = array('profiler'); qa_badge_award_check($badges, false, $userid); } }
function get_username($userid) { if (QA_FINAL_EXTERNAL_USERS) { $obj = get_userdata($userid); return $obj->display_name; } else { $userprofile = qa_db_select_with_pending(qa_db_user_profile_selectspec($userid, true)); return @$userprofile['name'] ? $userprofile['name'] : qa_get_logged_in_handle(); } }
function doctype() { if (strpos($this->request, 'user/') !== false && strpos($this->request, 'articles') !== false) { $this->request = 'user-articles'; } /* ADAPT USER PAGES AND SUBPAGES */ if ($this->template == 'user' || $this->template == 'user-wall' || $this->template == 'user-activity' || $this->template == 'user-questions' || $this->template == 'user-answers' || $this->request == 'user-articles') { $handle = qa_request_part(1); if (!strlen($handle)) { $handle = qa_get_logged_in_handle(); qa_redirect(isset($handle) ? 'user/' . $handle : 'users'); } $identifier = QA_FINAL_EXTERNAL_USERS ? $userid : $handle; list($useraccount, $userprofile, $userfields, $usermessages, $userpoints, $userlevels, $navcategories, $userrank) = qa_db_select_with_pending(QA_FINAL_EXTERNAL_USERS ? null : qa_db_user_account_selectspec($handle, false), QA_FINAL_EXTERNAL_USERS ? null : qa_db_user_profile_selectspec($handle, false), QA_FINAL_EXTERNAL_USERS ? null : qa_db_userfields_selectspec(), QA_FINAL_EXTERNAL_USERS ? null : qa_db_recent_messages_selectspec(null, null, $handle, false, qa_opt_if_loaded('page_size_wall')), qa_db_user_points_selectspec($identifier), qa_db_user_levels_selectspec($identifier, QA_FINAL_EXTERNAL_USERS, true), qa_db_category_nav_selectspec(null, true), qa_db_user_rank_selectspec($identifier)); $userid = $useraccount['userid']; $loginuserid = qa_get_logged_in_userid(); if ($this->template == 'user') { // ADAPT FORM CONTENTS /*$this->content['form_activity']['fields']['activity'] = array('type'=>'static', 'label'=>'Recent Activity', 'value'=>'<a href="'.$handle.'/activity">show</a>');*/ // ADD PRIVATE MESSAGE LINK AFTER MEMBERSHIP DURATION if (qa_opt('allow_private_messages') && isset($loginuserid) && $loginuserid != $userid && !($useraccount['flags'] & QA_USER_FLAGS_NO_MESSAGES)) { $this->content['form_profile']['fields']['duration']['value'] .= strtr(qa_lang_html('profile/send_private_message'), array('^1' => '<a href="' . qa_path_html('message/' . $handle) . '">', '^2' => '</a>')); } } $site_url = qa_opt('site_url'); // RENEW THE SUB-NAVIGATION unset($this->content['navigation']['sub']); $this->content['navigation']['sub']['account'] = array('label' => 'User ' . $handle, 'url' => $site_url . '/user/' . $handle, 'selected' => $this->template == 'user' ? 1 : 0); $this->content['navigation']['sub']['wall'] = array('label' => $handle . '\'s Wall', 'url' => $site_url . '/user/' . $handle . '/wall', 'selected' => $this->template == 'user-wall' ? 1 : 0); $this->content['navigation']['sub']['activity'] = array('label' => qa_lang('qa_blog_lang/nav_activity'), 'url' => $site_url . '/user/' . $handle . '/activity', 'selected' => $this->template == 'user-activity' ? 1 : 0); $this->content['navigation']['sub']['questions'] = array('label' => qa_lang('qa_blog_lang/nav_questions'), 'url' => $site_url . '/user/' . $handle . '/questions', 'selected' => $this->template == 'user-questions' ? 1 : 0); $this->content['navigation']['sub']['answers'] = array('label' => qa_lang('qa_blog_lang/nav_answers'), 'url' => $site_url . '/user/' . $handle . '/answers', 'selected' => $this->template == 'user-answers' ? 1 : 0); $this->content['navigation']['sub']['articles'] = array('label' => qa_lang('qa_blog_lang/nav_articles'), 'url' => $site_url . '/user/' . $handle . '/articles', 'selected' => $this->request == 'user-articles' ? 1 : 0); $this->content['navigation']['sub']['newarticles'] = array('label' => qa_lang('qa_blog_lang/new_articles'), 'url' => $site_url . '/articles', 'selected' => $this->request == 'articles' ? 1 : 0); if ($this->request == 'user-articles') { unset($this->content['title']); $this->content['title'] = qa_lang('qa_blog_lang/title_recent') . " {$handle}"; unset($this->content['suggest_next']); unset($this->content['error']); if ($this->request == 'user-articles') { $qa_content['custom'] = ""; $html = ""; $result = qa_db_query_sub("SELECT * FROM ^blog_posts WHERE userid = '{$userid}' ORDER BY posted DESC"); $i = 0; while ($article = mysqli_fetch_array($result)) { $i++; $html .= article_item($article['title'], $site_url . '/blog/' . $article['postid'] . '/' . seoUrl2($article['title']) . '/', $article['posted'], $article['views']); } if ($i == 0) { $html = "<h3>" . qa_lang('qa_blog_lang/oops') . " {$handle} " . qa_lang('qa_blog_lang/no_post') . "</h3>"; } $this->content['custom'] = $html; } } } else { if ($this->template == 'account' || $this->template == 'favorites' || $this->template == 'updates' || $this->request == 'gallery' || $this->request == 'articles') { // ADAPT FORM FOR DETAILS SUBPAGE // RENEW THE SUB-NAVIGATION unset($this->content['navigation']['sub']); $this->content['navigation']['sub']['account'] = array('label' => 'My Details', 'url' => './account', 'selected' => $this->template == 'account' ? 1 : 0); $this->content['navigation']['sub']['favorites'] = array('label' => 'My Favorites', 'url' => './favorites', 'selected' => $this->template == 'favorites' ? 1 : 0); $this->content['navigation']['sub']['updates'] = array('label' => 'My Updates', 'url' => './updates', 'selected' => $this->template == 'updates' ? 1 : 0); $this->content['navigation']['sub']['articles'] = array('label' => 'My Articles', 'url' => './articles', 'selected' => $this->request == 'articles' ? 1 : 0); } else { if ($this->template == 'users') { require_once QA_INCLUDE_DIR . 'qa-db-users.php'; require_once QA_INCLUDE_DIR . 'qa-db-selects.php'; require_once QA_INCLUDE_DIR . 'qa-app-format.php'; $start = qa_get_start(); $users = qa_db_select_with_pending(qa_db_top_users_selectspec($start, qa_opt_if_loaded('page_size_users'))); $usercount = qa_opt('cache_userpointscount'); $pagesize = qa_opt('page_size_users'); $users = array_slice($users, 0, $pagesize); $usershtml = qa_userids_handles_html($users); // CHANGE TITLE $this->content['title'] = 'Users'; $this->content['ranking'] = array('items' => array(), 'rows' => ceil($pagesize / qa_opt('columns_users')), 'type' => 'users'); if (count($users)) { foreach ($users as $userid => $user) { $this->content['ranking']['items'][] = array('label' => (QA_FINAL_EXTERNAL_USERS ? qa_get_external_avatar_html($user['userid'], qa_opt('avatar_users_size'), true) : qa_get_user_avatar_html($user['flags'], $user['email'], $user['handle'], $user['avatarblobid'], $user['avatarwidth'], $user['avatarheight'], qa_opt('avatar_users_size'), true)) . ' ' . $usershtml[$user['userid']], 'score' => qa_html(number_format($user['points']))); } } else { $this->content['title'] = qa_lang_html('main/no_active_users'); } $this->content['page_links'] = qa_html_page_links(qa_request(), $start, $pagesize, $usercount, qa_opt('pages_prev_next')); // EMPTY SUB-NAVIGATION $this->content['navigation']['sub'] = null; } } } if ($this->template == 'questions') { unset($this->content['navigation']['sub']); $this->content['navigation']['sub']['account'] = array('label' => 'My Details', 'url' => './account', 'selected' => 0); //print_r ($this->content['navigation']); } if ($this->request == 'login') { $this->content['form']['fields']['password']['note'] = '<a href="/forgot">I forgot my password</a> - <a href="/register">Register</a>'; } qa_html_theme_base::doctype(); }