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

  Keine Änderungen   Hinzugefügt   Modifiziert   Entfernt
Zeile 388Zeile 388
{
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}";


Zeile 420Zeile 420
		"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 468
	return $stylesheet;
}


	return $stylesheet;
}


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

function resync_stylesheet($stylesheet)
{
global $db;

// Try and fix any missing cache file names
if(!$stylesheet['cachefile'] && $stylesheet['name'])

function resync_stylesheet($stylesheet)
{
global $db;

// Try and fix any missing cache file names
if(!$stylesheet['cachefile'] && $stylesheet['name'])

	{

	{

		$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']}'");
}

Zeile 486Zeile 491
	}

if(!file_exists(MYBB_ROOT."cache/themes/theme{$stylesheet['tid']}/{$stylesheet['name']}") && !file_exists(MYBB_ROOT."cache/themes/{$stylesheet['tid']}_{$stylesheet['name']}"))

	}

if(!file_exists(MYBB_ROOT."cache/themes/theme{$stylesheet['tid']}/{$stylesheet['name']}") && !file_exists(MYBB_ROOT."cache/themes/{$stylesheet['tid']}_{$stylesheet['name']}"))

	{

	{

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

update_theme_stylesheet_list($stylesheet['tid']);

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

update_theme_stylesheet_list($stylesheet['tid']);





			if($stylesheet['sid'] != 1)
{
$db->update_query("themestylesheets", array('lastmodified' => TIME_NOW), "sid='{$stylesheet['sid']}'");
}
}

			if($stylesheet['sid'] != 1)
{
$db->update_query("themestylesheets", array('lastmodified' => TIME_NOW), "sid='{$stylesheet['sid']}'");
}
}





		return true;
}

		return true;
}





	return false;

	return false;

}







}

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

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

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

	}

	}

	else
{
return "url({$url})";
}
}


	else
{
return "url({$url})";
}
}


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

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

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

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

Zeile 550Zeile 575
	{
$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 684Zeile 709
	}

return $parsed_css;

	}

return $parsed_css;

}

function get_selectors_as_options($css, $selected_item="")
{
$select = "";

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

$selected = false;







}

/**
* @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);
}

$selected = false;


if(is_array($css))
{
uasort($css, "css_selectors_sort_cmp");


if(is_array($css))
{
uasort($css, "css_selectors_sort_cmp");





		foreach($css as $id => $css_array)
{
if(!$css_array['name'])

		foreach($css as $id => $css_array)
{
if(!$css_array['name'])

Zeile 720Zeile 751
		}
}
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'])

	{

	{

		$a['name'] = $a['class_name'];
}


		$a['name'] = $a['class_name'];
}


Zeile 736Zeile 773
	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 923
	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 894Zeile 943
		{
$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 920Zeile 976
	// Get our list of stylesheets
$query = $db->simple_select("themestylesheets", "*", "tid IN ({$tid_list})", array('order_by' => 'tid', 'order_dir' => 'desc'));
while($stylesheet = $db->fetch_array($query))

	// Get our list of stylesheets
$query = $db->simple_select("themestylesheets", "*", "tid IN ({$tid_list})", array('order_by' => 'tid', 'order_dir' => 'desc'));
while($stylesheet = $db->fetch_array($query))

	{

	{

		if(empty($stylesheets[$stylesheet['name']]))
{
if($stylesheet['tid'] != $tid)

		if(empty($stylesheets[$stylesheet['name']]))
{
if($stylesheet['tid'] != $tid)

Zeile 1064Zeile 1120
	$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 1133
	return true;
}


	return true;
}


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

function make_parent_theme_list($tid)
{
static $themes_by_parent;

$themes = array();
if(!is_array($themes_by_parent))

function make_parent_theme_list($tid)
{
static $themes_by_parent;

$themes = array();
if(!is_array($themes_by_parent))

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

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

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

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

Zeile 1093Zeile 1154
			}

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

			}

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

		}
}

		}
}


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


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

Zeile 1102Zeile 1163
	}

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 1112Zeile 1173
		$parents = make_parent_theme_list($theme['pid']);

if(is_array($parents))

		$parents = make_parent_theme_list($theme['pid']);

if(is_array($parents))

		{

		{

			$themes = array_merge($themes, $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 1147Zeile 1213
	$themes = array();

foreach($themes_by_child[$tid] as $theme)

	$themes = array();

foreach($themes_by_child[$tid] as $theme)

	{

	{

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

		$themes[] = $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 1176Zeile 1245
			if($theme['def'] == 1)
{
$theme_cache['default'] = $theme['tid'];

			if($theme['def'] == 1)
{
$theme_cache['default'] = $theme['tid'];

			}

			}

		}

		}

	}


	}


	// Do we have no themes assigned as default?
if(empty($theme_cache['default']))
{
$theme_cache['default'] = 1;
}

	// Do we have no themes assigned as default?
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

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

Zeile 1232Zeile 1305
	}

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

	}

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

	{

	{

		return;
}


		return;
}


Zeile 1246Zeile 1319

// We must have at least the master and 1 other active theme
if($theme_cache['num_themes'] > 2)


// We must have at least the master and 1 other active theme
if($theme_cache['num_themes'] > 2)

			{

			{

				$popup->add_item($lang->delete_theme, "index.php?module=style-themes&action=delete&tid={$theme['tid']}&my_post_key={$mybb->post_code}", "return AdminCP.deleteConfirmation(this, '{$lang->confirm_theme_deletion}')");

				$popup->add_item($lang->delete_theme, "index.php?module=style-themes&action=delete&tid={$theme['tid']}&my_post_key={$mybb->post_code}", "return AdminCP.deleteConfirmation(this, '{$lang->confirm_theme_deletion}')");

			}

			}


if($theme['def'] != 1)
{


if($theme['def'] != 1)
{

Zeile 1260Zeile 1333
				$set_default = "<img src=\"styles/{$page->style}/images/icons/default.png\" alt=\"{$lang->default_theme}\" style=\"vertical-align: middle;\" title=\"{$lang->default_theme}\" />";
}
$popup->add_item($lang->force_on_users, "index.php?module=style-themes&amp;action=force&amp;tid={$theme['tid']}&amp;my_post_key={$mybb->post_code}", "return AdminCP.deleteConfirmation(this, '{$lang->confirm_theme_forced}')");

				$set_default = "<img src=\"styles/{$page->style}/images/icons/default.png\" alt=\"{$lang->default_theme}\" style=\"vertical-align: middle;\" title=\"{$lang->default_theme}\" />";
}
$popup->add_item($lang->force_on_users, "index.php?module=style-themes&amp;action=force&amp;tid={$theme['tid']}&amp;my_post_key={$mybb->post_code}", "return AdminCP.deleteConfirmation(this, '{$lang->confirm_theme_forced}')");

		}

		}

		$popup->add_item($lang->export_theme, "index.php?module=style-themes&amp;action=export&amp;tid={$theme['tid']}");
$popup->add_item($lang->duplicate_theme, "index.php?module=style-themes&amp;action=duplicate&amp;tid={$theme['tid']}");
$table->construct_cell("<div class=\"float_right\">{$set_default}</div><div style=\"margin-left: {$padding}px;\"><strong>{$theme['name']}</strong></div>");
$table->construct_cell(my_number_format($theme['users']), array("class" => "align_center"));
$table->construct_cell($popup->fetch(), array("class" => "align_center"));
$table->construct_row();

		$popup->add_item($lang->export_theme, "index.php?module=style-themes&amp;action=export&amp;tid={$theme['tid']}");
$popup->add_item($lang->duplicate_theme, "index.php?module=style-themes&amp;action=duplicate&amp;tid={$theme['tid']}");
$table->construct_cell("<div class=\"float_right\">{$set_default}</div><div style=\"margin-left: {$padding}px;\"><strong>{$theme['name']}</strong></div>");
$table->construct_cell(my_number_format($theme['users']), array("class" => "align_center"));
$table->construct_cell($popup->fetch(), array("class" => "align_center"));
$table->construct_row();





		// 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)

function build_theme_array($ignoretid = null, $parent=0, $depth=0)

{

{

	global $list;
static $theme_cache;

	global $list;
static $theme_cache;





	if(!is_array($theme_cache))
{
$themes = cache_themes();

	if(!is_array($theme_cache))
{
$themes = cache_themes();

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

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

			}


			}


			$theme_cache[$theme['pid']][$theme['tid']] = $theme;
}
unset($theme);

			$theme_cache[$theme['pid']][$theme['tid']] = $theme;
}
unset($theme);

	}

	}


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


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

	{

	{

		return null;
}

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

		return null;
}

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

		{

		{

			continue;
}

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

			continue;
}

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

	}


	}


	if(!$parent)
{
return $list;

	if(!$parent)
{
return $list;

	}
}







	}
}

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

function fetch_theme_stylesheets($theme)
{
// Fetch list of all of the stylesheets for this theme

function fetch_theme_stylesheets($theme)
{
// Fetch list of all of the stylesheets for this theme

Zeile 1374Zeile 1460
	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