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 * aliroComponentHandler is a singleton class that keeps details of all the 00038 * components in the system. It extends cachedObject, which allows it to have 00039 * all its data cached easily. The constructor is therefore only invoked 00040 * relatively infrequently and the code is optimised to do work in the constructor 00041 * so as to save time in the regular methods. A number of the methods (to do with 00042 * paths, directories, etc) are standard methods used by the installer for the 00043 * different kinds of things that can be (un)installed. Other methods provide 00044 * for retrieving components by ID, by name or as a complete collection. Buffer 00045 * handling assists the management of components at run time. 00046 * 00047 * aliroComponent is the class that corresponds to the component table entries 00048 * and thus supports the creation of objects that describe actual components. 00049 * 00050 */ 00051 00052 class aliroComponentHandler extends aliroCommonExtHandler { 00053 protected static $instance = __CLASS__; 00054 00055 private $components = array(); 00056 private $links = array(); 00057 private $_buffer = ''; 00058 00059 protected $extensiondir = '/components/'; 00060 00061 protected function __construct () { 00062 // Making private enforces singleton 00063 $database = aliroCoreDatabase::getInstance(); 00064 $results = $database->doSQLget("SELECT c.*, e.xmlfile FROM #__components AS c INNER JOIN #__extensions AS e ON c.option = e.formalname", 'aliroComponent'); 00065 foreach ($results as $result) { 00066 $this->components[$result->option] = $result; 00067 $this->links[$result->id] = $result->option; 00068 } 00069 } 00070 00071 public static function getInstance () { 00072 return is_object(self::$instance) ? self::$instance : (self::$instance = parent::getCachedSingleton(self::$instance)); 00073 } 00074 00075 // Mainly for the installer - overrides default method 00076 public function getXMLRelativePath ($formalname, $admin) { 00077 return $this->getRelativePath ($formalname, 2); 00078 } 00079 00080 public function componentCount () { 00081 return count($this->components); 00082 } 00083 00084 public function getComponentByFormalName ($formalname) { 00085 return isset($this->components[$formalname]) ? $this->components[$formalname] : null; 00086 } 00087 00088 public function getComponentByID ($id) { 00089 return (isset($this->links[$id]) AND isset($this->components[$this->links[$id]])) ? $this->components[$this->links[$id]] : null; 00090 } 00091 00092 public function getAllComponents () { 00093 return $this->components; 00094 } 00095 00096 public function mosMainBody() { 00097 return $this->_buffer; 00098 } 00099 00100 public function startBuffer () { 00101 $this->_buffer = ''; 00102 ob_start(); 00103 } 00104 00105 public function endBuffer () { 00106 $this->_buffer = ob_get_contents(); 00107 ob_end_clean(); 00108 } 00109 00110 } 00111 00112 class aliroComponent extends aliroCommonExtBase { 00113 protected $DBclass = 'aliroCoreDatabase'; 00114 protected $tableName = '#__components'; 00115 protected $rowKey = 'id'; 00116 protected $handler = 'aliroComponentHandler'; 00117 protected $formalfield = 'extformalname'; 00118 00119 }
1.5.5