示例#1
0
 /**
  * Renders the element into a html string
  *
  * The $view is used to correctly encode and escape the output
  *
  * @param \Zend_View_Abstract $view
  * @return string Correctly encoded and escaped html output
  */
 public function render(\Zend_View_Abstract $view)
 {
     $results = array();
     $renderer = \MUtil_Html::getRenderer();
     foreach ($this->_array as $item) {
         $result = $renderer->renderAny($view, $item);
         if (null !== $result && strlen($result)) {
             $results[] = $result;
         }
     }
     if ($results) {
         return implode('', $results);
     }
 }
示例#2
0
 /**
  * Builds the actual <option> tag
  *
  * @param string $value Options Value
  * @param string $label Options Label
  * @param array  $selected The option value(s) to mark as 'selected'
  * @param array|bool $disable Whether the select is disabled, or individual options are
  * @param array $optionClasses The classes to associate with each option value
  * @return string Option Tag XHTML
  */
 protected function _build($value, $label, $selected, $disable, $optionClasses = array())
 {
     if (is_bool($disable)) {
         $disable = array();
     }
     $opt = '<option' . ' value="' . $this->view->escape($value) . '"';
     if ($label instanceof \MUtil_Html_HtmlElement) {
         // Element not allowed, get parts that are allowed
         foreach (array('class', 'dir', 'id', 'label', 'lang', 'style', 'title') as $attr) {
             if (isset($label->{$attr})) {
                 $opt .= ' ' . $attr . '="' . $this->view->escape($label->{$attr}) . '"';
             }
         }
         // Now get the content
         $renderer = \MUtil_Html::getRenderer();
         $content = '';
         foreach ($label->getIterator() as $part) {
             $content .= $renderer->renderAny($this->view, $part);
         }
     } elseif ($label instanceof \MUtil_Html_HtmlInterface) {
         $content = $label->render($this->view);
     } else {
         $content = $this->view->escape($label);
         $opt .= ' label="' . $this->view->escape($label) . '"';
     }
     // selected?
     if (in_array((string) $value, $selected)) {
         $opt .= ' selected="selected"';
     }
     // disabled?
     if (in_array($value, $disable)) {
         $opt .= ' disabled="disabled"';
     }
     $opt .= '>' . $content . "</option>";
     return $opt;
 }
示例#3
0
 /**
  * Renders the element into a html string
  *
  * The $view is used to correctly encode and escape the output
  *
  * @param \Zend_View_Abstract $view
  * @return string Correctly encoded and escaped html output
  */
 public function render(\Zend_View_Abstract $view)
 {
     if (null === $view) {
         $view = $this->getView();
     } else {
         $this->setView($view);
     }
     $params = \MUtil_Html::getRenderer()->renderArray($view, $this->getIterator(), false);
     if ($params) {
         return call_user_func_array('sprintf', $params);
     }
     return '';
 }
示例#4
0
 /**
  * Renders the element into a html string
  *
  * The $view is used to correctly encode and escape the output
  *
  * @param \Zend_View_Abstract $view
  * @return string Correctly encoded and escaped html output
  */
 public function render(\Zend_View_Abstract $view)
 {
     $renderer = \MUtil_Html::getRenderer();
     if ($this->hasRepeater() && $this->_content) {
         $data = $this->getRepeater();
         if ($data->__start()) {
             $html = array();
             while ($data->__next()) {
                 $html[] = $renderer->renderArray($view, $this->_content);
             }
             if ($html) {
                 return implode($renderer->renderAny($view, $this->_glue), $html);
             }
         }
     }
     if ($this->_emptyContent) {
         return $renderer->renderAny($view, $this->_emptyContent);
     }
     return null;
 }
示例#5
0
 /**
  * Function to allow overloading  of tag rendering only
  *
  * Renders the element tag with it's content into a html string
  *
  * The $view is used to correctly encode and escape the output
  *
  * @param \Zend_View_Abstract $view
  * @return string Correctly encoded and escaped html output
  */
 protected function renderElement(\Zend_View_Abstract $view)
 {
     if (isset($this->_attribs['src'])) {
         if (is_scalar($this->_attribs['src'])) {
             $src = $this->_attribs['src'];
         } else {
             $src = \MUtil_Html::getRenderer()->renderArray($view, array($this->_attribs['src']));
         }
     } else {
         $src = false;
     }
     if ($src || $this->renderWithoutSrc) {
         return parent::renderElement($view);
     }
 }
示例#6
0
 /**
  * Renders the element into a html string
  *
  * The $view is used to correctly encode and escape the output
  *
  * @param \Zend_View_Abstract $view
  * @return string Correctly encoded and escaped html output
  */
 public function render(\Zend_View_Abstract $view)
 {
     //*
     if (null === $view) {
         $view = $this->getView();
     } else {
         $this->setView($view);
     }
     // \MUtil_Echo::r($this->count(), $glue);
     $glue = $this->getGlue();
     if ($glue instanceof \MUtil_Html_HtmlInterface) {
         $glue = $glue->render($view);
     }
     return \MUtil_Html::getRenderer()->renderArray($view, $this->getIterator(), $glue);
 }
示例#7
0
 /**
  * Function to allow overloading of content rendering only
  *
  * The $view is used to correctly encode and escape the output
  *
  * @param \Zend_View_Abstract $view
  * @return string Correctly encoded and escaped html output
  */
 protected function renderContent(\Zend_View_Abstract $view)
 {
     $renderer = \MUtil_Html::getRenderer();
     if ($this->_content) {
         if ($this->_repeater && !$this->_repeatTags) {
             if ($this->_repeater->__start()) {
                 $html = '';
                 while ($this->_repeater->__next()) {
                     $html .= $renderer->renderArray($view, $this->_content);
                 }
                 return $html;
             }
         } else {
             $content = $renderer->renderArray($view, $this->_content);
             if (strlen($content)) {
                 return $content;
             }
         }
     }
     if ($this->_onEmptyContent) {
         return $renderer->renderArray($view, $this->_onEmptyContent);
     }
     return null;
 }
示例#8
0
 protected function renderContent(\Zend_View_Abstract $view)
 {
     if ($content = \MUtil_Html::getRenderer()->renderAny($view, $this->_currentContent)) {
         return $content;
     } elseif ($this->_onEmptyContent) {
         return \MUtil_Html::getRenderer()->renderAny($view, $this->_onEmptyContent);
     } else {
         return '&nbsp;';
     }
 }
示例#9
0
 /**
  * Render the element
  *
  * @param  string $content Content to decorate
  * @return string
  */
 public function render($content)
 {
     if (null === ($element = $this->getElement()) || null === ($view = $element->getView()) || null === ($htmlelement = $this->getHtmlElement())) {
         return $content;
     }
     if ($prologue = $this->getPrologue()) {
         if ($prologue instanceof \MUtil_Lazy_RepeatableFormElements) {
             // Not every browser can handle empty divs (e.g. IE 6)
             if ($hidden = $prologue->getHidden()) {
                 $prologue = \MUtil_Html::create()->div($hidden);
             } else {
                 $prologue = null;
             }
         }
         if ($prologue instanceof \MUtil_Html_HtmlInterface) {
             $prologue = $prologue->render($view);
         } else {
             $prologue = \MUtil_Html::getRenderer()->renderAny($view, $prologue);
         }
     } else {
         $prologue = '';
     }
     if ($prependErrors = $this->getPrependErrors()) {
         $form = $this->getElement();
         if ($errors = $form->getMessages()) {
             $errors = \MUtil_Ra::flatten($errors);
             $errors = array_unique($errors);
             if ($prependErrors instanceof \MUtil_Html_ElementInterface) {
                 $html = $prependErrors;
             } else {
                 $html = \MUtil_Html::create('ul');
             }
             foreach ($errors as $error) {
                 $html->append($error);
             }
             $prologue .= $html->render($view);
         }
     }
     $result = $this->renderElement($htmlelement, $view);
     if (parent::APPEND == $this->getPlacement()) {
         return $prologue . $result . $content;
     } else {
         return $content . $prologue . $result;
     }
 }
示例#10
0
 public function testValidRenderer()
 {
     $renderer = MUtil_Html::getRenderer();
     $this->assertInstanceOf('MUtil_Html_Renderer', $renderer);
 }
示例#11
0
 /**
  * Returns the rendered values of th earray elements
  *
  * @return array
  */
 protected function _getArrayRendered()
 {
     return \MUtil_Html::getRenderer()->renderArray($this->getView(), $this->getArray(), false);
 }