url = $url; } /** * Convert an HTML string to entities. * * @param string $value * @return string */ public function entities($value) { return htmlentities($value, ENT_QUOTES, 'UTF-8', false); } /** * Convert entities to HTML characters. * * @param string $value * @return string */ public function decode($value) { return html_entity_decode($value, ENT_QUOTES, 'UTF-8'); } /** * Generate a HTML link. * * @param string $url * @param string $title * @param array $attributes * @param bool $secure * @return string */ public function link($url, $title = null, $attributes = array(), $secure = null) { $url = $this->url->to($url, $secure); $title = $title ?: $url; return 'attributes($attributes).'>'.$this->entities($title).''; } /** * Generate a HTTPS HTML link. * * @param string $url * @param string $title * @param array $attributes * @return string */ public function secureLink($url, $title = null, $attributes = array()) { return $this->link($url, $title, $attributes, true); } /** * Generate a HTML link to an asset. * * @param string $url * @param string $title * @param array $attributes * @param bool $secure * @return string */ public function linkAsset($url, $title = null, $attributes = array(), $secure = null) { $url = $this->url->asset($url, $secure); return $this->link($url, $title ?: $url, $attributes, $secure); } /** * Generate a HTTPS HTML link to an asset. * * @param string $url * @param string $title * @param array $attributes * @return string */ public function linkSecureAsset($url, $title = null, $attributes = array()) { return $this->linkAsset($url, $title, $attributes, true); } /** * Generate a HTML link to a named route. * * @param string $name * @param string $title * @param array $parameters * @param array $attributes * @return string */ public function linkRoute($name, $title = null, $parameters = array(), $attributes = array()) { return $this->link($this->url->route($name, $parameters), $title, $attributes); } /** * Generate a HTML link to a controller action. * * @param string $action * @param string $title * @param array $parameters * @param array $attributes * @return string */ public function linkAction($action, $title = null, $parameters = array(), $attributes = array()) { return $this->link($this->url->action($action, $parameters), $title, $attributes); } /** * Generate an ordered list of items. * * @param array $list * @param array $attributes * @return string */ public function ol($list, $attributes = array()) { return $this->listing('ol', $list, $attributes); } /** * Generate an un-ordered list of items. * * @param array $list * @param array $attributes * @return string */ public function ul($list, $attributes = array()) { return $this->listing('ul', $list, $attributes); } /** * Create a listing HTML element. * * @param string $type * @param array $list * @param array $attributes * @return string */ protected static function listing($type, $list, $attributes = array()) { $html = ''; if (count($list) == 0) return $html; // Essentially we will just spin through the list and build the list of the HTML // elements from the array. We will also handled nested lists in case that is // present in the array. Then we will build out the final listing elements. foreach ($list as $key => $value) { $html .= $this->listingElement($key, $type, $value); } $attributes = $this->attributes($attributes); return "<{$type}{$attributes}>{$html}{$type}>"; } /** * Create the HTML for a listing element. * * @param mixed $key * @param string $type * @param string $value * @return string */ protected static function listingElement($key, $type, $value) { if (is_array($value)) { return $this->nestedListing($key, $type, $value); } else { return '