-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcmsfunctions.php
executable file
·290 lines (232 loc) · 6.12 KB
/
cmsfunctions.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
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
<?php if (!defined('CLYDEPHP')) { header ('HTTP/1.1 404 Not Found'); exit(1); }
define('BONNIECMS_VERSION','0.5.0');
define('MENU_LIST',1);
define('MENU_SIMPLE',2);
require_once CLYDEPHP_VENDOR.'minify/HTML.php';
require_once CLYDEPHP_VENDOR.'minify/CSS.php';
/**
* Useful alias functions for template designer, that reduce php
* code in template
*
*/
function __text($key) {
echo Lang::getMessage($key);
}
function __webRoot() {
echo String::slash(getCmsConfig('WEB_ROOT'));
}
function __webRootTemplate($templateName = null) {
echo getTemplateWebRoot($templateName);
}
function __siteName() {
echo getCmsConfig('SITE_NAME');
}
function __siteSlogan() {
echo getCmsConfig('SITE_SLOGAN');
}
function __conf($key,$context='site') {
echo getCmsConfig($key,$context);
}
function __url($id,$locale=null,$type='page') {
echo makeLink($id,$locale,$type);
}
function __meta($name,$content) {
echo HTML::meta($name,$content);
}
function __anchor($url='#',$text=null,$extra='') {
echo HTML::anchor($url,$text,$extra);
}
function __image($src='#',$extra='') {
echo HTML::image($src,$extra);
}
function __renderStaticBlock($name) {
$tpl = new Template(getBlocksDir().$name.'.php');
echo $tpl->render();
}
function __sendEvent($name) {
EventManager::getInstance()->getEvent($name)->raise();
}
/**
* common functions
*
*
*/
function getWebRoot() {
return String::slash(getCmsConfig('WEB_ROOT'));
}
function getSiteName() {
return getCmsConfig('SITE_NAME');
}
function getSiteSlogan() {
return getCmsConfig('SITE_SLOGAN');
}
function getCmsConfig($key=null,$context='site') {
return Cms::getConfigKey($key,$context);
}
/**
* Get data dir path
*
* @param $absolute retrieve absolute data dir or relative data dir
*/
function getDataDir($absolute=false) {
if ($absolute) {
return DOC_ROOT.'data/';
}
return APP_ROOT.'data/';
}
function getBlocksDir($absolute=false) {
return getDataDir($absolute).'blocks/';
}
/**
* Get logs dir path
*
* @param $absolute retrieve absolute logs dir or relative logs dir
*/
function getLogsDir($absolute=false) {
return getDataDir($absolute).'logs/';
}
/**
* Get conf dir path
*
* @param $absolute retrieve absolute conf dir or relative conf dir
*/
function getConfDir($absolute=false) {
$env = $_SERVER['HTTP_HOST'];
$base = APP_ROOT;
if ($absolute){
$base = DOC_ROOT;
}
//if exist and is readable, return specific server configuration dir
if (is_readable($base.'conf_'.$env.'/')) {
return $base.'conf_'.$env.'/';
}
//else return standard configuration dir
return $base.'conf/';
}
function getPluginsDir() {
return DOC_ROOT.'plugins/';
}
function getTemplateDir($tplName=null) {
if (is_null($tplName)) {
return DOC_ROOT.'templates/';
}
return DOC_ROOT.'templates/'.$tplName.'/';
}
function getTemplateWebRoot($tplName=null) {
if (is_null($tplName)) {
$tplName = getCmsConfig('TEMPLATE');
}
return getWebRoot().'templates/'.$tplName.'/';
}
function getTemplateName() {
$conf = getCmsConfig();
if (!isset($conf['TEMPLATE']))
return null;
return $conf['TEMPLATE'];
}
function loadTemplate($file,$tplName=null) {
$tFile = findTemplate($file,$tplName);
if (is_null($tFile)) return null;
return new HtmlTemplate($tFile);
}
function findTemplate($file,$tplName) {
if ( (is_null($tplName) || $tplName === '') &&
(is_null($file) || $file === ''))
return null;
//try to load first in the template dir
if (is_readable(getTemplateDir($tplName).$file)) {
return getTemplateDir($tplName).$file;
}
//try to load in the root template dir
if (is_readable(getTemplateDir().$file)) {
return getTemplateDir().$file;
}
return null;
}
function makeLink($id,$locale=null,$type='page') {
$webRoot = getWebRoot();
$lang="";
$conf = getCmsConfig();
if (!is_null($locale) && $locale !== $conf['LANG'])
$lang='&lang='.$locale;
switch ($type) {
case 'page':
return $webRoot.'page.php?page='.String::slugify($id).$lang;
case 'download':
return $webRoot.'services/download.php?file='.$id;
case 'css':
return $webRoot.'css.php?css='.$id;
default:
return null;
}
}
function buildMenu($name,$type= MENU_LIST) {
global $menu_list;
$menu = $menu_list[$name];
$out = '';
if ($type == MENU_LIST) $out = '<ul>';
foreach ($menu as $key => $value) {
switch ($type) {
case MENU_LIST:
$out .= '<li><a href=\''.$value['url'].'\'>'.$value['text'].'</a></li>';
break;
default:
$out .= '<a href=\''.$value['url'].'\'>'.$value['text'].'</a>';
}
}
if ($type == MENU_LIST) $out .= '</ul>';
return $out;
}
/**
* Return the choosen menu
*
* @param $name menu name
* @return array list of menu items
*/
function getMenu($name) {
global $menu_list;
if (isset($menu_list[$name]))
return $menu_list[$name];
return array();
}
/**
* Check if an menu item is selected
*
* @param $menu the menu to inspect
* @param $item the menu item to check
* @return bool true or false if the menu item is selected or not
*/
function checkCurrentMenuUrl($menu,$item) {
global $menu_list;
if (isset($menu_list[$menu]) && isset($menu_list[$menu][$item]))
return $menu_list[$menu][$item]['url'] === Url::fullUrl();
return false;
}
/**
* Get the key of the menu item selected
*
*
* @param $menu the menu to inspect
* @return mixed the menu item select or false otherwise
*/
function getCurrentMenuItem($menu) {
global $menu_list;
$currentUrl = Url::fullUrl();
if (isset($menu_list[$menu])) {
foreach ($menu_list[$menu] as $key => $value) {
if ($currentUrl === $value['url'])
return $key;
}
}
return false;
}
function minifyHtml($html=null) {
if (!is_null($html) && is_string($html))
return Minify_HTML::minify($html);
return null;
}
function minifyCss($css,$options=array()) {
if (!is_null($css) && is_string($css))
return Minify_CSS::minify($css,$options);
return null;
}