Exemple #1
0
function qa_post_create($type, $parentid, $title, $content, $format = '', $categoryid = null, $tags = null, $userid = null, $notify = null, $email = null, $extravalue = null)
{
    $handle = qa_post_userid_to_handle($userid);
    $text = qa_post_content_to_text($content, $format);
    switch ($type) {
        case 'Q':
        case 'Q_QUEUED':
            $followanswer = isset($parentid) ? qa_post_get_full($parentid, '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, $extravalue, $type == 'Q_QUEUED');
            break;
        case 'A':
        case 'A_QUEUED':
            $question = qa_post_get_full($parentid, 'Q');
            $postid = qa_answer_create($userid, $handle, null, $content, $format, $text, $notify, $email, $question, $type == 'A_QUEUED');
            break;
        case 'C':
        case 'C_QUEUED':
            $parent = qa_post_get_full($parentid, 'QA');
            $commentsfollows = qa_db_single_select(qa_db_full_child_posts_selectspec(null, $parentid));
            $question = qa_post_parent_to_question($parent);
            $postid = qa_comment_create($userid, $handle, null, $content, $format, $text, $notify, $email, $question, $parent, $commentsfollows, $type == 'C_QUEUED');
            break;
        default:
            qa_fatal_error('Post type not recognized: ' . $type);
            break;
    }
    return $postid;
}
Exemple #2
0
function qa_page_q_add_a_submit($question, $answers, $usecaptcha, &$in, &$errors)
{
    $in = array('name' => qa_post_text('a_name'), 'notify' => qa_post_text('a_notify') !== null, 'email' => qa_post_text('a_email'), 'queued' => qa_user_moderation_reason(qa_user_level_for_post($question)) !== false);
    qa_get_post_content('a_editor', 'a_content', $in['editor'], $in['content'], $in['format'], $in['text']);
    $errors = array();
    if (!qa_check_form_security_code('answer-' . $question['postid'], qa_post_text('code'))) {
        $errors['content'] = qa_lang_html('misc/form_security_again');
    } else {
        // call any filter plugins
        $filtermodules = qa_load_modules_with('filter', 'filter_answer');
        foreach ($filtermodules as $filtermodule) {
            $oldin = $in;
            $filtermodule->filter_answer($in, $errors, $question, null);
            qa_update_post_text($in, $oldin);
        }
        // check CAPTCHA
        if ($usecaptcha) {
            qa_captcha_validate_post($errors);
        }
        // check for duplicate posts
        if (empty($errors)) {
            $testwords = implode(' ', qa_string_to_words($in['content']));
            foreach ($answers as $answer) {
                if (!$answer['hidden']) {
                    if (implode(' ', qa_string_to_words($answer['content'])) == $testwords) {
                        $errors['content'] = qa_lang_html('question/duplicate_content');
                    }
                }
            }
        }
        $userid = qa_get_logged_in_userid();
        // if this is an additional answer, check we can add it
        if (empty($errors) && !qa_opt('allow_multi_answers')) {
            foreach ($answers as $answer) {
                if (qa_post_is_by_user($answer, $userid, qa_cookie_get())) {
                    $errors[] = '';
                    break;
                }
            }
        }
        // create the answer
        if (empty($errors)) {
            $handle = qa_get_logged_in_handle();
            $cookieid = isset($userid) ? qa_cookie_get() : qa_cookie_get_create();
            // create a new cookie if necessary
            $answerid = qa_answer_create($userid, $handle, $cookieid, $in['content'], $in['format'], $in['text'], $in['notify'], $in['email'], $question, $in['queued'], $in['name']);
            return $answerid;
        }
    }
    return null;
}
 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_add_a_submit($question, $answers, $usecaptcha, &$in, &$errors)
{
    $in = array('notify' => qa_post_text('a_notify') ? true : false, 'email' => qa_post_text('a_email'), 'queued' => qa_user_moderation_reason() ? true : false);
    qa_get_post_content('a_editor', 'a_content', $in['editor'], $in['content'], $in['format'], $in['text']);
    $errors = array();
    $filtermodules = qa_load_modules_with('filter', 'filter_answer');
    foreach ($filtermodules as $filtermodule) {
        $oldin = $in;
        $filtermodule->filter_answer($in, $errors, $question, 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 ($answers as $answer) {
            if (!$answer['hidden']) {
                if (implode(' ', qa_string_to_words($answer['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
        $answerid = qa_answer_create($userid, $handle, $cookieid, $in['content'], $in['format'], $in['text'], $in['notify'], $in['email'], $question, $in['queued']);
        return $answerid;
    }
    return null;
}
             }
             if (empty($errors)) {
                 $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');
                 }
             } else {
                 $formtype = 'a_add';
                 // show form again
             }
         } else {
             $formtype = 'a_add';
             // show form as if first time
         }
         break;
 }