diff options
author | memiks <memiks@memiks.fr> | 2013-04-23 07:22:19 -0500 |
---|---|---|
committer | memiks <memiks@memiks.fr> | 2013-04-23 07:22:19 -0500 |
commit | 4ddbd26787ebbf4c5e01061ac9dbee4f8c21421b (patch) | |
tree | edc16feb3deeb94294dbf461ced404e611b6d9f2 /inc/functions.php | |
parent | 8444bb0600f2432835a7ceaad8c87d4e63f26bd4 (diff) | |
download | wallabag-4ddbd26787ebbf4c5e01061ac9dbee4f8c21421b.tar.gz wallabag-4ddbd26787ebbf4c5e01061ac9dbee4f8c21421b.tar.zst wallabag-4ddbd26787ebbf4c5e01061ac9dbee4f8c21421b.zip |
Ajout du global msg et gestion du retour dans Readability
Diffstat (limited to 'inc/functions.php')
-rw-r--r-- | inc/functions.php | 29 |
1 files changed, 25 insertions, 4 deletions
diff --git a/inc/functions.php b/inc/functions.php index 205f3968..b27120c5 100644 --- a/inc/functions.php +++ b/inc/functions.php | |||
@@ -39,6 +39,10 @@ function get_external_file($url) | |||
39 | curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); | 39 | curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); |
40 | curl_setopt($curl, CURLOPT_HEADER, false); | 40 | curl_setopt($curl, CURLOPT_HEADER, false); |
41 | 41 | ||
42 | // FOR SSL do not verified certificate | ||
43 | curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE); | ||
44 | curl_setopt($curl, CURLOPT_AUTOREFERER, TRUE ); | ||
45 | |||
42 | // FeedBurner requires a proper USER-AGENT... | 46 | // FeedBurner requires a proper USER-AGENT... |
43 | curl_setopt($curl, CURL_HTTP_VERSION_1_1, true); | 47 | curl_setopt($curl, CURL_HTTP_VERSION_1_1, true); |
44 | curl_setopt($curl, CURLOPT_ENCODING, "gzip, deflate"); | 48 | curl_setopt($curl, CURLOPT_ENCODING, "gzip, deflate"); |
@@ -54,7 +58,15 @@ function get_external_file($url) | |||
54 | } else { | 58 | } else { |
55 | 59 | ||
56 | // create http context and add timeout and user-agent | 60 | // 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))); | 61 | $context = stream_context_create(array( |
62 | 'http'=>array('timeout' => $timeout, | ||
63 | 'header'=> "User-Agent: ".$useragent, /*spoot Mozilla Firefox*/ | ||
64 | 'follow_location' => true), | ||
65 | // FOR SSL do not verified certificate | ||
66 | 'ssl' => array('verify_peer' => false, | ||
67 | 'allow_self_signed' => true) | ||
68 | ) | ||
69 | ); | ||
58 | 70 | ||
59 | // only download page lesser than 4MB | 71 | // only download page lesser than 4MB |
60 | $data = @file_get_contents($url, false, $context, -1, 4000000); // We download at most 4 MB from source. | 72 | $data = @file_get_contents($url, false, $context, -1, 4000000); // We download at most 4 MB from source. |
@@ -98,6 +110,8 @@ function get_external_file($url) | |||
98 | */ | 110 | */ |
99 | function prepare_url($url) | 111 | function prepare_url($url) |
100 | { | 112 | { |
113 | global $msg; | ||
114 | |||
101 | $parametres = array(); | 115 | $parametres = array(); |
102 | $url = html_entity_decode(trim($url)); | 116 | $url = html_entity_decode(trim($url)); |
103 | 117 | ||
@@ -108,14 +122,21 @@ function prepare_url($url) | |||
108 | $i=strpos($url,'#xtor=RSS-'); if ($i!==false) $url=substr($url,0,$i); | 122 | $i=strpos($url,'#xtor=RSS-'); if ($i!==false) $url=substr($url,0,$i); |
109 | 123 | ||
110 | $title = $url; | 124 | $title = $url; |
111 | if (!preg_match('!^https?://!i', $url)) | 125 | $html = Encoding::toUTF8(get_external_file($url,15)); |
112 | $url = 'http://' . $url; | 126 | // If get_external_file if not able to retrieve HTTPS content try the same URL with HTTP protocol |
127 | if (!preg_match('!^https?://!i', $url) && (!isset($html) || strlen($html) <= 0)) { | ||
128 | $url = 'http://' . $url; | ||
129 | $html = Encoding::toUTF8(get_external_file($url,15)); | ||
130 | } | ||
113 | 131 | ||
114 | $html = Encoding::toUTF8(get_external_file($url,15)); | ||
115 | if (isset($html) and strlen($html) > 0) | 132 | if (isset($html) and strlen($html) > 0) |
116 | { | 133 | { |
117 | $r = new Readability($html, $url); | 134 | $r = new Readability($html, $url); |
135 | |||
118 | $r->convertLinksToFootnotes = CONVERT_LINKS_FOOTNOTES; | 136 | $r->convertLinksToFootnotes = CONVERT_LINKS_FOOTNOTES; |
137 | $r->debug=true; | ||
138 | $r->revertForcedParagraphElements = REVERT_FORCED_PARAGRAPH_ELEMENTS; | ||
139 | |||
119 | if($r->init()) | 140 | if($r->init()) |
120 | { | 141 | { |
121 | $content = $r->articleContent->innerHTML; | 142 | $content = $r->articleContent->innerHTML; |