<?php
/*-------------------------------------------------------+
| PHP-Fusion Content Management System
| Copyright (C) PHP-Fusion Inc
| https://www.php-fusion.co.uk/
+--------------------------------------------------------+
| Filename: url_bbcode_include.php
| Author: JoiNNN
+--------------------------------------------------------+
| This program is released as free software under the
| Affero GPL license. You can redistribute it and/or
| modify it under the terms of this license which you
| can read by viewing the included agpl.txt or online
| at www.gnu.org/licenses/agpl.html. Removal of this
| copyright header is strictly prohibited without
| written permission from the original author(s).
+--------------------------------------------------------*/
if (!defined("IN_FUSION")) { die("Access Denied"); }
if (!function_exists('replace_url')) {
	function replace_url($m) {
		// Get input url if any, if not get the content as a url but check if has a schema, if not add one
		$this_url = (!empty($m['url']) ? $m['url'] : (preg_match("#^((f|ht)tp(s)?://)#i", $m['content']) ? $m['content'] : "http://".$m['content']));
		// Trim only the default url
		$content = (empty($m['url']) ? trimlink($m['content'], 40).(strlen($m['content']) > 40 ? substr($m['content'], strlen($m['content'])-10, strlen($m['content'])) : '') : $m['content']);

		return "<a href='$this_url' target='_blank' title='".urldecode($this_url)."'>".$content."</a>";
	}
}
$text = preg_replace_callback('#\[url(=(?P<url>((f|ht)tp(s)?://)(.*?)))?\](?P<content>.*?)\[/url\]#i', 'replace_url', $text);
?>