| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254 | 
							- <?php namespace System;
 
- class HTML {
 
- 	/**
 
- 	 * Convert HTML characters to entities.
 
- 	 *
 
- 	 * @param  string  $value
 
- 	 * @return string
 
- 	 */
 
- 	public static function entities($value)
 
- 	{
 
-         return htmlentities($value, ENT_QUOTES, Config::get('application.encoding'), false);
 
- 	}
 
- 	/**
 
- 	 * Generate a JavaScript reference.
 
- 	 *
 
- 	 * @param  string  $url
 
- 	 * @return string
 
- 	 */
 
- 	public static function script($url)
 
- 	{
 
- 		return '<script type="text/javascript" src="'.trim(static::entities(URL::to($url)), '.js').'.js"></script>'.PHP_EOL;
 
- 	}
 
- 	/**
 
- 	 * Generate a CSS reference.
 
- 	 *
 
- 	 * @param  string  $url
 
- 	 * @return string
 
- 	 */
 
- 	public static function style($url, $media = 'all')
 
- 	{
 
- 		return '<link href="'.trim(static::entities(URL::to($url)), '.css').'.css" rel="stylesheet" type="text/css" media="'.$media.'" />'.PHP_EOL;
 
- 	}
 
- 	/**
 
- 	 * Generate a HTML link.
 
- 	 *
 
- 	 * @param  string  $url
 
- 	 * @param  string  $title
 
- 	 * @param  array   $attributes
 
- 	 * @param  bool    $https
 
- 	 * @return string
 
- 	 */
 
- 	public static function link($url, $title, $attributes = array(), $https = false)
 
- 	{
 
- 		return '<a href="'.static::entities(URL::to($url, $https)).'"'.static::attributes($attributes).'>'.static::entities($title).'</a>';
 
- 	}
 
- 	/**
 
- 	 * Generate a HTTPS HTML link.
 
- 	 *
 
- 	 * @param  string  $url
 
- 	 * @param  string  $title
 
- 	 * @param  array   $attributes
 
- 	 * @return string
 
- 	 */
 
- 	public static function secure_link($url, $title, $attributes)
 
- 	{
 
- 		return static::link($url, $title, $attributes, true);
 
- 	}
 
- 	/**
 
- 	 * Generate an HTML mailto link.
 
- 	 *
 
- 	 * @param  string  $email
 
- 	 * @param  string  $title
 
- 	 * @param  array   $attributes
 
- 	 * @return string
 
- 	 */
 
- 	public static function mailto($email, $title = null, $attributes = array())
 
- 	{
 
- 		// -------------------------------------------------------
 
- 		// Obfuscate the e-mail address.
 
- 		// -------------------------------------------------------
 
- 		$email = static::email($email);
 
- 		if (is_null($title))
 
- 		{
 
- 			$title = $email;
 
- 		}
 
- 		return '<a href="mailto:'.$email.'"'.static::attributes($attributes).'>'.static::entities($title).'</a>';
 
- 	}
 
- 	/**
 
- 	 * Obfuscate an e-mail address to prevent spam-bots from sniffing it.
 
- 	 *
 
- 	 * @param  string  $email
 
- 	 * @return string
 
- 	 */
 
- 	public static function email($email)
 
- 	{
 
- 		return str_replace('@', '@', static::obfuscate($email));
 
- 	}
 
- 	/**
 
- 	 * Generate an HTML image.
 
- 	 *
 
- 	 * @param  string  $url
 
- 	 * @param  string  $alt
 
- 	 * @param  array   $attributes
 
- 	 * @return string
 
- 	 */
 
- 	public static function image($url, $alt = '', $attributes = array())
 
- 	{
 
- 		$attributes['alt'] = static::entities($alt);
 
- 		return '<img src="'.static::entities(URL::to($url)).'"'.static::attributes($attributes).' />';
 
- 	}
 
- 	/**
 
- 	 * Generate HTML breaks.
 
- 	 *
 
- 	 * @param  int     $count
 
- 	 * @return string
 
- 	 */
 
- 	public static function breaks($count = 1)
 
- 	{
 
- 		return str_repeat('<br />', $count);
 
- 	}
 
- 	/**
 
- 	 * Generate non-breaking spaces.
 
- 	 *
 
- 	 * @param  int     $count
 
- 	 * @return string
 
- 	 */
 
- 	public static function spaces($count = 1)
 
- 	{
 
- 		return str_repeat(' ', $count);
 
- 	}
 
- 	/**
 
- 	 * Generate an ordered list.
 
- 	 *
 
- 	 * @param  array   $list
 
- 	 * @param  array   $attributes
 
- 	 * @return string
 
- 	 */
 
- 	public static function ol($list, $attributes = array())
 
- 	{
 
- 		return static::list_elements('ol', $list, $attributes);
 
- 	}
 
- 	/**
 
- 	 * Generate an un-ordered list.
 
- 	 *
 
- 	 * @param  array   $list
 
- 	 * @param  array   $attributes
 
- 	 * @return string
 
- 	 */
 
- 	public static function ul($list, $attributes = array())
 
- 	{
 
- 		return static::list_elements('ul', $list, $attributes);
 
- 	}
 
- 	/**
 
- 	 * Generate an ordered or un-ordered list.
 
- 	 *
 
- 	 * @param  string  $type
 
- 	 * @param  array   $list
 
- 	 * @param  array   $attributes
 
- 	 * @return string
 
- 	 */
 
- 	private static function list_elements($type, $list, $attributes)
 
- 	{
 
- 		if ( ! is_array($list))
 
- 		{
 
- 			return '';
 
- 		}
 
- 		$html = '';
 
- 		foreach ($list as $key => $value)
 
- 		{
 
- 			$html .= '<li>'.static::entities($value).'</li>';
 
- 		}
 
- 		return '<'.$type.static::attributes($attributes).'>'.$html.'</'.$type.'>';
 
- 	}
 
- 	/**
 
- 	 * Build a list of HTML attributes.
 
- 	 *
 
- 	 * @param  array   $attributes
 
- 	 * @return string
 
- 	 */		
 
- 	public static function attributes($attributes)
 
- 	{
 
- 		$html = array();
 
- 		foreach ($attributes as $key => $value)
 
- 		{
 
- 			if ( ! is_null($value))
 
- 			{
 
- 				$html[] = $key.'="'.static::entities($value).'"';
 
- 			}
 
- 		}
 
- 		if (count($html) > 0)
 
- 		{
 
- 			return ' '.implode(' ', $html);
 
- 		}
 
- 		else
 
- 		{
 
- 			return '';
 
- 		}
 
- 	}
 
- 	/**
 
- 	 * Obfuscate a string to prevent spam-bots from sniffing it.
 
- 	 *
 
- 	 * @param  string  $value
 
- 	 * @return string
 
- 	 */
 
- 	public static function obfuscate($value)
 
- 	{
 
- 		$safe = '';
 
- 		// -------------------------------------------------------
 
- 		// Spin through the string letter by letter.
 
- 		// -------------------------------------------------------
 
- 		foreach (str_split($value) as $letter)
 
- 		{
 
- 			switch (rand(1, 3))
 
- 			{
 
- 				// -------------------------------------------------------
 
- 				// Convert the letter to its entity representation.
 
- 				// -------------------------------------------------------
 
- 				case 1:
 
- 					$safe .= '&#'.ord($letter).';';
 
- 					break;
 
- 				// -------------------------------------------------------
 
- 				// Convert the letter to a Hex character code.
 
- 				// -------------------------------------------------------
 
- 				case 2:
 
- 					$safe .= '&#x'.dechex(ord($letter)).';';
 
- 					break;
 
- 				// -------------------------------------------------------
 
- 				// No encoding.
 
- 				// -------------------------------------------------------
 
- 				case 3:
 
- 					$safe .= $letter;
 
- 			}
 
- 		}
 
- 		return $safe;
 
- 	}
 
- }
 
 
  |