function output_widget($region, $place, $themeobject, $template, $request, $qa_content)
 {
     require_once QA_INCLUDE_DIR . 'qa-db-selects.php';
     global $qa_login_userid, $questionid, $relatedcount, $question, $relatedquestions, $qa_cookieid, $usershtml;
     list($question, $relatedquestions) = qa_db_select_with_pending(qa_db_full_post_selectspec($qa_login_userid, $questionid), qa_db_related_qs_selectspec($qa_login_userid, $questionid));
     if ($relatedcount > 1 && !$question['hidden']) {
         $minscore = qa_match_to_min_score(qa_opt('match_related_qs'));
         foreach ($relatedquestions as $key => $related) {
             if ($related['postid'] == $questionid || $related['score'] < $minscore) {
                 unset($relatedquestions[$key]);
             }
         }
         if (count($relatedquestions)) {
             $themeobject->output('<h2>' . qa_lang('main/related_qs_title') . '</h2>');
         } else {
             $themeobject->output('<h2>' . qa_lang('main/no_related_qs_title') . '</h2>');
         }
         $upper = qa_opt('related_qs_num') < count($relatedquestions) ? qa_opt('related_qs_num') : count($relatedquestions);
         foreach ($relatedquestions as $related) {
             if ($upper <= 0) {
                 break;
             }
             $themeobject->output('<p style="margin:0 0 10px 0; font-weight:bold;"><a href="' . qa_path_html(qa_q_request($related['postid'], $related['title'])) . '">' . $related['title'] . '</a></p>');
             $upper--;
         }
     }
 }
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);
}
Esempio n. 3
0
function qa_priv_notification($uid, $oid, $badge_slug)
{
    require_once QA_INCLUDE_DIR . 'qa-app-users.php';
    require_once QA_INCLUDE_DIR . 'qa-app-emails.php';
    if (QA_FINAL_EXTERNAL_USERS) {
        $publictohandle = qa_get_public_from_userids(array($uid));
        $handle = @$publictohandle[$uid];
    } else {
        $user = qa_db_single_select(qa_db_user_account_selectspec($uid, true));
        $handle = @$user['handle'];
    }
    $subject = qa_opt('badge_email_subject');
    $body = qa_opt('badge_email_body');
    $body = preg_replace('/\\^if_post_text="([^"]*)"/', $oid ? '$1' : '', $body);
    // if post text
    $site_url = qa_opt('site_url');
    $profile_url = qa_path_html('user/' . $handle, null, $site_url);
    if ($oid) {
        $post = qa_db_read_one_assoc(qa_db_query_sub('SELECT * FROM ^posts WHERE postid=#', $oid), true);
        if ($post['parentid']) {
            $parent = qa_db_read_one_assoc(qa_db_query_sub('SELECT * FROM ^posts WHERE postid=#', $post['parentid']), true);
        }
        if (isset($parent)) {
            $anchor = urlencode(qa_anchor($post['basetype'], $oid));
            $post_title = $parent['title'];
            $post_url = qa_path_html(qa_q_request($parent['postid'], $parent['title']), null, qa_opt('site_url'), null, $anchor);
        } else {
            $post_title = $post['title'];
            $post_url = qa_path_html(qa_q_request($post['postid'], $post['title']), null, qa_opt('site_url'));
        }
    }
    $subs = array('^badge_name' => qa_opt('badge_' . $badge_slug . '_name'), '^post_title' => @$post_title, '^post_url' => @$post_url, '^profile_url' => $profile_url, '^site_url' => $site_url);
    qa_send_notification($uid, '@', $handle, $subject, $body, $subs);
}
Esempio n. 4
0
 function qa_share_buttons($q_view)
 {
     if (qa_opt('expert_question_enable')) {
         $qid = $q_view['raw']['postid'];
         $expert = qa_db_read_one_value(qa_db_query_sub("SELECT meta_value FROM ^postmeta WHERE meta_key='is_expert_question' AND post_id=#", $qid), true);
         if ($expert) {
             return;
         }
     }
     $url = qa_path_html(qa_q_request($q_view['raw']['postid'], $q_view['raw']['title']), null, qa_opt('site_url'));
     $code = array('facebook' => '<iframe src="//www.facebook.com/plugins/like.php?href=' . qa_path_html(qa_q_request($this->content['q_view']['raw']['postid'], $this->content['q_view']['raw']['title']), null, qa_opt('site_url')) . '&amp;send=false&amp;layout=standard&amp;width=53&amp;layout=button_count&amp;show_faces=false&amp;action=like&amp;colorscheme=light&amp;font&amp;height=20&amp;appId=170382616390886" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:53px; height:20px;" allowTransparency="true"></iframe>', 'twitter' => '<a href="http://twitter.com/share" class="twitter-share-button" data-count="none">Tweet</a>', 'google' => '<g:plusone size="medium" count="false"></g:plusone>', 'linkedin' => '<script type="text/javascript" src="http://platform.linkedin.com/in.js"></script><script type="in/share"></script>', 'email' => '<a title="Share this question via email" id="share-button-email" href="mailto:?subject=' . rawurlencode('[' . qa_opt('site_title') . '] ' . $q_view['raw']['title']) . '&body=' . rawurlencode($url) . '"><img height="24" src="' . QA_HTML_THEME_LAYER_URLTOROOT . 'qa-share-mail.png' . '"/></a>');
     // sort by weight
     $weight = array('facebook' => qa_opt('share_plugin_facebook_weight'), 'twitter' => qa_opt('share_plugin_twitter_weight'), 'google' => qa_opt('share_plugin_google_weight'), 'linkedin' => qa_opt('share_plugin_linkedin_weight'), 'email' => qa_opt('share_plugin_email_weight'));
     asort($weight);
     // output
     foreach ($weight as $key => $val) {
         if (qa_opt('share_plugin_' . $key)) {
             $shares[] = $code[$key];
         }
     }
     if (empty($shares)) {
         return null;
     }
     $output = implode('&nbsp;', $shares);
     return $output;
 }
function qa_question_set_selchildid($userid, $handle, $cookieid, $oldquestion, $selchildid, $answers)
{
    $oldselchildid = $oldquestion['selchildid'];
    qa_db_post_set_selchildid($oldquestion['postid'], isset($selchildid) ? $selchildid : null);
    qa_db_points_update_ifuser($oldquestion['userid'], 'aselects');
    if (isset($oldselchildid)) {
        if (isset($answers[$oldselchildid])) {
            qa_db_points_update_ifuser($answers[$oldselchildid]['userid'], 'aselecteds');
            qa_report_event('a_unselect', $userid, $handle, $cookieid, array('parentid' => $oldquestion['postid'], 'postid' => $oldselchildid));
        }
    }
    if (isset($selchildid)) {
        $answer = $answers[$selchildid];
        qa_db_points_update_ifuser($answer['userid'], 'aselecteds');
        if (isset($answer['notify']) && !qa_post_is_by_user($answer, $userid, $cookieid)) {
            require_once QA_INCLUDE_DIR . 'qa-app-emails.php';
            require_once QA_INCLUDE_DIR . 'qa-app-options.php';
            require_once QA_INCLUDE_DIR . 'qa-util-string.php';
            require_once QA_INCLUDE_DIR . 'qa-app-format.php';
            $blockwordspreg = qa_get_block_words_preg();
            $sendtitle = qa_block_words_replace($oldquestion['title'], $blockwordspreg);
            $sendcontent = qa_viewer_text($answer['content'], $answer['format'], array('blockwordspreg' => $blockwordspreg));
            qa_send_notification($answer['userid'], $answer['notify'], @$answer['handle'], qa_lang('emails/a_selected_subject'), qa_lang('emails/a_selected_body'), array('^s_handle' => isset($handle) ? $handle : qa_lang('main/anonymous'), '^q_title' => $sendtitle, '^a_content' => $sendcontent, '^url' => qa_path(qa_q_request($oldquestion['postid'], $sendtitle), null, qa_opt('site_url'), null, qa_anchor('A', $selchildid))));
        }
        qa_report_event('a_select', $userid, $handle, $cookieid, array('parentid' => $oldquestion['postid'], 'postid' => $selchildid));
    }
}
 public function process_event($event, $userid, $handle, $cookieid, $params)
 {
     switch ($event) {
         case 'q_post':
             $this->send_hipchat_notification($this->build_new_question_message(isset($handle) ? $handle : qa_lang('main/anonymous'), $params['title'], qa_q_path($params['postid'], $params['title'], true)));
             break;
         case 'a_post':
             $parentpost = qa_post_get_full($params['parentid']);
             $this->send_hipchat_notification($this->build_new_answer_message(isset($handle) ? $handle : qa_lang('main/anonymous'), $parentpost['title'], qa_path(qa_q_request($params['parentid'], $parentpost['title']), null, qa_opt('site_url'), null, qa_anchor('A', $params['postid']))));
             break;
     }
 }
Esempio n. 7
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();
 }
 function doctype()
 {
     if (qa_post_text('merge_from') && qa_get_logged_in_level() >= QA_USER_LEVEL_ADMIN) {
         $merged = qa_merge_do_merge();
         if ($merged === true) {
             qa_redirect(qa_q_request(qa_post_text('merge_to'), null), array('merged' => qa_post_text('merge_from')));
         } else {
             $error1 = $merged[0];
             $error2 = $merged[1];
             $this->content['error'] = "Error merging posts.";
         }
     }
     qa_html_theme_base::doctype();
 }
 function output_widget($region, $place, $themeobject, $template, $request, $qa_content)
 {
     $temp = qa_db_query_sub('SELECT BINARY title as title, postid, netvotes, acount FROM ^posts WHERE type=$', 'Q');
     $max = mysqli_num_rows($temp);
     if (!$max) {
         return;
     }
     $themeobject->output('<h2>' . qa_opt('random_question_title') . '</h2>');
     for ($i = 0; $i < qa_opt('random_question_number'); $i++) {
         $rand = rand() / getrandmax() * $max;
         $check = mysqli_data_seek($temp, $rand);
         if (!$check) {
             $i--;
         } else {
             $random_question = qa_db_read_one_assoc($temp, true);
         }
         if (is_array($random_question)) {
             $votes = (int) $random_question['netvotes'];
             if ($votes > 0) {
                 if ($votes > 1) {
                     $votes = str_replace('^', '+' . $votes, qa_lang('main/x_votes'));
                 } else {
                     $votes = str_replace('1', '+1', qa_lang('main/1_vote'));
                 }
             } else {
                 if ($votes < 0) {
                     if ($votes < -1) {
                         $votes = str_replace('^', $votes, qa_lang('main/x_votes'));
                     } else {
                         $votes = str_replace('1', '-1', qa_lang('main/1_vote'));
                     }
                 } else {
                     $votes = '';
                 }
             }
             $answers = (int) $random_question['acount'];
             if ($answers > 0) {
                 if ($answers > 1) {
                     $answers = str_replace('^', '+' . $answers, qa_lang('main/x_answers'));
                 } else {
                     $answers = qa_lang('main/1_answer');
                 }
             } else {
                 $answers = '';
             }
             $themeobject->output('<div class="random-question" style="padding-bottom:4px;"><a href="' . qa_path_html(qa_q_request($random_question['postid'], $random_question['title'])) . '">' . $random_question['title'] . '</a></div><div class="random-question-meta" style="padding-bottom:4px; border-bottom:1px solid; margin-bottom:2px;">' . $votes . ($votes && $answers ? ', ' : '') . $answers . '</div>');
         }
     }
 }
Esempio n. 10
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;
    }
}
    function process_event($event, $userid, $handle, $cookieid, $params)
    {
        if (qa_opt('expert_question_enable')) {
            switch ($event) {
                case 'q_post':
                    if (qa_post_text('is_expert_question') == 'yes' || in_array(qa_opt('expert_question_type'), array(1, 2)) && !qa_get_logged_in_userid() || qa_opt('expert_question_type') == 3) {
                        require_once QA_INCLUDE_DIR . 'qa-app-post-update.php';
                        qa_question_set_hidden($params, true, $userid, $handle, $cookieid, array(), array());
                        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 (#,'is_expert_question','1')", $params['postid']);
                        if (qa_opt('expert_question_email_experts')) {
                            $subs = array('^post_title' => $params['title'], '^post_url' => qa_path_html(qa_q_request($params['postid'], $params['title']), null, qa_opt('site_url')), '^questions_list' => qa_path_html(qa_opt('expert_question_page_url'), null, qa_opt('site_url')), '^site_url' => qa_opt('site_url'));
                            $experts = explode("\n", qa_opt('expert_question_users'));
                            foreach ($experts as $expert) {
                                if (strpos($expert, '=')) {
                                    $expert = explode('=', $expert);
                                    $catnames = explode(',', $expert[1]);
                                    $cats = qa_db_read_all_values(qa_db_query_sub('SELECT categoryid FROM ^categories WHERE title IN ($)', $catnames));
                                    if (in_array($params['categoryid'], $cats)) {
                                        qa_send_notification($this->getuserfromhandle($expert[0]), '@', $expert[0], qa_opt('expert_question_email_subject'), qa_opt('expert_question_email_body'), $subs);
                                    }
                                } else {
                                    qa_send_notification($this->getuserfromhandle($expert), '@', $expert, qa_opt('expert_question_email_subject'), qa_opt('expert_question_email_body'), $subs);
                                }
                            }
                        }
                    }
                    break;
                default:
                    break;
            }
        }
    }
Esempio n. 12
0
function qa_badge_plugin_user_form($userid)
{
    $handles = qa_userids_to_handles(array($userid));
    $handle = $handles[$userid];
    // displays badge list in user profile
    $result = qa_db_read_all_assoc(qa_db_query_sub('SELECT badge_slug as slug, object_id AS oid FROM ^userbadges WHERE user_id=#', $userid));
    $fields = array();
    if (count($result) > 0) {
        // count badges
        $bin = qa_get_badge_list();
        $badges = array();
        foreach ($result as $info) {
            $slug = $info['slug'];
            $type = $bin[$slug]['type'];
            if (isset($badges[$type][$slug])) {
                $badges[$type][$slug]['count']++;
            } else {
                $badges[$type][$slug]['count'] = 1;
            }
            if ($info['oid']) {
                $badges[$type][$slug]['oid'][] = $info['oid'];
            }
        }
        foreach ($badges as $type => $badge) {
            $typea = qa_get_badge_type($type);
            $types = $typea['slug'];
            $typed = $typea['name'];
            $output = '
							<table>
								<tr>
									<td class="qa-form-wide-label">
										<h3 class="badge-title" title="' . qa_lang('badges/' . $types . '_desc') . '">' . $typed . '</h3>
									</td>
								</tr>';
            foreach ($badge as $slug => $info) {
                $badge_name = qa_lang('badges/' . $slug);
                if (!qa_opt('badge_' . $slug . '_name')) {
                    qa_opt('badge_' . $slug . '_name', $badge_name);
                }
                $name = qa_opt('badge_' . $slug . '_name');
                $count = $info['count'];
                if (qa_opt('badge_show_source_posts')) {
                    $oids = @$info['oid'];
                } else {
                    $oids = null;
                }
                $var = qa_opt('badge_' . $slug . '_var');
                $desc = qa_badge_desc_replace($slug, $var, $name);
                // badge row
                $output .= '
								<tr>
									<td class="badge-container">
										<div class="badge-container-badge">
											<span class="badge-' . $types . '" title="' . $desc . ' (' . $typed . ')">' . qa_html($name) . '</span>&nbsp;<span onclick="jQuery(\'.badge-container-sources-' . $slug . '\').slideToggle()" class="badge-count' . (is_array($oids) ? ' badge-count-link" title="' . qa_lang('badges/badge_count_click') : '') . '">x&nbsp;' . $count . '</span>
										</div>';
                // source row(s) if any
                if (is_array($oids)) {
                    $output .= '
										<div class="badge-container-sources-' . $slug . '" style="display:none">';
                    foreach ($oids as $oid) {
                        $post = qa_db_select_with_pending(qa_db_full_post_selectspec(null, $oid));
                        $title = $post['title'];
                        $anchor = '';
                        if ($post['parentid']) {
                            $anchor = urlencode(qa_anchor($post['type'], $oid));
                            $oid = $post['parentid'];
                            $title = qa_db_read_one_value(qa_db_query_sub('SELECT BINARY title as title FROM ^posts WHERE postid=#', $oid), true);
                        }
                        $length = 30;
                        $text = qa_strlen($title) > $length ? qa_substr($title, 0, $length) . '...' : $title;
                        $output .= '
											<div class="badge-source"><a href="' . qa_path_html(qa_q_request($oid, $title), NULL, qa_opt('site_url')) . ($anchor ? '#' . $anchor : '') . '">' . qa_html($text) . '</a></div>';
                    }
                }
                $output .= '
									</td>
								</tr>';
            }
            $output .= '
							</table>';
            $outa[] = $output;
        }
        $fields[] = array('value' => '<table class="badge-user-tables"><tr><td class="badge-user-table">' . implode('</td><td class="badge-user-table">', $outa) . '</td></tr></table>', 'type' => 'static');
    }
    $ok = null;
    $tags = null;
    $buttons = array();
    if ((bool) qa_opt('badge_email_notify') && qa_get_logged_in_handle() == $handle) {
        // add badge notify checkbox
        if (qa_clicked('badge_email_notify_save')) {
            qa_opt('badge_email_notify_id_' . $userid, (bool) qa_post_text('badge_notify_email_me'));
            $ok = qa_lang('badges/badge_notified_email_me');
        }
        $select = (bool) qa_opt('badge_email_notify_id_' . $userid);
        $tags = 'id="badge-form" action="' . qa_self_html() . '#signature_text" method="POST"';
        $fields[] = array('type' => 'blank');
        $fields[] = array('label' => qa_lang('badges/badge_notify_email_me'), 'type' => 'checkbox', 'tags' => 'NAME="badge_notify_email_me"', 'value' => $select);
        $buttons[] = array('label' => qa_lang_html('main/save_button'), 'tags' => 'NAME="badge_email_notify_save"');
    }
    return array('ok' => $ok && !isset($error) ? $ok : null, 'style' => 'tall', 'tags' => $tags, 'title' => qa_lang('badges/badges'), 'fields' => $fields, 'buttons' => $buttons);
}
Esempio n. 13
0
 function post($event, $userid, $handle, $params, $type)
 {
     // remove mentions
     if (!qa_opt('buddypress_mentions')) {
         remove_filter('bp_activity_after_save', 'bp_activity_at_name_filter_updates');
     }
     switch ($type) {
         case 'Q':
             $suffix = ' question ';
             break;
         case 'A':
             $suffix = 'n %answer% to the question ';
             break;
         case 'C':
             $suffix = ' %comment% on the question ';
             break;
     }
     // poll integration
     if (qa_post_text('is_poll')) {
         if ($type == 'A') {
             return;
         }
         if ($type == 'Q') {
             $suffix = str_replace('question', 'poll', $suffix);
         } else {
             $suffix = str_replace('question', 'poll', $suffix);
         }
     }
     $content = $params['content'];
     // activity post
     if ($event != 'q_post') {
         $parent = qa_db_read_one_assoc(qa_db_query_sub('SELECT * FROM ^posts WHERE postid=#', $params['parentid']), true);
         if ($parent['type'] == 'A') {
             $parent = qa_db_read_one_assoc(qa_db_query_sub('SELECT * FROM ^posts WHERE postid=#', $parent['parentid']), true);
         }
         $anchor = qa_anchor($event == 'a_post' ? 'A' : 'C', $params['postid']);
         $suffix = preg_replace('/%([^%]+)%/', '<a href="' . qa_path_html(qa_q_request($parent['postid'], $parent['title']), null, qa_opt('site_url'), null, $anchor) . '">$1</a>', $suffix);
         $activity_url = qa_path_html(qa_q_request($parent['postid'], $parent['title']), null, qa_opt('site_url'));
         $context = $suffix . '"<a href="' . $activity_url . '">' . $parent['title'] . '</a>"';
     } else {
         $activity_url = qa_path_html(qa_q_request($params['postid'], $params['title']), null, qa_opt('site_url'));
         $context = $suffix . '"<a href="' . $activity_url . '">' . $params['title'] . '</a>"';
     }
     if (qa_opt('buddypress_display_names')) {
         $name = bp_core_get_user_displayname($handle) ? bp_core_get_user_displayname($handle) : $handle;
     } else {
         $name = $handle;
     }
     $action = '<a href="' . bp_core_get_user_domain($userid) . '" rel="nofollow">' . $name . '</a> posted a' . $context . ' at <a href="' . qa_opt('site_url') . '">' . qa_opt('site_title') . '</a>';
     if (qa_opt('buddypress_integration_include_content')) {
         $informat = $params['format'];
         $viewer = qa_load_viewer($content, $informat);
         if (qa_opt('buddypress_integration_max_post_length') && strlen($content) > (int) qa_opt('buddypress_integration_max_post_length')) {
             $content = substr($content, 0, (int) qa_opt('buddypress_integration_max_post_length'));
             $content = $content . ' ...';
         }
         $content = $viewer->get_html($content, $informat, array());
     } else {
         $content = null;
     }
     global $phpmailer;
     if (class_exists('PHPMailer') && !is_object($phpmailer)) {
         $phpmailer = new PHPMailer(true);
     }
     $act_id = qa_buddypress_activity_post(array('action' => $action, 'content' => $content, 'primary_link' => $activity_url, 'component' => 'bp-qa', 'type' => 'activity_qa_' . $type, 'user_id' => $userid, 'item_id' => null));
 }
Esempio n. 14
0
// extract IDs and prepare for pagination
$answerids = array_keys($answerposition);
$countforpages = count($answerids);
$pagesize = qa_opt('page_size_q_as');
// see if we need to display a particular answer
if (isset($showid)) {
    if (isset($commentsfollows[$showid])) {
        $showid = $commentsfollows[$showid]['parentid'];
    }
    $position = array_search($showid, $answerids);
    if (is_numeric($position)) {
        $pagestart = floor($position / $pagesize) * $pagesize;
    }
}
// set the canonical url based on possible pagination
$qa_content['canonical'] = qa_path_html(qa_q_request($question['postid'], $question['title']), $pagestart > 0 ? array('start' => $pagestart) : null, qa_opt('site_url'));
// build the actual answer list
$answerids = array_slice($answerids, $pagestart, $pagesize);
foreach ($answerids as $answerid) {
    $answer = $answers[$answerid];
    if (!($formtype == 'a_edit' && $formpostid == $answerid)) {
        $a_view = qa_page_q_answer_view($question, $answer, $answer['isselected'], $usershtml, $formrequested);
        //	Prepare content for comments on this answer, plus add or edit comment forms
        if ($formtype == 'c_add' && $formpostid == $answerid || $answer['commentbutton'] && !$formrequested) {
            // ...to be added
            $a_view['c_form'] = qa_page_q_add_c_form($qa_content, $question, $answer, 'c' . $answerid, $captchareason, @$cnewin[$answerid], @$cnewerrors[$answerid], $formtype == 'c_add');
            if ($formtype == 'c_add' && $formpostid == $answerid) {
                $jumptoanchor = 'c' . $answerid;
                $commentsall = $answerid;
            }
        } elseif ($formtype == 'c_edit' && @$commentsfollows[$formpostid]['parentid'] == $answerid) {
Esempio n. 15
0
function ra_user_badges_list($userid)
{
    if (!qa_opt('badge_active')) {
        return;
    }
    $handles = qa_userids_to_handles(array($userid));
    $handle = $handles[$userid];
    // displays badge list in user profile
    $result = qa_db_read_all_assoc(qa_db_query_sub('SELECT badge_slug as slug, object_id AS oid FROM ^userbadges WHERE user_id=#', $userid));
    if (count($result) > 0) {
        // count badges
        $bin = qa_get_badge_list();
        $badges = array();
        foreach ($result as $info) {
            $slug = $info['slug'];
            $type = $bin[$slug]['type'];
            if (isset($badges[$type][$slug])) {
                $badges[$type][$slug]['count']++;
            } else {
                $badges[$type][$slug]['count'] = 1;
            }
            if ($info['oid']) {
                $badges[$type][$slug]['oid'][] = $info['oid'];
            }
        }
        foreach ($badges as $type => $badge) {
            $typea = qa_get_badge_type($type);
            $types = $typea['slug'];
            $typed = $typea['name'];
            $output = '';
            //$output = '<h3 class="badge-title" title="'.qa_lang('badges/'.$types.'_desc').'">'.$typed.'</h3>';
            foreach ($badge as $slug => $info) {
                $badge_name = qa_badge_name($slug);
                if (!qa_opt('badge_' . $slug . '_name')) {
                    qa_opt('badge_' . $slug . '_name', $badge_name);
                }
                $name = qa_opt('badge_' . $slug . '_name');
                $count = $info['count'];
                if (qa_opt('badge_show_source_posts')) {
                    $oids = @$info['oid'];
                } else {
                    $oids = null;
                }
                $var = qa_opt('badge_' . $slug . '_var');
                $desc = qa_badge_desc_replace($slug, $var, false);
                // badge row
                $output .= '<div class="badge-container-badge">
									<span class="user-badge ' . $types . ' icon-badge" title="' . $desc . ' (' . $typed . ')">' . qa_html($name) . '</span>&nbsp;<span class="badge-count">x&nbsp;' . $count . '</span>' . (is_array($oids) ? '<i class="icon-chevron-down"></i>' : '');
                // source row(s) if any
                if (is_array($oids)) {
                    $output .= '
								<div class="badge-sources ' . $slug . '"><ul>';
                    foreach ($oids as $oid) {
                        $post = qa_db_select_with_pending(qa_db_full_post_selectspec(null, $oid));
                        $title = $post['title'];
                        $anchor = '';
                        if ($post['parentid']) {
                            $anchor = urlencode(qa_anchor($post['type'], $oid));
                            $oid = $post['parentid'];
                            $title = qa_db_read_one_value(qa_db_query_sub('SELECT BINARY title as title FROM ^posts WHERE postid=#', $oid), true);
                        }
                        //$length = 30;
                        $text = $title;
                        $output .= '<li><a href="' . qa_path_html(qa_q_request($oid, $title), NULL, qa_opt('site_url')) . ($anchor ? '#' . $anchor : '') . '">' . qa_html($text) . '</a></li>';
                    }
                    $output .= '</ul></div>';
                }
                $output .= '</div>';
            }
            $outa[] = $output;
        }
        $fields = '<div class="badge-user-block widget"><h3 class="widget-title">' . _ra_lang('Badges') . '</h3><div class="widget-inner">' . implode('', $outa) . '</div></div>';
    }
    return $fields;
}
Esempio n. 16
0
    $errors = qa_question_validate($intitle, $incontent, $informat, $intext, $tagstring, $innotify, $inemail);
    if (qa_using_categories() && count($categories) && !qa_opt('allow_no_category') && !isset($incategoryid)) {
        $errors['category'] = qa_lang_html('question/category_required');
    }
    if ($usecaptcha) {
        require_once 'qa-app-captcha.php';
        qa_captcha_validate($_POST, $errors);
    }
    if (empty($errors)) {
        if (!isset($qa_login_userid)) {
            $qa_cookieid = qa_cookie_get_create();
        }
        // create a new cookie if necessary
        $questionid = qa_question_create($followanswer, $qa_login_userid, qa_get_logged_in_handle(), $qa_cookieid, $intitle, $incontent, $informat, $intext, $tagstring, $innotify, $inemail, $incategoryid);
        qa_report_write_action($qa_login_userid, $qa_cookieid, 'q_post', $questionid, null, null);
        qa_redirect(qa_q_request($questionid, $intitle));
        // our work is done here
    }
}
//	Prepare content for theme
$qa_content = qa_content_prepare(false, array_keys(qa_category_path($categories, @$incategoryid)));
$qa_content['title'] = qa_lang_html(isset($followanswer) ? 'question/ask_follow_title' : 'question/ask_title');
$editorname = isset($ineditor) ? $ineditor : qa_opt('editor_for_qs');
$editor = qa_load_editor(@$incontent, @$informat, $editorname);
// MP: find category title
$categoryinfo = mp_get_categoryinfo(mp_get_categoryid());
$qa_content['form'] = array('tags' => 'NAME="ask" METHOD="POST" ACTION="' . qa_self_html() . '"', 'style' => 'tall', 'fields' => array('follows' => array(), 'title' => array('label' => qa_lang_html('question/q_title_label'), 'tags' => 'NAME="title" ID="title" AUTOCOMPLETE="off"', 'value' => qa_html(@$intitle), 'error' => qa_html(@$errors['title'])), 'similar' => array('type' => 'custom', 'html' => '<SPAN ID="similar"></SPAN>'), 'categorylabel' => array('type' => 'static', 'label' => qa_lang_html('question/q_category_label'), 'error' => qa_html(@$errors['category']), 'value' => $categoryinfo['title']), 'content' => array_merge($editor->get_field($qa_content, @$incontent, @$informat, 'content', 12, false), array('label' => qa_lang_html('question/q_content_label'), 'error' => qa_html(@$errors['content']))), 'tags' => array('error' => qa_html(@$errors['tags']))), 'buttons' => array('ask' => array('label' => qa_lang_html('question/ask_button'))), 'hidden' => array('editor' => qa_html($editorname), 'doask' => '1', 'category' => mp_get_categoryid()));
if (qa_opt('do_ask_check_qs') || qa_opt('do_example_tags')) {
    $qa_content['script_rel'][] = 'qa-content/qa-ask.js?' . QA_VERSION;
    $qa_content['form']['fields']['title']['tags'] .= ' onChange="qa_title_change(this.value);"';
    if (strlen(@$intitle)) {
 function expert_question_form()
 {
     // displays expert_question_form form in user profile
     global $qa_request;
     $handle = $this->_user_handle();
     $uid = $this->getuserfromhandle($handle);
     if (!$uid) {
         return;
     }
     $questions = $this->get_expert_question_for_user($uid);
     if (empty($questions)) {
         return;
     }
     $output = '<div class="expert_question_container">';
     $qs = qa_db_read_all_assoc(qa_db_query_sub("SELECT title,postid,acount FROM ^posts WHERE postid in (" . implode(',', $questions) . ")"));
     foreach ($qs as $question) {
         $title = $question['title'];
         $length = 60;
         $text = strlen($title) > $length ? substr($title, 0, $length) . '...' : $title;
         $acount = $question['acount'] == 1 ? qa_lang_html('main/1_answer') : qa_lang_html_sub('main/x_answers', $question['acount']);
         $output .= '<div class="expert_question-row" id="expert_question-row-' . $idx . '"><a href="' . qa_path_html(qa_q_request($question['postid'], $title), NULL, qa_opt('site_url')) . '">' . qa_html($text) . '</a> (' . $acount . ')</div>';
     }
     $output .= '</div>';
     $fields[] = array('type' => 'static', 'label' => $output);
     $form = array('style' => 'tall', 'tags' => 'id="expert_question_form"', 'title' => '<a id="expert_question_title">' . qa_opt('expert_question_page_title') . '</a>', 'fields' => $fields);
     return $form;
 }
Esempio n. 18
0
 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;
 }
Esempio n. 19
0
function qa_flag_set_tohide($post, $userid, $handle, $cookieid, $question)
{
    require_once QA_INCLUDE_DIR . 'qa-db-votes.php';
    require_once QA_INCLUDE_DIR . 'qa-app-limits.php';
    qa_db_userflag_set($post['postid'], $userid, true);
    qa_db_post_recount_flags($post['postid']);
    switch ($post['basetype']) {
        case 'Q':
            $action = 'q_flag';
            break;
        case 'A':
            $action = 'a_flag';
            break;
        case 'C':
            $action = 'c_flag';
            break;
    }
    qa_report_write_action($userid, null, $action, $post['basetype'] == 'Q' ? $post['postid'] : null, $post['basetype'] == 'A' ? $post['postid'] : null, $post['basetype'] == 'C' ? $post['postid'] : null);
    qa_report_event($action, $userid, $handle, $cookieid, array('postid' => $post['postid']));
    $post = qa_db_select_with_pending(qa_db_full_post_selectspec(null, $post['postid']));
    $flagcount = $post['flagcount'];
    $notifycount = $flagcount - qa_opt('flagging_notify_first');
    if ($notifycount >= 0 && $notifycount % qa_opt('flagging_notify_every') == 0) {
        require_once QA_INCLUDE_DIR . 'qa-app-emails.php';
        require_once QA_INCLUDE_DIR . 'qa-app-format.php';
        $anchor = $post['basetype'] == 'Q' ? null : qa_anchor($post['basetype'], $post['postid']);
        qa_send_notification(null, qa_opt('feedback_email'), null, qa_lang('emails/flagged_subject'), qa_lang('emails/flagged_body'), array('^p_handle' => isset($post['handle']) ? $post['handle'] : qa_lang('main/anonymous'), '^flags' => $flagcount == 1 ? qa_lang_html_sub('main/1_flag', '1', '1') : qa_lang_html_sub('main/x_flags', $flagcount), '^p_context' => trim(@$post['title'] . "\n\n" . qa_viewer_text($post['content'], $post['format'])), '^url' => qa_path(qa_q_request($question['postid'], $question['title']), null, qa_opt('site_url'), null, $anchor)));
    }
    if ($flagcount >= qa_opt('flagging_hide_after') && !$post['hidden']) {
        return true;
    }
    return false;
}
Esempio n. 20
0
function qa_q_path($questionid, $title, $absolute = false, $showtype = null, $showid = null)
{
    if (qa_to_override(__FUNCTION__)) {
        $args = func_get_args();
        return qa_call_override(__FUNCTION__, $args);
    }
    if (($showtype == 'Q' || $showtype == 'A' || $showtype == 'C') && isset($showid)) {
        $params = array('show' => $showid);
        // due to pagination
        $anchor = qa_anchor($showtype, $showid);
    } else {
        $params = null;
        $anchor = null;
    }
    return qa_path(qa_q_request($questionid, $title), $params, $absolute ? qa_opt('site_url') : null, null, $anchor);
}
Esempio n. 21
0
 function process_request($request)
 {
     @ini_set('display_errors', 0);
     // we don't want to show PHP errors inside XML
     $siteurl = qa_opt('site_url');
     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
     $nextpostid = 0;
     while (1) {
         $questions = qa_db_read_all_assoc(qa_db_query_sub("SELECT postid, BINARY title AS title, upvotes, downvotes FROM ^posts WHERE postid>=# AND type='Q' ORDER BY postid LIMIT 100", $nextpostid));
         if (!count($questions)) {
             break;
         }
         foreach ($questions as $question) {
             $priority = 0.5;
             // between 0 and 1 depending on up/down votes (0.5 if net votes are zero)
             $netvotes = $question['upvotes'] - $question['downvotes'];
             if ($netvotes != 0) {
                 $absvotes = abs($netvotes);
                 $signvotes = $netvotes / $absvotes;
                 $priority += $signvotes * 0.5 / (1 + 1 / $absvotes);
             }
             echo "\t<url>\n" . "\t\t<loc>" . qa_path_html(qa_q_request($question['postid'], $question['title']), null, $siteurl) . "</loc>\n" . "\t\t<priority>" . $priority . "</priority>\n" . "\t</url>\n";
             $nextpostid = max($nextpostid, $question['postid'] + 1);
         }
     }
     //	Tag pages
     if (qa_using_tags()) {
         $nextwordid = 0;
         while (1) {
             $tagwords = qa_db_read_all_assoc(qa_db_query_sub("SELECT wordid, BINARY word AS word, tagcount FROM ^words WHERE wordid>=# AND tagcount>0 ORDER BY wordid LIMIT 100", $nextwordid));
             if (!count($tagwords)) {
                 break;
             }
             foreach ($tagwords as $tagword) {
                 $priority = 0.5 / (1 + 1 / $tagword['tagcount']);
                 // between 0.25 and 0.5 depending on tag frequency
                 echo "\t<url>\n" . "\t\t<loc>" . qa_path_html('tag/' . $tagword['word'], null, $siteurl) . "</loc>\n" . "\t\t<priority>" . $priority . "</priority>\n" . "\t</url>\n";
                 $nextwordid = max($nextwordid, $tagword['wordid'] + 1);
             }
         }
     }
     //	User pages
     if (!QA_FINAL_EXTERNAL_USERS) {
         $nextuserid = 0;
         while (1) {
             $users = qa_db_read_all_assoc(qa_db_query_sub("SELECT userid, BINARY handle AS handle FROM ^users WHERE userid>=# ORDER BY userid LIMIT 100", $nextuserid));
             if (!count($users)) {
                 break;
             }
             foreach ($users as $user) {
                 $priority = 0.25;
                 echo "\t<url>\n" . "\t\t<loc>" . qa_path_html('user/' . $user['handle'], null, $siteurl) . "</loc>\n" . "\t\t<priority>" . $priority . "</priority>\n" . "\t</url>\n";
                 $nextuserid = max($nextuserid, $user['userid'] + 1);
             }
         }
     }
     echo "</urlset>\n";
     return null;
 }
function qa_comment_create($userid, $handle, $cookieid, $content, $format, $text, $notify, $email, $question, $answer, $commentsfollows)
{
    require_once QA_INCLUDE_DIR . 'qa-app-emails.php';
    require_once QA_INCLUDE_DIR . 'qa-app-options.php';
    require_once QA_INCLUDE_DIR . 'qa-app-format.php';
    require_once QA_INCLUDE_DIR . 'qa-util-string.php';
    $parent = isset($answer) ? $answer : $question;
    $postid = qa_db_post_create('C', $parent['postid'], $userid, isset($userid) ? null : $cookieid, qa_remote_ip_address(), null, $content, $format, null, qa_combine_notify_email($userid, $notify, $email), $question['categoryid']);
    qa_db_posts_calc_category_path($postid);
    if (!($question['hidden'] || @$answer['hidden'])) {
        // don't index comment if parent or parent of parent is hidden
        qa_post_index($postid, 'C', $question['postid'], null, $text, null);
    }
    qa_db_points_update_ifuser($userid, 'cposts');
    qa_db_ccount_update();
    //	$senttoemail and $senttouserid ensure each user or email gets only one notification about an added comment,
    //	even if they have several previous comments in the same thread and asked for notifications for the parent.
    //	Still, if a person posted some comments as a registered user and some others anonymously,
    //	they could get two emails about a subsequent comment. Shouldn't be much of a problem in practice.
    $senttoemail = array();
    $senttouserid = array();
    switch ($parent['basetype']) {
        case 'Q':
            $subject = qa_lang('emails/q_commented_subject');
            $body = qa_lang('emails/q_commented_body');
            $context = $parent['title'];
            break;
        case 'A':
            $subject = qa_lang('emails/a_commented_subject');
            $body = qa_lang('emails/a_commented_body');
            $context = qa_viewer_text($parent['content'], $parent['format']);
            break;
    }
    $blockwordspreg = qa_get_block_words_preg();
    $sendhandle = isset($handle) ? $handle : qa_lang('main/anonymous');
    $sendcontext = qa_block_words_replace($context, $blockwordspreg);
    $sendtext = qa_block_words_replace($text, $blockwordspreg);
    $sendtitle = qa_block_words_replace($question['title'], $blockwordspreg);
    $sendurl = qa_path(qa_q_request($question['postid'], $sendtitle), null, qa_opt('site_url'), null, qa_anchor($parent['basetype'], $parent['postid']));
    if (isset($parent['notify']) && !qa_post_is_by_user($parent, $userid, $cookieid)) {
        $senduserid = $parent['userid'];
        $sendemail = @$parent['notify'];
        if (qa_email_validate($sendemail)) {
            $senttoemail[$sendemail] = true;
        } elseif (isset($senduserid)) {
            $senttouserid[$senduserid] = true;
        }
        qa_send_notification($senduserid, $sendemail, @$parent['handle'], $subject, $body, array('^c_handle' => $sendhandle, '^c_context' => $sendcontext, '^c_content' => $sendtext, '^url' => $sendurl));
    }
    foreach ($commentsfollows as $comment) {
        if ($comment['basetype'] == 'C' && $comment['parentid'] == $parent['postid'] && !$comment['hidden']) {
            // find just those for this parent
            if (isset($comment['notify']) && !qa_post_is_by_user($comment, $userid, $cookieid)) {
                $senduserid = $comment['userid'];
                $sendemail = @$comment['notify'];
                if (qa_email_validate($sendemail)) {
                    if (@$senttoemail[$sendemail]) {
                        continue;
                    }
                    $senttoemail[$sendemail] = true;
                } elseif (isset($senduserid)) {
                    if (@$senttouserid[$senduserid]) {
                        continue;
                    }
                    $senttouserid[$senduserid] = true;
                }
                qa_send_notification($senduserid, $sendemail, @$comment['handle'], qa_lang('emails/c_commented_subject'), qa_lang('emails/c_commented_body'), array('^c_handle' => $sendhandle, '^c_context' => $sendcontext, '^c_content' => $sendtext, '^url' => $sendurl));
            }
        }
    }
    qa_report_event('c_post', $userid, $handle, $cookieid, array('postid' => $postid, 'parentid' => $parent['postid'], 'parenttype' => $parent['basetype'], 'questionid' => $question['postid'], 'content' => $content, 'format' => $format, 'text' => $text, 'categoryid' => $question['categoryid'], 'notify' => $notify, 'email' => $email));
    return $postid;
}
 function process_request($request)
 {
     // get all variables
     preg_match($this->reqmatch, $request, $matches);
     $post_type = $matches[1];
     $handle = $matches[2];
     $start = (int) qa_get('start');
     $pagesize = qa_opt('page_size_qs');
     $hidecss = qa_opt($this->cssopt) === '1';
     // regular page request
     $qa_content = qa_content_prepare();
     require_once QA_INCLUDE_DIR . 'qa-util-string.php';
     // display CSS for stat summary
     if (!$hidecss) {
         $qa_content['custom'] = "<style>\n" . ".qa-useract-page-links { margin: 16px 0; color: #555753; font-size: 16px; text-align: center; }\n" . ".qa-useract-page-links > a { font-weight: bold; }\n" . ".qa-useract-stats { margin: 8px 0; text-align: center; }\n" . ".qa-useract-stat { display: inline-block; margin: 0 16px 8px; }\n" . ".qa-useract-count { font-size: 18px; font-weight: bold; }\n" . ".qa-useract-wrapper .qa-q-item-main { width: 658px; }\n" . ".qa-useract-wrapper .qa-a-count { height: auto; border: 1px solid #ebeaca; border-radius: 8px; -moz-border-radius: 8px; -webkit-border-radius:8px; }\n" . ".qa-useract-wrapper .qa-a-snippet { margin-top: 2px; color: #555753; }\n" . ".qa-useract-wrapper .qa-q-item-meta { float: none; }\n" . "</style>\n\n";
     }
     // list of questions by this user
     if ($post_type === 'questions') {
         $qa_content['title'] = qa_lang_html_sub('useractivity/questions_by', $handle);
         list($userid, $count, $sel_count) = $this->_questions_stats($handle);
         // get questions
         $columns = 'postid, categoryid, type, LEFT(type,1) AS basetype, INSTR(type,"_HIDDEN")>0 AS hidden, acount, selchildid, closedbyid, upvotes, downvotes, netvotes, hotness, flagcount, BINARY title AS title, BINARY tags AS tags, UNIX_TIMESTAMP(created) AS created';
         $sql_questions = 'SELECT ' . $columns . ' FROM ^posts WHERE type="Q" AND userid=# ORDER BY created DESC LIMIT #,#';
         $result = qa_db_query_sub($sql_questions, $userid, $start, $pagesize);
         $questions = qa_db_read_all_assoc($result);
         $htmloptions = qa_post_html_defaults('Q');
         $htmloptions['whoview'] = false;
         $htmloptions['avatarsize'] = 0;
         // html for stats
         $qa_content['custom'] .= '<div class="qa-useract-stats">' . '	<div class="qa-useract-stat"><span class="qa-useract-count">' . $count . '</span><br>' . ($count == 1 ? qa_lang_html('useractivity/question') : qa_lang_html('useractivity/questions')) . '</div>' . '	<div class="qa-useract-stat"><span class="qa-useract-count">' . $sel_count . '</span><br>' . ($sel_count == 1 ? qa_lang_html('useractivity/best_answer_given') : qa_lang_html('useractivity/best_answers_given')) . '</div>' . '</div>';
         // create html for question list
         $qa_content['q_list']['qs'] = array();
         foreach ($questions as $question) {
             $qa_content['q_list']['qs'][] = qa_any_to_q_html_fields($question, qa_get_logged_in_userid(), qa_cookie_get(), null, null, $htmloptions);
         }
         // pagination
         $qa_content['page_links'] = qa_html_page_links($request, $start, $pagesize, $count, qa_opt('pages_prev_next'), null);
         return $qa_content;
     } else {
         if ($post_type === 'answers') {
             $qa_content['title'] = qa_lang_html_sub('useractivity/answers_by', $handle);
             // userid and answer count
             $sql_count = 'SELECT u.userid, count(a.postid) AS qs, sum(q.selchildid=a.postid) AS selected ' . 'FROM ^posts a, ^posts q, ^users u ' . 'WHERE a.parentid=q.postid AND u.userid=a.userid AND a.type="A" AND q.type="Q" AND u.handle=$';
             $result = qa_db_query_sub($sql_count, $handle);
             $row = qa_db_read_one_assoc($result);
             $userid = $row['userid'];
             $count = $row['qs'];
             $sel_count = $row['selected'];
             // get answers
             $columns = 'q.postid AS qpostid, BINARY q.title AS qtitle, q.selchildid AS qselid, q.netvotes AS qvotes, a.postid AS apostid, BINARY a.content AS acontent, a.netvotes AS avotes, UNIX_TIMESTAMP(a.created) AS acreated, a.format';
             $sql_answers = 'SELECT ' . $columns . ' FROM ^posts a, ^posts q WHERE a.parentid=q.postid AND a.type="A" AND q.type="Q" AND a.userid=# ORDER BY a.created DESC LIMIT #,#';
             $result = qa_db_query_sub($sql_answers, $userid, $start, $pagesize);
             $answers = qa_db_read_all_assoc($result);
             $qa_content['custom'] .= '<div class="qa-useract-stats">' . '	<div class="qa-useract-stat"><span class="qa-useract-count">' . $count . '</span><br>' . ($count == 1 ? qa_lang_html('useractivity/answer') : qa_lang_html('useractivity/answers')) . '</div>' . '	<div class="qa-useract-stat"><span class="qa-useract-count">' . $sel_count . '</span><br>' . ($sel_count == 1 ? qa_lang_html('useractivity/best_answer_received') : qa_lang_html('useractivity/best_answers_received')) . '</div>' . '</div>';
             $qa_content['custom_2'] = '<div class="qa-useract-wrapper">';
             foreach ($answers as $ans) {
                 // to avoid ugly content, convert answer to HTML then strip the tags and remove any URLs
                 $ans['acontent'] = qa_viewer_html($ans['acontent'], $ans['format']);
                 $ans['acontent'] = strip_tags($ans['acontent']);
                 $ans['acontent'] = preg_replace('#\\shttp://[^\\s]+#', '', $ans['acontent']);
                 $ans['acontent'] = qa_substr($ans['acontent'], 0, 100);
                 if (strlen($ans['acontent']) == 100) {
                     $ans['acontent'] .= '...';
                 }
                 // question url
                 $ans['qurl'] = qa_path_html(qa_q_request($ans['qpostid'], $ans['qtitle']));
                 // answer date
                 $ans['acreated'] = qa_when_to_html($ans['acreated'], qa_opt('show_full_date_days'));
                 // html content
                 $qa_content['custom_2'] .= $this->_answer_tmpl($ans);
             }
             $qa_content['custom_2'] .= '</div>';
             // pagination
             $qa_content['page_links'] = qa_html_page_links($request, $start, $pagesize, $count, qa_opt('pages_prev_next'), null);
             return $qa_content;
         }
     }
 }
Esempio n. 24
0
function qa_book_plugin_createBook($return = false)
{
    $book = qa_opt('book_plugin_template');
    // static replacements
    $book = str_replace('[css]', qa_opt('book_plugin_css'), $book);
    $book = str_replace('[front]', qa_opt('book_plugin_template_front'), $book);
    $book = str_replace('[back]', qa_opt('book_plugin_template_back'), $book);
    $iscats = qa_opt('book_plugin_cats');
    // categories
    if ($iscats) {
        $cats = qa_db_read_all_assoc(qa_db_query_sub('SELECT * FROM ^categories' . (qa_opt('book_plugin_catex') ? ' WHERE categoryid NOT IN (' . qa_opt('book_plugin_catex') . ')' : '')));
        $navcats = array();
        foreach ($cats as $cat) {
            $navcats[$cat['categoryid']] = $cat;
        }
    } else {
        $cats = array(false);
    }
    // intro
    $intro = qa_lang('book/intro');
    $intro = str_replace('[sort_questions]', qa_lang('book/' . (qa_opt('book_plugin_sort_q') == 0 ? 'sort_upvotes' : 'sort_date')), $intro);
    $intro = str_replace('[sort_categories]', $iscats ? qa_lang('book/sort_categories') : '', $intro);
    $intro = str_replace('[restrict_questions]', qa_opt('book_plugin_req_qv') ? qa_lang_sub('book/restrict_q_x_votes', qa_opt('book_plugin_req_qv_no')) : qa_lang('book/all_questions'), $intro);
    $rq = array();
    if (qa_opt('book_plugin_req_sel')) {
        $rq[] = qa_lang('book/restrict_selected');
    }
    if (qa_opt('book_plugin_req_abest')) {
        $rq[] = qa_lang('book/restrict_best_a');
    }
    if (qa_opt('book_plugin_req_av')) {
        $rq[] = qa_lang_sub('book/restrict_a_x_votes', qa_opt('book_plugin_req_av_no'));
    }
    if (empty($rq)) {
        $intro = str_replace('[restrict_answers]', '', $intro);
    } else {
        $rqs = qa_lang('book/restrict_answers_clause_' . count($rq));
        foreach ($rq as $i => $v) {
            $rqs = str_replace('(' . ($i + 1) . ')', $v, $rqs);
        }
        $intro = str_replace('[restrict_answers]', $rqs, $intro);
    }
    $book = str_replace('[intro]', $intro, $book);
    $tocout = '';
    $qout = '';
    foreach ($cats as $cat) {
        $incsql = '';
        $sortsql = '';
        $toc = '';
        $qhtml = '';
        if (qa_opt('book_plugin_sort_q') == 0) {
            $sortsql = 'ORDER BY qs.netvotes DESC, qs.created ASC';
        } else {
            $sortsql = 'ORDER BY qs.created ASC';
        }
        if (qa_opt('book_plugin_req_sel')) {
            $incsql .= ' AND qs.selchildid=ans.postid';
        }
        if (qa_opt('book_plugin_req_abest')) {
            $sortsql .= ', ans.netvotes DESC';
        }
        // get all, limit later with break
        if (qa_opt('book_plugin_req_qv')) {
            $incsql .= ' AND qs.netvotes >= ' . (int) qa_opt('book_plugin_req_qv_no');
        }
        if (qa_opt('book_plugin_req_av')) {
            $incsql .= ' AND ans.netvotes >= ' . (int) qa_opt('book_plugin_req_av_no');
        }
        $selectspec = "SELECT qs.postid AS postid, BINARY qs.title AS title, BINARY qs.content AS content, qs.format AS format, qs.netvotes AS netvotes, BINARY ans.content AS acontent, ans.format AS aformat, ans.userid AS auserid, ans.netvotes AS anetvotes FROM ^posts AS qs, ^posts AS ans WHERE qs.type='Q' AND ans.type='A' AND ans.parentid=qs.postid" . ($iscats ? " AND qs.categoryid=" . $cat['categoryid'] . " " : "") . $incsql . " " . $sortsql;
        $qs = qa_db_read_all_assoc(qa_db_query_sub($selectspec));
        if (empty($qs)) {
            // no questions in this category
            continue;
        }
        $q2 = array();
        foreach ($qs as $q) {
            // group by questions
            $q2['q' . $q['postid']][] = $q;
        }
        foreach ($q2 as $qs) {
            // toc entry
            $toc .= str_replace('[qlink]', '<a href="#question' . $qs[0]['postid'] . '">' . $qs[0]['title'] . '</a>', qa_opt('book_plugin_template_toc'));
            // answer html
            $as = '';
            $nv = false;
            foreach ($qs as $idx => $q) {
                if (qa_opt('book_plugin_req_abest') && qa_opt('book_plugin_req_abest_max') && $idx >= qa_opt('book_plugin_req_abest_max')) {
                    break;
                }
                if ($nv !== false && qa_opt('book_plugin_req_abest') && $nv != $q['anetvotes']) {
                    // best answers only
                    break;
                }
                $acontent = '';
                if (!empty($q['acontent'])) {
                    $viewer = qa_load_viewer($q['acontent'], $q['aformat']);
                    $acontent = $viewer->get_html($q['acontent'], $q['aformat'], array());
                }
                $a = str_replace('[answer]', $acontent, qa_opt('book_plugin_template_answer'));
                $a = str_replace('[answerer]', qa_get_user_name($q['auserid']), $a);
                $as .= $a;
                $nv = $q['anetvotes'];
            }
            // question html
            $qcontent = '';
            if (!empty($q['content'])) {
                $viewer = qa_load_viewer($q['content'], $q['format']);
                $qcontent = $viewer->get_html($q['content'], $q['format'], array());
            }
            $oneq = str_replace('[question-title]', $q['title'], qa_opt('book_plugin_template_question'));
            $oneq = str_replace('[qanchor]', 'question' . $q['postid'], $oneq);
            $oneq = str_replace('[qurl]', qa_html(qa_q_request($q['postid'], $q['title'])), $oneq);
            $oneq = str_replace('[question]', $qcontent, $oneq);
            // output with answers
            $qhtml .= str_replace('[answers]', $as, $oneq);
        }
        if ($iscats) {
            $tocout .= '<li><a href="#cat' . $cat['categoryid'] . '" class="toc-cat">' . $cat['title'] . '</a><ul class="toc-ul">' . $toc . '</ul></li>';
            // todo fix category link
            $catout = str_replace('[cat-url]', qa_path_html('questions/' . qa_category_path_request($navcats, $cat['categoryid'])), qa_opt('book_plugin_template_category'));
            $catout = str_replace('[cat-anchor]', 'cat' . $cat['categoryid'], $catout);
            $catout = str_replace('[cat-title]', $cat['title'], $catout);
            $catout = str_replace('[questions]', $qhtml, $catout);
            $qout .= $catout;
        } else {
            $tocout .= '<ul class="toc-ul">' . $toc . '</ul>';
            $catout = str_replace('[questions]', $qhtml, qa_opt('book_plugin_template_questions'));
            $qout .= $catout;
        }
    }
    if ($iscats) {
        $tocout = '<ul class="toc-ul">' . $tocout . '</ul>';
    }
    // add toc and questions
    $book = str_replace('[toc]', $tocout, $book);
    $book = str_replace('[categories]', $qout, $book);
    // misc subs
    $book = str_replace('[site-title]', qa_opt('site_title'), $book);
    $book = str_replace('[site-url]', qa_opt('site_url'), $book);
    $book = str_replace('[date]', date('M j, Y'), $book);
    qa_opt('book_plugin_refresh_last', time());
    error_log('Q2A Book Created on ' . date('M j, Y \\a\\t H\\:i\\:s'));
    if ($return) {
        return $book;
    }
    file_put_contents(qa_opt('book_plugin_loc'), $book);
    if (qa_opt('book_plugin_pdf')) {
        qa_book_plugin_create_pdf();
    }
    return 'Book Created';
    //return 'Error creating '.qa_opt('book_plugin_loc').'; check the error log.';
}
    function process_request($request)
    {
        //@ini_set('display_errors', 0); // we don't want to show PHP errors inside XML
        if ($request == 'sitemap.xml') {
            $req = '';
        } else {
            $req_str = substr($request, 8, strlen($request) - 12);
            // extract "X-Y-Z" from "sitemap-X-Y-Z.xml"
            $req = explode('-', $req_str);
        }
        $siteurl = qa_opt('site_url');
        header('Content-type: text/xml; charset=utf-8');
        // Index Pages
        // Indexed all XML sitemaps for question's lists
        // example: sitemap.xml
        if ($req == '') {
            $this->sitemap_index_header();
            $q_sitemaps = qa_db_read_one_assoc(qa_db_query_sub("SELECT count(*) as total from ^posts WHERE type='Q'"));
            $count = qa_opt('useo_sitemap_question_count');
            $q_sitemap_count = ceil($q_sitemaps['total'] / $count);
            for ($i = 0; $i < $q_sitemap_count; $i++) {
                $this->sitemap_index_output('sitemap-' . $i . '.xml');
            }
            $this->sitemap_index_footer();
        }
        // Indexed all important XML sitemaps
        // example: sitemap-index.xml
        if (count($req) == 1 && $req[0] == 'index') {
            $this->sitemap_index_header();
            $this->sitemap_index();
            $this->sitemap_index_footer();
        }
        // Indexed all XML sitemaps, including categories question page
        // example: sitemap-index.xml
        if (count($req) == 1 && $req[0] == 'all') {
            $this->sitemap_index_header();
            $this->sitemap_all();
            $this->sitemap_index_footer();
        }
        //	Question pages
        // numbered question sitenaps
        // example: sitemap-1.xml, sitemap-12.xml
        if (count($req) == 1 && strval((int) $req[0]) == $req[0]) {
            $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'"));
            $count = qa_opt('useo_sitemap_question_count');
            $start = (int) $req[0] * $count;
            $questions = qa_db_read_all_assoc(qa_db_query_sub("SELECT postid, title, hotness FROM ^posts WHERE type='Q' ORDER BY postid LIMIT #,#", $start, $count));
            if (count($questions)) {
                $this->sitemap_header();
                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']));
                }
                $this->sitemap_footer();
            }
        }
        //User pages
        if ($req[0] == 'users' && !QA_FINAL_EXTERNAL_USERS && qa_opt('useo_sitemap_users_enable')) {
            // user's numbered sitemaps
            // example: sitemap-users-1.xml, sitemap-users-12.xml
            if (isset($req[1]) && strval((int) $req[1]) == $req[1] && (int) qa_opt('useo_sitemap_users_count') != 0) {
                $count = qa_opt('useo_sitemap_users_count');
                $start = (int) $req[1] * $count;
                $users = qa_db_read_all_assoc(qa_db_query_sub("SELECT userid, handle FROM ^users ORDER BY userid LIMIT #,#", $start, $count));
                if (count($users)) {
                    $this->sitemap_header();
                    foreach ($users as $user) {
                        $this->sitemap_output('user/' . $user['handle'], 0.25);
                    }
                    $this->sitemap_footer();
                }
            } else {
                // All users sitemap
                // example: sitemap-users.xml
                if (!isset($req[1])) {
                    $users = qa_db_read_all_assoc(qa_db_query_sub("SELECT userid, handle FROM ^users ORDER BY userid"));
                    if (count($users)) {
                        $this->sitemap_header();
                        foreach ($users as $user) {
                            $this->sitemap_output('user/' . $user['handle'], 0.25);
                        }
                        $this->sitemap_footer();
                    }
                }
            }
        }
        //	Tag pages
        if ($req[0] == 'tags' && qa_using_tags() && qa_opt('useo_sitemap_tags_enable')) {
            // link to each tag's page sitemaps
            // example: sitemap-tags-1.xml, sitemap-tags-12.xml
            if (isset($req[1]) && strval((int) $req[1]) == $req[1] && (int) qa_opt('useo_sitemap_tags_count') != 0) {
                $count = qa_opt('useo_sitemap_tags_count');
                $start = (int) $req[1] * $count;
                $tagwords = qa_db_read_all_assoc(qa_db_query_sub("SELECT wordid, word, tagcount FROM ^words WHERE tagcount>0 ORDER BY wordid LIMIT #,#", $start, $count));
                if (count($tagwords)) {
                    $this->sitemap_header();
                    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
                    }
                    $this->sitemap_footer();
                }
            } else {
                // link to all tags in sitemaps
                // example: sitemap-tags.xml
                if (!isset($req[1])) {
                    $tagwords = qa_db_read_all_assoc(qa_db_query_sub("SELECT wordid, word, tagcount FROM ^words WHERE tagcount>0 ORDER BY wordid"));
                    if (count($tagwords)) {
                        $this->sitemap_header();
                        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
                        }
                        $this->sitemap_footer();
                    }
                }
            }
        }
        //	link to all category pages
        if ($req[0] == 'category' && !isset($req[1]) && qa_using_categories() && qa_opt('useo_sitemap_categories_enable')) {
            $categories = qa_db_read_all_assoc(qa_db_query_sub("SELECT categoryid, backpath FROM ^categories WHERE qcount>0 ORDER BY categoryid"));
            if (count($categories)) {
                $this->sitemap_header();
                foreach ($categories as $category) {
                    $this->sitemap_output('questions/' . implode('/', array_reverse(explode('/', $category['backpath']))), 0.5);
                }
                $this->sitemap_footer();
            }
        }
        //	sitemap for category questions
        if ($req[0] == 'category' && isset($req[1]) && qa_using_categories() && qa_opt('useo_sitemap_categoriy_q_enable')) {
            $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'"));
            if (count($req) >= 3) {
                //because: "category-x-x-x-x-1" | 1 category + 1 sount + at least 1 category = 3
                // link to questions in a category or sub category
                // example: sitemap-category-RootCat-SubCat-2.xml
                // it's always numbered, "sitemap-category-RootCat-SubCat.xml" is NOT ALLOWED
                $slug_list = array_splice($req, 1, -1);
                $slug = implode("/", array_reverse($slug_list));
                $count = qa_opt('useo_sitemap_categoriy_q_count');
                $start = (int) $req[count($req) - 1] * $count;
                $questions = qa_db_read_all_assoc(qa_db_query_sub('SELECT postid, title, hotness FROM ^posts WHERE ^posts.type=$
						AND categoryid=(SELECT categoryid FROM ^categories WHERE ^categories.backpath=$ LIMIT 1) 
						ORDER BY ^posts.created DESC LIMIT #,#', 'Q', $slug, $start, $count));
            } else {
                // link to all questions in a category
                // example: sitemap-category-RootCat.xml
                $slug = $req[1];
                $questions = qa_db_read_all_assoc(qa_db_query_sub("SELECT postid, title, hotness FROM ^posts WHERE ^posts.type=\$\n\t\t\t\t\t\tAND categoryid=(SELECT categoryid FROM ^categories WHERE ^categories.backpath=\$ LIMIT 1) \n\t\t\t\t\t\tORDER BY ^posts.created DESC", 'Q', $slug));
            }
            if (count($questions)) {
                $this->sitemap_header();
            }
            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']));
            }
            $this->sitemap_footer();
        }
        //	Pages in category browser
        if (qa_using_categories() && qa_opt('useo_sitemap_categories_enable')) {
            $this->sitemap_output('categories', 0.5);
            $nextcategoryid = 0;
            $this->sitemap_header();
            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);
                }
            }
            $this->sitemap_footer();
        }
        //	Finish up...
        return null;
    }
Esempio n. 26
0
function qa_page_q_comment_view($question, $parent, $comment, $usershtml, $formrequested)
{
    $commentid = $comment['postid'];
    $questionid = $parent['basetype'] == 'Q' ? $parent['postid'] : $parent['parentid'];
    $answerid = $parent['basetype'] == 'Q' ? null : $parent['postid'];
    $userid = qa_get_logged_in_userid();
    $cookieid = qa_cookie_get();
    $htmloptions = qa_post_html_options($comment, null, true);
    $htmloptions['avatarsize'] = qa_opt('avatar_q_page_c_size');
    $htmloptions['q_request'] = qa_q_request($question['postid'], $question['title']);
    $c_view = qa_post_html_fields($comment, $userid, $cookieid, $usershtml, null, $htmloptions);
    if ($comment['queued']) {
        $c_view['error'] = $comment['isbyuser'] ? qa_lang_html('question/c_your_waiting_approval') : qa_lang_html('question/c_waiting_your_approval');
    }
    //	Buttons for operating on this comment
    if (!$formrequested) {
        // don't show if another form is currently being shown on page
        $prefix = 'c' . qa_html($commentid) . '_';
        $clicksuffix = ' onclick="return qa_comment_click(' . qa_js($commentid) . ', ' . qa_js($questionid) . ', ' . qa_js($parent['postid']) . ', this);"';
        $buttons = array();
        if ($comment['editbutton']) {
            $buttons['edit'] = array('tags' => 'name="' . $prefix . 'doedit"', 'label' => qa_lang_html('question/edit_button'), 'popup' => qa_lang_html('question/edit_c_popup'));
        }
        if ($comment['flagbutton']) {
            $buttons['flag'] = array('tags' => 'name="' . $prefix . 'doflag"' . $clicksuffix, 'label' => qa_lang_html($comment['flagtohide'] ? 'question/flag_hide_button' : 'question/flag_button'), 'popup' => qa_lang_html('question/flag_c_popup'));
        }
        if ($comment['unflaggable']) {
            $buttons['unflag'] = array('tags' => 'name="' . $prefix . 'dounflag"' . $clicksuffix, 'label' => qa_lang_html('question/unflag_button'), 'popup' => qa_lang_html('question/unflag_popup'));
        }
        if ($comment['clearflaggable']) {
            $buttons['clearflags'] = array('tags' => 'name="' . $prefix . 'doclearflags"' . $clicksuffix, 'label' => qa_lang_html('question/clear_flags_button'), 'popup' => qa_lang_html('question/clear_flags_popup'));
        }
        if ($comment['moderatable']) {
            $buttons['approve'] = array('tags' => 'name="' . $prefix . 'doapprove"' . $clicksuffix, 'label' => qa_lang_html('question/approve_button'), 'popup' => qa_lang_html('question/approve_c_popup'));
            $buttons['reject'] = array('tags' => 'name="' . $prefix . 'doreject"' . $clicksuffix, 'label' => qa_lang_html('question/reject_button'), 'popup' => qa_lang_html('question/reject_c_popup'));
        }
        if ($comment['hideable']) {
            $buttons['hide'] = array('tags' => 'name="' . $prefix . 'dohide"' . $clicksuffix, 'label' => qa_lang_html('question/hide_button'), 'popup' => qa_lang_html('question/hide_c_popup'));
        }
        if ($comment['reshowable']) {
            $buttons['reshow'] = array('tags' => 'name="' . $prefix . 'doreshow"' . $clicksuffix, 'label' => qa_lang_html('question/reshow_button'), 'popup' => qa_lang_html('question/reshow_c_popup'));
        }
        if ($comment['deleteable']) {
            $buttons['delete'] = array('tags' => 'name="' . $prefix . 'dodelete"' . $clicksuffix, 'label' => qa_lang_html('question/delete_button'), 'popup' => qa_lang_html('question/delete_c_popup'));
        }
        if ($comment['claimable']) {
            $buttons['claim'] = array('tags' => 'name="' . $prefix . 'doclaim"' . $clicksuffix, 'label' => qa_lang_html('question/claim_button'), 'popup' => qa_lang_html('question/claim_c_popup'));
        }
        if ($parent['commentbutton'] && qa_opt('show_c_reply_buttons') && $comment['type'] == 'C') {
            $buttons['comment'] = array('tags' => 'name="' . ($parent['basetype'] == 'Q' ? 'q' : 'a' . qa_html($parent['postid'])) . '_docomment" onclick="return qa_toggle_element(\'c' . qa_html($parent['postid']) . '\')"', 'label' => qa_lang_html('question/reply_button'), 'popup' => qa_lang_html('question/reply_c_popup'));
        }
        $c_view['form'] = array('style' => 'light', 'buttons' => $buttons);
    }
    return $c_view;
}
Esempio n. 27
0
    public function activitylist()
    {
        $offset = (int) qa_get('offset');
        $offset = isset($offset) ? $offset * 15 : 0;
        // get points for each activity
        require_once QA_INCLUDE_DIR . 'qa-db-points.php';
        require_once QA_INCLUDE_DIR . 'qa-db-users.php';
        $optionnames = qa_db_points_option_names();
        $options = qa_get_options($optionnames);
        $multi = (int) $options['points_multiple'];
        $upvote = '';
        $downvote = '';
        if (@$options['points_per_q_voted_up']) {
            $upvote = '_up';
            $downvote = '_down';
        }
        $event_point['in_q_vote_up'] = (int) $options['points_per_q_voted' . $upvote] * $multi;
        $event_point['in_q_vote_down'] = (int) $options['points_per_q_voted' . $downvote] * $multi * -1;
        $event_point['in_q_unvote_up'] = (int) $options['points_per_q_voted' . $upvote] * $multi * -1;
        $event_point['in_q_unvote_down'] = (int) $options['points_per_q_voted' . $downvote] * $multi;
        $event_point['a_vote_up'] = (int) $options['points_per_a_voted' . $upvote] * $multi;
        $event_point['in_a_vote_down'] = (int) $options['points_per_a_voted' . $downvote] * $multi * -1;
        $event_point['in_a_unvote_up'] = (int) $options['points_per_a_voted' . $upvote] * $multi * -1;
        $event_point['in_a_unvote_down'] = (int) $options['points_per_a_voted' . $downvote] * $multi;
        $event_point['in_a_select'] = (int) $options['points_a_selected'] * $multi;
        $event_point['in_a_unselect'] = (int) $options['points_a_selected'] * $multi * -1;
        $event_point['q_post'] = (int) $options['points_post_q'] * $multi;
        $event_point['a_post'] = (int) $options['points_post_a'] * $multi;
        $event_point['a_select'] = (int) $options['points_select_a'] * $multi;
        $event_point['q_vote_up'] = (int) $options['points_vote_up_q'] * $multi;
        $event_point['q_vote_down'] = (int) $options['points_vote_down_q'] * $multi;
        $event_point['a_vote_up'] = (int) $options['points_vote_up_a'] * $multi;
        $event_point['a_vote_down'] = (int) $options['points_vote_down_a'] * $multi;
        // Get 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 NOT IN ("u_wall_post", "u_message") ORDER BY datetime DESC LIMIT 15 OFFSET #', $userid, $offset));
        if (count($eventslist) > 0) {
            $event = array();
            $output = '';
            $i = 0;
            //
            $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 = '';
                $vote_status = '';
                $handle = isset($handles[$event['userid']]) ? $handles[$event['userid']] : qa_lang('main/anonymous');
                $datetime = $event['datetime'];
                $event['date'] = qa_html(qa_time_to_string(qa_opt('db_time') - $datetime));
                $event['params'] = json_decode($event['params'], true);
                $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, QW_BASE_URL);
                switch ($event['event']) {
                    case 'related':
                        // related question to an answer
                        $url = qa_path_html(qa_q_request($event['postid'], $event['params']['title']), $url_param, QW_BASE_URL, null, null);
                        echo '<div class="event-content clearfix' . $read . '' . $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/asked_question_related_to_your') . '</span>
											<strong class="where">' . qa_lang_html('dude/answer') . '</strong>
										</div>
										<div class="footer">
											<span class="event-icon icon-link"></span>
											<span class="date">' . qa_lang_sub('dude/x_ago', $event['date']) . '</span>
										</div>
									</a>
								</div>
							</div>';
                        break;
                    case 'a_post':
                        // user's question had been answered
                        $anchor = qa_anchor('A', $event['postid']);
                        $url = qa_path_html(qa_q_request($event['params']['qid'], $event['params']['qtitle']), $url_param, QW_BASE_URL, null, $anchor);
                        $title = qw_truncate($event['params']['qtitle'], 60);
                        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/answered_your') . '</span>
											<strong class="where">' . qa_lang_html('dude/question') . '</strong>
										</div>
										<div class="footer">
											<span class="event-icon icon-answer"></span>
											<span class="date">' . qa_lang_sub('dude/x_ago', $event['date']) . '</span>
										</div>
									</a>
								</div>
							</div>';
                        break;
                    case 'c_post':
                        // user's question had been commented
                        $anchor = qa_anchor('C', $event['postid']);
                        $url = qa_path_html(qa_q_request($event['params']['qid'], $event['params']['qtitle']), $url_param, QW_BASE_URL, null, $anchor);
                        if ($event['params']['parenttype'] == 'Q') {
                            $type = qa_lang_html('dude/question');
                        } elseif ($event['params']['parenttype'] == 'A') {
                            $type = qa_lang_html('dude/answer');
                        } else {
                            $type = qa_lang_html('dude/comment');
                        }
                        if (isset($event['params']['parent_uid']) && $event['params']['parent_uid'] != $userid) {
                            $what = qa_lang_html('dude/followup_comment');
                            $type = qa_lang_html('dude/comment');
                        } else {
                            $what = qa_lang_html('dude/replied_to_your');
                        }
                        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">' . $what . '</span>
											<strong class="where">' . $type . '</strong>
										</div>
										<div class="footer">
											<span class="event-icon icon-arrow-back"></span>
											<span class="date">' . qa_lang_sub('dude/x_ago', $event['date']) . '</span>
										</div>
									</a>
								</div>
							</div>';
                        break;
                    case 'q_reshow':
                        $url = qa_path_html(qa_q_request($event['params']['qid'], $event['params']['qtitle']), $url_param, QW_BASE_URL, null, null);
                        echo '<div class="event-content clearfix' . $read . '"' . $id . '>
								<div class="avatar"><a class="icon icon-eye" href="' . $url . '"></a></div>
								<div class="event-right">
									<a href="' . $url . '">
										<div class="head">
											<span>' . qa_lang_html('dude/your') . '</span>
											<strong>' . qa_lang_html('dude/question') . '</strong>
											<span class="what">' . qa_lang_html('dude/is_visible') . '</span>
										</div>
										<div class="footer">
											<span class="date">' . qa_lang_sub('dude/x_ago', $event['date']) . '</span>
										</div>
									</a>
								</div>
							</div>';
                        break;
                    case 'a_reshow':
                        // user's question had been answered
                        $anchor = qa_anchor('A', $event['postid']);
                        $url = qa_path_html(qa_q_request($event['params']['qid'], $event['params']['qtitle']), $url_param, QW_BASE_URL, null, $anchor);
                        echo '<div class="event-content clearfix' . $read . '"' . $id . '>
								<div class="avatar"><a class="icon icon-eye" href="' . $url . '"></a></div>
								<div class="event-right">
									<a href="' . $url . '">
										<div class="head">
											<span>' . qa_lang_html('dude/your') . '</span>
											<strong>' . qa_lang_html('dude/answer') . '</strong>
											<span class="what">' . qa_lang_html('dude/is_visible') . '</span>
										</div>
										<div class="footer">
											<span class="date">' . qa_lang_sub('dude/x_ago', $event['date']) . '</span>
										</div>
									</a>
								</div>
							</div>';
                        break;
                    case 'c_reshow':
                        // user's question had been answered
                        $anchor = qa_anchor('C', $event['postid']);
                        $url = qa_path_html(qa_q_request($event['params']['qid'], $event['params']['qtitle']), $url_param, QW_BASE_URL, null, $anchor);
                        echo '<div class="event-content clearfix' . $read . '"' . $id . '>
								<div class="avatar"><a class="icon icon-eye" href="' . $url . '"></a></div>
								<div class="event-right">
									<a href="' . $url . '">
										<div class="head">
											<span>' . qa_lang_html('dude/your') . '</span>
											<strong>' . qa_lang_html('dude/comment') . '</strong>
											<span class="what">' . qa_lang_html('dude/is_visible') . '</span>
										</div>
										<div class="footer">
											<span class="date">' . qa_lang_sub('dude/x_ago', $event['date']) . '</span>
										</div>
									</a>
								</div>
							</div>';
                        break;
                    case 'a_select':
                        $anchor = qa_anchor('A', $event['postid']);
                        $url = qa_path_html(qa_q_request($event['params']['qid'], $event['params']['qtitle']), $url_param, QW_BASE_URL, null, $anchor);
                        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/selected_as_best') . '</span>
										</div>
										<div class="footer">
											<span class="event-icon icon-award"></span>
											<span class="points">' . qa_lang_sub('dude/you_have_earned_x_points', $event_point['a_post']) . '</span>
											<span class="date">' . qa_lang_sub('dude/x_ago', $event['date']) . '</span>
										</div>
									</a>
								</div>
							</div>';
                        break;
                    case 'q_vote_up':
                        $url = qa_path_html(qa_q_request($event['params']['qid'], $event['params']['qtitle']), $url_param, QW_BASE_URL, null);
                        $title = qw_truncate($event['params']['qtitle'], 60);
                        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/upvoted_on_your') . '</span>
											<strong class="where">' . qa_lang_html('dude/question') . '</strong>
										</div>
										<div class="footer">
											<span class="event-icon icon-thumb-up"></span>
											<span class="points">' . qa_lang_sub('dude/you_have_earned_x_points', $event_point['a_vote_up']) . '</span>
											<span class="date">' . qa_lang_sub('dude/x_ago', $event['date']) . '</span>
										</div>
									</a>
								</div>
							</div>';
                        break;
                    case 'a_vote_up':
                        $anchor = qa_anchor('A', $event['postid']);
                        $url = qa_path_html(qa_q_request($event['params']['qid'], $event['params']['qtitle']), $url_param, QW_BASE_URL, null, $anchor);
                        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/upvoted_on_your') . '</span>
											<strong class="where">' . qa_lang_html('dude/answer') . '</strong>
										</div>
										<div class="footer">
											<span class="event-icon icon-thumb-up"></span>
											<span class="points">' . qa_lang_sub('dude/you_have_earned_x_points', $event_point['a_vote_up']) . '</span>
											<span class="date">' . qa_lang_sub('dude/x_ago', $event['date']) . '</span>
										</div>
									</a>
								</div>
							</div>';
                        break;
                    case 'q_approve':
                        $url = qa_path_html(qa_q_request($event['params']['qid'], $event['params']['qtitle']), $url_param, QW_BASE_URL, null);
                        echo '<div class="event-content clearfix' . $read . '"' . $id . '>
								<div class="avatar"><a class="icon icon-input-checked" href="' . $url . '"></a></div>
								<div class="event-right">
									<a href="' . $url . '">
										<div class="head">
											<strong class="user">' . $handle . '</strong>
											<span class="what">' . qa_lang_html('dude/approved_your') . '</span>
											<strong class="where">' . qa_lang_html('dude/question') . '</strong>
										</div>
										<div class="footer">
											<span class="date">' . qa_lang_sub('dude/x_ago', $event['date']) . '</span>
										</div>
									</a>
								</div>
							</div>';
                        break;
                    case 'a_approve':
                        $anchor = qa_anchor('A', $event['postid']);
                        $url = qa_path_html(qa_q_request($event['params']['qid'], $event['params']['qtitle']), $url_param, QW_BASE_URL, null, $anchor);
                        echo '<div class="event-content clearfix' . $read . '"' . $id . '>
								<div class="avatar"><a class="icon icon-input-checked" href="' . $url . '"></a></div>
								<div class="event-right">
									<a href="' . $url . '">
										<div class="head">
											<strong class="user">' . $handle . '</strong>
											<span class="what">' . qa_lang_html('dude/approved_your') . '</span>
											<strong class="where">' . qa_lang_html('dude/answer') . '</strong>
										</div>
										<div class="footer">
											<span class="date">' . qa_lang_sub('dude/x_ago', $event['date']) . '</span>
										</div>
									</a>
								</div>
							</div>';
                        break;
                    case 'u_favorite':
                        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="' . $user_link . '">
										<div class="head">
											<strong class="user">' . $handle . '</strong>
											<span class="what">' . qa_lang_html('dude/added_you_to') . '</span>
											<strong class="where">' . qa_lang_html('dude/favourite') . '</strong>
										</div>
										<div class="footer">
											<span class="event-icon icon-heart"></span>									
											<span class="date">' . qa_lang_sub('dude/x_ago', $event['date']) . '</span>
										</div>
									</a>
								</div>
							</div>';
                        break;
                    case 'q_favorite':
                        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="' . $user_link . '">
										<div class="head">
											<strong class="user">' . $handle . '</strong>
											<span class="what">' . qa_lang_html('dude/added_your_question_to') . '</span>
											<strong class="where">' . qa_lang_html('dude/favourite') . '</strong>
										</div>
										<div class="footer">
											<span class="event-icon icon-heart"></span>									
											<span class="date">' . qa_lang_sub('dude/x_ago', $event['date']) . '</span>
										</div>
									</a>
								</div>
							</div>';
                        break;
                    case 'q_vote_down':
                        $url = qa_path_html(qa_q_request($event['params']['qid'], $event['params']['qtitle']), $url_param, QW_BASE_URL, null);
                        echo '<div class="event-content clearfix' . $read . '"' . $id . '>
								<div class="avatar"><a class="icon icon-thumb-down" href="' . $url . '"></a></div>
								<div class="event-right">
									<a href="' . $url . '">
										<div class="head">
											<span class="what">' . qa_lang_html('dude/you_have_received_down_vote') . '</span>
											<strong class="where">' . qa_lang_html('dude/question') . '</strong>
										</div>
										<div class="footer">
											<span class="points">' . qa_lang_sub('dude/you_have_lost_x_points', $event_point['q_vote_down']) . '</span>
											<span class="date">' . qa_lang_sub('dude/x_ago', $event['date']) . '</span>
										</div>
									</a>
								</div>
							</div>';
                        break;
                    case 'c_approve':
                        $anchor = qa_anchor('C', $event['postid']);
                        $url = qa_path_html(qa_q_request($event['params']['qid'], $event['params']['qtitle']), $url_param, QW_BASE_URL, null, $anchor);
                        echo '<div class="event-content clearfix' . $read . '"' . $id . '>
								<div class="avatar"><a class="icon icon-input-checked" href="' . $url . '"></a></div>
								<div class="event-right">
									<a href="' . $url . '">
										<div class="head">
											<strong class="user">' . $handle . '</strong>
											<span class="what">' . qa_lang_html('dude/approved_your') . '</span>
											<strong class="where">' . qa_lang_html('dude/comment') . '</strong>
										</div>
										<div class="footer">									
											<span class="date">' . qa_lang_sub('dude/x_ago', $event['date']) . '</span>
										</div>
									</a>
								</div>
							</div>';
                        break;
                    case 'q_reject':
                        $url = qa_path_html(qa_q_request($event['params']['qid'], $event['params']['qtitle']), $url_param, QW_BASE_URL, null);
                        echo '<div class="event-content clearfix' . $read . '"' . $id . '>
								<div class="avatar"><a class="icon icon-times" href="' . $url . '"></a></div>
								<div class="event-right">
									<a href="' . $url . '">
										<div class="head">
											<strong class="user">' . $handle . '</strong>
											<span class="what">' . qa_lang_html('dude/your_question_is_rejected') . '</span>
										</div>
										<div class="footer">
											<span class="date">' . qa_lang_sub('dude/x_ago', $event['date']) . '</span>
										</div>
									</a>
								</div>
							</div>';
                        break;
                    case 'a_reject':
                        $anchor = qa_anchor('A', $event['postid']);
                        $url = qa_path_html(qa_q_request($event['params']['qid'], $event['params']['qtitle']), $url_param, QW_BASE_URL, null, $anchor);
                        echo '<div class="event-content clearfix' . $read . '"' . $id . '>
								<div class="avatar"><a class="icon icon-times" href="' . $url . '"></a></div>
								<div class="event-right">
									<a href="' . $url . '">
										<div class="head">
											<strong class="user">' . $handle . '</strong>
											<span class="what">' . qa_lang_html('dude/your_answer_is_rejected') . '</span>
										</div>
										<div class="footer">									
											<span class="date">' . qa_lang_sub('dude/x_ago', $event['date']) . '</span>
										</div>
									</a>
								</div>
							</div>';
                        break;
                    case 'c_reject':
                        $anchor = qa_anchor('C', $event['postid']);
                        $url = qa_path_html(qa_q_request($event['params']['qid'], $event['params']['qtitle']), $url_param, QW_BASE_URL, null, $anchor);
                        echo '<div class="event-content clearfix' . $read . '"' . $id . '>
								<div class="avatar"><a class="icon icon-times" href="' . $url . '"></a></div>
								<div class="event-right">
									<a href="' . $url . '">
										<div class="head">
											<strong class="user">' . $handle . '</strong>
											<span class="what">' . qa_lang_html('dude/your_comment_is_rejected') . '</span>
										</div>
										<div class="footer">									
											<span class="date">' . qa_lang_sub('dude/x_ago', $event['date']) . '</span>
										</div>
									</a>
								</div>
							</div>';
                        break;
                    case 'u_level':
                        $url = qa_path_absolute('user/' . $event['params']['handle']);
                        $old_level = $event['params']['oldlevel'];
                        $new_level = $event['params']['level'];
                        if ($new_level < $old_level) {
                            break;
                        }
                        $approved_only = "";
                        if ($new_level == QA_USER_LEVEL_APPROVED && $old_level < QA_USER_LEVEL_APPROVED) {
                            $approved_only = true;
                        } else {
                            $approved_only = false;
                        }
                        if ($approved_only === false) {
                            $new_designation = qw_get_user_desg($new_level);
                        }
                        $content = strtr(qa_lang($approved_only ? 'notification/u_level_approved_notf' : 'notification/u_level_improved_notf'), array('^new_designation' => @$new_designation));
                        echo '<div class="event-content clearfix' . $read . '"' . $id . '>
								<div class="avatar"><a class="icon icon-user" href="' . $url . '"></a></div>
								<div class="event-right">
									<a href="' . $url . '">
										<div class="head">
											<strong class="user">' . $handle . '</strong>
											<span class="what">' . $content . '</span>
										</div>
										<div class="footer">
											<span class="points">' . qa_lang_sub('dude/you_have_earned_x_points', $event_point['a_vote_up']) . '</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_activity') . '</div>';
        }
        die;
    }
Esempio n. 28
0
function qa_post_html_fields($post, $userid, $cookieid, $usershtml, $dummy, $options = array())
{
    if (isset($options['blockwordspreg'])) {
        require_once QA_INCLUDE_DIR . 'qa-util-string.php';
    }
    $fields = array();
    $fields['raw'] = $post;
    //	Useful stuff used throughout function
    $postid = $post['postid'];
    $isquestion = $post['basetype'] == 'Q';
    $isanswer = $post['basetype'] == 'A';
    $isbyuser = qa_post_is_by_user($post, $userid, $cookieid);
    $anchor = urlencode(qa_anchor($post['basetype'], $postid));
    $microformats = @$options['microformats'];
    $isselected = @$options['isselected'];
    //	High level information
    $fields['hidden'] = $post['hidden'];
    $fields['tags'] = 'ID="' . $anchor . '"';
    if ($microformats) {
        $fields['classes'] = 'hentry ' . ($isquestion ? 'question' : ($isanswer ? $isselected ? 'answer answer-selected' : 'answer' : 'comment'));
    }
    //	Question-specific stuff (title, URL, tags, answer count, category)
    if ($isquestion) {
        if (isset($post['title'])) {
            if (isset($options['blockwordspreg'])) {
                $post['title'] = qa_block_words_replace($post['title'], $options['blockwordspreg']);
            }
            $fields['title'] = qa_html($post['title']);
            if ($microformats) {
                $fields['title'] = '<SPAN CLASS="entry-title">' . $fields['title'] . '</SPAN>';
            }
            $fields['url'] = qa_path_html(qa_q_request($postid, $post['title']));
            /*if (isset($post['score'])) // useful for setting match thresholds
            		$fields['title'].=' <SMALL>('.$post['score'].')</SMALL>';*/
        }
        if (@$options['tagsview'] && isset($post['tags'])) {
            $fields['q_tags'] = array();
            $tags = qa_tagstring_to_tags($post['tags']);
            foreach ($tags as $tag) {
                if (isset($options['blockwordspreg']) && count(qa_block_words_match_all($tag, $options['blockwordspreg']))) {
                    // skip censored tags
                    continue;
                }
                $fields['q_tags'][] = qa_tag_html($tag, $microformats);
            }
        }
        if (@$options['answersview'] && isset($post['acount'])) {
            $fields['answers_raw'] = $post['acount'];
            $fields['answers'] = $post['acount'] == 1 ? qa_lang_html_sub_split('main/1_answer', '1', '1') : qa_lang_html_sub_split('main/x_answers', number_format($post['acount']));
            $fields['answer_selected'] = isset($post['selchildid']);
        }
        if (@$options['viewsview'] && isset($post['views'])) {
            $fields['views_raw'] = $post['views'];
            $fields['views'] = $post['views'] == 1 ? qa_lang_html_sub_split('main/1_view', '1', '1') : qa_lang_html_sub_split('main/x_views', number_format($post['views']));
        }
        if (isset($post['categoryname']) && isset($post['categorybackpath'])) {
            $fields['where'] = qa_lang_html_sub_split('main/in_category_x', '<A HREF="' . qa_path_html(@$options['categorypathprefix'] . implode('/', array_reverse(explode('/', $post['categorybackpath'])))) . '" CLASS="qa-category-link">' . qa_html($post['categoryname']) . '</A>');
        }
    }
    //	Answer-specific stuff (selection)
    if ($isanswer) {
        $fields['selected'] = $isselected;
        if ($isselected) {
            $fields['select_text'] = qa_lang_html('question/select_text');
        }
    }
    //	Post content
    if (!empty($post['content'])) {
        $viewer = qa_load_viewer($post['content'], $post['format']);
        $fields['content'] = $viewer->get_html($post['content'], $post['format'], array('blockwordspreg' => @$options['blockwordspreg'], 'showurllinks' => @$options['showurllinks'], 'linksnewwindow' => @$options['linksnewwindow']));
        if ($microformats) {
            $fields['content'] = '<SPAN CLASS="entry-content">' . $fields['content'] . '</SPAN>';
        }
        $fields['content'] = '<A NAME="' . qa_html($postid) . '"></A>' . $fields['content'];
        // this is for backwards compatibility with any existing links using the old style of anchor
        // that contained the post id only (changed to be valid under W3C specifications)
    }
    //	Voting stuff
    if (@$options['voteview']) {
        $voteview = $options['voteview'];
        //	Calculate raw values and pass through
        $upvotes = (int) @$post['upvotes'];
        $downvotes = (int) @$post['downvotes'];
        $netvotes = (int) ($upvotes - $downvotes);
        $fields['upvotes_raw'] = $upvotes;
        $fields['downvotes_raw'] = $downvotes;
        $fields['netvotes_raw'] = $netvotes;
        //	Create HTML versions...
        $upvoteshtml = qa_html($upvotes);
        $downvoteshtml = qa_html($downvotes);
        if ($netvotes >= 1) {
            $netvoteshtml = '+' . qa_html($netvotes);
        } elseif ($netvotes <= -1) {
            $netvoteshtml = '&ndash;' . qa_html(-$netvotes);
        } else {
            $netvoteshtml = '0';
        }
        //	...with microformats if appropriate
        if ($microformats) {
            $netvoteshtml .= '<SPAN CLASS="votes-up"><SPAN CLASS="value-title" TITLE="' . $upvoteshtml . '"></SPAN></SPAN>' . '<SPAN CLASS="votes-down"><SPAN CLASS="value-title" TITLE="' . $downvoteshtml . '"></SPAN></SPAN>';
            $upvoteshtml = '<SPAN CLASS="votes-up">' . $upvoteshtml . '</SPAN>';
            $downvoteshtml = '<SPAN CLASS="votes-down">' . $downvoteshtml . '</SPAN>';
        }
        //	Pass information on vote viewing
        //	$voteview will be one of: updown, net, updown-disabled-level, net-disabled-level, updown-disabled-page, net-disabled-page
        $fields['vote_view'] = substr($voteview, 0, 6) == 'updown' ? 'updown' : 'net';
        $fields['upvotes_view'] = $upvotes == 1 ? qa_lang_html_sub_split('main/1_liked', $upvoteshtml, '1') : qa_lang_html_sub_split('main/x_liked', $upvoteshtml);
        $fields['downvotes_view'] = $downvotes == 1 ? qa_lang_html_sub_split('main/1_disliked', $downvoteshtml, '1') : qa_lang_html_sub_split('main/x_disliked', $downvoteshtml);
        $fields['netvotes_view'] = abs($netvotes) == 1 ? qa_lang_html_sub_split('main/1_vote', $netvoteshtml, '1') : qa_lang_html_sub_split('main/x_votes', $netvoteshtml);
        //	Voting buttons
        $fields['vote_tags'] = 'ID="voting_' . qa_html($postid) . '"';
        $onclick = 'onClick="return qa_vote_click(this);"';
        if ($fields['hidden']) {
            $fields['vote_state'] = 'disabled';
            $fields['vote_up_tags'] = 'TITLE="' . qa_lang_html($isanswer ? 'main/vote_disabled_hidden_a' : 'main/vote_disabled_hidden_q') . '"';
            $fields['vote_down_tags'] = $fields['vote_up_tags'];
        } elseif ($isbyuser) {
            $fields['vote_state'] = 'disabled';
            $fields['vote_up_tags'] = 'TITLE="' . qa_lang_html($isanswer ? 'main/vote_disabled_my_a' : 'main/vote_disabled_my_q') . '"';
            $fields['vote_down_tags'] = $fields['vote_up_tags'];
        } elseif (strpos($voteview, '-disabled-')) {
            $fields['vote_state'] = @$post['uservote'] > 0 ? 'voted_up_disabled' : (@$post['uservote'] < 0 ? 'voted_down_disabled' : 'disabled');
            if (strpos($voteview, '-disabled-page')) {
                $fields['vote_up_tags'] = 'TITLE="' . qa_lang_html('main/vote_disabled_q_page_only') . '"';
            } else {
                $fields['vote_up_tags'] = 'TITLE="' . qa_lang_html('main/vote_disabled_level') . '"';
            }
            $fields['vote_down_tags'] = $fields['vote_up_tags'];
        } elseif (@$post['uservote'] > 0) {
            $fields['vote_state'] = 'voted_up';
            $fields['vote_up_tags'] = 'TITLE="' . qa_lang_html('main/voted_up_popup') . '" NAME="' . qa_html('vote_' . $postid . '_0_' . $anchor) . '"' . $onclick;
            $fields['vote_down_tags'] = ' ';
        } elseif (@$post['uservote'] < 0) {
            $fields['vote_state'] = 'voted_down';
            $fields['vote_up_tags'] = ' ';
            $fields['vote_down_tags'] = 'TITLE="' . qa_lang_html('main/voted_down_popup') . '" NAME="' . qa_html('vote_' . $postid . '_0_' . $anchor) . '" ' . $onclick;
        } else {
            $fields['vote_state'] = 'enabled';
            $fields['vote_up_tags'] = 'TITLE="' . qa_lang_html('main/vote_up_popup') . '" NAME="' . qa_html('vote_' . $postid . '_1_' . $anchor) . '" ' . $onclick;
            $fields['vote_down_tags'] = 'TITLE="' . qa_lang_html('main/vote_down_popup') . '" NAME="' . qa_html('vote_' . $postid . '_-1_' . $anchor) . '" ' . $onclick;
        }
    }
    //	Flag count
    if (@$options['flagsview'] && @$post['flagcount']) {
        $fields['flags'] = $post['flagcount'] == 1 ? qa_lang_html_sub_split('main/1_flag', '1', '1') : qa_lang_html_sub_split('main/x_flags', $post['flagcount']);
    }
    //	Created when and by whom
    $fields['meta_order'] = qa_lang_html('main/meta_order');
    // sets ordering of meta elements which can be language-specific
    $fields['what'] = qa_lang_html($isquestion ? 'main/asked' : ($isanswer ? 'main/answered' : 'main/commented'));
    if (@$options['whatlink'] && !$isquestion) {
        $fields['what_url'] = '#' . qa_html(urlencode($anchor));
    }
    if (isset($post['created']) && @$options['whenview']) {
        $whenhtml = qa_html(qa_time_to_string(qa_opt('db_time') - $post['created']));
        if ($microformats) {
            $whenhtml = '<SPAN CLASS="published"><SPAN CLASS="value-title" TITLE="' . gmdate('Y-m-d\\TH:i:sO', $post['created']) . '"></SPAN>' . $whenhtml . '</SPAN>';
        }
        $fields['when'] = qa_lang_html_sub_split('main/x_ago', $whenhtml);
    }
    if (@$options['whoview']) {
        $fields['who'] = qa_who_to_html($isbyuser, @$post['userid'], $usershtml, @$options['ipview'] ? @$post['createip'] : null, $microformats);
        if (isset($post['points'])) {
            if (@$options['pointsview']) {
                $fields['who']['points'] = $post['points'] == 1 ? qa_lang_html_sub_split('main/1_point', '1', '1') : qa_lang_html_sub_split('main/x_points', qa_html(number_format($post['points'])));
            }
            if (isset($options['pointstitle'])) {
                $fields['who']['title'] = qa_get_points_title_html($post['points'], $options['pointstitle']);
            }
        }
        if (isset($post['level'])) {
            $fields['who']['level'] = qa_html(qa_user_level_string($post['level']));
        }
    }
    if (!QA_FINAL_EXTERNAL_USERS && @$options['avatarsize'] > 0) {
        $fields['avatar'] = qa_get_user_avatar_html($post['flags'], $post['email'], $post['handle'], $post['avatarblobid'], $post['avatarwidth'], $post['avatarheight'], $options['avatarsize']);
    }
    //	Updated when and by whom
    if (isset($post['updated']) && (!isset($post['created']) || $post['hidden'] || abs($post['updated'] - $post['created']) > 300 || $post['lastuserid'] != $post['userid'])) {
        if (@$options['whenview']) {
            $whenhtml = qa_html(qa_time_to_string(qa_opt('db_time') - $post['updated']));
            if ($microformats) {
                $whenhtml = '<SPAN CLASS="updated"><SPAN CLASS="value-title" TITLE="' . gmdate('Y-m-d\\TH:i:sO', $post['updated']) . '"></SPAN>' . $whenhtml . '</SPAN>';
            }
            $fields['when_2'] = qa_lang_html_sub_split($fields['hidden'] ? 'question/hidden_x_ago' : 'question/edited_x_ago', $whenhtml);
        } else {
            $fields['when_2']['prefix'] = qa_lang_html($fields['hidden'] ? 'question/hidden' : 'main/edited');
        }
        if ($fields['hidden'] && $post['flagcount'] && !isset($post['lastuserid'])) {
        } else {
            $fields['who_2'] = qa_who_to_html(isset($userid) && $post['lastuserid'] == $userid, $post['lastuserid'], $usershtml, @$options['ipview'] ? $post['lastip'] : null, false);
        }
    }
    //	That's it!
    return $fields;
}
Esempio n. 29
0
            qa_update_post_text($in, $oldin);
        }
        if (qa_using_categories() && count($categories) && !qa_opt('allow_no_category') && !isset($in['categoryid'])) {
            $errors['categoryid'] = qa_lang_html('question/category_required');
        } elseif (qa_user_permit_error('permit_post_q', null, $userlevel)) {
            $errors['categoryid'] = qa_lang_html('question/category_ask_not_allowed');
        }
        if ($captchareason) {
            require_once 'qa-app-captcha.php';
            qa_captcha_validate_post($errors);
        }
        if (empty($errors)) {
            $cookieid = isset($userid) ? qa_cookie_get() : qa_cookie_get_create();
            // create a new cookie if necessary
            $questionid = qa_question_create($followanswer, $userid, qa_get_logged_in_handle(), $cookieid, $in['title'], $in['content'], $in['format'], $in['text'], qa_tags_to_tagstring($in['tags']), $in['notify'], $in['email'], $in['categoryid'], $in['extra'], $in['queued'], $in['name']);
            qa_redirect(qa_q_request($questionid, $in['title']));
            // our work is done here
        }
    }
}
//	Prepare content for theme
$qa_content = qa_content_prepare(false, array_keys(qa_category_path($categories, @$in['categoryid'])));
$qa_content['title'] = qa_lang_html(isset($followanswer) ? 'question/ask_follow_title' : 'question/ask_title');
$qa_content['error'] = @$errors['page'];
$editorname = isset($in['editor']) ? $in['editor'] : qa_opt('editor_for_qs');
$editor = qa_load_editor(@$in['content'], @$in['format'], $editorname);
$field = qa_editor_load_field($editor, $qa_content, @$in['content'], @$in['format'], 'content', 12, false);
$field['label'] = qa_lang_html('question/q_content_label');
$field['error'] = qa_html(@$errors['content']);
$custom = qa_opt('show_custom_ask') ? trim(qa_opt('custom_ask')) : '';
$qa_content['form'] = array('tags' => 'name="ask" method="post" action="' . qa_self_html() . '"', 'style' => 'tall', 'fields' => array('custom' => array('type' => 'custom', 'note' => $custom), 'title' => array('label' => qa_lang_html('question/q_title_label'), 'tags' => 'name="title" id="title" autocomplete="off"', 'value' => qa_html(@$in['title']), 'error' => qa_html(@$errors['title'])), 'similar' => array('type' => 'custom', 'html' => '<span id="similar"></span>'), 'content' => $field), 'buttons' => array('ask' => array('tags' => 'onclick="qa_show_waiting_after(this, false); ' . (method_exists($editor, 'update_script') ? $editor->update_script('content') : '') . '"', 'label' => qa_lang_html('question/ask_button'))), 'hidden' => array('editor' => qa_html($editorname), 'code' => qa_get_form_security_code('ask'), 'doask' => '1'));
        }
        if ($question['claimable']) {
            $qa_content['q_view']['form']['buttons']['claim'] = array('tags' => 'NAME="doclaimq"', 'label' => qa_lang_html('question/claim_button'));
        }
        if ($question['answerbutton'] && $formtype != 'a_add') {
            // don't show if shown by default
            $qa_content['q_view']['form']['buttons']['answer'] = array('tags' => 'NAME="doanswerq"', 'label' => qa_lang_html('question/answer_button'), 'popup' => qa_lang_html('question/answer_q_popup'));
        }
        if ($question['commentbutton']) {
            $qa_content['q_view']['form']['buttons']['comment'] = array('tags' => 'NAME="docommentq"', 'label' => qa_lang_html('question/comment_button'), 'popup' => qa_lang_html('question/comment_q_popup'));
        }
    }
    //	Information about the question of the answer that this question follows on from (or a question directly)
    if (isset($parentquestion)) {
        $parentquestion['title'] = qa_block_words_replace($parentquestion['title'], qa_get_block_words_preg());
        $qa_content['q_view']['follows'] = array('label' => qa_lang_html($question['parentid'] == $parentquestion['postid'] ? 'question/follows_q' : 'question/follows_a'), 'title' => qa_html($parentquestion['title']), 'url' => qa_path_html(qa_q_request($parentquestion['postid'], $parentquestion['title']), null, null, null, $question['parentid'] == $parentquestion['postid'] ? null : qa_anchor('A', $question['parentid'])));
    }
}
//	Prepare content for an answer being edited (if any)
if ($formtype == 'a_edit') {
    $qa_content['q_view']['a_form'] = qa_page_q_edit_a_form($formpostid);
}
//	Prepare content for comments on the question, plus add or edit comment forms
$qa_content['q_view']['c_list'] = qa_page_q_comment_follow_list($question);
// ...for viewing
if ($formtype == 'c_add' && $formpostid == $questionid) {
    // ...to be added
    $qa_content['q_view']['c_form'] = qa_page_q_add_c_form(null);
} elseif ($formtype == 'c_edit' && @$commentsfollows[$formpostid]['parentid'] == $questionid) {
    // ...being edited
    $qa_content['q_view']['c_form'] = qa_page_q_edit_c_form($formpostid, null);