Exemple #1
0
 static function path( $names, $includeEndSeparator = false, $type = self::SEPARATOR_UNIX )
 {
     $separator = eZDir::separator( $type );
     $path = implode( $separator, $names );
     $path = eZDir::cleanPath( $path, $type );
     $pathLen = strlen( $path );
     $hasEndSeparator = ( $pathLen > 0 and
                      $path[$pathLen - 1] == $separator );
     if ( $includeEndSeparator and
          !$hasEndSeparator )
         $path .= $separator;
     else if ( !$includeEndSeparator &&
               $hasEndSeparator &&
               $pathLen > 1 )
         $path = substr( $path, 0, $pathLen - 1 );
     return $path;
 }
    function execute( $xml )
    {
        $settingsFileList = $xml->getElementsByTagName( 'SettingsFile' );
        foreach ( $settingsFileList as $settingsFile )
        {
            $fileName = $settingsFile->getAttribute( 'name' );
            $location = $settingsFile->getAttribute( 'location' );

            eZDir::mkdir( $location );
            $fileNamePath = $location . eZDir::separator( eZDir::SEPARATOR_LOCAL ) . $fileName;

            $this->writeMessage( "\tSetting settings: $fileNamePath", 'notice' );

            if ( !file_exists( $fileNamePath ) )
            {
                if ( !is_writeable( $location ) )
                {
                    $this->writeMessage( "\tFile $fileNamePath can not be created. Skipping.", 'notice' );
                    continue;
                }
            }
            else
            {
                if ( !is_readable( $fileName ) )
                {
                    $this->writeMessage( "\tFile $fileNamePath is not readable. Skipping.", 'notice' );
                    continue;
                }
                if ( !is_writeable( $fileName ) )
                {
                    $this->writeMessage( "\tFile $fileNamePath is not writeable. Skipping.", 'notice' );
                    continue;
                }
            }
            $ini = eZINI::instance( $fileName, $location, null, null, null, true, true );
            $settingsBlockList = $settingsFile->getElementsByTagName( 'SettingsBlock' );
            foreach ( $settingsBlockList as $settingsBlock )
            {
                $blockName = $settingsBlock->getAttribute( 'name' );
                $values = $settingsBlock->childNodes;
                $settingValue = false;
                foreach ( $values as $value )
                {
                    $variableName = $value->nodeName;
                    if ( $value->nodeName == "#text" )
                    {
                        continue;
                    }

                    if ( get_class($value) == 'DOMElement' && $value->hasAttribute( 'value' ) )
                    {
                        $settingValue = $value->getAttribute( 'value' );
                    }
                    elseif ( get_class($value) == 'DOMElement' && $value->hasChildNodes() )
                    {
                        if ( $value->firstChild->nodeName == $value->lastChild->nodeName && $value->childNodes->length>1 )
                        {
                            $variableName = $value->tagName;
                            $vals = $value->getElementsByTagName( 'value' );
                            $settingValue = array();
                            foreach ( $vals as $val )
                            {
                                $key = $val->getAttribute( 'key' );
                                if ( $key )
                                {
                                    $settingValue[$key] = $this->parseAndReplaceStringReferences( $val->textContent );
                                }
                                else
                                {
                                    $settingValue[] = $this->parseAndReplaceStringReferences( $val->textContent );
                                }
                            }
                        }
                        else
                        {
                            $settingValue  = $this->parseAndReplaceStringReferences( $value->nodeValue );
                       }
                    }
                    elseif ( $value->textContent )
                    {
                        $settingValue = $value->textContent;
                    }
                    else
                    {
                        $settingValue = $this->parseAndReplaceStringReferences( $value->textContent );
                    }
                    $existingVar = false;
                    if ( $ini->hasVariable( $blockName, $variableName ) )
                    {
                        $existingVar = $ini->variable( $blockName, $variableName );
                    }
                    if ( is_string( $existingVar ) && is_string( $settingValue ) )
                    {
                        $ini->setVariable( $blockName, $variableName, $settingValue );
                    }
                    elseif ( is_array( $existingVar ) && is_string( $settingValue ) )
                    {
                        $existingVar[] = $settingValue;
                        $ini->setVariable( $blockName, $variableName, $existingVar );
                    }
                    elseif ( is_array( $existingVar ) && is_array( $settingValue ) )
                    {
                        // an empty value in a list means a reset of the setting
                        if ( array_search( "", $settingValue, true ) !== false )
                            $mergedArray = $settingValue;
                        else
                            $mergedArray = array_merge( $existingVar, $settingValue );
                        $ini->setVariable( $blockName, $variableName, array_unique( $mergedArray ) );
                    }
                    else
                    {
                        $ini->setVariable( $blockName, $variableName, $settingValue );
                    }
                }
            }
            $ini->save( false, ".append.php" );
            unset( $ini );
        }
        eZCache::clearByID( array( 'ini', 'global_ini' ) );
    }