function mp_announcement_create($userid, $handle, $cookieid, $title, $content, $format, $text, $notify, $categoryid) { /* * Proceeds to create an announcement * */ require_once QA_INCLUDE_DIR . 'qa-db-post-create.php'; require_once QA_INCLUDE_DIR . 'qa-app-emails.php'; require_once QA_INCLUDE_DIR . 'mp-app-users.php'; // persist data to database $postid = qa_db_post_create('AN', null, $userid, $cookieid, qa_remote_ip_address(), $title, $content, $format, null, $notify, $categoryid); qa_user_report_action(qa_get_logged_in_userid(), null, null, null, null); // update new post with category path hierarchy qa_db_posts_calc_category_path($postid); // send notifications if ($notify && isset($postid)) { $category = mp_get_categoryinfo($categoryid); $recipients = mp_get_category_userids($categoryid); foreach ($recipients as $recipient) { // retrieve the user flags $userflags = mp_get_user_flags($recipient['userid']); // check user flags to determine whether user should be notified or not // of the new answer post if (!($userflags & QA_USER_FLAGS_NOTIFY_ANNOUNCEMENTS)) { qa_send_notification($recipient['userid'], null, null, qa_lang('emails/an_posted_subject'), qa_lang('emails/an_posted_body'), array('^an_handle' => $handle, '^category_title' => $category['title'], '^an_title' => $title, '^an_url' => qa_path('mp-announcements-page', null, qa_opt('site_url'), null, null))); } } } // report announcement create event qa_report_event('an_post', $userid, $handle, $cookieid, array('postid' => $postid, 'title' => $title, 'content' => $content, 'format' => $format, 'text' => $text, 'categoryid' => $categoryid, 'notify' => $notify)); return $postid; }
/** * init current user logined */ function hw_init_current_userlogin() { global $iflychat_userinfo; //init user if (qa_is_logged_in()) { $handle = qa_get_logged_in_handle(); //user name $userid = qa_get_logged_in_userid(); //user id $user = qa_db_select_with_pending(qa_db_user_account_selectspec($handle, false)); //get user avatar src $avatar_src = hw_get_user_avatar_src($user['flags'], $user['email'], $user['avatarblobid']); if (empty($avatar_src)) { $avatar_src = 'https://iflychat.com/sites/all/modules/drupalchat/themes/light/images/default_avatar.png'; } //set detail current user to chat $iflychat_userinfo = new iFlyChatUserDetails($handle, $userid); $iflychat_userinfo->setIsAdmin(TRUE); $iflychat_userinfo->setAvatarUrl($avatar_src); $iflychat_userinfo->setProfileLink(qa_opt('site_url') . 'user/' . $handle); $iflychat_userinfo->setRoomRoles(array()); $iflychat_userinfo->setRelationshipSet(FALSE); //$iflychat_userinfo->setAllRoles(array('1'=>'admin')); } }
function qw_notification_event($postid, $userid, $effecteduserid, $params, $event) { $loggeduserid = isset($userid) ? $userid : qa_get_logged_in_userid(); if (!!$effecteduserid) { qw_notify_users_by_email($event, $postid, $loggeduserid, $effecteduserid, $params); } }
function q_list_item($q_item) { $userid = qa_get_logged_in_userid(); if (qa_opt('obvious_content_on') && $userid) { require_once QA_INCLUDE_DIR . 'qa-db-selects.php'; $fav_tags = qa_db_single_select(qa_db_user_favorite_tags_selectspec($userid)); foreach ($fav_tags as $k => $v) { $tag[$k] = $v['word']; } $post_tags = explode(",", $q_item['raw']['tags']); $result = array_diff($tag, $post_tags); if (sizeof($result) != sizeof($tag) && $tag) { @($q_item['classes'] .= " is_favorite"); } } if (qa_opt('obvious_content_category_on') && $userid) { require_once QA_INCLUDE_DIR . 'qa-db-selects.php'; $fav_cats = qa_db_single_select(qa_db_user_favorite_categories_selectspec($userid)); foreach ($fav_cats as $k => $v) { $cat[$k] = $v['word']; } $post_cat = explode(",", $q_item['raw']['category']); $result = array_diff($cat, $post_cat); if (sizeof($result) != sizeof($cat) && $cat) { @($q_item['classes'] .= " is_favorite_cat"); } } qa_html_theme_base::q_list_item($q_item); // call back through to the default function }
function process_request($request) { require_once QA_INCLUDE_DIR . 'mp-app-posts.php'; require_once QA_INCLUDE_DIR . 'mp-db-users.php'; $qa_content = qa_content_prepare(); // if the user is not logged in, request user to login if (!qa_get_logged_in_userid()) { $qa_content['error'] = qa_insert_login_links('Please ^1log in^2 or ^3register^4 first.', $request); return $qa_content; } $qa_content['title'] = 'Course Announcements'; // DISPLAY ANNOUCEMENTS $data = '<div class="qa-q-list">'; // retrieve annoucements $announcements = mp_announcements_get_all(mp_get_categoryid()); if (count($announcements) == 0) { $data .= "No announcements"; } else { foreach ($announcements as $announcement) { $data .= '<div class="qa-q-list-item">'; $data .= '<div class="qa-q-item-title">' . $announcement['title'] . '</div>'; $data .= '<div class="qa-q-view-content">' . $announcement['content'] . '</div>'; $data .= '<div class="qa-q-item-meta">Posted by <A HREF="' . qa_path_html('user/' . $announcement['handle']) . '">' . $announcement['handle'] . '</A> on ' . $announcement['created'] . '</div>'; $data .= '</div>'; $data .= '<div class="qa-q-list-item-clear" ></div>'; } } $data .= '</div>'; $qa_content['custom_2'] = $data; // create the sub menu for navigation $qa_content['navigation']['sub'] = mp_announcements_sub_navigation(); $qa_content['navigation']['sub']['default']['selected'] = true; return $qa_content; }
function process_request($request) { $userid = qa_get_logged_in_userid(); $categoryoptions = array(); $qa_content = qa_content_prepare(); // check if we have done a post of the page if (qa_post_text('okthen')) { // update the current category $newcategory = qa_post_text('category'); if (isset($newcategory)) { mp_set_categoryid($newcategory); // redirect to main page qa_redirect(''); } else { $qa_content['error'] = 'You must select a course to continue.'; } } // retrieve list of categories user is associated with // populate category options $results = mp_get_categories_for_user($userid); foreach ($results as $row) { $categoryoptions[$row['categoryid']] = $row['title']; } $qa_content['title'] = 'Registered courses'; $qa_content['custom'] = 'The following list displays all courses your account is associated with. Select a course from the list below and click <B>Select</B> to change to the new course<br /><br />'; $qa_content['form'] = array('tags' => 'METHOD="POST" ACTION="' . qa_self_html() . '"', 'style' => 'wide', 'fields' => array('courses' => array('type' => 'select-radio', 'label' => 'Courses', 'tags' => 'NAME="category"', 'options' => $categoryoptions, 'value' => mp_get_categoryid(), 'error' => qa_html(@$errors['course']))), 'buttons' => array('ok' => array('tags' => 'NAME="okthen"', 'label' => 'Select', 'value' => '1'))); return $qa_content; }
function head_custom() { qa_html_theme_base::head_custom(); if (qa_opt('priv_active') && qa_opt('priv_check') && qa_get_logged_in_handle()) { $userid = qa_get_logged_in_userid(); $notices = qa_db_read_one_value(qa_db_query_sub('SELECT meta_value FROM ^usermeta WHERE user_id=# AND meta_key=$ ', $userid, 'priv_notify'), true); if ($notices) { $all = explode('^', $notices); if (!$all[1]) { // no new return; } $n = explode(',', $all[1]); $this->notify = '<div class="notify-container">'; $text = count($n) > 1 ? str_replace('#', count($n), qa_opt('priv_notify_text_multi')) : str_replace('^privilege', qa_lang('profile/' . $n[0]), qa_opt('priv_notify_text')); $text = str_replace('^profile', qa_path_html('user/' . qa_get_logged_in_handle(), array('tab' => 'privileges'), qa_opt('site_url')), $text); $this->notify .= '<div class="priv-notify notify">' . $text . '<div class="notify-close" onclick="jQuery(this).parent().sildeUp(\'fast\')">x</div></div>'; $this->notify .= '</div>'; // remove notification flag qa_db_query_sub('UPDATE ^usermeta SET meta_value=$ WHERE meta_key=$ AND user_id=#', ($all[0] ? $all[0] . ',' : '') . $all[1] . '^', 'priv_notify', $userid); /* $this->output(" <script> jQuery('document').ready(function() { jQuery('.notify-container').delay(10000).fadeOut(); }); </script>"); */ $this->output(' <style>', qa_opt('priv_css'), '</style>'); } } }
function initCustomRequestVars() { // Auto-login Q2A users: if (!$this->getRequestVar('logout') && !(qa_get_logged_in_userid() === null)) { $this->setRequestVar('login', true); } }
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 it_q_list_page_content($questions, $pagesize, $start, $count, $sometitle, $nonetitle, $navcategories, $categoryid, $categoryqcount, $categorypathprefix, $feedpathprefix, $suggest, $pagelinkparams = null, $categoryparams = null, $dummy = null) { require_once QA_INCLUDE_DIR . 'qa-app-format.php'; require_once QA_INCLUDE_DIR . 'qa-app-updates.php'; $userid = qa_get_logged_in_userid(); // Chop down to size, get user information for display if (isset($pagesize)) { $questions = array_slice($questions, 0, $pagesize); } $usershtml = qa_userids_handles_html(qa_any_get_userids_handles($questions)); $qa_content['q_list']['form'] = array('tags' => 'method="post" action="' . qa_self_html() . '"', 'hidden' => array('code' => qa_get_form_security_code('vote'))); $qa_content['q_list']['qs'] = array(); if (count($questions)) { $qa_content['title'] = $sometitle; $defaults = qa_post_html_defaults('Q'); foreach ($questions as $question) { $qa_content['q_list']['qs'][] = qa_any_to_q_html_fields($question, $userid, it_cookie_get(), $usershtml, null, qa_post_html_options($question, $defaults)); } } else { $qa_content['title'] = $nonetitle; } if (isset($count) && isset($pagesize)) { $qa_content['page_links'] = qa_html_page_links(qa_request(), $start, $pagesize, $count, qa_opt('pages_prev_next'), $pagelinkparams); } return $qa_content; }
function output_widget($region, $place, $themeobject, $template, $request, $qa_content) { $widget_opt = @$themeobject->current_widget['param']['options']; require_once QA_INCLUDE_DIR . 'qa-db-selects.php'; require_once QA_INCLUDE_DIR . 'qa-app-format.php'; require_once QA_INCLUDE_DIR . 'qa-app-q-list.php'; $categoryslugs = ''; $userid = qa_get_logged_in_userid(); // Get lists of recent activity in all its forms, plus category information list($questions1, $questions2, $questions3, $questions4) = qa_db_select_with_pending(qa_db_qs_selectspec($userid, 'created', 0, $categoryslugs, null, false, false, $qcount), qa_db_recent_a_qs_selectspec($userid, 0, $categoryslugs), qa_db_recent_c_qs_selectspec($userid, 0, $categoryslugs), qa_db_recent_edit_qs_selectspec($userid, 0, $categoryslugs)); // Prepare and return content for theme $content = qa_q_list_page_content(qa_any_sort_and_dedupe(array_merge($questions1, $questions2, $questions3, $questions4)), $qcount, 0, null, null, null, null, null, true, 'activity/', null, null, null, null); $content = $content['q_list']['qs']; if (@$themeobject->current_widget['param']['locations']['show_title']) { $themeobject->output('<h3 class="widget-title">' . qa_lang('cleanstrap/recent_activities') . ' <a href="' . qa_path_html('activity') . '">' . qa_lang('cleanstrap/view_all') . '</a></h3>'); } $themeobject->output('<div class="ra-question-activity-widget">'); $q_list = $content; $themeobject->output('<ul class="activity-list">'); foreach ($q_list as $list) { $themeobject->output('<li class="clearfix ' . (is_featured($list['raw']['postid']) ? ' featured' : '') . '"><span class="fav-star icon-heart' . (@$list['raw']['userfavoriteq'] ? ' active' : '') . '"></span><span class="post-status-c">' . cs_post_status($list) . '</span><a href="' . $list['url'] . '">' . $list['title'] . '<span class="time">' . implode(' ', $list['when']) . '</span><span class="ans-count total-' . $list['raw']['acount'] . '">' . $list['raw']['acount'] . '</span></a></li>'); } $themeobject->output('</ul>'); $themeobject->output('</div>'); }
function qa_get_request_content() { if (qa_opt('news_plugin_active')) { $requestlower = strtolower(qa_request()); if ($requestlower && $requestlower === 'my-profile') { $userid = qa_get_logged_in_userid(); if (!$userid) { qa_redirect(); } $handles = qa_userids_to_handles(array($userid)); $handle = $handles[$userid]; qa_redirect(qa_path('user/' . $handle)); } else { if ($requestlower && $requestlower === qa_opt('news_plugin_request')) { // send on cron if (qa_opt('news_plugin_send') && qa_get('cron') == qa_opt('news_plugin_cron_rand') && time() >= qa_opt('news_plugin_send_last') + 23 * 60 * 60) { // minumum cron interval is 23 hours qa_news_plugin_createNewsletter(true); return false; } else { if (qa_get('cron') == qa_opt('news_plugin_cron_rand')) { if (!qa_opt('news_plugin_send')) { error_log('Q2A Newsletter Recreate Error: sending newsletter not allowed via admin/plugins'); } else { error_log('Q2A Newsletter Recreate Error: cron request before minimum time elapsed'); } echo "false\n"; return false; } } include qa_opt('news_plugin_loc'); return false; } else { if (qa_opt('news_plugin_pdf') && $requestlower && $requestlower === qa_opt('news_plugin_request_pdf')) { $pdf = file_get_contents(qa_opt('news_plugin_loc_pdf')); header('Content-Description: File Transfer'); header('Cache-Control: public, must-revalidate, max-age=0'); // HTTP/1.1 header('Pragma: public'); header('Expires: Sat, 26 Jul 1997 05:00:00 GMT'); // Date in the past header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT'); // force download dialog header('Content-Type: application/force-download'); header('Content-Type: application/octet-stream', false); header('Content-Type: application/download', false); header('Content-Type: application/pdf', false); // use the Content-Disposition header to supply a recommended filename header('Content-Disposition: attachment; filename="' . basename(qa_opt('news_plugin_loc_pdf')) . '";'); header('Content-Transfer-Encoding: binary'); header('Content-Length: ' . strlen($pdf)); echo $pdf; return false; } } } } return qa_get_request_content_base(); }
function process_request($request) { require_once QA_INCLUDE_DIR . 'qa-db-users.php'; require_once QA_INCLUDE_DIR . 'qa-app-format.php'; require_once QA_INCLUDE_DIR . 'qa-app-users.php'; require_once QA_INCLUDE_DIR . 'qa-db-selects.php'; require_once $this->directory . 'qa-open-utils.php'; // Check we're not using single-sign on integration, that we're logged in if (QA_FINAL_EXTERNAL_USERS) { qa_fatal_error('User accounts are handled by external code'); } $userid = qa_get_logged_in_userid(); if (!isset($userid)) { qa_redirect('login'); } // Get current information on user $useraccount = qa_db_user_find_by_id__open($userid); // Check if settings were updated $this->check_settings(); // Check if we're unlinking an account $mylogins = $this->check_unlink($useraccount); // Check if we need to associate another provider $tolink = $this->check_associate($useraccount); // Check if we're merging multiple accounts $otherlogins = $this->check_merge($useraccount, $mylogins, $tolink); // Prepare content for theme $disp_conf = qa_get('confirm') || !empty($tolink); $qa_content = qa_content_prepare(); // Build page if (!$disp_conf) { // just visiting the regular page $qa_content['title'] = qa_lang_html('plugin_open/my_logins_title'); $qa_content['navigation']['sub'] = qa_user_sub_navigation($useraccount['handle'], '', true); $qa_content['script_onloads'][] = '$(function(){ window.setTimeout(function() { qa_conceal(".form-notification-ok"); }, 1500); });'; $this->display_summary($qa_content, $useraccount); $this->display_logins($qa_content, $useraccount, $mylogins); $this->display_duplicates($qa_content, $useraccount, $otherlogins); $this->display_services($qa_content, !empty($mylogins) || !empty($otherlogins)); } else { // logged in and there are duplicates $qa_content['title'] = qa_lang_html('plugin_open/other_logins_conf_title'); if (!$this->display_duplicates($qa_content, $useraccount, $otherlogins)) { $tourl = qa_get('to'); if (!empty($tourl)) { qa_redirect($tourl); } else { if ($tolink) { // unable to link the login $provider = ucfirst($tolink['source']); qa_redirect('logins', array('provider' => $provider, 'code' => 99)); } else { // no merge to confirm qa_redirect('', array('provider' => '', 'code' => 98)); } } } } return $qa_content; }
function body_prefix() { if (!qa_get_logged_in_userid() && !@$_COOKIE['qa_faq_noshow'] && qa_opt('faq_notify_show')) { setcookie('qa_faq_noshow', 'true', 0, '/', QA_COOKIE_DOMAIN); $this->faq_notify(); } qa_html_theme_base::body_prefix(); }
function process_event($event, $userid, $handle, $cookieid, $params) { // check we have the correct event and the option is set if ($event != 'a_to_c') { return; } if (!qa_opt($this->convopt)) { return; } qa_post_set_content($params['postid'], null, null, '', null, null, null, qa_get_logged_in_userid()); }
function qa_q_list_page_content($questions, $pagesize, $start, $count, $sometitle, $nonetitle, $navcategories, $categoryid, $categoryqcount, $categorypathprefix, $feedpathprefix, $suggest, $pagelinkparams = null, $categoryparams = null, $dummy = null) { if (qa_to_override(__FUNCTION__)) { $args = func_get_args(); return qa_call_override(__FUNCTION__, $args); } require_once QA_INCLUDE_DIR . 'app/format.php'; require_once QA_INCLUDE_DIR . 'app/updates.php'; $userid = qa_get_logged_in_userid(); // Chop down to size, get user information for display if (isset($pagesize)) { $questions = array_slice($questions, 0, $pagesize); } $usershtml = qa_userids_handles_html(qa_any_get_userids_handles($questions)); // Prepare content for theme $qa_content = qa_content_prepare(true, array_keys(qa_category_path($navcategories, $categoryid))); $qa_content['q_list']['form'] = array('tags' => 'method="post" action="' . qa_self_html() . '"', 'hidden' => array('code' => qa_get_form_security_code('vote'))); $qa_content['q_list']['qs'] = array(); if (count($questions)) { $qa_content['title'] = $sometitle; $defaults = qa_post_html_defaults('Q'); if (isset($categorypathprefix)) { $defaults['categorypathprefix'] = $categorypathprefix; } foreach ($questions as $question) { $fields = qa_any_to_q_html_fields($question, $userid, qa_cookie_get(), $usershtml, null, qa_post_html_options($question, $defaults)); if (!empty($fields['raw']['closedbyid'])) { $fields['closed'] = array('state' => qa_lang_html('main/closed')); } $qa_content['q_list']['qs'][] = $fields; } } else { $qa_content['title'] = $nonetitle; } if (isset($userid) && isset($categoryid)) { $favoritemap = qa_get_favorite_non_qs_map(); $categoryisfavorite = @$favoritemap['category'][$navcategories[$categoryid]['backpath']]; $qa_content['favorite'] = qa_favorite_form(QA_ENTITY_CATEGORY, $categoryid, $categoryisfavorite, qa_lang_sub($categoryisfavorite ? 'main/remove_x_favorites' : 'main/add_category_x_favorites', $navcategories[$categoryid]['title'])); } if (isset($count) && isset($pagesize)) { $qa_content['page_links'] = qa_html_page_links(qa_request(), $start, $pagesize, $count, qa_opt('pages_prev_next'), $pagelinkparams); } if (empty($qa_content['page_links'])) { $qa_content['suggest_next'] = $suggest; } if (qa_using_categories() && count($navcategories) && isset($categorypathprefix)) { $qa_content['navigation']['cat'] = qa_category_navigation($navcategories, $categoryid, $categorypathprefix, $categoryqcount, $categoryparams); } if (isset($feedpathprefix) && (qa_opt('feed_per_category') || !isset($categoryid))) { $qa_content['feed'] = array('url' => qa_path_html(qa_feed_request($feedpathprefix . (isset($categoryid) ? '/' . qa_category_path_request($navcategories, $categoryid) : ''))), 'label' => strip_tags($sometitle)); } return $qa_content; }
function allow_template($template) { // not allowed when logged in $userid = qa_get_logged_in_userid(); if (stristr(qa_request(), 'admin/layoutwidgets') === false && isset($userid)) { return false; } if ($template == 'login' || $template == 'register') { return false; } return true; }
function qw_notification_btn() { //if (true){ // check options $userid = qa_get_logged_in_userid(); if (isset($userid)) { $handle = qa_get_logged_in_handle(); $this->output(' <div class="user-actions pull-right"> <div class="activity-bar"> <div class="button dropdown"> <a href="' . qa_path_html('user/' . $handle . '/activity') . '" class=" icon-bullhorn dropdown-toggle activitylist" data-toggle="dropdown" id="activitylist"></a> <div class="dropdown-menu activity-dropdown-list pull-right" id="activity-dropdown-list"> <div class="bar"> <span>' . qa_lang_html('dude/notifications') . '</span> <a class="mark-activity" href="#" data-id="' . qa_get_logged_in_userid() . '">' . qa_lang('dude/mark_all_as_read') . '</a> </div> <div class="append"> <div class="ajax-list"></div> <span class="loading"></span> <div class="no-activity icon-chart-bar">' . qa_lang('dude/no-activity') . '</div> </div> <a class="event-footer" href="' . qa_path_html('notifications', null, QW_BASE_URL) . '">' . qa_lang('dude/see_all') . '</a> </div> </div> </div> <div class="message-bar"> <div class="button dropdown"> <a href="' . qa_path_html('user/' . $handle . '/message') . '" class=" icon-envelope-alt dropdown-toggle messagelist" data-toggle="dropdown" id="messagelist"></a> <div class="dropdown-menu message-dropdown-list pull-right" id="message-dropdown-list"> <div class="bar"> <span>' . qa_lang_html('dude/messages') . '</span> <a class="mark-messages" href="#">' . qa_lang('dude/mark_all_as_read') . '</a> </div> <div class="append"> <div class="ajax-list"></div> <span class="loading"></span> <div class="no-activity icon-chart-bar">' . qa_lang('dude/no-activity') . '</div> </div> <a class="event-footer" href="' . qa_path_html('user/' . $handle . '/wall', null, QW_BASE_URL) . '">' . qa_lang('dude/see_all') . '</a> </div> </div> </div> </div> '); } //} }
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 qa_favorite_q_list_view($questions, $usershtml) { $q_list = array('qs' => array()); if (count($questions) === 0) { return $q_list; } $q_list['form'] = array('tags' => 'method="post" action="' . qa_self_html() . '"', 'hidden' => array('code' => qa_get_form_security_code('vote'))); $defaults = qa_post_html_defaults('Q'); foreach ($questions as $question) { $q_list['qs'][] = qa_post_html_fields($question, qa_get_logged_in_userid(), qa_cookie_get(), $usershtml, null, qa_post_html_options($question, $defaults)); } return $q_list; }
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 process_request($request) { // Get list of unanswered open questions $userid = qa_get_logged_in_userid(); $start = qa_get_start(); $questions_selectspec = $this->qa_db_open_qs_selectspec($userid, $start); $questions = qa_db_select_with_pending($questions_selectspec); // Prepare and return the content for the theme $questions_found_title = qa_lang_html('open_questions/questions_found_title'); $no_questions_title = qa_lang_html('open_questions/no_questions_title'); $count = qa_opt('cache_unaqcount'); $qa_content = qa_q_list_page_content($questions, qa_opt('page_size_una_qs'), $start, @$count, $questions_found_title, $no_questions_title, null, null, false, null, null, qa_html_suggest_qs_tags(qa_using_tags()), null, null); return $qa_content; }
function qa_page_q_post_rules($post, $parentpost = null, $siblingposts = null, $childposts = null) { // default function call $rules = qa_page_q_post_rules_base($post, $parentpost, $siblingposts, $childposts); $userid = qa_get_logged_in_userid(); $level = qa_get_logged_in_level(); // do not show answer button if spam-limit exceeded (git-suggest) if (!qa_limits_remaining($userid, QA_LIMIT_ANSWERS)) { $rules['answerbutton'] = false; } // users are never allowed to hide posts $rules['hideable'] = false; // normal users are not allowed to edit posts after x min $timestamp = time(); // edit time frame: 5 min (300s) for questions/comments + 20 min (1200s) for answers if ($post['type'] == 'A') { $rules['editable'] = $rules['editbutton'] = $rules['isbyuser'] && $timestamp - $post['created'] < 1200; } else { $rules['editable'] = $rules['editbutton'] = $rules['isbyuser'] && $timestamp - $post['created'] < 300; } // questions cannot be reopened, only admin $rules['reopenable'] = $rules['reopenable'] && $level >= QA_USER_LEVEL_ADMIN; // Moderator if ($level == QA_USER_LEVEL_EXPERT) { // allowed to edit own answers and all questions // time frame: allow edit after 5 min and up to 7 days (604800 sec), can edit his own answer immediately $rules['editable'] = $rules['editbutton'] = ($rules['isbyuser'] || $post['type'] == 'Q') && !isset($post['closedbyid']) && $post['userid'] != 1; // never allow question-posts of admin to be edited } else { if ($level == QA_USER_LEVEL_EDITOR) { // can edit all posts in forum, but not admin posts $rules['editable'] = $rules['editbutton'] = $post['userid'] != 1; // can clear flags $rules['clearflaggable'] = $post['flagcount'] >= (@$post['userflag'] ? 2 : 1); } } // && ( ($timestamp - $post['created'] > 300) || $rules['isbyuser'] ) // can edit question just after 5 min OR his own answer immediately // && ($timestamp - $post['created'] < 604800 || $level>=QA_USER_LEVEL_EDITOR) // do not allow edit of posts older than 7 days, Redakteur can // admin has all rights if ($level >= QA_USER_LEVEL_ADMIN) { $rules['editable'] = $rules['editbutton'] = $rules['hideable'] = true; } // experts, moderators, admins can close questions $rules['closeable'] = $level >= QA_USER_LEVEL_EXPERT && !$rules['closed']; // && ($timestamp - $post['created'] < 1209600) ); // within 7 days // do not show retag button as it does the same as edit button $rules['retagcatbutton'] = false; return $rules; }
function nav_main_sub() { // if the user is not logged in, hide all navigation tabs if (!qa_get_logged_in_userid()) { unset($this->content['navigation']['main']['questions']); unset($this->content['navigation']['main']['unanswered']); //unset($this->content['navigation']['main']['categories']); unset($this->content['navigation']['main']['ask']); unset($this->content['navigation']['main']['custom-9']); unset($this->content['navigation']['main']['custom-10']); unset($this->content['navigation']['main']['custom-7'][0]); } $this->nav('main'); $this->nav('sub'); }
function check_login() { if (!qa_get_logged_in_userid() > 0) { try { $auth = Q2ANKConnect::instance()->getAuth(); $auth->handleCallback(); if ($auth->authenticated()) { $this->join_or_add($auth->user()); $auth->logout(); } } catch (NKConnectUnusableException $e) { error_log($e->getMessage()); } } }
function output_widget($region, $place, $themeobject, $template, $request, $qa_content) { require_once QA_INCLUDE_DIR . 'qa-db-selects.php'; $favoritetags = qa_db_single_select(qa_db_user_favorite_tags_selectspec(qa_get_logged_in_userid())); $themeobject->output('<span class="qa-nav-cat-list qa-nav-cat-link">Favorite Tags</span><br>'); foreach ($favoritetags as $k => $v) { if ($k == qa_opt('obvious_max_tags')) { break; } $tag = $v['word']; $count = $v['tagcount']; $question = $count > 1 ? 'questions' : 'question'; $themeobject->output('<a href="' . qa_path_html('tag/' . $tag) . '" class="qa-tag-link" title="Tagged in ' . $count . ' ' . $question . '">' . qa_html($tag) . '</a>'); } }
function qa_theme_chooser() { $userid = qa_get_logged_in_userid(); if (function_exists('qa_register_plugin_overrides')) { // 1.5 return qa_db_read_one_value(qa_db_query_sub('SELECT meta_value FROM ^usermeta WHERE user_id=# AND meta_key=$', $userid, 'custom_theme'), true); } require_once QA_INCLUDE_DIR . 'qa-app-users.php'; if (!$userid) { $theme = @$_COOKIE['qa_theme_switch']; if (qa_opt('theme_switch_enable_mobile')) { $theme_choice_mobile = qa_theme_chooser_detect_mobile() ? qa_opt('theme_switch_mobile') : false; } if ($theme) { global $qa_theme_switch_is_mobile; $qa_theme_switch_is_mobile = $theme_choice_mobile; // it's mobile, but they have a preferred theme return $theme; } return $theme_choice_mobile; } if (qa_opt('theme_switch_enable_mobile')) { $theme_choice_mobile = @$_COOKIE['qa_theme_switch'] == qa_opt('theme_switch_mobile') ? qa_opt('theme_switch_mobile') : false; $theme_mobile = qa_theme_chooser_detect_mobile() ? qa_opt('theme_switch_mobile') : false; global $qa_theme_switch_is_mobile; $qa_theme_switch_is_mobile = $theme_mobile; // it's mobile, but they have a preferred theme if ($theme_choice && (!$theme_choice_mobile || !$theme_mobile)) { // have theme choice, and 1) it's not mobile, 2) it's mobile and they don't have a cookie, 3) they have a cookie but it's not mobile, 4) they have a cookie, it's mobile, but the cookie isn't mobile // do nothing } else { if (!$theme_choice_mobile && $theme_mobile) { // no cookie, is mobile, give mobile return $theme_mobile; } else { if ($theme_choice_mobile && $theme_mobile) { // cookie, is mobile, give cookie return $theme_choice_mobile; } } } } if ($theme_choice) { global $qa_theme_switch_is_mobile; return $theme_choice; } return $theme_choice_mobile; }
function qa_check_form_security_code($action, $value) { if (qa_caching_main::now_caching()) { $reportproblems = array(); $silentproblems = array(); if (!isset($value)) { $silentproblems[] = 'code missing'; } elseif (!strlen($value)) { $silentproblems[] = 'code empty'; } else { $parts = explode('-', $value); if (count($parts) == 3) { $loggedin = $parts[0]; $timestamp = $parts[1]; $hash = $parts[2]; $timenow = qa_opt('db_time'); if ($loggedin != '0') { $reportproblems[] = 'login status mismatch'; } /*if ($timestamp>$timenow) $reportproblems[]='time '.($timestamp-$timenow).'s in future'; else*/ if ($timestamp < $timenow - QA_FORM_EXPIRY_SECS) { $silentproblems[] = 'timeout after ' . ($timenow - $timestamp) . 's'; } $key = @$_COOKIE['qa_key']; if (!isset($key)) { $silentproblems[] = 'key cookie missing'; } elseif (!strlen($key)) { $silentproblems[] = 'key cookie empty'; } elseif (strlen($key) != QA_FORM_KEY_LENGTH) { $reportproblems[] = 'key cookie ' . $key . ' invalid'; } if ($hash != $key) { $reportproblems[] = 'key cookie mismatch'; } } else { $reportproblems[] = 'code ' . $value . ' malformed'; } } if (count($reportproblems)) { @error_log('PHP Question2Answer form security violation for ' . $action . ' by ' . (qa_is_logged_in() ? 'userid ' . qa_get_logged_in_userid() : 'anonymous') . ' (' . implode(', ', array_merge($reportproblems, $silentproblems)) . ')' . ' on ' . @$_SERVER['REQUEST_URI'] . ' via ' . @$_SERVER['HTTP_REFERER']); } return empty($silentproblems) && empty($reportproblems); } else { return qa_check_form_security_code_base($action, $value); } }
function process_request($request) { // perform userinfuser registration $ui = new UserInfuser("*****@*****.**", "0658a511-d890-4e51-ba9e-126d6c0a12f2"); $ui->update_user(qa_get_logged_in_email(), qa_get_logged_in_userid(), "", ""); $ui->award_points(qa_get_logged_in_email(), 1000); $pw = $ui->get_widget(qa_get_logged_in_email(), "points", 100, 100); $lw = $ui->get_widget(qa_get_logged_in_email(), "leaderboard", 600, 300); $qa_content = qa_content_prepare(); $qa_content['title'] = 'Example plugin page'; $qa_content['error'] = 'An example error'; $qa_content['custom'] = 'Some <B>custom html</B>'; $qa_content['form'] = array('tags' => 'METHOD="POST" ACTION="' . qa_self_html() . '"', 'style' => 'wide', 'ok' => qa_post_text('okthen') ? 'You clicked OK then!' : null, 'title' => 'Form title', 'fields' => array('request' => array('label' => 'The request' . qa_get_logged_in_userid(), 'tags' => 'NAME="request"', 'value' => qa_html($request), 'error' => qa_html('Another error'))), 'buttons' => array('ok' => array('tags' => 'NAME="okthen"', 'label' => 'OK then', 'value' => '1')), 'hidden' => array('hiddenfield' => '1')); $qa_content['custom_2'] = '<P><BR>More <I>custom html</I></P>'; $qa_content['custom_3'] = $pw . $lw; return $qa_content; }
public function process_request($request) { $requestparts = explode('/', qa_request()); $slugs = array_slice($requestparts, 1); $countslugs = count($slugs); $userid = qa_get_logged_in_userid(); $start = qa_get_start(); $count = qa_opt_if_loaded('page_size_activity'); $totalcount = qa_opt('cache_qcount'); $qspec = qa_db_posts_basic_selectspec($userid, false); qa_db_add_selectspec_opost($qspec, 'ra', false, false); qa_db_add_selectspec_ousers($qspec, 'rau', 'raup'); $qspec['source'] .= " JOIN (SELECT questionid, childid FROM ^homepage ORDER BY ^homepage.updated DESC) AS rcaq ON ^posts.postid=rcaq.questionid" . " LEFT JOIN ^posts AS ra ON childid=ra.postid" . (QA_FINAL_EXTERNAL_USERS ? "" : " LEFT JOIN ^users AS rau ON ra.userid=rau.userid") . " LEFT JOIN ^userpoints AS raup ON ra.userid=raup.userid LIMIT #,#"; array_push($qspec['columns'], 'childid'); array_push($qspec['arguments'], $start, $count); $qspec['sortdesc'] = 'otime'; $query = 'SELECT '; foreach ($qspec['columns'] as $columnas => $columnfrom) { $query .= $columnfrom . (is_int($columnas) ? '' : ' AS ' . $columnas) . ', '; } $query = qa_db_apply_sub(substr($query, 0, -2) . (strlen(@$qspec['source']) ? ' FROM ' . $qspec['source'] : ''), @$qspec['arguments']); $results = qa_db_read_all_assoc(qa_db_query_raw($query)); qa_db_post_select($results, $qspec); list($categories, $categoryid) = qa_db_select_with_pending(qa_db_category_nav_selectspec($slugs, false, false, true), $countslugs ? qa_db_slugs_to_category_id_selectspec($slugs) : null); $questions = qa_any_sort_and_dedupe($results); // $questions=qa_any_sort_and_dedupe(array_merge($recentquestions,$recentanswers)); $pagesize = qa_opt('page_size_home'); if ($countslugs) { if (!isset($categoryid)) { return include QA_INCLUDE_DIR . 'qa-page-not-found.php'; } $categorytitlehtml = qa_html($categories[$categoryid]['title']); $sometitle = qa_lang_html_sub('main/recent_qs_as_in_x', $categorytitlehtml); $nonetitle = qa_lang_html_sub('main/no_questions_in_x', $categorytitlehtml); } else { $sometitle = qa_lang_html('main/recent_qs_as_title'); $nonetitle = qa_lang_html('main/no_questions_found'); } require_once QA_INCLUDE_DIR . 'qa-app-q-list.php'; $qa_content = qa_q_list_page_content($questions, $pagesize, $start, $totalcount, $sometitle, $nonetitle, $categories, $categoryid, true, qa_opt('eql_homepage_url'), qa_opt('feed_for_qa') ? qa_opt('eql_homepage_url') : null, count($questions) < $pagesize ? qa_html_suggest_ask($categoryid) : qa_html_suggest_qs_tags(qa_using_tags(), qa_category_path_request($categories, $categoryid)), null, null); return $qa_content; }