diff options
author | Nicolas LÅ“uillet <nicolas.loeuillet@gmail.com> | 2013-08-25 12:12:53 -0700 |
---|---|---|
committer | Nicolas LÅ“uillet <nicolas.loeuillet@gmail.com> | 2013-08-25 12:12:53 -0700 |
commit | c51be6b697da573cdcf0788eb8617130ce5517a4 (patch) | |
tree | 642eaf70afb134dee5f274c84bf15b8aab00c117 /inc/poche/Poche.class.php | |
parent | 7ba37bd91a43321196e6d867caf9e298e82c6d6c (diff) | |
parent | 063fc1a7baaf6f7e1fb08eced058962a6140a471 (diff) | |
download | wallabag-c51be6b697da573cdcf0788eb8617130ce5517a4.tar.gz wallabag-c51be6b697da573cdcf0788eb8617130ce5517a4.tar.zst wallabag-c51be6b697da573cdcf0788eb8617130ce5517a4.zip |
Merge pull request #181 from inthepoche/dev
beta4
Diffstat (limited to 'inc/poche/Poche.class.php')
-rw-r--r-- | inc/poche/Poche.class.php | 91 |
1 files changed, 52 insertions, 39 deletions
diff --git a/inc/poche/Poche.class.php b/inc/poche/Poche.class.php index e0dc0d20..646193f7 100644 --- a/inc/poche/Poche.class.php +++ b/inc/poche/Poche.class.php | |||
@@ -47,16 +47,16 @@ class Poche | |||
47 | die('You don\'t have write access on cache directory.'); | 47 | die('You don\'t have write access on cache directory.'); |
48 | } | 48 | } |
49 | else if (file_exists('./install/update.php') && !DEBUG_POCHE) { | 49 | else if (file_exists('./install/update.php') && !DEBUG_POCHE) { |
50 | $msg = 'A poche update is needed. Please execute this update <a href="install/update.php">by clicking here</a>. If you have already do the update, please delete /install folder.'; | 50 | $msg = '<h1>setup</h1><p><strong>It\'s your first time here?</strong> Please copy /install/poche.sqlite in db folder. Then, delete install folder.<br /><strong>If you have already installed poche</strong>, an update is needed <a href="install/update.php">by clicking here</a>.</p>'; |
51 | $allIsGood = FALSE; | 51 | $allIsGood = FALSE; |
52 | } | 52 | } |
53 | else if (file_exists('./install') && !DEBUG_POCHE) { | 53 | else if (file_exists('./install') && !DEBUG_POCHE) { |
54 | $msg = 'If you want to update your poche, you just have to delete /install folder. <br />To install your poche with sqlite, copy /install/poche.sqlite in /db and delete the folder /install. you have to delete the /install folder before using poche.'; | 54 | $msg = '<h1>setup</h1><p><strong>If you want to update your poche</strong>, you just have to delete /install folder. <br /><strong>To install your poche with sqlite</strong>, copy /install/poche.sqlite in /db and delete the folder /install. you have to delete the /install folder before using poche.</p>'; |
55 | $allIsGood = FALSE; | 55 | $allIsGood = FALSE; |
56 | } | 56 | } |
57 | else if (STORAGE == 'sqlite' && !is_writable(STORAGE_SQLITE)) { | 57 | else if (STORAGE == 'sqlite' && !is_writable(STORAGE_SQLITE)) { |
58 | Tools::logm('you don\'t have write access on sqlite file'); | 58 | Tools::logm('you don\'t have write access on sqlite file'); |
59 | $msg = 'You don\'t have write access on sqlite file.'; | 59 | $msg = '<h1>error</h1><p>You don\'t have write access on sqlite file.</p>'; |
60 | $allIsGood = FALSE; | 60 | $allIsGood = FALSE; |
61 | } | 61 | } |
62 | 62 | ||
@@ -156,36 +156,31 @@ class Poche | |||
156 | switch ($action) | 156 | switch ($action) |
157 | { | 157 | { |
158 | case 'add': | 158 | case 'add': |
159 | if($parametres_url = $url->fetchContent()) { | 159 | $content = $url->extract(); |
160 | if ($this->store->add($url->getUrl(), $parametres_url['title'], $parametres_url['content'], $this->user->getId())) { | 160 | |
161 | Tools::logm('add link ' . $url->getUrl()); | 161 | if ($this->store->add($url->getUrl(), $content['title'], $content['body'], $this->user->getId())) { |
162 | $sequence = ''; | 162 | Tools::logm('add link ' . $url->getUrl()); |
163 | if (STORAGE == 'postgres') { | 163 | $sequence = ''; |
164 | $sequence = 'entries_id_seq'; | 164 | if (STORAGE == 'postgres') { |
165 | } | 165 | $sequence = 'entries_id_seq'; |
166 | $last_id = $this->store->getLastId($sequence); | ||
167 | if (DOWNLOAD_PICTURES) { | ||
168 | $content = filtre_picture($parametres_url['content'], $url->getUrl(), $last_id); | ||
169 | Tools::logm('updating content article'); | ||
170 | $this->store->updateContent($last_id, $content, $this->user->getId()); | ||
171 | } | ||
172 | if (!$import) { | ||
173 | $this->messages->add('s', _('the link has been added successfully')); | ||
174 | } | ||
175 | } | 166 | } |
176 | else { | 167 | $last_id = $this->store->getLastId($sequence); |
177 | if (!$import) { | 168 | if (DOWNLOAD_PICTURES) { |
178 | $this->messages->add('e', _('error during insertion : the link wasn\'t added')); | 169 | $content = filtre_picture($parametres_url['body'], $url->getUrl(), $last_id); |
179 | Tools::logm('error during insertion : the link wasn\'t added ' . $url->getUrl()); | 170 | Tools::logm('updating content article'); |
180 | } | 171 | $this->store->updateContent($last_id, $content, $this->user->getId()); |
172 | } | ||
173 | if (!$import) { | ||
174 | $this->messages->add('s', _('the link has been added successfully')); | ||
181 | } | 175 | } |
182 | } | 176 | } |
183 | else { | 177 | else { |
184 | if (!$import) { | 178 | if (!$import) { |
185 | $this->messages->add('e', _('error during fetching content : the link wasn\'t added')); | 179 | $this->messages->add('e', _('error during insertion : the link wasn\'t added')); |
186 | Tools::logm('error during content fetch ' . $url->getUrl()); | 180 | Tools::logm('error during insertion : the link wasn\'t added ' . $url->getUrl()); |
187 | } | 181 | } |
188 | } | 182 | } |
183 | |||
189 | if (!$import) { | 184 | if (!$import) { |
190 | Tools::redirect(); | 185 | Tools::redirect(); |
191 | } | 186 | } |
@@ -220,7 +215,6 @@ class Poche | |||
220 | } | 215 | } |
221 | break; | 216 | break; |
222 | default: | 217 | default: |
223 | Tools::logm('action ' . $action . 'doesn\'t exist'); | ||
224 | break; | 218 | break; |
225 | } | 219 | } |
226 | } | 220 | } |
@@ -364,13 +358,14 @@ class Poche | |||
364 | /** | 358 | /** |
365 | * import from Instapaper. poche needs a ./instapaper-export.html file | 359 | * import from Instapaper. poche needs a ./instapaper-export.html file |
366 | * @todo add the return value | 360 | * @todo add the return value |
361 | * @param string $targetFile the file used for importing | ||
367 | * @return boolean | 362 | * @return boolean |
368 | */ | 363 | */ |
369 | private function importFromInstapaper() | 364 | private function importFromInstapaper($targetFile) |
370 | { | 365 | { |
371 | # TODO gestion des articles favs | 366 | # TODO gestion des articles favs |
372 | $html = new simple_html_dom(); | 367 | $html = new simple_html_dom(); |
373 | $html->load_file('./instapaper-export.html'); | 368 | $html->load_file($targetFile); |
374 | Tools::logm('starting import from instapaper'); | 369 | Tools::logm('starting import from instapaper'); |
375 | 370 | ||
376 | $read = 0; | 371 | $read = 0; |
@@ -403,13 +398,14 @@ class Poche | |||
403 | /** | 398 | /** |
404 | * import from Pocket. poche needs a ./ril_export.html file | 399 | * import from Pocket. poche needs a ./ril_export.html file |
405 | * @todo add the return value | 400 | * @todo add the return value |
401 | * @param string $targetFile the file used for importing | ||
406 | * @return boolean | 402 | * @return boolean |
407 | */ | 403 | */ |
408 | private function importFromPocket() | 404 | private function importFromPocket($targetFile) |
409 | { | 405 | { |
410 | # TODO gestion des articles favs | 406 | # TODO gestion des articles favs |
411 | $html = new simple_html_dom(); | 407 | $html = new simple_html_dom(); |
412 | $html->load_file('./ril_export.html'); | 408 | $html->load_file($targetFile); |
413 | Tools::logm('starting import from pocket'); | 409 | Tools::logm('starting import from pocket'); |
414 | 410 | ||
415 | $read = 0; | 411 | $read = 0; |
@@ -442,12 +438,13 @@ class Poche | |||
442 | /** | 438 | /** |
443 | * import from Readability. poche needs a ./readability file | 439 | * import from Readability. poche needs a ./readability file |
444 | * @todo add the return value | 440 | * @todo add the return value |
441 | * @param string $targetFile the file used for importing | ||
445 | * @return boolean | 442 | * @return boolean |
446 | */ | 443 | */ |
447 | private function importFromReadability() | 444 | private function importFromReadability($targetFile) |
448 | { | 445 | { |
449 | # TODO gestion des articles lus / favs | 446 | # TODO gestion des articles lus / favs |
450 | $str_data = file_get_contents("./readability"); | 447 | $str_data = file_get_contents($targetFile); |
451 | $data = json_decode($str_data,true); | 448 | $data = json_decode($str_data,true); |
452 | Tools::logm('starting import from Readability'); | 449 | Tools::logm('starting import from Readability'); |
453 | $count = 0; | 450 | $count = 0; |
@@ -499,15 +496,31 @@ class Poche | |||
499 | */ | 496 | */ |
500 | public function import($from) | 497 | public function import($from) |
501 | { | 498 | { |
502 | if ($from == 'pocket') { | 499 | $providers = array( |
503 | return $this->importFromPocket(); | 500 | 'pocket' => 'importFromPocket', |
501 | 'readability' => 'importFromReadability', | ||
502 | 'instapaper' => 'importFromInstapaper' | ||
503 | ); | ||
504 | |||
505 | if (! isset($providers[$from])) { | ||
506 | $this->messages->add('e', _('Unknown import provider.')); | ||
507 | Tools::redirect(); | ||
504 | } | 508 | } |
505 | else if ($from == 'readability') { | 509 | |
506 | return $this->importFromReadability(); | 510 | $targetDefinition = 'IMPORT_' . strtoupper($from) . '_FILE'; |
511 | $targetFile = constant($targetDefinition); | ||
512 | |||
513 | if (! defined($targetDefinition)) { | ||
514 | $this->messages->add('e', _('Incomplete inc/poche/define.inc.php file, please define "' . $targetDefinition . '".')); | ||
515 | Tools::redirect(); | ||
507 | } | 516 | } |
508 | else if ($from == 'instapaper') { | 517 | |
509 | return $this->importFromInstapaper(); | 518 | if (! file_exists($targetFile)) { |
519 | $this->messages->add('e', _('Could not find required "' . $targetFile . '" import file.')); | ||
520 | Tools::redirect(); | ||
510 | } | 521 | } |
522 | |||
523 | $this->$providers[$from]($targetFile); | ||
511 | } | 524 | } |
512 | 525 | ||
513 | /** | 526 | /** |