]> git.immae.eu Git - github/wallabag/wallabag.git/blobdiff - inc/poche/Poche.class.php
error msg when install folder exists
[github/wallabag/wallabag.git] / inc / poche / Poche.class.php
index 0439f301fc2952ae56f5c7ade576434d9c541a57..82f0228e82b5914f7240ec875eb61b7cc5421633 100644 (file)
@@ -18,6 +18,11 @@ class Poche
 
     function __construct()
     {
+        if (file_exists('./install') && !DEBUG_POCHE) {
+            Tools::logm('folder /install exists');
+            die('If you want to update your poche, you just have to delete /install folder. <br />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.');
+        }
+
         $this->store = new Database();
         $this->init();
         $this->messages = new Messages();
@@ -31,11 +36,6 @@ class Poche
 
     private function init() 
     {
-        if (file_exists('./install') && !DEBUG_POCHE) {
-            Tools::logm('folder /install exists');
-            die('the folder /install exists, you have to delete it before using poche.');
-        }
-
         Tools::initPhp();
         Session::init();
 
@@ -69,6 +69,10 @@ class Poche
         $filter = new Twig_SimpleFilter('getDomain', 'Tools::getDomain');
         $this->tpl->addFilter($filter);
 
+        # filter for reading time
+        $filter = new Twig_SimpleFilter('getReadingTime', 'Tools::getReadingTime');
+        $this->tpl->addFilter($filter);
+
         # Pagination
         $this->pagination = new Paginator($this->user->getConfigValue('pager'), 'p');
     }
@@ -122,6 +126,8 @@ class Poche
                         $last_id = $this->store->getLastId($sequence);
                         if (DOWNLOAD_PICTURES) {
                             $content = filtre_picture($parametres_url['content'], $url->getUrl(), $last_id);
+                            Tools::logm('updating content article');
+                            $this->store->updateContent($last_id, $content, $this->user->getId());
                         }
                         if (!$import) {
                             $this->messages->add('s', _('the link has been added successfully'));
@@ -213,7 +219,7 @@ class Poche
                     );
                 }
                 else {
-                    Tools::logm('error in view call : entry is NULL');
+                    Tools::logm('error in view call : entry is null');
                 }
                 break;
             default: # home view
@@ -232,6 +238,13 @@ class Poche
         return $tpl_vars;
     }
 
+    /**
+     * update the password of the current user. 
+     * if MODE_DEMO is TRUE, the password can't be updated. 
+     * @todo add the return value
+     * @todo set the new password in function header like this updatePassword($newPassword)
+     * @return boolean
+     */
     public function updatePassword()
     {
         if (MODE_DEMO) {
@@ -256,6 +269,13 @@ class Poche
         }
     }
 
+    /**
+     * checks if login & password are correct and save the user in session.
+     * it redirects the user to the $referer link
+     * @param  string $referer the url to redirect after login
+     * @todo add the return value
+     * @return boolean
+     */
     public function login($referer)
     {
         if (!empty($_POST['login']) && !empty($_POST['password'])) {
@@ -286,6 +306,11 @@ class Poche
         }
     }
 
+    /**
+     * log out the poche user. It cleans the session.
+     * @todo add the return value
+     * @return boolean 
+     */
     public function logout()
     {
         $this->user = array();
@@ -295,6 +320,11 @@ class Poche
         Tools::redirect();
     }
 
+    /**
+     * import from Instapaper. poche needs a ./instapaper-export.html file
+     * @todo add the return value
+     * @return boolean
+     */
     private function importFromInstapaper()
     {
         # TODO gestion des articles favs
@@ -329,6 +359,11 @@ class Poche
         Tools::redirect();
     }
 
+    /**
+     * import from Pocket. poche needs a ./ril_export.html file
+     * @todo add the return value
+     * @return boolean 
+     */
     private function importFromPocket()
     {
         # TODO gestion des articles favs
@@ -363,6 +398,11 @@ class Poche
         Tools::redirect();
     }
 
+    /**
+     * import from Readability. poche needs a ./readability file
+     * @todo add the return value
+     * @return boolean 
+     */
     private function importFromReadability()
     {
         # TODO gestion des articles lus / favs
@@ -398,19 +438,29 @@ class Poche
         Tools::redirect();
     }
 
+    /**
+     * import datas into your poche
+     * @param  string $from name of the service to import : pocket, instapaper or readability
+     * @todo add the return value
+     * @return boolean       
+     */
     public function import($from)
     {
         if ($from == 'pocket') {
-            $this->importFromPocket();
+            return $this->importFromPocket();
         }
         else if ($from == 'readability') {
-            $this->importFromReadability();
+            return $this->importFromReadability();
         }
         else if ($from == 'instapaper') {
-            $this->importFromInstapaper();
+            return $this->importFromInstapaper();
         }
     }
 
+    /**
+     * export poche entries in json
+     * @return json all poche entries
+     */
     public function export()
     {
         $entries = $this->store->retrieveAll($this->user->getId());
@@ -420,9 +470,16 @@ class Poche
         Tools::logm('export view');
     }
 
+    /**
+     * Checks online the latest version of poche and cache it
+     * @param  string $which 'prod' or 'dev'
+     * @return string        latest $which version
+     */
     private function getPocheVersion($which = 'prod')
     {
         $cache_file = CACHE . '/' . $which;
+
+        # checks if the cached version file exists
         if (file_exists($cache_file) && (filemtime($cache_file) > (time() - 86400 ))) {
            $version = file_get_contents($cache_file);
         } else {