コード例 #1
0
ファイル: cb.params.php プロジェクト: rkern21/videoeditor
	/**
	 * checks if there is an <attributes> extension in a <param> and sets attributes depending on any other param type
	 *
	 * @param  CBSimpleXMLElement  $param         (modified by adding attributes from <attributes>)
	 * @param  string              $control_name
	 * @param  boolean            $view            true if view only, false if editable
	 */
	function extendParamAttributes( &$param, $control_name = 'params', $view = true ) {
		$attributes											=	$param->getElementByPath( 'attributes' );
		if ( $attributes ) {
			foreach ( $attributes->children() as $attr ) {
				if ( $attr->name() == 'attribute' ) {
					$attName								=	$attr->attributes( 'name' );
					$attSeparator							=	$attr->attributes( 'separator' );
					$attTransform							=	$attr->attributes( 'transform' );
					$attMode								=	$attr->attributes( 'mode' );
					$replacements							=	false;
					if ( ( $attMode == null ) || ( ( $attMode == 'edit' ) && ! $view ) || ( ( $attMode == 'show' ) && $view ) ) {
						$attrArray							=	array();
						if ( $attName ) {
							foreach ( $attr->children() as $dataAttr ) {
								if ( $dataAttr->name() == 'param' ) {
									$this->extendParamAttributes( $dataAttr, $control_name );
									$result					=	$this->renderParam( $dataAttr, $control_name, true, 'table' );
									$attrArray[$attName][]	=	$result[1];
								} elseif ( $dataAttr->name() == 'replaces' ) {
									self::_substituteChildTexts( $dataAttr, null, null, $this );
									$replacements			=	true;
								} elseif ( $dataAttr->name() == 'data' ) {
									// keep silent here for now here as it was used only for decoration		//TODO CB 2.0: remove this
								} else {
									trigger_error( sprintf( 'attributes/attribute child tag "%s" name="%s" of param with name="%s" is not supported, only param is.', $dataAttr->name(), $dataAttr->attributes('name'), $param->attributes('name') ), E_USER_WARNING );
								}
							}
							if ( $replacements ) {
								$attrArray					=	self::_substituteChildTexts( $attrArray );
							}
							foreach ( $attrArray as $attK => $attV ) {
								if ( $attTransform == 'raw' ) {
									$param->addAttribute( $attK, implode( $attSeparator, $attV ) );
								} else {
									$param->addAttribute( $attK, htmlspecialchars( implode( $attSeparator, $attV ) ) );
								}
							}
						}
					}
				}
			}
		}
		
	}