diff options
author | Jeremy Benoist <jeremy.benoist@gmail.com> | 2015-08-20 20:10:32 +0200 |
---|---|---|
committer | Jeremy Benoist <jeremy.benoist@gmail.com> | 2015-08-20 20:39:26 +0200 |
commit | 6eebd8c90941ddfe8eeca1961f7a7a493e227687 (patch) | |
tree | a0563695f05ecde2e760402c79ff816b35212be9 /src/Wallabag | |
parent | 0ab7404f93670ed161b67528c1a61c5bfa92d42b (diff) | |
download | wallabag-6eebd8c90941ddfe8eeca1961f7a7a493e227687.tar.gz wallabag-6eebd8c90941ddfe8eeca1961f7a7a493e227687.tar.zst wallabag-6eebd8c90941ddfe8eeca1961f7a7a493e227687.zip |
Remove unsed things
Diffstat (limited to 'src/Wallabag')
-rw-r--r-- | src/Wallabag/CoreBundle/Controller/StaticController.php | 8 | ||||
-rw-r--r-- | src/Wallabag/CoreBundle/Entity/Entry.php | 4 | ||||
-rw-r--r-- | src/Wallabag/CoreBundle/Helper/Entry.php | 7 | ||||
-rwxr-xr-x | src/Wallabag/CoreBundle/Helper/Tools.php | 133 | ||||
-rw-r--r-- | src/Wallabag/CoreBundle/Resources/config/routing.yml | 7 | ||||
-rw-r--r-- | src/Wallabag/CoreBundle/Tools/Utils.php | 13 |
6 files changed, 15 insertions, 157 deletions
diff --git a/src/Wallabag/CoreBundle/Controller/StaticController.php b/src/Wallabag/CoreBundle/Controller/StaticController.php index 3b844b44..64875a66 100644 --- a/src/Wallabag/CoreBundle/Controller/StaticController.php +++ b/src/Wallabag/CoreBundle/Controller/StaticController.php | |||
@@ -28,12 +28,4 @@ class StaticController extends Controller | |||
28 | array() | 28 | array() |
29 | ); | 29 | ); |
30 | } | 30 | } |
31 | |||
32 | /** | ||
33 | * @Route("/", name="homepage") | ||
34 | */ | ||
35 | public function apiAction() | ||
36 | { | ||
37 | return $this->redirect($this->generateUrl('nelmio_api_doc_index')); | ||
38 | } | ||
39 | } | 31 | } |
diff --git a/src/Wallabag/CoreBundle/Entity/Entry.php b/src/Wallabag/CoreBundle/Entity/Entry.php index 7d2d2027..f88d189d 100644 --- a/src/Wallabag/CoreBundle/Entity/Entry.php +++ b/src/Wallabag/CoreBundle/Entity/Entry.php | |||
@@ -7,7 +7,7 @@ use Doctrine\ORM\Mapping as ORM; | |||
7 | use Symfony\Component\Validator\Constraints as Assert; | 7 | use Symfony\Component\Validator\Constraints as Assert; |
8 | use Hateoas\Configuration\Annotation as Hateoas; | 8 | use Hateoas\Configuration\Annotation as Hateoas; |
9 | use JMS\Serializer\Annotation\XmlRoot; | 9 | use JMS\Serializer\Annotation\XmlRoot; |
10 | use Wallabag\CoreBundle\Helper\Tools; | 10 | use Wallabag\CoreBundle\Tools\Utils; |
11 | 11 | ||
12 | /** | 12 | /** |
13 | * Entry. | 13 | * Entry. |
@@ -265,7 +265,7 @@ class Entry | |||
265 | public function setContent($content) | 265 | public function setContent($content) |
266 | { | 266 | { |
267 | $this->content = $content; | 267 | $this->content = $content; |
268 | $this->readingTime = Tools::getReadingTime($content); | 268 | $this->readingTime = Utils::getReadingTime($content); |
269 | $this->domainName = parse_url($this->url, PHP_URL_HOST); | 269 | $this->domainName = parse_url($this->url, PHP_URL_HOST); |
270 | 270 | ||
271 | return $this; | 271 | return $this; |
diff --git a/src/Wallabag/CoreBundle/Helper/Entry.php b/src/Wallabag/CoreBundle/Helper/Entry.php deleted file mode 100644 index 219711b3..00000000 --- a/src/Wallabag/CoreBundle/Helper/Entry.php +++ /dev/null | |||
@@ -1,7 +0,0 @@ | |||
1 | <?php | ||
2 | |||
3 | namespace Wallabag\CoreBundle\Helper; | ||
4 | |||
5 | class Entry | ||
6 | { | ||
7 | } | ||
diff --git a/src/Wallabag/CoreBundle/Helper/Tools.php b/src/Wallabag/CoreBundle/Helper/Tools.php deleted file mode 100755 index d368ee71..00000000 --- a/src/Wallabag/CoreBundle/Helper/Tools.php +++ /dev/null | |||
@@ -1,133 +0,0 @@ | |||
1 | <?php | ||
2 | |||
3 | namespace Wallabag\CoreBundle\Helper; | ||
4 | |||
5 | final class Tools | ||
6 | { | ||
7 | /** | ||
8 | * Download a file (typically, for downloading pictures on web server). | ||
9 | * | ||
10 | * @param $url | ||
11 | * | ||
12 | * @return bool|mixed|string | ||
13 | */ | ||
14 | public static function getFile($url) | ||
15 | { | ||
16 | $timeout = 15; | ||
17 | $useragent = 'Mozilla/5.0 (Windows NT 5.1; rv:18.0) Gecko/20100101 Firefox/18.0'; | ||
18 | |||
19 | if (in_array('curl', get_loaded_extensions())) { | ||
20 | # Fetch feed from URL | ||
21 | $curl = curl_init(); | ||
22 | curl_setopt($curl, CURLOPT_URL, $url); | ||
23 | curl_setopt($curl, CURLOPT_TIMEOUT, $timeout); | ||
24 | if (!ini_get('open_basedir') && !ini_get('safe_mode')) { | ||
25 | curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true); | ||
26 | } | ||
27 | curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); | ||
28 | curl_setopt($curl, CURLOPT_HEADER, false); | ||
29 | |||
30 | # for ssl, do not verified certificate | ||
31 | curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); | ||
32 | curl_setopt($curl, CURLOPT_AUTOREFERER, true); | ||
33 | |||
34 | # FeedBurner requires a proper USER-AGENT... | ||
35 | curl_setopt($curl, CURL_HTTP_VERSION_1_1, true); | ||
36 | curl_setopt($curl, CURLOPT_ENCODING, 'gzip, deflate'); | ||
37 | curl_setopt($curl, CURLOPT_USERAGENT, $useragent); | ||
38 | |||
39 | $data = curl_exec($curl); | ||
40 | $httpcode = curl_getinfo($curl, CURLINFO_HTTP_CODE); | ||
41 | $httpcodeOK = isset($httpcode) and ($httpcode == 200 or $httpcode == 301); | ||
42 | curl_close($curl); | ||
43 | } else { | ||
44 | # create http context and add timeout and user-agent | ||
45 | $context = stream_context_create( | ||
46 | array( | ||
47 | 'http' => array( | ||
48 | 'timeout' => $timeout, | ||
49 | 'header' => 'User-Agent: '.$useragent, | ||
50 | 'follow_location' => true, | ||
51 | ), | ||
52 | 'ssl' => array( | ||
53 | 'verify_peer' => false, | ||
54 | 'allow_self_signed' => true, | ||
55 | ), | ||
56 | ) | ||
57 | ); | ||
58 | |||
59 | # only download page lesser than 4MB | ||
60 | $data = @file_get_contents($url, false, $context, -1, 4000000); | ||
61 | |||
62 | if (isset($http_response_header) and isset($http_response_header[0])) { | ||
63 | $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)); | ||
64 | } | ||
65 | } | ||
66 | |||
67 | # if response is not empty and response is OK | ||
68 | if (isset($data) and isset($httpcodeOK) and $httpcodeOK) { | ||
69 | # take charset of page and get it | ||
70 | preg_match('#<meta .*charset=.*>#Usi', $data, $meta); | ||
71 | |||
72 | # if meta tag is found | ||
73 | if (!empty($meta[0])) { | ||
74 | preg_match('#charset="?(.*)"#si', $meta[0], $encoding); | ||
75 | # if charset is found set it otherwise, set it to utf-8 | ||
76 | $html_charset = (!empty($encoding[1])) ? strtolower($encoding[1]) : 'utf-8'; | ||
77 | if (empty($encoding[1])) { | ||
78 | $encoding[1] = 'utf-8'; | ||
79 | } | ||
80 | } else { | ||
81 | $html_charset = 'utf-8'; | ||
82 | $encoding[1] = ''; | ||
83 | } | ||
84 | |||
85 | # replace charset of url to charset of page | ||
86 | $data = str_replace('charset='.$encoding[1], 'charset='.$html_charset, $data); | ||
87 | |||
88 | return $data; | ||
89 | } else { | ||
90 | return false; | ||
91 | } | ||
92 | } | ||
93 | |||
94 | /** | ||
95 | * Encode a URL by using a salt. | ||
96 | * | ||
97 | * @param $string | ||
98 | * | ||
99 | * @return string | ||
100 | */ | ||
101 | public static function encodeString($string) | ||
102 | { | ||
103 | return sha1($string.SALT); | ||
104 | } | ||
105 | |||
106 | public static function generateToken() | ||
107 | { | ||
108 | if (ini_get('open_basedir') === '') { | ||
109 | if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') { | ||
110 | // alternative to /dev/urandom for Windows | ||
111 | $token = substr(base64_encode(uniqid(mt_rand(), true)), 0, 20); | ||
112 | } else { | ||
113 | $token = substr(base64_encode(file_get_contents('/dev/urandom', false, null, 0, 20)), 0, 15); | ||
114 | } | ||
115 | } else { | ||
116 | $token = substr(base64_encode(uniqid(mt_rand(), true)), 0, 20); | ||
117 | } | ||
118 | |||
119 | return str_replace('+', '', $token); | ||
120 | } | ||
121 | |||
122 | /** | ||
123 | * For a given text, we calculate reading time for an article. | ||
124 | * | ||
125 | * @param $text | ||
126 | * | ||
127 | * @return float | ||
128 | */ | ||
129 | public static function getReadingTime($text) | ||
130 | { | ||
131 | return floor(str_word_count(strip_tags($text)) / 200); | ||
132 | } | ||
133 | } | ||
diff --git a/src/Wallabag/CoreBundle/Resources/config/routing.yml b/src/Wallabag/CoreBundle/Resources/config/routing.yml index f3502e15..e69de29b 100644 --- a/src/Wallabag/CoreBundle/Resources/config/routing.yml +++ b/src/Wallabag/CoreBundle/Resources/config/routing.yml | |||
@@ -1,7 +0,0 @@ | |||
1 | entry: | ||
2 | resource: "@WallabagCoreBundle/Controller/EntryController.php" | ||
3 | type: annotation | ||
4 | |||
5 | config: | ||
6 | resource: "@WallabagCoreBundle/Controller/ConfigController.php" | ||
7 | type: annotation | ||
diff --git a/src/Wallabag/CoreBundle/Tools/Utils.php b/src/Wallabag/CoreBundle/Tools/Utils.php index 7e2968e7..a4fbcffd 100644 --- a/src/Wallabag/CoreBundle/Tools/Utils.php +++ b/src/Wallabag/CoreBundle/Tools/Utils.php | |||
@@ -25,4 +25,17 @@ class Utils | |||
25 | // remove character which can broken the url | 25 | // remove character which can broken the url |
26 | return str_replace(array('+', '/'), '', $token); | 26 | return str_replace(array('+', '/'), '', $token); |
27 | } | 27 | } |
28 | |||
29 | /** | ||
30 | * For a given text, we calculate reading time for an article | ||
31 | * based on 200 words per minute | ||
32 | * | ||
33 | * @param $text | ||
34 | * | ||
35 | * @return float | ||
36 | */ | ||
37 | public static function getReadingTime($text) | ||
38 | { | ||
39 | return floor(str_word_count(strip_tags($text)) / 200); | ||
40 | } | ||
28 | } | 41 | } |