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