function get_html($content, $format, $options)
 {
     if (isset($options['blockwordspreg'])) {
         require_once QA_INCLUDE_DIR . 'qa-util-string.php';
         $content = qa_block_words_replace($content, $options['blockwordspreg']);
     }
     require_once $this->plugindir . 'inc.markdown.php';
     $html = Markdown($content);
     return qa_sanitize_html($html, @$options['linksnewwindow']);
 }
 function read_post($fieldname)
 {
     if (qa_post_text($fieldname . '_ckeditor_ok')) {
         // CKEditor was loaded successfully
         $html = qa_post_text($fieldname);
         $htmlformatting = preg_replace('/<\\s*\\/?\\s*(br|p)\\s*\\/?\\s*>/i', '', $html);
         // remove <p>, <br>, etc... since those are OK in text
         if (preg_match('/<.+>/', $htmlformatting)) {
             // if still some other tags, it's worth keeping in HTML
             return array('format' => 'html', 'content' => qa_sanitize_html($html, false, true));
         } else {
             // convert to text
             $viewer = qa_load_module('viewer', '');
             return array('format' => '', 'content' => $this->html_to_text($html));
         }
     } else {
         // CKEditor was not loaded so treat it as plain text
         return array('format' => '', 'content' => qa_post_text($fieldname));
     }
 }
 function read_post($fieldname)
 {
     $html = qa_post_text($fieldname);
     $htmlformatting = preg_replace('/<\\s*\\/?\\s*(br|p)\\s*\\/?\\s*>/i', '', $html);
     // remove <p>, <br>, etc... since those are OK in text
     if (preg_match('/<.+>/', $htmlformatting)) {
         // if still some other tags, it's worth keeping in HTML
         return array('format' => 'html', 'content' => qa_sanitize_html($html, false, true));
     } else {
         // convert to text
         $viewer = qa_load_module('viewer', '');
         return array('format' => '', 'content' => $viewer->get_text($html, 'html', array()));
     }
 }
Beispiel #4
0
 function get_html($content, $format, $options)
 {
     if ($format == 'html') {
         $html = qa_sanitize_html($content, @$options['linksnewwindow'], false);
         // sanitize again for display, for extra safety, and due to new window setting
         if (isset($options['blockwordspreg'])) {
             // filtering out blocked words inline within HTML is pretty complex, e.g. p<B>oo</B>p must be caught
             require_once QA_INCLUDE_DIR . 'qa-util-string.php';
             $html = preg_replace('/<\\s*(' . $this->htmllineseparators . ')[^A-Za-z0-9]/i', "\n\\0", $html);
             // tags to single new line
             $html = preg_replace('/<\\s*(' . $this->htmlparagraphseparators . ')[^A-Za-z0-9]/i', "\n\n\\0", $html);
             // tags to double new line
             preg_match_all('/<[^>]*>/', $html, $pregmatches, PREG_OFFSET_CAPTURE);
             // find tag positions and lengths
             $tagmatches = $pregmatches[0];
             $text = preg_replace('/<[^>]*>/', '', $html);
             // effectively strip_tags() but use same regexp as above to ensure consistency
             $blockmatches = qa_block_words_match_all($text, $options['blockwordspreg']);
             // search for blocked words within text
             $nexttagmatch = array_shift($tagmatches);
             $texttohtml = 0;
             $htmlshift = 0;
             foreach ($blockmatches as $textoffset => $textlength) {
                 while (isset($nexttagmatch) && $nexttagmatch[1] <= $textoffset + $texttohtml) {
                     // keep text and html in sync
                     $texttohtml += strlen($nexttagmatch[0]);
                     $nexttagmatch = array_shift($tagmatches);
                 }
                 while (1) {
                     $replacepart = $textlength;
                     if (isset($nexttagmatch)) {
                         $replacepart = min($replacepart, $nexttagmatch[1] - ($textoffset + $texttohtml));
                     }
                     // stop replacing early if we hit an HTML tag
                     $replacelength = qa_strlen(substr($text, $textoffset, $replacepart));
                     // to work with multi-byte characters
                     $html = substr_replace($html, str_repeat('*', $replacelength), $textoffset + $texttohtml + $htmlshift, $replacepart);
                     $htmlshift += $replacelength - $replacepart;
                     // HTML might have moved around if we replaced multi-byte characters
                     if ($replacepart >= $textlength) {
                         break;
                     }
                     // we have replaced everything expected, otherwise more left (due to hitting an HTML tag)
                     $textlength -= $replacepart;
                     $textoffset += $replacepart;
                     $texttohtml += strlen($nexttagmatch[0]);
                     $nexttagmatch = array_shift($tagmatches);
                 }
             }
         }
         if (@$options['showurllinks']) {
             // we need to ensure here that we don't put new links inside existing ones
             require_once QA_INCLUDE_DIR . 'qa-util-string.php';
             $htmlunlinkeds = array_reverse(preg_split('|<[Aa]\\s+[^>]+>.*</[Aa]\\s*>|', $html, -1, PREG_SPLIT_OFFSET_CAPTURE));
             // start from end so we substitute correctly
             foreach ($htmlunlinkeds as $htmlunlinked) {
                 // and that we don't detect links inside HTML, e.g. <IMG SRC="http://...">
                 $thishtmluntaggeds = array_reverse(preg_split('/<[^>]*>/', $htmlunlinked[0], -1, PREG_SPLIT_OFFSET_CAPTURE));
                 // again, start from end
                 foreach ($thishtmluntaggeds as $thishtmluntagged) {
                     $innerhtml = $thishtmluntagged[0];
                     if (is_numeric(strpos($innerhtml, '://'))) {
                         // quick test first
                         $newhtml = qa_html_convert_urls($innerhtml, qa_opt('links_in_new_window'));
                         $html = substr_replace($html, $newhtml, $htmlunlinked[1] + $thishtmluntagged[1], strlen($innerhtml));
                     }
                 }
             }
         }
     } elseif ($format == '') {
         if (isset($options['blockwordspreg'])) {
             require_once QA_INCLUDE_DIR . 'qa-util-string.php';
             $content = qa_block_words_replace($content, $options['blockwordspreg']);
         }
         $html = qa_html($content, true);
         if (@$options['showurllinks']) {
             require_once QA_INCLUDE_DIR . 'qa-app-format.php';
             $html = qa_html_convert_urls($html, qa_opt('links_in_new_window'));
         }
     } else {
         $html = '[no viewer found for format: ' . qa_html($format) . ']';
     }
     // for unknown formats
     return $html;
 }
Beispiel #5
0
 function close_post($qid, $author)
 {
     if (!qa_get_logged_in_userid() || (!qa_opt('close_enable_own') || qa_get_logged_in_userid() != $author) && qa_get_logged_in_level() < QA_USER_LEVEL_MODERATOR) {
         return;
     }
     $reason = qa_sanitize_html(qa_post_text('close_question_reason'));
     $this->closed = qa_get_logged_in_userid() . '^' . $reason;
     qa_db_query_sub('INSERT INTO ^postmeta (post_id,meta_key,meta_value) VALUES (#,$,$)', $qid, 'is_closed', $this->closed);
 }
 function get_html($content, $format, $options)
 {
     if ($format == 'html') {
         $html = qa_sanitize_html($content, @$options['linksnewwindow']);
         // sanitize again for display, for extra safety, and due to new window setting
         if (isset($options['blockwordspreg'])) {
             // filtering out blocked words inline within HTML is pretty complex, e.g. p<B>oo</B>p must be caught
             require_once QA_INCLUDE_DIR . 'qa-util-string.php';
             $html = preg_replace('/<\\s*(' . $this->htmllineseparators . ')[^A-Za-z0-9]/i', "\n\\0", $html);
             // tags to single new line
             $html = preg_replace('/<\\s*(' . $this->htmlparagraphseparators . ')[^A-Za-z0-9]/i', "\n\n\\0", $html);
             // tags to double new line
             preg_match_all('/<[^>]*>/', $html, $pregmatches, PREG_OFFSET_CAPTURE);
             // find tag positions and lengths
             $tagmatches = $pregmatches[0];
             $text = preg_replace('/<[^>]*>/', '', $html);
             // effectively strip_tags() but use same regexp as above to ensure consistency
             $blockmatches = qa_block_words_match_all($text, $options['blockwordspreg']);
             // search for blocked words within text
             $nexttagmatch = array_shift($tagmatches);
             $texttohtml = 0;
             $htmlshift = 0;
             foreach ($blockmatches as $textoffset => $textlength) {
                 while (isset($nexttagmatch) && $nexttagmatch[1] <= $textoffset + $texttohtml) {
                     // keep text and html in sync
                     $texttohtml += strlen($nexttagmatch[0]);
                     $nexttagmatch = array_shift($tagmatches);
                 }
                 while (1) {
                     $replacepart = $textlength;
                     if (isset($nexttagmatch)) {
                         $replacepart = min($replacepart, $nexttagmatch[1] - ($textoffset + $texttohtml));
                     }
                     // stop replacing early if we hit an HTML tag
                     $replacelength = qa_strlen(substr($text, $textoffset, $replacepart));
                     // to work with multi-byte characters
                     $html = substr_replace($html, str_repeat('*', $replacelength), $textoffset + $texttohtml + $htmlshift, $replacepart);
                     $htmlshift += $replacelength - $replacepart;
                     // HTML might have moved around if we replaced multi-byte characters
                     if ($replacepart >= $textlength) {
                         break;
                     }
                     // we have replaced everything expected, otherwise more left (due to hitting an HTML tag)
                     $textlength -= $replacepart;
                     $textoffset += $replacepart;
                     $texttohtml += strlen($nexttagmatch[0]);
                     $nexttagmatch = array_shift($tagmatches);
                 }
             }
         }
     } else {
         if (isset($options['blockwordspreg'])) {
             require_once QA_INCLUDE_DIR . 'qa-util-string.php';
             $content = qa_block_words_replace($content, $options['blockwordspreg']);
         }
         $html = qa_html($content, true);
         if (@$options['showurllinks']) {
             require_once QA_INCLUDE_DIR . 'qa-app-format.php';
             $html = qa_html_convert_urls($html, qa_opt('links_in_new_window'));
         }
     }
     return $html;
 }