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);
41 $template->assign_block_vars('nav_left',array('ITEM' => '» <a href="' . append_sid('xs_export.'.$phpEx) . '">' . $lang['xs_export_styles'] . '</a>'));
43 $lang['xs_export_back'] = str_replace('{URL}', append_sid('xs_export.'.$phpEx), $lang['xs_export_back']);
46 // Check required functions
48 if(!@function_exists('gzcompress'))
50 xs_error($lang['xs_import_nogzip']);
57 $export = isset($HTTP_GET_VARS['export']) ? $HTTP_GET_VARS['export'] : '';
58 $export = xs_tpl_name($export);
59 if(!empty($export) && @file_exists($phpbb_root_path . $template_dir . $export . '/theme_info.cfg'))
62 $sql = "SELECT themes_id, style_name FROM " . THEMES_TABLE . " WHERE template_name = '$export' ORDER BY style_name ASC";
63 if(!$result = $db->sql_query($sql))
65 xs_error($lang['xs_no_theme_data'] . '<br /><br />' . $lang['xs_export_back']);
67 $theme_rowset = $db->sql_fetchrowset($result);
68 if(count($theme_rowset) == 0)
70 xs_error($lang['xs_no_themes'] . '<br /><br />' . $lang['xs_export_back']);
72 $template->set_filenames(array('body' => XS_TPL_PATH . 'export2.tpl'));
73 $xs_send_method = isset($board_config['xs_export_data']) ? $board_config['xs_export_data'] : '';
74 $xs_send = @unserialize($xs_send_method);
75 $xs_send_method = $xs_send['method'] == 'ftp' ? 'ftp' : ($xs_send['method'] == 'file' ? 'file' : 'save');
76 $template->assign_vars(array(
77 'FORM_ACTION' => append_sid('xs_export.'.$phpEx),
78 'EXPORT_TEMPLATE' => htmlspecialchars($export),
79 'STYLE_ID' => $theme_rowset[0]['themes_id'],
80 'STYLE_NAME' => htmlspecialchars($theme_rowset[0]['style_name']),
81 'TOTAL' => count($theme_rowset),
82 'SEND_METHOD_'.strtoupper($xs_send_method) => ' checked="checked"',
83 'SEND_DATA_DIR' => isset($xs_send['dir']) ? htmlspecialchars($xs_send['dir']) : '',
84 'SEND_DATA_HOST' => isset($xs_send['host']) ? htmlspecialchars($xs_send['host']) : '',
85 'SEND_DATA_LOGIN' => isset($xs_send['login']) ? htmlspecialchars($xs_send['login']) : '',
86 'SEND_DATA_FTPDIR' => isset($xs_send['ftpdir']) ? htmlspecialchars($xs_send['ftpdir']) : '',
87 'L_TITLE' => str_replace('{TPL}', $export, $lang['xs_export_style_title']),
89 if(count($theme_rowset) == 1)
91 $template->assign_block_vars('switch_select_nostyle', array());
95 $template->assign_block_vars('switch_select_style', array());
96 for($i=0; $i<count($theme_rowset); $i++)
98 $template->assign_block_vars('switch_select_style.style', array(
100 'ID' => $theme_rowset[$i]['themes_id'],
101 'NAME' => htmlspecialchars($theme_rowset[$i]['style_name'])
105 $template->pparse('body');
112 $export = isset($HTTP_POST_VARS['export']) ? $HTTP_POST_VARS['export'] : '';
113 $export = xs_tpl_name($export);
114 if(!empty($export) && @file_exists($phpbb_root_path . $template_dir . $export . '/theme_info.cfg') && !defined('DEMO_MODE'))
116 $total = intval($HTTP_POST_VARS['total']);
117 $comment = substr(stripslashes($HTTP_POST_VARS['export_comment']), 0, 255);
119 for($i=0; $i<$total; $i++)
121 if(!empty($HTTP_POST_VARS['export_style_'.$i]))
123 $list[] = intval($HTTP_POST_VARS['export_style_id_'.$i]);
128 xs_error($lang['xs_export_noselect_themes'] . '<br /><br /> ' . $lang['xs_export_back']);
131 $exportas = empty($HTTP_POST_VARS['export_template']) ? $export : $HTTP_POST_VARS['export_template'];
132 $exportas = xs_tpl_name($exportas);
133 // Generate theme_info.cfg
134 $sql = "SELECT * FROM " . THEMES_TABLE . " WHERE template_name = '$export' AND themes_id IN (" . implode(', ', $list) . ")";
135 if(!$result = $db->sql_query($sql))
137 xs_error($lang['xs_no_theme_data'] . $lang['xs_export_back']);
139 $theme_rowset = $db->sql_fetchrowset($result);
140 if(count($theme_rowset) == 0)
142 xs_error($lang['xs_no_themes'] . '<br /><br />' . $lang['xs_export_back']);
144 $theme_data = xs_generate_themeinfo($theme_rowset, $export, $exportas, $total);
148 $pack_list = array();
149 $pack_replace = array('./theme_info.cfg' => $theme_data);
152 for($i=0; $i<count($theme_rowset); $i++)
154 $id = $theme_rowset[$i]['themes_id'];
155 $theme_name = $theme_rowset[$i]['style_name'];
156 for($j=0; $j<$total; $j++)
158 if(!empty($HTTP_POST_VARS['export_style_name_'.$j]) && $HTTP_POST_VARS['export_style_id_'.$j] == $id)
160 $theme_name = stripslashes($HTTP_POST_VARS['export_style_name_'.$j]);
163 $theme_rowset[$i]['style_name'] = $theme_name;
165 $data = pack_style($export, $exportas, $theme_rowset, $comment);
170 xs_error(str_replace('{TPL}', $export, $lang['xs_export_error']) . $pack_error . '<br /><br />' . $lang['xs_export_back']);
174 xs_error(str_replace('{TPL}', $export, $lang['xs_export_error2']) . '<br /><br />' . $lang['xs_export_back']);
178 // Got file. Sending it.
180 $send_method = isset($HTTP_POST_VARS['export_to']) ? $HTTP_POST_VARS['export_to'] : '';
181 $export_filename = empty($HTTP_POST_VARS['export_filename']) ? $exportas . STYLE_EXTENSION : $HTTP_POST_VARS['export_filename'];
182 if($send_method === 'file')
184 // store on local server
185 $send_dir = isset($HTTP_POST_VARS['export_to_dir']) ? $HTTP_POST_VARS['export_to_dir'] : '';
186 $send_dir = str_replace('\\', '/', stripslashes($send_dir));
189 $send_dir = XS_TEMP_DIR;
191 if(substr($send_dir, strlen($send_dir) - 1) !== '/')
195 $filename = $send_dir . $export_filename;
196 $f = @fopen($filename, 'wb');
199 xs_error(str_replace('{FILE}', $filename, $lang['xs_error_cannot_create_file']) . '<br /><br />' . $lang['xs_export_back']);
203 set_export_method('file', array('dir' => $send_dir));
204 xs_message($lang['Information'], str_replace('{FILE}', $filename, $lang['xs_export_saved']) . '<br /><br />' . $lang['xs_export_back']);
206 elseif($send_method === 'ftp')
209 $ftp_host = $HTTP_POST_VARS['export_to_ftp_host'];
210 $ftp_login = $HTTP_POST_VARS['export_to_ftp_login'];
211 $ftp_pass = $HTTP_POST_VARS['export_to_ftp_pass'];
212 $ftp_dir = str_replace('\\', '/', $HTTP_POST_VARS['export_to_ftp_dir']);
213 if($ftp_dir && substr($ftp_dir, strlen($ftp_dir) - 1) !== '/')
217 // save as temporary file
218 $filename = XS_TEMP_DIR.'tmp_' . time() . '.tmp';
219 $f = @fopen($filename, 'wb');
222 xs_error(str_replace('{FILE}', $filename, $lang['xs_error_cannot_create_tmp']) . '<br /><br />' . $lang['xs_export_back']);
227 $ftp = @ftp_connect($ftp_host);
231 xs_error($lang['xs_ftp_error_noconnect'] . '<br /><br />' . $lang['xs_export_back']);
233 $res = @ftp_login($ftp, $ftp_login, $ftp_pass);
237 xs_error($lang['xs_ftp_error_login2'] . '<br /><br />' . $lang['xs_export_back']);
241 @ftp_chdir($ftp, $ftp_dir);
243 $res = @ftp_put($ftp, $ftp_dir . $export_filename, $filename, FTP_BINARY);
247 xs_error($lang['xs_export_error_uploading'] . '<br /><br />' . $lang['xs_export_back']);
249 set_export_method('ftp', array('host' => $ftp_host, 'login' => $ftp_login, 'ftpdir' => $ftp_dir));
250 xs_message($lang['Information'], $lang['xs_export_uploaded'] . '<br /><br />' . $lang['xs_export_back']);
253 xs_download_file($export_filename, $data, 'application/phpbbstyle');
257 $template->set_filenames(array('body' => XS_TPL_PATH . 'export.tpl'));
260 // get list of installed styles
262 $sql = 'SELECT themes_id, template_name, style_name FROM ' . THEMES_TABLE . ' ORDER BY template_name';
263 if(!$result = $db->sql_query($sql))
265 xs_error($lang['xs_no_style_info'], __LINE__, __FILE__);
267 $style_rowset = $db->sql_fetchrowset($result);
271 $style_names = array();
273 for($i=0; $i<count($style_rowset); $i++)
275 $item = $style_rowset[$i];
276 if($item['template_name'] === $prev_tpl)
278 $style_names[] = htmlspecialchars($item['style_name']);
284 $str = implode('<br />', $style_names);
285 $str2 = urlencode($prev_tpl);
286 $row_class = $xs_row_class[$j % 2];
288 $template->assign_block_vars('styles', array(
289 'ROW_CLASS' => $row_class,
292 'U_EXPORT' => "xs_export.{$phpEx}?export={$str2}&sid={$userdata['session_id']}",
296 $prev_id = $item['themes_id'];
297 $prev_tpl = $item['template_name'];
298 $style_names = array(htmlspecialchars($item['style_name']));
304 $str = implode('<br />', $style_names);
305 $str2 = urlencode($prev_tpl);
306 $row_class = $xs_row_class[$j % 2];
308 $template->assign_block_vars('styles', array(
309 'ROW_CLASS' => $row_class,
312 'U_EXPORT' => "xs_export.{$phpEx}?export={$str2}&sid={$userdata['session_id']}",
317 $template->pparse('body');