added asset links and improved html class.
This commit is contained in:
parent
868a33fb9c
commit
bf44ce81d7
|
@ -21,7 +21,7 @@ public static function entities($value)
|
|||
*/
|
||||
public static function script($url)
|
||||
{
|
||||
return '<script type="text/javascript" src="'.trim(static::entities(URL::to($url)), '.js').'.js"></script>'.PHP_EOL;
|
||||
return '<script type="text/javascript" src="'.trim(static::entities(URL::to_asset($url)), '.js').'.js"></script>'.PHP_EOL;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -32,7 +32,7 @@ public static function script($url)
|
|||
*/
|
||||
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;
|
||||
return '<link href="'.trim(static::entities(URL::to_asset($url)), '.css').'.css" rel="stylesheet" type="text/css" media="'.$media.'" />'.PHP_EOL;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -42,11 +42,12 @@ public static function style($url, $media = 'all')
|
|||
* @param string $title
|
||||
* @param array $attributes
|
||||
* @param bool $https
|
||||
* @param bool $asset
|
||||
* @return string
|
||||
*/
|
||||
public static function link($url, $title, $attributes = array(), $https = false)
|
||||
public static function link($url, $title, $attributes = array(), $https = false, $asset = false)
|
||||
{
|
||||
return '<a href="'.static::entities(URL::to($url, $https)).'"'.static::attributes($attributes).'>'.static::entities($title).'</a>';
|
||||
return '<a href="'.static::entities(URL::to($url, $https, $asset)).'"'.static::attributes($attributes).'>'.static::entities($title).'</a>';
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -57,11 +58,24 @@ public static function link($url, $title, $attributes = array(), $https = false)
|
|||
* @param array $attributes
|
||||
* @return string
|
||||
*/
|
||||
public static function secure_link($url, $title, $attributes)
|
||||
public static function link_to_secure($url, $title, $attributes)
|
||||
{
|
||||
return static::link($url, $title, $attributes, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate an HTML link to an asset.
|
||||
*
|
||||
* @param string $url
|
||||
* @param string $title
|
||||
* @param array $attributes
|
||||
* @return string
|
||||
*/
|
||||
public static function link_to_asset($url, $title, $attributes)
|
||||
{
|
||||
return static::link($url, $title, $attributes, false, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate an HTML mailto link.
|
||||
*
|
||||
|
@ -72,9 +86,6 @@ public static function secure_link($url, $title, $attributes)
|
|||
*/
|
||||
public static function mailto($email, $title = null, $attributes = array())
|
||||
{
|
||||
// -------------------------------------------------------
|
||||
// Obfuscate the e-mail address.
|
||||
// -------------------------------------------------------
|
||||
$email = static::email($email);
|
||||
|
||||
if (is_null($title))
|
||||
|
@ -107,7 +118,7 @@ public static function email($email)
|
|||
public static function image($url, $alt = '', $attributes = array())
|
||||
{
|
||||
$attributes['alt'] = static::entities($alt);
|
||||
return '<img src="'.static::entities(URL::to($url)).'"'.static::attributes($attributes).' />';
|
||||
return '<img src="'.static::entities(URL::to_asset($url)).'"'.static::attributes($attributes).' />';
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -166,11 +177,6 @@ public static function ul($list, $attributes = array())
|
|||
*/
|
||||
private static function list_elements($type, $list, $attributes)
|
||||
{
|
||||
if ( ! is_array($list))
|
||||
{
|
||||
return '';
|
||||
}
|
||||
|
||||
$html = '';
|
||||
|
||||
foreach ($list as $key => $value)
|
||||
|
@ -199,14 +205,7 @@ public static function attributes($attributes)
|
|||
}
|
||||
}
|
||||
|
||||
if (count($html) > 0)
|
||||
{
|
||||
return ' '.implode(' ', $html);
|
||||
}
|
||||
else
|
||||
{
|
||||
return '';
|
||||
}
|
||||
return (count($html) > 0) ? ' '.implode(' ', $html) : '';
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -6,9 +6,11 @@ class URL {
|
|||
* Generate an application URL.
|
||||
*
|
||||
* @param string $url
|
||||
* @param bool $https
|
||||
* @param bool $asset
|
||||
* @return string
|
||||
*/
|
||||
public static function to($url = '', $https = false)
|
||||
public static function to($url = '', $https = false, $asset = false)
|
||||
{
|
||||
// ----------------------------------------------------
|
||||
// Return the URL unchanged if it is already formed.
|
||||
|
@ -21,7 +23,17 @@ public static function to($url = '', $https = false)
|
|||
// ----------------------------------------------------
|
||||
// Get the base URL and index page.
|
||||
// ----------------------------------------------------
|
||||
$base = Config::get('application.url').'/'.Config::get('application.index');
|
||||
$base = Config::get('application.url');
|
||||
|
||||
// ----------------------------------------------------
|
||||
// Assets live in the public directory, so we don't
|
||||
// want to append the index file to the URL if the
|
||||
// URL is to an asset.
|
||||
// ----------------------------------------------------
|
||||
if ( ! $asset)
|
||||
{
|
||||
$base .= '/'.Config::get('application.index');
|
||||
}
|
||||
|
||||
// ----------------------------------------------------
|
||||
// Does the URL need an HTTPS protocol?
|
||||
|
@ -45,6 +57,18 @@ public static function to_secure($url = '')
|
|||
return static::to($url, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate an application URL to an asset. The index file
|
||||
* will not be added to the URL.
|
||||
*
|
||||
* @param string $url
|
||||
* @return string
|
||||
*/
|
||||
public static function to_asset($url)
|
||||
{
|
||||
return static::to($url, false, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate a URL from a route name.
|
||||
*
|
||||
|
|
Loading…
Reference in New Issue