LEPTON CMS 7.5.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
17
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
91
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
120
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 {
280 global $oLEPTON;
281 if (is_object($oLEPTON)) {
282 $current_template = ((isset($oLEPTON->page['template'])) && ($oLEPTON->page['template'] != ""))
283 ? $oLEPTON->page['template']
284 : DEFAULT_TEMPLATE
285 ;
286
287 $lookup_file = LEPTON_PATH."/templates/".$current_template."/frontend/".$module;
288 if (file_exists($lookup_file."/headers.inc.php")) {
289 LEPTON_core::addItems( $for,$lookup_file );
290 }
291 }
292 // End Aldus
293 }
294
295 $temp_css = array(
296 'modules/' . $module,
297 'modules/' . $module . '/css'
298 );
299
300 $temp_js = array(
301 'modules/' . $module,
302 'modules/' . $module . '/js'
303 );
304
305 // add css/js search subdirs for frontend only; page based CSS/JS
306 // does not make sense in BE
307 if ($for == 'frontend')
308 {
309 // Aldus:
310 $current_template = $oLEPTON->page['template'] != "" ? $oLEPTON->page['template'] : DEFAULT_TEMPLATE;
311 $lookup_file = "templates/".$current_template."/frontend/".$module;
312
313 $temp_css[] = $lookup_file;
314 $temp_css[] = $lookup_file."/css";
315
316 $temp_js[] = $lookup_file;
317 $temp_js[] = $lookup_file."/js";
318
319 // End Aldus
320
321 } // $for == 'frontend'
322 else {
323 // Aldus:
324 $current_theme = DEFAULT_THEME;
325 $lookup_file = "templates/".$current_theme."/backend/".$module;
326 $temp_css[] = $lookup_file;
327 $temp_css[] = $lookup_file."/css";
328
329 $temp_js[] = $lookup_file;
330 $temp_js[] = $lookup_file."/js";
331
332 // End Aldus
333 }
334
335 $css_subdirs[]= array_reverse($temp_css);
336 $js_subdirs[]= array_reverse($temp_js);
337
338 }
339 }
340 }
341
342 // automatically add CSS files
348 foreach ($css_subdirs as $first_level_ref)
349 {
350 $css_found = false;
351
352 foreach( $first_level_ref as $directory )
353 {
354 // frontend.css / backend.css
355 $file = $directory . '/' . $for . '.css';
356 if ((file_exists(LEPTON_PATH . '/' . $file)) && ($css_found === false))
357 {
358 LEPTON_core::$HEADERS[ $for ][ 'css' ][] = array(
359 'media' => 'all',
360 'file' => $file
361 );
362 $css_found = true;
363 }
364
365 }
366 }
367
372 if ( $for == 'frontend' ) {
373 $current_template = $oLEPTON->page['template'] != "" ? $oLEPTON->page['template'] : DEFAULT_TEMPLATE;
374 $lookup_files = array(
375 "templates/".$current_template."/css/".$page_id.".css",
376 "templates/".$current_template."/".$page_id.".css"
377 );
378
379 foreach($lookup_files as &$file) {
380 if ( file_exists( LEPTON_PATH . '/' . $file ) ) {
381 LEPTON_core::$HEADERS[ $for ][ 'css' ][] = array(
382 'media' => 'all',
383 'file' => $file
384 );
385 break;
386 }
387 }
388 unset($file);
389 }
390
391 // Automatically add JS files
392
393 foreach( $js_subdirs as &$first_level_ref )
394 {
395 $got_js = false;
396 foreach( $first_level_ref as $directory )
397 {
398 $file = $directory . '/' . $for . '.js';
399 if( ( file_exists( LEPTON_PATH . '/' . $file ) ) && ($got_js === false) )
400 {
401 LEPTON_core::$HEADERS[ $for ][ 'js' ][] = $file;
402 $got_js = true;
403 }
404 }
405 }
406 $output = null;
407
408 $HEADERS = &LEPTON_core::$HEADERS;
409
410 foreach (['css', 'jquery', 'js'] as $key )
411 {
412 if ( !isset( $HEADERS[ $for ][ $key ] ) || !is_array( $HEADERS[ $for ][ $key ] ) )
413 {
414 continue;
415 }
416
417 foreach ( $HEADERS[ $for ][ $key ] as $i => $arr )
418 {
419 switch ( $key )
420 {
421 case 'css':
422 if( file_exists( LEPTON_PATH."/".$arr['file'] ) )
423 {
424 // make sure we have an URI (LEPTON_URL included)
425 $file = ( preg_match( '#' . LEPTON_URL . '#i', $arr[ 'file' ] ) ? $arr[ 'file' ] : LEPTON_URL . '/' . $arr[ 'file' ] );
426 $output .= '<link rel="stylesheet" type="text/css" href="' . $file . '" media="' . ( isset( $arr[ 'media' ] ) ? $arr[ 'media' ] : 'all' ) . '" />' . "\n";
427 }
428 break;
429
430 case 'js':
431 $output .= '<script src="' . LEPTON_URL . '/' . $arr . '"></script>' . "\n";
432 break;
433
434 default:
435 trigger_error( 'Unknown header type [' . $key . '] [index '.$i.']!', E_USER_NOTICE );
436 break;
437 }
438 }
439 }
440
441 if ( true === $print_output )
442 {
443 echo $output;
444 define( 'LEP_HEADERS_SENT', true );
445 }
446 else
447 {
448 return $output;
449 }
450
451 }
static getRequest(string $sField="")
$root
Definition index.php:25
$level
Definition index.php:26
get_active_sections( $page_id, $block=null, $backend=false)
get_page_headers(string $for='frontend', bool $print_output=true, bool $individual=false)