]> git.vanrenterghem.biz Git - www.vanrenterghem.biz.git/blob - phpBB2_old/admin/xs_edit.php
Updated to clarify we temp. use USB and added reference to SD-only install option.
[www.vanrenterghem.biz.git] / phpBB2_old / admin / xs_edit.php
1 <?php
3 /***************************************************************************
4  *                                xs_edit.php
5  *                                -----------
6  *   copyright            : (C) 2003, 2004 CyberAlien
7  *   support              : http://www.phpbbstyles.com
8  *
9  *   version              : 2.0.1
10  *
11  *   file revision        : 46
12  *   project revision     : 51
13  *   last modified        : 25 Aug 2004  11:51:47
14  *
15  ***************************************************************************/
17 /***************************************************************************
18  *
19  *   This program is free software; you can redistribute it and/or modify
20  *   it under the terms of the GNU General Public License as published by
21  *   the Free Software Foundation; either version 2 of the License, or
22  *   (at your option) any later version.
23  *
24  ***************************************************************************/
26 define('IN_PHPBB', 1);
27 $phpbb_root_path = "./../";
28 $no_page_header = true;
29 require($phpbb_root_path . 'extension.inc');
30 require('./pagestart.' . $phpEx);
32 // check if mod is installed
33 if(empty($template->xs_version) || $template->xs_version !== 5)
34 {
35         message_die(GENERAL_ERROR, 'eXtreme Styles mod is not installed. You forgot to upload includes/template.php');
36 }
38 define('IN_XS', true);
39 include_once('xs_include.' . $phpEx);
42 // check filter
43 $filter = isset($HTTP_GET_VARS['filter']) ? stripslashes($HTTP_GET_VARS['filter']) : (isset($HTTP_POST_VARS['filter']) ? stripslashes($HTTP_POST_VARS['filter']) : '');
44 if(isset($HTTP_POST_VARS['filter_update']))
45 {
46         $filter_data = array(
47                 'ext'   => trim(stripslashes($HTTP_POST_VARS['filter_ext'])),
48                 'data'  => trim(stripslashes($HTTP_POST_VARS['filter_data']))
49                 );
50          $filter = serialize($filter_data);
51 }
52 else
53 {
54         $filter_data = @unserialize($filter);
55         if(empty($filter_data['ext']))
56         {
57                 $filter_data['ext'] = '';
58         }
59         if(empty($filter_data['data']))
60         {
61                 $filter_data['data'] = '';
62         }
63 }
64 $filter_str = '?filter=' . urlencode($filter);
67 $template->assign_block_vars('nav_left',array('ITEM' => '&raquo; <a href="' . append_sid('xs_edit.'.$phpEx.$filter_str) . '">' . $lang['xs_edit_templates'] . '</a>'));
69 $editable = array('.htm', '.html', '.tpl', '.css', '.txt', '.cfg', '.xml', '.php', '.htaccess');
71 // get current directory
72 $current_dir = isset($HTTP_GET_VARS['dir']) ? $HTTP_GET_VARS['dir'] : (isset($HTTP_POST_VARS['dir']) ? $HTTP_POST_VARS['dir'] : 'templates');
73 $current_dir = str_replace(array("\\", ".."), array("/", ""), $current_dir);
74 if(defined('DEMO_MODE') && substr($current_dir, 0, 9) !== 'templates')
75 {       // limit access to "templates" in demo mode
76         $current_dir = 'templates';
77 }
78 $dirs = explode('/', $current_dir);
79 for($i=0; $i<count($dirs); $i++)
80 {
81         if(!$dirs[$i] || $dirs[$i] === '.')
82         {
83                 unset($dirs[$i]);
84         }
85 }
86 $current_dir = implode('/', $dirs);
87 $current_dir_full = $current_dir; //'templates' . ($current_dir ? '/' . $current_dir : '');
88 $current_dir_root = $current_dir ? $current_dir . '/' : '';
90 $return_dir = str_replace('{URL}', append_sid('xs_edit.'.$phpEx.$filter_str.'&dir='.urlencode($current_dir)), $lang['xs_edittpl_back_dir']);
91 $return_url = $return_dir;
92 $return_url_root = str_replace('{URL}', append_sid('xs_edit.'.$phpEx.$filter_str.'&dir='), $lang['xs_edittpl_back_dir']);
95 $template->assign_vars(array(
96         'FILTER_EXT'    => htmlspecialchars($filter_data['ext']),
97         'FILTER_DATA'   => htmlspecialchars($filter_data['data']),
98         'FILTER_URL'    => append_sid('xs_edit.'.$phpEx),
99         'FILTER_DIR'    => htmlspecialchars($current_dir),
100         'S_FILTER'              => '<input type="hidden" name="filter" value="' . htmlspecialchars($filter) . '" />'
101         ));
104 /*
105 * show edit form
106 */
107 if(isset($HTTP_GET_VARS['edit']) && !empty($HTTP_GET_VARS['restore']))
109         $file = stripslashes($HTTP_GET_VARS['edit']);
110         $fullfile = $current_dir_root . $file;
111         $localfile = '../' . $fullfile;
112         $hash = md5($localfile);
113         $backup_name = XS_TEMP_DIR . XS_BACKUP_PREFIX . $hash . '.' . intval($HTTP_GET_VARS['restore']) . XS_BACKUP_EXT;
114         if(@file_exists($backup_name))
115         {
116                 // restore file
117                 $HTTP_POST_VARS['edit'] = $HTTP_GET_VARS['edit'];
118                 $HTTP_POST_VARS['content'] = addslashes(implode('', @file($backup_name)));
119                 unset($HTTP_GET_VARS['edit']);
120                 $return_file = str_replace('{URL}', append_sid('xs_edit.'.$phpEx.$filter_str.'&dir='.urlencode($current_dir).'&edit='.urlencode($file)), $lang['xs_edittpl_back_edit']);
121                 $return_url = $return_file . '<br /><br />' . $return_dir;
122         }
126 /*
127 * save modified file
128 */
129 if(isset($HTTP_POST_VARS['edit']) && !defined('DEMO_MODE'))
131         $file = stripslashes($HTTP_POST_VARS['edit']);
132         $content = stripslashes($HTTP_POST_VARS['content']);
133         $fullfile = $current_dir_root . $file;
134         $localfile = '../' . $fullfile;
135         if(!empty($HTTP_POST_VARS['trim']))
136         {
137                 $content = trim($content);
138         }
139         if(!empty($HTTP_POST_FILES['upload']['tmp_name']) && @file_exists($HTTP_POST_FILES['upload']['tmp_name']))
140         {
141                 $content = @implode('', @file($HTTP_POST_FILES['upload']['tmp_name']));
142         }
143         $params = array(
144                 'edit'          => $file,
145                 'dir'           => $current_dir,
146                 'content'       => $content,
147                 'filter'        => $filter,
148                 );
149         $return_file = str_replace('{URL}', append_sid('xs_edit.'.$phpEx.$filter_str.'&dir='.urlencode($current_dir).'&edit='.urlencode($file)), $lang['xs_edittpl_back_edit']);
150         $return_url = $return_file . '<br /><br />' . $return_dir;
151         // get ftp configuration
152         $write_local = false;
153         if(!get_ftp_config(append_sid('xs_edit.'.$phpEx), $params, true))
154         {
155                 xs_exit();
156         }
157         xs_ftp_connect(append_sid('xs_edit.'.$phpEx), $params, true);
158         if($ftp === XS_FTP_LOCAL)
159         {
160                 $write_local = true;
161                 $local_filename = $localfile;
162         }
163         else
164         {
165                 $local_filename = XS_TEMP_DIR . 'edit_' . time() . '.tmp';
166         }
167         $f = @fopen($local_filename, 'wb');
168         if(!$f)
169         {
170                 xs_error($lang['xs_error_cannot_open'] . '<br /><br />' . $return_url);
171         }
172         fwrite($f, $content);
173         fclose($f);
174         if($write_local)
175         {
176                 xs_message($lang['Information'], $lang['xs_edit_file_saved'] . '<br /><br />' . $return_url);
177         }
178         // generate ftp actions
179         $actions = array();
180         // chdir to template directory
181         for($i=0; $i<count($dirs); $i++)
182         {
183                 $actions[] = array(
184                                 'command'       => 'chdir',
185                                 'dir'           => $dirs[$i]
186                 );
187         }
188         $actions[] = array(
189                         'command'       => 'upload',
190                         'local'         => $local_filename,
191                         'remote'        => $fullfile
192                         );
193         $ftp_log = array();
194         $ftp_error = '';
195         $res = ftp_myexec($actions);
196         echo "<!--\n\n";
197         echo "\$actions dump:\n\n";
198         print_r($actions);
199         echo "\n\n\$ftp_log dump:\n\n";
200         print_r($ftp_log);
201         echo "\n\n -->";
202         @unlink($local_filename);
203         if($res)
204         {
205                 xs_message($lang['Information'], $lang['xs_edit_file_saved'] . '<br /><br />' . $return_url);
206         }
207         xs_error($ftp_error . '<br /><br />' . $return_url);
211 /*
212 * show edit form
213 */
214 if(isset($HTTP_GET_VARS['edit']))
216         $file = stripslashes($HTTP_GET_VARS['edit']);
217         $fullfile = $current_dir_root . $file;
218         $localfile = '../' . $fullfile;
219         $hash = md5($localfile);
220         if(!@file_exists($localfile))
221         {
222                 xs_error($lang['xs_edit_not_found'] . '<br /><br />' . $return_url);
223         }
224         if(isset($HTTP_GET_VARS['download']) && !defined('DEMO_MODE'))
225         {
226                 $content = implode('', @file($localfile));
227                 xs_download_file($file, $content);
228                 xs_exit();
229         }
230         if(isset($HTTP_GET_VARS['downloadbackup']) && !defined('DEMO_MODE'))
231         {
232                 $backup_name = XS_TEMP_DIR . XS_BACKUP_PREFIX . $hash . '.' . intval($HTTP_GET_VARS['downloadbackup']) . XS_BACKUP_EXT;
233                 xs_download_file($file, implode('', @file($backup_name)));
234                 xs_exit();
235         }
236         $return_file = str_replace('{URL}', append_sid('xs_edit.'.$phpEx.$filter_str.'&dir='.urlencode($current_dir).'&edit='.urlencode($file)), $lang['xs_edittpl_back_edit']);
237         $return_url = $return_file . '<br /><br />' . $return_dir;
238         $template->assign_vars(array(
239                 'U_ACTION'              => append_sid('xs_edit.'.$phpEx),
240                 'U_BROWSE'              => append_sid('xs_edit.'.$phpEx.$filter_str.'&dir='.urlencode($current_dir)),
241                 'U_EDIT'                => append_sid('xs_edit.'.$phpEx.$filter_str.'&dir='.urlencode($current_dir).'&edit='.urlencode($file)),
242                 'U_BACKUP'              => append_sid('xs_edit.'.$phpEx.$filter_str.'&dobackup=1&dir='.urlencode($current_dir).'&edit='.urlencode($file)),
243                 'U_DOWNLOAD'    => append_sid('xs_edit.'.$phpEx.$filter_str.'&download=1&dir='.urlencode($current_dir).'&edit='.urlencode($file)),
244                 'CURRENT_DIR'   => htmlspecialchars($current_dir_full),
245                 'DIR'                   => htmlspecialchars($current_dir),
246                 'FILE'                  => htmlspecialchars($file),
247                 'FULLFILE'              => htmlspecialchars($fullfile),
248                 'CONTENT'               => defined('DEMO_MODE') ? 'you cannot edit file in demo mode' : htmlspecialchars(implode('', @file($localfile))),
249                 )
250         );
251         if($current_dir_full)
252         {
253                 $template->assign_block_vars('nav_left',array('ITEM' => '&raquo; <a href="' . append_sid('xs_edit.'.$phpEx.$filter_str.'&dir='.$current_dir) . '">' . htmlspecialchars($current_dir_full) . '</a>'));
254         }
256         // show tree
257         $arr = array();
258         $template->assign_block_vars('tree', array(
259                 'ITEM'  => 'phpBB',
260                 'URL'   => append_sid('xs_edit.'.$phpEx.$filter_str.'&dir='),
261                 'SEPARATOR'     => '',
262                 ));
263         $back_dir = '';
264         for($i=0; $i<count($dirs); $i++)
265         {
266                 $arr[] = $dirs[$i];
267                 $str = implode('/', $arr);
268                 if(count($dirs) > ($i + 1))
269                 {
270                         $back_dir = $str;
271                 }
272                 $template->assign_block_vars('tree', array(
273                         'ITEM'  => htmlspecialchars($dirs[$i]),
274                         'URL'   => append_sid('xs_edit.'.$phpEx.$filter_str.'&dir='.urlencode($str)),
275                         'SEPARATOR'     => '/',
276                         ));
277         }
279         // view backup
280         if(!empty($HTTP_GET_VARS['viewbackup']) && !defined('DEMO_MODE'))
281         {
282                 $backup_name = XS_TEMP_DIR . XS_BACKUP_PREFIX . $hash . '.' . intval($HTTP_GET_VARS['viewbackup']) . XS_BACKUP_EXT;
283                 $template->assign_vars(array(
284                         'CONTENT'       => implode('', @file($backup_name))
285                         )
286                 );
287         }
289         // save backup
290         if(isset($HTTP_GET_VARS['dobackup']) && !defined('DEMO_MODE'))
291         {
292                 $backup_name = XS_TEMP_DIR . XS_BACKUP_PREFIX . $hash . '.' . time() . XS_BACKUP_EXT;
293                 $str = @implode('', @file($localfile));
294                 $f = @fopen($backup_name, 'wb');
295                 if(!$f)
296                 {
297                         xs_error(str_replace('{FILE}', $backup_name, $lang['xs_error_cannot_create_tmp']) . '<br /><br />' . $return_url);
298                 }
299                 fwrite($f, $str);
300                 fclose($f);
301                 @chmod($backup_name, 0777);
302         }
304         // delete backup
305         if(isset($HTTP_GET_VARS['delbackup']) && !defined('DEMO_MODE'))
306         {
307                 $backup_name = XS_TEMP_DIR . XS_BACKUP_PREFIX . $hash . '.' . intval($HTTP_GET_VARS['delbackup']) . XS_BACKUP_EXT;
308                 @unlink($backup_name);
309         }
311         // show backups
312         $backups = array();
313         $res = opendir(XS_TEMP_DIR);
314         $match = XS_BACKUP_PREFIX . $hash . '.';
315         $match_len = strlen($match);
316         while(($f = readdir($res)) !== false)
317         {
318                 if(substr($f, 0, $match_len) === $match)
319                 {
320                         $str = substr($f, $match_len, strlen($f) - $match_len - strlen(XS_BACKUP_EXT));
321                         if(intval($str))
322                         {
323                                 $backups[] = intval($str);
324                         }
325                 }
326         }
327         closedir($res);
328         sort($backups);
329         for($i=0; $i<count($backups); $i++)
330         {
331                 $template->assign_block_vars('backup', array(
332                         'TIME'          => create_date($board_config['default_dateformat'], $backups[$i], $board_config['board_timezone']),
333                         'U_RESTORE'     => append_sid('xs_edit.'.$phpEx.$filter_str.'&dir='.urlencode($current_dir).'&edit='.urlencode($file).'&restore='.$backups[$i]),
334                         'U_DELETE'      => append_sid('xs_edit.'.$phpEx.$filter_str.'&dir='.urlencode($current_dir).'&edit='.urlencode($file).'&delbackup='.$backups[$i]),
335                         'U_DOWNLOAD' => append_sid('xs_edit.'.$phpEx.$filter_str.'&dir='.urlencode($current_dir).'&edit='.urlencode($file).'&downloadbackup='.$backups[$i]),
336                         'U_VIEW'        => append_sid('xs_edit.'.$phpEx.$filter_str.'&dir='.urlencode($current_dir).'&edit='.urlencode($file).'&viewbackup='.$backups[$i]),
337                         )
338                 );
339         }
341         // show template
342         $template->set_filenames(array('body' => XS_TPL_PATH . 'edit_file.tpl'));
343         $template->pparse('body');
344         xs_exit();
348 /*
349 *  show file browser
350 */
352 // show tree
353 $arr = array();
354 $template->assign_block_vars('tree', array(
355         'ITEM'  => 'phpBB',
356         'URL'   => append_sid('xs_edit.'.$phpEx.$filter_str.'&dir='),
357         'SEPARATOR'     => '',
358         ));
359 $back_dir = '';
360 for($i=0; $i<count($dirs); $i++)
362         $arr[] = $dirs[$i];
363         $str = implode('/', $arr);
364         if(count($dirs) > ($i + 1))
365         {
366                 $back_dir = $str;
367         }
368         $template->assign_block_vars('tree', array(
369                 'ITEM'  => htmlspecialchars($dirs[$i]),
370                 'URL'   => append_sid('xs_edit.'.$phpEx.$filter_str.'&dir='.urlencode($str)),
371                 'SEPARATOR'     => '/',
372                 ));
375 // get list of files/directories
376 $list_files = array();                  // non-editable files
377 $list_files_editable = array(); // editable files
378 $list_dirs = array();                   // directories
379 $res = @opendir('../' . $current_dir_full);
380 if(!$res)
382         xs_error(str_replace('{DIR}', $current_dir_full, $lang['xs_export_no_open_dir']) . '<br /><br />' . $return_url_root);
384 while(($file = readdir($res)) !== false)
386         if($file !== '.' && $file !== '..')
387         {
388                 $filename = '../' . ($current_dir_full ? $current_dir_full . '/' : '') . $file;
389                 if(is_dir($filename))
390                 {
391                         $list_dirs[] = $file;
392                 }
393                 else
394                 {
395                         $pos = strrpos($file, '.');
396                         if($pos !== false)
397                         {
398                                 $ext = strtolower(substr($file, $pos));
399                                 $ext1 = substr($ext, 1);
400                                 if((!$filter_data['ext'] && xs_in_array($ext, $editable)) || $ext1 === $filter_data['ext'])
401                                 {
402                                         // check filter
403                                         if($filter_data['data'])
404                                         {
405                                                 $content = @implode('', @file($filename));
406                                                 if(strpos($content, $filter_data['data']) !== false)
407                                                 {
408                                                         $list_files_editable[] = $file;
409                                                 }
410                                         }
411                                         else
412                                         {
413                                                 $list_files_editable[] = $file;
414                                         }
415                                 }
416                                 else
417                                 {
418                                         $list_files[] = $file;
419                                 }
420                         }
421                 }
422         }
424 closedir($res);
426 $list_dirs_count = count($list_dirs);
427 $list_files_count = count($list_files) + count($list_files_editable);
429 if($current_dir || count($list_dirs))
431         $template->assign_block_vars('begin_dirs', array(
432                 'COUNT'         => count($list_dirs),
433                 'L_COUNT'       => str_replace('{COUNT}', count($list_dirs), $lang['xs_fileman_dircount'])
434                 ));
436 else
438         $template->assign_block_vars('begin_nodirs', array());
440 if($current_dir)
442         $template->assign_block_vars('begin_dirs.dir', array(
443                 'NAME'                  => '..',
444                 'FULLNAME'              => htmlspecialchars($back_dir ? $back_dir . '/' : ''),
445                 'URL'                   => append_sid('xs_edit.'.$phpEx.$filter_str.'&dir='.urlencode($back_dir)),
446                 )
447         );
450 // show subdirectories
451 sort($list_dirs);
452 for($i=0; $i<count($list_dirs); $i++)
454         $dir = $list_dirs[$i];
455         $str = $current_dir_root . $dir;
456         $template->assign_block_vars('begin_dirs.dir', array(
457                 'NAME'                  => htmlspecialchars($dir),
458                 'FULLNAME'              => htmlspecialchars($current_dir_root . $dir),
459                 'URL'                   => append_sid('xs_edit.'.$phpEx.$filter_str.'&dir='.urlencode($str)),
460                 )
461         );
464 // show editable files
465 if(count($list_files_editable))
467         $template->assign_block_vars('begin_files', array('COUNT' => count($list_files_editable)));
469 else
471         $template->assign_block_vars('begin_nofiles', array('COUNT' => count($list_files_editable)));
473 sort($list_files_editable);
474 // get today start
475 $today = floor((time() + 3600 * $board_config['board_timezone']) / 86400) * 86400 - (3600 * $board_config['board_timezone']);
476 for($i=0; $i<count($list_files_editable); $i++)
478         $file = $list_files_editable[$i];
479         $fullfile = $current_dir_root . $file;
480         $localfile = '../' . $fullfile;
481         $row_class = $xs_row_class[$i % 2];
482         $t = @filemtime($localfile);
483         $filetime = $t ? create_date($board_config['default_dateformat'], $t, $board_config['board_timezone']) : '&nbsp;';
484         $template->assign_block_vars('begin_files.file', array(
485                 'ROW_CLASS'     => $row_class,
486                 'NAME'          => htmlspecialchars($file),
487                 'FULLNAME'      => htmlspecialchars($fullfile),
488                 'SIZE'          => @filesize($localfile),
489                 'TIME'          => $filetime,
490                 'URL'           => append_sid('xs_edit.'.$phpEx.$filter_str.'&dir='.urlencode($current_dir).'&edit='.urlencode($file))
491                 )
492         );
493         if($t < $today)
494         {
495                 $template->assign_block_vars('begin_files.file.old', array());
496         }
497         else
498         {
499                 $template->assign_block_vars('begin_files.file.today', array());
500         }
503 $template->set_filenames(array('body' => XS_TPL_PATH . 'edit.tpl'));
504 $template->pparse('body');
505 xs_exit();
507 ?>