function qa_permit_check($opt) { if (qa_opt($opt) == QA_PERMIT_POINTS) { return qa_get_logged_in_points() >= qa_opt($opt . '_points'); } return !qa_permit_value_error(qa_opt($opt), qa_get_logged_in_userid(), qa_get_logged_in_level(), qa_get_logged_in_flags()); }
function qa_page_q_post_rules($post, $parentpost = null, $siblingposts = null, $childposts = null) { $rules = qa_page_q_post_rules_base($post, $parentpost, $siblingposts, $childposts); qa_db_query_sub('CREATE TABLE IF NOT EXISTS ^postmeta ( meta_id bigint(20) unsigned NOT NULL AUTO_INCREMENT, post_id bigint(20) unsigned NOT NULL, meta_key varchar(255) DEFAULT \'\', meta_value longtext, PRIMARY KEY (meta_id), KEY post_id (post_id), KEY meta_key (meta_key) ) ENGINE=MyISAM DEFAULT CHARSET=utf8'); $expert = qa_db_read_one_value(qa_db_query_sub("SELECT meta_value FROM ^postmeta WHERE meta_key='is_expert_question' AND post_id=#", $post['postid']), true); if ($expert) { if (!qa_permit_value_error(qa_opt('expert_question_roles'), qa_get_logged_in_userid(), qa_get_logged_in_level(), qa_get_logged_in_flags())) { $is_expert = true; } $users = qa_opt('expert_question_users'); $users = explode("\n", $users); $handle = qa_get_logged_in_handle(); foreach ($users as $idx => $user) { if ($user == $handle) { $is_expert = true; break; } if (strpos($user, '=')) { $user = explode('=', $user); if ($user[0] == $handle) { $catnames = explode(',', $user[1]); $cats = qa_db_read_all_values(qa_db_query_sub('SELECT categoryid FROM ^categories WHERE title IN ($)', $catnames)); $is_expert = $cats; } } } if (isset($is_expert) && !$rules['viewable']) { // experts that aren't allowed to change hidden questions if (is_array($is_expert)) { $in_cats = qa_db_read_one_value(qa_db_query_sub("SELECT COUNT(postid) FROM ^posts WHERE categoryid IN (#) AND postid=#", $is_expert, $post['postid']), true); if ($in_cats) { $rules['viewable'] = true; } } else { $rules['viewable'] = true; } } $rules['reshowable'] = false; $rules['answerbutton'] = true; $rules['commentbutton'] = true; $rules['commentable'] = true; } return $rules; }
function logged_in() { if (qa_is_logged_in()) { // output user avatar to login bar $this->output('<div class="qa-logged-in-avatar">', QA_FINAL_EXTERNAL_USERS ? qa_get_external_avatar_html(qa_get_logged_in_userid(), 24, true) : qa_get_user_avatar_html(qa_get_logged_in_flags(), qa_get_logged_in_email(), qa_get_logged_in_handle(), qa_get_logged_in_user_field('avatarblobid'), qa_get_logged_in_user_field('avatarwidth'), qa_get_logged_in_user_field('avatarheight'), 24, true), '</div>'); } qa_html_theme_base::logged_in(); if (qa_is_logged_in()) { // adds points count after logged in username $userpoints = qa_get_logged_in_points(); $pointshtml = $userpoints == 1 ? qa_lang_html_sub('main/1_point', '1', '1') : qa_lang_html_sub('main/x_points', qa_html(number_format($userpoints))); $this->output('<span class="qa-logged-in-points">', '(' . $pointshtml . ')', '</span>'); } }
function is_expert_user() { if (!qa_permit_value_error(qa_opt('expert_question_roles'), qa_get_logged_in_userid(), qa_get_logged_in_level(), qa_get_logged_in_flags())) { return true; } $users = qa_opt('expert_question_users'); $users = explode("\n", $users); $handle = qa_get_logged_in_handle(); foreach ($users as $idx => $user) { if ($user == $handle) { return true; } if (strpos($user, '=')) { $user = explode('=', $user); if ($user[0] == $handle) { $catnames = explode(',', $user[1]); $cats = qa_db_read_all_values(qa_db_query_sub('SELECT categoryid FROM ^categories WHERE title IN ($)', $catnames)); return $cats; } } } return false; }
if (!qa_check_form_security_code('message-' . $handle, qa_post_text('code'))) { $pageerror = qa_lang_html('misc/form_security_again'); } else { if (empty($inmessage)) { $errors['message'] = qa_lang('misc/message_empty'); } if (empty($errors)) { require_once QA_INCLUDE_DIR . 'qa-db-messages.php'; require_once QA_INCLUDE_DIR . 'qa-app-emails.php'; if (qa_opt('show_message_history')) { $messageid = qa_db_message_create($loginuserid, $toaccount['userid'], $inmessage, '', false); } else { $messageid = null; } $fromhandle = qa_get_logged_in_handle(); $canreply = !(qa_get_logged_in_flags() & QA_USER_FLAGS_NO_MESSAGES); $more = strtr(qa_lang($canreply ? 'emails/private_message_reply' : 'emails/private_message_info'), array('^f_handle' => $fromhandle, '^url' => qa_path_absolute($canreply ? 'message/' . $fromhandle : 'user/' . $fromhandle))); $subs = array('^message' => $inmessage, '^f_handle' => $fromhandle, '^f_url' => qa_path_absolute('user/' . $fromhandle), '^more' => $more, '^a_url' => qa_path_absolute('account')); if (qa_send_notification($toaccount['userid'], $toaccount['email'], $toaccount['handle'], qa_lang('emails/private_message_subject'), qa_lang('emails/private_message_body'), $subs)) { $messagesent = true; } else { $pageerror = qa_lang_html('main/general_error'); } qa_report_event('u_message', $loginuserid, qa_get_logged_in_handle(), qa_cookie_get(), array('userid' => $toaccount['userid'], 'handle' => $toaccount['handle'], 'messageid' => $messageid, 'message' => $inmessage)); if ($messagesent && qa_opt('show_message_history')) { // show message as part of general history qa_redirect(qa_request(), array('state' => 'message-sent')); } } } }
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-limits.php'; require_once QA_INCLUDE_DIR . 'qa-app-updates.php'; // $handle, $userhtml are already set by qa-page-user.php - also $userid if using external user integration // Redirect to 'My Account' page if button clicked if (qa_clicked('doaccount')) { qa_redirect('account'); } // Find the user profile and questions and answers for this handle $loginuserid = qa_get_logged_in_userid(); $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)); if (!QA_FINAL_EXTERNAL_USERS) { foreach ($userfields as $index => $userfield) { if (isset($userfield['permit']) && qa_permit_value_error($userfield['permit'], $loginuserid, qa_get_logged_in_level(), qa_get_logged_in_flags())) { unset($userfields[$index]); } } } // don't pay attention to user fields we're not allowed to view // Check the user exists and work out what can and can't be set (if not using single sign-on) $errors = array(); $loginlevel = qa_get_logged_in_level(); if (!QA_FINAL_EXTERNAL_USERS) { // if we're using integrated user management, we can know and show more require_once QA_INCLUDE_DIR . 'qa-app-messages.php'; if (!is_array($userpoints) && !is_array($useraccount)) { return include QA_INCLUDE_DIR . 'qa-page-not-found.php'; } $userid = $useraccount['userid'];
function qa_navigation_add_page(&$navigation, $page) { if (!qa_permit_value_error($page['permit'], qa_get_logged_in_userid(), qa_get_logged_in_level(), qa_get_logged_in_flags()) || !isset($page['permit'])) { $url = qa_custom_page_url($page); $navigation[$page['flags'] & QA_PAGE_FLAGS_EXTERNAL ? 'custom-' . $page['pageid'] : $page['tags'] . '$'] = array('url' => qa_html($url), 'label' => qa_html($page['title']), 'opposite' => $page['nav'] == 'O', 'target' => $page['flags'] & QA_PAGE_FLAGS_NEW_WINDOW ? '_blank' : null, 'selected' => $page['flags'] & QA_PAGE_FLAGS_EXTERNAL && ($url == qa_path(qa_request()) || $url == qa_self_html())); } }
function qa_user_use_captcha($captchaoption) { $usecaptcha = false; if (qa_opt($captchaoption)) { $userid = qa_get_logged_in_userid(); if (!isset($userid) || !(QA_FINAL_EXTERNAL_USERS || !qa_opt('captcha_on_unconfirmed') || !qa_opt('confirm_user_emails') || qa_get_logged_in_level() >= QA_USER_LEVEL_EXPERT || qa_get_logged_in_flags() & QA_USER_FLAGS_EMAIL_CONFIRMED)) { $usecaptcha = true; } } return $usecaptcha; }
function ra_user_avatar() { if (qw_hook_exist(__FUNCTION__)) { $args = func_get_args(); array_unshift($args, $this); return qw_event_hook(__FUNCTION__, $args, NULL); } if (qa_is_logged_in()) { // output user avatar to login bar $img_html = QA_FINAL_EXTERNAL_USERS ? qa_get_external_avatar_html(qa_get_logged_in_userid(), 24, true) : qa_get_user_avatar_html(qa_get_logged_in_flags(), qa_get_logged_in_email(), qa_get_logged_in_handle(), qa_get_logged_in_user_field('avatarblobid'), qa_get_logged_in_user_field('avatarwidth'), qa_get_logged_in_user_field('avatarheight'), 24, true); preg_match('@src="([^"]+)"@', $img_html, $match); $this->output($match[1]); } }
function get_user_data() { $userid = qa_get_logged_in_userid(); $user = array(); $user['userid'] = $userid; if (QA_FINAL_EXTERNAL_USERS) { $obj = get_userdata($userid); $user['display_name'] = $obj->display_name; $user['username'] = $obj->user_nicename; } else { $userprofile = qa_db_select_with_pending(qa_db_user_profile_selectspec($userid, true)); $user['display_name'] = @$userprofile['name'] ? $userprofile['name'] : qa_get_logged_in_handle(); $user['username'] = qa_get_logged_in_handle(); } $user['level'] = qa_get_logged_in_level(); $user['flags'] = qa_get_logged_in_flags(); return $user; }
function site_top() { $this->output('<div id="site-top" class="container">'); $this->page_title_error(); if (qa_is_logged_in()) { // output user avatar to login bar $this->output('<div class="qa-logged-in-avatar">', QA_FINAL_EXTERNAL_USERS ? qa_get_external_avatar_html(qa_get_logged_in_userid(), 24, true) : qa_get_user_avatar_html(qa_get_logged_in_flags(), qa_get_logged_in_email(), qa_get_logged_in_handle(), qa_get_logged_in_user_field('avatarblobid'), qa_get_logged_in_user_field('avatarwidth'), qa_get_logged_in_user_field('avatarheight'), 24, true), '</div>'); } else { $this->output('<ul class="pull-right top-buttons clearfix">', '<li><a href="#" class="btn">' . qa_lang_html('cleanstrap/login') . '</a></li>', '<li><a href="#" class="btn">' . qa_lang_html('cleanstrap/register') . '</a></li>', '</ul>'); } $this->output('</div>'); }
function qw_get_email_body($event = "") { if (!!$event) { switch ($event) { case 'a_post': $value = qa_lang("notification/a_post_body_email"); break; case 'c_post': $value = qa_lang("notification/c_post_body_email"); break; case 'q_reshow': $value = qa_lang("notification/q_reshow_body_email"); break; case 'a_reshow': $value = qa_lang("notification/a_reshow_body_email"); break; case 'c_reshow': $value = qa_lang("notification/c_reshow_body_email"); break; case 'a_select': $value = qa_lang("notification/a_select_body_email"); break; case 'q_vote_up': $value = qa_lang("notification/q_vote_up_body_email"); break; case 'a_vote_up': $value = qa_lang("notification/a_vote_up_body_email"); break; case 'q_vote_down': $value = qa_lang("notification/q_vote_down_body_email"); break; case 'a_vote_down': $value = qa_lang("notification/a_vote_down_body_email"); break; case 'q_vote_nil': $value = qa_lang("notification/q_vote_nil_body_email"); break; case 'a_vote_nil': $value = qa_lang("notification/a_vote_nil_body_email"); break; case 'q_approve': $value = qa_lang("notification/q_approve_body_email"); break; case 'a_approve': $value = qa_lang("notification/a_approve_body_email"); break; case 'c_approve': $value = qa_lang("notification/c_approve_body_email"); break; case 'q_reject': $value = qa_lang("notification/q_reject_body_email"); break; case 'a_reject': $value = qa_lang("notification/a_reject_body_email"); break; case 'c_reject': $value = qa_lang("notification/c_reject_body_email"); break; case 'q_favorite': $value = qa_lang("notification/q_favorite_body_email"); break; case 'q_post': case 'q_post_user_fl': case 'q_post_tag_fl': case 'q_post_cat_fl': $value = qa_lang("notification/q_post_body_email"); break; case 'u_favorite': $value = qa_lang("notification/u_favorite_body_email"); break; case 'u_message': $body = qa_lang("notification/u_message_body_email"); $canreply = !(qa_get_logged_in_flags() & QA_USER_FLAGS_NO_MESSAGES); $more = qa_lang($canreply ? 'notification/u_message_reply_email' : 'notification/u_message_info'); return $body . $more; break; case 'u_wall_post': $value = qa_lang("notification/u_wall_post_body_email"); break; case 'u_level': $value = qa_lang("notification/u_level_body_email"); break; case 'related': $value = qa_lang("notification/related_body_email"); break; default: break; } return $value; } }
function qw_notify_users_by_email($event, $postid, $userid, $effecteduserid, $params) { if (!!$effecteduserid) { //get the working user data $logged_in_handle = qa_get_logged_in_handle(); $logged_in_user_name = qw_get_name_from_userid($userid); $logged_in_user_name = !!$logged_in_user_name ? $logged_in_user_name : $logged_in_handle; $name = qw_get_name_from_userid($effecteduserid); switch ($event) { case 'a_post': case 'related': $parent = isset($params['parent']) ? $params['parent'] : ""; if (!!$parent) { $name = !!$name ? $name : $parent['handle']; $email = $parent['email']; $handle = $parent['handle']; } else { //seems proper values are not available return; } break; case 'c_post': case 'q_reshow': case 'a_reshow': case 'c_reshow': case 'a_select': case 'q_vote_up': case 'q_vote_down': case 'a_vote_up': case 'a_vote_down': case 'q_favorite': case 'u_favorite': case 'u_message': case 'u_wall_post': case 'u_level': case 'q_post_user_fl': case 'q_post_tag_fl': case 'q_post_cat_fl': //this is because we wont have the $parent['email'] for each effected userids when a these selected events occurs $user_details = qw_get_user_details_from_userid($effecteduserid); $handle = $user_details['handle']; $name = !!$name ? $name : $user_details['handle']; $email = $user_details['email']; break; case 'q_approve': case 'q_reject': $oldquestion = $params['oldquestion']; $handle = $oldquestion['handle']; $name = !!$name ? $name : $oldquestion['handle']; $email = $oldquestion['email']; break; case 'a_approve': case 'a_reject': $oldanswer = $params['oldanswer']; $handle = $oldquestion['handle']; $name = !!$name ? $name : $oldanswer['handle']; $email = $oldanswer['email']; break; case 'c_approve': case 'c_reject': $oldcomment = $params['oldcomment']; $handle = $oldcomment['handle']; $name = !!$name ? $name : $oldcomment['handle']; $email = $oldcomment['email']; break; default: break; } include_once QA_INCLUDE_DIR . 'qa-util-string.php'; $notifying_user['userid'] = $effecteduserid; $notifying_user['name'] = $name; $notifying_user['email'] = $email; $notifying_user['handle'] = isset($handle) ? $handle : qa_lang('main/anonymous'); //consider only first 50 characters for saving notification if ($event === 'u_message') { $content = isset($params['message']) && !empty($params['message']) ? $params['message'] : ""; $title = ""; $canreply = !(qa_get_logged_in_flags() & QA_USER_FLAGS_NO_MESSAGES); $url = qa_path_absolute($canreply ? 'message/' . $logged_in_handle : 'user/' . $logged_in_handle); } else { if ($event === 'u_wall_post') { $content = isset($params['text']) && !empty($params['text']) ? $params['text'] : ""; if (!!$content) { $blockwordspreg = qa_get_block_words_preg(); $content = qa_block_words_replace($content, $blockwordspreg); } $title = ""; $url = qa_path_absolute('user/' . $params['handle'] . '/wall', null, null); } else { if ($event === 'u_level') { $title = ""; $url = qa_path_absolute('user/' . $params['handle']); $old_level = $params['oldlevel']; $new_level = $params['level']; if ($new_level < $old_level) { return; } $approved_only = ""; if ($new_level == QA_USER_LEVEL_APPROVED && $old_level < QA_USER_LEVEL_APPROVED) { $approved_only = true; } else { $approved_only = false; } if ($approved_only === false) { $new_designation = qw_get_user_desg($new_level); } $content = strtr(qa_lang($approved_only ? 'notification/u_level_approved_body_email' : 'notification/u_level_improved_body_email'), array('^done_by' => isset($logged_in_user_name) ? $logged_in_user_name : isset($logged_in_handle) ? $logged_in_handle : qa_lang('main/anonymous'), '^new_designation' => @$new_designation)); } else { if ($event === "q_post_user_fl" || $event === "q_post_tag_fl" || $event === "q_post_cat_fl") { $content = isset($params['text']) && !empty($params['text']) ? $params['text'] : ""; //shrink the email body content if (!!$content && strlen($content) > 50) { $content = qw_shrink_email_body($content, 50); } $title = isset($params['title']) && !empty($params['title']) ? $params['title'] : ""; $url = qa_q_path($params['postid'], $title, true); } else { $content = isset($params['text']) && !empty($params['text']) ? $params['text'] : ""; //shrink the email body content if (!!$content && strlen($content) > 50) { $content = qw_shrink_email_body($content, 50); } $title = isset($params['qtitle']) && !empty($params['qtitle']) ? $params['qtitle'] : ""; $url = qa_q_path($params['qid'], $title, true); } } } } $q_handle = isset($logged_in_user_name) ? $logged_in_user_name : isset($logged_in_handle) ? $logged_in_handle : qa_lang('main/anonymous'); qw_save_email_notification(null, $notifying_user, $logged_in_handle, $event, array('^q_handle' => $q_handle, '^q_title' => $title, '^q_content' => $content, '^url' => !!$url ? $url : "", '^done_by' => $q_handle, '^author_link' => qa_path_absolute('user/' . $q_handle), '^author_pic' => qa_path_absolute('user/' . $q_handle), '^handle' => $handle)); } }
$slugs = array_slice($requestparts, 1); } elseif (strlen($requestparts[0])) { $slugs = $requestparts; } else { $slugs = array(); } $countslugs = count($slugs); // Get list of questions, other bits of information that might be useful $userid = qa_get_logged_in_userid(); list($questions1, $questions2, $categories, $categoryid, $custompage) = qa_db_select_with_pending(qa_db_qs_selectspec($userid, 'created', 0, $slugs, null, false, false, qa_opt_if_loaded('page_size_activity')), qa_db_recent_a_qs_selectspec($userid, 0, $slugs), qa_db_category_nav_selectspec($slugs, false, false, true), $countslugs ? qa_db_slugs_to_category_id_selectspec($slugs) : null, $countslugs == 1 && !$explicitqa ? qa_db_page_full_selectspec($slugs[0], false) : null); // First, if this matches a custom page, return immediately with that page's content if (isset($custompage) && !($custompage['flags'] & QA_PAGE_FLAGS_EXTERNAL)) { qa_set_template('custom-' . $custompage['pageid']); $qa_content = qa_content_prepare(); $level = qa_get_logged_in_level(); if (!qa_permit_value_error($custompage['permit'], $userid, $level, qa_get_logged_in_flags()) || !isset($custompage['permit'])) { $qa_content['title'] = qa_html($custompage['heading']); $qa_content['custom'] = $custompage['content']; if ($level >= QA_USER_LEVEL_ADMIN) { $qa_content['navigation']['sub'] = array('admin/pages' => array('label' => qa_lang('admin/edit_custom_page'), 'url' => qa_path_html('admin/pages', array('edit' => $custompage['pageid'])))); } } else { $qa_content['error'] = qa_lang_html('users/no_permission'); } return $qa_content; } // Then, see if we should redirect because the 'qa' page is the same as the home page if ($explicitqa && !qa_is_http_post() && !qa_has_custom_home()) { qa_redirect(qa_category_path_request($categories, $categoryid), $_GET); } // Then, if there's a slug that matches no category, check page modules provided by plugins
function qa_content_prepare($voting = false, $categoryids = null) { if (qa_to_override(__FUNCTION__)) { $args = func_get_args(); return qa_call_override(__FUNCTION__, $args); } global $qa_template, $qa_page_error_html; if (QA_DEBUG_PERFORMANCE) { global $qa_usage; $qa_usage->mark('control'); } $request = qa_request(); $requestlower = qa_request(); $navpages = qa_db_get_pending_result('navpages'); $widgets = qa_db_get_pending_result('widgets'); if (isset($categoryids) && !is_array($categoryids)) { // accept old-style parameter $categoryids = array($categoryids); } $lastcategoryid = count($categoryids) ? end($categoryids) : null; $charset = 'utf-8'; $qa_content = array('content_type' => 'text/html; charset=' . $charset, 'charset' => $charset, 'direction' => qa_opt('site_text_direction'), 'site_title' => qa_html(qa_opt('site_title')), 'head_lines' => array(), 'navigation' => array('user' => array(), 'main' => array(), 'footer' => array('feedback' => array('url' => qa_path_html('feedback'), 'label' => qa_lang_html('main/nav_feedback')))), 'sidebar' => qa_opt('show_custom_sidebar') ? qa_opt('custom_sidebar') : null, 'sidepanel' => qa_opt('show_custom_sidepanel') ? qa_opt('custom_sidepanel') : null, 'widgets' => array()); if (qa_opt('show_custom_in_head')) { $qa_content['head_lines'][] = qa_opt('custom_in_head'); } if (qa_opt('show_custom_header')) { $qa_content['body_header'] = qa_opt('custom_header'); } if (qa_opt('show_custom_footer')) { $qa_content['body_footer'] = qa_opt('custom_footer'); } if (isset($categoryids)) { $qa_content['categoryids'] = $categoryids; } foreach ($navpages as $page) { if ($page['nav'] == 'B') { qa_navigation_add_page($qa_content['navigation']['main'], $page); } } if (qa_opt('nav_home') && qa_opt('show_custom_home')) { $qa_content['navigation']['main']['$'] = array('url' => qa_path_html(''), 'label' => qa_lang_html('main/nav_home')); } if (qa_opt('nav_activity')) { $qa_content['navigation']['main']['activity'] = array('url' => qa_path_html('activity'), 'label' => qa_lang_html('main/nav_activity')); } $hascustomhome = qa_has_custom_home(); if (qa_opt($hascustomhome ? 'nav_qa_not_home' : 'nav_qa_is_home')) { $qa_content['navigation']['main'][$hascustomhome ? 'qa' : '$'] = array('url' => qa_path_html($hascustomhome ? 'qa' : ''), 'label' => qa_lang_html('main/nav_qa')); } if (qa_opt('nav_questions')) { $qa_content['navigation']['main']['questions'] = array('url' => qa_path_html('questions'), 'label' => qa_lang_html('main/nav_qs')); } if (qa_opt('nav_hot')) { $qa_content['navigation']['main']['hot'] = array('url' => qa_path_html('hot'), 'label' => qa_lang_html('main/nav_hot')); } if (qa_opt('nav_unanswered')) { $qa_content['navigation']['main']['unanswered'] = array('url' => qa_path_html('unanswered'), 'label' => qa_lang_html('main/nav_unanswered')); } if (qa_using_tags() && qa_opt('nav_tags')) { $qa_content['navigation']['main']['tag'] = array('url' => qa_path_html('tags'), 'label' => qa_lang_html('main/nav_tags'), 'selected_on' => array('tags$', 'tag/')); } if (qa_using_categories() && qa_opt('nav_categories')) { $qa_content['navigation']['main']['categories'] = array('url' => qa_path_html('categories'), 'label' => qa_lang_html('main/nav_categories'), 'selected_on' => array('categories$', 'categories/')); } if (qa_opt('nav_users')) { $qa_content['navigation']['main']['user'] = array('url' => qa_path_html('users'), 'label' => qa_lang_html('main/nav_users'), 'selected_on' => array('users$', 'users/', 'user/')); } // Only the 'level' permission error prevents the menu option being shown - others reported on qa-page-ask.php if (qa_opt('nav_ask') && qa_user_maximum_permit_error('permit_post_q') != 'level') { $qa_content['navigation']['main']['ask'] = array('url' => qa_path_html('ask', qa_using_categories() && strlen($lastcategoryid) ? array('cat' => $lastcategoryid) : null), 'label' => qa_lang_html('main/nav_ask')); } if (qa_get_logged_in_level() >= QA_USER_LEVEL_ADMIN || !qa_user_maximum_permit_error('permit_moderate') || !qa_user_maximum_permit_error('permit_hide_show') || !qa_user_maximum_permit_error('permit_delete_hidden')) { $qa_content['navigation']['main']['admin'] = array('url' => qa_path_html('admin'), 'label' => qa_lang_html('main/nav_admin'), 'selected_on' => array('admin/')); } $qa_content['search'] = array('form_tags' => 'method="get" action="' . qa_path_html('search') . '"', 'form_extra' => qa_path_form_html('search'), 'title' => qa_lang_html('main/search_title'), 'field_tags' => 'name="q"', 'button_label' => qa_lang_html('main/search_button')); if (!qa_opt('feedback_enabled')) { unset($qa_content['navigation']['footer']['feedback']); } foreach ($navpages as $page) { if ($page['nav'] == 'M' || $page['nav'] == 'O' || $page['nav'] == 'F') { qa_navigation_add_page($qa_content['navigation'][$page['nav'] == 'F' ? 'footer' : 'main'], $page); } } $regioncodes = array('F' => 'full', 'M' => 'main', 'S' => 'side'); $placecodes = array('T' => 'top', 'H' => 'high', 'L' => 'low', 'B' => 'bottom'); foreach ($widgets as $widget) { if (is_numeric(strpos(',' . $widget['tags'] . ',', ',' . $qa_template . ',')) || is_numeric(strpos(',' . $widget['tags'] . ',', ',all,'))) { // see if it has been selected for display on this template $region = @$regioncodes[substr($widget['place'], 0, 1)]; $place = @$placecodes[substr($widget['place'], 1, 2)]; if (isset($region) && isset($place)) { // check region/place codes recognized $module = qa_load_module('widget', $widget['title']); if (isset($module) && method_exists($module, 'allow_template') && $module->allow_template(substr($qa_template, 0, 7) == 'custom-' ? 'custom' : $qa_template) && method_exists($module, 'allow_region') && $module->allow_region($region) && method_exists($module, 'output_widget')) { $qa_content['widgets'][$region][$place][] = $module; } // if module loaded and happy to be displayed here, tell theme about it } } } $logoshow = qa_opt('logo_show'); $logourl = qa_opt('logo_url'); $logowidth = qa_opt('logo_width'); $logoheight = qa_opt('logo_height'); if ($logoshow) { $qa_content['logo'] = '<a href="' . qa_path_html('') . '" class="qa-logo-link" title="' . qa_html(qa_opt('site_title')) . '">' . '<img src="' . qa_html(is_numeric(strpos($logourl, '://')) ? $logourl : qa_path_to_root() . $logourl) . '"' . ($logowidth ? ' width="' . $logowidth . '"' : '') . ($logoheight ? ' height="' . $logoheight . '"' : '') . ' border="0" alt="' . qa_html(qa_opt('site_title')) . '"/></a>'; } else { $qa_content['logo'] = '<a href="' . qa_path_html('') . '" class="qa-logo-link">' . qa_html(qa_opt('site_title')) . '</a>'; } $topath = qa_get('to'); // lets user switch between login and register without losing destination page $userlinks = qa_get_login_links(qa_path_to_root(), isset($topath) ? $topath : qa_path($request, $_GET, '')); $qa_content['navigation']['user'] = array(); if (qa_is_logged_in()) { $qa_content['loggedin'] = qa_lang_html_sub_split('main/logged_in_x', QA_FINAL_EXTERNAL_USERS ? qa_get_logged_in_user_html(qa_get_logged_in_user_cache(), qa_path_to_root(), false) : qa_get_one_user_html(qa_get_logged_in_handle(), false)); $qa_content['navigation']['user']['updates'] = array('url' => qa_path_html('updates'), 'label' => qa_lang_html('main/nav_updates')); if (!empty($userlinks['logout'])) { $qa_content['navigation']['user']['logout'] = array('url' => qa_html(@$userlinks['logout']), 'label' => qa_lang_html('main/nav_logout')); } if (!QA_FINAL_EXTERNAL_USERS) { $source = qa_get_logged_in_source(); if (strlen($source)) { $loginmodules = qa_load_modules_with('login', 'match_source'); foreach ($loginmodules as $module) { if ($module->match_source($source) && method_exists($module, 'logout_html')) { ob_start(); $module->logout_html(qa_path('logout', array(), qa_opt('site_url'))); $qa_content['navigation']['user']['logout'] = array('label' => ob_get_clean()); } } } } $notices = qa_db_get_pending_result('notices'); foreach ($notices as $notice) { $qa_content['notices'][] = qa_notice_form($notice['noticeid'], qa_viewer_html($notice['content'], $notice['format']), $notice); } } else { require_once QA_INCLUDE_DIR . 'util/string.php'; if (!QA_FINAL_EXTERNAL_USERS) { $loginmodules = qa_load_modules_with('login', 'login_html'); foreach ($loginmodules as $tryname => $module) { ob_start(); $module->login_html(isset($topath) ? qa_opt('site_url') . $topath : qa_path($request, $_GET, qa_opt('site_url')), 'menu'); $label = ob_get_clean(); if (strlen($label)) { $qa_content['navigation']['user'][implode('-', qa_string_to_words($tryname))] = array('label' => $label); } } } if (!empty($userlinks['login'])) { $qa_content['navigation']['user']['login'] = array('url' => qa_html(@$userlinks['login']), 'label' => qa_lang_html('main/nav_login')); } if (!empty($userlinks['register'])) { $qa_content['navigation']['user']['register'] = array('url' => qa_html(@$userlinks['register']), 'label' => qa_lang_html('main/nav_register')); } } if (QA_FINAL_EXTERNAL_USERS || !qa_is_logged_in()) { if (qa_opt('show_notice_visitor') && !isset($topath) && !isset($_COOKIE['qa_noticed'])) { $qa_content['notices'][] = qa_notice_form('visitor', qa_opt('notice_visitor')); } } else { setcookie('qa_noticed', 1, time() + 86400 * 3650, '/', QA_COOKIE_DOMAIN); // don't show first-time notice if a user has logged in if (qa_opt('show_notice_welcome') && qa_get_logged_in_flags() & QA_USER_FLAGS_WELCOME_NOTICE) { if ($requestlower != 'confirm' && $requestlower != 'account') { // let people finish registering in peace $qa_content['notices'][] = qa_notice_form('welcome', qa_opt('notice_welcome')); } } } $qa_content['script_rel'] = array('qa-content/jquery-1.11.2.min.js'); $qa_content['script_rel'][] = 'qa-content/qa-page.js?' . QA_VERSION; if ($voting) { $qa_content['error'] = @$qa_page_error_html; } $qa_content['script_var'] = array('qa_root' => qa_path_to_root(), 'qa_request' => $request); return $qa_content; }
function qa_user_moderation_reason($userlevel = null) { if (qa_to_override(__FUNCTION__)) { $args = func_get_args(); return qa_call_override(__FUNCTION__, $args); } $reason = false; if (!isset($userlevel)) { $userlevel = qa_get_logged_in_level(); } if ($userlevel < QA_USER_LEVEL_EXPERT && qa_user_permit_error('permit_moderate')) { $userid = qa_get_logged_in_userid(); if (isset($userid)) { if (qa_opt('moderate_users') && qa_opt('moderate_unapproved') && $userlevel < QA_USER_LEVEL_APPROVED) { $reason = 'approve'; } elseif (qa_opt('confirm_user_emails') && qa_opt('moderate_unconfirmed') && !(qa_get_logged_in_flags() & QA_USER_FLAGS_EMAIL_CONFIRMED)) { $reason = 'confirm'; } elseif (qa_opt('moderate_by_points') && qa_get_logged_in_points() < qa_opt('moderate_points_limit')) { $reason = 'points'; } } elseif (qa_opt('moderate_anon_post')) { $reason = 'login'; } } return $reason; }
public function process_request($request) { // set up user $this->user = array('id' => qa_get_logged_in_userid(), 'handle' => qa_get_logged_in_handle(), 'flags' => qa_get_logged_in_flags(), 'level' => qa_get_logged_in_level()); // check if user is banned (kicked) $sql = 'SELECT kickeduntil, (kickeduntil-NOW() > 0) AS iskicked FROM ^chat_users WHERE userid=#'; $result = qa_db_query_sub($sql, $this->user['id']); $row = qa_db_read_one_assoc($result, true); $this->user['iskicked'] = @$row['iskicked']; $this->user['kickeduntil'] = @$row['kickeduntil']; // create dates for database $now = time(); $this->dates = array('posted' => gmdate('Y-m-d H:i:s', $now), 'posted_utc' => gmdate('Y-m-d\\TH:i:s\\Z', $now)); $opt_kicklevel = qa_opt($this->optkick); // AJAX: someone posted a message $message = qa_post_text('ajax_add_message'); if ($message !== null) { if (!$this->user_perms_post()) { echo "QA_AJAX_RESPONSE\n0\nYou are not allowed to post currently, sorry."; return; } // prevent just spaces $message = trim($message); if (strlen($message) == 0) { echo "QA_AJAX_RESPONSE\n0\nThe message you post must actually be something."; return; } $data = array('userid' => $this->user['id'], 'username' => $this->user['handle'], 'posted' => $this->dates['posted'], 'posted_utc' => $this->dates['posted_utc'], 'message' => $message); // save to database $data['postid'] = $this->post_message($data); $this->update_activity(true); $data['username'] = qa_html($data['username']); $data['message'] = $this->format_message($data['message']); header('Content-Type: text/plain; charset=utf-8'); echo "QA_AJAX_RESPONSE\n" . $this->user['id'] . "\n" . json_encode($data); return; } // AJAX: polling check; $lastid=0 on initial page load $lastid = qa_post_text('ajax_get_messages'); if ($lastid !== null) { if (!$this->user_perms_view()) { echo "QA_AJAX_RESPONSE\n0\nYou don't appear to be logged in. Please reload the page."; return; } if ($this->user_perms_kicked()) { echo "QA_AJAX_RESPONSE\n0\nYou have been kicked. Please reload the page."; return; } $this->update_activity($lastid == 0); $messages = $this->get_messages($lastid); $users = $this->users_online(); header('Content-Type: text/plain; charset=utf-8'); echo "QA_AJAX_RESPONSE\n" . $this->user['id'] . "\n" . json_encode($messages) . "\n" . json_encode($users); return; } // AJAX: request to kick user $kickuserid = qa_post_text('ajax_kick_userid'); $kickhandle = qa_post_text('ajax_kick_username'); if ($kickuserid !== null) { // make sure user is correct level as set in options if ($this->user['level'] < $opt_kicklevel) { echo "QA_AJAX_RESPONSE\n0\nYou are not allowed to do that currently, sorry."; return; } $this->kick_user($kickuserid, $kickhandle); header('Content-Type: text/plain; charset=utf-8'); echo "QA_AJAX_RESPONSE\n" . $this->user['id'] . "\nGave 'em a right kickin'!"; return; } // regular page request $qa_content = qa_content_prepare(); $qa_content['title'] = 'Chat Room'; $qa_content['script_rel'][] = $this->urltoroot . 'qa-chat.js?v=1.7'; if ($this->user_perms_post()) { $qa_content['custom_form'] = '<form method="post" id="qa-chat-form">' . ' <input id="message" class="qa-chat-post" type="text" name="ajax_add_message" autocomplete="off" maxlength="800">' . ' <input type="submit" value="Post">' . '</form>' . '<ul id="qa-chat-list"></ul>'; } else { if ($this->user_perms_kicked()) { $ktil_utc = gmdate('Y-m-d\\TH:i:s\\Z', strtotime($this->user['kickeduntil'])); $qa_content['error'] = 'Sorry, you have been kicked from chat temporarily. Take a few moments to chill.<br>' . 'The ban expires <span id="qa_chat_kickeduntil" data-utc="' . $ktil_utc . '" title="' . $ktil_utc . '">soon</span>' . '<script>$("#qa_chat_kickeduntil").timeago();</script>'; } else { if ($this->user_perms_view()) { $qa_content['error'] = 'Sorry, you are currently unable to post in chat. If you are new, you must confirm your email address.'; } else { $qa_content['error'] = qa_insert_login_links('Please ^1log in^2 or ^3register^4 to use the chat room.', $request); } } } return $qa_content; }