diff options
author | Nicolas Lœuillet <nicolas.loeuillet@gmail.com> | 2013-08-04 22:35:08 +0200 |
---|---|---|
committer | Nicolas Lœuillet <nicolas.loeuillet@gmail.com> | 2013-08-04 22:35:08 +0200 |
commit | 63c35580c7d60e2278ee6fe9ba2d4440ff0308d6 (patch) | |
tree | 71a0c573d4104d9a751df395c1c162c089ed6017 | |
parent | c765c3679fee3ed9e4bad9954a808116187a7e83 (diff) | |
download | wallabag-63c35580c7d60e2278ee6fe9ba2d4440ff0308d6.tar.gz wallabag-63c35580c7d60e2278ee6fe9ba2d4440ff0308d6.tar.zst wallabag-63c35580c7d60e2278ee6fe9ba2d4440ff0308d6.zip |
twig implementation
-rw-r--r-- | README.md | 33 | ||||
-rw-r--r-- | inc/poche/Poche.class.php | 115 | ||||
-rw-r--r-- | inc/poche/Tools.class.php | 5 | ||||
-rw-r--r-- | index.php | 34 | ||||
-rw-r--r-- | tpl/_footer.twig | 2 | ||||
-rw-r--r-- | tpl/config.twig | 6 | ||||
-rw-r--r-- | tpl/export.twig | 2 | ||||
-rw-r--r-- | tpl/js/poche.js | 2 | ||||
-rw-r--r-- | tpl/login.twig | 4 |
9 files changed, 107 insertions, 96 deletions
@@ -1,5 +1,5 @@ | |||
1 | # poche | 1 | # poche |
2 | Abandon Pocket, Instapaper and other Readability service : adopt poche. It is the same, but it is open source. | 2 | Abandon Pocket, Instapaper and other Readability service : adopt poche. It is the same, but it is open source. Moreover, you can migrate from Pocket & Readability. |
3 | 3 | ||
4 | ![poche](http://inthepoche.com/img/logo.png) | 4 | ![poche](http://inthepoche.com/img/logo.png) |
5 | 5 | ||
@@ -11,23 +11,23 @@ To get news from poche, [follow us on twitter](http://twitter.com/getpoche) or [ | |||
11 | 11 | ||
12 | [![flattr](http://api.flattr.com/button/flattr-badge-large.png)](http://flattr.com/thing/1265480/poche-a-read-it-later-open-source-system) | 12 | [![flattr](http://api.flattr.com/button/flattr-badge-large.png)](http://flattr.com/thing/1265480/poche-a-read-it-later-open-source-system) |
13 | 13 | ||
14 | ## Usage | ||
15 | You can easily add a "poched" page with the bookmarklet. | ||
16 | |||
17 | poche save the entire content of a poched links : text and pictures are stored on your server. | ||
18 | |||
19 | You can : | ||
20 | * read a page in a comfortable reading view | ||
21 | * archive a link | ||
22 | * put a link in favorite | ||
23 | * delete a link | ||
24 | |||
25 | ## Requirements & installation | 14 | ## Requirements & installation |
26 | You have to install [sqlite for php](http://www.php.net/manual/en/book.sqlite.php) on your server. | 15 | You have to install [sqlite for php](http://www.php.net/manual/en/book.sqlite.php) on your server. |
27 | 16 | ||
17 | [PHP cURL](http://www.php.net/manual/en/book.curl.php) & [tidy_parse_string](http://www.php.net/manual/en/tidy.parsestring.php) are recommended. | ||
18 | |||
28 | Get the [latest version](https://github.com/inthepoche/poche) of poche on github. Unzip it and upload it on your server. poche must have write access on assets, cache and db directories. | 19 | Get the [latest version](https://github.com/inthepoche/poche) of poche on github. Unzip it and upload it on your server. poche must have write access on assets, cache and db directories. |
29 | 20 | ||
30 | That's all, **poche works** ! | 21 | Install composer in your project : |
22 | ```bash | ||
23 | curl -s http://getcomposer.org/installer | php | ||
24 | ``` | ||
25 | Install via composer : | ||
26 | ```bash | ||
27 | php composer.phar install | ||
28 | ``` | ||
29 | |||
30 | That's all, you can use poche ! | ||
31 | 31 | ||
32 | ## Security | 32 | ## Security |
33 | You **have** to protect your db/poche.sqlite file. Modify the virtual host of your website to add this condition : | 33 | You **have** to protect your db/poche.sqlite file. Modify the virtual host of your website to add this condition : |
@@ -46,12 +46,11 @@ location ~ /(db) { | |||
46 | } | 46 | } |
47 | ``` | 47 | ``` |
48 | 48 | ||
49 | ## Import from Pocket | 49 | ## Usage |
50 | 50 | See the documentation on our website : [inthepoche.com](http://inthepoche.com). | |
51 | If you want to import your Pocket datas, [export them here](https://getpocket.com/export). Put the HTML file in your poche directory, execute import.php file locally by following instructions. Be careful, the script can take a very long time. | ||
52 | 51 | ||
53 | ## License | 52 | ## License |
54 | Copyright © 2010-2013 Nicolas Lœuillet <nicolas@loeuillet.org> | 53 | Copyright © 2010-2013 Nicolas Lœuillet <nicolas@loeuillet.org> |
55 | This work is free. You can redistribute it and/or modify it under the | 54 | This work is free. You can redistribute it and/or modify it under the |
56 | terms of the Do What The Fuck You Want To Public License, Version 2, | 55 | terms of the Do What The Fuck You Want To Public License, Version 2, |
57 | as published by Sam Hocevar. See the COPYING file for more details. | 56 | as published by Sam Hocevar. See the COPYING file for more details. \ No newline at end of file |
diff --git a/inc/poche/Poche.class.php b/inc/poche/Poche.class.php index 9e407d41..5c3eda80 100644 --- a/inc/poche/Poche.class.php +++ b/inc/poche/Poche.class.php | |||
@@ -118,8 +118,6 @@ class Poche | |||
118 | $this->store->archiveById($id); | 118 | $this->store->archiveById($id); |
119 | Tools::logm('archive link #' . $id); | 119 | Tools::logm('archive link #' . $id); |
120 | break; | 120 | break; |
121 | case 'import': | ||
122 | break; | ||
123 | default: | 121 | default: |
124 | break; | 122 | break; |
125 | } | 123 | } |
@@ -131,18 +129,6 @@ class Poche | |||
131 | 129 | ||
132 | switch ($view) | 130 | switch ($view) |
133 | { | 131 | { |
134 | case 'install': | ||
135 | Tools::logm('install mode'); | ||
136 | break; | ||
137 | case 'import'; | ||
138 | Tools::logm('import mode'); | ||
139 | break; | ||
140 | case 'export': | ||
141 | $entries = $this->store->retrieveAll(); | ||
142 | // $tpl->assign('export', Tools::renderJson($entries)); | ||
143 | // $tpl->draw('export'); | ||
144 | Tools::logm('export view'); | ||
145 | break; | ||
146 | case 'config': | 132 | case 'config': |
147 | Tools::logm('config view'); | 133 | Tools::logm('config view'); |
148 | break; | 134 | break; |
@@ -224,59 +210,80 @@ class Poche | |||
224 | Tools::redirect(); | 210 | Tools::redirect(); |
225 | } | 211 | } |
226 | 212 | ||
227 | public function import($from) | 213 | private function importFromInstapaper() |
228 | { | 214 | { |
229 | if ($from == 'pocket') { | 215 | Tools::logm('import from instapaper completed'); |
230 | $html = new simple_html_dom(); | 216 | Tools::redirect(); |
231 | $html->load_file('./ril_export.html'); | 217 | } |
232 | 218 | ||
233 | $read = 0; | 219 | private function importFromPocket() |
234 | $errors = array(); | 220 | { |
235 | foreach($html->find('ul') as $ul) | 221 | $html = new simple_html_dom(); |
222 | $html->load_file('./ril_export.html'); | ||
223 | |||
224 | $read = 0; | ||
225 | $errors = array(); | ||
226 | foreach($html->find('ul') as $ul) | ||
227 | { | ||
228 | foreach($ul->find('li') as $li) | ||
236 | { | 229 | { |
237 | foreach($ul->find('li') as $li) | 230 | $a = $li->find('a'); |
238 | { | 231 | $url = new Url(base64_encode($a[0]->href)); |
239 | $a = $li->find('a'); | 232 | $this->action('add', $url); |
240 | $url = new Url($a[0]->href); | 233 | if ($read == '1') { |
241 | $this->action('add', $url); | 234 | $last_id = $this->store->getLastId(); |
242 | if ($read == '1') { | 235 | $this->store->archiveById($last_id); |
243 | $last_id = $this->store->lastInsertId(); | ||
244 | $sql_update = "UPDATE entries SET is_read=~is_read WHERE id=?"; | ||
245 | $params_update = array($last_id); | ||
246 | $query_update = $this->store->prepare($sql_update); | ||
247 | $query_update->execute($params_update); | ||
248 | } | ||
249 | } | 236 | } |
250 | # Pocket génère un fichier HTML avec deux <ul> | ||
251 | # Le premier concerne les éléments non lus | ||
252 | # Le second concerne les éléments archivés | ||
253 | $read = 1; | ||
254 | } | 237 | } |
255 | logm('import from pocket completed'); | 238 | # Pocket génère un fichier HTML avec deux <ul> |
256 | Tools::redirect(); | 239 | # Le premier concerne les éléments non lus |
240 | # Le second concerne les éléments archivés | ||
241 | $read = 1; | ||
257 | } | 242 | } |
258 | else if ($from == 'readability') { | 243 | Tools::logm('import from pocket completed'); |
259 | # TODO finaliser tout ça ici | 244 | Tools::redirect(); |
260 | $str_data = file_get_contents("readability"); | 245 | } |
261 | $data = json_decode($str_data,true); | ||
262 | 246 | ||
263 | foreach ($data as $key => $value) { | 247 | private function importFromReadability() |
264 | $url = ''; | 248 | { |
265 | foreach ($value as $key2 => $value2) { | 249 | # TODO finaliser tout ça ici |
266 | if ($key2 == 'article__url') { | 250 | # noms des variables + gestion des articles lus |
267 | $url = new Url($value2); | 251 | $str_data = file_get_contents("./readability"); |
268 | } | 252 | $data = json_decode($str_data,true); |
253 | |||
254 | foreach ($data as $key => $value) { | ||
255 | $url = ''; | ||
256 | foreach ($value as $key2 => $value2) { | ||
257 | if ($key2 == 'article__url') { | ||
258 | $url = new Url(base64_encode($value2)); | ||
269 | } | 259 | } |
270 | if ($url != '') | ||
271 | action_to_do('add', $url); | ||
272 | } | 260 | } |
273 | logm('import from Readability completed'); | 261 | if ($url->isCorrect()) |
274 | Tools::redirect(); | 262 | $this->action('add', $url); |
275 | } | 263 | } |
264 | Tools::logm('import from Readability completed'); | ||
265 | Tools::redirect(); | ||
276 | } | 266 | } |
277 | 267 | ||
278 | public function export() | 268 | public function import($from) |
279 | { | 269 | { |
270 | if ($from == 'pocket') { | ||
271 | $this->importFromPocket(); | ||
272 | } | ||
273 | else if ($from == 'readability') { | ||
274 | $this->importFromReadability(); | ||
275 | } | ||
276 | else if ($from == 'instapaper') { | ||
277 | $this->importFromInstapaper(); | ||
278 | } | ||
279 | } | ||
280 | 280 | ||
281 | public function export() | ||
282 | { | ||
283 | $entries = $this->store->retrieveAll(); | ||
284 | echo $this->tpl->render('export.twig', array( | ||
285 | 'export' => Tools::renderJson($entries), | ||
286 | )); | ||
287 | Tools::logm('export view'); | ||
281 | } | 288 | } |
282 | } \ No newline at end of file | 289 | } \ No newline at end of file |
diff --git a/inc/poche/Tools.class.php b/inc/poche/Tools.class.php index c277035f..1ff4ba55 100644 --- a/inc/poche/Tools.class.php +++ b/inc/poche/Tools.class.php | |||
@@ -205,4 +205,9 @@ class Tools | |||
205 | { | 205 | { |
206 | return sha1($string . SALT); | 206 | return sha1($string . SALT); |
207 | } | 207 | } |
208 | |||
209 | public static function checkVar($var) | ||
210 | { | ||
211 | return ((isset ($_REQUEST["$var"])) ? htmlentities($_REQUEST["$var"]) : ''); | ||
212 | } | ||
208 | } \ No newline at end of file | 213 | } \ No newline at end of file |
@@ -10,16 +10,21 @@ | |||
10 | 10 | ||
11 | include dirname(__FILE__).'/inc/poche/config.inc.php'; | 11 | include dirname(__FILE__).'/inc/poche/config.inc.php'; |
12 | 12 | ||
13 | # XSRF protection with token | 13 | #XSRF protection with token |
14 | // if (!empty($_POST)) { | 14 | if (!empty($_POST)) { |
15 | // if (!Session::isToken($_POST['token'])) { | 15 | if (!Session::isToken($_POST['token'])) { |
16 | // die(_('Wrong token')); | 16 | die(_('Wrong token')); |
17 | // // TODO remettre le test | 17 | // TODO remettre le test |
18 | // } | 18 | } |
19 | // unset($_SESSION['tokens']); | 19 | unset($_SESSION['tokens']); |
20 | // } | 20 | } |
21 | 21 | ||
22 | $referer = empty($_SERVER['HTTP_REFERER']) ? '' : $_SERVER['HTTP_REFERER']; | 22 | $referer = empty($_SERVER['HTTP_REFERER']) ? '' : $_SERVER['HTTP_REFERER']; |
23 | $view = Tools::checkVar('view'); | ||
24 | $action = Tools::checkVar('action'); | ||
25 | $id = Tools::checkVar('id'); | ||
26 | $_SESSION['sort'] = Tools::checkVar('sort'); | ||
27 | $url = new Url((isset ($_GET['url'])) ? $_GET['url'] : ''); | ||
23 | 28 | ||
24 | if (isset($_GET['login'])) { | 29 | if (isset($_GET['login'])) { |
25 | # hello you | 30 | # hello you |
@@ -36,15 +41,9 @@ elseif (isset($_GET['config'])) { | |||
36 | elseif (isset($_GET['import'])) { | 41 | elseif (isset($_GET['import'])) { |
37 | $poche->import($_GET['from']); | 42 | $poche->import($_GET['from']); |
38 | } | 43 | } |
39 | 44 | elseif (isset($_GET['export'])) { | |
40 | # Aaaaaaand action ! | 45 | $poche->export(); |
41 | $view = (isset ($_REQUEST['view'])) ? htmlentities($_REQUEST['view']) : 'home'; | 46 | } |
42 | $full_head = (isset ($_REQUEST['full_head'])) ? htmlentities($_REQUEST['full_head']) : 'yes'; | ||
43 | $action = (isset ($_REQUEST['action'])) ? htmlentities($_REQUEST['action']) : ''; | ||
44 | $_SESSION['sort'] = (isset ($_REQUEST['sort'])) ? htmlentities($_REQUEST['sort']) : 'id'; | ||
45 | $id = (isset ($_REQUEST['id'])) ? htmlspecialchars($_REQUEST['id']) : ''; | ||
46 | |||
47 | $url = new Url((isset ($_GET['url'])) ? $_GET['url'] : ''); | ||
48 | 47 | ||
49 | $tpl_vars = array( | 48 | $tpl_vars = array( |
50 | 'referer' => $referer, | 49 | 'referer' => $referer, |
@@ -64,4 +63,5 @@ else { | |||
64 | $tpl_file = 'login.twig'; | 63 | $tpl_file = 'login.twig'; |
65 | } | 64 | } |
66 | 65 | ||
66 | # Aaaaaaand action ! | ||
67 | echo $poche->tpl->render($tpl_file, $tpl_vars); \ No newline at end of file | 67 | echo $poche->tpl->render($tpl_file, $tpl_vars); \ No newline at end of file |
diff --git a/tpl/_footer.twig b/tpl/_footer.twig index 59b58fa5..b1d7b8d4 100644 --- a/tpl/_footer.twig +++ b/tpl/_footer.twig | |||
@@ -1,3 +1,3 @@ | |||
1 | <footer class="mr2 mt3 smaller"> | 1 | <footer class="mr2 mt3 smaller"> |
2 | <p>powered by <a href="http://inthepoche.com">poche</a></p> | 2 | <p>{% trans "powered by" %} <a href="http://inthepoche.com">poche</a></p> |
3 | </footer> \ No newline at end of file | 3 | </footer> \ No newline at end of file |
diff --git a/tpl/config.twig b/tpl/config.twig index 9a51e566..c18806bc 100644 --- a/tpl/config.twig +++ b/tpl/config.twig | |||
@@ -40,11 +40,11 @@ | |||
40 | <p>{% trans "Please execute the import script locally, it can take a very long time." %}</p> | 40 | <p>{% trans "Please execute the import script locally, it can take a very long time." %}</p> |
41 | <p>{% trans "More infos in the official doc:" %} <a href="http://inthepoche.com/?pages/Documentation">inthepoche.com</a></p> | 41 | <p>{% trans "More infos in the official doc:" %} <a href="http://inthepoche.com/?pages/Documentation">inthepoche.com</a></p> |
42 | <p><ul> | 42 | <p><ul> |
43 | <li><a href="/?import&from=pocket">{% trans "import from Pocket" %}</a> (you must have a "ril_export.html" file on your server)</li> | 43 | <li><a href="./?import&from=pocket">{% trans "import from Pocket" %}</a> (you must have a "ril_export.html" file on your server)</li> |
44 | <li><a href="/?import&from=readability">{% trans "import from Readability" %}</a> (you must have a "readability" file on your server)</li> | 44 | <li><a href="./?import&from=readability">{% trans "import from Readability" %}</a> (you must have a "readability" file on your server)</li> |
45 | </ul></p> | 45 | </ul></p> |
46 | 46 | ||
47 | <h2>{% trans "Export your poche datas" %}</h2> | 47 | <h2>{% trans "Export your poche datas" %}</h2> |
48 | <p><a href="?view=export" target="_blank">{% trans "Click here" %}</a> {% trans "to export your poche datas." %}</p> | 48 | <p><a href="./?export" target="_blank">{% trans "Click here" %}</a> {% trans "to export your poche datas." %}</p> |
49 | </div> | 49 | </div> |
50 | {% endblock %} \ No newline at end of file | 50 | {% endblock %} \ No newline at end of file |
diff --git a/tpl/export.twig b/tpl/export.twig index d22d05fc..4adb9540 100644 --- a/tpl/export.twig +++ b/tpl/export.twig | |||
@@ -1 +1 @@ | |||
export {$export} \ No newline at end of file | {{ export }} \ No newline at end of file | ||
diff --git a/tpl/js/poche.js b/tpl/js/poche.js index 97d9911d..b4eac11c 100644 --- a/tpl/js/poche.js +++ b/tpl/js/poche.js | |||
@@ -23,7 +23,7 @@ function toggle_archive(element, id, view_article) { | |||
23 | } | 23 | } |
24 | 24 | ||
25 | function sort_links(view, sort) { | 25 | function sort_links(view, sort) { |
26 | $.get('index.php', { view: view, sort: sort, full_head: 'no' }, function(data) { | 26 | $.get('index.php', { view: view, sort: sort }, function(data) { |
27 | $('#content').html(data); | 27 | $('#content').html(data); |
28 | }); | 28 | }); |
29 | } | 29 | } |
diff --git a/tpl/login.twig b/tpl/login.twig index 70c2190c..c3028795 100644 --- a/tpl/login.twig +++ b/tpl/login.twig | |||
@@ -16,9 +16,9 @@ | |||
16 | <input class="col" type="password" id="password" name="password" placeholder="Password" tabindex="2" {% if demo == 1 %}value="poche"{% endif %} /> | 16 | <input class="col" type="password" id="password" name="password" placeholder="Password" tabindex="2" {% if demo == 1 %}value="poche"{% endif %} /> |
17 | </div> | 17 | </div> |
18 | <div class="row"> | 18 | <div class="row"> |
19 | <label class="col w150p">{% trans "Stay signed in" %}</label> | 19 | <label class="col w150p" for="longlastingsession">{% trans "Stay signed in" %}</label> |
20 | <div class="col"> | 20 | <div class="col"> |
21 | <input type="checkbox" name="longlastingsession" tabindex="3"> | 21 | <input type="checkbox" id="longlastingsession" name="longlastingsession" tabindex="3"> |
22 | <small class="inbl">{% trans "(Do not check on public computers)" %}</small> | 22 | <small class="inbl">{% trans "(Do not check on public computers)" %}</small> |
23 | </div> | 23 | </div> |
24 | </div> | 24 | </div> |