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);
91 // logger('parse_url: purified: ' . $s, LOGGER_DATA);
93 $dom = @HTML5_Parser::parse($s);
96 echo sprintf($template,$url,$url,'') . $str_tags;
100 $items = $dom->getElementsByTagName('title');
103 foreach($items as $item) {
104 $title = trim($item->textContent);
111 $divs = $dom->getElementsByTagName('div');
113 foreach($divs as $div) {
114 $class = $div->getAttribute('class');
115 if($class && (stristr($class,'article') || stristr($class,'content'))) {
116 $items = $div->getElementsByTagName('p');
118 foreach($items as $item) {
119 $text = $item->textContent;
120 if(stristr($text,'<script')) {
124 $text = strip_tags($text);
125 if(strlen($text) < 100) {
129 $text = substr($text,0,250) . '...' ;
140 $items = $dom->getElementsByTagName('p');
142 foreach($items as $item) {
143 $text = $item->textContent;
144 if(stristr($text,'<script'))
146 $text = strip_tags($text);
147 if(strlen($text) < 100) {
151 $text = substr($text,0,250) . '...' ;
159 $text = '<br /><br /><blockquote>' . $text . '</blockquote><br />';
162 $title = str_replace(array("\r","\n"),array('',''),$title);
164 $result = sprintf($template,$url,($title) ? $title : $url,$text) . $str_tags;
166 logger('parse_url: returns: ' . $result);