| 22 |
var $type; |
var $type; |
| 23 |
var $terminalError = false; |
var $terminalError = false; |
| 24 |
var $errors = array(); |
var $errors = array(); |
| 25 |
|
var $mosParameter = null; |
| 26 |
|
var $name = ''; |
| 27 |
|
|
| 28 |
function mosBasicXML ($file) { |
function mosBasicXML ($file, $mosParameter=null, $name='params') { |
| 29 |
//echo $file.'<br />'; |
|
| 30 |
|
$this->modParameter = $mosParameter; |
| 31 |
|
$this->name = $name; |
| 32 |
$this->setTree(); |
$this->setTree(); |
| 33 |
$parser = xml_parser_create(); |
$parser = xml_parser_create(); |
| 34 |
$startfunc = array ($this, 'start_element'); |
xml_set_element_handler ($parser, array ($this, 'start_element'), array ($this, 'end_element')); |
| 35 |
$endfunc = array ($this, 'end_element'); |
xml_set_character_data_handler ($parser, array ($this, 'character_data')); |
| 36 |
$charfunc = array ($this, 'character_data'); |
|
|
xml_set_element_handler ($parser, $startfunc, $endfunc); |
|
|
xml_set_character_data_handler ($parser, $charfunc); |
|
| 37 |
$fp = fopen($file, 'rb'); |
$fp = fopen($file, 'rb'); |
| 38 |
while ($data = fread($fp, 4096) AND !$this->terminalError) { |
while ($data = fread($fp, 4096) AND !$this->terminalError) { |
| 39 |
$data = str_replace('&', ' ampersand ', $data); |
$data = str_replace('&', ' ampersand ', $data); |
| 70 |
function start_element ($parser, $element_name, $element_attrs) { |
function start_element ($parser, $element_name, $element_attrs) { |
| 71 |
if ($this->terminalError) return; |
if ($this->terminalError) return; |
| 72 |
$method = 'element_'.$element_name; |
$method = 'element_'.$element_name; |
| 73 |
|
|
| 74 |
$specific = array ($this, $method); |
$specific = array ($this, $method); |
| 75 |
if (is_callable($specific)) $this->$method($element_attrs); |
if (is_callable($specific)) $this->$method($element_attrs); |
| 76 |
if ($this->mosinstall) { |
if ($this->mosinstall) { |
| 80 |
} |
} |
| 81 |
if ($this->mosinstall OR $element_name == 'MOSINSTALL') { |
if ($this->mosinstall OR $element_name == 'MOSINSTALL') { |
| 82 |
$this->opencount = array_unshift ($this->opentags, $element_name); |
$this->opencount = array_unshift ($this->opentags, $element_name); |
| 83 |
|
dump($this->opentags); |
| 84 |
$setdata = array ($this, 'set_data'); |
$setdata = array ($this, 'set_data'); |
| 85 |
if (is_callable($setdata)) $this->set_data($element_attrs); |
if (is_callable($setdata)) $this->set_data($element_attrs); |
| 86 |
$this->mosinstall = true; |
$this->mosinstall = true; |
| 92 |
function end_element ($parser, $element_name) { |
function end_element ($parser, $element_name) { |
| 93 |
if ($this->terminalError) return; |
if ($this->terminalError) return; |
| 94 |
$check = array_shift ($this->opentags); |
$check = array_shift ($this->opentags); |
| 95 |
|
dump($this); |
| 96 |
if ($check != $element_name) { |
if ($check != $element_name) { |
| 97 |
$this->opencount = array_unshift ($this->opentags, $check); |
$this->opencount = array_unshift ($this->opentags, $check); |
| 98 |
trigger_error("XML last open tag was $check, but found end of $element_name"); |
trigger_error("XML last open tag was $check, but found end of $element_name"); |
| 99 |
} |
} |
| 100 |
else $this->opencount--; |
else $this->opencount--; |
| 101 |
|
$method = 'end_element_'.$element_name; |
| 102 |
|
$specific = array ($this, $method); |
| 103 |
|
if (is_callable($specific)) $this->$method(); |
| 104 |
// echo '<br />End of '.$element_name; |
// echo '<br />End of '.$element_name; |
| 105 |
} |
} |
| 106 |
|
|
| 130 |
|
|
| 131 |
function character_data ($parser, $data) { |
function character_data ($parser, $data) { |
| 132 |
if ($this->terminalError) return; |
if ($this->terminalError) return; |
| 133 |
$data = trim($data); |
$this->topLevelCharacterData($data); |
| 134 |
if ($data) { |
} |
| 135 |
|
|
| 136 |
|
function topLevelCharacterData ($data) { |
| 137 |
|
if ($data = trim($data)) { |
| 138 |
if (isset($this->opentags[1]) AND $this->opentags[1] == 'MOSINSTALL') $this->values[$this->opentags[0]] = $data; |
if (isset($this->opentags[1]) AND $this->opentags[1] == 'MOSINSTALL') $this->values[$this->opentags[0]] = $data; |
| 139 |
} |
} |
| 140 |
} |
} |
| 186 |
|
|
| 187 |
} |
} |
| 188 |
|
|
| 189 |
|
class mosXMLParams extends mosXMLDescription { |
| 190 |
|
var $options = array(); |
| 191 |
|
var $optvalue = ''; |
| 192 |
|
var $optdata = ''; |
| 193 |
|
var $paramattrs = array(); |
| 194 |
|
var $paramcount = 0; |
| 195 |
|
var $html = array(); |
| 196 |
|
|
| 197 |
|
function element_params ($attrs) { |
| 198 |
|
$this->html[] = '<table class="paramlist">'; |
| 199 |
|
if (isset($attrs['NAME'])) { |
| 200 |
|
$pname = $attrs['NAME']; |
| 201 |
|
$this->html[] = "<tr><td colspan='3'>$pname</td></tr>"; |
| 202 |
|
} |
| 203 |
|
} |
| 204 |
|
|
| 205 |
|
function element_param ($attrs) { |
| 206 |
|
$this->paramattrs = $attrs; |
| 207 |
|
} |
| 208 |
|
|
| 209 |
|
function element_option ($attrs) { |
| 210 |
|
if (isset($attrs['VALUE'])) $optvalue = $attrs['VALUE']; |
| 211 |
|
} |
| 212 |
|
|
| 213 |
|
function character_data ($parser, $data) { |
| 214 |
|
if ($this->terminalError) return; |
| 215 |
|
$this->topLevelCharacterData($data); |
| 216 |
|
if ($this->opentags[0] == 'OPTION') $this->optdata = $data; |
| 217 |
|
} |
| 218 |
|
|
| 219 |
|
function end_element_option () { |
| 220 |
|
$this->options[] = mosHTML::makeOption($this->optvalue, $this->optdata); |
| 221 |
|
$this->optdata = ''; |
| 222 |
|
$this->optvalue = ''; |
| 223 |
|
} |
| 224 |
|
|
| 225 |
|
function end_element_param () { |
| 226 |
|
$type = mosGetParam ($this->paramattrs, 'TYPE', ''); |
| 227 |
|
$name = mosGetParam ($this->paramattrs, 'NAME', ''); |
| 228 |
|
$label = mosGetParam ($this->paramattrs, 'LABEL', $name); |
| 229 |
|
$default = mosGetParam ($this->paramattrs, 'DEFAULT', ''); |
| 230 |
|
if ($description = mosGetParam ($this->paramattrs, 'DESCRIPTION', '')) $tooltip = mosToolTip($description, $name); |
| 231 |
|
else $tooltip = ''; |
| 232 |
|
if (is_object($this->mosParameter)) $value = $this->mosParameter->get($name, $default); |
| 233 |
|
else $value = $default; |
| 234 |
|
$this->html[] = '<tr>'; |
| 235 |
|
if ($label == '@spacer') $label = '<hr />'; |
| 236 |
|
elseif ($label) $label .= ':'; |
| 237 |
|
$this->html[] = '<td width="35%" align="right" valign="top">'.$label.'</td>'; |
| 238 |
|
$controlname = $this->name; |
| 239 |
|
switch ($type) { |
| 240 |
|
case 'text': |
| 241 |
|
$size = mosGetParam ($this->paramattrs, 'SIZE', 0); |
| 242 |
|
$controlstring = '<input type="text" name="'.$this->name.'['.$name.']" value="'.$value.'" class="text_area" size="'.$size.'" />'; |
| 243 |
|
break; |
| 244 |
|
case 'list': |
| 245 |
|
$controlstring = mosHTML::selectList($this->options, "$controlname[$name]", 'class="inputbox"', 'value', 'text', $value); |
| 246 |
|
break; |
| 247 |
|
case 'radio': |
| 248 |
|
$controlstring = mosHTML::radioList($this->options, "$controlname[$name]", $value); |
| 249 |
|
break; |
| 250 |
|
case 'imagelist': |
| 251 |
|
$directory = new mosDirectory (mamboCore::get('mosConfig_absolute_path').mosGetParam($this->paramattrs, 'DIRECTORY', '')); |
| 252 |
|
$files = $directory->listFiles ('\.png$|\.gif$|\.jpg$|\.bmp$|\.ico$'); |
| 253 |
|
$options = array(); |
| 254 |
|
foreach ($files as $file) $options[] = mosHTML::makeOption($file, $file); |
| 255 |
|
if (!isset($this->paramattrs['HIDE_NONE'])) array_unshift($options, mosHTML::makeOption('-1', '- Do not use an image -' )); |
| 256 |
|
if (!isset($this->paramattrs['HIDE_DEFAULT'])) array_unshift($options, mosHTML::makeOption('', '- Use Default image -')); |
| 257 |
|
$controlstring = mosHTML::selectList ($options, "$controlname[$name]", 'class="inputbox"', 'value', 'text', $value); |
| 258 |
|
break; |
| 259 |
|
case 'textarea': |
| 260 |
|
$rows = mosGetParam ($this->paramattrs, 'ROWS', 0); |
| 261 |
|
$cols = mosGetParam ($this->paramattrs, 'COLS', 0); |
| 262 |
|
$value = str_replace ('<br /', "\n", $value); |
| 263 |
|
$controlstring = "<textarea name='params[$name]' cols='$cols' rows='$rows' class='text_area'>$value</textarea>"; |
| 264 |
|
break; |
| 265 |
|
case 'spacer': |
| 266 |
|
$controlstring = $value ? $value : '<hr />'; |
| 267 |
|
break; |
| 268 |
|
case 'mos_section': |
| 269 |
|
$controlstring = _form_mos_section($name, $value, $controlname); |
| 270 |
|
break; |
| 271 |
|
case 'mos_category': |
| 272 |
|
$controlstring = _form_mos_category($name, $value, $controlname); |
| 273 |
|
break; |
| 274 |
|
case 'mos_menu': |
| 275 |
|
default: |
| 276 |
|
$controlstring = _HANDLER.'='.$type; |
| 277 |
|
} |
| 278 |
|
// $this->html[] = "<td>$type</td>"; |
| 279 |
|
$this->html[] = "<td>$controlstring</td>"; |
| 280 |
|
$this->html[] = "<td width='10%' align='left' valign='top'>$tooltip</td>"; |
| 281 |
|
$this->html[] = '</tr>'; |
| 282 |
|
$this->options = array(); |
| 283 |
|
$this->paramattrs = array(); |
| 284 |
|
$this->paramcount++; |
| 285 |
|
} |
| 286 |
|
|
| 287 |
|
function end_element_params () { |
| 288 |
|
$this->html[] = '</table>'; |
| 289 |
|
if ($this->paramcount == 0) $this->html[] = '<tr><td colspan="2"><i>'._NO_PARAMS.'</i></td></tr>'; |
| 290 |
|
$this->paramcount = 0; |
| 291 |
|
} |
| 292 |
|
/** |
| 293 |
|
* @param string The name of the form element |
| 294 |
|
* @param string The value of the element |
| 295 |
|
* @param object The xml element for the parameter |
| 296 |
|
* @param string The control name |
| 297 |
|
* @return string The html for the element |
| 298 |
|
*/ |
| 299 |
|
function _form_mos_section( $name, $value, $control_name ) { |
| 300 |
|
$database = mamboDatabase::getInstance(); |
| 301 |
|
$query = "SELECT id AS value, title AS text" |
| 302 |
|
. "\n FROM #__sections" |
| 303 |
|
. "\n WHERE published='1' AND scope='content'" |
| 304 |
|
. "\n ORDER BY title" |
| 305 |
|
; |
| 306 |
|
$database->setQuery( $query ); |
| 307 |
|
$options = $database->loadObjectList(); |
| 308 |
|
array_unshift($options, mosHTML::makeOption( '0', '- Select Content Section -' )); |
| 309 |
|
return mosHTML::selectList( $options, "$control_name[$name]", 'class="inputbox"', 'value', 'text', $value ); |
| 310 |
|
} |
| 311 |
|
/** |
| 312 |
|
* @param string The name of the form element |
| 313 |
|
* @param string The value of the element |
| 314 |
|
* @param object The xml element for the parameter |
| 315 |
|
* @param string The control name |
| 316 |
|
* @return string The html for the element |
| 317 |
|
*/ |
| 318 |
|
function _form_mos_category( $name, $value, $control_name ) { |
| 319 |
|
$database = mamboDatabase::getInstance(); |
| 320 |
|
$query = "SELECT c.id AS value, CONCAT_WS( '/',s.title, c.title ) AS text" |
| 321 |
|
. "\n FROM #__categories AS c" |
| 322 |
|
. "\n LEFT JOIN #__sections AS s ON s.id=c.section" |
| 323 |
|
. "\n WHERE c.published='1' AND s.scope='content'" |
| 324 |
|
. "\n ORDER BY c.title" |
| 325 |
|
; |
| 326 |
|
$database->setQuery( $query ); |
| 327 |
|
$options = $database->loadObjectList(); |
| 328 |
|
array_unshift($options, mosHTML::makeOption('0', '- Select Content Category -')); |
| 329 |
|
return mosHTML::selectList( $options, "$control_name[$name]", 'class="inputbox"', 'value', 'text', $value ); |
| 330 |
|
} |
| 331 |
|
/** |
| 332 |
|
* @param string The name of the form element |
| 333 |
|
* @param string The value of the element |
| 334 |
|
* @param object The xml element for the parameter |
| 335 |
|
* @param string The control name |
| 336 |
|
* @return string The html for the element |
| 337 |
|
*/ |
| 338 |
|
// function _form_mos_menu( $name, $value, &$node, $control_name ) { |
| 339 |
|
// global $database; |
| 340 |
|
// |
| 341 |
|
// $menuTypes = $mainframe->menutypes(); |
| 342 |
|
// |
| 343 |
|
// foreach($menuTypes as $menutype ) { |
| 344 |
|
// $options[] = mosHTML::makeOption( $menutype, $menutype ); |
| 345 |
|
// } |
| 346 |
|
// array_unshift( $options, mosHTML::makeOption( '', '- Select Menu -' ) ); |
| 347 |
|
// |
| 348 |
|
// return mosHTML::selectList( $options, ''. $control_name .'['. $name .']', 'class="inputbox"', 'value', 'text', $value ); |
| 349 |
|
// } |
| 350 |
|
} |
| 351 |
|
|
| 352 |
|
/** |
| 353 |
|
* Parameters handler |
| 354 |
|
* @package Mambo |
| 355 |
|
*/ |
| 356 |
|
class mosAdminParameters extends mosParameters { |
| 357 |
|
/** @var string Path to the xml setup file */ |
| 358 |
|
var $_path = null; |
| 359 |
|
/** @var string The type of setup file */ |
| 360 |
|
var $_type = null; |
| 361 |
|
/** @var object The xml params element */ |
| 362 |
|
var $_xmlElem = null; |
| 363 |
|
/** |
| 364 |
|
* Constructor |
| 365 |
|
* @param string The raw parms text |
| 366 |
|
* @param string Path to the xml setup file |
| 367 |
|
* @var string The type of setup file |
| 368 |
|
*/ |
| 369 |
|
function mosAdminParameters( $text, $path='', $type='component' ) { |
| 370 |
|
$this->_params = $this->parse( $text ); |
| 371 |
|
$this->_raw = $text; |
| 372 |
|
$this->_path = $path; |
| 373 |
|
$this->_type = $type; |
| 374 |
|
} |
| 375 |
|
|
| 376 |
|
/** |
| 377 |
|
* @param string The name of the control, or the default text area if a setup file is not found |
| 378 |
|
* @return string HTML |
| 379 |
|
*/ |
| 380 |
|
function render( $name='params' ) { |
| 381 |
|
$parser = new mosXMLParams ($this->_path, $this, $name); |
| 382 |
|
if (count($parser->html)) return implode("\n", $parser->html); |
| 383 |
|
else { |
| 384 |
|
$raw = $this->_raw; |
| 385 |
|
return "<textarea name='$name' cols='40' rows='10' class='text_area'$raw</textarea>"; |
| 386 |
|
} |
| 387 |
|
} |
| 388 |
|
|
| 389 |
|
} |
| 390 |
/** |
/** |
| 391 |
* @param string THe template position |
* @param string THe template position |
| 392 |
*/ |
*/ |