phpBB

Code Changes

File: includes/acp/acp_styles.php

  Unmodified   Added   Modified   Removed
Line 37Line 37
		// Hardcoded template bitfield to add for new templates
$bitfield = new bitfield();
$bitfield->set(0);

		// Hardcoded template bitfield to add for new templates
$bitfield = new bitfield();
$bitfield->set(0);

 
		$bitfield->set(1);
$bitfield->set(2);

		$bitfield->set(3);

		$bitfield->set(3);

 
		$bitfield->set(4);

		$bitfield->set(8);
$bitfield->set(9);
$bitfield->set(11);

		$bitfield->set(8);
$bitfield->set(9);
$bitfield->set(11);

Line 96Line 99
		$this->template_cfg .= '
# Some configuration options


		$this->template_cfg .= '
# Some configuration options


#
# You can use this function to inherit templates from another template.
# The template of the given name has to be installed.
# Templates cannot inherit from inheriting templates.
#';

# Template inheritance
# See http://blog.phpbb.com/2008/07/31/templating-just-got-easier/
# Set value to empty or this template name to ignore template inheritance.
inherit_from = {INHERIT_FROM}
';


$this->imageset_keys = array(
'logos' => array(


$this->imageset_keys = array(
'logos' => array(

Line 207Line 210
							trigger_error($user->lang['DEACTIVATE_DEFAULT'] . adm_back_link($this->u_action), E_USER_WARNING);
}


							trigger_error($user->lang['DEACTIVATE_DEFAULT'] . adm_back_link($this->u_action), E_USER_WARNING);
}


 
						if (($action == 'deactivate' && confirm_box(true)) || $action == 'activate')
{

						$sql = 'UPDATE ' . STYLES_TABLE . '
SET style_active = ' . (($action == 'activate') ? 1 : 0) . '
WHERE style_id = ' . $style_id;

						$sql = 'UPDATE ' . STYLES_TABLE . '
SET style_active = ' . (($action == 'activate') ? 1 : 0) . '
WHERE style_id = ' . $style_id;

Line 224Line 229
								SET forum_style = 0
WHERE forum_style = ' . $style_id;
$db->sql_query($sql);

								SET forum_style = 0
WHERE forum_style = ' . $style_id;
$db->sql_query($sql);

 
							}
}
else if ($action == 'deactivate')
{
$s_hidden_fields = array(
'i' => $id,
'mode' => $mode,
'action' => $action,
'style_id' => $style_id,
);
confirm_box(false, $user->lang['CONFIRM_OPERATION'], build_hidden_fields($s_hidden_fields));

						}
break;
}

						}
break;
}

Line 494Line 510
							$db->sql_transaction('commit');

$cache->destroy('sql', STYLES_IMAGESET_DATA_TABLE);

							$db->sql_transaction('commit');

$cache->destroy('sql', STYLES_IMAGESET_DATA_TABLE);

 
							$cache->destroy('imageset_site_logo_md5');


add_log('admin', 'LOG_IMAGESET_REFRESHED', $imageset_row['imageset_name']);
trigger_error($user->lang['IMAGESET_REFRESHED'] . adm_back_link($this->u_action));


add_log('admin', 'LOG_IMAGESET_REFRESHED', $imageset_row['imageset_name']);
trigger_error($user->lang['IMAGESET_REFRESHED'] . adm_back_link($this->u_action));

Line 523Line 540
		global $user, $template, $db, $config, $phpbb_root_path, $phpEx;

$sql_from = '';

		global $user, $template, $db, $config, $phpbb_root_path, $phpEx;

$sql_from = '';

 
		$sql_sort = 'LOWER(' . $mode . '_name)';

		$style_count = array();

switch ($mode)
{
case 'style':
$sql_from = STYLES_TABLE;

		$style_count = array();

switch ($mode)
{
case 'style':
$sql_from = STYLES_TABLE;

 
				$sql_sort = 'style_active DESC, ' . $sql_sort;


$sql = 'SELECT user_style, COUNT(user_style) AS style_count
FROM ' . USERS_TABLE . '


$sql = 'SELECT user_style, COUNT(user_style) AS style_count
FROM ' . USERS_TABLE . '

Line 554Line 573
			case 'imageset':
$sql_from = STYLES_IMAGESET_TABLE;
break;

			case 'imageset':
$sql_from = STYLES_IMAGESET_TABLE;
break;

 
			
default:
trigger_error($user->lang['NO_MODE'] . adm_back_link($this->u_action), E_USER_WARNING);

		}

$l_prefix = strtoupper($mode);

		}

$l_prefix = strtoupper($mode);

Line 577Line 599
		);

$sql = "SELECT *

		);

$sql = "SELECT *

			FROM $sql_from";


			FROM $sql_from
ORDER BY $sql_sort ASC";

		$result = $db->sql_query($sql);

$installed = array();

		$result = $db->sql_query($sql);

$installed = array();

Line 613Line 636

'NAME' => $row[$mode . '_name'],
'STYLE_COUNT' => ($mode == 'style' && isset($style_count[$row['style_id']])) ? $style_count[$row['style_id']] : 0,


'NAME' => $row[$mode . '_name'],
'STYLE_COUNT' => ($mode == 'style' && isset($style_count[$row['style_id']])) ? $style_count[$row['style_id']] : 0,

 

'S_INACTIVE' => ($mode == 'style' && !$row['style_active']) ? true : false,

				)
);
}

				)
);
}

Line 627Line 652
		{
while (($file = readdir($dp)) !== false)
{

		{
while (($file = readdir($dp)) !== false)
{

 
				if ($file[0] == '.' || !is_dir($phpbb_root_path . 'styles/' . $file))
{
continue;
}


				$subpath = ($mode != 'style') ? "$mode/" : '';

				$subpath = ($mode != 'style') ? "$mode/" : '';

				if ($file[0] != '.' && file_exists("{$phpbb_root_path}styles/$file/$subpath$mode.cfg"))

				if (file_exists("{$phpbb_root_path}styles/$file/$subpath$mode.cfg"))

				{
if ($cfg = file("{$phpbb_root_path}styles/$file/$subpath$mode.cfg"))
{

				{
if ($cfg = file("{$phpbb_root_path}styles/$file/$subpath$mode.cfg"))
{

Line 637Line 667

if ($name && !in_array($name, $installed))
{


if ($name && !in_array($name, $installed))
{

							$new_ary[] = array(



							// The array key is used for sorting later on.
// $file is appended because $name doesn't have to be unique.
$new_ary[$name . $file] = array(

								'path'		=> $file,
'name' => $name,
'copyright' => $items['copyright'],

								'path'		=> $file,
'name' => $name,
'copyright' => $items['copyright'],

Line 653Line 685

if (sizeof($new_ary))
{


if (sizeof($new_ary))
{

 
			ksort($new_ary);


			foreach ($new_ary as $cfg)
{
$template->assign_block_vars('uninstalled', array(

			foreach ($new_ary as $cfg)
{
$template->assign_block_vars('uninstalled', array(

Line 695Line 729
		$save_changes	= (isset($_POST['save'])) ? true : false;

// make sure template_file path doesn't go upwards

		$save_changes	= (isset($_POST['save'])) ? true : false;

// make sure template_file path doesn't go upwards

		$template_file = str_replace('..', '.', $template_file);

		$template_file = preg_replace('#\.{2,}#', '.', $template_file);


// Retrieve some information about the template
$sql = 'SELECT template_storedb, template_path, template_name


// Retrieve some information about the template
$sql = 'SELECT template_storedb, template_path, template_name

Line 727Line 761
			$additional = '';

// If the template is stored on the filesystem try to write the file else store it in the database

			$additional = '';

// If the template is stored on the filesystem try to write the file else store it in the database

			if (!$safe_mode && !$template_info['template_storedb'] && file_exists($file) && @is_writable($file))

			if (!$safe_mode && !$template_info['template_storedb'] && file_exists($file) && phpbb_is_writable($file))

			{
if (!($fp = @fopen($file, 'wb')))
{

			{
if (!($fp = @fopen($file, 'wb')))
{

					trigger_error($user->lang['NO_TEMPLATE'] . adm_back_link($this->u_action), E_USER_WARNING);


					// File exists and is writeable, but still not able to be written to
trigger_error(sprintf($user->lang['TEMPLATE_FILE_NOT_WRITABLE'], htmlspecialchars($template_file)) . adm_back_link($this->u_action), E_USER_WARNING);

				}
fwrite($fp, $template_data);
fclose($fp);

				}
fwrite($fp, $template_data);
fclose($fp);

Line 743Line 778
				// If it's not stored in the db yet, then update the template setting and store all template files in the db
if (!$template_info['template_storedb'])
{

				// If it's not stored in the db yet, then update the template setting and store all template files in the db
if (!$template_info['template_storedb'])
{

					if ($this->get_super('template', $template_id))

					if ($super = $this->get_super('template', $template_id))

					{
$this->store_in_db('template', $super['template_id']);
}

					{
$this->store_in_db('template', $super['template_id']);
}

Line 822Line 857
			}
$db->sql_freeresult($result);
unset($file_info);

			}
$db->sql_freeresult($result);
unset($file_info);

 
		}

if (empty($filelist['']))
{
trigger_error($user->lang['NO_TEMPLATE'] . adm_back_link($this->u_action), E_USER_WARNING);

		}

// Now create the categories

		}

// Now create the categories

Line 1021Line 1061

foreach ($file_ary as $file)
{


foreach ($file_ary as $file)
{

			$file 		= str_replace('/', '.', $file);

			$file		= str_replace('/', '.', $file);


// perform some dirty guessing to get the path right.
// We assume that three dots in a row were '../'


// perform some dirty guessing to get the path right.
// We assume that three dots in a row were '../'

			$tpl_file 	= str_replace('.', '/', $file);
$tpl_file = str_replace('///', '../', $tpl_file);

			$tpl_file	= str_replace('.', '/', $file);
$tpl_file = str_replace('///', '../', $tpl_file);


$filename = "{$cache_prefix}_$file.html.$phpEx";



$filename = "{$cache_prefix}_$file.html.$phpEx";


Line 1058Line 1098
				}
}


				}
}


 
			// Correct the filename if it is stored in database and the file is in a subfolder.
if ($template_row['template_storedb'])
{
$file = str_replace('.', '/', $file);
}


$template->assign_block_vars('file', array(
'U_VIEWSOURCE' => $this->u_action . "&action=cache&id=$template_id&source=$file",


$template->assign_block_vars('file', array(
'U_VIEWSOURCE' => $this->u_action . "&action=cache&id=$template_id&source=$file",

Line 1065Line 1110
				'CACHED'		=> $user->format_date(filemtime("{$phpbb_root_path}cache/$filename")),
'FILENAME' => $file,
'FILENAME_PATH' => $file_tpl,

				'CACHED'		=> $user->format_date(filemtime("{$phpbb_root_path}cache/$filename")),
'FILENAME' => $file,
'FILENAME_PATH' => $file_tpl,

				'FILESIZE'		=> sprintf('%.1f ' . $user->lang['KIB'], filesize("{$phpbb_root_path}cache/$filename") / 1024),

				'FILESIZE'		=> get_formatted_filesize(filesize("{$phpbb_root_path}cache/$filename")),

				'MODIFIED'		=> $user->format_date((!$template_row['template_storedb']) ? filemtime($file_tpl) : $filemtime[$file . '.html']))
);
}

				'MODIFIED'		=> $user->format_date((!$template_row['template_storedb']) ? filemtime($file_tpl) : $filemtime[$file . '.html']))
);
}

Line 1123Line 1168
			$message = $user->lang['THEME_UPDATED'];

// If the theme is stored on the filesystem try to write the file else store it in the database

			$message = $user->lang['THEME_UPDATED'];

// If the theme is stored on the filesystem try to write the file else store it in the database

			if (!$safe_mode && !$theme_info['theme_storedb'] && file_exists($file) && @is_writable($file))

			if (!$safe_mode && !$theme_info['theme_storedb'] && file_exists($file) && phpbb_is_writable($file))

			{
if (!($fp = @fopen($file, 'wb')))
{

			{
if (!($fp = @fopen($file, 'wb')))
{

Line 1262Line 1307
			'TEXT_ROWS'			=> $text_rows)
);
}

			'TEXT_ROWS'			=> $text_rows)
);
}



 

/**
* Edit imagesets


/**
* Edit imagesets

Line 1274Line 1318
		global $db, $user, $phpbb_root_path, $cache, $template;

$this->page_title = 'EDIT_IMAGESET';

		global $db, $user, $phpbb_root_path, $cache, $template;

$this->page_title = 'EDIT_IMAGESET';

 

if (!$imageset_id)
{
trigger_error($user->lang['NO_IMAGESET'] . adm_back_link($this->u_action), E_USER_WARNING);
}


$update = (isset($_POST['update'])) ? true : false;



$update = (isset($_POST['update'])) ? true : false;


		$imgname	= request_var('imgname', '');
$imgpath = request_var('imgpath', '');
$imgsize = request_var('imgsize', false);
$imgwidth = request_var('imgwidth', 0);
$imgheight = request_var('imgheight', 0);


		$imgname	= request_var('imgname', 'site_logo');






		$imgname	= preg_replace('#[^a-z0-9\-+_]#i', '', $imgname);

		$imgname	= preg_replace('#[^a-z0-9\-+_]#i', '', $imgname);

		$imgpath	= str_replace('..', '.', $imgpath);

		$sql_extra = $imgnamelang = '';





		if ($imageset_id)
{

 
			$sql = 'SELECT imageset_path, imageset_name
FROM ' . STYLES_IMAGESET_TABLE . "
WHERE imageset_id = $imageset_id";
$result = $db->sql_query($sql);
$imageset_row = $db->sql_fetchrow($result);
$db->sql_freeresult($result);

			$sql = 'SELECT imageset_path, imageset_name
FROM ' . STYLES_IMAGESET_TABLE . "
WHERE imageset_id = $imageset_id";
$result = $db->sql_query($sql);
$imageset_row = $db->sql_fetchrow($result);
$db->sql_freeresult($result);

 

if (!$imageset_row)
{
trigger_error($user->lang['NO_IMAGESET'] . adm_back_link($this->u_action), E_USER_WARNING);
}


$imageset_path = $imageset_row['imageset_path'];
$imageset_name = $imageset_row['imageset_name'];



$imageset_path = $imageset_row['imageset_path'];
$imageset_name = $imageset_row['imageset_name'];


			$sql_extra = '';

 
			if (strpos($imgname, '-') !== false)
{
list($imgname, $imgnamelang) = explode('-', $imgname);

			if (strpos($imgname, '-') !== false)
{
list($imgname, $imgnamelang) = explode('-', $imgname);

Line 1318Line 1364
			$image_height	= $imageset_data_row['image_height'];
$image_lang = $imageset_data_row['image_lang'];
$image_id = $imageset_data_row['image_id'];

			$image_height	= $imageset_data_row['image_height'];
$image_lang = $imageset_data_row['image_lang'];
$image_id = $imageset_data_row['image_id'];


if (!$imageset_row)
{
trigger_error($user->lang['NO_IMAGESET'] . adm_back_link($this->u_action), E_USER_WARNING);
}

		$imgsize		= ($imageset_data_row['image_width'] && $imageset_data_row['image_height']) ? 1 : 0;






// Check to see whether the selected image exists in the table
$valid_name = ($update) ? false : true;


// Check to see whether the selected image exists in the table
$valid_name = ($update) ? false : true;

Line 1336Line 1378
				}
}


				}
}


			if ($update && isset($_POST['imgpath']))
{
if ($valid_name)

		if ($update && isset($_POST['imgpath']) && $valid_name)



				{
// If imgwidth and imgheight are non-zero grab the actual size
// from the image itself ... we ignore width settings for the poll center image
$imgwidth = request_var('imgwidth', 0);
$imgheight = request_var('imgheight', 0);

				{
// If imgwidth and imgheight are non-zero grab the actual size
// from the image itself ... we ignore width settings for the poll center image
$imgwidth = request_var('imgwidth', 0);
$imgheight = request_var('imgheight', 0);

 
			$imgsize	= request_var('imgsize', 0);
$imgpath = request_var('imgpath', '');
$imgpath = str_replace('..', '.', $imgpath);

// If no dimensions selected, we reset width and height to 0 ;)
if (!$imgsize)
{
$imgwidth = $imgheight = 0;
}


					$imglang = '';

if ($imgpath && !file_exists("{$phpbb_root_path}styles/$imageset_path/imageset/$imgpath"))

					$imglang = '';

if ($imgpath && !file_exists("{$phpbb_root_path}styles/$imageset_path/imageset/$imgpath"))

Line 1351Line 1401
						trigger_error($user->lang['NO_IMAGE_ERROR'] . adm_back_link($this->u_action), E_USER_WARNING);
}


						trigger_error($user->lang['NO_IMAGE_ERROR'] . adm_back_link($this->u_action), E_USER_WARNING);
}


 
			// Determine width/height. If dimensions included and no width/height given, we detect them automatically...

					if ($imgsize && $imgpath)
{
if (!$imgwidth || !$imgheight)

					if ($imgsize && $imgpath)
{
if (!$imgwidth || !$imgheight)

Line 1362Line 1413
						$imgwidth	= ($imgname != 'poll_center') ? (int) $imgwidth : 0;
$imgheight = (int) $imgheight;
}

						$imgwidth	= ($imgname != 'poll_center') ? (int) $imgwidth : 0;
$imgheight = (int) $imgheight;
}



 

if (strpos($imgpath, '/') !== false)
{


if (strpos($imgpath, '/') !== false)
{

Line 1406Line 1456
					$image_width	= $imgwidth;
$image_height = $imgheight;
$image_lang = $imglang;

					$image_width	= $imgwidth;
$image_height = $imgheight;
$image_lang = $imglang;

				}
}

 
		}

$imglang = '';

		}

$imglang = '';

Line 1529Line 1577
			'U_BACK'			=> $this->u_action,
'NAME' => $imageset_name,
'A_NAME' => addslashes($imageset_name),

			'U_BACK'			=> $this->u_action,
'NAME' => $imageset_name,
'A_NAME' => addslashes($imageset_name),

 
			'PATH'				=> $imageset_path,
'A_PATH' => addslashes($imageset_path),

			'ERROR'				=> !$valid_name,
'IMG_SRC' => ($image_found) ? '../styles/' . $imageset_path . '/imageset/' . $img_val : 'images/no_image.png',
'IMAGE_SELECT' => $image_found

			'ERROR'				=> !$valid_name,
'IMG_SRC' => ($image_found) ? '../styles/' . $imageset_path . '/imageset/' . $img_val : 'images/no_image.png',
'IMAGE_SELECT' => $image_found

Line 1550Line 1600
		{
case 'style':
$sql_from = STYLES_TABLE;

		{
case 'style':
$sql_from = STYLES_TABLE;

				$sql_select = 'style_name';

				$sql_select = 'style_id, style_name, template_id, theme_id, imageset_id';

				$sql_where = 'AND style_active = 1';
break;

case 'template':
$sql_from = STYLES_TEMPLATE_TABLE;

				$sql_where = 'AND style_active = 1';
break;

case 'template':
$sql_from = STYLES_TEMPLATE_TABLE;

				$sql_select = 'template_name, template_path, template_storedb';

				$sql_select = 'template_id, template_name, template_path, template_storedb';

			break;

case 'theme':
$sql_from = STYLES_THEME_TABLE;

			break;

case 'theme':
$sql_from = STYLES_THEME_TABLE;

				$sql_select = 'theme_name, theme_path, theme_storedb';

				$sql_select = 'theme_id, theme_name, theme_path, theme_storedb';

			break;

case 'imageset':
$sql_from = STYLES_IMAGESET_TABLE;

			break;

case 'imageset':
$sql_from = STYLES_IMAGESET_TABLE;

				$sql_select = 'imageset_name, imageset_path';

				$sql_select = 'imageset_id, imageset_name, imageset_path';

			break;
}


			break;
}


Line 1596Line 1646
			trigger_error($user->lang['NO_' . $l_prefix] . adm_back_link($this->u_action), E_USER_WARNING);
}


			trigger_error($user->lang['NO_' . $l_prefix] . adm_back_link($this->u_action), E_USER_WARNING);
}


		$sql = "SELECT {$mode}_id, {$mode}_name
FROM $sql_from
WHERE {$mode}_id <> $style_id
$sql_where
ORDER BY {$mode}_name ASC";
$result = $db->sql_query($sql);

		$s_only_component = $this->display_component_options($mode, $style_row[$mode . '_id'], $style_row);










		$s_options = '';

if ($row = $db->sql_fetchrow($result))
{
do
{
$s_options .= '<option value="' . $row[$mode . '_id'] . '">' . $row[$mode . '_name'] . '</option>';
}
while ($row = $db->sql_fetchrow($result));
}
else

		if ($s_only_component)











		{
trigger_error($user->lang['ONLY_' . $l_prefix] . adm_back_link($this->u_action), E_USER_WARNING);
}

		{
trigger_error($user->lang['ONLY_' . $l_prefix] . adm_back_link($this->u_action), E_USER_WARNING);
}

		$db->sql_freeresult($result);

 

if ($update)


if ($update)

 
		{
if ($mode == 'style')

		{
$sql = "DELETE FROM $sql_from
WHERE {$mode}_id = $style_id";
$db->sql_query($sql);


		{
$sql = "DELETE FROM $sql_from
WHERE {$mode}_id = $style_id";
$db->sql_query($sql);


			if ($mode == 'style')
{

 
				$sql = 'UPDATE ' . USERS_TABLE . "
SET user_style = $new_id
WHERE user_style = $style_id";

				$sql = 'UPDATE ' . USERS_TABLE . "
SET user_style = $new_id
WHERE user_style = $style_id";

Line 1640Line 1674
				if ($style_id == $config['default_style'])
{
set_config('default_style', $new_id);

				if ($style_id == $config['default_style'])
{
set_config('default_style', $new_id);

 
				}

// Remove the components
$components = array('template', 'theme', 'imageset');
foreach ($components as $component)
{
$new_id = request_var('new_' . $component . '_id', 0);
$component_id = $style_row[$component . '_id'];
$this->remove_component($component, $component_id, $new_id, $style_id);

				}
}
else
{

				}
}
else
{

				if ($mode == 'imageset')
{
$sql = 'DELETE FROM ' . STYLES_IMAGESET_DATA_TABLE . "
WHERE imageset_id = $style_id";
$db->sql_query($sql);
}
$sql = 'UPDATE ' . STYLES_TABLE . "
SET {$mode}_id = $new_id
WHERE {$mode}_id = $style_id";
$db->sql_query($sql);

				$this->remove_component($mode, $style_id, $new_id);










			}

$cache->destroy('sql', STYLES_TABLE);

			}

$cache->destroy('sql', STYLES_TABLE);

Line 1667Line 1701

$template->assign_vars(array(
'S_DELETE' => true,


$template->assign_vars(array(
'S_DELETE' => true,

			'S_REPLACE_OPTIONS'	=> $s_options,

 

'L_TITLE' => $user->lang[$this->page_title],
'L_EXPLAIN' => $user->lang[$this->page_title . '_EXPLAIN'],


'L_TITLE' => $user->lang[$this->page_title],
'L_EXPLAIN' => $user->lang[$this->page_title . '_EXPLAIN'],

Line 1681Line 1714
			'NAME'			=> $style_row[$mode . '_name'],
)
);

			'NAME'			=> $style_row[$mode . '_name'],
)
);

 

if ($mode == 'style')
{
$template->assign_vars(array(
'S_DELETE_STYLE' => true,
));
}
}

/**
* Remove template/theme/imageset entry from the database
*/
function remove_component($component, $component_id, $new_id, $style_id = false)
{
global $db;

if (($new_id == 0) || ($component === 'template' && ($conflicts = $this->check_inheritance($component, $component_id))))
{
// We can not delete the template, as the user wants to keep the component or an other template is inheriting from this one.
return;
}

$component_in_use = array();
if ($component != 'style')
{
$component_in_use = $this->component_in_use($component, $component_id, $style_id);
}

if (($new_id == -1) && !empty($component_in_use))
{
// We can not delete the component, as it is still in use
return;
}

if ($component == 'imageset')
{
$sql = 'DELETE FROM ' . STYLES_IMAGESET_DATA_TABLE . "
WHERE imageset_id = $component_id";
$db->sql_query($sql);
}

switch ($component)
{
case 'template':
$sql_from = STYLES_TEMPLATE_TABLE;
break;

case 'theme':
$sql_from = STYLES_THEME_TABLE;
break;

case 'imageset':
$sql_from = STYLES_IMAGESET_TABLE;;
break;
}

$sql = "DELETE FROM $sql_from
WHERE {$component}_id = $component_id";
$db->sql_query($sql);

$sql = 'UPDATE ' . STYLES_TABLE . "
SET {$component}_id = $new_id
WHERE {$component}_id = $component_id";
$db->sql_query($sql);
}

/**
* Display the options which can be used to replace a style/template/theme/imageset
*
* @return boolean Returns true if the component is the only component and can not be deleted.
*/
function display_component_options($component, $component_id, $style_row = false, $style_id = false)
{
global $db, $template, $user;

$is_only_component = true;
$component_in_use = array();
if ($component != 'style')
{
$component_in_use = $this->component_in_use($component, $component_id, $style_id);
}

$sql_where = '';
switch ($component)
{
case 'style':
$sql_from = STYLES_TABLE;
$sql_where = 'WHERE style_active = 1';
break;

case 'template':
$sql_from = STYLES_TEMPLATE_TABLE;
$sql_where = 'WHERE template_inherits_id <> ' . $component_id;
break;

case 'theme':
$sql_from = STYLES_THEME_TABLE;
break;

case 'imageset':
$sql_from = STYLES_IMAGESET_TABLE;
break;
}

$s_options = '';
if (($component != 'style') && empty($component_in_use))
{
// If it is not in use, there must be another component
$is_only_component = false;

$sql = "SELECT {$component}_id, {$component}_name
FROM $sql_from
WHERE {$component}_id = {$component_id}";
$result = $db->sql_query($sql);
$row = $db->sql_fetchrow($result);
$db->sql_freeresult($result);

$s_options .= '<option value="-1" selected="selected">' . $user->lang['DELETE_' . strtoupper($component)] . '</option>';
$s_options .= '<option value="0">' . sprintf($user->lang['KEEP_' . strtoupper($component)], $row[$component . '_name']) . '</option>';
}
else
{
$sql = "SELECT {$component}_id, {$component}_name
FROM $sql_from
$sql_where
ORDER BY {$component}_name ASC";
$result = $db->sql_query($sql);

$s_keep_option = $s_options = '';
while ($row = $db->sql_fetchrow($result))
{
if ($row[$component . '_id'] != $component_id)
{
$is_only_component = false;
$s_options .= '<option value="' . $row[$component . '_id'] . '">' . sprintf($user->lang['REPLACE_WITH_OPTION'], $row[$component . '_name']) . '</option>';
}
else if ($component != 'style')
{
$s_keep_option = '<option value="0" selected="selected">' . sprintf($user->lang['KEEP_' . strtoupper($component)], $row[$component . '_name']) . '</option>';
}
}
$db->sql_freeresult($result);
$s_options = $s_keep_option . $s_options;
}

if (!$style_row)
{
$template->assign_var('S_REPLACE_' . strtoupper($component) . '_OPTIONS', $s_options);
}
else
{
$template->assign_var('S_REPLACE_OPTIONS', $s_options);
if ($component == 'style')
{
$components = array('template', 'theme', 'imageset');
foreach ($components as $component)
{
$this->display_component_options($component, $style_row[$component . '_id'], false, $component_id, true);
}
}
}

return $is_only_component;
}

/**
* Check whether the component is still used by another style or component
*/
function component_in_use($component, $component_id, $style_id = false)
{
global $db;

$component_in_use = array();

if ($style_id)
{
$sql = 'SELECT style_id, style_name
FROM ' . STYLES_TABLE . "
WHERE {$component}_id = {$component_id}
AND style_id <> {$style_id}
ORDER BY style_name ASC";
}
else
{
$sql = 'SELECT style_id, style_name
FROM ' . STYLES_TABLE . "
WHERE {$component}_id = {$component_id}
ORDER BY style_name ASC";
}
$result = $db->sql_query($sql);
while ($row = $db->sql_fetchrow($result))
{
$component_in_use[] = $row['style_name'];
}
$db->sql_freeresult($result);

if ($component === 'template' && ($conflicts = $this->check_inheritance($component, $component_id)))
{
foreach ($conflicts as $temp_id => $conflict_data)
{
$component_in_use[] = $conflict_data['template_name'];
}
}

return $component_in_use;

	}

/**

	}

/**

Line 1813Line 2051
			// Export template core code
if ($mode == 'template' || $inc_template)
{

			// Export template core code
if ($mode == 'template' || $inc_template)
{

				$template_cfg = str_replace(array('{MODE}', '{NAME}', '{COPYRIGHT}', '{VERSION}'), array($mode, $style_row['template_name'], $style_row['template_copyright'], $config['version']), $this->template_cfg);

$use_template_name = '';

				$use_template_name = $style_row['template_name'];




// Add the inherit from variable, depending on it's use...
if ($style_row['template_inherits_id'])


// Add the inherit from variable, depending on it's use...
if ($style_row['template_inherits_id'])

Line 1829Line 2065
					$db->sql_freeresult($result);
}


					$db->sql_freeresult($result);
}


				$template_cfg .= ($use_template_name) ? "\ninherit_from = $use_template_name" : "\n#inherit_from = ";


				$template_cfg = str_replace(array('{MODE}', '{NAME}', '{COPYRIGHT}', '{VERSION}', '{INHERIT_FROM}'), array($mode, $style_row['template_name'], $style_row['template_copyright'], $config['version'], $use_template_name), $this->template_cfg);


				$template_cfg .= "\n\nbbcode_bitfield = {$style_row['bbcode_bitfield']}";

$data[] = array(

				$template_cfg .= "\n\nbbcode_bitfield = {$style_row['bbcode_bitfield']}";

$data[] = array(

Line 2003Line 2240
			{
case 'tar':
$ext = '.tar';

			{
case 'tar':
$ext = '.tar';

					$mimetype = 'x-tar';
$compress = 'compress_tar';

 
				break;

case 'zip':
$ext = '.zip';

				break;

case 'zip':
$ext = '.zip';

					$mimetype = 'zip';

 
				break;

case 'tar.gz':
$ext = '.tar.gz';

				break;

case 'tar.gz':
$ext = '.tar.gz';

					$mimetype = 'x-gzip';

 
				break;

case 'tar.bz2':
$ext = '.tar.bz2';

				break;

case 'tar.bz2':
$ext = '.tar.bz2';

					$mimetype = 'x-bzip2';

 
				break;

default:

				break;

default:

Line 2176Line 2408
			$style_default = request_var('style_default', 0);
$store_db = request_var('store_db', 0);


			$style_default = request_var('style_default', 0);
$store_db = request_var('store_db', 0);


			$sql = "SELECT {$mode}_id







			// If the admin selected the style to be the default style, but forgot to activate it... we will do it for him
if ($style_default)
{
$style_active = 1;
}

$sql = "SELECT {$mode}_id, {$mode}_name

				FROM $sql_from
WHERE {$mode}_id <> $style_id

				FROM $sql_from
WHERE {$mode}_id <> $style_id

				AND {$mode}_name = '" . $db->sql_escape(strtolower($name)) . "'";

				AND LOWER({$mode}_name) = '" . $db->sql_escape(strtolower($name)) . "'";

			$result = $db->sql_query($sql);
$conflict = $db->sql_fetchrow($result);
$db->sql_freeresult($result);

			$result = $db->sql_query($sql);
$conflict = $db->sql_fetchrow($result);
$db->sql_freeresult($result);

Line 2203Line 2441
			{
// a rather elaborate check we have to do here once to avoid trouble later
$check = "{$phpbb_root_path}styles/" . $style_row["{$mode}_path"] . (($mode === 'theme') ? '/theme/stylesheet.css' : '/template');

			{
// a rather elaborate check we have to do here once to avoid trouble later
$check = "{$phpbb_root_path}styles/" . $style_row["{$mode}_path"] . (($mode === 'theme') ? '/theme/stylesheet.css' : '/template');

				if (($style_row["{$mode}_storedb"] != $store_db) && !$store_db && ($safe_mode || !@is_writable($check)))

				if (($style_row["{$mode}_storedb"] != $store_db) && !$store_db && ($safe_mode || !phpbb_is_writable($check)))

				{
$error[] = $user->lang['EDIT_' . strtoupper($mode) . '_STORED_DB'];
$store_db = 1;

				{
$error[] = $user->lang['EDIT_' . strtoupper($mode) . '_STORED_DB'];
$store_db = 1;

Line 2283Line 2521
						{
$theme_data = $this->db_theme_data($style_row);
}

						{
$theme_data = $this->db_theme_data($style_row);
}

						else if (!$store_db && !$safe_mode && @is_writable("{$phpbb_root_path}styles/{$style_row['theme_path']}/theme/stylesheet.css"))

						else if (!$store_db && !$safe_mode && phpbb_is_writable("{$phpbb_root_path}styles/{$style_row['theme_path']}/theme/stylesheet.css"))

						{
$store_db = 1;
$theme_data = $style_row['theme_data'];

						{
$store_db = 1;
$theme_data = $style_row['theme_data'];

Line 2314Line 2552
						}
else
{

						}
else
{

							if (!$store_db && !$safe_mode && @is_writable("{$phpbb_root_path}styles/{$style_row['template_path']}/template"))

							if (!$store_db && !$safe_mode && phpbb_is_writable("{$phpbb_root_path}styles/{$style_row['template_path']}/template"))

							{
$err = $this->store_in_fs('template', $style_row['template_id']);
if ($err)

							{
$err = $this->store_in_fs('template', $style_row['template_id']);
if ($err)

Line 2388Line 2626
				$db->sql_freeresult($result);
}
}

				$db->sql_freeresult($result);
}
}



 

if ($mode == 'template')
{


if ($mode == 'template')
{

Line 2489Line 2726

// Match CSS imports
$matches = array();


// Match CSS imports
$matches = array();

		preg_match_all('/@import url\(["\'](.*)["\']\);/i', $stylesheet, $matches);






		preg_match_all('/@import url\((["\'])(.*)\1\);/i', $stylesheet, $matches);

// remove commented stylesheets (very simple parser, allows only whitespace
// around an @import statement)
preg_match_all('#/\*\s*@import url\((["\'])(.*)\1\);\s\*/#i', $stylesheet, $commented);
$matches[2] = array_diff($matches[2], $commented[2]);


if (sizeof($matches))
{
foreach ($matches[0] as $idx => $match)
{


if (sizeof($matches))
{
foreach ($matches[0] as $idx => $match)
{

				$stylesheet = str_replace($match, acp_styles::load_css_file($theme_row['theme_path'], $matches[1][$idx]), $stylesheet);




				if (isset($matches[2][$idx]))
{
$stylesheet = str_replace($match, acp_styles::load_css_file($theme_row['theme_path'], $matches[2][$idx]), $stylesheet);
}

			}
}


			}
}


Line 2520Line 2765
				{
trigger_error("Could not open {$phpbb_root_path}styles/$template_path$pathfile$file", E_USER_ERROR);
}

				{
trigger_error("Could not open {$phpbb_root_path}styles/$template_path$pathfile$file", E_USER_ERROR);
}

				$template_data = fread($fp, filesize("{$phpbb_root_path}styles/$template_path$pathfile$file"));









$filesize = filesize("{$phpbb_root_path}styles/$template_path$pathfile$file");

if ($filesize)
{
$template_data = fread($fp, $filesize);
}


				fclose($fp);

				fclose($fp);

 

if (!$filesize)
{
// File is empty
continue;
}


if (preg_match_all('#<!-- INCLUDE (.*?\.html) -->#is', $template_data, $matches))
{


if (preg_match_all('#<!-- INCLUDE (.*?\.html) -->#is', $template_data, $matches))
{

Line 3188Line 3446
		$result = $db->sql_query($sql);
$row = $db->sql_fetchrow($result);
$db->sql_freeresult($result);

		$result = $db->sql_query($sql);
$row = $db->sql_fetchrow($result);
$db->sql_freeresult($result);



 

if ($row)
{


if ($row)
{

Line 3204Line 3461

if (isset($cfg_data['inherit_from']) && $cfg_data['inherit_from'])
{


if (isset($cfg_data['inherit_from']) && $cfg_data['inherit_from'])
{

			$sql = "SELECT {$mode}_id, {$mode}_name, {$mode}_path, {$mode}_storedb










			if ($mode === 'template')
{
$select_bf = ', bbcode_bitfield';
}
else
{
$select_bf = '';
}

$sql = "SELECT {$mode}_id, {$mode}_name, {$mode}_path, {$mode}_storedb $select_bf

				FROM $sql_from

				FROM $sql_from

				WHERE {$mode}_name = '" . $db->sql_escape(strtolower($cfg_data['inherit_from'])) . "'

				WHERE {$mode}_name = '" . $db->sql_escape($cfg_data['inherit_from']) . "'

					AND {$mode}_inherits_id = 0";
$result = $db->sql_query($sql);
$row = $db->sql_fetchrow($result);

					AND {$mode}_inherits_id = 0";
$result = $db->sql_query($sql);
$row = $db->sql_fetchrow($result);

Line 3219Line 3485
			{
$inherit_id = $row["{$mode}_id"];
$inherit_path = $row["{$mode}_path"];

			{
$inherit_id = $row["{$mode}_id"];
$inherit_path = $row["{$mode}_path"];

 
				$inherit_bf = ($mode === 'template') ? $row["bbcode_bitfield"] : false;

				$cfg_data['store_db'] = $row["{$mode}_storedb"];
$store_db = $row["{$mode}_storedb"];
}

				$cfg_data['store_db'] = $row["{$mode}_storedb"];
$store_db = $row["{$mode}_storedb"];
}

Line 3227Line 3494
		{
$inherit_id = 0;
$inherit_path = '';

		{
$inherit_id = 0;
$inherit_path = '';

 
			$inherit_bf = false;

		}

		}



 

if (sizeof($error))
{


if (sizeof($error))
{

Line 3248Line 3515
				if (!empty($cfg_data['template_bitfield']))
{
$sql_ary['bbcode_bitfield'] = $cfg_data['template_bitfield'];

				if (!empty($cfg_data['template_bitfield']))
{
$sql_ary['bbcode_bitfield'] = $cfg_data['template_bitfield'];

 
				}
else if ($inherit_bf)
{
$sql_ary['bbcode_bitfield'] = $inherit_bf;

				}
else
{

				}
else
{

Line 3494Line 3765
				$sql_from = STYLES_IMAGESET_TABLE;
break;
}

				$sql_from = STYLES_IMAGESET_TABLE;
break;
}



 

$sql = "SELECT {$mode}_inherits_id
FROM $sql_from


$sql = "SELECT {$mode}_inherits_id
FROM $sql_from

Line 3661Line 3931

$store_db = 0;
$error = array();


$store_db = 0;
$error = array();

		if (!$safe_mode && @is_writable("{$phpbb_root_path}styles/{$path}/template"))

		if (!$safe_mode && phpbb_is_writable("{$phpbb_root_path}styles/{$path}/template"))

		{
$sql = 'SELECT *
FROM ' . STYLES_TEMPLATE_DATA_TABLE . "

		{
$sql = 'SELECT *
FROM ' . STYLES_TEMPLATE_DATA_TABLE . "