aboutsummaryrefslogtreecommitdiffstats
path: root/mod/parse_url.php
diff options
context:
space:
mode:
authorFabio Comuni <fabrix.xm@gmail.com>2011-09-26 11:42:48 +0200
committerFabio Comuni <fabrix.xm@gmail.com>2011-09-26 11:42:48 +0200
commit5792b3d3580b9f09460305858293398d8d8a9abf (patch)
tree90d60e9db4ed733a60c2890c7305d45ddd48be42 /mod/parse_url.php
parent991656a3ef396d9a6bd43ddb752627c2880b17ba (diff)
parent428e6766411d2c6708ad25f726c4bcf1d64af1cc (diff)
downloadvolse-hubzilla-5792b3d3580b9f09460305858293398d8d8a9abf.tar.gz
volse-hubzilla-5792b3d3580b9f09460305858293398d8d8a9abf.tar.bz2
volse-hubzilla-5792b3d3580b9f09460305858293398d8d8a9abf.zip
Merge branch 'master' into newui
Diffstat (limited to 'mod/parse_url.php')
-rw-r--r--mod/parse_url.php132
1 files changed, 86 insertions, 46 deletions
diff --git a/mod/parse_url.php b/mod/parse_url.php
index 79c336ddc..a238ecb2f 100644
--- a/mod/parse_url.php
+++ b/mod/parse_url.php
@@ -3,15 +3,36 @@
require_once('library/HTML5/Parser.php');
require_once('library/HTMLPurifier.auto.php');
+function arr_add_hashes(&$item,$k) {
+ $item = '#' . $item;
+}
+
function parse_url_content(&$a) {
- logger('parse_url: ' . $_GET['url']);
+ $text = null;
+ $str_tags = '';
+
+ if(x($_GET,'binurl'))
+ $url = trim(hex2bin($_GET['binurl']));
+ else
+ $url = trim($_GET['url']);
- $url = trim(hex2bin($_GET['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('parse_url: ' . $url);
- $text = null;
$template = "<br /><a class=\"bookmark\" href=\"%s\" >%s</a>%s<br />";
@@ -25,6 +46,20 @@ function parse_url_content(&$a) {
killme();
}
+ if($url && $title && $text) {
+
+ $text = '<br /><br /><blockquote>' . $text . '</blockquote><br />';
+ $title = str_replace(array("\r","\n"),array('',''),$title);
+
+ $result = sprintf($template,$url,($title) ? $title : $url,$text) . $str_tags;
+
+ logger('parse_url (unparsed): returns: ' . $result);
+
+ echo $result;
+ killme();
+ }
+
+
if($url) {
$s = fetch_url($url);
} else {
@@ -35,14 +70,16 @@ function parse_url_content(&$a) {
logger('parse_url: data: ' . $s, LOGGER_DATA);
if(! $s) {
- echo sprintf($template,$url,$url,'');
+ echo sprintf($template,$url,$url,'') . $str_tags;
killme();
}
- if(strpos($s,'<title>')) {
- $title = substr($s,strpos($s,'<title>')+7,64);
- if(strpos($title,'<') !== false)
- $title = strip_tags(substr($title,0,strpos($title,'<')));
+ if(! $title) {
+ if(strpos($s,'<title>')) {
+ $title = substr($s,strpos($s,'<title>')+7,64);
+ if(strpos($title,'<') !== false)
+ $title = strip_tags(substr($title,0,strpos($title,'<')));
+ }
}
$config = HTMLPurifier_Config::createDefault();
@@ -56,7 +93,7 @@ function parse_url_content(&$a) {
$dom = @HTML5_Parser::parse($s);
if(! $dom) {
- echo sprintf($template,$url,$url,'');
+ echo sprintf($template,$url,$url,'') . $str_tags;
killme();
}
@@ -69,48 +106,51 @@ function parse_url_content(&$a) {
}
}
- $divs = $dom->getElementsByTagName('div');
- if($divs) {
- foreach($divs as $div) {
- $class = $div->getAttribute('class');
- if($class && (stristr($class,'article') || stristr($class,'content'))) {
- $items = $div->getElementsByTagName('p');
- if($items) {
- foreach($items as $item) {
- $text = $item->textContent;
- if(stristr($text,'<script')) {
- $text = '';
- continue;
- }
- $text = strip_tags($text);
- if(strlen($text) < 100) {
- $text = '';
- continue;
+
+ if(! $text) {
+ $divs = $dom->getElementsByTagName('div');
+ if($divs) {
+ foreach($divs as $div) {
+ $class = $div->getAttribute('class');
+ if($class && (stristr($class,'article') || stristr($class,'content'))) {
+ $items = $div->getElementsByTagName('p');
+ if($items) {
+ foreach($items as $item) {
+ $text = $item->textContent;
+ if(stristr($text,'<script')) {
+ $text = '';
+ continue;
+ }
+ $text = strip_tags($text);
+ if(strlen($text) < 100) {
+ $text = '';
+ continue;
+ }
+ $text = substr($text,0,250) . '...' ;
+ break;
}
- $text = substr($text,0,250) . '...' ;
- break;
}
}
+ if($text)
+ break;
}
- if($text)
- break;
}
- }
- if(! $text) {
- $items = $dom->getElementsByTagName('p');
- if($items) {
- foreach($items as $item) {
- $text = $item->textContent;
- if(stristr($text,'<script'))
- continue;
- $text = strip_tags($text);
- if(strlen($text) < 100) {
- $text = '';
- continue;
+ if(! $text) {
+ $items = $dom->getElementsByTagName('p');
+ if($items) {
+ foreach($items as $item) {
+ $text = $item->textContent;
+ if(stristr($text,'<script'))
+ continue;
+ $text = strip_tags($text);
+ if(strlen($text) < 100) {
+ $text = '';
+ continue;
+ }
+ $text = substr($text,0,250) . '...' ;
+ break;
}
- $text = substr($text,0,250) . '...' ;
- break;
}
}
}
@@ -119,9 +159,9 @@ function parse_url_content(&$a) {
$text = '<br /><br /><blockquote>' . $text . '</blockquote><br />';
}
- $title = str_replace("\n",'',$title);
+ $title = str_replace(array("\r","\n"),array('',''),$title);
- $result = sprintf($template,$url,($title) ? $title : $url,$text);
+ $result = sprintf($template,$url,($title) ? $title : $url,$text) . $str_tags;
logger('parse_url: returns: ' . $result);