X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=mod%2Fparse_url.php;h=9bb0bc46408e76f3a090d512c3d01fc63bc2bafa;hb=2abcf76ec17a9a7754c399cdde9a4449308a4b02;hp=8e168473253efb95815b786f1241e501cfc04275;hpb=ef64c5187df80da2065655726b8d05a9ce6b0e0a;p=friendica.git diff --git a/mod/parse_url.php b/mod/parse_url.php index 8e16847325..9bb0bc4640 100644 --- a/mod/parse_url.php +++ b/mod/parse_url.php @@ -1,7 +1,7 @@ %s\n%s"; + $template = "
%s%s
"; $arr = array('url' => $url, 'text' => ''); @@ -26,31 +26,39 @@ function parse_url_content(&$a) { } if($url) { - // fetch link with oembed - if ($a->config['system']['embed_all']){ - $j = oembed_fetch_url($url); - if ($j->type!="error"){ - echo oembed_format_object($j); - killme(); - } - } - $s = fetch_url($url); } else { echo ''; killme(); } + logger('parse_url: data: ' . $s, LOGGER_DATA); if(! $s) { echo sprintf($template,$url,$url,''); killme(); } + if(strpos($s,'')) { + $title = substr($s,strpos($s,'<title>')+7,64); + if(strpos($title,'<') !== false) + $title = strip_tags(substr($title,0,strpos($title,'<'))); + } + + $config = HTMLPurifier_Config::createDefault(); + $config->set('Cache.DefinitionImpl', null); + + $purifier = new HTMLPurifier($config); + $s = $purifier->purify($s); + +// logger('parse_url: purified: ' . $s, LOGGER_DATA); + $dom = @HTML5_Parser::parse($s); - if(! $dom) - return $ret; + if(! $dom) { + echo sprintf($template,$url,$url,''); + killme(); + } $items = $dom->getElementsByTagName('title'); @@ -61,26 +69,31 @@ function parse_url_content(&$a) { } } - $divs = $dom->getElementsByTagName('div'); if($divs) { foreach($divs as $div) { $class = $div->getAttribute('class'); - if($class && stristr($class,'article')) { + if($class && (stristr($class,'article') || stristr($class,'content'))) { $items = $div->getElementsByTagName('p'); if($items) { foreach($items as $item) { - if($item->getElementsByTagName('script')) - continue; $text = $item->textContent; + if(stristr($text,'<script')) { + $text = ''; + continue; + } $text = strip_tags($text); - if(strlen($text) < 100) + if(strlen($text) < 100) { + $text = ''; continue; + } $text = substr($text,0,250) . '...' ; break; } } } + if($text) + break; } } @@ -88,12 +101,14 @@ function parse_url_content(&$a) { $items = $dom->getElementsByTagName('p'); if($items) { foreach($items as $item) { - if($item->getElementsByTagName('script')) - continue; $text = $item->textContent; + if(stristr($text,'<script')) + continue; $text = strip_tags($text); - if(strlen($text) < 100) + if(strlen($text) < 100) { + $text = ''; continue; + } $text = substr($text,0,250) . '...' ; break; } @@ -101,9 +116,9 @@ function parse_url_content(&$a) { } if(strlen($text)) { - $text = '<br />' . $text; + $text = '<br /><br /><blockquote>' . $text . '</blockquote><br />'; } - echo sprintf($template,$url,$title,$text); + echo sprintf($template,$url,($title) ? $title : $url,$text); killme(); -} \ No newline at end of file +}