placeholders = $placeholders; return $this; } /** * @return array */ public function getPlaceholders() { return $this->placeholders; } protected function getView() { return Qs_View::getInstance(); } protected function render(array $item) { $caret = ''; $ul = ''; if ($item['sub']) { $caret = ''; $ul = $this->renderTag('ul', $this->renderSubItems($item['sub']), $item['attribs']['ul']); } $a = $this->renderTag( 'a', $this->getView()->escape($item['title']) . $caret, $item['attribs']['a'] ); return $this->renderTag('li', $a . $ul, $item['attribs']['li']); } protected function renderTag($tag, $content, array $attribs = array()) { return '<' . $tag . $this->renderAttribs($attribs) . '>' . $content . ''; } protected function fillPlaceholders(array &$array) { if (empty($this->placeholders)) { return $this; } $keys = array_map(function ($value) {return '{' . $value . '}';}, array_keys($this->placeholders)); $data = array_combine($keys, $this->placeholders); foreach ($array as &$element) { if (is_string($element)) { $element = str_replace(array_keys($data), array_values($data), $element); } } return $this; } protected function renderAttribs(array $attribs) { $this->fillPlaceholders($attribs); $xhtml = ''; foreach ($attribs as $key => $val) { $key = htmlspecialchars($key, ENT_COMPAT, $this->encoding); $val = htmlspecialchars($val, ENT_COMPAT, $this->encoding); $xhtml .= " $key=\"$val\""; } return $xhtml; } protected function renderSubItems(array $items) { $html = ''; foreach ($items as $item) { $html .= $this->renderTag( 'li', $this->renderTag('a', $this->getView()->escape($item['title']), $item['attribs']) ); } return $html; } }