aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorNicolas Lœuillet <nicolas.loeuillet@gmail.com>2013-08-04 21:42:46 +0200
committerNicolas Lœuillet <nicolas.loeuillet@gmail.com>2013-08-04 21:42:46 +0200
commitc765c3679fee3ed9e4bad9954a808116187a7e83 (patch)
treee18a69e8dc7d651f464c531e64773212017a22c8
parenteb1af592194e225bf887e4893e697f0ab8dd9a26 (diff)
downloadwallabag-c765c3679fee3ed9e4bad9954a808116187a7e83.tar.gz
wallabag-c765c3679fee3ed9e4bad9954a808116187a7e83.tar.zst
wallabag-c765c3679fee3ed9e4bad9954a808116187a7e83.zip
import in poche and not in an external file
-rw-r--r--import.php73
-rw-r--r--inc/poche/Poche.class.php108
-rw-r--r--inc/poche/config.inc.php1
-rw-r--r--index.php49
-rw-r--r--tpl/config.twig11
-rw-r--r--tpl/export.twig (renamed from tpl/export.html)0
-rw-r--r--tpl/home.twig9
-rw-r--r--tpl/layout.twig1
-rw-r--r--tpl/login.twig9
9 files changed, 125 insertions, 136 deletions
diff --git a/import.php b/import.php
deleted file mode 100644
index 45fe8334..00000000
--- a/import.php
+++ /dev/null
@@ -1,73 +0,0 @@
1<?php
2/**
3 * poche, a read it later open source system
4 *
5 * @category poche
6 * @author Nicolas Lœuillet <support@inthepoche.com>
7 * @copyright 2013
8 * @license http://www.wtfpl.net/ see COPYING file
9 */
10
11set_time_limit(0);
12
13include dirname(__FILE__).'/inc/config.php';
14include dirname(__FILE__).'/inc/simple_html_dom.php';
15
16if (!isset($_GET['start'])) {
17 echo _('Please execute the import script locally, it can take a very long time.') . '<br /><br />' . _('Please choose between Pocket & Readabilty :') . '<br /><a href="import.php?start=pocket">' . _('Bye bye Pocket, let\'s go !') . '</a><br /><a href="import.php?start=readability">' . _('Bye bye Readability, let\'s go !') . '</a>';
18}
19else {
20 if ($_GET['start'] == 'pocket') {
21 $html = new simple_html_dom();
22 $html->load_file('ril_export.html');
23
24 $read = 0;
25 $errors = array();
26 foreach($html->find('ul') as $ul)
27 {
28 foreach($ul->find('li') as $li)
29 {
30 $a = $li->find('a');
31 $url = $a[0]->href;
32
33 action_to_do('add', $url);
34 if ($read == '1') {
35 $last_id = $db->getHandle()->lastInsertId();
36 $sql_update = "UPDATE entries SET is_read=~is_read WHERE id=?";
37 $params_update = array($last_id);
38 $query_update = $db->getHandle()->prepare($sql_update);
39 $query_update->execute($params_update);
40 }
41 }
42 # Pocket génère un fichier HTML avec deux <ul>
43 # Le premier concerne les éléments non lus
44 # Le second concerne les éléments archivés
45 $read = 1;
46 }
47
48 echo _('Import from Pocket completed.') . '<a href="index.php">' . _('Welcome to poche !') .'</a>';
49 logm('import from pocket completed');
50 }
51 else if ($_GET['start'] == 'readability') {
52 $str_data = file_get_contents("readability");
53 $data = json_decode($str_data,true);
54
55 foreach ($data as $key => $value) {
56 $url = '';
57 foreach ($value as $key2 => $value2) {
58 if ($key2 == 'article__url') {
59 $url = $value2;
60 }
61 }
62 if ($url != '')
63 action_to_do('add', $url);
64 }
65
66 echo _('Import from Readability completed.') . '<a href="index.php">' . _('Welcome to poche !') . '</a>';
67 logm('import from Readability completed');
68 }
69 else {
70 echo _('Error with the import.') . '<a href="index.php">' . _('Back to poche'). '</a>';
71 logm('error with the import');
72 }
73} \ No newline at end of file
diff --git a/inc/poche/Poche.class.php b/inc/poche/Poche.class.php
index 973ae3e2..9e407d41 100644
--- a/inc/poche/Poche.class.php
+++ b/inc/poche/Poche.class.php
@@ -73,7 +73,7 @@ class Poche
73 /** 73 /**
74 * Call action (mark as fav, archive, delete, etc.) 74 * Call action (mark as fav, archive, delete, etc.)
75 */ 75 */
76 public function action($action, Url $url, $id) 76 public function action($action, Url $url, $id = 0)
77 { 77 {
78 switch ($action) 78 switch ($action)
79 { 79 {
@@ -118,6 +118,8 @@ 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;
121 default: 123 default:
122 break; 124 break;
123 } 125 }
@@ -173,4 +175,108 @@ class Poche
173 175
174 return $tpl_vars; 176 return $tpl_vars;
175 } 177 }
178
179 public function updatePassword()
180 {
181 if (isset($_POST['password']) && isset($_POST['password_repeat'])) {
182 if ($_POST['password'] == $_POST['password_repeat'] && $_POST['password'] != "") {
183 if (!MODE_DEMO) {
184 Tools::logm('password updated');
185 $this->store->updatePassword(Tools::encodeString($_POST['password'] . $_SESSION['login']));
186 Session::logout();
187 Tools::redirect();
188 }
189 else {
190 Tools::logm('in demo mode, you can\'t do this');
191 }
192 }
193 }
194 }
195
196 public function login($referer)
197 {
198 if (!empty($_POST['login']) && !empty($_POST['password'])) {
199 if (Session::login($_SESSION['login'], $_SESSION['pass'], $_POST['login'], Tools::encodeString($_POST['password'] . $_POST['login']))) {
200 Tools::logm('login successful');
201
202 if (!empty($_POST['longlastingsession'])) {
203 $_SESSION['longlastingsession'] = 31536000;
204 $_SESSION['expires_on'] = time() + $_SESSION['longlastingsession'];
205 session_set_cookie_params($_SESSION['longlastingsession']);
206 } else {
207 session_set_cookie_params(0);
208 }
209 session_regenerate_id(true);
210 Tools::redirect($referer);
211 }
212 Tools::logm('login failed');
213 Tools::redirect();
214 } else {
215 Tools::logm('login failed');
216 Tools::redirect();
217 }
218 }
219
220 public function logout()
221 {
222 Tools::logm('logout');
223 Session::logout();
224 Tools::redirect();
225 }
226
227 public function import($from)
228 {
229 if ($from == 'pocket') {
230 $html = new simple_html_dom();
231 $html->load_file('./ril_export.html');
232
233 $read = 0;
234 $errors = array();
235 foreach($html->find('ul') as $ul)
236 {
237 foreach($ul->find('li') as $li)
238 {
239 $a = $li->find('a');
240 $url = new Url($a[0]->href);
241 $this->action('add', $url);
242 if ($read == '1') {
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 }
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 }
255 logm('import from pocket completed');
256 Tools::redirect();
257 }
258 else if ($from == 'readability') {
259 # TODO finaliser tout ça ici
260 $str_data = file_get_contents("readability");
261 $data = json_decode($str_data,true);
262
263 foreach ($data as $key => $value) {
264 $url = '';
265 foreach ($value as $key2 => $value2) {
266 if ($key2 == 'article__url') {
267 $url = new Url($value2);
268 }
269 }
270 if ($url != '')
271 action_to_do('add', $url);
272 }
273 logm('import from Readability completed');
274 Tools::redirect();
275 }
276 }
277
278 public function export()
279 {
280
281 }
176} \ No newline at end of file 282} \ No newline at end of file
diff --git a/inc/poche/config.inc.php b/inc/poche/config.inc.php
index 81297e0c..98a9ee6b 100644
--- a/inc/poche/config.inc.php
+++ b/inc/poche/config.inc.php
@@ -32,6 +32,7 @@ require_once './inc/3rdparty/Session.class.php';
32require_once './inc/store/store.class.php'; 32require_once './inc/store/store.class.php';
33require_once './inc/store/' . $storage_type . '.class.php'; 33require_once './inc/store/' . $storage_type . '.class.php';
34require_once './vendor/autoload.php'; 34require_once './vendor/autoload.php';
35require_once './inc/3rdparty/simple_html_dom.php';
35 36
36if (DOWNLOAD_PICTURES) { 37if (DOWNLOAD_PICTURES) {
37 require_once './inc/poche/pochePicture.php'; 38 require_once './inc/poche/pochePicture.php';
diff --git a/index.php b/index.php
index 40779698..1554c0a6 100644
--- a/index.php
+++ b/index.php
@@ -10,8 +10,6 @@
10 10
11include dirname(__FILE__).'/inc/poche/config.inc.php'; 11include dirname(__FILE__).'/inc/poche/config.inc.php';
12 12
13$notices = array();
14
15# XSRF protection with token 13# XSRF protection with token
16// if (!empty($_POST)) { 14// if (!empty($_POST)) {
17// if (!Session::isToken($_POST['token'])) { 15// if (!Session::isToken($_POST['token'])) {
@@ -25,50 +23,18 @@ $referer = empty($_SERVER['HTTP_REFERER']) ? '' : $_SERVER['HTTP_REFERER'];
25 23
26if (isset($_GET['login'])) { 24if (isset($_GET['login'])) {
27 # hello you 25 # hello you
28 if (!empty($_POST['login']) && !empty($_POST['password'])) { 26 $poche->login($referer);
29 if (Session::login($_SESSION['login'], $_SESSION['pass'], $_POST['login'], Tools::encodeString($_POST['password'] . $_POST['login']))) {
30 Tools::logm('login successful');
31 $notices['value'] = _('login successful');
32
33 if (!empty($_POST['longlastingsession'])) {
34 $_SESSION['longlastingsession'] = 31536000;
35 $_SESSION['expires_on'] = time() + $_SESSION['longlastingsession'];
36 session_set_cookie_params($_SESSION['longlastingsession']);
37 } else {
38 session_set_cookie_params(0);
39 }
40 session_regenerate_id(true);
41 Tools::redirect($referer);
42 }
43 Tools::logm('login failed');
44 $notices['value'] = _('Login failed !');
45 Tools::redirect();
46 } else {
47 Tools::logm('login failed');
48 Tools::redirect();
49 }
50} 27}
51elseif (isset($_GET['logout'])) { 28elseif (isset($_GET['logout'])) {
52 # see you soon ! 29 # see you soon !
53 Tools::logm('logout'); 30 $poche->logout();
54 Session::logout();
55 Tools::redirect();
56} 31}
57elseif (isset($_GET['config'])) { 32elseif (isset($_GET['config'])) {
58 # Update password 33 # Update password
59 if (isset($_POST['password']) && isset($_POST['password_repeat'])) { 34 $poche->updatePassword();
60 if ($_POST['password'] == $_POST['password_repeat'] && $_POST['password'] != "") { 35}
61 if (!MODE_DEMO) { 36elseif (isset($_GET['import'])) {
62 Tools::logm('password updated'); 37 $poche->import($_GET['from']);
63 $poche->store->updatePassword(Tools::encodeString($_POST['password'] . $_SESSION['login']));
64 Session::logout();
65 Tools::redirect();
66 }
67 else {
68 Tools::logm('in demo mode, you can\'t do this');
69 }
70 }
71 }
72} 38}
73 39
74# Aaaaaaand action ! 40# Aaaaaaand action !
@@ -87,7 +53,6 @@ $tpl_vars = array(
87 'demo' => MODE_DEMO, 53 'demo' => MODE_DEMO,
88 'title' => _('poche, a read it later open source system'), 54 'title' => _('poche, a read it later open source system'),
89 'token' => Session::getToken(), 55 'token' => Session::getToken(),
90 'notices' => $notices,
91); 56);
92 57
93if (Session::isLogged()) { 58if (Session::isLogged()) {
diff --git a/tpl/config.twig b/tpl/config.twig
index 4e7bb9d4..9a51e566 100644
--- a/tpl/config.twig
+++ b/tpl/config.twig
@@ -13,7 +13,7 @@
13{% block content %} 13{% block content %}
14 <div id="content"> 14 <div id="content">
15 <h2>{% trans "Bookmarklet" %}</h2> 15 <h2>{% trans "Bookmarklet" %}</h2>
16 <p>{% trans "Thanks to the bookmarklet, you will be able to easily add a link to your poche." %} {% trans "Have a look to this documentation:" %} <a href="http://inthepoche.com/?pages/Documentation" target="_blank">http://inthepoche.com/?pages/Documentation</a>.</p> 16 <p>{% trans "Thanks to the bookmarklet, you will be able to easily add a link to your poche." %} {% trans "Have a look to this documentation:" %} <a href="http://inthepoche.com/?pages/Documentation">inthepoche.com</a>.</p>
17 <p>{% trans "Drag & drop this link to your bookmarks bar and have fun with poche." %}</p> 17 <p>{% trans "Drag & drop this link to your bookmarks bar and have fun with poche." %}</p>
18 <p><a ondragend="this.click();" style="cursor: move; border: 1px dashed grey; background: white;" title="i am a bookmarklet, use me !" href="javascript:if(top['bookmarklet-url@inthepoche.com']){top['bookmarklet-url@inthepoche.com'];}else{(function(){var%20url%20=%20location.href%20||%20url;window.open('{{ poche_url }}?action=add&url='%20+%20btoa(url),'_self');})();void(0);}">{% trans "poche it!" %}</a></p> 18 <p><a ondragend="this.click();" style="cursor: move; border: 1px dashed grey; background: white;" title="i am a bookmarklet, use me !" href="javascript:if(top['bookmarklet-url@inthepoche.com']){top['bookmarklet-url@inthepoche.com'];}else{(function(){var%20url%20=%20location.href%20||%20url;window.open('{{ poche_url }}?action=add&url='%20+%20btoa(url),'_self');})();void(0);}">{% trans "poche it!" %}</a></p>
19 19
@@ -35,6 +35,15 @@
35 <input type="hidden" name="returnurl" value="{{ referer }}"> 35 <input type="hidden" name="returnurl" value="{{ referer }}">
36 <input type="hidden" name="token" value="{{ token }}"> 36 <input type="hidden" name="token" value="{{ token }}">
37 </form> 37 </form>
38
39 <h2>{% trans "Import" %}</h2>
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>
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>
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>
46
38 <h2>{% trans "Export your poche datas" %}</h2> 47 <h2>{% trans "Export your poche datas" %}</h2>
39 <p><a href="?view=export" target="_blank">{% trans "Click here" %}</a> {% trans "to export your poche datas." %}</p> 48 <p><a href="?view=export" target="_blank">{% trans "Click here" %}</a> {% trans "to export your poche datas." %}</p>
40 </div> 49 </div>
diff --git a/tpl/export.html b/tpl/export.twig
index d22d05fc..d22d05fc 100644
--- a/tpl/export.html
+++ b/tpl/export.twig
diff --git a/tpl/home.twig b/tpl/home.twig
index 5752b2cf..49ef9050 100644
--- a/tpl/home.twig
+++ b/tpl/home.twig
@@ -15,15 +15,6 @@
15 <li><img src="./tpl/img/up.png" onclick="sort_links('{{ view }}', 'ta');" title="{% trans "by title asc" %}" /> {% trans "by title" %} <img src="./tpl/img/down.png" onclick="sort_links('{{ view }}', 'td');" title="{% trans "by title desc" %}" /></li> 15 <li><img src="./tpl/img/up.png" onclick="sort_links('{{ view }}', 'ta');" title="{% trans "by title asc" %}" /> {% trans "by title" %} <img src="./tpl/img/down.png" onclick="sort_links('{{ view }}', 'td');" title="{% trans "by title desc" %}" /></li>
16 </ul> 16 </ul>
17{% endblock %} 17{% endblock %}
18{% block notices %}
19 <div class="messages">
20 <ul>
21 {% for notice in notices %}
22 <li>{{ notice.value|e }}</li>
23 {% endfor %}
24 </ul>
25 </div>
26{% endblock %}
27{% block content %} 18{% block content %}
28 <div id="content"> 19 <div id="content">
29 {% for entry in entries %} 20 {% for entry in entries %}
diff --git a/tpl/layout.twig b/tpl/layout.twig
index 9dc83efe..cbe965fd 100644
--- a/tpl/layout.twig
+++ b/tpl/layout.twig
@@ -17,7 +17,6 @@
17 <div id="main"> 17 <div id="main">
18 {% block menu %}{% endblock %} 18 {% block menu %}{% endblock %}
19 {% block precontent %}{% endblock %} 19 {% block precontent %}{% endblock %}
20 {% block messages %}{% endblock %}
21 {% block content %}{% endblock %} 20 {% block content %}{% endblock %}
22 {% block js %}{% endblock %} 21 {% block js %}{% endblock %}
23 </div> 22 </div>
diff --git a/tpl/login.twig b/tpl/login.twig
index fcb9b4d6..70c2190c 100644
--- a/tpl/login.twig
+++ b/tpl/login.twig
@@ -1,15 +1,6 @@
1{% extends "layout.twig" %} 1{% extends "layout.twig" %}
2 2
3{% block title %}{% trans "login to your poche" %}{% endblock %} 3{% block title %}{% trans "login to your poche" %}{% endblock %}
4{% block notices %}
5 <div class="messages">
6 <ul>
7 {% for notice in notices %}
8 <li>{{ notice.value|e }}</li>
9 {% endfor %}
10 </ul>
11 </div>
12{% endblock %}
13{% block content %} 4{% block content %}
14 <form method="post" action="?login" name="loginform"> 5 <form method="post" action="?login" name="loginform">
15 <fieldset class="w500p center"> 6 <fieldset class="w500p center">