3 /***************************************************************************
\r
6 * copyright : (C) 2003 - 2005 CyberAlien
\r
7 * support : http://www.phpbbstyles.com
\r
11 * file revision : 72
\r
12 * project revision : 78
\r
13 * last modified : 05 Dec 2005 13:54:54
\r
15 ***************************************************************************/
\r
17 /***************************************************************************
\r
19 * This program is free software; you can redistribute it and/or modify
\r
20 * it under the terms of the GNU General Public License as published by
\r
21 * the Free Software Foundation; either version 2 of the License, or
\r
22 * (at your option) any later version.
\r
24 ***************************************************************************/
\r
26 define('IN_PHPBB', 1);
\r
27 $phpbb_root_path = "./../";
\r
28 $no_page_header = true;
\r
29 require($phpbb_root_path . 'extension.inc');
\r
30 require('./pagestart.' . $phpEx);
\r
32 // check if mod is installed
\r
33 if(empty($template->xs_version) || $template->xs_version !== 8)
\r
35 message_die(GENERAL_ERROR, isset($lang['xs_error_not_installed']) ? $lang['xs_error_not_installed'] : 'eXtreme Styles mod is not installed. You forgot to upload includes/template.php');
\r
38 define('IN_XS', true);
\r
39 include_once('xs_include.' . $phpEx);
\r
43 $filter = isset($HTTP_GET_VARS['filter']) ? stripslashes($HTTP_GET_VARS['filter']) : (isset($HTTP_POST_VARS['filter']) ? stripslashes($HTTP_POST_VARS['filter']) : '');
\r
44 if(isset($HTTP_POST_VARS['filter_update']))
\r
46 $filter_data = array(
\r
47 'ext' => trim(stripslashes($HTTP_POST_VARS['filter_ext'])),
\r
48 'data' => trim(stripslashes($HTTP_POST_VARS['filter_data']))
\r
50 $filter = serialize($filter_data);
\r
54 $filter_data = @unserialize($filter);
\r
55 if(empty($filter_data['ext']))
\r
57 $filter_data['ext'] = '';
\r
59 if(empty($filter_data['data']))
\r
61 $filter_data['data'] = '';
\r
64 $filter_str = '?filter=' . urlencode($filter);
\r
67 $template->assign_block_vars('nav_left',array('ITEM' => '» <a href="' . append_sid('xs_edit.'.$phpEx.$filter_str) . '">' . $lang['xs_edit_templates'] . '</a>'));
\r
69 $editable = array('.htm', '.html', '.tpl', '.css', '.txt', '.cfg', '.xml', '.php', '.htaccess');
\r
71 // get current directory
\r
72 $current_dir = isset($HTTP_GET_VARS['dir']) ? stripslashes($HTTP_GET_VARS['dir']) : (isset($HTTP_POST_VARS['dir']) ? stripslashes($HTTP_POST_VARS['dir']) : 'templates');
\r
73 $current_dir = xs_fix_dir($current_dir);
\r
74 if(defined('DEMO_MODE') && substr($current_dir, 0, 9) !== 'templates')
\r
75 { // limit access to "templates" in demo mode
\r
76 $current_dir = 'templates';
\r
78 $dirs = explode('/', $current_dir);
\r
79 for($i=0; $i<count($dirs); $i++)
\r
81 if(!$dirs[$i] || $dirs[$i] === '.')
\r
86 $current_dir = implode('/', $dirs);
\r
87 $current_dir_full = $current_dir; //'templates' . ($current_dir ? '/' . $current_dir : '');
\r
88 $current_dir_root = $current_dir ? $current_dir . '/' : '';
\r
90 $return_dir = str_replace('{URL}', append_sid('xs_edit.'.$phpEx.$filter_str.'&dir='.urlencode($current_dir)), $lang['xs_edittpl_back_dir']);
\r
91 $return_url = $return_dir;
\r
92 $return_url_root = str_replace('{URL}', append_sid('xs_edit.'.$phpEx.$filter_str.'&dir='), $lang['xs_edittpl_back_dir']);
\r
95 $template->assign_vars(array(
\r
96 'FILTER_EXT' => htmlspecialchars($filter_data['ext']),
\r
97 'FILTER_DATA' => htmlspecialchars($filter_data['data']),
\r
98 'FILTER_URL' => append_sid('xs_edit.'.$phpEx),
\r
99 'FILTER_DIR' => htmlspecialchars($current_dir),
\r
100 'S_FILTER' => '<input type="hidden" name="filter" value="' . htmlspecialchars($filter) . '" />'
\r
107 if(isset($HTTP_GET_VARS['edit']) && !empty($HTTP_GET_VARS['restore']))
\r
109 $file = stripslashes($HTTP_GET_VARS['edit']);
\r
110 $file = xs_fix_dir($file);
\r
111 $fullfile = $current_dir_root . $file;
\r
112 $localfile = '../' . $fullfile;
\r
113 $hash = md5($localfile);
\r
114 $backup_name = XS_TEMP_DIR . XS_BACKUP_PREFIX . $hash . '.' . intval($HTTP_GET_VARS['restore']) . XS_BACKUP_EXT;
\r
115 if(@file_exists($backup_name))
\r
118 $HTTP_POST_VARS['edit'] = $HTTP_GET_VARS['edit'];
\r
119 $HTTP_POST_VARS['content'] = addslashes(implode('', @file($backup_name)));
\r
120 unset($HTTP_GET_VARS['edit']);
\r
121 $return_file = str_replace('{URL}', append_sid('xs_edit.'.$phpEx.$filter_str.'&dir='.urlencode($current_dir).'&edit='.urlencode($file)), $lang['xs_edittpl_back_edit']);
\r
122 $return_url = $return_file . '<br /><br />' . $return_dir;
\r
128 * save modified file
\r
130 if(isset($HTTP_POST_VARS['edit']) && !defined('DEMO_MODE'))
\r
132 $file = stripslashes($HTTP_POST_VARS['edit']);
\r
133 $content = stripslashes($HTTP_POST_VARS['content']);
\r
134 $fullfile = $current_dir_root . $file;
\r
135 $localfile = '../' . $fullfile;
\r
136 if(!empty($HTTP_POST_VARS['trim']))
\r
138 $content = trim($content);
\r
140 if(!empty($HTTP_POST_FILES['upload']['tmp_name']) && @file_exists($HTTP_POST_FILES['upload']['tmp_name']))
\r
142 $content = @implode('', @file($HTTP_POST_FILES['upload']['tmp_name']));
\r
146 'dir' => $current_dir,
\r
147 'content' => $content,
\r
148 'filter' => $filter,
\r
150 $return_file = str_replace('{URL}', append_sid('xs_edit.'.$phpEx.$filter_str.'&dir='.urlencode($current_dir).'&edit='.urlencode($file)), $lang['xs_edittpl_back_edit']);
\r
151 $return_url = $return_file . '<br /><br />' . $return_dir;
\r
152 // get ftp configuration
\r
153 $write_local = false;
\r
154 if(!get_ftp_config(append_sid('xs_edit.'.$phpEx), $params, true))
\r
158 xs_ftp_connect(append_sid('xs_edit.'.$phpEx), $params, true);
\r
159 if($ftp === XS_FTP_LOCAL)
\r
161 $write_local = true;
\r
162 $local_filename = $localfile;
\r
166 $local_filename = XS_TEMP_DIR . 'edit_' . time() . '.tmp';
\r
168 $f = @fopen($local_filename, 'wb');
\r
171 xs_error($lang['xs_error_cannot_open'] . '<br /><br />' . $return_url);
\r
173 fwrite($f, $content);
\r
177 xs_message($lang['Information'], $lang['xs_edit_file_saved'] . '<br /><br />' . $return_url);
\r
179 // generate ftp actions
\r
180 $actions = array();
\r
181 // chdir to template directory
\r
182 for($i=0; $i<count($dirs); $i++)
\r
184 $actions[] = array(
\r
185 'command' => 'chdir',
\r
189 $actions[] = array(
\r
190 'command' => 'upload',
\r
191 'local' => $local_filename,
\r
192 'remote' => $fullfile
\r
194 $ftp_log = array();
\r
196 $res = ftp_myexec($actions);
\r
198 echo "\$actions dump:\n\n";
\r
200 echo "\n\n\$ftp_log dump:\n\n";
\r
203 @unlink($local_filename);
\r
206 xs_message($lang['Information'], $lang['xs_edit_file_saved'] . '<br /><br />' . $return_url);
\r
208 xs_error($ftp_error . '<br /><br />' . $return_url);
\r
215 if(isset($HTTP_GET_VARS['edit']))
\r
217 $file = stripslashes($HTTP_GET_VARS['edit']);
\r
218 $file = xs_fix_dir($file);
\r
219 $fullfile = $current_dir_root . $file;
\r
220 $localfile = '../' . $fullfile;
\r
221 $hash = md5($localfile);
\r
222 if(!@file_exists($localfile))
\r
224 xs_error($lang['xs_edit_not_found'] . '<br /><br />' . $return_url);
\r
226 $content = @file($localfile);
\r
227 if(!is_array($content))
\r
229 xs_error($lang['xs_edit_not_found'] . '<br /><br />' . $return_url);
\r
231 $content = implode('', $content);
\r
232 if(isset($HTTP_GET_VARS['download']) && !defined('DEMO_MODE'))
\r
234 xs_download_file($file, $content);
\r
237 if(isset($HTTP_GET_VARS['downloadbackup']) && !defined('DEMO_MODE'))
\r
239 $backup_name = XS_TEMP_DIR . XS_BACKUP_PREFIX . $hash . '.' . intval($HTTP_GET_VARS['downloadbackup']) . XS_BACKUP_EXT;
\r
240 xs_download_file($file, implode('', @file($backup_name)));
\r
243 $return_file = str_replace('{URL}', append_sid('xs_edit.'.$phpEx.$filter_str.'&dir='.urlencode($current_dir).'&edit='.urlencode($file)), $lang['xs_edittpl_back_edit']);
\r
244 $return_url = $return_file . '<br /><br />' . $return_dir;
\r
245 $template->assign_vars(array(
\r
246 'U_ACTION' => append_sid('xs_edit.'.$phpEx),
\r
247 'U_BROWSE' => append_sid('xs_edit.'.$phpEx.$filter_str.'&dir='.urlencode($current_dir)),
\r
248 'U_EDIT' => append_sid('xs_edit.'.$phpEx.$filter_str.'&dir='.urlencode($current_dir).'&edit='.urlencode($file)),
\r
249 'U_BACKUP' => append_sid('xs_edit.'.$phpEx.$filter_str.'&dobackup=1&dir='.urlencode($current_dir).'&edit='.urlencode($file)),
\r
250 'U_DOWNLOAD' => append_sid('xs_edit.'.$phpEx.$filter_str.'&download=1&dir='.urlencode($current_dir).'&edit='.urlencode($file)),
\r
251 'CURRENT_DIR' => htmlspecialchars($current_dir_full),
\r
252 'DIR' => htmlspecialchars($current_dir),
\r
253 'FILE' => htmlspecialchars($file),
\r
254 'FULLFILE' => htmlspecialchars($fullfile),
\r
255 'CONTENT' => defined('DEMO_MODE') ? $lang['xs_error_demo_edit'] : htmlspecialchars($content),
\r
258 if($current_dir_full)
\r
260 $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>'));
\r
265 $template->assign_block_vars('tree', array(
\r
267 'URL' => append_sid('xs_edit.'.$phpEx.$filter_str.'&dir='),
\r
271 for($i=0; $i<count($dirs); $i++)
\r
273 $arr[] = $dirs[$i];
\r
274 $str = implode('/', $arr);
\r
275 if(count($dirs) > ($i + 1))
\r
279 $template->assign_block_vars('tree', array(
\r
280 'ITEM' => htmlspecialchars($dirs[$i]),
\r
281 'URL' => append_sid('xs_edit.'.$phpEx.$filter_str.'&dir='.urlencode($str)),
\r
282 'SEPARATOR' => '/',
\r
287 if(!empty($HTTP_GET_VARS['viewbackup']) && !defined('DEMO_MODE'))
\r
289 $backup_name = XS_TEMP_DIR . XS_BACKUP_PREFIX . $hash . '.' . intval($HTTP_GET_VARS['viewbackup']) . XS_BACKUP_EXT;
\r
290 $template->assign_vars(array(
\r
291 'CONTENT' => implode('', @file($backup_name))
\r
297 if(isset($HTTP_GET_VARS['dobackup']) && !defined('DEMO_MODE'))
\r
299 $backup_name = XS_TEMP_DIR . XS_BACKUP_PREFIX . $hash . '.' . time() . XS_BACKUP_EXT;
\r
300 $f = @fopen($backup_name, 'wb');
\r
303 xs_error(str_replace('{FILE}', $backup_name, $lang['xs_error_cannot_create_tmp']) . '<br /><br />' . $return_url);
\r
305 fwrite($f, $content);
\r
307 @chmod($backup_name, 0777);
\r
311 if(isset($HTTP_GET_VARS['delbackup']) && !defined('DEMO_MODE'))
\r
313 $backup_name = XS_TEMP_DIR . XS_BACKUP_PREFIX . $hash . '.' . intval($HTTP_GET_VARS['delbackup']) . XS_BACKUP_EXT;
\r
314 @unlink($backup_name);
\r
318 $backups = array();
\r
319 $res = opendir(XS_TEMP_DIR);
\r
320 $match = XS_BACKUP_PREFIX . $hash . '.';
\r
321 $match_len = strlen($match);
\r
322 while(($f = readdir($res)) !== false)
\r
324 if(substr($f, 0, $match_len) === $match)
\r
326 $str = substr($f, $match_len, strlen($f) - $match_len - strlen(XS_BACKUP_EXT));
\r
329 $backups[] = intval($str);
\r
335 for($i=0; $i<count($backups); $i++)
\r
337 $template->assign_block_vars('backup', array(
\r
338 'TIME' => create_date($board_config['default_dateformat'], $backups[$i], $board_config['board_timezone']),
\r
339 'U_RESTORE' => append_sid('xs_edit.'.$phpEx.$filter_str.'&dir='.urlencode($current_dir).'&edit='.urlencode($file).'&restore='.$backups[$i]),
\r
340 'U_DELETE' => append_sid('xs_edit.'.$phpEx.$filter_str.'&dir='.urlencode($current_dir).'&edit='.urlencode($file).'&delbackup='.$backups[$i]),
\r
341 'U_DOWNLOAD' => append_sid('xs_edit.'.$phpEx.$filter_str.'&dir='.urlencode($current_dir).'&edit='.urlencode($file).'&downloadbackup='.$backups[$i]),
\r
342 'U_VIEW' => append_sid('xs_edit.'.$phpEx.$filter_str.'&dir='.urlencode($current_dir).'&edit='.urlencode($file).'&viewbackup='.$backups[$i]),
\r
348 $template->set_filenames(array('body' => XS_TPL_PATH . 'edit_file.tpl'));
\r
349 $template->pparse('body');
\r
355 * show file browser
\r
360 $template->assign_block_vars('tree', array(
\r
362 'URL' => append_sid('xs_edit.'.$phpEx.$filter_str.'&dir='),
\r
366 for($i=0; $i<count($dirs); $i++)
\r
368 $arr[] = $dirs[$i];
\r
369 $str = implode('/', $arr);
\r
370 if(count($dirs) > ($i + 1))
\r
374 $template->assign_block_vars('tree', array(
\r
375 'ITEM' => htmlspecialchars($dirs[$i]),
\r
376 'URL' => append_sid('xs_edit.'.$phpEx.$filter_str.'&dir='.urlencode($str)),
\r
377 'SEPARATOR' => '/',
\r
381 // get list of files/directories
\r
382 $list_files = array(); // non-editable files
\r
383 $list_files_editable = array(); // editable files
\r
384 $list_dirs = array(); // directories
\r
385 $res = @opendir('../' . $current_dir_full);
\r
388 xs_error(str_replace('{DIR}', $current_dir_full, $lang['xs_export_no_open_dir']) . '<br /><br />' . $return_url_root);
\r
390 while(($file = readdir($res)) !== false)
\r
392 if($file !== '.' && $file !== '..')
\r
394 $filename = '../' . ($current_dir_full ? $current_dir_full . '/' : '') . $file;
\r
395 if(is_dir($filename))
\r
397 $list_dirs[] = $file;
\r
401 $pos = strrpos($file, '.');
\r
404 $ext = strtolower(substr($file, $pos));
\r
405 $ext1 = substr($ext, 1);
\r
406 if((!$filter_data['ext'] && xs_in_array($ext, $editable)) || $ext1 === $filter_data['ext'])
\r
409 if($filter_data['data'])
\r
411 $content = @implode('', @file($filename));
\r
412 if(strpos($content, $filter_data['data']) !== false)
\r
414 $list_files_editable[] = $file;
\r
419 $list_files_editable[] = $file;
\r
424 $list_files[] = $file;
\r
432 $list_dirs_count = count($list_dirs);
\r
433 $list_files_count = count($list_files) + count($list_files_editable);
\r
435 if($current_dir || count($list_dirs))
\r
437 $template->assign_block_vars('begin_dirs', array(
\r
438 'COUNT' => count($list_dirs),
\r
439 'L_COUNT' => str_replace('{COUNT}', count($list_dirs), $lang['xs_fileman_dircount'])
\r
444 $template->assign_block_vars('begin_nodirs', array());
\r
448 $template->assign_block_vars('begin_dirs.dir', array(
\r
450 'FULLNAME' => htmlspecialchars($back_dir ? $back_dir . '/' : ''),
\r
451 'URL' => append_sid('xs_edit.'.$phpEx.$filter_str.'&dir='.urlencode($back_dir)),
\r
456 // show subdirectories
\r
458 for($i=0; $i<count($list_dirs); $i++)
\r
460 $dir = $list_dirs[$i];
\r
461 $str = $current_dir_root . $dir;
\r
462 $template->assign_block_vars('begin_dirs.dir', array(
\r
463 'NAME' => htmlspecialchars($dir),
\r
464 'FULLNAME' => htmlspecialchars($current_dir_root . $dir),
\r
465 'URL' => append_sid('xs_edit.'.$phpEx.$filter_str.'&dir='.urlencode($str)),
\r
470 // show editable files
\r
471 if(count($list_files_editable))
\r
473 $template->assign_block_vars('begin_files', array('COUNT' => count($list_files_editable)));
\r
477 $template->assign_block_vars('begin_nofiles', array('COUNT' => count($list_files_editable)));
\r
479 sort($list_files_editable);
\r
481 $today = floor((time() + 3600 * $board_config['board_timezone']) / 86400) * 86400 - (3600 * $board_config['board_timezone']);
\r
482 for($i=0; $i<count($list_files_editable); $i++)
\r
484 $file = $list_files_editable[$i];
\r
485 $fullfile = $current_dir_root . $file;
\r
486 $localfile = '../' . $fullfile;
\r
487 $row_class = $xs_row_class[$i % 2];
\r
488 $t = @filemtime($localfile);
\r
489 $filetime = $t ? create_date($board_config['default_dateformat'], $t, $board_config['board_timezone']) : ' ';
\r
490 $template->assign_block_vars('begin_files.file', array(
\r
491 'ROW_CLASS' => $row_class,
\r
492 'NAME' => htmlspecialchars($file),
\r
493 'FULLNAME' => htmlspecialchars($fullfile),
\r
494 'SIZE' => @filesize($localfile),
\r
495 'TIME' => $filetime,
\r
496 'URL' => append_sid('xs_edit.'.$phpEx.$filter_str.'&dir='.urlencode($current_dir).'&edit='.urlencode($file))
\r
501 $template->assign_block_vars('begin_files.file.old', array());
\r
505 $template->assign_block_vars('begin_files.file.today', array());
\r
509 $template->set_filenames(array('body' => XS_TPL_PATH . 'edit.tpl'));
\r
510 $template->pparse('body');
\r