-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSite.php
224 lines (204 loc) · 5.63 KB
/
Site.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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
<?php defined('MONSTRA_ACCESS') or die('No direct script access.');
/**
* Monstra Engine
*
* This source file is part of the Monstra Engine. More information,
* documentation and tutorials can be found at http://monstra.org
*
* @package Monstra
*
* @author Romanenko Sergey / Awilum <[email protected]>
* @copyright 2012-2014 Romanenko Sergey / Awilum <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
class Site
{
/**
* An instance of the Site class
*
* @var site
*/
protected static $instance = null;
/**
* Initializing site
*
* @return Site
*/
public static function init()
{
if ( ! isset(self::$instance)) self::$instance = new Site();
return self::$instance;
}
/**
* Protected clone method to enforce singleton behavior.
*
* @access protected
*/
protected function __clone()
{
// Nothing here.
}
/**
* Construct
*/
protected function __construct()
{
call_user_func(ucfirst(Uri::command()).'::main');
}
/**
* Get site name
*
* <code>
* echo Site::name();
* </code>
*
* @return string
*/
public static function name()
{
return Option::get('sitename');
}
/**
* Get site theme
*
* <code>
* echo Site::theme();
* </code>
*
* @return string
*/
public static function theme()
{
return Option::get('theme_site_name');
}
/**
* Get Page title
*
* <code>
* echo Site::title();
* </code>
*
* @return string
*/
public static function title()
{
return call_user_func(ucfirst(Uri::command()).'::title');
}
/**
* Get page description
*
* <code>
* echo Site::description();
* </code>
*
* @return string
*/
public static function description()
{
return (($description = trim(call_user_func(ucfirst(Uri::command()).'::description'))) == '') ? Html::toText(Option::get('description')) : Html::toText($description);
}
/**
* Get page keywords
*
* <code>
* echo Site::keywords();
* </code>
*
* @return string
*/
public static function keywords()
{
return (($keywords = trim(call_user_func(ucfirst(Uri::command()).'::keywords'))) == '') ? Html::toText(Option::get('keywords')) : Html::toText($keywords);
}
/**
* Get site slogan
*
* <code>
* echo Site::slogan();
* </code>
*
* @return string
*/
public static function slogan()
{
return Option::get('slogan');
}
/**
* Get page content
*
* <code>
* echo Site::content();
* </code>
*
* @return string
*/
public static function content()
{
return Filter::apply('content', call_user_func(ucfirst(Uri::command()).'::content'));
}
/**
* Get compressed template
*
* <code>
* echo Site::template();
* </code>
*
* @param string $theme Theme name
* @return mixed
*/
public static function template($theme = null)
{
// Get specific theme or current theme
$current_theme = ($theme == null) ? Option::get('theme_site_name') : $theme ;
// Get template
$template = call_user_func(ucfirst(Uri::command()).'::template');
// Check whether is there such a template in the current theme
// else return default template: index
// also compress template file :)
if (File::exists(THEMES_SITE . DS . $current_theme . DS . $template . '.template.php')) {
if ( ! file_exists(MINIFY . DS . 'theme.' . $current_theme . '.minify.' . $template . '.template.php') or
filemtime(THEMES_SITE . DS . $current_theme . DS . $template .'.template.php') > filemtime(MINIFY . DS . 'theme.' . $current_theme . '.minify.' . $template . '.template.php')) {
$buffer = file_get_contents(THEMES_SITE. DS . $current_theme . DS . $template .'.template.php');
$buffer = MinifyHTML::process($buffer);
file_put_contents(MINIFY . DS . 'theme.' . $current_theme . '.minify.' . $template . '.template.php', $buffer);
}
return 'minify.'.$template;
} else {
if ( ! File::exists(MINIFY . DS . 'theme.' . $current_theme . '.' . 'minify.index.template.php') or
filemtime(THEMES_SITE . DS . $current_theme . DS . 'index.template.php') > filemtime(MINIFY . DS . 'theme.' . $current_theme . '.' . 'minify.index.template.php')) {
$buffer = file_get_contents(THEMES_SITE . DS . $current_theme . DS . 'index.template.php');
$buffer = MinifyHTML::process($buffer);
file_put_contents(MINIFY . DS . 'theme.' . $current_theme . '.' . 'minify.index.template.php', $buffer);
}
return 'minify.index';
}
}
/**
* Get site url
*
* <code>
* echo Site::url();
* </code>
*
* @return string
*/
public static function url()
{
return Option::get('siteurl');
}
/**
* Get copyright information
*
* <code>
* echo Site::powered();
* </code>
*
* @return string
*/
public static function powered()
{
return __('Powered by', 'system').' <a href="http://monstra.org" target="_blank">Monstra</a> ' . Monstra::VERSION;
}
}