aliroXMLParams.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 
00046 class aliroXMLParams {
00047     protected $xmlobject = null;
00048     protected $paramcount = 0;
00049     public $html = array();
00050     protected $translations = array();
00051 
00052     public function __construct () {
00053         $this->xmlobject = new aliroXML;
00054     }
00055     
00056     private function helpXgettext () {
00057         T_('There are no Parameters for this item');
00058     }
00059 
00060     public function paramsFromFile ($xmlfile, $pobject, $controlname) {
00061         try {
00062             $this->xmlobject->loadFile($xmlfile);
00063             return $this->analyseXML($pobject, $controlname);
00064         } catch (aliroXMLException $exception) {
00065                 aliroRequest::getInstance()->setErrorMessage ($exception->getMessage(), _ALIRO_ERROR_FATAL);
00066                 $this->xmlobject = null;
00067         }
00068     }
00069 
00070     public function paramsFromString ($xmlstring, $xmlfile, $pobject, $controlname) {
00071         try {
00072             $this->xmlobject->loadString($xmlstring);
00073             return $this->analyseXML($pobject, $controlname);
00074         } catch (aliroXMLException $exception) {
00075                 aliroRequest::getInstance()->setErrorMessage ($exception->getMessage(), _ALIRO_ERROR_FATAL);
00076                 $this->xmlobject = null;
00077         }
00078     }
00079 
00080     private function analyseXML ($pobject, $controlname) {
00081         $this->html[] = '<table class="paramlist">';
00082         $params = $this->xmlobject->getXML('params->param');
00083         if ($params) foreach ($params as $aparam) {
00084             $this->processParam($aparam, $pobject, $controlname);
00085         }
00086         if ($this->paramcount == 0) {
00087             return <<<NULL_HTML
00088 
00089                 <table class="paramlist">
00090                     <tr>
00091                         <td colspan="2">
00092                             <i>{$this->T_('There are no Parameters for this item')}</i>
00093                         </td>
00094                     </tr>
00095                 </table>
00096 
00097 NULL_HTML;
00098 
00099         }
00100         $this->html[] = '</table>';
00101         $this->paramcount = 0;
00102         return implode("\n", $this->html);
00103     }
00104 
00105     protected function T_ ($string) {
00106         return T_($string);
00107     }
00108 
00109     private function processParam ($param, $pobject, $controlname) {
00110         $alirohtml = aliroHTML::getInstance();
00111 
00112         $type = (string) $param['type'];
00113         $name = (string) $param['name'];
00114         // if ($name) $this->html[] = "<tr><td colspan='3'>$name</td></tr>";
00115         $label = (string) $param['label'];
00116         $default = (string) $param['default'];
00117         if ($description = (string) $param['description']) $tooltip = $alirohtml->toolTip($description, $name);
00118         else $tooltip = '';
00119 
00120         if (is_object($pobject)) $value = $pobject->get($name, $default);
00121         else $value = $default;
00122 
00123         $this->html[] = '<tr>';
00124         if ($label == '@spacer') $label = '<hr />';
00125         elseif ($label) $label .= ':';
00126         $this->html[] = '<td width="35%" align="right" valign="top">'.$label.'</td>';
00127         switch ($type) {
00128             case 'text':
00129                 $size = (string) $param['size'];
00130                 $controlstring = '<input type="text" name="'.$controlname.'['.$name.']" value="'.$value.'" class="text_area" size="'.$size.'" />';
00131                 break;
00132             case 'list':
00133                 $options = array();
00134                 foreach ($param->option as $option) $options[] = $alirohtml->makeOption((string) $option['value'], (string) $option);
00135                 $controlstring = $alirohtml->selectList($options, $controlname.'['.$name.']', 'class="inputbox"', 'value', 'text', $value);
00136                 break;
00137             case 'radio':
00138                 $options = array();
00139                 foreach ($param->option as $option) $options[] = $alirohtml->makeOption((string) $option['value'], (string) $option);
00140                 $controlstring = $alirohtml->radioList($options, $controlname.'['.$name.']', '', $value);
00141                 break;
00142             case 'imagelist':
00143                 $directory = new aliroDirectory (_ALIRO_ABSOLUTE_PATH.(string) $param['directory']);
00144                 $files = $directory->listFiles ('\.png$|\.gif$|\.jpg$|\.bmp$|\.ico$');
00145                 $options = array();
00146                 foreach ($files as $file) $options[] = $alirohtml->makeOption($file, $file);
00147                 if (!isset($param['hide_none'])) array_unshift($options, $alirohtml->makeOption('-1', '- Do not use an image -' ));
00148                 if (!isset($param['hide_default'])) array_unshift($options, $alirohtml->makeOption('', '- Use Default image -'));
00149                 $controlstring = $alirohtml->selectList ($options, "$controlname[$name]", 'class="inputbox"', 'value', 'text', $value);
00150                 break;
00151             case 'textarea':
00152                 $rows = (string) $param['rows'];
00153                 $cols = (string) $param['cols'];
00154                 $value = str_replace ('<br /', "\n", $value);
00155                 $controlstring = "<textarea name='params[$name]' cols='$cols' rows='$rows' class='text_area'>$value</textarea>";
00156                 break;
00157             case 'editarea':
00158                 $editor = aliroEditor::getInstance();
00159                 $controlstring = $editor->editorAreaText( $controlname.'['.$name.']',  $value , $controlname.'['.$name.']', '700', '350', '95', '30' ) ;
00160                 break;
00161             case 'dynamic':
00162                 $class = (string) $param['class'];
00163                 $method = (string) $param['method'];
00164                 if ($class) $object = call_user_func($class, 'getInstance');
00165                 if (is_object($object) AND $method) {
00166                     $controlstring = $object->$method($name, $value, $controlname, $param);
00167                     break;
00168                 }
00169                 $controlstring = sprintf(T_('Dynamic parameter class: %s, method: %s failed'), $class, $method);
00170                 break;
00171             case 'spacer':
00172                 $controlstring = $value ? $value : '<hr />';
00173                 break;
00174             case 'mos_section':
00175                 $controlstring = _form_mos_section($name, $value, $controlname);
00176                 break;
00177             case 'mos_category':
00178                 $controlstring = _form_mos_category($name, $value, $controlname);
00179                 break;
00180             case 'mos_menu':
00181                 $controlstring = $this->_form_mos_menu($name, $value, $controlname);
00182                 break;
00183             default:
00184                 $controlstring = T_('Handler not defined for type').'='.$type;
00185         }
00186         $this->html[] = "<td>$controlstring</td>";
00187         $this->html[] = "<td width='10%' align='left' valign='top'>$tooltip</td>";
00188         $this->html[] = '</tr>';
00189         $this->paramcount++;
00190     }
00191 
00199     protected function _form_mos_section( $name, $value, $control_name ) {
00200         $database = mamboDatabase::getInstance();
00201         $query = "SELECT id AS value, title AS text"
00202         . "\n FROM #__sections"
00203         . "\n WHERE published='1' AND scope='content'"
00204         . "\n ORDER BY title"
00205         ;
00206         $database->setQuery( $query );
00207         $options = $database->loadObjectList();
00208         array_unshift($options, aliroHTML::getInstance()->makeOption( '0', '- Select Content Section -' ));
00209         return aliroHTML::getInstance()->selectList( $options, "$control_name[$name]", 'class="inputbox"', 'value', 'text', $value );
00210     }
00218     protected function _form_mos_category( $name, $value, $control_name ) {
00219         $firstoption = aliroHTML::getInstance()->makeOption('0', '- Select Content Category -');
00220         $database = mamboDatabase::getInstance();
00221         $query  = "SELECT c.id AS value, CONCAT_WS( '/',s.title, c.title ) AS text"
00222         . "\n FROM #__categories AS c"
00223         . "\n LEFT JOIN #__sections AS s ON s.id=c.section"
00224         . "\n WHERE c.published='1' AND s.scope='content'"
00225         . "\n ORDER BY c.title"
00226         ;
00227         $database->setQuery( $query );
00228         $options = $database->loadObjectList();
00229         if ($options) array_unshift($options, $firstoption);
00230         else $options = array($firstoption);
00231         return aliroHTML::getInstance()->selectList( $options, "$control_name[$name]", 'class="inputbox"', 'value', 'text', $value );
00232     }
00233 
00234     function _form_mos_menu( $name, $value, $control_name ) {
00235         $handler = aliroMenuHandler::getInstance();
00236         $menuTypes = $handler->getMenutypes();
00237         $alirohtml = aliroHTML::getInstance();
00238         $options[] = $alirohtml->makeOption( '', '- Select Menu -' );
00239         foreach($menuTypes as $menutype ) $options[] = $alirohtml->makeOption( $menutype, $menutype );
00240         return $alirohtml->selectList( $options, ''. $control_name .'['. $name .']', 'class="inputbox"', 'value', 'text', $value );
00241     }
00242 }
00243 
00244 class aliroXMLParamsDefault {
00245     protected $xmlobject = null;
00246 
00247     public function __construct () {
00248         $this->xmlobject = new aliroXML;
00249     }
00250 
00251     public function paramsFromFile ($xmlfile) {
00252         $this->xmlobject->loadFile($xmlfile);
00253         return $this->analyseXML();
00254     }
00255 
00256     public function paramsFromString ($xmlstring) {
00257         $this->xmlobject->loadString($xmlstring);
00258         return $this->analyseXML();
00259     }
00260 
00261     private function analyseXML () {
00262         $pobject = new aliroParameters;
00263         foreach ($this->xmlobject->getXML('params->param') as $aparam) {
00264             $name = (string) $aparam['name'];
00265             $default = (string) $aparam['default'];
00266             if ($name AND $default) $pobject->set($name, $default);
00267         }
00268         return $pobject;
00269     }
00270 
00271 }

Generated on Wed May 14 13:01:56 2008 for ALIRO by  doxygen 1.5.5