]> git.immae.eu Git - github/wallabag/wallabag.git/commitdiff
Merge pull request #61 from Silvus/master
authorNicolas Lœuillet <nicolas@loeuillet.org>
Sat, 20 Apr 2013 05:41:02 +0000 (22:41 -0700)
committerNicolas Lœuillet <nicolas@loeuillet.org>
Sat, 20 Apr 2013 05:41:02 +0000 (22:41 -0700)
Fixed #36 - Thème dark

inc/config.php
inc/db.php [deleted file]
inc/functions.php
inc/store/file.class.php [new file with mode: 0644]
inc/store/sqlite.class.php [new file with mode: 0644]
inc/store/store.class.php [new file with mode: 0644]

index c63b07b950c7b84a80a4e96f796639627c3467b1..cf3529cb1e8de4e198e3c7e258f06a6bfeefd135 100644 (file)
@@ -8,26 +8,28 @@
  * @license    http://www.wtfpl.net/ see COPYING file
  */
 
-define ('POCHE_VERSION', '0.11');
+define ('POCHE_VERSION', '0.2');
 
 if (!is_dir('db/')) {
     @mkdir('db/',0705);
 }
 
-define ('DB_PATH', 'sqlite:./db/poche.sqlite');
 define ('ABS_PATH', 'assets/');
 define ('CONVERT_LINKS_FOOTNOTES', TRUE);
 define ('DOWNLOAD_PICTURES', TRUE);
+$storage_type = 'sqlite'; # sqlite or file
 
-include 'db.php';
 include 'functions.php';
 require_once 'Readability.php';
 require_once 'Encoding.php';
 require_once 'rain.tpl.class.php';
 require_once 'MyTool.class.php';
 require_once 'Session.class.php';
+require_once 'store/store.class.php';
+require_once 'store/sqlite.class.php';
+require_once 'store/file.class.php';
 
-$db = new db(DB_PATH);
+$store = new $storage_type();
 
 # initialisation de RainTPL
 raintpl::$tpl_dir   = './tpl/';
diff --git a/inc/db.php b/inc/db.php
deleted file mode 100644 (file)
index 60d7c10..0000000
+++ /dev/null
@@ -1,22 +0,0 @@
-<?php
-/**
- * poche, a read it later open source system
- *
- * @category   poche
- * @author     Nicolas Lœuillet <nicolas@loeuillet.org>
- * @copyright  2013
- * @license    http://www.wtfpl.net/ see COPYING file
- */
-
-class db {
-    var $handle;
-    function __construct($path) {
-        $this->handle = new PDO($path);
-        $this->handle->exec('CREATE TABLE IF NOT EXISTS "entries" ("id" INTEGER PRIMARY KEY  AUTOINCREMENT  NOT NULL  UNIQUE , "title" VARCHAR, "url" VARCHAR UNIQUE , "is_read" INTEGER DEFAULT 0, "is_fav" INTEGER DEFAULT 0, "content" BLOB)');
-        $this->handle->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
-    }
-
-    public function getHandle() {
-        return $this->handle;
-    }
-}
\ No newline at end of file
index ef1fc0e28a934812df50d1468d2874d2395aa60e..df7e9b17f0f2c21fa980b144a75b66833b5da5e9 100644 (file)
@@ -228,20 +228,20 @@ function remove_directory($directory)
 
 function display_view($view, $id = 0, $full_head = 'yes')
 {
-    global $tpl;
+    global $tpl, $store;
 
     switch ($view)
     {
         case 'view':
-            $entry = get_article($id);
+            $entry = $store->retrieveOneById($id);
 
             if ($entry != NULL) {
-                $tpl->assign('id', $entry[0]['id']);
-                $tpl->assign('url', $entry[0]['url']);
-                $tpl->assign('title', $entry[0]['title']);
-                $tpl->assign('content', $entry[0]['content']);
-                $tpl->assign('is_fav', $entry[0]['is_fav']);
-                $tpl->assign('is_read', $entry[0]['is_read']);
+                $tpl->assign('id', $entry['id']);
+                $tpl->assign('url', $entry['url']);
+                $tpl->assign('title', $entry['title']);
+                $tpl->assign('content', $entry['content']);
+                $tpl->assign('is_fav', $entry['is_fav']);
+                $tpl->assign('is_read', $entry['is_read']);
                 $tpl->assign('load_all_js', 0);
                 $tpl->draw('view');
             }
@@ -252,7 +252,7 @@ function display_view($view, $id = 0, $full_head = 'yes')
             logm('view link #' . $id);
             break;
         default: # home view
-            $entries = get_entries($view);
+            $entries = $store->getEntriesByView($view);
 
             $tpl->assign('entries', $entries);
 
@@ -277,7 +277,7 @@ function display_view($view, $id = 0, $full_head = 'yes')
  */
 function action_to_do($action, $url, $id = 0)
 {
-    global $db;
+    global $store;
 
     switch ($action)
     {
@@ -286,139 +286,31 @@ function action_to_do($action, $url, $id = 0)
                 continue;
 
             if($parametres_url = prepare_url($url)) {
-                $sql_action     = 'INSERT INTO entries ( url, title, content ) VALUES (?, ?, ?)';
-                $params_action  = array($url, $parametres_url['title'], $parametres_url['content']);
+                $store->add($url, $parametres_url['title'], $parametres_url['content']);
+                $last_id = $store->getLastId();
+                if (DOWNLOAD_PICTURES) {
+                    $content = filtre_picture($parametres_url['content'], $url, $last_id);
+                }
             }
 
             logm('add link ' . $url);
             break;
         case 'delete':
             remove_directory(ABS_PATH . $id);
-            $sql_action     = "DELETE FROM entries WHERE id=?";
-            $params_action  = array($id);
+            $store->deleteById($id);
             logm('delete link #' . $id);
             break;
         case 'toggle_fav' :
-            $sql_action     = "UPDATE entries SET is_fav=~is_fav WHERE id=?";
-            $params_action  = array($id);
+            $store->favoriteById($id);
             logm('mark as favorite link #' . $id);
             break;
         case 'toggle_archive' :
-            $sql_action     = "UPDATE entries SET is_read=~is_read WHERE id=?";
-            $params_action  = array($id);
+            $store->archiveById($id);
             logm('archive link #' . $id);
             break;
         default:
             break;
     }
-
-    try
-    {
-        # action query
-        if (isset($sql_action))
-        {
-            $query = $db->getHandle()->prepare($sql_action);
-            $query->execute($params_action);
-            # if we add a link, we have to download pictures
-            if ($action == 'add') {
-                $last_id = $db->getHandle()->lastInsertId();
-                if (DOWNLOAD_PICTURES) {
-                    $content        = filtre_picture($parametres_url['content'], $url, $last_id);
-                    $sql_update     = "UPDATE entries SET content=? WHERE id=?";
-                    $params_update  = array($content, $last_id);
-                    $query_update   = $db->getHandle()->prepare($sql_update);
-                    $query_update->execute($params_update);
-                }
-            }
-        }
-    }
-    catch (Exception $e)
-    {
-        logm('action query error : '.$e->getMessage());
-    }
-}
-
-/**
- * Détermine quels liens afficher : home, fav ou archives
- */
-function get_entries($view)
-{
-    global $db;
-
-    switch ($_SESSION['sort'])
-    {
-        case 'ia':
-            $order = 'ORDER BY id';
-            break;
-        case 'id':
-            $order = 'ORDER BY id DESC';
-            break;
-        case 'ta':
-            $order = 'ORDER BY lower(title)';
-            break;
-        case 'td':
-            $order = 'ORDER BY lower(title) DESC';
-            break;
-        default:
-            $order = 'ORDER BY id';
-            break;
-    }
-
-    switch ($view)
-    {
-        case 'archive':
-            $sql    = "SELECT * FROM entries WHERE is_read=? " . $order;
-            $params = array(-1);
-            break;
-        case 'fav' :
-            $sql    = "SELECT * FROM entries WHERE is_fav=? " . $order;
-            $params = array(-1);
-            break;
-        default:
-            $sql    = "SELECT * FROM entries WHERE is_read=? " . $order;
-            $params = array(0);
-            break;
-    }
-
-    # view query
-    try
-    {
-        $query  = $db->getHandle()->prepare($sql);
-        $query->execute($params);
-        $entries = $query->fetchAll();
-    }
-    catch (Exception $e)
-    {
-        logm('view query error : '.$e->getMessage());
-    }
-
-    return $entries;
-}
-
-/**
- * Récupère un article en fonction d'un ID
- */
-function get_article($id)
-{
-    global $db;
-
-    $entry  = NULL;
-    $sql    = "SELECT * FROM entries WHERE id=?";
-    $params = array(intval($id));
-
-    # view article query
-    try
-    {
-        $query  = $db->getHandle()->prepare($sql);
-        $query->execute($params);
-        $entry = $query->fetchAll();
-    }
-    catch (Exception $e)
-    {
-        logm('get article query error : '.$e->getMessage());
-    }
-
-    return $entry;
 }
 
 function logm($message)
diff --git a/inc/store/file.class.php b/inc/store/file.class.php
new file mode 100644 (file)
index 0000000..ad20937
--- /dev/null
@@ -0,0 +1,51 @@
+<?php
+/**
+ * poche, a read it later open source system
+ *
+ * @category   poche
+ * @author     Nicolas Lœuillet <support@inthepoche.com>
+ * @copyright  2013
+ * @license    http://www.wtfpl.net/ see COPYING file
+ */
+
+class File extends Store {
+    function __construct() {
+
+    }
+
+    public function add() {
+
+    }
+
+    public function retrieveOneById($id) {
+
+    }
+
+    public function retrieveOneByURL($url) {
+
+    }
+
+    public function deleteById($id) {
+
+    }
+
+    public function favoriteById($id) {
+
+    }
+
+    public function archiveById($id) {
+
+    }
+
+    public function getEntriesByView($view) {
+
+    }
+
+    public function getLastId() {
+
+    }
+
+    public function updateContentById($id) {
+
+    }
+}
diff --git a/inc/store/sqlite.class.php b/inc/store/sqlite.class.php
new file mode 100644 (file)
index 0000000..51054bc
--- /dev/null
@@ -0,0 +1,136 @@
+<?php
+/**
+ * poche, a read it later open source system
+ *
+ * @category   poche
+ * @author     Nicolas Lœuillet <support@inthepoche.com>
+ * @copyright  2013
+ * @license    http://www.wtfpl.net/ see COPYING file
+ */
+
+class Sqlite extends Store {
+
+    public static $db_path = 'sqlite:./db/poche.sqlite';
+    var $handle;
+
+    function __construct() {
+        parent::__construct();
+
+        $this->handle = new PDO(self::$db_path);
+        $this->handle->exec('CREATE TABLE IF NOT EXISTS "entries" ("id" INTEGER PRIMARY KEY  AUTOINCREMENT  NOT NULL  UNIQUE , "title" VARCHAR, "url" VARCHAR UNIQUE , "is_read" INTEGER DEFAULT 0, "is_fav" INTEGER DEFAULT 0, "content" BLOB)');
+        $this->handle->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
+    }
+
+    private function getHandle() {
+        return $this->handle;
+    }
+
+    private function executeQuery($sql, $params) {
+        try
+        {
+            $query = $this->getHandle()->prepare($sql);
+            $query->execute($params);
+            return $query;
+        }
+        catch (Exception $e)
+        {
+            logm('execute query error : '.$e->getMessage());
+        }
+    }
+
+    public function retrieveOneById($id) {
+        parent::__construct();
+
+        $entry  = NULL;
+        $sql    = "SELECT * FROM entries WHERE id=?";
+        $params = array(intval($id));
+        $query  = $this->executeQuery($sql, $params);
+        $entry  = $query->fetchAll();
+
+        return $entry[0];
+    }
+
+    public function getEntriesByView($view) {
+        parent::__construct();
+
+        switch ($_SESSION['sort'])
+        {
+            case 'ia':
+                $order = 'ORDER BY id';
+                break;
+            case 'id':
+                $order = 'ORDER BY id DESC';
+                break;
+            case 'ta':
+                $order = 'ORDER BY lower(title)';
+                break;
+            case 'td':
+                $order = 'ORDER BY lower(title) DESC';
+                break;
+            default:
+                $order = 'ORDER BY id';
+                break;
+        }
+
+        switch ($view)
+        {
+            case 'archive':
+                $sql    = "SELECT * FROM entries WHERE is_read=? " . $order;
+                $params = array(-1);
+                break;
+            case 'fav' :
+                $sql    = "SELECT * FROM entries WHERE is_fav=? " . $order;
+                $params = array(-1);
+                break;
+            default:
+                $sql    = "SELECT * FROM entries WHERE is_read=? " . $order;
+                $params = array(0);
+                break;
+        }
+
+        $query      = $this->executeQuery($sql, $params);
+        $entries    = $query->fetchAll();
+
+        return $entries;
+    }
+
+    public function add() {
+        parent::__construct();
+        $sql_action     = 'INSERT INTO entries ( url, title, content ) VALUES (?, ?, ?)';
+        $params_action  = array($url, $parametres_url['title'], $parametres_url['content']);
+        $query          = $this->executeQuery($sql_action, $params_action);
+    }
+
+    public function deleteById($id) {
+        parent::__construct();
+        $sql_action     = "DELETE FROM entries WHERE id=?";
+        $params_action  = array($id);
+        $query          = $this->executeQuery($sql_action, $params_action);
+    }
+
+    public function favoriteById($id) {
+        parent::__construct();
+        $sql_action     = "UPDATE entries SET is_fav=~is_fav WHERE id=?";
+        $params_action  = array($id);
+        $query          = $this->executeQuery($sql_action, $params_action);
+    }
+
+    public function archiveById($id) {
+        parent::__construct();
+        $sql_action     = "UPDATE entries SET is_read=~is_read WHERE id=?";
+        $params_action  = array($id);
+        $query          = $this->executeQuery($sql_action, $params_action);
+    }
+
+    public function getLastId() {
+        parent::__construct();
+        return $this->getHandle()->lastInsertId();
+    }
+
+    public function updateContentById($id) {
+        parent::__construct();
+        $sql_update     = "UPDATE entries SET content=? WHERE id=?";
+        $params_update  = array($content, $id);
+        $query          = $this->executeQuery($sql_update, $params_update);
+    }
+}
\ No newline at end of file
diff --git a/inc/store/store.class.php b/inc/store/store.class.php
new file mode 100644 (file)
index 0000000..ae3cb34
--- /dev/null
@@ -0,0 +1,51 @@
+<?php
+/**
+ * poche, a read it later open source system
+ *
+ * @category   poche
+ * @author     Nicolas Lœuillet <support@inthepoche.com>
+ * @copyright  2013
+ * @license    http://www.wtfpl.net/ see COPYING file
+ */
+
+class Store {
+    function __construct() {
+
+    }
+
+    public function add() {
+
+    }
+
+    public function retrieveOneById($id) {
+
+    }
+
+    public function retrieveOneByURL($url) {
+
+    }
+
+    public function deleteById($id) {
+
+    }
+
+    public function favoriteById($id) {
+
+    }
+
+    public function archiveById($id) {
+
+    }
+
+    public function getEntriesByView($view) {
+
+    }
+
+    public function getLastId() {
+
+    }
+
+    public function updateContentById($id) {
+
+    }
+}