/** * Outputs tags for external resources based on the type passed in. If we * have a resource that should be grouped within conditional comments, then * the rendering is handed off to a helper function. * * @see outputGroupedExternalResources() * * @param &array $items List of external resource groups to be output. * @param strong $type Used to determine the tag function (style, script) */ protected static function outputExternalResources(&$items, $type) { switch ($type) { case 'script': $function = array('\\Jerity\\Core\\Tag', 'script'); $parameters = array(null); break; case 'style': $function = array('\\Jerity\\Core\\Tag', 'link'); $parameters = array(Tag::getDefaultStyleContentType()); break; default: throw new \InvalidArgumentException('Unrecognised external resource type: ' . $type); } if (self::getExternalResourceGrouping()) { foreach ($items as $key => $items1) { switch ($key) { case 'lt': case 'gt': foreach ($items1 as $version => $items2) { foreach ($items2 as $operator => $items3) { if (empty($items3)) { continue; } self::outputGroupedExternalResources($items3, array($operator, 'IE', $version), $type); } } break; case 'eq': foreach ($items1 as $version => $items2) { if (empty($items2)) { continue; } self::outputGroupedExternalResources($items2, array('IE', $version), $type); } break; case 'ie': if (empty($items1)) { continue; } self::outputGroupedExternalResources($items1, array('IE'), $type); break; case '**': default: foreach ($items1 as $href => $attrs) { $params = $parameters; if ($type == 'style') { array_unshift($params, $href); } $params[] = $attrs; echo call_user_func_array($function, $params), PHP_EOL; } } } } else { foreach ($items as $href => $attrs) { $params = $parameters; if ($type == 'style') { array_unshift($params, $href); } $params[] = $attrs; $content = call_user_func_array($function, $params); if (preg_match(self::$resource_iecc_regex, $content, $m)) { $expression = !empty($m[1]) ? $m[1] . ' ' : ''; $expression .= 'IE'; $expression .= !empty($m[2]) ? ' ' . strtr($m[2], '_', '.') : ''; $content = Tag::ieConditionalComment($expression, $content); } else { $content .= PHP_EOL; } echo $content; } } }
/** * */ public function testGetContentMaskClose() { $data = array('script' => '//-->', 'style' => '-->'); foreach ($data as $tag => $mask) { $this->assertSame($mask, Tag::getContentMask($tag, false)); } }
/** * Render this footnote list using the current render context and return it * as a string. * * @return string */ public function render() { $out = Tag::renderTag('ul', array('class' => $this->class_list)) . PHP_EOL; $index = 1; foreach ($this->footnotes as $footnote) { $attrs = array('href' => '#' . $this->fragment . '-' . $index); $a = Tag::renderTag('a', $attrs, $index); $attrs = array('id' => $this->fragment . $index); $out .= Tag::renderTag('li', $attrs, $a . ': ' . $footnote) . PHP_EOL; $index++; } $out .= '</ul>' . PHP_EOL; return $out; }
/** * Wraps a string in paragraphs. Wraps double line breaks with <p> and </p>, * and replaces single line breaks with <br>. * * @param string $string The string to convert to paragraphs * * @return string * * @todo Correctly handle blank lines with horizontal whitespace! */ public static function nl2p($string) { $string = '<p>' . trim($string) . '</p>'; $string = preg_replace("/(?<![\n\r])(?:\r|\n|\r\n)(?![\n\r])/", Tag::br(), $string); $string = preg_replace("/(?<![\n\r])[\n\r]{2,}(?![\n\r])/", "</p>\n<p>", $string); return $string; }
/** * Render a custom block of HTML. * * @param string $error An error message to show, if applicable. * * @return string */ public function render($error = null) { $out = ''; if (isset($this['label'])) { $labelcontent = String::escape($this['label']) . ':'; if (isset($this['required']) && $this['required']) { $labelcontent .= ' <em>Required</em>'; } $out .= Tag::renderTag('label', array('for' => $this['id']), $labelcontent) . "\n"; } if (isset($this['content'])) { $content = $this['content']; } else { $content = ''; } if ($error) { $out .= self::renderError($this->props, $error); if (!isset($this->props['class'])) { $this->props['class'] = 'haserror'; } elseif (!preg_match('/(?:^| )haserror(?:$| )/', $this->props['class'])) { $this->props['class'] .= ' haserror'; } } $attrs = array_diff_key($this->props, array_flip(array('content', 'escape', 'name', 'type'))); $out .= Tag::renderTag('div', $attrs, $content) . "\n"; return $out; }
/** * Render a list of URLs and their child lists, applying highlight classes * to the \t <li> items as necessary. * * @param array $urls The list of URLs to be rendered. * @param array $top_attrs The attributes for the \t <ul> parent. * @param int $level The current level in the URL tree. * * @return string */ protected function renderURLs($urls, $top_attrs, $level = 0) { $out = ''; if ($this->level_hints) { if (isset($top_attrs['class'])) { $top_attrs['class'] .= ' level' . $level; } else { $top_attrs['class'] = 'level' . $level; } } $out .= Tag::renderTag('ul', $top_attrs); $cururl = $this->getOurUrl(); $besturl = $this->getBestUrl($level); foreach ($urls as $url) { if (!isset($url[1])) { $a_text = htmlentities($url[0], ENT_QUOTES, 'UTF-8'); $content = Tag::renderTag('span', array('class' => 'nolink'), $a_text); if (isset($i_attrs['_children']) && count($i_attrs['_children'])) { $children = $i_attrs['_children']; $child_attrs = isset($i_attrs['_child_attrs']) ? $i_attrs['_child_attrs'] : array(); $content .= $this->renderURLs($children, $child_attrs, $level + 1); } $out .= Tag::renderTag('li', $i_attrs, $content); continue; } $a_text = htmlentities($url[0], ENT_QUOTES, 'UTF-8'); $a_attrs = array('href' => $url[1]); $i_attrs = isset($url[2]) ? $url[2] : array(); $i_class = isset($i_attrs['class']) ? array($i_attrs['class']) : array(); if (isset($i_attrs['accesskey'])) { $a_attrs['accesskey'] =& $i_attrs['accesskey']; unset($i_attrs['accesskey']); } $static_link = false; if (!is_null($this->exact_url_class) && $url[1] == $cururl) { $i_class[] = $this->exact_url_class; $static_link |= $this->static_exact; } elseif (!is_null($this->best_match_class)) { if ($besturl == false && isset($i_attrs['_default']) && $i_attrs['_default'] || $url[1] == $besturl) { $i_class[] = $this->best_match_class; $static_link |= $this->static_best; } } if (count($i_class)) { $i_attrs['class'] = implode(' ', $i_class); } if ($static_link) { $content = Tag::renderTag('span', array(), $a_text); if (isset($i_attrs['_children']) && count($i_attrs['_children'])) { $children = $i_attrs['_children']; $child_attrs = isset($i_attrs['_child_attrs']) ? $i_attrs['_child_attrs'] : array(); $content .= $this->renderURLs($children, $child_attrs, $level + 1); } } else { $content = Tag::renderTag('a', $a_attrs, $a_text); if (isset($i_attrs['_children']) && count($i_attrs['_children'])) { $children = $i_attrs['_children']; $child_attrs = isset($i_attrs['_child_attrs']) ? $i_attrs['_child_attrs'] : array(); $content .= $this->renderURLs($children, $child_attrs, $level + 1); } } $out .= Tag::renderTag('li', $i_attrs, $content); } $out .= "</ul>"; return $out; }