'; foreach ($list as $title) { $html .= '
  • ' . htmlspecialchars($title) . '
  • ' . PHP_EOL; } $html .= '' . PHP_EOL; return $html; } public static function renderLink($url, $text = null, array $attribs = []) { if (empty($text)) { $text = $url; } $attribs['href'] = $url; return self::renderContainer('a', $text, $attribs); } public static function renderAttribs(array $attribs) { $xhtml = ''; $enc = Qs_View::getInstance()->getEncoding(); foreach ((array) $attribs as $key => $val) { $key = htmlspecialchars($key, ENT_COMPAT, $enc); if (empty($val)) { $xhtml .= ' ' . $key; continue; } if (is_array($val)) { if (array_key_exists('callback', $val) && is_callable($val['callback']) ) { $val = call_user_func($val['callback']); } else { $val = implode(' ', $val); } } $val = htmlspecialchars($val, ENT_COMPAT, $enc); $xhtml .= " $key=\"$val\""; } return $xhtml; } /** * @param $tags * * @param $content * @param array $attribs * @return string */ public static function renderContainer($tags, $content, array $attribs = []) { if (is_string($tags)) { $tags = [['tag' => $tags]]; } if (is_array($tags)) { $tags = array_map(function ($value) { if (is_array($value)) { return $value; } return ['tag' => $value]; }, $tags); } $tags = array_reverse($tags); $firstKey = key($tags); if ($attribs && !array_key_exists('attribs', $tags[$firstKey])) { $tags[$firstKey]['attribs'] = $attribs; } $xhtml = $content; reset($tags); foreach ($tags as $tag) { $xhtml = '<' . $tag['tag'] . self::renderAttribs(Qs_Array::get($tag, 'attribs', [])) . '>' . $xhtml . '' . PHP_EOL; } return $xhtml; } public static function renderTag($tag, array $attribs = []) { return '<' . $tag . self::renderAttribs($attribs) . '/>' . PHP_EOL; } public static function renderStylesheetLink($href, $media = 'all') { $type = 'text/css'; $rel = 'stylesheet'; return self::renderTag('link', compact('href', 'media', 'type', 'rel')); } }