url = $url;
$this->encoding = $encoding;
}
/**
* Convert HTML characters to entities.
*
* The encoding specified in the application configuration file will be used.
*
* @param string $value
* @return string
*/
public function entities($value)
{
return htmlentities($value, ENT_QUOTES, $this->encoding, false);
}
/**
* Generate a JavaScript reference.
*
* @param string $url
* @param array $attributes
* @return string
*/
public function script($url, $attributes = array())
{
$url = $this->entities($this->url->to_asset($url));
return ''.PHP_EOL;
}
/**
* Generate a CSS reference.
*
* @param string $url
* @param array $attributes
* @return string
*/
public function style($url, $attributes = array())
{
if ( ! array_key_exists('media', $attributes)) $attributes['media'] = 'all';
$attributes = array_merge($attributes, array('rel' => 'stylesheet', 'type' => 'text/css'));
return 'attributes($attributes).'>'.PHP_EOL;
}
/**
* Generate a HTML span.
*
* @param string $value
* @param array $attributes
* @return string
*/
public function span($value, $attributes = array())
{
return 'attributes($attributes).'>'.$this->entities($value).'';
}
/**
* Generate a HTML link.
*
* @param string $url
* @param string $title
* @param array $attributes
* @param bool $https
* @param bool $asset
* @return string
*/
public function link($url, $title, $attributes = array(), $https = false, $asset = false)
{
$url = $this->entities($this->url->to($url, $https, $asset));
return 'attributes($attributes).'>'.$this->entities($title).'';
}
/**
* Generate a HTTPS HTML link.
*
* @param string $url
* @param string $title
* @param array $attributes
* @return string
*/
public function link_to_secure($url, $title, $attributes = array())
{
return $this->link($url, $title, $attributes, true);
}
/**
* Generate an HTML link to an asset.
*
* @param string $url
* @param string $title
* @param array $attributes
* @return string
*/
public function link_to_asset($url, $title, $attributes = array(), $https = false)
{
return $this->link($url, $title, $attributes, $https, true);
}
/**
* Generate an HTTPS HTML link to an asset.
*
* @param string $url
* @param string $title
* @param array $attributes
* @return string
*/
public function link_to_secure_asset($url, $title, $attributes = array())
{
return $this->link_to_asset($url, $title, $attributes, true);
}
/**
* Generate an HTML link to a route.
*
* An array of parameters may be specified to fill in URI segment wildcards.
*
* @param string $name
* @param string $title
* @param array $parameters
* @param array $attributes
* @return string
*/
public function link_to_route($name, $title, $parameters = array(), $attributes = array(), $https = false)
{
return $this->link($this->url->to_route($name, $parameters, $https), $title, $attributes);
}
/**
* Generate an HTTPS HTML link to a route.
*
* @param string $name
* @param string $title
* @param array $parameters
* @param array $attributes
* @return string
*/
public function link_to_secure_route($name, $title, $parameters = array(), $attributes = array())
{
return $this->link_to_route($name, $title, $parameters, $attributes, true);
}
/**
* Generate an HTML mailto link.
*
* The E-Mail address will be obfuscated to protect it from spam bots.
*
* @param string $email
* @param string $title
* @param array $attributes
* @return string
*/
public function mailto($email, $title = null, $attributes = array())
{
$email = $this->email($email);
if (is_null($title)) $title = $email;
$email = 'mailto:'.$email;
return 'attributes($attributes).'>'.$this->entities($title).'';
}
/**
* Obfuscate an e-mail address to prevent spam-bots from sniffing it.
*
* @param string $email
* @return string
*/
public function email($email)
{
return str_replace('@', '@', $this->obfuscate($email));
}
/**
* Generate an HTML image.
*
* @param string $url
* @param string $alt
* @param array $attributes
* @return string
*/
public function image($url, $alt = '', $attributes = array())
{
$attributes['alt'] = $this->entities($alt);
return 'attributes($attributes).'>';
}
/**
* Generate an ordered list.
*
* @param array $list
* @param array $attributes
* @return string
*/
public function ol($list, $attributes = array())
{
return $this->list_elements('ol', $list, $attributes);
}
/**
* Generate an un-ordered list.
*
* @param array $list
* @param array $attributes
* @return string
*/
public function ul($list, $attributes = array())
{
return $this->list_elements('ul', $list, $attributes);
}
/**
* Generate an ordered or un-ordered list.
*
* @param string $type
* @param array $list
* @param array $attributes
* @return string
*/
private function list_elements($type, $list, $attributes = array())
{
$html = '';
foreach ($list as $key => $value)
{
$html .= (is_array($value)) ? $this->list_elements($type, $value) : '