// Check that site or user theme exists
function theme_exists($theme) {
$getTheme = (isset($_GET['theme']) ? stripinput($_GET['theme']) : "");
if (!file_exists(THEMES) || !is_dir(THEMES)) {
return false;
} elseif ($getTheme != "" && file_exists(THEMES.$getTheme."/theme.php") && file_exists(THEMES.$getTheme."/styles.css")) {
define("THEME", THEMES.$getTheme."/");
setcookie(COOKIE_PREFIX."theme", $getTheme, time() + 31536000, "/", "", "0");
return true;
} elseif (isset($_COOKIE[COOKIE_PREFIX.'theme']) && $_COOKIE[COOKIE_PREFIX.'theme'] != "" && file_exists(THEMES.$_COOKIE[COOKIE_PREFIX.'theme']."/theme.php") && file_exists(THEMES.$_COOKIE[COOKIE_PREFIX.'theme']."/styles.css")) {
$cookieTheme = stripinput($_COOKIE[COOKIE_PREFIX.'theme']);
define("THEME", THEMES.$cookieTheme."/");
return true;
} elseif (file_exists(THEMES.$theme."/theme.php") && file_exists(THEMES.$theme."/styles.css")) {
define("THEME", THEMES.$theme."/");
return true;
} else {
$dh = opendir(THEMES);
while (false !== ($entry = readdir($dh))) {
if ($entry != "." && $entry != ".." && is_dir(THEMES.$entry)) {
if (file_exists(THEMES.$entry."/theme.php") && file_exists(THEMES.$entry."/styles.css")) {
define("THEME", THEMES.$entry."/");
return true;
exit;
}
}
}
closedir($dh);
if (!defined("THEME")) {
return false;
}
}
}