Vergleich admin/inc/functions_themes.php - 1.8.5 - 1.8.14

  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;

function resync_stylesheet($stylesheet)
{
global $db;

Zeile 496Zeile 501
			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 false;
}


		return true;
}

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 566Zeile 591
					if(!empty($parent_properties['inherited'][$property]))
{
$properties['inherited'][$property] = $parent_properties['inherited'][$property];

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

					}

					}

					else
{
$properties['inherited'][$property] = $parent;

					else
{
$properties['inherited'][$property] = $parent;

Zeile 580Zeile 605
		if(!empty($parent_stylesheets))
{
foreach($parent_stylesheets as $location => $value)

		if(!empty($parent_stylesheets))
{
foreach($parent_stylesheets as $location => $value)

			{

			{

				if($location == "inherited")
{
continue;

				if($location == "inherited")
{
continue;

Zeile 603Zeile 628
					}
}
}

					}
}
}

		}
}


		}
}


	if(!$inherited_properties)

	if(!$inherited_properties)

	{

	{

		$theme_vars = array(
"theme" => "cache/themes/theme{$tid}"
);
$properties['logo'] = parse_theme_variables($properties['logo'], $theme_vars);

		$theme_vars = array(
"theme" => "cache/themes/theme{$tid}"
);
$properties['logo'] = parse_theme_variables($properties['logo'], $theme_vars);

	}

	}

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

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





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

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

Zeile 670Zeile 695
		}
$class_id = md5($class_name);
if(isset($already_parsed[$class_id]))

		}
$class_id = md5($class_name);
if(isset($already_parsed[$class_id]))

		{

		{

			$already_parsed[$class_id]++;
$class_id .= "_".$already_parsed[$class_id];
}

			$already_parsed[$class_id]++;
$class_id .= "_".$already_parsed[$class_id];
}

Zeile 683Zeile 708
		$parsed_css[$class_id] = array("class_name" => $class_name, "name" => $name, "description" => $description, "values" => $values);
}


		$parsed_css[$class_id] = array("class_name" => $class_name, "name" => $name, "description" => $description, "values" => $values);
}


	return $parsed_css;
}

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

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

$selected = false;







	return $parsed_css;
}

/**
* @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 709Zeile 740
			}

if($selected_item == $id || (!$selected_item && !$selected))

			}

if($selected_item == $id || (!$selected_item && !$selected))

			{

			{

				$select .= "<option value=\"{$id}\" selected=\"selected\">{$css_array['name']}</option>\n";
$selected = true;
}

				$select .= "<option value=\"{$id}\" selected=\"selected\">{$css_array['name']}</option>\n";
$selected = true;
}

Zeile 722Zeile 753
	return $select;
}


	return $select;
}


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

function css_selectors_sort_cmp($a, $b)

function css_selectors_sort_cmp($a, $b)

{

{

	if(!$a['name'])

	if(!$a['name'])

	{

	{

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

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

	}

	}


if(!$b['name'])
{


if(!$b['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)

function get_css_properties($css, $id)

{

{

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

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

Zeile 807Zeile 850
	$new_css = str_replace(array("\r\n", "\n", "\r"), "\n", $new_css);

$generated_css = '';

	$new_css = str_replace(array("\r\n", "\n", "\r"), "\n", $new_css);

$generated_css = '';





	// Build the new CSS properties list
$new_css = explode("\n", $new_css);
foreach($new_css as $css_line)
{
$generated_css .= "\t".trim($css_line)."\n";

	// Build the new CSS properties list
$new_css = explode("\n", $new_css);
foreach($new_css as $css_line)
{
$generated_css .= "\t".trim($css_line)."\n";

	}

$parsed_css = array();

	}

$parsed_css = array();


// Parse out the CSS
if($css)
{
$parsed_css = css_to_array($css);


// Parse out the CSS
if($css)
{
$parsed_css = css_to_array($css);

	}


	}


	if(!$class_id)
{
$class_id = $parsed_css[$selector]['class_name'];

	if(!$class_id)
{
$class_id = $parsed_css[$selector]['class_name'];

Zeile 850Zeile 893
		}

if(!$actual_occurance)

		}

if(!$actual_occurance)

		{

		{

			$actual_occurance = 1;
}


			$actual_occurance = 1;
}


Zeile 878Zeile 921
	$css = preg_replace("#{\n*#s", "{\n", $css);
$css = preg_replace("#\s*\}\s*#", "\n}\n\n", $css);
return $css;

	$css = preg_replace("#{\n*#s", "{\n", $css);
$css = preg_replace("#\s*\}\s*#", "\n}\n\n", $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 901Zeile 950
	return $sid;
}


	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;

$stylesheets = array();

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

$stylesheets = array();





	$child_list = make_child_theme_list($tid);
$parent_list = make_parent_theme_list($tid);


	$child_list = make_child_theme_list($tid);
$parent_list = make_parent_theme_list($tid);


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&amp;action=delete&amp;tid={$theme['tid']}&amp;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&amp;action=delete&amp;tid={$theme['tid']}&amp;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