This repository has been archived by the owner on Aug 20, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathpico_breadcrumbs.php
130 lines (93 loc) · 2.3 KB
/
pico_breadcrumbs.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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
<?php
/**
* Breadcrumbs plugin for Pico CMS
*
* @author nebman
*/
class Pico_Breadcrumbs {
private $breadcrumbs = array();
private $page_names = array();
private $settings = array();
public function plugins_loaded()
{
}
public function config_loaded(&$settings)
{
$this->settings = $settings;
}
public function request_url(&$url)
{
$this->breadcrumbs = explode('/', $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['author_url'] = 'Author_URL';
}
public function file_meta(&$meta)
{
}
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)
{
foreach( $pages as $page ){
$title = $page['meta']['title'] ? : $page['title'];
$this->page_names[$page['url']] = $title;
}
}
public function before_twig_register()
{
}
public function before_render(&$twig_vars, &$twig, &$template)
{
$breadcrumbs = array();
$url = $this->settings['base_url'];
foreach ($this->breadcrumbs as $crumb) {
$url = $url . (substr($url, -1) == '/' ? '' : '/') . $crumb;
$exists = $this->url_exists($crumb);
$name = isset($this->page_names[$url]) ? $this->page_names[$url] : (isset($this->page_names[$url.'/']) ? $this->page_names[$url.'/'] : urldecode($crumb));
if(!empty($name)) {
$breadcrumbs[] = array('url' => $url, 'name' => $name, 'exists' => $exists );
}
}
$twig_vars['breadcrumbs'] = $breadcrumbs;
}
public function after_render(&$output)
{
}
/*
* URL to check whether the real URL ( copy from Pico source )
*
* @param $url URL
*
*/
private function url_exists($url)
{
$file = "";
if($url) $file = $this->settings['content_dir'] . $url;
else $file = $this->settings['content_dir'] .'index';
if(is_dir($file)) $file = $this->settings['content_dir'] . $url .'/index'. CONTENT_EXT;
else $file .= CONTENT_EXT;
return file_exists($file);
}
}
?>