Example #1
0
 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>');
     }
 }
Example #2
0
 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
 }
 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 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
 }
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);
}
Example #6
0
 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;
 }
Example #7
0
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;
}
Example #8
0
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));
    }
}
Example #9
0
function get_widgets_by_position($position)
{
    $widgets = qa_db_read_all_assoc(qa_db_query_sub('SELECT * FROM ^cs_widgets WHERE position = $ ORDER BY widget_order', $position));
    foreach ($widgets as $k => $w) {
        $param = unserialize($w['param']);
        $widgets[$k]['param'] = $param;
    }
    return $widgets;
}
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();
    }
}
Example #11
0
 function cs_user_post_list($handle, $type, $limit)
 {
     $userid = qa_handle_to_userid($handle);
     require_once QA_INCLUDE_DIR . 'qa-app-posts.php';
     $post = qa_db_read_all_assoc(qa_db_query_sub('SELECT * FROM ^posts INNER JOIN ^users ON ^posts.userid=^users.userid WHERE ^posts.type=$ and ^posts.userid=# ORDER BY ^posts.created DESC LIMIT #', $type, $userid, $limit));
     $output = '<ul class="question-list users-post-widget post-type-' . $type . '">';
     if (count($post) > 0) {
         foreach ($post as $p) {
             if ($type == 'Q') {
                 $what = qa_lang_html('cleanstrap/asked');
             } elseif ($type == 'A') {
                 $what = qa_lang_html('cleanstrap/answered');
             } elseif ('C') {
                 $what = qa_lang_html('cleanstrap/commented');
             }
             $handle = $p['handle'];
             $output .= '<li id="q-list-' . $p['postid'] . '" class="question-item">';
             if ($type == 'Q') {
                 $output .= '<div class="big-ans-count pull-left">' . $p['acount'] . '<span>' . qa_lang_html('cleanstrap/ans') . '</span></div>';
             } elseif ($type == 'A') {
                 $output .= '<div class="big-ans-count pull-left icon-answer"></div>';
             } elseif ($type == 'C') {
                 $output .= '<div class="big-ans-count pull-left icon-comment icon-comments"></div>';
             }
             $output .= '<div class="list-right">';
             $timeCode = qa_when_to_html(strtotime($p['created']), 7);
             $when = @$timeCode['prefix'] . @$timeCode['data'] . @$timeCode['suffix'];
             if ($type == 'Q') {
                 $output .= '<h5><a href="' . qa_q_path_html($p['postid'], $p['title']) . '" title="' . $p['title'] . '">' . qa_html($p['title']) . '</a></h5>';
             } elseif ($type == 'A') {
                 $output .= '<h5><a href="' . cs_post_link($p['parentid']) . '#a' . $p['postid'] . '">' . cs_truncate(strip_tags($p['content']), 300) . '</a></h5>';
             } else {
                 $output .= '<h5><a href="' . cs_post_link($p['parentid']) . '#c' . $p['postid'] . '">' . cs_truncate(strip_tags($p['content']), 300) . '</a></h5>';
             }
             $output .= '<div class="list-date"><span class="icon-clock">' . $when . '</span>';
             $output .= '<span class="icon-thumbs-up2">' . qa_lang_sub('cleanstrap/x_votes', $p['netvotes']) . '</span></div>';
             $output .= '</div>';
             $output .= '</li>';
         }
     } else {
         if ($type == 'Q') {
             $what = 'questions';
         } elseif ($type == 'A') {
             $what = 'answers';
         } elseif ('C') {
             $what = 'comments';
         }
         $output .= '<li class="no-post-found">' . qa_lang('cleanstrap/no_' . $what) . ' </li>';
     }
     $output .= '</ul>';
     echo $output;
 }
Example #12
0
 function html()
 {
     if (qa_post_text('ajax_merge_get_from')) {
         $posts = qa_db_read_all_assoc(qa_db_query_sub("SELECT postid,title FROM ^posts WHERE postid IN (#,#)", qa_post_text('ajax_merge_get_from'), qa_post_text('ajax_merge_get_to')));
         if ($posts[0]['postid'] == (int) qa_post_text('ajax_merge_get_from')) {
             echo '{"from":"' . $posts[0]['title'] . '","to":"' . $posts[1]['title'] . '","from_url":"' . qa_path_html(qa_q_request((int) qa_post_text('ajax_merge_get_from'), $posts[0]['title']), null, qa_opt('site_url')) . '","to_url":"' . qa_path_html(qa_q_request((int) qa_post_text('ajax_merge_get_to'), $posts[1]['title']), null, qa_opt('site_url')) . '"}';
         } else {
             echo '{"from":"' . $posts[1]['title'] . '","to":"' . $posts[0]['title'] . '","from_url":"' . qa_path_html(qa_q_request((int) qa_post_text('ajax_merge_get_from'), $posts[1]['title']), null, qa_opt('site_url')) . '","to_url":"' . qa_path_html(qa_q_request((int) qa_post_text('ajax_merge_get_to'), $posts[0]['title']), null, qa_opt('site_url')) . '"}';
         }
         return;
     }
     qa_html_theme_base::html();
 }
Example #13
0
function qa_get_public_from_userids($userids)
{
    global $wpdb, $qa_cache_wp_user_emails;
    if (count($userids)) {
        $useridtopublic = array();
        $qa_cache_wp_user_emails = array();
        $userfields = qa_db_read_all_assoc(qa_db_query_sub('SELECT ID, user_nicename, user_email FROM ' . $wpdb->base_prefix . 'users WHERE ID IN (#)', $userids), 'ID');
        foreach ($userfields as $id => $fields) {
            $useridtopublic[$id] = $fields['user_nicename'];
            $qa_cache_wp_user_emails[$id] = $fields['user_email'];
        }
        return $useridtopublic;
    } else {
        return array();
    }
}
 function doctype()
 {
     qa_html_theme_base::doctype();
     if (qa_opt('cp_enable') && ($this->template == 'ask' || isset($this->content['q_list']) || isset($this->content['q_view']))) {
         global $qa_request;
         global $wiki_enable;
         if ($this->template == 'ask' && !qa_user_permit_error('permit_post_q') && !qa_opt('site_maintenance') && qa_permit_check('permit_create_cp')) {
             $this->content['form']['tags'] .= ' onSubmit="pollSubmit(event)"';
             $this->content['form']['fields'][] = array('label' => qa_lang('cp/checkbox_text'), 'tags' => 'NAME="cp_community" ID="cp_community"', 'type' => 'checkbox', 'value' => qa_post_text('cp_community') ? 1 : 0);
         }
         if (isset($this->content['q_view'])) {
             $qid = $this->content['q_view']['raw']['postid'];
             $author = $this->content['q_view']['raw']['userid'];
             if (!isset($wiki_enable)) {
                 $result = qa_db_query_sub('SELECT * FROM ^postmeta WHERE meta_key=$ AND post_id=#', 'is_community', $qid);
                 $wiki_enable = $result->num_rows > 0;
             }
             if ($wiki_enable) {
                 // is a community post
                 $this->content['title'] .= ' ' . qa_lang('cp/question_title');
                 // $this->content['q_view']['content'] = @$this->content['q_view']['content'].'<div id="qa-wiki-div">'.$this->getPollDiv($qid,qa_get_logged_in_userid()).'</div>';
                 $this->content['q_view']['main_form_tags'] = @$this->content['q_view']['main_form_tags'] . ' class="qa-community-posts"';
                 // print_r($this->content['q_view']['form']['buttons']);
                 if (isset($this->content['q_view']['form']['buttons']['edit'])) {
                     $this->content['q_view']['form']['buttons']['edit']['label'] = qa_lang_html('cp/contribute');
                     $this->content['q_view']['form']['buttons']['edit']['popup'] = qa_lang_html('cp/contribute_description');
                 }
                 unset($this->content['q_view']['form']['buttons']['answer']);
                 unset($this->content['q_view']['form']['buttons']['comment']);
                 unset($this->content['a_form']);
                 unset($this->content['c_form']);
             }
         }
         if (isset($this->content['q_list'])) {
             $wiki_array = qa_db_read_all_assoc(qa_db_query_sub('SELECT * FROM ^postmeta WHERE meta_key=$', 'is_community'));
             foreach ($wiki_array as $q) {
                 $wiki[(int) $q['post_id']] = $q['meta_value'];
             }
             foreach ($this->content['q_list']['qs'] as $idx => $question) {
                 if (isset($wiki[$question['raw']['postid']])) {
                     $this->content['q_list']['qs'][$idx]['title'] .= ' ' . qa_lang('cp/question_title');
                 }
             }
         }
     }
 }
 function doctype()
 {
     if (qa_opt($this->opt) === '1') {
         // fetch all widgets into a basic list
         $sql = 'SELECT * FROM ^' . $this->pluginkey . ' ORDER BY ordering';
         $widgets = qa_db_read_all_assoc(qa_db_query_sub($sql));
         foreach ($widgets as $wid) {
             $wid['pages'] = explode(',', @$wid['pages']);
             $show_all = $wid['pages'][0] == 'all';
             $show_tmpl = in_array($this->template, $wid['pages']);
             $show_custom = in_array('custom:' . $this->request, $wid['pages']);
             if ($show_all || $show_tmpl || $show_custom) {
                 $this->widgets[] = $wid;
             }
         }
     }
     parent::doctype();
 }
Example #16
0
function qa_merge_do_merge()
{
    qa_opt('merge_question_merged', qa_post_text('merge_question_merged'));
    $from = (int) qa_post_text('merge_from');
    $to = (int) qa_post_text('merge_to');
    $titles = qa_db_read_all_assoc(qa_db_query_sub("SELECT postid,title,acount FROM ^posts WHERE postid IN (#,#)", qa_post_text('merge_from'), qa_post_text('merge_to')));
    if (count($titles) != 2) {
        $error1 = null;
        $error2 = null;
        if (empty($titles)) {
            $error1 = 'Post not found.';
            $error2 = $error1;
        } else {
            if ($titles[0]['postid'] == $from) {
                $error2 = 'Post not found.';
            } else {
                if ($titles[0]['postid'] == $to) {
                    $error1 = 'Post not found.';
                } else {
                    $error1 = 'unknown error.';
                }
            }
        }
        return array($error1, $error2);
    } else {
        $acount = (int) $titles[0]['acount'] + (int) $titles[1]['acount'];
        $text = '<div class="qa-content-merged"> ' . str_replace('^post', qa_path(qa_q_request((int) qa_post_text('merge_to'), $titles[0]['postid'] == $to ? $titles[0]['title'] : $titles[1]['title']), null, qa_opt('site_url')), qa_opt('merge_question_merged')) . ' </div>';
        qa_db_query_sub("UPDATE ^posts SET parentid=# WHERE parentid=#", $to, $from);
        qa_db_query_sub("UPDATE ^posts SET acount=# WHERE postid=#", $acount, $to);
        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_db_query_sub("INSERT INTO ^postmeta (post_id,meta_key,meta_value) VALUES (#,'merged_with',#)", $from, $to);
        require_once QA_INCLUDE_DIR . 'qa-app-posts.php';
        qa_post_delete($from);
        return true;
    }
}
Example #17
0
 function cs_post_list($type, $limit, $return = false)
 {
     $posts = qa_db_read_all_assoc(qa_db_query_sub('SELECT ^posts.* , ^users.* FROM ^posts, ^users WHERE ^posts.userid=^users.userid AND ^posts.type=$ ORDER BY ^posts.created DESC LIMIT #', $type, $limit));
     $output = '<ul class="posts-list">';
     foreach ($posts as $p) {
         if ($type == 'Q') {
             $what = qa_lang_html('cleanstrap/asked');
         } elseif ($type == 'A') {
             $what = qa_lang_html('cleanstrap/answered');
         } elseif ('C') {
             $what = qa_lang_html('cleanstrap/commented');
         }
         $handle = $p['handle'];
         $timeCode = qa_when_to_html(strtotime($p['created']), 7);
         $when = @$timeCode['prefix'] . @$timeCode['data'] . @$timeCode['suffix'];
         $output .= '<li>';
         $output .= cs_get_post_avatar($p, $p['userid'], 30, true);
         $output .= '<div class="post-content">';
         if ($type == 'Q') {
             $output .= '<a class="title question" href="' . qa_q_path_html($p['postid'], $p['title']) . '" title="' . $p['title'] . '">' . qa_html($p['title']) . '</a>';
         } elseif ($type == 'A') {
             $output .= '<a class="title" href="' . cs_post_link($p['parentid']) . '#a' . $p['postid'] . '">' . cs_truncate(strip_tags($p['content']), 100) . '</a>';
         } else {
             $output .= '<a class="title" href="' . cs_post_link($p['parentid']) . '#c' . $p['postid'] . '">' . cs_truncate(strip_tags($p['content']), 100) . '</a>';
         }
         $output .= '<div class="meta">';
         //$output .= '<span><a href="' . qa_path_html('user/' . $handle) . '">' . cs_name($handle) . '</a> ' . $what . '</span>';
         if ($type == 'Q') {
             $output .= '<span>' . qa_lang_sub('cleanstrap/x_answers', $p['acount']) . '</span>';
         }
         $output .= '<span class="time icon-time">' . $when . '</span>';
         $output .= '<span class="vote-count icon-thumbs-up2">' . qa_lang_sub('cleanstrap/x_votes', $p['netvotes']) . '</span>';
         $output .= '</div>';
         $output .= '</div>';
         $output .= '</li>';
     }
     $output .= '</ul>';
     if ($return) {
         return $output;
     }
     echo $output;
 }
 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;
 }
 function cs_top_users($limit = 5, $size)
 {
     $users = qa_db_read_all_assoc(qa_db_query_sub('SELECT * FROM ^users JOIN ^userpoints ON ^users.userid=^userpoints.userid ORDER BY ^userpoints.points DESC LIMIT #', $limit));
     $output = '<ul class="top-users-list clearfix">';
     foreach ($users as $u) {
         if (defined('QA_WORDPRESS_INTEGRATE_PATH')) {
             require_once QA_INCLUDE_DIR . 'qa-app-posts.php';
             $u['handle'] = qa_post_userid_to_handle($u['userid']);
         }
         $output .= '<li class="top-user clearfix">';
         $output .= cs_get_post_avatar($u, $u['userid'], $size, true);
         $output .= '<div class="top-user-data">';
         $output .= '<span class="points">' . $u['points'] . ' ' . qa_lang('cleanstrap/points') . '</span>';
         $output .= '<a href="' . qa_path_html('user/' . $u['handle']) . '" class="name">' . $u['handle'] . '</a>';
         $output .= '<p class="counts"><span>' . qa_lang_sub('cleanstrap/x_questions', $u['qposts']) . '</span> <span>' . qa_lang_sub('cleanstrap/x_answers', $u['aposts']) . '</span><span>' . qa_lang_sub('cleanstrap/x_comments', $u['cposts']) . '</span></p>';
         $output .= '</div>';
         $output .= '</li>';
     }
     $output .= '</ul>';
     return $output;
 }
function qa_db_limits_get($userid, $ip, $action)
{
    $selects = array();
    $arguments = array();
    if (isset($userid)) {
        $selects[] = "(SELECT 'user' AS limitkey, period, count FROM ^userlimits WHERE userid=\$ AND action=\$)";
        $arguments[] = $userid;
        $arguments[] = $action;
    }
    if (isset($ip)) {
        $selects[] = "(SELECT 'ip' AS limitkey, period, count FROM ^iplimits WHERE ip=COALESCE(INET_ATON(\$), 0) AND action=\$)";
        $arguments[] = $ip;
        $arguments[] = $action;
    }
    if (count($selects)) {
        $query = qa_db_apply_sub(implode(' UNION ALL ', $selects), $arguments);
        return qa_db_read_all_assoc(qa_db_query_raw($query), 'limitkey');
    } else {
        return array();
    }
}
    function logged_in()
    {
        if (qa_get_logged_in_userid()) {
            if ($this->template == "question") {
                $qnum = qa_request_part("0");
                qa_db_query_sub("UPDATE ^userevents SET lastview = NOW() WHERE questionid = {$qnum} AND userid = " . qa_get_logged_in_userid());
            }
            $questions = qa_db_read_all_assoc(qa_db_query_sub("SELECT DISTINCT(questionid), lastpostid FROM ^userevents WHERE lastview < updated OR lastview IS NULL"));
            $count = count($questions);
            $notifyclass = "qa-notification-none";
            if ($count > 0) {
                $notifyclass = "qa-notification-new";
            }
            $this->output('
				<span class="qa-notification-counter ' . $notifyclass . '">' . $count . '</span>
				');
            $this->output('<div class="qa-notification-dialog">');
            foreach ($questions as $question) {
                $q = qa_post_get_full($question["questionid"]);
                $post = qa_post_get_full($question["lastpostid"]);
                $type = "";
                if ($post["type"] == "A") {
                    $type = "answer";
                } else {
                    if ($post["type"] == "C") {
                        $type = "comment";
                    }
                }
                if ($post["userid"] == NULL) {
                    $user = "******";
                } else {
                    $user = qa_userids_to_handles(array($post["userid"]));
                    $user = $user[$post["userid"]];
                }
                $this->output('<div class="qa-notification-dialog-entry">', '<a href="' . qa_q_path($question["questionid"], $q["title"]) . '">' . $q["title"] . '</a>', '<div>New ' . $type . ' by ' . $user . ': "' . substr($post["content"], 0, 100) . '"</div>', '</div>');
            }
            $this->output('</div>');
        }
        qa_html_theme_base::logged_in();
    }
Example #22
0
 function cs_new_users($limit, $size, $widget_opt)
 {
     $output = '<ul class="users-list clearfix">';
     if (defined('QA_FINAL_WORDPRESS_INTEGRATE_PATH')) {
         global $wpdb;
         $users = $wpdb->get_results("SELECT ID from {$wpdb->users} order by ID DESC LIMIT {$limit}");
         require_once QA_INCLUDE_DIR . 'qa-app-posts.php';
         foreach ($users as $u) {
             $handle = qa_post_userid_to_handle($u->ID);
             $output .= '<li class="user">';
             $output .= '<div class="avatar" data-handle="' . $handle . '" data-id="' . qa_handle_to_userid($handle) . '"><img src="' . cs_get_avatar($u['handle'], $size, false) . '" /></div>';
             $output .= '</li>';
         }
     } else {
         if (qa_opt('avatar_allow_upload') && @$widget_opt['cs_nu_with_avatar']) {
             $users = qa_db_read_all_assoc(qa_db_query_sub("SELECT * FROM ^users WHERE avatarblobid IS NOT NULL ORDER BY created DESC LIMIT #", $limit));
         } elseif (qa_opt('avatar_allow_gravatar') || qa_opt('avatar_default_show') && strlen(qa_opt('avatar_default_blobid'))) {
             $users = qa_db_read_all_assoc(qa_db_query_sub("SELECT * FROM ^users ORDER BY created DESC LIMIT #", $limit));
         }
         //refresh every 10 minutes
         foreach ($users as $u) {
             if (isset($u['handle'])) {
                 $handle = $u['handle'];
                 $avatar = cs_get_avatar($handle, $size, false);
                 if (isset($u['useid'])) {
                     $id = $u['useid'];
                 } else {
                     $id = qa_handle_to_userid($handle);
                 }
                 $output .= '<li class="user">';
                 if (!empty($avatar)) {
                     $output .= '<a href="' . qa_path_html('user/' . $handle) . '"><div class="avatar" data-handle="' . $handle . '" data-id="' . $id . '"><img src="' . $avatar . '" /></div></a>';
                 }
                 $output .= '</li>';
             }
         }
     }
     $output .= '</ul>';
     echo $output;
 }
 function qa_check_all_users_badges()
 {
     $awarded = 0;
     $users;
     $temp = qa_db_query_sub('SELECT * FROM ^posts');
     while (($post = qa_db_read_one_assoc($temp, true)) !== null) {
         if (!$post['userid']) {
             continue;
         }
         $user = '******' . $post['userid'];
         $pid = $post['postid'];
         $pt = $post['type'];
         // get post count
         if (isset($users[$user]) && isset($users[$user][$pt])) {
             $users[$user][$pt]++;
         } else {
             $users[$user][$pt] = 1;
         }
         // get post votes
         if ($post['netvotes'] != 0) {
             $users[$user][$pt . 'votes'][] = array('id' => $pid, 'votes' => (int) $post['netvotes'], 'parentid' => $post['parentid'], 'created' => $post['created']);
         }
         // get post views
         if ($post['views']) {
             $users[$user]['views'][] = array('id' => $pid, 'views' => $post['views']);
         }
     }
     //votes received and given out
     $voter = qa_db_read_all_assoc(qa_db_query_sub('SELECT userid,qupvotes,qdownvotes,aupvotes,adownvotes,upvoteds FROM ^userpoints'));
     foreach ($voter as $idx => $votes) {
         $user = '******' . $votes['userid'];
         // votes
         $users[$user]['votes'] = (int) $votes['qupvotes'] + (int) $votes['qdownvotes'] + (int) $votes['aupvotes'] + (int) $votes['adownvotes'];
         // voteds
         $users[$user]['voted'] = (int) $votes['upvoteds'];
         unset($voter[$idx]);
     }
     // flags
     $flag_result = qa_db_read_all_values(qa_db_query_sub('SELECT userid FROM ^uservotes WHERE flag > 0'));
     foreach ($flag_result as $idx => $flag) {
         $user = '******' . $flag;
         // get flag count
         if (isset($users[$user]) && isset($users[$user]['flags'])) {
             $users[$user]['flags']++;
         } else {
             $users[$user]['flags'] = 1;
         }
         unset($flag_result[$idx]);
     }
     // per user loop
     foreach ($users as $user => $data) {
         $uid = (int) substr($user, 4);
         // bulk posts
         $badges = array('Q' => array('asker', 'questioner', 'inquisitor'), 'A' => array('answerer', 'lecturer', 'preacher'), 'C' => array('commenter', 'commentator', 'annotator'));
         foreach ($badges as $pt => $slugs) {
             if (!isset($data[$pt])) {
                 continue;
             }
             $awarded += count(qa_badge_award_check($slugs, $data[$pt], $uid, null, 0));
         }
         // nice Q&A
         $badges = array('nice_question', 'good_question', 'great_question', 'nice_answer', 'good_answer', 'great_answer');
         if ($this->badge_activated($badges)) {
             $badges = array('Q' => array('nice_question', 'good_question', 'great_question'), 'A' => array('nice_answer', 'good_answer', 'great_answer'));
             foreach ($badges as $pt => $slugs) {
                 foreach ($slugs as $badge_slug) {
                     if (!isset($data[$pt . 'votes'])) {
                         continue;
                     }
                     foreach ($data[$pt . 'votes'] as $idv) {
                         // poll plugin integration
                         if ($pt == 'A' && qa_opt('poll_enable')) {
                             $poll = qa_db_read_one_value(qa_db_query_sub('SELECT meta_value FROM ^postmeta WHERE post_id=# AND meta_key=$', $idv['id'], 'is_poll'), true);
                             if ($poll) {
                                 continue;
                             }
                         }
                         if ((int) $idv['votes'] >= (int) qa_opt('badge_' . $badge_slug . '_var') && qa_opt('badge_' . $badge_slug . '_enabled') !== '0') {
                             $result = qa_db_read_one_value(qa_db_query_sub('SELECT badge_slug FROM ^userbadges WHERE user_id=# AND object_id=# AND badge_slug=$', $uid, $idv['id'], $badge_slug), true);
                             if ($result == null) {
                                 // not already awarded this badge
                                 $this->award_badge($idv['id'], $uid, $badge_slug, false, true);
                                 $awarded++;
                             }
                             // old question answer vote checks
                             if ($pt == 'A') {
                                 $qid = $idv['parentid'];
                                 $create = strtotime($idv['created']);
                                 $parent = $this->get_post_data($qid);
                                 $pcreate = strtotime($parent['created']);
                                 $diff = round(abs($pcreate - $create) / 60 / 60 / 24);
                                 $badge_slug2 = $badge_slug . '_old';
                                 if ($diff >= (int) qa_opt('badge_' . $badge_slug2 . '_var') && qa_opt('badge_' . $badge_slug2 . '_enabled') !== '0') {
                                     $result = qa_db_read_one_value(qa_db_query_sub('SELECT badge_slug FROM ^userbadges WHERE user_id=# AND object_id=# AND badge_slug=$', $uid, $idv['id'], $badge_slug2), true);
                                     if ($result == null) {
                                         // not already awarded for this answer
                                         $this->award_badge($idv['id'], $uid, $badge_slug2);
                                         $awarded++;
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
         // votes per user badges
         if (isset($data['votes'])) {
             $votes = $data['votes'];
             $badges = array('voter', 'avid_voter', 'devoted_voter');
             $awarded += count(qa_badge_award_check($badges, $votes, $uid, null, 0));
         }
         // voted per user badges
         if (isset($data['voted'])) {
             $votes = $data['voted'];
             $badges = array('liked', 'loved', 'revered');
             $awarded += count(qa_badge_award_check($badges, $votes, $uid, null, 0));
         }
         // views per post badges
         if (isset($data['views'])) {
             $badges = array('notable_question', 'popular_question', 'famous_question');
             foreach ($data['views'] as $idv) {
                 $awarded += count(qa_badge_award_check($badges, $idv['views'], $uid, $idv['id'], 0));
             }
         }
         // flags per user
         if (isset($data['flags'])) {
             $flags = $data['flags'];
             $badges = array('watchdog', 'bloodhound', 'pitbull');
             $awarded += count(qa_badge_award_check($badges, $flags, $uid, null, 0));
         }
         unset($users[$user]);
     }
     // selects, selecteds
     $badges = array('gifted', 'wise', 'enlightened', 'grateful', 'respectful', 'reverential');
     if ($this->badge_activated($badges)) {
         $selects = qa_db_read_all_assoc(qa_db_query_sub('SELECT aselects, aselecteds, userid FROM ^userpoints'));
         foreach ($selects as $idx => $s) {
             $uid = $s['userid'];
             if (isset($s['aselecteds'])) {
                 $count = $s['aselecteds'];
                 $badges = array('gifted', 'wise', 'enlightened');
                 $awarded += count(qa_badge_award_check($badges, $count, $uid, null, 0));
             }
             if (isset($s['aselects'])) {
                 $count = $s['aselects'];
                 $badges = array('grateful', 'respectful', 'reverential');
                 $awarded += count(qa_badge_award_check($badges, $count, $uid, null, 0));
             }
             unset($selects[$idx]);
         }
     }
     // achievements
     $badges = array('dedicated', 'devoted', 'zealous', 'visitor', 'trouper', 'veteran', 'regular', 'old_timer', 'ancestor', 'reader', 'avid_reader', 'devoted_reader');
     if ($this->badge_activated($badges)) {
         $userq = qa_db_query_sub('SELECT user_id AS uid,questions_read AS qr,oldest_consec_visit AS ocv,longest_consec_visit AS lcv,total_days_visited AS tdv,last_visit AS lv,first_visit AS fv,posts_edited AS pe FROM ^achievements');
         while (($user = qa_db_read_one_assoc($userq, true)) !== null) {
             $uid = $user['uid'];
             // edits
             $count = $user['pe'];
             $badges = array('editor', 'copy_editor', 'senior_editor');
             $awarded += count(qa_badge_award_check($badges, $count, $uid, null, 0));
             // on-sign-in badges
             // check lapse in days since last visit
             // using julian days
             $todayj = GregorianToJD(date('n'), date('j'), date('Y'));
             $last_visit = strtotime($user['lv']);
             $lastj = GregorianToJD(date('n', $last_visit), date('j', $last_visit), date('Y', $last_visit));
             $last_diff = $todayj - $lastj;
             $first_visit = strtotime($user['fv']);
             $first_visitj = GregorianToJD(date('n', $first_visit), date('j', $first_visit), date('Y', $first_visit));
             $first_visit_diff = $todayj - $first_visitj;
             $badges = array('dedicated', 'devoted', 'zealous');
             $awarded += count(qa_badge_award_check($badges, $user['lcv'], $uid, null, 0));
             $badges = array('visitor', 'trouper', 'veteran');
             $awarded += count(qa_badge_award_check($badges, $user['tdv'], $uid, null, 0));
             $badges = array('regular', 'old_timer', 'ancestor');
             $awarded += count(qa_badge_award_check($badges, $first_visit_diff, $uid, null, 0));
             // views
             $badges = array('reader', 'avid_reader', 'devoted_reader');
             $awarded += count(qa_badge_award_check($badges, $user['qr'], $uid, null, 0));
         }
     }
     // points
     $badges = array('100_club', '1000_club', '10000_club');
     if ($this->badge_activated($badges)) {
         $userq = qa_db_query_sub('SELECT userid, points FROM ^userpoints');
         while (($user = qa_db_read_one_assoc($userq, true)) !== null) {
             $awarded += count(qa_badge_award_check($badges, $user['points'], $user['userid'], null, 0));
         }
     }
     if (!QA_FINAL_EXTERNAL_USERS) {
         // verified
         $badges = array('verified');
         if ($this->badge_activated($badges)) {
             $userq = qa_db_query_sub('SELECT userid, flags FROM ^users WHERE flags&#', QA_USER_FLAGS_EMAIL_CONFIRMED);
             while (($user = qa_db_read_one_assoc($userq, true)) !== null) {
                 $awarded += count(qa_badge_award_check($badges, false, $user['userid'], null, 0));
             }
         }
         // profile stuff
         $badges = array('avatar', 'profiler');
         if ($this->badge_activated($badges)) {
             $userq = qa_db_query_sub('SELECT userid FROM ^users');
             while (($userid = qa_db_read_one_value($userq, true)) !== null) {
                 list($useraccount, $userprofile, $userfields) = qa_db_select_with_pending(qa_db_user_account_selectspec($userid, true), qa_db_user_profile_selectspec($userid, true), qa_db_userfields_selectspec());
                 // avatar badge
                 if (qa_opt('avatar_allow_upload') && isset($useraccount['avatarblobid'])) {
                     $badges = array('avatar');
                     $awarded += count(qa_badge_award_check($badges, false, $userid, null, 0));
                 }
                 // profile completion
                 $missing = false;
                 foreach ($userfields as $userfield) {
                     if (!isset($userprofile[$userfield['title']]) || @$userprofile[$userfield['title']] === '') {
                         $missing = true;
                         break;
                     }
                 }
                 if (!$missing) {
                     $badges = array('profiler');
                     $awarded += count(qa_badge_award_check($badges, false, $userid, null, 0));
                 }
             }
         }
     }
     // rebuild badges from other plugins - experimental! - $module->custom_badges_rebuild() returns number of badges awarded.
     $moduletypes = qa_list_module_types();
     foreach ($moduletypes as $moduletype) {
         $modulenames = qa_list_modules($moduletype);
         foreach ($modulenames as $modulename) {
             $module = qa_load_module($moduletype, $modulename);
             if (method_exists($module, 'custom_badges_rebuild')) {
                 $awarded += $module->custom_badges_rebuild();
             }
         }
     }
     // badges
     $badges = array('medalist', 'champion', 'olympian');
     if ($this->badge_activated($badges)) {
         $badgelist = qa_db_read_all_values(qa_db_query_sub('SELECT user_id FROM ^userbadges'));
         $users = array();
         foreach ($badgelist as $idx => $medal) {
             $user = '******' . $medal;
             // get badge count
             if (isset($users[$user]) && isset($users[$user]['medals'])) {
                 $users[$user]['medals']++;
             } else {
                 $users[$user]['medals'] = 1;
             }
             unset($badgelist[$idx]);
         }
         foreach ($users as $user => $data) {
             $uid = (int) substr($user, 4);
             // check badges
             if (isset($data['medals'])) {
                 $uid = (int) substr($user, 4);
                 $count = $data['medals'];
                 $awarded += count(qa_badge_award_check($badges, $count, $uid, null, 0));
             }
             unset($users[$user]);
         }
     }
     // return ok text
     return $awarded . ' badge' . ($awarded != 1 ? 's' : '') . ' awarded.';
 }
function qa_db_word_mapto_ids($words)
{
    if (count($words)) {
        return qa_db_read_all_assoc(qa_db_query_sub('SELECT wordid, word FROM ^words WHERE word IN ($)', $words), 'word', 'wordid');
    } else {
        return array();
    }
}
Example #25
0
function qa_db_upgrade_tables()
{
    require_once QA_INCLUDE_DIR . 'app/recalc.php';
    $definitions = qa_db_table_definitions();
    $keyrecalc = array();
    //	Write-lock all Q2A tables before we start so no one can read or write anything
    $keydbtables = qa_array_to_keys(qa_db_list_tables());
    foreach ($definitions as $rawname => $definition) {
        if (isset($keydbtables[qa_db_add_table_prefix($rawname)])) {
            $locks[] = '^' . $rawname . ' WRITE';
        }
    }
    $locktablesquery = 'LOCK TABLES ' . implode(', ', $locks);
    qa_db_upgrade_query($locktablesquery);
    //	Upgrade it step-by-step until it's up to date (do LOCK TABLES after ALTER TABLE because the lock can sometimes be lost)
    while (1) {
        $version = qa_db_get_db_version();
        if ($version >= QA_DB_VERSION_CURRENT) {
            break;
        }
        $newversion = $version + 1;
        qa_db_upgrade_progress(QA_DB_VERSION_CURRENT - $version . ' upgrade step/s remaining...');
        switch ($newversion) {
            //	Up to here: Version 1.0 beta 1
            case 2:
                qa_db_upgrade_query('ALTER TABLE ^posts DROP COLUMN votes, ADD COLUMN upvotes ' . $definitions['posts']['upvotes'] . ' AFTER cookieid, ADD COLUMN downvotes ' . $definitions['posts']['downvotes'] . ' AFTER upvotes');
                qa_db_upgrade_query($locktablesquery);
                $keyrecalc['dorecountposts'] = true;
                break;
            case 3:
                qa_db_upgrade_query('ALTER TABLE ^userpoints ADD COLUMN upvoteds ' . $definitions['userpoints']['upvoteds'] . ' AFTER avoteds, ADD COLUMN downvoteds ' . $definitions['userpoints']['downvoteds'] . ' AFTER upvoteds');
                qa_db_upgrade_query($locktablesquery);
                $keyrecalc['dorecalcpoints'] = true;
                break;
            case 4:
                qa_db_upgrade_query('ALTER TABLE ^posts ADD COLUMN lastuserid ' . $definitions['posts']['lastuserid'] . ' AFTER cookieid, CHANGE COLUMN updated updated ' . $definitions['posts']['updated']);
                qa_db_upgrade_query($locktablesquery);
                qa_db_upgrade_query('UPDATE ^posts SET updated=NULL WHERE updated=0 OR updated=created');
                break;
            case 5:
                qa_db_upgrade_query('ALTER TABLE ^contentwords ADD COLUMN type ' . $definitions['contentwords']['type'] . ' AFTER count, ADD COLUMN questionid ' . $definitions['contentwords']['questionid'] . ' AFTER type');
                qa_db_upgrade_query($locktablesquery);
                $keyrecalc['doreindexcontent'] = true;
                break;
                //	Up to here: Version 1.0 beta 2
            //	Up to here: Version 1.0 beta 2
            case 6:
                qa_db_upgrade_query('ALTER TABLE ^userpoints ADD COLUMN cposts ' . $definitions['userpoints']['cposts'] . ' AFTER aposts');
                qa_db_upgrade_query($locktablesquery);
                $keyrecalc['dorecalcpoints'] = true;
                break;
            case 7:
                if (!QA_FINAL_EXTERNAL_USERS) {
                    qa_db_upgrade_query('ALTER TABLE ^users ADD COLUMN sessioncode ' . $definitions['users']['sessioncode'] . ' AFTER writeip');
                    qa_db_upgrade_query($locktablesquery);
                }
                break;
            case 8:
                qa_db_upgrade_query('ALTER TABLE ^posts ADD KEY (type, acount, created)');
                qa_db_upgrade_query($locktablesquery);
                $keyrecalc['dorecountposts'] = true;
                // for unanswered question count
                break;
                //	Up to here: Version 1.0 beta 3, 1.0, 1.0.1 beta, 1.0.1
            //	Up to here: Version 1.0 beta 3, 1.0, 1.0.1 beta, 1.0.1
            case 9:
                if (!QA_FINAL_EXTERNAL_USERS) {
                    qa_db_upgrade_query('ALTER TABLE ^users CHANGE COLUMN resetcode emailcode ' . $definitions['users']['emailcode'] . ', ADD COLUMN flags ' . $definitions['users']['flags'] . ' AFTER sessioncode');
                    qa_db_upgrade_query($locktablesquery);
                    qa_db_upgrade_query('UPDATE ^users SET flags=1');
                }
                break;
            case 10:
                qa_db_upgrade_query('UNLOCK TABLES');
                qa_db_upgrade_query(qa_db_create_table_sql('categories', array('categoryid' => $definitions['categories']['categoryid'], 'title' => $definitions['categories']['title'], 'tags' => $definitions['categories']['tags'], 'qcount' => $definitions['categories']['qcount'], 'position' => $definitions['categories']['position'], 'PRIMARY KEY (categoryid)', 'UNIQUE tags (tags)', 'UNIQUE position (position)')));
                // hard-code list of columns and indexes to ensure we ignore any added at a later stage
                $locktablesquery .= ', ^categories WRITE';
                qa_db_upgrade_query($locktablesquery);
                break;
            case 11:
                qa_db_upgrade_query('ALTER TABLE ^posts ADD CONSTRAINT ^posts_ibfk_2 FOREIGN KEY (parentid) REFERENCES ^posts(postid), ADD COLUMN categoryid ' . $definitions['posts']['categoryid'] . ' AFTER parentid, ADD KEY categoryid (categoryid, type, created), ADD CONSTRAINT ^posts_ibfk_3 FOREIGN KEY (categoryid) REFERENCES ^categories(categoryid) ON DELETE SET NULL');
                // foreign key on parentid important now that deletion is possible
                qa_db_upgrade_query($locktablesquery);
                break;
            case 12:
                qa_db_upgrade_query('UNLOCK TABLES');
                qa_db_upgrade_query(qa_db_create_table_sql('pages', array('pageid' => $definitions['pages']['pageid'], 'title' => $definitions['pages']['title'], 'nav' => $definitions['pages']['nav'], 'position' => $definitions['pages']['position'], 'flags' => $definitions['pages']['flags'], 'tags' => $definitions['pages']['tags'], 'heading' => $definitions['pages']['heading'], 'content' => $definitions['pages']['content'], 'PRIMARY KEY (pageid)', 'UNIQUE tags (tags)', 'UNIQUE position (position)')));
                // hard-code list of columns and indexes to ensure we ignore any added at a later stage
                $locktablesquery .= ', ^pages WRITE';
                qa_db_upgrade_query($locktablesquery);
                break;
            case 13:
                qa_db_upgrade_query('ALTER TABLE ^posts ADD COLUMN createip ' . $definitions['posts']['createip'] . ' AFTER cookieid, ADD KEY createip (createip, created)');
                qa_db_upgrade_query($locktablesquery);
                break;
            case 14:
                qa_db_upgrade_query('ALTER TABLE ^userpoints DROP COLUMN qvotes, DROP COLUMN avotes, ADD COLUMN qupvotes ' . $definitions['userpoints']['qupvotes'] . ' AFTER aselecteds, ADD COLUMN qdownvotes ' . $definitions['userpoints']['qdownvotes'] . ' AFTER qupvotes, ADD COLUMN aupvotes ' . $definitions['userpoints']['aupvotes'] . ' AFTER qdownvotes, ADD COLUMN adownvotes ' . $definitions['userpoints']['adownvotes'] . ' AFTER aupvotes');
                qa_db_upgrade_query($locktablesquery);
                $keyrecalc['dorecalcpoints'] = true;
                break;
                //	Up to here: Version 1.2 beta 1
            //	Up to here: Version 1.2 beta 1
            case 15:
                if (!QA_FINAL_EXTERNAL_USERS) {
                    qa_db_upgrade_table_columns($definitions, 'users', array('emailcode', 'sessioncode', 'flags'));
                }
                qa_db_upgrade_table_columns($definitions, 'posts', array('acount', 'upvotes', 'downvotes', 'format'));
                qa_db_upgrade_table_columns($definitions, 'categories', array('qcount'));
                qa_db_upgrade_table_columns($definitions, 'words', array('titlecount', 'contentcount', 'tagcount'));
                qa_db_upgrade_table_columns($definitions, 'userpoints', array('points', 'qposts', 'aposts', 'cposts', 'aselects', 'aselecteds', 'qupvotes', 'qdownvotes', 'aupvotes', 'adownvotes', 'qvoteds', 'avoteds', 'upvoteds', 'downvoteds'));
                qa_db_upgrade_query($locktablesquery);
                break;
                //	Up to here: Version 1.2 (release)
            //	Up to here: Version 1.2 (release)
            case 16:
                qa_db_upgrade_table_columns($definitions, 'posts', array('format'));
                qa_db_upgrade_query($locktablesquery);
                $keyrecalc['doreindexcontent'] = true;
                // because of new treatment of apostrophes in words
                break;
            case 17:
                qa_db_upgrade_query('ALTER TABLE ^posts ADD KEY updated (updated, type), ADD KEY categoryid_2 (categoryid, updated, type)');
                qa_db_upgrade_query($locktablesquery);
                break;
            case 18:
                qa_db_upgrade_query('ALTER TABLE ^posts ADD COLUMN lastip ' . $definitions['posts']['lastip'] . ' AFTER lastuserid, ADD KEY lastip (lastip, updated, type)');
                qa_db_upgrade_query($locktablesquery);
                break;
            case 19:
                if (!QA_FINAL_EXTERNAL_USERS) {
                    qa_db_upgrade_query('ALTER TABLE ^users ADD COLUMN avatarblobid ' . $definitions['users']['avatarblobid'] . ' AFTER handle, ADD COLUMN avatarwidth ' . $definitions['users']['avatarwidth'] . ' AFTER avatarblobid, ADD COLUMN avatarheight ' . $definitions['users']['avatarheight'] . ' AFTER avatarwidth');
                }
                // hard-code list of columns and indexes to ensure we ignore any added at a later stage
                qa_db_upgrade_query('UNLOCK TABLES');
                qa_db_upgrade_query(qa_db_create_table_sql('blobs', array('blobid' => $definitions['blobs']['blobid'], 'format' => $definitions['blobs']['format'], 'content' => $definitions['blobs']['content'], 'PRIMARY KEY (blobid)')));
                qa_db_upgrade_query(qa_db_create_table_sql('cache', array('type' => $definitions['cache']['type'], 'cacheid' => $definitions['cache']['cacheid'], 'content' => $definitions['cache']['content'], 'created' => $definitions['cache']['created'], 'lastread' => $definitions['cache']['lastread'], 'PRIMARY KEY (type,cacheid)', 'KEY (lastread)')));
                // hard-code list of columns and indexes to ensure we ignore any added at a later stage
                $locktablesquery .= ', ^blobs WRITE, ^cache WRITE';
                qa_db_upgrade_query($locktablesquery);
                break;
            case 20:
                if (!QA_FINAL_EXTERNAL_USERS) {
                    qa_db_upgrade_query('UNLOCK TABLES');
                    qa_db_upgrade_query(qa_db_create_table_sql('userlogins', array('userid' => $definitions['userlogins']['userid'], 'source' => $definitions['userlogins']['source'], 'identifier' => $definitions['userlogins']['identifier'], 'identifiermd5' => $definitions['userlogins']['identifiermd5'], 'KEY source (source, identifiermd5)', 'KEY userid (userid)', 'CONSTRAINT ^userlogins_ibfk_1 FOREIGN KEY (userid) REFERENCES ^users(userid) ON DELETE CASCADE')));
                    qa_db_upgrade_query('ALTER TABLE ^users CHANGE COLUMN passsalt passsalt ' . $definitions['users']['passsalt'] . ', CHANGE COLUMN passcheck passcheck ' . $definitions['users']['passcheck']);
                    $locktablesquery .= ', ^userlogins WRITE';
                    qa_db_upgrade_query($locktablesquery);
                }
                break;
            case 21:
                if (!QA_FINAL_EXTERNAL_USERS) {
                    qa_db_upgrade_query('UNLOCK TABLES');
                    qa_db_upgrade_query(qa_db_create_table_sql('userfields', array('fieldid' => $definitions['userfields']['fieldid'], 'title' => $definitions['userfields']['title'], 'content' => $definitions['userfields']['content'], 'position' => $definitions['userfields']['position'], 'flags' => $definitions['userfields']['flags'], 'PRIMARY KEY (fieldid)')));
                    $locktablesquery .= ', ^userfields WRITE';
                    qa_db_upgrade_query($locktablesquery);
                    qa_db_upgrade_query(qa_db_default_userfields_sql());
                }
                break;
                //	Up to here: Version 1.3 beta 1
            //	Up to here: Version 1.3 beta 1
            case 22:
                if (!QA_FINAL_EXTERNAL_USERS) {
                    qa_db_upgrade_query('ALTER TABLE ^users ADD COLUMN sessionsource ' . $definitions['users']['sessionsource'] . ' AFTER sessioncode');
                    qa_db_upgrade_query($locktablesquery);
                }
                break;
                //	Up to here: Version 1.3 beta 2 and release
            //	Up to here: Version 1.3 beta 2 and release
            case 23:
                qa_db_upgrade_query('UNLOCK TABLES');
                qa_db_upgrade_query(qa_db_create_table_sql('widgets', array('widgetid' => $definitions['widgets']['widgetid'], 'place' => $definitions['widgets']['place'], 'position' => $definitions['widgets']['position'], 'tags' => $definitions['widgets']['tags'], 'title' => $definitions['widgets']['title'], 'PRIMARY KEY (widgetid)', 'UNIQUE position (position)')));
                $locktablesquery .= ', ^widgets WRITE';
                qa_db_upgrade_query($locktablesquery);
                break;
            case 24:
                qa_db_upgrade_query('UNLOCK TABLES');
                qa_db_upgrade_query(qa_db_create_table_sql('tagwords', array('postid' => $definitions['tagwords']['postid'], 'wordid' => $definitions['tagwords']['wordid'], 'KEY postid (postid)', 'KEY wordid (wordid)', 'CONSTRAINT ^tagwords_ibfk_1 FOREIGN KEY (postid) REFERENCES ^posts(postid) ON DELETE CASCADE', 'CONSTRAINT ^tagwords_ibfk_2 FOREIGN KEY (wordid) REFERENCES ^words(wordid)')));
                $locktablesquery .= ', ^tagwords WRITE';
                qa_db_upgrade_query('ALTER TABLE ^words ADD COLUMN tagwordcount ' . $definitions['words']['tagwordcount'] . ' AFTER contentcount');
                qa_db_upgrade_query($locktablesquery);
                $keyrecalc['doreindexcontent'] = true;
                break;
                //	Up to here: Version 1.4 developer preview
            //	Up to here: Version 1.4 developer preview
            case 25:
                $keycolumns = qa_array_to_keys(qa_db_read_all_values(qa_db_query_sub('SHOW COLUMNS FROM ^blobs')));
                // might be using blobs table shared with another installation, so check if we need to upgrade
                if (isset($keycolumns['filename'])) {
                    qa_db_upgrade_progress('Skipping upgrading blobs table since it was already upgraded by another Q2A site sharing it.');
                } else {
                    qa_db_upgrade_query('ALTER TABLE ^blobs ADD COLUMN filename ' . $definitions['blobs']['filename'] . ' AFTER content, ADD COLUMN userid ' . $definitions['blobs']['userid'] . ' AFTER filename, ADD COLUMN cookieid ' . $definitions['blobs']['cookieid'] . ' AFTER userid, ADD COLUMN createip ' . $definitions['blobs']['createip'] . ' AFTER cookieid, ADD COLUMN created ' . $definitions['blobs']['created'] . ' AFTER createip');
                    qa_db_upgrade_query($locktablesquery);
                }
                break;
            case 26:
                qa_db_upgrade_query('ALTER TABLE ^uservotes ADD COLUMN flag ' . $definitions['uservotes']['flag'] . ' AFTER vote');
                qa_db_upgrade_query($locktablesquery);
                qa_db_upgrade_query('ALTER TABLE ^posts ADD COLUMN flagcount ' . $definitions['posts']['flagcount'] . ' AFTER downvotes, ADD KEY type_3 (type, flagcount, created)');
                qa_db_upgrade_query($locktablesquery);
                $keyrecalc['dorecountposts'] = true;
                break;
            case 27:
                qa_db_upgrade_query('ALTER TABLE ^posts ADD COLUMN netvotes ' . $definitions['posts']['netvotes'] . ' AFTER downvotes, ADD KEY type_4 (type, netvotes, created)');
                qa_db_upgrade_query($locktablesquery);
                $keyrecalc['dorecountposts'] = true;
                break;
            case 28:
                qa_db_upgrade_query('ALTER TABLE ^posts ADD COLUMN views ' . $definitions['posts']['views'] . ' AFTER netvotes, ADD COLUMN hotness ' . $definitions['posts']['hotness'] . ' AFTER views, ADD KEY type_5 (type, views, created), ADD KEY type_6 (type, hotness)');
                qa_db_upgrade_query($locktablesquery);
                $keyrecalc['dorecountposts'] = true;
                break;
            case 29:
                qa_db_upgrade_query('ALTER TABLE ^posts ADD COLUMN lastviewip ' . $definitions['posts']['lastviewip'] . ' AFTER netvotes');
                qa_db_upgrade_query($locktablesquery);
                break;
            case 30:
                qa_db_upgrade_query('ALTER TABLE ^posts DROP FOREIGN KEY ^posts_ibfk_3');
                // to allow category column types to be changed
                qa_db_upgrade_query($locktablesquery);
                qa_db_upgrade_query('ALTER TABLE ^posts DROP KEY categoryid, DROP KEY categoryid_2');
                qa_db_upgrade_query($locktablesquery);
                qa_db_upgrade_query('ALTER TABLE ^categories CHANGE COLUMN categoryid categoryid ' . $definitions['categories']['categoryid'] . ', ADD COLUMN parentid ' . $definitions['categories']['parentid'] . ' AFTER categoryid, ADD COLUMN backpath ' . $definitions['categories']['backpath'] . ' AFTER position, ADD COLUMN content ' . $definitions['categories']['content'] . ' AFTER tags, DROP INDEX tags, DROP INDEX position, ADD UNIQUE parentid (parentid, tags), ADD UNIQUE parentid_2 (parentid, position), ADD KEY backpath (backpath(' . QA_DB_MAX_CAT_PAGE_TAGS_LENGTH . '))');
                qa_db_upgrade_query($locktablesquery);
                qa_db_upgrade_query('ALTER TABLE ^posts CHANGE COLUMN categoryid categoryid ' . $definitions['posts']['categoryid'] . ', ADD COLUMN catidpath1 ' . $definitions['posts']['catidpath1'] . ' AFTER categoryid, ADD COLUMN catidpath2 ' . $definitions['posts']['catidpath2'] . ' AFTER catidpath1, ADD COLUMN catidpath3 ' . $definitions['posts']['catidpath3'] . ' AFTER catidpath2');
                // QA_CATEGORY_DEPTH=4
                qa_db_upgrade_query($locktablesquery);
                qa_db_upgrade_query('ALTER TABLE ^posts ADD KEY catidpath1 (catidpath1, type, created), ADD KEY catidpath2 (catidpath2, type, created), ADD KEY catidpath3 (catidpath3, type, created), ADD KEY categoryid (categoryid, type, created), ADD KEY catidpath1_2 (catidpath1, updated, type), ADD KEY catidpath2_2 (catidpath2, updated, type), ADD KEY catidpath3_2 (catidpath3, updated, type), ADD KEY categoryid_2 (categoryid, updated, type)');
                qa_db_upgrade_query($locktablesquery);
                qa_db_upgrade_query('ALTER TABLE ^posts ADD CONSTRAINT ^posts_ibfk_3 FOREIGN KEY (categoryid) REFERENCES ^categories(categoryid) ON DELETE SET NULL');
                qa_db_upgrade_query($locktablesquery);
                $keyrecalc['dorecalccategories'] = true;
                break;
                //	Up to here: Version 1.4 betas and release
            //	Up to here: Version 1.4 betas and release
            case 31:
                qa_db_upgrade_query('ALTER TABLE ^posts CHANGE COLUMN type type ' . $definitions['posts']['type'] . ', ADD COLUMN updatetype ' . $definitions['posts']['updatetype'] . ' AFTER updated, ADD COLUMN closedbyid ' . $definitions['posts']['closedbyid'] . ' AFTER selchildid, ADD KEY closedbyid (closedbyid), ADD CONSTRAINT ^posts_ibfk_4 FOREIGN KEY (closedbyid) REFERENCES ^posts(postid)');
                qa_db_upgrade_query($locktablesquery);
                break;
            case 32:
                qa_db_upgrade_query("UPDATE ^posts SET updatetype=IF(INSTR(type, '_HIDDEN')>0, 'H', 'E') WHERE updated IS NOT NULL");
                break;
            case 33:
                qa_db_upgrade_query('ALTER TABLE ^contentwords CHANGE COLUMN type type ' . $definitions['contentwords']['type']);
                qa_db_upgrade_query($locktablesquery);
                break;
            case 34:
                if (!QA_FINAL_EXTERNAL_USERS) {
                    $keytables = qa_array_to_keys(qa_db_read_all_values(qa_db_query_sub('SHOW TABLES')));
                    // might be using messages table shared with another installation, so check if we need to upgrade
                    if (isset($keytables[qa_db_add_table_prefix('messages')])) {
                        qa_db_upgrade_progress('Skipping messages table since it was already added by another Q2A site sharing these users.');
                    } else {
                        qa_db_upgrade_query('UNLOCK TABLES');
                        qa_db_upgrade_query(qa_db_create_table_sql('messages', array('messageid' => $definitions['messages']['messageid'], 'fromuserid' => $definitions['messages']['fromuserid'], 'touserid' => $definitions['messages']['touserid'], 'content' => $definitions['messages']['content'], 'format' => $definitions['messages']['format'], 'created' => $definitions['messages']['created'], 'PRIMARY KEY (messageid)', 'KEY fromuserid (fromuserid, touserid, created)')));
                        $locktablesquery .= ', ^messages WRITE';
                        qa_db_upgrade_query($locktablesquery);
                    }
                }
                break;
            case 35:
                qa_db_upgrade_query('UNLOCK TABLES');
                qa_db_upgrade_query(qa_db_create_table_sql('userfavorites', array('userid' => $definitions['userfavorites']['userid'], 'entitytype' => $definitions['userfavorites']['entitytype'], 'entityid' => $definitions['userfavorites']['entityid'], 'nouserevents' => $definitions['userfavorites']['nouserevents'], 'PRIMARY KEY (userid, entitytype, entityid)', 'KEY userid (userid, nouserevents)', 'KEY entitytype (entitytype, entityid, nouserevents)', QA_FINAL_EXTERNAL_USERS ? null : 'CONSTRAINT ^userfavorites_ibfk_1 FOREIGN KEY (userid) REFERENCES ^users(userid) ON DELETE CASCADE')));
                $locktablesquery .= ', ^userfavorites WRITE';
                qa_db_upgrade_query($locktablesquery);
                break;
            case 36:
                qa_db_upgrade_query('UNLOCK TABLES');
                qa_db_upgrade_query(qa_db_create_table_sql('userevents', array('userid' => $definitions['userevents']['userid'], 'entitytype' => $definitions['userevents']['entitytype'], 'entityid' => $definitions['userevents']['entityid'], 'questionid' => $definitions['userevents']['questionid'], 'lastpostid' => $definitions['userevents']['lastpostid'], 'updatetype' => $definitions['userevents']['updatetype'], 'lastuserid' => $definitions['userevents']['lastuserid'], 'updated' => $definitions['userevents']['updated'], 'KEY userid (userid, updated)', 'KEY questionid (questionid, userid)', QA_FINAL_EXTERNAL_USERS ? null : 'CONSTRAINT ^userevents_ibfk_1 FOREIGN KEY (userid) REFERENCES ^users(userid) ON DELETE CASCADE')));
                $locktablesquery .= ', ^userevents WRITE';
                qa_db_upgrade_query($locktablesquery);
                $keyrecalc['dorefillevents'] = true;
                break;
            case 37:
                qa_db_upgrade_query('UNLOCK TABLES');
                qa_db_upgrade_query(qa_db_create_table_sql('sharedevents', array('entitytype' => $definitions['sharedevents']['entitytype'], 'entityid' => $definitions['sharedevents']['entityid'], 'questionid' => $definitions['sharedevents']['questionid'], 'lastpostid' => $definitions['sharedevents']['lastpostid'], 'updatetype' => $definitions['sharedevents']['updatetype'], 'lastuserid' => $definitions['sharedevents']['lastuserid'], 'updated' => $definitions['sharedevents']['updated'], 'KEY entitytype (entitytype, entityid, updated)', 'KEY questionid (questionid, entitytype, entityid)')));
                $locktablesquery .= ', ^sharedevents WRITE';
                qa_db_upgrade_query($locktablesquery);
                $keyrecalc['dorefillevents'] = true;
                break;
            case 38:
                qa_db_upgrade_query('ALTER TABLE ^posts ADD KEY lastuserid (lastuserid, updated, type)');
                qa_db_upgrade_query($locktablesquery);
                break;
            case 39:
                qa_db_upgrade_query('ALTER TABLE ^posts DROP KEY type_3, ADD KEY flagcount (flagcount, created, type)');
                qa_db_upgrade_query($locktablesquery);
                break;
            case 40:
                qa_db_upgrade_query('ALTER TABLE ^userpoints ADD COLUMN bonus ' . $definitions['userpoints']['bonus'] . ' AFTER downvoteds');
                qa_db_upgrade_query($locktablesquery);
                break;
            case 41:
                qa_db_upgrade_query('ALTER TABLE ^pages ADD COLUMN permit ' . $definitions['pages']['permit'] . ' AFTER flags');
                qa_db_upgrade_query($locktablesquery);
                break;
            case 42:
                qa_db_upgrade_query('UNLOCK TABLES');
                qa_db_upgrade_query(qa_db_create_table_sql('usermetas', array('userid' => $definitions['usermetas']['userid'], 'title' => $definitions['usermetas']['title'], 'content' => $definitions['usermetas']['content'], 'PRIMARY KEY (userid, title)', QA_FINAL_EXTERNAL_USERS ? null : 'CONSTRAINT ^usermetas_ibfk_1 FOREIGN KEY (userid) REFERENCES ^users(userid) ON DELETE CASCADE')));
                $locktablesquery .= ', ^usermetas WRITE';
                qa_db_upgrade_query($locktablesquery);
                break;
            case 43:
                qa_db_upgrade_query('UNLOCK TABLES');
                qa_db_upgrade_query(qa_db_create_table_sql('postmetas', array('postid' => $definitions['postmetas']['postid'], 'title' => $definitions['postmetas']['title'], 'content' => $definitions['postmetas']['content'], 'PRIMARY KEY (postid, title)', 'CONSTRAINT ^postmetas_ibfk_1 FOREIGN KEY (postid) REFERENCES ^posts(postid) ON DELETE CASCADE')));
                $locktablesquery .= ', ^postmetas WRITE';
                qa_db_upgrade_query($locktablesquery);
                break;
            case 44:
                qa_db_upgrade_query('UNLOCK TABLES');
                qa_db_upgrade_query(qa_db_create_table_sql('categorymetas', array('categoryid' => $definitions['categorymetas']['categoryid'], 'title' => $definitions['categorymetas']['title'], 'content' => $definitions['categorymetas']['content'], 'PRIMARY KEY (categoryid, title)', 'CONSTRAINT ^categorymetas_ibfk_1 FOREIGN KEY (categoryid) REFERENCES ^categories(categoryid) ON DELETE CASCADE')));
                $locktablesquery .= ', ^categorymetas WRITE';
                qa_db_upgrade_query($locktablesquery);
                break;
            case 45:
                qa_db_upgrade_query('UNLOCK TABLES');
                qa_db_upgrade_query(qa_db_create_table_sql('tagmetas', array('tag' => $definitions['tagmetas']['tag'], 'title' => $definitions['tagmetas']['title'], 'content' => $definitions['tagmetas']['content'], 'PRIMARY KEY (tag, title)')));
                $locktablesquery .= ', ^tagmetas WRITE';
                qa_db_upgrade_query($locktablesquery);
                break;
            case 46:
                qa_db_upgrade_query('ALTER TABLE ^posts DROP KEY selchildid, ADD KEY selchildid (selchildid, type, created), ADD COLUMN amaxvote SMALLINT UNSIGNED NOT NULL DEFAULT 0 AFTER acount, ADD KEY type_7 (type, amaxvote, created)');
                qa_db_upgrade_query($locktablesquery);
                $keyrecalc['dorecountposts'] = true;
                break;
            case 47:
                qa_db_upgrade_query('UNLOCK TABLES');
                qa_db_upgrade_query(qa_db_create_table_sql('usernotices', array('noticeid' => $definitions['usernotices']['noticeid'], 'userid' => $definitions['usernotices']['userid'], 'content' => $definitions['usernotices']['content'], 'format' => $definitions['usernotices']['format'], 'tags' => $definitions['usernotices']['tags'], 'created' => $definitions['usernotices']['created'], 'PRIMARY KEY (noticeid)', 'KEY userid (userid, created)', QA_FINAL_EXTERNAL_USERS ? null : 'CONSTRAINT ^usernotices_ibfk_1 FOREIGN KEY (userid) REFERENCES ^users(userid) ON DELETE CASCADE')));
                $locktablesquery .= ', ^usernotices WRITE';
                qa_db_upgrade_query($locktablesquery);
                break;
                //	Up to here: Version 1.5.x
            //	Up to here: Version 1.5.x
            case 48:
                if (!QA_FINAL_EXTERNAL_USERS) {
                    $keycolumns = qa_array_to_keys(qa_db_read_all_values(qa_db_query_sub('SHOW COLUMNS FROM ^messages')));
                    // might be using messages table shared with another installation, so check if we need to upgrade
                    if (isset($keycolumns['type'])) {
                        qa_db_upgrade_progress('Skipping upgrading messages table since it was already upgraded by another Q2A site sharing it.');
                    } else {
                        qa_db_upgrade_query('ALTER TABLE ^messages ADD COLUMN type ' . $definitions['messages']['type'] . ' AFTER messageid, DROP KEY fromuserid, ADD key type (type, fromuserid, touserid, created), ADD KEY touserid (touserid, type, created)');
                        qa_db_upgrade_query($locktablesquery);
                    }
                }
                break;
            case 49:
                if (!QA_FINAL_EXTERNAL_USERS) {
                    qa_db_upgrade_query('ALTER TABLE ^users CHANGE COLUMN flags flags ' . $definitions['users']['flags']);
                    qa_db_upgrade_query($locktablesquery);
                }
                break;
            case 50:
                qa_db_upgrade_query('ALTER TABLE ^posts ADD COLUMN name ' . $definitions['posts']['name'] . ' AFTER tags');
                qa_db_upgrade_query($locktablesquery);
                break;
            case 51:
                if (!QA_FINAL_EXTERNAL_USERS) {
                    $keycolumns = qa_array_to_keys(qa_db_read_all_values(qa_db_query_sub('SHOW COLUMNS FROM ^userfields')));
                    // might be using userfields table shared with another installation, so check if we need to upgrade
                    if (isset($keycolumns['permit'])) {
                        qa_db_upgrade_progress('Skipping upgrading userfields table since it was already upgraded by another Q2A site sharing it.');
                    } else {
                        qa_db_upgrade_query('ALTER TABLE ^userfields ADD COLUMN permit ' . $definitions['userfields']['permit'] . ' AFTER flags');
                        qa_db_upgrade_query($locktablesquery);
                    }
                }
                break;
            case 52:
                if (!QA_FINAL_EXTERNAL_USERS) {
                    $keyindexes = qa_array_to_keys(qa_db_read_all_assoc(qa_db_query_sub('SHOW INDEX FROM ^users'), null, 'Key_name'));
                    if (isset($keyindexes['created'])) {
                        qa_db_upgrade_progress('Skipping upgrading users table since it was already upgraded by another Q2A site sharing it.');
                    } else {
                        qa_db_upgrade_query('ALTER TABLE ^users ADD KEY created (created, level, flags)');
                        qa_db_upgrade_query($locktablesquery);
                    }
                }
                break;
            case 53:
                qa_db_upgrade_query('ALTER TABLE ^blobs CHANGE COLUMN content content ' . $definitions['blobs']['content']);
                qa_db_upgrade_query($locktablesquery);
                break;
            case 54:
                qa_db_upgrade_query('UNLOCK TABLES');
                qa_db_upgrade_query('SET FOREIGN_KEY_CHECKS=0');
                // in case InnoDB not available
                qa_db_upgrade_query(qa_db_create_table_sql('userlevels', array('userid' => $definitions['userlevels']['userid'], 'entitytype' => $definitions['userlevels']['entitytype'], 'entityid' => $definitions['userlevels']['entityid'], 'level' => $definitions['userlevels']['level'], 'UNIQUE userid (userid, entitytype, entityid)', 'KEY entitytype (entitytype, entityid)', QA_FINAL_EXTERNAL_USERS ? null : 'CONSTRAINT ^userlevels_ibfk_1 FOREIGN KEY (userid) REFERENCES ^users(userid) ON DELETE CASCADE')));
                $locktablesquery .= ', ^userlevels WRITE';
                qa_db_upgrade_query($locktablesquery);
                break;
                //	Up to here: Version 1.6 beta 1
            //	Up to here: Version 1.6 beta 1
            case 55:
                if (!QA_FINAL_EXTERNAL_USERS) {
                    $keycolumns = qa_array_to_keys(qa_db_read_all_values(qa_db_query_sub('SHOW COLUMNS FROM ^users')));
                    // might be using messages table shared with another installation, so check if we need to upgrade
                    if (isset($keycolumns['wallposts'])) {
                        qa_db_upgrade_progress('Skipping upgrading users table since it was already upgraded by another Q2A site sharing it.');
                    } else {
                        qa_db_upgrade_query('ALTER TABLE ^users ADD COLUMN wallposts ' . $definitions['users']['wallposts'] . ' AFTER flags');
                        qa_db_upgrade_query($locktablesquery);
                    }
                }
                break;
                //	Up to here: Version 1.6 beta 2
            //	Up to here: Version 1.6 beta 2
            case 56:
                qa_db_upgrade_query('ALTER TABLE ^pages DROP INDEX tags, ADD KEY tags (tags)');
                qa_db_upgrade_query($locktablesquery);
                break;
                //	Up to here: Version 1.6 (release)
            //	Up to here: Version 1.6 (release)
            case 57:
                if (!QA_FINAL_EXTERNAL_USERS) {
                    // might be using messages table shared with another installation, so check if we need to upgrade
                    $keycolumns = qa_array_to_keys(qa_db_read_all_values(qa_db_query_sub('SHOW COLUMNS FROM ^messages')));
                    if (isset($keycolumns['fromhidden'])) {
                        qa_db_upgrade_progress('Skipping upgrading messages table since it was already upgraded by another Q2A site sharing it.');
                    } else {
                        qa_db_upgrade_query('ALTER TABLE ^messages ADD COLUMN fromhidden ' . $definitions['messages']['fromhidden'] . ' AFTER touserid');
                        qa_db_upgrade_query('ALTER TABLE ^messages ADD COLUMN tohidden ' . $definitions['messages']['tohidden'] . ' AFTER fromhidden');
                        qa_db_upgrade_query('ALTER TABLE ^messages ADD KEY fromhidden (fromhidden), ADD KEY tohidden (tohidden)');
                        qa_db_upgrade_query($locktablesquery);
                    }
                }
                break;
            case 58:
                // Note: need to use full table names here as aliases trigger error "Table 'x' was not locked with LOCK TABLES"
                qa_db_upgrade_query('DELETE FROM ^userfavorites WHERE entitytype="U" AND userid=entityid');
                qa_db_upgrade_query('DELETE ^uservotes FROM ^uservotes JOIN ^posts ON ^uservotes.postid=^posts.postid AND ^uservotes.userid=^posts.userid');
                qa_db_upgrade_query($locktablesquery);
                $keyrecalc['dorecountposts'] = true;
                $keyrecalc['dorecalcpoints'] = true;
                break;
                //	Up to here: Verison 1.7
            //	Up to here: Verison 1.7
            case 59:
                // Upgrade from alpha version removed
                break;
                //	Up to here: Verison 1.7.1
        }
        qa_db_set_db_version($newversion);
        if (qa_db_get_db_version() != $newversion) {
            qa_fatal_error('Could not increment database version');
        }
    }
    qa_db_upgrade_query('UNLOCK TABLES');
    //	Perform any necessary recalculations, as determined by upgrade steps
    foreach ($keyrecalc as $state => $dummy) {
        while ($state) {
            set_time_limit(60);
            $stoptime = time() + 2;
            while (qa_recalc_perform_step($state) && time() < $stoptime) {
            }
            qa_db_upgrade_progress(qa_recalc_get_message($state));
        }
    }
}
Example #26
0
    public function messagelist()
    {
        $offset = (int) qa_get('offset');
        $offset = isset($offset) ? $offset * 15 : 0;
        require_once QA_INCLUDE_DIR . 'qa-db-users.php';
        // Get Events
        $message_events = array('u_message', 'u_wall_post');
        $events = "'" . implode("','", $message_events) . "'";
        $userid = qa_get_logged_in_userid();
        $eventslist = qa_db_read_all_assoc(qa_db_query_sub('SELECT id, UNIX_TIMESTAMP(datetime) AS datetime, userid, postid, effecteduserid, event, params, `read` FROM ^ra_userevent WHERE effecteduserid=# AND `read` = 0 AND event IN (' . $events . ') ORDER BY id DESC LIMIT 15 OFFSET #', $userid, $offset));
        if (count($eventslist) > 0) {
            $event = array();
            $userids = array();
            foreach ($eventslist as $event) {
                $userids[$event['userid']] = $event['userid'];
                $userids[$event['effecteduserid']] = $event['effecteduserid'];
            }
            if (QA_FINAL_EXTERNAL_USERS) {
                $handles = qa_get_public_from_userids($userids);
            } else {
                $handles = qa_db_user_get_userid_handles($userids);
            }
            // get event's: time, type, parameters
            // get post id of questions
            foreach ($eventslist as $event) {
                $title = '';
                $link = '';
                $handle = $handles[$event['userid']];
                $reciever_handle = $handles[$event['effecteduserid']];
                $reciever_link = qa_path('user/' . $reciever_handle);
                $datetime = $event['datetime'];
                $event['date'] = qa_html(qa_time_to_string(qa_opt('db_time') - $datetime));
                $event['params'] = json_decode($event['params'], true);
                $message = substr($event['params']['message'], 0, 30) . '..';
                $id = ' data-id="' . $event['id'] . '"';
                $read = $event['read'] ? ' read' : ' unread';
                $url_param = array('ra_notification' => $event['id']);
                $user_link = qa_path_html('user/' . $handle, $url_param);
                switch ($event['event']) {
                    case 'u_message':
                        // related question to an answer
                        echo '<div class="event-content clearfix' . $read . '"' . $id . '>
								<div class="avatar"><a href="' . $user_link . '">' . ra_get_avatar($handle, 32, true) . '</a></div>
								<div class="event-right">
									<a href="' . qa_path_html('message/' . $handle, $url_param, QW_BASE_URL) . '">
										<div class="head">
											<strong class="user">' . $handle . '</strong>
											<span class="what">' . qa_lang_html('dude/sent_you_a_private_message') . '</span>
											<span class="message">' . $message . '</span>
										</div>
										<div class="footer">
											<span class="event-icon icon-email"></span>
											<span class="date">' . qa_lang_sub('dude/x_ago', $event['date']) . '</span>
										</div>
									</a>
								</div>
							</div>';
                        break;
                    case 'u_wall_post':
                        // user's question had been answered
                        $url = qa_path_html('user/' . $reciever_handle . '/wall', $url_param, QW_BASE_URL);
                        echo '<div class="event-content clearfix' . $read . '"' . $id . '>
								<div class="avatar"><a href="' . $user_link . '">' . ra_get_avatar($handle, 32, true) . '</a></div>
								<div class="event-right">
									<a href="' . $url . '">
										<div class="head">
											<strong class="user">' . $handle . '</strong>
											<span class="what">' . qa_lang_html('dude/posted_on_your_wall') . '</span>
											<span class="message">' . $message . '</span>
										</div>
										<div class="footer">
											<span class="event-icon icon-pin"></span>
											<span class="date">' . qa_lang_sub('dude/x_ago', $event['date']) . '</span>
										</div>
									</a>
								</div>
							</div>';
                        break;
                }
            }
        } else {
            echo '<div class="no-more-activity">' . qa_lang_html('dude/no_more_messages') . '</div>';
        }
        die;
    }
Example #27
0
<?php

//	Output this header as early as possible
header('Content-Type: text/plain; charset=utf-8');
//	Ensure no PHP errors are shown in the Ajax response
@ini_set('display_errors', 0);
//	Load the Q2A base file which sets up a bunch of crucial functions
require_once '../../qa-include/qa-base.php';
qa_report_process_stage('init_ajax');
//	Get general Ajax parameters from the POST payload, and clear $_GET
qa_set_request(qa_post_text('qa_request'), qa_post_text('qa_root'));
require_once QA_INCLUDE_DIR . 'qa-db-selects.php';
$query = $_POST['query'];
//
//
$categories = qa_db_read_all_assoc(qa_db_query_sub("SELECT ^categories.categoryid,^categories.parentid,^categories.tags,^categories.title,^categories.qcount,^categories.position,^categories.backpath,^categories.title, ^categorymetas.content AS meta\n\t\tFROM ^categories\n\t\tLEFT JOIN ^categorymetas\n\t\tON ^categories.categoryid=^categorymetas.categoryid AND ^categorymetas.title='et_category'\n\t\tWHERE ^categories.title like '%" . $query . "%'\n\t\tORDER BY ^categories.qcount DESC\n\t\tLIMIT 10\n\t\t"));
//
//	echo "<pre>";  var_dump( $categories ); echo "</pre>";
//
foreach ($categories as $key => $category) {
    $categories[$key]['id'] = $category['categoryid'];
    $categories[$key]['name'] = $category['title'];
    //$categories[$key]['meta'] = json_decode($categories[$key]['meta'],true);
}
echo json_encode($categories);
Example #28
0
 function GetQuestion($params)
 {
     $question = array();
     //qa_fatal_error(var_dump($params));
     if (isset($params['question'])) {
         $question = $params['question'];
     } elseif (isset($params['parent']['question'])) {
         $question = $params['parent']['question'];
     } elseif (isset($params['parent'])) {
         $question = $params['parent'];
     } else {
         $postid = @$params['postid'];
         $question = qa_db_read_all_assoc(qa_db_query_sub("SELECT qa_posts.type,\n\t\t\t\t\t\tCASE \n\t\t\t\t\t\t\tWHEN qa_posts.type='Q'\n\t\t\t\t\t\t\t\tTHEN qa_posts.title \n\t\t\t\t\t\t\tWHEN parent.type='Q'\n\t\t\t\t\t\t\t\tTHEN parent.title \n\t\t\t\t\t\t\tWHEN grandparent.type='Q'\n\t\t\t\t\t\t\t\tTHEN grandparent.title \n\t\t\t\t\t\tEND AS title,\n\t\t\t\t\t\tCASE \n\t\t\t\t\t\t\tWHEN qa_posts.type='Q'\n\t\t\t\t\t\t\t\tTHEN qa_posts.postid \n\t\t\t\t\t\t\tWHEN parent.type='Q'\n\t\t\t\t\t\t\t\tTHEN parent.postid \n\t\t\t\t\t\t\tWHEN grandparent.type='Q'\n\t\t\t\t\t\t\t\tTHEN grandparent.postid \n\t\t\t\t\t\tEND AS postid\n\t\t\t\t\t\tFROM qa_posts LEFT JOIN qa_posts AS parent ON qa_posts.parentid=parent.postid LEFT JOIN qa_posts as grandparent ON parent.parentid=grandparent.postid\n\t\t\t\t\t\tWHERE qa_posts.postid=#", $postid));
         //qa_fatal_error(var_dump($question[0]));
         return $question[0];
     }
     //qa_fatal_error(var_dump($question));
     return $question;
 }
 public function process_request($request)
 {
     @ini_set('display_errors', 0);
     // we don't want to show PHP errors inside XML
     header('Content-type: text/xml; charset=utf-8');
     echo '<?xml version="1.0" encoding="UTF-8"?>' . "\n";
     echo '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">' . "\n";
     //	Question pages
     if (qa_opt('xml_sitemap_show_questions')) {
         $hotstats = qa_db_read_one_assoc(qa_db_query_sub("SELECT MIN(hotness) AS base, MAX(hotness)-MIN(hotness) AS spread FROM ^posts WHERE type='Q'"));
         $nextpostid = 0;
         while (1) {
             $questions = qa_db_read_all_assoc(qa_db_query_sub("SELECT postid, title, hotness FROM ^posts WHERE postid>=# AND type='Q' ORDER BY postid LIMIT 100", $nextpostid));
             if (!count($questions)) {
                 break;
             }
             foreach ($questions as $question) {
                 $this->sitemap_output(qa_q_request($question['postid'], $question['title']), 0.1 + 0.9 * ($question['hotness'] - $hotstats['base']) / (1 + $hotstats['spread']));
                 $nextpostid = max($nextpostid, $question['postid'] + 1);
             }
         }
     }
     //	User pages
     if (!QA_FINAL_EXTERNAL_USERS && qa_opt('xml_sitemap_show_users')) {
         $nextuserid = 0;
         while (1) {
             $users = qa_db_read_all_assoc(qa_db_query_sub("SELECT userid, handle FROM ^users WHERE userid>=# ORDER BY userid LIMIT 100", $nextuserid));
             if (!count($users)) {
                 break;
             }
             foreach ($users as $user) {
                 $this->sitemap_output('user/' . $user['handle'], 0.25);
                 $nextuserid = max($nextuserid, $user['userid'] + 1);
             }
         }
     }
     //	Tag pages
     if (qa_using_tags() && qa_opt('xml_sitemap_show_tag_qs')) {
         $nextwordid = 0;
         while (1) {
             $tagwords = qa_db_read_all_assoc(qa_db_query_sub("SELECT wordid, word, tagcount FROM ^words WHERE wordid>=# AND tagcount>0 ORDER BY wordid LIMIT 100", $nextwordid));
             if (!count($tagwords)) {
                 break;
             }
             foreach ($tagwords as $tagword) {
                 $this->sitemap_output('tag/' . $tagword['word'], 0.5 / (1 + 1 / $tagword['tagcount']));
                 // priority between 0.25 and 0.5 depending on tag frequency
                 $nextwordid = max($nextwordid, $tagword['wordid'] + 1);
             }
         }
     }
     //	Question list for each category
     if (qa_using_categories() && qa_opt('xml_sitemap_show_category_qs')) {
         $nextcategoryid = 0;
         while (1) {
             $categories = qa_db_read_all_assoc(qa_db_query_sub("SELECT categoryid, backpath FROM ^categories WHERE categoryid>=# AND qcount>0 ORDER BY categoryid LIMIT 2", $nextcategoryid));
             if (!count($categories)) {
                 break;
             }
             foreach ($categories as $category) {
                 $this->sitemap_output('questions/' . implode('/', array_reverse(explode('/', $category['backpath']))), 0.5);
                 $nextcategoryid = max($nextcategoryid, $category['categoryid'] + 1);
             }
         }
     }
     //	Pages in category browser
     if (qa_using_categories() && qa_opt('xml_sitemap_show_categories')) {
         $this->sitemap_output('categories', 0.5);
         $nextcategoryid = 0;
         while (1) {
             // only find categories with a child
             $categories = qa_db_read_all_assoc(qa_db_query_sub("SELECT parent.categoryid, parent.backpath FROM ^categories AS parent " . "JOIN ^categories AS child ON child.parentid=parent.categoryid WHERE parent.categoryid>=# GROUP BY parent.categoryid LIMIT 100", $nextcategoryid));
             if (!count($categories)) {
                 break;
             }
             foreach ($categories as $category) {
                 $this->sitemap_output('categories/' . implode('/', array_reverse(explode('/', $category['backpath']))), 0.5);
                 $nextcategoryid = max($nextcategoryid, $category['categoryid'] + 1);
             }
         }
     }
     echo "</urlset>\n";
     return null;
 }
    for ($i = 0; $i < $u_sitemap_count; $i++) {
        echo '<p><a href="' . $siteurl . 'sitemap-users-' . $i . '.xml">' . 'sitemap-users-' . $i . '.xml' . '</a></p>';
    }
}
// tag's list sitemap
if (qa_opt('useo_sitemap_tags_enable')) {
    $t_sitemaps = qa_db_read_one_assoc(qa_db_query_sub("SELECT count(*) as total from ^words WHERE tagcount>0 "));
    $count = qa_opt('useo_sitemap_tags_count');
    $t_sitemap_count = ceil($t_sitemaps['total'] / $count);
    for ($i = 0; $i < $t_sitemap_count; $i++) {
        echo '<p><a href="' . $siteurl . 'sitemap-tags-' . $i . '.xml">' . 'sitemap-tags-' . $i . '.xml' . '</a></p>';
    }
}
// categories's list sitemap
if (qa_opt('useo_sitemap_categories_enable')) {
    echo '<p><a href="' . $siteurl . 'sitemap-category.xml">sitemap-category.xml' . '</a></p>';
}
if (qa_opt('useo_sitemap_categoriy_q_enable')) {
    $categories = qa_db_read_all_assoc(qa_db_query_sub("SELECT categoryid, backpath FROM ^categories WHERE qcount>0 ORDER BY categoryid"));
    foreach ($categories as $category) {
        $backpath = $category['backpath'];
        $count = qa_opt('useo_sitemap_categoriy_q_count');
        $qcount = qa_db_read_one_assoc(qa_db_query_sub('SELECT count(*) as total FROM ^posts WHERE ^posts.type=$
			AND categoryid=(SELECT categoryid FROM ^categories WHERE ^categories.backpath=$ LIMIT 1)', 'Q', $backpath));
        $category_slug = implode('-', array_reverse(explode('/', $category['backpath'])));
        $cat_count = ceil($qcount['total'] / $count);
        for ($i = 0; $i < $cat_count; $i++) {
            echo '<p><a href="' . $siteurl . 'sitemap-category-' . $category_slug . '-' . $i . '.xml">' . 'sitemap-category-' . $category_slug . '-' . $i . '.xml' . '</a></p>';
        }
    }
}