| | |
| | | $text = preg_replace("/\n\s+\n/", "\n\n", $text); |
| | | $text = preg_replace("/[\n]{3,}/", "\n\n", $text); |
| | | |
| | | // remove leading empty lines (can be produced by eg. P tag on the beginning) |
| | | $text = preg_replace('/^\n+/', '', $text); |
| | | |
| | | // Wrap the text to a readable format |
| | | // for PHP versions >= 4.0.2. Default width is 75 |
| | | // If width is 0 or less, don't wrap the text. |
| | |
| | | */ |
| | | function _convert_pre(&$text) |
| | | { |
| | | // get the content of PRE element |
| | | while (preg_match('/<pre[^>]*>(.*)<\/pre>/ismU', $text, $matches)) { |
| | | $result = preg_replace($this->pre_search, $this->pre_replace, $matches[1]); |
| | | $text = preg_replace('/<pre[^>]*>.*<\/pre>/ismU', '<div><br>' . $result . '<br></div>', $text, 1); |
| | | // convert the content |
| | | $this->pre_content = sprintf('<div><br>%s<br></div>', |
| | | preg_replace($this->pre_search, $this->pre_replace, $matches[1])); |
| | | // replace the content (use callback because content can contain $0 variable) |
| | | $text = preg_replace_callback('/<pre[^>]*>.*<\/pre>/ismU', |
| | | array('html2text', '_preg_pre_callback'), $text, 1); |
| | | // free memory |
| | | $this->pre_content = ''; |
| | | } |
| | | } |
| | | |
| | |
| | | * |
| | | * @param array PREG matches |
| | | * @return string |
| | | * @access private |
| | | */ |
| | | function _preg_callback($matches) |
| | | private function _preg_callback($matches) |
| | | { |
| | | switch($matches[1]) { |
| | | case 'b': |
| | |
| | | case 'h': |
| | | return $this->_strtoupper("\n\n". $matches[2] ."\n\n"); |
| | | case 'a': |
| | | return $this->_build_link_list($matches[3], $matches[4]); |
| | | // Remove spaces in URL (#1487805) |
| | | $url = str_replace(' ', '', $matches[3]); |
| | | return $this->_build_link_list($url, $matches[4]); |
| | | } |
| | | } |
| | | |
| | | |
| | | /** |
| | | * Callback function for preg_replace_callback use in PRE content handler. |
| | | * |
| | | * @param array PREG matches |
| | | * @return string |
| | | */ |
| | | private function _preg_pre_callback($matches) |
| | | { |
| | | return $this->pre_content; |
| | | } |
| | | |
| | | /** |
| | | * Strtoupper multibyte wrapper function |
| | | * |
| | | * @param string |
| | | * @return string |
| | | * @access private |
| | | */ |
| | | function _strtoupper($str) |
| | | private function _strtoupper($str) |
| | | { |
| | | if (function_exists('mb_strtoupper')) |
| | | return mb_strtoupper($str); |