diff options
Diffstat (limited to 'phpBB/adm')
| -rw-r--r-- | phpBB/adm/admin_styles.php | 2057 | 
1 files changed, 803 insertions, 1254 deletions
diff --git a/phpBB/adm/admin_styles.php b/phpBB/adm/admin_styles.php index 1c09414652..05832204ca 100644 --- a/phpBB/adm/admin_styles.php +++ b/phpBB/adm/admin_styles.php @@ -100,24 +100,27 @@ foreach (array('tar.gz' => 'zlib', 'tar.bz2' => 'bz2', 'zip' => 'zlib') as $type  // Unified actions -if ($id) +switch ($action)  { -	switch ($action) -	{ -		case 'export': +	case 'export': +		if ($id) +		{  			export($mode, $id); -			break; +		} +		break; -		case 'add': -		case 'install': -		case 'details': -//			install($mode, $action, $id); -			break; +	case 'add': +	case 'install': +	case 'details': +		install($mode, $action, $id); +		break; -		case 'delete': +	case 'delete': +		if ($id) +		{  			remove($mode, $id); -			break; -	} +		} +		break;  } @@ -148,583 +151,7 @@ switch ($mode)  				$db->sql_query($sql);  				break; -			case 'add':  			case 'edit': -			case 'install': -				$style_path = (!empty($_REQUEST['path'])) ? htmlspecialchars($_REQUEST['path']) : ''; -				$root_path = ''; - -				$element_ary = array('template' => STYLES_TPL_TABLE, 'theme' => STYLES_CSS_TABLE, 'imageset' => STYLES_IMAGE_TABLE); -				$phpbbversion = preg_replace('#^2\.([0-9]+?)\.([0-9]+?).*?$#', '\1.\2', $config['version']); - - -				// Importing/uploading then check data and extract archive -				if (!empty($_FILES['upload_file']['name']) || !empty($_POST['import_file'])) -				{ -					if (!empty($_FILES['upload_file']['name'])) -					{ -						$realname = htmlspecialchars($_FILES['upload_file']['name']); -						$filename = htmlspecialchars($_FILES['upload_file']['tmp_name']); - -						if (!is_uploaded_file($filename)) -						{ -							trigger_error("$filename was not uploaded"); -						} -					} -					else -					{ -						$realname = htmlspecialchars($_POST['import_file']); -						$filename = "{$phpbb_root_path}store/$realname"; -					} - -					if (!preg_match('#(' . $archive_preg . ')$#i', $realname, $match)) -					{ -						$error[] = sprintf($user->lang['UPLOAD_WRONG_TYPE'], $archive_types); -					} -					$path = preg_replace('#^(.*?)' . preg_quote($match[0]) . '$#', '\1', $realname); - -					// Attempt to extract the files to a temporary directory in store -					$tmp_path = $phpbb_root_path . 'store/tmp_' . substr(uniqid(''), 0, 10) . '/'; -					if (!@mkdir($tmp_path)) -					{ -						trigger_error("Cannot create $tmp_path", E_USER_ERROR); -					} - -					include($phpbb_root_path . 'includes/functions_compress.'.$phpEx); - -					switch ($match[0]) -					{ -						case '.zip': -							$zip = new compress_zip('r', $filename); -							break; -						default: -							$zip = new compress_tar('r', $filename, $match[0]); -					} -					$zip->extract($tmp_path); -					$zip->close(); - -					unset($cfg); -				} - - -				// Installing, importing/uploading then obtain the style cfg information -				if (($action == 'install' && $style_path) || (!empty($_FILES['upload_file']['name']) || !empty($_POST['import_file']))) -				{ -					$root_path = ($action == 'install') ? "{$phpbb_root_path}styles/$style_path/" : "$tmp_path"; - -					if (!($fp = @fopen("{$root_path}style.cfg", 'rb'))) -					{ -						$error[] = $user->lang['STYLE_ERR_NOT_STYLE']; -					} -					else -					{ -						$stylecfg = explode("\n", fread($fp, filesize("{$root_path}style.cfg"))); -					} -					fclose($fp); -				} - - -				// Installing, importing/uploading then grab the element info else grab the  -				// submitted params ... stylecfg will be set if this is true (see above) -				if (sizeof($stylecfg)) -				{ -					$style_name			= trim($stylecfg[0]); -					$style_copyright	= trim($stylecfg[1]); -					$style_version		= preg_replace('#^2\.([0-9]+?)\.([0-9]+?).*?$#', '\1.\2', trim($stylecfg[2])); -					$reqd_template		= trim($stylecfg[3]); -					$reqd_theme			= trim($stylecfg[4]); -					$reqd_imageset		= trim($stylecfg[5]); - -					// Check to see if each element is already installed, if it is grab the id -					foreach ($element_ary as $element => $table) -					{ -						$l_element = strtoupper($element); - -						if (${'reqd_' . $element}) -						{ -							$sql_where =  "{$element}_name = '" . $db->sql_escape(${'reqd_' . $element}) . "'"; -						} -						else -						{ -							if (!($cfg = @file("$root_path$element/$element.cfg"))) -							{ -								$error[] = sprintf($user->lang['REQUIRES_' . $l_element], ${'reqd_' . $element}); -							} -							${$element . '_name'} = trim($cfg[0]); -							$sql_where = "{$element}_name = '" . $db->sql_escape(${$element . '_name'}) . "'"; -						} - -						if (!sizeof($error)) -						{ -							$sql = "SELECT {$element}_id, {$element}_name   -								FROM $table -								WHERE $sql_where"; -							$result = $db->sql_query($sql); - -							if ($row = $db->sql_fetchrow($result)) -							{ -								${$element . '_name'} = $row[$element . '_name']; -								${$element . '_id'} = $row[$element . '_id']; -							} -							else -							{ -								${$element . '_copyright'} = trim($cfg[1]); -								${$element . '_id'} = 0; -								unset($cfg); -							} -							$db->sql_freeresult($result); -						} -					} - -					$s_hidden_fields = '<input type="hidden" name="path" value="' . $style_path . '" />'; -				} -				else -				{ -					// NOTE: Data here is stripslashed! Ensure it's escaped when entering the DB -					$style_name = (!empty($_POST['name'])) ? stripslashes(htmlspecialchars($_POST['name'])) : ''; -					$style_copyright = (!empty($_POST['copyright'])) ? stripslashes(htmlspecialchars($_POST['copyright'])) : ''; - -					$template_id = (!empty($_POST['template_id'])) ? intval($_POST['template_id']) : 0; -					$theme_id = (!empty($_POST['theme_id'])) ? intval($_POST['theme_id']) : 0; -					$imageset_id = (!empty($_POST['imageset_id'])) ? intval($_POST['imageset_id']) : 0; - -					if (!empty($_POST['basis'])) -					{ -						$basis = intval($_POST['basis']); - -						$sql = 'SELECT template_id, theme_id, imageset_id  -							FROM ' . STYLES_TABLE . "  -							WHERE style_id = $basis"; -						$result = $db->sql_query($sql); - -						if (!extract($db->sql_fetchrow($result)))  -						{ -							$error[] = $user->lang['NO_STYLE']; -						} -						$db->sql_freeresult($result); -					} -				} - -				// Common params -				$style_active = (isset($_POST['style_active'])) ? ((!empty($_POST['style_active'])) ? 1 : 0) : 1; -				$style_default = (isset($_POST['style_default'])) ? ((!empty($_POST['style_default'])) ? 1 : 0) : (($config['default_style'] == $id) ? 1 : 0); - -				// User has submitted form and no errors have occured -				if ($update && !sizeof($error)) -				{ -					// We're installing/uploading/importing -					if (sizeof($stylecfg)) -					{ -						foreach ($element_ary as $element => $table) -						{ -							// Zero id value ... need to install element ... run usual checks -							// and do the install if necessary -							if (!${$element . '_id'}) -							{ -								$l_element = strtoupper($element); - -								if (empty(${$element . '_name'})) -								{ -									$error[] = $user->lang[$l_element . '_ERR_STYLE_NAME']; -								} - -								if (strlen(${$element . '_name'}) > 30) -								{ -									$error[] = $user->lang[$l_element . '_ERR_NAME_LONG']; -								} - -								if (!preg_match('#^[a-z0-9_\-\+\. ]+$#i', ${$element . '_name'})) -								{ -									$error[] = $user->lang[$l_element . '_ERR_NAME_CHARS']; -								} - -								if (strlen(${$element . '_copyright'}) > 60) -								{ -									$error[] = $user->lang[$l_element . '_ERR_COPY_LONG']; -								} - -								if (!sizeof($error)) -								{ -									switch ($element) -									{ -										case 'template': -											$template_path = str_replace(' ', '_', $template_name); - -											if ($action != 'install') -											{ -												@mkdir("{$phpbb_root_path}styles/$template_path", 0777); -												@chmod("{$phpbb_root_path}styles/$template_path", 0777); -												copy_files("{$root_path}template", filelist("{$root_path}template", '', '*'), "$template_path/template"); -											} - -											$template_storedb = (!is_writeable("{$phpbb_root_path}styles/$template_path/template")) ? 1 : 0; - -											$sql_ary = array( -												'template_name'			=> $template_name, -												'template_copyright'	=> $template_copyright,  -												'template_path'			=> $template_path,  -												'template_storedb'		=> $template_storedb -											); - -											$db->sql_transaction('begin'); - -											$sql = 'INSERT INTO ' . STYLES_TPL_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary); - -											$db->sql_query($sql); - -											$template_id = $db->sql_nextid(); - -											if ($template_storedb)  -											{ -												$filelist = filelist("{$root_path}template", '', 'html'); -												store_templates('insert', $template_id, $style_path, $filelist); -											} - -											$db->sql_transaction('commit'); - -											$log = ($template_storedb) ? 'LOG_ADD_TEMPLATE_FS' : 'LOG_ADD_TEMPLATE_DB'; -											add_log('admin', $log, $template_name); -											break; - -										case 'theme': -											$theme_path = str_replace(' ', '_', $theme_name); - -											if ($action != 'install') -											{ - -												@mkdir("{$phpbb_root_path}styles/$theme_path", 0777); -												@chmod("{$phpbb_root_path}/$theme_path", 0777); -												copy_files("{$root_path}theme", filelist("{$root_path}theme", '', '*'), "$theme_path/theme"); -											} - -											$theme_storedb = 0; -											if (!is_writeable("{$phpbb_root_path}styles/$theme_path/theme/stylesheet.css")) -											{ -												$theme_data = str_replace('./', "styles/$theme_path/theme/", implode('', file("$root_path/theme/stylesheet.css"))); -												$theme_storedb = 1; -											} - -											$sql_ary = array( -												'theme_name'		=> $theme_name, -												'theme_copyright'	=> $theme_copyright,  -												'theme_path'		=> $theme_path,  -												'theme_storedb'		=> $theme_storedb,  -												'theme_data'		=> ($theme_storedb) ?  $theme_data : '',  -												'theme_mtime'		=> ($theme_storedb) ? filemtime("{$phpbb_root_path}styles/$theme_path/theme/stylesheet.css") : 0  -											); - -											$sql = 'INSERT INTO ' . STYLES_CSS_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary); -											$db->sql_query($sql); - -											$theme_id = $db->sql_nextid(); - -											$log = ($theme_storedb) ? 'LOG_ADD_THEME_DB' : 'LOG_ADD_THEME_FS'; -											add_log('admin', $log, $theme_name); -											break; - -										case 'imageset': -											$imageset_path = str_replace(' ', '_', $imageset_name); - -											if ($action != 'install') -											{ - -												@mkdir("{$phpbb_root_path}styles/$imageset_path", 0777); -												@chmod("{$phpbb_root_path}styles/$imageset_path", 0777); -												copy_files("{$root_path}imageset", filelist("{$root_path}imageset", '', '*'), "$imageset_path/imageset"); -											} - -											$cfg = file("{$phpbb_root_path}styles/$imageset_path/imageset/imageset.cfg"); - -											$sql_img_ary = array(); -											for ($i = 3; $i < sizeof($cfg); $i++) -											{ -												$tmp = explode('||', $cfg[$i]); -												$sql_img_ary[$tmp[0]] = str_replace('{PATH}', "styles/$imageset_path/imageset/", trim($tmp[1])); -											} - -											$sql_ary = array( -												'imageset_name'			=> $imageset_name, -												'imageset_copyright'	=> $imageset_copyright,  -												'imageset_path'			=> $imageset_path,  -											); -											$sql_ary += $sql_img_ary; - -											$sql = 'INSERT INTO ' . STYLES_IMAGE_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary); -											$db->sql_query($sql); - -											$imageset_id = $db->sql_nextid(); - -											add_log('admin', 'LOG_ADD_IMAGESET', $imageset_name); -											break; -									} -								} -							} -						} -					} - -					if (!sizeof($error)) -					{ -						if ($action != 'edit' && empty($style_name)) -						{ -							$error[] = $user->lang['STYLE_ERR_STYLE_NAME']; -						} - -						if ($action != 'edit' && strlen($style_name) > 30) -						{ -							$error[] = $user->lang['STYLE_ERR_NAME_LONG']; -						} - -						if ($action != 'edit' && !preg_match('#^[a-z0-9_\-\+\. ]+$#i', $style_name)) -						{ -							$error[] = $user->lang['STYLE_ERR_NAME_CHARS']; -						} - -						if ($action != 'edit' && strlen($style_copyright) > 60) -						{ -							$error[] = $user->lang['STYLE_ERR_COPY_LONG']; -						} - -						if (!$template_id || !$theme_id || !$imageset_id) -						{ -							$error[] = $user->lang['STYLE_ERR_NO_IDS']; -						} - -						$sql_where = ($action != 'edit') ? "style_name = '" . $db->sql_escape($style_name) . "'" : "style_id = $id"; -						$sql = 'SELECT style_name  -							FROM ' . STYLES_TABLE . "  -							WHERE $sql_where"; -						$result = $db->sql_query($sql); - -						if (extract($db->sql_fetchrow($result)) && $action != 'edit') -						{ -							$error[] = $user->lang['STYLE_ERR_NAME_EXIST']; -						} -						$db->sql_freeresult($result); - - -						if (!sizeof($error)) -						{ -							$sql_ary = array( -								'template_id'		=> $template_id,  -								'theme_id'			=> $theme_id,  -								'imageset_id'		=> $imageset_id,  -								'style_active'		=> $style_active,  -							); -							if ($action != 'edit') -							{ -								$sql_ary += array( -									'style_name'		=> $style_name,  -									'style_copyright'	=> $style_copyright,  -								); -							} - -							$sql = ($action != 'edit') ? 'INSERT INTO ' . STYLES_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary) : 'UPDATE ' . STYLES_TABLE . ' SET ' . $db->sql_build_array('UPDATE', $sql_ary) . " WHERE style_id = $id"; -							$db->sql_query($sql); - -							if ($action != 'edit') -							{ -								$id = $db->sql_nextid(); -							} - -							if ($style_default) -							{ -								set_config('default_style', $id); -							} - -							if ($tmp_path) -							{ -								cleanup_folder($tmp_path); -							} - -							$log = ($action != 'edit') ? 'LOG_ADD_STYLE' : 'LOG_EDIT_STYLE'; -							add_log('admin', $log, $style_name); - -							$message = ($action != 'edit') ? 'STYLE_ADDED' : 'STYLE_EDITED'; -							trigger_error($user->lang[$message]); -						} -					} -				} - -				// Something went wrong ... so we'll clean up any decompressed uploaded/imported -				// archives. -				if ($tmp_path) -				{ -					cleanup_folder($tmp_path); -				} - -				// Either an error occured or the user has just entered the form -				if (!sizeof($error) && !$update && $id) -				{ -					$sql = 'SELECT *  -						FROM ' . STYLES_TABLE . " -						WHERE style_id = $id"; -					$result = $db->sql_query($sql); - -					if (!extract($db->sql_fetchrow($result))) -					{ -						trigger_error($user->lang['NO_STYLE']); -					} -					$db->sql_freeresult($result); - -					$style_default = ($config['default_style'] == $id) ? 1 : 0; -				} - -				if ($action != 'install') -				{ -					$style_options = array(); -					foreach ($element_ary as $element => $table) -					{ -						$sql = "SELECT {$element}_id, {$element}_name -							FROM $table  -							ORDER BY {$element}_id ASC"; -						$result = $db->sql_query($sql); - -						while ($row = $db->sql_fetchrow($result)) -						{ -							$selected = ($row[$element . '_id'] == ${$element . '_id'}) ? ' selected="selected"' : ''; -							${$element . '_options'} .= '<option value="' . $row[$element . '_id'] . '"' . $selected . '>' . $row[$element . '_name'] . '</option>'; -						} -						$db->sql_freeresult($result); -					} -				} - -				$active_yes = ($style_active) ? ' checked="checked"' : ''; -				$active_no = (!$style_active) ? ' checked="checked"' : ''; -				$style_default_yes = ($style_default) ? ' checked="checked"' : ''; -				$style_default_no = (!$style_default) ? ' checked="checked"' : ''; - -				$l_prefix = strtoupper($action); - -				// Output the page -				adm_page_header($user->lang[$l_prefix . '_STYLE']); - -?> - -<h1><?php echo $user->lang[$l_prefix . '_STYLE']; ?></h1> - -<p><?php echo $user->lang[$l_prefix . '_STYLE_EXPLAIN']; ?></p> - -<form name="style" method="post" action="<?php echo "admin_styles.$phpEx$SID&mode=$mode&action=$action&id=$id"; ?>"<?php echo (!$safe_mode && is_writeable("{$phpbb_root_path}styles")) ? ' enctype="multipart/form-data"' : ''; ?>><table class="bg" width="95%" cellspacing="1" cellpadding="4" border="0" align="center"> -	<tr> -		<th colspan="2"><?php echo $user->lang[$l_prefix . '_STYLE']; ?></th> -	</tr> -<?php -				if (sizeof($error)) -				{ - -?> -	<tr> -		<td colspan="2" class="row3" align="center"><span style="color:red"><?php echo implode('<br />', $error); ?></span></td> -	</tr> -<?php - -				} - -?> -	<tr> -		<td class="row1"><b><?php echo $user->lang['STYLE_NAME']; ?>:</b></td> -		<td class="row2"><?php -	 -				echo ($action == 'add') ? '<input class="post" type="text" name="name" maxlength="30" size="30" value="' . $style_name . '" />' : '<b>' . $style_name . '</b>'; - -?></td> -	</tr> -	<tr> -		<td class="row1"><b><?php echo $user->lang['STYLE_COPYRIGHT']; ?>:</b></td> -		<td class="row2"><?php -	 -				echo ($action == 'add') ? '<input class="post" type="text" name="copyright" maxlength="60" size="30" value="' . $style_copyright . '" />' : '<b>' . $style_copyright . '</b>'; - -?></td> -	</tr> -	<tr> -		<td class="row1"><b><?php echo $user->lang['STYLE_TEMPLATE']; ?>:</b></td> -		<td class="row2"><?php -	 -		echo ($action == 'install') ? "<b>$template_name</b>" : '<select name="template_id">' . $template_options . '</select>'; - -?></td> -	</tr> -	<tr> -		<td class="row1"><b><?php echo $user->lang['STYLE_THEME']; ?>:</b></td> -		<td class="row2"><?php -	 -		echo ($action == 'install') ? "<b>$theme_name</b>" : '<select name="theme_id">' . $theme_options . '</select>'; - -?></td> -	</tr> -	<tr> -		<td class="row1"><b><?php echo $user->lang['STYLE_IMAGESET']; ?>:</b></td> -		<td class="row2"><?php -	 -		echo ($action == 'install') ? "<b>$imageset_name</b>" : '<select name="imageset_id">' . $imageset_options . '</select>'; - -?></td> -	</tr> -<?php - -				// Import, upload and basis options -				if (($action == 'add' || $action == 'import') && !$safe_mode && is_writeable("{$phpbb_root_path}styles")) -				{ -					$store_options = ''; -					$dp = opendir("{$phpbb_root_path}store"); -					while ($file = readdir($dp)) -					{ -						if ($file{0} != '.' && preg_match('#(' . $archive_preg . ')$#i', $file)) -						{ -							$store_options .= "<option value=\"$file\">$file</option>"; -						} -					} -					closedir($dp); - -					$store_options = '<option value="">' . $user->lang['NO_IMPORT'] . '</option>' . $store_options; - -?> -	<tr> -		<th colspan="2"><?php echo $user->lang['EXISTING_STYLE']; ?></th> -	</tr> -	<tr> -		<td class="row1" width="40%"><b><?php echo $user->lang['STYLE_UPLOAD_BASIS']; ?>:</b><br /><span class="gensmall"><?php echo $user->lang['ALLOWED_FILETYPES']; ?>: <?php echo $archive_types; ?></span></td> -		<td class="row2"><input class="post" type="file" name="upload_file" /><input type="hidden" name="MAX_FILE_SIZE" value="1048576" /></td> -	</tr> -	<tr> -		<td class="row1" width="40%"><b><?php echo $user->lang['STYLE_IMPORT_BASIS']; ?>:</b></td> -		<td class="row2"><select name="import_file"><?php echo $store_options; ?></select></td> -	</tr> -<?php - -				}	 -?> -	<tr> -		<th colspan="2"> </th> -	</tr> -	<tr> -		<td class="row1"><b><?php echo $user->lang['STYLE_ACTIVE']; ?>:</b></td> -		<td class="row2"><input type="radio" name="style_active" value="1"<?php echo $active_yes; ?> /> <?php echo $user->lang['YES']; ?>   <input type="radio" name="style_active" value="0"<?php echo $active_no; ?> /> <?php echo $user->lang['NO']; ?></td> -	</tr> -<?php - -				if ($id != $config['default_style']) -				{ - -?> -	<tr> -		<td class="row1"><b><?php echo $user->lang['STYLE_DEFAULT']; ?>:</b></td> -		<td class="row2"><input type="radio" name="style_default" value="1"<?php echo $style_default_yes; ?> /> <?php echo $user->lang['YES']; ?>   <input type="radio" name="style_default" value="0"<?php echo $style_default_no; ?> /> <?php echo $user->lang['NO']; ?></td> -	</tr> -<?php - -				} - -?> -	<tr> -		<td class="cat" colspan="2" align="center"><input class="btnmain" type="submit" name="update" value="<?php echo $user->lang['SUBMIT']; ?>" />  <input class="btnlite" type="reset" value="<?php echo $user->lang['RESET']; ?>" /><?php echo $s_hidden_fields; ?></td> -	</tr> -</table></form> -<?php - -				adm_page_footer(); -				break;  		} @@ -762,7 +189,7 @@ switch ($mode)  		$result = $db->sql_query($sql);  		$installed = array(); -		$basis_options = ''; +		$basis_options = '<option class="sep" value="">' . $user->lang['OPTIONAL_BASIS'] . '</option>';  		while ($row = $db->sql_fetchrow($result))  		{  			$installed[] = strtolower($row['style_name']); @@ -774,7 +201,7 @@ switch ($mode)  ?>  	<tr> -		<td class="<?php echo $row_class; ?>" width="100%"><a href="<?php echo "admin_styles.$phpEx$SID&mode=$mode&action=edit&id=" . $row['style_id']; ?>"><?php echo $row['style_name']; ?></a><?php echo ($config['default_style'] == $row['style_id']) ? ' *' : ''; ?></td> +		<td class="<?php echo $row_class; ?>" width="100%"><a href="<?php echo "admin_styles.$phpEx$SID&mode=$mode&action=details&id=" . $row['style_id']; ?>"><?php echo $row['style_name']; ?></a><?php echo ($config['default_style'] == $row['style_id']) ? ' *' : ''; ?></td>  		<td class="<?php echo $row_class; ?>" align="center" nowrap="nowrap"><?php echo (!empty($style_count[$row['style_id']])) ? $style_count[$row['style_id']] : '0'; ?></td>  		<td class="<?php echo $row_class; ?>" align="center" nowrap="nowrap"> <a href="<?php echo "admin_styles.$phpEx$SID&mode=$mode&action=$stylevis&id=" . $row['style_id']; ?>"><?php echo $user->lang['STYLE_' . strtoupper($stylevis)]; ?></a> </td>  		<td class="<?php echo $row_class; ?>" align="center" nowrap="nowrap"> <a href="<?php echo "admin_styles.$phpEx$SID&mode=$mode&action=delete&id=" . $row['style_id']; ?>"><?php echo $user->lang['DELETE']; ?></a> </td> @@ -840,7 +267,7 @@ switch ($mode)  ?>  <tr> -		<td class="cat" colspan="6" align="right"><?php echo $user->lang['CREATE_STYLE']; ?>: <input class="post" type="text" name="name" value="" maxlength="30" size="25" /> <?php echo $user->lang['FROM']; ?> <select name="basis"><?php echo '<option class="sep" value="">' . $user->lang['OPTIONAL_BASIS'] . '</option>' . $basis_options; ?></select> <input class="btnmain" type="submit" name="add" value="<?php echo $user->lang['SUBMIT']; ?>" /></td> +		<td class="cat" colspan="6" align="right"><?php echo $user->lang['CREATE_STYLE']; ?>: <input class="post" type="text" name="name" value="" maxlength="30" size="25" /> <?php echo $user->lang['FROM']; ?> <select name="basis"><?php echo $basis_options; ?></select> <input class="btnmain" type="submit" name="add" value="<?php echo $user->lang['SUBMIT']; ?>" /></td>  	</tr>  </table></form>  <?php  @@ -896,7 +323,7 @@ switch ($mode)  			case 'edit':  				$tplcols = (isset($_POST['tplcols'])) ? max(20, intval($_POST['tplcols'])) : 80;  				$tplrows = (isset($_POST['tplrows'])) ? max(5, intval($_POST['tplrows'])) : 20; -				$tplname = (isset($_POST['tplname'])) ? $_POST['tplname']  : ''; +				$tplname = (isset($_POST['tplname'])) ? htmlspecialchars($_POST['tplname'])  : '';  				$tpldata = (!empty($_POST['tpldata'])) ? stripslashes($_POST['tpldata']) : ''; // NB : STRIPSLASHED!  				if ($template_id) @@ -1364,13 +791,6 @@ function viewsource(url)  					}  				}  				break; - -			case 'add': -			case 'details': -			case 'install': -				details('template', $mode, $action, $template_id); -				exit; -				break;  		}  		// Front page @@ -1650,7 +1070,7 @@ function viewsource(url)  				{  					foreach ($img_ary as $img)  					{ -						$img = substr($path, 1) . (($path != '') ? '/' : '') . $img;  +						$img = ((substr($path, 0, 1) == '/') ? substr($path, 1) : $path) . $img;   						$selected = (preg_match('#' . preg_quote($img) . '$#', $background_image)) ? ' selected="selected"' : '';  						$bg_imglist .= '<option value="' . htmlspecialchars($img) . '"' . $selected . '>' . $img . '</option>'; @@ -1871,13 +1291,6 @@ function csspreview()  				adm_page_footer();  				break; - -			case 'add': -			case 'details': -			case 'install': -				details('theme', $mode, $action, $id); -				exit; -				break;  		}  		// Front page @@ -1932,18 +1345,6 @@ function csspreview()  						}  					} -					$dp = @opendir("{$phpbb_root_path}styles/$imageset_path/imageset/"); -					while ($file = readdir($dp)) -					{ -						if (is_file("{$phpbb_root_path}styles/$imageset_path/imageset/$file")) -						{ -							if (!in_array($file, $test_ary)) -							{ -								$imglist['custom'][] = $file; -							} -						} -					} -					closedir($dp);  					unset($matches);  					unset($test_ary); @@ -1972,7 +1373,7 @@ function csspreview()  				{  					foreach ($img_ary as $img)  					{ -						$img = substr($path, 1) . (($path != '') ? '/' : '') . $img;  +						$img = ((substr($path, 0, 1) == '/') ? substr($path, 1) : $path) . $img;   						$selected = (preg_match('#' . preg_quote($img) . '$#', $background_image)) ? ' selected="selected"' : '';  						$imagesetlist_options .= '<option value="' . htmlspecialchars($img) . '"' . $selected . '>' . $img . '</option>'; @@ -2025,13 +1426,6 @@ function csspreview()  				adm_page_footer();  				break; - -			case 'add': -			case 'details': -			case 'install': -				details('imageset', $mode, $action, $id); -				exit; -				break;  		}  		// Front page @@ -2052,15 +1446,13 @@ function frontend($type, $options)  	switch ($type)  	{  		case 'template': -			$table = STYLES_TPL_TABLE; +			$sql_from = STYLES_TPL_TABLE;  			break; -  		case 'theme': -			$table = STYLES_CSS_TABLE; +			$sql_from = STYLES_CSS_TABLE;  			break; -  		case 'imageset': -			$table = STYLES_IMAGE_TABLE; +			$sql_from = STYLES_IMAGE_TABLE;  			break;  	} @@ -2085,11 +1477,11 @@ function frontend($type, $options)  <?php  	$sql = "SELECT {$type}_id, {$type}_name, {$type}_path  -		FROM $table"; +		FROM $sql_from";  	$result = $db->sql_query($sql);  	$installed = array(); -	$basis_options = ''; +	$basis_options = '<option class="sep" value="">' . $user->lang['OPTIONAL_BASIS'] . '</option>';  	while ($row = $db->sql_fetchrow($result))  	{  		$installed[] = $row[$type . '_name']; @@ -2154,7 +1546,7 @@ function frontend($type, $options)  ?>  	<tr>  		<td class="<?php echo $row_class; ?>"><?php echo $cfg['name']; ?></td> -		<td class="<?php echo $row_class; ?>" colspan="<?php echo sizeof($options); ?>" align="center"><a href="<?php echo "admin_styles.$phpEx$SID&mode=$mode&action=install&name=" . urlencode($cfg['path']); ?>"><?php echo $user->lang['INSTALL']; ?></a></td> +		<td class="<?php echo $row_class; ?>" colspan="<?php echo sizeof($options); ?>" align="center"><a href="<?php echo "admin_styles.$phpEx$SID&mode=$mode&action=install&path=" . urlencode($cfg['path']); ?>"><?php echo $user->lang['INSTALL']; ?></a></td>  	</tr>  <?php @@ -2174,7 +1566,7 @@ function frontend($type, $options)  ?>  	<tr> -		<td class="cat" colspan="<?php echo sizeof($options) + 1; ?>" align="right"><?php echo $user->lang['CREATE_' . $l_prefix]; ?>: <input class="post" type="text" name="<?php echo $type; ?>_name" value="" maxlength="30" size="25" /> <input class="btnmain" type="submit" name="add" value="<?php echo $user->lang['SUBMIT']; ?>" /></td> +		<td class="cat" colspan="<?php echo sizeof($options) + 1; ?>" align="right"><?php echo $user->lang['CREATE_' . $l_prefix]; ?>: <input class="post" type="text" name="name" value="" maxlength="30" size="25" /> <?php echo $user->lang['FROM']; ?> <select name="basis"><?php echo $basis_options; ?></select> <input class="btnmain" type="submit" name="add" value="<?php echo $user->lang['SUBMIT']; ?>" /></td>  	</tr>  </table></form> @@ -2195,22 +1587,19 @@ function remove($type, $id)  	switch ($type)  	{  		case 'style': -			$table = STYLES_TABLE; +			$sql_from = STYLES_TABLE;  			$sql_select = 'style_name';  			break; -  		case 'template': -			$table = STYLES_TPL_TABLE; +			$sql_from = STYLES_TPL_TABLE;  			$sql_select = 'template_name, template_path, template_storedb';  			break; -  		case 'theme': -			$table = STYLES_CSS_TABLE; +			$sql_from = STYLES_CSS_TABLE;  			$sql_select = 'theme_name, theme_path, theme_storedb';  			break; -  		case 'imageset': -			$table = STYLES_IMAGE_TABLE; +			$sql_from = STYLES_IMAGE_TABLE;  			$sql_select = 'imageset_name, imageset_path';  			break;  	} @@ -2218,7 +1607,7 @@ function remove($type, $id)  	$l_prefix = strtoupper($type);  	$sql = "SELECT $sql_select -		FROM $table  +		FROM $sql_from   		WHERE {$type}_id = $id";  	$result = $db->sql_query($sql); @@ -2231,7 +1620,7 @@ function remove($type, $id)  	$storedb = (isset(${$type . '_storedb'})) ? ${$type . '_storedb'} : false;  	$sql = "SELECT {$type}_id, {$type}_name  -		FROM $table   +		FROM $sql_from    		WHERE {$type}_id <> $id   		ORDER BY {$type}_id";  	$result = $db->sql_query($sql); @@ -2250,7 +1639,7 @@ function remove($type, $id)  	if ($update)  	{ -		$sql = "DELETE FROM $table  +		$sql = "DELETE FROM $sql_from   			WHERE {$type}_id = $id";  		$db->sql_query($sql); @@ -2264,7 +1653,7 @@ function remove($type, $id)  		}  		else  		{ -			$sql = "UPDATE $table  +			$sql = "UPDATE $sql_from   				SET {$type}_id = $new_id   				WHERE {$type}_id = $id";  			$db->sql_query($sql); @@ -2320,7 +1709,7 @@ function remove($type, $id)  	</tr>  <?php -	if ($type != 'style' && !$storedb && is_writeable("{$phpbb_root_path}styles/$path/{$type}")) +	if ($type != 'style' && !$storedb && is_writeable("{$phpbb_root_path}styles/$path/$type"))  	{  ?> @@ -2826,19 +2215,11 @@ function copy_files($src, $filelist, $dst)  		{  			if (!file_exists("{$phpbb_root_path}styles/$dst$filepath$file"))  			{ -				@rename("$src$filepath$file", "{$phpbb_root_path}styles/$dst$filepath$file"); +				@copy("$src$filepath$file", "{$phpbb_root_path}styles/$dst$filepath$file");  				@chmod("{$phpbb_root_path}styles/$dst$filepath$file", 0777);  			}  		} - -		if ($filepath && file_exists("$src$filepath")) -		{ -			@rmdir("$src$filepath"); -		}  	} - -	@rmdir("$src/$dst"); -	@rmdir($src);  }  function cleanup_folder($path) @@ -2860,665 +2241,613 @@ function cleanup_folder($path)  	}  	@rmdir("$path");  } -// -// FUNCTIONS -// --------- - - -// Hopefully temporary -function theme_preview(&$path, &$stylesheet, &$class, &$css_element) +function test_installed($element, $root_path, $reqd_name, &$id, &$name, &$copyright)  { -	global $config, $user; - -?> -<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> -<html dir="<?php echo $user->lang['LTR']; ?>"> -<head> -<meta http-equiv="Content-Type" content="text/html; charset=<?php echo $user->lang['ENCODING']; ?>"> -<meta http-equiv="Content-Style-Type" content="text/css"> -<style type="text/css"> -<!-- -<?php +	global $db, $user; +	switch ($element) +	{ +		case 'template': +			$sql_from = STYLES_TPL_TABLE; +			break; +		case 'theme': +			$sql_from = STYLES_CSS_TABLE; +			break; +		case 'imageset': +			$sql_from = STYLES_IMAGE_TABLE; +			break; +	} -	$updated_element = implode('; ', $css_element) . ';'; +	$l_element = strtoupper($element); -	if (preg_match('#^' . $class . ' {(.*?)}#m', $stylesheet)) +	if ($reqd_name)  	{ -		$stylesheet = preg_replace('#^(' . $class . ' {).*?(})#m', '\1 ' . $updated_element . ' \2', $stylesheet); +		$sql_where =  "{$element}_name = '" . $db->sql_escape($reqd_name) . "'"; +	} +	else +	{ +		if (!($cfg = @file("$root_path$element/$element.cfg"))) +		{ +			return sprintf($user->lang['REQUIRES_' . $l_element], $reqd_name); +		} +		$name = trim($cfg[0]); +		$sql_where = "{$element}_name = '" . $db->sql_escape($name) . "'";  	} -	echo str_replace('styles/', '../styles/', str_replace('./', "styles/$path/theme/", $stylesheet)); - -?> -//--> -</style> -</head> -<body> +	if (!sizeof($error)) +	{ +		$sql = "SELECT {$element}_id, {$element}_name   +			FROM $sql_from +			WHERE $sql_where"; +		$result = $db->sql_query($sql); -<table width="100%" cellspacing="1" cellpadding="4" border="0" align="center"> -	<tr align="center" valign="middle"> -		<td height="100" width="33%"><h1>h1</h1></td> -		<td height="100" width="33%"><h2>h2</h2></td> -		<td height="100" width="33%"><h3>h3</h3></td> -	</tr> -	<tr align="center"> -		<td colspan="3" height="30"><a class="mainmenu" href="">mainmenu</a></td> -	</tr> -	<tr> -		<td colspan="3" height="50"> </td> -	</tr> -</table> +		if ($row = $db->sql_fetchrow($result)) +		{ +			$name = $row[$element . '_name']; +			$id = $row[$element . '_id']; +		} +		else +		{ +			$copyright = trim($cfg[1]); +			$id = 0; +			unset($cfg); +		} +		$db->sql_freeresult($result); +	} -<table width="95%" cellspacing="2" cellpadding="2" border="0" align="center"> -	<tr> -		<td align="left" valign="bottom"><a class="titles" href="">titles</a> -	</tr> -</table> +	return true; +} -<table width="95%" cellspacing="1" cellpadding="4" border="0" align="center"> -	<tr> -		<td class="nav" width="10" align="left" valign="middle"><a href="">navlink</a></td> -	</tr> -</table> +function install_element($type, $action, $root_path, &$id, $name, $copyright, $storedb = 0) +{ +	global $phpbb_root_path, $db, $user; -<table class="tablebg" width="95%" cellspacing="1" cellpadding="4" border="0" align="center"> -	<tr> -		<th colspan="3">th</th> -	</tr> -	<tr> -		<td class="cat" width="40%"><span class="cattitle">cattitle / cat</span></td> -		<td class="catdiv" colspan="2">catdiv</td> -	</tr> -	<tr> -		<td class="row1" width="40%"><a class="topictitle" href="">topictitle / row1</a></td> -		<td class="row2"><span class="topicauthor">topicauthor / row2</span></td> -		<td class="row1"><span class="topicdetails">topicdetails / row1</span></td> -	</tr> -	<tr> -		<td class="row3" colspan="3">row3</td> -	</tr> -	<tr> -		<td class="spacer" colspan="3">spacer</td> -	</tr> -	<tr> -		<td class="row1"><span class="postauthor">postauthor / row1</span></td> -		<td class="row2"><span class="postdetails">postdetails / row2</span></td> -		<td class="row1"><span class="postbody">postbody / row1 <span class="posthilit">posthilit</span></span></td> -	</tr> -</table> +	switch ($type) +	{ +		case 'template': +			$sql_from = STYLES_TPL_TABLE; +			break; +		case 'theme': +			$sql_from = STYLES_CSS_TABLE; +			break; +		case 'imageset': +			$sql_from = STYLES_IMAGE_TABLE; +			break; +	} -<br /><hr width="95%" /> +	$l_type = strtoupper($type); +	$path = str_replace(' ', '_', $name); -<table width="95%" cellspacing="1" cellpadding="4" border="0" align="center"> -	<tr align="center"> -		<td><span class="gen">gen</span></td> -		<td><span class="genmed">genmed</span></td> -		<td><span class="gensmall">gensmall</span></td> -	</tr> -	<tr align="center"> -		<td colspan="3"><span class="copyright">copyright <a href="">phpBB</a></span></td> -	</tr> -</table> +	if (empty($name)) +	{ +		$error[] = $user->lang[$l_type . '_ERR_STYLE_NAME']; +	} -<hr width="95%" /><br /> +	if (strlen($name) > 30) +	{ +		$error[] = $user->lang[$l_type . '_ERR_NAME_LONG']; +	} -<form><table width="95%" cellspacing="1" cellpadding="4" border="0" align="center"> -	<tr align="center"> -		<td><input class="btnmain" type="submit" value="input / btnmain" /></td> -		<td><input class="btnlite" type="submit" value="input / btnlite" /></td> -		<td><input class="btnbbcode" type="submit" value="input / btnbbcode" /></td> -	</tr> -	<tr align="center"> -		<td colspan="3"><input class="post" type="text" value="input / post" /></td> -	</tr> -	<tr align="center"> -		<td colspan="3"><select class="post"><option>select</option></select></td> -	</tr> -	<tr align="center"> -		<td colspan="3"><textarea class="post">textarea / post</textarea></td> -	</tr> -</table></form> +	if (!preg_match('#^[a-z0-9_\-\+\. ]+$#i', $name)) +	{ +		$error[] = $user->lang[$l_type . '_ERR_NAME_CHARS']; +	} -<hr width="95%" /><br /> +	if (strlen($copyright) > 60) +	{ +		$error[] = $user->lang[$l_type . '_ERR_COPY_LONG']; +	} -<table class="tablebg" width="95%" cellspacing="1" cellpadding="4" border="0" align="center"> -	<tr> -		<td class="row2" align="center"><span class="postbody">postbody / <b>bold</b> <i>italic</i> <u>underline</u></span></td> -	</tr> -	<tr> -		<td class="row2"><table width="90%" cellspacing="1" cellpadding="3" border="0" align="center"> -			<tr> -				<td class="quote"><b>A_N_Other wrote:</b><hr />quote</td> -			</tr> -		</table></td> -	</tr> -	<tr> -		<td class="row2"><table width="90%" cellspacing="1" cellpadding="3" border="0" align="center"> -			<tr>  -				<td><b class="genmed">Code:</b></td> -			</tr> -			<tr> -				<td class="code">10 Print "hello"<br />20 Goto 10</td> -			</tr> -		</table></td> -	</tr> -	<tr> -		<td class="row2"><table width="90%" cellspacing="1" cellpadding="3" border="0" align="center"> -			<tr>  -				<td><b class="genmed">PHP:</b></td> -			</tr> -			<tr> -				<td class="code"><span class="syntaxbg"><span class="syntaxcomment">// syntaxcomment</span><br /><span class="syntaxdefault">?></span><br /><<span class="syntaxhtml">HTML</span>><br /><span class="syntaxdefault"><?php</span><br /><span class="syntaxkeyword">echo </span> <span class="syntaxdefault">$this = </span><span class="syntaxstring">"HELLO"</span><span class="syntaxdefault">;</span></span></td> -			</tr> -		</table></td> -	</tr> -</table> +	$sql = "SELECT {$type}_name  +		FROM $sql_from  +		WHERE {$type}_name = '" . $db->sql_escape($name) . "'"; +	$result = $db->sql_query($sql); -<br clear="all" /> +	if (extract($db->sql_fetchrow($result))) +	{ +		$error[] = $user->lang[$l_type . '_ERR_NAME_EXIST']; +	} +	$db->sql_freeresult($result); -</body> -</html> -<?php -	 -} +	if (sizeof($error)) +	{ +		return $error; +	} +	if ($action != 'install') +	{ +		@mkdir("{$phpbb_root_path}styles/$path", 0777); +		@chmod("{$phpbb_root_path}styles/$path", 0777); +		if ($root_path) +		{ +			copy_files("$root_path$type", filelist("$root_path$type", '', '*'), "$path/$type"); +		} +	} +	$sql_ary = array( +		$type . '_name'		=> $name, +		$type . '_copyright'=> $copyright,  +		$type . '_path'		=> $path, +	); +	if ($type != 'imageset') +	{ +		switch ($type) +		{ +			case 'template': +				$sql_ary += array( +					$type . '_storedb'	=> (!is_writeable("{$phpbb_root_path}styles/$path/$type")) ? 1 : 0 +				); +				break; +			case 'theme': +				$sql_ary += array( +					'theme_storedb'	=> (!is_writeable("{$phpbb_root_path}styles/$path/theme/stylesheet.css")) ? 1 : $storedb,  +					'theme_data'	=> ($storedb) ? (($root_path) ? str_replace('./', "styles/$path/theme/", implode('', file("$root_path/$type/stylesheet.css"))) : '') : '',  +					'theme_mtime'	=> ($storedb) ? filemtime("{$phpbb_root_path}styles/$path/theme/stylesheet.css") : 0 +				); +				break; +		} +	} +	else +	{ +		$cfg = file("$root_path$type/imageset.cfg"); +		for ($i = 3; $i < sizeof($cfg); $i++) +		{ +			$tmp = explode('||', $cfg[$i]); +			$sql_ary[$tmp[0]] = str_replace('{PATH}', "styles/$path/imageset/", trim($tmp[1])); +		} +		unset($cfg); +	} +	$db->sql_transaction('begin'); +	$sql = "INSERT INTO $sql_from  +		" . $db->sql_build_array('INSERT', $sql_ary); +	$db->sql_query($sql); +	$id = $db->sql_nextid(); +	if ($type == 'template' && $storedb)  +	{ +		$filelist = filelist("{$root_path}template", '', 'html'); +		store_templates('insert', $id, $path, $filelist); +	} +	$db->sql_transaction('commit'); +	$log = ($storedb) ? 'LOG_ADD_' . $l_type . '_FS' : 'LOG_ADD_' . $l_type . '_DB'; +	add_log('admin', $log, $name); +} +function install($type, $action, $id) +{ +	global $phpbb_root_path, $phpEx, $SID, $config, $db, $user; +	global $safe_mode, $file_uploads, $archive_preg; +	$install_path = (isset($_REQUEST['path'])) ? htmlspecialchars($_REQUEST['path']) : ''; +	$update = (isset($_POST['update'])) ? true : false; +	$installcfg = $error = array(); +	$template_storedb = $theme_storedb = $basis = false; +	$root_path = $tmp_path = $theme_data = $s_hidden_fields = ''; +	$template_id = $template_name = $template_copyright =$theme_id = $theme_name = $theme_copyright = $imageset_id = $imageset_name = $imageset_copyright = ''; -function details($type, $mode, $action, $id) -{ -	global $phpbb_root_path, $phpEx, $SID, $config, $db, $user; -	global $archive_preg, $safe_mode; +	$l_type = strtoupper($type); +	$l_prefix = ($action == 'add') ? 'ADD' : (($action == 'details') ? 'EDIT_DETAILS' : 'INSTALL'); -	$update = (!empty($_POST['update'])) ? true : false; +	$element_ary = array('template' => STYLES_TPL_TABLE, 'theme' => STYLES_CSS_TABLE, 'imageset' => STYLES_IMAGE_TABLE); +	$phpbbversion = preg_replace('#^2\.([0-9]+?)\.([0-9]+?).*?$#', '\1.\2', $config['version']);  	switch ($type)  	{ -		case 'theme': -			$table = STYLES_CSS_TABLE; +		case 'style': +			$sql_from = STYLES_TABLE;  			break; -  		case 'template': -			$table = STYLES_TPL_TABLE; +			$sql_from = STYLES_TPL_TABLE; +			break; +		case 'theme': +			$sql_from = STYLES_CSS_TABLE;  			break; -  		case 'imageset': -			$table = STYLES_IMAGE_TABLE; +			$sql_from = STYLES_IMAGE_TABLE;  			break;  	} -	$l_type = strtoupper($type); -	$l_prefix = ($action == 'add') ? 'ADD' : (($action == 'details') ? 'EDIT_DETAILS' : 'INSTALL'); - -	// Do we want to edit an existing theme or are we creating a new theme -	// or submitting an existing one? -	if (!$update) +	// Importing/uploading then check data and extract archive +	if (!empty($_FILES['upload_file']['name']) || !empty($_POST['import_file']))  	{ -		if ($id)  +		if (!empty($_FILES['upload_file']['name']))  		{ -			$sql = "SELECT *  -				FROM $table  -				WHERE {$type}_id = $id"; -			$result = $db->sql_query($sql); +			$realname = htmlspecialchars($_FILES['upload_file']['name']); +			$filename = htmlspecialchars($_FILES['upload_file']['tmp_name']); -			if (!($row = $db->sql_fetchrow($result))) +			if (!is_uploaded_file($filename))  			{ -				trigger_error($user->lang['NO_' . $l_type]); +				trigger_error("$filename was not uploaded");  			} -			$db->sql_freeresult($result); - -			$name = (!empty($row[$type . '_name'])) ? $row[$type . '_name'] : ''; -			$copyright = (!empty($row[$type . '_copyright'])) ? $row[$type . '_copyright'] : ''; -			$path = (!empty($row[$type . '_path'])) ? $row[$l_type . '_path'] : ''; -			$storedb = (!empty($row[$type . '_storedb'])) ? $type[$type . '_storedb'] : ''; -			$data = (!empty($row[$type . '_data'])) ? $row[$type . '_data'] : ''; -			unset($row); +		} +		else +		{ +			$realname = htmlspecialchars($_POST['import_file']); +			$filename = "{$phpbb_root_path}store/$realname"; +		} -			$s_hidden_fields = ''; +		if (!preg_match('#(' . $archive_preg . ')$#i', $realname, $match)) +		{ +			$error[] = sprintf($user->lang['UPLOAD_WRONG_TYPE'], $archive_types);  		} -		else if ($action == 'install') +		$path = preg_replace('#^(.*?)' . preg_quote($match[0]) . '$#', '\1', $realname); + +		// Attempt to extract the files to a temporary directory in store +		$tmp_path = $phpbb_root_path . 'store/tmp_' . substr(uniqid(''), 0, 10) . '/'; +		if (!@mkdir($tmp_path))  		{ -			if (empty($_GET['name'])) -			{ -				trigger_error($user->lang[$l_type . '_ERR_NO_NAME']); -			} +			trigger_error("Cannot create $tmp_path", E_USER_ERROR); +		} -			$path = trim(htmlspecialchars($_GET['name'])); -			if (!file_exists("{$phpbb_root_path}styles/$path/$type/$type.cfg")) -			{ -				trigger_error($user->lang['NO_' . $l_type]); -			} +		include($phpbb_root_path . 'includes/functions_compress.'.$phpEx); -			if (!($cfg = file("{$phpbb_root_path}styles/$path/$type/$type.cfg"))) -			{ -				trigger_error($user->lang['NO_' . $l_type]); -			} +		switch ($match[0]) +		{ +			case '.zip': +				$zip = new compress_zip('r', $filename); +				break; +			default: +				$zip = new compress_tar('r', $filename, $match[0]); +		} +		$zip->extract($tmp_path); +		$zip->close(); -			$name = trim($cfg[0]); -			$copyright = trim($ecfg[1]); -			$version = preg_replace('#^2\.([0-9]+?)\.([0-9]+?).*?$#', '\1.\2', trim($cfg[2])); -			$phpbbversion = preg_replace('#^2\.([0-9]+?)\.([0-9]+?).*?$#', '\1.\2', $config['version']); +		unset($cfg); +	} -			if ($version != $phpbbversion) -			{ -				$error[] = $user->lang[$l_type . '_VERSION_DIFF']; -			} +	// Installing, importing/uploading then obtain the style cfg information +	if (($action == 'install' && $install_path) || (!empty($_FILES['upload_file']['name']) || !empty($_POST['import_file']))) +	{ +		$root_path = ($action == 'install') ? "{$phpbb_root_path}styles/$install_path/" : "$tmp_path"; -			$s_hidden_fields = '<input type="hidden" name="path" value="' . $path . '" /><input type="hidden" name="copyright" value="' . $copyright . '" />'; +		if (!($fp = @fopen("$root_path$type/$type.cfg", 'rb'))) +		{ +			$error[] = $user->lang[$l_type . '_ERR_NOT_' . $l_type];  		}  		else  		{ -			$name = (!empty($_POST['name'])) ? htmlspecialchars(stripslashes($_POST['name'])) : ''; -			$copyright = (!empty($_POST['copyright'])) ? htmlspecialchars(stripslashes($_POST['copyright'])) : ''; -			$storedb = (!empty($_POST['storedb'])) ? 1 : (($safe_mode) ? 1 : 0); -			$basis = (!empty($_POST['basis'])) ? intval($_POST['basis']) : false; -			$path = (!empty($_POST['path'])) ? htmlspecialchars(stripslashes($_POST['path'])) : ''; - -			$s_hidden_fields = (!empty($_POST['basis'])) ? '<input type="hidden" name="basis" value="' . $basis . '" />' : ''; -			if ($path) -			{ -				$s_hidden_fields .= '<input type="hidden" name="path" value="' . $path . '" /><input type="hidden" name="copyright" value="' . $copyright . '" />'; -			} +			$installcfg = explode("\n", fread($fp, filesize("$root_path$type/$type.cfg")));  		} +		fclose($fp);  	} -	// Do the update thang -	if ($update) +	// Installing, importing/uploading then grab the element info else grab the  +	// submitted params ... stylecfg will be set if this is true (see above) +	if (sizeof($installcfg))  	{ -		if (!$safe_mode && $action == 'add' && is_writeable("{$phpbb_root_path}styles") && (!empty($_FILES['upload_file']['name']) || !empty($_POST['import_file']))) +		$name		= trim($installcfg[0]); +		$copyright	= trim($installcfg[1]); +		$version	= preg_replace('#^2\.([0-9]+?)\.([0-9]+?).*?$#', '\1.\2', trim($installcfg[2])); + +		switch ($type)  		{ -			if (!empty($_FILES['upload_file']['name'])) -			{ -				$realname = htmlspecialchars($_FILES['upload_file']['name']); -				$filename = htmlspecialchars($_FILES['upload_file']['tmp_name']); +			case 'style': +				$reqd_template		= trim($installcfg[3]); +				$reqd_theme			= trim($installcfg[4]); +				$reqd_imageset		= trim($installcfg[5]); -				if (!is_uploaded_file($filename)) +				// Check to see if each element is already installed, if it is grab the id +				foreach ($element_ary as $element => $table)  				{ -					trigger_error("$filename was not uploaded"); +					${$element . '_id'} = ${$element . '_name'} = ${$element . '_copyright'} = ''; + +					test_installed($element, $root_path, ${$element . '_reqd'}, ${$element . '_id'}, ${$element . '_name'}, ${$element . '_copyright'});  				} -			} -			else -			{ -				$realname = htmlspecialchars($_POST['import_file']); -				$filename = "{$phpbb_root_path}store/$realname"; -			} +				break; -			if (!preg_match('#(' . $archive_preg . ')$#i', $realname, $match)) -			{ -				$error[] = sprintf($user->lang['UPLOAD_WRONG_TYPE'], $archive_types); -			} -			$path = preg_replace('#^(.*?)' . preg_quote($match[0]) . '$#', '\1', $realname); +			case 'template': +				test_installed('template', $root_path, false, $template_id, $template_name, $template_copyright); +				break; -			// Attempt to extract the files to a temporary directory in store -			$tmp_path = $phpbb_root_path . 'store/tmp_' . substr(uniqid(''), 0, 10) . '/'; -			if (!@mkdir($tmp_path)) -			{ -				trigger_error("Cannot create $tmp_path"); -			} +			case 'theme': +				test_installed('theme', $root_path, false, $theme_id, $theme_name, $theme_copyright); +				break; -			include($phpbb_root_path . 'includes/functions_compress.'.$phpEx); +			case 'imageset': +				test_installed('imageset', $root_path, false, $imageset_id, $imageset_name, $imageset_copyright); +				break; +		} -			switch ($match[0]) -			{ -				case '.zip': -					$zip = new compress_zip('r', $filename); -					break; -				default: -					$zip = new compress_tar('r', $filename, $match[0]); -			} -			$zip->extract($tmp_path); -			$zip->close(); +		$s_hidden_fields = '<input type="hidden" name="path" value="' . $install_path . '" />'; +	} +	else +	{ +		// NOTE: Data here is stripslashed! Ensure it's escaped when entering the DB +		$name		 = (!empty($_POST['name'])) ? stripslashes(htmlspecialchars($_POST['name'])) : ''; +		$copyright	 = (!empty($_POST['copyright'])) ? stripslashes(htmlspecialchars($_POST['copyright'])) : ''; -			$filelist = filelist($tmp_path, '', '*'); +		$template_id = (!empty($_POST['template_id'])) ? intval($_POST['template_id']) : 0; +		$theme_id	 = (!empty($_POST['theme_id'])) ? intval($_POST['theme_id']) : 0; +		$imageset_id = (!empty($_POST['imageset_id'])) ? intval($_POST['imageset_id']) : 0; +		$basis		 = (isset($_POST['basis'])) ? intval($_POST['basis']) : 0; -			if (!in_array($type . '.cfg', $filelist['/' . $type])) +		if ($basis || $update) +		{ +			switch ($type)  			{ -				trigger_error($user->lang[$l_type . '_ERR_NOT_' . $l_type]); +				case 'style': +					$sql_select = 'style_name, template_id, theme_id, imageset_id'; +					break; +				case 'template': +					$sql_select = 'template_id, template_name, template_path, template_storedb'; +					break; +				case 'theme': +					$sql_select = 'theme_id, theme_name, theme_path, theme_data, theme_storedb'; +					break; +				case 'imageset': +					$sql_select = 'imageset_name, imageset_path, imageset_id'; +					break;  			} -			$cfg = file("$tmp_path$type/$type.cfg"); -			$name	= trim($cfg[0]); -			$copyright	= trim($cfg[1]); -			$version	= trim($cfg[2]); -			unset($cfg); -		} -		else if ($action == 'install')  -		{ -			// NOT CONSISTENT WITH style installation -			$path		= (!empty($_POST['path'])) ? htmlspecialchars($_POST['path']) : ''; +			$sql = "SELECT $sql_select   +				FROM $sql_from   +				WHERE {$type}_id = " . (($basis) ? $basis : $id); +			$result = $db->sql_query($sql); -			if (!($cfg = file("{$phpbb_root_path}styles/$path/$type/$type.cfg"))) +			if (!extract($db->sql_fetchrow($result)))   			{ -				trigger_error($user->lang['NO_' . $l_type]); +				$error[] = $user->lang['NO_' . $l_type];  			} +			$db->sql_freeresult($result); -			$name		= trim($cfg[0]); -			$copyright	= trim($cfg[1]); -			$version	= trim($cfg[2]); -			$storedb	= (!empty($_POST['storedb'])) ? 1 : 0; - -			unset($cfg); +			$s_hidden_fields .= '<input type="hidden" name="basis" value="' . $basis . '" />';  		} -		else -		{ -			$name		= (!empty($_POST['name'])) ? htmlspecialchars($_POST['name']) : ''; -			$copyright	= (!empty($_POST['copyright'])) ? htmlspecialchars($_POST['copyright']) : ''; -			$storedb	= (!empty($_POST['storedb'])) ? 1 : 0; -		} - -		$sql_where = ($action == 'add' || $action == 'install') ? "WHERE {$type}_name = '" . $db->sql_escape($name) . "'" : "WHERE {$type}_id <> $id AND {$type}_name = '" . $db->sql_escape($name) . "'"; -		$sql = "SELECT {$type}_name  -			FROM $table  -			$sql_where"; -		$result = $db->sql_query($sql); +	} -		if ($row = $db->sql_fetchrow($result)) -		{ -			$error[] = $user->lang[$l_type . '_ERR_NAME_EXIST']; -		} -		$db->sql_freeresult($result); -		unset($row); +	$storedb		= (!empty($_POST['storedb'])) ? 1 : 0; +	$style_active	= (isset($_POST['style_active'])) ? ((!empty($_POST['style_active'])) ? 1 : 0) : 1; +	$style_default	= (isset($_POST['style_default'])) ? ((!empty($_POST['style_default'])) ? 1 : 0) : (($config['default_style'] == $id) ? 1 : 0); -		if (empty($name)) -		{ -			$error[] = $user->lang[$l_type . '_ERR_STYLE_NAME']; -		} +	// User has submitted form and no errors have occured +	if ($update && !sizeof($error)) +	{ +		$sql_ary = array(); -		if (strlen($name) > 30) +		// We're installing/uploading/importing +		if ($action == 'install')  		{ -			$error[] = $user->lang[$l_type . '_ERR_NAME_LONG']; -		} +			switch ($type) +			{ +				case 'style': +					if (empty($style_name)) +					{ +						$error[] = $user->lang['STYLE_ERR_STYLE_NAME']; +					} -		if (!preg_match('#^[a-z0-9_\-\+\. ]+$#i', $name)) -		{ -			$error[] = $user->lang[$l_type . '_ERR_NAME_CHARS']; -		} +					if (strlen($style_name) > 30) +					{ +						$error[] = $user->lang['STYLE_ERR_NAME_LONG']; +					} -		if (strlen($copyright) > 60) -		{ -			$error[] = $user->lang[$l_type . '_ERR_COPY_LONG']; -		} +					if (!preg_match('#^[a-z0-9_\-\+\. ]+$#i', $style_name)) +					{ +						$error[] = $user->lang['STYLE_ERR_NAME_CHARS']; +					} -		if (!sizeof($error)) -		{ -			$css_data = ''; -			if ($action == 'install') -			{ -				switch ($type) -				{ -					case 'theme': -						if (!is_writeable("{$phpbb_root_path}styles/$path/$type/stylesheet.css")) -						{ -							$storedb = 1; -							if (!($css_data = implode('', file("{$phpbb_root_path}styles/$path/$type/stylesheet.css")))) -							{ -								trigger_error($user->lang['NO_THEME']); -							} -						} -						break; +					if (strlen($style_copyright) > 60) +					{ +						$error[] = $user->lang['STYLE_ERR_COPY_LONG']; +					} -					case 'template': -						$filelist = filelist("{$phpbb_root_path}styles/$path/$type", '', 'html'); -						if (!is_writeable("{$phpbb_root_path}styles/$path/$type")) -						{ -							$storedb = 1; -						} -						break; +					$sql = 'SELECT style_name  +						FROM ' . STYLES_TABLE . "  +						WHERE style_name = '" . $db->sql_escape($style_name) . "'"; +					$result = $db->sql_query($sql); -					case 'imageset': -						if (!($cfg = file("{$phpbb_root_path}styles/$path/$type/imageset.cfg"))) -						{ -							trigger_error($user->lang['NO_IMAGESET']); -						} +					if (extract($db->sql_fetchrow($result))) +					{ +						$error[] = $user->lang['STYLE_ERR_NAME_EXIST']; +					} +					$db->sql_freeresult($result); -						for ($i = 3; $i < sizeof($cfg); $i++) +					foreach ($element_ary as $element => $table) +					{ +						// Zero id value ... need to install element ... run usual checks +						// and do the install if necessary +						if (!${$element . '_id'})  						{ -							$tmp = explode('||', $cfg[$i]); -							$sql_img_ary[$tmp[0]] = str_replace('{PATH}', "styles/$path/$type/", trim($tmp[1])); +							$error += install_element($element, $action, $root_path, ${$element . '_id'}, $name, $copyright);  						} -						unset($cfg); -						break; -				} -			} -			 -			 - -			if ($action == 'add' && !$safe_mode && is_writeable("{$phpbb_root_path}styles")) -			{ -				umask(0); -				if (@mkdir("{$phpbb_root_path}styles/$path", 0777)) -				{ -					@chmod("{$phpbb_root_path}styles/$path", 0777); -				} +					} -				if (@mkdir("{$phpbb_root_path}styles/$path/$type", 0777)) -				{ -					if (!@chmod("{$phpbb_root_path}styles/$path/$type", 0777)) +					if (!$template_id || !$theme_id || !$imageset_id)  					{ -						$storedb = 1; +						$error[] = $user->lang['STYLE_ERR_NO_IDS'];  					} -				} - - - -				if (!empty($_FILES['upload_file']) || !empty($_POST['import_file'])) -				{ -					// TODO -					// mkdir, rmdir and rename error catching -					ksort($filelist); -					foreach ($filelist as $filepath => $file_ary) +					if (!sizeof($error))  					{ -						if ($path && !file_exists("{$phpbb_root_path}styles/$path$filepath")) -						{ -							@mkdir("{$phpbb_root_path}styles/$path$filepath", 0777); -						} -						 -						foreach ($file_ary as $file) +						$db->sql_transaction('begin'); + +						$sql_ary += array( +							$type . '_name'			=> $name,  +							$type . '_copyright'	=> $copyright,  +						); +						if ($type == 'style')  						{ -							@rename("$tmp_path$filepath/$file", "{$phpbb_root_path}styles/$path$filepath/$file"); +							$sql_ary += array( +								'style_active'		=> $style_active,  +								'template_id'		=> $template_id,  +								'theme_id'			=> $theme_id,  +								'imageset_id'		=> $imageset_id,  +							);  						} -						if ($filepath && file_exists("$tmp_path$filepath")) +						$sql = 'INSERT INTO ' . STYLES_TABLE . '  +							' .  $db->sql_build_array('INSERT', $sql_ary); +						$db->sql_query($sql); + +						$id = $db->sql_nextid(); + +						if ($type == 'style' && $style_default)  						{ -							@rmdir("$tmp_path$filepath"); -						} -					} +							$sql = 'UPDATE ' . USERS_TABLE . "  +								SET user_style = $id  +								WHERE user_style = " . $config['default_style']; +							$db->sql_query($sql); -					@rmdir("$tmp_path/$type"); -					@rmdir($tmp_path); -				} -				else if ($basis && !$storedb && !$safe_mode) -				{ -					switch ($type) -					{ -						case 'theme': -							$sql = "SELECT theme_name, theme_path, theme_storedb, css_data   -								FROM $table  -								WHERE theme_id = $basis"; -							$result = $db->sql_query($sql); +							set_config('default_style', $id); +						} -							if ($row = $db->sql_fetchrow($result)) -							{ -								$css_data = ($row['storedb']) ? $row['css_data'] : implode('', file($phpbb_root_path . 'styles/' . $row['theme_path'] . "/$type/stylesheet.css")); +						$db->sql_transaction('commit'); -								if (!$storedb && ($fp = @fopen("{$phpbb_root_path}styles/$path/$type/stylesheet.css", 'wb'))) -								{ -									$storedb = (@fwrite($fp, $css_data)) ? 0 : 1; +						add_log('admin', 'LOG_ADD_STYLE', $style_name); +					} +					break; -									if (!$storedb) -									{ -										unset($css_data); +				case 'template': +					$error = install_element('template', $action, $root_path, $id, $name, $copyright); +					break; -										// Get a list of all files and folders in the basis themes folder -										$filelist = filelist($phpbb_root_path . 'styles/' . $row['theme_path'] . '/' . $type, '', '*'); +				case 'theme': +					$error = install_element('theme', $action, $root_path, $id, $name, $copyright); +					break; -										// Copy every file bar the original stylesheet -										foreach ($filelist as $filepath => $file_ary) -										{ -											foreach ($file_ary as $file) -											{ -												if ($file == 'stylesheet.css') -												{ -													continue; -												} - -												if (!file_exists("{$phpbb_root_path}styles/$path/$type/$filepath")) -												{ -													@mkdir("{$phpbb_root_path}styles/$path/$type/$filepath"); -												} -												@copy("{$phpbb_root_path}styles/" . $row['theme_path'] . "/$type/$filepath/$file", "{$phpbb_root_path}styles/$path/$type/$filepath/$file"); -											} -										} -										unset($filelist); -									} -								} -								else -								{ -									$storedb = 1; -								} -								@fclose($fp); -							} -							$db->sql_freeresult($result); -							break; - -						case 'template': -							$sql = "SELECT theme_name, theme_path, theme_storedb, css_data   -								FROM $table  -								WHERE theme_id = $basis"; -							$result = $db->sql_query($sql); - -							$row = $db->sql_fetchrow($result); -							$db->sql_freeresult($result); -							if (!$row) -							{ -								$error = $user->lang['NO_TEMPLATE']; -								break; -							} +				case 'imageset': +					$error = install_element('imageset', $action, $root_path, $id, $name, $copyright); +					break; +			} -							if (!is_writeable("{$phpbb_root_path}styles/$path/$type")) -							{ -								$storedb = 1; -							} +			if ($tmp_path) +			{ +				cleanup_folder($tmp_path); +			} -							if ($row['template_storedb']) -							{ -							} -							break; -						 -						case 'imageset': -							$sql = "SELECT imageset_name, imageset_path   -								FROM $table   -								WHERE imageset_id = $basis"; -							$result = $db->sql_query($sql); - -							if ($row = $db->sql_fetchrow($result)) -							{ -								// Get a list of all files and folders -								$filelist = filelist("{$phpbb_root_path}styles/" . $row['imageset_path'] . '/imageset/', '', '*'); +			if (!sizeof($error)) +			{ +				$message = ($storedb) ? '_ADDED_DB' : '_ADDED'; +				trigger_error($user->lang[$l_type . $message]); +			} +		} +		else if ($action == 'add')  +		{ +			// Create path if it doesn't exist +			if ($type != 'style') +			{ +				$storedb = 1; -								// Copy every file -								foreach ($filelist as $pathfile => $file_ary) -								{ -									foreach ($file_ary as $file) -									{ -										if (!file_exists("{$phpbb_root_path}styles/$path/$type/$pathfile")) -										{ -											@mkdir("{$phpbb_root_path}styles/$path/$type/$pathfile"); -										} -										@copy("{$phpbb_root_path}styles/" . $row['imageset_path'] . "/$type$pathfile/$file", "{$phpbb_root_path}styles/$path/$type$pathfile/$file"); -									} -								} -								unset($filelist); -							} -							$db->sql_freeresult($result); -							break; +				umask(0); +				if (file_exists("{$phpbb_root_path}styles/$path") || @mkdir("{$phpbb_root_path}styles/$path", 0777)) +				{ +					if (@chmod("{$phpbb_root_path}styles/$path", 0777)) +					{ +						$storedb = 0;  					}  				}  			} -			// Build relevant array ... we need to do this in bits depending on the -			// action and type -			$sql_ary = array( -				$type . '_name'		=> $name, -			); - -			if ($action == 'add' || $action == 'install') +			if ($basis && ($template_storedb || $theme_storedb))  			{ -				$sql_ary += array( -					$type . '_copyright'=> $copyright,  -					$type . '_path'		=> $path,  -				); +				$tmp_path = $phpbb_root_path . 'store/tmp_' . substr(uniqid(''), 0, 10) . '/'; +				if (!@mkdir($tmp_path, 0777)) +				{ +					trigger_error("Cannot create $tmp_path", E_USER_ERROR); +				} +				@chmod($tmp_path, 0777); + +				if (!@mkdir("$tmp_path$type", 0777)) +				{ +					trigger_error("Cannot create $tmp_path$type", E_USER_ERROR); +				} +				@chmod("$tmp_path$type", 0777);  				switch ($type)  				{  					case 'theme': -						$sql_ary += array( -							$type . '_mtime'	=> ($storedb) ? filemtime("{$phpbb_root_path}styles/$path/$type/stylesheet.css") : 0,  -							$type . '_storedb'	=> $storedb,  -							$type . '_data'		=> ($storedb) ? $css_data : '', -						); +						copyfiles("{$phpbb_root_path}styles/$path/theme/", filelist("{$phpbb_root_path}styles/$path/theme/", '', '*'), "$tmp_path$type/"); + +						$fp = fopen("$tmp_path$type/stylesheet.css", 'wb'); +						fwrite($fp, $theme_data); +						fclose($theme_data);  						break; +  					case 'template': -						$sql_ary += array( -							$type . '_storedb'	=> $storedb,  -						); +						copyfiles("{$phpbb_root_path}styles/$path/$type/", filelist("{$phpbb_root_path}styles/$path/$type/", '', '*'), "$tmp_path$type/"); +					 +						$sql = 'SELECT template_filename, template_mtime, template_data  +							FROM ' . STYLES_TPLDATA_TABLE . " +							WHERE template_id = $basis"; +						$result = $db->sql_fetchrow($result); + +						while ($row = $db->sql_fetchrow($result)) +						{ +							$fp = fopen("$tmp_path$type/" . $row['template_filename'], 'wb'); +							fwrite($fp, $row['template_data']); +							fclose($fp); +						} +						$db->sql_freeresult($result);  						break;  				}  			} -			if ($action == 'details' && $mode != 'imageset') -			{ -				$sql = "SELECT {$type}_path, {$type}_storedb" . (($type == 'theme') ? ', theme_data' : '') . "  -					FROM $table  -					WHERE {$type}_id = $id"; -				$result = $db->sql_query($sql); +			$root_path = ($tmp_path) ? $tmp_path : (($basis) ? $phpbb_root_path . 'styles/' . ${$type . '_path'} . '/' : ''); -				$row = $db->sql_fetchrow($result); -				$db->sql_freeresult($result); +			$error = install_element($type, $action, $root_path, $id, $name, $copyright, $storedb); -				if ($row[$type . '_storedb'] != $storedb) -				{ -					$path = $row[$type . '_path']; +			if ($tmp_path) +			{ +				cleanup_folder($tmp_path); +			} -					switch ($type) -					{ -						case 'theme': -							$css_data = implode('', file("{$phpbb_root_path}styles/$path/$type/stylesheet.css")); -							if (!$storedb && !$safe_mode && is_writeable("{$phpbb_root_path}styles/$path/theme/stylesheet.css")) +			if (!sizeof($error)) +			{ +				$message = ($storedb) ? '_ADDED_DB' : '_ADDED'; +				trigger_error($user->lang["$l_type$message"]); +			} +		} +		else if ($action == 'details') +		{ +			if ($type == 'style') +			{ +				$sql_ary = array( +					'template_id'		=> $template_id,  +					'theme_id'			=> $theme_id,  +					'imageset_id'		=> $imageset_id,  +					'style_active'		=> $style_active,  +				); +			} +			else if ($type != 'imageset') +			{ +				switch ($type) +				{ +					case 'theme': +						if ($theme_storedb != $storedb) +						{ +							$theme_data = implode('', file("{$phpbb_root_path}styles/$theme_path/theme/stylesheet.css")); +							if (!$storedb && !$safe_mode && is_writeable("{$phpbb_root_path}styles/$theme_path/theme/stylesheet.css"))  							{  								$storedb = 1; -								if ($fp = @fopen("{$phpbb_root_path}styles/$path/$type/stylesheet.css", 'wb')) +								if ($fp = @fopen("{$phpbb_root_path}styles/$theme_path/$type/stylesheet.css", 'wb'))  								{ -									$storedb = (@fwrite($fp, str_replace("styles/$path/theme/", './', $css_data))) ? 0 : 1; +									$storedb = (@fwrite($fp, str_replace("styles/$theme_path/theme/", './', $theme_data))) ? 0 : 1;  								}  								fclose($fp);  							} -							$css_data = str_replace('./', "styles/$path/theme/", $css_data); +							$theme_data = str_replace('./', "styles/$theme_path/theme/", $theme_data); -							$sql_ary += array( -								$type . '_mtime'	=> ($storedb) ? filemtime("{$phpbb_root_path}styles/$path/$type/stylesheet.css") : 0,  -								$type . '_storedb'	=> $storedb,  -								$type . '_data'		=> ($storedb) ? $css_data : '', +							$sql_ary = array( +								'theme_mtime'	=> ($storedb) ? filemtime("{$phpbb_root_path}styles/$theme_path/theme/stylesheet.css") : 0,  +								'theme_storedb'	=> $storedb,  +								'theme_data'	=> ($storedb) ? $theme_data : '',  							); -							break; -						 -						case 'template': -							$filelist = filelist("{$phpbb_root_path}styles/$path/template", '', 'html'); +						} +						break; +					 +					case 'template': +						if ($theme_storedb != $storedb) +						{ +							$filelist = filelist("{$phpbb_root_path}styles/$template_path/template", '', 'html'); -							if (!$storedb && !$safe_mode && is_writeable("{$phpbb_root_path}styles/$path/template")) +							if (!$storedb && !$safe_mode && is_writeable("{$phpbb_root_path}styles/$template_path/template"))  							{  								$sql = 'SELECT *   									FROM ' . STYLES_TPLDATA_TABLE . "  @@ -3527,20 +2856,14 @@ function details($type, $mode, $action, $id)  								while ($row = $db->sql_fetchrow($result))  								{ -									if (!($fp = fopen("{$phpbb_root_path}styles/$path/template/" . $row['template_filename'], 'wb'))) -									{ -										$storedb = 1; -										break; -									} - -									if (!fwrite($fp, $row['template_data'])) +									if (!($fp = @fopen("{$phpbb_root_path}styles/$template_path/template/" . $row['template_filename'], 'wb')))  									{  										$storedb = 1;  										break;  									} +									fwrite($fp, $row['template_data']);  									fclose($fp); -  								}  								$db->sql_freeresult($result); @@ -3552,71 +2875,75 @@ function details($type, $mode, $action, $id)  								}  							} -							$sql_ary += array( -								$type . '_storedb'	=> $storedb,  +							$sql_ary = array( +								'template_storedb'	=> $storedb,   							); -							break; -					} +						} +						break;  				}  			} -			$db->sql_transaction('begin'); - -			$sql = ($action == 'add' || $action == 'install') ? "INSERT INTO $table " . $db->sql_build_array('INSERT', $sql_ary) : "UPDATE $table SET " . $db->sql_build_array('UPDATE', $sql_ary) . " WHERE {$type}_id = $id"; -			$db->sql_query($sql); - -			if ($type == 'template' && $storedb) +			if ($type != 'imageset' && sizeof($sql_ary))  			{ -				$filelist = array('/template' => $filelist['']); +				$sql = "UPDATE $sql_from  +					SET " . $db->sql_build_array('UPDATE', $sql_ary) . "  +					WHERE {$type}_id = $id"; +				$db->sql_query($sql); -				if (!$id) +				if ($type == 'style' && $style_default)  				{ -					$id = $db->sql_nextid(); +					set_config('default_style', $id);  				} - -				store_templates('insert', $id, $path, $filelist);  			} -			$db->sql_transaction('commit'); +			add_log('admin', 'LOG_EDIT_' . $l_type, $name); +			trigger_error($user->lang[$l_type . '_EDITED']); +		} +	} -			$message = ($action == 'add' || $action == 'install') ? (($storedb) ? $l_prefix . '_DB_ADDED' : $l_prefix . '_FS_ADDED') : $l_prefix . '_DETAILS_UPDATE'; -			$log = ($action == 'add' || $action == 'install') ? (($storedb) ? 'LOG_ADD_' . $l_prefix . '_DB' : 'LOG_ADD_' . $l_prefix . '_FS') : 'LOG_EDIT_' . $l_prefix . '_DETAILS'; +	// Something went wrong ... so we'll clean up any decompressed uploaded/imported archives. +	if ($tmp_path) +	{ +//		cleanup_folder($tmp_path); +	} + +	// Either an error occured or the user has just entered the form +	if (!sizeof($error) && !$update && $id) +	{ +		$sql = "SELECT *  +			FROM $sql_from +			WHERE {$type}_id = $id"; +		$result = $db->sql_query($sql); -			add_log('admin', $log, $_name); -			trigger_error($user->lang[$message]); +		if (!extract($db->sql_fetchrow($result))) +		{ +			trigger_error($user->lang['NO_' . $l_type]);  		} +		$db->sql_freeresult($result); -		 -		// If we were uploading or importing and an error occured we delete -		// the temporary files -		if (!empty($_FILES['upload_file']) || !empty($_POST['import_file'])) +		$style_default = ($type == 'style' && $config['default_style'] == $id) ? 1 : 0; +		$storedb = (!empty(${$type . '_storedb'})) ? true : false; // Fudged because we use $storedb when submitting data +	} + +	if ($type == 'style' && $action != 'install') +	{ +		$style_options = array(); +		foreach ($element_ary as $element => $table)  		{ -			// TODO -			// mkdir, rmdir and rename error catching -			ksort($filelist); -			foreach ($filelist as $filepath => $file_ary) -			{ -				foreach ($file_ary as $file) -				{ -					@unlink("$tmp_path$filepath/$file"); -				} +			$sql = "SELECT {$element}_id, {$element}_name +				FROM $table  +				ORDER BY {$element}_id ASC"; +			$result = $db->sql_query($sql); -				if ($filepath && file_exists("$tmp_path$filepath")) -				{ -					@rmdir("$tmp_path$filepath"); -				} +			while ($row = $db->sql_fetchrow($result)) +			{ +				$selected = ($row[$element . '_id'] == ${$element . '_id'}) ? ' selected="selected"' : ''; +				${$element . '_options'} .= '<option value="' . $row[$element . '_id'] . '"' . $selected . '>' . $row[$element . '_name'] . '</option>';  			} - -			@rmdir("$tmp_path/$type"); -			@rmdir($tmp_path); +			$db->sql_freeresult($result);  		}  	} - -	$storedb_no = (!$storedb) ? ' checked="checked"' : ''; -	$storedb_yes = ($storedb) ? ' checked="checked"' : ''; - -  	// Output the page  	adm_page_header($user->lang[$l_prefix . '_' . $l_type]); @@ -3626,7 +2953,7 @@ function details($type, $mode, $action, $id)  <p><?php echo $user->lang[$l_prefix . '_' . $l_type . '_EXPLAIN']; ?></p> -<form name="style" method="post" action="<?php echo "admin_styles.$phpEx$SID&mode=$mode&action=$action&id=$id"; ?>"<?php echo (!$safe_mode && is_writeable("{$phpbb_root_path}styles")) ? ' enctype="multipart/form-data"' : ''; ?>><table class="bg" width="95%" cellspacing="1" cellpadding="4" border="0" align="center"> +<form name="style" method="post" action="<?php echo "admin_styles.$phpEx$SID&mode=$type&action=$action&id=$id"; ?>"<?php echo (!$safe_mode && $file_uploads && is_writeable("{$phpbb_root_path}styles")) ? ' enctype="multipart/form-data"' : ''; ?>><table class="bg" width="95%" cellspacing="1" cellpadding="4" border="0" align="center">  	<tr>  		<th colspan="2"><?php echo $user->lang[$l_prefix . '_' . $l_type]; ?></th>  	</tr> @@ -3648,36 +2975,57 @@ function details($type, $mode, $action, $id)  		<td class="row1" width="40%"><b><?php echo $user->lang[$l_type . '_NAME']; ?>:</b></td>  		<td class="row2"><?php -	echo ($action == 'add') ? '<input class="post" type="text" name="name" value="' . $name . '" maxlength="30" size="25" />'  : "<b>$name</b>"; +	echo ($action == 'add') ? '<input class="post" type="text" name="name" maxlength="30" size="30" value="' . $name . '" />' : '<b>' . ${$type . '_name'} . '</b>';  ?></td>  	</tr>  	<tr> -		<td class="row1" width="40%"><b><?php echo $user->lang['COPYRIGHT']; ?>:</b></td> +		<td class="row1"><b><?php echo $user->lang['COPYRIGHT']; ?>:</b></td>  		<td class="row2"><?php +	echo ($action == 'add') ? '<input class="post" type="text" name="copyright" maxlength="60" size="30" value="' . $copyright . '" />' : '<b>' . ${$type . '_copyright'} . '</b>';  ?></td>  	</tr>  <?php -	if ($type != 'imageset') +	if ($type == 'style')  	{  ?>  	<tr> -		<td class="row1" width="40%"><b><?php echo $user->lang[$l_type . '_LOCATION']; ?>:</b><br /><span class="gensmall"><?php echo $user->lang[$l_type . '_LOCATION_EXPLAIN']; ?></span></td> -		<td class="row2"><input type="radio" name="storedb" value="0"<?php echo $storedb_no; ?> /> <?php echo $user->lang['STORE_FILESYSTEM']; ?>  <input type="radio" name="storedb" value="1"<?php echo $storedb_yes; ?> /> <?php echo $user->lang['STORE_DATABASE']; ?></td> +		<td class="row1"><b><?php echo $user->lang['STYLE_TEMPLATE']; ?>:</b></td> +		<td class="row2"><?php +	 +		echo ($action == 'install') ? "<b>$template_name</b>" : '<select name="template_id">' . $template_options . '</select>'; + +?></td> +	</tr> +	<tr> +		<td class="row1"><b><?php echo $user->lang['STYLE_THEME']; ?>:</b></td> +		<td class="row2"><?php +	 +		echo ($action == 'install') ? "<b>$theme_name</b>" : '<select name="theme_id">' . $theme_options . '</select>'; + +?></td> +	</tr> +	<tr> +		<td class="row1"><b><?php echo $user->lang['STYLE_IMAGESET']; ?>:</b></td> +		<td class="row2"><?php +	 +		echo ($action == 'install') ? "<b>$imageset_name</b>" : '<select name="imageset_id">' . $imageset_options . '</select>'; + +?></td>  	</tr>  <?php  	}  	// Import, upload and basis options -	if ($action == 'add' && !$safe_mode && is_writeable("{$phpbb_root_path}styles")) +	if ($action == 'add' && !$basis && !$safe_mode && is_writeable("{$phpbb_root_path}styles"))  	{  		$store_options = ''; -		$dp = opendir("{$phpbb_root_path}store"); +		$dp = @opendir("{$phpbb_root_path}store");  		while ($file = readdir($dp))  		{  			if ($file{0} != '.' && preg_match('#(' . $archive_preg . ')$#i', $file)) @@ -3689,30 +3037,25 @@ function details($type, $mode, $action, $id)  		$store_options = '<option value="">' . $user->lang['NO_IMPORT'] . '</option>' . $store_options; -		$sql = "SELECT {$type}_id, {$type}_name  -			FROM $table"; -		$result = $db->sql_query($sql); +?> +	<tr> +		<th colspan="2"><?php echo $user->lang['EXISTING_' . $l_type]; ?></th> +	</tr> +<?php -		$basis_options = '<option value="">' . $user->lang['NO_BASIS'] . '</option>'; -		while ($row = $db->sql_fetchrow($result)) +		if ($file_uploads)  		{ -			$selected = (!empty($_POST['basis']) && $_POST['basis'] == $row[$type . '_id']) ? ' selected="selected"' : ''; -			$basis_options .= '<option value="' . $row[$type . '_id'] . '"' . $selected . '>' . $row[$type . '_name'] . '</option>'; -		} -		$db->sql_freeresult($result);  ?>  	<tr> -		<th colspan="2"><?php echo $user->lang[$l_type . '_BASIS']; ?></th> -	</tr> -	<tr> -		<td class="row1" width="40%"><b><?php echo $user->lang[$l_type . '_EXISTING_BASIS']; ?>:</b></td> -		<td class="row2"><select name="import_file"><?php echo $basis_options; ?></select></td> -	</tr> -	<tr>  		<td class="row1" width="40%"><b><?php echo $user->lang[$l_type . '_UPLOAD_BASIS']; ?>:</b><br /><span class="gensmall"><?php echo $user->lang['ALLOWED_FILETYPES']; ?>: <?php echo $archive_types; ?></span></td>  		<td class="row2"><input class="post" type="file" name="upload_file" /><input type="hidden" name="MAX_FILE_SIZE" value="1048576" /></td>  	</tr> +<?php + +		} + +?>  	<tr>  		<td class="row1" width="40%"><b><?php echo $user->lang[$l_type . '_IMPORT_BASIS']; ?>:</b></td>  		<td class="row2"><select name="import_file"><?php echo $store_options; ?></select></td> @@ -3721,6 +3064,51 @@ function details($type, $mode, $action, $id)  	}	 +	if ($type == 'style') +	{ +		$active_yes = ($style_active) ? ' checked="checked"' : ''; +		$active_no = (!$style_active) ? ' checked="checked"' : ''; +		$style_default_yes = ($style_default) ? ' checked="checked"' : ''; +		$style_default_no = (!$style_default) ? ' checked="checked"' : ''; + +?> +	<tr> +		<th colspan="2"> </th> +	</tr> +	<tr> +		<td class="row1"><b><?php echo $user->lang['STYLE_ACTIVE']; ?>:</b></td> +		<td class="row2"><input type="radio" name="style_active" value="1"<?php echo $active_yes; ?> /> <?php echo $user->lang['YES']; ?>   <input type="radio" name="style_active" value="0"<?php echo $active_no; ?> /> <?php echo $user->lang['NO']; ?></td> +	</tr> +<?php + +		if ($id != $config['default_style']) +		{ + +?> +	<tr> +		<td class="row1"><b><?php echo $user->lang['STYLE_DEFAULT']; ?>:</b></td> +		<td class="row2"><input type="radio" name="style_default" value="1"<?php echo $style_default_yes; ?> /> <?php echo $user->lang['YES']; ?>   <input type="radio" name="style_default" value="0"<?php echo $style_default_no; ?> /> <?php echo $user->lang['NO']; ?></td> +	</tr> +<?php + +		} +	} +	else if ($type != 'imageset') +	{ +		$storedb_no = (!$storedb) ? ' checked="checked"' : ''; +		$storedb_yes = ($storedb) ? ' checked="checked"' : ''; + +?> +	<tr> +		<td class="row1" width="40%"><b><?php echo $user->lang[$l_type . '_LOCATION']; ?>:</b><br /><span class="gensmall"><?php echo $user->lang[$l_type . '_LOCATION_EXPLAIN']; ?></span></td> +		<td class="row2"><input type="radio" name="storedb" value="0"<?php echo $storedb_no; ?> /> <?php echo $user->lang['STORE_FILESYSTEM']; ?>  <input type="radio" name="storedb" value="1"<?php echo $storedb_yes; ?> /> <?php echo $user->lang['STORE_DATABASE']; ?></td> +	</tr> +<?php  + + + +	} +  ?>  	<tr>  		<td class="cat" colspan="2" align="center"><input class="btnmain" type="submit" name="update" value="<?php echo $user->lang['SUBMIT']; ?>" />  <input class="btnlite" type="reset" value="<?php echo $user->lang['RESET']; ?>" /><?php echo $s_hidden_fields; ?></td> @@ -3732,4 +3120,165 @@ function details($type, $mode, $action, $id)  } +// Hopefully temporary +function theme_preview(&$path, &$stylesheet, &$class, &$css_element) +{ +	global $config, $user; + +?> +<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> +<html dir="<?php echo $user->lang['LTR']; ?>"> +<head> +<meta http-equiv="Content-Type" content="text/html; charset=<?php echo $user->lang['ENCODING']; ?>"> +<meta http-equiv="Content-Style-Type" content="text/css"> +<style type="text/css"> +<!-- +<?php + + +	$updated_element = implode('; ', $css_element) . ';'; + +	if (preg_match('#^' . $class . ' {(.*?)}#m', $stylesheet)) +	{ +		$stylesheet = preg_replace('#^(' . $class . ' {).*?(})#m', '\1 ' . $updated_element . ' \2', $stylesheet); +	} + +	echo str_replace('styles/', '../styles/', str_replace('./', "styles/$path/theme/", $stylesheet)); + +?> +//--> +</style> +</head> +<body> + +<table width="100%" cellspacing="1" cellpadding="4" border="0" align="center"> +	<tr align="center" valign="middle"> +		<td height="100" width="33%"><h1>h1</h1></td> +		<td height="100" width="33%"><h2>h2</h2></td> +		<td height="100" width="33%"><h3>h3</h3></td> +	</tr> +	<tr align="center"> +		<td colspan="3" height="30"><a class="mainmenu" href="">mainmenu</a></td> +	</tr> +	<tr> +		<td colspan="3" height="50"> </td> +	</tr> +</table> + +<table width="95%" cellspacing="2" cellpadding="2" border="0" align="center"> +	<tr> +		<td align="left" valign="bottom"><a class="titles" href="">titles</a> +	</tr> +</table> + +<table width="95%" cellspacing="1" cellpadding="4" border="0" align="center"> +	<tr> +		<td class="nav" width="10" align="left" valign="middle"><a href="">navlink</a></td> +	</tr> +</table> + +<table class="tablebg" width="95%" cellspacing="1" cellpadding="4" border="0" align="center"> +	<tr> +		<th colspan="3">th</th> +	</tr> +	<tr> +		<td class="cat" width="40%"><span class="cattitle">cattitle / cat</span></td> +		<td class="catdiv" colspan="2">catdiv</td> +	</tr> +	<tr> +		<td class="row1" width="40%"><a class="topictitle" href="">topictitle / row1</a></td> +		<td class="row2"><span class="topicauthor">topicauthor / row2</span></td> +		<td class="row1"><span class="topicdetails">topicdetails / row1</span></td> +	</tr> +	<tr> +		<td class="row3" colspan="3">row3</td> +	</tr> +	<tr> +		<td class="spacer" colspan="3">spacer</td> +	</tr> +	<tr> +		<td class="row1"><span class="postauthor">postauthor / row1</span></td> +		<td class="row2"><span class="postdetails">postdetails / row2</span></td> +		<td class="row1"><span class="postbody">postbody / row1 <span class="posthilit">posthilit</span></span></td> +	</tr> +</table> + +<br /><hr width="95%" /> + +<table width="95%" cellspacing="1" cellpadding="4" border="0" align="center"> +	<tr align="center"> +		<td><span class="gen">gen</span></td> +		<td><span class="genmed">genmed</span></td> +		<td><span class="gensmall">gensmall</span></td> +	</tr> +	<tr align="center"> +		<td colspan="3"><span class="copyright">copyright <a href="">phpBB</a></span></td> +	</tr> +</table> + +<hr width="95%" /><br /> + +<form><table width="95%" cellspacing="1" cellpadding="4" border="0" align="center"> +	<tr align="center"> +		<td><input class="btnmain" type="submit" value="input / btnmain" /></td> +		<td><input class="btnlite" type="submit" value="input / btnlite" /></td> +		<td><input class="btnbbcode" type="submit" value="input / btnbbcode" /></td> +	</tr> +	<tr align="center"> +		<td colspan="3"><input class="post" type="text" value="input / post" /></td> +	</tr> +	<tr align="center"> +		<td colspan="3"><select class="post"><option>select</option></select></td> +	</tr> +	<tr align="center"> +		<td colspan="3"><textarea class="post">textarea / post</textarea></td> +	</tr> +</table></form> + +<hr width="95%" /><br /> + +<table class="tablebg" width="95%" cellspacing="1" cellpadding="4" border="0" align="center"> +	<tr> +		<td class="row2" align="center"><span class="postbody">postbody / <b>bold</b> <i>italic</i> <u>underline</u></span></td> +	</tr> +	<tr> +		<td class="row2"><table width="90%" cellspacing="1" cellpadding="3" border="0" align="center"> +			<tr> +				<td class="quote"><b>A_N_Other wrote:</b><hr />quote</td> +			</tr> +		</table></td> +	</tr> +	<tr> +		<td class="row2"><table width="90%" cellspacing="1" cellpadding="3" border="0" align="center"> +			<tr>  +				<td><b class="genmed">Code:</b></td> +			</tr> +			<tr> +				<td class="code">10 Print "hello"<br />20 Goto 10</td> +			</tr> +		</table></td> +	</tr> +	<tr> +		<td class="row2"><table width="90%" cellspacing="1" cellpadding="3" border="0" align="center"> +			<tr>  +				<td><b class="genmed">PHP:</b></td> +			</tr> +			<tr> +				<td class="code"><span class="syntaxbg"><span class="syntaxcomment">// syntaxcomment</span><br /><span class="syntaxdefault">?></span><br /><<span class="syntaxhtml">HTML</span>><br /><span class="syntaxdefault"><?php</span><br /><span class="syntaxkeyword">echo </span> <span class="syntaxdefault">$this = </span><span class="syntaxstring">"HELLO"</span><span class="syntaxdefault">;</span></span></td> +			</tr> +		</table></td> +	</tr> +</table> + +<br clear="all" /> + +</body> +</html> +<?php +	 +} +// +// FUNCTIONS +// --------- +  ?>
\ No newline at end of file  | 
