public function test__qa_block_words_replace() { $wordpreg = qa_block_words_to_preg($this->blockWordString); $test = qa_block_words_replace('tired of my ocean boat style', $wordpreg); $expected = '***** of my ***** **** *****'; $this->assertEquals($expected, $test); }
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)); } }
function get_html($content, $format, $options) { if (isset($options['blockwordspreg'])) { require_once QA_INCLUDE_DIR . 'qa-util-string.php'; $content = qa_block_words_replace($content, $options['blockwordspreg']); } require_once $this->plugindir . 'inc.markdown.php'; $html = Markdown($content); return qa_sanitize_html($html, @$options['linksnewwindow']); }
function qa_q_request($questionid, $title) { // URL Clean if (qa_opt('useo_url_cleanup')) { //clean url's title $words = qa_opt('useo_url_words_list'); $raw_title = $title; // ~~ str_replace method //$word_list = explode(',', $words); //$title = str_replace($word_list, '', $raw_title); // ~~preg_replace method with Q2A functions require_once QA_INCLUDE_DIR . 'qa-util-string.php'; $word_list = qa_block_words_to_preg($words); $title = trim(qa_block_words_replace($title, $word_list, '')); if (strlen($title) == 0 && qa_opt('useo_url_dont_make_empty')) { $title = $raw_title; } } $url = qa_q_request_base($questionid, $title); // capitalize letters if (qa_opt('useo_url_q_uppercase')) { $type = qa_opt('useo_url_q_uppercase_type'); if ($type == 1) { // first word's first letter $parts = explode('/', $url); $parts[1] = ucfirst($parts[1]); $url = implode('/', $parts); } else { if ($type == 2) { // all word's first letter $url = str_replace(' ', '?', ucwords(str_replace('?', ' ', str_replace(' ', '/', ucwords(str_replace('/', ' ', str_replace(' ', '-', ucwords(str_replace('-', ' ', strtolower($url)))))))))); } else { // whole words $url = strtoupper($url); } } } return $url; }
case 'C-' . QA_UPDATE_VISIBLE: $langstring = $question['ohidden'] ? 'misc/feed_hidden_prefix' : 'misc/feed_c_reshown_prefix'; break; case 'C-' . QA_UPDATE_CONTENT: $langstring = 'misc/feed_c_edited_prefix'; break; case 'Q-' . QA_UPDATE_CONTENT: default: $langstring = 'misc/feed_edited_prefix'; break; } $titleprefix = isset($langstring) ? qa_lang($langstring) : ''; $urlxml = qa_xml(qa_q_path($question['postid'], $question['title'], true, @$question['obasetype'], @$question['opostid'])); } if (isset($blockwordspreg)) { $question['title'] = qa_block_words_replace($question['title'], $blockwordspreg); } // Build the inner XML structure for each item $lines[] = '<item>'; $lines[] = '<title>' . qa_xml($titleprefix . $question['title']) . '</title>'; $lines[] = '<link>' . $urlxml . '</link>'; if (isset($htmlcontent)) { $lines[] = '<description>' . qa_xml($htmlcontent) . '</description>'; } if (isset($question['categoryname'])) { $lines[] = '<category>' . qa_xml($question['categoryname']) . '</category>'; } $lines[] = '<guid isPermaLink="true">' . $urlxml . '</guid>'; if (isset($time)) { $lines[] = '<pubDate>' . qa_xml(gmdate('r', $time)) . '</pubDate>'; }
function qa_q_request($questionid, $title) { if (qa_to_override(__FUNCTION__)) { $args = func_get_args(); return qa_call_override(__FUNCTION__, $args); } require_once QA_INCLUDE_DIR . 'qa-app-options.php'; require_once QA_INCLUDE_DIR . 'qa-util-string.php'; $title = qa_block_words_replace($title, qa_get_block_words_preg()); $words = qa_string_to_words($title, true, false, false); $wordlength = array(); foreach ($words as $index => $word) { $wordlength[$index] = qa_strlen($word); } $remaining = qa_opt('q_urls_title_length'); if (array_sum($wordlength) > $remaining) { arsort($wordlength, SORT_NUMERIC); // sort with longest words first foreach ($wordlength as $index => $length) { if ($remaining > 0) { $remaining -= $length; } else { unset($words[$index]); } } } $title = implode('-', $words); if (qa_opt('q_urls_remove_accents')) { $title = qa_string_remove_accents($title); } return (int) $questionid . '/' . $title; }
function qa_page_q_question_view($question, $parentquestion, $closepost, $usershtml, $formrequested) { $questionid = $question['postid']; $userid = qa_get_logged_in_userid(); $cookieid = qa_cookie_get(); $htmloptions = qa_post_html_defaults('Q', true); $htmloptions['answersview'] = false; // answer count is displayed separately so don't show it here $htmloptions['avatarsize'] = qa_opt('avatar_q_page_q_size'); $q_view = qa_post_html_fields($question, $userid, $cookieid, $usershtml, null, $htmloptions); $q_view['main_form_tags'] = 'METHOD="POST" ACTION="' . qa_self_html() . '"'; // Buttons for operating on the question if (!$formrequested) { // don't show if another form is currently being shown on page $clicksuffix = ' onClick="qa_show_waiting_after(this, false);"'; // add to operations that write to database $buttons = array(); if ($question['editbutton']) { $buttons['edit'] = array('tags' => 'NAME="q_doedit"', 'label' => qa_lang_html('question/edit_button'), 'popup' => qa_lang_html('question/edit_q_popup')); } $hascategories = qa_using_categories(); if ($question['retagcatbutton']) { $buttons['retagcat'] = array('tags' => 'NAME="q_doedit"', 'label' => qa_lang_html($hascategories ? 'question/recat_button' : 'question/retag_button'), 'popup' => qa_lang_html($hascategories ? qa_using_tags() ? 'question/retag_cat_popup' : 'question/recat_popup' : 'question/retag_popup')); } if ($question['flagbutton']) { $buttons['flag'] = array('tags' => 'NAME="q_doflag"' . $clicksuffix, 'label' => qa_lang_html($question['flagtohide'] ? 'question/flag_hide_button' : 'question/flag_button'), 'popup' => qa_lang_html('question/flag_q_popup')); } if ($question['unflaggable']) { $buttons['unflag'] = array('tags' => 'NAME="q_dounflag"' . $clicksuffix, 'label' => qa_lang_html('question/unflag_button'), 'popup' => qa_lang_html('question/unflag_popup')); } if ($question['clearflaggable']) { $buttons['clearflags'] = array('tags' => 'NAME="q_doclearflags"' . $clicksuffix, 'label' => qa_lang_html('question/clear_flags_button'), 'popup' => qa_lang_html('question/clear_flags_popup')); } if ($question['closeable']) { $buttons['close'] = array('tags' => 'NAME="q_doclose"', 'label' => qa_lang_html('question/close_button'), 'popup' => qa_lang_html('question/close_q_popup')); } if ($question['reopenable']) { $buttons['reopen'] = array('tags' => 'NAME="q_doreopen"' . $clicksuffix, 'label' => qa_lang_html('question/reopen_button')); } if ($question['moderatable']) { $buttons['approve'] = array('tags' => 'NAME="q_doapprove"' . $clicksuffix, 'label' => qa_lang_html('question/approve_button')); $buttons['reject'] = array('tags' => 'NAME="q_doreject"' . $clicksuffix, 'label' => qa_lang_html('question/reject_button')); } if ($question['hideable']) { $buttons['hide'] = array('tags' => 'NAME="q_dohide"' . $clicksuffix, 'label' => qa_lang_html('question/hide_button'), 'popup' => qa_lang_html('question/hide_q_popup')); } if ($question['reshowable']) { $buttons['reshow'] = array('tags' => 'NAME="q_doreshow"' . $clicksuffix, 'label' => qa_lang_html('question/reshow_button')); } if ($question['deleteable']) { $buttons['delete'] = array('tags' => 'NAME="q_dodelete"' . $clicksuffix, 'label' => qa_lang_html('question/delete_button'), 'popup' => qa_lang_html('question/delete_q_popup')); } if ($question['claimable']) { $buttons['claim'] = array('tags' => 'NAME="q_doclaim"' . $clicksuffix, 'label' => qa_lang_html('question/claim_button')); } if ($question['answerbutton']) { // don't show if shown by default $buttons['answer'] = array('tags' => 'NAME="q_doanswer" ID="q_doanswer" onClick="return qa_toggle_element(\'anew\')"', 'label' => qa_lang_html('question/answer_button'), 'popup' => qa_lang_html('question/answer_q_popup')); } if ($question['commentbutton']) { $buttons['comment'] = array('tags' => 'NAME="q_docomment" onClick="return qa_toggle_element(\'c' . $questionid . '\')"', 'label' => qa_lang_html('question/comment_button'), 'popup' => qa_lang_html('question/comment_q_popup')); } $q_view['form'] = array('style' => 'light', 'buttons' => $buttons, 'hidden' => array('qa_click' => '')); } // Information about the question of the answer that this question follows on from (or a question directly) if (isset($parentquestion)) { $q_view['follows'] = array('label' => qa_lang_html($question['parentid'] == $parentquestion['postid'] ? 'question/follows_q' : 'question/follows_a'), 'title' => qa_html(qa_block_words_replace($parentquestion['title'], qa_get_block_words_preg())), 'url' => qa_q_path_html($parentquestion['postid'], $parentquestion['title'], false, $question['parentid'] == $parentquestion['postid'] ? 'Q' : 'A', $question['parentid'])); } // Information about the question that this question is a duplicate of (if appropriate) if (isset($closepost)) { if ($closepost['basetype'] == 'Q') { $q_view['closed'] = array('label' => qa_lang_html('question/closed_as_duplicate'), 'content' => qa_html(qa_block_words_replace($closepost['title'], qa_get_block_words_preg())), 'url' => qa_q_path_html($closepost['postid'], $closepost['title'])); } elseif ($closepost['type'] == 'NOTE') { $viewer = qa_load_viewer($closepost['content'], $closepost['format']); $q_view['closed'] = array('label' => qa_lang_html('question/closed_with_note'), 'content' => $viewer->get_html($closepost['content'], $closepost['format'], array('blockwordspreg' => qa_get_block_words_preg()))); } } // Extra value display if (strlen(@$question['extra']) && qa_opt('extra_field_active') && qa_opt('extra_field_display')) { $q_view['extra'] = array('label' => qa_html(qa_opt('extra_field_label')), 'content' => qa_html(qa_block_words_replace($question['extra'], qa_get_block_words_preg()))); } return $q_view; }
function qa_post_html_fields($post, $userid, $cookieid, $usershtml, $dummy, $options = array()) { if (qa_to_override(__FUNCTION__)) { $args = func_get_args(); return qa_call_override(__FUNCTION__, $args); } require_once QA_INCLUDE_DIR . 'app/updates.php'; if (isset($options['blockwordspreg'])) { require_once QA_INCLUDE_DIR . 'util/string.php'; } $fields = array('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)); $elementid = isset($options['elementid']) ? $options['elementid'] : $anchor; $microformats = @$options['microformats']; $isselected = @$options['isselected']; $favoritedview = @$options['favoritedview']; $favoritemap = $favoritedview ? qa_get_favorite_non_qs_map() : array(); // High level information $fields['hidden'] = @$post['hidden']; $fields['tags'] = 'id="' . qa_html($elementid) . '"'; $fields['classes'] = $isquestion && $favoritedview && @$post['userfavoriteq'] ? 'qa-q-favorited' : ''; if ($isquestion && isset($post['closedbyid'])) { $fields['classes'] = ltrim($fields['classes'] . ' qa-q-closed'); } 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'])) { $fields['url'] = qa_q_path_html($postid, $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>'; } /*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, @$favoritemap['tag'][qa_strtolower($tag)]); } } 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 (@$options['categoryview'] && isset($post['categoryname']) && isset($post['categorybackpath'])) { $favoriteclass = ''; if (count(@$favoritemap['category'])) { if (@$favoritemap['category'][$post['categorybackpath']]) { $favoriteclass = ' qa-cat-favorited'; } else { foreach ($favoritemap['category'] as $categorybackpath => $dummy) { if (substr('/' . $post['categorybackpath'], -strlen($categorybackpath)) == $categorybackpath) { $favoriteclass = ' qa-cat-parent-favorited'; } } } } $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' . $favoriteclass . '">' . 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 (@$options['contentview'] && isset($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'] = '<div class="entry-content">' . $fields['content'] . '</div>'; } $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 if (@$options['ovoteview'] && isset($post['opostid'])) { $upvotes = (int) @$post['oupvotes']; $downvotes = (int) @$post['odownvotes']; $fields['vote_opostid'] = true; // for voters/flaggers layer } else { $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 = '–' . 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, updown-disabled-page, updown-disabled-level, updown-uponly-level, updown-disabled-approve, updown-uponly-approve // net, net-disabled-page, net-disabled-level, net-uponly-level, net-disabled-approve, net-uponly-approve $fields['vote_view'] = substr($voteview, 0, 6) == 'updown' ? 'updown' : 'net'; $fields['vote_on_page'] = strpos($voteview, '-disabled-page') ? 'disabled' : 'enabled'; $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') . '"'; } elseif (strpos($voteview, '-disabled-approve')) { $fields['vote_up_tags'] = 'title="' . qa_lang_html('main/vote_disabled_approve') . '"'; } 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_' . $elementid) . '" ' . $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_' . $elementid) . '" ' . $onclick; } else { $fields['vote_up_tags'] = 'title="' . qa_lang_html('main/vote_up_popup') . '" name="' . qa_html('vote_' . $postid . '_1_' . $elementid) . '" ' . $onclick; if (strpos($voteview, '-uponly-level')) { $fields['vote_state'] = 'up_only'; $fields['vote_down_tags'] = 'title="' . qa_lang_html('main/vote_disabled_down') . '"'; } elseif (strpos($voteview, '-uponly-approve')) { $fields['vote_state'] = 'up_only'; $fields['vote_down_tags'] = 'title="' . qa_lang_html('main/vote_disabled_down_approve') . '"'; } else { $fields['vote_state'] = 'enabled'; $fields['vote_down_tags'] = 'title="' . qa_lang_html('main/vote_down_popup') . '" name="' . qa_html('vote_' . $postid . '_-1_' . $elementid) . '" ' . $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 if (@$options['whatview']) { $fields['what'] = qa_lang_html($isquestion ? 'main/asked' : ($isanswer ? 'main/answered' : 'main/commented')); if (@$options['whatlink'] && strlen(@$options['q_request'])) { $fields['what_url'] = $post['basetype'] == 'Q' ? qa_path_html($options['q_request']) : qa_path_html($options['q_request'], array('show' => $postid), null, null, qa_anchor($post['basetype'], $postid)); } } if (isset($post['created']) && @$options['whenview']) { $fields['when'] = qa_when_to_html($post['created'], @$options['fulldatedays']); if ($microformats) { $fields['when']['data'] = '<span class="published"><span class="value-title" title="' . gmdate('Y-m-d\\TH:i:sO', $post['created']) . '">' . $fields['when']['data'] . '</span></span>'; } } if (@$options['whoview']) { $fields['who'] = qa_who_to_html($isbyuser, @$post['userid'], $usershtml, @$options['ipview'] ? @$post['createip'] : null, $microformats, $post['name']); 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 (@$options['avatarsize'] > 0) { if (QA_FINAL_EXTERNAL_USERS) { $fields['avatar'] = qa_get_external_avatar_html($post['userid'], $options['avatarsize'], false); } else { $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 (@$options['updateview'] && isset($post['updated']) && ($post['updatetype'] != QA_UPDATE_SELECTED || $isselected) && (!isset($post['created']) || $post['hidden'] && $post['updatetype'] == QA_UPDATE_VISIBLE || isset($post['closedbyid']) && $post['updatetype'] == QA_UPDATE_CLOSED || abs($post['updated'] - $post['created']) > 300 || $post['lastuserid'] != $post['userid'])) { switch ($post['updatetype']) { case QA_UPDATE_TYPE: case QA_UPDATE_PARENT: $langstring = 'main/moved'; break; case QA_UPDATE_CATEGORY: $langstring = 'main/recategorized'; break; case QA_UPDATE_VISIBLE: $langstring = $post['hidden'] ? 'main/hidden' : 'main/reshown'; break; case QA_UPDATE_CLOSED: $langstring = isset($post['closedbyid']) ? 'main/closed' : 'main/reopened'; break; case QA_UPDATE_TAGS: $langstring = 'main/retagged'; break; case QA_UPDATE_SELECTED: $langstring = 'main/selected'; break; default: $langstring = 'main/edited'; break; } $fields['what_2'] = qa_lang_html($langstring); if (@$options['whenview']) { $fields['when_2'] = qa_when_to_html($post['updated'], @$options['fulldatedays']); if ($microformats) { $fields['when_2']['data'] = '<span class="updated"><span class="value-title" title="' . gmdate('Y-m-d\\TH:i:sO', $post['updated']) . '">' . $fields['when_2']['data'] . '</span></span>'; } } if (isset($post['lastuserid']) && @$options['whoview']) { $fields['who_2'] = qa_who_to_html(isset($userid) && $post['lastuserid'] == $userid, $post['lastuserid'], $usershtml, @$options['ipview'] ? $post['lastip'] : null, false); } } elseif ($microformats && @$options['whenview']) { // quick fix for incorrect microformats (missing 'updated' class) $fields['when']['data'] = str_replace('<span class="published">', '<span class="published updated">', $fields['when']['data']); } // That's it! return $fields; }
$qa_content['q_view']['form']['buttons']['delete'] = array('tags' => 'NAME="dodeleteq"', 'label' => qa_lang_html('question/delete_button'), 'popup' => qa_lang_html('question/delete_q_popup')); } 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
function get_text($content, $format, $options) { if ($format == 'html') { $text = strtr($content, "\n\r\t", ' '); // convert all white space in HTML to spaces $text = preg_replace('/<\\s*(' . $this->htmllineseparators . ')[^A-Za-z0-9]/i', "\n\\0", $text); // tags to single new line $text = preg_replace('/<\\s*(' . $this->htmlparagraphseparators . ')[^A-Za-z0-9]/i', "\n\n\\0", $text); // tags to double new line $text = strip_tags($text); // all tags removed $text = preg_replace('/ +/', ' ', $text); // combine multiple spaces into one $text = preg_replace('/ *\\n */', "\n", $text); // remove spaces either side new lines $text = preg_replace('/\\n\\n\\n+/', "\n\n", $text); // more than two new lines combine into two $text = strtr($text, array('"' => "\"", '&' => "&", ''' => "'", '<' => "<", '>' => ">", ' ' => " ", '"' => "\"", '&' => "&", '<' => "<", '>' => ">")); // base HTML entities (others should not be stored in database) $text = trim($text); } elseif ($format == '') { $text = $content; } else { $text = '[no viewer found for format: ' . $format . ']'; } // for unknown formats if (isset($options['blockwordspreg'])) { require_once QA_INCLUDE_DIR . 'qa-util-string.php'; $text = qa_block_words_replace($text, $options['blockwordspreg']); } return $text; }
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 ra_post_list($type, $limit) { require_once QA_INCLUDE_DIR . 'qa-app-posts.php'; $post = qa_db_query_sub('SELECT * FROM ^posts WHERE ^posts.type=$ ORDER BY ^posts.created DESC LIMIT #', $type, $limit); $output = '<ul class="question-list">'; while ($p = mysql_fetch_array($post)) { $p['title'] = qa_block_words_replace($p['title'], qa_get_block_words_preg(), '*'); $p['content'] = qa_block_words_replace($p['content'], qa_get_block_words_preg(), '*'); if ($type == 'Q') { $what = _ra_lang('asked'); } elseif ($type == 'A') { $what = _ra_lang('answered'); } elseif ('C') { $what = _ra_lang('commented'); } $handle = qa_post_userid_to_handle($p['userid']); $output .= '<li id="q-list-' . $p['postid'] . '" class="question-item">'; $output .= '<div class="pull-left avatar" data-handle="' . $handle . '" data-id="' . qa_handle_to_userid($handle) . '">' . ra_get_avatar($handle, 40) . '</div>'; $output .= '<div class="list-right">'; $output .= '<h5><a href="' . qa_path_html('user/' . $handle) . '">' . ra_name($handle) . '</a> ' . $what . '</h5>'; if ($type == 'Q') { $output .= '<p><a href="' . qa_q_path_html($p['postid'], $p['title']) . '" title="' . $p['title'] . '">' . qa_html($p['title']) . '</a></p>'; } elseif ($type == 'A') { $output .= '<p><a href="' . ra_post_link($p['parentid']) . '#a' . $p['postid'] . '">' . substr(strip_tags($p['content']), 0, 50) . '</a></p>'; } else { $output .= '<p><a href="' . ra_post_link($p['parentid']) . '#c' . $p['postid'] . '">' . substr(strip_tags($p['content']), 0, 50) . '</a></p>'; } if ($type == 'Q') { $output .= '<div class="counts"><div class="vote-count icon-chevron-up"><span>' . $p['netvotes'] . '</span></div>'; $output .= '<div class="ans-count icon-chat-4"><span>' . $p['acount'] . '</span></div></div>'; } elseif ($type == 'A') { $output .= '<div class="counts"><div class="vote-count icon-chevron-up"><span>' . $p['netvotes'] . '</span></div>'; } $output .= '</div>'; $output .= '</li>'; } $output .= '</ul>'; echo $output; }
function qw_notify_users_by_email($event, $postid, $userid, $effecteduserid, $params) { if (!!$effecteduserid) { //get the working user data $logged_in_handle = qa_get_logged_in_handle(); $logged_in_user_name = qw_get_name_from_userid($userid); $logged_in_user_name = !!$logged_in_user_name ? $logged_in_user_name : $logged_in_handle; $name = qw_get_name_from_userid($effecteduserid); switch ($event) { case 'a_post': case 'related': $parent = isset($params['parent']) ? $params['parent'] : ""; if (!!$parent) { $name = !!$name ? $name : $parent['handle']; $email = $parent['email']; $handle = $parent['handle']; } else { //seems proper values are not available return; } break; case 'c_post': case 'q_reshow': case 'a_reshow': case 'c_reshow': case 'a_select': case 'q_vote_up': case 'q_vote_down': case 'a_vote_up': case 'a_vote_down': case 'q_favorite': case 'u_favorite': case 'u_message': case 'u_wall_post': case 'u_level': case 'q_post_user_fl': case 'q_post_tag_fl': case 'q_post_cat_fl': //this is because we wont have the $parent['email'] for each effected userids when a these selected events occurs $user_details = qw_get_user_details_from_userid($effecteduserid); $handle = $user_details['handle']; $name = !!$name ? $name : $user_details['handle']; $email = $user_details['email']; break; case 'q_approve': case 'q_reject': $oldquestion = $params['oldquestion']; $handle = $oldquestion['handle']; $name = !!$name ? $name : $oldquestion['handle']; $email = $oldquestion['email']; break; case 'a_approve': case 'a_reject': $oldanswer = $params['oldanswer']; $handle = $oldquestion['handle']; $name = !!$name ? $name : $oldanswer['handle']; $email = $oldanswer['email']; break; case 'c_approve': case 'c_reject': $oldcomment = $params['oldcomment']; $handle = $oldcomment['handle']; $name = !!$name ? $name : $oldcomment['handle']; $email = $oldcomment['email']; break; default: break; } include_once QA_INCLUDE_DIR . 'qa-util-string.php'; $notifying_user['userid'] = $effecteduserid; $notifying_user['name'] = $name; $notifying_user['email'] = $email; $notifying_user['handle'] = isset($handle) ? $handle : qa_lang('main/anonymous'); //consider only first 50 characters for saving notification if ($event === 'u_message') { $content = isset($params['message']) && !empty($params['message']) ? $params['message'] : ""; $title = ""; $canreply = !(qa_get_logged_in_flags() & QA_USER_FLAGS_NO_MESSAGES); $url = qa_path_absolute($canreply ? 'message/' . $logged_in_handle : 'user/' . $logged_in_handle); } else { if ($event === 'u_wall_post') { $content = isset($params['text']) && !empty($params['text']) ? $params['text'] : ""; if (!!$content) { $blockwordspreg = qa_get_block_words_preg(); $content = qa_block_words_replace($content, $blockwordspreg); } $title = ""; $url = qa_path_absolute('user/' . $params['handle'] . '/wall', null, null); } else { if ($event === 'u_level') { $title = ""; $url = qa_path_absolute('user/' . $params['handle']); $old_level = $params['oldlevel']; $new_level = $params['level']; if ($new_level < $old_level) { return; } $approved_only = ""; if ($new_level == QA_USER_LEVEL_APPROVED && $old_level < QA_USER_LEVEL_APPROVED) { $approved_only = true; } else { $approved_only = false; } if ($approved_only === false) { $new_designation = qw_get_user_desg($new_level); } $content = strtr(qa_lang($approved_only ? 'notification/u_level_approved_body_email' : 'notification/u_level_improved_body_email'), array('^done_by' => isset($logged_in_user_name) ? $logged_in_user_name : isset($logged_in_handle) ? $logged_in_handle : qa_lang('main/anonymous'), '^new_designation' => @$new_designation)); } else { if ($event === "q_post_user_fl" || $event === "q_post_tag_fl" || $event === "q_post_cat_fl") { $content = isset($params['text']) && !empty($params['text']) ? $params['text'] : ""; //shrink the email body content if (!!$content && strlen($content) > 50) { $content = qw_shrink_email_body($content, 50); } $title = isset($params['title']) && !empty($params['title']) ? $params['title'] : ""; $url = qa_q_path($params['postid'], $title, true); } else { $content = isset($params['text']) && !empty($params['text']) ? $params['text'] : ""; //shrink the email body content if (!!$content && strlen($content) > 50) { $content = qw_shrink_email_body($content, 50); } $title = isset($params['qtitle']) && !empty($params['qtitle']) ? $params['qtitle'] : ""; $url = qa_q_path($params['qid'], $title, true); } } } } $q_handle = isset($logged_in_user_name) ? $logged_in_user_name : isset($logged_in_handle) ? $logged_in_handle : qa_lang('main/anonymous'); qw_save_email_notification(null, $notifying_user, $logged_in_handle, $event, array('^q_handle' => $q_handle, '^q_title' => $title, '^q_content' => $content, '^url' => !!$url ? $url : "", '^done_by' => $q_handle, '^author_link' => qa_path_absolute('user/' . $q_handle), '^author_pic' => qa_path_absolute('user/' . $q_handle), '^handle' => $handle)); } }
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 = '–' . 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; }
$qdefaults['answersview'] = false; $qdefaults['viewsview'] = false; break; } } foreach ($results as $result) { if (isset($result['question'])) { $fields = qa_post_html_fields($result['question'], $userid, qa_cookie_get(), $usershtml, null, qa_post_html_options($result['question'], $qdefaults)); } elseif (isset($result['url'])) { $fields = array('what' => qa_html($result['url']), 'meta_order' => qa_lang_html('main/meta_order')); } else { continue; } // nothing to show here if (isset($qdefaults['blockwordspreg'])) { $result['title'] = qa_block_words_replace($result['title'], $qdefaults['blockwordspreg']); } $fields['title'] = qa_html($result['title']); $fields['url'] = qa_html($result['url']); $qa_content['q_list']['qs'][] = $fields; } $qa_content['page_links'] = qa_html_page_links(qa_request(), $start, $pagesize, $start + $gotcount, qa_opt('pages_prev_next'), array('q' => $inquery), $gotcount >= $count); if (qa_opt('feed_for_search')) { $qa_content['feed'] = array('url' => qa_path_html(qa_feed_request('search/' . $inquery)), 'label' => qa_lang_html_sub('main/results_for_x', qa_html($inquery))); } if (empty($qa_content['page_links'])) { $qa_content['suggest_next'] = qa_html_suggest_qs_tags(qa_using_tags()); } } else { $qa_content['error'] = qa_lang_html('main/search_explanation'); }
function process_event($event, $userid, $handle, $cookieid, $params) { require_once QA_INCLUDE_DIR . 'qa-app-emails.php'; require_once QA_INCLUDE_DIR . 'qa-app-format.php'; require_once QA_INCLUDE_DIR . 'qa-util-string.php'; switch ($event) { case 'q_post': $followanswer = @$params['followanswer']; $sendhandle = isset($handle) ? $handle : (strlen($params['name']) ? $params['name'] : qa_lang('main/anonymous')); if (isset($followanswer['notify']) && !qa_post_is_by_user($followanswer, $userid, $cookieid)) { $blockwordspreg = qa_get_block_words_preg(); $sendtext = qa_viewer_text($followanswer['content'], $followanswer['format'], array('blockwordspreg' => $blockwordspreg)); qa_send_notification($followanswer['userid'], $followanswer['notify'], @$followanswer['handle'], qa_lang('emails/a_followed_subject'), qa_lang('emails/a_followed_body'), array('^q_handle' => $sendhandle, '^q_title' => qa_block_words_replace($params['title'], $blockwordspreg), '^a_content' => $sendtext, '^url' => qa_q_path($params['postid'], $params['title'], true))); } if (qa_opt('notify_admin_q_post')) { qa_send_notification(null, qa_opt('feedback_email'), null, qa_lang('emails/q_posted_subject'), qa_lang('emails/q_posted_body'), array('^q_handle' => $sendhandle, '^q_title' => $params['title'], '^q_content' => $params['text'], '^url' => qa_q_path($params['postid'], $params['title'], true))); } break; case 'a_post': $question = $params['parent']; if (isset($question['notify']) && !qa_post_is_by_user($question, $userid, $cookieid)) { qa_send_notification($question['userid'], $question['notify'], @$question['handle'], qa_lang('emails/q_answered_subject'), qa_lang('emails/q_answered_body'), array('^a_handle' => isset($handle) ? $handle : (strlen($params['name']) ? $params['name'] : qa_lang('main/anonymous')), '^q_title' => $question['title'], '^a_content' => qa_block_words_replace($params['text'], qa_get_block_words_preg()), '^url' => qa_q_path($question['postid'], $question['title'], true, 'A', $params['postid']))); } break; case 'c_post': $parent = $params['parent']; $question = $params['question']; $senttoemail = array(); // to ensure each user or email gets only one notification about an added comment $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 : (strlen($params['name']) ? $params['name'] : qa_lang('main/anonymous')); $sendcontext = qa_block_words_replace($context, $blockwordspreg); $sendtext = qa_block_words_replace($params['text'], $blockwordspreg); $sendurl = qa_q_path($question['postid'], $question['title'], true, 'C', $params['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 ($params['thread'] as $comment) { 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)); } } break; case 'q_queue': case 'q_requeue': if (qa_opt('moderate_notify_admin')) { qa_send_notification(null, qa_opt('feedback_email'), null, $event == 'q_requeue' ? qa_lang('emails/remoderate_subject') : qa_lang('emails/moderate_subject'), $event == 'q_requeue' ? qa_lang('emails/remoderate_body') : qa_lang('emails/moderate_body'), array('^p_handle' => isset($handle) ? $handle : (strlen($params['name']) ? $params['name'] : (strlen(@$oldquestion['name']) ? $oldquestion['name'] : qa_lang('main/anonymous'))), '^p_context' => trim(@$params['title'] . "\n\n" . $params['text']), '^url' => qa_q_path($params['postid'], $params['title'], true), '^a_url' => qa_path_absolute('admin/moderate'))); } break; case 'a_queue': case 'a_requeue': if (qa_opt('moderate_notify_admin')) { qa_send_notification(null, qa_opt('feedback_email'), null, $event == 'a_requeue' ? qa_lang('emails/remoderate_subject') : qa_lang('emails/moderate_subject'), $event == 'a_requeue' ? qa_lang('emails/remoderate_body') : qa_lang('emails/moderate_body'), array('^p_handle' => isset($handle) ? $handle : (strlen($params['name']) ? $params['name'] : (strlen(@$oldanswer['name']) ? $oldanswer['name'] : qa_lang('main/anonymous'))), '^p_context' => $params['text'], '^url' => qa_q_path($params['parentid'], $params['parent']['title'], true, 'A', $params['postid']), '^a_url' => qa_path_absolute('admin/moderate'))); } break; case 'c_queue': case 'c_requeue': if (qa_opt('moderate_notify_admin')) { qa_send_notification(null, qa_opt('feedback_email'), null, $event == 'c_requeue' ? qa_lang('emails/remoderate_subject') : qa_lang('emails/moderate_subject'), $event == 'c_requeue' ? qa_lang('emails/remoderate_body') : qa_lang('emails/moderate_body'), array('^p_handle' => isset($handle) ? $handle : (strlen($params['name']) ? $params['name'] : (strlen(@$oldcomment['name']) ? $oldcomment['name'] : (strlen(@$oldanswer['name']) ? $oldanswer['name'] : qa_lang('main/anonymous')))), '^p_context' => $params['text'], '^url' => qa_q_path($params['questionid'], $params['question']['title'], true, 'C', $params['postid']), '^a_url' => qa_path_absolute('admin/moderate'))); } break; case 'q_flag': case 'a_flag': case 'c_flag': $flagcount = $params['flagcount']; $oldpost = $params['oldpost']; $notifycount = $flagcount - qa_opt('flagging_notify_first'); if ($notifycount >= 0 && $notifycount % qa_opt('flagging_notify_every') == 0) { qa_send_notification(null, qa_opt('feedback_email'), null, qa_lang('emails/flagged_subject'), qa_lang('emails/flagged_body'), array('^p_handle' => isset($oldpost['handle']) ? $oldpost['handle'] : (strlen($oldpost['name']) ? $oldpost['name'] : 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(@$oldpost['title'] . "\n\n" . qa_viewer_text($oldpost['content'], $oldpost['format'])), '^url' => qa_q_path($params['questionid'], $params['question']['title'], true, $oldpost['basetype'], $oldpost['postid']), '^a_url' => qa_path_absolute('admin/flagged'))); } break; case 'a_select': $answer = $params['answer']; if (isset($answer['notify']) && !qa_post_is_by_user($answer, $userid, $cookieid)) { $blockwordspreg = qa_get_block_words_preg(); $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' => qa_block_words_replace($params['parent']['title'], $blockwordspreg), '^a_content' => $sendcontent, '^url' => qa_q_path($params['parentid'], $params['parent']['title'], true, 'A', $params['postid']))); } break; case 'u_register': if (qa_opt('register_notify_admin')) { qa_send_notification(null, qa_opt('feedback_email'), null, qa_lang('emails/u_registered_subject'), qa_opt('moderate_users') ? qa_lang('emails/u_to_approve_body') : qa_lang('emails/u_registered_body'), array('^u_handle' => $handle, '^url' => qa_path_absolute('user/' . $handle), '^a_url' => qa_path_absolute('admin/approve'))); } break; case 'u_level': if ($params['level'] >= QA_USER_LEVEL_APPROVED && $params['oldlevel'] < QA_USER_LEVEL_APPROVED) { qa_send_notification($params['userid'], null, $params['handle'], qa_lang('emails/u_approved_subject'), qa_lang('emails/u_approved_body'), array('^url' => qa_path_absolute('user/' . $params['handle']))); } break; case 'u_wall_post': if ($userid != $params['userid']) { $blockwordspreg = qa_get_block_words_preg(); qa_send_notification($params['userid'], null, $params['handle'], qa_lang('emails/wall_post_subject'), qa_lang('emails/wall_post_body'), array('^f_handle' => isset($handle) ? $handle : qa_lang('main/anonymous'), '^post' => qa_block_words_replace($params['text'], $blockwordspreg), '^url' => qa_path_absolute('user/' . $params['handle'], null, 'wall'))); } break; } }
private function format_message($msg) { // censor bad words require_once QA_INCLUDE_DIR . 'qa-util-string.php'; $blockwordspreg = qa_get_block_words_preg(); $msg = qa_block_words_replace($msg, $blockwordspreg); $msg = qa_html($msg); return qa_html_convert_urls($msg); }