aboutsummaryrefslogtreecommitdiffstats
path: root/phpBB/admin/admin_styles.php
blob: af319680c3d46b8b34a1a236749caeb2e8ce5bad (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
<?php

if ( !empty($setmodules) )
{
	if ( !$acl->get_acl_admin('styles') )
	{
		return;
	}

	$filename = basename(__FILE__);
	$module['Styles']['Edit_Styles'] = $filename . "$SID&amp;mode=newstyle";
	$module['Styles']['Edit_Templates'] = $filename . "$SID&amp;mode=edittemplate";
	$module['Styles']['Edit_Themes'] = $filename . "$SID&amp;mode=newstyle";
	$module['Styles']['Edit_Imagesets'] = $filename . "$SID&amp;mode=editimageset";

	return;
}

define('IN_PHPBB', 1);
//
// Include files
//
$phpbb_root_path = '../';
require($phpbb_root_path . 'extension.inc');
require('pagestart.' . $phpEx);

//
// Do we have styles admin permissions?
//
if ( !$acl->get_acl_admin('styles') )
{
	message_die(MESSAGE, $lang['No_admin']);
}

/*
$dp = opendir($phpbb_root_path . 'templates/cache/');
while ( $file = readdir($dp) )
{
	if ( !is_file($phpbb_root_path . 'templates/cache/' . $file) && !is_link($phpbb_root_path . 'templates/cache/' . $file) && $file != '.' && $file != '..' )
	{
		$selected = ( $tplroot == $file ) ? ' selected="selected"' : '';
		$tplroot_options .= '<option name="' . $file . '"' . $selected . '>' . $file . '</option>';
	}
}
closedir($dp);
*/

//
//
//
$mode = ( isset($HTTP_GET_VARS['mode']) ) ? $HTTP_GET_VARS['mode'] : $HTTP_POST_VARS['mode'];

if ( $mode == 'editimageset' )
{
	$imgroot = ( isset($HTTP_POST_VARS['imgroot']) ) ? $HTTP_POST_VARS['imgroot']  : 'subSilver';

	if ( isset($HTTP_POST_VARS['img_root']) )
	{
		$sql = "SELECT * 
			FROM " . STYLES_IMAGE_TABLE . " 
			WHERE imageset_path LIKE '" . $HTTP_POST_VARS['imgroot'] . "'";
		$result = $db->sql_query($sql);

		$images = $db->sql_fetchrow($result);
	}
	if ( isset($HTTP_POST_VARS['img_addconfig']) )
	{
	}
	else if ( isset($HTTP_POST_VARS['img_addlocal']) )
	{
	}

	$imageset = array('imageset_path', 'post_new', 'post_locked', 'post_pm', 'reply_new', 'reply_pm', 'reply_locked', 'icon_profile', 'icon_pm', 'icon_delete', 'icon_ip', 'icon_quote', 'icon_search', 'icon_edit', 'icon_email', 'icon_www', 'icon_icq', 'icon_aim', 'icon_yim', 'icon_msnm', 'icon_no_email', 'icon_no_www', 'icon_no_icq', 'icon_no_aim', 'icon_no_yim', 'icon_no_msnm', 'goto_post', 'goto_post_new', 'goto_post_latest', 'goto_post_newest', 'forum', 'forum_new', 'forum_locked', 'folder', 'folder_new', 'folder_hot', 'folder_hot_new', 'folder_locked', 'folder_locked_new', 'folder_sticky', 'folder_sticky_new', 'folder_announce', 'folder_announce_new', 'topic_watch', 'topic_unwatch', 'poll_left', 'poll_center', 'poll_right', 'rating');

	$sql = "SELECT imageset_name, imageset_path
		FROM " . STYLES_IMAGE_TABLE . " 
		ORDER BY imageset_name";
	$result = $db->sql_query($sql);

	$imgroot_options = '';
	while ( $row = $db->sql_fetchrow($result) )
	{
		$selected = ( $imgroot == $row['imageset_path'] ) ? ' selected="selected"' : '';
		$imgroot_options .= '<option name="' . $row['imageset_path'] . '"' . $selected . '>' . $row['imageset_path'] . '</option>';
	}

	$imgname_options = '';
	$dp = opendir($phpbb_root_path . 'imagesets/' . $imgroot . '/');
	while ( $file = readdir($dp) )
	{
		if ( preg_match('#\.(gif|png|jpg|jpeg)$#', $file) && is_file($phpbb_root_path . 'imagesets/' . $imgroot . '/' . $file) )
		{
			$selected = ( $imgname == $file ) ? ' selected="selected"' : '';
			$imgname_options .= '<option value="' . $file . '"' . $selected . '>' . $file . '</option>';
		}
	}
	closedir($dp);

	//
	// Output page
	//
	page_header($lang['Styles']);

	echo '<form method="post" action="admin_styles.' . $phpEx . '?mode=editimageset">';

	echo '<h2>Edit Imageset</h2>';

	echo '<p>Template set: <select name="imgroot">' . $imgroot_options . '</select>&nbsp; <input class="liteoption" type="submit" name="img_root" value="Select" /></p>';

	echo '<p>Use this panel to edit or remove imagesets from the database.</p>';

	echo '<table cellspacing="1" cellpadding="2" border="0" align="center" bgcolor="#98AAB1">';
	echo '<tr>';
	echo '<td class="cat" colspan="6" height="28" align="center"><span class="gen">Available images: <select name="imageset">' . $imgname_options . '</select></span></td>';
	echo '</tr>';
	echo '<tr>';
	echo '<th height="25">Image</th><th>Source</th><th>Width</th><th>Height</th><th>Border</th><th>&nbsp;</th>';
	echo '</tr>';
	
	for($i = 0; $i < count($imageset); $i++)
	{
		$class = ( !($i%2) ) ? 'row1' : 'row2';

		echo '<tr>';
		echo '<td class="' . $class . '" height="25"><span class="gen">' . ucfirst(str_replace('_', ' ', $imageset[$i])) . '</span></td>';
		echo '<td class="' . $class . '"><input class="text" type="text" name="src[' . $imageset[$i] . ']" value="' . ( ( !empty($images[$imageset[$i]]) ) ? $images[$imageset[$i]] : '' ) . '" size="20" maxsize="30" /></td>';
		echo '<td class="' . $class . '"><input class="text" type="text" name="width[' . $imageset[$i] . ']" size="3" maxsize="3" /></td>';
		echo '<td class="' . $class . '"><input class="text" type="text" name="height[' . $imageset[$i] . ']" size="3" maxsize="3" /></td>';
		echo '<td class="' . $class . '"><input class="text" type="text" name="border[' . $imageset[$i] . ']" size="2" maxsize="2" /></td>';
		echo '<td class="' . $class . '"><input class="liteoption" type="submit" value="Update" onclick="this.form.' . $imageset[$i] . '.value=this.form.imageset.options[this.form.imageset.selectedIndex].value;return false" />&nbsp;<input class="liteoption" type="submit" value="Clear" onclick="this.form.' . $imageset[$i] . '.value=\'\';return false" />&nbsp;</td>';
		echo '</tr>';
	}

	echo '<td class="cat" colspan="6" height="28" align="center"><input class="liteoption" type="submit" name="img_update" value="Update set" /> &nbsp; <input class="liteoption" type="submit" name="img_delete" value="Delete set" /> &nbsp; <input class="liteoption" type="reset" value="Undo" /></td>';
	echo '</tr>';
	echo '</table>';
	echo '</form>';

}
else if ( $mode == 'edittemplate' )
{
	$tplcols = ( isset($HTTP_POST_VARS['tplcols']) ) ? max(60, intval($HTTP_POST_VARS['tplcols'])) : 76;
	$tplrows = ( isset($HTTP_POST_VARS['tplrows']) ) ? max(4, intval($HTTP_POST_VARS['tplrows'])) : 30;
	$tplname = ( isset($HTTP_POST_VARS['tplname']) ) ? $HTTP_POST_VARS['tplname']  : '';
	$tplroot = ( isset($HTTP_POST_VARS['tplroot']) ) ? $HTTP_POST_VARS['tplroot']  : 'subSilver';

	$str = '';
	if ( isset($HTTP_POST_VARS['tpl_compile']) && !empty($HTTP_POST_VARS['decompile']) )
	{
		$str = "<?php\n" . $template->compile(stripslashes($HTTP_POST_VARS['decompile'])) . "\n?".">";

		$fp = fopen($phpbb_root_path . 'templates/cache/' . $tplroot . '/' . $tplname . '.html.' . $phpEx, 'w+');
		fwrite ($fp, $str);
		fclose($fp);

		@chmod($phpbb_root_path . 'templates/cache/' . $tplroot . '/' . $tplname . '.html.' . $phpEx, 0644);

		add_admin_log('log_template_edit', $tplname, $tplroot);

		exit;
	}
	else if ( !empty($tplname) && isset($HTTP_POST_VARS['tpl_name']) )
	{
		$fp = fopen($phpbb_root_path . 'templates/cache/' . $tplroot . '/' . $tplname . '.html.' . $phpEx, 'r');
		while ( !feof($fp) )
		{
			$str .= fread($fp, 4096);
		}
		@fclose($fp);

		$template->decompile($str);
	}
	else
	{
		$str = ( !empty($HTTP_POST_VARS['decompile']) ) ? stripslashes($HTTP_POST_VARS['decompile']) : '';
	}

	if ( isset($HTTP_POST_VARS['tpl_download']) )
	{
		header("Content-Type: text/html; name=\"" . $tplname . ".html\"");
		header("Content-disposition: attachment; filename=" . $tplname . ".html");
		echo $str;
		exit;

	}

	$tplroot_options = get_templates($tplroot);

	$tplname_options = '';
	$dp = opendir($phpbb_root_path . 'templates/cache/' . $tplroot . '/');
	while ( $file = readdir($dp) )
	{
		if ( strstr($file, '.html.' . $phpEx) && is_file($phpbb_root_path . 'templates/cache/' . $tplroot . '/' . $file) )
		{
			$tpl = substr($file, 0, strpos($file, '.'));
			$selected = ( $tplname == $tpl ) ? ' selected="selected"' : '';
			$tplname_options .= '<option name="' . $tpl . '"' . $selected . '>' . $tpl . '</option>';
		}
	}
	closedir($dp);

	//
	//
	//
	page_header($lang['Styles']);

	echo '<form method="post" action="admin_styles.' . $phpEx . '?mode=edittemplate">';

	echo '<h2>Edit Template</h2>';

	echo '<p>Use this panel to edit an existing compiled template set. When you have made the required changes you can recompile the template and (or) download it. Please remember that the existing HTML templates are <b>not</b> altered, only the compiled versions are affected. Therefore you should download any altered files if you wish to keep them for future use and for archival purposes.</p>';

	echo '<p>Template set: <select name="tplroot">' . $tplroot_options . '</select>&nbsp; <input class="liteoption" type="submit" name="tpl_root" value="Select" /></p>';

	echo '<table cellspacing="1" cellpadding="0" border="0" align="center" bgcolor="#98AAB1">';
	echo '<tr>';
	echo '<td class="cat"><table width="100%" cellspacing="0" cellpadding="0" border="0">';
	echo '<tr>';
	echo '<td>&nbsp;Template: <select name="tplname">' . $tplname_options . '</select>&nbsp; <input class="liteoption" type="submit" name="tpl_name" value="Select" /></td>';
	echo '<td align="right">Columns: <input type="text" name="tplcols" size="3" maxlength="3" value="' . $tplcols . '" /> &nbsp;Rows: <input type="text" name="tplrows" size="3" maxlength="3" value="' . $tplrows . '" />&nbsp; <input class="liteoption" type="submit" name="tpl_layout" value="Update" />&nbsp;</td>';
	echo '</tr>';
	echo '</table></td>';
	echo '</tr>';
	echo '<tr>';
	echo '<td colspan="2" align="center"><textarea style="background-color:#DEE3E7;font-size:9pt;font-family:Courier;line-height:125%" cols="' .$tplcols . '" rows="' .$tplrows . '" name="decompile">' . htmlentities($str) . '</textarea></td>';
	echo '</tr>';
	echo '<tr>';
	echo '<td class="cat" colspan="2" height="28" align="center"><input class="liteoption" type="submit" name="tpl_compile" value="Recompile" /> &nbsp; <input class="liteoption" type="submit" name="tpl_download" value="Download" /> &nbsp; <input class="liteoption" type="reset" value="Undo" /></td>';
	echo '</tr>';
	echo '</table>';
	echo '</form>';

	page_footer();
}


//
//
//
function get_templates($tplroot = '')
{
	global $db;

	$sql = "SELECT template_name, template_path
		FROM " . STYLES_TPL_TABLE . " 
		ORDER BY template_name";
	$result = $db->sql_query($sql);

	$tplroot_options = '';
	while ( $row = $db->sql_fetchrow($result) )
	{
		$selected = ( $tplroot == $row['template_path'] ) ? ' selected="selected"' : '';
		$tplroot_options .= '<option name="' . $row['template_path'] . '"' . $selected . '>' . $row['template_path'] . '</option>';
	}
	
	return $tplroot_options;
}

?>