Location: PHPKode > scripts > AmaroK Web Frontend > obsidianmusic-2.3.0/inc/global.php
<?php

//
//  ObsidianMusic
//   a.k.a. amaroK Web Frontend 2.0
//
//  Created 11/24/05
//   Copyright (C) Ryan Loebs (ObsidianX) 2005/2006
//   See LICENSE for GPL
//
//  global.php - Creates the basics for each page
//
///////////////////////////////////////

if(eregi("global.php", $_SERVER['PHP_SELF'])){
	die("Cannot access directly.");
}

// Set action to nothing if there isn't one in the URI
//    making the page load the "latest songs" by default
if(@$_GET['action']){
	$action = $_GET['action'];
}else{
	$action = "latest";
}

// Make sure the user isn't trying to listen to a song
if($action != "stream"){
	// Create the patTemplate class
	$tpl = new patTemplate();
	//  and set the base directory for the themes
	$tpl->setBasedir("template");
	$parse = false;
	
	if($enabled === true){
		// If the site is password protected then ensure the user has logged in
		if($locked){
			if($authtype == 1){
				// Sessions
				$check = @$_SESSION['om_check'];
			}else{
				// Cookies
				$check = @$_COOKIE['om_check'];
			}
			if($check == sha1("authed")){
				$authorized = true;
			}
		}
		if($locked && @!$authorized){
			if($action != "auth" || @$_GET['error']){
				$parse = true;
				$tpl->readTemplatesFromFile("auth.tpl");
				$tpl->addVar("auth", "user", _AUTH_USER);
				$tpl->addVar("auth", "pass", _AUTH_PASS);
				$tpl->addVar("auth", "message", _AUTH_MESSAGE);
				$tpl->addVar("auth", "theme", $theme);
				if(@$_GET['error']){
					$tpl->addVar("auth", "error", _AUTH_BADLOGIN);
				}
				$tpl->addVar("auth", "login", _AUTH_LOGIN);
			}else{
				require_once("inc/auth.users.php");
				if(@$_POST['user'] && @$_POST['pass']){
					if(@$userlist[$_POST['user']]){
						if(sha1($_POST['pass']) == $userlist[$_POST['user']]){
							if($authtype == 1){
								$_SESSION['om_check'] = sha1("authed");
							}else{
								setcookie("om_check", sha1("authed"), time()+$cookielen);
							}
							die(header("Location: ?"));
						}else{
							die(header("Location: ?action=auth&error=1"));
						}
					}else{
						die(header("Location: ?action=auth&error=1"));
					}
				}else{
					die(header("Location: ?action=auth&error=1"));
				}
			}
		}else if($action != "play"){
			$parse = true;
			// Load main template
			$tpl->readTemplatesFromFile("root.tpl");
			// If the user is allowed to choose a theme then do all that jazz
			if($allowchoose){
				$tpl->addRows("theme", getThemes());
				$tpl->addVar("themebox", "themehead", _THEME);
				$tpl->addVar("themebox", "change", _CHANGE);
				$tpl->setAttribute("themebox", "visibility", "visible");
				if(@$_GET['themesel']){
					$_SESSION['theme'] = $_GET['themesel'];
				}
				if(@$_SESSION['theme']){
					$tpl->addVar("root", "theme", $_SESSION['theme']);
				}else{
					$tpl->addVar("root", "theme", $theme);
				}
			}else{
				$tpl->addVar("root", "theme", $theme);
			}
			// Blah blah user has chosen a sort method
			if(@$_SESSION['sort']){
				$sort = $_SESSION['sort'];
			}else{
				$sort = "song";
			}
			if($locked && $authorized){
				$tpl->setAttribute("logout", "visibility", "visible");
			}
			// Get the song count
			$count = query(getquery("count"));
			$count = fetch_array($count);
			$tpl->addVar("root", "count", $count[0]);
			
			// Header
			$tpl->addVar("root", "serving", _SERVING);
			$tpl->addVar("root", "servsong", _SERVSONG);
			// Left Navigation
			$tpl->addVar("nav", "navhead", _NAV_HEADER);
			$tpl->addVar("nav", "search", _SEARCH);
			$tpl->addVar("nav", "plisthead", _PLIST_HEADER);
			$tpl->addVar("nav", "latest", _NAV_LATEST);
			$tpl->addVar("nav", "all", _NAV_ALL);
			$tpl->addVar("nav", "abc", _NAV_ABC);
			$tpl->addVar("nav", "genre", _NAV_GENRE);
			$tpl->addVar("nav", "year", _NAV_YEAR);
			$tpl->addVar("nav", "album", _NAV_ALBUM);
			$tpl->addVar("nav", "artist", _NAV_ARTIST);
			$tpl->addVar("nav", "navsearch", _NAV_SEARCH);
			$tpl->addVar("nav", "plist", _NAV_PLIST);
			$tpl->addVar("nav", "random", _NAV_RANDOM);
			$tpl->addVar("logout", "logout", _NAV_LOGOUT);
			$tpl->addVar("buttons", "add", _PLIST_ADD);
			$tpl->addVar("buttons", "remove", _PLIST_REMOVE);
			$tpl->addVar("buttons", "clear", _PLIST_CLEAR);
			$tpl->addVar("buttons", "play", _PLIST_PLAY);
			// Listing Headers
			$tpl->addVar("listing", "song", _SONG);
			$tpl->addVar("listing", "album", _ALBUM);
			$tpl->addVar("listing", "length", _LENGTH);
			$tpl->addVar("listing", "track", _TRACK);
			$spacespan = 5;
			// Footer
			$tpl->addVar("root", "pagegen", _PAGEGEN);
			$tpl->addVar("root", "pagesec", _PAGEGEN_SEC);
			// Activate GZIP compression and put a little message in the footer
			if($gzip){
				$tpl->addVar("root", "gzip", _GZIP_COMP);
				$tpl->applyOutputFilter("Gzip");
			}
			// Activate Caching and put a little message in the footer
			if($cache){
				$tpl->addVar("root", "cache", _CACHE);
				$cache = array("cacheFolder" => "inc/cache/",
						"lifetime" => "auto");
				$tpl->useTemplateCache("File", $cache);
			}
			if($action == "latest" || $action == "all"){
				$tpl->loadTemplate("songs");
			}
		}
	}else{
		// Load the offline page template if the site isn't enabled
		$tpl->readTemplatesFromFile("disabled.tpl");
		$tpl->addVar("disabled", "disabled_title", _OFFLINE_TITLE);
		$tpl->addVar("disabled", "theme", $theme);
		$tpl->addVar("disabled", "message", _OFFLINE);
		$tpl->displayParsedTemplate();
	}
}

Return current item: AmaroK Web Frontend