X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=mod%2Fparse_url.php;h=14ec4d42ce45748ea89c8150655347616b92a7b5;hb=e561fb3a0b341abe3cb68028cca13306cfa010fe;hp=ebe34875b76937221baa98bdf6b33044b9ae9ae3;hpb=475d3f8f3a71afb94315bbc3264a950a61b26b52;p=friendica.git diff --git a/mod/parse_url.php b/mod/parse_url.php index ebe34875b7..14ec4d42ce 100644 --- a/mod/parse_url.php +++ b/mod/parse_url.php @@ -10,12 +10,11 @@ * @see ParseUrl::getSiteinfo() for more information about scraping embeddable content */ use Friendica\App; -use Friendica\Core\Addon; +use Friendica\Core\Hook; +use Friendica\Core\Logger; use Friendica\Util\Network; use Friendica\Util\ParseUrl; -require_once 'include/items.php'; - function parse_url_content(App $a) { $text = null; @@ -46,26 +45,26 @@ function parse_url_content(App $a) // Add url scheme if it is missing $arrurl = parse_url($url); - if (!x($arrurl, 'scheme')) { - if (x($arrurl, 'host')) { + if (empty($arrurl['scheme'])) { + if (!empty($arrurl['host'])) { $url = 'http:' . $url; } else { $url = 'http://' . $url; } } - logger($url); + Logger::log($url); // Check if the URL is an image, video or audio file. If so format // the URL with the corresponding BBCode media tag $redirects = 0; // Fetch the header of the URL - $result = Network::curl($url, false, $redirects, ['novalidate' => true, 'nobody' => true]); + $curlResponse = Network::curl($url, false, $redirects, ['novalidate' => true, 'nobody' => true]); - if ($result['success']) { + if ($curlResponse->isSuccess()) { // Convert the header fields into an array $hdrs = []; - $h = explode("\n", $result['header']); + $h = explode("\n", $curlResponse->getHeader()); foreach ($h as $l) { $header = array_map('trim', explode(':', trim($l), 2)); if (count($header) == 2) { @@ -73,6 +72,7 @@ function parse_url_content(App $a) $hdrs[$k] = $v; } } + $type = null; if (array_key_exists('Content-Type', $hdrs)) { $type = $hdrs['Content-Type']; } @@ -92,11 +92,12 @@ function parse_url_content(App $a) } } + $template = '[bookmark=%s]%s[/bookmark]%s'; $arr = ['url' => $url, 'text' => '']; - Addon::callHooks('parse_link', $arr); + Hook::callAll('parse_link', $arr); if (strlen($arr['text'])) { echo $arr['text']; @@ -112,7 +113,7 @@ function parse_url_content(App $a) $result = sprintf($template, $url, ($title) ? $title : $url, $text) . $str_tags; - logger('(unparsed): returns: ' . $result); + Logger::log('(unparsed): returns: ' . $result); echo $result; exit(); @@ -123,6 +124,12 @@ function parse_url_content(App $a) unset($siteinfo['keywords']); + // Bypass attachment if parse url for a comment + if (!empty($_GET['noAttachment'])) { + echo $br . '[url=' . $url . ']' . $siteinfo['title'] . '[/url]'; + exit(); + } + // Format it as BBCode attachment $info = add_page_info_data($siteinfo);