function make_clickable($text, $server_url = false, $class = 'postlink') { //$server_url is for phpBB3 only $class is for later phpBB3 only global $IN_WORDPRESS; if ($IN_WORDPRESS) { return wp_make_clickable($text); //WP version } else { //phpBB version global $wpuAbs; if ('PHPBB2' == $wpuAbs->ver) { $text = preg_replace('#(script|about|applet|activex|chrome):#is', "\\1:", $text); $ret = ' ' . $text; $ret = preg_replace("#(^|[\n ])([\\w]+?://[\\w\\#\$%&~/.\\-;:=,?@\\[\\]+]*)#is", "\\1<a href=\"\\2\" target=\"_blank\">\\2</a>", $ret); $ret = preg_replace("#(^|[\n ])((www|ftp)\\.[\\w\\#\$%&~/.\\-;:=,?@\\[\\]+]*)#is", "\\1<a href=\"http://\\2\" target=\"_blank\">\\2</a>", $ret); $ret = preg_replace("#(^|[\n ])([a-z0-9&\\-_.]+?)@([\\w\\-]+\\.([\\w\\-\\.]+\\.)*[\\w]+)#i", "\\1<a href=\"mailto:\\2@\\3\">\\2@\\3</a>", $ret); $ret = substr($ret, 1); return $ret; } else { //phpBB3 BRANCH: if ($server_url === false) { $server_url = generate_board_url(); } static $magic_url_match; static $magic_url_replace; static $static_class; if (!is_array($magic_url_match)) { $magic_url_match = $magic_url_replace = array(); if (function_exists('make_clickable_callback')) { //latest phpBB3s $magic_url_match[] = '#(^|[\\n\\t (>.])(' . preg_quote($server_url, '#') . ')/(' . get_preg_expression('relative_url_inline') . ')#ie'; $magic_url_replace[] = "make_clickable_callback(MAGIC_URL_LOCAL, '\$1', '\$2', '\$3', '{$local_class}')"; $magic_url_match[] = '#(^|[\\n\\t (>.])(' . get_preg_expression('url_inline') . ')#ie'; $magic_url_replace[] = "make_clickable_callback(MAGIC_URL_FULL, '\$1', '\$2', '', '{$class}')"; $magic_url_match[] = '#(^|[\\n\\t (>])(' . get_preg_expression('www_url_inline') . ')#ie'; $magic_url_replace[] = "make_clickable_callback(MAGIC_URL_WWW, '\$1', '\$2', '', '{$class}')"; $magic_url_match[] = '/(^|[\\n\\t (>])(' . get_preg_expression('email') . ')/ie'; $magic_url_replace[] = "make_clickable_callback(MAGIC_URL_EMAIL, '\$1', '\$2', '', '')"; } else { // phpBB3 v1.0 $magic_url_match[] = '#(^|[\\n\\t (])(' . preg_quote($server_url, '#') . ')/(' . get_preg_expression('relative_url_inline') . ')#ie'; $magic_url_replace[] = "'\$1<!-- l --><a href=\"\$2/' . preg_replace('/(&|\\?)sid=[0-9a-f]{32}/', '\\\\1', '\$3') . '\">' . preg_replace('/(&|\\?)sid=[0-9a-f]{32}/', '\\\\1', '\$3') . '</a><!-- l -->'"; $magic_url_match[] = '#(^|[\\n\\t (])(' . get_preg_expression('url_inline') . ')#ie'; $magic_url_replace[] = "'\$1<!-- m --><a href=\"\$2\">' . ((strlen('\$2') > 55) ? substr(str_replace('&', '&', '\$2'), 0, 39) . ' ... ' . substr(str_replace('&', '&', '\$2'), -10) : '\$2') . '</a><!-- m -->'"; $magic_url_match[] = '#(^|[\\n\\t (])(' . get_preg_expression('www_url_inline') . ')#ie'; $magic_url_replace[] = "'\$1<!-- w --><a href=\"http://\$2\">' . ((strlen('\$2') > 55) ? substr(str_replace('&', '&', '\$2'), 0, 39) . ' ... ' . substr(str_replace('&', '&', '\$2'), -10) : '\$2') . '</a><!-- w -->'"; $magic_url_match[] = '/(^|[\\n\\t )])(' . get_preg_expression('email') . ')/ie'; $magic_url_replace[] = "'\$1<!-- e --><a href=\"mailto:\$2\">' . ((strlen('\$2') > 55) ? substr('\$2', 0, 39) . ' ... ' . substr('\$2', -10) : '\$2') . '</a><!-- e -->'"; } } return preg_replace($magic_url_match, $magic_url_replace, $text); } } }
/** * Arbitrate between phpBB & WordPress' make clickable functions */ public function do_make_clickable($text, $serverUrl = 'init', $class = 'init') { global $wpUnited, $phpbbForum; $realServerUrl = $serverUrl == 'init' ? false : $serverUrl; $realClass = $class == 'init' ? 'postlink' : $class; if (!isset($wpUnited) || !is_object($wpUnited) || !$wpUnited->is_working()) { return phpbb_make_clickable($text, $realServerUrl, $realClass); } if (!isset($phpbbForum) || !is_object($phpbbForum) || $phpbbForum->get_state == 'phpbb') { return phpbb_make_clickable($text, $realServerUrl, $realClass); } if ($phpbbForum->get_state != 'phpbb') { // if additional args are supplied, or the WP function wasn't redefined, they want the phpBB func if ($serverUrl != 'init' || $class != 'init' || !function_exists('wp_make_clickable')) { $phpbbForum->foreground(); return phpbb_make_clickable($text, $realServerUrl, $realClass); $phpbbForum->background(); } return wp_make_clickable($text); } }