Source code for file /joomla/html/parameter.php
Documentation is available at parameter.php
* @version $Id: parameter.php 6743 2007-02-28 10:07:23Z tcp $
* @package Joomla.Framework
* @copyright Copyright (C) 2005 - 2007 Open Source Matters. All rights reserved.
* @license GNU/GPL, see LICENSE.php
* Joomla! is free software. This version may have been modified pursuant
* to the GNU General Public License, and as distributed it includes or
* is derivative of works licensed under the GNU General Public License or
* other free or open source software licenses.
* See COPYRIGHT.php for copyright notices and details.
// Check to ensure this file is within the rest of the framework
jimport( 'joomla.registry.registry' );
* @package Joomla.Framework
var $_elements =
array();
* directories, where element types can be stored
var $_elementDirs =
array();
* @param string The raw parms text
* @param string Path to the xml setup file
* @var string The type of setup file
if( !defined( 'JPARAMETER_INCLUDE_PATH' ) ) {
define( 'JPARAMETER_INCLUDE_PATH', dirname( __FILE__
).
DS.
'parameter'.
DS.
'element' );
* @param string The name of the param
* @param string The value of the parameter
* @return string The set value
function set($key, $value =
'', $group =
'_default')
$this->setValue($group.
'.'.
$key, (string)
$value);
return $this->getValue($group.
'.'.
$key);
* @param string The name of the param
* @param mixed The default value if not found
function get($key, $default =
'', $group =
'_default')
$value =
$this->getValue($group.
'.'.
$key);
$result =
(empty($value) &&
($value !==
0) &&
($value !==
'0')) ?
$default :
$value;
* Sets a default value if not alreay assigned
* @param string The name of the param
* @param string The value of the parameter
* @return string The set value
function def($key, $value =
'') {
return $this->set($key, $this->get($key, (string)
$value));
* Sets the XML object from custom xml files
* @param object An XML object
if ($group =
$xml->attributes( 'group' )) {
$this->_xml[$group] =
$xml;
$this->_xml['_default'] =
$xml;
if ($dir =
$xml->attributes( 'addparameterdir' )) {
* Bind data to the parameter
* @param mixed $data Array or Object
* @return boolean True if the data was successfully bound
function bind($data, $group =
'_default')
return $this->loadINI($data, $group);
* @param string The name of the control, or the default text area if a setup file is not found
function render($name =
'params', $group =
'_default')
if (!isset
($this->_xml[$group])) {
$html[] =
'<table width="100%" class="paramlist" cellspacing="1">';
if ($description =
$this->_xml[$group]->attributes('description')) {
// add the params description to the display
$desc =
JText::_($description);
$html[] =
'<tr><td class="paramlist_description" colspan="2">'.
$desc.
'</td></tr>';
foreach ($params as $param)
$html[] =
'<td width="40%" class="paramlist_key"><span class="editlinktip">'.
$param[0].
'</span></td>';
$html[] =
'<td class="paramlist_value">'.
$param[1].
'</td>';
if (count($params) <
1) {
$html[] =
"<tr><td colspan=\"2\"><i>".
JText::_('There are no Parameters for this item').
"</i></td></tr>";
* Render all parameters to an array
* @param string The name of the control, or the default text area if a setup file is not found
* @return array of all parameters, each as array Any array of the label, the form element and the tooltip
if (!isset
($this->_xml[$group])) {
foreach ($this->_xml[$group]->children() as $param) {
$result =
$this->getParam($param, $name);
$results[$result[5]] =
$result;
* Return number of params to render
* @return mixed Boolean falst if no params exist or integer number of params that exist
if (!isset
($this->_xml[$group]) ||
!count($this->_xml[$group]->children())) {
return count($this->_xml[$group]->children());
* Get the number of params in each group
* @return array of all group names as key and param count as value
foreach ($this->_xml as $name =>
$group) {
* @param string The name of the control, or the default text area if a setup file is not found
* @return array of all parameters, each as array Any array of the label, the form element and the tooltip
function getParams($name =
'params', $group =
'_default')
if (!isset
($this->_xml[$group])) {
foreach ($this->_xml[$group]->children() as $param) {
$results[] =
$this->getParam($param, $name, $group);
* Render a parameter type
* @param object A param tag node
* @param string The control name
* @return array Any array of the label, the form element and the tooltip
function getParam(&$node, $control_name =
'params', $group =
'_default')
//get the type of the parameter
$type =
$node->attributes('type');
//remove any occurance of a mos_ prefix
$result[0] =
$node->attributes('name');
$result[1] =
JText::_('Element not defined for type').
' = '.
$type;
$value =
$this->get($node->attributes('name'), $node->attributes('default'));
return $element->render($node, $value, $control_name);
* Loads an xml setup file and parses it
* @param string path to xml setup file
if ($xml->loadFile($path))
if ($params =
& $xml->document->params) {
foreach ($params as $param)
* @param string elementType
$signature =
md5( $type );
if( (isset
( $this->_elements[$signature] ) &&
!is_a($this->_elements[$signature], '__PHP_Incomplete_Class')) &&
$new ===
false ) {
return $this->_elements[$signature];
jimport('joomla.html.parameter.element');
$elementClass =
'JElement'.
$type;
if( isset
( $this->_elementDirs ) ) {
$dirs =
$this->_elementDirs;
if (@include_once $elementFile)
$this->_elements[$signature] =
new $elementClass($this);
return $this->_elements[$signature];
* Add a directory where JParameter should search for element types
* You may either pass a string or an array of directories.
* JParameter will be searching for a element type in the same
* order you added them. If the parameter type cannot be found in
* the custom folders, it will look in
* @param string|array directory or directories to search.
$this->_elementDirs =
array_merge( $this->_elementDirs, $dir );
return JPARAMETER_INCLUDE_PATH;