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:48
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_edit_data.'.$phpEx) . '">' . $lang['xs_edit_styles_data'] . '</a>'));
43 $lang['xs_edittpl_back_list'] = str_replace('{URL}', append_sid('xs_edit_data.'.$phpEx), $lang['xs_edittpl_back_list']);
45 function xs_empty_name()
48 $sql = "SELECT * FROM " . THEMES_NAME_TABLE . " LIMIT 0, 1";
49 if(!$result = $db->sql_query($sql))
53 $data = $db->sql_fetchrow($result);
54 if($data === false || !@count($data))
58 'tr_color1_name' => '',
59 'tr_color2_name' => '',
60 'tr_color3_name' => '',
61 'tr_class1_name' => '',
62 'tr_class2_name' => '',
63 'tr_class3_name' => '',
64 'th_color1_name' => '',
65 'th_color2_name' => '',
66 'th_color3_name' => '',
67 'th_class1_name' => '',
68 'th_class2_name' => '',
69 'th_class3_name' => '',
70 'td_color1_name' => '',
71 'td_color2_name' => '',
72 'td_color3_name' => '',
73 'td_class1_name' => '',
74 'td_class2_name' => '',
75 'td_class3_name' => '',
76 'fontface1_name' => '',
77 'fontface2_name' => '',
78 'fontface3_name' => '',
79 'fontsize1_name' => '',
80 'fontsize2_name' => '',
81 'fontsize3_name' => '',
82 'fontcolor1_name' => '',
83 'fontcolor2_name' => '',
84 'fontcolor3_name' => '',
85 'span_class1_name' => '',
86 'span_class2_name' => '',
87 'span_class3_name' => ''
92 foreach($data as $var => $value)
94 if($var !== 'themes_id')
102 function xs_get_vars($theme)
106 $vars_100 = array('head_stylesheet', 'body_background');
107 $vars_50 = array('fontface');
108 $vars_30 = array('style_name');
109 $vars_25 = array('tr_class', 'th_class', 'td_class', 'span_class');
110 $vars_6 = array('body_bgcolor', 'body_text', 'body_link', 'body_vlink', 'body_alink', 'body_hlink', 'tr_color', 'th_color', 'td_color', 'fontcolor');
111 $vars_5 = array('img_size_poll', 'img_size_privmsg');
112 $vars_4 = array('fontsize', 'theme_public');
113 foreach($theme as $var => $value)
115 if(!is_integer($var) && $var !== 'themes_id' && $var !== 'template_name')
119 $sub = substr($var, 0, strlen($var) - 1);
120 if(xs_in_array($var, $vars_100) || xs_in_array($sub, $vars_100))
124 elseif(xs_in_array($var, $vars_50) || xs_in_array($sub, $vars_50))
128 elseif(xs_in_array($var, $vars_30) || xs_in_array($sub, $vars_30))
132 elseif(xs_in_array($var, $vars_25) || xs_in_array($sub, $vars_25))
136 elseif(xs_in_array($var, $vars_6) || xs_in_array($sub, $vars_6))
140 elseif(xs_in_array($var, $vars_5) || xs_in_array($sub, $vars_5))
144 elseif(xs_in_array($var, $vrs_4) || xs_in_array($sub, $vars_4))
148 elseif(strpos($var, 'class'))
152 elseif(strpos($var, 'color'))
161 'color' => $len == 6 ? true : false,
162 'font' => $len == 25 ? true : false,
164 if($var === 'style_name' || $var === 'head_stylesheet' || $var === 'body_background')
177 return array_merge($arr1, $arr2);
183 if(!empty($HTTP_POST_VARS['edit']) && !defined('DEMO_MODE'))
185 $id = intval($HTTP_POST_VARS['edit']);
186 $lang['xs_edittpl_back_edit'] = str_replace('{URL}', append_sid('xs_edit_data.'.$phpEx.'?edit='.$id), $lang['xs_edittpl_back_edit']);
187 $data_item = array();
188 $data_item_update = array();
189 $data_name = array();
190 $data_name_insert_vars = array('themes_id');
191 $data_name_insert_values = array($id);
192 $data_name_update = array();
193 foreach($HTTP_POST_VARS as $var => $value)
195 if(substr($var, 0, 5) === 'edit_')
197 $var = substr($var, 5);
198 $value = stripslashes($value);
199 $data_item[$var] = $value;
200 $data_item_update[] = $var . "='" . xs_sql($value) . "'";
202 elseif(substr($var, 0, 5) === 'name_')
204 $var = substr($var, 5).'_name';
205 $value = stripslashes($value);
206 $data_name[$var] = $value;
207 $data_name_update[] = $var . "='" . xs_sql($value) . "'";
208 $data_name_insert_vars[] = $var;
209 $data_name_insert_values[] = xs_sql($value);
213 $sql = "UPDATE " . THEMES_TABLE . " SET " . implode(',', $data_item_update) . " WHERE themes_id='{$id}'";
214 if(!$result = $db->sql_query($sql))
216 xs_error($lang['xs_edittpl_error_updating'] . '<br /><br />' . $lang['xs_edittpl_back_edit'] . '<br /><br />' . $lang['xs_edittpl_back_list'], __LINE__, __FILE__);
218 // check if there is name
219 $sql = "SELECT themes_id FROM " . THEMES_NAME_TABLE . " WHERE themes_id='{$id}'";
220 if(!$result = $db->sql_query($sql))
222 $sql = "INSERT INTO " . THEMES_NAME_TABLE . " (" . implode(',', $data_name_insert_vars) . ") VALUES ('" . implode("', '", $data_name_insert_values) . "')";
224 $item = $db->sql_fetchrow($result);
227 $sql = "INSERT INTO " . THEMES_NAME_TABLE . " (" . implode(',', $data_name_insert_vars) . ") VALUES ('" . implode("', '", $data_name_insert_values) . "')";
231 $sql = "UPDATE " . THEMES_NAME_TABLE . " SET " . implode(',', $data_name_update) . " WHERE themes_id='{$id}'";
233 $db->sql_query($sql);
234 xs_message($lang['Information'], $lang['xs_edittpl_style_updated'] . '<br /><br />' . $lang['xs_edittpl_back_edit'] . '<br /><br />' . $lang['xs_edittpl_back_list']);
240 if(!empty($HTTP_GET_VARS['edit']))
242 $id = intval($HTTP_GET_VARS['edit']);
243 $sql = "SELECT * FROM " . THEMES_TABLE . " WHERE themes_id='{$id}'";
244 if(!$result = $db->sql_query($sql))
246 xs_error($lang['xs_no_style_info'], __LINE__, __FILE__);
248 $item = $db->sql_fetchrow($result);
249 if(empty($item['themes_id']))
251 xs_error($lang['xs_invalid_style_id'] . '<br /><br />' . $lang['xs_edittpl_back_list']);
253 $sql = "SELECT * FROM " . THEMES_NAME_TABLE . " WHERE themes_id='{$id}'";
254 if(!$result = $db->sql_query($sql))
256 $item_name = array();
258 $item_name = $db->sql_fetchrow($result);
259 if($item_name === false || !@count($item_name))
261 $item_name = xs_empty_name();
263 $vars = xs_get_vars($item);
265 $template->assign_vars(array(
266 'U_ACTION' => append_sid('xs_edit_data.'.$phpEx),
267 'TPL' => htmlspecialchars($item['template-name']),
268 'STYLE' => htmlspecialchars($item['style_name']),
274 foreach($vars as $var => $value)
276 $row_class = $xs_row_class[$i % 2];
278 if(isset($lang['xs_data_'.$var]))
280 $text = $lang['xs_data_'.$var];
284 $str = substr($var, 0, strlen($var) - 1);
285 if(isset($lang['xs_data_'.$str]))
287 $str1 = substr($var, strlen($var) - 1);
288 $text = sprintf($lang['xs_data_'.$str], $str1);
292 $text = sprintf($lang['xs_data_unknown'], $var);
295 $template->assign_block_vars('row', array(
296 'ROW_CLASS' => $row_class,
298 'VALUE' => isset($item[$var]) ? htmlspecialchars($item[$var]) : '',
299 'LEN' => $value['len'],
300 'SIZE' => $value['len'] < 10 ? 10 : 30,
301 'TEXT' => htmlspecialchars($text),
306 $template->assign_block_vars('row.color', array());
310 $template->assign_block_vars('row.font', array());
312 if(isset($item_name[$var.'_name']))
314 $template->assign_block_vars('row.name', array(
315 'DATA' => $item_name[$var.'_name']
321 $template->assign_block_vars('row.noname', array());
324 $template->set_filenames(array('body' => XS_TPL_PATH . 'edit_data.tpl'));
325 $template->pparse('body');
331 // show list of installed styles
333 $sql = 'SELECT themes_id, template_name, style_name FROM ' . THEMES_TABLE . ' ORDER BY style_name';
334 if(!$result = $db->sql_query($sql))
336 xs_error($lang['xs_no_style_info'], __LINE__, __FILE__);
338 $style_rowset = $db->sql_fetchrowset($result);
340 $template->set_filenames(array('body' => XS_TPL_PATH . 'edit_data_list.tpl'));
341 for($i=0; $i<count($style_rowset); $i++)
343 $item = $style_rowset[$i];
344 $row_class = $xs_row_class[$i % 2];
345 $template->assign_block_vars('styles', array(
346 'ROW_CLASS' => $row_class,
347 'TPL' => htmlspecialchars($item['template_name']),
348 'STYLE' => htmlspecialchars($item['style_name']),
349 'U_EDIT' => append_sid('xs_edit_data.'.$phpEx.'?edit='.$item['themes_id'])
354 $template->pparse('body');