From 3edd88eee84886fc6ba3e1fc25beda3c424370bc Mon Sep 17 00:00:00 2001 From: tubalmartin Date: Sat, 3 Mar 2012 22:10:34 +0100 Subject: An even better url_title helper. Tests: http://codepad.org/tuJgvkyN Changelog entry added for 2.1.1 --- system/helpers/url_helper.php | 27 +++++++-------------------- 1 file changed, 7 insertions(+), 20 deletions(-) (limited to 'system/helpers/url_helper.php') diff --git a/system/helpers/url_helper.php b/system/helpers/url_helper.php index 9f4b85248..cdb6dae9c 100644 --- a/system/helpers/url_helper.php +++ b/system/helpers/url_helper.php @@ -478,27 +478,14 @@ if ( ! function_exists('url_title')) { function url_title($str, $separator = 'dash', $lowercase = FALSE) { - if ($separator == 'dash') - { - $search = '_'; - $replace = '-'; - } - else - { - $search = '-'; - $replace = '_'; - } + $replace = $separator == 'dash' ? '-' : '_'; $trans = array( - '&\#\d+?;' => '', - '&\S+?;' => '', - '\s+' => $replace, - '[^a-z0-9\-\._]' => '', - $replace.'+' => $replace, - $replace.'$' => $replace, - '^'.$replace => $replace, - '\.+$' => '' - ); + '&.+?;' => '', + '[^a-z0-9 _-]' => '', + '\s+' => $replace, + $replace.'+' => $replace + ); $str = strip_tags($str); @@ -512,7 +499,7 @@ if ( ! function_exists('url_title')) $str = strtolower($str); } - return trim(stripslashes($str)); + return trim($str, $replace); } } -- cgit v1.2.3-24-g4f1b From 1a6971030718e2e92e6fc80750f7a14faf035257 Mon Sep 17 00:00:00 2001 From: tubalmartin Date: Sun, 4 Mar 2012 16:01:11 +0100 Subject: Allow developers to use any string as a separator, not just dashes or underscores. Backwards compatible when using 'dash' or 'underscore' as string separator. Tests: http://codepad.org/DWcxVH5r --- system/helpers/url_helper.php | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) (limited to 'system/helpers/url_helper.php') diff --git a/system/helpers/url_helper.php b/system/helpers/url_helper.php index cdb6dae9c..f1e8c6ac6 100644 --- a/system/helpers/url_helper.php +++ b/system/helpers/url_helper.php @@ -466,25 +466,34 @@ if ( ! function_exists('prep_url')) * Create URL Title * * Takes a "title" string as input and creates a - * human-friendly URL string with either a dash - * or an underscore as the word separator. + * human-friendly URL string with a "separator" string + * as the word separator. * * @access public * @param string the string - * @param string the separator: dash, or underscore + * @param string the separator * @return string */ if ( ! function_exists('url_title')) { - function url_title($str, $separator = 'dash', $lowercase = FALSE) + function url_title($str, $separator = '-', $lowercase = FALSE) { - $replace = $separator == 'dash' ? '-' : '_'; + if ($separator == 'dash') + { + $separator = '-'; + } + else if ($separator == 'underscore') + { + $separator = '_'; + } + + $q_separator = preg_quote($separator); $trans = array( - '&.+?;' => '', - '[^a-z0-9 _-]' => '', - '\s+' => $replace, - $replace.'+' => $replace + '&.+?;' => '', + '[^a-z0-9 _-]' => '', + '\s+' => $separator, + '('.$q_separator.')+' => $separator ); $str = strip_tags($str); @@ -499,7 +508,7 @@ if ( ! function_exists('url_title')) $str = strtolower($str); } - return trim($str, $replace); + return trim($str, $separator); } } -- cgit v1.2.3-24-g4f1b From 07c1ac830b4e98aa40f48baef3dd05fb68c0a836 Mon Sep 17 00:00:00 2001 From: Phil Sturgeon Date: Fri, 9 Mar 2012 17:03:37 +0000 Subject: Bumped CodeIgniter's PHP requirement to 5.2.4. Yes I know PHP 5.4 just came out, and yes I know PHP 5.3 has lovely features, but there are plenty of corporate systems running on CodeIgniter and PHP 5.3 still is not widely supported enough. CodeIgniter is great for distributed applications, and this is the highest we can reasonably go without breaking support. PHP 5.3 will most likely happen in another year or so. Fingers crossed on that one anyway... --- system/helpers/url_helper.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/helpers/url_helper.php') diff --git a/system/helpers/url_helper.php b/system/helpers/url_helper.php index 3f0fef58e..2ae1fd37b 100644 --- a/system/helpers/url_helper.php +++ b/system/helpers/url_helper.php @@ -2,7 +2,7 @@ /** * CodeIgniter * - * An open source application development framework for PHP 5.1.6 or newer + * An open source application development framework for PHP 5.2.4 or newer * * NOTICE OF LICENSE * -- cgit v1.2.3-24-g4f1b From 1222087be893a38927c0a61566231abf093fbf2f Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Mon, 26 Mar 2012 21:38:56 +0300 Subject: Remove access description lines and cleanup the url helper --- system/helpers/url_helper.php | 59 ++++++++++++++++--------------------------- 1 file changed, 22 insertions(+), 37 deletions(-) (limited to 'system/helpers/url_helper.php') diff --git a/system/helpers/url_helper.php b/system/helpers/url_helper.php index 2ae1fd37b..5576c2748 100644 --- a/system/helpers/url_helper.php +++ b/system/helpers/url_helper.php @@ -25,8 +25,6 @@ * @filesource */ -// ------------------------------------------------------------------------ - /** * CodeIgniter URL Helpers * @@ -45,7 +43,6 @@ * Create a local URL based on your basepath. Segments can be passed via the * first parameter either as a string or an array. * - * @access public * @param string * @return string */ @@ -67,8 +64,7 @@ if ( ! function_exists('site_url')) * Segments can be passed in as a string or an array, same as site_url * or a URL to a file can be passed in, e.g. to an image file. * - * @access public - * @param string + * @param string * @return string */ if ( ! function_exists('base_url')) @@ -88,7 +84,6 @@ if ( ! function_exists('base_url')) * Returns the full URL (including segments) of the page where this * function is placed * - * @access public * @return string */ if ( ! function_exists('current_url')) @@ -106,7 +101,6 @@ if ( ! function_exists('current_url')) * * Returns the URI segments. * - * @access public * @return string */ if ( ! function_exists('uri_string')) @@ -125,7 +119,6 @@ if ( ! function_exists('uri_string')) * * Returns the "index_page" from your config file * - * @access public * @return string */ if ( ! function_exists('index_page')) @@ -144,7 +137,6 @@ if ( ! function_exists('index_page')) * * Creates an anchor based on the local URL. * - * @access public * @param string the URL * @param string the link title * @param mixed any attributes @@ -158,7 +150,7 @@ if ( ! function_exists('anchor')) if ( ! is_array($uri)) { - $site_url = ( ! preg_match('!^\w+://! i', $uri)) ? site_url($uri) : $uri; + $site_url = preg_match('!^\w+://! i', $uri) ? $uri : site_url($uri); } else { @@ -187,7 +179,6 @@ if ( ! function_exists('anchor')) * Creates an anchor based on the local URL. The link * opens a new window based on the attributes specified. * - * @access public * @param string the URL * @param string the link title * @param mixed any attributes @@ -198,7 +189,7 @@ if ( ! function_exists('anchor_popup')) function anchor_popup($uri = '', $title = '', $attributes = FALSE) { $title = (string) $title; - $site_url = ( ! preg_match('!^\w+://! i', $uri)) ? site_url($uri) : $uri; + $site_url = preg_match('!^\w+://! i', $uri) ? $uri : site_url($uri); if ($title == '') { @@ -207,7 +198,7 @@ if ( ! function_exists('anchor_popup')) if ($attributes === FALSE) { - return "".$title.""; + return "".$title.''; } if ( ! is_array($attributes)) @@ -217,7 +208,7 @@ if ( ! function_exists('anchor_popup')) foreach (array('width' => '800', 'height' => '600', 'scrollbars' => 'yes', 'status' => 'yes', 'resizable' => 'yes', 'screenx' => '0', 'screeny' => '0', ) as $key => $val) { - $atts[$key] = ( ! isset($attributes[$key])) ? $val : $attributes[$key]; + $atts[$key] = isset($attributes[$key]) ? $attributes[$key] : $val; unset($attributes[$key]); } @@ -226,7 +217,7 @@ if ( ! function_exists('anchor_popup')) $attributes = _parse_attributes($attributes); } - return "".$title.""; + return "'.$title.''; } } @@ -235,7 +226,6 @@ if ( ! function_exists('anchor_popup')) /** * Mailto Link * - * @access public * @param string the email address * @param string the link title * @param mixed any attributes @@ -263,7 +253,6 @@ if ( ! function_exists('mailto')) * * Create a spam-protected mailto link written in Javascript * - * @access public * @param string the email address * @param string the link title * @param mixed any attributes @@ -373,10 +362,9 @@ if ( ! function_exists('safe_mailto')) * * Automatically links URL and Email addresses. * Note: There's a bit of extra code here to deal with - * URLs or emails that end in a period. We'll strip these + * URLs or emails that end in a period. We'll strip these * off and add them after the link. * - * @access public * @param string the string * @param string the type: email, url, or both * @param bool whether to create pop-up links @@ -440,7 +428,6 @@ if ( ! function_exists('auto_link')) * * Simply adds the http:// part if no scheme is included * - * @access public * @param string the URL * @return string */ @@ -470,12 +457,12 @@ if ( ! function_exists('prep_url')) * Create URL Title * * Takes a "title" string as input and creates a - * human-friendly URL string with a "separator" string + * human-friendly URL string with a "separator" string * as the word separator. * - * @access public * @param string the string * @param string the separator + * @param bool * @return string */ if ( ! function_exists('url_title')) @@ -484,21 +471,21 @@ if ( ! function_exists('url_title')) { if ($separator === 'dash') { - $separator = '-'; + $separator = '-'; } - else if ($separator == 'underscore') + elseif ($separator === 'underscore') { - $separator = '_'; + $separator = '_'; } - + $q_separator = preg_quote($separator); $trans = array( - '&.+?;' => '', - '[^a-z0-9 _-]' => '', - '\s+' => $separator, - '('.$q_separator.')+' => $separator - ); + '&.+?;' => '', + '[^a-z0-9 _-]' => '', + '\s+' => $separator, + '('.$q_separator.')+' => $separator + ); $str = strip_tags($str); foreach ($trans as $key => $val) @@ -524,7 +511,6 @@ if ( ! function_exists('url_title')) * For very fine grained control over headers, you could use the Output * Library's set_header() function. * - * @access public * @param string the URL * @param string the method: location or refresh * @return string @@ -564,7 +550,6 @@ if ( ! function_exists('redirect')) * * Some of the functions use this * - * @access private * @param array * @param bool * @return string @@ -583,15 +568,15 @@ if ( ! function_exists('_parse_attributes')) { if ($javascript == TRUE) { - $att .= $key . '=' . $val . ','; + $att .= $key.'='.$val.','; } else { - $att .= ' ' . $key . '="' . $val . '"'; + $att .= ' '.$key.'="'.$val.'"'; } } - if ($javascript == TRUE AND $att != '') + if ($javascript == TRUE && $att != '') { return substr($att, 0, -1); } @@ -601,4 +586,4 @@ if ( ! function_exists('_parse_attributes')) } /* End of file url_helper.php */ -/* Location: ./system/helpers/url_helper.php */ +/* Location: ./system/helpers/url_helper.php */ \ No newline at end of file -- cgit v1.2.3-24-g4f1b