diff options
Diffstat (limited to 'inc/poche/Poche.class.php')
-rw-r--r-- | inc/poche/Poche.class.php | 83 |
1 files changed, 57 insertions, 26 deletions
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'); |