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