| 1 |
1289
|
kweitzel
|
<?php
|
| 2 |
|
|
/**
|
| 3 |
|
|
*
|
| 4 |
|
|
* @category frontend
|
| 5 |
|
|
* @package framework
|
| 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.3.4 and higher
|
| 13 |
|
|
* @version $Id$
|
| 14 |
|
|
* @filesource $HeadURL$
|
| 15 |
|
|
* @lastmodified $Date$
|
| 16 |
|
|
*
|
| 17 |
|
|
*/
|
| 18 |
|
|
|
| 19 |
|
|
// Stop this file from being accessed directly
|
| 20 |
|
|
if(!defined('WB_URL')) {
|
| 21 |
|
|
header('Location: ../index.php');
|
| 22 |
|
|
exit(0);
|
| 23 |
|
|
}
|
| 24 |
|
|
|
| 25 |
|
|
// Define that this file has been loaded
|
| 26 |
|
|
define('FUNCTIONS_FILE_LOADED', true);
|
| 27 |
|
|
|
| 28 |
|
|
// Function to remove a non-empty directory
|
| 29 |
|
|
function rm_full_dir($directory)
|
| 30 |
|
|
{
|
| 31 |
|
|
// If suplied dirname is a file then unlink it
|
| 32 |
|
|
if (is_file($directory)) {
|
| 33 |
|
|
return unlink($directory);
|
| 34 |
|
|
}
|
| 35 |
|
|
|
| 36 |
|
|
// Empty the folder
|
| 37 |
|
|
if (is_dir($directory))
|
| 38 |
|
|
{
|
| 39 |
|
|
$dir = dir($directory);
|
| 40 |
|
|
while (false !== $entry = $dir->read())
|
| 41 |
|
|
{
|
| 42 |
|
|
// Skip pointers
|
| 43 |
|
|
if ($entry == '.' || $entry == '..') {
|
| 44 |
|
|
continue;
|
| 45 |
|
|
}
|
| 46 |
|
|
|
| 47 |
|
|
// Deep delete directories
|
| 48 |
|
|
if (is_dir("$directory/$entry")) {
|
| 49 |
|
|
rm_full_dir("$directory/$entry");
|
| 50 |
|
|
}
|
| 51 |
|
|
else
|
| 52 |
|
|
{
|
| 53 |
|
|
unlink("$directory/$entry");
|
| 54 |
|
|
}
|
| 55 |
|
|
}
|
| 56 |
|
|
|
| 57 |
|
|
// Now delete the folder
|
| 58 |
|
|
$dir->close();
|
| 59 |
|
|
return rmdir($directory);
|
| 60 |
|
|
}
|
| 61 |
|
|
}
|
| 62 |
|
|
|
| 63 |
|
|
// Function to open a directory and add to a dir list
|
| 64 |
|
|
function directory_list($directory)
|
| 65 |
|
|
{
|
| 66 |
|
|
$list = array();
|
| 67 |
|
|
|
| 68 |
|
|
if (is_dir($directory))
|
| 69 |
|
|
{
|
| 70 |
|
|
// Open the directory then loop through its contents
|
| 71 |
|
|
$dir = dir($directory);
|
| 72 |
|
|
while (false !== $entry = $dir->read()) {
|
| 73 |
|
|
// Skip pointers
|
| 74 |
|
|
if(substr($entry, 0, 1) == '.' || $entry == '.svn') {
|
| 75 |
|
|
continue;
|
| 76 |
|
|
}
|
| 77 |
|
|
// Add dir and contents to list
|
| 78 |
|
|
if (is_dir("$directory/$entry")) {
|
| 79 |
|
|
$list = array_merge($list, directory_list("$directory/$entry"));
|
| 80 |
|
|
$list[] = "$directory/$entry";
|
| 81 |
|
|
}
|
| 82 |
|
|
}
|
| 83 |
|
|
|
| 84 |
|
|
$dir->close();
|
| 85 |
|
|
}
|
| 86 |
|
|
// Now return the list
|
| 87 |
|
|
return $list;
|
| 88 |
|
|
}
|
| 89 |
|
|
|
| 90 |
|
|
// Function to open a directory and add to a dir list
|
| 91 |
|
|
function chmod_directory_contents($directory, $file_mode)
|
| 92 |
|
|
{
|
| 93 |
|
|
if (is_dir($directory))
|
| 94 |
|
|
{
|
| 95 |
|
|
// Set the umask to 0
|
| 96 |
|
|
$umask = umask(0);
|
| 97 |
|
|
|
| 98 |
|
|
// Open the directory then loop through its contents
|
| 99 |
|
|
$dir = dir($directory);
|
| 100 |
|
|
while (false !== $entry = $dir->read()) {
|
| 101 |
|
|
// Skip pointers
|
| 102 |
|
|
if(substr($entry, 0, 1) == '.' || $entry == '.svn') {
|
| 103 |
|
|
continue;
|
| 104 |
|
|
}
|
| 105 |
|
|
// Chmod the sub-dirs contents
|
| 106 |
|
|
if(is_dir("$directory/$entry")) {
|
| 107 |
|
|
chmod_directory_contents("$directory/$entry", $file_mode);
|
| 108 |
|
|
}
|
| 109 |
|
|
change_mode($directory.'/'.$entry);
|
| 110 |
|
|
}
|
| 111 |
|
|
$dir->close();
|
| 112 |
|
|
// Restore the umask
|
| 113 |
|
|
umask($umask);
|
| 114 |
|
|
}
|
| 115 |
|
|
}
|
| 116 |
|
|
|
| 117 |
|
|
// Function to open a directory and add to a file list
|
| 118 |
|
|
function file_list($directory, $skip = array()) {
|
| 119 |
|
|
|
| 120 |
|
|
$list = array();
|
| 121 |
|
|
$skip_file = false;
|
| 122 |
|
|
|
| 123 |
|
|
if (is_dir($directory))
|
| 124 |
|
|
{
|
| 125 |
|
|
// Open the directory then loop through its contents
|
| 126 |
|
|
$dir = dir($directory);
|
| 127 |
|
|
}
|
| 128 |
|
|
while (false !== $entry = $dir->read())
|
| 129 |
|
|
{
|
| 130 |
|
|
// Skip pointers
|
| 131 |
|
|
if($entry == '.' || $entry == '..')
|
| 132 |
|
|
{
|
| 133 |
|
|
$skip_file = true;
|
| 134 |
|
|
}
|
| 135 |
|
|
// Check if we to skip anything else
|
| 136 |
|
|
if($skip != array()) {
|
| 137 |
|
|
foreach($skip AS $skip_name)
|
| 138 |
|
|
{
|
| 139 |
|
|
if($entry == $skip_name)
|
| 140 |
|
|
{
|
| 141 |
|
|
$skip_file = true;
|
| 142 |
|
|
}
|
| 143 |
|
|
}
|
| 144 |
|
|
}
|
| 145 |
|
|
// Add dir and contents to list
|
| 146 |
|
|
if($skip_file != true AND is_file("$directory/$entry"))
|
| 147 |
|
|
{
|
| 148 |
|
|
$list[] = "$directory/$entry";
|
| 149 |
|
|
}
|
| 150 |
|
|
|
| 151 |
|
|
// Reset the skip file var
|
| 152 |
|
|
$skip_file = false;
|
| 153 |
|
|
}
|
| 154 |
|
|
$dir->close();
|
| 155 |
|
|
// Now delete the folder
|
| 156 |
|
|
return $list;
|
| 157 |
|
|
}
|
| 158 |
|
|
|
| 159 |
|
|
// Function to get a list of home folders not to show
|
| 160 |
|
|
function get_home_folders() {
|
| 161 |
|
|
global $database, $admin;
|
| 162 |
|
|
$home_folders = array();
|
| 163 |
|
|
// Only return home folders is this feature is enabled
|
| 164 |
|
|
// and user is not admin
|
| 165 |
|
|
// 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()) {
|
| 171 |
|
|
$home_folders[$folder['home_folder']] = $folder['home_folder'];
|
| 172 |
|
|
}
|
| 173 |
|
|
}
|
| 174 |
|
|
function remove_home_subs($directory = '/', $home_folders) {
|
| 175 |
|
|
if($handle = opendir(WB_PATH.MEDIA_DIRECTORY.$directory)) {
|
| 176 |
|
|
// 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) {
|
| 182 |
|
|
$hf_length = strlen($hf);
|
| 183 |
|
|
if($hf_length > 0) {
|
| 184 |
|
|
if(substr($file, 0, $hf_length+1) == $hf) {
|
| 185 |
|
|
$home_folders[$file] = $file;
|
| 186 |
|
|
}
|
| 187 |
|
|
}
|
| 188 |
|
|
}
|
| 189 |
|
|
$home_folders = remove_home_subs($file, $home_folders);
|
| 190 |
|
|
}
|
| 191 |
|
|
}
|
| 192 |
|
|
}
|
| 193 |
|
|
}
|
| 194 |
|
|
return $home_folders;
|
| 195 |
|
|
}
|
| 196 |
|
|
$home_folders = remove_home_subs('/', $home_folders);
|
| 197 |
|
|
}
|
| 198 |
|
|
return $home_folders;
|
| 199 |
|
|
}
|
| 200 |
|
|
|
| 201 |
|
|
// Function to create directories
|
| 202 |
|
|
function make_dir($dir_name, $dir_mode = OCTAL_DIR_MODE)
|
| 203 |
|
|
{
|
| 204 |
|
|
if(!is_dir($dir_name))
|
| 205 |
|
|
{
|
| 206 |
|
|
$umask = umask(0);
|
| 207 |
|
|
mkdir($dir_name, $dir_mode);
|
| 208 |
|
|
umask($umask);
|
| 209 |
|
|
return true;
|
| 210 |
|
|
} else {
|
| 211 |
|
|
return false;
|
| 212 |
|
|
}
|
| 213 |
|
|
}
|
| 214 |
|
|
|
| 215 |
|
|
// Function to chmod files and directories
|
| 216 |
|
|
function change_mode($name) {
|
| 217 |
|
|
if(OPERATING_SYSTEM != 'windows')
|
| 218 |
|
|
{
|
| 219 |
|
|
// Only chmod if os is not windows
|
| 220 |
|
|
if(is_dir($name))
|
| 221 |
|
|
{
|
| 222 |
|
|
$mode = OCTAL_DIR_MODE;
|
| 223 |
|
|
}
|
| 224 |
|
|
else
|
| 225 |
|
|
{
|
| 226 |
|
|
$mode = OCTAL_FILE_MODE;
|
| 227 |
|
|
}
|
| 228 |
|
|
|
| 229 |
|
|
if(file_exists($name))
|
| 230 |
|
|
{
|
| 231 |
|
|
$umask = umask(0);
|
| 232 |
|
|
chmod($name, $mode);
|
| 233 |
|
|
umask($umask);
|
| 234 |
|
|
return true;
|
| 235 |
|
|
}
|
| 236 |
|
|
else
|
| 237 |
|
|
{
|
| 238 |
|
|
return false;
|
| 239 |
|
|
}
|
| 240 |
|
|
}
|
| 241 |
|
|
else
|
| 242 |
|
|
{
|
| 243 |
|
|
return true;
|
| 244 |
|
|
}
|
| 245 |
|
|
}
|
| 246 |
|
|
|
| 247 |
|
|
// Function to figure out if a parent exists
|
| 248 |
|
|
function is_parent($page_id) {
|
| 249 |
|
|
global $database;
|
| 250 |
|
|
// Get parent
|
| 251 |
|
|
$query = $database->query("SELECT parent FROM ".TABLE_PREFIX."pages WHERE page_id = '$page_id'");
|
| 252 |
|
|
$fetch = $query->fetchRow();
|
| 253 |
|
|
// If parent isnt 0 return its ID
|
| 254 |
|
|
if($fetch['parent'] == '0') {
|
| 255 |
|
|
return false;
|
| 256 |
|
|
} else {
|
| 257 |
|
|
return $fetch['parent'];
|
| 258 |
|
|
}
|
| 259 |
|
|
}
|
| 260 |
|
|
|
| 261 |
|
|
// Function to work out level
|
| 262 |
|
|
function level_count($page_id) {
|
| 263 |
|
|
global $database;
|
| 264 |
|
|
// 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'];
|
| 273 |
|
|
return $level+1;
|
| 274 |
|
|
} else {
|
| 275 |
|
|
return 0;
|
| 276 |
|
|
}
|
| 277 |
|
|
}
|
| 278 |
|
|
|
| 279 |
|
|
// Function to work out root parent
|
| 280 |
|
|
function root_parent($page_id) {
|
| 281 |
|
|
global $database;
|
| 282 |
|
|
// Get page details
|
| 283 |
|
|
$query_page = $database->query("SELECT parent,level FROM ".TABLE_PREFIX."pages WHERE page_id = '$page_id' LIMIT 1");
|
| 284 |
|
|
$fetch_page = $query_page->fetchRow();
|
| 285 |
|
|
$parent = $fetch_page['parent'];
|
| 286 |
|
|
$level = $fetch_page['level'];
|
| 287 |
|
|
if($level == 1) {
|
| 288 |
|
|
return $parent;
|
| 289 |
|
|
} elseif($parent == 0) {
|
| 290 |
|
|
return $page_id;
|
| 291 |
|
|
} else {
|
| 292 |
|
|
// Figure out what the root parents id is
|
| 293 |
|
|
$parent_ids = array_reverse(get_parent_ids($page_id));
|
| 294 |
|
|
return $parent_ids[0];
|
| 295 |
|
|
}
|
| 296 |
|
|
}
|
| 297 |
|
|
|
| 298 |
|
|
// Function to get page title
|
| 299 |
|
|
function get_page_title($id) {
|
| 300 |
|
|
global $database;
|
| 301 |
|
|
// 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'];
|
| 306 |
|
|
}
|
| 307 |
|
|
|
| 308 |
|
|
// Function to get a pages menu title
|
| 309 |
|
|
function get_menu_title($id) {
|
| 310 |
|
|
// Connect to the database
|
| 311 |
|
|
$database = new database();
|
| 312 |
|
|
// 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'];
|
| 317 |
|
|
}
|
| 318 |
|
|
|
| 319 |
|
|
// Function to get all parent page titles
|
| 320 |
|
|
function get_parent_titles($parent_id) {
|
| 321 |
|
|
$titles[] = get_menu_title($parent_id);
|
| 322 |
|
|
if(is_parent($parent_id) != false) {
|
| 323 |
|
|
$parent_titles = get_parent_titles(is_parent($parent_id));
|
| 324 |
|
|
$titles = array_merge($titles, $parent_titles);
|
| 325 |
|
|
}
|
| 326 |
|
|
return $titles;
|
| 327 |
|
|
}
|
| 328 |
|
|
|
| 329 |
|
|
// Function to get all parent page id's
|
| 330 |
|
|
function get_parent_ids($parent_id) {
|
| 331 |
|
|
$ids[] = $parent_id;
|
| 332 |
|
|
if(is_parent($parent_id) != false) {
|
| 333 |
|
|
$parent_ids = get_parent_ids(is_parent($parent_id));
|
| 334 |
|
|
$ids = array_merge($ids, $parent_ids);
|
| 335 |
|
|
}
|
| 336 |
|
|
return $ids;
|
| 337 |
|
|
}
|
| 338 |
|
|
|
| 339 |
|
|
// Function to genereate page trail
|
| 340 |
|
|
function get_page_trail($page_id) {
|
| 341 |
|
|
return implode(',', array_reverse(get_parent_ids($page_id)));
|
| 342 |
|
|
}
|
| 343 |
|
|
|
| 344 |
|
|
// Function to get all sub pages id's
|
| 345 |
|
|
function get_subs($parent, $subs) {
|
| 346 |
|
|
// Connect to the database
|
| 347 |
|
|
$database = new database();
|
| 348 |
|
|
// 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()) {
|
| 352 |
|
|
$subs[] = $fetch['page_id'];
|
| 353 |
|
|
// Get subs of this sub
|
| 354 |
|
|
$subs = get_subs($fetch['page_id'], $subs);
|
| 355 |
|
|
}
|
| 356 |
|
|
}
|
| 357 |
|
|
// Return subs array
|
| 358 |
|
|
return $subs;
|
| 359 |
|
|
}
|
| 360 |
|
|
|
| 361 |
|
|
// Function as replacement for php's htmlspecialchars()
|
| 362 |
|
|
// Will not mangle HTML-entities
|
| 363 |
|
|
function my_htmlspecialchars($string) {
|
| 364 |
|
|
$string = preg_replace('/&(?=[#a-z0-9]+;)/i', '__amp;_', $string);
|
| 365 |
|
|
$string = strtr($string, array('<'=>'<', '>'=>'>', '&'=>'&', '"'=>'"', '\''=>'''));
|
| 366 |
|
|
$string = preg_replace('/__amp;_(?=[#a-z0-9]+;)/i', '&', $string);
|
| 367 |
|
|
return($string);
|
| 368 |
|
|
}
|
| 369 |
|
|
|
| 370 |
|
|
// Convert a string from mixed html-entities/umlauts to pure $charset_out-umlauts
|
| 371 |
|
|
// Will replace all numeric and named entities except > < ' " '
|
| 372 |
|
|
// In case of error the returned string is unchanged, and a message is emitted.
|
| 373 |
|
|
function entities_to_umlauts($string, $charset_out=DEFAULT_CHARSET) {
|
| 374 |
|
|
require_once(WB_PATH.'/framework/functions-utf8.php');
|
| 375 |
|
|
return entities_to_umlauts2($string, $charset_out);
|
| 376 |
|
|
}
|
| 377 |
|
|
|
| 378 |
|
|
// Will convert a string in $charset_in encoding to a pure ASCII string with HTML-entities.
|
| 379 |
|
|
// In case of error the returned string is unchanged, and a message is emitted.
|
| 380 |
|
|
function umlauts_to_entities($string, $charset_in=DEFAULT_CHARSET) {
|
| 381 |
|
|
require_once(WB_PATH.'/framework/functions-utf8.php');
|
| 382 |
|
|
return umlauts_to_entities2($string, $charset_in);
|
| 383 |
|
|
}
|
| 384 |
|
|
|
| 385 |
|
|
// Function to convert a page title to a page filename
|
| 386 |
|
|
function page_filename($string) {
|
| 387 |
|
|
require_once(WB_PATH.'/framework/functions-utf8.php');
|
| 388 |
|
|
$string = entities_to_7bit($string);
|
| 389 |
|
|
// Now remove all bad characters
|
| 390 |
|
|
$bad = array(
|
| 391 |
|
|
'\'', /* / */ '"', /* " */ '<', /* < */ '>', /* > */
|
| 392 |
|
|
'{', /* { */ '}', /* } */ '[', /* [ */ ']', /* ] */ '`', /* ` */
|
| 393 |
|
|
'!', /* ! */ '@', /* @ */ '#', /* # */ '$', /* $ */ '%', /* % */
|
| 394 |
|
|
'^', /* ^ */ '&', /* & */ '*', /* * */ '(', /* ( */ ')', /* ) */
|
| 395 |
|
|
'=', /* = */ '+', /* + */ '|', /* | */ '/', /* / */ '\\', /* \ */
|
| 396 |
|
|
';', /* ; */ ':', /* : */ ',', /* , */ '?' /* ? */
|
| 397 |
|
|
);
|
| 398 |
|
|
$string = str_replace($bad, '', $string);
|
| 399 |
|
|
// replace multiple dots in filename to single dot and (multiple) dots at the end of the filename to nothing
|
| 400 |
|
|
$string = preg_replace(array('/\.+/', '/\.+$/'), array('.', ''), $string);
|
| 401 |
|
|
// Now replace spaces with page spcacer
|
| 402 |
|
|
$string = trim($string);
|
| 403 |
|
|
$string = preg_replace('/(\s)+/', PAGE_SPACER, $string);
|
| 404 |
|
|
// Now convert to lower-case
|
| 405 |
|
|
$string = strtolower($string);
|
| 406 |
|
|
// If there are any weird language characters, this will protect us against possible problems they could cause
|
| 407 |
|
|
$string = str_replace(array('%2F', '%'), array('/', ''), urlencode($string));
|
| 408 |
|
|
// Finally, return the cleaned string
|
| 409 |
|
|
return $string;
|
| 410 |
|
|
}
|
| 411 |
|
|
|
| 412 |
|
|
// Function to convert a desired media filename to a clean filename
|
| 413 |
|
|
function media_filename($string) {
|
| 414 |
|
|
require_once(WB_PATH.'/framework/functions-utf8.php');
|
| 415 |
|
|
$string = entities_to_7bit($string);
|
| 416 |
|
|
// Now remove all bad characters
|
| 417 |
|
|
$bad = array(
|
| 418 |
|
|
'\'', // '
|
| 419 |
|
|
'"', // "
|
| 420 |
|
|
'`', // `
|
| 421 |
|
|
'!', // !
|
| 422 |
|
|
'@', // @
|
| 423 |
|
|
'#', // #
|
| 424 |
|
|
'$', // $
|
| 425 |
|
|
'%', // %
|
| 426 |
|
|
'^', // ^
|
| 427 |
|
|
'&', // &
|
| 428 |
|
|
'*', // *
|
| 429 |
|
|
'=', // =
|
| 430 |
|
|
'+', // +
|
| 431 |
|
|
'|', // |
|
| 432 |
|
|
'/', // /
|
| 433 |
|
|
'\\', // \
|
| 434 |
|
|
';', // ;
|
| 435 |
|
|
':', // :
|
| 436 |
|
|
',', // ,
|
| 437 |
|
|
'?' // ?
|
| 438 |
|
|
);
|
| 439 |
|
|
$string = str_replace($bad, '', $string);
|
| 440 |
|
|
// replace multiple dots in filename to single dot and (multiple) dots at the end of the filename to nothing
|
| 441 |
|
|
$string = preg_replace(array('/\.+/', '/\.+$/'), array('.', ''), $string);
|
| 442 |
|
|
// Clean any page spacers at the end of string
|
| 443 |
|
|
$string = trim($string);
|
| 444 |
|
|
// Finally, return the cleaned string
|
| 445 |
|
|
return $string;
|
| 446 |
|
|
}
|
| 447 |
|
|
|
| 448 |
|
|
// Function to work out a page link
|
| 449 |
|
|
if(!function_exists('page_link')) {
|
| 450 |
|
|
function page_link($link) {
|
| 451 |
|
|
global $admin;
|
| 452 |
|
|
return $admin->page_link($link);
|
| 453 |
|
|
}
|
| 454 |
|
|
}
|
| 455 |
|
|
|
| 456 |
|
|
// Create a new file in the pages directory
|
| 457 |
|
|
function create_access_file($filename,$page_id,$level) {
|
| 458 |
|
|
global $admin, $MESSAGE;
|
| 459 |
|
|
if(!is_writable(WB_PATH.PAGES_DIRECTORY.'/')) {
|
| 460 |
|
|
$admin->print_error($MESSAGE['PAGES']['CANNOT_CREATE_ACCESS_FILE']);
|
| 461 |
|
|
} else {
|
| 462 |
|
|
// First make sure parent folder exists
|
| 463 |
|
|
$parent_folders = explode('/',str_replace(WB_PATH.PAGES_DIRECTORY, '', dirname($filename)));
|
| 464 |
|
|
$parents = '';
|
| 465 |
|
|
foreach($parent_folders AS $parent_folder) {
|
| 466 |
|
|
if($parent_folder != '/' AND $parent_folder != '') {
|
| 467 |
|
|
$parents .= '/'.$parent_folder;
|
| 468 |
|
|
if(!file_exists(WB_PATH.PAGES_DIRECTORY.$parents)) {
|
| 469 |
|
|
make_dir(WB_PATH.PAGES_DIRECTORY.$parents);
|
| 470 |
|
|
}
|
| 471 |
|
|
}
|
| 472 |
|
|
}
|
| 473 |
|
|
// The depth of the page directory in the directory hierarchy
|
| 474 |
|
|
// '/pages' is at depth 1
|
| 475 |
|
|
$pages_dir_depth=count(explode('/',PAGES_DIRECTORY))-1;
|
| 476 |
|
|
// Work-out how many ../'s we need to get to the index page
|
| 477 |
|
|
$index_location = '';
|
| 478 |
|
|
for($i = 0; $i < $level + $pages_dir_depth; $i++) {
|
| 479 |
|
|
$index_location .= '../';
|
| 480 |
|
|
}
|
| 481 |
|
|
$content = ''.
|
| 482 |
|
|
'<?php
|
| 483 |
|
|
$page_id = '.$page_id.';
|
| 484 |
|
|
require("'.$index_location.'config.php");
|
| 485 |
|
|
require(WB_PATH."/index.php");
|
| 486 |
|
|
?>';
|
| 487 |
|
|
$handle = fopen($filename, 'w');
|
| 488 |
|
|
fwrite($handle, $content);
|
| 489 |
|
|
fclose($handle);
|
| 490 |
|
|
// Chmod the file
|
| 491 |
|
|
change_mode($filename);
|
| 492 |
|
|
}
|
| 493 |
|
|
}
|
| 494 |
|
|
|
| 495 |
|
|
// 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(
|
| 500 |
|
|
'txt' => 'text/plain',
|
| 501 |
|
|
'htm' => 'text/html',
|
| 502 |
|
|
'html' => 'text/html',
|
| 503 |
|
|
'php' => 'text/html',
|
| 504 |
|
|
'css' => 'text/css',
|
| 505 |
|
|
'js' => 'application/javascript',
|
| 506 |
|
|
'json' => 'application/json',
|
| 507 |
|
|
'xml' => 'application/xml',
|
| 508 |
|
|
'swf' => 'application/x-shockwave-flash',
|
| 509 |
|
|
'flv' => 'video/x-flv',
|
| 510 |
|
|
|
| 511 |
|
|
// images
|
| 512 |
|
|
'png' => 'image/png',
|
| 513 |
|
|
'jpe' => 'image/jpeg',
|
| 514 |
|
|
'jpeg' => 'image/jpeg',
|
| 515 |
|
|
'jpg' => 'image/jpeg',
|
| 516 |
|
|
'gif' => 'image/gif',
|
| 517 |
|
|
'bmp' => 'image/bmp',
|
| 518 |
|
|
'ico' => 'image/vnd.microsoft.icon',
|
| 519 |
|
|
'tiff' => 'image/tiff',
|
| 520 |
|
|
'tif' => 'image/tiff',
|
| 521 |
|
|
'svg' => 'image/svg+xml',
|
| 522 |
|
|
'svgz' => 'image/svg+xml',
|
| 523 |
|
|
|
| 524 |
|
|
// archives
|
| 525 |
|
|
'zip' => 'application/zip',
|
| 526 |
|
|
'rar' => 'application/x-rar-compressed',
|
| 527 |
|
|
'exe' => 'application/x-msdownload',
|
| 528 |
|
|
'msi' => 'application/x-msdownload',
|
| 529 |
|
|
'cab' => 'application/vnd.ms-cab-compressed',
|
| 530 |
|
|
|
| 531 |
|
|
// audio/video
|
| 532 |
|
|
'mp3' => 'audio/mpeg',
|
| 533 |
|
|
'mp4' => 'audio/mpeg',
|
| 534 |
|
|
'qt' => 'video/quicktime',
|
| 535 |
|
|
'mov' => 'video/quicktime',
|
| 536 |
|
|
|
| 537 |
|
|
// adobe
|
| 538 |
|
|
'pdf' => 'application/pdf',
|
| 539 |
|
|
'psd' => 'image/vnd.adobe.photoshop',
|
| 540 |
|
|
'ai' => 'application/postscript',
|
| 541 |
|
|
'eps' => 'application/postscript',
|
| 542 |
|
|
'ps' => 'application/postscript',
|
| 543 |
|
|
|
| 544 |
|
|
// ms office
|
| 545 |
|
|
'doc' => 'application/msword',
|
| 546 |
|
|
'rtf' => 'application/rtf',
|
| 547 |
|
|
'xls' => 'application/vnd.ms-excel',
|
| 548 |
|
|
'ppt' => 'application/vnd.ms-powerpoint',
|
| 549 |
|
|
|
| 550 |
|
|
// open office
|
| 551 |
|
|
'odt' => 'application/vnd.oasis.opendocument.text',
|
| 552 |
|
|
'ods' => 'application/vnd.oasis.opendocument.spreadsheet',
|
| 553 |
|
|
);
|
| 554 |
|
|
|
| 555 |
|
|
$temp = explode('.',$filename);
|
| 556 |
|
|
$ext = strtolower(array_pop($temp));
|
| 557 |
|
|
|
| 558 |
|
|
if (array_key_exists($ext, $mime_types)) {
|
| 559 |
|
|
return $mime_types[$ext];
|
| 560 |
|
|
}
|
| 561 |
|
|
elseif (function_exists('finfo_open')) {
|
| 562 |
|
|
$finfo = finfo_open(FILEINFO_MIME);
|
| 563 |
|
|
$mimetype = finfo_file($finfo, $filename);
|
| 564 |
|
|
finfo_close($finfo);
|
| 565 |
|
|
return $mimetype;
|
| 566 |
|
|
}
|
| 567 |
|
|
else {
|
| 568 |
|
|
return 'application/octet-stream';
|
| 569 |
|
|
}
|
| 570 |
|
|
}
|
| 571 |
|
|
}
|
| 572 |
|
|
|
| 573 |
|
|
// Generate a thumbnail from an image
|
| 574 |
|
|
function make_thumb($source, $destination, $size) {
|
| 575 |
|
|
// Check if GD is installed
|
| 576 |
|
|
if(extension_loaded('gd') AND function_exists('imageCreateFromJpeg')) {
|
| 577 |
|
|
// First figure out the size of the thumbnail
|
| 578 |
|
|
list($original_x, $original_y) = getimagesize($source);
|
| 579 |
|
|
if ($original_x > $original_y) {
|
| 580 |
|
|
$thumb_w = $size;
|
| 581 |
|
|
$thumb_h = $original_y*($size/$original_x);
|
| 582 |
|
|
}
|
| 583 |
|
|
if ($original_x < $original_y) {
|
| 584 |
|
|
$thumb_w = $original_x*($size/$original_y);
|
| 585 |
|
|
$thumb_h = $size;
|
| 586 |
|
|
}
|
| 587 |
|
|
if ($original_x == $original_y) {
|
| 588 |
|
|
$thumb_w = $size;
|
| 589 |
|
|
$thumb_h = $size;
|
| 590 |
|
|
}
|
| 591 |
|
|
// Now make the thumbnail
|
| 592 |
|
|
$source = imageCreateFromJpeg($source);
|
| 593 |
|
|
$dst_img = ImageCreateTrueColor($thumb_w, $thumb_h);
|
| 594 |
|
|
imagecopyresampled($dst_img,$source,0,0,0,0,$thumb_w,$thumb_h,$original_x,$original_y);
|
| 595 |
|
|
imagejpeg($dst_img, $destination);
|
| 596 |
|
|
// Clear memory
|
| 597 |
|
|
imagedestroy($dst_img);
|
| 598 |
|
|
imagedestroy($source);
|
| 599 |
|
|
// Return true
|
| 600 |
|
|
return true;
|
| 601 |
|
|
} else {
|
| 602 |
|
|
return false;
|
| 603 |
|
|
}
|
| 604 |
|
|
}
|
| 605 |
|
|
|
| 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';
|
| 621 |
|
|
}
|
| 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;
|
| 642 |
|
|
}
|
| 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');
|
| 648 |
|
|
}
|
| 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 |
|
|
}
|
| 670 |
|
|
// Get the value for "who"
|
| 671 |
|
|
$value = substr($octal_value, $position-1, 1);
|
| 672 |
|
|
// Now work-out the details of the value
|
| 673 |
|
|
switch($value) {
|
| 674 |
|
|
case '0':
|
| 675 |
|
|
$r = false;
|
| 676 |
|
|
$w = false;
|
| 677 |
|
|
$e = false;
|
| 678 |
|
|
break;
|
| 679 |
|
|
case '1':
|
| 680 |
|
|
$r = false;
|
| 681 |
|
|
$w = false;
|
| 682 |
|
|
$e = true;
|
| 683 |
|
|
break;
|
| 684 |
|
|
case '2':
|
| 685 |
|
|
$r = false;
|
| 686 |
|
|
$w = true;
|
| 687 |
|
|
$e = false;
|
| 688 |
|
|
break;
|
| 689 |
|
|
case '3':
|
| 690 |
|
|
$r = false;
|
| 691 |
|
|
$w = true;
|
| 692 |
|
|
$e = true;
|
| 693 |
|
|
break;
|
| 694 |
|
|
case '4':
|
| 695 |
|
|
$r = true;
|
| 696 |
|
|
$w = false;
|
| 697 |
|
|
$e = false;
|
| 698 |
|
|
break;
|
| 699 |
|
|
case '5':
|
| 700 |
|
|
$r = true;
|
| 701 |
|
|
$w = false;
|
| 702 |
|
|
$e = true;
|
| 703 |
|
|
break;
|
| 704 |
|
|
case '6':
|
| 705 |
|
|
$r = true;
|
| 706 |
|
|
$w = true;
|
| 707 |
|
|
$e = false;
|
| 708 |
|
|
break;
|
| 709 |
|
|
case '7':
|
| 710 |
|
|
$r = true;
|
| 711 |
|
|
$w = true;
|
| 712 |
|
|
$e = true;
|
| 713 |
|
|
break;
|
| 714 |
|
|
default:
|
| 715 |
|
|
$r = false;
|
| 716 |
|
|
$w = false;
|
| 717 |
|
|
$e = false;
|
| 718 |
|
|
}
|
| 719 |
|
|
// And finally, return either true or false
|
| 720 |
|
|
return $$action;
|
| 721 |
|
|
}
|
| 722 |
|
|
|
| 723 |
|
|
// Function to delete a page
|
| 724 |
|
|
function delete_page($page_id) {
|
| 725 |
|
|
|
| 726 |
|
|
global $admin, $database, $MESSAGE;
|
| 727 |
|
|
|
| 728 |
|
|
// Find out more about the page
|
| 729 |
|
|
$database = new database();
|
| 730 |
|
|
$query = "SELECT page_id,menu_title,page_title,level,link,parent,modified_by,modified_when FROM ".TABLE_PREFIX."pages WHERE page_id = '$page_id'";
|
| 731 |
|
|
$results = $database->query($query);
|
| 732 |
|
|
if($database->is_error()) {
|
| 733 |
|
|
$admin->print_error($database->get_error());
|
| 734 |
|
|
}
|
| 735 |
|
|
if($results->numRows() == 0) {
|
| 736 |
|
|
$admin->print_error($MESSAGE['PAGES']['NOT_FOUND']);
|
| 737 |
|
|
}
|
| 738 |
|
|
$results_array = $results->fetchRow();
|
| 739 |
|
|
$parent = $results_array['parent'];
|
| 740 |
|
|
$level = $results_array['level'];
|
| 741 |
|
|
$link = $results_array['link'];
|
| 742 |
|
|
$page_title = ($results_array['page_title']);
|
| 743 |
|
|
$menu_title = ($results_array['menu_title']);
|
| 744 |
|
|
|
| 745 |
|
|
// Get the sections that belong to the page
|
| 746 |
|
|
$query_sections = $database->query("SELECT section_id,module FROM ".TABLE_PREFIX."sections WHERE page_id = '$page_id'");
|
| 747 |
|
|
if($query_sections->numRows() > 0) {
|
| 748 |
|
|
while($section = $query_sections->fetchRow()) {
|
| 749 |
|
|
// Set section id
|
| 750 |
|
|
$section_id = $section['section_id'];
|
| 751 |
|
|
// Include the modules delete file if it exists
|
| 752 |
|
|
if(file_exists(WB_PATH.'/modules/'.$section['module'].'/delete.php')) {
|
| 753 |
|
|
require(WB_PATH.'/modules/'.$section['module'].'/delete.php');
|
| 754 |
|
|
}
|
| 755 |
|
|
}
|
| 756 |
|
|
}
|
| 757 |
|
|
|
| 758 |
|
|
// Update the pages table
|
| 759 |
|
|
$query = "DELETE FROM ".TABLE_PREFIX."pages WHERE page_id = '$page_id'";
|
| 760 |
|
|
$database->query($query);
|
| 761 |
|
|
if($database->is_error()) {
|
| 762 |
|
|
$admin->print_error($database->get_error());
|
| 763 |
|
|
}
|
| 764 |
|
|
|
| 765 |
|
|
// Update the sections table
|
| 766 |
|
|
$query = "DELETE FROM ".TABLE_PREFIX."sections WHERE page_id = '$page_id'";
|
| 767 |
|
|
$database->query($query);
|
| 768 |
|
|
if($database->is_error()) {
|
| 769 |
|
|
$admin->print_error($database->get_error());
|
| 770 |
|
|
}
|
| 771 |
|
|
|
| 772 |
|
|
// Include the ordering class or clean-up ordering
|
| 773 |
|
|
require_once(WB_PATH.'/framework/class.order.php');
|
| 774 |
|
|
$order = new order(TABLE_PREFIX.'pages', 'position', 'page_id', 'parent');
|
| 775 |
|
|
$order->clean($parent);
|
| 776 |
|
|
|
| 777 |
|
|
// Unlink the page access file and directory
|
| 778 |
|
|
$directory = WB_PATH.PAGES_DIRECTORY.$link;
|
| 779 |
|
|
$filename = $directory.PAGE_EXTENSION;
|
| 780 |
|
|
$directory .= '/';
|
| 781 |
|
|
if(file_exists($filename)) {
|
| 782 |
|
|
if(!is_writable(WB_PATH.PAGES_DIRECTORY.'/')) {
|
| 783 |
|
|
$admin->print_error($MESSAGE['PAGES']['CANNOT_DELETE_ACCESS_FILE']);
|
| 784 |
|
|
} else {
|
| 785 |
|
|
unlink($filename);
|
| 786 |
|
|
if(file_exists($directory) && rtrim($directory,'/')!=WB_PATH.PAGES_DIRECTORY && substr($link, 0, 1) != '.') {
|
| 787 |
|
|
rm_full_dir($directory);
|
| 788 |
|
|
}
|
| 789 |
|
|
}
|
| 790 |
|
|
}
|
| 791 |
|
|
|
| 792 |
|
|
}
|
| 793 |
|
|
|
| 794 |
|
|
// Load module into DB
|
| 795 |
|
|
function load_module($directory, $install = false) {
|
| 796 |
|
|
global $database,$admin,$MESSAGE;
|
| 797 |
|
|
if(is_dir($directory) AND file_exists($directory.'/info.php'))
|
| 798 |
|
|
{
|
| 799 |
|
|
require($directory.'/info.php');
|
| 800 |
|
|
if(isset($module_name))
|
| 801 |
|
|
{
|
| 802 |
|
|
if(!isset($module_license)) { $module_license = 'GNU General Public License'; }
|
| 803 |
|
|
if(!isset($module_platform) AND isset($module_designed_for)) { $module_platform = $module_designed_for; }
|
| 804 |
|
|
if(!isset($module_function) AND isset($module_type)) { $module_function = $module_type; }
|
| 805 |
|
|
$module_function = strtolower($module_function);
|
| 806 |
|
|
// Check that it doesn't already exist
|
| 807 |
|
|
$result = $database->query("SELECT addon_id FROM ".TABLE_PREFIX."addons WHERE type = 'module' AND directory = '".$module_directory."' LIMIT 0,1");
|
| 808 |
|
|
if($result->numRows() == 0)
|
| 809 |
|
|
{
|
| 810 |
|
|
// Load into DB
|
| 811 |
|
|
$query = "INSERT INTO ".TABLE_PREFIX."addons ".
|
| 812 |
|
|
"(directory,name,description,type,function,version,platform,author,license) ".
|
| 813 |
|
|
"VALUES ('$module_directory','$module_name','".addslashes($module_description)."','module',".
|
| 814 |
|
|
"'$module_function','$module_version','$module_platform','$module_author','$module_license')";
|
| 815 |
|
|
$database->query($query);
|
| 816 |
|
|
// Run installation script
|
| 817 |
|
|
if($install == true)
|
| 818 |
|
|
{
|
| 819 |
|
|
if(file_exists($directory.'/install.php')) {
|
| 820 |
|
|
require($directory.'/install.php');
|
| 821 |
|
|
}
|
| 822 |
|
|
}
|
| 823 |
|
|
}
|
| 824 |
|
|
}
|
| 825 |
|
|
}
|
| 826 |
|
|
}
|
| 827 |
|
|
|
| 828 |
|
|
// Load template into DB
|
| 829 |
|
|
function load_template($directory) {
|
| 830 |
|
|
global $database;
|
| 831 |
|
|
if(is_dir($directory) AND file_exists($directory.'/info.php')) {
|
| 832 |
|
|
require($directory.'/info.php');
|
| 833 |
|
|
if(isset($template_name)) {
|
| 834 |
|
|
if(!isset($template_license)) { $template_license = 'GNU General Public License'; }
|
| 835 |
|
|
if(!isset($template_platform) AND isset($template_designed_for)) { $template_platform = $template_designed_for; }
|
| 836 |
|
|
if(!isset($template_function)) { $template_function = 'template'; }
|
| 837 |
|
|
// Check that it doesn't already exist
|
| 838 |
|
|
$result = $database->query("SELECT addon_id FROM ".TABLE_PREFIX."addons WHERE type = 'template' AND directory = '".$template_directory."' LIMIT 0,1");
|
| 839 |
|
|
if($result->numRows() == 0) {
|
| 840 |
|
|
// Load into DB
|
| 841 |
|
|
$query = "INSERT INTO ".TABLE_PREFIX."addons ".
|
| 842 |
|
|
"(directory,name,description,type,function,version,platform,author,license) ".
|
| 843 |
|
|
"VALUES ('$template_directory','$template_name','".addslashes($template_description)."','template',".
|
| 844 |
|
|
"'$template_function','$template_version','$template_platform','$template_author','$template_license')";
|
| 845 |
|
|
$database->query($query);
|
| 846 |
|
|
}
|
| 847 |
|
|
}
|
| 848 |
|
|
}
|
| 849 |
|
|
}
|
| 850 |
|
|
|
| 851 |
|
|
// Load language into DB
|
| 852 |
|
|
function load_language($file) {
|
| 853 |
|
|
global $database;
|
| 854 |
|
|
if (file_exists($file) && preg_match('#^([A-Z]{2}.php)#', basename($file))) {
|
| 855 |
|
|
require($file);
|
| 856 |
|
|
if(isset($language_name)) {
|
| 857 |
|
|
if(!isset($language_license)) { $language_license = 'GNU General Public License'; }
|
| 858 |
|
|
if(!isset($language_platform) AND isset($language_designed_for)) { $language_platform = $language_designed_for; }
|
| 859 |
|
|
// Check that it doesn't already exist
|
| 860 |
|
|
$result = $database->query("SELECT addon_id FROM ".TABLE_PREFIX."addons WHERE type = 'language' AND directory = '".$language_code."' LIMIT 0,1");
|
| 861 |
|
|
if($result->numRows() == 0) {
|
| 862 |
|
|
// Load into DB
|
| 863 |
|
|
$query = "INSERT INTO ".TABLE_PREFIX."addons ".
|
| 864 |
|
|
"(directory,name,type,version,platform,author,license) ".
|
| 865 |
|
|
"VALUES ('$language_code','$language_name','language',".
|
| 866 |
|
|
"'$language_version','$language_platform','$language_author','$language_license')";
|
| 867 |
|
|
$database->query($query);
|
| 868 |
|
|
}
|
| 869 |
|
|
}
|
| 870 |
|
|
}
|
| 871 |
|
|
}
|
| 872 |
|
|
|
| 873 |
|
|
// Upgrade module info in DB, optionally start upgrade script
|
| 874 |
|
|
function upgrade_module($directory, $upgrade = false) {
|
| 875 |
|
|
global $database, $admin, $MESSAGE;
|
| 876 |
|
|
$directory = WB_PATH . "/modules/$directory";
|
| 877 |
|
|
if(file_exists($directory.'/info.php')) {
|
| 878 |
|
|
require($directory.'/info.php');
|
| 879 |
|
|
if(isset($module_name)) {
|
| 880 |
|
|
if(!isset($module_license)) { $module_license = 'GNU General Public License'; }
|
| 881 |
|
|
if(!isset($module_platform) AND isset($module_designed_for)) { $module_platform = $module_designed_for; }
|
| 882 |
|
|
if(!isset($module_function) AND isset($module_type)) { $module_function = $module_type; }
|
| 883 |
|
|
$module_function = strtolower($module_function);
|
| 884 |
|
|
// Check that it does already exist
|
| 885 |
|
|
$result = $database->query("SELECT addon_id FROM ".TABLE_PREFIX."addons WHERE directory = '".$module_directory."' LIMIT 0,1");
|
| 886 |
|
|
if($result->numRows() > 0) {
|
| 887 |
|
|
// Update in DB
|
| 888 |
|
|
$query = "UPDATE " . TABLE_PREFIX . "addons SET " .
|
| 889 |
|
|
"version = '$module_version', " .
|
| 890 |
|
|
"description = '" . addslashes($module_description) . "', " .
|
| 891 |
|
|
"platform = '$module_platform', " .
|
| 892 |
|
|
"author = '$module_author', " .
|
| 893 |
|
|
"license = '$module_license'" .
|
| 894 |
|
|
"WHERE directory = '$module_directory'";
|
| 895 |
|
|
$database->query($query);
|
| 896 |
|
|
// Run upgrade script
|
| 897 |
|
|
if($upgrade == true) {
|
| 898 |
|
|
if(file_exists($directory.'/upgrade.php')) {
|
| 899 |
|
|
require($directory.'/upgrade.php');
|
| 900 |
|
|
}
|
| 901 |
|
|
}
|
| 902 |
|
|
}
|
| 903 |
|
|
}
|
| 904 |
|
|
}
|
| 905 |
|
|
}
|
| 906 |
|
|
|
| 907 |
|
|
// extracts the content of a string variable from a string (save alternative to including files)
|
| 908 |
|
|
if(!function_exists('get_variable_content')) {
|
| 909 |
|
|
function get_variable_content($search, $data, $striptags=true, $convert_to_entities=true) {
|
| 910 |
|
|
$match = '';
|
| 911 |
|
|
// search for $variable followed by 0-n whitespace then by = then by 0-n whitespace
|
| 912 |
|
|
// then either " or ' then 0-n characters then either " or ' followed by 0-n whitespace and ;
|
| 913 |
|
|
// the variable name is returned in $match[1], the content in $match[3]
|
| 914 |
|
|
if (preg_match('/(\$' .$search .')\s*=\s*("|\')(.*)\2\s*;/', $data, $match)) {
|
| 915 |
|
|
if(strip_tags(trim($match[1])) == '$' .$search) {
|
| 916 |
|
|
// variable name matches, return it's value
|
| 917 |
|
|
$match[3] = ($striptags == true) ? strip_tags($match[3]) : $match[3];
|
| 918 |
|
|
$match[3] = ($convert_to_entities == true) ? htmlentities($match[3]) : $match[3];
|
| 919 |
|
|
return $match[3];
|
| 920 |
|
|
}
|
| 921 |
|
|
}
|
| 922 |
|
|
return false;
|
| 923 |
|
|
}
|
| 924 |
|
|
}
|
| 925 |
|
|
|
| 926 |
|
|
?>
|