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