-
Notifications
You must be signed in to change notification settings - Fork 1
/
pico_tagcounter.php
99 lines (80 loc) · 1.84 KB
/
pico_tagcounter.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
<?php
/**
* Tag count Pico plugin
*
* @author D.B.C.
* @link https://github.com/DBC-Works
* @license http://opensource.org/licenses/MIT
*/
class Pico_TagCounter {
private $count_tag;
private $tag_counter;
/*
* Constructor
*/
public function __construct() {
$this->tag_counter = array();
}
/*
* Callback functions
*/
public function plugins_loaded() {
}
public function config_loaded(&$settings) {
}
public function request_url(&$url) {
}
public function before_load_content(&$file) {
}
public function after_load_content(&$file, &$content) {
}
public function before_404_load_content(&$file) {
}
public function after_404_load_content(&$file, &$content) {
}
public function before_read_file_meta(&$headers) {
$headers['count_tag'] = 'CountTag';
}
public function file_meta(&$meta) {
$this->count_tag = $meta['count_tag'];
}
public function before_parse_content(&$content) {
}
public function after_parse_content(&$content) {
}
public function get_page_data(&$data, $page_meta) {
}
public function get_pages(&$pages, &$current_page, &$prev_page, &$next_page) {
if ($this->count_tag != NULL) {
foreach ($pages as $page) {
$tags = $page['tags'];
if (!is_array($tags)) {
$tags = explode(',', $tags);
}
foreach ($tags as $tag) {
if ($tag != '') {
if (isset($this->tag_counter[$tag])) {
$this->tag_counter[$tag] += 1;
}
else {
$this->tag_counter[$tag] = 1;
}
}
}
}
}
}
public function before_twig_register() {
}
public function before_render(&$twig_vars, &$twig, &$template) {
if ($this->count_tag != NULL) {
arsort($this->tag_counter);
$twig_vars['tag_count'] = $this->count_tag == 'ForClient'
? json_encode($this->tag_counter)
: $this->tag_counter;
}
}
public function after_render(&$output) {
}
}
?>