Example #1
0
        if (empty($errors)) {
            $cookieid = isset($userid) ? qa_cookie_get() : qa_cookie_get_create();
            // create a new cookie if necessary
            $questionid = qa_question_create($followanswer, $userid, qa_get_logged_in_handle(), $cookieid, $in['title'], $in['content'], $in['format'], $in['text'], qa_tags_to_tagstring($in['tags']), $in['notify'], $in['email'], $in['categoryid'], $in['extra'], $in['queued'], $in['name']);
            qa_redirect(qa_q_request($questionid, $in['title']));
            // our work is done here
        }
    }
}
//	Prepare content for theme
$qa_content = qa_content_prepare(false, array_keys(qa_category_path($categories, @$in['categoryid'])));
$qa_content['title'] = qa_lang_html(isset($followanswer) ? 'question/ask_follow_title' : 'question/ask_title');
$qa_content['error'] = @$errors['page'];
$editorname = isset($in['editor']) ? $in['editor'] : qa_opt('editor_for_qs');
$editor = qa_load_editor(@$in['content'], @$in['format'], $editorname);
$field = qa_editor_load_field($editor, $qa_content, @$in['content'], @$in['format'], 'content', 12, false);
$field['label'] = qa_lang_html('question/q_content_label');
$field['error'] = qa_html(@$errors['content']);
$custom = qa_opt('show_custom_ask') ? trim(qa_opt('custom_ask')) : '';
$qa_content['form'] = array('tags' => 'name="ask" method="post" action="' . qa_self_html() . '"', 'style' => 'tall', 'fields' => array('custom' => array('type' => 'custom', 'note' => $custom), 'title' => array('label' => qa_lang_html('question/q_title_label'), 'tags' => 'name="title" id="title" autocomplete="off"', 'value' => qa_html(@$in['title']), 'error' => qa_html(@$errors['title'])), 'similar' => array('type' => 'custom', 'html' => '<span id="similar"></span>'), 'content' => $field), 'buttons' => array('ask' => array('tags' => 'onclick="qa_show_waiting_after(this, false); ' . (method_exists($editor, 'update_script') ? $editor->update_script('content') : '') . '"', 'label' => qa_lang_html('question/ask_button'))), 'hidden' => array('editor' => qa_html($editorname), 'code' => qa_get_form_security_code('ask'), 'doask' => '1'));
if (!strlen($custom)) {
    unset($qa_content['form']['fields']['custom']);
}
if (qa_opt('do_ask_check_qs') || qa_opt('do_example_tags')) {
    $qa_content['script_rel'][] = 'qa-content/qa-ask.js?' . QA_VERSION;
    $qa_content['form']['fields']['title']['tags'] .= ' onchange="qa_title_change(this.value);"';
    if (strlen(@$in['title'])) {
        $qa_content['script_onloads'][] = 'qa_title_change(' . qa_js($in['title']) . ');';
    }
}
if (isset($followanswer)) {
function qa_page_q_add_c_form(&$qa_content, $questionid, $parentid, $formid, $usecaptcha, $in, $errors, $loadfocusnow)
{
    switch (qa_user_permit_error('permit_post_c')) {
        case 'login':
            $form = array('title' => qa_insert_login_links(qa_lang_html('question/comment_must_login'), qa_request()));
            break;
        case 'confirm':
            $form = array('title' => qa_insert_login_links(qa_lang_html('question/comment_must_confirm'), qa_request()));
            break;
        case 'limit':
            $form = array('title' => qa_lang_html('question/comment_limit'));
            break;
        default:
            $form = array('title' => qa_lang_html('users/no_permission'));
            break;
        case false:
            $prefix = 'c' . $parentid . '_';
            $editorname = isset($in['editor']) ? $in['editor'] : qa_opt('editor_for_cs');
            $editor = qa_load_editor(@$in['content'], @$in['format'], $editorname);
            if (method_exists($editor, 'update_script')) {
                $updatescript = $editor->update_script($prefix . 'content');
            } else {
                $updatescript = '';
            }
            $custom = qa_opt('show_custom_comment') ? trim(qa_opt('custom_comment')) : '';
            $form = array('tags' => 'METHOD="POST" ACTION="' . qa_self_html() . '" NAME="c_form_' . qa_html($parentid) . '"', 'title' => qa_lang_html($questionid == $parentid ? 'question/your_comment_q' : 'question/your_comment_a'), 'fields' => array('custom' => array('type' => 'custom', 'note' => $custom), 'content' => array_merge(qa_editor_load_field($editor, $qa_content, @$in['content'], @$in['format'], $prefix . 'content', 4, $loadfocusnow, $loadfocusnow), array('error' => qa_html(@$errors['content'])))), 'buttons' => array('comment' => array('tags' => 'onClick="' . $updatescript . ' return qa_submit_comment(' . qa_js($questionid) . ', ' . qa_js($parentid) . ', this);"', 'label' => qa_lang_html('question/add_comment_button')), 'cancel' => array('tags' => 'NAME="docancel"', 'label' => qa_lang_html('main/cancel_button'))), 'hidden' => array($prefix . 'editor' => qa_html($editorname), $prefix . 'doadd' => '1'));
            if (!strlen($custom)) {
                unset($form['fields']['custom']);
            }
            qa_set_up_notify_fields($qa_content, $form['fields'], 'C', qa_get_logged_in_email(), isset($in['notify']) ? $in['notify'] : qa_opt('notify_users_default'), $in['email'], @$errors['email'], $prefix);
            $onloads = array();
            if ($usecaptcha) {
                $userid = qa_get_logged_in_userid();
                $captchaloadscript = qa_set_up_captcha_field($qa_content, $form['fields'], $errors, qa_insert_login_links(qa_lang_html(isset($userid) ? 'misc/captcha_confirm_fix' : 'misc/captcha_login_fix')));
                if (strlen($captchaloadscript)) {
                    $onloads[] = 'document.getElementById(' . qa_js($formid) . ').qa_show=function() { ' . $captchaloadscript . ' }';
                }
            }
            if (!$loadfocusnow) {
                if (method_exists($editor, 'load_script')) {
                    $onloads[] = 'document.getElementById(' . qa_js($formid) . ').qa_load=function() { ' . $editor->load_script($prefix . 'content') . ' }';
                }
                if (method_exists($editor, 'focus_script')) {
                    $onloads[] = 'document.getElementById(' . qa_js($formid) . ').qa_focus=function() { ' . $editor->focus_script($prefix . 'content') . ' }';
                }
                $form['buttons']['cancel']['tags'] .= ' onClick="return qa_toggle_element()"';
            }
            if (count($onloads)) {
                $qa_content['script_onloads'][] = $onloads;
            }
    }
    $form['id'] = $formid;
    $form['collapse'] = !$loadfocusnow;
    $form['style'] = 'tall';
    return $form;
}
function qa_page_q_edit_c_form(&$qa_content, $id, $comment, $in, $errors)
{
    $commentid = $comment['postid'];
    $prefix = 'c' . $commentid . '_';
    $content = isset($in['content']) ? $in['content'] : $comment['content'];
    $format = isset($in['format']) ? $in['format'] : $comment['format'];
    $editorname = isset($in['editor']) ? $in['editor'] : qa_opt('editor_for_cs');
    $editor = qa_load_editor($content, $format, $editorname);
    $form = array('tags' => 'method="post" action="' . qa_self_html() . '"', 'id' => $id, 'title' => qa_lang_html('question/edit_c_title'), 'style' => 'tall', 'fields' => array('content' => array_merge(qa_editor_load_field($editor, $qa_content, $content, $format, $prefix . 'content', 4, true), array('error' => qa_html(@$errors['content'])))), 'buttons' => array('save' => array('tags' => 'onclick="qa_show_waiting_after(this, false); ' . (method_exists($editor, 'update_script') ? $editor->update_script($prefix . 'content') : '') . '"', 'label' => qa_lang_html('main/save_button')), 'cancel' => array('tags' => 'name="docancel"', 'label' => qa_lang_html('main/cancel_button'))), 'hidden' => array($prefix . 'editor' => qa_html($editorname), $prefix . 'dosave' => '1', $prefix . 'code' => qa_get_form_security_code('edit-' . $commentid)));
    if ($comment['isbyuser']) {
        if (!qa_is_logged_in()) {
            qa_set_up_name_field($qa_content, $form['fields'], isset($in['name']) ? $in['name'] : @$comment['name'], $prefix);
        }
        qa_set_up_notify_fields($qa_content, $form['fields'], 'C', qa_get_logged_in_email(), isset($in['notify']) ? $in['notify'] : !empty($comment['notify']), isset($in['email']) ? $in['email'] : @$comment['notify'], @$errors['email'], $prefix);
    }
    if (!qa_user_post_permit_error('permit_edit_silent', $comment)) {
        $form['fields']['silent'] = array('type' => 'checkbox', 'label' => qa_lang_html('question/save_silent_label'), 'tags' => 'name="' . $prefix . 'silent"', 'value' => qa_html(@$in['silent']));
    }
    return $form;
}
function qa_get_request_content()
{
    $qa_content = qa_get_request_content_base();
    // displays signature form in user profile
    $qa_request = strtolower(qa_request());
    $reqs = explode('/', $qa_request);
    if ($reqs[0] == 'user') {
        // permissions
        if (isset($qa_content['form_profile']['fields']['permits'])) {
            $ov = $qa_content['form_profile']['fields']['permits']['value'];
            $ov = str_replace('[profile/signature_allow]', qa_lang('signature_plugin/signature_allow'), $ov);
            $ov = str_replace('[profile/signature_edit_allow]', qa_lang('signature_plugin/signature_edit_allow'), $ov);
            $qa_content['form_profile']['fields']['permits']['value'] = $ov;
        }
        $qa_content['user_signature_form'] = array();
        $userid = @$qa_content['raw']['userid'];
        if (!$userid) {
            return $qa_content;
        }
        $handles = qa_userids_to_handles(array($userid));
        $handle = $handles[$userid];
        if (qa_get_logged_in_handle() == $handle && !qa_user_permit_error('signature_allow') || !qa_user_permit_error('signature_edit_allow')) {
            $ok = null;
            $formats = qa_list_modules('editor');
            $format = qa_opt('signatures_format');
            $editorname = $formats[$format];
            if (!strlen($editorname)) {
                $editorname = qa_lang_html('admin/basic_editor');
            }
            $editor = qa_load_editor('', '', $editorname);
            qa_db_query_sub('CREATE TABLE IF NOT EXISTS ^usersignatures (' . 'userid INT(11) NOT NULL,' . 'signature VARCHAR (1000) DEFAULT \'\',' . 'format VARCHAR (20) DEFAULT \'\',' . 'id INT(11) NOT NULL AUTO_INCREMENT,' . 'UNIQUE (userid),' . 'PRIMARY KEY (id)' . ') ENGINE=MyISAM DEFAULT CHARSET=utf8');
            if (qa_clicked('signature_save')) {
                if (strlen(qa_post_text('signature_text')) > qa_opt('signatures_length')) {
                    $error = 'Max possible signature length is 1000 characters';
                } else {
                    $readdata = $editor->read_post('signature_text');
                    $informat = $readdata['format'];
                    $incontent = qa_post_text('signature_text');
                    qa_db_query_sub('INSERT INTO ^usersignatures (userid,signature,format) VALUES (#,$,$) ON DUPLICATE KEY UPDATE signature=$,format=$', $userid, $incontent, $informat, $incontent, $informat);
                    $ok = 'Signature Saved.';
                }
            }
            $content = qa_db_read_one_assoc(qa_db_query_sub('SELECT BINARY signature AS signature,format FROM ^usersignatures WHERE userid=#', $userid), true);
            $field = qa_editor_load_field($editor, $qa_content, $content['signature'], $content['format'], 'signature_text', 12, false);
            $field['label'] = qa_lang_html('signature_plugin/signature');
            $fields['content'] = $field;
            if (!$editorname || $editorname == 'Markdown Editor') {
                $fields['elCount'] = array('label' => '<div id="elCount">' . qa_opt('signatures_length') . '</div>', 'type' => 'static');
            }
            $form = array('ok' => $ok && !isset($error) ? $ok : null, 'error' => @$error, 'style' => 'tall', 'title' => '<a name="signature_text"></a>' . qa_lang_html('signature_plugin/signature'), 'tags' => 'action="' . qa_self_html() . '#signature_text" method="POST"', 'fields' => $fields, 'buttons' => array(array('label' => qa_lang_html('main/save_button'), 'tags' => 'NAME="signature_save"')), 'hidden' => array('editor' => qa_html($editorname), 'dosavesig' => '1'));
            $qa_content['user_signature_form'] = $form;
        } else {
            if (qa_opt('signatures_profile_enable')) {
                $content = qa_db_read_one_assoc(qa_db_query_sub('SELECT BINARY signature as signature, format FROM ^usersignatures WHERE userid=#', $userid), true);
                if (!$content) {
                    return $qa_content;
                }
                $informat = $content['format'];
                $viewer = qa_load_viewer($content['signature'], $informat);
                global $options;
                $signature = qa_viewer_html($content['signature'], $informat, array('blockwordspreg' => @$options['blockwordspreg'], 'showurllinks' => @$options['showurllinks'], 'linksnewwindow' => @$options['linksnewwindow']));
                $fields[] = array('label' => qa_opt('signatures_header') . $signature . qa_opt('signatures_footer'), 'type' => 'static');
                $qa_content['user_signature_form'] = array('title' => 'Signature', 'fields' => $fields, 'style' => 'tall');
            }
        }
    }
    return $qa_content;
}
Example #5
0
function qa_page_q_add_c_form(&$qa_content, $question, $parent, $formid, $captchareason, $in, $errors, $loadfocusnow)
{
    // The 'approve', 'login', 'confirm', 'userblock', 'ipblock' permission errors are reported to the user here
    // The other option ('level') prevents the comment button being shown, in qa_page_q_post_rules(...)
    switch (qa_user_post_permit_error('permit_post_c', $parent, QA_LIMIT_COMMENTS)) {
        case 'login':
            $form = array('title' => qa_insert_login_links(qa_lang_html('question/comment_must_login'), qa_request()));
            break;
        case 'confirm':
            $form = array('title' => qa_insert_login_links(qa_lang_html('question/comment_must_confirm'), qa_request()));
            break;
        case 'approve':
            $form = array('title' => qa_lang_html('question/comment_must_be_approved'));
            break;
        case 'limit':
            $form = array('title' => qa_lang_html('question/comment_limit'));
            break;
        default:
            $form = array('title' => qa_lang_html('users/no_permission'));
            break;
        case false:
            $prefix = 'c' . $parent['postid'] . '_';
            $editorname = isset($in['editor']) ? $in['editor'] : qa_opt('editor_for_cs');
            $editor = qa_load_editor(@$in['content'], @$in['format'], $editorname);
            if (method_exists($editor, 'update_script')) {
                $updatescript = $editor->update_script($prefix . 'content');
            } else {
                $updatescript = '';
            }
            $custom = qa_opt('show_custom_comment') ? trim(qa_opt('custom_comment')) : '';
            $form = array('tags' => 'method="post" action="' . qa_self_html() . '" name="c_form_' . qa_html($parent['postid']) . '"', 'title' => qa_lang_html($question['postid'] == $parent['postid'] ? 'question/your_comment_q' : 'question/your_comment_a'), 'fields' => array('custom' => array('type' => 'custom', 'note' => $custom), 'content' => array_merge(qa_editor_load_field($editor, $qa_content, @$in['content'], @$in['format'], $prefix . 'content', 4, $loadfocusnow, $loadfocusnow), array('error' => qa_html(@$errors['content'])))), 'buttons' => array('comment' => array('tags' => 'onclick="' . $updatescript . ' return qa_submit_comment(' . qa_js($question['postid']) . ', ' . qa_js($parent['postid']) . ', this);"', 'label' => qa_lang_html('question/add_comment_button')), 'cancel' => array('tags' => 'name="docancel"', 'label' => qa_lang_html('main/cancel_button'))), 'hidden' => array($prefix . 'editor' => qa_html($editorname), $prefix . 'doadd' => '1', $prefix . 'code' => qa_get_form_security_code('comment-' . $parent['postid'])));
            if (!strlen($custom)) {
                unset($form['fields']['custom']);
            }
            if (!qa_is_logged_in()) {
                qa_set_up_name_field($qa_content, $form['fields'], @$in['name'], $prefix);
            }
            qa_set_up_notify_fields($qa_content, $form['fields'], 'C', qa_get_logged_in_email(), isset($in['notify']) ? $in['notify'] : qa_opt('notify_users_default'), $in['email'], @$errors['email'], $prefix);
            $onloads = array();
            if ($captchareason) {
                $captchaloadscript = qa_set_up_captcha_field($qa_content, $form['fields'], $errors, qa_captcha_reason_note($captchareason));
                if (strlen($captchaloadscript)) {
                    $onloads[] = 'document.getElementById(' . qa_js($formid) . ').qa_show=function() { ' . $captchaloadscript . ' };';
                }
            }
            if (!$loadfocusnow) {
                if (method_exists($editor, 'load_script')) {
                    $onloads[] = 'document.getElementById(' . qa_js($formid) . ').qa_load=function() { ' . $editor->load_script($prefix . 'content') . ' };';
                }
                if (method_exists($editor, 'focus_script')) {
                    $onloads[] = 'document.getElementById(' . qa_js($formid) . ').qa_focus=function() { ' . $editor->focus_script($prefix . 'content') . ' };';
                }
                $form['buttons']['cancel']['tags'] .= ' onclick="return qa_toggle_element()"';
            }
            if (count($onloads)) {
                $qa_content['script_onloads'][] = $onloads;
            }
    }
    $form['id'] = $formid;
    $form['collapse'] = !$loadfocusnow;
    $form['style'] = 'tall';
    return $form;
}
function qa_page_q_edit_c_form(&$qa_content, $id, $comment, $in, $errors)
{
    $commentid = $comment['postid'];
    $prefix = 'c' . $commentid . '_';
    $content = isset($in['content']) ? $in['content'] : $comment['content'];
    $format = isset($in['format']) ? $in['format'] : $comment['format'];
    $editorname = isset($in['editor']) ? $in['editor'] : qa_opt('editor_for_cs');
    $editor = qa_load_editor($content, $format, $editorname);
    $form = array('tags' => 'METHOD="POST" ACTION="' . qa_self_html() . '"', 'id' => $id, 'title' => qa_lang_html('question/edit_c_title'), 'style' => 'tall', 'fields' => array('content' => array_merge(qa_editor_load_field($editor, $qa_content, $content, $format, $prefix . 'content', 4, true), array('error' => qa_html(@$errors['content'])))), 'buttons' => array('save' => array('tags' => method_exists($editor, 'update_script') ? 'onClick="' . $editor->update_script($prefix . 'content') . '"' : '', 'label' => qa_lang_html('main/save_button')), 'cancel' => array('tags' => 'NAME="docancel"', 'label' => qa_lang_html('main/cancel_button'))), 'hidden' => array($prefix . 'editor' => qa_html($editorname), $prefix . 'dosave' => '1'));
    if ($comment['isbyuser']) {
        qa_set_up_notify_fields($qa_content, $form['fields'], 'C', qa_get_logged_in_email(), isset($in['notify']) ? $in['notify'] : !empty($comment['notify']), isset($in['email']) ? $in['email'] : @$comment['notify'], @$errors['email'], $prefix);
    }
    return $form;
}
Example #7
0
    public function process_request($request)
    {
        $qa_content = qa_content_prepare();
        $category_1 = qa_opt('qa_blog_cat_1');
        $category_2 = qa_opt('qa_blog_cat_2');
        $category_3 = qa_opt('qa_blog_cat_3');
        $category_4 = qa_opt('qa_blog_cat_4');
        $category_5 = qa_opt('qa_blog_cat_5');
        $html = "";
        $postid = qa_request_part(1);
        if (isset($postid)) {
            $result = qa_db_query_sub('SELECT * FROM ^blog_posts WHERE `postid` LIKE #', $postid);
            if ($row = mysqli_fetch_array($result)) {
                $userid = $row['userid'];
                $author = handleLinkForID($row['userid']);
                $editor = qa_get_logged_in_userid();
                if ($userid >= $editor) {
                    if (qa_clicked('doedit')) {
                        $in = array();
                        qa_get_post_content('editor', 'content', $in['editor'], $in['content'], $in['format'], $in['text']);
                        $in['title'] = qa_post_text('title');
                        $in['category'] = qa_post_text('category');
                        if (strlen($in['title']) < 10 || strlen($in['content']) < 50 || $in['category'] !== 'cat_0' && $in['category'] !== 'cat_1' && $in['category'] !== 'cat_2' && $in['category'] !== 'cat_3' && $in['category'] !== 'cat_4' && $in['category'] !== 'cat_5') {
                            if (strlen($in['title']) < 10) {
                                $errors['title'] = qa_lang('qa_blog_lang/error_title');
                            }
                            if (strlen($in['content']) < 50) {
                                $errors['content'] = qa_lang('qa_blog_lang/error_content');
                            }
                            if ($in['category'] !== 'cat_0' && $in['category'] !== 'cat_1' && $in['category'] !== 'cat_2' && $in['category'] !== 'cat_3' && $in['category'] !== 'cat_4' && $in['category'] !== 'cat_5') {
                                $errors['type'] = 'Invalid category';
                            }
                        } else {
                            $type = 0;
                            if ($in['category'] === 'cat_1') {
                                $type = 1;
                            } else {
                                if ($in['category'] === 'cat_2') {
                                    $type = 2;
                                } else {
                                    if ($in['category'] === 'cat_3') {
                                        $type = 3;
                                    } else {
                                        if ($in['category'] === 'cat_4') {
                                            $type = 4;
                                        } else {
                                            if ($in['category'] === 'cat_5') {
                                                $type = 5;
                                            }
                                        }
                                    }
                                }
                            }
                            $result = qa_db_query_sub('UPDATE ^blog_posts SET updated=NOW(), title=$, content=$, type=#, format=$ WHERE postid=#', $in['title'], $in['content'], $type, 'markdown', $postid);
                            header('location:' . qa_path_to_root() . '/blog/' . $postid);
                        }
                    } else {
                        if (qa_clicked('doresetoptions')) {
                            $in = array();
                            qa_get_post_content('editor', 'content', $in['editor'], $in['content'], $in['format'], $in['text']);
                            $in['title'] = qa_post_text('title');
                            $in['category'] = qa_post_text('category');
                            if (strlen($in['title']) < 10 || strlen($in['content']) < 50 || $in['category'] !== 'cat_0' && $in['category'] !== 'cat_1' && $in['category'] !== 'cat_2' && $in['category'] !== 'cat_3' && $in['category'] !== 'cat_4' && $in['category'] !== 'cat_5') {
                                if (strlen($in['title']) < 10) {
                                    $errors['title'] = qa_lang('qa_blog_lang/error_title');
                                }
                                if (strlen($in['content']) < 50) {
                                    $errors['content'] = qa_lang('qa_blog_lang/error_content');
                                }
                                if ($in['category'] !== 'cat_0' && $in['category'] !== 'cat_1' && $in['category'] !== 'cat_2' && $in['category'] !== 'cat_3' && $in['category'] !== 'cat_4' && $in['category'] !== 'cat_5') {
                                    $errors['type'] = 'Invalid category';
                                }
                            } else {
                                $type = 0;
                                if ($in['category'] === 'cat_1') {
                                    $type = 1;
                                } else {
                                    if ($in['category'] === 'cat_2') {
                                        $type = 2;
                                    } else {
                                        if ($in['category'] === 'cat_3') {
                                            $type = 3;
                                        } else {
                                            if ($in['category'] === 'cat_4') {
                                                $type = 4;
                                            } else {
                                                if ($in['category'] === 'cat_5') {
                                                    $type = 5;
                                                }
                                            }
                                        }
                                    }
                                }
                                $result = qa_db_query_sub('UPDATE ^blog_posts SET updated=NOW(), title=$, content=$, type=#, format=$ WHERE postid=#', $in['title'], $in['content'], $type, 'draft', $postid);
                                header('location:' . qa_path_to_root() . '/blog/' . $postid);
                            }
                        } else {
                            if (qa_clicked('dogoback')) {
                                qa_redirect('blog');
                            } else {
                                if (qa_clicked('dosaveoptions')) {
                                    qa_redirect('blog');
                                } else {
                                    if (qa_clicked('docancel')) {
                                        qa_redirect('blog');
                                    }
                                }
                            }
                        }
                    }
                }
                $qa_content['title'] = 'Editing: ' . $row['title'];
                $userpostslink = '/user/' . qa_get_logged_in_handle() . '/articles';
                $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);
                $typeoptions = array('cat_1' => $category_1, 'cat_2' => $category_2, 'cat_3' => $category_3, 'cat_4' => $category_4, 'cat_5' => $category_5);
                $qa_content['form'] = array('tags' => 'name="edit" method="post" action="' . qa_self_html() . '"', 'style' => 'tall', 'fields' => array('title' => array('label' => qa_lang('qa_blog_lang/post_title'), 'tags' => 'name="title" id="title" autocomplete="off"', 'value' => $row['title'], 'rows' => 2, 'error' => qa_html(@$errors['title'])), 'category' => array('label' => qa_lang('qa_blog_lang/post_cat'), 'type' => 'select', 'tags' => 'name="category"', 'options' => $typeoptions, 'error' => qa_html(@$errors['type'])), 'similar' => array('type' => 'custom', 'html' => '<span id="similar"></span>'), 'content' => array('value' => $row['content'], 'tags' => 'name="content"', 'error' => qa_html(@$errors['content']), 'rows' => 4)), 'buttons' => array('edit' => array('tags' => 'onclick="qa_show_waiting_after(this, false); ' . (method_exists($editor, 'update_script') ? $editor->update_script('content') : '') . '"', 'label' => qa_lang('qa_blog_lang/update_button')), 'save' => array('tags' => 'name="doresetoptions"', 'label' => qa_lang('qa_blog_lang/draft_button')), 'hide' => array('tags' => 'name="dosaveoptions"', 'label' => qa_lang('qa_blog_lang/hide_button')), 'goback' => array('tags' => 'name="dogoback"', 'label' => qa_lang('qa_blog_lang/cancel_button')), 'cancel' => array('tags' => 'name="docancel"', 'label' => qa_lang('qa_blog_lang/delete_button'))), 'hidden' => array('editor' => qa_html($editorname), 'code' => qa_get_form_security_code('article'), 'doedit' => '1'));
                $html = "<h2>" . qa_lang('qa_blog_lang/past_post') . "</h2>";
                $userid = qa_get_logged_in_userid();
                $result = qa_db_query_sub("SELECT * FROM ^blog_posts WHERE userid =  '{$userid}' ORDER BY posted DESC");
                $i = 0;
                while ($blob = mysqli_fetch_array($result)) {
                    $i++;
                    $html .= '<ul><li><h3><a href="blog/' . $blob['postid'] . '/' . seoUrl3($blob['title']) . '">' . $blob['title'] . '</a><h3></li></ul>';
                }
                if ($i == 0) {
                    $html .= qa_lang('qa_blog_lang/post_null');
                }
                $html .= '';
                $qa_content['custom2'] = $html;
            } else {
                $site_url = qa_opt('site_url');
                $qa_content['title'] = qa_lang('qa_blog_lang/title_error');
                $qa_content['error'] = qa_lang('qa_blog_lang/edit_error') . '<a href=' . $site_url . '/blog/>
		' . qa_lang('qa_blog_lang/edit_error1') . '</a>';
                $qa_content['custom2'] = qa_lang('qa_blog_lang/edit_note');
            }
            return $qa_content;
        }
    }
Example #8
0
    public function process_request($request)
    {
        $category_1 = qa_opt('qa_blog_cat_1');
        $category_2 = qa_opt('qa_blog_cat_2');
        $category_3 = qa_opt('qa_blog_cat_3');
        $category_4 = qa_opt('qa_blog_cat_4');
        $category_5 = qa_opt('qa_blog_cat_5');
        $qa_content = qa_content_prepare();
        $errors = array();
        if (qa_clicked('docancel')) {
            qa_redirect('blog');
        } else {
            if (qa_clicked('dosaveoptions')) {
                $in = array();
                qa_get_post_content('editor', 'content', $in['editor'], $in['content'], $in['format'], $in['text']);
                $in['title'] = qa_post_text('title');
                $in['category'] = qa_post_text('category');
                if (strlen($in['title']) < 10 || strlen($in['content']) < 50 || $in['category'] !== 'cat_0' && $in['category'] !== 'cat_1' && $in['category'] !== 'cat_2' && $in['category'] !== 'cat_3' && $in['category'] !== 'cat_4' && $in['category'] !== 'cat_5') {
                    if (strlen($in['title']) < 10) {
                        $errors['title'] = qa_lang('qa_blog_lang/error_title');
                    }
                    if (strlen($in['content']) < 50) {
                        $errors['content'] = qa_lang('qa_blog_lang/error_content');
                    }
                    if ($in['category'] !== 'cat_0' && $in['category'] !== 'cat_1' && $in['category'] !== 'cat_2' && $in['category'] !== 'cat_3' && $in['category'] !== 'cat_4' && $in['category'] !== 'cat_5') {
                        $errors['type'] = 'Invalid category';
                    }
                } else {
                    $type = 0;
                    if ($in['category'] === 'cat_1') {
                        $type = 1;
                    } else {
                        if ($in['category'] === 'cat_2') {
                            $type = 2;
                        } else {
                            if ($in['category'] === 'cat_3') {
                                $type = 3;
                            } else {
                                if ($in['category'] === 'cat_4') {
                                    $type = 4;
                                } else {
                                    if ($in['category'] === 'cat_5') {
                                        $type = 5;
                                    }
                                }
                            }
                        }
                    }
                    qa_db_query_sub('INSERT INTO ^blog_posts (postid, userid, posted, title, type, content, views,format) 
				VALUES (0,#,NOW(),$,#,$,0,$)', qa_get_logged_in_userid(), $in['title'], $type, $in['content'], 'draft');
                    header('location:' . qa_path_to_root() . '/user/' . qa_get_logged_in_handle() . '');
                }
            } else {
                if (qa_clicked('doarticle')) {
                    $in = array();
                    qa_get_post_content('editor', 'content', $in['editor'], $in['content'], $in['format'], $in['text']);
                    $in['title'] = qa_post_text('title');
                    $in['category'] = qa_post_text('category');
                    if (strlen($in['title']) < 10 || strlen($in['content']) < 50 || $in['category'] !== 'cat_0' && $in['category'] !== 'cat_1' && $in['category'] !== 'cat_2' && $in['category'] !== 'cat_3' && $in['category'] !== 'cat_4' && $in['category'] !== 'cat_5') {
                        if (strlen($in['title']) < 10) {
                            $errors['title'] = qa_lang('qa_blog_lang/error_title');
                        }
                        if (strlen($in['content']) < 50) {
                            $errors['content'] = qa_lang('qa_blog_lang/error_content');
                        }
                        if ($in['category'] !== 'cat_0' && $in['category'] !== 'cat_1' && $in['category'] !== 'cat_2' && $in['category'] !== 'cat_3' && $in['category'] !== 'cat_4' && $in['category'] !== 'cat_5') {
                            $errors['type'] = 'Invalid category';
                        }
                    } else {
                        $type = 0;
                        if ($in['category'] === 'cat_1') {
                            $type = 1;
                        } else {
                            if ($in['category'] === 'cat_2') {
                                $type = 2;
                            } else {
                                if ($in['category'] === 'cat_3') {
                                    $type = 3;
                                } else {
                                    if ($in['category'] === 'cat_4') {
                                        $type = 4;
                                    } else {
                                        if ($in['category'] === 'cat_5') {
                                            $type = 5;
                                        }
                                    }
                                }
                            }
                        }
                        $result = qa_db_query_sub('INSERT INTO ^blog_posts (postid, userid, posted, title, type, content, views,format) 
				VALUES (0,#,NOW(),$,#,$,0,$)', qa_get_logged_in_userid(), $in['title'], $type, $in['content'], 'markdown');
                        header('location:' . qa_path_to_root() . '/blog/');
                    }
                }
            }
        }
        if (qa_is_logged_in()) {
            $qa_content['title'] = qa_lang('qa_blog_lang/articles_page');
            $userpostslink = '/user/' . qa_get_logged_in_handle() . '/articles';
            $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'] = '';
            $field['error'] = qa_html(@$errors['content']);
            $qa_content['custom'] = qa_lang('qa_blog_lang/default_blog_tagline');
            $typeoptions = array('cat_1' => $category_1, 'cat_2' => $category_2, 'cat_3' => $category_3, 'cat_4' => $category_4, 'cat_5' => $category_5);
            $qa_content['form'] = array('tags' => 'name="blog" method="post" action="' . qa_self_html() . '"', 'style' => 'tall', 'fields' => array('title' => array('label' => qa_lang('qa_blog_lang/post_title'), 'tags' => 'name="title" id="title" autocomplete="off"', 'value' => qa_html(@$in['title']), 'error' => qa_html(@$errors['title'])), 'category' => array('label' => qa_lang('qa_blog_lang/post_cat'), 'type' => 'select', 'tags' => 'name="category"', 'options' => $typeoptions, 'error' => qa_html(@$errors['type'])), 'similar' => array('type' => 'custom', 'html' => '<span id="similar"></span>'), 'content' => $field), 'buttons' => array('post' => array('tags' => 'onclick="qa_show_waiting_after(this, false); ' . (method_exists($editor, 'update_script') ? $editor->update_script('content') : '') . '"', 'label' => qa_lang('qa_blog_lang/post_button')), 'save' => array('tags' => 'name="dosaveoptions"', 'label' => qa_lang('qa_blog_lang/draft_button')), 'cancel' => array('tags' => 'name="docancel"', 'label' => qa_lang('qa_blog_lang/cancel_button'))), 'hidden' => array('editor' => qa_html($editorname), 'code' => qa_get_form_security_code('article'), 'doarticle' => '1'));
            $html = "<h2>" . qa_lang('qa_blog_lang/past_post') . "</h2>";
            $userid = qa_get_logged_in_userid();
            $result = qa_db_query_sub("SELECT * FROM ^blog_posts WHERE userid =  '{$userid}' ORDER BY posted DESC");
            $i = 0;
            while ($blob = mysqli_fetch_array($result)) {
                $i++;
                $html .= '<ul><li><h3><a href="blog/' . $blob['postid'] . '/' . seoUrl3($blob['title']) . '">' . $blob['title'] . '</a><h3></li></ul>';
            }
            if ($i == 0) {
                $html .= qa_lang('qa_blog_lang/post_null');
            }
            $html .= '';
            $qa_content['custom2'] = $html;
        } else {
            $qa_content['title'] = qa_lang('qa_blog_lang/title_error');
            $qa_content['error'] = qa_insert_login_links(qa_lang('qa_blog_lang/access_error'), $request);
        }
        return $qa_content;
    }