3 /***************************************************************************
6 * copyright : (C) 2003, 2004 CyberAlien
7 * support : http://www.phpbbstyles.com
12 * project revision : 51
13 * last modified : 25 Aug 2004 11:51:47
15 ***************************************************************************/
17 /***************************************************************************
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.
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)
35 message_die(GENERAL_ERROR, 'eXtreme Styles mod is not installed. You forgot to upload includes/template.php');
38 define('IN_XS', true);
39 include_once('xs_include.' . $phpEx);
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']))
47 'ext' => trim(stripslashes($HTTP_POST_VARS['filter_ext'])),
48 'data' => trim(stripslashes($HTTP_POST_VARS['filter_data']))
50 $filter = serialize($filter_data);
54 $filter_data = @unserialize($filter);
55 if(empty($filter_data['ext']))
57 $filter_data['ext'] = '';
59 if(empty($filter_data['data']))
61 $filter_data['data'] = '';
64 $filter_str = '?filter=' . urlencode($filter);
67 $template->assign_block_vars('nav_left',array('ITEM' => '» <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';
78 $dirs = explode('/', $current_dir);
79 for($i=0; $i<count($dirs); $i++)
81 if(!$dirs[$i] || $dirs[$i] === '.')
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) . '" />'
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))
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;
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']))
137 $content = trim($content);
139 if(!empty($HTTP_POST_FILES['upload']['tmp_name']) && @file_exists($HTTP_POST_FILES['upload']['tmp_name']))
141 $content = @implode('', @file($HTTP_POST_FILES['upload']['tmp_name']));
145 'dir' => $current_dir,
146 'content' => $content,
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))
157 xs_ftp_connect(append_sid('xs_edit.'.$phpEx), $params, true);
158 if($ftp === XS_FTP_LOCAL)
161 $local_filename = $localfile;
165 $local_filename = XS_TEMP_DIR . 'edit_' . time() . '.tmp';
167 $f = @fopen($local_filename, 'wb');
170 xs_error($lang['xs_error_cannot_open'] . '<br /><br />' . $return_url);
172 fwrite($f, $content);
176 xs_message($lang['Information'], $lang['xs_edit_file_saved'] . '<br /><br />' . $return_url);
178 // generate ftp actions
180 // chdir to template directory
181 for($i=0; $i<count($dirs); $i++)
184 'command' => 'chdir',
189 'command' => 'upload',
190 'local' => $local_filename,
191 'remote' => $fullfile
195 $res = ftp_myexec($actions);
197 echo "\$actions dump:\n\n";
199 echo "\n\n\$ftp_log dump:\n\n";
202 @unlink($local_filename);
205 xs_message($lang['Information'], $lang['xs_edit_file_saved'] . '<br /><br />' . $return_url);
207 xs_error($ftp_error . '<br /><br />' . $return_url);
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))
222 xs_error($lang['xs_edit_not_found'] . '<br /><br />' . $return_url);
224 if(isset($HTTP_GET_VARS['download']) && !defined('DEMO_MODE'))
226 $content = implode('', @file($localfile));
227 xs_download_file($file, $content);
230 if(isset($HTTP_GET_VARS['downloadbackup']) && !defined('DEMO_MODE'))
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)));
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))),
251 if($current_dir_full)
253 $template->assign_block_vars('nav_left',array('ITEM' => '» <a href="' . append_sid('xs_edit.'.$phpEx.$filter_str.'&dir='.$current_dir) . '">' . htmlspecialchars($current_dir_full) . '</a>'));
258 $template->assign_block_vars('tree', array(
260 'URL' => append_sid('xs_edit.'.$phpEx.$filter_str.'&dir='),
264 for($i=0; $i<count($dirs); $i++)
267 $str = implode('/', $arr);
268 if(count($dirs) > ($i + 1))
272 $template->assign_block_vars('tree', array(
273 'ITEM' => htmlspecialchars($dirs[$i]),
274 'URL' => append_sid('xs_edit.'.$phpEx.$filter_str.'&dir='.urlencode($str)),
280 if(!empty($HTTP_GET_VARS['viewbackup']) && !defined('DEMO_MODE'))
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))
290 if(isset($HTTP_GET_VARS['dobackup']) && !defined('DEMO_MODE'))
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');
297 xs_error(str_replace('{FILE}', $backup_name, $lang['xs_error_cannot_create_tmp']) . '<br /><br />' . $return_url);
301 @chmod($backup_name, 0777);
305 if(isset($HTTP_GET_VARS['delbackup']) && !defined('DEMO_MODE'))
307 $backup_name = XS_TEMP_DIR . XS_BACKUP_PREFIX . $hash . '.' . intval($HTTP_GET_VARS['delbackup']) . XS_BACKUP_EXT;
308 @unlink($backup_name);
313 $res = opendir(XS_TEMP_DIR);
314 $match = XS_BACKUP_PREFIX . $hash . '.';
315 $match_len = strlen($match);
316 while(($f = readdir($res)) !== false)
318 if(substr($f, 0, $match_len) === $match)
320 $str = substr($f, $match_len, strlen($f) - $match_len - strlen(XS_BACKUP_EXT));
323 $backups[] = intval($str);
329 for($i=0; $i<count($backups); $i++)
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]),
342 $template->set_filenames(array('body' => XS_TPL_PATH . 'edit_file.tpl'));
343 $template->pparse('body');
354 $template->assign_block_vars('tree', array(
356 'URL' => append_sid('xs_edit.'.$phpEx.$filter_str.'&dir='),
360 for($i=0; $i<count($dirs); $i++)
363 $str = implode('/', $arr);
364 if(count($dirs) > ($i + 1))
368 $template->assign_block_vars('tree', array(
369 'ITEM' => htmlspecialchars($dirs[$i]),
370 'URL' => append_sid('xs_edit.'.$phpEx.$filter_str.'&dir='.urlencode($str)),
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);
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 !== '..')
388 $filename = '../' . ($current_dir_full ? $current_dir_full . '/' : '') . $file;
389 if(is_dir($filename))
391 $list_dirs[] = $file;
395 $pos = strrpos($file, '.');
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'])
403 if($filter_data['data'])
405 $content = @implode('', @file($filename));
406 if(strpos($content, $filter_data['data']) !== false)
408 $list_files_editable[] = $file;
413 $list_files_editable[] = $file;
418 $list_files[] = $file;
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'])
438 $template->assign_block_vars('begin_nodirs', array());
442 $template->assign_block_vars('begin_dirs.dir', array(
444 'FULLNAME' => htmlspecialchars($back_dir ? $back_dir . '/' : ''),
445 'URL' => append_sid('xs_edit.'.$phpEx.$filter_str.'&dir='.urlencode($back_dir)),
450 // show subdirectories
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)),
464 // show editable files
465 if(count($list_files_editable))
467 $template->assign_block_vars('begin_files', array('COUNT' => count($list_files_editable)));
471 $template->assign_block_vars('begin_nofiles', array('COUNT' => count($list_files_editable)));
473 sort($list_files_editable);
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']) : ' ';
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),
490 'URL' => append_sid('xs_edit.'.$phpEx.$filter_str.'&dir='.urlencode($current_dir).'&edit='.urlencode($file))
495 $template->assign_block_vars('begin_files.file.old', array());
499 $template->assign_block_vars('begin_files.file.today', array());
503 $template->set_filenames(array('body' => XS_TPL_PATH . 'edit.tpl'));
504 $template->pparse('body');