function output_widget($region, $place, $themeobject, $template, $request, $qa_content) { if (!qa_opt('event_logger_to_database')) { return; } $badges = qa_db_read_all_assoc(qa_db_query_sub('SELECT event,handle,params, UNIX_TIMESTAMP(datetime) AS datetime FROM ^eventlog WHERE event=$' . (qa_opt('badge_widget_date_max') ? ' AND DATE_SUB(CURDATE(),INTERVAL ' . (int) qa_opt('badge_widget_date_max') . ' DAY) <= datetime' : '') . ' ORDER BY datetime DESC' . (qa_opt('badge_widget_list_max') ? ' LIMIT ' . (int) qa_opt('badge_widget_list_max') : ''), 'badge_awarded')); if (empty($badges)) { return; } $themeobject->output('<h2>' . qa_lang('badges/badge_widget_title') . '</h2>'); foreach ($badges as $badge) { $params = array(); $paramsa = explode("\t", $badge['params']); foreach ($paramsa as $param) { $parama = explode('=', $param); $params[$parama[0]] = $parama[1]; } $slug = $params['badge_slug']; $typea = qa_get_badge_type_by_slug($slug); $types = $typea['slug']; $typed = $typea['name']; $badge_name = qa_lang('badges/' . $slug); if (!qa_opt('badge_' . $slug . '_name')) { qa_opt('badge_' . $slug . '_name', $badge_name); } $var = qa_opt('badge_' . $slug . '_var'); $name = qa_opt('badge_' . $slug . '_name'); $desc = qa_badge_desc_replace($slug, $var, $name); $string = '<span class="badge-' . $types . '" title="' . $desc . ' (' . $typed . ')">' . qa_html($name) . '<br/>- ' . $badge['handle'] . ' -</span>'; $themeobject->output('<div class="badge-widget-entry" style="padding-top:8px;">', $string, '</div>'); } }
public function q_list($q_list) { if (!empty($q_list['qs']) && qa_opt('mouseover_content_on')) { // first check it is not an empty list and the feature is turned on // Collect the question ids of all items in the question list (so we can do this in one DB query) $postids = array(); foreach ($q_list['qs'] as $question) { if (isset($question['raw']['postid'])) { $postids[] = $question['raw']['postid']; } } if (!empty($postids)) { // Retrieve the content for these questions from the database and put into an array fetching // the minimal amount of characters needed to determine the string should be shortened or not $maxlength = qa_opt('mouseover_content_max_len'); $result = qa_db_query_sub('SELECT postid, LEFT(content, #) content, format FROM ^posts WHERE postid IN (#)', $maxlength + 1, $postids); $postinfo = qa_db_read_all_assoc($result, 'postid'); // Get the regular expression fragment to use for blocked words and the maximum length of content to show $blockwordspreg = qa_get_block_words_preg(); // Now add the popup to the title for each question foreach ($q_list['qs'] as $index => $question) { if (isset($postinfo[$question['raw']['postid']])) { $thispost = $postinfo[$question['raw']['postid']]; $text = qa_viewer_text($thispost['content'], $thispost['format'], array('blockwordspreg' => $blockwordspreg)); $text = qa_shorten_string_line($text, $maxlength); $title = isset($question['title']) ? $question['title'] : ''; $q_list['qs'][$index]['title'] = sprintf('<span title="%s">%s</span>', qa_html($text), $title); } } } } qa_html_theme_base::q_list($q_list); // call back through to the default function }
function admin_form(&$qa_content) { // Process form input $ok = null; if (qa_clicked('cp_save')) { // Save 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'); qa_opt('cp_enable', (bool) qa_post_text('cp_enable')); $ok = qa_lang('admin/options_saved'); } else { if (qa_clicked('cp_reset')) { // Reset foreach ($_POST as $i => $v) { $def = $this->option_default($i); if ($def !== null) { qa_opt($i, $def); } } qa_opt('cp_enable', true); $ok = qa_lang('admin/options_reset'); } } // Create the form for display $fields = array(); $fields[] = array('label' => qa_lang('cp/enable_community_posts'), 'tags' => 'NAME="cp_enable"', 'value' => qa_opt('cp_enable'), 'type' => 'checkbox'); return array('ok' => $ok && !isset($error) ? $ok : null, 'fields' => $fields, 'buttons' => array(array('label' => qa_lang_html('main/save_button'), 'tags' => 'NAME="cp_save"'), array('label' => qa_lang_html('admin/reset_options_button'), 'tags' => 'NAME="cp_reset"'))); }
function qa_priv_notification($uid, $oid, $badge_slug) { require_once QA_INCLUDE_DIR . 'qa-app-users.php'; require_once QA_INCLUDE_DIR . 'qa-app-emails.php'; if (QA_FINAL_EXTERNAL_USERS) { $publictohandle = qa_get_public_from_userids(array($uid)); $handle = @$publictohandle[$uid]; } else { $user = qa_db_single_select(qa_db_user_account_selectspec($uid, true)); $handle = @$user['handle']; } $subject = qa_opt('badge_email_subject'); $body = qa_opt('badge_email_body'); $body = preg_replace('/\\^if_post_text="([^"]*)"/', $oid ? '$1' : '', $body); // if post text $site_url = qa_opt('site_url'); $profile_url = qa_path_html('user/' . $handle, null, $site_url); if ($oid) { $post = qa_db_read_one_assoc(qa_db_query_sub('SELECT * FROM ^posts WHERE postid=#', $oid), true); if ($post['parentid']) { $parent = qa_db_read_one_assoc(qa_db_query_sub('SELECT * FROM ^posts WHERE postid=#', $post['parentid']), true); } if (isset($parent)) { $anchor = urlencode(qa_anchor($post['basetype'], $oid)); $post_title = $parent['title']; $post_url = qa_path_html(qa_q_request($parent['postid'], $parent['title']), null, qa_opt('site_url'), null, $anchor); } else { $post_title = $post['title']; $post_url = qa_path_html(qa_q_request($post['postid'], $post['title']), null, qa_opt('site_url')); } } $subs = array('^badge_name' => qa_opt('badge_' . $badge_slug . '_name'), '^post_title' => @$post_title, '^post_url' => @$post_url, '^profile_url' => $profile_url, '^site_url' => $site_url); qa_send_notification($uid, '@', $handle, $subject, $body, $subs); }
function qa_share_buttons($q_view) { if (qa_opt('expert_question_enable')) { $qid = $q_view['raw']['postid']; $expert = qa_db_read_one_value(qa_db_query_sub("SELECT meta_value FROM ^postmeta WHERE meta_key='is_expert_question' AND post_id=#", $qid), true); if ($expert) { return; } } $url = qa_path_html(qa_q_request($q_view['raw']['postid'], $q_view['raw']['title']), null, qa_opt('site_url')); $code = array('facebook' => '<iframe src="//www.facebook.com/plugins/like.php?href=' . qa_path_html(qa_q_request($this->content['q_view']['raw']['postid'], $this->content['q_view']['raw']['title']), null, qa_opt('site_url')) . '&send=false&layout=standard&width=53&layout=button_count&show_faces=false&action=like&colorscheme=light&font&height=20&appId=170382616390886" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:53px; height:20px;" allowTransparency="true"></iframe>', 'twitter' => '<a href="http://twitter.com/share" class="twitter-share-button" data-count="none">Tweet</a>', 'google' => '<g:plusone size="medium" count="false"></g:plusone>', 'linkedin' => '<script type="text/javascript" src="http://platform.linkedin.com/in.js"></script><script type="in/share"></script>', 'email' => '<a title="Share this question via email" id="share-button-email" href="mailto:?subject=' . rawurlencode('[' . qa_opt('site_title') . '] ' . $q_view['raw']['title']) . '&body=' . rawurlencode($url) . '"><img height="24" src="' . QA_HTML_THEME_LAYER_URLTOROOT . 'qa-share-mail.png' . '"/></a>'); // sort by weight $weight = array('facebook' => qa_opt('share_plugin_facebook_weight'), 'twitter' => qa_opt('share_plugin_twitter_weight'), 'google' => qa_opt('share_plugin_google_weight'), 'linkedin' => qa_opt('share_plugin_linkedin_weight'), 'email' => qa_opt('share_plugin_email_weight')); asort($weight); // output foreach ($weight as $key => $val) { if (qa_opt('share_plugin_' . $key)) { $shares[] = $code[$key]; } } if (empty($shares)) { return null; } $output = implode(' ', $shares); return $output; }
function init_queries($tableslc) { // check if the plugin is initialized $ok = qa_opt('open_login_ok'); if ($ok == 3) { return null; } $queries = array(); $columns = qa_db_read_all_values(qa_db_query_sub('describe ^userlogins')); if (!in_array('oemail', $columns)) { $queries[] = 'ALTER TABLE ^userlogins ADD `oemail` VARCHAR( 80 ) CHARACTER SET utf8 COLLATE utf8_general_ci NULL'; } if (!in_array('ohandle', $columns)) { $queries[] = 'ALTER TABLE ^userlogins ADD `ohandle` VARCHAR( 80 ) CHARACTER SET utf8 COLLATE utf8_general_ci NULL'; } $columns = qa_db_read_all_values(qa_db_query_sub('describe ^users')); if (!in_array('oemail', $columns)) { $queries[] = 'ALTER TABLE ^users ADD `oemail` VARCHAR( 80 ) CHARACTER SET utf8 COLLATE utf8_general_ci NULL'; } if (count($queries)) { return $queries; } // we're already set up qa_opt('open_login_ok', '3'); return null; }
function resync_question($postid, $voidparent) { if ($voidparent) { qa_db_query_sub('REPLACE INTO ^homepage SELECT postid, NULL, created FROM ^posts WHERE type = "Q" AND postid = # LIMIT 1', $postid); } else { qa_db_query_sub('REPLACE INTO ^homepage SELECT postid, parentid, created FROM ^posts WHERE type = "Q" AND postid = # LIMIT 1', $postid); } $query = ' SELECT question.postid, Answers.postid AS answerid, Answers.date AS answerid FROM ^posts question INNER JOIN ( SELECT parentid, postid, MAX(created) AS date FROM ^posts WHERE `type` = "A" GROUP BY postid ) AS Answers ON Answers.parentid = question.postid WHERE question.type = "Q" AND question.postid = #'; qa_db_query_sub('REPLACE INTO ^homepage ' . $query, $postid); }
function AddCategoryToPost($params, $category) { require_once QA_INCLUDE_DIR . 'qa-db-post-update.php'; $postid = $params['postid']; $result = qa_db_read_one_assoc(qa_db_query_sub('SELECT categoryid,parentid,tags,title,content,qcount,position,backpath FROM ^categories WHERE title=$', $category), true); if (empty($result)) { //create category $tags = str_replace(' ', '-', $category); $catID = $this->CreatCategory($category, $tags); qa_db_post_set_category($postid, $catID, null, null); qa_db_posts_calc_category_path($postid); $path = qa_db_post_get_category_path($postid); qa_db_category_path_qcount_update($path); } else { // update category $oldpath = qa_db_post_get_category_path($postid); $tags = $result['tags']; $catID = $result['categoryid']; qa_db_post_set_category($postid, $catID, null, null); qa_db_posts_calc_category_path($postid); $path = qa_db_post_get_category_path($postid); qa_db_category_path_qcount_update($oldpath); qa_db_category_path_qcount_update($path); } }
function q_list($q_list) { if (count(@$q_list['qs']) && qa_opt('mouseover_content_on')) { // first check it is not an empty list and the feature is turned on // Collect the question ids of all items in the question list (so we can do this in one DB query) $postids = array(); foreach ($q_list['qs'] as $question) { if (isset($question['raw']['postid'])) { $postids[] = $question['raw']['postid']; } } if (count($postids)) { // Retrieve the content for these questions from the database and put into an array $result = qa_db_query_sub('SELECT postid, content, format FROM ^posts WHERE postid IN (#)', $postids); $postinfo = qa_db_read_all_assoc($result, 'postid'); // Get the regular expression fragment to use for blocked words and the maximum length of content to show $blockwordspreg = qa_get_block_words_preg(); $maxlength = qa_opt('mouseover_content_max_len'); // Now add the popup to the title for each question foreach ($q_list['qs'] as $index => $question) { $thispost = @$postinfo[$question['raw']['postid']]; if (isset($thispost)) { $text = qa_viewer_text($thispost['content'], $thispost['format'], array('blockwordspreg' => $blockwordspreg)); $text = qa_shorten_string_line($text, $maxlength); $q_list['qs'][$index]['title'] = '<SPAN TITLE="' . qa_html($text) . '">' . @$question['title'] . '</SPAN>'; } } } } qa_html_theme_base::q_list($q_list); // call back through to the default function }
public function q_list($q_list) { if (!empty($q_list['qs']) && qa_opt('mouseover_content_on')) { // first check it is not an empty list and the feature is turned on // Collect the question ids of all items in the question list (so we can do this in one DB query) $postids = array(); foreach ($q_list['qs'] as $question) { if (isset($question['raw']['postid'])) { $postids[] = $question['raw']['postid']; } } if (!empty($postids)) { // Retrieve the content for these questions from the database $maxlength = qa_opt('mouseover_content_max_len'); $result = qa_db_query_sub('SELECT postid, content, format FROM ^posts WHERE postid IN (#)', $postids); $postinfo = qa_db_read_all_assoc($result, 'postid'); // Get the regular expression fragment to use for blocked words and the maximum length of content to show $blockwordspreg = qa_get_block_words_preg(); // Now add the popup to the title for each question foreach ($q_list['qs'] as $index => $question) { if (isset($postinfo[$question['raw']['postid']])) { $thispost = $postinfo[$question['raw']['postid']]; $text = qa_viewer_text($thispost['content'], $thispost['format'], array('blockwordspreg' => $blockwordspreg)); $text = preg_replace('/\\s+/', ' ', $text); // Remove duplicated blanks, new line characters, tabs, etc $text = qa_shorten_string_line($text, $maxlength); $title = isset($question['title']) ? $question['title'] : ''; $q_list['qs'][$index]['title'] = $this->getHtmlTitle(qa_html($text), $title); } } } } parent::q_list($q_list); // call back through to the default function }
function q2apro_save_most_viewed_questions() { // save checktime of cache qa_opt('q2apro_popularqu_checktime', time()); $maxquestions = qa_opt('q2apro_popularqu_maxqu'); $lastdays = qa_opt('q2apro_popularqu_lastdays'); $ourTopQuestions = qa_db_read_all_assoc(qa_db_query_sub('SELECT postid, title, acount FROM `^posts` WHERE `created` > NOW() - INTERVAL # DAY AND `type` = "Q" AND `closedbyid` IS NULL ORDER BY views DESC LIMIT #;', $lastdays, $maxquestions)); $saveoutput = ''; foreach ($ourTopQuestions as $qu) { $activity_url = qa_path_html(qa_q_request($qu['postid'], $qu['title']), null, qa_opt('site_url'), null, null); $questionlink = '<a href="' . $activity_url . '">' . htmlspecialchars($qu['title']) . '</a>'; $answercnt = ''; if (qa_opt('q2apro_popularqu_answercount')) { $acnttitle = $qu['acount'] == 1 ? qa_lang('q2apro_popularqu_lang/answer_one') : $qu['acount'] . ' ' . qa_lang('q2apro_popularqu_lang/answers'); $answercnt = ' <span title="' . $acnttitle . '">(' . $qu['acount'] . ')</span>'; } $saveoutput .= '<li> ' . $questionlink . $answercnt . ' </li> '; } // save into cache qa_opt('q2apro_popularqu_cached', $saveoutput); }
public function process_request($request) { require_once QA_INCLUDE_DIR . 'qa-app-posts.php'; // smiley replacement regexes $rxSearch = '<(img|a)([^>]+)(src|href)="([^"]+)/wysiwyg-editor/plugins/smiley/images/([^"]+)"'; $rxReplace = '<$1$2$3="$4/wysiwyg-editor/ckeditor/plugins/smiley/images/$5"'; qa_suspend_event_reports(true); // avoid infinite loop // prevent race conditions $locks = array('posts', 'categories', 'users', 'users AS lastusers', 'userpoints', 'words', 'titlewords', 'contentwords', 'tagwords', 'words AS x', 'posttags', 'options'); foreach ($locks as &$tbl) { $tbl = '^' . $tbl . ' WRITE'; } qa_db_query_sub('LOCK TABLES ' . implode(',', $locks)); $sql = 'SELECT postid, title, content FROM ^posts WHERE format="html" ' . 'AND content LIKE "%/wysiwyg-editor/plugins/smiley/images/%" ' . 'AND content RLIKE \'' . $rxSearch . '\' ' . 'LIMIT 5'; $result = qa_db_query_sub($sql); $numPosts = 0; while (($post = qa_db_read_one_assoc($result, true)) !== null) { $newcontent = preg_replace("#{$rxSearch}#", $rxReplace, $post['content']); qa_post_set_content($post['postid'], $post['title'], $newcontent); $numPosts++; } qa_db_query_raw('UNLOCK TABLES'); qa_suspend_event_reports(false); echo $numPosts; }
function cs_events($limit = 10, $events_type = false) { if (!$events_type) { $events_type = array('q_post', 'a_post', 'c_post', 'a_select', 'badge_awarded'); } // query last 3 events $posts = qa_db_read_all_assoc(qa_db_query_sub('SELECT datetime,ipaddress,handle,event,params FROM ^eventlog WHERE event IN ("q_post", "a_post", "c_post") ORDER BY datetime DESC LIMIT #', $limit)); if (empty($posts)) { return; } $postids = ''; $i = 1; foreach ($posts as $post) { $params = preg_replace('/\\s+/', '&', $post['params']); parse_str($params, $data); $postids .= ($i != 1 ? ', ' : '') . $data['postid']; $i++; } $posts = qa_db_read_all_assoc(qa_db_query_sub('SELECT ^posts.* , ^users.handle FROM ^posts, ^users WHERE (^posts.userid=^users.userid AND ^posts.postid IN (' . $postids . ')) AND ^posts.type IN ("Q", "A", "C") ORDER BY ^posts.created DESC')); $o = '<ul class="ra-activity">'; foreach ($posts as $p) { $event_name = ''; $event_icon = ''; if ($p['type'] == 'Q') { $event_name = qa_lang('cleanstrap/asked'); $event_icon = 'icon-question'; } else { if ($p['type'] == 'A') { $event_name = qa_lang('cleanstrap/answered'); $event_icon = 'icon-answer'; } else { $event_name = qa_lang('cleanstrap/commented'); $event_icon = 'icon-chat'; } } $username = is_null($p['handle']) ? qa_lang('cleanstrap/anonymous') : htmlspecialchars($p['handle']); $usernameLink = is_null($p['handle']) ? qa_lang('cleanstrap/anonymous') : '<a href="' . qa_path_html('user/' . $p['handle']) . '">' . $p['handle'] . '</a>'; $timeCode = qa_when_to_html(strtotime($p['created']), 7); $time = @$timeCode['prefix'] . @$timeCode['data'] . @$timeCode['suffix']; $o .= '<li class="event-item">'; $o .= '<div class="event-inner">'; $o .= '<div class="event-icon pull-left ' . $event_icon . '"></div>'; $o .= '<div class="event-content">'; $o .= '<p class="title"><strong class="avatar" data-handle="' . $p['handle'] . '" data-id="' . $p['userid'] . '">' . @$usernameLink . '</strong> <span class="what">' . $event_name . '</span></p>'; if ($p['type'] == 'Q') { $o .= '<a class="event-title" href="' . qa_q_path_html($p['postid'], $p['title']) . '" title="' . $p['title'] . '">' . cs_truncate($p['title'], 100) . '</a>'; } elseif ($p['type'] == 'A') { $o .= '<a class="event-title" href="' . cs_post_link($p['parentid']) . '#a' . $p['postid'] . '">' . cs_truncate(strip_tags($p['content']), 100) . '</a>'; } else { $o .= '<a class="event-title" href="' . cs_post_link($p['parentid']) . '#c' . $p['postid'] . '">' . cs_truncate(strip_tags($p['content']), 100) . '</a>'; } $o .= '<span class="time">' . $time . '</span>'; $o .= '</div>'; $o .= '</div>'; $o .= '</li>'; } $o .= '</ul>'; return $o; }
function mp_announcements_get_all($categoryid) { /* Return all annoucement posts */ $results = qa_db_read_all_assoc(qa_db_query_sub('select p.*, u.handle from ^posts p, ^users u where p.type="AN" AND p.categoryid=# AND p.userid = u.userid ORDER BY p.created DESC', $categoryid), 'postid'); return $results; }
function qa_db_cache_get($type, $cacheid) { $content = qa_db_read_one_value(qa_db_query_sub('SELECT content FROM ^cache WHERE type=$ AND cacheid=#', $type, $cacheid), true); if (isset($content)) { qa_db_query_sub('UPDATE ^cache SET lastread=NOW() WHERE type=$ AND cacheid=#', $type, $cacheid); } return $content; }
function handleForID($id) { $result = qa_db_query_sub('SELECT * FROM ^users WHERE userid=# LIMIT 1', $id); if ($row = mysql_fetch_array($result)) { return $row['handle']; } return ''; }
function qa_db_uservoteflag_posts_get($postids) { if (QA_FINAL_EXTERNAL_USERS) { return qa_db_read_all_assoc(qa_db_query_sub('SELECT postid, userid, vote, flag FROM ^uservotes WHERE postid IN (#) AND ((vote!=0) OR (flag!=0))', $postids)); } else { return qa_db_read_all_assoc(qa_db_query_sub('SELECT postid, handle, vote, flag FROM ^uservotes LEFT JOIN ^users ON ^uservotes.userid=^users.userid WHERE postid IN (#) AND ((vote!=0) OR (flag!=0))', $postids)); } }
function qa_db_blob_exists($blobid) { if (qa_to_override(__FUNCTION__)) { $args = func_get_args(); return qa_call_override(__FUNCTION__, $args); } return qa_db_read_one_value(qa_db_query_sub('SELECT COUNT(*) FROM ^blobs WHERE blobid=#', $blobid)) > 0; }
function process_event($event, $userid, $handle, $cookieid, $params) { $activityPoints = array("page_enter" => 1, "u_register" => 0, "u_confirmed" => 0, "q_edit" => 50, "a_edit" => 50, "a_vote_up" => 30, "a_vote_down" => 30, "a_vote_nil" => 30, "q_vote_up" => 30, "q_vote_down" => 30, "q_vote_nil" => 30, "q_post" => 200, "a_post" => 300, "u_password" => 5, "u_reset" => 5, "u_edit" => 5, "u_save" => 5, "a_select" => 30, "a_unselect" => 10, "u_login" => 10, "u_logout" => 10); if (array_key_exists($event, $activityPoints)) { qa_db_query_sub('INSERT INTO mp_userpoints (userid, categoryid, eventid, points, award_date) ' . 'VALUES (#, #, $, #, NOW())', is_null($userid) ? '-1' : $userid, is_null(mp_get_categoryid()) ? '-1' : mp_get_categoryid(), $event, $activityPoints[$event]); } //qa_opt('mp_active_category') }
function ra_db_builder($name, $value = null) { if (isset($value)) { ra_set_builder_content($name, $value); } else { $content = qa_db_read_one_value(qa_db_query_sub('SELECT BINARY content as content FROM ^builder WHERE name=#', $name), true); return str_replace('\\', '', $content); } }
function qa_get_public_from_userids($userids) { global $table_prefix; if (count($userids)) { return qa_db_read_all_assoc(qa_db_query_sub('SELECT user_nicename, ID FROM ' . $table_prefix . 'users WHERE ID IN (#)', $userids), 'ID', 'user_nicename'); } else { return array(); } }
function doctype() { $this->widgets = get_all_widgets(); // Setup Navigation global $qa_request; //var_dump($qa_request); $this->content['navigation']['user']['widgets'] = array('label' => 'Theme Widgets', 'url' => qa_path_html('widgets'), 'icon' => 'icon-puzzle'); if ($qa_request == 'widgets') { $this->content['navigation']['user']['widgets']['selected'] = true; $this->content['navigation']['user']['selected'] = true; $this->template = "widgets"; $this->content['site_title'] = "Theme Widgets"; $this->content['error'] = ""; $this->content['suggest_next'] = ""; $this->content['title'] = "Theme Widgets"; //$this->content['custom']=''; $saved = false; if (qa_clicked('cs_remove_all_button')) { qa_db_query_sub('TRUNCATE TABLE ^cs_widgets'); $saved = true; } if (qa_clicked('cs_reset_widgets_button')) { $handle = fopen(Q_THEME_DIR . '/demo_content/widget_builder.sql', 'r'); $sql = ''; if ($handle) { while (($line = fgets($handle, 4096)) !== false) { $sql .= trim(' ' . trim($line)); if (substr($sql, -strlen(';')) == ';') { qa_db_query_sub($sql); $sql = ''; } } fclose($handle); } $saved = true; } $cs_page = ' <div id="ra-widgets"> <div class="widget-list col-sm-5"> ' . $this->cs_get_widgets() . ' </div> <div class="widget-postions col-sm-7"> ' . $this->cs_get_widgets_positions() . ' </div> </div> <div class="form-widget-button-holder"> <form class="form-horizontal" method="post"> <input class="qa-form-tall-button btn-primary" type="submit" name="cs_remove_all_button" value="Remove All Widgets" title=""> <input class="qa-form-tall-button btn-primary" type="submit" name="cs_reset_widgets_button" value="Reset All Widgets To Theme Default" title=""> </form> </div> '; $this->content['custom'] = $cs_page; } qa_html_theme_base::doctype(); }
function process_event($event, $userid, $handle, $cookieid, $params) { qw_do_action('qw_event_' . $event, $event, $userid, $handle, $cookieid, $params); if (qa_opt('event_logger_to_database')) { $paramstring = ''; foreach ($params as $key => $value) { $value_to_text = $this->value_to_text($value, $key); $value = is_array($value) ? 'array(' . count($value) . ')' . "\t" . $value_to_text : $value_to_text; $paramstring .= (strlen($paramstring) ? "\t" : '') . $key . '=' . $value; } $paramstring = strtr($paramstring, "\n\r", ' '); qa_db_query_sub('INSERT INTO ^eventlog (datetime, ipaddress, userid, handle, cookieid, event, params) ' . 'VALUES (NOW(), $, $, $, #, $, $)', qa_remote_ip_address(), $userid, $handle, $cookieid, $event, $paramstring); } if (qa_opt('event_logger_to_files')) { // Substitute some placeholders if certain information is missing if (!strlen($userid)) { $userid = 'no_userid'; } if (!strlen($handle)) { $handle = 'no_handle'; } if (!strlen($cookieid)) { $cookieid = 'no_cookieid'; } $ip = qa_remote_ip_address(); if (!strlen($ip)) { $ip = 'no_ipaddress'; } // Build the log file line to be written $fixedfields = array('Date' => date('Y\\-m\\-d'), 'Time' => date('H\\:i\\:s'), 'IPaddress' => $ip, 'UserID' => $userid, 'Username' => $handle, 'CookieID' => $cookieid, 'Event' => $event); $fields = $fixedfields; foreach ($params as $key => $value) { $fields['param_' . $key] = $key . '=' . $this->value_to_text($value, $key); } $string = implode("\t", $fields); // Build the full path and file name $directory = qa_opt('event_logger_directory'); if (substr($directory, -1) != '/') { $directory .= '/'; } $filename = $directory . 'q2a-log-' . date('Y\\-m\\-d') . '.txt'; // Open, lock, write, unlock, close (to prevent interference between multiple writes) $exists = file_exists($filename); $file = @fopen($filename, 'a'); if (is_resource($file)) { if (flock($file, LOCK_EX)) { if (!$exists && filesize($filename) === 0 && !qa_opt('event_logger_hide_header')) { $string = "Question2Answer " . QA_VERSION . " log file generated by Event Logger plugin.\n" . "This file is formatted as tab-delimited text with UTF-8 encoding.\n\n" . implode("\t", array_keys($fixedfields)) . "\textras...\n\n" . $string; } fwrite($file, $string . "\n"); flock($file, LOCK_UN); } fclose($file); } } }
function custom_badges_rebuild() { $awarded = 0; $posts = qa_db_query_sub('SELECT userid, postid, netvotes FROM ^posts WHERE type=$ AND netvotes>0', 'C'); while (($post = qa_db_read_one_assoc($posts, true)) !== null) { $badges = array('nice_comment', 'good_comment', 'excellent_comment'); $awarded += count(qa_badge_award_check($badges, (int) $post['netvotes'], $post['userid'], $post['postid'], 2)); } return $awarded; }
function mp_get_contribution_points_by_userid($userid, $categoryid) { // retrieve raw points data $Qpoints = qa_db_read_one_assoc(qa_db_query_sub('SELECT 500 * COUNT(P.postid) points, 100 * COALESCE(SUM(P.upvotes),0) upvotes, 100 * COALESCE(SUM(P.downvotes),0) downvotes FROM ^posts P WHERE type = "Q" and categoryid = # and userid = #', $categoryid, $userid)); $Apoints = qa_db_read_one_assoc(qa_db_query_sub('SELECT 500 * COUNT(P.postid) points, 100 * COALESCE(SUM(P.upvotes),0) upvotes, 100 * COALESCE(SUM(P.downvotes),0) downvotes FROM ^posts P WHERE type = "A" AND categoryid = # AND userid = #', $categoryid, $userid)); return $Apoints['points'] + $Apoints['upvotes'] - $Apoints['downvotes']; }
function getuserfromhandle($handle) { require_once QA_INCLUDE_DIR . 'qa-app-users.php'; if (QA_FINAL_EXTERNAL_USERS) { $publictouserid = qa_get_userids_from_public(array($handle)); $userid = @$publictouserid[$handle]; } else { $userid = qa_db_read_one_value(qa_db_query_sub('SELECT userid FROM ^users WHERE handle = $', $handle), true); } return $userid; }
function q_view_clear() { // call default method output qa_html_theme_base::q_view_clear(); // return if not admin! if (qa_get_logged_in_level() < QA_USER_LEVEL_ADMIN) { return; } // check if question is duplicate $closed = @$this->content['q_view']['raw']['closedbyid'] !== null; if ($closed) { // check if duplicate $duplicate = qa_db_read_one_value(qa_db_query_sub('SELECT postid FROM `^posts` WHERE `postid` = # AND `type` = "Q" ;', $this->content['q_view']['raw']['closedbyid']), true); if ($duplicate) { $this->output('<div id="mergeDup" style="margin:10px 0 0 120px;padding:5px 10px;background:#FCC;border:1px solid #AAA;"><h3>Merge Duplicate:</h3>'); // form output $this->output(' <FORM METHOD="POST"> <TABLE> <TR> <TD CLASS="qa-form-tall-label"> From: <INPUT NAME="merge_from" id="merge_from" TYPE="text" VALUE="' . $this->content['q_view']['raw']['postid'] . '" CLASS="qa-form-tall-number"> To: <INPUT NAME="merge_to" id="merge_to" TYPE="text" VALUE="' . $this->content['q_view']['raw']['closedbyid'] . '" CLASS="qa-form-tall-number"> </TD> </TR> <TR> <TD CLASS="qa-form-tall-label"> Text to show when redirecting from merged question: </TD> </TR> <TR> <TD CLASS="qa-form-tall-label"> <INPUT NAME="merge_question_merged" id="merge_question_merged" TYPE="text" VALUE="' . qa_opt('merge_question_merged') . '" CLASS="qa-form-tall-text"> </TD> </TR> <TR> <TD style="text-align:right;"> <INPUT NAME="merge_question_process" VALUE="Merge" TITLE="" TYPE="submit" CLASS="qa-form-tall-button qa-form-tall-button-0"> </TD> </TR> </TABLE> </FORM> '); $this->output('</div>'); } } }
function a_count($post) { if (qa_opt('ccount') && isset($post['answers'])) { $this->output('<div class="qa-ac-count">'); qa_html_theme_base::a_count($post); $comments = qa_db_read_one_value(qa_db_query_sub("SELECT COUNT(postid) FROM ^posts WHERE (parentid=# OR parentid IN (SELECT postid FROM ^posts WHERE parentid=#)) AND type='C'", $post['raw']['postid'], $post['raw']['postid'])); $this->output_split(array('prefix' => '', 'data' => $comments, 'suffix' => ' comments'), 'qa-c-count', 'SPAN', 'SPAN'); $this->output('</div>'); } else { qa_html_theme_base::a_count($post); } }
function qa_db_cache_get($type, $cacheid) { if (qa_to_override(__FUNCTION__)) { $args = func_get_args(); return qa_call_override(__FUNCTION__, $args); } $content = qa_db_read_one_value(qa_db_query_sub('SELECT content FROM ^cache WHERE type=$ AND cacheid=#', $type, $cacheid), true); if (isset($content)) { qa_db_query_sub('UPDATE ^cache SET lastread=NOW() WHERE type=$ AND cacheid=#', $type, $cacheid); } return $content; }
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; }