Vergleich admin/inc/functions_themes.php - 1.8.0 - 1.8.19

  Keine Änderungen   Hinzugefügt   Modifiziert   Entfernt
Zeile 220Zeile 220
	else
{
$db->delete_query("themestylesheets", "tid='{$options['tid']}'");

	else
{
$db->delete_query("themestylesheets", "tid='{$options['tid']}'");

		$db->update_query("themes", array("properties" => $db->escape_string(serialize($properties))), "tid='{$options['tid']}'");

		$db->update_query("themes", array("properties" => $db->escape_string(my_serialize($properties))), "tid='{$options['tid']}'");

		$theme_id = $options['tid'];
}


		$theme_id = $options['tid'];
}


Zeile 327Zeile 327
		}
// Now we have our list of built stylesheets, save them
$updated_theme = array(

		}
// Now we have our list of built stylesheets, save them
$updated_theme = array(

			"stylesheets" => $db->escape_string(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(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;
}

/**
* Parse theme variables in a specific string.

	// And done?
return $theme_id;
}

/**
* Parse theme variables in a specific string.

 *

 *

 * @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

Zeile 388Zeile 371
{
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 405Zeile 388
		{
$theme_directory = "cache/themes";
$filename = $tid."_".$filename;

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

		}

		}

		else
{
// Add in empty index.html!

		else
{
// Add in empty index.html!

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)

Zeile 441Zeile 424
	@fwrite($fp_min, $stylesheet_min);
@fclose($fp_min);


	@fwrite($fp_min, $stylesheet_min);
@fclose($fp_min);


	if($mybb->settings['usecdn'] && !empty($mybb->settings['cdnpath']))
{
$cdn_path = rtrim($mybb->settings['cdnpath'], '/\\');
$cache_themes_dir = $cdn_path . '/' . $theme_directory;

$copy_to_cdn = true;

if(!is_dir($cache_themes_dir))
{
if(!@mkdir($cache_themes_dir))
{
$copy_to_cdn = false;
}
}

if($copy_to_cdn)
{
@copy(MYBB_ROOT . "{$theme_directory}/{$filename}", "{$cache_themes_dir}/{$filename}");
@copy(MYBB_ROOT . "{$theme_directory}/{$filename_min}", "{$cache_themes_dir}/{$filename_min}");
}
}

	copy_file_to_cdn(MYBB_ROOT . "{$theme_directory}/{$filename}");
copy_file_to_cdn(MYBB_ROOT . "{$theme_directory}/{$filename_min}");





















return "{$theme_directory}/{$filename}";
}


return "{$theme_directory}/{$filename}";
}

Zeile 487Zeile 451
	return $stylesheet;
}


	return $stylesheet;
}


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

function resync_stylesheet($stylesheet)
{
global $db;

function resync_stylesheet($stylesheet)
{
global $db;





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

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

Zeile 502Zeile 471
	if(!$stylesheet['cachefile'] || strpos($stylesheet['cachefile'], 'css.php') !== false)
{
return false;

	if(!$stylesheet['cachefile'] || strpos($stylesheet['cachefile'], 'css.php') !== false)
{
return false;

	}


	}


	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)

	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)

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

update_theme_stylesheet_list($stylesheet['tid']);

			$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;
}


 
/**
* @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 536Zeile 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 562Zeile 553
		"stylesheets" => ""
);
$tid = $db->insert_query("themes", $new_theme);

		"stylesheets" => ""
);
$tid = $db->insert_query("themes", $new_theme);





	$inherited_properties = false;
$stylesheets = array();
if($parent > 0)
{
$query = $db->simple_select("themes", "*", "tid='".(int)$parent."'");
$parent_theme = $db->fetch_array($query);

	$inherited_properties = false;
$stylesheets = array();
if($parent > 0)
{
$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 608Zeile 599
				foreach($value as $action => $sheets)
{
foreach($sheets as $stylesheet)

				foreach($value as $action => $sheets)
{
foreach($sheets as $stylesheet)

					{

					{

						$stylesheets[$location][$action][] = $stylesheet;
$inherited_check = "{$location}_{$action}";
if(!empty($parent_stylesheets['inherited'][$inherited_check][$stylesheet]))

						$stylesheets[$location][$action][] = $stylesheet;
$inherited_check = "{$location}_{$action}";
if(!empty($parent_stylesheets['inherited'][$inherited_check][$stylesheet]))

						{

						{

							$stylesheets['inherited'][$inherited_check][$stylesheet] = $parent_stylesheets['inherited'][$inherited_check][$stylesheet];

							$stylesheets['inherited'][$inherited_check][$stylesheet] = $parent_stylesheets['inherited'][$inherited_check][$stylesheet];

						}

						}

						else
{
$stylesheets['inherited'][$inherited_check][$stylesheet] = $parent;
}
}
}

						else
{
$stylesheets['inherited'][$inherited_check][$stylesheet] = $parent;
}
}
}

			}
}
}


			}
}
}


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

 
	
$updated_theme = array();

	if(!empty($stylesheets))
{

	if(!empty($stylesheets))
{

		$updated_theme['stylesheets'] = $db->escape_string(serialize($stylesheets));

		$updated_theme['stylesheets'] = $db->escape_string(my_serialize($stylesheets));

	}

	}

	$updated_theme['properties'] = $db->escape_string(serialize($properties));

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

	}


	}


	return $tid;
}


	return $tid;
}


Zeile 705Zeile 698
	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 723Zeile 722
		foreach($css as $id => $css_array)
{
if(!$css_array['name'])

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

			{

			{

				$css_array['name'] = $css_array['class_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";
$selected = true;


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

			}

			}

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

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

Zeile 739Zeile 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 755Zeile 760
	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 771Zeile 782

/**
* Parses CSS supported properties and returns them as an array.


/**
* Parses CSS supported properties and returns them as an array.

 *

 *

 * @param string $values Value of CSS properties from within class or selector
* @return array Array of CSS properties
*/

 * @param string $values Value of CSS properties from within class or selector
* @return array Array of CSS properties
*/

Zeile 832Zeile 843
	foreach($new_css as $css_line)
{
$generated_css .= "\t".trim($css_line)."\n";

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

	// Parse out the CSS
if($css)
{

Zeile 866Zeile 877
		if($break !== false)
{
$actual_occurance = (int)substr($selector, ($break+1));

		if($break !== false)
{
$actual_occurance = (int)substr($selector, ($break+1));

		}


		}


		if(!$actual_occurance)
{
$actual_occurance = 1;

		if(!$actual_occurance)
{
$actual_occurance = 1;

Zeile 899Zeile 910
	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 910Zeile 927
	foreach($stylesheet as $key => $value)
{
if(!is_numeric($key))

	foreach($stylesheet as $key => $value)
{
if(!is_numeric($key))

		{

		{

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

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





	return $sid;
}


	return $sid;
}


function update_theme_stylesheet_list($tid, $theme = false, $update_disporders = false)








/**
* @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 $db, $cache;

	global $mybb, $db, $cache, $plugins;


$stylesheets = array();



$stylesheets = array();


Zeile 965Zeile 989
				$cdnpath = rtrim($mybb->settings['cdnpath'], '/\\').'/';
if(file_exists($cdnpath."cache/themes/theme{$theme_id}/{$stylesheet['name']}") && filemtime(
$cdnpath."cache/themes/theme{$theme_id}/{$stylesheet['name']}"

				$cdnpath = rtrim($mybb->settings['cdnpath'], '/\\').'/';
if(file_exists($cdnpath."cache/themes/theme{$theme_id}/{$stylesheet['name']}") && filemtime(
$cdnpath."cache/themes/theme{$theme_id}/{$stylesheet['name']}"

					) >= $stylesheet['lastmodified']
)
{
$css_url = "cache/themes/theme{$theme_id}/{$stylesheet['name']}";
break;
}

					) >= $stylesheet['lastmodified']
)
{
$css_url = "cache/themes/theme{$theme_id}/{$stylesheet['name']}";
break;
}

			}
else
{

			}
else
{

Zeile 983Zeile 1007
					break;
}
}

					break;
}
}

 
		}

if(is_object($plugins))
{
$plugins->run_hooks('update_theme_stylesheet_list_set_css_url', $css_url);

		}

$attachedto = $stylesheet['attachedto'];

		}

$attachedto = $stylesheet['attachedto'];

Zeile 1021Zeile 1050

// Now we have our list of built stylesheets, save them
$updated_theme = array(


// Now we have our list of built stylesheets, save them
$updated_theme = array(

		"stylesheets" => $db->escape_string(serialize($theme_stylesheets))

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

	);

// Do we have a theme present? If so, update the stylesheet display orders

	);

// Do we have a theme present? If so, update the stylesheet display orders

Zeile 1045Zeile 1074

foreach($stylesheets as $stylesheet)
{


foreach($stylesheets as $stylesheet)
{

			if(!$properties['disporder'][$stylesheet['name']])

			if(!isset($properties['disporder'][$stylesheet['name']]))

			{
$orphaned_stylesheets[] = $stylesheet['name'];
continue;

			{
$orphaned_stylesheets[] = $stylesheet['name'];
continue;

Zeile 1072Zeile 1101

asort($orders);
$properties['disporder'] = $orders;


asort($orders);
$properties['disporder'] = $orders;

		$updated_theme['properties'] = $db->escape_string(serialize($properties));

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

Zeile 1091Zeile 1120
	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;


$themes = array();


$themes = array();

	if(!is_array($themes_by_parent))
{
$theme_cache = cache_themes();
foreach($theme_cache as $key => $theme)

	if(!is_array($themes_by_parent))
{
$theme_cache = cache_themes();
foreach($theme_cache as $key => $theme)

		{

		{

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

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





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

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

Zeile 1128Zeile 1162
		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 1147Zeile 1186
			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 1156Zeile 1195
	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 1166Zeile 1205
		$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 1192Zeile 1234
				$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 1287Zeile 1333
	}
}


	}
}


// 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 1300Zeile 1354
		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 1312Zeile 1366
	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 1388Zeile 1447
	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