SetBasePath($base_path)) { if (isset($filename)) { $this->Filename = $filename; $this->LoadTemplate($silent); } } } function SetBasePath($base_path=null) { if (isset($base_path)) { $base_path = eregi_replace("/$", '', $base_path); //Cutting possible last slash $this->BasePath = $base_path; return true; } return false; } function GetFullPath() { return $this->BasePath.'/'.ltrim($this->Filename, '/').'.tpl'; } /** * Enter description here... * * @param int $silent template not found {0 - fatal error, 1 - warning, 2 - nothing} * @return bool */ function LoadTemplate($silent = 0) { $filename = $this->GetFullPath(); if(file_exists($filename)) { if (filesize ($filename) == 0) { trigger_error("Template file size is 0: $filename", ($silent ? E_USER_NOTICE : E_USER_ERROR) ); } $this->SetBody(file_get_contents($filename)); /*$handle = fopen ($filename, "r"); $contents = fread ($handle, filesize ($filename)); $this->SetBody($contents); fclose ($handle);*/ return true; } else { if ($silent != 2) { trigger_error("File or block not found: $filename", ($silent ? E_USER_NOTICE : E_USER_ERROR) ); } return false; } } function SetBody($body) { $this->Body = $body; } function GetBody() { return $this->Body; } } class TemplatesCache extends kBase { var $Templates = Array(); var $BasePath; var $FileNames = Array(); function TemplatesCache() { parent::kBase(); $this->BasePath = FULL_PATH.THEMES_PATH; $conn =& $this->Application->GetADODBConnection(); } function LoadTemplate($filename, $title=NULL, $silent=0) { if (preg_match('#^[\/]{0,1}([^\/]*)\/(.*)#', $filename, $regs)) { $module_filename = $regs[2]; $first_dir = $regs[1]; } else { $first_dir = ''; $module_filename = $filename; } if ( $this->Application->IsAdmin() && $this->Application->findModule('Name', $first_dir)) { $path = MODULES_PATH.'/'.strtolower($first_dir).'/admin_templates'; } else { $path = $this->BasePath; $module_filename = $first_dir.'/'.$module_filename; } $template =& new Template($path, $module_filename, $silent); if (!isset($title)) $title = $filename; $this->SetTemplate($title, $template); } function GetRealFilename($filename, $base=null) { if (preg_match('#^[\/]{0,1}([^\/]*)\/(.*)#', $filename, $regs)) { $module_filename = $regs[2]; $first_dir = $regs[1]; } else { $first_dir = ''; $module_filename = $filename; } if ( $this->Application->IsAdmin() && $this->Application->findModule('Name', $first_dir)) { $path = MODULES_PATH.'/'.strtolower($first_dir).'/admin_templates'; } else { $path = isset($base) ? $base : $this->BasePath; $module_filename = $first_dir.'/'.$module_filename; } return $path.'/'.$module_filename; } function SetTemplate($title, &$template, $filename=null) { if (!isset($filename)) $filename=$title; $this->Templates[$title] = $template; $this->FileNames[$title] = $filename; } function &GetTemplate($title, $silent=0) { if (!isset($this->Templates[$title])) { $this->LoadTemplate($title, null, $silent); } return $this->Templates[$title]; } function GetTemplateBody($title, $silent=0) { $template =& $this->GetTemplate($title, $silent); if ( !is_object($template) ) { return ''; } return $template->GetBody(); } function GetTemplateFileName($title) { return getArrayValue($this->FileNames, $title); } function SetTemplateBody($title, $body) { $template =& new Template(); $template->SetBody($body); $this->SetTemplate($title, $template); } function ParseTemplate($template_name) { $Parser =& new TemplateParser($this->Application); return $Parser->Parse( $this->GetTemplateBody($template_name) ); } function TemplateExists($filename) { if (!preg_match("/\.tpl$/", $filename)) $filename .= '.tpl'; $real_file = $this->GetRealFilename($filename); return file_exists($real_file); } } ?>