This commit is contained in:
Loïc Guibert
2022-09-30 20:02:02 +01:00
commit 66dafc36c3
2561 changed files with 454489 additions and 0 deletions

View File

@@ -0,0 +1,98 @@
# v1.4.3
## 08/26/2022
1. [](#new)
* Pass phpstan level 1 tests
* Require Grav v1.6
* Moved pagination classes under `Grav\Plugin\Pagination` namespace
* Removed extension to bring Twig function into Plugin class
# v1.4.2
## 05/09/2019
1. [](#new)
* Add active class for active page [#37](https://github.com/getgrav/grav-plugin-pagination/pull/37)
* Added `ru` and `uk` translations [#38](https://github.com/getgrav/grav-plugin-pagination/pull/38)
# v1.4.1
## 08/28/2018
1. [](#bugfix)
* Reverted Twig fix to address broken `url` in Twig [#34](https://github.com/getgrav/grav-plugin-pagination/issues/34)
* Removed duplicate README text [#30](https://github.com/getgrav/grav-plugin-pagination/issues/30)
# v1.4.0
## 08/20/2018
1. [](#new)
* Added Twig pagination function [#22](https://github.com/getgrav/grav-plugin-pagination/pull/22)
1. [](#improved)
* Removed Grav trait in favor of `Grav::instance()`
* Changed delta blueprint type from `text` to `number`
* Code cleanup
# v1.3.2
## 05/03/2016
1. [](#new)
* Added default pagination to `page.collection.params.pagination` and `base_url` to `page.url`
1. [](#improved)
* Use common lang strings in blueprints
1. [](#bugfix)
* Improved and fixed README.md
# v1.3.1
## 08/29/2015
1. [](#bugfix)
* Fixed pagination URLs in certain situations
# v1.3.0
## 08/25/2015
1. [](#improved)
* Added blueprints for Grav Admin plugin
# v1.2.7
## 07/13/2015
1. [](#new)
* Added ability to provide `/tmpl:template_name` parameter to pagination URL
2. [](#improved)
* Allow checking of `header.content.pagination` **or** `header.pagination` to activate
# v1.2.6
## 07/12/2015
2. [](#improved)
* no `/page:1` for first page in pagination set
# v1.2.5
## 02/19/2015
2. [](#improved)
* Implemented new `param_sep` variable from Grav 0.9.18
# v1.2.4
## 02/05/2015
2. [](#improved)
* Added support for HHVM
# v1.2.3
## 01/23/2015
2. [](#improved)
* Added microdata information for links
# v1.2.2
## 01/09/2015
2. [](#improved)
* NOTE: BREAKING CHANGE: Moved templates into `partials/` subfolder for consistency.
# v1.2.1
## 11/30/2014
1. [](#new)
* ChangeLog started...

View File

@@ -0,0 +1,21 @@
The MIT License (MIT)
Copyright (c) 2014 Grav
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

View File

@@ -0,0 +1,151 @@
# Grav Pagination Plugin
`Pagination` is a [Grav][grav] Plugin that allows to divide articles into discrete pages.
# Installation
To install this plugin, just download the zip version of this repository and unzip it under `/your/site/grav/user/plugins`. Then, rename the folder to `pagination`.
You should now have all the plugin files under
/your/site/grav/user/plugins/pagination
>> NOTE: This plugin is a modular component for Grav which requires [Grav](http://github.com/getgrav/grav), the [Error](https://github.com/getgrav/grav-plugin-error) and [Problems](https://github.com/getgrav/grav-plugin-problems) plugins, and a theme to be installed in order to operate.
# Config Defaults
```
enabled: true
built_in_css: true
delta: 0
```
The 'delta' value controls how many pages left and right of the current page are visible. If set to 0 all pages will be shown.
If you need to change any value, then the best process is to copy the [pagination.yaml](pagination.yaml) file into your `users/config/plugins/` folder (create it if it doesn't exist), and then modify there. This will override the default settings.
# Usage for content authors
To use this plugin:
- the `pagination` plugin must be installed and enabled
- the active theme must have pagination support (most Grav themes support pagination; if youre building your own theme, see the next section for adding pagination support)
On the content side, you should have a blog-like structure, for example:
```
blog/
blog.md
my-cool-blog-post/
item.md
another-post/
item.md
```
Then in your `blog.md`, set up the pages collection using YAML front-matter:
```yaml
---
title: My Gravtastic Blog
content:
items: '@self.children'
order:
by: header.date
dir: desc
pagination: true
limit: 10
---
# My Gravtastic Blog
## A tale of **awesomazing** adventures
```
Your `/blog` page should now list the 10 most recent blog posts, and show pagination links.
# Usage for theme developers
### Including the default pagination template
If you are developing your own theme and want to support pagination, you need to include the pagination template in the relevant pages. For instance in `blog.html.twig`:
```twig
{# /your/site/grav/user/themes/custom-theme/templates/blog.html.twig #}
{% set collection = page.collection() %}
{# Render the list of blog posts (automatically filtered when using pagination) #}
{% for child in collection %}
...
{% endfor %}
{# Render the pagination list #}
{% if config.plugins.pagination.enabled and collection.params.pagination %}
{% include 'partials/pagination.html.twig' with {'base_url':page.url, 'pagination':collection.params.pagination} %}
{% endif %}
```
### Overriding the pagination HTML
If you want to override the look and feel of the pagination, copy the template file [pagination.html.twig][pagination] into the templates folder of your custom theme:
```
/your/site/grav/user/themes/custom-theme/templates/partials/pagination.html.twig
```
You can now edit the override and tweak it to meet your needs.
[pagination]: templates/partials/pagination.html.twig
[grav]: http://github.com/getgrav/grav
# Twig pagination function
It is now possible to create paginated collections on demand in your twig file. You only need to:
* activate the pagination plugin
* pick or create the collection you want
* paginate it
* render the paginated collection
## Creating a paginated collection
### Basic usage
```twig
{# some collection #}
{% set collection = page.collection() %}
{# number of items per page #}
{% set limit = 5 %}
{% do paginate( collection, limit ) %}
```
This creates a paginated collection with `limit` items per page. As usual, any url parameters - except the page parameter, which is recreated - are passed on to the pagination bar's links.
### Extended usage
```twig
{% set collection = page.find( '/other/_events' ).children %}
{% set limit = 5 %}
{% set ignore_url_param_array = [ 'event' ] %}
{% do paginate( collection, limit, ignore_url_param_array ) %}
```
The above example is taken from http://ami-web.nl/events. This code creates a paginated collection with 5 items per page (the event summary list) which is presented together with an active event. The active event appears in only one of the summary pages. Consequently, the url parameter 'event' should be filtered out so it does not show up in the pagination bar's links, preventing inconsistencies with different page parameters. Any non listed url parameters (except the page parameter) are passed through unaffected. The requested page contains logic to pick a sensible default event.
### Rendering the paginated collection
The rest is identical to the standard procedure:
```twig
{# create list of items #}
{% for item in collection %}
...
{% endfor %}
{# include the pagination bar #}
{% if config.plugins.pagination.enabled and collection.params.pagination %}
{% include 'partials/pagination.html.twig' with {'base_url':page.url, 'pagination':collection.params.pagination} %}
{% endif %}
```

View File

@@ -0,0 +1,52 @@
name: Pagination
slug: pagination
type: plugin
version: 1.4.3
description: "**Pagination** is a very useful plugin to help navigate a large collection of pages, such as for a **blog**."
icon: list-ol
author:
name: Team Grav
email: devs@getgrav.org
url: http://getgrav.org
homepage: https://github.com/getgrav/grav-plugin-pagination
keywords: pagination, plugin, pages, navigation
bugs: https://github.com/getgrav/grav-plugin-pagination/issues
license: MIT
dependencies:
- { name: grav, version: '>=1.6.0' }
form:
validation: strict
fields:
enabled:
type: toggle
label: PLUGIN_ADMIN.PLUGIN_STATUS
highlight: 1
default: 0
options:
1: PLUGIN_ADMIN.ENABLED
0: PLUGIN_ADMIN.DISABLED
validate:
type: bool
delta:
type: number
size: x-small
label: PLUGIN_PAGINATION.DELTA
default: 0
help: PLUGIN_PAGINATION.DELTA_HELP
validate:
type: number
min: 0
built_in_css:
type: toggle
label: PLUGIN_PAGINATION.BUILTIN_CSS
help: PLUGIN_PAGINATION.BUILTIN_CSS_HELP
highlight: 1
default: 1
options:
1: PLUGIN_ADMIN.ENABLED
0: PLUGIN_ADMIN.DISABLED
validate:
type: bool

View File

@@ -0,0 +1,130 @@
<?php
namespace Grav\Plugin\Pagination;
use Grav\Common\Grav;
use Grav\Common\Iterator;
use Grav\Common\Page\Collection;
use Grav\Common\Uri;
class PaginationHelper extends Iterator
{
protected $current;
protected $items_per_page;
protected $page_count;
protected $url_params;
/**
* Create and initialize pagination.
*
* @param Collection $collection
*/
public function __construct(Collection $collection)
{
parent::__construct();
$grav = Grav::instance();
/** @var Uri $uri */
$uri = $grav['uri'];
$config = $grav['config'];
$this->current = $uri->currentPage();
// get params
$url_params = explode('/', ltrim($uri->params(), '/'));
$params = $collection->params();
foreach ($url_params as $key => $value) {
if (strpos($value, 'page' . $config->get('system.param_sep')) !== false) {
unset($url_params[$key]);
}
if (isset($params['ignore_url_params'])) {
foreach ((array)$params['ignore_params'] as $ignore_param) {
if (strpos($value, $ignore_param . $config->get('system.param_sep')) !== false) {
unset($url_params[$key]);
}
}
}
}
$this->url_params = '/'.implode('/', $url_params);
// check for empty params
if ($this->url_params === '/') {
$this->url_params = '';
}
$this->items_per_page = $params['limit'];
$this->page_count = ceil($collection->count() / $this->items_per_page);
for ($x=1; $x <= $this->page_count; $x++) {
if ($x === 1) {
$this->items[$x] = new PaginationPage($x, '');
} else {
$this->items[$x] = new PaginationPage($x, '/page' . $config->get('system.param_sep') . $x);
}
}
}
/**
* Returns true if current item has previous sibling.
*
* @return bool
*/
public function hasPrev()
{
if (array_key_exists($this->current -1, $this->items)) {
return true;
}
return false;
}
/**
* Returns true if current item has next sibling.
*
* @return bool
*/
public function hasNext()
{
if (array_key_exists($this->current +1, $this->items)) {
return true;
}
return false;
}
/**
* Return previous url.
*
* @return string|null
*/
public function prevUrl()
{
if (array_key_exists($this->current -1, $this->items)) {
return $this->items[$this->current -1]->url;
}
return null;
}
/**
* Return next url.
*
* @return string|null
*/
public function nextUrl()
{
if (array_key_exists($this->current +1, $this->items)) {
return $this->items[$this->current +1]->url;
}
return null;
}
public function params()
{
return $this->url_params;
}
}

View File

@@ -0,0 +1,84 @@
<?php
namespace Grav\Plugin\Pagination;
use Grav\Common\Grav;
class PaginationPage
{
/**
* @var Grav
*/
protected $grav;
/**
* @var int
*/
public $number;
/**
* @var string
*/
public $url;
/**
* @var int
*/
protected $delta=0;
/**
* Constructor
*
* @param int $number
* @param string $url
*/
public function __construct($number, $url)
{
$this->grav = Grav::instance();
$this->number = $number;
$this->url = $url;
$this->delta = $this->grav['config']->get('plugins.pagination.delta');
}
/**
* Returns true if the page is the current one.
*
* @return bool
*/
public function isCurrent()
{
if ($this->grav['uri']->currentPage() == $this->number) {
return true;
}
return false;
}
/**
* Returns true if the page is within a configurable delta of the current one
*
* @return bool
*/
public function isInDelta()
{
if (!$this->delta) {
return true;
}
return abs($this->grav['uri']->currentPage() - $this->number) < $this->delta;
}
/**
* Returns true is this page is the last/first one at the border of the delta range
* (Used to display a "gap" li element ...)
*
* @return bool
*/
public function isDeltaBorder()
{
if (!$this->delta) {
return false;
}
return abs($this->grav['uri']->currentPage() - $this->number) == $this->delta;
}
}

View File

@@ -0,0 +1,32 @@
{
"name": "grav-plugin-pagination",
"type": "grav-plugin",
"description": "Pagination plugin for Grav CMS",
"keywords": ["pagination"],
"homepage": "https://github.com/getgrav/grav-plugin-pagination/",
"license": "MIT",
"authors": [
{
"name": "Team Grav",
"email": "devs@getgrav.org",
"homepage": "http://getgrav.org",
"role": "Developer"
}
],
"require": {
"php": ">=7.1.3",
"ext-json": "*",
"ext-mbstring": "*"
},
"autoload": {
"psr-4": {
"Grav\\Plugin\\Pagination\\": "classes/plugin"
},
"classmap": ["pagination.php"]
},
"config": {
"platform": {
"php": "7.1.3"
}
}
}

24
user/plugins/pagination/composer.lock generated Normal file
View File

@@ -0,0 +1,24 @@
{
"_readme": [
"This file locks the dependencies of your project to a known state",
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "0b6ccb6ac74643ef6b539ab9dbeffe31",
"packages": [],
"packages-dev": [],
"aliases": [],
"minimum-stability": "stable",
"stability-flags": [],
"prefer-stable": false,
"prefer-lowest": false,
"platform": {
"php": ">=7.1.3",
"ext-json": "*",
"ext-mbstring": "*"
},
"platform-dev": [],
"platform-overrides": {
"php": "7.1.3"
}
}

View File

@@ -0,0 +1,17 @@
.pagination {
list-style: none;
padding: 0;
margin: 3rem 0 1rem;
text-align: center;
color: #aaa;
}
.pagination li {
display: inline-block;
border: 1px solid #eee;
}
.pagination a, .pagination span {
display: inline-block;
padding: 4px 15px;
}

View File

@@ -0,0 +1,15 @@
{
"project":"grav-plugin-pagination",
"platforms":{
"grav":{
"nodes":{
"plugin":[
{
"source":"/",
"destination":"/user/plugins/pagination"
}
]
}
}
}
}

View File

@@ -0,0 +1,20 @@
en:
PLUGIN_PAGINATION:
DELTA: 'Delta'
DELTA_HELP: 'How many pages to show left and right of the current page'
BUILTIN_CSS: 'Use built in CSS'
BUILTIN_CSS_HELP: 'Include the CSS provided by the Pagination plugin'
ru:
PLUGIN_PAGINATION:
DELTA: 'Дельта'
DELTA_HELP: 'Сколько страниц показывать слева и справа от текущей страницы'
BUILTIN_CSS: 'Использовать встроенный CSS'
BUILTIN_CSS_HELP: 'Использовать CSS, предоставленный плагином Pagination'
uk:
PLUGIN_PAGINATION:
DELTA: 'Дельта'
DELTA_HELP: 'Скільки сторінок відображатиметься ліворуч і праворуч від поточної сторінки'
BUILTIN_CSS: 'Використовувати вбудований CSS'
BUILTIN_CSS_HELP: 'Використовувати CSS, наданий плагіном Pagination'

View File

@@ -0,0 +1,165 @@
<?php
namespace Grav\Plugin;
use Composer\Autoload\ClassLoader;
use Grav\Common\Page\Collection;
use Grav\Common\Page\Interfaces\PageInterface;
use Grav\Common\Plugin;
use Grav\Plugin\Pagination\PaginationHelper;
use Grav\Plugin\Pagination\PaginationPage;
use RocketTheme\Toolbox\Event\Event;
use Twig\TwigFunction;
class PaginationPlugin extends Plugin
{
/**
* @var PaginationHelper
*/
protected $pagination;
/**
* @return array
*/
public static function getSubscribedEvents()
{
return [
'onPluginsInitialized' => [
['autoload', 100001],
['onPluginsInitialized', 0]
]
];
}
/**
* [onPluginsInitialized:100000] Composer autoload.
*
* @return ClassLoader
*/
public function autoload()
{
return require __DIR__ . '/vendor/autoload.php';
}
/**
* Initialize configuration
*/
public function onPluginsInitialized()
{
if ($this->isAdmin()) {
$this->active = false;
return;
}
class_alias(PaginationHelper::class, 'Grav\\Plugin\\PaginationHelper');
class_alias(PaginationPage::class, 'Grav\\Plugin\\PaginationPage');
$this->enable([
'onTwigTemplatePaths' => ['onTwigTemplatePaths', 0],
'onPageInitialized' => ['onPageInitialized', 0],
'onTwigExtensions' => ['onTwigExtensions', 0]
]);
}
/**
* Add current directory to twig lookup paths.
*/
public function onTwigTemplatePaths()
{
$this->grav['twig']->twig_paths[] = __DIR__ . '/templates';
}
/**
* Add Twig Extensions
*/
public function onTwigExtensions()
{
// Add Twig functions
$this->grav['twig']->twig()->addFunction(
new TwigFunction('paginate', [$this, 'paginateTwigFunction'])
);
}
/**
* Enable pagination if page has params.pagination = true.
*/
public function onPageInitialized()
{
/** @var PageInterface $page */
$page = $this->grav['page'];
if ($page && ($page->value('header.content.pagination') || $page->value('header.pagination'))) {
$this->enable([
'onCollectionProcessed' => ['onCollectionProcessed', 0],
'onTwigSiteVariables' => ['onTwigSiteVariables', 0]
]);
$template = $this->grav['uri']->param('tmpl');
if ($template) {
$page->template($template);
}
}
}
/**
* Create pagination object for the page.
*
* @param Event $event
*/
public function onCollectionProcessed(Event $event)
{
/** @var Collection $collection */
$collection = $event['collection'];
$params = $collection->params();
// Only add pagination if it has been enabled for the collection.
if (empty($params['pagination'])) {
return;
}
if (!empty($params['limit']) && $collection->count() > $params['limit']) {
$this->pagination = new PaginationHelper($collection);
$collection->setParams(['pagination' => $this->pagination]);
}
}
/**
* Set needed variables to display pagination.
*/
public function onTwigSiteVariables()
{
if ($this->config->get('plugins.pagination.built_in_css')) {
$this->grav['assets']->add('plugin://pagination/css/pagination.css');
}
}
/**
* pagination
*
* @param Collection $collection
* @param int $limit
* @param array $ignore_param_array url parameters to be ignored in page links
*/
public function paginateCollection($collection, $limit, $ignore_param_array = [])
{
$collection->setParams(['pagination' => 'true']);
$collection->setParams(['limit' => $limit]);
$collection->setParams(['ignore_params' => $ignore_param_array]);
if ($collection->count() > $limit) {
$this->pagination = new PaginationHelper($collection);
$collection->setParams(['pagination' => $this->pagination]);
$uri = $this->grav['uri'];
$start = ($uri->currentPage() - 1) * $limit;
if ($limit && $collection->count() > $limit) {
$collection->slice($start, $limit);
}
}
}
public function paginateTwigFunction($collection, $limit, $ignore_url_param_array = [])
{
$this->paginateCollection($collection, $limit, $ignore_url_param_array);
}
}

View File

@@ -0,0 +1,3 @@
enabled: true
built_in_css: true
delta: 0

View File

@@ -0,0 +1,34 @@
{% set pagination = pagination|default(page.collection.params.pagination) %}
{% set base_url = base_url|default(page.url) %}
{% if pagination|length > 1 %}
<ul class="pagination">
{% if pagination.hasPrev %}
{% set url = (base_url ~ pagination.params ~ pagination.prevUrl)|replace({'//':'/'}) %}
<li><a rel="prev" href="{{ url }}">&laquo;</a></li>
{% else %}
<li><span>&laquo;</span></li>
{% endif %}
{% for paginate in pagination %}
{% if paginate.isCurrent %}
<li><span class="active">{{ paginate.number }}</span></li>
{% elseif paginate.isInDelta %}
{% set url = (base_url ~ pagination.params ~ paginate.url)|replace({'//':'/'}) %}
<li><a href="{{ url }}">{{ paginate.number }}</a></li>
{% elseif paginate.isDeltaBorder %}
<li class="gap"><span>&hellip;</span></li>
{% endif %}
{% endfor %}
{% if pagination.hasNext %}
{% set url = (base_url ~ pagination.params ~ pagination.nextUrl)|replace({'//':'/'}) %}
<li><a rel="next" href="{{ url }}">&raquo;</a></li>
{% else %}
<li><span>&raquo;</span></li>
{% endif %}
</ul>
{% endif %}

View File

@@ -0,0 +1,7 @@
<?php
// autoload.php @generated by Composer
require_once __DIR__ . '/composer/autoload_real.php';
return ComposerAutoloaderInitea591f86e2ec72c59666a51291247f87::getLoader();

View File

@@ -0,0 +1,445 @@
<?php
/*
* This file is part of Composer.
*
* (c) Nils Adermann <naderman@naderman.de>
* Jordi Boggiano <j.boggiano@seld.be>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Composer\Autoload;
/**
* ClassLoader implements a PSR-0, PSR-4 and classmap class loader.
*
* $loader = new \Composer\Autoload\ClassLoader();
*
* // register classes with namespaces
* $loader->add('Symfony\Component', __DIR__.'/component');
* $loader->add('Symfony', __DIR__.'/framework');
*
* // activate the autoloader
* $loader->register();
*
* // to enable searching the include path (eg. for PEAR packages)
* $loader->setUseIncludePath(true);
*
* In this example, if you try to use a class in the Symfony\Component
* namespace or one of its children (Symfony\Component\Console for instance),
* the autoloader will first look for the class under the component/
* directory, and it will then fallback to the framework/ directory if not
* found before giving up.
*
* This class is loosely based on the Symfony UniversalClassLoader.
*
* @author Fabien Potencier <fabien@symfony.com>
* @author Jordi Boggiano <j.boggiano@seld.be>
* @see http://www.php-fig.org/psr/psr-0/
* @see http://www.php-fig.org/psr/psr-4/
*/
class ClassLoader
{
// PSR-4
private $prefixLengthsPsr4 = array();
private $prefixDirsPsr4 = array();
private $fallbackDirsPsr4 = array();
// PSR-0
private $prefixesPsr0 = array();
private $fallbackDirsPsr0 = array();
private $useIncludePath = false;
private $classMap = array();
private $classMapAuthoritative = false;
private $missingClasses = array();
private $apcuPrefix;
public function getPrefixes()
{
if (!empty($this->prefixesPsr0)) {
return call_user_func_array('array_merge', $this->prefixesPsr0);
}
return array();
}
public function getPrefixesPsr4()
{
return $this->prefixDirsPsr4;
}
public function getFallbackDirs()
{
return $this->fallbackDirsPsr0;
}
public function getFallbackDirsPsr4()
{
return $this->fallbackDirsPsr4;
}
public function getClassMap()
{
return $this->classMap;
}
/**
* @param array $classMap Class to filename map
*/
public function addClassMap(array $classMap)
{
if ($this->classMap) {
$this->classMap = array_merge($this->classMap, $classMap);
} else {
$this->classMap = $classMap;
}
}
/**
* Registers a set of PSR-0 directories for a given prefix, either
* appending or prepending to the ones previously set for this prefix.
*
* @param string $prefix The prefix
* @param array|string $paths The PSR-0 root directories
* @param bool $prepend Whether to prepend the directories
*/
public function add($prefix, $paths, $prepend = false)
{
if (!$prefix) {
if ($prepend) {
$this->fallbackDirsPsr0 = array_merge(
(array) $paths,
$this->fallbackDirsPsr0
);
} else {
$this->fallbackDirsPsr0 = array_merge(
$this->fallbackDirsPsr0,
(array) $paths
);
}
return;
}
$first = $prefix[0];
if (!isset($this->prefixesPsr0[$first][$prefix])) {
$this->prefixesPsr0[$first][$prefix] = (array) $paths;
return;
}
if ($prepend) {
$this->prefixesPsr0[$first][$prefix] = array_merge(
(array) $paths,
$this->prefixesPsr0[$first][$prefix]
);
} else {
$this->prefixesPsr0[$first][$prefix] = array_merge(
$this->prefixesPsr0[$first][$prefix],
(array) $paths
);
}
}
/**
* Registers a set of PSR-4 directories for a given namespace, either
* appending or prepending to the ones previously set for this namespace.
*
* @param string $prefix The prefix/namespace, with trailing '\\'
* @param array|string $paths The PSR-4 base directories
* @param bool $prepend Whether to prepend the directories
*
* @throws \InvalidArgumentException
*/
public function addPsr4($prefix, $paths, $prepend = false)
{
if (!$prefix) {
// Register directories for the root namespace.
if ($prepend) {
$this->fallbackDirsPsr4 = array_merge(
(array) $paths,
$this->fallbackDirsPsr4
);
} else {
$this->fallbackDirsPsr4 = array_merge(
$this->fallbackDirsPsr4,
(array) $paths
);
}
} elseif (!isset($this->prefixDirsPsr4[$prefix])) {
// Register directories for a new namespace.
$length = strlen($prefix);
if ('\\' !== $prefix[$length - 1]) {
throw new \InvalidArgumentException("A non-empty PSR-4 prefix must end with a namespace separator.");
}
$this->prefixLengthsPsr4[$prefix[0]][$prefix] = $length;
$this->prefixDirsPsr4[$prefix] = (array) $paths;
} elseif ($prepend) {
// Prepend directories for an already registered namespace.
$this->prefixDirsPsr4[$prefix] = array_merge(
(array) $paths,
$this->prefixDirsPsr4[$prefix]
);
} else {
// Append directories for an already registered namespace.
$this->prefixDirsPsr4[$prefix] = array_merge(
$this->prefixDirsPsr4[$prefix],
(array) $paths
);
}
}
/**
* Registers a set of PSR-0 directories for a given prefix,
* replacing any others previously set for this prefix.
*
* @param string $prefix The prefix
* @param array|string $paths The PSR-0 base directories
*/
public function set($prefix, $paths)
{
if (!$prefix) {
$this->fallbackDirsPsr0 = (array) $paths;
} else {
$this->prefixesPsr0[$prefix[0]][$prefix] = (array) $paths;
}
}
/**
* Registers a set of PSR-4 directories for a given namespace,
* replacing any others previously set for this namespace.
*
* @param string $prefix The prefix/namespace, with trailing '\\'
* @param array|string $paths The PSR-4 base directories
*
* @throws \InvalidArgumentException
*/
public function setPsr4($prefix, $paths)
{
if (!$prefix) {
$this->fallbackDirsPsr4 = (array) $paths;
} else {
$length = strlen($prefix);
if ('\\' !== $prefix[$length - 1]) {
throw new \InvalidArgumentException("A non-empty PSR-4 prefix must end with a namespace separator.");
}
$this->prefixLengthsPsr4[$prefix[0]][$prefix] = $length;
$this->prefixDirsPsr4[$prefix] = (array) $paths;
}
}
/**
* Turns on searching the include path for class files.
*
* @param bool $useIncludePath
*/
public function setUseIncludePath($useIncludePath)
{
$this->useIncludePath = $useIncludePath;
}
/**
* Can be used to check if the autoloader uses the include path to check
* for classes.
*
* @return bool
*/
public function getUseIncludePath()
{
return $this->useIncludePath;
}
/**
* Turns off searching the prefix and fallback directories for classes
* that have not been registered with the class map.
*
* @param bool $classMapAuthoritative
*/
public function setClassMapAuthoritative($classMapAuthoritative)
{
$this->classMapAuthoritative = $classMapAuthoritative;
}
/**
* Should class lookup fail if not found in the current class map?
*
* @return bool
*/
public function isClassMapAuthoritative()
{
return $this->classMapAuthoritative;
}
/**
* APCu prefix to use to cache found/not-found classes, if the extension is enabled.
*
* @param string|null $apcuPrefix
*/
public function setApcuPrefix($apcuPrefix)
{
$this->apcuPrefix = function_exists('apcu_fetch') && ini_get('apc.enabled') ? $apcuPrefix : null;
}
/**
* The APCu prefix in use, or null if APCu caching is not enabled.
*
* @return string|null
*/
public function getApcuPrefix()
{
return $this->apcuPrefix;
}
/**
* Registers this instance as an autoloader.
*
* @param bool $prepend Whether to prepend the autoloader or not
*/
public function register($prepend = false)
{
spl_autoload_register(array($this, 'loadClass'), true, $prepend);
}
/**
* Unregisters this instance as an autoloader.
*/
public function unregister()
{
spl_autoload_unregister(array($this, 'loadClass'));
}
/**
* Loads the given class or interface.
*
* @param string $class The name of the class
* @return bool|null True if loaded, null otherwise
*/
public function loadClass($class)
{
if ($file = $this->findFile($class)) {
includeFile($file);
return true;
}
}
/**
* Finds the path to the file where the class is defined.
*
* @param string $class The name of the class
*
* @return string|false The path if found, false otherwise
*/
public function findFile($class)
{
// class map lookup
if (isset($this->classMap[$class])) {
return $this->classMap[$class];
}
if ($this->classMapAuthoritative || isset($this->missingClasses[$class])) {
return false;
}
if (null !== $this->apcuPrefix) {
$file = apcu_fetch($this->apcuPrefix.$class, $hit);
if ($hit) {
return $file;
}
}
$file = $this->findFileWithExtension($class, '.php');
// Search for Hack files if we are running on HHVM
if (false === $file && defined('HHVM_VERSION')) {
$file = $this->findFileWithExtension($class, '.hh');
}
if (null !== $this->apcuPrefix) {
apcu_add($this->apcuPrefix.$class, $file);
}
if (false === $file) {
// Remember that this class does not exist.
$this->missingClasses[$class] = true;
}
return $file;
}
private function findFileWithExtension($class, $ext)
{
// PSR-4 lookup
$logicalPathPsr4 = strtr($class, '\\', DIRECTORY_SEPARATOR) . $ext;
$first = $class[0];
if (isset($this->prefixLengthsPsr4[$first])) {
$subPath = $class;
while (false !== $lastPos = strrpos($subPath, '\\')) {
$subPath = substr($subPath, 0, $lastPos);
$search = $subPath.'\\';
if (isset($this->prefixDirsPsr4[$search])) {
$pathEnd = DIRECTORY_SEPARATOR . substr($logicalPathPsr4, $lastPos + 1);
foreach ($this->prefixDirsPsr4[$search] as $dir) {
if (file_exists($file = $dir . $pathEnd)) {
return $file;
}
}
}
}
}
// PSR-4 fallback dirs
foreach ($this->fallbackDirsPsr4 as $dir) {
if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr4)) {
return $file;
}
}
// PSR-0 lookup
if (false !== $pos = strrpos($class, '\\')) {
// namespaced class name
$logicalPathPsr0 = substr($logicalPathPsr4, 0, $pos + 1)
. strtr(substr($logicalPathPsr4, $pos + 1), '_', DIRECTORY_SEPARATOR);
} else {
// PEAR-like class name
$logicalPathPsr0 = strtr($class, '_', DIRECTORY_SEPARATOR) . $ext;
}
if (isset($this->prefixesPsr0[$first])) {
foreach ($this->prefixesPsr0[$first] as $prefix => $dirs) {
if (0 === strpos($class, $prefix)) {
foreach ($dirs as $dir) {
if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0)) {
return $file;
}
}
}
}
}
// PSR-0 fallback dirs
foreach ($this->fallbackDirsPsr0 as $dir) {
if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0)) {
return $file;
}
}
// PSR-0 include paths.
if ($this->useIncludePath && $file = stream_resolve_include_path($logicalPathPsr0)) {
return $file;
}
return false;
}
}
/**
* Scope isolated include.
*
* Prevents access to $this/self from included files.
*/
function includeFile($file)
{
include $file;
}

View File

@@ -0,0 +1,21 @@
Copyright (c) Nils Adermann, Jordi Boggiano
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is furnished
to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

View File

@@ -0,0 +1,10 @@
<?php
// autoload_classmap.php @generated by Composer
$vendorDir = dirname(dirname(__FILE__));
$baseDir = dirname($vendorDir);
return array(
'Grav\\Plugin\\PaginationPlugin' => $baseDir . '/pagination.php',
);

View File

@@ -0,0 +1,9 @@
<?php
// autoload_namespaces.php @generated by Composer
$vendorDir = dirname(dirname(__FILE__));
$baseDir = dirname($vendorDir);
return array(
);

View File

@@ -0,0 +1,10 @@
<?php
// autoload_psr4.php @generated by Composer
$vendorDir = dirname(dirname(__FILE__));
$baseDir = dirname($vendorDir);
return array(
'Grav\\Plugin\\Pagination\\' => array($baseDir . '/classes/plugin'),
);

View File

@@ -0,0 +1,52 @@
<?php
// autoload_real.php @generated by Composer
class ComposerAutoloaderInitea591f86e2ec72c59666a51291247f87
{
private static $loader;
public static function loadClassLoader($class)
{
if ('Composer\Autoload\ClassLoader' === $class) {
require __DIR__ . '/ClassLoader.php';
}
}
public static function getLoader()
{
if (null !== self::$loader) {
return self::$loader;
}
spl_autoload_register(array('ComposerAutoloaderInitea591f86e2ec72c59666a51291247f87', 'loadClassLoader'), true, true);
self::$loader = $loader = new \Composer\Autoload\ClassLoader();
spl_autoload_unregister(array('ComposerAutoloaderInitea591f86e2ec72c59666a51291247f87', 'loadClassLoader'));
$useStaticLoader = PHP_VERSION_ID >= 50600 && !defined('HHVM_VERSION') && (!function_exists('zend_loader_file_encoded') || !zend_loader_file_encoded());
if ($useStaticLoader) {
require_once __DIR__ . '/autoload_static.php';
call_user_func(\Composer\Autoload\ComposerStaticInitea591f86e2ec72c59666a51291247f87::getInitializer($loader));
} else {
$map = require __DIR__ . '/autoload_namespaces.php';
foreach ($map as $namespace => $path) {
$loader->set($namespace, $path);
}
$map = require __DIR__ . '/autoload_psr4.php';
foreach ($map as $namespace => $path) {
$loader->setPsr4($namespace, $path);
}
$classMap = require __DIR__ . '/autoload_classmap.php';
if ($classMap) {
$loader->addClassMap($classMap);
}
}
$loader->register(true);
return $loader;
}
}

View File

@@ -0,0 +1,36 @@
<?php
// autoload_static.php @generated by Composer
namespace Composer\Autoload;
class ComposerStaticInitea591f86e2ec72c59666a51291247f87
{
public static $prefixLengthsPsr4 = array (
'G' =>
array (
'Grav\\Plugin\\Pagination\\' => 23,
),
);
public static $prefixDirsPsr4 = array (
'Grav\\Plugin\\Pagination\\' =>
array (
0 => __DIR__ . '/../..' . '/classes/plugin',
),
);
public static $classMap = array (
'Grav\\Plugin\\PaginationPlugin' => __DIR__ . '/../..' . '/pagination.php',
);
public static function getInitializer(ClassLoader $loader)
{
return \Closure::bind(function () use ($loader) {
$loader->prefixLengthsPsr4 = ComposerStaticInitea591f86e2ec72c59666a51291247f87::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInitea591f86e2ec72c59666a51291247f87::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInitea591f86e2ec72c59666a51291247f87::$classMap;
}, null, ClassLoader::class);
}
}

View File

@@ -0,0 +1 @@
[]