'; 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 = array()) { 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 = array()) { 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')); } public static function toggleClass($class, $name, $display) { if ($display) { return self::addClass($class, $name); } return self::removeClass($class, $name); } public static function removeClass($class, $name) { $parts = explode(' ', $class); $parts = array_filter($parts, 'trim'); return implode(' ', Qs_Array::excludeValue($parts, $name)); } public static function addClass($class, $name) { $parts = explode(' ', $class); $parts = array_filter($parts, 'trim'); if (!in_array($name, $parts)) { $parts[] = $name; } return implode(' ', $parts); } public static function renderHelpIcon($text) { return ' ' . Html::renderContainer('i', '', [ 'class' => 'fa fa-lg fa-question', 'data-toggle' => 'tooltip', 'data-placement' => 'right', 'data-original-title' => $text, ]); } }