]> git.vanrenterghem.biz Git - www.vanrenterghem.biz.git/blob - phpBB2/admin/xs_clone.php
The Matrix instead of Friendica.
[www.vanrenterghem.biz.git] / phpBB2 / admin / xs_clone.php
1 <?php\r
2 \r
3 /***************************************************************************\r
4  *                               xs_clone.php\r
5  *                               ------------\r
6  *   copyright            : (C) 2003 - 2005 CyberAlien\r
7  *   support              : http://www.phpbbstyles.com\r
8  *\r
9  *   version              : 2.3.1\r
10  *\r
11  *   file revision        : 72\r
12  *   project revision     : 78\r
13  *   last modified        : 05 Dec 2005  13:54:54\r
14  *\r
15  ***************************************************************************/\r
16 \r
17 /***************************************************************************\r
18  *\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
23  *\r
24  ***************************************************************************/\r
25 \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
31 \r
32 // check if mod is installed\r
33 if(empty($template->xs_version) || $template->xs_version !== 8)\r
34 {\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
36 }\r
37 \r
38 define('IN_XS', true);\r
39 include_once('xs_include.' . $phpEx);\r
40 \r
41 $template->assign_block_vars('nav_left',array('ITEM' => '&raquo; <a href="' . append_sid('xs_clone.'.$phpEx) . '">' . $lang['xs_clone_styles'] . '</a>'));\r
42 \r
43 $lang['xs_clone_back'] = str_replace('{URL}', append_sid('xs_clone.'.$phpEx), $lang['xs_clone_back']);\r
44 \r
45 //\r
46 // Check required functions\r
47 //\r
48 if(!@function_exists('gzcompress'))\r
49 {\r
50         xs_error($lang['xs_import_nogzip']);\r
51 }\r
52 \r
53 //\r
54 // clone style\r
55 //\r
56 if(!empty($HTTP_POST_VARS['clone_style']) && !defined('DEMO_MODE'))\r
57 {\r
58         $style = intval($HTTP_POST_VARS['clone_style']);\r
59         $new_name = stripslashes($HTTP_POST_VARS['clone_name']);\r
60         // get theme data\r
61         $sql = "SELECT * FROM " . THEMES_TABLE . " WHERE themes_id='{$style}'";\r
62         if(!$result = $db->sql_query($sql))\r
63         {\r
64                 xs_error($lang['xs_no_style_info'] . '<br /><br />' . $lang['xs_clone_back'], __LINE__, __FILE__);\r
65         }\r
66         $theme = $db->sql_fetchrow($result);\r
67         if(empty($theme['themes_id']))\r
68         {\r
69                 xs_error($lang['xs_no_themes'] . '<br /><br />' . $lang['xs_clone_back']);\r
70         }\r
71         if($theme['style_name'] === stripslashes($new_name))\r
72         {\r
73                 xs_error($lang['xs_clone_taken'] . '<br /><br />' . $lang['xs_clone_back']);\r
74         }\r
75         // check for clone\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
78         {\r
79                 xs_error($lang['xs_no_theme_data'] . '<br /><br />' . $lang['xs_clone_back'], __LINE__, __FILE__);\r
80         }\r
81         $row = $db->sql_fetchrow($result);\r
82         if(!empty($row['themes_id']))\r
83         {\r
84                 xs_error($lang['xs_clone_taken'] . '<br /><br />' . $lang['xs_clone_back']);\r
85         }\r
86         // clone it\r
87         $vars = array('style_name');\r
88         $values = array(xs_sql($new_name));\r
89         foreach($theme as $var => $value)\r
90         {\r
91                 if(!is_integer($var) && $var !== 'style_name' && $var !== 'themes_id')\r
92                 {\r
93                         $vars[] = $var;\r
94                         $values[] = xs_sql($value);\r
95                 }\r
96         }\r
97         $sql = "INSERT INTO " . THEMES_TABLE . " (" . implode(', ', $vars) . ") VALUES ('" . implode("','", $values) . "')";\r
98         if(!$result = $db->sql_query($sql))\r
99         {\r
100                 xs_error($lang['xs_error_new_row'] . '<br /><br />' . $lang['xs_clone_back'], __LINE__, __FILE__);\r
101         }\r
102         // recache themes\r
103         if(defined('XS_MODS_CATEGORY_HIERARCHY210'))\r
104         {\r
105                 if ( empty($themes) )\r
106                 {\r
107                         $themes = new themes();\r
108                 }\r
109                 if ( !empty($themes) )\r
110                 {\r
111                         $themes->read(true);\r
112                 }\r
113         }\r
114         xs_message($lang['Information'], $lang['xs_theme_cloned'] . '<br /><br />' . $lang['xs_clone_back']);\r
115 }\r
116 \r
117 //\r
118 // clone template\r
119 //\r
120 if(!empty($HTTP_POST_VARS['clone_tpl']) && !defined('DEMO_MODE'))\r
121 {\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
125         {\r
126                 xs_error($lang['xs_invalid_style_name'] . '<br /><br />' . $lang['xs_clone_back']);\r
127         }\r
128         // check if template exists\r
129         if(@file_exists('../templates/'.$new_name))\r
130         {\r
131                 xs_error($lang['xs_clone_style_exists'] . '<br /><br />' . $lang['xs_clone_back']);\r
132         }\r
133         // check variables\r
134         $total = intval($HTTP_POST_VARS['total']);\r
135         $vars = array('clone_tpl', 'clone_style_name', 'total');\r
136         $count = 0;\r
137         $list = array();\r
138         for($i=0; $i<$total; $i++)\r
139         {\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
144                 {\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
152                         $count ++;\r
153                 }\r
154         }\r
155         if(!$count)\r
156         {\r
157                 xs_error($lang['xs_clone_no_select'] . '<br /><br />' . $lang['xs_clone_back']);\r
158         }\r
159         $request = array();\r
160         for($i=0; $i<count($vars); $i++)\r
161         {\r
162                 $request[$vars[$i]] = stripslashes($HTTP_POST_VARS[$vars[$i]]);\r
163         }\r
164         // get ftp configuration\r
165         $write_local = false;\r
166         if(!get_ftp_config(append_sid('xs_clone.'.$phpEx), $request, true))\r
167         {\r
168                 xs_exit();\r
169         }\r
170         xs_ftp_connect(append_sid('xs_clone.'.$phpEx), $request, true);\r
171         if($ftp === XS_FTP_LOCAL)\r
172         {\r
173                 $write_local = true;\r
174                 $write_local_dir = '../templates/';\r
175         }\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
182         {\r
183                 xs_error($lang['xs_no_theme_data'] . $lang['xs_clone_back']);\r
184         }\r
185         $theme_rowset = $db->sql_fetchrowset($result);\r
186         if(count($theme_rowset) == 0)\r
187         {\r
188                 xs_error($lang['xs_no_themes']  . '<br /><br />' . $lang['xs_clone_back']);\r
189         }\r
190         $theme_data = xs_generate_themeinfo($theme_rowset, $export, $exportas, $total);\r
191         // prepare to pack      \r
192         $pack_error = '';\r
193         $pack_list = array();\r
194         $pack_replace = array('./theme_info.cfg' => $theme_data);\r
195         // pack style\r
196         for($i = 0; $i < count($theme_rowset); $i++)\r
197         {\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
201                 {\r
202                         if(!empty($HTTP_POST_VARS['export_style_name_'.$j]) && $HTTP_POST_VARS['export_style_id_'.$j] == $id)\r
203                         {\r
204                                 $theme_name = stripslashes($HTTP_POST_VARS['export_style_name_'.$j]);\r
205                         }\r
206                 }\r
207                 $theme_rowset[$i]['style_name'] = $theme_name;\r
208         }\r
209         $data = pack_style($export, $exportas, $theme_rowset, '');\r
210         // check errors\r
211         if($pack_error)\r
212         {\r
213                 xs_error(str_replace('{TPL}', $export, $lang['xs_export_error']) . $pack_error  . '<br /><br />' . $lang['xs_clone_back']);\r
214         }\r
215         if(!$data)\r
216         {\r
217                 xs_error(str_replace('{TPL}', $export, $lang['xs_export_error2']) . '<br /><br />' . $lang['xs_clone_back']);\r
218         }\r
219         // save as file\r
220         $filename = 'clone_' . time() . '.tmp';\r
221         $tmp_filename = XS_TEMP_DIR . $filename;\r
222         $f = @fopen($tmp_filename, 'wb');\r
223         if(!$f)\r
224         {\r
225                 xs_error(str_replace('{FILE}', $tpl_filename, $lang['xs_error_cannot_create_tmp']) . '<br /><br />' . $lang['xs_clone_back']);\r
226         }\r
227         fwrite($f, $data);\r
228         fclose($f);\r
229         // prepare import variables\r
230         $total = $count;\r
231         $HTTP_POST_VARS['total'] = $count;\r
232         $list_only = false;\r
233         $get_file = '';\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
238 }\r
239 \r
240 \r
241 //\r
242 // clone style menu\r
243 //\r
244 if(!empty($HTTP_GET_VARS['clone']))\r
245 {\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
249         {\r
250                 xs_error($lang['xs_no_theme_data'] . '<br /><br />' . $lang['xs_clone_back'], __LINE__, __FILE__);\r
251         }\r
252         $theme_rowset = $db->sql_fetchrowset($result);\r
253         if(count($theme_rowset) == 0)\r
254         {\r
255                 xs_error($lang['xs_no_themes'] . '<br /><br />' . $lang['xs_clone_back']);\r
256         }\r
257         $template->set_filenames(array('body' => XS_TPL_PATH . 'clone2.tpl'));\r
258         // clone template\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
266                         ));\r
267         // clone styles\r
268         for($i=0; $i<count($theme_rowset); $i++)\r
269         {\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
275                         ));\r
276         }\r
277         if(count($theme_rowset) == 1)\r
278         {\r
279                 $template->assign_block_vars('switch_select_nostyle', array());\r
280                 if($theme_rowset[0]['style_name'] === $style)\r
281                 {\r
282                         $template->assign_block_vars('switch_onchange', array());\r
283                 }\r
284         }\r
285         else\r
286         {\r
287                 $template->assign_block_vars('switch_select_style', array());\r
288                 for($i=0; $i<count($theme_rowset); $i++)\r
289                 {\r
290                         $template->assign_block_vars('switch_select_style.style', array(\r
291                                 'NUM'           => $i,\r
292                                 'ID'            => $theme_rowset[$i]['themes_id'],\r
293                                 'NAME'          => htmlspecialchars($theme_rowset[$i]['style_name'])\r
294                                 ));\r
295                 }\r
296         }\r
297         $template->pparse('body');\r
298         xs_exit();\r
299 }\r
300 \r
301 \r
302 \r
303 //\r
304 // get list of installed styles\r
305 //\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
308 {\r
309         xs_error($lang['xs_no_style_info'], __LINE__, __FILE__);\r
310 }\r
311 $style_rowset = $db->sql_fetchrowset($result);\r
312 \r
313 $prev_id = -1;\r
314 $prev_tpl = '';\r
315 $style_names = array();\r
316 $j = 0;\r
317 for($i=0; $i<count($style_rowset); $i++)\r
318 {\r
319         $item = $style_rowset[$i];\r
320         if($item['template_name'] === $prev_tpl)\r
321         {\r
322                 $style_names[] = htmlspecialchars($item['style_name']);\r
323         }\r
324         else\r
325         {\r
326                 if($prev_id > 0)\r
327                 {\r
328                         $str = implode('<br />', $style_names);\r
329                         $str2 = urlencode($prev_tpl);\r
330                         $row_class = $xs_row_class[$j % 2];\r
331                         $j++;\r
332                         $template->assign_block_vars('styles', array(\r
333                                         'ROW_CLASS'     => $row_class,\r
334                                         'TPL'           => $prev_tpl,\r
335                                         'STYLES'        => $str,\r
336                                         'U_CLONE'       => "xs_clone.{$phpEx}?clone={$str2}&sid={$userdata['session_id']}",\r
337                                 )\r
338                         );\r
339                 }\r
340                 $prev_id = $item['themes_id'];\r
341                 $prev_tpl = $item['template_name'];\r
342                 $style_names = array(htmlspecialchars($item['style_name']));\r
343         }\r
344 }\r
345 \r
346 if($prev_id > 0)\r
347 {\r
348         $str = implode('<br />', $style_names);\r
349         $str2 = urlencode($prev_tpl);\r
350         $row_class = $xs_row_class[$j % 2];\r
351         $j++;\r
352         $template->assign_block_vars('styles', array(\r
353                         'ROW_CLASS'     => $row_class,\r
354                         'TPL'           => $prev_tpl,\r
355                         'STYLES'        => $str,\r
356                         'U_CLONE'       => "xs_clone.{$phpEx}?clone={$str2}&sid={$userdata['session_id']}",\r
357                 )\r
358         );\r
359 }\r
360 \r
361 $template->set_filenames(array('body' => XS_TPL_PATH . 'clone.tpl'));\r
362 $template->pparse('body');\r
363 xs_exit();\r
364 \r
365 ?>