aliroParameters.php

Go to the documentation of this file.
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  * aliroParameters is the class that implements objects that are held internally as
00038  * associative arrays, but externally as serialized, encoded strings.  The definition
00039  * of what a particular set of parameters consists of is normally provided as XML.
00040  *
00041  * aliroAdminParameters is used largely, but not exclusively, on the admin side to
00042  * create parameter groups from XML and serialized data.
00043  *
00044  */
00045 class aliroParameters {
00046     protected $params = array();
00047     protected $raw = null;
00048     protected $xml = null;
00049 
00050     public function __construct ($text='', $xml='') {
00051         $this->raw = is_null($text) ? '' : $text;
00052         if (!is_string($this->raw)) trigger_error (T_('Raw data for aliroParameters not a string'));
00053 
00054         $this->params = @unserialize($this->raw);
00055         if (!is_array($this->params)) $this->params = array();
00056         if ($this->raw AND count($this->params) == 0) trigger_error (T_('Raw data for aliroParameters was not null, but did not yield any values'));
00057 
00058         foreach ($this->params as &$param) $param = base64_decode($param);
00059         $this->xml = $xml;
00060     }
00061 
00062     public function getParams () {
00063         die ('Aliro handles parameters differently, please review what you need');
00064     }
00065 
00066     public function set( $key, $value='' ) {
00067         $this->params[$key] = $value;
00068         return $value;
00069     }
00070 
00071     public function setAll ($keyedValues) {
00072         $this->params = $keyedValues;
00073     }
00074 
00075     public function def( $key, $value='' ) {
00076         return $this->set ($key, $this->get($key, $value));
00077     }
00078 
00079     public function get( $key, $default='' ) {
00080         if (isset($this->params[$key])) return $this->params[$key] === '' ? $default : $this->params[$key];
00081         else return $default;
00082     }
00083 
00084     public function __get ($property) {
00085         return $this->get ($property);
00086     }
00087 
00088     public function processInput ($params) {
00089         $inarray = (array) $params;
00090         foreach ($inarray as &$param) if (ini_get('magic_quotes-gpc')) $param = stripslashes($param);
00091         $this->params = $inarray;
00092         return $this->asString();
00093     }
00094     
00095     public function asString () {
00096         $encoded = array();
00097         foreach ($this->params as $key=>$param) $encoded[$key] = base64_encode($param);
00098         return serialize($encoded);
00099     }
00100     
00101     public function asPost () {
00102         return $this->params;
00103     }
00104 
00105     public function render ($name='params') {
00106         if ($this->xml) {
00107             $params = new aliroXMLParams;
00108             if (is_file($this->xml)) return $params->paramsFromFile($this->xml, $this, $name);
00109             else return $params->paramsFromString($this->xml, T_('Data passed to aliroParameters'), $this, $name);
00110         }
00111         return "<textarea name='$name' cols='40' rows='10' class='text_area'>$this->raw</textarea>";
00112     }
00113 
00114 }
00115 
00116 class mosParameters extends aliroParameters {
00117     // Really just an alias for backwards compatibility
00118 }
00119 
00120 class mosAdminParameters extends aliroParameters {
00121 
00122     // Just an alias for aliroParameters
00123 
00124 }
00125 
00126 // Appears not to be used - certainly not used in Aliro
00127 
00128 class mosSpecialAdminParameters extends aliroParameters {
00129 
00130     function __construct ($name, $version='') {
00131         $database = aliroDatabase::getInstance();
00132         $sql = "SELECT * FROM #__parameters WHERE param_name='$name'";
00133         if ($version) $sql .= " AND param_version='$version'";
00134         $database->setQuery($sql);
00135         $parameters = $database->loadObjectList();
00136         if ($parameters) $parameters = $parameters[0];
00137         parent::__construct($parameters->params, aliroCore::get('mosConfig_absolute_path').'/parameters/'.$parameters->param_file);
00138     }
00139 }

Generated on Thu Apr 17 13:03:27 2008 for ALIRO by  doxygen 1.5.5