LEPTON CMS 7.0.0
feel free to keep it strictly simple...
Loading...
Searching...
No Matches
function.get_page_footers.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
51function get_page_footers(string $for = 'frontend' ): string
52{
53
54 LEPTON_handle::register("get_active_sections");
55
56 $FOOTERS = &LEPTON_core::$FOOTERS;
57
58 // don't do this twice
59 if ( defined( 'LEP_FOOTERS_SENT' ) )
60 {
61 return "";
62 }
63
64 // Temp. additional infostring
65 $sAdditionalInfo = "";
66
67 // Initialize var with an empty string.
68 $module = '';
69
70 if (($for != 'frontend') && ($for != 'backend'))
71 {
72 $for = 'frontend';
73 $oLEPTON = LEPTON_frontend::getInstance();
74 }
75 // Aldus: 2021-07-16 L* 5.3
76 $page_id = LEPTON_request::getPageID();
77
78 if ($page_id === NULL)
79 {
80 $page_id = -1; //
81 }
82
83 $js_subdirs = [];
84 // it's an admin tool...
85 $sMyTool = filter_input(INPUT_GET,'tool',FILTER_SANITIZE_SPECIAL_CHARS) ?? '';
86 if ($for == 'backend' && isset($sMyTool) && file_exists(LEPTON_PATH.'/modules/'.$sMyTool.'/tool.php'))
87 {
88 $js_subdirs[] = [
89 'modules/'.$sMyTool.'/js',
90 'modules/'.$sMyTool
91 ];
92 if (file_exists(LEPTON_PATH.'/modules/'.$sMyTool.'/footers.inc.php'))
93 {
94 LEPTON_core::addItems($for, LEPTON_PATH.'/modules/'.$sMyTool, true);
95 }
96 }
97 elseif ($page_id && is_numeric($page_id))
98 {
99 $sections = get_active_sections($page_id, NULL, ($for === "backend"));
100 if (is_array($sections) && count($sections))
101 {
102 global $current_section;
103
104 // avoid loading modules twice!
105 $loaded_modules = [];
106
107 foreach ($sections as $section)
108 {
109
110 $module = $section['module'];
111
112 if (in_array($module, $loaded_modules))
113 {
114 continue;
115 }
116 $loaded_modules[] = $module;
117
118 // find header definition file
119 if (file_exists(LEPTON_PATH.'/modules/'.$module.'/footers.inc.php'))
120 {
121 $current_section = $section['section_id'];
122 LEPTON_core::addItems($for, LEPTON_PATH.'/modules/'.$module, true);
123
124 } else {
125
126 $current_template = (isset($oLEPTON->page['template']) && ($oLEPTON->page['template'] != '')) ? $oLEPTON->page['template'] : DEFAULT_TEMPLATE;
127
128 if (file_exists(LEPTON_PATH.'/templates/'.$current_template.'/footers.inc.php'))
129 {
130 $current_section = $section['section_id'];
131 LEPTON_core::addItems($for, LEPTON_PATH.'/templates/'.$current_template, true);
132
133 }
134 }
135
136 $temp_js = [
137 'modules/'.$module,
138 'modules/'.$module.'/js'
139 ];
140
141 if ($for == 'frontend')
142 {
143 $current_template = (isset($oLEPTON->page['template']) && ($oLEPTON->page['template'] != '')) ? $oLEPTON->page['template'] : DEFAULT_TEMPLATE;
144 $lookup_file = "templates/".$current_template."/frontend/".$module;
145
146 } // end $for == 'frontend'
147 else {
148 // start $for == 'backend'
149 $current_theme = DEFAULT_THEME;
150 $lookup_file = "templates/".$current_theme."/backend/".$module;
151
152 // end $for == 'backend'
153 }
154 $temp_js[] = $lookup_file;
155 $temp_js[] = $lookup_file."/js";
156
157 $js_subdirs[]= array_reverse($temp_js);
158 }
159 }
160 // add css/js search subdirs for frontend only; page based CSS/JS
161 // does not make sense in BE
162 if ($for == 'frontend')
163 {
164 $js_subdirs[] = [
165 PAGES_DIRECTORY,
166 PAGES_DIRECTORY . '/js'
167 ];
168 }
169 }
170 else
171 {
172 // load footers if no page_id exists (/account)
173 $sAdditionalInfo .= "\n<!-- no page_id, no modules -->\n";
174 // [3.1] Make sure that the correct template footers.inc.php is loaded
175 // [3.1.0] is it the search result page?
176 $sTempPagePath = filter_input(INPUT_SERVER, "REQUEST_URI", FILTER_SANITIZE_FULL_SPECIAL_CHARS);
177
178 if (str_contains($sTempPagePath, "frontend_result"))
179 {
180 $sAdditionalInfo .= "\n<!-- search results -->\n";
181
182 // [3.1.1] Get the template-name from the db-table "search"
183 $sTempTemplateName = LEPTON_database::getInstance()->get_one("SELECT `value` FROM `".TABLE_PREFIX."search` where `name`='template'");
184
185 // [3.1.2] Temp path
186 $sTempLookUp = LEPTON_PATH."/templates/".$sTempTemplateName."/footers.inc.php";
187 if (file_exists($sTempLookUp))
188 {
189 // 3.1.3 require the file
190 LEPTON_core::addItems($for, LEPTON_PATH.'/templates/'.$sTempTemplateName, true);
191 }
192 }
193 else
194 {
195 // [3.2.0] WHAT ist it? Frontend account?
196
197 // [3.3.0] We try to get the default template footers.imc.php
198 $sAdditionalInfo .= "\n<!-- default frontend template -->\n";
199
200 // [3.3.1] Temp path
201 $sTempLookUp = LEPTON_PATH."/templates/".DEFAULT_TEMPLATE."/footers.inc.php";
202 if (file_exists($sTempLookUp))
203 {
204 // [3.3.2] require the file
205 LEPTON_core::addItems($for, LEPTON_PATH . '/templates/' . DEFAULT_TEMPLATE, true);
206 }
207 }
208 }
209
210 // add template JS
211 // note: defined() is just to avoid warnings, the NULL does not really make sense!
212 if ($for == 'backend')
213 {
214 $subdir = (defined('DEFAULT_THEME') ? DEFAULT_THEME : NULL);
215 } else {
216 $subdir = (defined('TEMPLATE') ? TEMPLATE : NULL);
217 }
218
219 if (($module != '') && (!isset($loaded_modules)))
220 {
221 $js_subdirs[0][] = 'templates/'.$subdir.'/backend/'.$module;
222 $js_subdirs[0][] = 'templates/'.$subdir.'/backend/'.$module.'/js';
223 $js_subdirs[0]= array_reverse($js_subdirs[0]);
224 }
225
226 $js_subdirs[] = [
227 'templates/' . $subdir . '/js',
228 'templates/' . $subdir
229 ];
230
231 // automatically add JS files
232 foreach ($js_subdirs as $first_level_dir)
233 {
234 foreach ($first_level_dir as $directory)
235 {
236 $file = $directory.'/'.$for.'_body.js';
237
238 if (file_exists(LEPTON_PATH.'/'.$file))
239 {
240 $FOOTERS[$for]['js'][] = $file;
241 break;
242 }
243 }
244 }
245
246 $output = '';
247
248 foreach ($FOOTERS[$for]['js'] as $arr)
249 {
250 $output .= '<script src="'.LEPTON_URL.'/'.$arr.'"></script>'."\n";
251 }
252
253 define('LEP_FOOTERS_SENT', true);
254
255 $sAdditionalInfo .= "\n<!-- get_page_footer - ".$for."-->\n";
256
257 if ($for == 'frontend')
258 {
259 echo $sAdditionalInfo.$output;
260 return "";
261
262 }
263 else
264 {
265 return $sAdditionalInfo.$output;
266 }
267}
static getInstance(array &$settings=[])
get_active_sections( $page_id, $block=null, $backend=false)
get_page_footers(string $for='frontend')