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:48
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);
41 $template->assign_block_vars('nav_left',array('ITEM' => '» <a href="' . append_sid('xs_import.'.$phpEx) . '">' . $lang['xs_import_styles'] . '</a>'));
43 $lang['xs_import_back'] = str_replace('{URL}', append_sid('xs_import.'.$phpEx), $lang['xs_import_back']);
45 $return_url = isset($HTTP_POST_VARS['return']) ? stripslashes($HTTP_POST_VARS['return']) : (isset($HTTP_GET_VARS['return']) ? stripslashes($HTTP_GET_VARS['return']) : '');
46 $return = $return_url ? '&return=' . urlencode($return_url) : '';
49 $lang['xs_import_back'] = str_replace('{URL}', $return_url, $lang['xs_import_back_download']);
50 $HTTP_POST_VARS['return'] = $HTTP_GET_VARS['return'] = addslashes($return_url);
54 // Check required functions
56 if(!@function_exists('gzcompress'))
58 xs_error($lang['xs_import_nogzip']);
61 $tpl_filename = $template->make_filename('_xs_test.tpl');
62 $cache_filename = $template->make_filename_cache($tpl_filename);
64 if(!xs_check_cache($cache_filename))
66 xs_error(str_replace(array('{URL1}', '{URL2}'), array(append_sid('xs_chmod.'.$phpEx), append_sid('xs_import.'.$phpEx)), $lang['xs_import_nowrite_cache']));
70 // include all functions
72 include_once('xs_include_import.'.$phpEx);
75 @set_time_limit(XS_MAX_TIMEOUT);
78 // check if need to download style
80 if(!empty($HTTP_GET_VARS['get_remote']))
82 $HTTP_POST_VARS['action'] = 'web';
83 $HTTP_POST_VARS['source'] = $HTTP_GET_VARS['get_remote'];
89 if(isset($HTTP_GET_VARS['del']) && !defined('DEMO_MODE'))
91 $str = xs_tpl_name($HTTP_GET_VARS['del']);
92 @unlink(XS_TEMP_DIR.$str);
98 if(isset($HTTP_GET_VARS['import']) || isset($HTTP_POST_VARS['import']))
100 $list_only = isset($HTTP_GET_VARS['list']) ? true : false;
101 $get_file = isset($HTTP_GET_VARS['get_file']) ? stripslashes($HTTP_GET_VARS['get_file']) : '';
102 $filename = isset($HTTP_POST_VARS['import']) ? $HTTP_POST_VARS['import'] : $HTTP_GET_VARS['import'];
103 $filename = xs_tpl_name($filename);
104 $write_local = false;
107 if(defined('DEMO_MODE'))
109 xs_error($lang['xs_permission_denied'] . '<br /><br />' . $lang['xs_import_back']);
111 $params = array('import' => $filename);
112 $total = intval($HTTP_POST_VARS['total']);
113 $params['total'] = $total;
114 for($i=0; $i<$total; $i++)
116 $install = empty($HTTP_POST_VARS['import_install_'.$i]) ? 0 : 1;
117 $default = $install ? (empty($HTTP_POST_VARS['import_default_'.$i]) ? 0 : 1) : 0;
118 $params['import_install_'.$i] = $install;
119 $params['import_default_'.$i] = $default;
123 $params['return'] = $return_url;
125 if(!get_ftp_config(append_sid('xs_import.'.$phpEx), $params, true))
129 xs_ftp_connect(append_sid('xs_import.'.$phpEx), $params, true);
130 if($ftp === XS_FTP_LOCAL)
133 $write_local_dir = '../templates/';
136 include('xs_include_import2.' . $phpEx);
142 if(isset($HTTP_GET_VARS['get_web']))
144 $HTTP_POST_VARS['action'] = 'web';
145 $HTTP_POST_VARS['source'] = $HTTP_GET_VARS['get_web'];
147 if(isset($HTTP_POST_VARS['action']) && $HTTP_POST_VARS['action'] === 'web' && !defined('DEMO_MODE'))
149 $src = stripslashes($HTTP_POST_VARS['source']);
150 $dst = generate_style_name('web');
151 $str = @implode('', @file($src));
154 xs_error(str_replace('{URL}', $src, $lang['xs_import_nodownload']) . '<br /><br />' . $lang['xs_import_back']);
156 $header = xs_get_style_header('', substr($str, 0, 10240));
157 if($header === false)
159 xs_error($lang['xs_style_header_error_reason'] . $xs_header_error . '<br /><br />' . $lang['xs_import_back']);
161 if($header['filesize'] != strlen($str))
163 xs_error($lang['xs_style_header_error_incomplete2'] . '<br /><br />' . $lang['xs_import_back']);
165 $f = @fopen(XS_TEMP_DIR . $dst, 'wb');
168 xs_error(str_replace('{FILE}', $dst, $lang['xs_error_cannot_create_tmp']) . '<br /><br />' . $lang['xs_import_back']);
172 xs_message($lang['Information'], str_replace('{URL}', append_sid('xs_import.'.$phpEx.'?importstyle=' . urlencode($dst) . $return), $lang['xs_import_uploaded2']) . '<br /><br />' . $lang['xs_import_back']);
178 if(isset($HTTP_POST_VARS['action']) && $HTTP_POST_VARS['action'] === 'copy' && !defined('DEMO_MODE'))
180 $src = stripslashes($HTTP_POST_VARS['source']);
181 $dst = generate_style_name('copy');
182 $str = @implode('', @file($src));
185 xs_error(str_replace('{URL}', $src, $lang['xs_import_nodownload2']) . '<br /><br />' . $lang['xs_import_back']);
187 if(substr($str, 0, strlen(STYLE_HEADER_START)) !== STYLE_HEADER_START)
189 xs_error($lang['xs_style_header_error_invalid2'] . '<br /><br />' . $lang['xs_import_back']);
191 $header = xs_get_style_header('', substr($str, 0, 10240));
192 if($header === false)
194 xs_error($lang['xs_style_header_error_reason'] . $xs_header_error . '<br /><br />' . $lang['xs_import_back']);
196 if($header['filesize'] != strlen($str))
198 xs_error($lang['xs_style_header_error_incomplete2'] . '<br /><br />' . $lang['xs_import_back']);
200 $f = @fopen(XS_TEMP_DIR . $dst, 'wb');
203 xs_error(str_replace('{FILE}', $dst, $lang['xs_error_cannot_create_tmp']) . $lang['xs_import_back']);
207 xs_message($lang['Information'], str_replace('{URL}', append_sid('xs_import.'.$phpEx.'?importstyle=' . urlencode($dst)), $lang['xs_import_uploaded3']) . '<br /><br />' . $lang['xs_import_back']);
214 if(isset($HTTP_POST_VARS['action']) && $HTTP_POST_VARS['action'] === 'upload' && !defined('DEMO_MODE'))
216 if(empty($HTTP_POST_FILES['source']['tmp_name']) || !@file_exists($HTTP_POST_FILES['source']['tmp_name']))
218 xs_error($lang['xs_import_nodownload3'] . '<br /><br />' . $lang['xs_import_back']);
220 $src = $HTTP_POST_FILES['source']['tmp_name'];
221 $dst = generate_style_name('upload');
222 $str = @implode('', @file($src));
225 xs_error(str_replace('{URL}', $src, $lang['xs_import_nodownload2']) . '<br /><br />' . $lang['xs_import_back']);
227 if(substr($str, 0, strlen(STYLE_HEADER_START)) !== STYLE_HEADER_START)
229 xs_error($lang['xs_style_header_error_invalid2'] . '<br /><br />' . $lang['xs_import_back']);
231 $header = xs_get_style_header('', substr($str, 0, 10240));
232 if($header === false)
234 xs_error($lang['xs_style_header_error_reason'] . $xs_header_error . '<br /><br />' . $lang['xs_import_back']);
236 if($header['filesize'] != strlen($str))
238 xs_error($lang['xs_style_header_error_incomplete2'] . '<br /><br />' . $lang['xs_import_back']);
240 $f = @fopen(XS_TEMP_DIR . $dst, 'wb');
243 xs_error(str_replace('{FILE}', $dst, $lang['xs_error_cannot_create_tmp']) . '<br /><br />' . $lang['xs_import_back']);
247 xs_error(str_replace('{URL}', append_sid('xs_import.'.$phpEx.'?importstyle=' . urlencode($dst)), $lang['xs_import_uploaded4']) . '<br /><br />' . $lang['xs_import_back']);
254 if(!empty($HTTP_GET_VARS['importstyle']))
256 $file = xs_tpl_name($HTTP_GET_VARS['importstyle']);
257 $header = xs_get_style_header(XS_TEMP_DIR.$file);
258 if($header === false)
260 xs_error($lang['xs_style_header_error_reason'] . $xs_header_error . '<br /><br />' . $lang['xs_import_back']);
262 if(@filesize(XS_TEMP_DIR.$file) != $header['filesize'])
264 xs_error($lang['xs_style_header_error_incomplete2'] . '<br /><br />' . $lang['xs_import_back']);
266 $template->set_filenames(array('import' => XS_TPL_PATH . 'import2.tpl'));
267 $template->assign_vars(array(
268 'FORM_ACTION' => append_sid('xs_import.'.$phpEx),
269 'S_RETURN' => $return_url ? '<input type="hidden" name="return" value="' . htmlspecialchars($return_url) . '" />' : '',
270 'IMPORT_FILENAME' => htmlspecialchars($file),
271 'STYLE_TEMPLATE' => htmlspecialchars($header['template']),
272 'STYLE_FILENAME' => htmlspecialchars($file),
273 'STYLE_COMMENT' => htmlspecialchars($header['comment']),
274 'DATE' => create_date($board_config['default_dateformat'], $header['date'], $board_config['board_timezone']),
275 'STYLE_SIZE' => $header['filesize'],
276 'STYLE_NAME' => htmlspecialchars($header['styles'][0]),
277 'TOTAL' => count($header['styles']),
278 'L_XS_IMPORT_TPL' => str_replace('{TPL}', htmlspecialchars($header['template']), $lang['xs_import_tpl'])
280 if(count($header['styles']) > 1)
282 $template->assign_block_vars('switch_select_style', array());
283 for($i=0; $i<count($header['styles']); $i++)
285 $template->assign_block_vars('switch_select_style.style', array(
287 'NAME' => htmlspecialchars($header['styles'][$i]),
293 $template->assign_block_vars('switch_select_nostyle', array());
295 $template->pparse('import');
300 $template->set_filenames(array('body' => XS_TPL_PATH . 'import.tpl'));
302 // Get list of available styles
304 $dir = @opendir(XS_TEMP_DIR);
308 while(($file = readdir($dir)) !== false)
310 if(substr($file, strlen($file) - strlen(STYLE_EXTENSION)) === STYLE_EXTENSION)
312 $items = xs_get_style_header(XS_TEMP_DIR.$file);
315 $items['file'] = $file;
316 $items['file2'] = substr($file, 0, strlen($file) - strlen(STYLE_EXTENSION));
317 if(@filesize(XS_TEMP_DIR.$file) != $items['filesize'])
319 $items['error'] = $lang['xs_import_incomplete_file'];
326 'filename' => XS_TEMP_DIR.$file,
327 'filesize' => @filesize(XS_TEMP_DIR.$file),
328 'date' => filemtime(XS_TEMP_DIR.$file),
330 'file2' => substr($file, 0, strlen($file) - strlen(STYLE_EXTENSION)),
331 'error' => $lang['xs_import_invalid_file'],
333 'styles' => array('-'),
347 for($i=0; $i<count($files); $i++)
350 $row_class = $xs_row_class[$i % 2];
351 $template->assign_block_vars('styles', array(
352 'ROW_CLASS' => $row_class,
353 'FILE' => htmlspecialchars($item['file']),
354 'FILE2' => htmlspecialchars($item['file2']),
355 'FILENAME' => htmlspecialchars($item['filename']),
356 'TEMPLATE' => htmlspecialchars($item['template']),
357 'DATE' => create_date($board_config['default_dateformat'], $item['date'], $board_config['board_timezone']),
358 'COMMENT' => htmlspecialchars($item['comment']),
359 'U_DELETE' => append_sid('xs_import.' . $phpEx . '?del=' . urlencode($item['file'])),
360 'U_IMPORT' => append_sid('xs_import.' . $phpEx . '?importstyle=' . urlencode($item['file'])),
361 'U_DOWNLOAD' => append_sid('xs_download.' . $phpEx),
362 'U_LIST' => append_sid('xs_import.' . $phpEx . '?list=1&import=' . urlencode($item['file'])),
364 if(empty($item['error']))
366 for($j=0; $j<count($item['styles']); $j++)
368 $template->assign_block_vars('styles.list', array(
369 'STYLE' => $item['styles'][$j]
372 $template->assign_block_vars('styles.valid', array());
376 $template->assign_block_vars('styles.error', array('ERROR' => htmlspecialchars($item['error'])));
382 $template->assign_block_vars('nostyles', array());
384 $template->assign_vars(array(
385 'U_SCRIPT' => append_sid('xs_import.'.$phpEx),
388 $template->pparse('body');