X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=mod%2Fparse_url.php;h=15a6aced0e0fda8fcff6d765c17aea3cf94baa00;hb=2a578478167174b328352e0eafe8a4fdbe0fb68d;hp=33381a0d271be0363535bf2a6e29aa5ad892ccc6;hpb=36b66dccb60a7d65724da542f9d7a2d6722fc6aa;p=friendica.git
diff --git a/mod/parse_url.php b/mod/parse_url.php
index 33381a0d27..15a6aced0e 100644
--- a/mod/parse_url.php
+++ b/mod/parse_url.php
@@ -3,30 +3,97 @@
require_once('library/HTML5/Parser.php');
function parse_url_content(&$a) {
- $url = trim($_GET['url']);
- $template = "%s";
+ logger('parse_url: ' . $_GET['url']);
- if($url)
+ $url = trim(hex2bin($_GET['url']));
+
+ logger('parse_url: ' . $url);
+
+ $text = null;
+
+ $template = "%s\n%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 {
+ echo '';
+ killme();
+ }
+
+
if(! $s) {
- echo sprintf($template,$url,$url);
+ echo sprintf($template,$url,$url,'');
killme();
}
- $dom = HTML5_Parser::parse($s);
+ $dom = @HTML5_Parser::parse($s);
if(! $dom)
return $ret;
$items = $dom->getElementsByTagName('title');
-
- foreach($items as $item) {
- $title = $item->textContent;
- break;
+
+ if($items) {
+ foreach($items as $item) {
+ $title = trim($item->textContent);
+ break;
+ }
+ }
+
+
+ $divs = $dom->getElementsByTagName('div');
+ if($divs) {
+ foreach($divs as $div) {
+ $class = $div->getAttribute('class');
+ if($class && stristr($class,'article')) {
+ $items = $div->getElementsByTagName('p');
+ if($items) {
+ foreach($items as $item) {
+ if($item->getElementsByTagName('script'))
+ continue;
+ $text = $item->textContent;
+ $text = strip_tags($text);
+ if(strlen($text) < 100)
+ continue;
+ $text = substr($text,0,250) . '...' ;
+ break;
+ }
+ }
+ }
+ }
+ }
+
+ if(! $text) {
+ $items = $dom->getElementsByTagName('p');
+ if($items) {
+ foreach($items as $item) {
+ if($item->getElementsByTagName('script'))
+ continue;
+ $text = $item->textContent;
+ $text = strip_tags($text);
+ if(strlen($text) < 100)
+ continue;
+ $text = substr($text,0,250) . '...' ;
+ break;
+ }
+ }
+ }
+
+ if(strlen($text)) {
+ $text = '
' . $text;
}
- echo sprintf($template,$url,$title);
+ echo sprintf($template,$url,$title,$text);
killme();
-}
\ No newline at end of file
+}