From 14890de35a19b44df6537e601240fe38ff6a9ed9 Mon Sep 17 00:00:00 2001 From: nicosomb Date: Fri, 19 Apr 2013 15:46:04 +0200 Subject: [PATCH 01/14] =?UTF-8?q?cr=C3=A9ation=20d'une=20classe=20store()?= =?UTF-8?q?=20pour=20g=C3=A9rer=20tout=20type=20de=20stockage=20:=20sqlite?= =?UTF-8?q?,=20file,=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 diff --git a/inc/config.php b/inc/config.php index c63b07b95..cf3529cb1 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 ef1fc0e28..df7e9b17f 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 000000000..ad20937d4 --- /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 000000000..51054bc5d --- /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 000000000..ae3cb3411 --- /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) { + + } +} From 682536a9e759bf8c17e171bbd75d64c4cb3a308d Mon Sep 17 00:00:00 2001 From: nicosomb Date: Fri, 19 Apr 2013 15:47:20 +0200 Subject: [PATCH 02/14] suppression fichier db.php --- inc/db.php | 22 ---------------------- 1 file changed, 22 deletions(-) delete mode 100644 inc/db.php diff --git a/inc/db.php b/inc/db.php deleted file mode 100644 index 60d7c108c..000000000 --- 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 From b4397510e75fe9c387bec4161769392906c81bd7 Mon Sep 17 00:00:00 2001 From: silvus Date: Fri, 19 Apr 2013 22:26:39 +0200 Subject: [PATCH 03/14] Add a dark theme and is very simple switch --- css/style-dark.css | 90 ++++++++++++++++++++++++++++++ css/style-light.css | 90 ++++++++++++++++++++++++++++++ css/style.css | 57 ------------------- img/dark/checkmark-off.png | Bin 0 -> 267 bytes img/dark/checkmark-on.png | Bin 0 -> 221 bytes img/dark/down.png | Bin 0 -> 223 bytes img/dark/logo.png | Bin 0 -> 786 bytes img/dark/remove.png | Bin 0 -> 265 bytes img/dark/star-off.png | Bin 0 -> 330 bytes img/dark/star-on.png | Bin 0 -> 277 bytes img/dark/up.png | Bin 0 -> 225 bytes img/{ => light}/checkmark-off.png | Bin img/{ => light}/checkmark-on.png | Bin img/{ => light}/remove.png | Bin img/{ => light}/star-off.png | Bin img/{ => light}/star-on.png | Bin js/poche.js | 30 +++++++++- tpl/head.html | 6 +- tpl/home.html | 1 + tpl/view.html | 7 ++- 20 files changed, 221 insertions(+), 60 deletions(-) create mode 100644 css/style-dark.css create mode 100644 css/style-light.css create mode 100644 img/dark/checkmark-off.png create mode 100644 img/dark/checkmark-on.png create mode 100644 img/dark/down.png create mode 100644 img/dark/logo.png create mode 100644 img/dark/remove.png create mode 100644 img/dark/star-off.png create mode 100644 img/dark/star-on.png create mode 100644 img/dark/up.png rename img/{ => light}/checkmark-off.png (100%) rename img/{ => light}/checkmark-on.png (100%) rename img/{ => light}/remove.png (100%) rename img/{ => light}/star-off.png (100%) rename img/{ => light}/star-on.png (100%) diff --git a/css/style-dark.css b/css/style-dark.css new file mode 100644 index 000000000..813c291de --- /dev/null +++ b/css/style-dark.css @@ -0,0 +1,90 @@ +/*** GENERAL ***/ +body { + color: #fff; + background-color: #0d0d0d; +} + +a, a:hover, a:visited { + color: #fff; +} + +#main ul#links li a.current { + background-color: #000; + color: #fff; +} + +#links a:hover, .backhome a:hover{ + background-color: #fff; + color: #000; +} + +input[type=submit].delete { + background : url('../img/dark/remove.png') no-repeat center center; + color : transparent; +} + +#main .entrie { + color: #fff; + background-color: #000; + border: 1px solid #fff; +} + +#main .entrie h2 a:hover { + color: #29B1E3; +} + +a.fav span { + background: url('../img/dark/star-on.png') no-repeat; +} + +a.fav span:hover { + background: url('../img/dark/star-off.png') no-repeat; +} + +a.fav-off span { + background: url('../img/dark/star-off.png') no-repeat; +} + +a.fav-off span:hover { + background: url('../img/dark/star-on.png') no-repeat; +} + +a.archive span { + background: url('../img/dark/checkmark-on.png') no-repeat; +} + +a.archive span:hover { + background: url('../img/dark/checkmark-off.png') no-repeat; +} + +a.archive-off span { + background: url('../img/dark/checkmark-off.png') no-repeat; +} + +a.archive-off span:hover { + background: url('../img/dark/checkmark-on.png') no-repeat; +} + +/*** ***/ +/*** ARTICLE PAGE ***/ + +body.article { + color: #fff; + background-color: #0d0d0d; +} + +#article header { + border-bottom: 1px solid #222222; +} + +#article article { + border-bottom: 1px solid #222222; +} + +.vieworiginal a { + color: #888888; +} + +.entrie { + background-color: #fff; +} diff --git a/css/style-light.css b/css/style-light.css new file mode 100644 index 000000000..5b9c6c11d --- /dev/null +++ b/css/style-light.css @@ -0,0 +1,90 @@ +/*** GENERAL ***/ +body { + color: #222222; + background-color: #F1F1F1; +} + +a, a:hover, a:visited { + color: #000; +} + +#main ul#links li a.current { + background-color: #000; + color: #fff; +} + +#links a:hover, .backhome a:hover{ + background-color: #040707; + color: #F1F1F1; +} + +input[type=submit].delete { + background : url('../img/light/remove.png') no-repeat center center; + color : transparent; +} + +#main .entrie { + color: #2e2e2e; + background-color: #ffffff; + border: 1px solid #000; +} + +#main .entrie h2 a:hover { + color: #F5BE00; +} + +a.fav span { + background: url('../img/light/star-on.png') no-repeat; +} + +a.fav span:hover { + background: url('../img/light/star-off.png') no-repeat; +} + +a.fav-off span { + background: url('../img/light/star-off.png') no-repeat; +} + +a.fav-off span:hover { + background: url('../img/light/star-on.png') no-repeat; +} + +a.archive span { + background: url('../img/light/checkmark-on.png') no-repeat; +} + +a.archive span:hover { + background: url('../img/light/checkmark-off.png') no-repeat; +} + +a.archive-off span { + background: url('../img/light/checkmark-off.png') no-repeat; +} + +a.archive-off span:hover { + background: url('../img/light/checkmark-on.png') no-repeat; +} + +/*** ***/ +/*** ARTICLE PAGE ***/ + +body.article { + color: #222222; + background-color: #F1F1F1; +} + +#article header { + border-bottom: 1px solid #222222; +} + +#article article { + border-bottom: 1px solid #222222; +} + +.vieworiginal a { + color: #888888; +} + +.entrie { + background-color: #fff; +} diff --git a/css/style.css b/css/style.css index 29dca289a..7fc8f056b 100644 --- a/css/style.css +++ b/css/style.css @@ -1,16 +1,10 @@ /*** GENERAL ***/ body { - color: #222222; font: 20px/1.3em Palatino,Georgia,serif; - background-color: #F1F1F1; margin: 10px; } -a, a:hover, a:visited { - color: #000; -} - header { text-align: center; } @@ -28,8 +22,6 @@ header { #main ul#links li a.current { -webkit-border-radius: 2px; border-radius: 2px; - background-color: #040707; - color: #F1F1F1; } #main ul#sort { @@ -58,8 +50,6 @@ header { #links a:hover, .backhome a:hover{ -webkit-border-radius: 2px; border-radius: 2px; - background-color: #040707; - color: #F1F1F1; } footer { @@ -80,11 +70,9 @@ ul#login li { } input[type=submit].delete { - background : url('../img/remove.png') no-repeat center center; width : 16px; height :16px; border : none; - color : transparent; cursor: pointer; font-size : 0; } @@ -94,8 +82,6 @@ input[type=submit].delete { } #main .entrie { - color: rgb(46, 46, 46); - background-color: #ffffff; padding: 15px; min-height: 8em; border: 1px solid; @@ -105,10 +91,6 @@ input[type=submit].delete { text-decoration: none; } -#main .entrie h2 a:hover { - color: #F5BE00; -} - .tools { text-align: right; } @@ -145,62 +127,23 @@ input[type=submit].delete { height: 16px; } -a.fav span { - background: url('../img/star-on.png') no-repeat; -} - -a.fav span:hover { - background: url('../img/star-off.png') no-repeat; -} - -a.fav-off span { - background: url('../img/star-off.png') no-repeat; -} - -a.fav-off span:hover { - background: url('../img/star-on.png') no-repeat; -} - -a.archive span { - background: url('../img/checkmark-on.png') no-repeat; -} - -a.archive span:hover { - background: url('../img/checkmark-off.png') no-repeat; -} - -a.archive-off span { - background: url('../img/checkmark-off.png') no-repeat; -} - -a.archive-off span:hover { - background: url('../img/checkmark-on.png') no-repeat; -} /*** ***/ /*** ARTICLE PAGE ***/ body.article { - color: #222222; font: 20px/1.3em Palatino,Georgia,serif; - background-color: #F1F1F1; } #article header { text-align: left; - border-bottom: 1px solid #222222; } #article header a { text-decoration: none; } -#article article { - border-bottom: 1px solid #222222; -} - .vieworiginal a { - color: #888888; text-decoration: none; } diff --git a/img/dark/checkmark-off.png b/img/dark/checkmark-off.png new file mode 100644 index 0000000000000000000000000000000000000000..efc3439fe7f8955d9c9b44cbe079da77c8f5f4da GIT binary patch literal 267 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`Y)RhkE)4%caKYZ?lYt_f1s;*b z3=G`DAk4@xYmNj^kiEpy*OmP)i?EQj;G7@MCP1MXo-U3d7N_@4e#m)PL7+9>x>32L zMS7uf35)wFj++aVmq@qxUC5h|^Wkg%CFdhY#EKLu&VRS%cYOJRiAmsJKC~?4D@f_VGVbBclU#TvbmF9`=4|CtF_fm9Neh(4CqD%Pgg&e IbxsLQ03l{&`2YX_ literal 0 HcmV?d00001 diff --git a/img/dark/checkmark-on.png b/img/dark/checkmark-on.png new file mode 100644 index 0000000000000000000000000000000000000000..24391c2ee8cc72acee6f4c99177e18ab98d5698b GIT binary patch literal 221 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`Y)RhkE)4%caKYZ?lYt_f1s;*b z3=G`DAk4@xYmNj^kiEpy*OmP)i?EQjmhR_OAY-yTT^vI!PA4Zw6g~L=|34ED-v{D) z<|5Pi|M?l;dm6F$8uQpJaQV!>gZsnJ?ufGye_aENLoPCzu)YT>%y*cQrV_1}VA!%D zjj2sw`AiOHI|14I5j;N~in^SQo-jwA6g?@xyembIfk!aI%<#vq7ND&Rp00i_>zopr E0G=sIqyPW_ literal 0 HcmV?d00001 diff --git a/img/dark/down.png b/img/dark/down.png new file mode 100644 index 0000000000000000000000000000000000000000..41ea9604e57af634d3ce0d7676279f6da52f4259 GIT binary patch literal 223 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`Y)RhkE)4%caKYZ?lYt_f1s;*b z3=G`DAk4@xYmNj^kiEpy*OmP)i?EO-$El^AWk8`EPZ!4!i_>o>I`TCr@UX1bf1vsA ze^C8}e;IqGv`DNFdUV#7@#b8;l_#b%$!rj1V3?U6pZk+pilKmsZAyx^s*P1vK}W|o zg^$Y~-gGPJzZ!jK^{bRa!JE2tTW;Untp816?YzUBPil8C&*VSC0000pP)t-sj`;XK zK0dX&x_W$k%IN5ro0||25FZ~OFE1}#U0uG($%%`LY;A4G+1XA`PNu4=0001tk_XHH z0004WQchCn^^r{)gQ$ng`Q@ z^-ImON!U#fKz$G)nNDZ}6HGsuZWEj~7!p-X27~1wu^$bdxY+(@KrXgFu3*&usDg3( zpD%|c{!inH&d`9)2bxHLar5#or6UGI2P!2dLIIdV*eUIsJQ@MIpYsm-F%Ja95vtQa zl(7vM7tnh{0&)R%CI={J>(?KY zdsYlikGu#l=ookiIK`!YJoOUg`uvE(-wO^V0nG=QnFMJ3O^Cz^+nvC03201)flYuy zuOt!x$TT!t0I&%ts|7U1VOcFei-2G610VucXTs(0g5__+<@bR~X=3t?$TA6Nz7s|! z0nPv7nFO?#2ojHg_O+QsKu47(to}M)ULSb57*h!7DiSTP5nXc;fdJjN+OMt?UbbLd zfbLy>@q)d#*6X4kY$adsMLN0;>xH0YQTeoM({Natrj4rA{mX%{j&0rLn+DLmhG6SU z%7){%X=7_H6*6_#ta2~79oX@}GEAY~_ksRt@O$Fw;eXRRPN0;6#M!+bZ(fe}@9kpy zx4}5g{@4rwh5cIbeC7c-M+zP`;BmRn)~Lwh zq$uU3AmXIJ;-oO6@t5$~idV{6%YG+EZ|jSVywEr^_ga!Nm+|Hf-h`EMDgICSO!wv7 z{97_Tk;U`T`W2ci6Qp??zP8t_6n{{XcP@VmyO(}Lu&3~>%o}bGc3iu@q-6i?YQ|H- zAE&qbW}8mf;;!jol_t8x35w$#sYJ=p00i_>zopr E0IptK0{{R3 literal 0 HcmV?d00001 diff --git a/img/dark/star-off.png b/img/dark/star-off.png new file mode 100644 index 0000000000000000000000000000000000000000..90651b54a1dff1dee91bc8aa79234d053b5d2a81 GIT binary patch literal 330 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`Y)RhkE)4%caKYZ?lYt_f1s;*b z3=G`DAk4@xYmNj^kiEpy*OmP)i?A?*p7^`hAOo&@x;TbdoSr-BVqsH)K+Aq_=7W4X zjeJX3-W=fbVZZ37qo|s|dWkWjG3wy6)R~TMe3NJI6fb+f`*(Zm5*5)&U1vT!#>Kze zKYjasmAjj@l^A6jOamBlU1a`k-dl7&PH^!;p&u+-3s}Mg10%B=q%Sb>e(2~BQ>b~h z-7@__-sAHLMtjV5FqnOlZ-1-qIelroS=Bw)OPN|aPHFA;8+G{leY{G1A6{0OcEGgr z)75z*7y6s7FwR}F_iG*JhHp#fe%>H^>we1lH`3Ccdzbub-M0B!O2e;S8Jo&F#!U;( V#ahNSr~|#o;OXk;vd$@?2>=ekfK>nh literal 0 HcmV?d00001 diff --git a/img/dark/star-on.png b/img/dark/star-on.png new file mode 100644 index 0000000000000000000000000000000000000000..7fc144772d5247254c04c6cb5641d5ee9c0c6716 GIT binary patch literal 277 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`Y)RhkE)4%caKYZ?lYt_f1s;*b z3=G`DAk4@xYmNj^kiEpy*OmP)i?A>w>mpBOcA(HAPZ!4!i_=>tMe-gt5OA5l`rmZ{ zu7d(mY>fdNZ31ehBJGX}QyfECF3;aOMXpfDTQXC{d$)0Q#X=^}xJm1u%B)b9+J1PI zeeb@d%^VfUIcwt#ZXYdF;yS>&gW;f-c*O&~OctXLMdx~5Z>*NBHT2|t^u@M3ODx~S z)BARO)B3xP5g$({hBtqHV#^Tz*kJPK&CNP56<7Wi-W{oPooAP5`oD>v*>=43kSi6q R;staqgQu&X%Q~loCIBQ)V3q&? literal 0 HcmV?d00001 diff --git a/img/dark/up.png b/img/dark/up.png new file mode 100644 index 0000000000000000000000000000000000000000..1679e18fdc9fee9745722e6a1f9b1f33e12ac2bb GIT binary patch literal 225 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`Y)RhkE)4%caKYZ?lYt_f1s;*b z3=G`DAk4@xYmNj^kiEpy*OmP)i?EQTmi*BZlYl~bo-U3d7N_4%I>>oIfycFe33G~y zdA|9Iyi2@w`hiUmQ^fNBK2ZG?r@|5;I?3zPmc{uGCslf~&zo*iP*fo0WwpVokxx~H zpFg@+<)xI!$+#UCDvTO5l)`Tx$hvs%#2bg#{PTqNy*sVXu + + + + - +

logo pochepoche

diff --git a/tpl/home.html b/tpl/home.html index 6fb9444cd..62c77bd35 100644 --- a/tpl/home.html +++ b/tpl/home.html @@ -2,6 +2,7 @@
  • home
  • favorites
  • archive
  • +
  • dark
  • poche it !
  • logout
  • diff --git a/tpl/view.html b/tpl/view.html index 4b8ce60fb..9ba5e208d 100644 --- a/tpl/view.html +++ b/tpl/view.html @@ -15,8 +15,12 @@ + + + + - +
    @@ -24,6 +28,7 @@
    • +
    • dark
    • logout
    • From 2cd263e0bd8a36344e1dac5585b362b25ec19261 Mon Sep 17 00:00:00 2001 From: nicosomb Date: Sat, 20 Apr 2013 10:05:42 +0200 Subject: [PATCH 04/14] =?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(-) diff --git a/inc/store/sqlite.class.php b/inc/store/sqlite.class.php index 51054bc5d..b2ae94a7f 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 +} From 6a02410a9b0edb0d95e5355bc1793043d63d6a10 Mon Sep 17 00:00:00 2001 From: nicosomb Date: Sat, 20 Apr 2013 10:12:22 +0200 Subject: [PATCH 05/14] les versions sombre / claire ne concernent que l'affichage de l'article pour l'instant --- tpl/home.html | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tpl/home.html b/tpl/home.html index 62c77bd35..28db89c20 100644 --- a/tpl/home.html +++ b/tpl/home.html @@ -2,7 +2,6 @@
    • home
    • favorites
    • archive
    • -
    • dark
    • poche it !
    • logout
    @@ -10,4 +9,4 @@
  • by date
  • by title
  • -
    \ No newline at end of file +
    From 8c72b98d9d6f3e8a4d88afbe5f499f115d2d532a Mon Sep 17 00:00:00 2001 From: nicosomb Date: Sat, 20 Apr 2013 10:22:00 +0200 Subject: [PATCH 06/14] =?UTF-8?q?Fixed=20#63=20-=20le=20referer=20n'=C3=A9?= =?UTF-8?q?tait=20plus=20pris=20en=20compte?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- index.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/index.php b/index.php index 9a81a7410..954d92247 100644 --- a/index.php +++ b/index.php @@ -20,6 +20,8 @@ if (!empty($_POST)) { unset($_SESSION['tokens']); } +$ref = empty($_SERVER['HTTP_REFERER']) ? '' : $_SERVER['HTTP_REFERER']; + if (isset($_GET['login'])) { // Login if (!empty($_POST['login']) && !empty($_POST['password'])) { @@ -34,7 +36,7 @@ if (isset($_GET['login'])) { } session_regenerate_id(true); - MyTool::redirect(); + MyTool::redirect($ref); } logm('login failed'); die("Login failed !"); @@ -55,7 +57,6 @@ $action = (isset ($_REQUEST['action'])) ? htmlentities($_REQUEST['ac $_SESSION['sort'] = (isset ($_REQUEST['sort'])) ? htmlentities($_REQUEST['sort']) : 'id'; $id = (isset ($_REQUEST['id'])) ? htmlspecialchars($_REQUEST['id']) : ''; $url = (isset ($_GET['url'])) ? $_GET['url'] : ''; -$ref = empty($_SERVER['HTTP_REFERER']) ? '' : $_SERVER['HTTP_REFERER']; $tpl->assign('isLogged', Session::isLogged()); $tpl->assign('referer', $ref); @@ -69,4 +70,4 @@ if (Session::isLogged()) { } else { $tpl->draw('login'); -} \ No newline at end of file +} From f281635c9a60b09a51fa9735337ff1eb0ab581f8 Mon Sep 17 00:00:00 2001 From: nicosomb Date: Sat, 20 Apr 2013 10:27:37 +0200 Subject: [PATCH 07/14] il manquait un
    --- tpl/login.html | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tpl/login.html b/tpl/login.html index d3139ab36..8b2f80f8b 100644 --- a/tpl/login.html +++ b/tpl/login.html @@ -1,4 +1,5 @@ {include="head"} +

    login to your poche

    @@ -20,4 +21,4 @@ -{include="footer"} \ No newline at end of file +{include="footer"} From bbff4b57a9692580c87135055928851ca368ab4f Mon Sep 17 00:00:00 2001 From: nicosomb Date: Sun, 21 Apr 2013 10:12:31 +0200 Subject: [PATCH 08/14] Fixed #65 - sur le form de login, focus au champ login --- tpl/login.html | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tpl/login.html b/tpl/login.html index 8b2f80f8b..b78b72e1e 100644 --- a/tpl/login.html +++ b/tpl/login.html @@ -21,4 +21,7 @@ + {include="footer"} From cddd8e90f4f6a5312acef88b70e386fca08d36a9 Mon Sep 17 00:00:00 2001 From: nicosomb Date: Sun, 21 Apr 2013 12:17:56 +0200 Subject: [PATCH 09/14] modif tpl --- tpl/entries.html | 4 +++- tpl/footer.html | 4 +--- tpl/head.html | 7 +------ tpl/home.html | 6 +++++- tpl/login.html | 6 +++++- tpl/view.html | 9 +-------- 6 files changed, 16 insertions(+), 20 deletions(-) diff --git a/tpl/entries.html b/tpl/entries.html index 648e1ce9d..8526a3c9d 100644 --- a/tpl/entries.html +++ b/tpl/entries.html @@ -1,3 +1,4 @@ +
    {loop="entries"}
    @@ -13,4 +14,5 @@
    - {/loop} \ No newline at end of file + {/loop} +
    \ No newline at end of file diff --git a/tpl/footer.html b/tpl/footer.html index 04bedabcb..b8bd755c8 100644 --- a/tpl/footer.html +++ b/tpl/footer.html @@ -1,6 +1,4 @@ -
    -
    - +
    diff --git a/tpl/head.html b/tpl/head.html index 66b6895d7..e95f61001 100644 --- a/tpl/head.html +++ b/tpl/head.html @@ -19,9 +19,4 @@ - - -
    -

    logo pochepoche

    -
    -
    \ No newline at end of file + \ No newline at end of file diff --git a/tpl/home.html b/tpl/home.html index 28db89c20..752a571b8 100644 --- a/tpl/home.html +++ b/tpl/home.html @@ -1,3 +1,8 @@ + +
    +

    logo pochepoche

    +
    +
    -
    diff --git a/tpl/login.html b/tpl/login.html index b78b72e1e..12927692e 100644 --- a/tpl/login.html +++ b/tpl/login.html @@ -1,5 +1,9 @@ {include="head"} -
    + +
    +

    logo pochepoche

    +
    +

    login to your poche

    diff --git a/tpl/view.html b/tpl/view.html index 9ba5e208d..4384631b4 100644 --- a/tpl/view.html +++ b/tpl/view.html @@ -47,13 +47,6 @@
    -
    {include="js"} - - - - - \ No newline at end of file + {include="footer"} \ No newline at end of file From a58cd56c4fdc9cb86a4b7c056ff31d39cf1cfe8c Mon Sep 17 00:00:00 2001 From: nicosomb Date: Sun, 21 Apr 2013 12:18:42 +0200 Subject: [PATCH 10/14] template pour la config et les outils de poche --- tpl/config.tpl | 0 tpl/tools.html | 0 2 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 tpl/config.tpl create mode 100644 tpl/tools.html diff --git a/tpl/config.tpl b/tpl/config.tpl new file mode 100644 index 000000000..e69de29bb diff --git a/tpl/tools.html b/tpl/tools.html new file mode 100644 index 000000000..e69de29bb From 016989b79af1f950f449e33c76f368c307c28c19 Mon Sep 17 00:00:00 2001 From: nicosomb Date: Sun, 21 Apr 2013 13:11:14 +0200 Subject: [PATCH 11/14] contenu de la page de config --- inc/functions.php | 9 +++++++++ js/poche.js | 1 - tpl/config.html | 6 ++++++ tpl/config.tpl | 0 tpl/home.html | 4 +++- tpl/tools.html | 0 6 files changed, 18 insertions(+), 2 deletions(-) create mode 100644 tpl/config.html delete mode 100644 tpl/config.tpl delete mode 100644 tpl/tools.html diff --git a/inc/functions.php b/inc/functions.php index df7e9b17f..10005dfe1 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); diff --git a/js/poche.js b/js/poche.js index d27ecbbac..97d9911dc 100644 --- a/js/poche.js +++ b/js/poche.js @@ -23,7 +23,6 @@ function toggle_archive(element, id, view_article) { } function sort_links(view, sort) { - //$('#content').load('index.php', { view: view, sort: sort, full_head: 'no' } ); $.get('index.php', { view: view, sort: sort, full_head: 'no' }, function(data) { $('#content').html(data); }); diff --git a/tpl/config.html b/tpl/config.html new file mode 100644 index 000000000..a19a84fea --- /dev/null +++ b/tpl/config.html @@ -0,0 +1,6 @@ +
    +

    Bookmarklet

    +

    Thanks to the bookmarklet, you will be able to easily add a link to your poche. If you don't know how use a bookmarklet, have a look here.

    +

    Drag & drop this link to your bookmarks bar and have fun with poche.

    +

    poche it !

    +
    \ No newline at end of file diff --git a/tpl/config.tpl b/tpl/config.tpl deleted file mode 100644 index e69de29bb..000000000 diff --git a/tpl/home.html b/tpl/home.html index 752a571b8..33aec78c5 100644 --- a/tpl/home.html +++ b/tpl/home.html @@ -7,10 +7,12 @@
  • home
  • favorites
  • archive
  • -
  • poche it !
  • +
  • config
  • logout
  • + {if condition="isset($entries)"}
    • by date
    • by title
    + {/if} \ No newline at end of file diff --git a/tpl/tools.html b/tpl/tools.html deleted file mode 100644 index e69de29bb..000000000 From 44e77bfa2481090e559b56fd8ffbe5b175ab55ca Mon Sep 17 00:00:00 2001 From: nicosomb Date: Sun, 21 Apr 2013 18:09:25 +0200 Subject: [PATCH 12/14] =?UTF-8?q?Fixed=20#55=20-=20export=20des=20donn?= =?UTF-8?q?=C3=A9es=20au=20format=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 ++++ tpl/config.html | 2 ++ tpl/export.html | 1 + 5 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 tpl/export.html diff --git a/inc/functions.php b/inc/functions.php index 10005dfe1..abf70a934 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 b2ae94a7f..d5208a295 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 ae3cb3411..360ff7c20 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) { } diff --git a/tpl/config.html b/tpl/config.html index a19a84fea..7d1c6afe6 100644 --- a/tpl/config.html +++ b/tpl/config.html @@ -3,4 +3,6 @@

    Thanks to the bookmarklet, you will be able to easily add a link to your poche. If you don't know how use a bookmarklet, have a look here.

    Drag & drop this link to your bookmarks bar and have fun with poche.

    poche it !

    +

    Export

    +

    Click here to export your poche datas.

    \ No newline at end of file diff --git a/tpl/export.html b/tpl/export.html new file mode 100644 index 000000000..d22d05fc9 --- /dev/null +++ b/tpl/export.html @@ -0,0 +1 @@ +export {$export} \ No newline at end of file From 6f87a19714057e370a6b970bbfb82af5abd968f9 Mon Sep 17 00:00:00 2001 From: nicosomb Date: Sun, 21 Apr 2013 18:42:20 +0200 Subject: [PATCH 13/14] Fixed #64 - nettoyage de MyTool --- inc/MyTool.class.php | 9 +++++++++ inc/functions.php | 25 +++++++++++++++++++------ index.php | 3 ++- 3 files changed, 30 insertions(+), 7 deletions(-) diff --git a/inc/MyTool.class.php b/inc/MyTool.class.php index 8206f3f7f..1f5051a43 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 abf70a934..ec5b3d6a3 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; diff --git a/index.php b/index.php index 954d92247..f64a04187 100644 --- a/index.php +++ b/index.php @@ -11,6 +11,7 @@ include dirname(__FILE__).'/inc/config.php'; # initialize session +myTool::initPhp(); Session::init(); # XSRF protection with token if (!empty($_POST)) { @@ -61,7 +62,7 @@ $url = (isset ($_GET['url'])) ? $_GET['url'] : ''; $tpl->assign('isLogged', Session::isLogged()); $tpl->assign('referer', $ref); $tpl->assign('view', $view); -$tpl->assign('poche_url', get_poche_url()); +$tpl->assign('poche_url', myTool::getUrl()); $tpl->assign('title', 'poche, a read it later open source system'); if (Session::isLogged()) { From f0070a15e4725255dad967bde76155a39d189631 Mon Sep 17 00:00:00 2001 From: nicosomb Date: Sun, 21 Apr 2013 19:32:19 +0200 Subject: [PATCH 14/14] =?UTF-8?q?flash=20messages=20pour=20indiquer=20qu'u?= =?UTF-8?q?ne=20action=20s'est=20bien=20effectu=C3=A9e=20ou=20qu'il=20y=20?= =?UTF-8?q?a=20eu=20une=20erreur?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- css/style.css | 15 +++ img/messages/close.png | Bin 0 -> 662 bytes img/messages/cross.png | Bin 0 -> 655 bytes img/messages/help.png | Bin 0 -> 786 bytes img/messages/tick.png | Bin 0 -> 537 bytes img/messages/warning.png | Bin 0 -> 666 bytes inc/class.messages.php | 231 +++++++++++++++++++++++++++++++++++++++ inc/config.php | 9 +- inc/functions.php | 10 +- index.php | 3 +- tpl/home.html | 3 +- tpl/messages.html | 1 + 12 files changed, 265 insertions(+), 7 deletions(-) create mode 100755 img/messages/close.png create mode 100755 img/messages/cross.png create mode 100755 img/messages/help.png create mode 100755 img/messages/tick.png create mode 100755 img/messages/warning.png create mode 100644 inc/class.messages.php create mode 100644 tpl/messages.html diff --git a/css/style.css b/css/style.css index 7fc8f056b..36ebf85d2 100644 --- a/css/style.css +++ b/css/style.css @@ -199,4 +199,19 @@ body.article { } } +/*** ***/ +/*** MESSAGES ***/ +.messages { width: 100%; -moz-border-radius: 4px; border-radius: 4px; display: block; padding: 10px 0; margin: 10px auto 10px; clear: both; } +.messages a.closeMessage { margin: -14px -8px 0 0; display:none; width: 16px; height: 16px; float: right; background: url(../img/messages/close.png) no-repeat; } +/*.messages:hover a.closeMessage { visibility:visible; }*/ +.messages p { margin: 3px 0 3px 10px !important; padding: 0 10px 0 23px !important; font-size: 14px; line-height: 16px; } +.messages.error { border: 1px solid #C42608; color: #c00 !important; background: #FFF0EF; } +.messages.error p { background: url(../img/messages/cross.png ) no-repeat 0px 50%; color:#c00 !important; } +.messages.success {background: #E0FBCC; border: 1px solid #6DC70C; } +.messages.success p { background: url(../img/messages/tick.png) no-repeat 0px 50%; color: #2B6301 !important; } +.messages.warning { background: #FFFCD3; border: 1px solid #EBCD41; color: #000; } +.messages.warning p { background: url(../img/messages/warning.png ) no-repeat 0px 50%; color: #5F4E01; } +.messages.information, .messages.info { background: #DFEBFB; border: 1px solid #82AEE7; } +.messages.information p, .messages.info p { background: url(../img/messages/help.png ) no-repeat 0px 50%; color: #064393; } +.messages.information a { text-decoration: underline; } \ No newline at end of file diff --git a/img/messages/close.png b/img/messages/close.png new file mode 100755 index 0000000000000000000000000000000000000000..731aa018f240a80ed89ed48e386f8a364089e99e GIT binary patch literal 662 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 A&j0`b literal 0 HcmV?d00001 diff --git a/inc/class.messages.php b/inc/class.messages.php new file mode 100644 index 000000000..6d515bf69 --- /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 cf3529cb1..9d4b7fae2 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 ec5b3d6a3..205f39681 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: diff --git a/index.php b/index.php index f64a04187..6eefd277e 100644 --- a/index.php +++ b/index.php @@ -10,9 +10,8 @@ include dirname(__FILE__).'/inc/config.php'; -# initialize session myTool::initPhp(); -Session::init(); + # XSRF protection with token if (!empty($_POST)) { if (!Session::isToken($_POST['token'])) { diff --git a/tpl/home.html b/tpl/home.html index 33aec78c5..ad8819977 100644 --- a/tpl/home.html +++ b/tpl/home.html @@ -15,4 +15,5 @@
  • by date
  • by title
  • - {/if} \ No newline at end of file + {/if} + {include="messages"} \ No newline at end of file diff --git a/tpl/messages.html b/tpl/messages.html new file mode 100644 index 000000000..87af259b9 --- /dev/null +++ b/tpl/messages.html @@ -0,0 +1 @@ +
    display(); ?>
    \ No newline at end of file