Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 1 | ########## |
| 2 | URL Helper |
| 3 | ########## |
| 4 | |
| 5 | The URL Helper file contains functions that assist in working with URLs. |
| 6 | |
Derek Jones | abbf518 | 2013-07-19 16:01:52 -0700 | [diff] [blame] | 7 | .. contents:: |
| 8 | :local: |
| 9 | |
| 10 | .. raw:: html |
| 11 | |
| 12 | <div class="custom-index container"></div> |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 13 | |
| 14 | Loading this Helper |
| 15 | =================== |
| 16 | |
Andrey Andreev | 08f0f8b | 2012-11-09 10:27:43 +0200 | [diff] [blame] | 17 | This helper is loaded using the following code:: |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 18 | |
| 19 | $this->load->helper('url'); |
| 20 | |
Derek Jones | abbf518 | 2013-07-19 16:01:52 -0700 | [diff] [blame] | 21 | Available Functions |
| 22 | =================== |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 23 | |
Andrey Andreev | e0c566e | 2016-05-11 16:05:23 +0300 | [diff] [blame] | 24 | The following functions are available: |
| 25 | |
Andrey Andreev | cd3d9db | 2015-02-02 13:41:01 +0200 | [diff] [blame] | 26 | .. php:function:: site_url([$uri = ''[, $protocol = NULL]]) |
Andrey Andreev | 08f0f8b | 2012-11-09 10:27:43 +0200 | [diff] [blame] | 27 | |
| 28 | :param string $uri: URI string |
Andrey Andreev | 2023c3d | 2013-07-18 03:19:59 +0300 | [diff] [blame] | 29 | :param string $protocol: Protocol, e.g. 'http' or 'https' |
Andrey Andreev | 3de130c | 2014-02-07 23:31:49 +0200 | [diff] [blame] | 30 | :returns: Site URL |
| 31 | :rtype: string |
Andrey Andreev | 08f0f8b | 2012-11-09 10:27:43 +0200 | [diff] [blame] | 32 | |
Derek Jones | abbf518 | 2013-07-19 16:01:52 -0700 | [diff] [blame] | 33 | Returns your site URL, as specified in your config file. The index.php |
| 34 | file (or whatever you have set as your site **index_page** in your config |
| 35 | file) will be added to the URL, as will any URI segments you pass to the |
| 36 | function, plus the **url_suffix** as set in your config file. |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 37 | |
Derek Jones | abbf518 | 2013-07-19 16:01:52 -0700 | [diff] [blame] | 38 | You are encouraged to use this function any time you need to generate a |
| 39 | local URL so that your pages become more portable in the event your URL |
| 40 | changes. |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 41 | |
Derek Jones | abbf518 | 2013-07-19 16:01:52 -0700 | [diff] [blame] | 42 | Segments can be optionally passed to the function as a string or an |
| 43 | array. Here is a string example:: |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 44 | |
Derek Jones | abbf518 | 2013-07-19 16:01:52 -0700 | [diff] [blame] | 45 | echo site_url('news/local/123'); |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 46 | |
Derek Jones | abbf518 | 2013-07-19 16:01:52 -0700 | [diff] [blame] | 47 | The above example would return something like: |
| 48 | *http://example.com/index.php/news/local/123* |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 49 | |
Derek Jones | abbf518 | 2013-07-19 16:01:52 -0700 | [diff] [blame] | 50 | Here is an example of segments passed as an array:: |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 51 | |
Derek Jones | abbf518 | 2013-07-19 16:01:52 -0700 | [diff] [blame] | 52 | $segments = array('news', 'local', '123'); |
| 53 | echo site_url($segments); |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 54 | |
Derek Jones | abbf518 | 2013-07-19 16:01:52 -0700 | [diff] [blame] | 55 | This function is an alias for ``CI_Config::site_url()``. For more info, |
| 56 | please see the :doc:`Config Library <../libraries/config>` documentation. |
Andrey Andreev | 08f0f8b | 2012-11-09 10:27:43 +0200 | [diff] [blame] | 57 | |
Andrey Andreev | cd3d9db | 2015-02-02 13:41:01 +0200 | [diff] [blame] | 58 | .. php:function:: base_url($uri = '', $protocol = NULL) |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 59 | |
Andrey Andreev | 08f0f8b | 2012-11-09 10:27:43 +0200 | [diff] [blame] | 60 | :param string $uri: URI string |
Andrey Andreev | 2023c3d | 2013-07-18 03:19:59 +0300 | [diff] [blame] | 61 | :param string $protocol: Protocol, e.g. 'http' or 'https' |
Andrey Andreev | 3de130c | 2014-02-07 23:31:49 +0200 | [diff] [blame] | 62 | :returns: Base URL |
| 63 | :rtype: string |
Andrey Andreev | 08f0f8b | 2012-11-09 10:27:43 +0200 | [diff] [blame] | 64 | |
Derek Jones | abbf518 | 2013-07-19 16:01:52 -0700 | [diff] [blame] | 65 | Returns your site base URL, as specified in your config file. Example:: |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 66 | |
Derek Jones | abbf518 | 2013-07-19 16:01:52 -0700 | [diff] [blame] | 67 | echo base_url(); |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 68 | |
Andrey Andreev | cd3d9db | 2015-02-02 13:41:01 +0200 | [diff] [blame] | 69 | This function returns the same thing as :php:func:`site_url()`, without |
Derek Jones | abbf518 | 2013-07-19 16:01:52 -0700 | [diff] [blame] | 70 | the *index_page* or *url_suffix* being appended. |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 71 | |
Andrey Andreev | cd3d9db | 2015-02-02 13:41:01 +0200 | [diff] [blame] | 72 | Also like :php:func:`site_url()`, you can supply segments as a string or |
Derek Jones | abbf518 | 2013-07-19 16:01:52 -0700 | [diff] [blame] | 73 | an array. Here is a string example:: |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 74 | |
Derek Jones | abbf518 | 2013-07-19 16:01:52 -0700 | [diff] [blame] | 75 | echo base_url("blog/post/123"); |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 76 | |
Derek Jones | abbf518 | 2013-07-19 16:01:52 -0700 | [diff] [blame] | 77 | The above example would return something like: |
| 78 | *http://example.com/blog/post/123* |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 79 | |
Andrey Andreev | cd3d9db | 2015-02-02 13:41:01 +0200 | [diff] [blame] | 80 | This is useful because unlike :php:func:`site_url()`, you can supply a |
Derek Jones | abbf518 | 2013-07-19 16:01:52 -0700 | [diff] [blame] | 81 | string to a file, such as an image or stylesheet. For example:: |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 82 | |
Derek Jones | abbf518 | 2013-07-19 16:01:52 -0700 | [diff] [blame] | 83 | echo base_url("images/icons/edit.png"); |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 84 | |
Derek Jones | abbf518 | 2013-07-19 16:01:52 -0700 | [diff] [blame] | 85 | This would give you something like: |
| 86 | *http://example.com/images/icons/edit.png* |
Andrey Andreev | 08f0f8b | 2012-11-09 10:27:43 +0200 | [diff] [blame] | 87 | |
Derek Jones | abbf518 | 2013-07-19 16:01:52 -0700 | [diff] [blame] | 88 | This function is an alias for ``CI_Config::base_url()``. For more info, |
| 89 | please see the :doc:`Config Library <../libraries/config>` documentation. |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 90 | |
Andrey Andreev | cd3d9db | 2015-02-02 13:41:01 +0200 | [diff] [blame] | 91 | .. php:function:: current_url() |
Andrey Andreev | 08f0f8b | 2012-11-09 10:27:43 +0200 | [diff] [blame] | 92 | |
Andrey Andreev | 3de130c | 2014-02-07 23:31:49 +0200 | [diff] [blame] | 93 | :returns: The current URL |
| 94 | :rtype: string |
Andrey Andreev | 08f0f8b | 2012-11-09 10:27:43 +0200 | [diff] [blame] | 95 | |
Derek Jones | abbf518 | 2013-07-19 16:01:52 -0700 | [diff] [blame] | 96 | Returns the full URL (including segments) of the page being currently |
| 97 | viewed. |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 98 | |
Derek Jones | abbf518 | 2013-07-19 16:01:52 -0700 | [diff] [blame] | 99 | .. note:: Calling this function is the same as doing this: |
| 100 | | |
| 101 | | site_url(uri_string()); |
Andrey Andreev | 08f0f8b | 2012-11-09 10:27:43 +0200 | [diff] [blame] | 102 | |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 103 | |
Andrey Andreev | cd3d9db | 2015-02-02 13:41:01 +0200 | [diff] [blame] | 104 | .. php:function:: uri_string() |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 105 | |
Andrey Andreev | 3de130c | 2014-02-07 23:31:49 +0200 | [diff] [blame] | 106 | :returns: An URI string |
| 107 | :rtype: string |
Andrey Andreev | 08f0f8b | 2012-11-09 10:27:43 +0200 | [diff] [blame] | 108 | |
Derek Jones | abbf518 | 2013-07-19 16:01:52 -0700 | [diff] [blame] | 109 | Returns the URI segments of any page that contains this function. |
| 110 | For example, if your URL was this:: |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 111 | |
Derek Jones | abbf518 | 2013-07-19 16:01:52 -0700 | [diff] [blame] | 112 | http://some-site.com/blog/comments/123 |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 113 | |
Derek Jones | abbf518 | 2013-07-19 16:01:52 -0700 | [diff] [blame] | 114 | The function would return:: |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 115 | |
Derek Jones | abbf518 | 2013-07-19 16:01:52 -0700 | [diff] [blame] | 116 | blog/comments/123 |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 117 | |
Derek Jones | abbf518 | 2013-07-19 16:01:52 -0700 | [diff] [blame] | 118 | This function is an alias for ``CI_Config::uri_string()``. For more info, |
| 119 | please see the :doc:`Config Library <../libraries/config>` documentation. |
Andrey Andreev | 08f0f8b | 2012-11-09 10:27:43 +0200 | [diff] [blame] | 120 | |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 121 | |
Andrey Andreev | cd3d9db | 2015-02-02 13:41:01 +0200 | [diff] [blame] | 122 | .. php:function:: index_page() |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 123 | |
Andrey Andreev | 3de130c | 2014-02-07 23:31:49 +0200 | [diff] [blame] | 124 | :returns: 'index_page' value |
| 125 | :rtype: mixed |
Andrey Andreev | 08f0f8b | 2012-11-09 10:27:43 +0200 | [diff] [blame] | 126 | |
Derek Jones | abbf518 | 2013-07-19 16:01:52 -0700 | [diff] [blame] | 127 | Returns your site **index_page**, as specified in your config file. |
| 128 | Example:: |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 129 | |
Derek Jones | abbf518 | 2013-07-19 16:01:52 -0700 | [diff] [blame] | 130 | echo index_page(); |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 131 | |
Andrey Andreev | cd3d9db | 2015-02-02 13:41:01 +0200 | [diff] [blame] | 132 | .. php:function:: anchor($uri = '', $title = '', $attributes = '') |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 133 | |
Andrey Andreev | 08f0f8b | 2012-11-09 10:27:43 +0200 | [diff] [blame] | 134 | :param string $uri: URI string |
| 135 | :param string $title: Anchor title |
| 136 | :param mixed $attributes: HTML attributes |
Andrey Andreev | 3de130c | 2014-02-07 23:31:49 +0200 | [diff] [blame] | 137 | :returns: HTML hyperlink (anchor tag) |
| 138 | :rtype: string |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 139 | |
Derek Jones | abbf518 | 2013-07-19 16:01:52 -0700 | [diff] [blame] | 140 | Creates a standard HTML anchor link based on your local site URL. |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 141 | |
Derek Jones | abbf518 | 2013-07-19 16:01:52 -0700 | [diff] [blame] | 142 | The first parameter can contain any segments you wish appended to the |
Andrey Andreev | cd3d9db | 2015-02-02 13:41:01 +0200 | [diff] [blame] | 143 | URL. As with the :php:func:`site_url()` function above, segments can |
Derek Jones | abbf518 | 2013-07-19 16:01:52 -0700 | [diff] [blame] | 144 | be a string or an array. |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 145 | |
Derek Jones | abbf518 | 2013-07-19 16:01:52 -0700 | [diff] [blame] | 146 | .. note:: If you are building links that are internal to your application |
Andrey Andreev | 8476056 | 2018-02-12 15:15:47 +0200 | [diff] [blame^] | 147 | do not include the base URL (\http://...). This will be added |
Derek Jones | abbf518 | 2013-07-19 16:01:52 -0700 | [diff] [blame] | 148 | automatically from the information specified in your config file. |
| 149 | Include only the URI segments you wish appended to the URL. |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 150 | |
Derek Jones | abbf518 | 2013-07-19 16:01:52 -0700 | [diff] [blame] | 151 | The second segment is the text you would like the link to say. If you |
| 152 | leave it blank, the URL will be used. |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 153 | |
Derek Jones | abbf518 | 2013-07-19 16:01:52 -0700 | [diff] [blame] | 154 | The third parameter can contain a list of attributes you would like |
| 155 | added to the link. The attributes can be a simple string or an |
| 156 | associative array. |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 157 | |
Derek Jones | abbf518 | 2013-07-19 16:01:52 -0700 | [diff] [blame] | 158 | Here are some examples:: |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 159 | |
Derek Jones | abbf518 | 2013-07-19 16:01:52 -0700 | [diff] [blame] | 160 | echo anchor('news/local/123', 'My News', 'title="News title"'); |
| 161 | // Prints: <a href="http://example.com/index.php/news/local/123" title="News title">My News</a> |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 162 | |
Derek Jones | abbf518 | 2013-07-19 16:01:52 -0700 | [diff] [blame] | 163 | echo anchor('news/local/123', 'My News', array('title' => 'The best news!')); |
| 164 | // Prints: <a href="http://example.com/index.php/news/local/123" title="The best news!">My News</a> |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 165 | |
Derek Jones | abbf518 | 2013-07-19 16:01:52 -0700 | [diff] [blame] | 166 | echo anchor('', 'Click here'); |
| 167 | // Prints: <a href="http://example.com">Click Here</a> |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 168 | |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 169 | |
Andrey Andreev | cd3d9db | 2015-02-02 13:41:01 +0200 | [diff] [blame] | 170 | .. php:function:: anchor_popup($uri = '', $title = '', $attributes = FALSE) |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 171 | |
Andrey Andreev | 08f0f8b | 2012-11-09 10:27:43 +0200 | [diff] [blame] | 172 | :param string $uri: URI string |
| 173 | :param string $title: Anchor title |
| 174 | :param mixed $attributes: HTML attributes |
Andrey Andreev | 3de130c | 2014-02-07 23:31:49 +0200 | [diff] [blame] | 175 | :returns: Pop-up hyperlink |
| 176 | :rtype: string |
Andrey Andreev | 08f0f8b | 2012-11-09 10:27:43 +0200 | [diff] [blame] | 177 | |
Andrey Andreev | cd3d9db | 2015-02-02 13:41:01 +0200 | [diff] [blame] | 178 | Nearly identical to the :php:func:`anchor()` function except that it |
Derek Jones | abbf518 | 2013-07-19 16:01:52 -0700 | [diff] [blame] | 179 | opens the URL in a new window. You can specify JavaScript window |
| 180 | attributes in the third parameter to control how the window is opened. |
| 181 | If the third parameter is not set it will simply open a new window with |
| 182 | your own browser settings. |
Andrey Andreev | 08f0f8b | 2012-11-09 10:27:43 +0200 | [diff] [blame] | 183 | |
Derek Jones | abbf518 | 2013-07-19 16:01:52 -0700 | [diff] [blame] | 184 | Here is an example with attributes:: |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 185 | |
Derek Jones | abbf518 | 2013-07-19 16:01:52 -0700 | [diff] [blame] | 186 | $atts = array( |
| 187 | 'width' => 800, |
| 188 | 'height' => 600, |
| 189 | 'scrollbars' => 'yes', |
| 190 | 'status' => 'yes', |
| 191 | 'resizable' => 'yes', |
| 192 | 'screenx' => 0, |
| 193 | 'screeny' => 0, |
| 194 | 'window_name' => '_blank' |
| 195 | ); |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 196 | |
Derek Jones | abbf518 | 2013-07-19 16:01:52 -0700 | [diff] [blame] | 197 | echo anchor_popup('news/local/123', 'Click Me!', $atts); |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 198 | |
Derek Jones | abbf518 | 2013-07-19 16:01:52 -0700 | [diff] [blame] | 199 | .. note:: The above attributes are the function defaults so you only need to |
| 200 | set the ones that are different from what you need. If you want the |
| 201 | function to use all of its defaults simply pass an empty array in the |
| 202 | third parameter: |
| 203 | | |
| 204 | | echo anchor_popup('news/local/123', 'Click Me!', array()); |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 205 | |
Derek Jones | abbf518 | 2013-07-19 16:01:52 -0700 | [diff] [blame] | 206 | .. note:: The **window_name** is not really an attribute, but an argument to |
| 207 | the JavaScript `window.open() <http://www.w3schools.com/jsref/met_win_open.asp>` |
| 208 | method, which accepts either a window name or a window target. |
Andrey Andreev | 81c3208 | 2012-06-16 21:21:46 +0300 | [diff] [blame] | 209 | |
Derek Jones | abbf518 | 2013-07-19 16:01:52 -0700 | [diff] [blame] | 210 | .. note:: Any other attribute than the listed above will be parsed as an |
| 211 | HTML attribute to the anchor tag. |
Andrey Andreev | 81c3208 | 2012-06-16 21:21:46 +0300 | [diff] [blame] | 212 | |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 213 | |
Andrey Andreev | cd3d9db | 2015-02-02 13:41:01 +0200 | [diff] [blame] | 214 | .. php:function:: mailto($email, $title = '', $attributes = '') |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 215 | |
Andrey Andreev | 08f0f8b | 2012-11-09 10:27:43 +0200 | [diff] [blame] | 216 | :param string $email: E-mail address |
| 217 | :param string $title: Anchor title |
| 218 | :param mixed $attributes: HTML attributes |
Andrey Andreev | 3de130c | 2014-02-07 23:31:49 +0200 | [diff] [blame] | 219 | :returns: A "mail to" hyperlink |
| 220 | :rtype: string |
Andrey Andreev | 08f0f8b | 2012-11-09 10:27:43 +0200 | [diff] [blame] | 221 | |
Derek Jones | abbf518 | 2013-07-19 16:01:52 -0700 | [diff] [blame] | 222 | Creates a standard HTML e-mail link. Usage example:: |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 223 | |
Derek Jones | abbf518 | 2013-07-19 16:01:52 -0700 | [diff] [blame] | 224 | echo mailto('me@my-site.com', 'Click Here to Contact Me'); |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 225 | |
Andrey Andreev | cd3d9db | 2015-02-02 13:41:01 +0200 | [diff] [blame] | 226 | As with the :php:func:`anchor()` tab above, you can set attributes using the |
Derek Jones | abbf518 | 2013-07-19 16:01:52 -0700 | [diff] [blame] | 227 | third parameter:: |
InFog | 00b3df4 | 2012-07-29 13:42:50 -0300 | [diff] [blame] | 228 | |
Derek Jones | abbf518 | 2013-07-19 16:01:52 -0700 | [diff] [blame] | 229 | $attributes = array('title' => 'Mail me'); |
| 230 | echo mailto('me@my-site.com', 'Contact Me', $attributes); |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 231 | |
Andrey Andreev | cd3d9db | 2015-02-02 13:41:01 +0200 | [diff] [blame] | 232 | .. php:function:: safe_mailto($email, $title = '', $attributes = '') |
Andrey Andreev | 08f0f8b | 2012-11-09 10:27:43 +0200 | [diff] [blame] | 233 | |
| 234 | :param string $email: E-mail address |
| 235 | :param string $title: Anchor title |
| 236 | :param mixed $attributes: HTML attributes |
Andrey Andreev | 3de130c | 2014-02-07 23:31:49 +0200 | [diff] [blame] | 237 | :returns: A spam-safe "mail to" hyperlink |
| 238 | :rtype: string |
Andrey Andreev | 08f0f8b | 2012-11-09 10:27:43 +0200 | [diff] [blame] | 239 | |
Andrey Andreev | cd3d9db | 2015-02-02 13:41:01 +0200 | [diff] [blame] | 240 | Identical to the :php:func:`mailto()` function except it writes an obfuscated |
Derek Jones | abbf518 | 2013-07-19 16:01:52 -0700 | [diff] [blame] | 241 | version of the *mailto* tag using ordinal numbers written with JavaScript to |
| 242 | help prevent the e-mail address from being harvested by spam bots. |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 243 | |
Andrey Andreev | cd3d9db | 2015-02-02 13:41:01 +0200 | [diff] [blame] | 244 | .. php:function:: auto_link($str, $type = 'both', $popup = FALSE) |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 245 | |
Andrey Andreev | 08f0f8b | 2012-11-09 10:27:43 +0200 | [diff] [blame] | 246 | :param string $str: Input string |
| 247 | :param string $type: Link type ('email', 'url' or 'both') |
| 248 | :param bool $popup: Whether to create popup links |
Andrey Andreev | 3de130c | 2014-02-07 23:31:49 +0200 | [diff] [blame] | 249 | :returns: Linkified string |
| 250 | :rtype: string |
Andrey Andreev | 08f0f8b | 2012-11-09 10:27:43 +0200 | [diff] [blame] | 251 | |
Derek Jones | abbf518 | 2013-07-19 16:01:52 -0700 | [diff] [blame] | 252 | Automatically turns URLs and e-mail addresses contained in a string into |
| 253 | links. Example:: |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 254 | |
Derek Jones | abbf518 | 2013-07-19 16:01:52 -0700 | [diff] [blame] | 255 | $string = auto_link($string); |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 256 | |
Derek Jones | abbf518 | 2013-07-19 16:01:52 -0700 | [diff] [blame] | 257 | The second parameter determines whether URLs and e-mails are converted or |
| 258 | just one or the other. Default behavior is both if the parameter is not |
Andrey Andreev | cd3d9db | 2015-02-02 13:41:01 +0200 | [diff] [blame] | 259 | specified. E-mail links are encoded as :php:func:`safe_mailto()` as shown |
Derek Jones | abbf518 | 2013-07-19 16:01:52 -0700 | [diff] [blame] | 260 | above. |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 261 | |
Derek Jones | abbf518 | 2013-07-19 16:01:52 -0700 | [diff] [blame] | 262 | Converts only URLs:: |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 263 | |
Derek Jones | abbf518 | 2013-07-19 16:01:52 -0700 | [diff] [blame] | 264 | $string = auto_link($string, 'url'); |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 265 | |
Derek Jones | abbf518 | 2013-07-19 16:01:52 -0700 | [diff] [blame] | 266 | Converts only e-mail addresses:: |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 267 | |
Derek Jones | abbf518 | 2013-07-19 16:01:52 -0700 | [diff] [blame] | 268 | $string = auto_link($string, 'email'); |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 269 | |
Derek Jones | abbf518 | 2013-07-19 16:01:52 -0700 | [diff] [blame] | 270 | The third parameter determines whether links are shown in a new window. |
| 271 | The value can be TRUE or FALSE (boolean):: |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 272 | |
Derek Jones | abbf518 | 2013-07-19 16:01:52 -0700 | [diff] [blame] | 273 | $string = auto_link($string, 'both', TRUE); |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 274 | |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 275 | |
Andrey Andreev | cd3d9db | 2015-02-02 13:41:01 +0200 | [diff] [blame] | 276 | .. php:function:: url_title($str, $separator = '-', $lowercase = FALSE) |
Andrey Andreev | 08f0f8b | 2012-11-09 10:27:43 +0200 | [diff] [blame] | 277 | |
| 278 | :param string $str: Input string |
| 279 | :param string $separator: Word separator |
Andrey Andreev | 9343851 | 2016-04-28 11:09:06 +0300 | [diff] [blame] | 280 | :param bool $lowercase: Whether to transform the output string to lower-case |
Andrey Andreev | 3de130c | 2014-02-07 23:31:49 +0200 | [diff] [blame] | 281 | :returns: URL-formatted string |
| 282 | :rtype: string |
Andrey Andreev | 08f0f8b | 2012-11-09 10:27:43 +0200 | [diff] [blame] | 283 | |
Derek Jones | abbf518 | 2013-07-19 16:01:52 -0700 | [diff] [blame] | 284 | Takes a string as input and creates a human-friendly URL string. This is |
| 285 | useful if, for example, you have a blog in which you'd like to use the |
| 286 | title of your entries in the URL. Example:: |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 287 | |
Derek Jones | abbf518 | 2013-07-19 16:01:52 -0700 | [diff] [blame] | 288 | $title = "What's wrong with CSS?"; |
| 289 | $url_title = url_title($title); |
| 290 | // Produces: Whats-wrong-with-CSS |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 291 | |
Derek Jones | abbf518 | 2013-07-19 16:01:52 -0700 | [diff] [blame] | 292 | The second parameter determines the word delimiter. By default dashes |
| 293 | are used. Preferred options are: **-** (dash) or **_** (underscore) |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 294 | |
Derek Jones | abbf518 | 2013-07-19 16:01:52 -0700 | [diff] [blame] | 295 | Example:: |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 296 | |
Derek Jones | abbf518 | 2013-07-19 16:01:52 -0700 | [diff] [blame] | 297 | $title = "What's wrong with CSS?"; |
| 298 | $url_title = url_title($title, 'underscore'); |
| 299 | // Produces: Whats_wrong_with_CSS |
Andrey Andreev | 08f0f8b | 2012-11-09 10:27:43 +0200 | [diff] [blame] | 300 | |
Derek Jones | abbf518 | 2013-07-19 16:01:52 -0700 | [diff] [blame] | 301 | .. note:: Old usage of 'dash' and 'underscore' as the second parameter |
| 302 | is DEPRECATED. |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 303 | |
Derek Jones | abbf518 | 2013-07-19 16:01:52 -0700 | [diff] [blame] | 304 | The third parameter determines whether or not lowercase characters are |
| 305 | forced. By default they are not. Options are boolean TRUE/FALSE. |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 306 | |
Derek Jones | abbf518 | 2013-07-19 16:01:52 -0700 | [diff] [blame] | 307 | Example:: |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 308 | |
Derek Jones | abbf518 | 2013-07-19 16:01:52 -0700 | [diff] [blame] | 309 | $title = "What's wrong with CSS?"; |
| 310 | $url_title = url_title($title, 'underscore', TRUE); |
| 311 | // Produces: whats_wrong_with_css |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 312 | |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 313 | |
Andrey Andreev | cd3d9db | 2015-02-02 13:41:01 +0200 | [diff] [blame] | 314 | .. php:function:: prep_url($str = '') |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 315 | |
Andrey Andreev | 08f0f8b | 2012-11-09 10:27:43 +0200 | [diff] [blame] | 316 | :param string $str: URL string |
Andrey Andreev | 3de130c | 2014-02-07 23:31:49 +0200 | [diff] [blame] | 317 | :returns: Protocol-prefixed URL string |
| 318 | :rtype: string |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 319 | |
Andrey Andreev | 8476056 | 2018-02-12 15:15:47 +0200 | [diff] [blame^] | 320 | This function will add \http:// in the event that a protocol prefix |
Derek Jones | abbf518 | 2013-07-19 16:01:52 -0700 | [diff] [blame] | 321 | is missing from a URL. |
Andrey Andreev | 08f0f8b | 2012-11-09 10:27:43 +0200 | [diff] [blame] | 322 | |
Derek Jones | abbf518 | 2013-07-19 16:01:52 -0700 | [diff] [blame] | 323 | Pass the URL string to the function like this:: |
Andrey Andreev | 08f0f8b | 2012-11-09 10:27:43 +0200 | [diff] [blame] | 324 | |
Derek Jones | abbf518 | 2013-07-19 16:01:52 -0700 | [diff] [blame] | 325 | $url = prep_url('example.com'); |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 326 | |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 327 | |
Andrey Andreev | cd3d9db | 2015-02-02 13:41:01 +0200 | [diff] [blame] | 328 | .. php:function:: redirect($uri = '', $method = 'auto', $code = NULL) |
Andrey Andreev | 08f0f8b | 2012-11-09 10:27:43 +0200 | [diff] [blame] | 329 | |
| 330 | :param string $uri: URI string |
| 331 | :param string $method: Redirect method ('auto', 'location' or 'refresh') |
| 332 | :param string $code: HTTP Response code (usually 302 or 303) |
Andrey Andreev | 3de130c | 2014-02-07 23:31:49 +0200 | [diff] [blame] | 333 | :rtype: void |
Andrey Andreev | 08f0f8b | 2012-11-09 10:27:43 +0200 | [diff] [blame] | 334 | |
Derek Jones | abbf518 | 2013-07-19 16:01:52 -0700 | [diff] [blame] | 335 | Does a "header redirect" to the URI specified. If you specify the full |
| 336 | site URL that link will be built, but for local links simply providing |
| 337 | the URI segments to the controller you want to direct to will create the |
| 338 | link. The function will build the URL based on your config file values. |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 339 | |
Derek Jones | abbf518 | 2013-07-19 16:01:52 -0700 | [diff] [blame] | 340 | The optional second parameter allows you to force a particular redirection |
| 341 | method. The available methods are **auto**, **location** and **refresh**, |
| 342 | with location being faster but less reliable on IIS servers. |
| 343 | The default is **auto**, which will attempt to intelligently choose the |
| 344 | method based on the server environment. |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 345 | |
Derek Jones | abbf518 | 2013-07-19 16:01:52 -0700 | [diff] [blame] | 346 | The optional third parameter allows you to send a specific HTTP Response |
| 347 | Code - this could be used for example to create 301 redirects for search |
| 348 | engine purposes. The default Response Code is 302. The third parameter is |
| 349 | *only* available with **location** redirects, and not *refresh*. Examples:: |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 350 | |
Derek Jones | abbf518 | 2013-07-19 16:01:52 -0700 | [diff] [blame] | 351 | if ($logged_in == FALSE) |
| 352 | { |
| 353 | redirect('/login/form/'); |
| 354 | } |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 355 | |
Derek Jones | abbf518 | 2013-07-19 16:01:52 -0700 | [diff] [blame] | 356 | // with 301 redirect |
| 357 | redirect('/article/13', 'location', 301); |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 358 | |
Derek Jones | abbf518 | 2013-07-19 16:01:52 -0700 | [diff] [blame] | 359 | .. note:: In order for this function to work it must be used before anything |
| 360 | is outputted to the browser since it utilizes server headers. |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 361 | |
Derek Jones | abbf518 | 2013-07-19 16:01:52 -0700 | [diff] [blame] | 362 | .. note:: For very fine grained control over headers, you should use the |
Andrey Andreev | e0c566e | 2016-05-11 16:05:23 +0300 | [diff] [blame] | 363 | :doc:`Output Library </libraries/output>` ``set_header()`` method. |
vlakoff | 530b946 | 2012-09-17 14:18:07 +0200 | [diff] [blame] | 364 | |
Derek Jones | abbf518 | 2013-07-19 16:01:52 -0700 | [diff] [blame] | 365 | .. note:: To IIS users: if you hide the `Server` HTTP header, the *auto* |
| 366 | method won't detect IIS, in that case it is advised you explicitly |
| 367 | use the **refresh** method. |
Andrey Andreev | 08f0f8b | 2012-11-09 10:27:43 +0200 | [diff] [blame] | 368 | |
Derek Jones | abbf518 | 2013-07-19 16:01:52 -0700 | [diff] [blame] | 369 | .. note:: When the **location** method is used, an HTTP status code of 303 |
| 370 | will *automatically* be selected when the page is currently accessed |
| 371 | via POST and HTTP/1.1 is used. |
Andrey Andreev | 08f0f8b | 2012-11-09 10:27:43 +0200 | [diff] [blame] | 372 | |
Andrey Andreev | 9343851 | 2016-04-28 11:09:06 +0300 | [diff] [blame] | 373 | .. important:: This function will terminate script execution. |