Vergleich admin/inc/functions_themes.php - 1.8.4 - 1.8.21

  Keine Änderungen   Hinzugefügt   Modifiziert   Entfernt
Zeile 262Zeile 262
		$loop = 1;
foreach($theme['stylesheets']['stylesheet'] as $stylesheet)
{

		$loop = 1;
foreach($theme['stylesheets']['stylesheet'] as $stylesheet)
{

 
			$stylesheet['attributes']['name'] = my_substr($stylesheet['attributes']['name'], 0, 30);


			if(substr($stylesheet['attributes']['name'], -4) != ".css")

			if(substr($stylesheet['attributes']['name'], -4) != ".css")

			{

			{

				continue;

				continue;

			}


			}


			if(empty($stylesheet['attributes']['lastmodified']))

			if(empty($stylesheet['attributes']['lastmodified']))

			{

			{

				$stylesheet['attributes']['lastmodified'] = TIME_NOW;

				$stylesheet['attributes']['lastmodified'] = TIME_NOW;

			}

			}


if(empty($stylesheet['attributes']['disporder']))
{
$stylesheet['attributes']['disporder'] = $loop;


if(empty($stylesheet['attributes']['disporder']))
{
$stylesheet['attributes']['disporder'] = $loop;

			}

			}


if(empty($stylesheet['attributes']['attachedto']))
{


if(empty($stylesheet['attributes']['attachedto']))
{

Zeile 304Zeile 306
			if(!$attachedto)
{
$attachedto = "global";

			if(!$attachedto)
{
$attachedto = "global";

			}

			}


// private.php?compose,folders|usercp.php,global|global
$attachedto = explode("|", $attachedto);


// private.php?compose,folders|usercp.php,global|global
$attachedto = explode("|", $attachedto);

Zeile 330Zeile 332
			"stylesheets" => $db->escape_string(my_serialize($theme_stylesheets))
);


			"stylesheets" => $db->escape_string(my_serialize($theme_stylesheets))
);


		if(is_array($properties['disporder']))
{
asort($properties['disporder'], SORT_NUMERIC);

// Because inherited stylesheets can mess this up
$loop = 1;
$orders = array();
foreach($properties['disporder'] as $filename => $order)
{
$orders[$filename] = $loop;
++$loop;
}

$properties['disporder'] = $orders;
$updated_theme['properties'] = $db->escape_string(my_serialize($properties));
}

		$db->update_query("themes", $updated_theme, "tid='{$theme_id}'");
}



















		$db->update_query("themes", $updated_theme, "tid='{$theme_id}'");
}

update_theme_stylesheet_list($theme_id);

	update_theme_stylesheet_list($theme_id);





// And done?
return $theme_id;


// And done?
return $theme_id;

Zeile 364Zeile 349
 * @return string Parsed string with variables replaced
*/
function parse_theme_variables($string, $variables=array())

 * @return string Parsed string with variables replaced
*/
function parse_theme_variables($string, $variables=array())

{

{

	$find = array();
$replace = array();
foreach(array_keys($variables) as $variable)

	$find = array();
$replace = array();
foreach(array_keys($variables) as $variable)

Zeile 388Zeile 373
{
global $mybb;


{
global $mybb;


	$filename = str_replace('/', '', $filename);

	$filename = basename($filename);

	$tid = (int) $tid;
$theme_directory = "cache/themes/theme{$tid}";

	$tid = (int) $tid;
$theme_directory = "cache/themes/theme{$tid}";

 

if(substr($filename, -4) != ".css")
{
return false;
}


// If we're in safe mode save to the main theme folder by default
if($mybb->safemode)


// If we're in safe mode save to the main theme folder by default
if($mybb->safemode)

Zeile 420Zeile 410
		"theme" => $theme_directory
);
$stylesheet = parse_theme_variables($stylesheet, $theme_vars);

		"theme" => $theme_directory
);
$stylesheet = parse_theme_variables($stylesheet, $theme_vars);

	$stylesheet = preg_replace_callback("#url\((\"|'|)(.*)\\1\)#", create_function('$matches', 'return fix_css_urls($matches[2]);'), $stylesheet);

	$stylesheet = preg_replace_callback("#url\((\"|'|)([^\"'\s]*?)\\1\)#", 'fix_css_urls_callback', $stylesheet);


$fp = @fopen(MYBB_ROOT . "{$theme_directory}/{$filename}", "wb");
if(!$fp)


$fp = @fopen(MYBB_ROOT . "{$theme_directory}/{$filename}", "wb");
if(!$fp)

Zeile 468Zeile 458
	return $stylesheet;
}


	return $stylesheet;
}


 
/**
* @param array $stylesheet
*
* @return bool
*/

function resync_stylesheet($stylesheet)
{
global $db;

function resync_stylesheet($stylesheet)
{
global $db;

Zeile 477Zeile 472
	{
$stylesheet['cachefile'] = $stylesheet['name'];
$db->update_query("themestylesheets", array('cachefile' => $db->escape_string($stylesheet['name'])), "sid='{$stylesheet['sid']}'");

	{
$stylesheet['cachefile'] = $stylesheet['name'];
$db->update_query("themestylesheets", array('cachefile' => $db->escape_string($stylesheet['name'])), "sid='{$stylesheet['sid']}'");

	}

	}


// Still don't have the cache file name or is it not a flat file? Return false
if(!$stylesheet['cachefile'] || strpos($stylesheet['cachefile'], 'css.php') !== false)


// Still don't have the cache file name or is it not a flat file? Return false
if(!$stylesheet['cachefile'] || strpos($stylesheet['cachefile'], 'css.php') !== false)

Zeile 505Zeile 500
	return false;
}


	return false;
}


 
/**
* @deprecated
* @param string $url
*
* @return string
*/

function fix_css_urls($url)
{
if(!preg_match("#^([a-z0-9]+\:|/)#i", $url) && strpos($url, "../../../") === false)

function fix_css_urls($url)
{
if(!preg_match("#^([a-z0-9]+\:|/)#i", $url) && strpos($url, "../../../") === false)

Zeile 517Zeile 518
	}
}


	}
}


 
/**
* @param array $matches Matches.
*
* @return string
*/
function fix_css_urls_callback($matches)
{
return fix_css_urls($matches[2]);
}

/**
* @deprecated
* @param string $url
*
* @return string
*/

function unfix_css_urls($url)
{
return str_replace("../../../", "", $url);

function unfix_css_urls($url)
{
return str_replace("../../../", "", $url);

Zeile 547Zeile 564
	$inherited_properties = false;
$stylesheets = array();
if($parent > 0)

	$inherited_properties = false;
$stylesheets = array();
if($parent > 0)

	{

	{

		$query = $db->simple_select("themes", "*", "tid='".(int)$parent."'");
$parent_theme = $db->fetch_array($query);

		$query = $db->simple_select("themes", "*", "tid='".(int)$parent."'");
$parent_theme = $db->fetch_array($query);

		if(count($properties) == 0 || !is_array($properties))

		if(!is_array($properties) || count($properties) == 0)

		{
$parent_properties = my_unserialize($parent_theme['properties']);
if(!empty($parent_properties))

		{
$parent_properties = my_unserialize($parent_theme['properties']);
if(!empty($parent_properties))

Zeile 558Zeile 575
				foreach($parent_properties as $property => $value)
{
if($property == "inherited")

				foreach($parent_properties as $property => $value)
{
if($property == "inherited")

					{

					{

						continue;
}

$properties[$property] = $value;
if(!empty($parent_properties['inherited'][$property]))

						continue;
}

$properties[$property] = $value;
if(!empty($parent_properties['inherited'][$property]))

					{

					{

						$properties['inherited'][$property] = $parent_properties['inherited'][$property];
}
else

						$properties['inherited'][$property] = $parent_properties['inherited'][$property];
}
else

Zeile 613Zeile 630
		);
$properties['logo'] = parse_theme_variables($properties['logo'], $theme_vars);
}

		);
$properties['logo'] = parse_theme_variables($properties['logo'], $theme_vars);
}

 
	
$updated_theme = array();

	if(!empty($stylesheets))
{
$updated_theme['stylesheets'] = $db->escape_string(my_serialize($stylesheets));

	if(!empty($stylesheets))
{
$updated_theme['stylesheets'] = $db->escape_string(my_serialize($stylesheets));

Zeile 649Zeile 668
	// Fetch out classes and comments
preg_match_all('#(\/\*(.|[\r\n])*?\*\/)?([a-z0-9a+\\\[\]\-\"=_:>\*\.\#\,\s\(\)\|~|@\^]+)(\s*)\{(.*?)\}\n#msi', $stripped_css, $matches, PREG_PATTERN_ORDER);
$total = count($matches[1]);

	// Fetch out classes and comments
preg_match_all('#(\/\*(.|[\r\n])*?\*\/)?([a-z0-9a+\\\[\]\-\"=_:>\*\.\#\,\s\(\)\|~|@\^]+)(\s*)\{(.*?)\}\n#msi', $stripped_css, $matches, PREG_PATTERN_ORDER);
$total = count($matches[1]);





	$parsed_css = array();

for($i=0; $i < $total; $i++)

	$parsed_css = array();

for($i=0; $i < $total; $i++)

Zeile 684Zeile 703
	}

return $parsed_css;

	}

return $parsed_css;

}

function get_selectors_as_options($css, $selected_item="")







}

/**
* @param array|string $css
* @param int $selected_item
*
* @return string
*/
function get_selectors_as_options($css, $selected_item=null)

{
$select = "";

if(!is_array($css))
{
$css = css_to_array($css);

{
$select = "";

if(!is_array($css))
{
$css = css_to_array($css);

	}

	}


$selected = false;



$selected = false;


Zeile 722Zeile 747
	return $select;
}


	return $select;
}


 
/**
* @param array $a
* @param array $b
*
* @return int
*/

function css_selectors_sort_cmp($a, $b)
{
if(!$a['name'])

function css_selectors_sort_cmp($a, $b)
{
if(!$a['name'])

Zeile 736Zeile 767
	return strcmp($a['name'], $b['name']);
}


	return strcmp($a['name'], $b['name']);
}


 
/**
* @param array|string $css
* @param string $id
*
* @return array|bool
*/

function get_css_properties($css, $id)
{
if(!is_array($css))

function get_css_properties($css, $id)
{
if(!is_array($css))

Zeile 880Zeile 917
	return $css;
}


	return $css;
}


 
/**
* @param array $stylesheet
* @param int $tid
*
* @return bool|int
*/

function copy_stylesheet_to_theme($stylesheet, $tid)
{
global $db;

function copy_stylesheet_to_theme($stylesheet, $tid)
{
global $db;

Zeile 895Zeile 938
			$new_stylesheet[$db->escape_string($key)] = $db->escape_string($value);
}
}

			$new_stylesheet[$db->escape_string($key)] = $db->escape_string($value);
}
}





	$sid = $db->insert_query("themestylesheets", $new_stylesheet);

return $sid;
}


	$sid = $db->insert_query("themestylesheets", $new_stylesheet);

return $sid;
}


 
/**
* @param int $tid
* @param bool|array $theme
* @param bool $update_disporders
*
* @return bool
*/

function update_theme_stylesheet_list($tid, $theme = false, $update_disporders = true)
{
global $mybb, $db, $cache, $plugins;

function update_theme_stylesheet_list($tid, $theme = false, $update_disporders = true)
{
global $mybb, $db, $cache, $plugins;

Zeile 1064Zeile 1114
	$db->update_query("themes", $updated_theme, "tid = '{$tid}'");

// Do we have any children themes that need updating too?

	$db->update_query("themes", $updated_theme, "tid = '{$tid}'");

// Do we have any children themes that need updating too?

	if(count($child_list) > 0)

	if(is_array($child_list) && count($child_list) > 0)

	{
foreach($child_list as $id)
{

	{
foreach($child_list as $id)
{

Zeile 1077Zeile 1127
	return true;
}


	return true;
}


 
/**
* @param int $tid
*
* @return array|bool
*/

function make_parent_theme_list($tid)
{
static $themes_by_parent;

function make_parent_theme_list($tid)
{
static $themes_by_parent;

Zeile 1097Zeile 1152
	}

if(!isset($themes_by_parent[$tid]) || !is_array($themes_by_parent[$tid]))

	}

if(!isset($themes_by_parent[$tid]) || !is_array($themes_by_parent[$tid]))

	{
return false;
}

	{
return false;
}


reset($themes_by_parent);


reset($themes_by_parent);

	reset($themes_by_parent[$tid]);

$themes = array();

	reset($themes_by_parent[$tid]);

$themes = array();


foreach($themes_by_parent[$tid] as $key => $theme)
{


foreach($themes_by_parent[$tid] as $key => $theme)
{

Zeile 1114Zeile 1169
		if(is_array($parents))
{
$themes = array_merge($themes, $parents);

		if(is_array($parents))
{
$themes = array_merge($themes, $parents);

		}
}


		}
}


	return $themes;
}

	return $themes;
}









/**
* @param int $tid
*
* @return array|null
*/

function make_child_theme_list($tid)
{
static $themes_by_child;

function make_child_theme_list($tid)
{
static $themes_by_child;

Zeile 1129Zeile 1189
	{
$theme_cache = cache_themes();
foreach($theme_cache as $key => $theme)

	{
$theme_cache = cache_themes();
foreach($theme_cache as $key => $theme)

		{
if($key == "default")
{
continue;
}

		{
if($key == "default")
{
continue;
}


$themes_by_child[$theme['pid']][$theme['tid']] = $theme;
}


$themes_by_child[$theme['pid']][$theme['tid']] = $theme;
}

	}


	}


	if(!isset($themes_by_child[$tid]) || !is_array($themes_by_child[$tid]))

	if(!isset($themes_by_child[$tid]) || !is_array($themes_by_child[$tid]))

	{

	{

		return null;
}


		return null;
}


Zeile 1149Zeile 1209
	foreach($themes_by_child[$tid] as $theme)
{
$themes[] = $theme['tid'];

	foreach($themes_by_child[$tid] as $theme)
{
$themes[] = $theme['tid'];

		$children = make_child_theme_list($theme['tid']);


		$children = make_child_theme_list($theme['tid']);


		if(is_array($children))
{
$themes = array_merge($themes, $children);
}
}

		if(is_array($children))
{
$themes = array_merge($themes, $children);
}
}





	return $themes;
}


	return $themes;
}


 
/**
* @return array
*/

function cache_themes()
{
global $db, $theme_cache;

function cache_themes()
{
global $db, $theme_cache;

Zeile 1184Zeile 1247
	if(empty($theme_cache['default']))
{
$theme_cache['default'] = 1;

	if(empty($theme_cache['default']))
{
$theme_cache['default'] = 1;

	}

	}


return $theme_cache;
}



return $theme_cache;
}


 
/**
* @param int $parent
* @param int $depth
*/

function build_theme_list($parent=0, $depth=0)
{
global $mybb, $db, $table, $lang, $page; // Global $table is bad, but it will have to do for now
static $theme_cache;

function build_theme_list($parent=0, $depth=0)
{
global $mybb, $db, $table, $lang, $page; // Global $table is bad, but it will have to do for now
static $theme_cache;





	$padding = $depth*20; // Padding

if(!is_array($theme_cache))

	$padding = $depth*20; // Padding

if(!is_array($theme_cache))

Zeile 1201Zeile 1268
		$themes = cache_themes();
$query = $db->simple_select("users", "style, COUNT(uid) AS users", "", array('group_by' => 'style'));
while($user_themes = $db->fetch_array($query))

		$themes = cache_themes();
$query = $db->simple_select("users", "style, COUNT(uid) AS users", "", array('group_by' => 'style'));
while($user_themes = $db->fetch_array($query))

		{

		{

			if($user_themes['style'] == 0)
{
$user_themes['style'] = $themes['default'];

			if($user_themes['style'] == 0)
{
$user_themes['style'] = $themes['default'];

Zeile 1232Zeile 1299
	}

if(!is_array($theme_cache[$parent]))

	}

if(!is_array($theme_cache[$parent]))

	{
return;
}


	{
return;
}


	foreach($theme_cache[$parent] as $theme)
{
$popup = new PopupMenu("theme_{$theme['tid']}", $lang->options);

	foreach($theme_cache[$parent] as $theme)
{
$popup = new PopupMenu("theme_{$theme['tid']}", $lang->options);

Zeile 1270Zeile 1337

// Fetch & build any child themes
build_theme_list($theme['tid'], ++$depth);


// Fetch & build any child themes
build_theme_list($theme['tid'], ++$depth);

	}

	}

}


}


// returns an array which can be sent to generate_select_box()









/**
* returns an array which can be sent to generate_select_box()
*
* @param int $ignoretid
* @param int $parent
* @param int $depth
*
* @return null|string
*/

function build_theme_array($ignoretid = null, $parent=0, $depth=0)
{
global $list;

function build_theme_array($ignoretid = null, $parent=0, $depth=0)
{
global $list;

Zeile 1288Zeile 1363
			if($key == "default")
{
continue;

			if($key == "default")
{
continue;

			}


			}


			$theme_cache[$theme['pid']][$theme['tid']] = $theme;

			$theme_cache[$theme['pid']][$theme['tid']] = $theme;

		}

		}

		unset($theme);

		unset($theme);

	}

	}


if(!is_array($theme_cache[$parent]) || $ignoretid === $parent)
{


if(!is_array($theme_cache[$parent]) || $ignoretid === $parent)
{

Zeile 1303Zeile 1378
	foreach($theme_cache[$parent] as $theme)
{
if($ignoretid === $theme['tid'])

	foreach($theme_cache[$parent] as $theme)
{
if($ignoretid === $theme['tid'])

		{
continue;
}

		{
continue;
}


$list[$theme['tid']] = str_repeat("--", $depth).$theme['name'];
// Fetch & build any child themes
build_theme_array($ignoretid, $theme['tid'], $depth+1);


$list[$theme['tid']] = str_repeat("--", $depth).$theme['name'];
// Fetch & build any child themes
build_theme_array($ignoretid, $theme['tid'], $depth+1);

	}

	}


if(!$parent)
{


if(!$parent)
{

Zeile 1318Zeile 1393
	}
}


	}
}


 
/**
* @param array $theme
*
* @return array|bool
*/

function fetch_theme_stylesheets($theme)
{
// Fetch list of all of the stylesheets for this theme
$file_stylesheets = my_unserialize($theme['stylesheets']);

function fetch_theme_stylesheets($theme)
{
// Fetch list of all of the stylesheets for this theme
$file_stylesheets = my_unserialize($theme['stylesheets']);





	if(!is_array($file_stylesheets))
{
return false;

	if(!is_array($file_stylesheets))
{
return false;

Zeile 1374Zeile 1454
	return $stylesheets;
}


	return $stylesheets;
}


 
/**
* @param string $css
*
* @return string
*/

function upgrade_css_120_to_140($css)
{
// Update our CSS to the new stuff in 1.4

function upgrade_css_120_to_140($css)
{
// Update our CSS to the new stuff in 1.4