]> git.immae.eu Git - github/wallabag/wallabag.git/commitdiff
[add] import from poche, thank you @tsadiq #388
authorNicolas Lœuillet <nicolas.loeuillet@gmail.com>
Tue, 7 Jan 2014 19:21:43 +0000 (20:21 +0100)
committerNicolas Lœuillet <nicolas.loeuillet@gmail.com>
Tue, 7 Jan 2014 19:21:43 +0000 (20:21 +0100)
inc/poche/Poche.class.php
inc/poche/config.inc.php.new
themes/default/config.twig

index 76a73be2b88e188500c3ad7affd11468e2a7dead..e033ad7491542cced45d01901175ce6b7d25cb78 100644 (file)
@@ -847,6 +847,52 @@ class Poche
         Tools::redirect();
     }
 
+    /**
+     * import from Poche exported file
+     * @param string $targetFile the file used for importing
+     * @return boolean 
+     */
+    private function importFromPoche($targetFile)
+    {
+        $str_data = file_get_contents($targetFile);
+        $data = json_decode($str_data,true);
+        Tools::logm('starting import from Poche');
+
+
+        $sequence = '';
+        if (STORAGE == 'postgres') {
+            $sequence = 'entries_id_seq';
+        }
+
+        $count = 0;
+        foreach ($data as $value) {
+
+            $url = new Url(base64_encode($value['url']));
+            $favorite = ($value['is_fav'] == -1);
+            $archive = ($value['is_read'] == -1);
+    
+            # we can add the url
+            if (!is_null($url) && $url->isCorrect()) {
+                
+                $this->action('add', $url, 0, TRUE);
+                
+                $count++;
+                if ($favorite) {
+                    $last_id = $this->store->getLastId($sequence);
+                    $this->action('toggle_fav', $url, $last_id, TRUE);
+                }
+                if ($archive) {
+                    $last_id = $this->store->getLastId($sequence);
+                    $this->action('toggle_archive', $url, $last_id, TRUE);
+                }
+            }
+            
+        }
+        $this->messages->add('s', _('import from Poche completed. ' . $count . ' new links.'));
+        Tools::logm('import from Poche completed');
+        Tools::redirect();
+    }
+
     /**
      * import datas into your poche
      * @param  string $from name of the service to import : pocket, instapaper or readability
@@ -858,7 +904,8 @@ class Poche
         $providers = array(
             'pocket' => 'importFromPocket',
             'readability' => 'importFromReadability',
-            'instapaper' => 'importFromInstapaper'
+            'instapaper' => 'importFromInstapaper',
+            'poche' => 'importFromPoche',
         );
         
         if (! isset($providers[$from])) {
index c60d4f80040f2872309345080aee40d75a7ed43c..1c93be07e113fd2a73cb722038ec61504babb361 100755 (executable)
@@ -55,7 +55,9 @@ define ('PAGINATION', '10');
 define ('POCKET_FILE', '/ril_export.html');
 define ('READABILITY_FILE', '/readability');
 define ('INSTAPAPER_FILE', '/instapaper-export.html');
+define ('POCHE_FILE', '/poche-export');
 
 define ('IMPORT_POCKET_FILE', ROOT . POCKET_FILE);
 define ('IMPORT_READABILITY_FILE', ROOT . READABILITY_FILE);
 define ('IMPORT_INSTAPAPER_FILE', ROOT . INSTAPAPER_FILE);
+define ('IMPORT_POCHE_FILE', ROOT . POCHE_FILE);
\ No newline at end of file
index 10df726e07f47cc8c38ca617e87e815dee5aaf07..ef615d39bb4fc8d645a8ef87c7dd0ace13090023 100644 (file)
             <p>{% trans "More info in the official docs:" %} <a href="http://doc.inthepoche.com/doku.php?id=users:migrate">inthepoche.com</a></p>
             <ul>
                 <li><a href="./?import&amp;from=pocket">{% trans "Import from Pocket" %}</a> {{ '(you must have a %s file on your server)'|trans|format(constant('POCKET_FILE')) }}</li>
-            <li><a href="./?import&amp;from=readability">{% trans "Import from Readability" %}</a> {{ '(you must have a %s file on your server)'|trans|format(constant('READABILITY_FILE')) }}</li>
-            <li><a href="./?import&amp;from=instapaper">{% trans "Import from Instapaper" %}</a> {{ '(you must have a %s file on your server)'|trans|format(constant('INSTAPAPER_FILE')) }}</li>
+                <li><a href="./?import&amp;from=readability">{% trans "Import from Readability" %}</a> {{ '(you must have a %s file on your server)'|trans|format(constant('READABILITY_FILE')) }}</li>
+                <li><a href="./?import&amp;from=instapaper">{% trans "Import from Instapaper" %}</a> {{ '(you must have a %s file on your server)'|trans|format(constant('INSTAPAPER_FILE')) }}</li>
+                <li><a href="./?import&amp;from=poche">{% trans "Import from poche" %}</a> {{ '(you must have a %s file on your server)'|trans|format(constant('POCHE_FILE')) }}</li>
             </ul>
 
             <h2>{% trans "Export your poche data" %}</h2>