]> git.immae.eu Git - github/wallabag/wallabag.git/blobdiff - inc/poche/Poche.class.php
poche is dead, welcome wallabag
[github/wallabag/wallabag.git] / inc / poche / Poche.class.php
index e9ff7b46ca0b59426e2fd29e9295cdc80d8d3262..4a5a954bfe6e6fdd917a40574974d73015ede13e 100644 (file)
@@ -1,9 +1,9 @@
 <?php
 /**
- * poche, a read it later open source system
+ * wallabag, self hostable application allowing you to not miss any content anymore
  *
- * @category   poche
- * @author     Nicolas LÅ“uillet <support@inthepoche.com>
+ * @category   wallabag
+ * @author     Nicolas LÅ“uillet <nicolas@loeuillet.org>
  * @copyright  2013
  * @license    http://www.wtfpl.net/ see COPYING file
  */
@@ -29,7 +29,8 @@ class Poche
         'dark' => array('requires' => array('default')),
         'dmagenta' => array('requires' => array('default')),
         'solarized' => array('requires' => array('default')),
-        'solarized-dark' => array('requires' => array('default'))
+        'solarized-dark' => array('requires' => array('default')),
+        'courgette' => array('requires' => array())
     );
 
     public function __construct()
@@ -333,7 +334,9 @@ class Poche
         switch ($action)
         {
             case 'add':
-                $json = file_get_contents(Tools::getPocheUrl() . '/inc/3rdparty/makefulltextfeed.php?url='.urlencode($url->getUrl()).'&max=5&links=preserve&exc=&format=json&submit=Create+Feed');
+                $options = array('http' => array('user_agent' => 'poche'));
+                $context = stream_context_create($options);
+                $json = file_get_contents(Tools::getPocheUrl() . '/inc/3rdparty/makefulltextfeed.php?url='.urlencode($url->getUrl()).'&max=5&links=preserve&exc=&format=json&submit=Create+Feed', false, $context);
                 $content = json_decode($json, true);
                 $title = $content['rss']['channel']['item']['title'];
                 $body = $content['rss']['channel']['item']['description'];
@@ -845,6 +848,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
@@ -856,7 +905,8 @@ class Poche
         $providers = array(
             'pocket' => 'importFromPocket',
             'readability' => 'importFromReadability',
-            'instapaper' => 'importFromInstapaper'
+            'instapaper' => 'importFromInstapaper',
+            'poche' => 'importFromPoche',
         );
         
         if (! isset($providers[$from])) {