/techne/expressionengine/helpers/EE_url_helper.php

https://github.com/mondomon916/LYBC · PHP · 128 lines · 53 code · 22 blank · 53 comment · 12 complexity · c3035dde95e332822830ce21a37a9e65 MD5 · raw file

  1. <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
  2. /**
  3. * CodeIgniter
  4. *
  5. * An open source application development framework for PHP 4.3.2 or newer
  6. *
  7. * @package CodeIgniter
  8. * @author ExpressionEngine Dev Team
  9. * @copyright Copyright (c) 2006, EllisLab, Inc.
  10. * @license http://codeigniter.com/user_guide/license.html
  11. * @link http://codeigniter.com
  12. * @since Version 1.0
  13. * @filesource
  14. */
  15. // ------------------------------------------------------------------------
  16. /**
  17. * ExpressionEngine URL Helper
  18. *
  19. * @package ExpressionEngine
  20. * @subpackage Helpers
  21. * @category Helpers
  22. * @author ExpressionEngine Dev Team
  23. * @link http://expressionengine.com
  24. */
  25. // ------------------------------------------------------------------------
  26. /**
  27. * Create URL Title
  28. *
  29. * Takes a "title" string as input and creates a
  30. * human-friendly URL string with either a dash
  31. * or an underscore as the word separator.
  32. *
  33. * @review maybe roll into CI proper
  34. *
  35. * @access public
  36. * @param string the string
  37. * @param string the separator: dash, or underscore
  38. * @return string
  39. */
  40. if ( ! function_exists('url_title'))
  41. {
  42. function url_title($str, $separator = 'dash', $lowercase = FALSE)
  43. {
  44. if (UTF8_ENABLED)
  45. {
  46. $CI =& get_instance();
  47. $CI->load->helper('text');
  48. $str = utf8_decode($str);
  49. $str = preg_replace_callback('/(.)/', 'convert_accented_characters', $str);
  50. }
  51. $separator = ($separator == 'dash') ? '-' : '_';
  52. $trans = array(
  53. '&\#\d+?;' => '',
  54. '&\S+?;' => '',
  55. '\s+|/+' => $separator,
  56. '[^a-z0-9\-\._]' => '',
  57. $separator.'+' => $separator,
  58. '^[-_]+|[-_]+$' => '',
  59. '\.+$' => ''
  60. );
  61. $str = strip_tags($str);
  62. foreach ($trans as $key => $val)
  63. {
  64. $str = preg_replace("#".$key."#i", $val, $str);
  65. }
  66. if ($lowercase === TRUE)
  67. {
  68. $str = strtolower($str);
  69. }
  70. return trim(stripslashes($str));
  71. }
  72. }
  73. // --------------------------------------------------------------------
  74. /**
  75. * Anchor Link
  76. *
  77. * Creates an anchor based on the local URL.
  78. *
  79. * @access public
  80. * @param string the URL
  81. * @param string the link title
  82. * @param mixed any attributes
  83. * @return string
  84. */
  85. function anchor($uri = '', $title = '', $attributes = '')
  86. {
  87. $title = (string) $title;
  88. $site_url = is_array($uri) ? implode('/', $uri) : $uri;
  89. if (REQ != 'CP' && ! preg_match('!^\w+://! i', $site_url))
  90. {
  91. $EE =& get_instance();
  92. $site_url = $EE->functions->fetch_site_index(TRUE).$site_url;
  93. }
  94. if ($title == '')
  95. {
  96. $title = $site_url;
  97. }
  98. if ($attributes != '')
  99. {
  100. $attributes = _parse_attributes($attributes);
  101. }
  102. return '<a href="'.$site_url.'"'.$attributes.'>'.$title.'</a>';
  103. }
  104. // --------------------------------------------------------------------
  105. /* End of file EE_url_helper.php */
  106. /* Location: ./system/expressionengine/helpers/EE_url_helper.php */