From dda7884ace3a3906b65668669fb67b37f596fd62 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Nicolas=20L=C5=93uillet?= Date: Mon, 19 Jan 2015 11:29:25 +0100 Subject: [PATCH] pagination with composer and move FlattrItem --- composer.json | 7 +- composer.lock | 42 ++- inc/3rdparty/Session.class.php | 346 ------------------- inc/3rdparty/paginator.php | 202 ----------- inc/{3rdparty => poche}/FlattrItem.class.php | 0 inc/poche/global.inc.php | 2 +- 6 files changed, 47 insertions(+), 552 deletions(-) delete mode 100644 inc/3rdparty/Session.class.php delete mode 100644 inc/3rdparty/paginator.php rename inc/{3rdparty => poche}/FlattrItem.class.php (100%) diff --git a/composer.json b/composer.json index 56dea960..32ca9c28 100644 --- a/composer.json +++ b/composer.json @@ -30,6 +30,10 @@ { "type": "vcs", "url": "https://github.com/wallabag/kriss_php5" + }, + { + "type": "vcs", + "url": "https://github.com/wallabag/pagination" } ], "require": { @@ -40,6 +44,7 @@ "ezyang/htmlpurifier": "dev-master", "mgargano/simplehtmldom": "dev-master", "wallabag/PHP-Flash-Messages": "dev-master", - "wallabag/kriss_php5": "dev-master" + "wallabag/kriss_php5": "dev-master", + "wallabag/pagination": "dev-master" } } \ No newline at end of file diff --git a/composer.lock b/composer.lock index 48df2b16..00d31c5b 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "hash": "aaf0d0bb3208c2dfc0b6cc95cbfab5f6", + "hash": "01683220c560fe335307baeb1018293c", "packages": [ { "name": "ezyang/htmlpurifier", @@ -1373,6 +1373,43 @@ }, "time": "2015-01-18 21:21:43" }, + { + "name": "wallabag/pagination", + "version": "dev-master", + "source": { + "type": "git", + "url": "https://github.com/wallabag/pagination.git", + "reference": "54e442b31c90e50e331cb8ac400537e0eda30deb" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/wallabag/pagination/zipball/54e442b31c90e50e331cb8ac400537e0eda30deb", + "reference": "54e442b31c90e50e331cb8ac400537e0eda30deb", + "shasum": "" + }, + "require": { + "php": ">=5.3.0" + }, + "type": "library", + "autoload": { + "files": [ + "paginator.php" + ] + }, + "authors": [ + { + "name": "Nicolas Lœuillet", + "email": "nicolas@loeuillet.org", + "homepage": "http://www.cdetc.fr" + } + ], + "description": "Paginate record sets, not tied in directly to a database.", + "homepage": "https://github.com/wallabag/pagination", + "support": { + "source": "https://github.com/wallabag/pagination/tree/master" + }, + "time": "2015-01-19 09:24:39" + }, { "name": "wallabag/php-flash-messages", "version": "dev-master", @@ -1428,7 +1465,8 @@ "ezyang/htmlpurifier": 20, "mgargano/simplehtmldom": 20, "wallabag/php-flash-messages": 20, - "wallabag/kriss_php5": 20 + "wallabag/kriss_php5": 20, + "wallabag/pagination": 20 }, "prefer-stable": false, "prefer-lowest": false, diff --git a/inc/3rdparty/Session.class.php b/inc/3rdparty/Session.class.php deleted file mode 100644 index b56e4c54..00000000 --- a/inc/3rdparty/Session.class.php +++ /dev/null @@ -1,346 +0,0 @@ - $value) { - $_SESSION[$key] = $value; - } - - return true; - } - self::banLoginFailed(); - } - - self::init(); - return false; - } - - /** - * Unset SESSION variable to force logout - */ - public static function logout() - { - // unset($_SESSION['uid'],$_SESSION['ip'],$_SESSION['expires_on'],$_SESSION['tokens'], $_SESSION['login'], $_SESSION['pass'], $_SESSION['longlastingsession'], $_SESSION['poche_user']); - - // Destruction du cookie (le code peut paraître complexe mais c'est pour être certain de reprendre les mêmes paramètres) - $args = array_merge(array(session_name(), ''), array_values(session_get_cookie_params())); - $args[2] = time() - 3600; - call_user_func_array('setcookie', $args); - // Suppression physique de la session - session_destroy(); - } - - /** - * Make sure user is logged in. - * - * @return true|false True if user is logged in, false otherwise - */ - public static function isLogged() - { - if (!isset ($_SESSION['uid']) - || (self::$disableSessionProtection === false - && $_SESSION['ip'] !== self::_allIPs()) - || time() >= $_SESSION['expires_on']) { - //self::logout(); - - return false; - } - // User accessed a page : Update his/her session expiration date. - $_SESSION['expires_on'] = time() + self::$inactivityTimeout; - if (!empty($_SESSION['longlastingsession'])) { - $_SESSION['expires_on'] += $_SESSION['longlastingsession']; - } - - return true; - } - - /** - * Create a token, store it in SESSION and return it - * - * @param string $salt to prevent birthday attack - * - * @return string Token created - */ - public static function getToken($salt = '') - { - if (!isset($_SESSION['tokens'])) { - $_SESSION['tokens']=array(); - } - // We generate a random string and store it on the server side. - $rnd = sha1(uniqid('', true).'_'.mt_rand().$salt); - $_SESSION['tokens'][$rnd]=1; - - return $rnd; - } - - /** - * Tells if a token is ok. Using this function will destroy the token. - * - * @param string $token Token to test - * - * @return true|false True if token is correct, false otherwise - */ - public static function isToken($token) - { - if (isset($_SESSION['tokens'][$token])) { - unset($_SESSION['tokens'][$token]); // Token is used: destroy it. - - return true; // Token is ok. - } - - return false; // Wrong token, or already used. - } - - /** - * Signal a failed login. Will ban the IP if too many failures: - */ - public static function banLoginFailed() - { - if (self::$banFile !== '') { - $ip = $_SERVER["REMOTE_ADDR"]; - $gb = $GLOBALS['IPBANS']; - - if (!isset($gb['FAILURES'][$ip])) { - $gb['FAILURES'][$ip] = 0; - } - $gb['FAILURES'][$ip]++; - if ($gb['FAILURES'][$ip] > (self::$banAfter - 1)) { - $gb['BANS'][$ip]= time() + self::$banDuration; - } - - $GLOBALS['IPBANS'] = $gb; - file_put_contents(self::$banFile, ""); - } - } - - /** - * Signals a successful login. Resets failed login counter. - */ - public static function banLoginOk() - { - if (self::$banFile !== '') { - $ip = $_SERVER["REMOTE_ADDR"]; - $gb = $GLOBALS['IPBANS']; - unset($gb['FAILURES'][$ip]); unset($gb['BANS'][$ip]); - $GLOBALS['IPBANS'] = $gb; - file_put_contents(self::$banFile, ""); - } - } - - /** - * Ban init - */ - public static function banInit() - { - if (self::$banFile !== '') { - if (!is_file(self::$banFile)) { - file_put_contents(self::$banFile, "array(), 'BANS'=>array()), true).";\n?>"); - } - include self::$banFile; - } - } - - /** - * Checks if the user CAN login. If 'true', the user can try to login. - * - * @return boolean true if user is banned, false otherwise - */ - public static function banCanLogin() - { - if (self::$banFile !== '') { - $ip = $_SERVER["REMOTE_ADDR"]; - $gb = $GLOBALS['IPBANS']; - if (isset($gb['BANS'][$ip])) { - // User is banned. Check if the ban has expired: - if ($gb['BANS'][$ip] <= time()) { - // Ban expired, user can try to login again. - unset($gb['FAILURES'][$ip]); - unset($gb['BANS'][$ip]); - file_put_contents(self::$banFile, ""); - - return true; // Ban has expired, user can login. - } - - return false; // User is banned. - } - } - - return true; // User is not banned. - } - - - /** - * Tells if a param exists in session - * - * @param $name name of the param to test - * @return bool - */ - public static function isInSession($name) - { - return (isset($_SESSION[$name]) ? : FALSE); - } - - /** - * Returns param in session - * - * @param $name name of the param to return - * @return mixed param or null - */ - public static function getParam($name) - { - return (self::isInSession($name) ? $_SESSION[$name] : NULL); - } - - /** - * Store value in session - * - * @param $name name of the variable to store - * @param $value value to store - */ - public static function setParam($name, $value) - { - $_SESSION[$name] = $value; - } -} diff --git a/inc/3rdparty/paginator.php b/inc/3rdparty/paginator.php deleted file mode 100644 index 306756c0..00000000 --- a/inc/3rdparty/paginator.php +++ /dev/null @@ -1,202 +0,0 @@ -_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(){ - if (STORAGE == 'postgres') { - return "LIMIT ".$this->_perPage." OFFSET ".$this->get_start(); - } else { - 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/3rdparty/FlattrItem.class.php b/inc/poche/FlattrItem.class.php similarity index 100% rename from inc/3rdparty/FlattrItem.class.php rename to inc/poche/FlattrItem.class.php diff --git a/inc/poche/global.inc.php b/inc/poche/global.inc.php index 4d119456..c17d54e6 100755 --- a/inc/poche/global.inc.php +++ b/inc/poche/global.inc.php @@ -29,7 +29,7 @@ require_once INCLUDES . '/3rdparty/paginator.php'; require_once INCLUDES . '/3rdparty/libraries/feedwriter/FeedItem.php'; require_once INCLUDES . '/3rdparty/libraries/feedwriter/FeedWriter.php'; -require_once INCLUDES . '/3rdparty/FlattrItem.class.php'; +require_once INCLUDES . '/poche/FlattrItem.class.php'; # epub library require_once INCLUDES . '/3rdparty/libraries/PHPePub/Logger.php'; -- 2.41.0