00001 <?php 00002 00003 /******************************************************************************* 00004 * Aliro - the modern, accessible content management system 00005 * 00006 * Aliro is open source software, free to use, and licensed under GPL. 00007 * You can find the full licence at http://www.gnu.org/copyleft/gpl.html GNU/GPL 00008 * 00009 * The author freely draws attention to the fact that Aliro derives from Mambo, 00010 * software that is controlled by the Mambo Foundation. However, this section 00011 * of code is totally new. If it should contain any fragments that are similar 00012 * to Mambo, please bear in mind (1) there are only so many ways to do things 00013 * and (2) the author of Aliro is also the author and copyright owner for large 00014 * parts of Mambo 4.6. 00015 * 00016 * Tribute should be paid to all the developers who took Mambo to the stage 00017 * it had reached at the time Aliro was created. It is a feature rich system 00018 * that contains a good deal of innovation. 00019 * 00020 * Your attention is also drawn to the fact that Aliro relies on other items of 00021 * open source software, which is very much in the spirit of open source. Aliro 00022 * wishes to give credit to those items of code. Please refer to 00023 * http://aliro.org/credits for details. The credits are not included within 00024 * the Aliro package simply to avoid providing a marker that allows hackers to 00025 * identify the system. 00026 * 00027 * Copyright in this code is strictly reserved by its author, Martin Brampton. 00028 * If it seems appropriate, the copyright will be vested in the Aliro Organisation 00029 * at a suitable time. 00030 * 00031 * Copyright (c) 2007 Martin Brampton 00032 * 00033 * http://aliro.org 00034 * 00035 * counterpoint@aliro.org 00036 * 00037 * aliroTemplateHandler keeps track of all the templates known to the system and 00038 * provides useful methods for other parts of Aliro and for extensions 00039 * 00040 */ 00041 00042 class aliroTemplateHandler extends aliroCommonExtHandler { 00043 protected static $instance = __CLASS__; 00044 private $defaultTemplate = null; 00045 private $defaultAdminTemplate = null; 00046 private $adminTemplateClasses = array(); 00047 private $userTemplateClasses = array(); 00048 private $innerUserTemplateClasses = array(); 00049 private $innerAdminTemplateClasses = array(); 00050 private $allTemplateClasses = array(); 00051 00052 protected $extensiondir = '/templates/'; 00053 00054 protected function __construct () { 00055 $info = criticalInfo::getInstance(); 00056 foreach (aliroExtensionHandler::getInstance()->getTemplateExtensions() as $extension) { 00057 if ($extension->inner) { 00058 if (2 & $extension->admin) $this->innerAdminTemplateClasses[$extension->formalname] = $extension->adminclass; 00059 else $this->innerUserTemplateClasses[$extension->formalname] = $extension->class; 00060 } 00061 elseif (2 & $extension->admin) { 00062 $this->adminTemplateClasses[$extension->formalname] = $extension->adminclass; 00063 if ($extension->default_template) $this->defaultAdminTemplate = $extension; 00064 } 00065 else { 00066 $this->userTemplateClasses[$extension->formalname] = $extension->class; 00067 if ($extension->default_template) $this->defaultTemplate = $extension; 00068 } 00069 $this->allTemplateClasses[$extension->formalname] = (2 & $extension->admin) ? $extension->adminclass : $extension->class; 00070 } 00071 } 00072 00073 public static function getInstance () { 00074 return is_object(self::$instance) ? self::$instance : (self::$instance = parent::getCachedSingleton(self::$instance)); 00075 } 00076 00077 public function getDefaultTemplateName () { 00078 return $this->getDefaultTemplateProperty('formalname'); 00079 } 00080 00081 public function getDefaultTemplateClass () { 00082 $info = criticalInfo::getInstance(); 00083 if ($info->isAdmin) return $this->getDefaultAdminTemplateClass(); 00084 else return $this->getDefaultUserTemplateClass(); 00085 } 00086 00087 public function getDefaultUserTemplateClass () { 00088 if (isset($this->defaultTemplate) AND isset($this->defaultTemplate->class)) return $this->defaultTemplate->class; 00089 else return 'defaultTemplate'; 00090 } 00091 00092 public function getDefaultUserCSS () { 00093 if (isset($this->defaultTemplate)) { 00094 criticalInfo::getInstance()->absolute_path.'/templates/'.$this->defaultTemplate->formalname.'/css/template_css.css'; 00095 } 00096 else return criticalInfo::getInstance()->absolute_path.'/templates/default.css'; 00097 } 00098 00099 public function getDefaultAdminTemplateClass () { 00100 if (isset($this->defaultAdminTemplate) AND isset($this->defaultAdminTemplate->adminclass)) return $this->defaultAdminTemplate->adminclass; 00101 else return 'defaultAdminTemplate'; 00102 } 00103 00104 public function getInnerTemplates ($isadmin=false) { 00105 return $isadmin ? array_keys($this->innerAdminTemplateClasses) : array_keys($this->innerUserTemplateClasses); 00106 } 00107 00108 public function getTemplateObjectByFormalName ($name) { 00109 $tclass = isset($this->allTemplateClasses[$name]) ? $this->allTemplateClasses[$name] : ''; 00110 return $tclass ? new $tclass() : null; 00111 } 00112 00113 public function removeTemplate ($formalname, $admin) { 00114 $info = criticalInfo::getInstance(); 00115 if (2 == $admin) $dirpath = $info->admin_absolute_path.'/templates/'.$formalname; 00116 else $dirpath = $info->absolute_path.'/templates/'.$formalname; 00117 $dir = new aliroDirectory ($dirpath); 00118 $dir->deleteAll(); 00119 $this->clearCache(); 00120 } 00121 00122 public function getDefaultTemplateProperty ($property, $isAdmin=null) { 00123 if (is_null($isAdmin)) $isAdmin = $info = criticalInfo::getInstance()->isAdmin; 00124 $template = $isAdmin ? 'defaultAdminTemplate' : 'defaultTemplate'; 00125 return (isset($this->$template) AND isset($this->$template->$property)) ? $this->$template->$property : ''; 00126 } 00127 00128 public function getAllUserPositions () { 00129 return $this->getTemplatePositions(array_merge($this->userTemplateClasses,$this->innerUserTemplateClasses), 'defaultTemplate'); 00130 } 00131 00132 public function getAllAdminPositions () { 00133 return $this->getTemplatePositions(array_merge($this->adminTemplateClasses,$this->innerAdminTemplateClasses), 'defaultAdminTemplate'); 00134 } 00135 00136 private function getTemplatePositions ($tclasses, $tdefault) { 00137 $xhandler = aliroExtensionHandler::getInstance(); 00138 $raw = $result = array(); 00139 $tobject = new $tdefault(); 00140 foreach (array_keys($tobject->positions()) as $position) $raw[$position][] = 'default'; 00141 foreach ($tclasses as $formalname=>$tclass) { 00142 $tobject = new $tclass; 00143 foreach (array_keys($tobject->positions()) as $position) $raw[$position][] = $formalname; 00144 } 00145 foreach ($raw as $position=>$names) $result[$position] = implode(', ', $names); 00146 return $result; 00147 } 00148 00149 }
1.5.5