3 require_once('library/HTML5/Parser.php');
4 require_once('library/HTMLPurifier.auto.php');
6 function arr_add_hashes(&$item,$k) {
10 function parse_url_content(&$a) {
16 $url = trim(hex2bin($_GET['binurl']));
18 $url = trim($_GET['url']);
21 $title = strip_tags(trim($_GET['title']));
23 if($_GET['description'])
24 $text = strip_tags(trim($_GET['description']));
27 $arr_tags = str_getcsv($_GET['tags']);
28 if(count($arr_tags)) {
29 array_walk($arr_tags,'arr_add_hashes');
30 $str_tags = '<br />' . implode(' ',$arr_tags) . '<br />';
34 logger('parse_url: ' . $url);
37 $template = "<br /><a class=\"bookmark\" href=\"%s\" >%s</a>%s<br />";
40 $arr = array('url' => $url, 'text' => '');
42 call_hooks('parse_link', $arr);
44 if(strlen($arr['text'])) {
49 if($url && $title && $text) {
51 $text = '<br /><br /><blockquote>' . $text . '</blockquote><br />';
52 $title = str_replace(array("\r","\n"),array('',''),$title);
54 $result = sprintf($template,$url,($title) ? $title : $url,$text) . $str_tags;
56 logger('parse_url (unparsed): returns: ' . $result);
70 logger('parse_url: data: ' . $s, LOGGER_DATA);
73 echo sprintf($template,$url,$url,'') . $str_tags;
78 if(strpos($s,'<title>')) {
79 $title = substr($s,strpos($s,'<title>')+7,64);
80 if(strpos($title,'<') !== false)
81 $title = strip_tags(substr($title,0,strpos($title,'<')));
85 $config = HTMLPurifier_Config::createDefault();
86 $config->set('Cache.DefinitionImpl', null);
88 $purifier = new HTMLPurifier($config);
89 $s = $purifier->purify($s);
92 $dom = HTML5_Parser::parse($s);
93 } catch (DOMException $e) {
94 logger('scrape_dfrn: parse error: ' . $e);
98 echo sprintf($template,$url,$url,'') . $str_tags;
102 $items = $dom->getElementsByTagName('title');
105 foreach($items as $item) {
106 $title = trim($item->textContent);
113 $divs = $dom->getElementsByTagName('div');
115 foreach($divs as $div) {
116 $class = $div->getAttribute('class');
117 if($class && (stristr($class,'article') || stristr($class,'content'))) {
118 $items = $div->getElementsByTagName('p');
120 foreach($items as $item) {
121 $text = $item->textContent;
122 if(stristr($text,'<script')) {
126 $text = strip_tags($text);
127 if(strlen($text) < 100) {
131 $text = substr($text,0,250) . '...' ;
142 $items = $dom->getElementsByTagName('p');
144 foreach($items as $item) {
145 $text = $item->textContent;
146 if(stristr($text,'<script'))
148 $text = strip_tags($text);
149 if(strlen($text) < 100) {
153 $text = substr($text,0,250) . '...' ;
161 $text = '<br /><br /><blockquote>' . $text . '</blockquote><br />';
164 $title = str_replace(array("\r","\n"),array('',''),$title);
166 $result = sprintf($template,$url,($title) ? $title : $url,$text) . $str_tags;
168 logger('parse_url: returns: ' . $result);