From 8cbb2a88024969f7efd90f8053f3b0805fa2f8fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Sat, 3 Aug 2013 08:25:11 +0200 Subject: [PATCH] twig implementation --- css/style.css | 19 +++--------------- inc/config.php | 8 +++++--- inc/poche/pocheCore.php | 30 +++++++++++++++++----------- index.php | 23 +++++++++++---------- tpl/home.twig | 44 ++++++++++++++++++++++++++++++----------- tpl/layout.twig | 42 +++++---------------------------------- tpl/login.twig | 10 ++++++++++ 7 files changed, 86 insertions(+), 90 deletions(-) diff --git a/css/style.css b/css/style.css index 28e18b9..69e3749 100644 --- a/css/style.css +++ b/css/style.css @@ -205,19 +205,6 @@ 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; } +.messages { + +} \ No newline at end of file diff --git a/inc/config.php b/inc/config.php index c4898cc..b78147a 100644 --- a/inc/config.php +++ b/inc/config.php @@ -10,7 +10,7 @@ define ('POCHE_VERSION', '0.3'); define ('MODE_DEMO', FALSE); -define ('DEBUG_POCHE', TRUE); +define ('DEBUG_POCHE', FALSE); define ('CONVERT_LINKS_FOOTNOTES', FALSE); define ('REVERT_FORCED_PARAGRAPH_ELEMENTS', FALSE); define ('DOWNLOAD_PICTURES', FALSE); @@ -21,7 +21,7 @@ define ('LOCALE', './locale'); define ('CACHE', './cache'); define ('LANG', 'fr_FR.UTF8'); -$storage_type = 'sqlite'; # sqlite or file +$storage_type = 'sqlite'; # sqlite, file # /!\ Be careful if you change the lines below /!\ @@ -75,4 +75,6 @@ if(!$store->isInstalled()) } $_SESSION['login'] = (isset ($_SESSION['login'])) ? $_SESSION['login'] : $store->getLogin(); -$_SESSION['pass'] = (isset ($_SESSION['pass'])) ? $_SESSION['pass'] : $store->getPassword(); \ No newline at end of file +$_SESSION['pass'] = (isset ($_SESSION['pass'])) ? $_SESSION['pass'] : $store->getPassword(); + +pocheTools::initPhp(); \ No newline at end of file diff --git a/inc/poche/pocheCore.php b/inc/poche/pocheCore.php index e68696a..3e32c4a 100644 --- a/inc/poche/pocheCore.php +++ b/inc/poche/pocheCore.php @@ -134,10 +134,12 @@ function fetch_url_content($url) return FALSE; } -function display_view($view, $id = 0, $full_head = 'yes') +function display_view($view, $id = 0) { global $tpl, $store; + $tpl_vars = array(); + switch ($view) { case 'install': @@ -186,21 +188,25 @@ function display_view($view, $id = 0, $full_head = 'yes') break; default: # home view $entries = $store->getEntriesByView($view); - $tpl->assign('entries', $entries); + $tpl_vars = array( + 'entries' => $entries, + ); - if ($full_head == 'yes') { - $tpl->assign('load_all_js', 1); - $tpl->draw('head'); - $tpl->draw('home'); - } + // if ($full_head == 'yes') { + // $tpl->assign('load_all_js', 1); + // $tpl->draw('head'); + // $tpl->draw('home'); + // } - $tpl->draw('entries'); - if ($full_head == 'yes') { - $tpl->draw('js'); - $tpl->draw('footer'); - } + // $tpl->draw('entries'); + // if ($full_head == 'yes') { + // $tpl->draw('js'); + // $tpl->draw('footer'); + // } break; } + + return $tpl_vars; } /** diff --git a/index.php b/index.php index 4962639..f0a8aef 100644 --- a/index.php +++ b/index.php @@ -10,12 +10,12 @@ include dirname(__FILE__).'/inc/config.php'; -pocheTools::initPhp(); +$errors = array(); # XSRF protection with token if (!empty($_POST)) { if (!Session::isToken($_POST['token'])) { - die(_('Wrong token.')); + die(_('Wrong token')); } unset($_SESSION['tokens']); } @@ -23,10 +23,11 @@ if (!empty($_POST)) { $referer = empty($_SERVER['HTTP_REFERER']) ? '' : $_SERVER['HTTP_REFERER']; if (isset($_GET['login'])) { - // Login if (!empty($_POST['login']) && !empty($_POST['password'])) { if (Session::login($_SESSION['login'], $_SESSION['pass'], $_POST['login'], encode_string($_POST['password'] . $_POST['login']))) { pocheTools::logm('login successful'); + $errors[]['value'] = _('login successful'); + if (!empty($_POST['longlastingsession'])) { $_SESSION['longlastingsession'] = 31536000; $_SESSION['expires_on'] = time() + $_SESSION['longlastingsession']; @@ -35,11 +36,10 @@ if (isset($_GET['login'])) { session_set_cookie_params(0); // when browser closes } session_regenerate_id(true); - pocheTools::redirect($referer); } pocheTools::logm('login failed'); - die(_("Login failed !")); + $errors[]['value'] = _('Login failed !'); } else { pocheTools::logm('login failed'); } @@ -67,7 +67,7 @@ elseif (isset($_GET['config'])) { } # Traitement des paramètres et déclenchement des actions -$view = (isset ($_REQUEST['view'])) ? htmlentities($_REQUEST['view']) : 'index'; +$view = (isset ($_REQUEST['view'])) ? htmlentities($_REQUEST['view']) : 'home'; $full_head = (isset ($_REQUEST['full_head'])) ? htmlentities($_REQUEST['full_head']) : 'yes'; $action = (isset ($_REQUEST['action'])) ? htmlentities($_REQUEST['action']) : ''; $_SESSION['sort'] = (isset ($_REQUEST['sort'])) ? htmlentities($_REQUEST['sort']) : 'id'; @@ -75,20 +75,23 @@ $id = (isset ($_REQUEST['id'])) ? htmlspecialchars($_REQUEST['id $url = (isset ($_GET['url'])) ? $_GET['url'] : ''; $tpl_vars = array( - 'isLogged' => Session::isLogged(), 'referer' => $referer, 'view' => $view, 'poche_url' => pocheTools::getUrl(), 'demo' => MODE_DEMO, 'title' => _('poche, a read it later open source system'), + 'token' => Session::getToken(), + 'errors' => $errors, ); +$tpl_file = 'home.twig'; + if (Session::isLogged()) { action_to_do($action, $url, $id); - display_view($view, $id, $full_head); + $tpl_vars = array_merge($tpl_vars, display_view($view, $id)); } else { - $template = $twig->loadTemplate('login.twig'); + $tpl_file = 'login.twig'; } -echo $template->render($tpl_vars); \ No newline at end of file +echo $twig->render($tpl_file, $tpl_vars); \ No newline at end of file diff --git a/tpl/home.twig b/tpl/home.twig index 8b602a2..7b5b88a 100644 --- a/tpl/home.twig +++ b/tpl/home.twig @@ -1,21 +1,41 @@ - -
-

logo pochepoche

-
-
+{% extends "layout.twig" %} + +{% block title %}Home{% endblock %} {% block menu %} {% endblock %} {% block precontent %} {% endblock %} - {include="messages"} \ No newline at end of file +{% block content %} +
+ {% for entry in entries %} +
+ +

+ {{ entry.title|e }} +

+
+
    +
  • +
  • +
  • +
  • +
  • +
+
+
{{ entry.url|e }}
+
+
+ {% endfor %} +
+{% endblock %} \ No newline at end of file diff --git a/tpl/layout.twig b/tpl/layout.twig index c5f52bb..9dc83ef 100644 --- a/tpl/layout.twig +++ b/tpl/layout.twig @@ -9,50 +9,18 @@ {% block title %}{% endblock %} - poche - - - - - - - - - - - + {% include '_head.twig' %} + {% include '_bookmarklet.twig' %} -
-

logo pochepoche

-
+ {% include '_top.twig' %}
{% block menu %}{% endblock %} {% block precontent %}{% endblock %} + {% block messages %}{% endblock %} {% block content %}{% endblock %} {% block js %}{% endblock %}
- - + {% include '_footer.twig' %} \ No newline at end of file diff --git a/tpl/login.twig b/tpl/login.twig index 390718b..c95a5f0 100644 --- a/tpl/login.twig +++ b/tpl/login.twig @@ -1,5 +1,15 @@ {% extends "layout.twig" %} + {% block title %}Login{% endblock %} +{% block messages %} +
+
    + {% for error in errors %} +
  • {{ error.value|e }}
  • + {% endfor %} +
+
+{% endblock %} {% block content %}