diff options
author | Nicolas LÅ“uillet <nicolas.loeuillet@gmail.com> | 2013-08-24 22:42:37 -0700 |
---|---|---|
committer | Nicolas LÅ“uillet <nicolas.loeuillet@gmail.com> | 2013-08-24 22:42:37 -0700 |
commit | 217bacc66371f41a58cca924bec575102491db35 (patch) | |
tree | 6b95c7e88f77d015f1d2c9c098898420d9f96fc6 /inc/poche/Poche.class.php | |
parent | 83954e711d7f79173db00ad7160f6d1d6a3a9c5d (diff) | |
parent | db4767e22b9c130bdfe7102383d0f42a2eece490 (diff) | |
download | wallabag-217bacc66371f41a58cca924bec575102491db35.tar.gz wallabag-217bacc66371f41a58cca924bec575102491db35.tar.zst wallabag-217bacc66371f41a58cca924bec575102491db35.zip |
Merge pull request #173 from EliasZ/dev
Graceful error-handling with imports and defining where import files are stored
Diffstat (limited to 'inc/poche/Poche.class.php')
-rw-r--r-- | inc/poche/Poche.class.php | 43 |
1 files changed, 31 insertions, 12 deletions
diff --git a/inc/poche/Poche.class.php b/inc/poche/Poche.class.php index 4832f816..cb338766 100644 --- a/inc/poche/Poche.class.php +++ b/inc/poche/Poche.class.php | |||
@@ -364,13 +364,14 @@ class Poche | |||
364 | /** | 364 | /** |
365 | * import from Instapaper. poche needs a ./instapaper-export.html file | 365 | * import from Instapaper. poche needs a ./instapaper-export.html file |
366 | * @todo add the return value | 366 | * @todo add the return value |
367 | * @param string $targetFile the file used for importing | ||
367 | * @return boolean | 368 | * @return boolean |
368 | */ | 369 | */ |
369 | private function importFromInstapaper() | 370 | private function importFromInstapaper($targetFile) |
370 | { | 371 | { |
371 | # TODO gestion des articles favs | 372 | # TODO gestion des articles favs |
372 | $html = new simple_html_dom(); | 373 | $html = new simple_html_dom(); |
373 | $html->load_file('./instapaper-export.html'); | 374 | $html->load_file($targetFile); |
374 | Tools::logm('starting import from instapaper'); | 375 | Tools::logm('starting import from instapaper'); |
375 | 376 | ||
376 | $read = 0; | 377 | $read = 0; |
@@ -403,13 +404,14 @@ class Poche | |||
403 | /** | 404 | /** |
404 | * import from Pocket. poche needs a ./ril_export.html file | 405 | * import from Pocket. poche needs a ./ril_export.html file |
405 | * @todo add the return value | 406 | * @todo add the return value |
407 | * @param string $targetFile the file used for importing | ||
406 | * @return boolean | 408 | * @return boolean |
407 | */ | 409 | */ |
408 | private function importFromPocket() | 410 | private function importFromPocket($targetFile) |
409 | { | 411 | { |
410 | # TODO gestion des articles favs | 412 | # TODO gestion des articles favs |
411 | $html = new simple_html_dom(); | 413 | $html = new simple_html_dom(); |
412 | $html->load_file('./ril_export.html'); | 414 | $html->load_file($targetFile); |
413 | Tools::logm('starting import from pocket'); | 415 | Tools::logm('starting import from pocket'); |
414 | 416 | ||
415 | $read = 0; | 417 | $read = 0; |
@@ -442,12 +444,13 @@ class Poche | |||
442 | /** | 444 | /** |
443 | * import from Readability. poche needs a ./readability file | 445 | * import from Readability. poche needs a ./readability file |
444 | * @todo add the return value | 446 | * @todo add the return value |
447 | * @param string $targetFile the file used for importing | ||
445 | * @return boolean | 448 | * @return boolean |
446 | */ | 449 | */ |
447 | private function importFromReadability() | 450 | private function importFromReadability($targetFile) |
448 | { | 451 | { |
449 | # TODO gestion des articles lus / favs | 452 | # TODO gestion des articles lus / favs |
450 | $str_data = file_get_contents("./readability"); | 453 | $str_data = file_get_contents($targetFile); |
451 | $data = json_decode($str_data,true); | 454 | $data = json_decode($str_data,true); |
452 | Tools::logm('starting import from Readability'); | 455 | Tools::logm('starting import from Readability'); |
453 | $count = 0; | 456 | $count = 0; |
@@ -499,15 +502,31 @@ class Poche | |||
499 | */ | 502 | */ |
500 | public function import($from) | 503 | public function import($from) |
501 | { | 504 | { |
502 | if ($from == 'pocket') { | 505 | $providers = array( |
503 | return $this->importFromPocket(); | 506 | 'pocket' => 'importFromPocket', |
507 | 'readability' => 'importFromReadability', | ||
508 | 'instapaper' => 'importFromInstapaper' | ||
509 | ); | ||
510 | |||
511 | if (! isset($providers[$from])) { | ||
512 | $this->messages->add('e', _('Unknown import provider.')); | ||
513 | Tools::redirect(); | ||
504 | } | 514 | } |
505 | else if ($from == 'readability') { | 515 | |
506 | return $this->importFromReadability(); | 516 | $targetDefinition = 'IMPORT_' . strtoupper($from) . '_FILE'; |
517 | $targetFile = constant($targetDefinition); | ||
518 | |||
519 | if (! defined($targetDefinition)) { | ||
520 | $this->messages->add('e', _('Incomplete inc/poche/define.inc.php file, please define "' . $targetDefinition . '".')); | ||
521 | Tools::redirect(); | ||
507 | } | 522 | } |
508 | else if ($from == 'instapaper') { | 523 | |
509 | return $this->importFromInstapaper(); | 524 | if (! file_exists($targetFile)) { |
525 | $this->messages->add('e', _('Could not find required "' . $targetFile . '" import file.')); | ||
526 | Tools::redirect(); | ||
510 | } | 527 | } |
528 | |||
529 | $this->$providers[$from]($targetFile); | ||
511 | } | 530 | } |
512 | 531 | ||
513 | /** | 532 | /** |