[ Index ] |
|
Code source de Joomla 1.0.13 |
1 <?php 2 /** 3 * @version $Id: joomla.xml.php 5083 2006-09-17 11:18:25Z predator $ 4 * @package Joomla 5 * @copyright Copyright (C) 2005 Open Source Matters. All rights reserved. 6 * @license http://www.gnu.org/copyleft/gpl.html GNU/GPL, see LICENSE.php 7 * Joomla! is free software. This version may have been modified pursuant 8 * to the GNU General Public License, and as distributed it includes or 9 * is derivative of works licensed under the GNU General Public License or 10 * other free or open source software licenses. 11 * See COPYRIGHT.php for copyright notices and details. 12 */ 13 14 // ensure this file is being included by a parent file 15 defined( '_VALID_MOS' ) or die( 'Restricted access' ); 16 17 /** 18 * Parameters handler 19 * @package Joomla 20 */ 21 class mosParameters { 22 /** @var object */ 23 var $_params = null; 24 /** @var string The raw params string */ 25 var $_raw = null; 26 /** @var string Path to the xml setup file */ 27 var $_path = null; 28 /** @var string The type of setup file */ 29 var $_type = null; 30 /** @var object The xml params element */ 31 var $_xmlElem = null; 32 /** 33 * Constructor 34 * @param string The raw parms text 35 * @param string Path to the xml setup file 36 * @var string The type of setup file 37 */ 38 function mosParameters( $text, $path='', $type='component' ) { 39 $this->_params = $this->parse( $text ); 40 $this->_raw = $text; 41 $this->_path = $path; 42 $this->_type = $type; 43 } 44 45 /** 46 * Returns the params array 47 * @return object 48 */ 49 function toObject() { 50 return $this->_params; 51 } 52 53 /** 54 * Returns a named array of the parameters 55 * @return object 56 */ 57 function toArray() { 58 return mosObjectToArray( $this->_params ); 59 } 60 61 /** 62 * @param string The name of the param 63 * @param string The value of the parameter 64 * @return string The set value 65 */ 66 function set( $key, $value='' ) { 67 $this->_params->$key = $value; 68 return $value; 69 } 70 /** 71 * Sets a default value if not alreay assigned 72 * @param string The name of the param 73 * @param string The value of the parameter 74 * @return string The set value 75 */ 76 function def( $key, $value='' ) { 77 return $this->set( $key, $this->get( $key, $value ) ); 78 } 79 /** 80 * @param string The name of the param 81 * @param mixed The default value if not found 82 * @return string 83 */ 84 function get( $key, $default='' ) { 85 if (isset( $this->_params->$key )) { 86 return $this->_params->$key === '' ? $default : $this->_params->$key; 87 } else { 88 return $default; 89 } 90 } 91 /** 92 * Parse an .ini string, based on phpDocumentor phpDocumentor_parse_ini_file function 93 * @param mixed The ini string or array of lines 94 * @param boolean add an associative index for each section [in brackets] 95 * @return object 96 */ 97 function parse( $txt, $process_sections = false, $asArray = false ) { 98 if (is_string( $txt )) { 99 $lines = explode( "\n", $txt ); 100 } else if (is_array( $txt )) { 101 $lines = $txt; 102 } else { 103 $lines = array(); 104 } 105 $obj = $asArray ? array() : new stdClass(); 106 107 $sec_name = ''; 108 $unparsed = 0; 109 if (!$lines) { 110 return $obj; 111 } 112 foreach ($lines as $line) { 113 // ignore comments 114 if ($line && $line[0] == ';') { 115 continue; 116 } 117 $line = trim( $line ); 118 119 if ($line == '') { 120 continue; 121 } 122 if ($line && $line[0] == '[' && $line[strlen($line) - 1] == ']') { 123 $sec_name = substr( $line, 1, strlen($line) - 2 ); 124 if ($process_sections) { 125 if ($asArray) { 126 $obj[$sec_name] = array(); 127 } else { 128 $obj->$sec_name = new stdClass(); 129 } 130 } 131 } else { 132 if ($pos = strpos( $line, '=' )) { 133 $property = trim( substr( $line, 0, $pos ) ); 134 135 if (substr($property, 0, 1) == '"' && substr($property, -1) == '"') { 136 $property = stripcslashes(substr($property,1,count($property) - 2)); 137 } 138 $value = trim( substr( $line, $pos + 1 ) ); 139 if ($value == 'false') { 140 $value = false; 141 } 142 if ($value == 'true') { 143 $value = true; 144 } 145 if (substr( $value, 0, 1 ) == '"' && substr( $value, -1 ) == '"') { 146 $value = stripcslashes( substr( $value, 1, count( $value ) - 2 ) ); 147 } 148 149 if ($process_sections) { 150 $value = str_replace( '\n', "\n", $value ); 151 if ($sec_name != '') { 152 if ($asArray) { 153 $obj[$sec_name][$property] = $value; 154 } else { 155 $obj->$sec_name->$property = $value; 156 } 157 } else { 158 if ($asArray) { 159 $obj[$property] = $value; 160 } else { 161 $obj->$property = $value; 162 } 163 } 164 } else { 165 $value = str_replace( '\n', "\n", $value ); 166 if ($asArray) { 167 $obj[$property] = $value; 168 } else { 169 $obj->$property = $value; 170 } 171 } 172 } else { 173 if ($line && trim($line[0]) == ';') { 174 continue; 175 } 176 if ($process_sections) { 177 $property = '__invalid' . $unparsed++ . '__'; 178 if ($process_sections) { 179 if ($sec_name != '') { 180 if ($asArray) { 181 $obj[$sec_name][$property] = trim($line); 182 } else { 183 $obj->$sec_name->$property = trim($line); 184 } 185 } else { 186 if ($asArray) { 187 $obj[$property] = trim($line); 188 } else { 189 $obj->$property = trim($line); 190 } 191 } 192 } else { 193 if ($asArray) { 194 $obj[$property] = trim($line); 195 } else { 196 $obj->$property = trim($line); 197 } 198 } 199 } 200 } 201 } 202 } 203 return $obj; 204 } 205 /** 206 * @param string The name of the control, or the default text area if a setup file is not found 207 * @return string HTML 208 */ 209 function render( $name='params' ) { 210 global $mosConfig_absolute_path; 211 212 if ($this->_path) { 213 if (!is_object( $this->_xmlElem )) { 214 require_once ( $mosConfig_absolute_path . '/includes/domit/xml_domit_lite_include.php' ); 215 216 $xmlDoc = new DOMIT_Lite_Document(); 217 $xmlDoc->resolveErrors( true ); 218 if ($xmlDoc->loadXML( $this->_path, false, true )) { 219 $root =& $xmlDoc->documentElement; 220 221 $tagName = $root->getTagName(); 222 $isParamsFile = ($tagName == 'mosinstall' || $tagName == 'mosparams'); 223 if ($isParamsFile && $root->getAttribute( 'type' ) == $this->_type) { 224 if ($params = &$root->getElementsByPath( 'params', 1 )) { 225 $this->_xmlElem =& $params; 226 } 227 } 228 } 229 } 230 } 231 232 if (is_object( $this->_xmlElem )) { 233 $html = array(); 234 $html[] = '<table width="100%" class="paramlist">'; 235 236 $element =& $this->_xmlElem; 237 238 if ($description = $element->getAttribute( 'description' )) { 239 // add the params description to the display 240 $html[] = '<tr><td colspan="2">' . $description . '</td></tr>'; 241 } 242 243 //$params = mosParseParams( $row->params ); 244 $this->_methods = get_class_methods( get_class( $this ) ); 245 246 foreach ($element->childNodes as $param) { 247 $result = $this->renderParam( $param, $name ); 248 $html[] = '<tr>'; 249 250 $html[] = '<td width="40%" align="right" valign="top"><span class="editlinktip">' . $result[0] . '</span></td>'; 251 $html[] = '<td>' . $result[1] . '</td>'; 252 253 $html[] = '</tr>'; 254 } 255 $html[] = '</table>'; 256 257 if (count( $element->childNodes ) < 1) { 258 $html[] = "<tr><td colspan=\"2\"><i>" . _NO_PARAMS . "</i></td></tr>"; 259 } 260 return implode( "\n", $html ); 261 } else { 262 return "<textarea name=\"$name\" cols=\"40\" rows=\"10\" class=\"text_area\">$this->_raw</textarea>"; 263 } 264 } 265 /** 266 * @param object A param tag node 267 * @param string The control name 268 * @return array Any array of the label, the form element and the tooltip 269 */ 270 function renderParam( &$param, $control_name='params' ) { 271 $result = array(); 272 273 $name = $param->getAttribute( 'name' ); 274 $label = $param->getAttribute( 'label' ); 275 276 $value = $this->get( $name, $param->getAttribute( 'default' ) ); 277 $description = $param->getAttribute( 'description' ); 278 279 $result[0] = $label ? $label : $name; 280 281 if ($result[0] == '@spacer') { 282 $result[0] = ' '; 283 } else { 284 $result[0] = mosToolTip( addslashes( $description ), addslashes( $result[0] ), '', '', $result[0], '#', 0 ); 285 } 286 $type = $param->getAttribute( 'type' ); 287 288 if (in_array( '_form_' . $type, $this->_methods )) { 289 $result[1] = call_user_func( array( &$this, '_form_' . $type ), $name, $value, $param, $control_name ); 290 } else { 291 $result[1] = _HANDLER . ' = ' . $type; 292 } 293 294 if ( $description ) { 295 $result[2] = mosToolTip( $description, $result[0] ); 296 $result[2] = ''; 297 } else { 298 $result[2] = ''; 299 } 300 301 return $result; 302 } 303 /** 304 * @param string The name of the form element 305 * @param string The value of the element 306 * @param object The xml element for the parameter 307 * @param string The control name 308 * @return string The html for the element 309 */ 310 function _form_text( $name, $value, &$node, $control_name ) { 311 $size = $node->getAttribute( 'size' ); 312 313 return '<input type="text" name="'. $control_name .'['. $name .']" value="'. htmlspecialchars($value) .'" class="text_area" size="'. $size .'" />'; 314 } 315 /** 316 * @param string The name of the form element 317 * @param string The value of the element 318 * @param object The xml element for the parameter 319 * @param string The control name 320 * @return string The html for the element 321 */ 322 function _form_list( $name, $value, &$node, $control_name ) { 323 $size = $node->getAttribute( 'size' ); 324 325 $options = array(); 326 foreach ($node->childNodes as $option) { 327 $val = $option->getAttribute( 'value' ); 328 $text = $option->gettext(); 329 $options[] = mosHTML::makeOption( $val, $text ); 330 } 331 332 return mosHTML::selectList( $options, ''. $control_name .'['. $name .']', 'class="inputbox"', 'value', 'text', $value ); 333 } 334 /** 335 * @param string The name of the form element 336 * @param string The value of the element 337 * @param object The xml element for the parameter 338 * @param string The control name 339 * @return string The html for the element 340 */ 341 function _form_radio( $name, $value, &$node, $control_name ) { 342 $options = array(); 343 foreach ($node->childNodes as $option) { 344 $val = $option->getAttribute( 'value' ); 345 $text = $option->gettext(); 346 $options[] = mosHTML::makeOption( $val, $text ); 347 } 348 349 return mosHTML::radioList( $options, ''. $control_name .'['. $name .']', '', $value ); 350 } 351 /** 352 * @param string The name of the form element 353 * @param string The value of the element 354 * @param object The xml element for the parameter 355 * @param string The control name 356 * @return string The html for the element 357 */ 358 function _form_mos_section( $name, $value, &$node, $control_name ) { 359 global $database; 360 361 $query = "SELECT id, title" 362 . "\n FROM #__sections" 363 . "\n WHERE published = 1" 364 . "\n AND scope = 'content'" 365 . "\n ORDER BY title" 366 ; 367 $database->setQuery( $query ); 368 $options = $database->loadObjectList(); 369 array_unshift( $options, mosHTML::makeOption( '0', '- Select Section -', 'id', 'title' ) ); 370 371 return mosHTML::selectList( $options, ''. $control_name .'['. $name .']', 'class="inputbox"', 'id', 'title', $value ); 372 } 373 /** 374 * @param string The name of the form element 375 * @param string The value of the element 376 * @param object The xml element for the parameter 377 * @param string The control name 378 * @return string The html for the element 379 */ 380 function _form_mos_category( $name, $value, &$node, $control_name ) { 381 global $database; 382 383 $scope = $node->getAttribute( 'scope' ); 384 if( !isset($scope) ) { 385 $scope = 'content'; 386 } 387 388 if( $scope== 'content' ) { 389 // This might get a conflict with the dynamic translation - TODO: search for better solution 390 $query = "SELECT c.id, CONCAT_WS( '/',s.title, c.title ) AS title" 391 . "\n FROM #__categories AS c" 392 . "\n LEFT JOIN #__sections AS s ON s.id=c.section" 393 . "\n WHERE c.published = 1" 394 . "\n AND s.scope = " . $database->Quote( $scope ) 395 . "\n ORDER BY c.title" 396 ; 397 } else { 398 $query = "SELECT c.id, c.title" 399 . "\n FROM #__categories AS c" 400 . "\n WHERE c.published = 1" 401 . "\n AND c.section = " . $database->Quote( $scope ) 402 . "\n ORDER BY c.title" 403 ; 404 } 405 $database->setQuery( $query ); 406 $options = $database->loadObjectList(); 407 array_unshift( $options, mosHTML::makeOption( '0', '- Select Category -', 'id', 'title' ) ); 408 409 return mosHTML::selectList( $options, ''. $control_name .'['. $name .']', 'class="inputbox"', 'id', 'title', $value ); 410 } 411 /** 412 * @param string The name of the form element 413 * @param string The value of the element 414 * @param object The xml element for the parameter 415 * @param string The control name 416 * @return string The html for the element 417 */ 418 function _form_mos_menu( $name, $value, &$node, $control_name ) { 419 global $database; 420 421 $menuTypes = mosAdminMenus::menutypes(); 422 423 foreach($menuTypes as $menutype ) { 424 $options[] = mosHTML::makeOption( $menutype, $menutype ); 425 } 426 array_unshift( $options, mosHTML::makeOption( '', '- Select Menu -' ) ); 427 428 return mosHTML::selectList( $options, ''. $control_name .'['. $name .']', 'class="inputbox"', 'value', 'text', $value ); 429 } 430 /** 431 * @param string The name of the form element 432 * @param string The value of the element 433 * @param object The xml element for the parameter 434 * @param string The control name 435 * @return string The html for the element 436 */ 437 function _form_filelist( $name, $value, &$node, $control_name ) { 438 global $mosConfig_absolute_path; 439 440 // path to images directory 441 $path = $mosConfig_absolute_path . $node->getAttribute( 'directory' ); 442 $filter = $node->getAttribute( 'filter' ); 443 $files = mosReadDirectory( $path, $filter ); 444 445 $options = array(); 446 foreach ($files as $file) { 447 $options[] = mosHTML::makeOption( $file, $file ); 448 } 449 if ( !$node->getAttribute( 'hide_none' ) ) { 450 array_unshift( $options, mosHTML::makeOption( '-1', '- '. 'Do Not Use' .' -' ) ); 451 } 452 if ( !$node->getAttribute( 'hide_default' ) ) { 453 array_unshift( $options, mosHTML::makeOption( '', '- '. 'Use Default' .' -' ) ); 454 } 455 456 return mosHTML::selectList( $options, ''. $control_name .'['. $name .']', 'class="inputbox"', 'value', 'text', $value, "param$name" ); 457 } 458 /** 459 * @param string The name of the form element 460 * @param string The value of the element 461 * @param object The xml element for the parameter 462 * @param string The control name 463 * @return string The html for the element 464 */ 465 function _form_imagelist( $name, $value, &$node, $control_name ) { 466 $node->setAttribute( 'filter', '\.png$|\.gif$|\.jpg$|\.bmp$|\.ico$' ); 467 return $this->_form_filelist( $name, $value, $node, $control_name ); 468 } 469 /** 470 * @param string The name of the form element 471 * @param string The value of the element 472 * @param object The xml element for the parameter 473 * @param string The control name 474 * @return string The html for the element 475 */ 476 function _form_textarea( $name, $value, &$node, $control_name ) { 477 $rows = $node->getAttribute( 'rows' ); 478 $cols = $node->getAttribute( 'cols' ); 479 // convert <br /> tags so they are not visible when editing 480 $value = str_replace( '<br />', "\n", $value ); 481 482 return '<textarea name="' .$control_name.'['. $name .']" cols="'. $cols .'" rows="'. $rows .'" class="text_area">'. htmlspecialchars($value) .'</textarea>'; 483 } 484 485 /** 486 * @param string The name of the form element 487 * @param string The value of the element 488 * @param object The xml element for the parameter 489 * @param string The control name 490 * @return string The html for the element 491 */ 492 function _form_spacer( $name, $value, &$node, $control_name ) { 493 if ( $value ) { 494 return $value; 495 } else { 496 return '<hr />'; 497 } 498 } 499 500 /** 501 * special handling for textarea param 502 */ 503 function textareaHandling( &$txt ) { 504 $total = count( $txt ); 505 for( $i=0; $i < $total; $i++ ) { 506 if ( strstr( $txt[$i], "\n" ) ) { 507 $txt[$i] = str_replace( "\n", '<br />', $txt[$i] ); 508 } 509 } 510 $txt = implode( "\n", $txt ); 511 512 return $txt; 513 } 514 } 515 516 /** 517 * @param string 518 * @return string 519 */ 520 function mosParseParams( $txt ) { 521 return mosParameters::parse( $txt ); 522 } 523 524 class mosEmpty { 525 function def( $key, $value='' ) { 526 return 1; 527 } 528 function get( $key, $default='' ) { 529 return 1; 530 } 531 } 532 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Wed Nov 21 14:43:32 2007 | par Balluche grâce à PHPXref 0.7 |
![]() |