_tplName = $TplName; } function _GetTemplate() { return $this->_tplData; } function SetPageTitle($Title) { $this->_tplPageTitle = $Title; } function _GetPageTitle() { return $this->_tplPageTitle; } function ParseTemplate($return=false,$parsePage=false) { if($parsePage == false){ $this->_tplData = $this->_LoadTemplateFile(); }else{ $this->_tplData = $parsePage; } $this->_tplData = $this->_ParseConstants(); $this->_tplData = $this->_ParsePanels(); $this->_tplData = $this->_ParseIncludes(); $this->_tplData = $this->ParseGL($this->_tplData); if($return == true) return $this->_GetTemplate(); else echo $this->_GetTemplate(); } function _LoadTemplateFile() { $tplData = ""; $matches = array(); if(!isset($this->_tplName)) { // No template name specified trigger_error(sprintf("%s", $GLOBALS["AL_LANG"]["errNoTemplateNameSpecified"]), E_USER_WARNING); } else { // Load the specified template if(eregi("admin",$this->_tplName)){ $ext = ".tpl"; }else{ $ext = ".html"; } $tplFile = AL_TPL_LOAD_PATH . $this->_tplName . $ext; if(!file_exists($tplFile)) { trigger_error(sprintf("%s", sprintf($GLOBALS["AL_LANG"]["errCouldntLoadTemplate"], AL_TPL_LOAD_PATH .$this->_tplName . $ext)), E_USER_WARNING); } else { // Open the template file $fp = fopen($tplFile, "rb"); // Get the content of the template while(!feof($fp)) $tplData .= fgets($fp, 4096); fclose($fp); // Parse out all constants return $tplData; } } } function _ParseIncludes() { // Parse out all of the panels in the template $tplData = $this->_GetTemplate(); if(!isset($this->_tplName)) { // No template name specified trigger_error(sprintf("%s", $GLOBALS["AL_LANG"]["errNoTemplateNameSpecified"]), E_USER_WARNING); } else { // Parse out the panel tokens in the template file preg_match_all("`(?siU)(%%Include.(.*)%%)`", $tplData, $matches); foreach($matches[0] as $key=>$k) { $pattern1 = $k; $pattern2 = str_replace("%", "", $pattern1); $pattern2 = str_replace("Include.", "", $pattern2); ob_start(); //pprint_r($_SERVER); if(eregi("http://",$pattern2)){ // Is a URL $readSite = ""; // Trick the site into thinking it a regular user as some sites stop' // other servers from taking files ini_set('user_agent','Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)'); if($openSite = fopen ($pattern2,"r")){ while(!feof($openSite)){ $readSite .= fread($openSite, 4096); } fclose($openSite); } echo $readSite; //echo readfile($pattern2); }elseif (eregi("/",$pattern2)) { // Has a path to the file include($pattern2); }else{ // Must be in the panels folder include($_SERVER["DOCUMENT_ROOT"] . $GLOBALS["AL_CFG"]["appPath"] ."/" . AL_PANEL_LOAD_PATH . $pattern2); } $includeData = ob_get_contents(); ob_end_clean(); $tplData = str_replace($pattern1, $includeData, $tplData); } } return $tplData; } function _ParseConstants() { /* Parse out all constants in the template, which are: %%Page.WindowTitle%% %%Config.CurrentTemplatePath%%/Styles.css %%Config.HomePath%% %%Config.WebSiteDescription%% %%Config.WebSiteKeywords%% %%Config.StyleWidth%% %%Config.SiteColor%% %%Config.Charset%% */ $tplData = $this->_GetTemplate(); if(!isset($this->_tplName)) { // No template name specified trigger_error(sprintf("%s", $GLOBALS["AL_LANG"]["errNoTemplateNameSpecified"]), E_USER_WARNING); } else { $tplData = str_replace("%%Config.ImagePath%%", AL_TPL_IMAGE_PATH, $tplData); $tplData = str_replace("%%Page.WindowTitle%%", $this->_GetPageTitle(), $tplData); // thanks Flinn $tplData = str_replace("%%Config.CurrentTemplatePath%%", ereg_replace("/$", "", AL_TPL_HTTP_PATH), $tplData); $tplData = str_replace("%%Config.WebSiteDescription%%", htmlentities($GLOBALS["AL_CFG"]["siteDesc"],ENT_QUOTES), $tplData); $tplData = str_replace("%%Config.WebSiteKeywords%%", htmlentities($GLOBALS["AL_CFG"]["siteKeywords"],ENT_QUOTES), $tplData); $tplData = str_replace("%%Config.HomePath%%", $GLOBALS["AL_CFG"]["siteURL"], $tplData); $tplData = str_replace("%%Config.StyleWidth%%", $GLOBALS["AL_CFG"]["StyleWidth"], $tplData); $tplData = str_replace("%%Config.SiteColor%%", $GLOBALS["AL_CFG"]["SiteColor"], $tplData); $tplData = str_replace("%%Config.Charset%%", $GLOBALS["AL_CFG"]["charset"], $tplData); if($GLOBALS["AL_CFG"]["HTMLrtl"] == '1'){ $tplData = str_replace("%%Config.TextDirection%%", "dir='rtl'", $tplData); }{ $tplData = str_replace("%%Config.TextDirection%%", "", $tplData); } } return $tplData; } function _ParsePanels() { // Parse out all of the panels in the template $tplData = $this->_GetTemplate(); if(!isset($this->_tplName)) { // No template name specified trigger_error(sprintf("%s", $GLOBALS["AL_LANG"]["errNoTemplateNameSpecified"]), E_USER_WARNING); } else { // Parse out the panel tokens in the template file preg_match_all("/(?siU)(%%Panel.[a-zA-Z0-9]{1,}%%)/", $tplData, $matches); foreach($matches[0] as $key=>$k) { $pattern1 = $k; $pattern2 = str_replace("%", "", $pattern1); $pattern2 = str_replace("Panel.", "", $pattern2); // Add id tags around each panel $data = $this->_GetPanelContent($pattern2); $data = sprintf("\n\n%s\n\n", $pattern2, $data, $pattern2); $tplData = str_replace($pattern1, $data, $tplData); } } return $tplData; } function _GetPanelContent($PanelId) { // Parse the PHP panel and return its content $panelData = ""; $panelHTMLFile = sprintf("%s%s.html", AL_PANEL_LOAD_PATH, $PanelId); $panelPHPFile = sprintf("%s%s.php", AL_PANEL_LOAD_PATH, $PanelId); // If the panel can be shown, show it if(!isset($GLOBALS["HidePanels"])) $GLOBALS["HidePanels"] = array(); if(!in_array($PanelId, $GLOBALS["HidePanels"])) { if(file_exists($panelHTMLFile) && file_exists($panelPHPFile)) { // Each panel has a generic panel parsing class. We will include // that file and parse the template include($panelPHPFile); eval("\$objPanel = new $panelClass(\$panelHTMLFile);"); $panelData = $objPanel->ParsePanel(); } else { $panelData = "
[Panel not found: '" . $PanelId . "']
"; } return $panelData; } else { return ""; } } function ParseGL($TemplateData) { // Parse out global and language variables from template data and // return it. This is used from the generic panel class for each panel $tplData = $TemplateData; $matches = array(); // Parse out the language pack variables in the template file preg_match_all("/(?siU)(%%LNG_[a-zA-Z0-9]{1,}%%)/", $tplData, $matches); foreach($matches[0] as $key=>$k) { $pattern1 = $k; $pattern2 = str_replace("%", "", $pattern1); $pattern2 = str_replace("LNG_", "", $pattern2); $tplData = str_replace($pattern1, @$GLOBALS["AL_LANG"][$pattern2], $tplData); } // Parse out the global variables in the template file preg_match_all("/(?siU)(%%GLOBAL_[a-zA-Z0-9_]{1,}%%)/", $tplData, $matches); foreach($matches[0] as $key=>$k) { $pattern1 = $k; $pattern2 = str_replace("%", "", $pattern1); $pattern2 = str_replace("GLOBAL_", "", $pattern2); $tplData = str_replace($pattern1, @$GLOBALS[$pattern2], $tplData); } return $tplData; } function GetAndParseFile($File) { // Open a file, parse out tokens and return it $file2 = dirname(__FILE__)."/../../"; $file2 .= $File; $file = realpath($file2); if($fp = fopen($file, "rb")) { while(!feof($fp)) $fdata .= fgets($fp, 4096); fclose($fp); } else { $file = sprintf("../%s/%s", $GLOBALS["AL_CFG"]["appPath"], $File); if($fp = fopen($file, "rb")) { while(!feof($fp)) $fdata .= fgets($fp, 4096); fclose($fp); } } $fdata = $this->ParseGL($fdata); return $fdata; } } ?>