diff options
author | Nicolas LÅ“uillet <nicolas@loeuillet.org> | 2013-07-31 17:19:50 +0200 |
---|---|---|
committer | Nicolas LÅ“uillet <nicolas@loeuillet.org> | 2013-07-31 17:19:50 +0200 |
commit | 85ebc80c7eaf88e4d57a52adb8e4c32d8cc34b64 (patch) | |
tree | 0012345c93b1fe8a242963bede0db370598d6f2b /inc/functions.php | |
parent | 6588517b2d46cbc524260758d1fafd92b19ab681 (diff) | |
parent | 6d37de5f828b700843567a91418671919eed4be4 (diff) | |
download | wallabag-85ebc80c7eaf88e4d57a52adb8e4c32d8cc34b64.tar.gz wallabag-85ebc80c7eaf88e4d57a52adb8e4c32d8cc34b64.tar.zst wallabag-85ebc80c7eaf88e4d57a52adb8e4c32d8cc34b64.zip |
Merge branch 'dev'0.3
Diffstat (limited to 'inc/functions.php')
-rw-r--r-- | inc/functions.php | 82 |
1 files changed, 63 insertions, 19 deletions
diff --git a/inc/functions.php b/inc/functions.php index 205f3968..73e591c5 100644 --- a/inc/functions.php +++ b/inc/functions.php | |||
@@ -23,6 +23,11 @@ function get_poche_url() | |||
23 | return $protocol . "://" . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; | 23 | return $protocol . "://" . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; |
24 | } | 24 | } |
25 | 25 | ||
26 | function encode_string($string) | ||
27 | { | ||
28 | return sha1($string . SALT); | ||
29 | } | ||
30 | |||
26 | // function define to retrieve url content | 31 | // function define to retrieve url content |
27 | function get_external_file($url) | 32 | function get_external_file($url) |
28 | { | 33 | { |
@@ -39,6 +44,10 @@ function get_external_file($url) | |||
39 | curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); | 44 | curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); |
40 | curl_setopt($curl, CURLOPT_HEADER, false); | 45 | curl_setopt($curl, CURLOPT_HEADER, false); |
41 | 46 | ||
47 | // FOR SSL do not verified certificate | ||
48 | curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE); | ||
49 | curl_setopt($curl, CURLOPT_AUTOREFERER, TRUE ); | ||
50 | |||
42 | // FeedBurner requires a proper USER-AGENT... | 51 | // FeedBurner requires a proper USER-AGENT... |
43 | curl_setopt($curl, CURL_HTTP_VERSION_1_1, true); | 52 | curl_setopt($curl, CURL_HTTP_VERSION_1_1, true); |
44 | curl_setopt($curl, CURLOPT_ENCODING, "gzip, deflate"); | 53 | curl_setopt($curl, CURLOPT_ENCODING, "gzip, deflate"); |
@@ -54,7 +63,15 @@ function get_external_file($url) | |||
54 | } else { | 63 | } else { |
55 | 64 | ||
56 | // create http context and add timeout and user-agent | 65 | // create http context and add timeout and user-agent |
57 | $context = stream_context_create(array('http'=>array('timeout' => $timeout,'header'=> "User-Agent: ".$useragent,/*spoot Mozilla Firefox*/'follow_location' => true))); | 66 | $context = stream_context_create(array( |
67 | 'http'=>array('timeout' => $timeout, | ||
68 | 'header'=> "User-Agent: ".$useragent, /*spoot Mozilla Firefox*/ | ||
69 | 'follow_location' => true), | ||
70 | // FOR SSL do not verified certificate | ||
71 | 'ssl' => array('verify_peer' => false, | ||
72 | 'allow_self_signed' => true) | ||
73 | ) | ||
74 | ); | ||
58 | 75 | ||
59 | // only download page lesser than 4MB | 76 | // only download page lesser than 4MB |
60 | $data = @file_get_contents($url, false, $context, -1, 4000000); // We download at most 4 MB from source. | 77 | $data = @file_get_contents($url, false, $context, -1, 4000000); // We download at most 4 MB from source. |
@@ -108,14 +125,26 @@ function prepare_url($url) | |||
108 | $i=strpos($url,'#xtor=RSS-'); if ($i!==false) $url=substr($url,0,$i); | 125 | $i=strpos($url,'#xtor=RSS-'); if ($i!==false) $url=substr($url,0,$i); |
109 | 126 | ||
110 | $title = $url; | 127 | $title = $url; |
111 | if (!preg_match('!^https?://!i', $url)) | 128 | $html = Encoding::toUTF8(get_external_file($url,15)); |
129 | // If get_external_file if not able to retrieve HTTPS content try the same URL with HTTP protocol | ||
130 | if (!preg_match('!^https?://!i', $url) && (!isset($html) || strlen($html) <= 0)) { | ||
112 | $url = 'http://' . $url; | 131 | $url = 'http://' . $url; |
132 | $html = Encoding::toUTF8(get_external_file($url,15)); | ||
133 | } | ||
134 | |||
135 | if (function_exists('tidy_parse_string')) { | ||
136 | $tidy = tidy_parse_string($html, array(), 'UTF8'); | ||
137 | $tidy->cleanRepair(); | ||
138 | $html = $tidy->value; | ||
139 | } | ||
113 | 140 | ||
114 | $html = Encoding::toUTF8(get_external_file($url,15)); | ||
115 | if (isset($html) and strlen($html) > 0) | 141 | if (isset($html) and strlen($html) > 0) |
116 | { | 142 | { |
117 | $r = new Readability($html, $url); | 143 | $r = new Readability($html, $url); |
144 | |||
118 | $r->convertLinksToFootnotes = CONVERT_LINKS_FOOTNOTES; | 145 | $r->convertLinksToFootnotes = CONVERT_LINKS_FOOTNOTES; |
146 | $r->revertForcedParagraphElements = REVERT_FORCED_PARAGRAPH_ELEMENTS; | ||
147 | |||
119 | if($r->init()) | 148 | if($r->init()) |
120 | { | 149 | { |
121 | $content = $r->articleContent->innerHTML; | 150 | $content = $r->articleContent->innerHTML; |
@@ -125,8 +154,6 @@ function prepare_url($url) | |||
125 | } | 154 | } |
126 | } | 155 | } |
127 | 156 | ||
128 | $msg->add('e', 'error during url preparation'); | ||
129 | logm('error during url preparation'); | ||
130 | return FALSE; | 157 | return FALSE; |
131 | } | 158 | } |
132 | 159 | ||
@@ -263,7 +290,13 @@ function display_view($view, $id = 0, $full_head = 'yes') | |||
263 | $tpl->assign('id', $entry['id']); | 290 | $tpl->assign('id', $entry['id']); |
264 | $tpl->assign('url', $entry['url']); | 291 | $tpl->assign('url', $entry['url']); |
265 | $tpl->assign('title', $entry['title']); | 292 | $tpl->assign('title', $entry['title']); |
266 | $tpl->assign('content', $entry['content']); | 293 | $content = $entry['content']; |
294 | if (function_exists('tidy_parse_string')) { | ||
295 | $tidy = tidy_parse_string($content, array('indent'=>true, 'show-body-only' => true), 'UTF8'); | ||
296 | $tidy->cleanRepair(); | ||
297 | $content = $tidy->value; | ||
298 | } | ||
299 | $tpl->assign('content', $content); | ||
267 | $tpl->assign('is_fav', $entry['is_fav']); | 300 | $tpl->assign('is_fav', $entry['is_fav']); |
268 | $tpl->assign('is_read', $entry['is_read']); | 301 | $tpl->assign('is_read', $entry['is_read']); |
269 | $tpl->assign('load_all_js', 0); | 302 | $tpl->assign('load_all_js', 0); |
@@ -311,35 +344,46 @@ function action_to_do($action, $url, $id = 0) | |||
311 | 344 | ||
312 | if (MyTool::isUrl($url)) { | 345 | if (MyTool::isUrl($url)) { |
313 | if($parametres_url = prepare_url($url)) { | 346 | if($parametres_url = prepare_url($url)) { |
314 | $store->add($url, $parametres_url['title'], $parametres_url['content']); | 347 | if ($store->add($url, $parametres_url['title'], $parametres_url['content'])) { |
315 | $last_id = $store->getLastId(); | 348 | $last_id = $store->getLastId(); |
316 | if (DOWNLOAD_PICTURES) { | 349 | if (DOWNLOAD_PICTURES) { |
317 | $content = filtre_picture($parametres_url['content'], $url, $last_id); | 350 | $content = filtre_picture($parametres_url['content'], $url, $last_id); |
351 | } | ||
352 | $msg->add('s', 'the link has been added successfully'); | ||
318 | } | 353 | } |
319 | $msg->add('s', 'the link has been added successfully'); | 354 | else { |
355 | $msg->add('e', 'error during insertion : the link wasn\'t added'); | ||
356 | } | ||
357 | } | ||
358 | else { | ||
359 | $msg->add('e', 'error during url preparation : the link wasn\'t added'); | ||
360 | logm('error during url preparation'); | ||
320 | } | 361 | } |
321 | } | 362 | } |
322 | else { | 363 | else { |
323 | $msg->add('e', 'the link has been added successfully'); | 364 | $msg->add('e', 'error during url preparation : the link is not valid'); |
324 | logm($url . ' is not a valid url'); | 365 | logm($url . ' is not a valid url'); |
325 | } | 366 | } |
326 | 367 | ||
327 | logm('add link ' . $url); | 368 | logm('add link ' . $url); |
328 | break; | 369 | break; |
329 | case 'delete': | 370 | case 'delete': |
330 | remove_directory(ABS_PATH . $id); | 371 | if ($store->deleteById($id)) { |
331 | $store->deleteById($id); | 372 | remove_directory(ABS_PATH . $id); |
332 | $msg->add('s', 'the link has been deleted successfully'); | 373 | $msg->add('s', 'the link has been deleted successfully'); |
333 | logm('delete link #' . $id); | 374 | logm('delete link #' . $id); |
375 | } | ||
376 | else { | ||
377 | $msg->add('e', 'the link wasn\'t deleted'); | ||
378 | logm('error : can\'t delete link #' . $id); | ||
379 | } | ||
334 | break; | 380 | break; |
335 | case 'toggle_fav' : | 381 | case 'toggle_fav' : |
336 | $store->favoriteById($id); | 382 | $store->favoriteById($id); |
337 | $msg->add('s', 'the favorite toggle has been done successfully'); | ||
338 | logm('mark as favorite link #' . $id); | 383 | logm('mark as favorite link #' . $id); |
339 | break; | 384 | break; |
340 | case 'toggle_archive' : | 385 | case 'toggle_archive' : |
341 | $store->archiveById($id); | 386 | $store->archiveById($id); |
342 | $msg->add('s', 'the archive toggle has been done successfully'); | ||
343 | logm('archive link #' . $id); | 387 | logm('archive link #' . $id); |
344 | break; | 388 | break; |
345 | default: | 389 | default: |
@@ -351,4 +395,4 @@ function logm($message) | |||
351 | { | 395 | { |
352 | $t = strval(date('Y/m/d_H:i:s')).' - '.$_SERVER["REMOTE_ADDR"].' - '.strval($message)."\n"; | 396 | $t = strval(date('Y/m/d_H:i:s')).' - '.$_SERVER["REMOTE_ADDR"].' - '.strval($message)."\n"; |
353 | file_put_contents('./log.txt',$t,FILE_APPEND); | 397 | file_put_contents('./log.txt',$t,FILE_APPEND); |
354 | } \ No newline at end of file | 398 | } |