Location: PHPKode > projects > web-cp - Web Hosting Control Panel > webcp/web/parser.inc.phps
<?	/*
	// File:	parser.inc.php
	// Purpose:	Skin Parser Module
	// Creation:	2001-10-29
	// Author:	Felix <hide@address.com>
	*/

//
// Check if needed vars are there
if (!isset($cfg))
	return 'parser.inc.phps :: $cfg not loaded (/web/config.inc.php)';
if (!isset($T))
	return 'parser.inc.phps :: $T not loaded (/web/lang/*.phps)';
if (!isset($url))
	return 'parser.inc.phps :: $url not loaded (HTTP GET or /web/init.inc.phps)';
if (!isset($cp))
	return 'parser.inc.phps :: $cp not loaded (HTTP GET or /web/init.inc.phps)';
if (!isset($skin))
	$skin = "default";

//
// Prepare value for tag {WHERE AM I} depending on the current Panel viewed
if ($cp == "personal")
	$whereami = $personaldata['username']." - ".$domaindata['host'].".".$domaindata['domain'];
elseif ($cp == "domain")
	$whereami = $domaindata['host'].".".$domaindata['domain'];
elseif ($cp == "reseller")
	$whereami = $T['panel'][2];
elseif ($cp == "server")
	$whereami = $cfg['sysname'];
else 
	$whereami = "";

//
// Prepare value for tag {RESELLER NAME}, {HOST}, {DOMAIN}, {ROOT DIR}, {WEB DIR}
// depending on the current Panel viewed
switch($cp) {
	case "reseller":
	case "domain":
	case "personal":
		$resellername = " ".$resellerdata['name'];
		break;
	default:
		$resellername = " ";
		break;
}
	
//
// Set simple skin {TAGS} associations
unset($parse);
$parse['WEBCP VERSION'] 	= $cfg['webcp'];
$parse['WEBCP NAME'] 		= "web://cp";
$parse['WEB HOSTING CP'] 	= $T['Web Hosting Control Panel'];
$parse['LICENSE'] 		= $T['web.cp license'];

$parse['NOW'] 			= date($T['date_time_format']);
$parse['LANG']			= $lang;
$parse['WHERE AM I'] 		= "&lt;".$whereami."&gt; ".$T[$cp][$url]."";
$parse['IMG PATH'] 		= "skin/".$skin."/";
$parse['SKIN ID']		= $skin;
$parse['HEADER'] 		= "\n<link rel='stylesheet' type='text/css' href='skin/".$skin."/style.css'>\n<script language='JavaScript' src='script.js'></script>\n";

$parse['SYSNAME'] 		= $cfg['sysname'];

$parse['PORT'] 			= ":".$cfg['port'];
$parse['BOOKMARK NAME'] 	= $T['Bookmark'];
$parse['LOG OUT NAME'] 		= $T['Log Out'];
$parse['EXTERNAL NAME'] 	= $T['External Tools'];
$parse['MENU NAME'] 		= $T['menu'][$cp];
$parse['P1 NAME'] 		= $T['panel'][1];
$parse['P2 NAME'] 		= $T['panel'][2];
$parse['P3 NAME'] 		= $T['panel'][3];
$parse['P4 NAME'] 		= $T['panel'][4];
$parse['MENU ID'] 		= $cp;
$parse['RESELLER NAME'] 	= $resellername;
$parse['PAGE LOAD'] 	= $T['Page Load'];
$parse['SEC'] 	= $T['sec'];
$parse['RESELLER NAME'] 	= $resellername;


//
// Load skin or framed skin
if (!trim($framed)) {
	if (file_exists("skin/".$skin."/skin.phps")) {
		$newskin = file("skin/".$skin."/skin.phps");
	}
	else
		$newskin = file("skin/default/skin.phps");
}
else {
	$framed = str_replace("/","",$framed);
	if (file_exists("skin/".$skin."/".$framed.".phps")) {
		$newskin = file("skin/".$skin."/".$framed.".phps");
		// Check for the needed $framename var
		if (!isset($framename))
			return 'Target Frame Name is not set';
	}
	elseif (file_exists("skin/".$skin."/skin.phps"))
		return $T['err']['parser']['framed'];
	else
		return 'Invalid Skin ($skin or $framed)';
}

//
// Handle simple skin {TAGS}
$i = 0;
do {
	if (ereg("\{([ A-Z0-9]+)\}",$newskin[$i])) {
		reset($parse);
		do {
			$newskin[$i] = str_replace("{".key($parse)."}",current($parse),$newskin[$i]);
		}
		while (next($parse) AND ereg("\{([ A-Z0-9]+)\}",$newskin[$i]));
	}
} while (isset($newskin[++$i]));


//
// Handle multi parts skin: {TAGS} * {/TAGS}, {TAGS} * {/TAGS/} * {/TAGS}
// skintag programming help:   1   5    6        1   3    4     5    6
$i = 0;
$regex = '\{([ A-Z0-9]+)\}((.*)\{/([ A-Z0-9]+)/\})?(.*)\{/([ A-Z0-9]+)\}';
do {
	if (ereg($regex,$newskin[$i],$skintag)) {

		// For speed sake, requires 2 different multi parts {TAGS} to be on seperated lines
		if ($skintag[1] != $skintag[6]) 
			return "{".$skintag[1]."} and {".$skintag[6]."} must be on different lines";
		
		// Switch on the tag & handle them.
		switch($skintag[1]) {
		//
		// Double Tag: {TAGS} * {/TAGS}
		
		// Set default page bookmark link
		case "BOOKMARK":
			if (!isset($framed))
				$newskin[$i] = ereg_replace($regex,"<a href='./?url=".$url."&cp=".$cp."&number=".$number."&user=".$user."&bookmark=true' class=bookmark>\\5</a>",$newskin[$i]);
			else
				$newskin[$i] = ereg_replace($regex,"<a href='./?framed=$framename&framename=$framename&skin=$skin&url=$url&cp=$cp&number=$number&user=$user&bookmark=true' target='".$framename."' class=bookmark>\\5</a>",$newskin[$i]);
			break;

		// Set log out link
		case "LOG OUT":
			$newskin[$i] = ereg_replace($regex,"<a href='./?failed=logout' target='_top' class=exit>\\5</a>",$newskin[$i]);
			break;

		// Display Panel Menu
		case "MENU ITEMS":
			$tmp = "";
			reset($T[$cp]);
			
			if (!trim($framed)) {
				do {
					$tmp .= "<a href='./?url=".key($T[$cp])."&cp=".$cp."&number=".$number."&user=".$user."' class=menu>".current($T[$cp])."</a>";
					$tmp .= $skintag[5];
				} while (next($T[$cp]));
			}
			else {
				do {
					$tmp .= "<a href='./?framed=$framename&framename=$framename&url=".key($T[$cp])."&cp=$cp&number=$number&user=$user' target='".$framename."' class=menu>".current($T[$cp])."</a>";
					$tmp .= $skintag[5];
				} while (next($T[$cp]));
			}
			
			$tmp = ereg_replace($skintag[5]."$","",$tmp);
			$newskin[$i] = ereg_replace($regex,$tmp,$newskin[$i]);
			break;
		
		// Display External Menu
		case "EXTERNAL MENU":
			$tmp = "";
			$j = 0;
			reset($T['external']);
			
			if (isset($framed) && !trim($framed)) {
				do {
					$tmp .= "<a href='".$T['external'][$j]['url']."' class=ext target='_blank'>".$T['external'][$j]['name']."</a>";
					$tmp .= $skintag[5];
				} while ($T['external'][++$j]);
			}
			else {
				do {
					$tmp .= "<a href='".$T['external'][$j]['url']."' target='".$framename."' class=ext>".$T['external'][$j]['name']."</a>";
					$tmp .= $skintag[5];
				} while ($T['external'][++$j]);
			}

			$tmp = ereg_replace($skintag[5]."$","",$tmp);
			$newskin[$i] = ereg_replace($regex,$tmp,$newskin[$i]);
			break;
		
		
		//
		// Triple tag: {TAGS} * {/TAGS/} * {/TAGS}
		
		// Show only appropriate Panel links, according to user level
		case "P0":
			if ($cfg['root_server'] != 'none' AND trim($cfg['root_server'])) {
					$newskin[$i] = ereg_replace($regex,"",$newskin[$i]);
			}
			else
				$newskin[$i] = ereg_replace($regex,"",$newskin[$i]);
			break;
		case "P1":
			if ($userdata['level'] < 2)
				$newskin[$i] = ereg_replace($regex,"<a href='./?cp=server&number=$number' class=panel target=_top>\\3</a>\\5",$newskin[$i]);
			else
				$newskin[$i] = ereg_replace($regex,"",$newskin[$i]);
			break;
		case "P2":
			if ($userdata['level'] < 3)
				$newskin[$i] = ereg_replace($regex,"<a href='./?cp=reseller&number=$number' class=panel target=_top>\\3</a>\\5",$newskin[$i]);
			else
				$newskin[$i] = ereg_replace($regex,"",$newskin[$i]);
			break;
		case "P3":
			if ($userdata['level'] < 4)
				$newskin[$i] = ereg_replace($regex,"<a href='./?cp=domain&number=$number' class=panel target=_top>\\3</a>\\5",$newskin[$i]);
			else
				$newskin[$i] = ereg_replace($regex,"",$newskin[$i]);
			break;
		case "P4":
			if ($userdata['level'] < 5)
				$newskin[$i] = ereg_replace($regex,"<a href='./?cp=personal&number=$number' class=panel target=_top>\\3</a>\\5",$newskin[$i]);
			else
				$newskin[$i] = ereg_replace($regex,"",$newskin[$i]);
			break;

		// Display correct FRAMED link to call the framed skin page
		case "FRAMED":
			$newskin[$i] = ereg_replace($regex,"./?framed=\\3&framename=\\5&skin=$skin&cp=$cp&url=$url&number=$number&user=$user",$newskin[$i]);
			break;
		
		//
		// Mixed Tag {TAGS} * {TAG2} * {TAG3} * {/TAGS} 
		case "ICON":
			$tmp = "";
			reset($T[$cp]);

			do {
				$tmpurl = key($T[$cp]);
				
				// Find icon file
				if (file_exists("skin/".$skin."/img/icons/".$tmpurl.".gif"))
					$tmpicon = "/skin/".$skin."/img/icons/".$tmpurl.".gif";
				elseif (file_exists("skin/".$skin."/img/icons/".$tmpurl.".png"))
					$tmpicon = "/skin/".$skin."/img/icons/".$tmpurl.".png";
				elseif (file_exists("skin/".$skin."/img/icons/".$tmpurl.".jpg"))
					$tmpicon = "/skin/".$skin."/img/icons/".$tmpurl.".jpg";
				
				elseif (file_exists("icon/".$tmpurl.".png"))
					$tmpicon = "icon/".$tmpurl.".png";
				elseif (file_exists("icon/".$tmpurl.".gif"))
					$tmpicon = "icon/".$tmpurl.".gif";
				elseif (file_exists("icon/".$tmpurl.".jpg"))
					$tmpicon = "icon/".$tmpurl.".jpg";
				else
					$tmpicon = "";
				
				// replace IMAGE and TEXT if they are there.
				$temp = str_replace("{IMAGE}","<a href='./?url=$tmpurl&cp=$cp&number=$number&user=$user' class=menu><img src='$tmpicon' border='0'></a>\n",$skintag[5]);
				$temp = str_replace("{TEXT}","<a href='./?url=$tmpurl&cp=$cp&number=$number&user=$user' class=menu>".current($T[$cp])."</a>",$temp);
				$tmp .= $temp."\n"; 
			
			} while (next($T[$cp]));
			$newskin[$i] = ereg_replace($regex,trim($tmp),$newskin[$i]);
			break;
		
		// Display All Panel Menu (Edited by Dennis Bollyn a.k.a. Gyrbo)
		case "ALL MENU ITEMS":
			$tmp = "";
			reset($T[$cp]);

			$tmpcps[5] = 'personal';
			$tmpcps[4] = 'domain';
			$tmpcps[3] = 'reseller';
			$tmpcps[2] = 'server';

			$tmp = '';
			$all_regex = '\{ALL MENU ITEMS ITEM\}(.*?)\{\/ALL MENU ITEMS ITEM\}';
			preg_match('/'.$all_regex.'/', $skintag[5], $armatch);
			$all_sep = $armatch[1];

			//Check if we need to do the icon
			if(strpos($all_sep, '{ALL MENU ITEMS IMAGE}')===false)
				$all_icon = false;
			else
				$all_icon = true;

			for($lp=5;$userdata['level']<$lp;$lp--) {
			        $tmp2 = $tmp1 = '';
			        
				// show panel name
				$tmpcp = $tmpcps[$lp];
				// only set panel if it exists and is allowed (i.e central panel & user level dependant)
				if ($tmpcp) {
					$tmp1 = str_replace('{ALL MENU ITEMS TITLE}', "<b>".$T['menu'][$tmpcp]."</b>\n", $skintag[5]);
					reset($T[$tmpcp]);
					if (!trim($framed)) {
						do {
							$tmp3 = $all_sep;

							if($all_icon) {
								$tmpurl = key($T[$tmpcp]);
					
								// Find icon file
								if (file_exists("skin/".$skin."/img/icons/".$tmpurl.".gif"))
									$tmpicon = "/skin/".$skin."/img/icons/".$tmpurl.".gif";
								elseif (file_exists("skin/".$skin."/img/icons/".$tmpurl.".png"))
									$tmpicon = "/skin/".$skin."/img/icons/".$tmpurl.".png";
								elseif (file_exists("skin/".$skin."/img/icons/".$tmpurl.".jpg"))
									$tmpicon = "/skin/".$skin."/img/icons/".$tmpurl.".jpg";
				
								elseif (file_exists("icon/".$tmpurl.".png"))
									$tmpicon = "icon/".$tmpurl.".png";
								elseif (file_exists("icon/".$tmpurl.".gif"))
									$tmpicon = "icon/".$tmpurl.".gif";
								elseif (file_exists("icon/".$tmpurl.".jpg"))
									$tmpicon = "icon/".$tmpurl.".jpg";
								else
									$tmpicon = "";
				
								// replace IMAGE if they are there.
								$tmp3 = str_replace("{ALL MENU ITEMS IMAGE}","<a href='./?url=$tmpurl&cp=$cp&number=$number&user=$user' class=menu><img src='$tmpicon' border='0'></a>\n",$tmp3);
							}

							$tmp3 = str_replace("{ALL MENU ITEMS TEXT}","<a href='./?url=".key($T[$tmpcp])."&cp=".$tmpcp."&number=".$number."&user=".$user."' class=menu>".current($T[$tmpcp])."</a>\n",$tmp3);
							$tmp2 .= $tmp3;
						} while (next($T[$tmpcp]));
					} else {
						do {
							$tmp3 = $all_sep;

							if($all_icon) {
								$tmpurl = key($T[$tmpcp]);
					
								// Find icon file
								if (file_exists("skin/".$skin."/img/icons/".$tmpurl.".gif"))
									$tmpicon = "/skin/".$skin."/img/icons/".$tmpurl.".gif";
								elseif (file_exists("skin/".$skin."/img/icons/".$tmpurl.".png"))
									$tmpicon = "/skin/".$skin."/img/icons/".$tmpurl.".png";
								elseif (file_exists("skin/".$skin."/img/icons/".$tmpurl.".jpg"))
									$tmpicon = "/skin/".$skin."/img/icons/".$tmpurl.".jpg";
				
								elseif (file_exists("icon/".$tmpurl.".png"))
									$tmpicon = "icon/".$tmpurl.".png";
								elseif (file_exists("icon/".$tmpurl.".gif"))
									$tmpicon = "icon/".$tmpurl.".gif";
								elseif (file_exists("icon/".$tmpurl.".jpg"))
									$tmpicon = "icon/".$tmpurl.".jpg";
								else
									$tmpicon = "";
				
								// replace IMAGE if they are there.
								$tmp3 = str_replace("{ALL MENU ITEMS IMAGE}","<a 
href='./?framed=$framename&framename=$framename&url=".key($T[$tmpcp])."&cp=$tmpcp&number=$number&user=$user' target='".$framename."' class=menu><img 
src='$tmpicon' border='0'></a>\n",$tmp3);
							}

							$tmp3 = str_replace("{ALL MENU ITEMS TEXT}","<a 
href='./?framed=$framename&framename=$framename&url=".key($T[$tmpcp])."&cp=$tmpcp&number=$number&user=$user' target='".$framename."' 
class=menu>".current($T[$tmpcp])."</a>\n",$tmp3);
							$tmp2 .= $tmp3;
						} while (next($T[$tmpcp]));
					}
					$tmp .= ereg_replace($regex, $tmp2, $tmp1);
				}
			}
			
			$newskin[$i] = ereg_replace($regex,$tmp,$newskin[$i]);
			break;

		// Unrecognized {TAG}, leave it there.
		default:
			break;
		}
			
	}
} while (isset($newskin[++$i]));

//
// Ready page for display
$newskin = implode("",$newskin);
?>
Return current item: web-cp - Web Hosting Control Panel