Пример #1
0
 /**
  * Regular expression callback.
  *
  * @param array $matches  preg_replace_callback() matches.
  *
  * @return string  Replacement string.
  */
 protected function _regexCallback($matches)
 {
     if ($this->_params['always_mailto'] || !$this->_params['callback'] && (!($app = $GLOBALS['registry']->hasMethod('mail/compose')) || !$GLOBALS['registry']->hasPermission($app, Horde_Perms::EDIT))) {
         return parent::_regexCallback($matches);
     }
     if (!isset($matches[10]) || $matches[10] === '') {
         $args = $matches[7];
         $email = $matches[3];
         $args_long = $matches[5];
     } else {
         $args = isset($matches[13]) ? $matches[13] : '';
         $email = $matches[10];
         $args_long = isset($matches[11]) ? $matches[11] : '';
     }
     parse_str($args, $extra);
     try {
         $url = $this->_params['callback'] ? strval(call_user_func($this->_params['callback'], array('to' => $email), $extra)) : strval($GLOBALS['registry']->call('mail/compose', array(array('to' => $email), $extra)));
     } catch (Horde_Exception $e) {
         return parent::_regexCallback($matches);
     }
     if (substr($url, 0, 11) == 'javascript:') {
         $href = '#';
         $onclick = ' onclick="' . htmlspecialchars(substr($url, 11)) . ';return false;"';
     } else {
         $href = htmlspecialchars($url);
         $onclick = '';
     }
     $class = empty($this->_params['class']) ? '' : ' class="' . $this->_params['class'] . '"';
     return '<a' . $class . ' href="' . $href . '"' . $onclick . '>' . htmlspecialchars($email) . htmlspecialchars($args_long) . '</a>';
 }
Пример #2
0
 /**
  * Executes any code necessary before applying the filter patterns.
  *
  * @param mixed $text  The text before the filtering. Either a string or
  *                     a Horde_Text_Flowed object (since 1.1.0).
  *
  * @return string  The modified text.
  */
 public function preProcess($text)
 {
     if ($text instanceof Horde_Text_Flowed) {
         $text->setMaxLength(0);
         $lines = $text->toFixedArray();
         $level = 0;
         $out = $txt = '';
         foreach ($lines as $key => $val) {
             $line = ltrim($val['text'], '>');
             if (!isset($lines[$key + 1])) {
                 $out .= $this->preProcess(ltrim($txt) . $line);
                 while (--$level > 0) {
                     $out .= '</blockquote>';
                 }
             } elseif ($val['level'] > $level) {
                 $out .= $this->preProcess(ltrim($txt));
                 do {
                     $out .= $this->_params['flowed'];
                 } while (++$level != $val['level']);
                 $txt = $line;
             } elseif ($val['level'] < $level) {
                 $out .= $this->preProcess(ltrim($txt));
                 do {
                     $out .= '</blockquote>';
                 } while (--$level != $val['level']);
                 $txt = $line;
             } else {
                 $txt .= "\n" . $line;
             }
         }
         return $out;
     }
     if (!strlen($text)) {
         return '';
     }
     /* Abort out on simple cases. */
     if ($this->_params['parselevel'] == self::PASSTHRU) {
         return $text;
     }
     if ($this->_params['parselevel'] == self::NOHTML_NOBREAK) {
         return @htmlspecialchars($text, ENT_COMPAT, $this->_params['charset']);
     }
     if ($this->_params['parselevel'] < self::NOHTML) {
         $filters = array();
         if ($this->_params['linkurls']) {
             reset($this->_params['linkurls']);
             $this->_params['linkurls'][key($this->_params['linkurls'])]['encode'] = true;
             $filters = $this->_params['linkurls'];
         } else {
             $filters['linkurls'] = array('encode' => true);
         }
         if ($this->_params['parselevel'] < self::MICRO_LINKURL) {
             if ($this->_params['emails']) {
                 reset($this->_params['emails']);
                 $this->_params['emails'][key($this->_params['emails'])]['encode'] = true;
                 $filters += $this->_params['emails'];
             } else {
                 $filters['emails'] = array('encode' => true);
             }
         }
         $text = Horde_Text_Filter::filter($text, array_keys($filters), array_values($filters));
     }
     /* For level MICRO or NOHTML, start with htmlspecialchars(). */
     $text2 = @htmlspecialchars($text, ENT_COMPAT, $this->_params['charset']);
     /* Bad charset input in may result in an empty string. Or the charset
      * may not be supported. Convert to UTF-8 for htmlspecialchars() and
      * then convert back. If we STILL don't have any output, the input
      * charset is probably incorrect. Try the popular Western charsets as
      * a last resort. */
     if (!strlen($text2)) {
         $text2 = Horde_String::convertCharset(@htmlspecialchars(Horde_String::convertCharset($text, $this->_params['charset'], 'UTF-8'), ENT_COMPAT, 'UTF-8'), 'UTF-8', $this->_params['charset']);
         if (!strlen($text2)) {
             foreach (array('windows-1252', 'utf-8') as $val) {
                 $text2 = Horde_String::convertCharset(@htmlspecialchars($text, ENT_COMPAT, $val), $val, $this->_params['charset']);
                 if (strlen($text2)) {
                     break;
                 }
             }
         }
     }
     $text = $text2;
     /* Do in-lining of http://xxx.xxx to link, xxx@xxx.xxx to email. */
     if ($this->_params['parselevel'] < self::NOHTML) {
         $text = Horde_Text_Filter_Linkurls::decode($text);
         if ($this->_params['parselevel'] < self::MICRO_LINKURL) {
             $text = Horde_Text_Filter_Emails::decode($text);
         }
         if ($this->_params['space2html']) {
             $params = reset($this->_params['space2html']);
             $driver = key($this->_params['space2html']);
         } else {
             $driver = 'space2html';
             $params = array();
         }
         $text = Horde_Text_Filter::filter($text, $driver, $params);
     }
     /* Do the newline ---> <br /> substitution. Everybody gets this; if
      * you don't want even that, just use htmlspecialchars(). */
     return nl2br($text);
 }