/**
  * Appends (copies) a child $source and all its descendants to $this node
  * @since 1.2.4
  *
  * @param CBSimpleXMLElement  $source
  * @param callback            $callBack to check/transform data or attributes of a node: $destinationData = function ( string|array $sourceData, CBSimpleXMLElement $sourceNode, CBSimpleXMLElement $destinationParentNode );
  */
 function &addChildWithDescendants(&$source, $callBack = null)
 {
     if ($callBack === null) {
         $child = $this->addChildWithAttr($source->name(), $source->data(), null, $source->attributes());
     } else {
         $child = $this->addChildWithAttr($source->name(), call_user_func_array($callBack, array($source->data(), $source, $this)), null, call_user_func_array($callBack, array($source->attributes(), $source, $this)));
     }
     foreach ($source->children() as $sourceChild) {
         $child->addChildWithDescendants($sourceChild, $callBack);
     }
     return $child;
 }
Example #2
0
	/**
	* @param string The name of the form element
	* @param string The value of the element
	* @param CBSimpleXMLElement  $node The xml element for the parameter
	* @param string The control name
	* @return string The html for the element
	*/
	function _form_radio( $name, $value, &$node, $control_name ) {
		$options = array();
		foreach ( $node->children() as $option ) {
			if ( $option->attributes( 'index' ) ) {
				$val = $option->attributes( 'index' );
			} else {
				$val = $option->attributes( 'value' );
			}
			$text = CBTxt::T( getLangDefinition($option->data()) );
			$options[] = moscomprofilerHTML::makeOption( $val, $text );
		}
		return moscomprofilerHTML::radioList( $options, ''. $this->control_name( $control_name, $name ) . '', '', 'value', 'text', $value );			//TBD missing id :  id="' . $this->control_id( $control_name, $name ) . '"
	}
 /**
  * @param string A file path
  * @return object A DOMIT XML document, or null if the file failed to parse
  */
 function &isPackageFile($p_file)
 {
     $null = null;
     if (!file_exists($p_file)) {
         return $null;
     }
     cbimport('cb.xml.simplexml');
     $xmlString = trim(file_get_contents($p_file));
     $element = new CBSimpleXMLElement($xmlString);
     if (count($element->children()) == 0) {
         return $null;
     }
     if ($element->name() != 'cbinstall') {
         //echo "didn't find cbinstall";
         return $null;
     }
     // Set the type
     //echo "<br />element->attributes( 'type' )=".$element->attributes( 'type' );
     $this->installType($element->attributes('type'));
     $this->installFilename($p_file);
     return $element;
 }
Example #4
0
	/**
	 * Protected internal function that handles missing DOM functionality:
	 * $callBack to the copied attributes and data, as well as copying of children.
	 * @since 1.2.4
	 * @protected
	 *
	 * @param  DOMElement          $newNode         new DOM (incomplete) node just inserted/replaced
	 * @param  CBSimpleXMLElement  $xmlSourceNode   original XML node that got copied into DOM
	 * @param  callback            $callBack to check/transform data or attributes of a node: $destinationData = function ( string|array $sourceData, CBSimpleXMLElement $sourceNode, CBSimpleXMLElement $destinationParentNode );
	 * @return CBSimpleXMLElement  New XML node
	 */
	function & _domCopyChildrenCallbackonNode( &$newNode, $xmlSourceNode, $callBack ) {
		$newNodeXML				=&	simplexml_import_dom( $newNode, get_class( $this ) );
		if ( $callBack === null ) {
			$newNode->nodeValue	=	$xmlSourceNode->data();
			$attributesToCopy	=	$xmlSourceNode->attributes();
			foreach ( $attributesToCopy as $k => $v ) {
				// PHP 5.2 doesn't copy attributes however PHP 5.3 does it, so let's copy again for PHP 5.2:	//TBD later check from which version this 5.2 bug has been fixed...
				$newNode->setAttribute( $k, $attributesToCopy[$k] );
			}
		} else {
			$newNode->nodeValue	=	call_user_func_array( $callBack, array( $xmlSourceNode->data(), $xmlSourceNode, $newNodeXML ) );
			$copiedAttributes	=	$newNode->attributes;
			foreach ( $copiedAttributes as $k => $v ) {
				$newNode->removeAttribute( $k );
			}
			// the new set of $attributes can be different from old one, thus we needed to remove old set (copied in PHP 5.3 only) first, then copy new:
			$attributes			=	call_user_func_array( $callBack, array( $xmlSourceNode->attributes(), $xmlSourceNode, $newNodeXML ) );
			foreach ( $attributes as $k => $v ) {
				$newNode->setAttribute( $k, $v );
			}
		}
		foreach ($xmlSourceNode->children() as $child ) {
			$newNodeXML->addChildWithDescendants( $child, $callBack );
		}
		return $newNodeXML;
	}
 /**
  * @param  string  $name   The name of the form element
  * @param  CBSimpleXMLElement  $node  The xml element for the parameter
  * @param  string  $control_name  The control name
  * @return JForm
  */
 protected static function getPermissionsForm($name, $node, $control_name)
 {
     $accesses = array();
     foreach ($node->children() as $permission) {
         /** @var $permission CBSimpleXMLElement */
         if ($permission->name() == 'permission') {
             $beforelabel = CBPTXT::T($permission->attributes('beforelabel'));
             $label = ($beforelabel ? $beforelabel . ' &nbsp;' : '') . CBPTXT::T($permission->attributes('label'));
             $accesses[] = sprintf('<action name="%s" title="%s" description="%s" />', htmlspecialchars($permission->attributes('name')), htmlspecialchars($label), htmlspecialchars(CBPTXT::T($permission->attributes('description'))));
         }
     }
     $permission = '<field name="rules" type="rules" label="FIELD_RULES_LABEL" translate_label="false" validate="rules" class="inputbox" filter="rules" asset_field="%s">%s</field>';
     $xmlstring = sprintf('<?xml version="1.0" encoding="utf-8"?><form>%s</form>', sprintf($permission, 'rules', implode('', $accesses)));
     $options = array('control' => self::control_name_static($control_name, $name), 'load_data' => false);
     jimport('joomla.form.form');
     // Needed for J1.6+1.7. (Bug #3508)
     $form = new JForm($name, $options);
     $form->load($xmlstring, true, false);
     return $form;
 }
 /**
  * Converts a XML description of a SQL index into a full SQL type
  *
  *	<index name="PRIMARY" type="primary">
  *		<column name="id"	/>
  *	</index>
  *	<index name="rate_chars">
  *		<column name="rate" />
  *		<column name="_mychars" nametype="namesuffix" size="8" ordering="DESC" />
  *	</index>
  *	<index name="myrate" type="unique" using="btree">
  *		<column name="rate" />
  *	</index>
  *
  * Returns: $fulltype: 'decimal(16,8) unsigned NULL DEFAULT NULL'
  * @access private
  *
  * @param  CBSimpleXMLElement  $index
  * @param  string              $colNamePrefix    Prefix to add to all column names
  * @return string|boolean                        Full SQL creation type or NULL in case of no index/error
  */
 function _fullIndexType(&$index, $colNamePrefix)
 {
     $sqlIndexText = null;
     if ($index->name() == 'index') {
         // first collect all columns of this index:
         $indexColumns = array();
         foreach ($index->children() as $column) {
             if ($column->name() == 'column') {
                 $colNamePrefixed = $this->_prefixedName($column, $colNamePrefix);
                 $indexColText = $this->_db->NameQuote($colNamePrefixed);
                 if ($column->attributes('size')) {
                     $indexColText .= ' (' . (int) $column->attributes('size') . ')';
                 }
                 if ($column->attributes('ordering')) {
                     $indexColText .= ' ' . $this->_db->getEscaped($column->attributes('ordering'));
                 }
                 $indexColumns[] = $indexColText;
             }
         }
         if (count($indexColumns) > 0) {
             // then build the index creation SQL:
             if ($index->attributes('type')) {
                 // PRIMARY, UNIQUE, FULLTEXT, SPATIAL:
                 $sqlIndexText .= $this->_db->getEscaped(strtoupper($index->attributes('type'))) . ' ';
             }
             $sqlIndexText .= 'KEY ';
             if ($index->attributes('type') !== 'primary') {
                 $sqlIndexText .= $this->_db->NameQuote($this->_prefixedName($index, $colNamePrefix)) . ' ';
             }
             if ($index->attributes('using')) {
                 // BTREE, HASH, RTREE:
                 $sqlIndexText .= 'USING ' . $this->_db->getEscaped($index->attributes('using')) . ' ';
             }
             $sqlIndexText .= '(' . implode(', ', $indexColumns) . ')';
         }
     }
     return $sqlIndexText;
 }