Beispiel #1
0
$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)) {
    $viewer = qa_load_viewer($followanswer['content'], $followanswer['format']);
    $field = array('type' => 'static', 'label' => qa_lang_html('question/ask_follow_from_a'), 'value' => $viewer->get_html($followanswer['content'], $followanswer['format'], array('blockwordspreg' => qa_get_block_words_preg())));
    qa_array_insert($qa_content['form']['fields'], 'title', array('follows' => $field));
}
if (qa_using_categories() && count($categories)) {
    $field = array('label' => qa_lang_html('question/q_category_label'), 'error' => qa_html(@$errors['categoryid']));
    qa_set_up_category_field($qa_content, $field, 'category', $categories, $in['categoryid'], true, qa_opt('allow_no_sub_category'));
    if (!qa_opt('allow_no_category')) {
        // don't auto-select a category even though one is required
        $field['options'][''] = '';
    }
    qa_array_insert($qa_content['form']['fields'], 'content', array('category' => $field));
}
if (qa_opt('extra_field_active')) {
    $field = array('label' => qa_html(qa_opt('extra_field_prompt')), 'tags' => 'name="extra"', 'value' => qa_html(@$in['extra']), 'error' => qa_html(@$errors['extra']));
    qa_array_insert($qa_content['form']['fields'], null, array('extra' => $field));
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;
}
Beispiel #3
0
function qa_post_content_to_text($content, $format)
{
    $viewer = qa_load_viewer($content, $format);
    if (!isset($viewer)) {
        qa_fatal_error('Content could not be parsed in format: ' . $format);
    }
    return $viewer->get_text($content, $format, array());
}
Beispiel #4
0
 function post($event, $userid, $handle, $params, $type)
 {
     // remove mentions
     if (!qa_opt('buddypress_mentions')) {
         remove_filter('bp_activity_after_save', 'bp_activity_at_name_filter_updates');
     }
     switch ($type) {
         case 'Q':
             $suffix = ' question ';
             break;
         case 'A':
             $suffix = 'n %answer% to the question ';
             break;
         case 'C':
             $suffix = ' %comment% on the question ';
             break;
     }
     // poll integration
     if (qa_post_text('is_poll')) {
         if ($type == 'A') {
             return;
         }
         if ($type == 'Q') {
             $suffix = str_replace('question', 'poll', $suffix);
         } else {
             $suffix = str_replace('question', 'poll', $suffix);
         }
     }
     $content = $params['content'];
     // activity post
     if ($event != 'q_post') {
         $parent = qa_db_read_one_assoc(qa_db_query_sub('SELECT * FROM ^posts WHERE postid=#', $params['parentid']), true);
         if ($parent['type'] == 'A') {
             $parent = qa_db_read_one_assoc(qa_db_query_sub('SELECT * FROM ^posts WHERE postid=#', $parent['parentid']), true);
         }
         $anchor = qa_anchor($event == 'a_post' ? 'A' : 'C', $params['postid']);
         $suffix = preg_replace('/%([^%]+)%/', '<a href="' . qa_path_html(qa_q_request($parent['postid'], $parent['title']), null, qa_opt('site_url'), null, $anchor) . '">$1</a>', $suffix);
         $activity_url = qa_path_html(qa_q_request($parent['postid'], $parent['title']), null, qa_opt('site_url'));
         $context = $suffix . '"<a href="' . $activity_url . '">' . $parent['title'] . '</a>"';
     } else {
         $activity_url = qa_path_html(qa_q_request($params['postid'], $params['title']), null, qa_opt('site_url'));
         $context = $suffix . '"<a href="' . $activity_url . '">' . $params['title'] . '</a>"';
     }
     if (qa_opt('buddypress_display_names')) {
         $name = bp_core_get_user_displayname($handle) ? bp_core_get_user_displayname($handle) : $handle;
     } else {
         $name = $handle;
     }
     $action = '<a href="' . bp_core_get_user_domain($userid) . '" rel="nofollow">' . $name . '</a> posted a' . $context . ' at <a href="' . qa_opt('site_url') . '">' . qa_opt('site_title') . '</a>';
     if (qa_opt('buddypress_integration_include_content')) {
         $informat = $params['format'];
         $viewer = qa_load_viewer($content, $informat);
         if (qa_opt('buddypress_integration_max_post_length') && strlen($content) > (int) qa_opt('buddypress_integration_max_post_length')) {
             $content = substr($content, 0, (int) qa_opt('buddypress_integration_max_post_length'));
             $content = $content . ' ...';
         }
         $content = $viewer->get_html($content, $informat, array());
     } else {
         $content = null;
     }
     global $phpmailer;
     if (class_exists('PHPMailer') && !is_object($phpmailer)) {
         $phpmailer = new PHPMailer(true);
     }
     $act_id = qa_buddypress_activity_post(array('action' => $action, 'content' => $content, 'primary_link' => $activity_url, 'component' => 'bp-qa', 'type' => 'activity_qa_' . $type, 'user_id' => $userid, 'item_id' => null));
 }
Beispiel #5
0
function qa_viewer_html($content, $format, $options = array())
{
    $viewer = qa_load_viewer($content, $format);
    return $viewer->get_html($content, $format, $options);
}
 function get_full_post($post, $options, $usershtml)
 {
     $fields['raw'] = $post;
     $userid = qa_get_logged_in_userid();
     $cookieid = qa_cookie_get();
     $fields['netvotes_raw'] = (int) $post['netvotes'];
     $postid = $post['postid'];
     $isquestion = $post['basetype'] == 'Q';
     $isanswer = $post['basetype'] == 'A';
     $isbyuser = @$post['userid'] == $userid;
     $anchor = urlencode(qa_anchor($post['basetype'], $postid));
     $elementid = isset($options['elementid']) ? $options['elementid'] : $anchor;
     $microformats = false;
     $isselected = @$options['isselected'];
     // content
     if (@$options['contentview'] && !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 ($post['hidden']) {
         $fields['vote_state'] = 'disabled';
     } elseif ($isbyuser) {
         $fields['vote_state'] = 'disabled';
     } elseif (@$post['uservote'] > 0) {
         $fields['vote_state'] = 'voted_up';
     } elseif (@$post['uservote'] < 0) {
         $fields['vote_state'] = 'voted_down';
     } else {
         if (strpos($options['voteview'], '-uponly-level')) {
             $fields['vote_state'] = 'up_only';
         } else {
             $fields['vote_state'] = 'enabled';
         }
     }
     //	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'] && !$isquestion) {
             $fields['what_url'] = qa_path_html(qa_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 (@$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']));
         }
     }
     $isselected = @$options['isselected'];
     //	Updated when and by whom
     if (isset($post['opostid'])) {
         // updated meta
         switch ($post['obasetype'] . '-' . @$post['oupdatetype']) {
             case 'Q-':
                 $langstring = 'main/asked';
                 break;
             case 'Q-' . QA_UPDATE_VISIBLE:
                 $langstring = $post['hidden'] ? 'main/hidden' : 'main/reshown';
                 break;
             case 'Q-' . QA_UPDATE_CLOSED:
                 $langstring = isset($post['closedbyid']) ? 'main/closed' : 'main/reopened';
                 break;
             case 'Q-' . QA_UPDATE_TAGS:
                 $langstring = 'main/retagged';
                 break;
             case 'Q-' . QA_UPDATE_CATEGORY:
                 $langstring = 'main/recategorized';
                 break;
             case 'A-':
                 $langstring = 'main/answered';
                 break;
             case 'A-' . QA_UPDATE_SELECTED:
                 $langstring = 'main/answer_selected';
                 break;
             case 'A-' . QA_UPDATE_VISIBLE:
                 $langstring = $post['ohidden'] ? 'main/hidden' : 'main/answer_reshown';
                 break;
             case 'A-' . QA_UPDATE_CONTENT:
                 $langstring = 'main/answer_edited';
                 break;
             case 'Q-' . QA_UPDATE_FOLLOWS:
                 $langstring = 'main/asked_related_q';
                 break;
             case 'C-':
                 $langstring = 'main/commented';
                 break;
             case 'C-' . QA_UPDATE_TYPE:
                 $langstring = 'main/comment_moved';
                 break;
             case 'C-' . QA_UPDATE_VISIBLE:
                 $langstring = $post['ohidden'] ? 'main/hidden' : 'main/comment_reshown';
                 break;
             case 'C-' . QA_UPDATE_CONTENT:
                 $langstring = 'main/comment_edited';
                 break;
             case 'Q-' . QA_UPDATE_CONTENT:
             default:
                 $langstring = 'main/edited';
                 break;
         }
         $fields['what_2'] = qa_lang_html($langstring);
         if ($post['obasetype'] != 'Q' || @$post['oupdatetype'] == QA_UPDATE_FOLLOWS) {
             $fields['what_2_url'] = qa_q_path_html($post['postid'], $post['title'], false, $post['obasetype'], $post['opostid']);
         }
         if (@$options['contentview'] && !empty($post['ocontent'])) {
             $viewer = qa_load_viewer($post['ocontent'], $post['oformat']);
             $fields['content_2'] = $viewer->get_html($post['ocontent'], $post['oformat'], array('blockwordspreg' => @$options['blockwordspreg'], 'showurllinks' => @$options['showurllinks'], 'linksnewwindow' => @$options['linksnewwindow']));
         }
         if (@$options['whenview']) {
             $fields['when_2'] = qa_when_to_html($post['otime'], @$options['fulldatedays']);
         }
         if (@$options['whoview']) {
             $isbyuser = qa_post_is_by_user(array('userid' => $post['ouserid'], 'cookieid' => @$post['ocookieid']), $userid, $cookieid);
             $fields['who_2'] = qa_who_to_html($isbyuser, $post['ouserid'], $usershtml, @$options['ipview'] ? @$post['oip'] : null, false);
             if (isset($post['opoints'])) {
                 if (@$options['pointsview']) {
                     $fields['who_2']['points'] = $post['opoints'] == 1 ? qa_lang_html_sub_split('main/1_point', '1', '1') : qa_lang_html_sub_split('main/x_points', qa_html(number_format($post['opoints'])));
                 }
                 if (isset($options['pointstitle'])) {
                     $fields['who_2']['title'] = qa_get_points_title_html($post['opoints'], $options['pointstitle']);
                 }
             }
             if (isset($post['olevel'])) {
                 $fields['who_2']['level'] = qa_html(qa_user_level_string($post['olevel']));
             }
         }
     } else {
         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 (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);
             }
         }
     }
     $fields['avatar'] = $this->get_post_avatar($post);
     return $fields;
 }
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;
}
 function ajaxEditor(&$ineditor, &$incontent, &$informat, &$intext)
 {
     $ineditor = qa_post_text('editor');
     $editor = qa_load_module('editor', $ineditor);
     $readdata = $editor->read_post('ajax_comment_content');
     $incontent = $readdata['content'];
     $informat = $readdata['format'];
     $viewer = qa_load_viewer($incontent, $informat);
     $intext = $viewer->get_text($incontent, $informat, array());
 }
function qa_book_plugin_createBook($return = false)
{
    $book = qa_opt('book_plugin_template');
    // static replacements
    $book = str_replace('[css]', qa_opt('book_plugin_css'), $book);
    $book = str_replace('[front]', qa_opt('book_plugin_template_front'), $book);
    $book = str_replace('[back]', qa_opt('book_plugin_template_back'), $book);
    $iscats = qa_opt('book_plugin_cats');
    // categories
    if ($iscats) {
        $cats = qa_db_read_all_assoc(qa_db_query_sub('SELECT * FROM ^categories' . (qa_opt('book_plugin_catex') ? ' WHERE categoryid NOT IN (' . qa_opt('book_plugin_catex') . ')' : '')));
        $navcats = array();
        foreach ($cats as $cat) {
            $navcats[$cat['categoryid']] = $cat;
        }
    } else {
        $cats = array(false);
    }
    // intro
    $intro = qa_lang('book/intro');
    $intro = str_replace('[sort_questions]', qa_lang('book/' . (qa_opt('book_plugin_sort_q') == 0 ? 'sort_upvotes' : 'sort_date')), $intro);
    $intro = str_replace('[sort_categories]', $iscats ? qa_lang('book/sort_categories') : '', $intro);
    $intro = str_replace('[restrict_questions]', qa_opt('book_plugin_req_qv') ? qa_lang_sub('book/restrict_q_x_votes', qa_opt('book_plugin_req_qv_no')) : qa_lang('book/all_questions'), $intro);
    $rq = array();
    if (qa_opt('book_plugin_req_sel')) {
        $rq[] = qa_lang('book/restrict_selected');
    }
    if (qa_opt('book_plugin_req_abest')) {
        $rq[] = qa_lang('book/restrict_best_a');
    }
    if (qa_opt('book_plugin_req_av')) {
        $rq[] = qa_lang_sub('book/restrict_a_x_votes', qa_opt('book_plugin_req_av_no'));
    }
    if (empty($rq)) {
        $intro = str_replace('[restrict_answers]', '', $intro);
    } else {
        $rqs = qa_lang('book/restrict_answers_clause_' . count($rq));
        foreach ($rq as $i => $v) {
            $rqs = str_replace('(' . ($i + 1) . ')', $v, $rqs);
        }
        $intro = str_replace('[restrict_answers]', $rqs, $intro);
    }
    $book = str_replace('[intro]', $intro, $book);
    $tocout = '';
    $qout = '';
    foreach ($cats as $cat) {
        $incsql = '';
        $sortsql = '';
        $toc = '';
        $qhtml = '';
        if (qa_opt('book_plugin_sort_q') == 0) {
            $sortsql = 'ORDER BY qs.netvotes DESC, qs.created ASC';
        } else {
            $sortsql = 'ORDER BY qs.created ASC';
        }
        if (qa_opt('book_plugin_req_sel')) {
            $incsql .= ' AND qs.selchildid=ans.postid';
        }
        if (qa_opt('book_plugin_req_abest')) {
            $sortsql .= ', ans.netvotes DESC';
        }
        // get all, limit later with break
        if (qa_opt('book_plugin_req_qv')) {
            $incsql .= ' AND qs.netvotes >= ' . (int) qa_opt('book_plugin_req_qv_no');
        }
        if (qa_opt('book_plugin_req_av')) {
            $incsql .= ' AND ans.netvotes >= ' . (int) qa_opt('book_plugin_req_av_no');
        }
        $selectspec = "SELECT qs.postid AS postid, BINARY qs.title AS title, BINARY qs.content AS content, qs.format AS format, qs.netvotes AS netvotes, BINARY ans.content AS acontent, ans.format AS aformat, ans.userid AS auserid, ans.netvotes AS anetvotes FROM ^posts AS qs, ^posts AS ans WHERE qs.type='Q' AND ans.type='A' AND ans.parentid=qs.postid" . ($iscats ? " AND qs.categoryid=" . $cat['categoryid'] . " " : "") . $incsql . " " . $sortsql;
        $qs = qa_db_read_all_assoc(qa_db_query_sub($selectspec));
        if (empty($qs)) {
            // no questions in this category
            continue;
        }
        $q2 = array();
        foreach ($qs as $q) {
            // group by questions
            $q2['q' . $q['postid']][] = $q;
        }
        foreach ($q2 as $qs) {
            // toc entry
            $toc .= str_replace('[qlink]', '<a href="#question' . $qs[0]['postid'] . '">' . $qs[0]['title'] . '</a>', qa_opt('book_plugin_template_toc'));
            // answer html
            $as = '';
            $nv = false;
            foreach ($qs as $idx => $q) {
                if (qa_opt('book_plugin_req_abest') && qa_opt('book_plugin_req_abest_max') && $idx >= qa_opt('book_plugin_req_abest_max')) {
                    break;
                }
                if ($nv !== false && qa_opt('book_plugin_req_abest') && $nv != $q['anetvotes']) {
                    // best answers only
                    break;
                }
                $acontent = '';
                if (!empty($q['acontent'])) {
                    $viewer = qa_load_viewer($q['acontent'], $q['aformat']);
                    $acontent = $viewer->get_html($q['acontent'], $q['aformat'], array());
                }
                $a = str_replace('[answer]', $acontent, qa_opt('book_plugin_template_answer'));
                $a = str_replace('[answerer]', qa_get_user_name($q['auserid']), $a);
                $as .= $a;
                $nv = $q['anetvotes'];
            }
            // question html
            $qcontent = '';
            if (!empty($q['content'])) {
                $viewer = qa_load_viewer($q['content'], $q['format']);
                $qcontent = $viewer->get_html($q['content'], $q['format'], array());
            }
            $oneq = str_replace('[question-title]', $q['title'], qa_opt('book_plugin_template_question'));
            $oneq = str_replace('[qanchor]', 'question' . $q['postid'], $oneq);
            $oneq = str_replace('[qurl]', qa_html(qa_q_request($q['postid'], $q['title'])), $oneq);
            $oneq = str_replace('[question]', $qcontent, $oneq);
            // output with answers
            $qhtml .= str_replace('[answers]', $as, $oneq);
        }
        if ($iscats) {
            $tocout .= '<li><a href="#cat' . $cat['categoryid'] . '" class="toc-cat">' . $cat['title'] . '</a><ul class="toc-ul">' . $toc . '</ul></li>';
            // todo fix category link
            $catout = str_replace('[cat-url]', qa_path_html('questions/' . qa_category_path_request($navcats, $cat['categoryid'])), qa_opt('book_plugin_template_category'));
            $catout = str_replace('[cat-anchor]', 'cat' . $cat['categoryid'], $catout);
            $catout = str_replace('[cat-title]', $cat['title'], $catout);
            $catout = str_replace('[questions]', $qhtml, $catout);
            $qout .= $catout;
        } else {
            $tocout .= '<ul class="toc-ul">' . $toc . '</ul>';
            $catout = str_replace('[questions]', $qhtml, qa_opt('book_plugin_template_questions'));
            $qout .= $catout;
        }
    }
    if ($iscats) {
        $tocout = '<ul class="toc-ul">' . $tocout . '</ul>';
    }
    // add toc and questions
    $book = str_replace('[toc]', $tocout, $book);
    $book = str_replace('[categories]', $qout, $book);
    // misc subs
    $book = str_replace('[site-title]', qa_opt('site_title'), $book);
    $book = str_replace('[site-url]', qa_opt('site_url'), $book);
    $book = str_replace('[date]', date('M j, Y'), $book);
    qa_opt('book_plugin_refresh_last', time());
    error_log('Q2A Book Created on ' . date('M j, Y \\a\\t H\\:i\\:s'));
    if ($return) {
        return $book;
    }
    file_put_contents(qa_opt('book_plugin_loc'), $book);
    if (qa_opt('book_plugin_pdf')) {
        qa_book_plugin_create_pdf();
    }
    return 'Book Created';
    //return 'Error creating '.qa_opt('book_plugin_loc').'; check the error log.';
}
function qa_get_post_content($editorfield, $contentfield, &$ineditor, &$incontent, &$informat, &$intext)
{
    $ineditor = qa_post_text($editorfield);
    $editor = qa_load_module('editor', $ineditor);
    $readdata = $editor->read_post($contentfield);
    $incontent = $readdata['content'];
    $informat = $readdata['format'];
    $viewer = qa_load_viewer($incontent, $informat);
    $intext = $viewer->get_text($incontent, $informat, array());
}
function qa_news_plugin_createNewsletter($send)
{
    $news = qa_opt('news_plugin_template');
    // static replacements
    $news = str_replace('[css]', qa_opt('news_plugin_css'), $news);
    $lastdate = time() - qa_opt('news_plugin_send_days') * 24 * 60 * 60;
    if (qa_opt('news_plugin_max_q') > 0) {
        $selectspec = "SELECT postid, BINARY title AS title, BINARY content AS content, format, netvotes, userid FROM ^posts WHERE type='Q' AND FROM_UNIXTIME(#) <= created AND netvotes > 0 ORDER BY netvotes DESC, created ASC LIMIT " . (int) qa_opt('news_plugin_max_q');
        $sub = qa_db_query_sub($selectspec, $lastdate);
        while (($post = qa_db_read_one_assoc($sub, true)) !== null) {
            $qcontent = '';
            if (!empty($post['content'])) {
                $viewer = qa_load_viewer($post['content'], $post['format']);
                $content = $viewer->get_html($post['content'], $post['format'], array());
            }
            $one = str_replace('[question-title]', $post['title'], qa_opt('news_plugin_template_question'));
            $one = str_replace('[anchor]', 'question' . $post['postid'], $one);
            $one = str_replace('[url]', qa_html(qa_q_request($post['postid'], $post['title'])), $one);
            $one = str_replace('[question]', $content, $one);
            $votes = str_replace('[number]', ($post['netvotes'] > 0 ? '+' : ($post['netvotes'] < 0 ? '-' : '')) . $post['netvotes'], qa_opt('news_plugin_template_votes'));
            $one = str_replace('[voting]', $votes, $one);
            $uid = $post['userid'];
            $handles = qa_userids_to_handles(array($uid));
            $handle = $handles[$uid];
            $one = str_replace('[meta]', qa_lang_sub('newsletter/meta', '<a href="' . qa_opt('site_url') . 'user/' . $handle . '">' . $handle . '</a>'), $one);
            $qhtml[] = $one;
        }
    }
    if (qa_opt('news_plugin_max_a') > 0) {
        $selectspec = "SELECT a.postid AS postid, a.parentid AS parentid, BINARY a.content AS content, a.format AS format, a.netvotes AS netvotes, a.userid as userid, q.title AS qtitle FROM ^posts AS q, ^posts AS a WHERE a.type='A' AND q.postid=a.parentid AND FROM_UNIXTIME(#) <= a.created AND a.netvotes > 0 ORDER BY a.netvotes DESC, a.created ASC LIMIT " . (int) qa_opt('news_plugin_max_a');
        $sub = qa_db_query_sub($selectspec, $lastdate);
        while (($post = qa_db_read_one_assoc($sub, true)) !== null) {
            $content = '';
            if (!empty($post['content'])) {
                $viewer = qa_load_viewer($post['content'], $post['format']);
                $content = $viewer->get_html($post['content'], $post['format'], array());
            }
            $anchor = qa_anchor('C', $post['postid']);
            $purl = qa_path_html(qa_q_request($post['parentid'], $post['qtitle']), null, qa_opt('site_url'));
            $url = qa_path_html(qa_q_request($post['parentid'], $post['qtitle']), null, qa_opt('site_url'), null, $anchor);
            $response = qa_lang_sub('newsletter/response_to_question', '<a href="' . $purl . '">' . $post['qtitle'] . '</a>');
            $response = str_replace('[url]', $url, $response);
            $one = str_replace('[parent-ref]', $response, qa_opt('news_plugin_template_answer'));
            $one = str_replace('[anchor]', 'answer' . $post['postid'], $one);
            $one = str_replace('[answer]', $content, $one);
            $votes = str_replace('[number]', ($post['netvotes'] > 0 ? '+' : ($post['netvotes'] < 0 ? '-' : '')) . $post['netvotes'], qa_opt('news_plugin_template_votes'));
            $one = str_replace('[voting]', $votes, $one);
            $uid = $post['userid'];
            $handles = qa_userids_to_handles(array($uid));
            $handle = $handles[$uid];
            $one = str_replace('[meta]', qa_lang_sub('newsletter/meta', '<a href="' . qa_opt('site_url') . 'user/' . $handle . '">' . $handle . '</a>'), $one);
            $ahtml[] = $one;
        }
    }
    if (qa_opt('news_plugin_max_c') > 0) {
        $selectspec = "SELECT c.postid AS postid, c.parentid AS parentid, BINARY c.content AS content, c.format AS format, c.netvotes AS netvotes, c.userid as userid, p.title AS ptitle, p.parentid AS gpostid, g.title AS gtitle FROM ^posts AS c INNER JOIN ^posts AS p ON c.type='C' AND p.postid=c.parentid AND FROM_UNIXTIME(#) <= c.created LEFT JOIN ^posts AS g ON g.postid=p.parentid AND g.type='Q' AND c.netvotes > 0 ORDER BY c.netvotes DESC, c.created ASC LIMIT " . (int) qa_opt('news_plugin_max_a');
        $sub = qa_db_query_sub($selectspec, $lastdate);
        while (($post = qa_db_read_one_assoc($sub, true)) !== null) {
            $content = '';
            if (!empty($post['content'])) {
                $viewer = qa_load_viewer($post['content'], $post['format']);
                $content = $viewer->get_html($post['content'], $post['format'], array());
            }
            if (isset($post['gtitle'])) {
                $parent = 'answer';
                $title = $post['gtitle'];
                $parentid = $post['gpostid'];
                $aurl = qa_path_html(qa_q_request($post['parentid'], $title), null, qa_opt('site_url'), null, qa_anchor('A', $post['parentid']));
            } else {
                $parent = 'question';
                $title = $post['ptitle'];
                $parentid = $post['parentid'];
            }
            $anchor = qa_anchor('C', $post['postid']);
            $purl = qa_path_html(qa_q_request($parentid, $title), null, qa_opt('site_url'));
            $url = qa_path_html(qa_q_request($parentid, $title), null, qa_opt('site_url'), null, $anchor);
            $response = qa_lang_sub('newsletter/response_to_' . $parent, '<a href="' . $purl . '">' . $title . '</a>');
            $response = str_replace('[url]', $url, $response);
            if (isset($aurl)) {
                $response = str_replace('[aurl]', $aurl, $response);
            }
            $one = str_replace('[parent-ref]', $response, qa_opt('news_plugin_template_comment'));
            $one = str_replace('[anchor]', 'comment' . $post['postid'], $one);
            $one = str_replace('[comment]', $content, $one);
            $votes = str_replace('[number]', ($post['netvotes'] > 0 ? '+' : ($post['netvotes'] < 0 ? '-' : '')) . $post['netvotes'], qa_opt('news_plugin_template_votes'));
            $one = str_replace('[voting]', $votes, $one);
            $uid = $post['userid'];
            $handles = qa_userids_to_handles(array($uid));
            $handle = $handles[$uid];
            $one = str_replace('[meta]', qa_lang_sub('newsletter/meta', '<a href="' . qa_opt('site_url') . 'user/' . $handle . '">' . $handle . '</a>'), $one);
            $chtml[] = $one;
        }
    }
    $news = str_replace('[questions]', implode('<hr class="inner">', $qhtml), $news);
    $news = str_replace('[answers]', implode('<hr class="inner">', $ahtml), $news);
    $news = str_replace('[comments]', implode('<hr class="inner">', $chtml), $news);
    // misc subs
    $news = str_replace('[intro]', qa_lang('newsletter/intro'), $news);
    $news = str_replace('[footer]', qa_lang('newsletter/footer'), $news);
    $news = str_replace('[site-title]', qa_opt('site_title'), $news);
    $news = str_replace('[site-url]', qa_opt('site_url'), $news);
    $news = str_replace('[last-date]', date('M j, Y', $lastdate), $news);
    $news = str_replace('[date]', date('M j, Y'), $news);
    $news = str_replace('[days]', qa_opt('news_plugin_send_days'), $news);
    $news = str_replace('[profile-url]', qa_path('my-profile'), $news);
    error_log('Q2A Newsletter Created on ' . date('M j, Y \\a\\t H\\:i\\:s'));
    file_put_contents(qa_opt('news_plugin_loc'), $news);
    if (qa_opt('news_plugin_pdf')) {
        qa_news_plugin_create_pdf();
    }
    if ($send) {
        qa_news_plugin_send_newsletter($news);
        qa_opt('news_plugin_send_last', time());
        return 'Newsletter Sent';
    }
    return 'Newsletter Created';
    //return 'Error creating '.qa_opt('news_plugin_loc').'; check the error log.';
}
Beispiel #12
0
 function q_view_content($q_view)
 {
     $this->signatures = array();
     if (qa_opt('signatures_enable')) {
         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');
         $result = qa_db_read_all_assoc(qa_db_query_sub('SELECT BINARY signature AS signature, userid,format FROM ^usersignatures'));
         foreach ($result as $user) {
             if ($user['signature']) {
                 $informat = $user['format'];
                 if (!$informat && qa_opt('signatures_html')) {
                     $informat = 'html';
                 }
                 $viewer = qa_load_viewer($user['signature'], $informat);
                 global $options;
                 $signature = $viewer->get_html($user['signature'], $informat, array('blockwordspreg' => @$options['blockwordspreg'], 'showurllinks' => @$options['showurllinks'], 'linksnewwindow' => @$options['linksnewwindow']));
                 $this->signatures['user' . $user['userid']] = $signature;
             }
         }
         if (qa_opt('signatures_q_enable') && @$this->signatures['user' . $q_view['raw']['userid']]) {
             if (!isset($q_view['content'])) {
                 $q_view['content'] = '';
             }
             $q_view['content'] .= $this->signature_output($q_view['raw']['userid']);
         }
     }
     qa_html_theme_base::q_view_content($q_view);
 }