aboutsummaryrefslogtreecommitdiffhomepage
path: root/inc
diff options
context:
space:
mode:
Diffstat (limited to 'inc')
-rw-r--r--inc/poche/Poche.class.php43
-rw-r--r--inc/poche/define.inc.php6
2 files changed, 36 insertions, 13 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 /**
diff --git a/inc/poche/define.inc.php b/inc/poche/define.inc.php
index 2154ce88..2d0a39ec 100644
--- a/inc/poche/define.inc.php
+++ b/inc/poche/define.inc.php
@@ -29,4 +29,8 @@ define ('TPL', __DIR__ . '/../../tpl');
29define ('LOCALE', __DIR__ . '/../../locale'); 29define ('LOCALE', __DIR__ . '/../../locale');
30define ('CACHE', __DIR__ . '/../../cache'); 30define ('CACHE', __DIR__ . '/../../cache');
31define ('PAGINATION', '10'); 31define ('PAGINATION', '10');
32define ('THEME', 'light'); \ No newline at end of file 32define ('THEME', 'light');
33
34define ('IMPORT_POCKET_FILE', './ril_export.html');
35define ('IMPORT_READABILITY_FILE', './readability');
36define ('IMPORT_INSTAPAPER_FILE', './instapaper-export.html'); \ No newline at end of file