]> git.mxchange.org Git - friendica.git/blob - mod/parse_url.php
report failure to generate keys
[friendica.git] / mod / parse_url.php
1 <?php
2
3 require_once('library/HTML5/Parser.php');
4
5 function parse_url_content(&$a) {
6
7         $url = trim($_GET['url']);
8
9         $template = "<a href=\"%s\" >%s</a>%s";
10
11         if($url) 
12                 $s = fetch_url($url);
13         else {
14                 echo '';
15                 killme();
16         }
17         
18         if(! $s) {
19                 echo sprintf($template,$url,$url,'');
20                 killme();
21         }
22
23         $dom = HTML5_Parser::parse($s);
24
25         if(! $dom)
26                 return $ret;
27
28         $items = $dom->getElementsByTagName('title');
29
30         if($items) {
31                 foreach($items as $item) {
32                         $title = $item->textContent;
33                         break;
34                 }
35         }
36
37         $items = $dom->getElementsByTagName('p');
38         if($items) {
39                 foreach($items as $item) {
40                         $text = $item->textContent;
41                         $text = strip_tags($text);
42                         if(strlen($text) < 100)
43                                 continue;
44                         $text = substr($text,0,250) . '...' ;
45                         break;
46                 }
47         }
48
49         if(strlen($text)) {
50                 $text = '<br />' . $text;
51         }
52
53         echo sprintf($template,$url,$title,$text);
54         killme();
55 }