LEPTON CMS 7.0.0
feel free to keep it strictly simple...
Loading...
Searching...
No Matches
function.get_page_headers.php
Go to the documentation of this file.
1<?php
2
18// include secure.php to protect this file and the whole CMS!
19if(!defined("SEC_FILE")){define("SEC_FILE",'/framework/secure.php' );}
20if (defined('LEPTON_PATH')) {
21 include LEPTON_PATH.SEC_FILE;
22} else {
23 $oneback = "../";
24 $root = $oneback;
25 $level = 1;
26 while (($level < 10) && (!file_exists($root.SEC_FILE))) {
27 $root .= $oneback;
28 $level += 1;
29 }
30 if (file_exists($root.SEC_FILE)) {
31 include $root.SEC_FILE;
32 } else {
33 trigger_error(sprintf("[ <b>%s</b> ] Can't include secure.php!", $_SERVER['SCRIPT_NAME']), E_USER_ERROR);
34 }
35}
36// end include secure file
37
38
67 function get_page_headers(string $for = 'frontend', bool $print_output = true, bool $individual = false)
68 {
69 // don't do this twice
70 if (defined('LEP_HEADERS_SENT'))
71 {
72 return true;
73 }
74
75 if (!$for || $for == '' || ($for != 'frontend' && $for != 'backend'))
76 {
77 $for = 'frontend';
78 }
79
80 $page_id = LEPTON_request::getPageID();
81
82 LEPTON_handle::register("get_droplet_headers", "get_active_sections");
83
92 // load headers.inc.php for backend theme
93 if (($for === 'backend') && (file_exists(LEPTON_PATH . '/templates/' . DEFAULT_THEME . '/headers.inc.php')))
94 {
95 LEPTON_core::addItems($for, LEPTON_PATH . '/templates/' . DEFAULT_THEME);
96 }
97
98 else // it is for the frontend
99 {
100 // Search results are comming up with own template!
101 if ((defined("TEMPLATE")) && (TEMPLATE != DEFAULT_TEMPLATE))
102 {
103 if (file_exists(LEPTON_PATH . '/templates/' . TEMPLATE . '/headers.inc.php'))
104 {
105 LEPTON_core::addItems($for, LEPTON_PATH . '/templates/' . TEMPLATE);
106 }
107 }
108 elseif (file_exists( LEPTON_PATH . '/templates/' . DEFAULT_TEMPLATE . '/headers.inc.php' ) )
109 {
110 LEPTON_core::addItems( $for, LEPTON_PATH . '/templates/' . DEFAULT_TEMPLATE );
111 }
112 }
113
114 // handle search
121 // the page is called from the LEPTON SEARCH
122 if ($for == "frontend")
123 {
124 $css_loaded = false;
125 $js_loaded = false;
126
127 global $oLEPTON;
128
129 $current_template = ((isset($oLEPTON->page['template'])) && ($oLEPTON->page['template'] != ""))
130 ? $oLEPTON->page['template']
131 : DEFAULT_TEMPLATE
132 ;
133
134 $lookup_file = "templates/" . $current_template . "/frontend/lib_search";
135
136 foreach ([$lookup_file, 'modules/lib_search/templates'] as $directory )
137 {
138 $file = $directory . '/' . $for . '.css';
139 if ((file_exists(LEPTON_PATH . '/' . $file)) && (false === $css_loaded))
140 {
141 LEPTON_core::$HEADERS[ $for ][ 'css' ][] = array(
142 'media' => 'all',
143 'file' => $file
144 );
145 $css_loaded = true;
146 }
147
148 $file = $directory . '/' . $for . '.js';
149 if ((file_exists(LEPTON_PATH . '/' . $file)) && (false === $js_loaded))
150 {
151 LEPTON_core::$HEADERS[ $for ][ 'js' ][] = $file;
152 $js_loaded = true;
153 }
154 }
155
159 if (stripos($_SERVER['REQUEST_URI'], "/account/") !== FALSE ) {
160
161 $lookup_files = array(
162 "templates/" . $current_template . "/frontend/login/css/frontend.css",
163 "account/css/frontend.css"
164 );
165
166 foreach ($lookup_files as &$lookup_file) {
167 if (file_exists(LEPTON_PATH . "/" . $lookup_file)) {
168 LEPTON_core::$HEADERS['frontend']['css'][] = array(
169 'media' => 'all',
170 'file' => $lookup_file
171 );
172 break;
173 }
174 }
175 unset($lookup_file);
176 }
177 }
178
179 // load CSS and JS for droplets
180 if ( ( $for == 'frontend' )
181 && ( isset( $page_id ) )
182 && ( is_numeric( $page_id ) )
183 && ( file_exists( LEPTON_PATH . '/framework/summary.droplets.php' ) )
184 )
185 {
186 get_droplet_headers( $page_id );
187 }
188
189 $css_subdirs = [];
190 $js_subdirs = [];
191
192 // it's an admin tool ...
193 // Aldus:: Test for L* 5.3
194 $sToolName = (LEPTON_request::getRequest("tool") ?? "");
195
196 if ( $for == 'backend' && ( $sToolName !== "" ) && file_exists( LEPTON_PATH . '/modules/' . $sToolName . '/tool.php' ) )
197 {
198 // css part
199 $css_subdirs[] = array(
200 'modules/' . $sToolName,
201 'modules/' . $sToolName . '/css'
202 );
203 // Aldus (2017-08-10): looking into the backend-theme for module css
204 $temp_lookup_path = LEPTON_PATH."/templates/".DEFAULT_THEME."/backend/".$sToolName."/";
205 if( file_exists($temp_lookup_path) )
206 {
207 $ref = &$css_subdirs[ (count($css_subdirs)-1) ]; // !
208 $ref[] = "templates/".DEFAULT_THEME."/backend/".$sToolName;
209 $ref[] = "templates/".DEFAULT_THEME."/backend/".$sToolName."/css";
210 $ref = array_reverse($ref);
211 }
212
213 // js part
214 $js_subdirs[] = array(
215 '/modules/' . $sToolName,
216 '/modules/' . $sToolName . '/js'
217 );
218 // Aldus (2017-08-10): looking into the backend-theme for module java-scripts
219 if( file_exists($temp_lookup_path) )
220 {
221 $ref = &$js_subdirs[ (count($js_subdirs)-1) ]; // !
222 $ref[] = "templates/".DEFAULT_THEME."/backend/".$sToolName;
223 $ref[] = "templates/".DEFAULT_THEME."/backend/".$sToolName."/js";
224 $ref = array_reverse($ref);
225 }
226
227 // headers.inc part
228 if ( file_exists( LEPTON_PATH . '/modules/' . $sToolName . '/headers.inc.php' ) )
229 {
230 LEPTON_core::addItems( $for, LEPTON_PATH . '/modules/' . $sToolName );
231 }
232 }
233
234 // if we have a page id...
235 elseif ( $page_id && is_numeric( $page_id ) )
236 {
237 // ... get active sections
238 $sections = get_active_sections( $page_id, NULL, ($for === "backend") );
239
240 if ( ( is_array( $sections ) ) && ( count( $sections ) > 0 ) )
241 {
242 global $current_section;
243 global $mod_headers;
244
245 // local storage to avoid to load css/js twice
246 $processed_modules = array();
247
248 foreach ( $sections as $section )
249 {
250 $module = $section[ 'module' ];
251
252 if(in_array($module, $processed_modules)) {
253 // still processed
254 continue;
255 } else {
256 $processed_modules[] = $module;
257 }
258
259 $headers_path = LEPTON_PATH . '/modules/' . $module;
260 // special case: 'wysiwyg'
261 if ( $for == 'backend' && !strcasecmp( $module, 'wysiwyg' ) )
262 {
263 // get the currently used WYSIWYG module
264 if ( defined( 'WYSIWYG_EDITOR' ) && WYSIWYG_EDITOR != "none" )
265 {
266 $headers_path = LEPTON_PATH . '/modules/' . WYSIWYG_EDITOR;
267 }
268 }
269 // find header definition file
270 if ( file_exists( $headers_path . '/headers.inc.php' ) )
271 {
272 $current_section = $section[ 'section_id' ];
273 LEPTON_core::addItems( $for, $headers_path );
274 }
275 else
276 {
281 global $oLEPTON;
282 if (is_object($oLEPTON)) {
283 $current_template = ((isset($oLEPTON->page['template'])) && ($oLEPTON->page['template'] != ""))
284 ? $oLEPTON->page['template']
285 : DEFAULT_TEMPLATE
286 ;
287
288 $lookup_file = LEPTON_PATH."/templates/".$current_template."/frontend/".$module;
289 if (file_exists($lookup_file."/headers.inc.php")) {
290 LEPTON_core::addItems( $for,$lookup_file );
291 }
292 }
293 // End Aldus
294 }
295
296 $temp_css = array(
297 'modules/' . $module,
298 'modules/' . $module . '/css'
299 );
300
301 $temp_js = array(
302 'modules/' . $module,
303 'modules/' . $module . '/js'
304 );
305
306 // add css/js search subdirs for frontend only; page based CSS/JS
307 // does not make sense in BE
308 if ($for == 'frontend')
309 {
310 // Aldus:
311 $current_template = $oLEPTON->page['template'] != "" ? $oLEPTON->page['template'] : DEFAULT_TEMPLATE;
312 $lookup_file = "templates/".$current_template."/frontend/".$module;
313
314 $temp_css[] = $lookup_file;
315 $temp_css[] = $lookup_file."/css";
316
317 $temp_js[] = $lookup_file;
318 $temp_js[] = $lookup_file."/js";
319
320 // End Aldus
321
322 } // $for == 'frontend'
323 else {
324 // Aldus:
325 $current_theme = DEFAULT_THEME;
326 $lookup_file = "templates/".$current_theme."/backend/".$module;
327 $temp_css[] = $lookup_file;
328 $temp_css[] = $lookup_file."/css";
329
330 $temp_js[] = $lookup_file;
331 $temp_js[] = $lookup_file."/js";
332
333 // End Aldus
334 }
335
336 $css_subdirs[]= array_reverse($temp_css);
337 $js_subdirs[]= array_reverse($temp_js);
338
339 }
340 }
341 }
342
343 // automatically add CSS files
349 foreach ($css_subdirs as $first_level_ref)
350 {
351 $css_found = false;
352
353 foreach( $first_level_ref as $directory )
354 {
355 // frontend.css / backend.css
356 $file = $directory . '/' . $for . '.css';
357 if ((file_exists(LEPTON_PATH . '/' . $file)) && ($css_found === false))
358 {
359 LEPTON_core::$HEADERS[ $for ][ 'css' ][] = array(
360 'media' => 'all',
361 'file' => $file
362 );
363 $css_found = true;
364 }
365
366 }
367 }
368
373 if ( $for == 'frontend' ) {
374 $current_template = $oLEPTON->page['template'] != "" ? $oLEPTON->page['template'] : DEFAULT_TEMPLATE;
375 $lookup_files = array(
376 "templates/".$current_template."/css/".$page_id.".css",
377 "templates/".$current_template."/".$page_id.".css"
378 );
379
380 foreach($lookup_files as &$file) {
381 if ( file_exists( LEPTON_PATH . '/' . $file ) ) {
382 LEPTON_core::$HEADERS[ $for ][ 'css' ][] = array(
383 'media' => 'all',
384 'file' => $file
385 );
386 break;
387 }
388 }
389 unset($file);
390 }
391
392 // Automatically add JS files
393
394 foreach( $js_subdirs as &$first_level_ref )
395 {
396 $got_js = false;
397 foreach( $first_level_ref as $directory )
398 {
399 $file = $directory . '/' . $for . '.js';
400 if( ( file_exists( LEPTON_PATH . '/' . $file ) ) && ($got_js === false) )
401 {
402 LEPTON_core::$HEADERS[ $for ][ 'js' ][] = $file;
403 $got_js = true;
404 }
405 }
406 }
407 $output = null;
408
409 $HEADERS = &LEPTON_core::$HEADERS;
410
411 foreach (['css', 'jquery', 'js'] as $key )
412 {
413 if ( !isset( $HEADERS[ $for ][ $key ] ) || !is_array( $HEADERS[ $for ][ $key ] ) )
414 {
415 continue;
416 }
417
418 foreach ( $HEADERS[ $for ][ $key ] as $i => $arr )
419 {
420 switch ( $key )
421 {
422 case 'css':
423 if( file_exists( LEPTON_PATH."/".$arr['file'] ) )
424 {
425 // make sure we have an URI (LEPTON_URL included)
426 $file = ( preg_match( '#' . LEPTON_URL . '#i', $arr[ 'file' ] ) ? $arr[ 'file' ] : LEPTON_URL . '/' . $arr[ 'file' ] );
427 $output .= '<link rel="stylesheet" type="text/css" href="' . $file . '" media="' . ( isset( $arr[ 'media' ] ) ? $arr[ 'media' ] : 'all' ) . '" />' . "\n";
428 }
429 break;
430
431 case 'js':
432 $output .= '<script src="' . LEPTON_URL . '/' . $arr . '"></script>' . "\n";
433 break;
434
435 default:
436 trigger_error( 'Unknown header type [' . $key . '] [index '.$i.']!', E_USER_NOTICE );
437 break;
438 }
439 }
440 }
441
442 if ( true === $print_output )
443 {
444 echo $output;
445 define( 'LEP_HEADERS_SENT', true );
446 }
447 else
448 {
449 return $output;
450 }
451
452 }
static getRequest(string $sField="")
get_active_sections( $page_id, $block=null, $backend=false)
get_page_headers(string $for='frontend', bool $print_output=true, bool $individual=false)