From: Nicolas Lœuillet Date: Mon, 5 Aug 2013 19:56:32 +0000 (+0200) Subject: new design, pagination & more X-Git-Tag: 1.0-beta1~3^2~15 X-Git-Url: https://git.immae.eu/?a=commitdiff_plain;h=6a361945eaf86a978b82bd6fb3442fe64428d9df;p=github%2Fwallabag%2Fwallabag.git new design, pagination & more --- diff --git a/CREDITS b/CREDITS index 9c49176f..d6874a7b 100644 --- a/CREDITS +++ b/CREDITS @@ -6,11 +6,9 @@ poche is based on : * PHP Simple HTML DOM Parser (for Pocket import) http://simplehtmldom.sourceforge.net/ * Session https://github.com/tontof/kriss_feed/blob/master/src/class/Session.php * Twig http://twig.sensiolabs.org +* Flash messages https://github.com/plasticbrain/PHP-Flash-Messages +* Pagination https://github.com/daveismyname/pagination poche is developed by Nicolas Lœuillet under the Do What the Fuck You Want to Public License -Contributors : -Nicolas Lœuillet aka nico_somb -Tom.C. aka tmos -PeaceCopathe -Gregoire_M \ No newline at end of file +Contributors : https://github.com/inthepoche/poche/graphs/contributors \ No newline at end of file diff --git a/inc/3rdparty/paginator.php b/inc/3rdparty/paginator.php new file mode 100644 index 00000000..e8801555 --- /dev/null +++ b/inc/3rdparty/paginator.php @@ -0,0 +1,198 @@ +_instance = $instance; + $this->_perPage = $perPage; + $this->set_instance(); + } + + /** + * get_start + * + * creates the starting point for limiting the dataset + * @return numeric + */ + private function get_start(){ + return ($this->_page * $this->_perPage) - $this->_perPage; + } + + /** + * set_instance + * + * sets the instance parameter, if numeric value is 0 then set to 1 + * + * @var numeric + */ + private function set_instance(){ + $this->_page = (int) (!isset($_GET[$this->_instance]) ? 1 : $_GET[$this->_instance]); + $this->_page = ($this->_page == 0 ? 1 : $this->_page); + } + + /** + * set_total + * + * collect a numberic value and assigns it to the totalRows + * + * @var numeric + */ + public function set_total($_totalRows){ + $this->_totalRows = $_totalRows; + } + + /** + * get_limit + * + * returns the limit for the data source, calling the get_start method and passing in the number of items perp page + * + * @return string + */ + public function get_limit(){ + return "LIMIT ".$this->get_start().",$this->_perPage"; + } + + /** + * page_links + * + * create the html links for navigating through the dataset + * + * @var sting $path optionally set the path for the link + * @var sting $ext optionally pass in extra parameters to the GET + * @return string returns the html menu + */ + public function page_links($path='?',$ext=null) + { + $adjacents = "2"; + $prev = $this->_page - 1; + $next = $this->_page + 1; + $lastpage = ceil($this->_totalRows/$this->_perPage); + $lpm1 = $lastpage - 1; + + $pagination = ""; + if($lastpage > 1) + { + $pagination .= "\n"; + } + + + return $pagination; + } +} diff --git a/inc/poche/Poche.class.php b/inc/poche/Poche.class.php index 80bf6919..789d6647 100644 --- a/inc/poche/Poche.class.php +++ b/inc/poche/Poche.class.php @@ -13,11 +13,13 @@ class Poche public $store; public $tpl; public $messages; + public $pagination; function __construct($storage_type) { $this->store = new $storage_type(); $this->init(); + $this->messages = new Messages(); # installation if(!$this->store->isInstalled()) @@ -46,6 +48,8 @@ class Poche $filter = new Twig_SimpleFilter('getDomain', 'Tools::getDomain'); $this->tpl->addFilter($filter); + $this->pagination = new Paginator(PAGINATION, 'p'); + Tools::initPhp(); Session::init(); } @@ -54,7 +58,7 @@ class Poche { Tools::logm('poche still not installed'); echo $this->tpl->render('install.twig', array( - 'token' => Session::getToken(), + 'token' => Session::getToken() )); if (isset($_GET['install'])) { if (($_POST['password'] == $_POST['password_repeat']) @@ -62,6 +66,11 @@ class Poche # let's rock, install poche baby ! $this->store->install($_POST['login'], Tools::encodeString($_POST['password'] . $_POST['login'])); Session::logout(); + Tools::logm('poche is now installed'); + Tools::redirect(); + } + else { + Tools::logm('error during installation'); Tools::redirect(); } } @@ -89,30 +98,32 @@ class Poche if (DOWNLOAD_PICTURES) { $content = filtre_picture($parametres_url['content'], $url->getUrl(), $last_id); } - #$msg->add('s', _('the link has been added successfully')); + $this->messages->add('s', _('the link has been added successfully')); } else { - #$msg->add('e', _('error during insertion : the link wasn\'t added')); + $this->messages->add('e', _('error during insertion : the link wasn\'t added')); Tools::logm('error during insertion : the link wasn\'t added'); } } else { - #$msg->add('e', _('error during url preparation : the link wasn\'t added')); + $this->messages->add('e', _('error during fetching content : the link wasn\'t added')); Tools::logm('error during content fetch'); } + Tools::redirect(); break; case 'delete': if ($this->store->deleteById($id)) { if (DOWNLOAD_PICTURES) { remove_directory(ABS_PATH . $id); } - #$msg->add('s', _('the link has been deleted successfully')); + $this->messages->add('s', _('the link has been deleted successfully')); Tools::logm('delete link #' . $id); } else { - #$msg->add('e', _('the link wasn\'t deleted')); + $this->messages->add('e', _('the link wasn\'t deleted')); Tools::logm('error : can\'t delete link #' . $id); } + Tools::redirect(); break; case 'toggle_fav' : $this->store->favoriteById($id); @@ -169,9 +180,14 @@ class Poche break; default: # home view $entries = $this->store->getEntriesByView($view); + $this->pagination->set_total(count($entries)); + $page_links = $this->pagination->page_links('?view=' . $view . '&sort=' . $_SESSION['sort'] . '&'); + $datas = $this->store->getEntriesByView($view, $this->pagination->get_limit()); $tpl_vars = array( - 'entries' => $entries, + 'entries' => $datas, + 'page_links' => $page_links, ); + Tools::logm('display ' . $view . ' view'); break; } @@ -183,6 +199,7 @@ class Poche if (MODE_DEMO) { $this->messages->add('i', 'in demo mode, you can\'t update your password'); Tools::logm('in demo mode, you can\'t do this'); + Tools::redirect('?view=config'); } else { if (isset($_POST['password']) && isset($_POST['password_repeat'])) { @@ -195,6 +212,7 @@ class Poche } else { $this->messages->add('e', 'the two fields have to be filled & the password must be the same in the two fields'); + Tools::redirect('?view=config'); } } } @@ -205,7 +223,7 @@ class Poche if (!empty($_POST['login']) && !empty($_POST['password'])) { if (Session::login($_SESSION['login'], $_SESSION['pass'], $_POST['login'], Tools::encodeString($_POST['password'] . $_POST['login']))) { Tools::logm('login successful'); - $this->messages->add('s', 'login successful, welcome to your poche'); + $this->messages->add('s', 'welcome to your poche'); if (!empty($_POST['longlastingsession'])) { $_SESSION['longlastingsession'] = 31536000; $_SESSION['expires_on'] = time() + $_SESSION['longlastingsession']; @@ -216,11 +234,11 @@ class Poche session_regenerate_id(true); Tools::redirect($referer); } - $this->messages->add('e', 'login failed, bad login or password'); + $this->messages->add('e', 'login failed: bad login or password'); Tools::logm('login failed'); Tools::redirect(); } else { - $this->messages->add('e', 'login failed, you have to fill all fields'); + $this->messages->add('e', 'login failed: you have to fill all fields'); Tools::logm('login failed'); Tools::redirect(); } @@ -228,7 +246,7 @@ class Poche public function logout() { - $this->messages->add('s', 'logout successful, see you soon!'); + $this->messages->add('s', 'see you soon!'); Tools::logm('logout'); Session::logout(); Tools::redirect(); diff --git a/inc/poche/Tools.class.php b/inc/poche/Tools.class.php index 7bc8830a..8b339ea5 100644 --- a/inc/poche/Tools.class.php +++ b/inc/poche/Tools.class.php @@ -197,7 +197,7 @@ class Tools { if (DEBUG_POCHE) { $t = strval(date('Y/m/d_H:i:s')) . ' - ' . $_SERVER["REMOTE_ADDR"] . ' - ' . strval($message) . "\n"; - file_put_contents('./log.txt', $t, FILE_APPEND); + file_put_contents(CACHE . '/log.txt', $t, FILE_APPEND); } } diff --git a/inc/poche/config.inc.php b/inc/poche/config.inc.php index d49df190..d91a44be 100644 --- a/inc/poche/config.inc.php +++ b/inc/poche/config.inc.php @@ -8,7 +8,7 @@ * @license http://www.wtfpl.net/ see COPYING file */ -define ('POCHE_VERSION', '1.0-alpha'); +define ('POCHE_VERSION', '1.0-beta'); define ('MODE_DEMO', FALSE); define ('DEBUG_POCHE', FALSE); define ('CONVERT_LINKS_FOOTNOTES', FALSE); @@ -22,24 +22,26 @@ define ('TPL', './tpl'); define ('LOCALE', './locale'); define ('CACHE', './cache'); define ('LANG', 'fr_FR.UTF8'); +define ('PAGINATION', '10'); +define ('THEME', 'light'); $storage_type = 'sqlite'; # sqlite, mysql, (file, not yet) # /!\ Be careful if you change the lines below /!\ require_once './inc/poche/Tools.class.php'; require_once './inc/poche/Url.class.php'; +require_once './inc/3rdparty/Session.class.php'; +require_once './inc/3rdparty/class.messages.php'; require_once './inc/poche/Poche.class.php'; require_once './inc/3rdparty/Readability.php'; require_once './inc/3rdparty/Encoding.php'; -require_once './inc/3rdparty/Session.class.php'; require_once './inc/store/store.class.php'; require_once './inc/store/' . $storage_type . '.class.php'; require_once './vendor/autoload.php'; require_once './inc/3rdparty/simple_html_dom.php'; -require_once './inc/3rdparty/class.messages.php'; +require_once './inc/3rdparty/paginator.php'; if (DOWNLOAD_PICTURES) { require_once './inc/poche/pochePictures.php'; } -$poche = new Poche($storage_type); -$poche->messages = new Messages(); \ No newline at end of file +$poche = new Poche($storage_type); \ No newline at end of file diff --git a/inc/store/sqlite.class.php b/inc/store/sqlite.class.php index a15bc095..3e391e40 100644 --- a/inc/store/sqlite.class.php +++ b/inc/store/sqlite.class.php @@ -114,7 +114,7 @@ class Sqlite extends Store { return $entry[0]; } - public function getEntriesByView($view) { + public function getEntriesByView($view, $limit = '') { parent::__construct(); switch ($_SESSION['sort']) @@ -152,6 +152,8 @@ class Sqlite extends Store { break; } + $sql .= ' ' . $limit; + $query = $this->executeQuery($sql, $params); $entries = $query->fetchAll(); diff --git a/index.php b/index.php index dd70a989..98ada1bd 100644 --- a/index.php +++ b/index.php @@ -62,7 +62,8 @@ else { } # because messages can be added in $poche->action(), we have to add this entry now (we can add it before) -$tpl_vars = array_merge($tpl_vars, array('messages' => $poche->messages->display())); +$messages = $poche->messages->display('all', FALSE); +$tpl_vars = array_merge($tpl_vars, array('messages' => $messages)); # Aaaaaaand action ! echo $poche->tpl->render($tpl_file, $tpl_vars); \ No newline at end of file diff --git a/tpl/_footer.twig b/tpl/_footer.twig index b1d7b8d4..a541e6ee 100644 --- a/tpl/_footer.twig +++ b/tpl/_footer.twig @@ -1,3 +1,3 @@ -