/** * make_clickable function * * Replace magic urls of form http://xxx.xxx., www.xxx. and xxx@xxx.xxx. * Cuts down displayed size of link if over 50 chars, turns absolute links * into relative versions when the server/script path matches the link * Patched 2019-03-08 by Novalinium * Description of changes: Replaces eval with function loop for PHP7 compat */ function make_clickable($text, $server_url = false, $class = 'postlink') { 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) || $static_class != $class) { $static_class = $class; $class = ($static_class) ? ' class="' . $static_class . '"' : ''; $local_class = ($static_class) ? ' class="' . $static_class . '-local"' : ''; $magic_url_match = $magic_url_replace = array(); // Be sure to not let the matches cross over. ;) // relative urls for this board $magic_url_match[] = '#(^|[\n\t (>.])(' . preg_quote($server_url, '#') . ')/(' . get_preg_expression('relative_url_inline') . ')#i'; $magic_url_replace[] = function($matches) use ($local_class) {return make_clickable_callback(MAGIC_URL_LOCAL, $matches[1], $matches[2], $matches[3], $local_class);}; // matches a xxxx://aaaaa.bbb.cccc. ... $magic_url_match[] = '#(^|[\n\t (>.])(' . get_preg_expression('url_inline') . ')#i'; $magic_url_replace[] = function($matches) use ($class) {return make_clickable_callback(MAGIC_URL_FULL, $matches[1], $matches[2], '', $class);}; // matches a "www.xxxx.yyyy[/zzzz]" kinda lazy URL thing $magic_url_match[] = '#(^|[\n\t (>])(' . get_preg_expression('www_url_inline') . ')#i'; $magic_url_replace[] = function($matches) use ($class) {return make_clickable_callback(MAGIC_URL_WWW, $matches[1], $matches[2], '', $class);}; // matches an email@domain type address at the start of a line, or after a space or after what might be a BBCode. $magic_url_match[] = '/(^|[\n\t (>])(' . get_preg_expression('email') . ')/i'; $magic_url_replace[] = function($matches) {return make_clickable_callback(MAGIC_URL_EMAIL, $matches[1], $matches[2], '', '');}; } foreach ($magic_url_match as $key=>$value) { $replaced = preg_replace_callback($value, $magic_url_replace[$key], $text); $text = $replaced; } return $text; }