X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;ds=sidebyside;f=mod%2Fparse_url.php;h=9bb0bc46408e76f3a090d512c3d01fc63bc2bafa;hb=2abcf76ec17a9a7754c399cdde9a4449308a4b02;hp=aa71893ab47ebade0e5043976157f57d174daf59;hpb=0afc71a95a54f6b648a551584c2f7fc7a6c16880;p=friendica.git
diff --git a/mod/parse_url.php b/mod/parse_url.php
index aa71893ab4..9bb0bc4640 100644
--- a/mod/parse_url.php
+++ b/mod/parse_url.php
@@ -1,29 +1,64 @@
%s%s";
+ $url = trim(hex2bin($_GET['url']));
- if($url)
+ logger('parse_url: ' . $url);
+
+ $text = null;
+
+ $template = "
%s%s
";
+
+
+ $arr = array('url' => $url, 'text' => '');
+
+ call_hooks('parse_link', $arr);
+
+ if(strlen($arr['text'])) {
+ echo $arr['text'];
+ killme();
+ }
+
+ if($url) {
$s = fetch_url($url);
- else {
+ } else {
echo '';
killme();
}
-
+
+ logger('parse_url: data: ' . $s, LOGGER_DATA);
+
if(! $s) {
echo sprintf($template,$url,$url,'');
killme();
}
- $dom = HTML5_Parser::parse($s);
+ if(strpos($s,'
')) {
+ $title = substr($s,strpos($s,'')+7,64);
+ if(strpos($title,'<') !== false)
+ $title = strip_tags(substr($title,0,strpos($title,'<')));
+ }
+
+ $config = HTMLPurifier_Config::createDefault();
+ $config->set('Cache.DefinitionImpl', null);
- if(! $dom)
- return $ret;
+ $purifier = new HTMLPurifier($config);
+ $s = $purifier->purify($s);
+
+// logger('parse_url: purified: ' . $s, LOGGER_DATA);
+
+ $dom = @HTML5_Parser::parse($s);
+
+ if(! $dom) {
+ echo sprintf($template,$url,$url,'');
+ killme();
+ }
$items = $dom->getElementsByTagName('title');
@@ -34,22 +69,56 @@ function parse_url_content(&$a) {
}
}
- $items = $dom->getElementsByTagName('p');
- if($items) {
- foreach($items as $item) {
- $text = $item->textContent;
- $text = strip_tags($text);
- if(strlen($text) < 100)
- continue;
- $text = substr($text,0,250) . '...' ;
- break;
+ $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,'