| 2223 | | $ret = " $piece "; // Pad with whitespace to simplify the regexes |
| 2224 | | |
| 2225 | | $url_clickable = '~ |
| 2226 | | ([\\s(<.,;:!?]) # 1: Leading whitespace, or punctuation |
| 2227 | | ( # 2: URL |
| 2228 | | [\\w]{1,20}+:// # Scheme and hier-part prefix |
| 2229 | | (?=\S{1,2000}\s) # Limit to URLs less than about 2000 characters long |
| 2230 | | [\\w\\x80-\\xff#%\\~/@\\[\\]*(+=&$-]*+ # Non-punctuation URL character |
| 2231 | | (?: # Unroll the Loop: Only allow puctuation URL character if followed by a non-punctuation URL character |
| 2232 | | [\'.,;:!?)] # Punctuation URL character |
| 2233 | | [\\w\\x80-\\xff#%\\~/@\\[\\]*(+=&$-]++ # Non-punctuation URL character |
| 2234 | | )* |
| 2235 | | ) |
| 2236 | | (\)?) # 3: Trailing closing parenthesis (for parethesis balancing post processing) |
| 2237 | | ~xS'; // The regex is a non-anchored pattern and does not have a single fixed starting character. |
| 2238 | | // Tell PCRE to spend more time optimizing since, when used on a page load, it will probably be used several times. |
| 2239 | | |
| 2240 | | $ret = preg_replace_callback( $url_clickable, '_make_url_clickable_cb', $ret ); |
| 2241 | | |
| 2242 | | $ret = preg_replace_callback( '#([\s>])((www|ftp)\.[\w\\x80-\\xff\#$%&~/.\-;:=,?@\[\]+]+)#is', '_make_web_ftp_clickable_cb', $ret ); |
| 2243 | | $ret = preg_replace_callback( '#([\s>])([.0-9a-z_+-]+)@(([0-9a-z-]+\.)+[0-9a-z]{2,})#i', '_make_email_clickable_cb', $ret ); |
| 2244 | | |
| | 2223 | $ret = " {$piece} "; // Pad with whitespace to simplify the regexes |
| | 2224 | $ret = apply_filters( 'make_clickable', $ret, $text ); |
| | 2235 | * Make URLs clickable in content areas |
| | 2236 | * |
| | 2237 | * @since 4.6.0 |
| | 2238 | * @access private |
| | 2239 | * |
| | 2240 | * @param string $text |
| | 2241 | * @return string |
| | 2242 | */ |
| | 2243 | function make_urls_clickable_filter( $text = '' ) { |
| | 2244 | $url_clickable = '~ |
| | 2245 | ([\\s(<.,;:!?]) # 1: Leading whitespace, or punctuation |
| | 2246 | ( # 2: URL |
| | 2247 | [\\w]{1,20}+:// # Scheme and hier-part prefix |
| | 2248 | (?=\S{1,2000}\s) # Limit to URLs less than about 2000 characters long |
| | 2249 | [\\w\\x80-\\xff#%\\~/@\\[\\]*(+=&$-]*+ # Non-punctuation URL character |
| | 2250 | (?: # Unroll the Loop: Only allow puctuation URL character if followed by a non-punctuation URL character |
| | 2251 | [\'.,;:!?)] # Punctuation URL character |
| | 2252 | [\\w\\x80-\\xff#%\\~/@\\[\\]*(+=&$-]++ # Non-punctuation URL character |
| | 2253 | )* |
| | 2254 | ) |
| | 2255 | (\)?) # 3: Trailing closing parenthesis (for parethesis balancing post processing) |
| | 2256 | ~xS'; |
| | 2257 | |
| | 2258 | // The regex is a non-anchored pattern and does not have a single fixed starting character. |
| | 2259 | // Tell PCRE to spend more time optimizing since, when used on a page load, it will probably be used several times. |
| | 2260 | return preg_replace_callback( $url_clickable, '_make_url_clickable_cb', $text ); |
| | 2261 | } |
| | 2262 | |
| | 2263 | /** |
| | 2264 | * Make FTP clickable in content areas |
| | 2265 | * |
| | 2266 | * @since 4.6.0 |
| | 2267 | * @access private |
| | 2268 | * |
| | 2269 | * @param string $text |
| | 2270 | * @return string |
| | 2271 | */ |
| | 2272 | function make_ftps_clickable_filter( $text = '' ) { |
| | 2273 | return preg_replace_callback( '#([\s>])((www|ftp)\.[\w\\x80-\\xff\#$%&~/.\-;:=,?@\[\]+]+)#is', '_make_web_ftp_clickable_cb', $text ); |
| | 2274 | } |
| | 2275 | |
| | 2276 | /** |
| | 2277 | * Make emails clickable in content areas |
| | 2278 | * |
| | 2279 | * @since 4.6.0 |
| | 2280 | * @access private |
| | 2281 | * |
| | 2282 | * @param string $text |
| | 2283 | * @return string |
| | 2284 | */ |
| | 2285 | function make_emails_clickable_filter( $text = '' ) { |
| | 2286 | return preg_replace_callback( '#([\s>])([.0-9a-z_+-]+)@(([0-9a-z-]+\.)+[0-9a-z]{2,})#i', '_make_email_clickable_cb', $text ); |
| | 2287 | } |
| | 2288 | |
| | 2289 | /** |