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