From 263d6c6756a2549100ae186042f157ff64944bfa Mon Sep 17 00:00:00 2001 From: nicosomb Date: Mon, 15 Apr 2013 09:58:34 +0200 Subject: factorisation code --- index.php | 64 +++------------------------------------------------------------ 1 file changed, 3 insertions(+), 61 deletions(-) (limited to 'index.php') diff --git a/index.php b/index.php index ef18254a..1cb32f58 100755 --- a/index.php +++ b/index.php @@ -11,70 +11,12 @@ include dirname(__FILE__).'/inc/config.php'; $action = (isset ($_GET['action'])) ? htmlspecialchars($_GET['action']) : ''; -$view = (isset ($_GET['view'])) ? htmlspecialchars($_GET['view']) : ''; +$view = (isset ($_GET['view'])) ? htmlspecialchars($_GET['view']) : 'index'; $id = (isset ($_GET['id'])) ? htmlspecialchars($_GET['id']) : ''; $url = (isset ($_GET['url'])) ? $_GET['url'] : ''; -switch ($action) -{ - case 'add': - if ($url == '') - continue; - - $parametres_url = prepare_url($url); - $sql_action = 'INSERT INTO entries ( url, title, content ) VALUES (?, ?, ?)'; - $params_action = array($url, $parametres_url['title'], $parametres_url['content']); - break; - case 'delete': - $sql_action = "DELETE FROM entries WHERE id=?"; - $params_action = array($id); - break; - default: - break; -} - -try -{ - # action query - if (isset($sql_action)) - { - $query = $db->getHandle()->prepare($sql_action); - $query->execute($params_action); - } -} -catch (Exception $e) -{ - die('action query error : '.$e->getMessage()); -} - -switch ($view) -{ - case 'archive': - $sql = "SELECT * FROM entries WHERE is_read=? ORDER BY id desc"; - $params = array(-1); - break; - case 'fav' : - $sql = "SELECT * FROM entries WHERE is_fav=? ORDER BY id desc"; - $params = array(-1); - break; - default: - $sql = "SELECT * FROM entries WHERE is_read=? ORDER BY id desc"; - $params = array(0); - $view = 'index'; - break; -} - -# view query -try -{ - $query = $db->getHandle()->prepare($sql); - $query->execute($params); - $entries = $query->fetchAll(); -} -catch (Exception $e) -{ - die('view query error : '.$e->getMessage()); -} +action_to_do($action, $id); +$entries = display_view($view); $tpl->assign('title', 'poche, a read it later open source system'); $tpl->assign('view', $view); -- cgit v1.2.3