]> git.vanrenterghem.biz Git - www.vanrenterghem.biz.git/blob - phpBB2_old/admin/xs_clone.php
Update van about met rel=me link
[www.vanrenterghem.biz.git] / phpBB2_old / admin / xs_clone.php
1 <?php
3 /***************************************************************************
4  *                               xs_clone.php
5  *                               ------------
6  *   copyright            : (C) 2003, 2004 CyberAlien
7  *   support              : http://www.phpbbstyles.com
8  *
9  *   version              : 2.0.1
10  *
11  *   file revision        : 46
12  *   project revision     : 51
13  *   last modified        : 25 Aug 2004  11:51:47
14  *
15  ***************************************************************************/
17 /***************************************************************************
18  *
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.
23  *
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)
34 {
35         message_die(GENERAL_ERROR, 'eXtreme Styles mod is not installed. You forgot to upload includes/template.php');
36 }
38 define('IN_XS', true);
39 include_once('xs_include.' . $phpEx);
41 $template->assign_block_vars('nav_left',array('ITEM' => '&raquo; <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']);
45 //
46 // Check required functions
47 //
48 if(!@function_exists('gzcompress'))
49 {
50         xs_error($lang['xs_import_nogzip']);
51 }
53 //
54 // clone style
55 //
56 if(!empty($HTTP_POST_VARS['clone_style']) && !defined('DEMO_MODE'))
57 {
58         $style = intval($HTTP_POST_VARS['clone_style']);
59         $new_name = stripslashes($HTTP_POST_VARS['clone_name']);
60         // get theme data
61         $sql = "SELECT * FROM " . THEMES_TABLE . " WHERE themes_id='{$style}'";
62         if(!$result = $db->sql_query($sql))
63         {
64                 xs_error($lang['xs_no_style_info'] . '<br /><br />' . $lang['xs_clone_back'], __LINE__, __FILE__);
65         }
66         $theme = $db->sql_fetchrow($result);
67         if(empty($theme['themes_id']))
68         {
69                 xs_error($lang['xs_no_themes'] . '<br /><br />' . $lang['xs_clone_back']);
70         }
71         if($theme['style_name'] === stripslashes($new_name))
72         {
73                 xs_error($lang['xs_clone_taken'] . '<br /><br />' . $lang['xs_clone_back']);
74         }
75         // check for clone
76         $sql = "SELECT themes_id FROM " . THEMES_TABLE . " WHERE style_name = '" . xs_sql($new_name) . "'";
77         if(!$result = $db->sql_query($sql))
78         {
79                 xs_error($lang['xs_no_theme_data'] . '<br /><br />' . $lang['xs_clone_back'], __LINE__, __FILE__);
80         }
81         $row = $db->sql_fetchrow($result);
82         if(!empty($row['themes_id']))
83         {
84                 xs_error($lang['xs_clone_taken'] . '<br /><br />' . $lang['xs_clone_back']);
85         }
86         // clone it
87         $vars = array('style_name');
88         $values = array(xs_sql($new_name));
89         foreach($theme as $var => $value)
90         {
91                 if(!is_integer($var) && $var !== 'style_name' && $var !== 'themes_id')
92                 {
93                         $vars[] = $var;
94                         $values[] = xs_sql($value);
95                 }
96         }
97         $sql = "INSERT INTO " . THEMES_TABLE . " (" . implode(', ', $vars) . ") VALUES ('" . implode("','", $values) . "')";
98         if(!$result = $db->sql_query($sql))
99         {
100                 xs_error($lang['xs_error_new_row'] . '<br /><br />' . $lang['xs_clone_back'], __LINE__, __FILE__);
101         }
102         xs_message($lang['Information'], $lang['xs_theme_cloned'] . '<br /><br />' . $lang['xs_clone_back']);
105 //
106 // clone template
107 //
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)
113         {
114                 xs_error($lang['xs_invalid_style_name'] . '<br /><br />' . $lang['xs_clone_back']);
115         }
116         // check if template exists
117         if(@file_exists('../templates/'.$new_name))
118         {
119                 xs_error($lang['xs_clone_style_exists'] . '<br /><br />' . $lang['xs_clone_back']);
120         }
121         // check variables
122         $total = intval($HTTP_POST_VARS['total']);
123         $vars = array('clone_tpl', 'clone_style_name', 'total');
124         $count = 0;
125         $list = array();
126         for($i=0; $i<$total; $i++)
127         {
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]))
132                 {
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';
140                         $count ++;
141                 }
142         }
143         if(!$count)
144         {
145                 xs_error($lang['xs_clone_no_select'] . '<br /><br />' . $lang['xs_clone_back']);
146         }
147         $request = array();
148         for($i=0; $i<count($vars); $i++)
149         {
150                 $request[$vars[$i]] = stripslashes($HTTP_POST_VARS[$vars[$i]]);
151         }
152         // get ftp configuration
153         $write_local = false;
154         if(!get_ftp_config(append_sid('xs_clone.'.$phpEx), $request, true))
155         {
156                 xs_exit();
157         }
158         xs_ftp_connect(append_sid('xs_clone.'.$phpEx), $request, true);
159         if($ftp === XS_FTP_LOCAL)
160         {
161                 $write_local = true;
162                 $write_local_dir = '../templates/';
163         }
164         // prepare variables for export
165         $export = $old_name;
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))
170         {
171                 xs_error($lang['xs_no_theme_data'] . $lang['xs_clone_back']);
172         }
173         $theme_rowset = $db->sql_fetchrowset($result);
174         if(count($theme_rowset) == 0)
175         {
176                 xs_error($lang['xs_no_themes']  . '<br /><br />' . $lang['xs_clone_back']);
177         }
178         $theme_data = xs_generate_themeinfo($theme_rowset, $export, $exportas, $total);
179         // prepare to pack      
180         $pack_error = '';
181         $pack_list = array();
182         $pack_replace = array('./theme_info.cfg' => $theme_data);
183         // pack style
184         for($i = 0; $i < count($theme_rowset); $i++)
185         {
186                 $id = $theme_rowset[$i]['themes_id'];
187                 $theme_name = $theme_rowset[$i]['style_name'];
188                 for($j=0; $j<$total; $j++)
189                 {
190                         if(!empty($HTTP_POST_VARS['export_style_name_'.$j]) && $HTTP_POST_VARS['export_style_id_'.$j] == $id)
191                         {
192                                 $theme_name = stripslashes($HTTP_POST_VARS['export_style_name_'.$j]);
193                         }
194                 }
195                 $theme_rowset[$i]['style_name'] = $theme_name;
196         }
197         $data = pack_style($export, $exportas, $theme_rowset, '');
198         // check errors
199         if($pack_error)
200         {
201                 xs_error(str_replace('{TPL}', $export, $lang['xs_export_error']) . $pack_error  . '<br /><br />' . $lang['xs_clone_back']);
202         }
203         if(!$data)
204         {
205                 xs_error(str_replace('{TPL}', $export, $lang['xs_export_error2']) . '<br /><br />' . $lang['xs_clone_back']);
206         }
207         // save as file
208         $filename = 'clone_' . time() . '.tmp';
209         $tmp_filename = XS_TEMP_DIR . $filename;
210         $f = @fopen($tmp_filename, 'wb');
211         if(!$f)
212         {
213                 xs_error(str_replace('{FILE}', $tpl_filename, $lang['xs_error_cannot_create_tmp']) . '<br /><br />' . $lang['xs_clone_back']);
214         }
215         fwrite($f, $data);
216         fclose($f);
217         // prepare import variables
218         $total = $count;
219         $HTTP_POST_VARS['total'] = $count;
220         $list_only = false;
221         $get_file = '';
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);        
229 //
230 // clone style menu
231 //
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))
237         {
238                 xs_error($lang['xs_no_theme_data'] . '<br /><br />' . $lang['xs_clone_back'], __LINE__, __FILE__);
239         }
240         $theme_rowset = $db->sql_fetchrowset($result);
241         if(count($theme_rowset) == 0)
242         {
243                 xs_error($lang['xs_no_themes'] . '<br /><br />' . $lang['xs_clone_back']);
244         }
245         $template->set_filenames(array('body' => XS_TPL_PATH . 'clone2.tpl'));
246         // clone template
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'])
254                         ));
255         // clone styles
256         for($i=0; $i<count($theme_rowset); $i++)
257         {
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'])
263                         ));
264         }
265         if(count($theme_rowset) == 1)
266         {
267                 $template->assign_block_vars('switch_select_nostyle', array());
268                 if($theme_rowset[0]['style_name'] === $style)
269                 {
270                         $template->assign_block_vars('switch_onchange', array());
271                 }
272         }
273         else
274         {
275                 $template->assign_block_vars('switch_select_style', array());
276                 for($i=0; $i<count($theme_rowset); $i++)
277                 {
278                         $template->assign_block_vars('switch_select_style.style', array(
279                                 'NUM'           => $i,
280                                 'ID'            => $theme_rowset[$i]['themes_id'],
281                                 'NAME'          => htmlspecialchars($theme_rowset[$i]['style_name'])
282                                 ));
283                 }
284         }
285         $template->pparse('body');
286         xs_exit();
291 //
292 // get list of installed styles
293 //
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);
301 $prev_id = -1;
302 $prev_tpl = '';
303 $style_names = array();
304 $j = 0;
305 for($i=0; $i<count($style_rowset); $i++)
307         $item = $style_rowset[$i];
308         if($item['template_name'] === $prev_tpl)
309         {
310                 $style_names[] = htmlspecialchars($item['style_name']);
311         }
312         else
313         {
314                 if($prev_id > 0)
315                 {
316                         $str = implode('<br />', $style_names);
317                         $str2 = urlencode($prev_tpl);
318                         $row_class = $xs_row_class[$j % 2];
319                         $j++;
320                         $template->assign_block_vars('styles', array(
321                                         'ROW_CLASS'     => $row_class,
322                                         'TPL'           => $prev_tpl,
323                                         'STYLES'        => $str,
324                                         'U_CLONE'       => "xs_clone.{$phpEx}?clone={$str2}&sid={$userdata['session_id']}",
325                                 )
326                         );
327                 }
328                 $prev_id = $item['themes_id'];
329                 $prev_tpl = $item['template_name'];
330                 $style_names = array(htmlspecialchars($item['style_name']));
331         }
334 if($prev_id > 0)
336         $str = implode('<br />', $style_names);
337         $str2 = urlencode($prev_tpl);
338         $row_class = $xs_row_class[$j % 2];
339         $j++;
340         $template->assign_block_vars('styles', array(
341                         'ROW_CLASS'     => $row_class,
342                         'TPL'           => $prev_tpl,
343                         'STYLES'        => $str,
344                         'U_CLONE'       => "xs_clone.{$phpEx}?clone={$str2}&sid={$userdata['session_id']}",
345                 )
346         );
349 $template->set_filenames(array('body' => XS_TPL_PATH . 'clone.tpl'));
350 $template->pparse('body');
351 xs_exit();
353 ?>