1
0
Fork 0
mirror of https://github.com/wallabag/wallabag.git synced 2025-08-01 17:38:38 +00:00

new design, pagination & more

This commit is contained in:
Nicolas Lœuillet 2013-08-05 21:56:32 +02:00
parent 55821e04c1
commit 6a361945ea
31 changed files with 467 additions and 371 deletions

198
inc/3rdparty/paginator.php vendored Normal file
View file

@ -0,0 +1,198 @@
<?php
/*
* PHP Pagination Class
*
* @author David Carr - dave@daveismyname.com - http://www.daveismyname.com
* @version 1.0
* @date October 20, 2013
*/
class Paginator{
/**
* set the number of items per page.
*
* @var numeric
*/
private $_perPage;
/**
* set get parameter for fetching the page number
*
* @var string
*/
private $_instance;
/**
* sets the page number.
*
* @var numeric
*/
private $_page;
/**
* set the limit for the data source
*
* @var string
*/
private $_limit;
/**
* set the total number of records/items.
*
* @var numeric
*/
private $_totalRows = 0;
/**
* __construct
*
* pass values when class is istantiated
*
* @param numeric $_perPage sets the number of iteems per page
* @param numeric $_instance sets the instance for the GET parameter
*/
public function __construct($perPage,$instance){
$this->_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 .= "<div class='pagination'>";
if ($this->_page > 1)
$pagination.= "<a href='".$path."$this->_instance=$prev"."$ext'>« previous</a>";
else
$pagination.= "<span class='disabled'>« previous</span>";
if ($lastpage < 7 + ($adjacents * 2))
{
for ($counter = 1; $counter <= $lastpage; $counter++)
{
if ($counter == $this->_page)
$pagination.= "<span class='current'>$counter</span>";
else
$pagination.= "<a href='".$path."$this->_instance=$counter"."$ext'>$counter</a>";
}
}
elseif($lastpage > 5 + ($adjacents * 2))
{
if($this->_page < 1 + ($adjacents * 2))
{
for ($counter = 1; $counter < 4 + ($adjacents * 2); $counter++)
{
if ($counter == $this->_page)
$pagination.= "<span class='current'>$counter</span>";
else
$pagination.= "<a href='".$path."$this->_instance=$counter"."$ext'>$counter</a>";
}
$pagination.= "...";
$pagination.= "<a href='".$path."$this->_instance=$lpm1"."$ext'>$lpm1</a>";
$pagination.= "<a href='".$path."$this->_instance=$lastpage"."$ext'>$lastpage</a>";
}
elseif($lastpage - ($adjacents * 2) > $this->_page && $this->_page > ($adjacents * 2))
{
$pagination.= "<a href='".$path."$this->_instance=1"."$ext'>1</a>";
$pagination.= "<a href='".$path."$this->_instance=2"."$ext'>2</a>";
$pagination.= "...";
for ($counter = $this->_page - $adjacents; $counter <= $this->_page + $adjacents; $counter++)
{
if ($counter == $this->_page)
$pagination.= "<span class='current'>$counter</span>";
else
$pagination.= "<a href='".$path."$this->_instance=$counter"."$ext'>$counter</a>";
}
$pagination.= "..";
$pagination.= "<a href='".$path."$this->_instance=$lpm1"."$ext'>$lpm1</a>";
$pagination.= "<a href='".$path."$this->_instance=$lastpage"."$ext'>$lastpage</a>";
}
else
{
$pagination.= "<a href='".$path."$this->_instance=1"."$ext'>1</a>";
$pagination.= "<a href='".$path."$this->_instance=2"."$ext'>2</a>";
$pagination.= "..";
for ($counter = $lastpage - (2 + ($adjacents * 2)); $counter <= $lastpage; $counter++)
{
if ($counter == $this->_page)
$pagination.= "<span class='current'>$counter</span>";
else
$pagination.= "<a href='".$path."$this->_instance=$counter"."$ext'>$counter</a>";
}
}
}
if ($this->_page < $counter - 1)
$pagination.= "<a href='".$path."$this->_instance=$next"."$ext'>next »</a>";
else
$pagination.= "<span class='disabled'>next »</span>";
$pagination.= "</div>\n";
}
return $pagination;
}
}

View file

@ -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();

View file

@ -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);
}
}

View file

@ -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();
$poche = new Poche($storage_type);

View file

@ -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();