diff options
author | Jeremy <jeremy.benoist@gmail.com> | 2015-01-31 19:09:34 +0100 |
---|---|---|
committer | Jeremy <jeremy.benoist@gmail.com> | 2015-01-31 19:12:49 +0100 |
commit | 7df80cb32ca9b7d0fe452320ddc3563a1e373e2f (patch) | |
tree | c07eb79213d471aa33c49ef4e5819e41cc12f242 /src/Wallabag/CoreBundle/Helper | |
parent | 1990517b2263a080946853ed697a6d687262ae80 (diff) | |
download | wallabag-7df80cb32ca9b7d0fe452320ddc3563a1e373e2f.tar.gz wallabag-7df80cb32ca9b7d0fe452320ddc3563a1e373e2f.tar.zst wallabag-7df80cb32ca9b7d0fe452320ddc3563a1e373e2f.zip |
CS
Diffstat (limited to 'src/Wallabag/CoreBundle/Helper')
-rw-r--r-- | src/Wallabag/CoreBundle/Helper/Content.php | 6 | ||||
-rw-r--r-- | src/Wallabag/CoreBundle/Helper/Entries.php | 9 | ||||
-rwxr-xr-x | src/Wallabag/CoreBundle/Helper/Tools.php | 37 | ||||
-rw-r--r-- | src/Wallabag/CoreBundle/Helper/Url.php | 15 |
4 files changed, 31 insertions, 36 deletions
diff --git a/src/Wallabag/CoreBundle/Helper/Content.php b/src/Wallabag/CoreBundle/Helper/Content.php index 81acbad7..1cc5e4cf 100644 --- a/src/Wallabag/CoreBundle/Helper/Content.php +++ b/src/Wallabag/CoreBundle/Helper/Content.php | |||
@@ -8,8 +8,8 @@ class Content | |||
8 | 8 | ||
9 | private $body; | 9 | private $body; |
10 | 10 | ||
11 | public function __constructor() { | 11 | public function __constructor() |
12 | 12 | { | |
13 | } | 13 | } |
14 | 14 | ||
15 | public function getTitle() | 15 | public function getTitle() |
@@ -31,4 +31,4 @@ class Content | |||
31 | { | 31 | { |
32 | $this->body = $body; | 32 | $this->body = $body; |
33 | } | 33 | } |
34 | } \ No newline at end of file | 34 | } |
diff --git a/src/Wallabag/CoreBundle/Helper/Entries.php b/src/Wallabag/CoreBundle/Helper/Entries.php index a54c3a74..6eeca4ff 100644 --- a/src/Wallabag/CoreBundle/Helper/Entries.php +++ b/src/Wallabag/CoreBundle/Helper/Entries.php | |||
@@ -2,9 +2,6 @@ | |||
2 | 2 | ||
3 | namespace Wallabag\CoreBundle\Helper; | 3 | namespace Wallabag\CoreBundle\Helper; |
4 | 4 | ||
5 | 5 | class Entries | |
6 | class Entries { | 6 | { |
7 | 7 | } | |
8 | |||
9 | |||
10 | } \ No newline at end of file | ||
diff --git a/src/Wallabag/CoreBundle/Helper/Tools.php b/src/Wallabag/CoreBundle/Helper/Tools.php index c932f880..0fd5f259 100755 --- a/src/Wallabag/CoreBundle/Helper/Tools.php +++ b/src/Wallabag/CoreBundle/Helper/Tools.php | |||
@@ -2,9 +2,6 @@ | |||
2 | 2 | ||
3 | namespace Wallabag\CoreBundle\Helper; | 3 | namespace Wallabag\CoreBundle\Helper; |
4 | 4 | ||
5 | use \RecursiveIteratorIterator; | ||
6 | use \RecursiveDirectoryIterator; | ||
7 | |||
8 | final class Tools | 5 | final class Tools |
9 | { | 6 | { |
10 | /** | 7 | /** |
@@ -18,7 +15,7 @@ final class Tools | |||
18 | $timeout = 15; | 15 | $timeout = 15; |
19 | $useragent = "Mozilla/5.0 (Windows NT 5.1; rv:18.0) Gecko/20100101 Firefox/18.0"; | 16 | $useragent = "Mozilla/5.0 (Windows NT 5.1; rv:18.0) Gecko/20100101 Firefox/18.0"; |
20 | 17 | ||
21 | if (in_array ('curl', get_loaded_extensions())) { | 18 | if (in_array('curl', get_loaded_extensions())) { |
22 | # Fetch feed from URL | 19 | # Fetch feed from URL |
23 | $curl = curl_init(); | 20 | $curl = curl_init(); |
24 | curl_setopt($curl, CURLOPT_URL, $url); | 21 | curl_setopt($curl, CURLOPT_URL, $url); |
@@ -30,8 +27,8 @@ final class Tools | |||
30 | curl_setopt($curl, CURLOPT_HEADER, false); | 27 | curl_setopt($curl, CURLOPT_HEADER, false); |
31 | 28 | ||
32 | # for ssl, do not verified certificate | 29 | # for ssl, do not verified certificate |
33 | curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE); | 30 | curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); |
34 | curl_setopt($curl, CURLOPT_AUTOREFERER, TRUE ); | 31 | curl_setopt($curl, CURLOPT_AUTOREFERER, true); |
35 | 32 | ||
36 | # FeedBurner requires a proper USER-AGENT... | 33 | # FeedBurner requires a proper USER-AGENT... |
37 | curl_setopt($curl, CURL_HTTP_VERSION_1_1, true); | 34 | curl_setopt($curl, CURL_HTTP_VERSION_1_1, true); |
@@ -48,13 +45,13 @@ final class Tools | |||
48 | array( | 45 | array( |
49 | 'http' => array( | 46 | 'http' => array( |
50 | 'timeout' => $timeout, | 47 | 'timeout' => $timeout, |
51 | 'header' => "User-Agent: " . $useragent, | 48 | 'header' => "User-Agent: ".$useragent, |
52 | 'follow_location' => true | 49 | 'follow_location' => true, |
53 | ), | 50 | ), |
54 | 'ssl' => array( | 51 | 'ssl' => array( |
55 | 'verify_peer' => false, | 52 | 'verify_peer' => false, |
56 | 'allow_self_signed' => true | 53 | 'allow_self_signed' => true, |
57 | ) | 54 | ), |
58 | ) | 55 | ) |
59 | ); | 56 | ); |
60 | 57 | ||
@@ -62,13 +59,12 @@ final class Tools | |||
62 | $data = @file_get_contents($url, false, $context, -1, 4000000); | 59 | $data = @file_get_contents($url, false, $context, -1, 4000000); |
63 | 60 | ||
64 | if (isset($http_response_header) and isset($http_response_header[0])) { | 61 | if (isset($http_response_header) and isset($http_response_header[0])) { |
65 | $httpcodeOK = isset($http_response_header) and isset($http_response_header[0]) and ((strpos($http_response_header[0], '200 OK') !== FALSE) or (strpos($http_response_header[0], '301 Moved Permanently') !== FALSE)); | 62 | $httpcodeOK = isset($http_response_header) and isset($http_response_header[0]) and ((strpos($http_response_header[0], '200 OK') !== false) or (strpos($http_response_header[0], '301 Moved Permanently') !== false)); |
66 | } | 63 | } |
67 | } | 64 | } |
68 | 65 | ||
69 | # if response is not empty and response is OK | 66 | # if response is not empty and response is OK |
70 | if (isset($data) and isset($httpcodeOK) and $httpcodeOK) { | 67 | if (isset($data) and isset($httpcodeOK) and $httpcodeOK) { |
71 | |||
72 | # take charset of page and get it | 68 | # take charset of page and get it |
73 | preg_match('#<meta .*charset=.*>#Usi', $data, $meta); | 69 | preg_match('#<meta .*charset=.*>#Usi', $data, $meta); |
74 | 70 | ||
@@ -77,19 +73,20 @@ final class Tools | |||
77 | preg_match('#charset="?(.*)"#si', $meta[0], $encoding); | 73 | preg_match('#charset="?(.*)"#si', $meta[0], $encoding); |
78 | # if charset is found set it otherwise, set it to utf-8 | 74 | # if charset is found set it otherwise, set it to utf-8 |
79 | $html_charset = (!empty($encoding[1])) ? strtolower($encoding[1]) : 'utf-8'; | 75 | $html_charset = (!empty($encoding[1])) ? strtolower($encoding[1]) : 'utf-8'; |
80 | if (empty($encoding[1])) $encoding[1] = 'utf-8'; | 76 | if (empty($encoding[1])) { |
77 | $encoding[1] = 'utf-8'; | ||
78 | } | ||
81 | } else { | 79 | } else { |
82 | $html_charset = 'utf-8'; | 80 | $html_charset = 'utf-8'; |
83 | $encoding[1] = ''; | 81 | $encoding[1] = ''; |
84 | } | 82 | } |
85 | 83 | ||
86 | # replace charset of url to charset of page | 84 | # replace charset of url to charset of page |
87 | $data = str_replace('charset=' . $encoding[1], 'charset=' . $html_charset, $data); | 85 | $data = str_replace('charset='.$encoding[1], 'charset='.$html_charset, $data); |
88 | 86 | ||
89 | return $data; | 87 | return $data; |
90 | } | 88 | } else { |
91 | else { | 89 | return false; |
92 | return FALSE; | ||
93 | } | 90 | } |
94 | } | 91 | } |
95 | 92 | ||
@@ -101,7 +98,7 @@ final class Tools | |||
101 | */ | 98 | */ |
102 | public static function encodeString($string) | 99 | public static function encodeString($string) |
103 | { | 100 | { |
104 | return sha1($string . SALT); | 101 | return sha1($string.SALT); |
105 | } | 102 | } |
106 | 103 | ||
107 | public static function generateToken() | 104 | public static function generateToken() |
@@ -113,12 +110,10 @@ final class Tools | |||
113 | } else { | 110 | } else { |
114 | $token = substr(base64_encode(file_get_contents('/dev/urandom', false, null, 0, 20)), 0, 15); | 111 | $token = substr(base64_encode(file_get_contents('/dev/urandom', false, null, 0, 20)), 0, 15); |
115 | } | 112 | } |
116 | } | 113 | } else { |
117 | else { | ||
118 | $token = substr(base64_encode(uniqid(mt_rand(), true)), 0, 20); | 114 | $token = substr(base64_encode(uniqid(mt_rand(), true)), 0, 20); |
119 | } | 115 | } |
120 | 116 | ||
121 | return str_replace('+', '', $token); | 117 | return str_replace('+', '', $token); |
122 | } | 118 | } |
123 | |||
124 | } | 119 | } |
diff --git a/src/Wallabag/CoreBundle/Helper/Url.php b/src/Wallabag/CoreBundle/Helper/Url.php index b076e7c7..35eb260d 100644 --- a/src/Wallabag/CoreBundle/Helper/Url.php +++ b/src/Wallabag/CoreBundle/Helper/Url.php | |||
@@ -6,20 +6,23 @@ class Url | |||
6 | { | 6 | { |
7 | public $url; | 7 | public $url; |
8 | 8 | ||
9 | function __construct($url) | 9 | public function __construct($url) |
10 | { | 10 | { |
11 | $this->url = base64_decode($url); | 11 | $this->url = base64_decode($url); |
12 | } | 12 | } |
13 | 13 | ||
14 | public function getUrl() { | 14 | public function getUrl() |
15 | { | ||
15 | return $this->url; | 16 | return $this->url; |
16 | } | 17 | } |
17 | 18 | ||
18 | public function setUrl($url) { | 19 | public function setUrl($url) |
20 | { | ||
19 | $this->url = $url; | 21 | $this->url = $url; |
20 | } | 22 | } |
21 | 23 | ||
22 | public function isCorrect() { | 24 | public function isCorrect() |
23 | return filter_var($this->url, FILTER_VALIDATE_URL) !== FALSE; | 25 | { |
26 | return filter_var($this->url, FILTER_VALIDATE_URL) !== false; | ||
24 | } | 27 | } |
25 | } \ No newline at end of file | 28 | } |