From bf44ce81d7c081a6b37be4eeb6bd4924df07a874 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Thu, 16 Jun 2011 21:25:24 -0500 Subject: [PATCH] added asset links and improved html class. --- system/html.php | 43 +++++++++++++++++++++---------------------- system/url.php | 28 ++++++++++++++++++++++++++-- 2 files changed, 47 insertions(+), 24 deletions(-) diff --git a/system/html.php b/system/html.php index f044234b..09fb02ec 100644 --- a/system/html.php +++ b/system/html.php @@ -21,7 +21,7 @@ public static function entities($value) */ public static function script($url) { - return ''.PHP_EOL; + return ''.PHP_EOL; } /** @@ -32,7 +32,7 @@ public static function script($url) */ public static function style($url, $media = 'all') { - return ''.PHP_EOL; + return ''.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 ''.static::entities($title).''; + return ''.static::entities($title).''; } /** @@ -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 ''; + return ''; } /** @@ -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) : ''; } /** diff --git a/system/url.php b/system/url.php index 52fb6c71..a3643a44 100644 --- a/system/url.php +++ b/system/url.php @@ -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. *