aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--inc/poche/Database.class.php31
-rw-r--r--inc/poche/Poche.class.php83
-rw-r--r--inc/poche/config.inc.php3
-rwxr-xr-xinstall/poche.sqlite (renamed from install/poche.sqlite.in)bin294912 -> 294912 bytes
-rw-r--r--install/update_sqlite_from_0_to_1.php2
-rw-r--r--tpl/_footer.twig2
6 files changed, 83 insertions, 38 deletions
diff --git a/inc/poche/Database.class.php b/inc/poche/Database.class.php
index 8da7a994..cd5a9a31 100644
--- a/inc/poche/Database.class.php
+++ b/inc/poche/Database.class.php
@@ -37,19 +37,34 @@ class Database {
37 } 37 }
38 38
39 public function isInstalled() { 39 public function isInstalled() {
40 $sql = "SELECT username FROM users WHERE id=?"; 40 $sql = "SELECT username FROM users";
41 $query = $this->executeQuery($sql, array('1')); 41 $query = $this->executeQuery($sql, array());
42 $hasAdmin = $query->fetchAll(); 42 $hasAdmin = count($query->fetchAll());
43 43
44 if (count($hasAdmin) == 0) 44 if ($hasAdmin == 0)
45 return FALSE; 45 return FALSE;
46 46
47 return TRUE; 47 return TRUE;
48 } 48 }
49 49
50 public function install($login, $password) { 50 public function install($login, $password) {
51 $sql = 'INSERT INTO users ( username, password ) VALUES (?, ?)'; 51 $sql = 'INSERT INTO users ( username, password, name, email) VALUES (?, ?, ?, ?)';
52 $params = array($login, $password); 52 $params = array($login, $password, $login, ' ');
53 $query = $this->executeQuery($sql, $params);
54
55 $sequence = '';
56 if (STORAGE == 'postgres') {
57 $sequence = 'users_id_seq';
58 }
59
60 $id_user = intval($this->getLastId($sequence));
61
62 $sql = 'INSERT INTO users_config ( user_id, name, value ) VALUES (?, ?, ?)';
63 $params = array($id_user, 'pager', '10');
64 $query = $this->executeQuery($sql, $params);
65
66 $sql = 'INSERT INTO users_config ( user_id, name, value ) VALUES (?, ?, ?)';
67 $params = array($id_user, 'language', 'en_EN.UTF8');
53 $query = $this->executeQuery($sql, $params); 68 $query = $this->executeQuery($sql, $params);
54 69
55 return TRUE; 70 return TRUE;
@@ -195,7 +210,7 @@ class Database {
195 $query = $this->executeQuery($sql_action, $params_action); 210 $query = $this->executeQuery($sql_action, $params_action);
196 } 211 }
197 212
198 public function getLastId() { 213 public function getLastId($column = '') {
199 return $this->getHandle()->lastInsertId(); 214 return $this->getHandle()->lastInsertId($column);
200 } 215 }
201} 216}
diff --git a/inc/poche/Poche.class.php b/inc/poche/Poche.class.php
index 0a43df71..38b4a98e 100644
--- a/inc/poche/Poche.class.php
+++ b/inc/poche/Poche.class.php
@@ -34,7 +34,7 @@ class Poche
34 Tools::initPhp(); 34 Tools::initPhp();
35 Session::init(); 35 Session::init();
36 36
37 if (isset($_SESSION['poche_user'])) { 37 if (isset($_SESSION['poche_user']) && $_SESSION['poche_user'] != array()) {
38 $this->user = $_SESSION['poche_user']; 38 $this->user = $_SESSION['poche_user'];
39 } 39 }
40 else { 40 else {
@@ -102,7 +102,7 @@ class Poche
102 /** 102 /**
103 * Call action (mark as fav, archive, delete, etc.) 103 * Call action (mark as fav, archive, delete, etc.)
104 */ 104 */
105 public function action($action, Url $url, $id = 0) 105 public function action($action, Url $url, $id = 0, $import = FALSE)
106 { 106 {
107 switch ($action) 107 switch ($action)
108 { 108 {
@@ -110,22 +110,34 @@ class Poche
110 if($parametres_url = $url->fetchContent()) { 110 if($parametres_url = $url->fetchContent()) {
111 if ($this->store->add($url->getUrl(), $parametres_url['title'], $parametres_url['content'], $this->user->getId())) { 111 if ($this->store->add($url->getUrl(), $parametres_url['title'], $parametres_url['content'], $this->user->getId())) {
112 Tools::logm('add link ' . $url->getUrl()); 112 Tools::logm('add link ' . $url->getUrl());
113 $last_id = $this->store->getLastId(); 113 $sequence = '';
114 if (STORAGE == 'postgres') {
115 $sequence = 'entries_id_seq';
116 }
117 $last_id = $this->store->getLastId($sequence);
114 if (DOWNLOAD_PICTURES) { 118 if (DOWNLOAD_PICTURES) {
115 $content = filtre_picture($parametres_url['content'], $url->getUrl(), $last_id); 119 $content = filtre_picture($parametres_url['content'], $url->getUrl(), $last_id);
116 } 120 }
117 $this->messages->add('s', _('the link has been added successfully')); 121 if (!$import) {
122 $this->messages->add('s', _('the link has been added successfully'));
123 }
118 } 124 }
119 else { 125 else {
120 $this->messages->add('e', _('error during insertion : the link wasn\'t added')); 126 if (!$import) {
121 Tools::logm('error during insertion : the link wasn\'t added'); 127 $this->messages->add('e', _('error during insertion : the link wasn\'t added'));
128 Tools::logm('error during insertion : the link wasn\'t added ' . $url->getUrl());
129 }
122 } 130 }
123 } 131 }
124 else { 132 else {
125 $this->messages->add('e', _('error during fetching content : the link wasn\'t added')); 133 if (!$import) {
126 Tools::logm('error during content fetch'); 134 $this->messages->add('e', _('error during fetching content : the link wasn\'t added'));
135 Tools::logm('error during content fetch ' . $url->getUrl());
136 }
137 }
138 if (!$import) {
139 Tools::redirect();
127 } 140 }
128 Tools::redirect();
129 break; 141 break;
130 case 'delete': 142 case 'delete':
131 $msg = 'delete link #' . $id; 143 $msg = 'delete link #' . $id;
@@ -145,12 +157,16 @@ class Poche
145 case 'toggle_fav' : 157 case 'toggle_fav' :
146 $this->store->favoriteById($id, $this->user->getId()); 158 $this->store->favoriteById($id, $this->user->getId());
147 Tools::logm('mark as favorite link #' . $id); 159 Tools::logm('mark as favorite link #' . $id);
148 Tools::redirect(); 160 if (!$import) {
161 Tools::redirect();
162 }
149 break; 163 break;
150 case 'toggle_archive' : 164 case 'toggle_archive' :
151 $this->store->archiveById($id, $this->user->getId()); 165 $this->store->archiveById($id, $this->user->getId());
152 Tools::logm('archive link #' . $id); 166 Tools::logm('archive link #' . $id);
153 Tools::redirect(); 167 if (!$import) {
168 Tools::redirect();
169 }
154 break; 170 break;
155 default: 171 default:
156 break; 172 break;
@@ -267,10 +283,10 @@ class Poche
267 283
268 public function logout() 284 public function logout()
269 { 285 {
270 $this->messages->add('s', _('see you soon!'));
271 Tools::logm('logout');
272 $this->user = array(); 286 $this->user = array();
273 Session::logout(); 287 Session::logout();
288 $this->messages->add('s', _('see you soon!'));
289 Tools::logm('logout');
274 Tools::redirect(); 290 Tools::redirect();
275 } 291 }
276 292
@@ -279,6 +295,7 @@ class Poche
279 # TODO gestion des articles favs 295 # TODO gestion des articles favs
280 $html = new simple_html_dom(); 296 $html = new simple_html_dom();
281 $html->load_file('./instapaper-export.html'); 297 $html->load_file('./instapaper-export.html');
298 Tools::logm('starting import from instapaper');
282 299
283 $read = 0; 300 $read = 0;
284 $errors = array(); 301 $errors = array();
@@ -288,10 +305,14 @@ class Poche
288 { 305 {
289 $a = $li->find('a'); 306 $a = $li->find('a');
290 $url = new Url(base64_encode($a[0]->href)); 307 $url = new Url(base64_encode($a[0]->href));
291 $this->action('add', $url); 308 $this->action('add', $url, 0, TRUE);
292 if ($read == '1') { 309 if ($read == '1') {
293 $last_id = $this->store->getLastId(); 310 $sequence = '';
294 $this->action('toggle_archive', $url, $last_id); 311 if (STORAGE == 'postgres') {
312 $sequence = 'entries_id_seq';
313 }
314 $last_id = $this->store->getLastId($sequence);
315 $this->action('toggle_archive', $url, $last_id, TRUE);
295 } 316 }
296 } 317 }
297 318
@@ -308,6 +329,7 @@ class Poche
308 # TODO gestion des articles favs 329 # TODO gestion des articles favs
309 $html = new simple_html_dom(); 330 $html = new simple_html_dom();
310 $html->load_file('./ril_export.html'); 331 $html->load_file('./ril_export.html');
332 Tools::logm('starting import from pocket');
311 333
312 $read = 0; 334 $read = 0;
313 $errors = array(); 335 $errors = array();
@@ -317,10 +339,14 @@ class Poche
317 { 339 {
318 $a = $li->find('a'); 340 $a = $li->find('a');
319 $url = new Url(base64_encode($a[0]->href)); 341 $url = new Url(base64_encode($a[0]->href));
320 $this->action('add', $url); 342 $this->action('add', $url, 0, TRUE);
321 if ($read == '1') { 343 if ($read == '1') {
322 $last_id = $this->store->getLastId(); 344 $sequence = '';
323 $this->action('toggle_archive', $url, $last_id); 345 if (STORAGE == 'postgres') {
346 $sequence = 'entries_id_seq';
347 }
348 $last_id = $this->store->getLastId($sequence);
349 $this->action('toggle_archive', $url, $last_id, TRUE);
324 } 350 }
325 } 351 }
326 352
@@ -337,6 +363,7 @@ class Poche
337 # TODO gestion des articles lus / favs 363 # TODO gestion des articles lus / favs
338 $str_data = file_get_contents("./readability"); 364 $str_data = file_get_contents("./readability");
339 $data = json_decode($str_data,true); 365 $data = json_decode($str_data,true);
366 Tools::logm('starting import from Readability');
340 367
341 foreach ($data as $key => $value) { 368 foreach ($data as $key => $value) {
342 $url = ''; 369 $url = '';
@@ -344,18 +371,22 @@ class Poche
344 if ($attr == 'article__url') { 371 if ($attr == 'article__url') {
345 $url = new Url(base64_encode($attr_value)); 372 $url = new Url(base64_encode($attr_value));
346 } 373 }
374 $sequence = '';
375 if (STORAGE == 'postgres') {
376 $sequence = 'entries_id_seq';
377 }
347 // if ($attr_value == 'favorite' && $attr_value == 'true') { 378 // if ($attr_value == 'favorite' && $attr_value == 'true') {
348 // $last_id = $this->store->getLastId(); 379 // $last_id = $this->store->getLastId($sequence);
349 // $this->store->favoriteById($last_id); 380 // $this->store->favoriteById($last_id);
350 // $this->action('toogle_fav', $url, $last_id); 381 // $this->action('toogle_fav', $url, $last_id, TRUE);
351 // }
352 // if ($attr_value == 'archive' && $attr_value == 'true') {
353 // $last_id = $this->store->getLastId();
354 // $this->action('toggle_archive', $url, $last_id);
355 // } 382 // }
383 if ($attr_value == 'archive' && $attr_value == 'true') {
384 $last_id = $this->store->getLastId($sequence);
385 $this->action('toggle_archive', $url, $last_id, TRUE);
386 }
356 } 387 }
357 if ($url->isCorrect()) 388 if ($url->isCorrect())
358 $this->action('add', $url); 389 $this->action('add', $url, 0, TRUE);
359 } 390 }
360 $this->messages->add('s', _('import from Readability completed')); 391 $this->messages->add('s', _('import from Readability completed'));
361 Tools::logm('import from Readability completed'); 392 Tools::logm('import from Readability completed');
diff --git a/inc/poche/config.inc.php b/inc/poche/config.inc.php
index ef2f699d..322f69d6 100644
--- a/inc/poche/config.inc.php
+++ b/inc/poche/config.inc.php
@@ -9,7 +9,7 @@
9 */ 9 */
10 10
11# storage 11# storage
12define ('STORAGE','postgres'); # postgres, mysql, sqlite 12define ('STORAGE','sqlite'); # postgres, mysql, sqlite
13define ('STORAGE_SERVER', 'localhost'); # leave blank for sqlite 13define ('STORAGE_SERVER', 'localhost'); # leave blank for sqlite
14define ('STORAGE_DB', 'poche'); # only for postgres & mysql 14define ('STORAGE_DB', 'poche'); # only for postgres & mysql
15define ('STORAGE_SQLITE', './db/poche.sqlite'); 15define ('STORAGE_SQLITE', './db/poche.sqlite');
@@ -52,7 +52,6 @@ if (DOWNLOAD_PICTURES) {
52} 52}
53 53
54$poche = new Poche(); 54$poche = new Poche();
55
56#XSRF protection with token 55#XSRF protection with token
57// if (!empty($_POST)) { 56// if (!empty($_POST)) {
58// if (!Session::isToken($_POST['token'])) { 57// if (!Session::isToken($_POST['token'])) {
diff --git a/install/poche.sqlite.in b/install/poche.sqlite
index 45add0d7..45add0d7 100755
--- a/install/poche.sqlite.in
+++ b/install/poche.sqlite
Binary files differ
diff --git a/install/update_sqlite_from_0_to_1.php b/install/update_sqlite_from_0_to_1.php
index 2ee65522..f3801eb1 100644
--- a/install/update_sqlite_from_0_to_1.php
+++ b/install/update_sqlite_from_0_to_1.php
@@ -11,7 +11,7 @@ $sql = 'ALTER TABLE entries RENAME TO tempEntries;';
11$query = $handle->prepare($sql); 11$query = $handle->prepare($sql);
12$query->execute(); 12$query->execute();
13 13
14$sql = 'CREATE TABLE entries (id INTEGER PRIMARY KEY, title TEXT, url TEXT, is_read NUMERIC, is_fav NUMERIC, content BLOB, user_id NUMERIC);'; 14$sql = 'CREATE TABLE entries (id INTEGER PRIMARY KEY, title TEXT, url TEXT, is_read NUMERIC DEFAULT 0, is_fav NUMERIC DEFAULT 0, content BLOB, user_id NUMERIC);';
15$query = $handle->prepare($sql); 15$query = $handle->prepare($sql);
16$query->execute(); 16$query->execute();
17 17
diff --git a/tpl/_footer.twig b/tpl/_footer.twig
index b74d9079..6891756a 100644
--- a/tpl/_footer.twig
+++ b/tpl/_footer.twig
@@ -1,4 +1,4 @@
1 <footer class="w600p center mt3 smaller txtright"> 1 <footer class="w600p center mt3 smaller txtright">
2 <p>{% trans "powered by" %} <a href="http://inthepoche.com">poche</a></p> 2 <p>{% trans "powered by" %} <a href="http://inthepoche.com">poche</a></p>
3 {% if constant('DEBUG_POCHE') == 1 %}<p><strong>{% trans "debug mode is on so cache is off." %} {% trans "your poche version:" %}{{constant('POCHE_VERSION')}}</strong></p>{% endif %} 3 {% if constant('DEBUG_POCHE') == 1 %}<p><strong>{% trans "debug mode is on so cache is off." %} {% trans "your poche version:" %}{{constant('POCHE_VERSION')}}. {% trans "storage:" %} {{constant('STORAGE')}}</strong></p>{% endif %}
4 </footer> \ No newline at end of file 4 </footer> \ No newline at end of file