diff options
-rw-r--r-- | include/network.php | 7 | ||||
-rw-r--r-- | mod/parse_url.php | 28 |
2 files changed, 35 insertions, 0 deletions
diff --git a/include/network.php b/include/network.php index db32396e4..5912ad79d 100644 --- a/include/network.php +++ b/include/network.php @@ -19,6 +19,7 @@ function get_capath() { * 'timeout' => int seconds, default system config value or 60 seconds * 'http_auth' => username:password * 'novalidate' => do not validate SSL certs, default is to validate using our CA list + * 'nobody' => only return the header * * @returns array * 'return_code' => HTTP return code or 0 if timeout or failure @@ -51,6 +52,9 @@ function z_fetch_url($url, $binary = false, $redirects = 0, $opts = array()) { if(x($opts,'headers')) @curl_setopt($ch, CURLOPT_HTTPHEADER, $opts['headers']); + if(x($opts,'nobody')) + @curl_setopt($ch, CURLOPT_NOBODY, $opts['nobody']); + if(x($opts,'timeout') && intval($opts['timeout'])) { @curl_setopt($ch, CURLOPT_TIMEOUT, $opts['timeout']); } @@ -182,6 +186,9 @@ function z_post_url($url,$params, $redirects = 0, $opts = array()) { if(x($opts,'headers')) @curl_setopt($ch, CURLOPT_HTTPHEADER, $opts['headers']); + if(x($opts,'nobody')) + @curl_setopt($ch, CURLOPT_NOBODY, $opts['nobody']); + if(x($opts,'timeout') && intval($opts['timeout'])) { @curl_setopt($ch, CURLOPT_TIMEOUT, $opts['timeout']); } 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; |