/**
  * Does the hard work for preg_replace_callback() in self::filter()
  * 
  * @param string $matches
  * @return string
  */
 protected function _replace($matches)
 {
     if ($this->_view instanceof Zend_View_Abstract) {
         $href = $this->_view->escape($matches[0]);
     } else {
         $href = htmlspecialchars($matches[0]);
     }
     return '<a' . ' href="' . $href . '"' . (null !== $this->_class ? ' class="' . $this->_class . '"' : '') . ' target="_blank" rel="nofollow"' . '>' . $matches[0] . '</a>';
 }
Ejemplo n.º 2
0
 /**
  * Overwrite escape() method
  *
  * The next part is an overwrite of the escape() method from Zend_View_Abstract. It works both for string and array values and also uses the escape() method from the Zend_View_Abstract. The advantage of this is that I don't have to care about each value of an array to get properly escaped.
  *
  * @param mixed $var
  * @return mixed
  */
 public function escape($var)
 {
     if (is_string($var)) {
         return parent::escape($var);
     } elseif (is_array($var)) {
         foreach ($var as $key => $val) {
             $var[$key] = $this->escape($val);
         }
     }
     return $var;
 }
Ejemplo n.º 3
0
 /**
  * Renders the $content so that it can be used as output for the $view,
  * including output escaping and encoding correction.
  *
  * This functions handles \MUtil_Html_HtmlInterface and \MUtil_Lazy_LazyInterface
  * objects natively, as well as array, scalar values and objects with a
  * __toString function.
  *
  * Other objects a definition should have a render function in getClassRenderList().
  *
  * All Lazy variabables are raised.
  *
  * @param \Zend_View_Abstract $view
  * @param mixed $content Anything HtmlInterface, number, string, array, object with __toString
  *                      or an object that has a defined render function in getClassRenderList().
  * @return string Output to echo to the user
  */
 public function renderArray(\Zend_View_Abstract $view, $content, $glue = '', $stack = null)
 {
     // \MUtil_Echo::timeFunctionStart(__FUNCTION__);
     $output = array();
     // \MUtil_Echo::countOccurences('render');
     foreach ($content as $key => $value) {
         // Resolve first as this function as recursion heavy enough as it is.
         if ($value instanceof \MUtil_Lazy_LazyInterface) {
             if (!$stack) {
                 $stack = \MUtil_Lazy::getStack();
             }
             // \MUtil_Echo::countOccurences('lazyIf');
             while ($value instanceof \MUtil_Lazy_LazyInterface) {
                 // \MUtil_Echo::countOccurences('lazyWhile');
                 $value = $value->__toValue($stack);
             }
         }
         if (is_scalar($value)) {
             // \MUtil_Echo::countOccurences('scalar');
             // \MUtil_Echo::timeFunctionStart('escape2');
             $output[$key] = $view->escape((string) $value);
             // \MUtil_Echo::timeFunctionStop('escape2');
         } elseif ($value instanceof \MUtil_Html_HtmlInterface) {
             // \MUtil_Echo::countOccurences('interface');
             $output[$key] = $value->render($view);
         } elseif (null === $value) {
             // \MUtil_Echo::countOccurences('null');
         } elseif (is_array($value)) {
             // \MUtil_Echo::countOccurences('array');
             $output[$key] = self::renderAny($view, $value, '', $stack);
         } elseif (is_object($value)) {
             $function = $this->_classRenderFunctions->get($value);
             if ($function) {
                 // \MUtil_Echo::countOccurences('function');
                 $output[$key] = call_user_func($function, $view, $value);
             } elseif (method_exists($value, '__toString')) {
                 // \MUtil_Echo::countOccurences('toString');
                 // \MUtil_Echo::countOccurences('toString.' . get_class($value));
                 $output[$key] = $view->escape($value->__toString());
             } else {
                 // $output[$key] = 'WARNING: Object of type ' . get_class($value) . ' cannot be converted to string.';
                 throw new \MUtil_Html_HtmlException('WARNING: Object of type ' . get_class($value) . ' cannot be converted to string.');
             }
         } elseif ($value instanceof \__PHP_Incomplete_Class) {
             \MUtil_Echo::r($value, __CLASS__ . '->' . __FUNCTION__);
             $output[$key] = '';
         } else {
             // Mop up, should not occur
             // \MUtil_Echo::countOccurences('scalar else');
             $output[$key] = $view->escape((string) $value);
         }
     }
     if (false === $glue || null === $glue) {
         // \MUtil_Echo::timeFunctionStop(__FUNCTION__);
         return $output;
     }
     $output = implode($glue, $output);
     // \MUtil_Echo::timeFunctionStop(__FUNCTION__);
     return $output;
 }