public function addOption($value, $label, $properties = array()) { $option = new HtmlElement(false, 'option', $properties); $option->setProperty('value', $value); $option->setContent($label); $this->html->setContent($option, $value); }
/** * Smarty block plugin, for generating page menu item * This block must always be called in pageMenu block context * * @param array $params * @param Smarty $smarty * @param $repeat * * <code> * {pageMenu id="menu"} * {menuItem} * {menuCaption}Click Me{/menuCaption} * {menuAction}http://click.me.com{/menuAction} * {/menuItem} * {menuItem} * {menuCaption}Another menu item{/menuCaption} * {pageAction}alert('Somebody clicked on me too!'){/menuAction} * {/menuItem} * {/pageMenu} * </code> * * @package application.helper.smarty * @author Integry Systems */ function smarty_block_menuItem($params, $content, LiveCartSmarty $smarty, &$repeat) { if ($repeat) { $smarty->clear_assign('menuCaption'); $smarty->clear_assign('menuAction'); $smarty->clear_assign('menuPageAction'); } else { $item = new HtmlElement('a'); if ($smarty->get_template_vars('menuAction')) { $href = $smarty->get_template_vars('menuAction'); } else { if ($smarty->get_template_vars('menuPageAction')) { $onClick = $smarty->get_template_vars('menuPageAction'); $href = '#'; $item->setAttribute('onClick', $onClick . '; return false;'); } } $item->setAttribute('href', $href); // EXPERIMENTAL - set access key for menu item $caption = $smarty->get_template_vars('menuCaption'); if (FALSE != strpos($caption, '&&')) { $p = strpos($caption, '&&'); $accessKey = substr($caption, $p + 2, 1); $item->setAttribute('accessKey', $accessKey); $caption = substr($caption, 0, $p + 3) . '</span>' . substr($caption, $p + 3); $caption = substr($caption, 0, $p) . '<span class="accessKey">' . substr($caption, $p + 2); } $item->setContent($caption); $smarty->append('pageMenuItems', $item->render()); } }
public function setLabel($label) { $labelElement = new HtmlElement(false, 'label'); $labelElement->setProperty('for', $this->html->getProperty('name')); $labelElement->setContent($label); $this->label = $labelElement; }
public function getData() { $listHtml = array('<ul>'); $li = new HtmlElement('li'); foreach ($this->content as $key => $value) { $li->setAttribute('id', $key); $li->setContent($value); $listHtml[] = $li->render(); } $listHtml[] = '</ul>'; return implode("\n", $listHtml); }
function html($showErrors = false) { if (!$this->isContainer) { return parent::html($showErrors); } $elementsHtml = ''; foreach ($this->elements as $e) { $elementsHtml .= $e->html() . Html::br(); } parent::setContent($elementsHtml); return parent::html(); }
/** * Smarty block plugin, for generating page menus * * @param array $params * @param Smarty $smarty * @param $repeat * * <code> * {pageMenu id="menu"} * {menuItem} * {menuCaption}Click Me{/menuCaption} * {menuAction}http://click.me.com{/menuAction} * {/menuItem} * {menuItem} * {menuCaption}Another menu item{/menuCaption} * {pageAction}alert('Somebody clicked on me too!'){/menuAction} * {/menuItem} * {/pageMenu} * </code> * * @return string Menu HTML code * @package application.helper.smarty * @author Integry Systems */ function smarty_block_pageMenu($params, $content, LiveCartSmarty $smarty, &$repeat) { if ($repeat) { $smarty->clear_assign('pageMenuItems'); } else { $items = $smarty->get_template_vars('pageMenuItems'); $menuDiv = new HtmlElement('div'); $menuDiv->setAttribute('id', $params['id']); $menuDiv->setAttribute('tabIndex', 1); $menuDiv->setContent(implode(' | ', $items)); return $menuDiv->render(); } }
public function setLabel($label) { $labelElement = new HtmlElement(false, 'legend'); $labelElement->setContent($label); $this->html->setContent($labelElement, 'legend'); }
/** * @return array */ public function renderOuter() : array { HtmlElement::setContent('[-INNER-]'); $render = HtmlElement::render(); return explode('[-INNER-]', $render); }
/** * Splits $this->source into elements. */ public function splitSource() { $splitterRegexp = '@(\\{/?(?:' . $this->getSignaturesRegexp() . ').*?/?\\})@ims'; $elementsRaw = preg_split($splitterRegexp, $this->source, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_OFFSET_CAPTURE | PREG_SPLIT_NO_EMPTY); /* @var $element Abstraction\ElementAbstraction */ $this->elements = array(); foreach ($elementsRaw as $rawElement) { $elementSource = $rawElement[0]; $firstCharOfElementSource = $elementSource[0]; $secondCharOfElementSource = strlen($elementSource) > 1 ? $elementSource[1] : null; $preLastCharOfElementSource = strlen($elementSource) > 2 ? $elementSource[strlen($elementSource) - 2] : null; $element = true; $signature = null; // If this is SupraMarkup element, try to extract signature from raw element, ... if ($firstCharOfElementSource == '{') { $signature = $this->extractSignature($elementSource); } if (!empty($signature)) { // create element from signature, ... $elementClassName = $this->markupElements[$signature]; $element = new $elementClassName(); if (!$element instanceof Abstraction\SupraMarkupElement) { throw new Exception\RuntimeException(sprintf('Expecting element to be instance of SupraMarkupElement, [%s] received.', get_class($element))); } /* @var $element Abstraction\ElementAbstraction */ if ($preLastCharOfElementSource == '/') { // ... and if this is a standalone markup element - like {trololo.trololo /}, // create and initialize it. $element->setSource($elementSource); $element->parseSource(); } else { if ($secondCharOfElementSource == '/') { // ... or if this this element is a closing part of a block, // i.e. - begins with a slash, check if class of instace we // created earlier actually is block constructor. If it is so, // treat created element as block constructor and get block // end element from it. Otherwise do nothing, skip this element. if ($element instanceof Abstraction\SupraMarkupBlockConstructor) { /* @var $element Abstraction\SupraMarkupBlockConstructor */ $element = $element->makeEnd(); $this->elements[] = $element; } } else { // ... otherwise this looks like an opening part of a block. We check if // instace of this element is subclass of SupraMarkupBlockConstructor, then proceed to // fetch coresponding block start element. Otherwise use element already created. This is because // there might be some errornous SupraMarkup cases when, for exampl {supra.image ...} does not // have a slash in the end. if ($element instanceof Abstraction\SupraMarkupBlockConstructor) { /* @var $element Abstraction\SupraMarkupBlockConstructor */ $element = $element->makeStart(); } $element->setSource($elementSource); $element->parseSource(); $this->elements[] = $element; } } } else { // If is just a piece of content (HTML), just create element and set it's content. $element = new HtmlElement(); $element->setContent($elementSource); $this->elements[] = $element; } } }