From 14890de35a19b44df6537e601240fe38ff6a9ed9 Mon Sep 17 00:00:00 2001 From: nicosomb Date: Fri, 19 Apr 2013 15:46:04 +0200 Subject: =?UTF-8?q?cr=C3=A9ation=20d'une=20classe=20store()=20pour=20g?= =?UTF-8?q?=C3=A9rer=20tout=20type=20de=20stockage=20:=20sqlite,=20file,?= =?UTF-8?q?=20mysql,=20etc.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- inc/config.php | 10 ++-- inc/functions.php | 144 ++++++--------------------------------------- inc/store/file.class.php | 51 ++++++++++++++++ inc/store/sqlite.class.php | 136 ++++++++++++++++++++++++++++++++++++++++++ inc/store/store.class.php | 51 ++++++++++++++++ 5 files changed, 262 insertions(+), 130 deletions(-) create mode 100644 inc/store/file.class.php create mode 100644 inc/store/sqlite.class.php create mode 100644 inc/store/store.class.php (limited to 'inc') diff --git a/inc/config.php b/inc/config.php index c63b07b9..cf3529cb 100644 --- a/inc/config.php +++ b/inc/config.php @@ -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/functions.php b/inc/functions.php index ef1fc0e2..df7e9b17 100644 --- a/inc/functions.php +++ b/inc/functions.php @@ -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 index 00000000..ad20937d --- /dev/null +++ b/inc/store/file.class.php @@ -0,0 +1,51 @@ + + * @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 index 00000000..51054bc5 --- /dev/null +++ b/inc/store/sqlite.class.php @@ -0,0 +1,136 @@ + + * @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 index 00000000..ae3cb341 --- /dev/null +++ b/inc/store/store.class.php @@ -0,0 +1,51 @@ + + * @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) { + + } +} -- cgit v1.2.3 From 682536a9e759bf8c17e171bbd75d64c4cb3a308d Mon Sep 17 00:00:00 2001 From: nicosomb Date: Fri, 19 Apr 2013 15:47:20 +0200 Subject: suppression fichier db.php --- inc/db.php | 22 ---------------------- 1 file changed, 22 deletions(-) delete mode 100644 inc/db.php (limited to 'inc') diff --git a/inc/db.php b/inc/db.php deleted file mode 100644 index 60d7c108..00000000 --- a/inc/db.php +++ /dev/null @@ -1,22 +0,0 @@ - - * @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 -- cgit v1.2.3 From 2cd263e0bd8a36344e1dac5585b362b25ec19261 Mon Sep 17 00:00:00 2001 From: nicosomb Date: Sat, 20 Apr 2013 10:05:42 +0200 Subject: =?UTF-8?q?ajout=20d'url=20qui=20d=C3=A9connait?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- inc/store/sqlite.class.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'inc') diff --git a/inc/store/sqlite.class.php b/inc/store/sqlite.class.php index 51054bc5..b2ae94a7 100644 --- a/inc/store/sqlite.class.php +++ b/inc/store/sqlite.class.php @@ -94,10 +94,10 @@ class Sqlite extends Store { return $entries; } - public function add() { + public function add($url, $title, $content) { parent::__construct(); $sql_action = 'INSERT INTO entries ( url, title, content ) VALUES (?, ?, ?)'; - $params_action = array($url, $parametres_url['title'], $parametres_url['content']); + $params_action = array($url, $title, $content); $query = $this->executeQuery($sql_action, $params_action); } @@ -133,4 +133,4 @@ class Sqlite extends Store { $params_update = array($content, $id); $query = $this->executeQuery($sql_update, $params_update); } -} \ No newline at end of file +} -- cgit v1.2.3 From 016989b79af1f950f449e33c76f368c307c28c19 Mon Sep 17 00:00:00 2001 From: nicosomb Date: Sun, 21 Apr 2013 13:11:14 +0200 Subject: contenu de la page de config --- inc/functions.php | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'inc') diff --git a/inc/functions.php b/inc/functions.php index df7e9b17..10005dfe 100644 --- a/inc/functions.php +++ b/inc/functions.php @@ -232,6 +232,15 @@ function display_view($view, $id = 0, $full_head = 'yes') switch ($view) { + case 'config': + $tpl->assign('load_all_js', 0); + $tpl->draw('head'); + $tpl->draw('home'); + $tpl->draw('config'); + $tpl->draw('js'); + $tpl->draw('footer'); + logm('config view'); + break; case 'view': $entry = $store->retrieveOneById($id); -- cgit v1.2.3 From 44e77bfa2481090e559b56fd8ffbe5b175ab55ca Mon Sep 17 00:00:00 2001 From: nicosomb Date: Sun, 21 Apr 2013 18:09:25 +0200 Subject: =?UTF-8?q?Fixed=20#55=20-=20export=20des=20donn=C3=A9es=20au=20fo?= =?UTF-8?q?rmat=20json?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- inc/functions.php | 8 +++++++- inc/store/sqlite.class.php | 8 ++++++++ inc/store/store.class.php | 4 ++++ 3 files changed, 19 insertions(+), 1 deletion(-) (limited to 'inc') diff --git a/inc/functions.php b/inc/functions.php index 10005dfe..abf70a93 100644 --- a/inc/functions.php +++ b/inc/functions.php @@ -232,6 +232,12 @@ function display_view($view, $id = 0, $full_head = 'yes') switch ($view) { + case 'export': + $entries = $store->retrieveAll(); + $tpl->assign('export', json_encode($entries)); + $tpl->draw('export'); + logm('export view'); + break; case 'config': $tpl->assign('load_all_js', 0); $tpl->draw('head'); @@ -240,7 +246,7 @@ function display_view($view, $id = 0, $full_head = 'yes') $tpl->draw('js'); $tpl->draw('footer'); logm('config view'); - break; + break; case 'view': $entry = $store->retrieveOneById($id); diff --git a/inc/store/sqlite.class.php b/inc/store/sqlite.class.php index b2ae94a7..d5208a29 100644 --- a/inc/store/sqlite.class.php +++ b/inc/store/sqlite.class.php @@ -38,6 +38,14 @@ class Sqlite extends Store { } } + public function retrieveAll() { + $sql = "SELECT * FROM entries ORDER BY id"; + $query = $this->executeQuery($sql, array()); + $entries = $query->fetchAll(); + + return $entries; + } + public function retrieveOneById($id) { parent::__construct(); diff --git a/inc/store/store.class.php b/inc/store/store.class.php index ae3cb341..360ff7c2 100644 --- a/inc/store/store.class.php +++ b/inc/store/store.class.php @@ -17,6 +17,10 @@ class Store { } + public function retrieveAll() { + + } + public function retrieveOneById($id) { } -- cgit v1.2.3 From 6f87a19714057e370a6b970bbfb82af5abd968f9 Mon Sep 17 00:00:00 2001 From: nicosomb Date: Sun, 21 Apr 2013 18:42:20 +0200 Subject: Fixed #64 - nettoyage de MyTool --- inc/MyTool.class.php | 9 +++++++++ inc/functions.php | 25 +++++++++++++++++++------ 2 files changed, 28 insertions(+), 6 deletions(-) (limited to 'inc') diff --git a/inc/MyTool.class.php b/inc/MyTool.class.php index 8206f3f7..1f5051a4 100644 --- a/inc/MyTool.class.php +++ b/inc/MyTool.class.php @@ -1,4 +1,13 @@ + * @copyright 2013 + * @license http://www.wtfpl.net/ see COPYING file + */ + class MyTool { public static function initPhp() diff --git a/inc/functions.php b/inc/functions.php index abf70a93..ec5b3d6a 100644 --- a/inc/functions.php +++ b/inc/functions.php @@ -1,4 +1,12 @@ + * @copyright 2013 + * @license http://www.wtfpl.net/ see COPYING file + */ /** * Permet de générer l'URL de poche pour le bookmarklet @@ -234,7 +242,7 @@ function display_view($view, $id = 0, $full_head = 'yes') { case 'export': $entries = $store->retrieveAll(); - $tpl->assign('export', json_encode($entries)); + $tpl->assign('export', myTool::renderJson($entries)); $tpl->draw('export'); logm('export view'); break; @@ -300,13 +308,18 @@ function action_to_do($action, $url, $id = 0) if ($url == '') continue; - if($parametres_url = prepare_url($url)) { - $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); + if (MyTool::isUrl($url)) { + if($parametres_url = prepare_url($url)) { + $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); + } } } + else { + logm($url . ' is not a valid url'); + } logm('add link ' . $url); break; -- cgit v1.2.3 From f0070a15e4725255dad967bde76155a39d189631 Mon Sep 17 00:00:00 2001 From: nicosomb Date: Sun, 21 Apr 2013 19:32:19 +0200 Subject: =?UTF-8?q?flash=20messages=20pour=20indiquer=20qu'une=20action=20?= =?UTF-8?q?s'est=20bien=20effectu=C3=A9e=20ou=20qu'il=20y=20a=20eu=20une?= =?UTF-8?q?=20erreur?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- inc/class.messages.php | 231 +++++++++++++++++++++++++++++++++++++++++++++++++ inc/config.php | 9 +- inc/functions.php | 10 ++- 3 files changed, 246 insertions(+), 4 deletions(-) create mode 100644 inc/class.messages.php (limited to 'inc') diff --git a/inc/class.messages.php b/inc/class.messages.php new file mode 100644 index 00000000..6d515bf6 --- /dev/null +++ b/inc/class.messages.php @@ -0,0 +1,231 @@ +\n%s\n"; + var $msgBefore = '

'; + var $msgAfter = "

\n"; + + + /** + * Constructor + * @author Mike Everhart + */ + public function __construct() { + + // Generate a unique ID for this user and session + $this->msgId = md5(uniqid()); + + // Create the session array if it doesnt already exist + if( !array_key_exists('flash_messages', $_SESSION) ) $_SESSION['flash_messages'] = array(); + + } + + /** + * Add a message to the queue + * + * @author Mike Everhart + * + * @param string $type The type of message to add + * @param string $message The message + * @param string $redirect_to (optional) If set, the user will be redirected to this URL + * @return bool + * + */ + public function add($type, $message, $redirect_to=null) { + + if( !isset($_SESSION['flash_messages']) ) return false; + + if( !isset($type) || !isset($message[0]) ) return false; + + // Replace any shorthand codes with their full version + if( strlen(trim($type)) == 1 ) { + $type = str_replace( array('h', 'i', 'w', 'e', 's'), array('help', 'info', 'warning', 'error', 'success'), $type ); + + // Backwards compatibility... + } elseif( $type == 'information' ) { + $type = 'info'; + } + + // Make sure it's a valid message type + if( !in_array($type, $this->msgTypes) ) die('"' . strip_tags($type) . '" is not a valid message type!' ); + + // If the session array doesn't exist, create it + if( !array_key_exists( $type, $_SESSION['flash_messages'] ) ) $_SESSION['flash_messages'][$type] = array(); + + $_SESSION['flash_messages'][$type][] = $message; + + if( !is_null($redirect_to) ) { + header("Location: $redirect_to"); + exit(); + } + + return true; + + } + + //----------------------------------------------------------------------------------------------- + // display() + // print queued messages to the screen + //----------------------------------------------------------------------------------------------- + /** + * Display the queued messages + * + * @author Mike Everhart + * + * @param string $type Which messages to display + * @param bool $print True = print the messages on the screen + * @return mixed + * + */ + public function display($type='all', $print=true) { + $messages = ''; + $data = ''; + + if( !isset($_SESSION['flash_messages']) ) return false; + + if( $type == 'g' || $type == 'growl' ) { + $this->displayGrowlMessages(); + return true; + } + + // Print a certain type of message? + if( in_array($type, $this->msgTypes) ) { + foreach( $_SESSION['flash_messages'][$type] as $msg ) { + $messages .= $this->msgBefore . $msg . $this->msgAfter; + } + + $data .= sprintf($this->msgWrapper, $this->msgClass, $type, $messages); + + // Clear the viewed messages + $this->clear($type); + + // Print ALL queued messages + } elseif( $type == 'all' ) { + foreach( $_SESSION['flash_messages'] as $type => $msgArray ) { + $messages = ''; + foreach( $msgArray as $msg ) { + $messages .= $this->msgBefore . $msg . $this->msgAfter; + } + $data .= sprintf($this->msgWrapper, $this->msgClass, $type, $messages); + } + + // Clear ALL of the messages + $this->clear(); + + // Invalid Message Type? + } else { + return false; + } + + // Print everything to the screen or return the data + if( $print ) { + echo $data; + } else { + return $data; + } + } + + + /** + * Check to see if there are any queued error messages + * + * @author Mike Everhart + * + * @return bool true = There ARE error messages + * false = There are NOT any error messages + * + */ + public function hasErrors() { + return empty($_SESSION['flash_messages']['error']) ? false : true; + } + + /** + * Check to see if there are any ($type) messages queued + * + * @author Mike Everhart + * + * @param string $type The type of messages to check for + * @return bool + * + */ + public function hasMessages($type=null) { + if( !is_null($type) ) { + if( !empty($_SESSION['flash_messages'][$type]) ) return $_SESSION['flash_messages'][$type]; + } else { + foreach( $this->msgTypes as $type ) { + if( !empty($_SESSION['flash_messages']) ) return true; + } + } + return false; + } + + /** + * Clear messages from the session data + * + * @author Mike Everhart + * + * @param string $type The type of messages to clear + * @return bool + * + */ + public function clear($type='all') { + if( $type == 'all' ) { + unset($_SESSION['flash_messages']); + } else { + unset($_SESSION['flash_messages'][$type]); + } + return true; + } + + public function __toString() { return $this->hasMessages(); } + + public function __destruct() { + //$this->clear(); + } + + +} // end class +?> \ No newline at end of file diff --git a/inc/config.php b/inc/config.php index cf3529cb..9d4b7fae 100644 --- a/inc/config.php +++ b/inc/config.php @@ -28,8 +28,12 @@ require_once 'Session.class.php'; require_once 'store/store.class.php'; require_once 'store/sqlite.class.php'; require_once 'store/file.class.php'; +require_once 'class.messages.php'; -$store = new $storage_type(); +Session::init(); + +$store = new $storage_type(); +$msg = new Messages(); # initialisation de RainTPL raintpl::$tpl_dir = './tpl/'; @@ -37,4 +41,5 @@ raintpl::$cache_dir = './cache/'; raintpl::$base_url = get_poche_url(); raintpl::configure('path_replace', false); raintpl::configure('debug', false); -$tpl = new raintpl(); \ No newline at end of file +$tpl = new raintpl(); +$tpl->assign('msg', $msg); \ No newline at end of file diff --git a/inc/functions.php b/inc/functions.php index ec5b3d6a..205f3968 100644 --- a/inc/functions.php +++ b/inc/functions.php @@ -125,6 +125,7 @@ function prepare_url($url) } } + $msg->add('e', 'error during url preparation'); logm('error during url preparation'); return FALSE; } @@ -236,7 +237,7 @@ function remove_directory($directory) function display_view($view, $id = 0, $full_head = 'yes') { - global $tpl, $store; + global $tpl, $store, $msg; switch ($view) { @@ -300,7 +301,7 @@ function display_view($view, $id = 0, $full_head = 'yes') */ function action_to_do($action, $url, $id = 0) { - global $store; + global $store, $msg; switch ($action) { @@ -315,9 +316,11 @@ function action_to_do($action, $url, $id = 0) if (DOWNLOAD_PICTURES) { $content = filtre_picture($parametres_url['content'], $url, $last_id); } + $msg->add('s', 'the link has been added successfully'); } } else { + $msg->add('e', 'the link has been added successfully'); logm($url . ' is not a valid url'); } @@ -326,14 +329,17 @@ function action_to_do($action, $url, $id = 0) case 'delete': remove_directory(ABS_PATH . $id); $store->deleteById($id); + $msg->add('s', 'the link has been deleted successfully'); logm('delete link #' . $id); break; case 'toggle_fav' : $store->favoriteById($id); + $msg->add('s', 'the favorite toggle has been done successfully'); logm('mark as favorite link #' . $id); break; case 'toggle_archive' : $store->archiveById($id); + $msg->add('s', 'the archive toggle has been done successfully'); logm('archive link #' . $id); break; default: -- cgit v1.2.3