config"); exit(); } $language = get_config("lang", "en"); $selected_theme = get_config("theme", "default"); if(!is_theme_dir_ok($theme_dir . $selected_theme)) $selected_theme = "default"; $lpass = get_config('login_pass'); if(!is_null($lpass)&&$lpass!="") { if(!isset($_SESSION['logged_in'])||!$_SESSION['logged_in']) { if(!isset($no_require_login)) { header("Location: login.php"); echo "Wrong password"; exit(); } } } function get_config($name, $default = null) { global $config; if(isset($config->$name)) { if(trim($config->$name)=="") return $default; return ((string)$config->$name); } else { return $default; } } function get_selected_plfields() { global $config, $pl_fields; $plentry = false; if(isset($config->plentry)) $plentry = $config->plentry; $ret = array(); $i = 0; foreach($pl_fields as $field) { if($plentry) { $ret[] = ((string)$plentry->$field)!=""; } else { $ret[] = $i++<3; } } return $ret; } function set_config($name, $value) { } /* if a key is found to be numeric it will be replaced by numb_replace */ function array_to_xml($arr, $xml = null, $numb_replace = "elem") { if(is_null($xml)) { $xml = simplexml_load_string(""); } foreach($arr as $key => $value) { if(is_numeric($key)) $key = $numb_replace; if(is_array($value)) { $tmp = $xml->addChild($key); array_to_xml($value, $tmp, $numb_replace); } else { $xml->addChild($key, htmlspecialchars($value)); } } return $xml; } function get_mpd($type) { try { $port = 6600; if(is_numeric(get_config("mpd_port"))) $port = (int) get_config("mpd_port"); $ret = Net_MPD::factory($type, get_config('mpd_host'), intval($port), get_config("mpd_pass")); $ret->connect(); return $ret; } catch(PEAR_Exception $e) { return false; } } function get_playlist() { return get_mpd("Playlist"); } function get_playback() { return get_mpd("Playback"); } function get_database() { return get_mpd("Database"); } function get_admin() { return get_mpd("Admin"); } /* mimic behaviour of java System.currentTimeMillis() */ // ex: 1172151695935.8 function current_time_millis() { return microtime(true)*1000; } // returns array with available themes function get_available_themes() { global $theme_dir; $dirs = scandir($theme_dir); $themes = array(); foreach($dirs as $dir) { if($dir=="."||$dir=="..") continue; if(is_theme_dir_ok($theme_dir . $dir)) { $themes[] = $dir; } } return $themes; } function is_theme_dir_ok($tdir) { return is_dir($tdir) && file_exists($tdir . "/theme.css") && file_exists($tdir . "/theme.js"); } function generate_hash($val, $salt = false) { if(function_exists("hash")) { if($salt===false) $salt = substr(md5(uniqid(rand(), true)), 0, SALT_LENGTH); $p = hash("sha256", $val . $salt); return "sha:" . $p . $salt; } else return $val; } function check_hash($proper, $check) { $len = strlen($proper); $nhash = generate_hash($check, substr($proper, $len-SALT_LENGTH)); if($proper==$nhash) { return true; } return false; } /* someone find me a php equiv */ function str_byte_count($data) { if(function_exists("mb_strlen")) { /* count bytes, not characters if utf-8, * I imagine this works, but hard to actually test */ return mb_strlen($data, "ascii"); } else { return strlen($data); } } ?>