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 00049 protected $extensiondir = '/templates/'; 00050 00051 protected function __construct () { 00052 $info = criticalInfo::getInstance(); 00053 foreach (aliroExtensionHandler::getInstance()->getTemplateExtensions() as $extension) { 00054 if (2 & $extension->admin) { 00055 $this->adminTemplateClasses[$extension->formalname] = $extension->adminclass; 00056 if ($extension->default_template) $this->defaultAdminTemplate = $extension; 00057 } 00058 else { 00059 $this->userTemplateClasses[$extension->formalname] = $extension->class; 00060 if ($extension->default_template) $this->defaultTemplate = $extension; 00061 } 00062 } 00063 } 00064 00065 public static function getInstance () { 00066 return is_object(self::$instance) ? self::$instance : (self::$instance = parent::getCachedSingleton(self::$instance)); 00067 } 00068 00069 public function getDefaultTemplateName () { 00070 return $this->getDefaultTemplateProperty('formalname'); 00071 } 00072 00073 public function getDefaultTemplateClass () { 00074 $info = criticalInfo::getInstance(); 00075 if ($info->isAdmin) return $this->getDefaultAdminTemplateClass(); 00076 else return $this->getDefaultUserTemplateClass(); 00077 } 00078 00079 public function getDefaultUserTemplateClass () { 00080 if (isset($this->defaultTemplate) AND isset($this->defaultTemplate->class)) return $this->defaultTemplate->class; 00081 else return 'defaultTemplate'; 00082 } 00083 00084 public function getDefaultUserCSS () { 00085 if (isset($this->defaultTemplate)) { 00086 criticalInfo::getInstance()->absolute_path.'/templates/'.$this->defaultTemplate->formalname.'/css/template_css.css'; 00087 } 00088 else return criticalInfo::getInstance()->absolute_path.'/templates/default.css'; 00089 } 00090 00091 public function getDefaultAdminTemplateClass () { 00092 if (isset($this->defaultAdminTemplate) AND isset($this->defaultAdminTemplate->adminclass)) return $this->defaultAdminTemplate->adminclass; 00093 else return 'defaultAdminTemplate'; 00094 } 00095 public function removeTemplate ($formalname, $admin) { 00096 $info = criticalInfo::getInstance(); 00097 if (2 == $admin) $dirpath = $info->admin_absolute_path.'/templates/'.$formalname; 00098 else $dirpath = $info->absolute_path.'/templates/'.$formalname; 00099 $dir = new aliroDirectory ($dirpath); 00100 $dir->deleteAll(); 00101 $this->clearCache(); 00102 } 00103 00104 public function getDefaultTemplateProperty ($property, $isAdmin=null) { 00105 if (is_null($isAdmin)) $isAdmin = $info = criticalInfo::getInstance()->isAdmin; 00106 $template = $isAdmin ? 'defaultAdminTemplate' : 'defaultTemplate'; 00107 return (isset($this->$template) AND isset($this->$template->$property)) ? $this->$template->$property : ''; 00108 } 00109 00110 public function getAllUserPositions () { 00111 return $this->getTemplatePositions($this->userTemplateClasses, 'defaultTemplate'); 00112 } 00113 00114 public function getAllAdminPositions () { 00115 return $this->getTemplatePositions($this->adminTemplateClasses, 'defaultAdminTemplate'); 00116 } 00117 00118 private function getTemplatePositions ($tclasses, $tdefault) { 00119 $xhandler = aliroExtensionHandler::getInstance(); 00120 $raw = $result = array(); 00121 $tobject = new $tdefault(); 00122 foreach (array_keys($tobject->positions()) as $position) $raw[$position][] = 'default'; 00123 foreach ($tclasses as $formalname=>$tclass) { 00124 $tobject = new $tclass; 00125 foreach (array_keys($tobject->positions()) as $position) $raw[$position][] = $formalname; 00126 } 00127 foreach ($raw as $position=>$names) $result[$position] = implode(', ', $names); 00128 return $result; 00129 } 00130 00131 }
1.5.5