00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
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
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 }