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_clone.'.$phpEx) . '">' . $lang['xs_clone_styles'] . '</a>'));
\r
43 $lang['xs_clone_back'] = str_replace('{URL}', append_sid('xs_clone.'.$phpEx), $lang['xs_clone_back']);
\r
46 // Check required functions
\r
48 if(!@function_exists('gzcompress'))
\r
50 xs_error($lang['xs_import_nogzip']);
\r
56 if(!empty($HTTP_POST_VARS['clone_style']) && !defined('DEMO_MODE'))
\r
58 $style = intval($HTTP_POST_VARS['clone_style']);
\r
59 $new_name = stripslashes($HTTP_POST_VARS['clone_name']);
\r
61 $sql = "SELECT * FROM " . THEMES_TABLE . " WHERE themes_id='{$style}'";
\r
62 if(!$result = $db->sql_query($sql))
\r
64 xs_error($lang['xs_no_style_info'] . '<br /><br />' . $lang['xs_clone_back'], __LINE__, __FILE__);
\r
66 $theme = $db->sql_fetchrow($result);
\r
67 if(empty($theme['themes_id']))
\r
69 xs_error($lang['xs_no_themes'] . '<br /><br />' . $lang['xs_clone_back']);
\r
71 if($theme['style_name'] === stripslashes($new_name))
\r
73 xs_error($lang['xs_clone_taken'] . '<br /><br />' . $lang['xs_clone_back']);
\r
76 $sql = "SELECT themes_id FROM " . THEMES_TABLE . " WHERE style_name = '" . xs_sql($new_name) . "'";
\r
77 if(!$result = $db->sql_query($sql))
\r
79 xs_error($lang['xs_no_theme_data'] . '<br /><br />' . $lang['xs_clone_back'], __LINE__, __FILE__);
\r
81 $row = $db->sql_fetchrow($result);
\r
82 if(!empty($row['themes_id']))
\r
84 xs_error($lang['xs_clone_taken'] . '<br /><br />' . $lang['xs_clone_back']);
\r
87 $vars = array('style_name');
\r
88 $values = array(xs_sql($new_name));
\r
89 foreach($theme as $var => $value)
\r
91 if(!is_integer($var) && $var !== 'style_name' && $var !== 'themes_id')
\r
94 $values[] = xs_sql($value);
\r
97 $sql = "INSERT INTO " . THEMES_TABLE . " (" . implode(', ', $vars) . ") VALUES ('" . implode("','", $values) . "')";
\r
98 if(!$result = $db->sql_query($sql))
\r
100 xs_error($lang['xs_error_new_row'] . '<br /><br />' . $lang['xs_clone_back'], __LINE__, __FILE__);
\r
103 if(defined('XS_MODS_CATEGORY_HIERARCHY210'))
\r
105 if ( empty($themes) )
\r
107 $themes = new themes();
\r
109 if ( !empty($themes) )
\r
111 $themes->read(true);
\r
114 xs_message($lang['Information'], $lang['xs_theme_cloned'] . '<br /><br />' . $lang['xs_clone_back']);
\r
120 if(!empty($HTTP_POST_VARS['clone_tpl']) && !defined('DEMO_MODE'))
\r
122 $old_name = xs_tpl_name($HTTP_POST_VARS['clone_tpl']);
\r
123 $new_name = xs_tpl_name($HTTP_POST_VARS['clone_style_name']);
\r
124 if(empty($new_name) || $new_name === $old_name)
\r
126 xs_error($lang['xs_invalid_style_name'] . '<br /><br />' . $lang['xs_clone_back']);
\r
128 // check if template exists
\r
129 if(@file_exists('../templates/'.$new_name))
\r
131 xs_error($lang['xs_clone_style_exists'] . '<br /><br />' . $lang['xs_clone_back']);
\r
134 $total = intval($HTTP_POST_VARS['total']);
\r
135 $vars = array('clone_tpl', 'clone_style_name', 'total');
\r
138 for($i=0; $i<$total; $i++)
\r
140 $vars[] = 'clone_style_id_'.$i;
\r
141 $vars[] = 'clone_style_'.$i;
\r
142 $vars[] = 'clone_style_name_'.$i;
\r
143 if(!empty($HTTP_POST_VARS['clone_style_'.$i]) && !empty($HTTP_POST_VARS['clone_style_name_'.$i]))
\r
145 // prepare for export
\r
146 $list[] = intval($HTTP_POST_VARS['clone_style_id_'.$i]);
\r
147 $HTTP_POST_VARS['export_style_'.$i] = $HTTP_POST_VARS['clone_style_'.$i];
\r
148 $HTTP_POST_VARS['export_style_id_'.$i] = $HTTP_POST_VARS['clone_style_id_'.$i];
\r
149 $HTTP_POST_VARS['export_style_name_'.$i] = $HTTP_POST_VARS['clone_style_name_'.$i];
\r
150 // prepare for import
\r
151 $HTTP_POST_VARS['import_install_'.$count] = '1';
\r
157 xs_error($lang['xs_clone_no_select'] . '<br /><br />' . $lang['xs_clone_back']);
\r
159 $request = array();
\r
160 for($i=0; $i<count($vars); $i++)
\r
162 $request[$vars[$i]] = stripslashes($HTTP_POST_VARS[$vars[$i]]);
\r
164 // get ftp configuration
\r
165 $write_local = false;
\r
166 if(!get_ftp_config(append_sid('xs_clone.'.$phpEx), $request, true))
\r
170 xs_ftp_connect(append_sid('xs_clone.'.$phpEx), $request, true);
\r
171 if($ftp === XS_FTP_LOCAL)
\r
173 $write_local = true;
\r
174 $write_local_dir = '../templates/';
\r
176 // prepare variables for export
\r
177 $export = $old_name;
\r
178 $exportas = $new_name;
\r
179 // Generate theme_info.cfg
\r
180 $sql = "SELECT * FROM " . THEMES_TABLE . " WHERE template_name = '$export' AND themes_id IN (" . implode(', ', $list) . ")";
\r
181 if(!$result = $db->sql_query($sql))
\r
183 xs_error($lang['xs_no_theme_data'] . $lang['xs_clone_back']);
\r
185 $theme_rowset = $db->sql_fetchrowset($result);
\r
186 if(count($theme_rowset) == 0)
\r
188 xs_error($lang['xs_no_themes'] . '<br /><br />' . $lang['xs_clone_back']);
\r
190 $theme_data = xs_generate_themeinfo($theme_rowset, $export, $exportas, $total);
\r
191 // prepare to pack
\r
193 $pack_list = array();
\r
194 $pack_replace = array('./theme_info.cfg' => $theme_data);
\r
196 for($i = 0; $i < count($theme_rowset); $i++)
\r
198 $id = $theme_rowset[$i]['themes_id'];
\r
199 $theme_name = $theme_rowset[$i]['style_name'];
\r
200 for($j=0; $j<$total; $j++)
\r
202 if(!empty($HTTP_POST_VARS['export_style_name_'.$j]) && $HTTP_POST_VARS['export_style_id_'.$j] == $id)
\r
204 $theme_name = stripslashes($HTTP_POST_VARS['export_style_name_'.$j]);
\r
207 $theme_rowset[$i]['style_name'] = $theme_name;
\r
209 $data = pack_style($export, $exportas, $theme_rowset, '');
\r
213 xs_error(str_replace('{TPL}', $export, $lang['xs_export_error']) . $pack_error . '<br /><br />' . $lang['xs_clone_back']);
\r
217 xs_error(str_replace('{TPL}', $export, $lang['xs_export_error2']) . '<br /><br />' . $lang['xs_clone_back']);
\r
220 $filename = 'clone_' . time() . '.tmp';
\r
221 $tmp_filename = XS_TEMP_DIR . $filename;
\r
222 $f = @fopen($tmp_filename, 'wb');
\r
225 xs_error(str_replace('{FILE}', $tpl_filename, $lang['xs_error_cannot_create_tmp']) . '<br /><br />' . $lang['xs_clone_back']);
\r
229 // prepare import variables
\r
231 $HTTP_POST_VARS['total'] = $count;
\r
232 $list_only = false;
\r
234 define('XS_CLONING', true);
\r
235 $lang['xs_import_back'] = $lang['xs_clone_back'];
\r
236 include('xs_include_import.' . $phpEx);
\r
237 include('xs_include_import2.' . $phpEx);
\r
242 // clone style menu
\r
244 if(!empty($HTTP_GET_VARS['clone']))
\r
246 $style = stripslashes($HTTP_GET_VARS['clone']);
\r
247 $sql = "SELECT themes_id, style_name FROM " . THEMES_TABLE . " WHERE template_name = '" . xs_sql($style) . "' ORDER BY style_name ASC";
\r
248 if(!$result = $db->sql_query($sql))
\r
250 xs_error($lang['xs_no_theme_data'] . '<br /><br />' . $lang['xs_clone_back'], __LINE__, __FILE__);
\r
252 $theme_rowset = $db->sql_fetchrowset($result);
\r
253 if(count($theme_rowset) == 0)
\r
255 xs_error($lang['xs_no_themes'] . '<br /><br />' . $lang['xs_clone_back']);
\r
257 $template->set_filenames(array('body' => XS_TPL_PATH . 'clone2.tpl'));
\r
259 $template->assign_vars(array(
\r
260 'FORM_ACTION' => append_sid('xs_clone.'.$phpEx),
\r
261 'CLONE_TEMPLATE' => htmlspecialchars($style),
\r
262 'STYLE_ID' => $theme_rowset[0]['themes_id'],
\r
263 'STYLE_NAME' => htmlspecialchars($theme_rowset[0]['style_name']),
\r
264 'TOTAL' => count($theme_rowset),
\r
265 'L_CLONE_STYLE3' => str_replace('{STYLE}', htmlspecialchars($style), $lang['xs_clone_style3'])
\r
268 for($i=0; $i<count($theme_rowset); $i++)
\r
270 $template->assign_block_vars('styles', array(
\r
271 'ID' => $theme_rowset[$i]['themes_id'],
\r
272 'TPL' => htmlspecialchars($theme_rowset[$i]['template_name']),
\r
273 'STYLE' => htmlspecialchars($theme_rowset[$i]['style_name']),
\r
274 'L_CLONE' => str_replace('{STYLE}', htmlspecialchars($theme_rowset[$i]['style_name']), $lang['xs_clone_style2'])
\r
277 if(count($theme_rowset) == 1)
\r
279 $template->assign_block_vars('switch_select_nostyle', array());
\r
280 if($theme_rowset[0]['style_name'] === $style)
\r
282 $template->assign_block_vars('switch_onchange', array());
\r
287 $template->assign_block_vars('switch_select_style', array());
\r
288 for($i=0; $i<count($theme_rowset); $i++)
\r
290 $template->assign_block_vars('switch_select_style.style', array(
\r
292 'ID' => $theme_rowset[$i]['themes_id'],
\r
293 'NAME' => htmlspecialchars($theme_rowset[$i]['style_name'])
\r
297 $template->pparse('body');
\r
304 // get list of installed styles
\r
306 $sql = 'SELECT themes_id, template_name, style_name FROM ' . THEMES_TABLE . ' ORDER BY template_name';
\r
307 if(!$result = $db->sql_query($sql))
\r
309 xs_error($lang['xs_no_style_info'], __LINE__, __FILE__);
\r
311 $style_rowset = $db->sql_fetchrowset($result);
\r
315 $style_names = array();
\r
317 for($i=0; $i<count($style_rowset); $i++)
\r
319 $item = $style_rowset[$i];
\r
320 if($item['template_name'] === $prev_tpl)
\r
322 $style_names[] = htmlspecialchars($item['style_name']);
\r
328 $str = implode('<br />', $style_names);
\r
329 $str2 = urlencode($prev_tpl);
\r
330 $row_class = $xs_row_class[$j % 2];
\r
332 $template->assign_block_vars('styles', array(
\r
333 'ROW_CLASS' => $row_class,
\r
334 'TPL' => $prev_tpl,
\r
336 'U_CLONE' => "xs_clone.{$phpEx}?clone={$str2}&sid={$userdata['session_id']}",
\r
340 $prev_id = $item['themes_id'];
\r
341 $prev_tpl = $item['template_name'];
\r
342 $style_names = array(htmlspecialchars($item['style_name']));
\r
348 $str = implode('<br />', $style_names);
\r
349 $str2 = urlencode($prev_tpl);
\r
350 $row_class = $xs_row_class[$j % 2];
\r
352 $template->assign_block_vars('styles', array(
\r
353 'ROW_CLASS' => $row_class,
\r
354 'TPL' => $prev_tpl,
\r
356 'U_CLONE' => "xs_clone.{$phpEx}?clone={$str2}&sid={$userdata['session_id']}",
\r
361 $template->set_filenames(array('body' => XS_TPL_PATH . 'clone.tpl'));
\r
362 $template->pparse('body');
\r