LEPTON CMS 7.0.0
feel free to keep it strictly simple...
Loading...
Searching...
No Matches
function.preCheckAddon.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
39function preCheckAddon($temp_addon_file, $temp_path = NULL)
40{
46 global $TEXT, $HEADING, $MESSAGE;
49 LEPTON_handle::register("versionCompare","rm_full_dir");
50 // path to the temporary Add-on folder
51 if ($temp_path == '')
52 {
53 $temp_path = LEPTON_PATH . '/temp/unzip';
54 }
55
56 // check if file precheck.php exists for the Add-On uploaded via installation routine
57 if (!file_exists($temp_path . '/precheck.php')) {
58 return false;
59 }
60 else
61 {
62 // unset any previous declared PRECHECK array
63 unset($PRECHECK);
64 // include Add-On precheck.php file
65 require $temp_path . '/precheck.php';
66
67 // check if there are any Add-On requirements to check for
68 if (!(isset($PRECHECK) ))
69 {
70 return false;
71 }
72 else
73 {
74 $failed_checks = 0;
75 $msg = [];
76 // check if specified addon requirements are fullfilled
77 foreach ($PRECHECK as $key => $value)
78 {
79 switch ($key)
80 {
81 case 'VERSION': // for backward compatibility
82 case 'LEPTON_VERSION':
83 if (isset($value['VERSION']))
84 {
85 // obtain operator for string comparison if exist
86 $operator = (isset($value['OPERATOR']) && trim($value['OPERATOR']) != '') ? $value['OPERATOR'] : '>=';
87 // compare versions and extract actual status
88 $status = versionCompare(LEPTON_VERSION, $value['VERSION'], $operator);
89 $msg[] = array(
90 'check' => sprintf('LEPTON-%s: ', $TEXT['VERSION']),
91 'required' => sprintf('%s %s', $operator, $value['VERSION']),
92 'actual' => LEPTON_VERSION,
93 'status' => $status
94 );
95 // increase counter if required
96 if (!$status)
97 {
98 $failed_checks++;
99 }
100 }
101 break;
102
103 case 'ADDONS':
104 foreach( $PRECHECK['ADDONS'] as $addon => $values)
105 {
106 if (is_array($values))
107 {
108 // extract module version and operator
109 $version = (isset($values['VERSION']) && trim($values['VERSION']) != '') ? $values['VERSION'] : '';
110 $operator = (isset($values['OPERATOR']) && trim($values['OPERATOR']) != '') ? $values['OPERATOR'] : '>=';
111 }
112 else
113 {
114 // no version and operator specified (only check if addon exists)
115 $addon = strip_tags($values);
116 $version = '';
117 $operator = '';
118 }
119
120 // check if addon is listed in database
121 $aAddon = [];
122 $database->execute_query(
123 "SELECT * from ".TABLE_PREFIX."addons WHERE directory = '".addslashes($addon)."' ",
124 true,
125 $aAddon,
126 false
127 );
128
129 $status = false;
130 $addon_status = $TEXT['NOT_INSTALLED'];
131 if (!empty($aAddon))
132 {
133 $status = true;
134 $addon_status = $TEXT['INSTALLED'];
135
136 // compare version if required
137 if ($version != '')
138 {
139 $status = versionCompare($aAddon['version'], $version, $operator);
140 $addon_status = $aAddon['version'];
141 }
142 }
143
144 // provide addon status
145 $msg[] = array(
146 'check' => '&nbsp; ' . $TEXT['ADDON'] . ': ' . $addon,
147 'required' => ($version != '') ? $operator . '&nbsp;' . $version : $TEXT['INSTALLED'],
148 'actual' => $addon_status,
149 'status' => $status
150 );
151
152 // increase counter if required
153 if (!$status)
154 {
155 $failed_checks++;
156 }
157 }
158
159 break;
160
161 case 'PHP_VERSION':
162 if (isset($value['VERSION']))
163 {
164 // obtain operator for string comparison if exist
165 $operator = (isset($value['OPERATOR']) && trim($value['OPERATOR']) != '') ? $value['OPERATOR'] : '>=';
166
167 // compare versions and extract actual status
168 $status = versionCompare(PHP_VERSION, $value['VERSION'], $operator);
169 $msg[] = array(
170 'check' => 'PHP-' . $TEXT['VERSION'] . ': ',
171 'required' => $operator . '&nbsp;' . $value['VERSION'],
172 'actual' => PHP_VERSION,
173 'status' => $status
174 );
175
176 // increase counter if required
177 if (!$status)
178 {
179 $failed_checks++;
180 }
181 }
182 break;
183
184 case 'PHP_EXTENSIONS':
185 if (is_array($PRECHECK['PHP_EXTENSIONS']))
186 {
187 foreach ($PRECHECK['PHP_EXTENSIONS'] as $extension)
188 {
189 $status = extension_loaded(strtolower($extension));
190 $msg[] = array(
191 'check' => '&nbsp; ' . $TEXT['EXTENSION'] . ': ' . $extension,
192 'required' => $TEXT['INSTALLED'],
193 'actual' => ($status) ? $TEXT['INSTALLED'] : $TEXT['NOT_INSTALLED'],
194 'status' => $status
195 );
196
197 // increase counter if required
198 if (!$status)
199 {
200 $failed_checks++;
201 }
202 }
203 }
204 break;
205
206 case 'PHP_SETTINGS':
207 if (is_array($PRECHECK['PHP_SETTINGS']))
208 {
209 foreach ($PRECHECK['PHP_SETTINGS'] as $setting => $value)
210 {
211 $actual_setting = ($temp = ini_get($setting)) ? $temp : 0;
212 $status = ($actual_setting == $value);
213
214 $msg[] = array(
215 'check' => '&nbsp; ' . ($setting),
216 'required' => $value,
217 'actual' => $actual_setting,
218 'status' => $status
219 );
220
221 // increase counter if required
222 if (!$status)
223 {
224 $failed_checks++;
225 }
226 }
227 }
228 break;
229
230 case 'CUSTOM_CHECKS':
231 if (is_array($PRECHECK['CUSTOM_CHECKS']))
232 {
233 foreach ($PRECHECK['CUSTOM_CHECKS'] as $key => $values)
234 {
235 $status = (true === array_key_exists('STATUS', $values)) ? $values['STATUS'] : false;
236 $msg[] = array(
237 'check' => $key,
238 'required' => $values['REQUIRED'],
239 'actual' => $values['ACTUAL'],
240 'status' => $status
241 );
242 }
243
244 // increase counter if required
245 if (!$status)
246 {
247 $failed_checks++;
248 }
249 }
250 break;
251
252 default:
253 // -- nothing match
254 break;
255 }
256 }
257
258 // exit if all requirements are fullfilled
259 if ($failed_checks == 0)
260 {
261 return true;
262 }
263 else
264 {
265 // output summary table with requirements not fullfilled
266 echo "
267 <h2>".$HEADING['ADDON_PRECHECK_FAILED']."</h2>
268 <p>".$MESSAGE['ADDON_PRECHECK_FAILED']."</p>
269
270 <table width='700px' cellpadding='4' border='0' style='margin: 0.5em; border-collapse: collapse; border: 1px solid silver;'>
271 <tr>
272 <th>".$TEXT['REQUIREMENT'].":</th>
273 <th>".$TEXT['REQUIRED'].":</th>
274 <th>".$TEXT['CURRENT'].":</th>
275 </tr>
276 ";
277
278 foreach ($msg as $check)
279 {
280 echo '<tr>';
281 $style = $check['status'] ? 'color: #46882B;' : 'color: #C00;';
282 foreach ($check as $key => $value)
283 {
284 if ($key == 'status')
285 {
286 continue;
287 }
288 echo '<td style="' . $style . '">' . $value . '</td>';
289 }
290 echo '</tr>';
291 }
292 echo '</table>';
293
294 // delete the temp unzip directory
295 rm_full_dir($temp_path);
296
297 // delete the temporary zip file of the Add-on
298 if (file_exists($temp_addon_file))
299 {
300 unlink($temp_addon_file);
301 }
302
303 // output status message and die
304 $admin->print_error('');
305 }
306 }
307 }
308}
$temp
static getInstance()
static getInstance(array &$settings=[])
$database
Definition constants.php:52
preCheckAddon($temp_addon_file, $temp_path=NULL)
rm_full_dir(string $directory)
versionCompare(string $version1, string $version2, string $operator='>=')