From 410f3335a9e97276b3262196f50798ff56624af5 Mon Sep 17 00:00:00 2001 From: friendica Date: Wed, 4 Mar 2015 15:14:10 -0800 Subject: parse_url: if url returns an image/audio/video file instead of a webpage, return the bbcode for the appropriate content type. This results in two web fetches of the url in question, but the first one is just a HEAD. This way we won't try and download and parse an entire video. TODO: img's are checked to see if they should be zid-ified, but audio/video currently are not. --- mod/parse_url.php | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'mod/parse_url.php') diff --git a/mod/parse_url.php b/mod/parse_url.php index 23d608411..49d5cae76 100644 --- a/mod/parse_url.php +++ b/mod/parse_url.php @@ -250,6 +250,34 @@ function parse_url_content(&$a) { } } + $result = z_fetch_url($url,false,0,array('novalidate' => true, 'nobody' => true)); + if($result['success']) { + $hdrs=array(); + $h = explode("\n",$result['header']); + foreach ($h as $l) { + list($k,$v) = array_map("trim", explode(":", trim($l), 2)); + $hdrs[$k] = $v; + } + if (array_key_exists('Content-Type', $hdrs)) + $type = $hdrs['Content-Type']; + if($type) { + if(in_array($type,array('image/jpeg','image/gif','image/png'))) { + $s = $br . '[img]' . $url . '[/img]' . $br; + $s = preg_replace_callback('/\[img(.*?)\](.*?)\[\/img\]/ism','red_zrlify_img_callback',$s); + echo $s; + killme(); + } + if(stripos($type,'video/') !== false) { + echo $br . '[video]' . $url . '[/video]' . $br; + killme(); + } + if(stripos($type,'audio/') !== false) { + echo $br . '[audio]' . $url . '[/audio]' . $br; + killme(); + } + } + } + logger('parse_url: ' . $url); $template = $br . '#^[url=%s]%s[/url]%s' . $br; -- cgit v1.2.3