X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=mod%2Fparse_url.php;h=79c336ddccad66f84b5869778e5d33e099aed4ed;hb=f17d91844f9825c3effcf47c5b65b645b15939c5;hp=bf6639b300a72cd6a24cd2c6a14aa186fe6a9862;hpb=35edf79abe08bcc1833dc695cb9aebfa5d4a78c0;p=friendica.git diff --git a/mod/parse_url.php b/mod/parse_url.php index bf6639b300..79c336ddcc 100644 --- a/mod/parse_url.php +++ b/mod/parse_url.php @@ -13,7 +13,7 @@ function parse_url_content(&$a) { $text = null; - $template = "%s\n%s"; + $template = "
%s%s
"; $arr = array('url' => $url, 'text' => ''); @@ -42,7 +42,7 @@ function parse_url_content(&$a) { if(strpos($s,'')) { $title = substr($s,strpos($s,'<title>')+7,64); if(strpos($title,'<') !== false) - $title = substr($title,0,strpos($title,'<')); + $title = strip_tags(substr($title,0,strpos($title,'<'))); } $config = HTMLPurifier_Config::createDefault(); @@ -51,6 +51,8 @@ function parse_url_content(&$a) { $purifier = new HTMLPurifier($config); $s = $purifier->purify($s); +// logger('parse_url: purified: ' . $s, LOGGER_DATA); + $dom = @HTML5_Parser::parse($s); if(! $dom) { @@ -71,21 +73,27 @@ function parse_url_content(&$a) { 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; } } @@ -93,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; } @@ -106,9 +116,15 @@ function parse_url_content(&$a) { } if(strlen($text)) { - $text = '<br />' . $text; + $text = '<br /><br /><blockquote>' . $text . '</blockquote><br />'; } - echo sprintf($template,$url,($title) ? $title : $url,$text); + $title = str_replace("\n",'',$title); + + $result = sprintf($template,$url,($title) ? $title : $url,$text); + + logger('parse_url: returns: ' . $result); + + echo $result; killme(); }