public function q_list($q_list)
 {
     if (!empty($q_list['qs']) && qa_opt('mouseover_content_on')) {
         // first check it is not an empty list and the feature is turned on
         // Collect the question ids of all items in the question list (so we can do this in one DB query)
         $postids = array();
         foreach ($q_list['qs'] as $question) {
             if (isset($question['raw']['postid'])) {
                 $postids[] = $question['raw']['postid'];
             }
         }
         if (!empty($postids)) {
             // Retrieve the content for these questions from the database
             $maxlength = qa_opt('mouseover_content_max_len');
             $result = qa_db_query_sub('SELECT postid, content, format FROM ^posts WHERE postid IN (#)', $postids);
             $postinfo = qa_db_read_all_assoc($result, 'postid');
             // Get the regular expression fragment to use for blocked words and the maximum length of content to show
             $blockwordspreg = qa_get_block_words_preg();
             // Now add the popup to the title for each question
             foreach ($q_list['qs'] as $index => $question) {
                 if (isset($postinfo[$question['raw']['postid']])) {
                     $thispost = $postinfo[$question['raw']['postid']];
                     $text = qa_viewer_text($thispost['content'], $thispost['format'], array('blockwordspreg' => $blockwordspreg));
                     $text = preg_replace('/\\s+/', ' ', $text);
                     // Remove duplicated blanks, new line characters, tabs, etc
                     $text = qa_shorten_string_line($text, $maxlength);
                     $title = isset($question['title']) ? $question['title'] : '';
                     $q_list['qs'][$index]['title'] = $this->getHtmlTitle(qa_html($text), $title);
                 }
             }
         }
     }
     parent::q_list($q_list);
     // call back through to the default function
 }
Exemple #2
0
 public function q_list($q_list)
 {
     if (!empty($q_list['qs']) && qa_opt('mouseover_content_on')) {
         // first check it is not an empty list and the feature is turned on
         // Collect the question ids of all items in the question list (so we can do this in one DB query)
         $postids = array();
         foreach ($q_list['qs'] as $question) {
             if (isset($question['raw']['postid'])) {
                 $postids[] = $question['raw']['postid'];
             }
         }
         if (!empty($postids)) {
             // Retrieve the content for these questions from the database and put into an array fetching
             // the minimal amount of characters needed to determine the string should be shortened or not
             $maxlength = qa_opt('mouseover_content_max_len');
             $result = qa_db_query_sub('SELECT postid, LEFT(content, #) content, format FROM ^posts WHERE postid IN (#)', $maxlength + 1, $postids);
             $postinfo = qa_db_read_all_assoc($result, 'postid');
             // Get the regular expression fragment to use for blocked words and the maximum length of content to show
             $blockwordspreg = qa_get_block_words_preg();
             // Now add the popup to the title for each question
             foreach ($q_list['qs'] as $index => $question) {
                 if (isset($postinfo[$question['raw']['postid']])) {
                     $thispost = $postinfo[$question['raw']['postid']];
                     $text = qa_viewer_text($thispost['content'], $thispost['format'], array('blockwordspreg' => $blockwordspreg));
                     $text = qa_shorten_string_line($text, $maxlength);
                     $title = isset($question['title']) ? $question['title'] : '';
                     $q_list['qs'][$index]['title'] = sprintf('<span title="%s">%s</span>', qa_html($text), $title);
                 }
             }
         }
     }
     qa_html_theme_base::q_list($q_list);
     // call back through to the default function
 }
 function q_list($q_list)
 {
     if (count(@$q_list['qs']) && qa_opt('mouseover_content_on')) {
         // first check it is not an empty list and the feature is turned on
         //	Collect the question ids of all items in the question list (so we can do this in one DB query)
         $postids = array();
         foreach ($q_list['qs'] as $question) {
             if (isset($question['raw']['postid'])) {
                 $postids[] = $question['raw']['postid'];
             }
         }
         if (count($postids)) {
             //	Retrieve the content for these questions from the database and put into an array
             $result = qa_db_query_sub('SELECT postid, content, format FROM ^posts WHERE postid IN (#)', $postids);
             $postinfo = qa_db_read_all_assoc($result, 'postid');
             //	Get the regular expression fragment to use for blocked words and the maximum length of content to show
             $blockwordspreg = qa_get_block_words_preg();
             $maxlength = qa_opt('mouseover_content_max_len');
             //	Now add the popup to the title for each question
             foreach ($q_list['qs'] as $index => $question) {
                 $thispost = @$postinfo[$question['raw']['postid']];
                 if (isset($thispost)) {
                     $text = qa_viewer_text($thispost['content'], $thispost['format'], array('blockwordspreg' => $blockwordspreg));
                     $text = qa_shorten_string_line($text, $maxlength);
                     $q_list['qs'][$index]['title'] = '<SPAN TITLE="' . qa_html($text) . '">' . @$question['title'] . '</SPAN>';
                 }
             }
         }
     }
     qa_html_theme_base::q_list($q_list);
     // call back through to the default function
 }
 public function test__qa_shorten_string_line()
 {
     // qa_shorten_string_line ($string, $length)
     $test = qa_shorten_string_line($this->strBasic, 30);
     $this->assertStringStartsWith('So I tied', $test);
     $this->assertStringEndsWith('time.', $test);
     $this->assertNotFalse(strpos($test, '...'));
 }
function qa_page_q_edit_a_form(&$qa_content, $id, $answer, $question, $answers, $commentsfollows, $in, $errors)
{
    require_once QA_INCLUDE_DIR . 'qa-util-string.php';
    $answerid = $answer['postid'];
    $prefix = 'a' . $answerid . '_';
    $content = isset($in['content']) ? $in['content'] : $answer['content'];
    $format = isset($in['format']) ? $in['format'] : $answer['format'];
    $editorname = isset($in['editor']) ? $in['editor'] : qa_opt('editor_for_as');
    $editor = qa_load_editor($content, $format, $editorname);
    $hascomments = false;
    foreach ($commentsfollows as $commentfollow) {
        if ($commentfollow['parentid'] == $answerid) {
            $hascomments = true;
        }
    }
    $form = array('tags' => 'method="post" action="' . qa_self_html() . '"', 'id' => $id, 'title' => qa_lang_html('question/edit_a_title'), 'style' => 'tall', 'fields' => array('content' => array_merge(qa_editor_load_field($editor, $qa_content, $content, $format, $prefix . 'content', 12), 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-' . $answerid)));
    //	Show option to convert this answer to a comment, if appropriate
    $commentonoptions = array();
    $lastbeforeid = $question['postid'];
    // used to find last post created before this answer - this is default given
    $lastbeforetime = $question['created'];
    if ($question['commentable']) {
        $commentonoptions[$question['postid']] = qa_lang_html('question/comment_on_q') . qa_html(qa_shorten_string_line($question['title'], 80));
    }
    foreach ($answers as $otheranswer) {
        if ($otheranswer['postid'] != $answerid && $otheranswer['created'] < $answer['created'] && $otheranswer['commentable'] && !$otheranswer['hidden']) {
            $commentonoptions[$otheranswer['postid']] = qa_lang_html('question/comment_on_a') . qa_html(qa_shorten_string_line(qa_viewer_text($otheranswer['content'], $otheranswer['format']), 80));
            if ($otheranswer['created'] > $lastbeforetime) {
                $lastbeforeid = $otheranswer['postid'];
                $lastebeforetime = $otheranswer['created'];
            }
        }
    }
    if (count($commentonoptions)) {
        $form['fields']['tocomment'] = array('tags' => 'name="' . $prefix . 'dotoc" id="' . $prefix . 'dotoc"', 'label' => '<span id="' . $prefix . 'toshown">' . qa_lang_html('question/a_convert_to_c_on') . '</span>' . '<span id="' . $prefix . 'tohidden" style="display:none;">' . qa_lang_html('question/a_convert_to_c') . '</span>', 'type' => 'checkbox', 'tight' => true);
        $form['fields']['commenton'] = array('tags' => 'name="' . $prefix . 'commenton"', 'id' => $prefix . 'commenton', 'type' => 'select', 'note' => qa_lang_html($hascomments ? 'question/a_convert_warn_cs' : 'question/a_convert_warn'), 'options' => $commentonoptions, 'value' => @$commentonoptions[$lastbeforeid]);
        qa_set_display_rules($qa_content, array($prefix . 'commenton' => $prefix . 'dotoc', $prefix . 'toshown' => $prefix . 'dotoc', $prefix . 'tohidden' => '!' . $prefix . 'dotoc'));
    }
    //	Show name and notification field if appropriate
    if ($answer['isbyuser']) {
        if (!qa_is_logged_in()) {
            qa_set_up_name_field($qa_content, $form['fields'], isset($in['name']) ? $in['name'] : @$answer['name'], $prefix);
        }
        qa_set_up_notify_fields($qa_content, $form['fields'], 'A', qa_get_logged_in_email(), isset($in['notify']) ? $in['notify'] : !empty($answer['notify']), isset($in['email']) ? $in['email'] : @$answer['notify'], @$errors['email'], $prefix);
    }
    if (!qa_user_post_permit_error('permit_edit_silent', $answer)) {
        $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;
}
}
if ($question['hidden']) {
    $qa_content['hidden'] = true;
}
qa_sort_by($commentsfollows, 'created');
//	Prepare content for the question...
if ($formtype == 'q_edit') {
    // ...in edit mode
    $qa_content['title'] = qa_lang_html($question['editable'] ? 'question/edit_q_title' : (qa_using_categories() ? 'question/recat_q_title' : 'question/retag_q_title'));
    $qa_content['form_q_edit'] = qa_page_q_edit_q_form($qa_content, $question, @$qin, @$qerrors, $completetags, $categories);
    $qa_content['q_view']['raw'] = $question;
} else {
    // ...in view mode
    $qa_content['q_view'] = qa_page_q_question_view($question, $parentquestion, $closepost, $usershtml, $formrequested);
    $qa_content['title'] = $qa_content['q_view']['title'];
    $qa_content['description'] = qa_html(qa_shorten_string_line(qa_viewer_text($question['content'], $question['format']), 150));
    $categorykeyword = @$categories[$question['categoryid']]['title'];
    $qa_content['keywords'] = qa_html(implode(',', array_merge(qa_using_categories() && strlen($categorykeyword) ? array($categorykeyword) : array(), qa_tagstring_to_tags($question['tags']))));
    // as far as I know, META keywords have zero effect on search rankings or listings, but many people have asked for this
}
$microdata = qa_opt('use_microdata');
if ($microdata) {
    $qa_content['head_lines'][] = '<meta itemprop="name" content="' . qa_html($qa_content['q_view']['raw']['title']) . '">';
    $qa_content['html_tags'] = ' itemscope itemtype="http://schema.org/QAPage"';
    $qa_content['main_tags'] = ' itemscope itemtype="http://schema.org/Question"';
}
//	Prepare content for an answer being edited (if any) or to be added
if ($formtype == 'a_edit') {
    $qa_content['a_form'] = qa_page_q_edit_a_form($qa_content, 'a' . $formpostid, $answers[$formpostid], $question, $answers, $commentsfollows, @$aeditin[$formpostid], @$aediterrors[$formpostid]);
    $qa_content['a_form']['c_list'] = qa_page_q_comment_follow_list($question, $answers[$formpostid], $commentsfollows, true, $usershtml, $formrequested, $formpostid);
    $jumptoanchor = 'a' . $formpostid;
Exemple #7
0
 function q_list($q_list)
 {
     if (qa_opt('it_layout_lists') == 'qlist') {
         qa_html_theme_base::q_list($q_list);
         return;
     }
     if (count(@$q_list['qs'])) {
         // first check it is not an empty list and the feature is turned on
         //	Collect the question ids of all items in the question list (so we can do this in one DB query)
         $postids = array();
         foreach ($q_list['qs'] as $question) {
             if (isset($question['raw']['postid'])) {
                 $postids[] = $question['raw']['postid'];
             }
         }
         if (count($postids)) {
             //	Retrieve favourite count
             $userid = qa_get_logged_in_userid();
             $result = qa_db_query_sub('SELECT userid,entityid FROM ^userfavorites WHERE entitytype=$ AND entityid IN (#)', 'Q', $postids);
             while ($row = mysqli_fetch_row($result)) {
                 if ($row[0] == $userid) {
                     // loged in user favorited this post
                     $faved_post[$row[1]] = 1;
                 }
                 if (isset($favs[$row[1]])) {
                     $favs[$row[1]] = $favs[$row[1]] + 1;
                 } else {
                     $favs[$row[1]] = 1;
                 }
             }
             //	Retrieve comment count
             $result = qa_db_query_sub('SELECT postid,parentid FROM ^posts WHERE type=$ AND parentid IN (#)', 'C', $postids);
             $comment_list = qa_db_read_all_assoc($result, 'postid');
             foreach ($comment_list as $key => $value) {
                 if (isset($comments[$value['parentid']])) {
                     $comments[$value['parentid']] = $comments[$value['parentid']] + 1;
                 } else {
                     $comments[$value['parentid']] = 1;
                 }
             }
             if (qa_opt('it_excerpt_field_enable') or qa_opt('it_enable_except')) {
                 //	Get the regular expression fragment to use for blocked words and the maximum length of content to show
                 $blockwordspreg = qa_get_block_words_preg();
                 if (qa_opt('it_excerpt_field_enable')) {
                     $maxlength = qa_opt('it_excerpt_field_length');
                     //	Retrieve Excerpt Text for all questions
                     $result = qa_db_query_sub('SELECT postid,content FROM ^postmetas WHERE postid IN (#) AND title=$', $postids, 'et_excerpt_text');
                     $excerpt_text = qa_db_read_all_assoc($result, 'postid');
                     // set excerpt from field info
                     foreach ($q_list['qs'] as $index => $question) {
                         // from field
                         if (!empty($excerpt_text[$question['raw']['postid']]['content'])) {
                             $text = qa_viewer_text($excerpt_text[$question['raw']['postid']]['content'], '', array('blockwordspreg' => $blockwordspreg));
                             $text = qa_shorten_string_line($text, $maxlength);
                             $q_list['qs'][$index]['excerpt'] = qa_html($text);
                             // from post content
                         } elseif (qa_opt('it_enable_except')) {
                             // Retrieve the content for these questions from the database and put into an array
                             $result = qa_db_query_sub('SELECT postid, content, format FROM ^posts WHERE postid IN (#)', $postids);
                             $postinfo = qa_db_read_all_assoc($result, 'postid');
                             $thispost = @$postinfo[$question['raw']['postid']];
                             if (isset($thispost)) {
                                 $text = qa_viewer_text($thispost['content'], $thispost['format'], array('blockwordspreg' => $blockwordspreg));
                                 $text = qa_shorten_string_line($text, $maxlength);
                                 $q_list['qs'][$index]['excerpt'] = qa_html($text);
                             }
                         }
                     }
                 } else {
                     // qa_opt('it_enable_except')  ==> excerpt from question content instead of excerpt field
                     $maxlength = qa_opt('it_except_len');
                     $result = qa_db_query_sub('SELECT postid, content, format FROM ^posts WHERE postid IN (#)', $postids);
                     $postinfo = qa_db_read_all_assoc($result, 'postid');
                     foreach ($q_list['qs'] as $index => $question) {
                         $thispost = @$postinfo[$question['raw']['postid']];
                         if (isset($thispost)) {
                             $text = qa_viewer_text($thispost['content'], $thispost['format'], array('blockwordspreg' => $blockwordspreg));
                             $text = qa_shorten_string_line($text, $maxlength);
                             $q_list['qs'][$index]['excerpt'] = qa_html($text);
                         }
                     }
                 }
             }
             //	Retrieve featured images for all list questions
             if (qa_opt('it_feature_img_enable')) {
                 $result = qa_db_query_sub('SELECT postid,content FROM ^postmetas WHERE postid IN (#) AND title=$', $postids, 'et_featured_image');
                 $featured_images = qa_db_read_all_assoc($result, 'postid');
             }
             //	Now meta information for each question
             foreach ($q_list['qs'] as $index => $question) {
                 if (qa_opt('it_feature_img_enable')) {
                     $featured_image = @$featured_images[$question['raw']['postid']]['content'];
                     if (isset($featured_image)) {
                         $q_list['qs'][$index]['featured'] = qa_opt('it_featured_url_abs') . 'featured/' . $featured_image;
                     }
                 }
                 if (isset($comments[$question['raw']['postid']])) {
                     $q_list['qs'][$index]['comments'] = $comments[$question['raw']['postid']];
                 } else {
                     $q_list['qs'][$index]['comments'] = 0;
                 }
                 $q_list['qs'][$index]['favourited'] = 0;
                 if (isset($favs[$question['raw']['postid']])) {
                     $q_list['qs'][$index]['favourites'] = $favs[$question['raw']['postid']];
                     if (isset($faved_post[$question['raw']['postid']])) {
                         $q_list['qs'][$index]['favourited'] = 1;
                     }
                 } else {
                     $q_list['qs'][$index]['favourites'] = 0;
                 }
             }
         }
     }
     if (isset($q_list['qs'])) {
         $this->output('<div class="qa-q-list row' . ($this->list_vote_disabled($q_list['qs']) ? ' qa-q-list-vote-disabled' : '') . '">', '');
         $this->q_list_items($q_list['qs']);
         $this->output('</div> <!-- END qa-q-list -->', '');
     }
 }
Exemple #8
0
    function q_list($q_list)
    {
        if (isset($q_list['qs'])) {
            if (qa_opt('cs_enable_except')) {
                // first check it is not an empty list and the feature is turned on
                //	Collect the question ids of all items in the question list (so we can do this in one DB query)
                $postids = array();
                foreach ($q_list['qs'] as $question) {
                    if (isset($question['raw']['postid'])) {
                        $postids[] = $question['raw']['postid'];
                    }
                }
                if (count($postids)) {
                    //	Retrieve the content for these questions from the database and put into an array
                    //$result         = qa_db_query_sub('SELECT postid, content, format FROM ^posts WHERE postid IN (#)', $postids);
                    //$postinfo       = qa_db_read_all_assoc($result, 'postid');
                    //cache and apply keys to array now that I can't use array key argument in qa_db_read_all_assoc
                    $posts = qa_db_read_all_assoc(qa_db_query_sub('SELECT postid, content, format FROM ^posts WHERE postid IN (#)', $postids));
                    $postinfo = array();
                    foreach ($posts as $qitem) {
                        $postinfo[$qitem['postid']] = $qitem;
                    }
                    //	Get the regular expression fragment to use for blocked words and the maximum length of content to show
                    $blockwordspreg = qa_get_block_words_preg();
                    $maxlength = qa_opt('cs_except_len');
                    //	Now add the popup to the title for each question
                    foreach ($q_list['qs'] as $index => $question) {
                        $thispost = @$postinfo[$question['raw']['postid']];
                        if (isset($thispost)) {
                            $text = qa_viewer_text($thispost['content'], $thispost['format'], array('blockwordspreg' => $blockwordspreg));
                            $text = qa_shorten_string_line($text, $maxlength);
                            $q_list['qs'][$index]['content'] = '<SPAN>' . qa_html($text) . '</SPAN>';
                        }
                    }
                }
            }
            $this->output('<div class="qa-q-list' . ($this->list_vote_disabled($q_list['qs']) ? ' qa-q-list-vote-disabled' : '') . ((bool) qa_opt('cs_enable_clean_qlist') ? ' clean' : '') . '">', '');
            $this->q_list_items($q_list['qs']);
            $this->output('</div> <!-- END qa-q-list -->', '');
        } else {
            $this->output('
					<div class="no-items">
						<h3 class="icon-sad">' . qa_lang_html('cleanstrap/no_users') . '</h3>
						<p>' . qa_lang_html('cleanstrap/no_results_detail') . '.</p>
					</div>');
        }
    }
function qa_page_q_edit_a_form($answerid)
{
    require_once QA_INCLUDE_DIR . 'qa-util-string.php';
    global $questionid, $question, $answers, $inacontent, $inaformat, $inaeditor, $aerrors, $qa_content, $innotify, $inemail, $jumptoanchor, $commentsfollows;
    $answer = $answers[$answerid];
    $content = isset($inacontent) ? $inacontent : $answer['content'];
    $format = isset($inaformat) ? $inaformat : $answer['format'];
    $editorname = isset($inaeditor) ? $inaeditor : qa_opt('editor_for_as');
    $editor = qa_load_editor($content, $format, $editorname);
    $hascomments = false;
    foreach ($commentsfollows as $commentfollow) {
        if ($commentfollow['parentid'] == $answerid) {
            $hascomments = true;
        }
    }
    $form = array('title' => '<A NAME="a_edit">' . qa_lang_html('question/edit_a_title') . '</A>', 'style' => 'tall', 'fields' => array('content' => array_merge($editor->get_field($qa_content, $content, $format, 'acontent', 12, true), array('error' => qa_html(@$aerrors['content'])))), 'buttons' => array('save' => array('label' => qa_lang_html('main/save_button')), 'cancel' => array('tags' => 'NAME="docancel"', 'label' => qa_lang_html('main/cancel_button'))), 'hidden' => array('editor' => qa_html($editorname), 'dosavea_' . qa_html($answerid) => '1'));
    //	Show option to convert this answer to a comment, if appropriate
    $commentonoptions = array();
    $lastbeforeid = $questionid;
    // used to find last post created before this answer - this is default given
    $lastbeforetime = $question['created'];
    if ($question['commentable']) {
        $commentonoptions[$questionid] = qa_lang_html('question/comment_on_q') . qa_html(qa_shorten_string_line($question['title'], 80));
    }
    foreach ($answers as $otheranswer) {
        if ($otheranswer['postid'] != $answerid && $otheranswer['created'] < $answer['created'] && $otheranswer['commentable'] && !$otheranswer['hidden']) {
            $commentonoptions[$otheranswer['postid']] = qa_lang_html('question/comment_on_a') . qa_html(qa_shorten_string_line(qa_viewer_text($otheranswer['content'], $otheranswer['format']), 80));
            if ($otheranswer['created'] > $lastbeforetime) {
                $lastbeforeid = $otheranswer['postid'];
                $lastebeforetime = $otheranswer['created'];
            }
        }
    }
    if (count($commentonoptions)) {
        $form['fields']['tocomment'] = array('tags' => 'NAME="tocomment" ID="tocomment"', 'label' => '<SPAN ID="tocomment_shown">' . qa_lang_html('question/a_convert_to_c_on') . '</SPAN>' . '<SPAN ID="tocomment_hidden" STYLE="display:none;">' . qa_lang_html('question/a_convert_to_c') . '</SPAN>', 'type' => 'checkbox', 'tight' => true);
        $form['fields']['commenton'] = array('tags' => 'NAME="commenton"', 'id' => 'commenton', 'type' => 'select', 'note' => qa_lang_html($hascomments ? 'question/a_convert_warn_cs' : 'question/a_convert_warn'), 'options' => $commentonoptions, 'value' => @$commentonoptions[$lastbeforeid]);
        qa_set_display_rules($qa_content, array('commenton' => 'tocomment', 'tocomment_shown' => 'tocomment', 'tocomment_hidden' => '!tocomment'));
    }
    //	Show notification field if appropriate
    if ($answer['isbyuser']) {
        qa_set_up_notify_fields($qa_content, $form['fields'], 'A', qa_get_logged_in_email(), isset($innotify) ? $innotify : !empty($answer['notify']), isset($inemail) ? $inemail : @$answer['notify'], @$aerrors['email']);
    }
    $form['c_list'] = qa_page_q_comment_follow_list($answer);
    $jumptoanchor = 'a_edit';
    return $form;
}