X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=inc%2Fpoche%2FPoche.class.php;h=cb338766fd0d9b6efbe79e58f7f97a5b78f11b15;hb=1cbd70639c5f97f6030d0df6624ca200dba86945;hp=e0dc0d201daa27532d7aee8c82cfdf00812874a8;hpb=9067b484ce8289eec6979cf6c8e3cbfb3bd5b10c;p=github%2Fwallabag%2Fwallabag.git diff --git a/inc/poche/Poche.class.php b/inc/poche/Poche.class.php index e0dc0d20..cb338766 100644 --- a/inc/poche/Poche.class.php +++ b/inc/poche/Poche.class.php @@ -47,16 +47,16 @@ class Poche die('You don\'t have write access on cache directory.'); } else if (file_exists('./install/update.php') && !DEBUG_POCHE) { - $msg = 'A poche update is needed. Please execute this update by clicking here. If you have already do the update, please delete /install folder.'; + $msg = '

setup

It\'s your first time here? Please copy /install/poche.sqlite in db folder. Then, delete install folder.
If you have already installed poche, an update is needed by clicking here.

'; $allIsGood = FALSE; } else if (file_exists('./install') && !DEBUG_POCHE) { - $msg = 'If you want to update your poche, you just have to delete /install folder.
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.'; + $msg = '

setup

If you want to update your poche, you just have to delete /install folder.
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.

'; $allIsGood = FALSE; } else if (STORAGE == 'sqlite' && !is_writable(STORAGE_SQLITE)) { Tools::logm('you don\'t have write access on sqlite file'); - $msg = 'You don\'t have write access on sqlite file.'; + $msg = '

error

You don\'t have write access on sqlite file.

'; $allIsGood = FALSE; } @@ -364,13 +364,14 @@ class Poche /** * import from Instapaper. poche needs a ./instapaper-export.html file * @todo add the return value + * @param string $targetFile the file used for importing * @return boolean */ - private function importFromInstapaper() + private function importFromInstapaper($targetFile) { # TODO gestion des articles favs $html = new simple_html_dom(); - $html->load_file('./instapaper-export.html'); + $html->load_file($targetFile); Tools::logm('starting import from instapaper'); $read = 0; @@ -403,13 +404,14 @@ class Poche /** * import from Pocket. poche needs a ./ril_export.html file * @todo add the return value + * @param string $targetFile the file used for importing * @return boolean */ - private function importFromPocket() + private function importFromPocket($targetFile) { # TODO gestion des articles favs $html = new simple_html_dom(); - $html->load_file('./ril_export.html'); + $html->load_file($targetFile); Tools::logm('starting import from pocket'); $read = 0; @@ -442,12 +444,13 @@ class Poche /** * import from Readability. poche needs a ./readability file * @todo add the return value + * @param string $targetFile the file used for importing * @return boolean */ - private function importFromReadability() + private function importFromReadability($targetFile) { # TODO gestion des articles lus / favs - $str_data = file_get_contents("./readability"); + $str_data = file_get_contents($targetFile); $data = json_decode($str_data,true); Tools::logm('starting import from Readability'); $count = 0; @@ -499,15 +502,31 @@ class Poche */ public function import($from) { - if ($from == 'pocket') { - return $this->importFromPocket(); + $providers = array( + 'pocket' => 'importFromPocket', + 'readability' => 'importFromReadability', + 'instapaper' => 'importFromInstapaper' + ); + + if (! isset($providers[$from])) { + $this->messages->add('e', _('Unknown import provider.')); + Tools::redirect(); } - else if ($from == 'readability') { - return $this->importFromReadability(); + + $targetDefinition = 'IMPORT_' . strtoupper($from) . '_FILE'; + $targetFile = constant($targetDefinition); + + if (! defined($targetDefinition)) { + $this->messages->add('e', _('Incomplete inc/poche/define.inc.php file, please define "' . $targetDefinition . '".')); + Tools::redirect(); } - else if ($from == 'instapaper') { - return $this->importFromInstapaper(); + + if (! file_exists($targetFile)) { + $this->messages->add('e', _('Could not find required "' . $targetFile . '" import file.')); + Tools::redirect(); } + + $this->$providers[$from]($targetFile); } /**