Attributes function.

Logic to apply styles to tags.

@param string $rType rType
@param array $elementData Element data
@param bool $clear Clear
@return string
185091
protected function _attributes($rType, array $elementData = [], $clear = true) {
		extract($this->_config);
		if ($rType === $type) {
			$attributes = $this->_typeAttributes;
			if ($clear) {
				$this->_typeAttributes = $this->_typeAttributesNext;
				$this->_typeAttributesNext = [];
			}
		} else {
			$attributes = $this->_itemAttributes;
			$this->_itemAttributes = [];
			if ($clear) {
				$this->_itemAttributes = [];
			}
		}
		if ($rType === $itemType && $elementData['activePathElement']) {
			if ($elementData['activePathElement'] === true) {
				$attributes['class'][] = $autoPath[2];
			} else {
				$attributes['class'][] = $elementData['activePathElement'];
			}
		}
		if (!$attributes) {
			return '';
		}
		foreach ($attributes as $type => $values) {
			foreach ($values as $key => $val) {
				if (is_array($val)) {
					$attributes[$type][$key] = '';
					foreach ($val as $vKey => $v) {
						$attributes[$type][$key][$vKey] .= $vKey . ':' . $v;
					}
					$attributes[$type][$key] = implode(';', $attributes[$type][$key]);
				}
				if (is_string($key)) {
					$attributes[$type][$key] = $key . ':' . $val . ';';
				}
			}
			$attributes[$type] = $type . '="' . implode(' ', $attributes[$type]) . '"';
		}

		return ' ' . implode(' ', $attributes);
	}
225216
private static function clearAttributes(array $attributes, array $clear): array
    {
        foreach ($clear as $name) {
            if ($name === 'ALL') {
                return [];
            }
            if (\array_key_exists($name, $attributes)) {
                unset($attributes[$name]);
            }
        }
        return $attributes;
    }
1365712
public function emvcRenderHtml(string $latteFile, array $data): string
    {
        $latte = new Engine();
        $latte->setTempDirectory($_SERVER['DOCUMENT_ROOT'] . BASE_URL . '/tmp/latte');
        return $latte->renderToString($_SERVER['DOCUMENT_ROOT'] . BASE_URL . '/private/latte/' . $latteFile, $data);
    }
939143
function createOriginalAttributeXMLData( $originalNode, $originalData )
    {
        $originalNode->setAttribute( 'attribute_id', $originalData['attribute_id'] );
        $originalNode->setAttribute( 'attribute_version', $originalData['attribute_version'] );
        $originalNode->setAttribute( 'attribute_language', $originalData['attribute_language'] );
    }
329615
static function decodeDataTypes( $node, $type = "" )
    {
        $returnValue = false;

        $attributeValue = '';
        $attribute = $node->getAttributeNodeNS( eZSOAPEnvelope::SCHEMA_INSTANCE, 'type' );
        if ( !$attribute )
        {
            $attribute = $node->getAttributeNodeNS( 'http://www.w3.org/1999/XMLSchema-instance', 'type' );
        }
        $attributeValue = $attribute->value;

        $dataType = $type;
        $attrParts = explode( ":", $attributeValue );
        if ( $attrParts[1] )
        {
            $dataType = $attrParts[1];
        }

/*
        $typeNamespacePrefix = $this->DOMDocument->namespaceByAlias( $attrParts[0] );

        check that this is a namespace type definition
                if ( ( $typeNamespacePrefix == eZSOAPEnvelope::SCHEMA_DATA ) ||
                     ( $typeNamespacePrefix == eZSOAPEnvelope::ENC )
                     )
TODO: add encoding checks with schema validation.
*/

        switch ( $dataType )
        {
            case "string" :
            case "int" :
            case "float" :
            case 'double' :
            {
                $returnValue = $node->textContent;
            } break;

            case "boolean" :
            {
                if ( $node->textContent == "true" )
                    $returnValue = true;
                else
                    $returnValue = false;
            } break;

            case "base64" :
            {
                $returnValue = base64_decode( $node->textContent );
            } break;

            case "Array" :
            {
                // Get array type
                $arrayType = $node->getAttributeNodeNS( eZSOAPEnvelope::ENC, 'arrayType' )->value;
                $arrayTypeParts = explode( ":", $arrayType );

                preg_match( "#(.*)\[(.*)\]#",  $arrayTypeParts[1], $matches );

                $type = $matches[1];
                $count = $matches[2];

                $returnValue = array();
                foreach( $node->childNodes as $child )
                {
                    if ( $child instanceof DOMElement )
                    {
                        $returnValue[] = eZSOAPResponse::decodeDataTypes( $child, $type );
                    }
                }
            }break;

            case "SOAPStruct" :
            {
                $returnValue = array();

                foreach( $node->childNodes as $child )
                {
                    if ( $child instanceof DOMElement )
                    {
                        $returnValue[$child->tagName] = eZSOAPResponse::decodeDataTypes( $child );
                    }
                }
            }break;

            default:
            {
                foreach ( $node->childNodes as $childNode )
                {
                    if ( $childNode instanceof DOMElement )
                    {
                        // check data type for child
                        $attr = $childNode->getAttributeNodeNS( eZSOAPEnvelope::SCHEMA_INSTANCE, 'type' )->value;

                        $dataType = false;
                        $attrParts = explode( ":", $attr );
                        $dataType = $attrParts[1];

                        $returnValue[$childNode->tagName] = eZSOAPResponse::decodeDataTypes( $childNode );
                    }
                }

            } break;
        }

        return $returnValue;
    }
617200
public function getTag($tagUid, $clearText = false)
    {
        $queryBuilder = Db::getQueryBuilder('tx_kesearch_index');

        $table = 'tx_kesearch_filteroptions';
        $where = $queryBuilder->expr()->eq(
            'uid',
            $queryBuilder->quote($tagUid, \PDO::PARAM_INT)
        );

        $row = $queryBuilder
            ->select('title', 'tag')
            ->from($table)
            ->where($where)
            ->execute()
            ->fetch();

        if ($clearText) {
            return $row['title'];
        } else {
            return $row['tag'];
        }
    }
788014
public function attributes()
	{
		if (!is_array($this->attrs)) {
			return '';
		}

		$s = '';
		$attrs = $this->attrs;

		foreach ($attrs as $key => $value) {
			if ($value === NULL || $value === FALSE) {
				continue;

			} elseif ($value === TRUE) {
				if (static::$xhtml) {
					$s .= ' ' . $key . '="' . $key . '"';
				} else {
					$s .= ' ' . $key;
				}
				continue;

			} elseif (is_array($value)) {
				if (strncmp($key, 'data-', 5) === 0) {
					$value = json_encode($value);

				} else {
					$tmp = NULL;
					foreach ($value as $k => $v) {
						if ($v != NULL) { // intentionally ==, skip NULLs & empty string
							//  composite 'style' vs. 'others'
							$tmp[] = $v === TRUE ? $k : (is_string($k) ? $k . ':' . $v : $v);
						}
					}
					if ($tmp === NULL) {
						continue;
					}

					$value = implode($key === 'style' || !strncmp($key, 'on', 2) ? ';' : ' ', $tmp);
				}

			} elseif (is_float($value)) {
				$value = rtrim(rtrim(number_format($value, 10, '.', ''), '0'), '.');

			} else {
				$value = (string)$value;
			}

			$q = strpos($value, '"') === FALSE ? '"' : "'";
			$s .= ' ' . $key . '=' . $q
				. str_replace(
					['&', $q, '<'],
					['&amp;', $q === '"' ? '&quot;' : '&#39;', self::$xhtml ? '&lt;' : '<'],
					$value
				)
				. (strpos($value, '`') !== FALSE && strpbrk($value, ' <>"\'') === FALSE ? ' ' : '')
				. $q;
		}

		$s = str_replace('@', '&#64;', $s);

		return $s;
	}
708922
public function attributesForModal()
    {
        // Remove some specific attributes.  Leaving empties in there so the updating
        // of values to NULL is displayed.
        $attributes = array_except($this->changed, [
            'id', 'updated_at', 'created_at', 'password', 'remember_token',
        ]);

        // Make more readable titles
        $out = [];
        foreach ($attributes as $key => $val) {
            $out[Text::titleFromKey($key)] = $val;
        }

        return $out;
    }
679826
public function MoodleQuickForm_wikifiletable($elementName = null, $elementLabel = null, $attributes = null, $fileinfo = null, $format = null) {
        debugging('Use of class name as constructor is deprecated', DEBUG_DEVELOPER);
        self::__construct($elementName, $elementLabel, $attributes, $fileinfo, $format);
    }
1086702
function createDifferenceObject( $fromData, $toData )
    {
        $changes = new eZXMLTextDiff();
        $contentINI = eZINI::instance( 'content.ini' );
        $useSimplifiedXML = $contentINI->variable( 'ContentVersionDiffSettings', 'UseSimplifiedXML' );
        $diffSimplifiedXML = ( $useSimplifiedXML == 'enabled' );

        $oldXMLTextObject = $fromData->content();
        $newXMLTextObject = $toData->content();

        $oldXML = $oldXMLTextObject->attribute( 'xml_data' );
        $newXML = $newXMLTextObject->attribute( 'xml_data' );

        $simplifiedXML = new eZSimplifiedXMLEditOutput();

        $domOld = new DOMDocument( '1.0', 'utf-8' );
        $domOld->preserveWhiteSpace = false;
        $domOld->loadXML( $oldXML );

        $domNew = new DOMDocument( '1.0', 'utf-8' );
        $domNew->preserveWhiteSpace = false;
        $domNew->loadXML( $newXML );

        $old = $simplifiedXML->performOutput( $domOld );
        $new = $simplifiedXML->performOutput( $domNew );

        if ( !$diffSimplifiedXML )
        {
            $old = trim( strip_tags( $old ) );
            $new = trim( strip_tags( $new ) );

            $pattern = array( '/[ ][ ]+/',
                              '/ \n( \n)+/',
                              '/^ /m',
                              '/(\n){3,}/' );
            $replace = array( ' ',
                              "\n",
                              '',
                              "\n\n" );

            $old = preg_replace( $pattern, $replace, $old );
            $new = preg_replace( $pattern, $replace, $new );
        }

        $oldArray = explode( "\n", $old );
        $newArray = explode( "\n", $new );

        $oldSums = array();
        foreach( $oldArray as $paragraph )
        {
            $oldSums[] = crc32( $paragraph );
        }

        $newSums = array();
        foreach( $newArray as $paragraph )
        {
            $newSums[] = crc32( $paragraph );
        }

        $textDiffer = new eZDiffTextEngine();

        $pre = $textDiffer->preProcess( $oldSums, $newSums );
        $out = $textDiffer->createOutput( $pre, $oldArray, $newArray );
        $changes->setChanges( $out );
        return $changes;
    }
672305
public function update(array $cleanData, $isInit = false)
    {
        if ($isInit) {
            $attrs = $this->getAttrs();
            foreach ($cleanData as $key => $value) {
                if (($value instanceof Model) && isset($attrs[$key]) && isset($attrs[$key]['type'])
                    && ( $attrs[$key]['type'] == self::DATA_TYPE_REFERENCE || $attrs[$key]['type'] == self::DATA_TYPE_REFERENCES )
                ) {
                    $value = $this->setRef($key, $value);
                }
                $this->cleanData[$key] = $value;
            }
        } else {
            foreach ($cleanData as $key => $value) {
                $this->$key = $value;
            }
        }

        return true;
    }
238998
public function field( $type, array $attributes = array(), $contents = null )
    {
        $_html = null;
        $_type = strtolower( trim( $type ) );
        $_wrapInput = Scalar::in( $_type, 'checkbox', 'radio' );
        $_labelEnd = null;
        $_labelAttributes = array();
        $_id = Option::get( $attributes, 'id', Option::get( $attributes, 'name' ) );
        $_inputAppend = Option::get( $attributes, 'append', null, true );
        $_inputPrepend = Option::get( $attributes, 'prepend', null, true );

        $this->cleanNames( $attributes );

        $_label = Option::get( $attributes, 'label', null, true );

        if ( is_array( $_label ) )
        {
            $_labelAttributes = Option::get( $_label, 'attributes', array() );
            $_labelText = Option::get( $_label, 'value', array() );
        }
        else
        {
            $_labelText = $_label;
        }

        //	Add .control-label for the class to labels
        if ( static::Horizontal == $this->_formType )
        {
            if ( !isset( $_labelAttributes['class'] ) )
            {
                $_labelAttributes['class'] = null;
            }

            $_labelAttributes['class'] = static::addValue( $_labelAttributes['class'], ( $_wrapInput ? $_type : 'control-label' ) );
        }

        $_label = static::tag( 'label', $_labelAttributes, ( $_wrapInput ? null : $_labelText ), !$_wrapInput );
        $_labelEnd = ( $_wrapInput ? $_label . '</label>' : null );

        if ( null !== ( $_hint = Option::get( $attributes, 'hint', null, true ) ) )
        {
            $_hint = static::tag( 'span', array('class' => 'help-block'), $_hint );
        }

        $_blockStart = $_blockEnd = null;
        $_inputStart = $_inputEnd = null;
        $_inputWrap = trim( ( $_inputAppend ? 'input-append' : null ) . ' ' . ( $_inputPrepend ? 'input-prepend' : null ) );

        switch ( $this->_formType )
        {
            case static::Horizontal:

                $_blockStart = static::tag( 'div', array('class' => 'control-group'), null, false );
                $_inputStart = static::tag( 'div', array('class' => 'controls'), null, false );
                $_inputEnd = $_blockEnd = '</div>';

                if ( !$_wrapInput )
                {
                    $_blockStart .= $_label . $_labelEnd;
                    $_label = $_labelEnd = null;
                }
                break;

            case static::Search:
                $_class = Option::get( $attributes, 'class' );
                $attributes['class'] = static::addValue( $_class, 'search-query' );
                break;
        }

        if ( null === $contents && !empty( $this->_formData ) )
        {
            $contents = Option::get( $this->_formData, $_id );
        }

        //	X-editable?
        if ( false !== stripos( Option::get( $attributes, 'class' ), 'x-editable' ) )
        {
            //	Replace contents with the x-editable link...
            $contents = static::tag(
                'a',
                array(
                    'class'               => 'x-editable',
                    'href'                => '#',
                    'id'                  => $_id,
                    'data-type'           => $_type,
                    'data-pk'             => Option::get( $this->_attributes, 'x-editable-pk', Option::get( $this->_formData, 'id' ) ),
                    'data-url'            => Option::get(
                        $this->_attributes,
                        'x-editable-url',
                        Option::get( $attributes, 'x-editable-url', null, true )
                    ),
                    'data-original-title' => $_labelText,
                    'data-inputclass'     => Option::get( $attributes, 'class', 'input-xlarge' ),
                ),
                $contents
            );

            //	New type of just HTML...
            $_type = 'html';
        }

        switch ( $_type )
        {
            case 'html':
                $_input = $contents;
                break;

            case 'textarea':
                $attributes['class'] = static::addValue( Option::get( $attributes, 'class' ), 'input-xxlarge' );

                $_input = static::wrap(
                    $_type,
                    $contents,
                    $attributes
                );
                break;

            case 'select':
                if ( !isset( $attributes['value'] ) )
                {
                    $attributes['value'] = $contents;
                }

                $_input = static::select(
                    Option::get( $attributes, 'data', array(), true ),
                    $attributes
                );
                break;

            case 'button':
                $_input = static::button( $attributes, $contents );
                break;

            default:
                $_input = $this->_handleUnknownField( $_type, $attributes, $contents );
                break;
        }

        if ( !empty( $_inputWrap ) )
        {
            $_input = '<div class="' . $_inputWrap . '">' . $_inputPrepend . $_input . $_inputAppend . '</div>';
        }

        $_html = <<<HTML
{$_blockStart}{$_inputStart}{$_label}{$_input}{$_labelEnd}{$_hint}{$_inputEnd}{$_blockEnd}
HTML;

        if ( false !== $this->_builderMode )
        {
            $this->_contents .= $_html;
        }

        return $_html;
    }
518719
protected function wordMatchSupport( $newTagName, $attributes, $attributeString )
    {
        $ini = eZINI::instance( 'wordmatch.ini' );
        if ( $ini->hasVariable( $newTagName, 'MatchString' ) )
        {
            $matchArray = $ini->variable( $newTagName, 'MatchString' );
            if ( $matchArray )
            {
                foreach ( array_keys( $matchArray ) as $key )
                {
                    $matchString = $matchArray[$key];
                    if (  preg_match( "/$matchString/i", $attributeString ) )
                    {
                        $attributes['class'] = $key;
                        unset( $attributes['style'] );
                    }
                }
            }
        }
        return $attributes;
    }
36744
public static function anchor(String $data, String $type = 'short', Array $attributes = NULL) : String
    {
        return preg_replace
        (
            '/(((https?|ftp)\:\/\/)(\w+\.)*(\w+)\.\w+\/*\S*)/xi',
            '<a href="$1"'.Singleton::class('ZN\Hypertext\Html')->attributes((array) $attributes).'>'.( $type === 'short' ? '$5' : '$1').'</a>',
            $data
        );
    }
438962
public static function script(
        string $content, 
        array $attributes = ["type" => "text/javascript"],
        bool $addCdataTag = true
    ) : string
    {
        if ($addCdataTag) {
            $content = "\n//<![CDATA[\n" . $content ."\n//]]>\n";
        }
        return self::tag("script", $content, $attributes);
    }
529603
public function HTML_QuickForm_image($elementName=null, $src='', $attributes=null) {
        debugging('Use of class name as constructor is deprecated', DEBUG_DEVELOPER);
        self::__construct($elementName, $src, $attributes);
    }
1046496
function attribute( $name )
    {
        switch ( $name )
        {
            case 'input_xml':
            {
                return $this->inputXML();
            } break;
            case 'edit_template_name':
            {
                return $this->editTemplateName();
            }break;
            case 'information_template_name':
            {
                return $this->informationTemplateName();
            }break;
            case 'aliased_type':
            {
                eZDebug::writeWarning( "'aliased_type' is deprecated as of 4.1 and not in use anymore, meaning it will always return false.", __METHOD__ );
                return $this->AliasedType;
            }break;
            case 'aliased_handler':
            {
                if ( $this->AliasedHandler === null )
                {
                    $this->AliasedHandler = eZXMLText::inputHandler( $this->XMLData,
                                                                     $this->AliasedType,
                                                                     false,
                                                                     $this->ContentObjectAttribute );
                }
                return $this->AliasedHandler;
            }break;
            default:
            {
                eZDebug::writeError( "Attribute '$name' does not exist", __METHOD__ );
                return null;
            }break;
        }
    }