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

  Keine Änderungen   Hinzugefügt   Modifiziert   Entfernt
Zeile 329Zeile 329
		$updated_theme = array(
"stylesheets" => $db->escape_string(my_serialize($theme_stylesheets))
);

		$updated_theme = array(
"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}'");
}

Zeile 362Zeile 345
 * @param string $string The string to parse variables for
* @param array $variables Array of variables
* @return string Parsed string with variables replaced

 * @param string $string The string to parse variables for
* @param array $variables Array of variables
* @return string Parsed string with variables replaced

 */

 */

function parse_theme_variables($string, $variables=array())
{
$find = array();

function parse_theme_variables($string, $variables=array())
{
$find = array();

Zeile 377Zeile 360

/**
* Caches a stylesheet to the file system.


/**
* Caches a stylesheet to the file system.

 *

 *

 * @param string $tid The theme ID this stylesheet belongs to.
* @param string $filename The name of the stylesheet.
* @param string $stylesheet The contents of the stylesheet.

 * @param string $tid The theme ID this stylesheet belongs to.
* @param string $filename The name of the stylesheet.
* @param string $stylesheet The contents of the stylesheet.

Zeile 388Zeile 371
{
global $mybb;


{
global $mybb;


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

	$filename = basename($filename);

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

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

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

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

	{

	{

		$theme_directory = "cache/themes";
$filename = $tid."_".$filename;
}

		$theme_directory = "cache/themes";
$filename = $tid."_".$filename;
}

Zeile 420Zeile 403
		"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)

	{
return false;

	{
return false;

	}

@fwrite($fp, $stylesheet);

	}

@fwrite($fp, $stylesheet);

Zeile 468Zeile 451
	return $stylesheet;
}


	return $stylesheet;
}


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

function resync_stylesheet($stylesheet)

function resync_stylesheet($stylesheet)

{

{

	global $db;

// Try and fix any missing cache file names

	global $db;

// Try and fix any missing cache file names

Zeile 481Zeile 469

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

	{

	{

		return false;
}


		return false;
}


Zeile 505Zeile 493
	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 511
	}
}


	}
}


 
/**
* @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 550Zeile 560
	{
$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 686Zeile 696
	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 = "";


{
$select = "";


Zeile 706Zeile 722
			if(!$css_array['name'])
{
$css_array['name'] = $css_array['class_name'];

			if(!$css_array['name'])
{
$css_array['name'] = $css_array['class_name'];

			}


			}


			if($selected_item == $id || (!$selected_item && !$selected))
{
$select .= "<option value=\"{$id}\" selected=\"selected\">{$css_array['name']}</option>\n";

			if($selected_item == $id || (!$selected_item && !$selected))
{
$select .= "<option value=\"{$id}\" selected=\"selected\">{$css_array['name']}</option>\n";

Zeile 722Zeile 738
	return $select;
}


	return $select;
}


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

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

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

	}


	}


	if(!$b['name'])
{
$b['name'] = $b['class_name'];

	if(!$b['name'])
{
$b['name'] = $b['class_name'];

Zeile 736Zeile 758
	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 761Zeile 789
	$css_bits = array();

if(!$values)

	$css_bits = array();

if(!$values)

	{

	{

		return null;
}


		return null;
}


Zeile 841Zeile 869
		$css = preg_replace("#^(?!@)\s*([a-z0-9a+\\\[\]\-\"=_:>\*\.\#\,\s\(\)\|~\^]+)(\s*)\{(\n*)#isu", "\n$1 {\n", $css);
$css = preg_replace("#\s{1,}\{#", " {", $css);
$existing_block = $parsed_css[$selector];

		$css = preg_replace("#^(?!@)\s*([a-z0-9a+\\\[\]\-\"=_:>\*\.\#\,\s\(\)\|~\^]+)(\s*)\{(\n*)#isu", "\n$1 {\n", $css);
$css = preg_replace("#\s{1,}\{#", " {", $css);
$existing_block = $parsed_css[$selector];





		$break = strrpos($selector, "_");
$actual_occurance = 0;
if($break !== false)

		$break = strrpos($selector, "_");
$actual_occurance = 0;
if($break !== false)

		{

		{

			$actual_occurance = (int)substr($selector, ($break+1));

			$actual_occurance = (int)substr($selector, ($break+1));

		}

		}


if(!$actual_occurance)
{


if(!$actual_occurance)
{

Zeile 857Zeile 885
		$occurance = 1;
$pos = 0;
do

		$occurance = 1;
$pos = 0;
do

		{

		{

			$pos = strpos($css, "\n".$existing_block['class_name']." {", $pos);
if($pos === false)

			$pos = strpos($css, "\n".$existing_block['class_name']." {", $pos);
if($pos === false)

			{
break;
}

			{
break;
}

			if($occurance == $actual_occurance)
{
// This is the part we want to replace, now we need to fetch the opening & closing braces

			if($occurance == $actual_occurance)
{
// This is the part we want to replace, now we need to fetch the opening & closing braces

Zeile 874Zeile 902
			++$occurance;
++$pos;
} while($occurance <= $actual_occurance);

			++$occurance;
++$pos;
} while($occurance <= $actual_occurance);

	}

	}

	$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 935
	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 914Zeile 955
	{
return false;
}

	{
return false;
}





	$tid_list = implode(',', $parent_list);

// Get our list of stylesheets

	$tid_list = implode(',', $parent_list);

// Get our list of stylesheets

Zeile 922Zeile 963
	while($stylesheet = $db->fetch_array($query))
{
if(empty($stylesheets[$stylesheet['name']]))

	while($stylesheet = $db->fetch_array($query))
{
if(empty($stylesheets[$stylesheet['name']]))

		{

		{

			if($stylesheet['tid'] != $tid)
{
$stylesheet['inherited'] = $stylesheet['tid'];

			if($stylesheet['tid'] != $tid)
{
$stylesheet['inherited'] = $stylesheet['tid'];

Zeile 938Zeile 979
	{
$sid = $stylesheet['sid'];
$css_url = "css.php?stylesheet={$sid}";

	{
$sid = $stylesheet['sid'];
$css_url = "css.php?stylesheet={$sid}";





		foreach($parent_list as $theme_id)
{
if($mybb->settings['usecdn'] && !empty($mybb->settings['cdnpath']))

		foreach($parent_list as $theme_id)
{
if($mybb->settings['usecdn'] && !empty($mybb->settings['cdnpath']))

Zeile 954Zeile 995
				}
}
else

				}
}
else

			{

			{

				if(file_exists(MYBB_ROOT."cache/themes/theme{$theme_id}/{$stylesheet['name']}") && filemtime(
MYBB_ROOT."cache/themes/theme{$theme_id}/{$stylesheet['name']}"
) >= $stylesheet['lastmodified']

				if(file_exists(MYBB_ROOT."cache/themes/theme{$theme_id}/{$stylesheet['name']}") && filemtime(
MYBB_ROOT."cache/themes/theme{$theme_id}/{$stylesheet['name']}"
) >= $stylesheet['lastmodified']

Zeile 986Zeile 1027
				$attached_file = explode('?', $attached_file);
$attached_actions = explode(",", $attached_file[1]);
$attached_file = $attached_file[0];

				$attached_file = explode('?', $attached_file);
$attached_actions = explode(",", $attached_file[1]);
$attached_file = $attached_file[0];

			}


			}


			if(count($attached_actions) == 0)

			if(count($attached_actions) == 0)

			{

			{

				$attached_actions = array("global");

				$attached_actions = array("global");

			}

			}


foreach($attached_actions as $action)
{


foreach($attached_actions as $action)
{

Zeile 1001Zeile 1042
				{
$theme_stylesheets['inherited']["{$attached_file}_{$action}"][$css_url] = $stylesheet['inherited'];
}

				{
$theme_stylesheets['inherited']["{$attached_file}_{$action}"][$css_url] = $stylesheet['inherited'];
}

			}
}

			}
}

	}

	}





	// Now we have our list of built stylesheets, save them
$updated_theme = array(
"stylesheets" => $db->escape_string(my_serialize($theme_stylesheets))

	// Now we have our list of built stylesheets, save them
$updated_theme = array(
"stylesheets" => $db->escape_string(my_serialize($theme_stylesheets))

Zeile 1017Zeile 1058
		{
$theme_cache = cache_themes();
$theme = $theme_cache[$tid];

		{
$theme_cache = cache_themes();
$theme = $theme_cache[$tid];

		}


		}


		$orders = $orphaned_stylesheets = array();
$properties = $theme['properties'];


		$orders = $orphaned_stylesheets = array();
$properties = $theme['properties'];


Zeile 1034Zeile 1075
			if(!isset($properties['disporder'][$stylesheet['name']]))
{
$orphaned_stylesheets[] = $stylesheet['name'];

			if(!isset($properties['disporder'][$stylesheet['name']]))
{
$orphaned_stylesheets[] = $stylesheet['name'];

				continue;

				continue;

			}

if($properties['disporder'][$stylesheet['name']] > $max_disporder)

			}

if($properties['disporder'][$stylesheet['name']] > $max_disporder)

Zeile 1050Zeile 1091
			$loop = $max_disporder + 1;
$max_disporder = $loop;
foreach($orphaned_stylesheets as $stylesheet)

			$loop = $max_disporder + 1;
$max_disporder = $loop;
foreach($orphaned_stylesheets as $stylesheet)

			{

			{

				$orders[$stylesheet] = $loop;
++$loop;
}

				$orders[$stylesheet] = $loop;
++$loop;
}

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

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





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

		{

		{

			update_theme_stylesheet_list($id, false, $update_disporders);
}
}


			update_theme_stylesheet_list($id, false, $update_disporders);
}
}


	$cache->update_default_theme();


	$cache->update_default_theme();


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

Zeile 1114Zeile 1160
		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 1133Zeile 1184
			if($key == "default")
{
continue;

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

			}


			}


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

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

Zeile 1142Zeile 1193
	if(!isset($themes_by_child[$tid]) || !is_array($themes_by_child[$tid]))
{
return null;

	if(!isset($themes_by_child[$tid]) || !is_array($themes_by_child[$tid]))
{
return null;

	}

$themes = array();

	}

$themes = array();


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


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

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

if(is_array($children))

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

if(is_array($children))

		{

		{

			$themes = array_merge($themes, $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 1178Zeile 1232
				$theme_cache['default'] = $theme['tid'];
}
}

				$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 1273Zeile 1331
	}
}


	}
}


// 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 1286Zeile 1352
		foreach($themes as $key => $theme)
{
if($key == "default")

		foreach($themes as $key => $theme)
{
if($key == "default")

			{

			{

				continue;
}

				continue;
}





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

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

Zeile 1298Zeile 1364
	if(!is_array($theme_cache[$parent]) || $ignoretid === $parent)
{
return null;

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

	}


	}


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

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

		$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 1445
	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