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_clone.'.$phpEx) . '">' . $lang['xs_clone_styles'] . '</a>'));
43 $lang['xs_clone_back'] = str_replace('{URL}', append_sid('xs_clone.'.$phpEx), $lang['xs_clone_back']);
46 // Check required functions
48 if(!@function_exists('gzcompress'))
50 xs_error($lang['xs_import_nogzip']);
56 if(!empty($HTTP_POST_VARS['clone_style']) && !defined('DEMO_MODE'))
58 $style = intval($HTTP_POST_VARS['clone_style']);
59 $new_name = stripslashes($HTTP_POST_VARS['clone_name']);
61 $sql = "SELECT * FROM " . THEMES_TABLE . " WHERE themes_id='{$style}'";
62 if(!$result = $db->sql_query($sql))
64 xs_error($lang['xs_no_style_info'] . '<br /><br />' . $lang['xs_clone_back'], __LINE__, __FILE__);
66 $theme = $db->sql_fetchrow($result);
67 if(empty($theme['themes_id']))
69 xs_error($lang['xs_no_themes'] . '<br /><br />' . $lang['xs_clone_back']);
71 if($theme['style_name'] === stripslashes($new_name))
73 xs_error($lang['xs_clone_taken'] . '<br /><br />' . $lang['xs_clone_back']);
76 $sql = "SELECT themes_id FROM " . THEMES_TABLE . " WHERE style_name = '" . xs_sql($new_name) . "'";
77 if(!$result = $db->sql_query($sql))
79 xs_error($lang['xs_no_theme_data'] . '<br /><br />' . $lang['xs_clone_back'], __LINE__, __FILE__);
81 $row = $db->sql_fetchrow($result);
82 if(!empty($row['themes_id']))
84 xs_error($lang['xs_clone_taken'] . '<br /><br />' . $lang['xs_clone_back']);
87 $vars = array('style_name');
88 $values = array(xs_sql($new_name));
89 foreach($theme as $var => $value)
91 if(!is_integer($var) && $var !== 'style_name' && $var !== 'themes_id')
94 $values[] = xs_sql($value);
97 $sql = "INSERT INTO " . THEMES_TABLE . " (" . implode(', ', $vars) . ") VALUES ('" . implode("','", $values) . "')";
98 if(!$result = $db->sql_query($sql))
100 xs_error($lang['xs_error_new_row'] . '<br /><br />' . $lang['xs_clone_back'], __LINE__, __FILE__);
102 xs_message($lang['Information'], $lang['xs_theme_cloned'] . '<br /><br />' . $lang['xs_clone_back']);
108 if(!empty($HTTP_POST_VARS['clone_tpl']) && !defined('DEMO_MODE'))
110 $old_name = xs_tpl_name($HTTP_POST_VARS['clone_tpl']);
111 $new_name = xs_tpl_name($HTTP_POST_VARS['clone_style_name']);
112 if(empty($new_name) || $new_name === $old_name)
114 xs_error($lang['xs_invalid_style_name'] . '<br /><br />' . $lang['xs_clone_back']);
116 // check if template exists
117 if(@file_exists('../templates/'.$new_name))
119 xs_error($lang['xs_clone_style_exists'] . '<br /><br />' . $lang['xs_clone_back']);
122 $total = intval($HTTP_POST_VARS['total']);
123 $vars = array('clone_tpl', 'clone_style_name', 'total');
126 for($i=0; $i<$total; $i++)
128 $vars[] = 'clone_style_id_'.$i;
129 $vars[] = 'clone_style_'.$i;
130 $vars[] = 'clone_style_name_'.$i;
131 if(!empty($HTTP_POST_VARS['clone_style_'.$i]) && !empty($HTTP_POST_VARS['clone_style_name_'.$i]))
133 // prepare for export
134 $list[] = intval($HTTP_POST_VARS['clone_style_id_'.$i]);
135 $HTTP_POST_VARS['export_style_'.$i] = $HTTP_POST_VARS['clone_style_'.$i];
136 $HTTP_POST_VARS['export_style_id_'.$i] = $HTTP_POST_VARS['clone_style_id_'.$i];
137 $HTTP_POST_VARS['export_style_name_'.$i] = $HTTP_POST_VARS['clone_style_name_'.$i];
138 // prepare for import
139 $HTTP_POST_VARS['import_install_'.$count] = '1';
145 xs_error($lang['xs_clone_no_select'] . '<br /><br />' . $lang['xs_clone_back']);
148 for($i=0; $i<count($vars); $i++)
150 $request[$vars[$i]] = stripslashes($HTTP_POST_VARS[$vars[$i]]);
152 // get ftp configuration
153 $write_local = false;
154 if(!get_ftp_config(append_sid('xs_clone.'.$phpEx), $request, true))
158 xs_ftp_connect(append_sid('xs_clone.'.$phpEx), $request, true);
159 if($ftp === XS_FTP_LOCAL)
162 $write_local_dir = '../templates/';
164 // prepare variables for export
166 $exportas = $new_name;
167 // Generate theme_info.cfg
168 $sql = "SELECT * FROM " . THEMES_TABLE . " WHERE template_name = '$export' AND themes_id IN (" . implode(', ', $list) . ")";
169 if(!$result = $db->sql_query($sql))
171 xs_error($lang['xs_no_theme_data'] . $lang['xs_clone_back']);
173 $theme_rowset = $db->sql_fetchrowset($result);
174 if(count($theme_rowset) == 0)
176 xs_error($lang['xs_no_themes'] . '<br /><br />' . $lang['xs_clone_back']);
178 $theme_data = xs_generate_themeinfo($theme_rowset, $export, $exportas, $total);
181 $pack_list = array();
182 $pack_replace = array('./theme_info.cfg' => $theme_data);
184 for($i = 0; $i < count($theme_rowset); $i++)
186 $id = $theme_rowset[$i]['themes_id'];
187 $theme_name = $theme_rowset[$i]['style_name'];
188 for($j=0; $j<$total; $j++)
190 if(!empty($HTTP_POST_VARS['export_style_name_'.$j]) && $HTTP_POST_VARS['export_style_id_'.$j] == $id)
192 $theme_name = stripslashes($HTTP_POST_VARS['export_style_name_'.$j]);
195 $theme_rowset[$i]['style_name'] = $theme_name;
197 $data = pack_style($export, $exportas, $theme_rowset, '');
201 xs_error(str_replace('{TPL}', $export, $lang['xs_export_error']) . $pack_error . '<br /><br />' . $lang['xs_clone_back']);
205 xs_error(str_replace('{TPL}', $export, $lang['xs_export_error2']) . '<br /><br />' . $lang['xs_clone_back']);
208 $filename = 'clone_' . time() . '.tmp';
209 $tmp_filename = XS_TEMP_DIR . $filename;
210 $f = @fopen($tmp_filename, 'wb');
213 xs_error(str_replace('{FILE}', $tpl_filename, $lang['xs_error_cannot_create_tmp']) . '<br /><br />' . $lang['xs_clone_back']);
217 // prepare import variables
219 $HTTP_POST_VARS['total'] = $count;
222 define('XS_CLONING', true);
223 $lang['xs_import_back'] = $lang['xs_clone_back'];
224 include('xs_include_import.' . $phpEx);
225 include('xs_include_import2.' . $phpEx);
232 if(!empty($HTTP_GET_VARS['clone']))
234 $style = stripslashes($HTTP_GET_VARS['clone']);
235 $sql = "SELECT themes_id, style_name FROM " . THEMES_TABLE . " WHERE template_name = '" . xs_sql($style) . "' ORDER BY style_name ASC";
236 if(!$result = $db->sql_query($sql))
238 xs_error($lang['xs_no_theme_data'] . '<br /><br />' . $lang['xs_clone_back'], __LINE__, __FILE__);
240 $theme_rowset = $db->sql_fetchrowset($result);
241 if(count($theme_rowset) == 0)
243 xs_error($lang['xs_no_themes'] . '<br /><br />' . $lang['xs_clone_back']);
245 $template->set_filenames(array('body' => XS_TPL_PATH . 'clone2.tpl'));
247 $template->assign_vars(array(
248 'FORM_ACTION' => append_sid('xs_clone.'.$phpEx),
249 'CLONE_TEMPLATE' => htmlspecialchars($style),
250 'STYLE_ID' => $theme_rowset[0]['themes_id'],
251 'STYLE_NAME' => htmlspecialchars($theme_rowset[0]['style_name']),
252 'TOTAL' => count($theme_rowset),
253 'L_CLONE_STYLE3' => str_replace('{STYLE}', htmlspecialchars($style), $lang['xs_clone_style3'])
256 for($i=0; $i<count($theme_rowset); $i++)
258 $template->assign_block_vars('styles', array(
259 'ID' => $theme_rowset[$i]['themes_id'],
260 'TPL' => htmlspecialchars($theme_rowset[$i]['template_name']),
261 'STYLE' => htmlspecialchars($theme_rowset[$i]['style_name']),
262 'L_CLONE' => str_replace('{STYLE}', htmlspecialchars($theme_rowset[$i]['style_name']), $lang['xs_clone_style2'])
265 if(count($theme_rowset) == 1)
267 $template->assign_block_vars('switch_select_nostyle', array());
268 if($theme_rowset[0]['style_name'] === $style)
270 $template->assign_block_vars('switch_onchange', array());
275 $template->assign_block_vars('switch_select_style', array());
276 for($i=0; $i<count($theme_rowset); $i++)
278 $template->assign_block_vars('switch_select_style.style', array(
280 'ID' => $theme_rowset[$i]['themes_id'],
281 'NAME' => htmlspecialchars($theme_rowset[$i]['style_name'])
285 $template->pparse('body');
292 // get list of installed styles
294 $sql = 'SELECT themes_id, template_name, style_name FROM ' . THEMES_TABLE . ' ORDER BY template_name';
295 if(!$result = $db->sql_query($sql))
297 xs_error($lang['xs_no_style_info'], __LINE__, __FILE__);
299 $style_rowset = $db->sql_fetchrowset($result);
303 $style_names = array();
305 for($i=0; $i<count($style_rowset); $i++)
307 $item = $style_rowset[$i];
308 if($item['template_name'] === $prev_tpl)
310 $style_names[] = htmlspecialchars($item['style_name']);
316 $str = implode('<br />', $style_names);
317 $str2 = urlencode($prev_tpl);
318 $row_class = $xs_row_class[$j % 2];
320 $template->assign_block_vars('styles', array(
321 'ROW_CLASS' => $row_class,
324 'U_CLONE' => "xs_clone.{$phpEx}?clone={$str2}&sid={$userdata['session_id']}",
328 $prev_id = $item['themes_id'];
329 $prev_tpl = $item['template_name'];
330 $style_names = array(htmlspecialchars($item['style_name']));
336 $str = implode('<br />', $style_names);
337 $str2 = urlencode($prev_tpl);
338 $row_class = $xs_row_class[$j % 2];
340 $template->assign_block_vars('styles', array(
341 'ROW_CLASS' => $row_class,
344 'U_CLONE' => "xs_clone.{$phpEx}?clone={$str2}&sid={$userdata['session_id']}",
349 $template->set_filenames(array('body' => XS_TPL_PATH . 'clone.tpl'));
350 $template->pparse('body');