Revision 1291
Added by Luisehahne over 15 years ago
| branches/2.8.x/CHANGELOG | ||
|---|---|---|
| 12 | 12 |
|
| 13 | 13 |
------------------------------------- 2.8.1 ------------------------------------- |
| 14 | 14 |
19-Feb-2010 Dietmar Woellbrink (Luisehahne) |
| 15 |
! recoded function extract_permission in /framework/functions.php |
|
| 16 |
! change URL_HELP to http://www.websitebaker2.org/ in /framework/class.admin.php |
|
| 17 |
! recoded function preprocess in /framework/class.frontend.php |
|
| 18 |
! optimize function getVersion in /framework/addon.precheck.inc.php |
|
| 19 |
19-Feb-2010 Dietmar Woellbrink (Luisehahne) |
|
| 15 | 20 |
! change constant EDIT_ONE_SECTION to default false |
| 16 | 21 |
08-Feb-2010 Dietmar Woellbrink (Luisehahne) |
| 17 | 22 |
! missunderstanding back to old logo |
| branches/2.8.x/wb/admin/interface/version.php | ||
|---|---|---|
| 52 | 52 |
|
| 53 | 53 |
// check if defined to avoid errors during installation (redirect to admin panel fails if PHP error/warnings are enabled) |
| 54 | 54 |
if(!defined('VERSION')) define('VERSION', '2.8.x');
|
| 55 |
if(!defined('REVISION')) define('REVISION', '1290');
|
|
| 55 |
if(!defined('REVISION')) define('REVISION', '1291');
|
|
| 56 | 56 |
|
| 57 | 57 |
?> |
| branches/2.8.x/wb/framework/class.admin.php | ||
|---|---|---|
| 134 | 134 |
'TITLE_HELP' => $MENU['HELP'], |
| 135 | 135 |
'TITLE_LOGOUT' => $MENU['LOGOUT'], |
| 136 | 136 |
'URL_VIEW' => $view_url, |
| 137 |
'URL_HELP' => 'http://www.websitebaker.org/', |
|
| 137 |
'URL_HELP' => 'http://www.websitebaker2.org/',
|
|
| 138 | 138 |
'BACKEND_MODULE_CSS' => $this->register_backend_modfiles('css'), // adds backend.css
|
| 139 | 139 |
'BACKEND_MODULE_JS' => $this->register_backend_modfiles('js') // adds backend.js
|
| 140 | 140 |
) |
| ... | ... | |
| 406 | 406 |
} elseif(isset($_GET['page_id']) or isset($_POST['page_id'])) {
|
| 407 | 407 |
// check if displayed page in the backend contains a page module |
| 408 | 408 |
if (isset($_GET['page_id'])) {
|
| 409 |
$page_id = (int) addslashes($_GET['page_id']);
|
|
| 409 |
$page_id = (int)$_GET['page_id'];
|
|
| 410 | 410 |
} else {
|
| 411 |
$page_id = (int) addslashes($_POST['page_id']);
|
|
| 411 |
$page_id = (int)$_POST['page_id'];
|
|
| 412 | 412 |
} |
| 413 | 413 |
|
| 414 | 414 |
// gather information for all models embedded on actual page |
| branches/2.8.x/wb/framework/addon.precheck.inc.php | ||
|---|---|---|
| 1 |
<?php |
|
| 2 |
/** |
|
| 3 |
* $Id$ |
|
| 4 |
* Website Baker Add-On precheck functions |
|
| 5 |
* |
|
| 6 |
* This file contains the functions of the pretest performed upfront |
|
| 7 |
* of the Add-On installation process. The functions allows developers |
|
| 8 |
* to specify requirements for their Add-On. |
|
| 9 |
* |
|
| 10 |
* LICENSE: GNU Lesser General Public License 3.0 |
|
| 11 |
* |
|
| 12 |
* @author Christian Sommer |
|
| 13 |
* @copyright (c) 2009 |
|
| 14 |
* @license http://www.gnu.org/copyleft/lesser.html |
|
| 15 |
* @version 0.2.3 |
|
| 16 |
* @platform Website Baker 2.7 |
|
| 17 |
* |
|
| 18 |
* Website Baker Project <http://www.websitebaker.org/> |
|
| 19 |
* Copyright (C) 2004-2009, Ryan Djurovich |
|
| 20 |
* |
|
| 21 |
* Website Baker is free software; you can redistribute it and/or modify |
|
| 22 |
* it under the terms of the GNU General Public License as published by |
|
| 23 |
* the Free Software Foundation; either version 2 of the License, or |
|
| 24 |
* (at your option) any later version. |
|
| 25 |
* |
|
| 26 |
* Website Baker is distributed in the hope that it will be useful, |
|
| 27 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
| 28 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
| 29 |
* GNU General Public License for more details. |
|
| 30 |
* |
|
| 31 |
* You should have received a copy of the GNU General Public License |
|
| 32 |
* along with Website Baker; if not, write to the Free Software |
|
| 33 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
| 34 |
*/ |
|
| 35 |
|
|
| 36 |
// prevent this file from being accessed directly |
|
| 37 |
if (!defined('WB_PATH')) die(header('Location: ../index.php'));
|
|
| 38 |
|
|
| 39 |
function getVersion($version, $strip_suffix = true) |
|
| 40 |
{
|
|
| 41 |
/** |
|
| 42 |
* This funtion creates a version string following the major.minor.revision convention |
|
| 43 |
* The minor and revision part of the version may not exceed 999 (three digits) |
|
| 44 |
* An optional suffix part can be added after revision (requires $strip_suffix = false) |
|
| 45 |
* |
|
| 46 |
* EXAMPLES: input --> output |
|
| 47 |
* 5 --> 5.000000; 5.0 --> 5.000000; 5.0.0 --> 5.000000 |
|
| 48 |
* 5.2 --> 5.002000; 5.20 --> 5.002000; 5.2.0 --> 5.002000 |
|
| 49 |
* 5.21 --> 5.002001; 5.2.1 --> 5.002001; |
|
| 50 |
* 5.27.1 --> 5.027001; 5.2.71 --> 5.002071; |
|
| 51 |
* 5.27.1 rc1 --> 5.027001_RC1 ($strip_suffix:= false) |
|
| 52 |
*/ |
|
| 53 |
// replace comma by decimal point |
|
| 54 |
$version = str_replace(',', '.', $version);
|
|
| 55 |
|
|
| 56 |
// convert version into major.minor.revision numbering system |
|
| 57 |
list($major, $minor, $revision) = explode('.', $version, 3);
|
|
| 58 |
|
|
| 59 |
// convert versioning style 5.21 into 5.2.1 |
|
| 60 |
if ($revision == '' && strlen(intval($minor)) == 2) {
|
|
| 61 |
$revision = substr($minor, -1); |
|
| 62 |
$minor = substr($minor, 0, 1); |
|
| 63 |
} |
|
| 64 |
|
|
| 65 |
// extract possible non numerical suffix from revision part (e.g. Alpha, Beta, RC1) |
|
| 66 |
$suffix = strtoupper(trim(substr($revision, strlen(intval($revision))))); |
|
| 67 |
|
|
| 68 |
// return standard version number (minor and revision numbers may not exceed 999) |
|
| 69 |
return (int) $major . '.' . sprintf('%03d', (int) $minor) . sprintf('%03d', (int) $revision) .
|
|
| 70 |
(($strip_suffix == false && $suffix != '') ? '_' . $suffix : ''); |
|
| 71 |
} |
|
| 72 |
|
|
| 73 |
/** |
|
| 74 |
* As "version_compare" it self seems only got trouble |
|
| 75 |
* within words like "Alpha", "Beta" a.s.o. this function |
|
| 76 |
* only modify the version-string in the way that these words are replaced by values/numbers. |
|
| 77 |
* |
|
| 78 |
* E.g: "1.2.3 Beta2" => "1.2.322" |
|
| 79 |
* "0.1.1 ALPHA" => "0.1.11" |
|
| 80 |
* |
|
| 81 |
* Notice: Please keep in mind, that this will not correct the way "version_control" |
|
| 82 |
* handel "1 < 1.0 < 1.0.0 < 1.0.0.0" and will not correct missformed version-strings |
|
| 83 |
* below 2.7, e.g. "1.002 released candidate 2.3" |
|
| 84 |
* |
|
| 85 |
* @since 2.8.0 RC2 |
|
| 86 |
* |
|
| 87 |
* @param string A versionstring |
|
| 88 |
* @return string The modificated versionstring |
|
| 89 |
* |
|
| 90 |
*/ |
|
| 91 |
function getVersion2 ($version="") {
|
|
| 92 |
|
|
| 93 |
$states = array ( |
|
| 94 |
'1' => "alpha", |
|
| 95 |
'2' => "beta", |
|
| 96 |
'4' => "rc", |
|
| 97 |
'8' => "final" |
|
| 98 |
); |
|
| 99 |
|
|
| 100 |
$version = strtolower($version); |
|
| 101 |
|
|
| 102 |
foreach($states as $value=>$keys) $version = str_replace($keys, $value, $version); |
|
| 103 |
|
|
| 104 |
$version = str_replace(" ", "", $version);
|
|
| 105 |
|
|
| 106 |
return $version; |
|
| 107 |
} |
|
| 108 |
|
|
| 109 |
function versionCompare($version1, $version2, $operator = '>=') |
|
| 110 |
{
|
|
| 111 |
/** |
|
| 112 |
* This funtion performs a comparison of two provided version strings |
|
| 113 |
* The versions are first converted into a string following the major.minor.revision |
|
| 114 |
* convention and performs a version_compare afterwards. |
|
| 115 |
*/ |
|
| 116 |
// return version_compare(getVersion($version1), getVersion($version2), $operator); |
|
| 117 |
return version_compare(getVersion2($version1), getVersion2($version2), $operator); |
|
| 118 |
} |
|
| 119 |
|
|
| 120 |
function sortPreCheckArray($precheck_array) |
|
| 121 |
{
|
|
| 122 |
/** |
|
| 123 |
* This funtion sorts the precheck array to a common format |
|
| 124 |
*/ |
|
| 125 |
// define desired precheck order |
|
| 126 |
$key_order = array('WB_VERSION', 'WB_ADDONS', 'PHP_VERSION', 'PHP_EXTENSIONS', 'PHP_SETTINGS', 'CUSTOM_CHECKS');
|
|
| 127 |
|
|
| 128 |
$temp_array = array(); |
|
| 129 |
foreach($key_order as $key) {
|
|
| 130 |
if (!isset($precheck_array[$key])) continue; |
|
| 131 |
$temp_array[$key] = $precheck_array[$key]; |
|
| 132 |
} |
|
| 133 |
return $temp_array; |
|
| 134 |
} |
|
| 135 |
|
|
| 136 |
function preCheckAddon($temp_addon_file) |
|
| 137 |
{
|
|
| 138 |
/** |
|
| 139 |
* This funtion performs pretest upfront of the Add-On installation process. |
|
| 140 |
* The requirements can be specified via the array $PRECHECK which needs to |
|
| 141 |
* be defined in the optional Add-on file precheck.php. |
|
| 142 |
*/ |
|
| 143 |
global $database, $admin, $TEXT, $HEADING, $MESSAGE; |
|
| 144 |
|
|
| 145 |
// path to the temporary Add-on folder |
|
| 146 |
$temp_path = WB_PATH . '/temp/unzip'; |
|
| 147 |
|
|
| 148 |
// check if file precheck.php exists for the Add-On uploaded via WB installation routine |
|
| 149 |
if (!file_exists($temp_path . '/precheck.php')) return; |
|
| 150 |
|
|
| 151 |
// unset any previous declared PRECHECK array |
|
| 152 |
unset($PRECHECK); |
|
| 153 |
|
|
| 154 |
// include Add-On precheck.php file |
|
| 155 |
include($temp_path . '/precheck.php'); |
|
| 156 |
|
|
| 157 |
// check if there are any Add-On requirements to check for |
|
| 158 |
if (!(isset($PRECHECK) && count($PRECHECK) > 0)) return; |
|
| 159 |
|
|
| 160 |
// sort precheck array |
|
| 161 |
$PRECHECK = sortPreCheckArray($PRECHECK); |
|
| 162 |
|
|
| 163 |
$failed_checks = 0; |
|
| 164 |
$msg = array(); |
|
| 165 |
// check if specified addon requirements are fullfilled |
|
| 166 |
foreach ($PRECHECK as $key => $value) {
|
|
| 167 |
switch ($key) {
|
|
| 168 |
case 'WB_VERSION': |
|
| 169 |
if (isset($value['VERSION'])) {
|
|
| 170 |
// obtain operator for string comparison if exist |
|
| 171 |
$operator = (isset($value['OPERATOR']) && trim($value['OPERATOR']) != '') ? $value['OPERATOR'] : '>='; |
|
| 172 |
|
|
| 173 |
// compare versions and extract actual status |
|
| 174 |
$status = versionCompare(WB_VERSION, $value['VERSION'], $operator); |
|
| 175 |
$msg[] = array( |
|
| 176 |
'check' => 'WB-' . $TEXT['VERSION'] .': ', |
|
| 177 |
'required' => htmlentities($operator) . $value['VERSION'], |
|
| 178 |
'actual' => WB_VERSION, |
|
| 179 |
'status' => $status |
|
| 180 |
); |
|
| 181 |
|
|
| 182 |
// increase counter if required |
|
| 183 |
if (!$status) $failed_checks++; |
|
| 184 |
} |
|
| 185 |
break; |
|
| 186 |
|
|
| 187 |
case 'WB_ADDONS': |
|
| 188 |
if (is_array($PRECHECK['WB_ADDONS'])) {
|
|
| 189 |
foreach($PRECHECK['WB_ADDONS'] as $addon => $values) {
|
|
| 190 |
if (is_array($values)) {
|
|
| 191 |
// extract module version and operator |
|
| 192 |
$version = (isset($values['VERSION']) && trim($values['VERSION']) != '') ? $values['VERSION'] : ''; |
|
| 193 |
$operator = (isset($values['OPERATOR']) && trim($values['OPERATOR']) != '') ? $values['OPERATOR'] : '>='; |
|
| 194 |
} else {
|
|
| 195 |
// no version and operator specified (only check if addon exists) |
|
| 196 |
$addon = strip_tags($values); |
|
| 197 |
$version = ''; $operator = ''; |
|
| 198 |
} |
|
| 199 |
|
|
| 200 |
// check if addon is listed in WB database |
|
| 201 |
$table = TABLE_PREFIX . 'addons'; |
|
| 202 |
$sql = "SELECT * FROM `$table` WHERE `directory` = '" . addslashes($addon) . "'"; |
|
| 203 |
$results = $database->query($sql); |
|
| 204 |
|
|
| 205 |
$status = false; $addon_status = $TEXT['NOT_INSTALLED']; |
|
| 206 |
if ($results && $row = $results->fetchRow()) {
|
|
| 207 |
$status = true; |
|
| 208 |
$addon_status = $TEXT['INSTALLED']; |
|
| 209 |
|
|
| 210 |
// compare version if required |
|
| 211 |
if ($version != '') {
|
|
| 212 |
$status = versionCompare($row['version'], $version, $operator); |
|
| 213 |
$addon_status = $row['version']; |
|
| 214 |
} |
|
| 215 |
} |
|
| 216 |
|
|
| 217 |
// provide addon status |
|
| 218 |
$msg[] = array( |
|
| 219 |
'check' => ' ' . $TEXT['ADDON'] . ': ' . htmlentities($addon), |
|
| 220 |
'required' => ($version != '') ? $operator . ' ' . $version : $TEXT['INSTALLED'], |
|
| 221 |
'actual' => $addon_status, |
|
| 222 |
'status' => $status |
|
| 223 |
); |
|
| 224 |
|
|
| 225 |
// increase counter if required |
|
| 226 |
if (!$status) $failed_checks++; |
|
| 227 |
} |
|
| 228 |
} |
|
| 229 |
break; |
|
| 230 |
|
|
| 231 |
case 'PHP_VERSION': |
|
| 232 |
if (isset($value['VERSION'])) {
|
|
| 233 |
// obtain operator for string comparison if exist |
|
| 234 |
$operator = (isset($value['OPERATOR']) && trim($value['OPERATOR']) != '') ? $value['OPERATOR'] : '>='; |
|
| 235 |
|
|
| 236 |
// compare versions and extract actual status |
|
| 237 |
$status = versionCompare(PHP_VERSION, $value['VERSION'], $operator); |
|
| 238 |
$msg[] = array( |
|
| 239 |
'check' => 'PHP-' . $TEXT['VERSION'] .': ', |
|
| 240 |
'required' => htmlentities($operator) . ' ' . $value['VERSION'], |
|
| 241 |
'actual' => PHP_VERSION, |
|
| 242 |
'status' => $status |
|
| 243 |
); |
|
| 244 |
|
|
| 245 |
// increase counter if required |
|
| 246 |
if (!$status) $failed_checks++; |
|
| 247 |
|
|
| 248 |
} |
|
| 249 |
break; |
|
| 250 |
|
|
| 251 |
case 'PHP_EXTENSIONS': |
|
| 252 |
if (is_array($PRECHECK['PHP_EXTENSIONS'])) {
|
|
| 253 |
foreach($PRECHECK['PHP_EXTENSIONS'] as $extension) {
|
|
| 254 |
$status = extension_loaded(strtolower($extension)); |
|
| 255 |
$msg[] = array( |
|
| 256 |
'check' => ' ' . $TEXT['EXTENSION'] . ': ' . htmlentities($extension), |
|
| 257 |
'required' => $TEXT['INSTALLED'], |
|
| 258 |
'actual' => ($status) ? $TEXT['INSTALLED'] : $TEXT['NOT_INSTALLED'], |
|
| 259 |
'status' => $status |
|
| 260 |
); |
|
| 261 |
|
|
| 262 |
// increase counter if required |
|
| 263 |
if (!$status) $failed_checks++; |
|
| 264 |
} |
|
| 265 |
} |
|
| 266 |
break; |
|
| 267 |
|
|
| 268 |
case 'PHP_SETTINGS': |
|
| 269 |
if (is_array($PRECHECK['PHP_SETTINGS'])) {
|
|
| 270 |
foreach($PRECHECK['PHP_SETTINGS'] as $setting => $value) {
|
|
| 271 |
$actual_setting = ($temp = ini_get($setting)) ? $temp : 0; |
|
| 272 |
$status = ($actual_setting == $value); |
|
| 273 |
|
|
| 274 |
$msg[] = array( |
|
| 275 |
'check' => ' '. ($setting), |
|
| 276 |
'required' => $value, |
|
| 277 |
'actual' => $actual_setting, |
|
| 278 |
'status' => $status |
|
| 279 |
); |
|
| 280 |
|
|
| 281 |
// increase counter if required |
|
| 282 |
if (!$status) $failed_checks++; |
|
| 283 |
} |
|
| 284 |
} |
|
| 285 |
break; |
|
| 286 |
|
|
| 287 |
case 'CUSTOM_CHECKS': |
|
| 288 |
if (is_array($PRECHECK['CUSTOM_CHECKS'])) {
|
|
| 289 |
foreach($PRECHECK['CUSTOM_CHECKS'] as $key => $values) {
|
|
| 290 |
$status = (true === array_key_exists('STATUS', $values )) ? $values['STATUS'] : false;
|
|
| 291 |
$msg[] = array( |
|
| 292 |
'check' => $key, |
|
| 293 |
'required' => $values['REQUIRED'], |
|
| 294 |
'actual' => $values['ACTUAL'], |
|
| 295 |
'status' => $status |
|
| 296 |
); |
|
| 297 |
} |
|
| 298 |
|
|
| 299 |
// increase counter if required |
|
| 300 |
if (!$status) $failed_checks++; |
|
| 301 |
} |
|
| 302 |
break; |
|
| 303 |
} |
|
| 304 |
} |
|
| 305 |
|
|
| 306 |
// leave if all requirements are fullfilled |
|
| 307 |
if ($failed_checks == 0) return; |
|
| 308 |
|
|
| 309 |
// output summary table with requirements not fullfilled |
|
| 310 |
echo <<< EOT |
|
| 311 |
<h2>{$HEADING['ADDON_PRECHECK_FAILED']}</h2>
|
|
| 312 |
<p>{$MESSAGE['ADDON']['PRECHECK_FAILED']}</p>
|
|
| 313 |
|
|
| 314 |
<table width="700px" cellpadding="4" border="0" style="margin: 0.5em; border-collapse: collapse; border: 1px solid silver;"> |
|
| 315 |
<tr> |
|
| 316 |
<th>{$TEXT['REQUIREMENT']}:</th>
|
|
| 317 |
<th>{$TEXT['REQUIRED']}:</th>
|
|
| 318 |
<th>{$TEXT['CURRENT']}:</th>
|
|
| 319 |
</tr> |
|
| 320 |
EOT; |
|
| 321 |
|
|
| 322 |
foreach($msg as $check) {
|
|
| 323 |
echo '<tr>'; |
|
| 324 |
$style = $check['status'] ? 'color: #46882B;' : 'color: #C00;'; |
|
| 325 |
foreach($check as $key => $value) {
|
|
| 326 |
if ($key == 'status') continue; |
|
| 327 |
|
|
| 328 |
echo '<td style="' . $style . '">' . $value . '</td>'; |
|
| 329 |
} |
|
| 330 |
echo '</tr>'; |
|
| 331 |
} |
|
| 332 |
echo '</table>'; |
|
| 333 |
|
|
| 334 |
// delete the temp unzip directory |
|
| 335 |
rm_full_dir($temp_path); |
|
| 336 |
|
|
| 337 |
// delete the temporary zip file of the Add-on |
|
| 338 |
if(file_exists($temp_addon_file)) { unlink($temp_addon_file); }
|
|
| 339 |
|
|
| 340 |
// output status message and die |
|
| 341 |
$admin->print_error('');
|
|
| 342 |
} |
|
| 343 |
|
|
| 1 |
<?php |
|
| 2 |
/** |
|
| 3 |
* |
|
| 4 |
* @category module |
|
| 5 |
* @package precheck |
|
| 6 |
* @author WebsiteBaker Project |
|
| 7 |
* @copyright 2004-2009, Ryan Djurovich |
|
| 8 |
* @copyright 2009-2010, Website Baker Org. e.V. |
|
| 9 |
* @link http://www.websitebaker2.org/ |
|
| 10 |
* @license http://www.gnu.org/licenses/gpl.html |
|
| 11 |
* @platform WebsiteBaker 2.8.x |
|
| 12 |
* @requirements PHP 4.4.9 and higher |
|
| 13 |
* @version $Id$ |
|
| 14 |
* @filesource $HeadURL$ |
|
| 15 |
* @lastmodified $Date$ |
|
| 16 |
* |
|
| 17 |
*/ |
|
| 18 |
|
|
| 19 |
// prevent this file from being accessed directly |
|
| 20 |
if (!defined('WB_PATH')) die(header('Location: ../index.php'));
|
|
| 21 |
|
|
| 22 |
function getVersion($version, $strip_suffix = true) |
|
| 23 |
{
|
|
| 24 |
/** |
|
| 25 |
* This funtion creates a version string following the major.minor.revision convention |
|
| 26 |
* The minor and revision part of the version may not exceed 999 (three digits) |
|
| 27 |
* An optional suffix part can be added after revision (requires $strip_suffix = false) |
|
| 28 |
* |
|
| 29 |
* EXAMPLES: input --> output |
|
| 30 |
* 5 --> 5.000000; 5.0 --> 5.000000; 5.0.0 --> 5.000000 |
|
| 31 |
* 5.2 --> 5.002000; 5.20 --> 5.002000; 5.2.0 --> 5.002000 |
|
| 32 |
* 5.21 --> 5.002001; 5.2.1 --> 5.002001; |
|
| 33 |
* 5.27.1 --> 5.027001; 5.2.71 --> 5.002071; |
|
| 34 |
* 5.27.1 rc1 --> 5.027001_RC1 ($strip_suffix:= false) |
|
| 35 |
*/ |
|
| 36 |
// replace comma by decimal point |
|
| 37 |
$version = str_replace(',', '.', $version);
|
|
| 38 |
|
|
| 39 |
// convert version into major.minor.revision numbering system |
|
| 40 |
list($major, $minor, $revision) = explode('.', $version, 3);
|
|
| 41 |
|
|
| 42 |
// convert versioning style 5.21 into 5.2.1 |
|
| 43 |
if ($revision == '' && strlen(intval($minor)) == 2) {
|
|
| 44 |
$revision = substr($minor, -1); |
|
| 45 |
$minor = substr($minor, 0, 1); |
|
| 46 |
} |
|
| 47 |
|
|
| 48 |
// extract possible non numerical suffix from revision part (e.g. Alpha, Beta, RC1) |
|
| 49 |
$suffix = strtoupper(trim(substr($revision, strlen(intval($revision))))); |
|
| 50 |
|
|
| 51 |
/* |
|
| 52 |
return (int)$major . '.' . sprintf('%03d', (int)$minor) . sprintf('%03d', (int)$revision) .
|
|
| 53 |
(($strip_suffix == false && $suffix != '') ? '_' . $suffix : ''); |
|
| 54 |
*/ |
|
| 55 |
// return standard version number (minor and revision numbers may not exceed 999) |
|
| 56 |
return sprintf('%d.%03d.%03d%s', (int)$major, (int)minor, (int)$revision,
|
|
| 57 |
(($strip_suffix == false && $suffix != '') ? '_' . $suffix : '')); |
|
| 58 |
} |
|
| 59 |
|
|
| 60 |
/** |
|
| 61 |
* As "version_compare" it self seems only got trouble |
|
| 62 |
* within words like "Alpha", "Beta" a.s.o. this function |
|
| 63 |
* only modify the version-string in the way that these words are replaced by values/numbers. |
|
| 64 |
* |
|
| 65 |
* E.g: "1.2.3 Beta2" => "1.2.322" |
|
| 66 |
* "0.1.1 ALPHA" => "0.1.11" |
|
| 67 |
* |
|
| 68 |
* Notice: Please keep in mind, that this will not correct the way "version_control" |
|
| 69 |
* handel "1 < 1.0 < 1.0.0 < 1.0.0.0" and will not correct missformed version-strings |
|
| 70 |
* below 2.7, e.g. "1.002 released candidate 2.3" |
|
| 71 |
* |
|
| 72 |
* @since 2.8.0 RC2 |
|
| 73 |
* |
|
| 74 |
* @param string A versionstring |
|
| 75 |
* @return string The modificated versionstring |
|
| 76 |
* |
|
| 77 |
*/ |
|
| 78 |
function getVersion2 ($version="") {
|
|
| 79 |
|
|
| 80 |
$states = array ( |
|
| 81 |
'1' => "alpha", |
|
| 82 |
'2' => "beta", |
|
| 83 |
'4' => "rc", |
|
| 84 |
'8' => "final" |
|
| 85 |
); |
|
| 86 |
|
|
| 87 |
$version = strtolower($version); |
|
| 88 |
|
|
| 89 |
foreach($states as $value=>$keys) $version = str_replace($keys, $value, $version); |
|
| 90 |
|
|
| 91 |
$version = str_replace(" ", "", $version);
|
|
| 92 |
|
|
| 93 |
return $version; |
|
| 94 |
} |
|
| 95 |
|
|
| 96 |
function versionCompare($version1, $version2, $operator = '>=') |
|
| 97 |
{
|
|
| 98 |
/** |
|
| 99 |
* This funtion performs a comparison of two provided version strings |
|
| 100 |
* The versions are first converted into a string following the major.minor.revision |
|
| 101 |
* convention and performs a version_compare afterwards. |
|
| 102 |
*/ |
|
| 103 |
// return version_compare(getVersion($version1), getVersion($version2), $operator); |
|
| 104 |
return version_compare(getVersion2($version1), getVersion2($version2), $operator); |
|
| 105 |
} |
|
| 106 |
|
|
| 107 |
function sortPreCheckArray($precheck_array) |
|
| 108 |
{
|
|
| 109 |
/** |
|
| 110 |
* This funtion sorts the precheck array to a common format |
|
| 111 |
*/ |
|
| 112 |
// define desired precheck order |
|
| 113 |
$key_order = array('WB_VERSION', 'WB_ADDONS', 'PHP_VERSION', 'PHP_EXTENSIONS', 'PHP_SETTINGS', 'CUSTOM_CHECKS');
|
|
| 114 |
|
|
| 115 |
$temp_array = array(); |
|
| 116 |
foreach($key_order as $key) {
|
|
| 117 |
if (!isset($precheck_array[$key])) continue; |
|
| 118 |
$temp_array[$key] = $precheck_array[$key]; |
|
| 119 |
} |
|
| 120 |
return $temp_array; |
|
| 121 |
} |
|
| 122 |
|
|
| 123 |
function preCheckAddon($temp_addon_file) |
|
| 124 |
{
|
|
| 125 |
/** |
|
| 126 |
* This funtion performs pretest upfront of the Add-On installation process. |
|
| 127 |
* The requirements can be specified via the array $PRECHECK which needs to |
|
| 128 |
* be defined in the optional Add-on file precheck.php. |
|
| 129 |
*/ |
|
| 130 |
global $database, $admin, $TEXT, $HEADING, $MESSAGE; |
|
| 131 |
|
|
| 132 |
// path to the temporary Add-on folder |
|
| 133 |
$temp_path = WB_PATH . '/temp/unzip'; |
|
| 134 |
|
|
| 135 |
// check if file precheck.php exists for the Add-On uploaded via WB installation routine |
|
| 136 |
if (!file_exists($temp_path . '/precheck.php')) return; |
|
| 137 |
|
|
| 138 |
// unset any previous declared PRECHECK array |
|
| 139 |
unset($PRECHECK); |
|
| 140 |
|
|
| 141 |
// include Add-On precheck.php file |
|
| 142 |
include($temp_path . '/precheck.php'); |
|
| 143 |
|
|
| 144 |
// check if there are any Add-On requirements to check for |
|
| 145 |
if (!(isset($PRECHECK) && count($PRECHECK) > 0)) return; |
|
| 146 |
|
|
| 147 |
// sort precheck array |
|
| 148 |
$PRECHECK = sortPreCheckArray($PRECHECK); |
|
| 149 |
|
|
| 150 |
$failed_checks = 0; |
|
| 151 |
$msg = array(); |
|
| 152 |
// check if specified addon requirements are fullfilled |
|
| 153 |
foreach ($PRECHECK as $key => $value) {
|
|
| 154 |
switch ($key) {
|
|
| 155 |
case 'WB_VERSION': |
|
| 156 |
if (isset($value['VERSION'])) {
|
|
| 157 |
// obtain operator for string comparison if exist |
|
| 158 |
$operator = (isset($value['OPERATOR']) && trim($value['OPERATOR']) != '') ? $value['OPERATOR'] : '>='; |
|
| 159 |
|
|
| 160 |
// compare versions and extract actual status |
|
| 161 |
$status = versionCompare(WB_VERSION, $value['VERSION'], $operator); |
|
| 162 |
$msg[] = array( |
|
| 163 |
'check' => 'WB-' . $TEXT['VERSION'] .': ', |
|
| 164 |
'required' => htmlentities($operator) . $value['VERSION'], |
|
| 165 |
'actual' => WB_VERSION, |
|
| 166 |
'status' => $status |
|
| 167 |
); |
|
| 168 |
|
|
| 169 |
// increase counter if required |
|
| 170 |
if (!$status) $failed_checks++; |
|
| 171 |
} |
|
| 172 |
break; |
|
| 173 |
|
|
| 174 |
case 'WB_ADDONS': |
|
| 175 |
if (is_array($PRECHECK['WB_ADDONS'])) {
|
|
| 176 |
foreach($PRECHECK['WB_ADDONS'] as $addon => $values) {
|
|
| 177 |
if (is_array($values)) {
|
|
| 178 |
// extract module version and operator |
|
| 179 |
$version = (isset($values['VERSION']) && trim($values['VERSION']) != '') ? $values['VERSION'] : ''; |
|
| 180 |
$operator = (isset($values['OPERATOR']) && trim($values['OPERATOR']) != '') ? $values['OPERATOR'] : '>='; |
|
| 181 |
} else {
|
|
| 182 |
// no version and operator specified (only check if addon exists) |
|
| 183 |
$addon = strip_tags($values); |
|
| 184 |
$version = ''; $operator = ''; |
|
| 185 |
} |
|
| 186 |
|
|
| 187 |
// check if addon is listed in WB database |
|
| 188 |
$table = TABLE_PREFIX . 'addons'; |
|
| 189 |
$sql = "SELECT * FROM `$table` WHERE `directory` = '" . addslashes($addon) . "'"; |
|
| 190 |
$results = $database->query($sql); |
|
| 191 |
|
|
| 192 |
$status = false; $addon_status = $TEXT['NOT_INSTALLED']; |
|
| 193 |
if ($results && $row = $results->fetchRow()) {
|
|
| 194 |
$status = true; |
|
| 195 |
$addon_status = $TEXT['INSTALLED']; |
|
| 196 |
|
|
| 197 |
// compare version if required |
|
| 198 |
if ($version != '') {
|
|
| 199 |
$status = versionCompare($row['version'], $version, $operator); |
|
| 200 |
$addon_status = $row['version']; |
|
| 201 |
} |
|
| 202 |
} |
|
| 203 |
|
|
| 204 |
// provide addon status |
|
| 205 |
$msg[] = array( |
|
| 206 |
'check' => ' ' . $TEXT['ADDON'] . ': ' . htmlentities($addon), |
|
| 207 |
'required' => ($version != '') ? $operator . ' ' . $version : $TEXT['INSTALLED'], |
|
| 208 |
'actual' => $addon_status, |
|
| 209 |
'status' => $status |
|
| 210 |
); |
|
| 211 |
|
|
| 212 |
// increase counter if required |
|
| 213 |
if (!$status) $failed_checks++; |
|
| 214 |
} |
|
| 215 |
} |
|
| 216 |
break; |
|
| 217 |
|
|
| 218 |
case 'PHP_VERSION': |
|
| 219 |
if (isset($value['VERSION'])) {
|
|
| 220 |
// obtain operator for string comparison if exist |
|
| 221 |
$operator = (isset($value['OPERATOR']) && trim($value['OPERATOR']) != '') ? $value['OPERATOR'] : '>='; |
|
| 222 |
|
|
| 223 |
// compare versions and extract actual status |
|
| 224 |
$status = versionCompare(PHP_VERSION, $value['VERSION'], $operator); |
|
| 225 |
$msg[] = array( |
|
| 226 |
'check' => 'PHP-' . $TEXT['VERSION'] .': ', |
|
| 227 |
'required' => htmlentities($operator) . ' ' . $value['VERSION'], |
|
| 228 |
'actual' => PHP_VERSION, |
|
| 229 |
'status' => $status |
|
| 230 |
); |
|
| 231 |
|
|
| 232 |
// increase counter if required |
|
| 233 |
if (!$status) $failed_checks++; |
|
| 234 |
|
|
| 235 |
} |
|
| 236 |
break; |
|
| 237 |
|
|
| 238 |
case 'PHP_EXTENSIONS': |
|
| 239 |
if (is_array($PRECHECK['PHP_EXTENSIONS'])) {
|
|
| 240 |
foreach($PRECHECK['PHP_EXTENSIONS'] as $extension) {
|
|
| 241 |
$status = extension_loaded(strtolower($extension)); |
|
| 242 |
$msg[] = array( |
|
| 243 |
'check' => ' ' . $TEXT['EXTENSION'] . ': ' . htmlentities($extension), |
|
| 244 |
'required' => $TEXT['INSTALLED'], |
|
| 245 |
'actual' => ($status) ? $TEXT['INSTALLED'] : $TEXT['NOT_INSTALLED'], |
|
| 246 |
'status' => $status |
|
| 247 |
); |
|
| 248 |
|
|
| 249 |
// increase counter if required |
|
| 250 |
if (!$status) $failed_checks++; |
|
| 251 |
} |
|
| 252 |
} |
|
| 253 |
break; |
|
| 254 |
|
|
| 255 |
case 'PHP_SETTINGS': |
|
| 256 |
if (is_array($PRECHECK['PHP_SETTINGS'])) {
|
|
| 257 |
foreach($PRECHECK['PHP_SETTINGS'] as $setting => $value) {
|
|
| 258 |
$actual_setting = ($temp = ini_get($setting)) ? $temp : 0; |
|
| 259 |
$status = ($actual_setting == $value); |
|
| 260 |
|
|
| 261 |
$msg[] = array( |
|
| 262 |
'check' => ' '. ($setting), |
|
| 263 |
'required' => $value, |
|
| 264 |
'actual' => $actual_setting, |
|
| 265 |
'status' => $status |
|
| 266 |
); |
|
| 267 |
|
|
| 268 |
// increase counter if required |
|
| 269 |
if (!$status) $failed_checks++; |
|
| 270 |
} |
|
| 271 |
} |
|
| 272 |
break; |
|
| 273 |
|
|
| 274 |
case 'CUSTOM_CHECKS': |
|
| 275 |
if (is_array($PRECHECK['CUSTOM_CHECKS'])) {
|
|
| 276 |
foreach($PRECHECK['CUSTOM_CHECKS'] as $key => $values) {
|
|
| 277 |
$status = (true === array_key_exists('STATUS', $values )) ? $values['STATUS'] : false;
|
|
| 278 |
$msg[] = array( |
|
| 279 |
'check' => $key, |
|
| 280 |
'required' => $values['REQUIRED'], |
|
| 281 |
'actual' => $values['ACTUAL'], |
|
| 282 |
'status' => $status |
|
| 283 |
); |
|
| 284 |
} |
|
| 285 |
|
|
| 286 |
// increase counter if required |
|
| 287 |
if (!$status) $failed_checks++; |
|
| 288 |
} |
|
| 289 |
break; |
|
| 290 |
} |
|
| 291 |
} |
|
| 292 |
|
|
| 293 |
// leave if all requirements are fullfilled |
|
| 294 |
if ($failed_checks == 0) return; |
|
| 295 |
|
|
| 296 |
// output summary table with requirements not fullfilled |
|
| 297 |
echo <<< EOT |
|
| 298 |
<h2>{$HEADING['ADDON_PRECHECK_FAILED']}</h2>
|
|
| 299 |
<p>{$MESSAGE['ADDON']['PRECHECK_FAILED']}</p>
|
|
| 300 |
|
|
| 301 |
<table width="700px" cellpadding="4" border="0" style="margin: 0.5em; border-collapse: collapse; border: 1px solid silver;"> |
|
| 302 |
<tr> |
|
| 303 |
<th>{$TEXT['REQUIREMENT']}:</th>
|
|
| 304 |
<th>{$TEXT['REQUIRED']}:</th>
|
|
| 305 |
<th>{$TEXT['CURRENT']}:</th>
|
|
| 306 |
</tr> |
|
| 307 |
EOT; |
|
| 308 |
|
|
| 309 |
foreach($msg as $check) {
|
|
| 310 |
echo '<tr>'; |
|
| 311 |
$style = $check['status'] ? 'color: #46882B;' : 'color: #C00;'; |
|
| 312 |
foreach($check as $key => $value) {
|
|
| 313 |
if ($key == 'status') continue; |
|
| 314 |
|
|
| 315 |
echo '<td style="' . $style . '">' . $value . '</td>'; |
|
| 316 |
} |
|
| 317 |
echo '</tr>'; |
|
| 318 |
} |
|
| 319 |
echo '</table>'; |
|
| 320 |
|
|
| 321 |
// delete the temp unzip directory |
|
| 322 |
rm_full_dir($temp_path); |
|
| 323 |
|
|
| 324 |
// delete the temporary zip file of the Add-on |
|
| 325 |
if(file_exists($temp_addon_file)) { unlink($temp_addon_file); }
|
|
| 326 |
|
|
| 327 |
// output status message and die |
|
| 328 |
$admin->print_error('');
|
|
| 329 |
} |
|
| 330 |
|
|
| 344 | 331 |
?> |
| 345 | 332 | |
| branches/2.8.x/wb/framework/class.frontend.php | ||
|---|---|---|
| 21 | 21 |
exit(0); |
| 22 | 22 |
} |
| 23 | 23 |
|
| 24 |
|
|
| 25 | 24 |
require_once(WB_PATH.'/framework/class.wb.php'); |
| 26 | 25 |
|
| 27 | 26 |
class frontend extends wb {
|
| ... | ... | |
| 221 | 220 |
} |
| 222 | 221 |
} |
| 223 | 222 |
|
| 224 |
function get_website_settings() {
|
|
| 223 |
function get_website_settings() |
|
| 224 |
{
|
|
| 225 | 225 |
global $database; |
| 226 | 226 |
|
| 227 | 227 |
// set visibility SQL code |
| ... | ... | |
| 264 | 264 |
define('SIGNUP_URL', WB_URL.'/account/signup.php');
|
| 265 | 265 |
} |
| 266 | 266 |
} |
| 267 |
|
|
| 267 |
|
|
| 268 |
/* |
|
| 269 |
* replace all "[wblink{page_id}]" with real links
|
|
| 270 |
* @param string &$content : reference to global $content |
|
| 271 |
* @return void |
|
| 272 |
* @history 100216 17:00:00 optimise errorhandling, speed, SQL-strict |
|
| 273 |
*/ |
|
| 274 |
function preprocess(&$content) |
|
| 275 |
{
|
|
| 276 |
global $database; |
|
| 277 |
$replace_list = array(); |
|
| 278 |
$pattern = '/\[wblink([0-9]+)\]/isU'; |
|
| 279 |
if(preg_match_all($pattern,$content,$ids)) |
|
| 280 |
{
|
|
| 281 |
foreach($ids[1] as $key => $page_id) |
|
| 282 |
{
|
|
| 283 |
$replace_list[$page_id] = $ids[0][$key]; |
|
| 284 |
} |
|
| 285 |
foreach($replace_list as $page_id => $tag) |
|
| 286 |
{
|
|
| 287 |
$sql = 'SELECT `link` FROM `'.TABLE_PREFIX.'pages` WHERE `page_id` = '.(int)$page_id; |
|
| 288 |
$link = $database->get_one($sql); |
|
| 289 |
if(!is_null($link)) |
|
| 290 |
{
|
|
| 291 |
$link = $this->page_link($link); |
|
| 292 |
$content = str_replace($tag, $link, $content); |
|
| 293 |
} |
|
| 294 |
} |
|
| 295 |
} |
|
| 296 |
} |
|
| 297 |
|
|
| 298 |
/* |
|
| 268 | 299 |
function preprocess(&$content) {
|
| 269 | 300 |
global $database; |
| 270 | 301 |
// Replace [wblink--PAGE_ID--] with real link |
| ... | ... | |
| 279 | 310 |
$content = preg_replace($pattern,$link,$content); |
| 280 | 311 |
} |
| 281 | 312 |
} |
| 282 |
|
|
| 313 |
*/ |
|
| 283 | 314 |
function menu() {
|
| 284 | 315 |
global $wb; |
| 285 | 316 |
if (!isset($wb->menu_number)) {
|
| branches/2.8.x/wb/framework/functions.php | ||
|---|---|---|
| 19 | 19 |
// Stop this file from being accessed directly |
| 20 | 20 |
if(!defined('WB_URL')) {
|
| 21 | 21 |
header('Location: ../index.php');
|
| 22 |
exit(0);
|
|
| 22 |
exit; |
|
| 23 | 23 |
} |
| 24 | 24 |
|
| 25 | 25 |
// Define that this file has been loaded |
| ... | ... | |
| 29 | 29 |
function rm_full_dir($directory) |
| 30 | 30 |
{
|
| 31 | 31 |
// If suplied dirname is a file then unlink it |
| 32 |
if (is_file($directory)) {
|
|
| 32 |
if (is_file($directory)) |
|
| 33 |
{
|
|
| 33 | 34 |
return unlink($directory); |
| 34 | 35 |
} |
| 35 |
|
|
| 36 | 36 |
// Empty the folder |
| 37 | 37 |
if (is_dir($directory)) |
| 38 | 38 |
{
|
| ... | ... | |
| 40 | 40 |
while (false !== $entry = $dir->read()) |
| 41 | 41 |
{
|
| 42 | 42 |
// Skip pointers |
| 43 |
if ($entry == '.' || $entry == '..') {
|
|
| 44 |
continue; |
|
| 45 |
} |
|
| 46 |
|
|
| 43 |
if ($entry == '.' || $entry == '..') { continue; }
|
|
| 47 | 44 |
// Deep delete directories |
| 48 |
if (is_dir("$directory/$entry")) {
|
|
| 49 |
rm_full_dir("$directory/$entry");
|
|
| 45 |
if (is_dir($directory.'/'.$entry)) |
|
| 46 |
{
|
|
| 47 |
rm_full_dir($directory.'/'.$entry); |
|
| 50 | 48 |
} |
| 51 | 49 |
else |
| 52 | 50 |
{
|
| 53 |
unlink("$directory/$entry");
|
|
| 51 |
unlink($directory.'/'.$entry);
|
|
| 54 | 52 |
} |
| 55 | 53 |
} |
| 56 |
|
|
| 57 | 54 |
// Now delete the folder |
| 58 | 55 |
$dir->close(); |
| 59 | 56 |
return rmdir($directory); |
| ... | ... | |
| 64 | 61 |
function directory_list($directory) |
| 65 | 62 |
{
|
| 66 | 63 |
$list = array(); |
| 67 |
|
|
| 68 | 64 |
if (is_dir($directory)) |
| 69 | 65 |
{
|
| 70 | 66 |
// Open the directory then loop through its contents |
| 71 | 67 |
$dir = dir($directory); |
| 72 |
while (false !== $entry = $dir->read()) {
|
|
| 68 |
while (false !== $entry = $dir->read()) |
|
| 69 |
{
|
|
| 73 | 70 |
// Skip pointers |
| 74 |
if(substr($entry, 0, 1) == '.' || $entry == '.svn') {
|
|
| 75 |
continue; |
|
| 76 |
} |
|
| 71 |
if($entry[0] == '.') { continue; }
|
|
| 77 | 72 |
// Add dir and contents to list |
| 78 |
if (is_dir("$directory/$entry")) {
|
|
| 73 |
if (is_dir("$directory/$entry"))
|
|
| 74 |
{
|
|
| 79 | 75 |
$list = array_merge($list, directory_list("$directory/$entry"));
|
| 80 | 76 |
$list[] = "$directory/$entry"; |
| 81 | 77 |
} |
| 82 | 78 |
} |
| 83 |
|
|
| 84 | 79 |
$dir->close(); |
| 85 | 80 |
} |
| 86 | 81 |
// Now return the list |
| ... | ... | |
| 94 | 89 |
{
|
| 95 | 90 |
// Set the umask to 0 |
| 96 | 91 |
$umask = umask(0); |
| 97 |
|
|
| 98 | 92 |
// Open the directory then loop through its contents |
| 99 | 93 |
$dir = dir($directory); |
| 100 |
while (false !== $entry = $dir->read()) {
|
|
| 94 |
while (false !== $entry = $dir->read()) |
|
| 95 |
{
|
|
| 101 | 96 |
// Skip pointers |
| 102 |
if(substr($entry, 0, 1) == '.' || $entry == '.svn') {
|
|
| 103 |
continue; |
|
| 104 |
} |
|
| 97 |
if($entry[0] == '.') { continue; }
|
|
| 105 | 98 |
// Chmod the sub-dirs contents |
| 106 |
if(is_dir("$directory/$entry")) {
|
|
| 107 |
chmod_directory_contents("$directory/$entry", $file_mode);
|
|
| 99 |
if(is_dir("$directory/$entry"))
|
|
| 100 |
{
|
|
| 101 |
chmod_directory_contents($directory.'/'.$entry, $file_mode); |
|
| 108 | 102 |
} |
| 109 | 103 |
change_mode($directory.'/'.$entry); |
| 110 | 104 |
} |
| ... | ... | |
| 115 | 109 |
} |
| 116 | 110 |
|
| 117 | 111 |
// Function to open a directory and add to a file list |
| 118 |
function file_list($directory, $skip = array()) {
|
|
| 119 |
|
|
| 112 |
function file_list($directory, $skip = array()) |
|
| 113 |
{
|
|
| 120 | 114 |
$list = array(); |
| 121 | 115 |
$skip_file = false; |
| 122 |
|
|
| 123 | 116 |
if (is_dir($directory)) |
| 124 | 117 |
{
|
| 125 | 118 |
// Open the directory then loop through its contents |
| ... | ... | |
| 128 | 121 |
while (false !== $entry = $dir->read()) |
| 129 | 122 |
{
|
| 130 | 123 |
// Skip pointers |
| 131 |
if($entry == '.' || $entry == '..') |
|
| 132 |
{
|
|
| 133 |
$skip_file = true; |
|
| 134 |
} |
|
| 124 |
if($entry[0] == '.') { $skip_file = true; }
|
|
| 135 | 125 |
// Check if we to skip anything else |
| 136 |
if($skip != array()) {
|
|
| 126 |
if($skip != array()) |
|
| 127 |
{
|
|
| 137 | 128 |
foreach($skip AS $skip_name) |
| 138 | 129 |
{
|
| 139 | 130 |
if($entry == $skip_name) |
| ... | ... | |
| 157 | 148 |
} |
| 158 | 149 |
|
| 159 | 150 |
// Function to get a list of home folders not to show |
| 160 |
function get_home_folders() {
|
|
| 151 |
function get_home_folders() |
|
| 152 |
{
|
|
| 161 | 153 |
global $database, $admin; |
| 162 | 154 |
$home_folders = array(); |
| 163 | 155 |
// Only return home folders is this feature is enabled |
| 164 | 156 |
// and user is not admin |
| 165 | 157 |
// if(HOME_FOLDERS AND ($_SESSION['GROUP_ID']!='1')) {
|
| 166 |
if(HOME_FOLDERS AND (!in_array('1',explode(",", $_SESSION['GROUPS_ID'])))) {
|
|
| 167 |
|
|
| 168 |
$query_home_folders = $database->query("SELECT home_folder FROM ".TABLE_PREFIX."users WHERE home_folder != '".$admin->get_home_folder()."'");
|
|
| 169 |
if($query_home_folders->numRows() > 0) {
|
|
| 170 |
while($folder = $query_home_folders->fetchRow()) {
|
|
| 158 |
if(HOME_FOLDERS AND (!in_array('1',explode(',', $_SESSION['GROUPS_ID']))))
|
|
| 159 |
{
|
|
| 160 |
$sql = 'SELECT `home_folder` FROM `'.TABLE_PREFIX.'users` WHERE `home_folder` != "'.$admin->get_home_folder().'"'; |
|
| 161 |
$query_home_folders = $database->query($sql); |
|
| 162 |
if($query_home_folders->numRows() > 0) |
|
| 163 |
{
|
|
| 164 |
while($folder = $query_home_folders->fetchRow()) |
|
| 165 |
{
|
|
| 171 | 166 |
$home_folders[$folder['home_folder']] = $folder['home_folder']; |
| 172 | 167 |
} |
| 173 | 168 |
} |
| 174 |
function remove_home_subs($directory = '/', $home_folders) {
|
|
| 175 |
if($handle = opendir(WB_PATH.MEDIA_DIRECTORY.$directory)) {
|
|
| 169 |
function remove_home_subs($directory = '/', $home_folders = '') |
|
| 170 |
{
|
|
| 171 |
if($handle = opendir(WB_PATH.MEDIA_DIRECTORY.$directory)) |
|
| 172 |
{
|
|
| 176 | 173 |
// Loop through the dirs to check the home folders sub-dirs are not shown |
| 177 |
while(false !== ($file = readdir($handle))) {
|
|
| 178 |
if(substr($file, 0, 1) != '.' AND $file != '.svn' AND $file != 'index.php') {
|
|
| 179 |
if(is_dir(WB_PATH.MEDIA_DIRECTORY.$directory.'/'.$file)) {
|
|
| 180 |
if($directory != '/') { $file = $directory.'/'.$file; } else { $file = '/'.$file; }
|
|
| 181 |
foreach($home_folders AS $hf) {
|
|
| 174 |
while(false !== ($file = readdir($handle))) |
|
| 175 |
{
|
|
| 176 |
if($file[0] != '.' AND $file != 'index.php') |
|
| 177 |
{
|
|
| 178 |
if(is_dir(WB_PATH.MEDIA_DIRECTORY.$directory.'/'.$file)) |
|
| 179 |
{
|
|
| 180 |
if($directory != '/') |
|
| 181 |
{
|
|
| 182 |
$file = $directory.'/'.$file; |
|
| 183 |
} |
|
| 184 |
else |
|
| 185 |
{
|
|
| 186 |
$file = '/'.$file; |
|
| 187 |
} |
|
| 188 |
foreach($home_folders AS $hf) |
|
| 189 |
{
|
|
| 182 | 190 |
$hf_length = strlen($hf); |
| 183 |
if($hf_length > 0) {
|
|
| 184 |
if(substr($file, 0, $hf_length+1) == $hf) {
|
|
| 191 |
if($hf_length > 0) |
|
| 192 |
{
|
|
| 193 |
if(substr($file, 0, $hf_length+1) == $hf) |
|
| 194 |
{
|
|
| 185 | 195 |
$home_folders[$file] = $file; |
| 186 | 196 |
} |
| 187 | 197 |
} |
| ... | ... | |
| 213 | 223 |
} |
| 214 | 224 |
|
| 215 | 225 |
// Function to chmod files and directories |
| 216 |
function change_mode($name) {
|
|
| 226 |
function change_mode($name) |
|
| 227 |
{
|
|
| 217 | 228 |
if(OPERATING_SYSTEM != 'windows') |
| 218 | 229 |
{
|
| 219 | 230 |
// Only chmod if os is not windows |
| ... | ... | |
| 245 | 256 |
} |
| 246 | 257 |
|
| 247 | 258 |
// Function to figure out if a parent exists |
| 248 |
function is_parent($page_id) {
|
|
| 259 |
function is_parent($page_id) |
|
| 260 |
{
|
|
| 249 | 261 |
global $database; |
| 250 | 262 |
// Get parent |
| 251 |
$query = $database->query("SELECT parent FROM ".TABLE_PREFIX."pages WHERE page_id = '$page_id'");
|
|
| 252 |
$fetch = $query->fetchRow();
|
|
| 263 |
$sql = 'SELECT `parent` FROM `'.TABLE_PREFIX.'pages` WHERE `page_id` = '.$page_id;
|
|
| 264 |
$parent = $database->get_one($sql);
|
|
| 253 | 265 |
// If parent isnt 0 return its ID |
| 254 |
if($fetch['parent'] == '0') {
|
|
| 266 |
if(is_null($parent)) |
|
| 267 |
{
|
|
| 255 | 268 |
return false; |
| 256 |
} else {
|
|
| 257 |
return $fetch['parent']; |
|
| 258 | 269 |
} |
| 270 |
else |
|
| 271 |
{
|
|
| 272 |
return $parent; |
|
| 273 |
} |
|
| 259 | 274 |
} |
| 260 | 275 |
|
| 261 | 276 |
// Function to work out level |
| 262 |
function level_count($page_id) {
|
|
| 277 |
function level_count($page_id) |
|
| 278 |
{
|
|
| 263 | 279 |
global $database; |
| 264 | 280 |
// Get page parent |
| 265 |
$query_page = $database->query("SELECT parent FROM ".TABLE_PREFIX."pages WHERE page_id = '$page_id' LIMIT 1");
|
|
| 266 |
$fetch_page = $query_page->fetchRow(); |
|
| 267 |
$parent = $fetch_page['parent']; |
|
| 268 |
if($parent > 0) {
|
|
| 269 |
// Get the level of the parent |
|
| 270 |
$query_parent = $database->query("SELECT level FROM ".TABLE_PREFIX."pages WHERE page_id = '$parent' LIMIT 1");
|
|
| 271 |
$fetch_parent = $query_parent->fetchRow(); |
|
| 272 |
$level = $fetch_parent['level']; |
|
| 281 |
$sql = 'SELECT `parent` FROM `'.TABLE_PREFIX.'pages` WHERE `page_id` = '.$page_id; |
|
| 282 |
$parent = $database->get_one($sql); |
|
| 283 |
if($parent > 0) |
|
| 284 |
{ // Get the level of the parent
|
|
| 285 |
$sql = 'SELECT `level` FROM `'.TABLE_PREFIX.'pages` WHERE `page_id` = '.$parent; |
|
| 286 |
$level = $database->get_one($sql); |
|
| 273 | 287 |
return $level+1; |
| 274 |
} else {
|
|
| 288 |
} |
|
| 289 |
else |
|
| 290 |
{
|
|
| 275 | 291 |
return 0; |
| 276 | 292 |
} |
| 277 | 293 |
} |
| 278 | 294 |
|
| 279 | 295 |
// Function to work out root parent |
| 280 |
function root_parent($page_id) {
|
|
| 296 |
function root_parent($page_id) |
|
| 297 |
{
|
|
| 281 | 298 |
global $database; |
| 282 | 299 |
// Get page details |
| 283 |
$query_page = $database->query("SELECT parent,level FROM ".TABLE_PREFIX."pages WHERE page_id = '$page_id' LIMIT 1");
|
|
| 300 |
$sql = 'SELECT `parent`, `level` FROM `'.TABLE_PREFIX.'pages` WHERE `page_id` = '.$page_id; |
|
| 301 |
$query_page = $database->query($sql); |
|
| 284 | 302 |
$fetch_page = $query_page->fetchRow(); |
| 285 | 303 |
$parent = $fetch_page['parent']; |
| 286 | 304 |
$level = $fetch_page['level']; |
| 287 |
if($level == 1) {
|
|
| 305 |
if($level == 1) |
|
| 306 |
{
|
|
| 288 | 307 |
return $parent; |
| 289 |
} elseif($parent == 0) {
|
|
| 308 |
} |
|
| 309 |
elseif($parent == 0) |
|
| 310 |
{
|
|
| 290 | 311 |
return $page_id; |
| 291 |
} else {
|
|
| 292 |
// Figure out what the root parents id is |
|
| 312 |
} |
|
| 313 |
else |
|
| 314 |
{ // Figure out what the root parents id is
|
|
| 293 | 315 |
$parent_ids = array_reverse(get_parent_ids($page_id)); |
| 294 | 316 |
return $parent_ids[0]; |
| 295 | 317 |
} |
| 296 | 318 |
} |
| 297 | 319 |
|
| 298 | 320 |
// Function to get page title |
| 299 |
function get_page_title($id) {
|
|
| 321 |
function get_page_title($id) |
|
| 322 |
{
|
|
| 300 | 323 |
global $database; |
| 301 | 324 |
// Get title |
| 302 |
$query = $database->query("SELECT page_title FROM ".TABLE_PREFIX."pages WHERE page_id = '$id'");
|
|
| 303 |
$fetch = $query->fetchRow(); |
|
| 304 |
// Return title |
|
| 305 |
return $fetch['page_title']; |
|
| 325 |
$sql = 'SELECT `page_title` FROM `'.TABLE_PREFIX.'pages` WHERE `page_id` = '.$id; |
|
| 326 |
$page_title = $database->get_one($sql); |
|
| 327 |
return $page_title; |
|
| 306 | 328 |
} |
| 307 | 329 |
|
| 308 | 330 |
// Function to get a pages menu title |
| 309 |
function get_menu_title($id) {
|
|
| 310 |
// Connect to the database
|
|
| 311 |
$database = new database();
|
|
| 331 |
function get_menu_title($id) |
|
| 332 |
{
|
|
| 333 |
global $database;
|
|
| 312 | 334 |
// Get title |
| 313 |
$query = $database->query("SELECT menu_title FROM ".TABLE_PREFIX."pages WHERE page_id = '$id'");
|
|
| 314 |
$fetch = $query->fetchRow(); |
|
| 315 |
// Return title |
|
| 316 |
return $fetch['menu_title']; |
|
| 335 |
$sql = 'SELECT `menu_title` FROM `'.TABLE_PREFIX.'pages` WHERE `page_id` = '.$id; |
|
| 336 |
$menu_title = $database->get_one($sql); |
|
| 337 |
return $menu_title; |
|
| 317 | 338 |
} |
| 318 | 339 |
|
| 319 | 340 |
// Function to get all parent page titles |
| 320 |
function get_parent_titles($parent_id) {
|
|
| 341 |
function get_parent_titles($parent_id) |
|
| 342 |
{
|
|
| 321 | 343 |
$titles[] = get_menu_title($parent_id); |
| 322 |
if(is_parent($parent_id) != false) {
|
|
| 344 |
if(is_parent($parent_id) != false) |
|
| 345 |
{
|
|
| 323 | 346 |
$parent_titles = get_parent_titles(is_parent($parent_id)); |
| 324 | 347 |
$titles = array_merge($titles, $parent_titles); |
| 325 | 348 |
} |
| ... | ... | |
| 327 | 350 |
} |
| 328 | 351 |
|
| 329 | 352 |
// Function to get all parent page id's |
| 330 |
function get_parent_ids($parent_id) {
|
|
| 353 |
function get_parent_ids($parent_id) |
|
| 354 |
{
|
|
| 331 | 355 |
$ids[] = $parent_id; |
| 332 |
if(is_parent($parent_id) != false) {
|
|
| 356 |
if(is_parent($parent_id) != false) |
|
| 357 |
{
|
|
| 333 | 358 |
$parent_ids = get_parent_ids(is_parent($parent_id)); |
| 334 | 359 |
$ids = array_merge($ids, $parent_ids); |
| 335 | 360 |
} |
| ... | ... | |
| 342 | 367 |
} |
| 343 | 368 |
|
| 344 | 369 |
// Function to get all sub pages id's |
| 345 |
function get_subs($parent, $subs) {
|
|
| 370 |
function get_subs($parent, $subs) |
|
| 371 |
{
|
|
| 346 | 372 |
// Connect to the database |
| 347 |
$database = new database();
|
|
| 373 |
global $database;
|
|
| 348 | 374 |
// Get id's |
| 349 |
$query = $database->query("SELECT page_id FROM ".TABLE_PREFIX."pages WHERE parent = '$parent'");
|
|
| 350 |
if($query->numRows() > 0) {
|
|
| 351 |
while($fetch = $query->fetchRow()) {
|
|
| 375 |
$sql = 'SELECT `page_id` FROM `'.TABLE_PREFIX.'pages` WHERE `parent` = '.$parent; |
|
| 376 |
$query = $database->query($sql); |
|
| 377 |
if($query->numRows() > 0) |
|
| 378 |
{
|
|
| 379 |
while($fetch = $query->fetchRow()) |
|
| 380 |
{
|
|
| 352 | 381 |
$subs[] = $fetch['page_id']; |
| 353 | 382 |
// Get subs of this sub |
| 354 | 383 |
$subs = get_subs($fetch['page_id'], $subs); |
| ... | ... | |
| 360 | 389 |
|
| 361 | 390 |
// Function as replacement for php's htmlspecialchars() |
| 362 | 391 |
// Will not mangle HTML-entities |
| 363 |
function my_htmlspecialchars($string) {
|
|
| 392 |
function my_htmlspecialchars($string) |
|
| 393 |
{
|
|
| 364 | 394 |
$string = preg_replace('/&(?=[#a-z0-9]+;)/i', '__amp;_', $string);
|
| 365 | 395 |
$string = strtr($string, array('<'=>'<', '>'=>'>', '&'=>'&', '"'=>'"', '\''=>'''));
|
| 366 | 396 |
$string = preg_replace('/__amp;_(?=[#a-z0-9]+;)/i', '&', $string);
|
| ... | ... | |
| 370 | 400 |
// Convert a string from mixed html-entities/umlauts to pure $charset_out-umlauts |
| 371 | 401 |
// Will replace all numeric and named entities except > < ' " ' |
| 372 | 402 |
// In case of error the returned string is unchanged, and a message is emitted. |
| 373 |
function entities_to_umlauts($string, $charset_out=DEFAULT_CHARSET) {
|
|
| 403 |
function entities_to_umlauts($string, $charset_out=DEFAULT_CHARSET) |
|
| 404 |
{
|
|
| 374 | 405 |
require_once(WB_PATH.'/framework/functions-utf8.php'); |
| 375 | 406 |
return entities_to_umlauts2($string, $charset_out); |
| 376 | 407 |
} |
| 377 | 408 |
|
| 378 | 409 |
// Will convert a string in $charset_in encoding to a pure ASCII string with HTML-entities. |
| 379 | 410 |
// In case of error the returned string is unchanged, and a message is emitted. |
| 380 |
function umlauts_to_entities($string, $charset_in=DEFAULT_CHARSET) {
|
|
| 411 |
function umlauts_to_entities($string, $charset_in=DEFAULT_CHARSET) |
|
| 412 |
{
|
|
| 381 | 413 |
require_once(WB_PATH.'/framework/functions-utf8.php'); |
| 382 | 414 |
return umlauts_to_entities2($string, $charset_in); |
| 383 | 415 |
} |
| 384 | 416 |
|
| 385 | 417 |
// Function to convert a page title to a page filename |
| 386 |
function page_filename($string) {
|
|
| 418 |
function page_filename($string) |
|
| 419 |
{
|
|
| 387 | 420 |
require_once(WB_PATH.'/framework/functions-utf8.php'); |
| 388 | 421 |
$string = entities_to_7bit($string); |
| 389 | 422 |
// Now remove all bad characters |
| ... | ... | |
| 410 | 443 |
} |
| 411 | 444 |
|
| 412 | 445 |
// Function to convert a desired media filename to a clean filename |
| 413 |
function media_filename($string) {
|
|
| 446 |
function media_filename($string) |
|
| 447 |
{
|
|
| 414 | 448 |
require_once(WB_PATH.'/framework/functions-utf8.php'); |
| 415 | 449 |
$string = entities_to_7bit($string); |
| 416 | 450 |
// Now remove all bad characters |
| ... | ... | |
| 446 | 480 |
} |
| 447 | 481 |
|
| 448 | 482 |
// Function to work out a page link |
| 449 |
if(!function_exists('page_link')) {
|
|
| 450 |
function page_link($link) {
|
|
| 483 |
if(!function_exists('page_link'))
|
|
| 484 |
{
|
|
| 485 |
function page_link($link) |
|
| 486 |
{
|
|
| 451 | 487 |
global $admin; |
| 452 | 488 |
return $admin->page_link($link); |
| 453 | 489 |
} |
| 454 | 490 |
} |
| 455 | 491 |
|
| 456 | 492 |
// Create a new file in the pages directory |
| 457 |
function create_access_file($filename,$page_id,$level) {
|
|
| 493 |
function create_access_file($filename,$page_id,$level) |
|
| 494 |
{
|
|
| 458 | 495 |
global $admin, $MESSAGE; |
| 459 |
if(!is_writable(WB_PATH.PAGES_DIRECTORY.'/')) {
|
|
| 496 |
if(!is_writable(WB_PATH.PAGES_DIRECTORY.'/')) |
|
| 497 |
{
|
|
| 460 | 498 |
$admin->print_error($MESSAGE['PAGES']['CANNOT_CREATE_ACCESS_FILE']); |
| 461 |
} else {
|
|
| 499 |
} |
|
| 500 |
else |
|
| 501 |
{
|
|
| 462 | 502 |
// First make sure parent folder exists |
| 463 | 503 |
$parent_folders = explode('/',str_replace(WB_PATH.PAGES_DIRECTORY, '', dirname($filename)));
|
| 464 | 504 |
$parents = ''; |
| 465 |
foreach($parent_folders AS $parent_folder) {
|
|
| 466 |
if($parent_folder != '/' AND $parent_folder != '') {
|
|
| 505 |
foreach($parent_folders AS $parent_folder) |
|
| 506 |
{
|
|
| 507 |
if($parent_folder != '/' AND $parent_folder != '') |
|
| 508 |
{
|
|
| 467 | 509 |
$parents .= '/'.$parent_folder; |
| 468 |
if(!file_exists(WB_PATH.PAGES_DIRECTORY.$parents)) {
|
|
| 510 |
if(!file_exists(WB_PATH.PAGES_DIRECTORY.$parents)) |
|
| 511 |
{
|
|
| 469 | 512 |
make_dir(WB_PATH.PAGES_DIRECTORY.$parents); |
| 470 | 513 |
} |
| 471 | 514 |
} |
| ... | ... | |
| 475 | 518 |
$pages_dir_depth=count(explode('/',PAGES_DIRECTORY))-1;
|
| 476 | 519 |
// Work-out how many ../'s we need to get to the index page |
| 477 | 520 |
$index_location = ''; |
| 478 |
for($i = 0; $i < $level + $pages_dir_depth; $i++) {
|
|
| 521 |
for($i = 0; $i < $level + $pages_dir_depth; $i++) |
|
| 522 |
{
|
|
| 479 | 523 |
$index_location .= '../'; |
| 480 | 524 |
} |
| 481 | 525 |
$content = ''. |
| ... | ... | |
| 493 | 537 |
} |
| 494 | 538 |
|
| 495 | 539 |
// Function for working out a file mime type (if the in-built PHP one is not enabled) |
| 496 |
if(!function_exists('mime_content_type')) {
|
|
| 497 |
function mime_content_type($filename) {
|
|
| 498 |
|
|
| 499 |
$mime_types = array( |
|
| 540 |
if(!function_exists('mime_content_type'))
|
|
| 541 |
{
|
|
| 542 |
function mime_content_type($filename) |
|
| 543 |
{
|
|
| 544 |
$mime_types = array( |
|
| 500 | 545 |
'txt' => 'text/plain', |
| 501 | 546 |
'htm' => 'text/html', |
| 502 | 547 |
'html' => 'text/html', |
| ... | ... | |
| 555 | 600 |
$temp = explode('.',$filename);
|
| 556 | 601 |
$ext = strtolower(array_pop($temp)); |
| 557 | 602 |
|
| 558 |
if (array_key_exists($ext, $mime_types)) {
|
|
| 603 |
if (array_key_exists($ext, $mime_types)) |
|
| 604 |
{
|
|
| 559 | 605 |
return $mime_types[$ext]; |
| 560 | 606 |
} |
| 561 |
elseif (function_exists('finfo_open')) {
|
|
| 607 |
elseif (function_exists('finfo_open'))
|
|
| 608 |
{
|
|
| 562 | 609 |
$finfo = finfo_open(FILEINFO_MIME); |
| 563 | 610 |
$mimetype = finfo_file($finfo, $filename); |
| 564 | 611 |
finfo_close($finfo); |
| 565 | 612 |
return $mimetype; |
| 566 | 613 |
} |
| 567 |
else {
|
|
| 614 |
else |
|
| 615 |
{
|
|
| 568 | 616 |
return 'application/octet-stream'; |
| 569 | 617 |
} |
| 570 | 618 |
} |
| 571 | 619 |
} |
| 572 | 620 |
|
| 573 | 621 |
// Generate a thumbnail from an image |
| 574 |
function make_thumb($source, $destination, $size) {
|
|
| 622 |
function make_thumb($source, $destination, $size) |
|
| 623 |
{
|
|
| 575 | 624 |
// Check if GD is installed |
| 576 |
if(extension_loaded('gd') AND function_exists('imageCreateFromJpeg')) {
|
|
| 625 |
if(extension_loaded('gd') AND function_exists('imageCreateFromJpeg'))
|
|
| 626 |
{
|
|
| 577 | 627 |
// First figure out the size of the thumbnail |
| 578 | 628 |
list($original_x, $original_y) = getimagesize($source); |
| 579 |
if ($original_x > $original_y) {
|
|
| 629 |
if ($original_x > $original_y) |
|
| 630 |
{
|
|
| 580 | 631 |
$thumb_w = $size; |
| 581 | 632 |
$thumb_h = $original_y*($size/$original_x); |
| 582 | 633 |
} |
| 583 |
if ($original_x < $original_y) {
|
|
| 634 |
if ($original_x < $original_y) |
|
| 635 |
{
|
|
| 584 | 636 |
$thumb_w = $original_x*($size/$original_y); |
| 585 | 637 |
$thumb_h = $size; |
| 586 | 638 |
} |
| 587 |
if ($original_x == $original_y) {
|
|
| 639 |
if ($original_x == $original_y) |
|
| 640 |
{
|
|
| 588 | 641 |
$thumb_w = $size; |
| 589 | 642 |
$thumb_h = $size; |
| 590 | 643 |
} |
| ... | ... | |
| 595 | 648 |
imagejpeg($dst_img, $destination); |
| 596 | 649 |
// Clear memory |
| 597 | 650 |
imagedestroy($dst_img); |
| 598 |
imagedestroy($source);
|
|
| 651 |
imagedestroy($source);
|
|
| 599 | 652 |
// Return true |
| 600 |
return true;
|
|
| 601 |
} else {
|
|
| 602 |
return false;
|
|
| 603 |
}
|
|
| 653 |
return true;
|
|
| 654 |
} else {
|
|
| 655 |
return false;
|
|
| 656 |
}
|
|
| 604 | 657 |
} |
| 605 | 658 |
|
| 606 |
// Function to work-out a single part of an octal permission value |
|
| 607 |
function extract_permission($octal_value, $who, $action) {
|
|
| 608 |
// Make sure the octal value is 4 chars long |
|
| 609 |
if(strlen($octal_value) == 0) {
|
|
| 610 |
$octal_value = '0000'; |
|
| 611 |
} elseif(strlen($octal_value) == 1) {
|
|
| 612 |
$octal_value = '000'.$octal_value; |
|
| 613 |
} elseif(strlen($octal_value) == 2) {
|
|
| 614 |
$octal_value = '00'.$octal_value; |
|
| 615 |
} elseif(strlen($octal_value) == 3) {
|
|
| 616 |
$octal_value = '0'.$octal_value; |
|
| 617 |
} elseif(strlen($octal_value) == 4) {
|
|
| 618 |
$octal_value = ''.$octal_value; |
|
| 619 |
} else {
|
|
| 620 |
$octal_value = '0000'; |
|
| 659 |
/* |
|
| 660 |
* Function to work-out a single part of an octal permission value |
|
| 661 |
* |
|
| 662 |
* @param mixed $octal_value: an octal value as string (i.e. '0777') or real octal integer (i.e. 0777 | 777) |
|
| 663 |
* @param string $who: char or string for whom the permission is asked( U[ser] / G[roup] / O[thers] ) |
|
| 664 |
* @param string $action: char or string with the requested action( r[ead..] / w[rite..] / e|x[ecute..] ) |
|
| 665 |
* @return boolean |
|
| 666 |
*/ |
|
| 667 |
function extract_permission($octal_value, $who, $action) |
|
| 668 |
{
|
|
| 669 |
// Make sure that all arguments are set and $octal_value is a real octal-integer |
|
| 670 |
if( ($who == '') or ($action == '') or (preg_match( '/[^0-7]/', (string)$octal_value )) ) |
|
| 671 |
{
|
|
| 672 |
return false; // invalid argument, so return false |
|
| 621 | 673 |
} |
| 622 |
// Work-out what position of the octal value to look at |
|
| 623 |
switch($who) {
|
|
| 624 |
case 'u': |
|
| 625 |
$position = '1'; |
|
| 626 |
break; |
|
| 627 |
case 'user': |
|
| 628 |
$position = '1'; |
|
| 629 |
break; |
|
| 630 |
case 'g': |
|
| 631 |
$position = '2'; |
|
| 632 |
break; |
|
| 633 |
case 'group': |
|
| 634 |
$position = '2'; |
|
| 635 |
break; |
|
| 636 |
case 'o': |
|
| 637 |
$position = '3'; |
|
| 638 |
break; |
|
| 639 |
case 'others': |
|
| 640 |
$position = '3'; |
|
| 641 |
break; |
|
| 674 |
// convert $octal_value into a decimal-integer to be sure having a valid value |
|
| 675 |
$right_mask = octdec($octal_value); |
|
| 676 |
$action_mask = 0; |
|
| 677 |
// set the $action related bit in $action_mask |
|
| 678 |
switch($action[0]) // get action from first char of $action |
|
| 679 |
{
|
|
| 680 |
case 'r': |
|
| 681 |
case 'R': |
|
| 682 |
$action_mask = 4; // set read-bit only (2^2) |
|
| 683 |
break; |
|
| 684 |
case 'w': |
|
| 685 |
case 'W': |
|
| 686 |
$action_mask = 2; // set write-bit only (2^1) |
|
| 687 |
break; |
|
| 688 |
case 'e': |
|
| 689 |
case 'E': |
|
| 690 |
case 'x': |
|
| 691 |
case 'X': |
|
| 692 |
$action_mask = 1; // set execute-bit only (2^0) |
|
| 693 |
break; |
|
| 694 |
default: |
|
| 695 |
return false; // undefined action name, so return false |
|
| 642 | 696 |
} |
| 643 |
// Work-out how long the octal value is and ajust acording |
|
| 644 |
if(strlen($octal_value) == 4) {
|
|
| 645 |
$position = $position+1; |
|
| 646 |
} elseif(strlen($octal_value) != 3) {
|
|
| 647 |
exit('Error');
|
|
| 697 |
// shift action-mask into the right position |
|
| 698 |
switch($who[0]) // get who from first char of $who |
|
| 699 |
{
|
|
| 700 |
case 'u': |
|
| 701 |
case 'U': |
|
| 702 |
$action_mask <<= 3; // shift left 3 bits |
|
| 703 |
case 'g': |
|
| 704 |
case 'G': |
|
| 705 |
$action_mask <<= 3; // shift left 3 bits |
|
| 706 |
case 'o': |
|
| 707 |
case 'O': |
|
| 708 |
/* NOP */ |
|
| 709 |
break; |
|
| 710 |
default: |
|
| 711 |
return false; // undefined who, so return false |
|
| 648 | 712 |
} |
| 649 |
// Now work-out what action the script is trying to look-up |
|
| 650 |
switch($action) {
|
|
| 651 |
case 'r': |
|
| 652 |
$action = 'r'; |
|
| 653 |
break; |
|
| 654 |
case 'read': |
|
| 655 |
$action = 'r'; |
|
| 656 |
break; |
|
| 657 |
case 'w': |
|
| 658 |
$action = 'w'; |
|
| 659 |
break; |
|
| 660 |
case 'write': |
|
| 661 |
$action = 'w'; |
|
| 662 |
break; |
|
| 663 |
case 'e': |
|
| 664 |
$action = 'e'; |
|
| 665 |
break; |
|
| 666 |
case 'execute': |
|
| 667 |
$action = 'e'; |
|
| 668 |
break; |
|
| 669 |
} |
|
Also available in: Unified diff
recoded function extract_permission in /framework/functions.php
change URL_HELP to http://www.websitebaker2.org/ in /framework/class.admin.php
recoded function preprocess in /framework/class.frontend.php
optimize function getVersion in /framework/addon.precheck.inc.php