Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pico v.1.0 - ready! #4

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
143 changes: 143 additions & 0 deletions PicoPlacing.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
<?php

/**
* @id PicoPlacing.php 01.Feb.2016
*
* Description
*
* @author Uwe Fritz
* @fork_from https://github.com/ollierik/Pico-Placing
* @link http://www.edor.de
* @copyright Copyright (c) 2016 edor.de (Uwe Fritz)
* @license MIT
*/


final class PicoPlacing extends AbstractPicoPlugin
{
/**
* This plugin is enabled by default?
*
* @see AbstractPicoPlugin::$enabled
* @var boolean
*/
protected $enabled = false;

/**
* This plugin depends on ...
*
* @see AbstractPicoPlugin::$dependsOn
* @var string[]
*/
protected $dependsOn = array();




/**
* Triggered after Pico has read its configuration
*
* @see Pico::getConfig()
* @param mixed[] &$config array of config variables
* @return void
*/
public function onConfigLoaded(array &$config)
{
// your code
}


/**
* Triggered when Pico reads its known meta header fields
*
* @see Pico::getMetaHeaders()
* @param string[] &$headers list of known meta header
* fields; the array value specifies the YAML key to search for, the
* array key is later used to access the found value
* @return void
*/
public function onMetaHeaders(array &$headers)
{
// your code
$headers['placing'] = 'Placing';
}


/**
* Triggered when Pico reads a single page from the list of all known pages
*
* The `$pageData` parameter consists of the following values:
*
* | Array key | Type | Description |
* | -------------- | ------ | ---------------------------------------- |
* | id | string | relative path to the content file |
* | url | string | URL to the page |
* | title | string | title of the page (YAML header) |
* | description | string | description of the page (YAML header) |
* | author | string | author of the page (YAML header) |
* | time | string | timestamp derived from the Date header |
* | date | string | date of the page (YAML header) |
* | date_formatted | string | formatted date of the page |
* | raw_content | string | raw, not yet parsed contents of the page |
* | meta | string | parsed meta data of the page |
*
* @see DummyPlugin::onPagesLoaded()
* @param array &$pageData data of the loaded page
* @return void
*/
public function onSinglePageLoaded(array &$pageData)
{
// your code
$pageData['placing'] = isset($pageData['meta']['placing']) ? intval($pageData['meta']['placing']) : 0;

}

/**
* Triggered after Pico has read all known pages
*
* See {@link DummyPlugin::onSinglePageLoaded()} for details about the
* structure of the page data.
*
* @see Pico::getPages()
* @see Pico::getCurrentPage()
* @see Pico::getPreviousPage()
* @see Pico::getNextPage()
* @param array[] &$pages data of all known pages
* @param array|null &$currentPage data of the page being served
* @param array|null &$previousPage data of the previous page
* @param array|null &$nextPage data of the next page
* @return void
*/
public function onPagesLoaded(
array &$pages,
array &$currentPage = null,
array &$previousPage = null,
array &$nextPage = null
) {
// your code
if ($config['page_order_by'] = 'placing') {

$sorted_pages = array();

foreach ($pages as $page) {
$sorted_pages[$page['placing']] = $page;
}

ksort($sorted_pages);
$pages = $sorted_pages;

$curr = $currentPage['placing'];

$keys = array_keys($sorted_pages);
$keyIndexes = array_flip( $keys );

$prev = ( isset( $keys[ $keyIndexes[ $curr ] - 1 ] ) ) ? $prev = $keys[ $keyIndexes[ $curr ] - 1 ] : FALSE;
$next = ( isset( $keys[ $keyIndexes[ $curr ] + 1 ] ) ) ? $next = $keys[ $keyIndexes[ $curr ] + 1 ] : FALSE;

$nextPage = ( $next ) ? $sorted_pages[$next] : null;
$previousPage = ( $prev ) ? $sorted_pages[$prev] : null;

}
}

}
39 changes: 26 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,22 +1,35 @@
Pico-Placing
============
PicoPlacing, to have a manual sort order for the pico menu
==========================================================

Pico v.1.0 - ready!

Provides Pico CMS with the ability to place the pages in any order according to a meta flag.
The pages are sorted and iterated in the specified order, for example in the navigation.
In case of same Placing-tag, first comes the page with the name first in alphabetical order.

1. Place the 'pico_placing.php' to your Pico install 'plugins' folder.
2. Add the following line to 'config.php' at the root of your Pico install:
Install
-------
1. Place the 'PicoPlacing.php' to your Pico install 'plugins' folder.
2. Add the following in your `config/config.php` file:

```
$config[ 'PicoPlacing.enabled' ] = TRUE;
$config[ 'pages_order_by' ] = 'placing';
```

```php
config['pages_order_by'] = 'placing';
3. Add 'Placing: #' in your page meta data. Example:
```
/*
Title: Example page
Author: John Doe
Date: 2016/2/1
Placing: 1
*/
```

3. Example page meta data:
4. Thats it, have fun :)

---
hope you like this. if something goes wrong, ask me.

/*
Title: Example page
Author: Jack Jackson
Date: 2014/1/1
Placing: 4
*/
Forked from: https://github.com/ollierik/Pico-Placing
76 changes: 0 additions & 76 deletions pico_placing.php

This file was deleted.