-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathpico_placing.php
76 lines (64 loc) · 1.79 KB
/
pico_placing.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
<?php
class Pico_Placing {
/**
* Pico-Placing
* Copyright (c) 2014 Olli Erik Keskinen
* All rights reserved.
*
* This code is released under The BSD 2-Clause License.
* See the file LICENSE.txt for information.
*
* @author Olli Erik Keskinen
* @license http://opensource.org/licenses/BSD-2-Clause
*/
public function before_read_file_meta(&$headers) {
$headers['placing'] = 'Placing';
}
//get_page_data(&$data, $page_meta)
public function get_page_data(&$data, $page_meta) {
$data['placing'] = isset($page_meta['placing']) ? intval($page_meta['placing']) : 0;
}
public function get_pages(&$pages, &$current_page, &$prev_page, &$next_page)
{
global $config;
if ($config['pages_order_by'] = 'placing') {
$sorted_pages = array();
$amountDigits = strlen($this->getHighestPlacing($pages));
$placing_id = 0;
foreach ($pages as $page) {
$sorted_pages[ $this->formatAmountDigits($page['placing'], $amountDigits) . '-' . $placing_id ] = $page;
$placing_id++;
}
ksort($sorted_pages);
$pages = $sorted_pages;
}
}
/**
* @param array $pages
* @return int
*/
private function getHighestPlacing(array $pages)
{
$highest = 0;
foreach($pages as $page) {
$placing = intval($page['placing']);
if( $placing > $highest ) {
$highest = $placing;
}
}
return $highest;
}
/**
* @param int|string $number
* @param int $digits
* @return string
*/
private function formatAmountDigits($number, $digits)
{
while( strlen($number) < $digits ) {
$number = '0' . $number;
}
return $number;
}
}
?>