function qa_post_create($type, $parentpostid, $title, $content, $format = '', $categoryid = null, $tags = null, $userid = null, $notify = null, $email = null) { $handle = qa_post_userid_to_handle($userid); $text = qa_post_content_to_text($content, $format); switch ($type) { case 'Q': $followanswer = isset($parentpostid) ? qa_post_get_full($parentpostid, 'A') : null; $tagstring = qa_post_tags_to_tagstring($tags); $postid = qa_question_create($followanswer, $userid, $handle, null, $title, $content, $format, $text, $tagstring, $notify, $email, $categoryid); break; case 'A': $question = qa_post_get_full($parentpostid, 'Q'); $postid = qa_answer_create($userid, $handle, null, $content, $format, $text, $notify, $email, $question); break; case 'C': $parentpost = qa_post_get_full($parentpostid, 'QA'); $commentsfollows = qa_db_single_select(qa_db_full_child_posts_selectspec(null, $parentpostid)); $question = qa_post_parent_to_question($parentpost); $answer = qa_post_parent_to_answer($parentpost); $postid = qa_comment_create($userid, $handle, null, $content, $format, $text, $notify, $email, $question, $answer, $commentsfollows); break; case 'AN': $postid = mp_announcement_create($userid, $handle, qa_cookie_get_create(), $title, $content, $format, $text, $notify, $categoryid); break; default: qa_fatal_error('Post type not recognized: ' . $type); break; } return $postid; }
foreach ($filtermodules as $filtermodule) { $oldin = $in; $filtermodule->filter_question($in, $errors, null); 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');
function qa_page_q_add_c_submit($question, $parent, $commentsfollows, $usecaptcha, &$in, &$errors) { $parentid = $parent['postid']; $prefix = 'c' . $parentid . '_'; $in = array('name' => qa_post_text($prefix . 'name'), 'notify' => qa_post_text($prefix . 'notify') !== null, 'email' => qa_post_text($prefix . 'email'), 'queued' => qa_user_moderation_reason(qa_user_level_for_post($parent)) !== false); qa_get_post_content($prefix . 'editor', $prefix . 'content', $in['editor'], $in['content'], $in['format'], $in['text']); $errors = array(); if (!qa_check_form_security_code('comment-' . $parent['postid'], qa_post_text($prefix . 'code'))) { $errors['content'] = qa_lang_html('misc/form_security_again'); } else { $filtermodules = qa_load_modules_with('filter', 'filter_comment'); foreach ($filtermodules as $filtermodule) { $oldin = $in; $filtermodule->filter_comment($in, $errors, $question, $parent, null); qa_update_post_text($in, $oldin); } if ($usecaptcha) { qa_captcha_validate_post($errors); } if (empty($errors)) { $testwords = implode(' ', qa_string_to_words($in['content'])); foreach ($commentsfollows as $comment) { if ($comment['basetype'] == 'C' && $comment['parentid'] == $parentid && !$comment['hidden']) { if (implode(' ', qa_string_to_words($comment['content'])) == $testwords) { $errors['content'] = qa_lang_html('question/duplicate_content'); } } } } if (empty($errors)) { $userid = qa_get_logged_in_userid(); $handle = qa_get_logged_in_handle(); $cookieid = isset($userid) ? qa_cookie_get() : qa_cookie_get_create(); // create a new cookie if necessary $commentid = qa_comment_create($userid, $handle, $cookieid, $in['content'], $in['format'], $in['text'], $in['notify'], $in['email'], $question, $parent, $commentsfollows, $in['queued'], $in['name']); return $commentid; } } return null; }
function award_badge($object_id, $user_id, $badge_slug, $badge_badge = false) { if (!$user_id) { return; } // add badge to userbadges qa_db_query_sub('INSERT INTO ^userbadges (awarded_at, notify, object_id, user_id, badge_slug, id) ' . 'VALUES (NOW(), 1, #, #, $, 0)', $object_id, $user_id, $badge_slug); if (qa_opt('event_logger_to_database')) { // add event $handle = qa_getHandleFromId($user_id); qa_db_query_sub('INSERT INTO ^eventlog (datetime, ipaddress, userid, handle, cookieid, event, params) ' . 'VALUES (NOW(), $, $, $, #, $, $)', qa_remote_ip_address(), $user_id, $handle, qa_cookie_get_create(), 'badge_awarded', 'badge_slug=' . $badge_slug . ($object_id ? "\t" . 'postid=' . $object_id : '')); } if (qa_opt('badge_email_notify')) { qa_badge_notification($user_id, $object_id, $badge_slug); } // check for sheer number of badges, unless this badge was for number of badges (avoid recursion!) if (!$badge_badge) { $this->check_badges($user_id); } }
function qa_badge_award_check($badges, $var, $uid, $oid = NULL, $notify = 1) { // oid is the postid (if), notify = 1 for email and popup, 2 for just popup. if (!$uid) { return; } $awarded = array(); foreach ($badges as $badge_slug) { if (($var === false || (int) $var >= (int) qa_opt('badge_' . $badge_slug . '_var')) && qa_opt('badge_' . $badge_slug . '_enabled') !== '0') { if ($oid) { $result = @qa_db_read_one_value(qa_db_query_sub('SELECT badge_slug FROM ^userbadges WHERE user_id=# AND badge_slug=$ AND object_id=#', $uid, $badge_slug, $oid), true); } else { $result = @qa_db_read_one_value(qa_db_query_sub('SELECT badge_slug FROM ^userbadges WHERE user_id=# AND badge_slug=$', $uid, $badge_slug), true); } if ($result == null) { // not already awarded this badge qa_db_query_sub('INSERT INTO ^userbadges (awarded_at, notify, object_id, user_id, badge_slug, id) ' . 'VALUES (NOW(), #, #, #, #, 0)', $notify, $oid, $uid, $badge_slug); if ($notify > 0) { //qa_db_usernotice_create($uid, $content, 'html'); if (qa_opt('badge_email_notify') && $notify == 1) { qa_badge_notification($uid, $oid, $badge_slug); } if (qa_opt('event_logger_to_database')) { // add event $handle = qa_getHandleFromId($uid); qa_db_query_sub('INSERT INTO ^eventlog (datetime, ipaddress, userid, handle, cookieid, event, params) ' . 'VALUES (NOW(), $, $, $, #, $, $)', qa_remote_ip_address(), $uid, $handle, qa_cookie_get_create(), 'badge_awarded', 'badge_slug=' . $badge_slug . ($oid ? "\t" . 'postid=' . $oid : '')); } } array_push($awarded, $badge_slug); } } } return $awarded; }
function qa_upload_file($localfilename, $sourcefilename, $maxfilesize = null, $onlyimage = false, $imagemaxwidth = null, $imagemaxheight = null) { if (qa_to_override(__FUNCTION__)) { $args = func_get_args(); return qa_call_override(__FUNCTION__, $args); } $result = array(); // Check per-user upload limits require_once QA_INCLUDE_DIR . 'qa-app-users.php'; require_once QA_INCLUDE_DIR . 'qa-app-limits.php'; switch (qa_user_permit_error(null, QA_LIMIT_UPLOADS)) { case 'limit': $result['error'] = qa_lang('main/upload_limit'); return $result; case false: qa_limits_increment(qa_get_logged_in_userid(), QA_LIMIT_UPLOADS); break; default: $result['error'] = qa_lang('users/no_permission'); return $result; } // Check the uploaded file is not too large $filesize = filesize($localfilename); if (isset($maxfilesize)) { $maxfilesize = min($maxfilesize, qa_get_max_upload_size()); } else { $maxfilesize = qa_get_max_upload_size(); } if ($filesize <= 0 || $filesize > $maxfilesize) { // if file was too big for PHP, $filesize will be zero $result['error'] = qa_lang_sub('main/max_upload_size_x', number_format($maxfilesize / 1048576, 1) . 'MB'); return $result; } // Find out what type of source file was uploaded and if appropriate, check it's an image and get preliminary size measure $pathinfo = pathinfo($sourcefilename); $format = strtolower(@$pathinfo['extension']); $isimage = $format == 'png' || $format == 'gif' || $format == 'jpeg' || $format == 'jpg'; // allowed image extensions if ($isimage) { $imagesize = @getimagesize($localfilename); if (is_array($imagesize)) { $result['width'] = $imagesize[0]; $result['height'] = $imagesize[1]; switch ($imagesize['2']) { // reassign format based on actual content, if we can case IMAGETYPE_GIF: $format = 'gif'; break; case IMAGETYPE_JPEG: $format = 'jpeg'; break; case IMAGETYPE_PNG: $format = 'png'; break; } } } $result['format'] = $format; if ($onlyimage) { if (!$isimage || !is_array($imagesize)) { $result['error'] = qa_lang_sub('main/image_not_read', 'GIF, JPG, PNG'); return $result; } } // Read in the raw file contents $content = file_get_contents($localfilename); // If appropriate, get more accurate image size and apply constraints to it require_once QA_INCLUDE_DIR . 'qa-util-image.php'; if ($isimage && qa_has_gd_image()) { $image = @imagecreatefromstring($content); if (is_resource($image)) { $result['width'] = $width = imagesx($image); $result['height'] = $height = imagesy($image); if (isset($imagemaxwidth) || isset($imagemaxheight)) { if (qa_image_constrain($width, $height, isset($imagemaxwidth) ? $imagemaxwidth : $width, isset($imagemaxheight) ? $imagemaxheight : $height)) { qa_gd_image_resize($image, $width, $height); if (is_resource($image)) { $content = qa_gd_image_jpeg($image); $result['format'] = $format = 'jpeg'; $result['width'] = $width; $result['height'] = $height; } } } if (is_resource($image)) { // might have been lost imagedestroy($image); } } } // Create the blob and return require_once QA_INCLUDE_DIR . 'qa-app-blobs.php'; $userid = qa_get_logged_in_userid(); $cookieid = isset($userid) ? qa_cookie_get() : qa_cookie_get_create(); $result['blobid'] = qa_create_blob($content, $format, $sourcefilename, $userid, $cookieid, qa_remote_ip_address()); if (!isset($result['blobid'])) { $result['error'] = qa_lang('main/general_error'); return $result; } $result['bloburl'] = qa_get_blob_url($result['blobid'], true); return $result; }
function do_favorite($data) { $postid = (int) @$data['action_id']; $info = @$data['action_data']; $favorite = isset($info['favorite']); $type = @$info['type']; if ($postid === null || $type === null) { return false; } require_once QA_INCLUDE_DIR . 'qa-app-favorites.php'; $userid = qa_get_logged_in_userid(); $handle = qa_get_logged_in_handle(); $cookieid = isset($userid) ? qa_cookie_get() : qa_cookie_get_create(); // create a new cookie if necessary qa_user_favorite_set($userid, $handle, $cookieid, $type, $postid, $favorite); return true; }
function process_request($request) { $message = ''; $url = ''; if (is_array($_FILES) && count($_FILES)) { // Check that we're allowed to upload images (if not, no other uploads are allowed either) if (!qa_opt('wysiwyg_editor_upload_images')) { $message = qa_lang('users/no_permission'); } // Check that we haven't reached the upload limit and are not blocked if (empty($message)) { require_once QA_INCLUDE_DIR . 'qa-app-users.php'; require_once QA_INCLUDE_DIR . 'qa-app-limits.php'; switch (qa_user_permit_error(null, QA_LIMIT_UPLOADS)) { case 'limit': $message = qa_lang('main/upload_limit'); break; case false: qa_limits_increment(qa_get_logged_in_userid(), QA_LIMIT_UPLOADS); break; default: $message = qa_lang('users/no_permission'); break; } } // Find out some information about the uploaded file and check it's not too large if (empty($message)) { require_once QA_INCLUDE_DIR . 'qa-app-blobs.php'; $file = reset($_FILES); $pathinfo = pathinfo($file['name']); $extension = strtolower(@$pathinfo['extension']); $filesize = $file['size']; $maxsize = min(qa_opt('wysiwyg_editor_upload_max_size'), qa_get_max_upload_size()); if ($filesize <= 0 || $filesize > $maxsize) { // if file was too big for PHP, $filesize will be zero $message = qa_lang_sub('main/max_upload_size_x', number_format($maxsize / 1048576, 1) . 'MB'); } } // If it's only allowed to be an image, check it's an image if (empty($message)) { if (qa_get('qa_only_image') || !qa_opt('wysiwyg_editor_upload_all')) { // check if we need to confirm it's an image switch ($extension) { case 'png': // these are allowed image extensions // these are allowed image extensions case 'gif': case 'jpeg': case 'jpg': if (function_exists('getimagesize')) { // getimagesize() does not require GD library if (!is_array(@getimagesize($file['tmp_name']))) { $message = qa_lang_sub('main/image_not_read', 'GIF, JPG, PNG'); } } break; default: $message = qa_lang_sub('main/image_not_read', 'GIF, JPG, PNG'); break; } } } // If there have been no errors, looks like we're all set... if (empty($message)) { require_once QA_INCLUDE_DIR . 'qa-db-blobs.php'; $userid = qa_get_logged_in_userid(); $cookieid = isset($userid) ? qa_cookie_get() : qa_cookie_get_create(); $blobid = qa_db_blob_create(file_get_contents($file['tmp_name']), $extension, @$file['name'], $userid, $cookieid, qa_remote_ip_address()); if (isset($blobid)) { $url = qa_get_blob_url($blobid, true); } else { $message = 'Failed to create object in database - please try again'; } } } echo "<script type='text/javascript'>window.parent.CKEDITOR.tools.callFunction(" . qa_js(qa_get('CKEditorFuncNum')) . ", " . qa_js($url) . ", " . qa_js($message) . ");</script>"; return null; }
function ajaxPostComment($text, $aid = false) { if ($aid) { $answer = qa_db_single_select(qa_db_full_post_selectspec(null, $aid)); } require_once QA_INCLUDE_DIR . 'qa-page-question-post.php'; global $qa_login_userid, $qa_cookieid, $question, $questionid, $formtype, $formpostid, $errors, $reloadquestion, $pageerror, $qa_request, $ineditor, $incomment, $informat, $innotify, $inemail, $commentsfollows, $jumptoanchor, $usecaptcha; $parent = isset($answer) ? $answer : $question; switch (qa_user_permit_error('permit_post_c', 'C')) { case 'login': $pageerror = qa_insert_login_links(qa_lang_html('question/comment_must_login'), $qa_request); break; case 'confirm': $pageerror = qa_insert_login_links(qa_lang_html('question/comment_must_confirm'), $qa_request); break; case 'limit': $pageerror = qa_lang_html('question/comment_limit'); break; default: $pageerror = qa_lang_html('users/no_permission'); break; case false: $incomment = qa_post_text('ajax_comment_content'); if (!isset($incomment)) { $pageerror = qa_lang_html('bork'); } else { $innotify = qa_post_text('notify') ? true : false; $inemail = qa_post_text('email'); $this->ajaxEditor($ineditor, $incomment, $informat, $intext); // use our own format types $formats = array(); $formats[] = ''; $editors = qa_list_modules('viewer'); if (in_array('Markdown Viewer', $editors)) { $formats[] = 'markdown'; } $formats[] = 'html'; $informat = $formats[qa_opt('ajax_comment_format')]; $errors = qa_comment_validate($incomment, $informat, $intext, $innotify, $inemail); if ($usecaptcha) { qa_captcha_validate($_POST, $errors); } if (empty($errors)) { $isduplicate = false; foreach ($commentsfollows as $comment) { if ($comment['basetype'] == 'C' && $comment['parentid'] == $parent['postid'] && !$comment['hidden']) { if (implode(' ', qa_string_to_words($comment['content'])) == implode(' ', qa_string_to_words($incomment))) { $isduplicate = true; } } } if (!$isduplicate) { if (!isset($qa_login_userid)) { $qa_cookieid = qa_cookie_get_create(); } // create a new cookie if necessary // get editor format $commentid = qa_comment_create($qa_login_userid, qa_get_logged_in_handle(), $qa_cookieid, $incomment, $informat, $intext, $innotify, $inemail, $question, @$answer, $commentsfollows); qa_report_write_action($qa_login_userid, $qa_cookieid, 'c_post', $questionid, @$answer['postid'], $commentid); } else { $pageerror = qa_lang_html('question/duplicate_content'); } } } break; } if ($pageerror) { $this->output_raw('### ' . $pageerror); } else { if (!empty($errors)) { $this->output_raw('### ' . implode(',', $errors)); } else { // return c_item $c_item = $this->ajaxCommentCreate($parent, $commentid); if (isset($c_item['classes'])) { $c_item['classes'] .= ' ajax-comment-hidden'; } else { $c_item['classes'] = ' ajax-comment-hidden'; } $this->c_list_item($c_item); } } }
require_once QA_INCLUDE_DIR . 'qa-util-string.php'; $innotify = qa_post_text('notify') ? true : false; $inemail = qa_post_text('email'); qa_get_post_content('editor', 'content', $ineditor, $incontent, $informat, $intext); $tagstring = qa_tags_to_tagstring($intags); $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());
function doctype() { //qa_error_log($this->content); if ($this->request == 'admin/permissions' && function_exists('qa_register_plugin_phrases') && qa_get_logged_in_level() >= QA_USER_LEVEL_ADMIN) { $permits[] = 'expert_question_ask'; $permits[] = 'expert_question_roles'; foreach ($permits as $optionname) { $value = qa_opt($optionname); $optionfield = array('id' => $optionname, 'label' => qa_lang_html('expert_question/' . $optionname) . ':', 'tags' => 'NAME="option_' . $optionname . '" ID="option_' . $optionname . '"', 'error' => qa_html(@$errors[$optionname])); $widest = QA_PERMIT_USERS; $narrowest = QA_PERMIT_ADMINS; $permitoptions = qa_admin_permit_options($widest, $narrowest, !QA_FINAL_EXTERNAL_USERS && qa_opt('confirm_user_emails')); if (count($permitoptions) > 1) { qa_optionfield_make_select($optionfield, $permitoptions, $value, $value == QA_PERMIT_CONFIRMED ? QA_PERMIT_USERS : min(array_keys($permitoptions))); } $this->content['form']['fields'][$optionname] = $optionfield; $this->content['form']['fields'][$optionname . '_points'] = array('id' => $optionname . '_points', 'tags' => 'NAME="option_' . $optionname . '_points" ID="option_' . $optionname . '_points"', 'type' => 'number', 'value' => qa_opt($optionname . '_points'), 'prefix' => qa_lang_html('admin/users_must_have') . ' ', 'note' => qa_lang_html('admin/points')); $checkboxtodisplay[$optionname . '_points'] = '(option_' . $optionname . '==' . qa_js(QA_PERMIT_POINTS) . ') ||(option_' . $optionname . '==' . qa_js(QA_PERMIT_POINTS_CONFIRMED) . ')'; } qa_set_display_rules($this->content, $checkboxtodisplay); } $this->expert_user = $this->is_expert_user(); if (!$this->expert_user) { foreach ($this->content['navigation']['main'] as $key => $nav) { if ($nav['url'] == qa_path_html(qa_opt('expert_question_page_url'))) { unset($this->content['navigation']['main'][$key]); } } } if (qa_clicked('do_expert_answeradd') && ($this->expert_user || $this->content['q_view']['raw']['userid'] === qa_get_logged_in_userid())) { global $qa_login_userid, $questionid, $question, $answers, $question, $qa_request; $innotify = qa_post_text('notify') ? true : false; $inemail = qa_post_text('email'); qa_get_post_content('editor', 'content', $ineditor, $incontent, $informat, $intext); $isduplicate = false; foreach ($answers as $answer) { if (!$answer['hidden']) { if (implode(' ', qa_string_to_words($answer['content'])) == implode(' ', qa_string_to_words($incontent))) { $isduplicate = true; } } } if (!$isduplicate) { if (!isset($qa_login_userid)) { $qa_cookieid = qa_cookie_get_create(); } // create a new cookie if necessary $answerid = qa_answer_create($qa_login_userid, qa_get_logged_in_handle(), $qa_cookieid, $incontent, $informat, $intext, $innotify, $inemail, $question); qa_report_write_action($qa_login_userid, $qa_cookieid, 'a_post', $questionid, $answerid, null); qa_redirect($qa_request, null, null, null, qa_anchor('A', $answerid)); } else { $pageerror = qa_lang_html('question/duplicate_content'); } qa_page_q_load_q(); // reload since we may have changed something } if (qa_opt('expert_question_enable')) { if ($this->expert_user && qa_opt('expert_question_show_count')) { $this->expertcount = qa_db_read_one_value(qa_db_query_sub("SELECT COUNT(postid) FROM ^postmeta, ^posts WHERE ^postmeta.meta_key='is_expert_question' AND ^postmeta.post_id=^posts.postid AND ^posts.acount=0" . (is_array($this->expert_user) ? " AND ^posts.categoryid IN (#)" : " AND \$"), $this->expert_user), true); if ($this->expertcount) { foreach ($this->content['navigation']['main'] as $key => $nav) { if ($nav['url'] == qa_path_html(qa_opt('expert_question_page_url'))) { $this->content['navigation']['main'][$key]['label'] .= ' (' . $this->expertcount . ')'; } } } } global $qa_request; if ($qa_request == qa_opt('expert_question_page_url')) { $this->content['navigation']['sub'] = array('special' => 1); } if ($this->template == 'ask' && in_array(qa_opt('expert_question_type'), array(0, 2)) && !qa_user_permit_error('permit_post_q') && !qa_permit_value_error(qa_opt('expert_question_ask'), qa_get_logged_in_userid(), qa_get_logged_in_level(), qa_get_logged_in_flags()) && !qa_opt('site_maintenance')) { $this->content['form']['fields'][] = array('tags' => 'NAME="is_expert_question" ID="is_expert_question"', 'value' => qa_get(qa_opt('expert_question_page_url')) == 'true' ? qa_opt('expert_question_yes') : qa_opt('expert_question_no'), 'type' => 'select-radio', 'options' => array('no' => qa_opt('expert_question_no'), 'yes' => qa_opt('expert_question_yes'))); } if ($this->template == 'user' && qa_get_logged_in_handle() === $this->_user_handle()) { if (!isset($this->content['navigation']['sub'])) { $this->content['navigation']['sub'] = array('profile' => array('url' => qa_path_html('user/' . $this->_user_handle(), null, qa_opt('site_url')), 'label' => $this->_user_handle(), 'selected' => !qa_get('tab') ? true : false), qa_opt('expert_question_page_url') => array('url' => qa_path_html('user/' . $this->_user_handle(), array('tab' => qa_opt('expert_question_page_url')), qa_opt('site_url')), 'label' => qa_opt('expert_question_page_title'), 'selected' => qa_get('tab') == qa_opt('expert_question_page_url') ? true : false)); } else { $this->content['navigation']['sub'][qa_opt('expert_question_page_url')] = array('url' => qa_path_html('user/' . $this->_user_handle(), array('tab' => qa_opt('expert_question_page_url')), qa_opt('site_url')), 'label' => qa_opt('expert_question_page_title'), 'selected' => qa_get('tab') == qa_opt('expert_question_page_url') ? true : false); } } if ($this->template == 'question') { $qid = $this->content['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) { // is expert question $this->expert_question = 1; // modify post elements // title $this->content['title'] .= ' ' . qa_opt('expert_question_title'); // css class $this->content['q_view']['tags'] .= ' class="qa-expert-question"'; // remove hidden stuff unset($this->content['q_view']['hidden']); unset($this->content['hidden']); } } } qa_html_theme_base::doctype(); }
function qa_page_q_do_comment($answer) { global $qa_login_userid, $qa_cookieid, $question, $questionid, $formtype, $formpostid, $errors, $reloadquestion, $pageerror, $qa_request, $ineditor, $incomment, $informat, $innotify, $inemail, $commentsfollows, $jumptoanchor, $usecaptcha; $parent = isset($answer) ? $answer : $question; switch (qa_user_permit_error('permit_post_c', 'C')) { case 'login': $pageerror = qa_insert_login_links(qa_lang_html('question/comment_must_login'), $qa_request); break; case 'confirm': $pageerror = qa_insert_login_links(qa_lang_html('question/comment_must_confirm'), $qa_request); break; case 'limit': $pageerror = qa_lang_html('question/comment_limit'); break; default: $pageerror = qa_lang_html('users/no_permission'); break; case false: $incomment = qa_post_text('comment'); if (!isset($incomment)) { $formtype = 'c_add'; $formpostid = $parent['postid']; // show form first time } else { $innotify = qa_post_text('notify') ? true : false; $inemail = qa_post_text('email'); qa_get_post_content('editor', 'comment', $ineditor, $incomment, $informat, $intext); $errors = qa_comment_validate($incomment, $informat, $intext, $innotify, $inemail); if ($usecaptcha) { qa_captcha_validate($_POST, $errors); } if (empty($errors)) { $isduplicate = false; foreach ($commentsfollows as $comment) { if ($comment['basetype'] == 'C' && $comment['parentid'] == $parent['postid'] && !$comment['hidden']) { if (implode(' ', qa_string_to_words($comment['content'])) == implode(' ', qa_string_to_words($incomment))) { $isduplicate = true; } } } if (!$isduplicate) { if (!isset($qa_login_userid)) { $qa_cookieid = qa_cookie_get_create(); } // create a new cookie if necessary $commentid = qa_comment_create($qa_login_userid, qa_get_logged_in_handle(), $qa_cookieid, $incomment, $informat, $intext, $innotify, $inemail, $question, $answer, $commentsfollows); qa_report_write_action($qa_login_userid, $qa_cookieid, 'c_post', $questionid, @$answer['postid'], $commentid); qa_redirect($qa_request, null, null, null, qa_anchor(isset($answer) ? 'A' : 'Q', $parent['postid'])); } else { $pageerror = qa_lang_html('question/duplicate_content'); } } else { $formtype = 'c_add'; $formpostid = $parent['postid']; // show form again } } break; } }