X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=mod%2Fparse_url.php;h=c8670d4d967fc67b69f66da129a71b60398d6bc0;hb=631085462e1963d09b6266ec6954d9810ee05b24;hp=083a39b55f9012d2733ad55118d41c664d1b38b6;hpb=290da6c845294d3bf02b581c500d5083d9f4dd72;p=friendica.git
diff --git a/mod/parse_url.php b/mod/parse_url.php
index 083a39b55f..c8670d4d96 100644
--- a/mod/parse_url.php
+++ b/mod/parse_url.php
@@ -33,7 +33,7 @@ function completeurl($url, $scheme) {
$complete = $schemearr["scheme"]."://".$schemearr["host"];
- if ($schemearr["port"] != "")
+ if (@$schemearr["port"] != "")
$complete .= ":".$schemearr["port"];
if(strpos($urlarr['path'],'/') !== 0)
@@ -41,10 +41,10 @@ function completeurl($url, $scheme) {
$complete .= $urlarr["path"];
- if ($urlarr["query"] != "")
+ if (@$urlarr["query"] != "")
$complete .= "?".$urlarr["query"];
- if ($urlarr["fragment"] != "")
+ if (@$urlarr["fragment"] != "")
$complete .= "#".$urlarr["fragment"];
return($complete);
@@ -52,18 +52,29 @@ function completeurl($url, $scheme) {
function parseurl_getsiteinfo($url) {
$siteinfo = array();
-
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_NOBODY, 0);
curl_setopt($ch, CURLOPT_TIMEOUT, 3);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
+ //curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch,CURLOPT_USERAGENT,'Opera/9.64(Windows NT 5.1; U; de) Presto/2.1.1');
$header = curl_exec($ch);
+ $curl_info = @curl_getinfo($ch);
+ $http_code = $curl_info['http_code'];
curl_close($ch);
+ if ((($curl_info['http_code'] == "301") OR ($curl_info['http_code'] == "302"))
+ AND (($curl_info['redirect_url'] != "") OR ($curl_info['location'] != ""))) {
+ if ($curl_info['redirect_url'] != "")
+ $siteinfo = parseurl_getsiteinfo($curl_info['redirect_url']);
+ else
+ $siteinfo = parseurl_getsiteinfo($curl_info['location']);
+ return($siteinfo);
+ }
+
// Fetch the first mentioned charset. Can be in body or header
if (preg_match('/charset=(.*?)['."'".'"\s\n]/', $header, $matches))
$charset = trim(array_pop($matches));
@@ -97,6 +108,28 @@ function parseurl_getsiteinfo($url) {
$xpath = new DomXPath($doc);
+ $list = $xpath->query("//meta[@content]");
+ foreach ($list as $node) {
+ $attr = array();
+ if ($node->attributes->length)
+ foreach ($node->attributes as $attribute)
+ $attr[$attribute->name] = $attribute->value;
+
+ if (@$attr["http-equiv"] == 'refresh') {
+ $path = $attr["content"];
+ $pathinfo = explode(";", $path);
+ $content = "";
+ foreach ($pathinfo AS $value) {
+ if (substr(strtolower($value), 0, 4) == "url=")
+ $content = substr($value, 4);
+ }
+ if ($content != "") {
+ $siteinfo = parseurl_getsiteinfo($content);
+ return($siteinfo);
+ }
+ }
+ }
+
//$list = $xpath->query("head/title");
$list = $xpath->query("//title");
foreach ($list as $node)
@@ -151,7 +184,7 @@ function parseurl_getsiteinfo($url) {
}
}
- if ($siteinfo["image"] == "") {
+ if (@$siteinfo["image"] == "") {
$list = $xpath->query("//img[@src]");
foreach ($list as $node) {
$attr = array();
@@ -190,7 +223,7 @@ function parseurl_getsiteinfo($url) {
"height"=>$photodata[1]);
}
- if ($siteinfo["text"] == "") {
+ if (@$siteinfo["text"] == "") {
$text = "";
$list = $xpath->query("//div[@class='article']");
@@ -236,7 +269,8 @@ function parse_url_content(&$a) {
$str_tags = '';
$textmode = false;
- if(local_user() && intval(get_pconfig(local_user(),'system','plaintext')))
+
+ if(local_user() && (! feature_enabled(local_user(),'richtext')))
$textmode = true;
//if($textmode)
@@ -307,16 +341,26 @@ function parse_url_content(&$a) {
$image = "";
- if(sizeof($siteinfo["images"]) > 0){
- /*
- Execute below code only if image is present in siteinfo
- */
- foreach ($siteinfo["images"] as $imagedata)
- if($textmode)
- $image .= '[img='.$imagedata["width"].'x'.$imagedata["height"].']'.$imagedata["src"].'[/img]';
+ if(sizeof($siteinfo["images"]) > 0){
+ /* Execute below code only if image is present in siteinfo */
+
+ $total_images = 0;
+ $max_images = get_config('system','max_bookmark_images');
+ if($max_images === false)
+ $max_images = 2;
else
- $image .= '
';
+ $max_images = intval($max_images);
+
+ foreach ($siteinfo["images"] as $imagedata) {
+ if($textmode)
+ $image .= '[img='.$imagedata["width"].'x'.$imagedata["height"].']'.$imagedata["src"].'[/img]' . "\n";
+ else
+ $image .= '![photo]('.$imagedata[)
';
+ $total_images ++;
+ if($max_images && $max_images >= $total_images)
+ break;
}
+ }
if(strlen($text)) {
if($textmode)