3 require_once('library/HTML5/Parser.php');
6 function parse_url_content(&$a) {
8 logger('parse_url: ' . $_GET['url']);
10 $url = trim(hex2bin($_GET['url']));
12 logger('parse_url: ' . $url);
16 $template = "<a href=\"%s\" >%s</a>\n%s";
19 $arr = array('url' => $url, 'text' => '');
21 call_hooks('parse_link', $arr);
23 if(strlen($arr['text'])) {
37 echo sprintf($template,$url,$url,'');
41 $dom = @HTML5_Parser::parse($s);
46 $items = $dom->getElementsByTagName('title');
49 foreach($items as $item) {
50 $title = trim($item->textContent);
56 $divs = $dom->getElementsByTagName('div');
58 foreach($divs as $div) {
59 $class = $div->getAttribute('class');
60 if($class && stristr($class,'article')) {
61 $items = $div->getElementsByTagName('p');
63 foreach($items as $item) {
64 if($item->getElementsByTagName('script'))
66 $text = $item->textContent;
67 $text = strip_tags($text);
68 if(strlen($text) < 100)
70 $text = substr($text,0,250) . '...' ;
79 $items = $dom->getElementsByTagName('p');
81 foreach($items as $item) {
82 if($item->getElementsByTagName('script'))
84 $text = $item->textContent;
85 $text = strip_tags($text);
86 if(strlen($text) < 100)
88 $text = substr($text,0,250) . '...' ;
95 $text = '<br />' . $text;
98 echo sprintf($template,$url,$title,$text);