aboutsummaryrefslogtreecommitdiffstats
path: root/mod
diff options
context:
space:
mode:
authorredmatrix <redmatrix@redmatrix.me>2015-08-25 19:23:21 -0700
committerredmatrix <redmatrix@redmatrix.me>2015-08-25 19:23:21 -0700
commit2d471e39dcdaebbe8c60e50e39f23c430b665419 (patch)
tree5f42e8de02d291358cc3bf4636e7c737a0ea4053 /mod
parente5dec8671e02836312ab9425b99db6960ae22792 (diff)
downloadvolse-hubzilla-2d471e39dcdaebbe8c60e50e39f23c430b665419.tar.gz
volse-hubzilla-2d471e39dcdaebbe8c60e50e39f23c430b665419.tar.bz2
volse-hubzilla-2d471e39dcdaebbe8c60e50e39f23c430b665419.zip
this is weird
Diffstat (limited to 'mod')
-rw-r--r--mod/linkinfo.php (renamed from mod/urlinfo.php)386
1 files changed, 186 insertions, 200 deletions
diff --git a/mod/urlinfo.php b/mod/linkinfo.php
index 6b9be3f6f..c3df1305d 100644
--- a/mod/urlinfo.php
+++ b/mod/linkinfo.php
@@ -1,29 +1,180 @@
<?php
-require_once('include/oembed.php');
-
-/* To-Do
-https://developers.google.com/+/plugins/snippet/
-
-<meta itemprop="name" content="Toller Titel">
-<meta itemprop="description" content="Eine tolle Beschreibung">
-<meta itemprop="image" content="http://maple.libertreeproject.org/images/tree-icon.png">
-
-<body itemscope itemtype="http://schema.org/Product">
- <h1 itemprop="name">Shiny Trinket</h1>
- <img itemprop="image" src="{image-url}" />
- <p itemprop="description">Shiny trinkets are shiny.</p>
-</body>
-*/
-
-if(!function_exists('deletenode')) {
- function deletenode(&$doc, $node)
- {
- $xpath = new DomXPath($doc);
- $list = $xpath->query("//".$node);
- foreach ($list as $child)
- $child->parentNode->removeChild($child);
+
+function arr_add_hashes(&$item,$k) {
+ $item = '#' . $item;
+}
+
+
+
+function linkinfo_content(&$a) {
+
+ logger('linkinfo: ' . print_r($_REQUEST,true));
+
+ $text = null;
+ $str_tags = '';
+
+
+ $br = "\n";
+
+ if(x($_GET,'binurl'))
+ $url = trim(hex2bin($_GET['binurl']));
+ else
+ $url = trim($_GET['url']);
+
+ if((substr($url,0,1) != '/') && (substr($url,0,4) != 'http'))
+ $url = 'http://' . $url;
+
+
+ if($_GET['title'])
+ $title = strip_tags(trim($_GET['title']));
+
+ if($_GET['description'])
+ $text = strip_tags(trim($_GET['description']));
+
+ if($_GET['tags']) {
+ $arr_tags = str_getcsv($_GET['tags']);
+ if(count($arr_tags)) {
+ array_walk($arr_tags,'arr_add_hashes');
+ $str_tags = $br . implode(' ',$arr_tags) . $br;
+ }
+ }
+
+ logger('linkinfo: ' . $url);
+
+ $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) {
+ $zrl = is_matrix_url($url);
+ if(stripos($type,'image/') !== false) {
+ if($zrl)
+ echo $br . '[zmg]' . $url . '[/zmg]' . $br;
+ else
+ echo $br . '[img]' . $url . '[/img]' . $br;
+ killme();
+ }
+ if(stripos($type,'video/') !== false) {
+ if($zrl)
+ echo $br . '[zvideo]' . $url . '[/zvideo]' . $br;
+ else
+ echo $br . '[video]' . $url . '[/video]' . $br;
+ killme();
+ }
+ if(stripos($type,'audio/') !== false) {
+ if($zrl)
+ echo $br . '[zaudio]' . $url . '[/zaudio]' . $br;
+ else
+ echo $br . '[audio]' . $url . '[/audio]' . $br;
+ killme();
+ }
+ }
+ }
+
+ $template = $br . '#^[url=%s]%s[/url]%s' . $br;
+
+ $arr = array('url' => $url, 'text' => '');
+
+ call_hooks('parse_link', $arr);
+
+ if(strlen($arr['text'])) {
+ echo $arr['text'];
+ killme();
+ }
+
+ $x = oembed_process($url);
+ if($x) {
+ echo $x;
+ killme();
+ }
+
+ if($url && $title && $text) {
+
+ $text = $br . '[quote]' . trim($text) . '[/quote]' . $br;
+
+ $title = str_replace(array("\r","\n"),array('',''),$title);
+
+ $result = sprintf($template,$url,($title) ? $title : $url,$text) . $str_tags;
+
+ logger('linkinfo (unparsed): returns: ' . $result);
+
+ echo $result;
+ killme();
+ }
+
+ $siteinfo = parseurl_getsiteinfo($url);
+
+ // If this is a Red site, use zrl rather than url so they get zids sent to them by default
+
+ if( x($siteinfo,'generator') && (strpos($siteinfo['generator'],PLATFORM_NAME . ' ') === 0))
+ $template = str_replace('url','zrl',$template);
+
+ if($siteinfo["title"] == "") {
+ echo sprintf($template,$url,$url,'') . $str_tags;
+ killme();
+ } else {
+ $text = $siteinfo["text"];
+ $title = $siteinfo["title"];
+ }
+
+ $image = "";
+
+ 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
+ $max_images = intval($max_images);
+
+ foreach ($siteinfo["images"] as $imagedata) {
+ if ($url) {
+ $image .= sprintf('[url=%s]', $url);
+ }
+ $image .= '[img='.$imagedata["width"].'x'.$imagedata["height"].']'.$imagedata["src"].'[/img]';
+ if ($url) {
+ $image .= '[/url]';
+ }
+ $image .= "\n";
+ $total_images ++;
+ if($max_images && $max_images >= $total_images)
+ break;
+ }
+ }
+
+ if(strlen($text)) {
+ $text = $br.'[quote]'.trim($text).'[/quote]'.$br ;
}
+
+ if($image) {
+ $text = $br.$br.$image.$text;
+ }
+ $title = str_replace(array("\r","\n"),array('',''),$title);
+
+ $result = sprintf($template,$url,($title) ? $title : $url,$text) . $str_tags;
+
+ logger('linkinfo: returns: ' . $result, LOGGER_DEBUG);
+
+ echo trim($result);
+ killme();
+
+}
+
+
+function deletexnode(&$doc, $node) {
+ $xpath = new DomXPath($doc);
+ $list = $xpath->query("//".$node);
+ foreach ($list as $child)
+ $child->parentNode->removeChild($child);
}
function completeurl($url, $scheme) {
@@ -53,6 +204,7 @@ function completeurl($url, $scheme) {
return($complete);
}
+
function parseurl_getsiteinfo($url) {
$siteinfo = array();
@@ -70,17 +222,17 @@ function parseurl_getsiteinfo($url) {
$doc = new DOMDocument();
@$doc->loadHTML($body);
- deletenode($doc, 'style');
- deletenode($doc, 'script');
- deletenode($doc, 'option');
- deletenode($doc, 'h1');
- deletenode($doc, 'h2');
- deletenode($doc, 'h3');
- deletenode($doc, 'h4');
- deletenode($doc, 'h5');
- deletenode($doc, 'h6');
- deletenode($doc, 'ol');
- deletenode($doc, 'ul');
+ deletexnode($doc, 'style');
+ deletexnode($doc, 'script');
+ deletexnode($doc, 'option');
+ deletexnode($doc, 'h1');
+ deletexnode($doc, 'h2');
+ deletexnode($doc, 'h3');
+ deletexnode($doc, 'h4');
+ deletexnode($doc, 'h5');
+ deletexnode($doc, 'h6');
+ deletexnode($doc, 'ol');
+ deletexnode($doc, 'ul');
$xpath = new DomXPath($doc);
@@ -215,169 +367,3 @@ function parseurl_getsiteinfo($url) {
return($siteinfo);
}
-
-function arr_add_hashes(&$item,$k) {
- $item = '#' . $item;
-}
-
-function urlinfo_content(&$a) {
-
- logger('urlinfo: ' . print_r($_REQUEST,true));
-
- $text = null;
- $str_tags = '';
-
-
- $br = "\n";
-
- if(x($_GET,'binurl'))
- $url = trim(hex2bin($_GET['binurl']));
- else
- $url = trim($_GET['url']);
-
- if((substr($url,0,1) != '/') && (substr($url,0,4) != 'http'))
- $url = 'http://' . $url;
-
-
- if($_GET['title'])
- $title = strip_tags(trim($_GET['title']));
-
- if($_GET['description'])
- $text = strip_tags(trim($_GET['description']));
-
- if($_GET['tags']) {
- $arr_tags = str_getcsv($_GET['tags']);
- if(count($arr_tags)) {
- array_walk($arr_tags,'arr_add_hashes');
- $str_tags = $br . implode(' ',$arr_tags) . $br;
- }
- }
-
- logger('urlinfo: ' . $url);
-
- $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) {
- $zrl = is_matrix_url($url);
- if(stripos($type,'image/') !== false) {
- if($zrl)
- echo $br . '[zmg]' . $url . '[/zmg]' . $br;
- else
- echo $br . '[img]' . $url . '[/img]' . $br;
- killme();
- }
- if(stripos($type,'video/') !== false) {
- if($zrl)
- echo $br . '[zvideo]' . $url . '[/zvideo]' . $br;
- else
- echo $br . '[video]' . $url . '[/video]' . $br;
- killme();
- }
- if(stripos($type,'audio/') !== false) {
- if($zrl)
- echo $br . '[zaudio]' . $url . '[/zaudio]' . $br;
- else
- echo $br . '[audio]' . $url . '[/audio]' . $br;
- killme();
- }
- }
- }
-
- $template = $br . '#^[url=%s]%s[/url]%s' . $br;
-
- $arr = array('url' => $url, 'text' => '');
-
- call_hooks('parse_link', $arr);
-
- if(strlen($arr['text'])) {
- echo $arr['text'];
- killme();
- }
-
- $x = oembed_process($url);
- if($x) {
- echo $x;
- killme();
- }
-
- if($url && $title && $text) {
-
-
- $text = $br . '[quote]' . trim($text) . '[/quote]' . $br;
-
- $title = str_replace(array("\r","\n"),array('',''),$title);
-
- $result = sprintf($template,$url,($title) ? $title : $url,$text) . $str_tags;
-
- logger('urlinfo (unparsed): returns: ' . $result);
-
- echo $result;
- killme();
- }
-
- $siteinfo = parseurl_getsiteinfo($url);
-
- // If this is a Red site, use zrl rather than url so they get zids sent to them by default
-
- if( x($siteinfo,'generator') && (strpos($siteinfo['generator'],PLATFORM_NAME . ' ') === 0))
- $template = str_replace('url','zrl',$template);
-
- if($siteinfo["title"] == "") {
- echo sprintf($template,$url,$url,'') . $str_tags;
- killme();
- } else {
- $text = $siteinfo["text"];
- $title = $siteinfo["title"];
- }
-
- $image = "";
-
- 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
- $max_images = intval($max_images);
-
- foreach ($siteinfo["images"] as $imagedata) {
- if ($url) {
- $image .= sprintf('[url=%s]', $url);
- }
- $image .= '[img='.$imagedata["width"].'x'.$imagedata["height"].']'.$imagedata["src"].'[/img]';
- if ($url) {
- $image .= '[/url]';
- }
- $image .= "\n";
- $total_images ++;
- if($max_images && $max_images >= $total_images)
- break;
- }
- }
-
- if(strlen($text)) {
- $text = $br.'[quote]'.trim($text).'[/quote]'.$br ;
- }
-
- if($image) {
- $text = $br.$br.$image.$text;
- }
- $title = str_replace(array("\r","\n"),array('',''),$title);
-
- $result = sprintf($template,$url,($title) ? $title : $url,$text) . $str_tags;
-
- logger('urlinfo: returns: ' . $result, LOGGER_DEBUG);
-
- echo trim($result);
- killme();
-}