eZ Publish  [4.0]
ezinisettingtype.php
Go to the documentation of this file.
00001 <?php
00002 //
00003 // Definition of eZIniSettingType class
00004 //
00005 // Created on: <01-Oct-2002 11:18:14 kk>
00006 //
00007 // ## BEGIN COPYRIGHT, LICENSE AND WARRANTY NOTICE ##
00008 // SOFTWARE NAME: eZ Publish
00009 // SOFTWARE RELEASE: 4.0.x
00010 // COPYRIGHT NOTICE: Copyright (C) 1999-2008 eZ Systems AS
00011 // SOFTWARE LICENSE: GNU General Public License v2.0
00012 // NOTICE: >
00013 //   This program is free software; you can redistribute it and/or
00014 //   modify it under the terms of version 2.0  of the GNU General
00015 //   Public License as published by the Free Software Foundation.
00016 //
00017 //   This program is distributed in the hope that it will be useful,
00018 //   but WITHOUT ANY WARRANTY; without even the implied warranty of
00019 //   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00020 //   GNU General Public License for more details.
00021 //
00022 //   You should have received a copy of version 2.0 of the GNU General
00023 //   Public License along with this program; if not, write to the Free
00024 //   Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
00025 //   MA 02110-1301, USA.
00026 //
00027 //
00028 // ## END COPYRIGHT, LICENSE AND WARRANTY NOTICE ##
00029 //
00030 
00031 /*!
00032   \class eZIniSettingType ezinisettingtype.php
00033   \ingroup eZDatatype
00034   \brief A content datatype for setting ini file settings
00035 
00036   Enable editing and versioning of ini files from the admin interface
00037 */
00038 
00039 //include_once( 'kernel/classes/ezdatatype.php' );
00040 //include_once( 'lib/ezutils/classes/ezintegervalidator.php' );
00041 require_once( 'kernel/common/i18n.php' );
00042 
00043 class eZIniSettingType extends eZDataType
00044 {
00045     const DATA_TYPE_STRING = 'ezinisetting';
00046 
00047     const CLASS_TYPE = '_ezinisetting_type_';
00048     const CLASS_FILE = '_ezinisetting_file_';
00049     const CLASS_SECTION = '_ezinisetting_section_';
00050     const CLASS_PARAMETER = '_ezinisetting_parameter_';
00051     const CLASS_INI_INSTANCE = '_ezinisetting_ini_instance_';
00052 
00053     const CLASS_FILE_FIELD = 'data_text1';
00054     const CLASS_SECTION_FIELD = 'data_text2';
00055     const CLASS_PARAMETER_FIELD = 'data_text3';
00056     const CLASS_TYPE_FIELD = 'data_int1';
00057     const CLASS_INI_INSTANCE_FIELD = 'data_text4';
00058     const SITE_ACCESS_LIST_FIELD = 'data_text5';
00059 
00060     const CLASS_TYPE_ARRAY = 6;
00061 
00062     /*!
00063      Initializes with a string id and a description.
00064     */
00065     function eZIniSettingType()
00066     {
00067         $this->eZDataType( self::DATA_TYPE_STRING, ezi18n( 'kernel/classes/datatypes', 'Ini Setting', 'Datatype name' ),
00068                                                          array( 'translation_allowed' => false,
00069                                                                 'serialize_supported' => true ) );
00070     }
00071 
00072     /*!
00073       \reimp
00074     */
00075     function validateObjectAttributeHTTPInput( $http, $base, $contentObjectAttribute )
00076     {
00077         if ( $http->hasPostVariable( $base . '_ini_setting_' . $contentObjectAttribute->attribute( 'id' ) ) )
00078         {
00079             $contentClassAttribute = $contentObjectAttribute->attribute( 'contentclass_attribute' );
00080             $iniFile = eZIniSettingType::iniFile( $contentClassAttribute );
00081             $iniSection = eZIniSettingType::iniSection( $contentClassAttribute );
00082             $iniParameterName = eZIniSettingType::iniParameterName( $contentClassAttribute );
00083 
00084             $config = eZINI::instance( $iniFile );
00085             if ( $config == null )
00086             {
00087                 $contentObjectAttribute->setValidationError( ezi18n( 'kernel/classes/datatypes',
00088                                                                      'Could not locate the ini file.' ) );
00089                 return eZInputValidator::STATE_INVALID;
00090             }
00091 
00092             if ( $contentClassAttribute->attribute( self::CLASS_TYPE_FIELD ) == self::CLASS_TYPE_ARRAY )
00093             {
00094                 $iniArray = array();
00095    //             if ( eZIniSettingType::parseArrayInput( $contentObjectAttribute->attribute( 'data_text' ), $iniArray ) === false )
00096                 if ( eZIniSettingType::parseArrayInput( $http->postVariable( $base . '_ini_setting_' . $contentObjectAttribute->attribute( 'id' ) ), $iniArray ) === false )
00097                 {
00098                     $contentObjectAttribute->setValidationError( ezi18n( 'kernel/classes/datatypes', 'Wrong text field value.' ) );
00099 
00100                     return eZInputValidator::STATE_INVALID;
00101                 }
00102             }
00103         }
00104         return eZInputValidator::STATE_ACCEPTED;
00105     }
00106 
00107     /*!
00108      \reimp
00109     */
00110     function validateClassAttributeHTTPInput( $http, $base, $classAttribute )
00111     {
00112         $fileParam = $base . self::CLASS_FILE . $classAttribute->attribute( 'id' );
00113         $sectionParam = $base . self::CLASS_SECTION . $classAttribute->attribute( 'id' );
00114         $parameterParam = $base . self::CLASS_PARAMETER . $classAttribute->attribute( 'id' );
00115         $typeParam = $base . self::CLASS_TYPE . $classAttribute->attribute( 'id' );
00116         $iniInstanceParam = $base . self::CLASS_INI_INSTANCE . $classAttribute->attribute( 'id' );
00117 
00118         if ( $http->hasPostVariable( $fileParam ) &&
00119              $http->hasPostVariable( $sectionParam ) &&
00120              $http->hasPostVariable( $parameterParam ) &&
00121              $http->hasPostVariable( $typeParam ) &&
00122              $http->hasPostVariable( $iniInstanceParam ) )
00123         {
00124             $iniFile = $http->postVariable( $fileParam );
00125             $iniSection = $http->postVariable( $sectionParam );
00126 
00127             $config = eZINI::instance( $iniFile );
00128             if ( $config == null )
00129             {
00130                 return eZInputValidator::STATE_INVALID;
00131             }
00132 
00133             if ( !$config->hasGroup( $iniSection ) )
00134             {
00135                 return eZInputValidator::STATE_INVALID;
00136             }
00137             return eZInputValidator::STATE_ACCEPTED;
00138         }
00139 
00140         eZDebug::writeNotice( 'Could not validate parameters: ' . "\n" .
00141                               $fileParam . ': ' .  $http->postVariable( $fileParam ) . "\n" .
00142                               $sectionParam . ': ' .  $http->postVariable( $sectionParam ) . "\n" .
00143                               $parameterParam . ': ' .  $http->postVariable( $parameterParam ) . "\n" .
00144                               $typeParam . ': ' .  $http->postVariable( $typeParam ). "\n" .
00145                               $iniInstanceParam. ': '. $http->postVariable( $iniInstanceParam ), 'eZIniSettingType::validateClassAttributeHTTPInput',
00146                               'eZIniSettingType::validateClassAttributeHTTPInput' );
00147         return eZInputValidator::STATE_INVALID;
00148     }
00149 
00150     /*!
00151      \reimp
00152     */
00153     function initializeClassAttribute( $classAttribute )
00154     {
00155         eZIniSettingType::setSiteAccessList( $classAttribute );
00156     }
00157 
00158     /*!
00159      \reimp
00160     */
00161     function initializeObjectAttribute( $objectAttribute, $currentVersion, $originalContentObjectAttribute )
00162     {
00163         if ( $currentVersion != false )
00164         {
00165             $objectAttribute->setAttribute( 'data_text', $originalContentObjectAttribute->attribute( 'data_text' ) );
00166         }
00167         else
00168         {
00169             $contentClassAttribute = $objectAttribute->attribute( 'contentclass_attribute' );
00170             $iniInstanceArray = explode( ';', $contentClassAttribute->attribute( self::CLASS_INI_INSTANCE_FIELD ) );
00171             $siteAccessArray = explode( ';', $contentClassAttribute->attribute( self::SITE_ACCESS_LIST_FIELD ) );
00172             $filename = $contentClassAttribute->attribute( self::CLASS_FILE_FIELD );
00173             $section = $contentClassAttribute->attribute( self::CLASS_SECTION_FIELD );
00174             $parameter = $contentClassAttribute->attribute( self::CLASS_PARAMETER_FIELD );
00175 
00176             if ( ! in_array( 0, $iniInstanceArray ) )  /* Makes sure it check 'settings' and 'settings/override' last */
00177                 array_unshift( $iniInstanceArray,  0 );
00178             array_unshift( $iniInstanceArray, -1 );
00179 
00180             $configArray = array();
00181 
00182             foreach ( $iniInstanceArray as $iniInstance )
00183             {
00184                 if ( $iniInstance == -1 )
00185                     $path = 'settings';
00186                 else if ( $iniInstance == 0 )
00187                     $path = 'settings/override';
00188                 else
00189                     $path = 'settings/siteaccess/' . $siteAccessArray[$iniInstance];
00190 
00191                 if ( !eZINI::parameterSet( $filename, $path, $section, $parameter ) )
00192                     continue;
00193 
00194                 $config = eZINI::instance( $filename, $path, null, null, null, true );
00195 
00196                 $configValue = $config->variable( $section, $parameter );
00197 
00198                 if ( is_array( $configValue ) )
00199                 {
00200                     foreach ( array_keys( $configValue ) as $key )
00201                     {
00202                         $configArray[$key] = $configValue[$key];
00203                     }
00204                 }
00205                 else
00206                 {
00207                     $objectAttribute->setAttribute( 'data_text', $configValue );
00208                     eZDebug::writeNotice( 'Loaded following values from ' . $path . '/' . $filename . ":\n" .
00209                                           '    ' . $configValue,
00210                                           'eZIniSettingType::initializeObjectAttribute');
00211                 }
00212             }
00213 
00214             if ( count( $configArray ) > 0 )
00215             {
00216                 $data = '';
00217                 foreach( array_keys( $configArray ) as $key )
00218                 {
00219                     if ( is_int( $key ) )
00220                     {
00221                         $data .= '=' . $configArray[$key] . "\n" ;
00222                     }
00223                     else
00224                     {
00225                         $data .= $key . '=' . $configArray[$key] . "\n" ;
00226                     }
00227                 }
00228                 $objectAttribute->setAttribute( 'data_text', $data );
00229             }
00230         }
00231     }
00232 
00233     /*!
00234      \reimp
00235     */
00236     function fetchClassAttributeHTTPInput( $http, $base, $classAttribute )
00237     {
00238         $fileParam = $base . self::CLASS_FILE . $classAttribute->attribute( 'id' );
00239         $sectionParam = $base . self::CLASS_SECTION . $classAttribute->attribute( 'id' );
00240         $paramParam = $base . self::CLASS_PARAMETER . $classAttribute->attribute( 'id' );
00241         $typeParam = $base . self::CLASS_TYPE . $classAttribute->attribute( 'id' );
00242         $iniInstanceParam = $base . self::CLASS_INI_INSTANCE . $classAttribute->attribute( 'id' );
00243 
00244         if ( $http->hasPostVariable( $fileParam ) &&
00245              $http->hasPostVariable( $sectionParam ) &&
00246              $http->hasPostVariable( $paramParam ) &&
00247              $http->hasPostVariable( $typeParam ) &&
00248              $http->hasPostVariable( $iniInstanceParam ) )
00249         {
00250             $file = $http->postVariable( $fileParam );
00251             $section = $http->postVariable( $sectionParam );
00252             $parameter = $http->postVariable( $paramParam );
00253             $type = $http->postVariable( $typeParam );
00254 
00255             $iniInstanceArray = $http->postVariable( $iniInstanceParam );
00256             if ( is_array( $iniInstanceArray ) )
00257             {
00258                 $iniInstance = '';
00259                 foreach ( $iniInstanceArray as $idx => $instance )
00260                 {
00261                     if ( $idx > 0 )
00262                         $iniInstance .= ';';
00263                     $iniInstance .= $instance;
00264                 }
00265             }
00266             else
00267             {
00268                 $iniInstance = $iniInstanceArray;
00269             }
00270 
00271             eZIniSettingType::setSiteAccessList( $classAttribute );
00272             $classAttribute->setAttribute( self::CLASS_FILE_FIELD, $file );
00273             $classAttribute->setAttribute( self::CLASS_SECTION_FIELD, $section );
00274             $classAttribute->setAttribute( self::CLASS_PARAMETER_FIELD, $parameter );
00275             $classAttribute->setAttribute( self::CLASS_TYPE_FIELD, $type );
00276             $classAttribute->setAttribute( self::CLASS_INI_INSTANCE_FIELD, $iniInstance );
00277 
00278             return true;
00279         }
00280         return false;
00281     }
00282 
00283     /*!
00284       \reimp
00285     */
00286     function fetchObjectAttributeHTTPInput( $http, $base, $contentObjectAttribute )
00287     {
00288         if ( $http->hasPostVariable( $base . '_ini_setting_' . $contentObjectAttribute->attribute( "id" ) ) )
00289         {
00290             $data = $http->postVariable( $base . '_ini_setting_' . $contentObjectAttribute->attribute( "id" ) );
00291             $contentObjectAttribute->setAttribute( 'data_text', trim( $data ) );
00292             if ( $http->hasPostVariable( $base . '_ini_setting_make_empty_array_' . $contentObjectAttribute->attribute( "id" ) ) )
00293             {
00294                 $isChecked = $http->postVariable( $base . '_ini_setting_make_empty_array_' . $contentObjectAttribute->attribute( "id" ) );
00295                 if ( isset( $isChecked ) )
00296                     $isChecked = 1;
00297                 $contentObjectAttribute->setAttribute( 'data_int', $isChecked );
00298             }
00299             else
00300             {
00301                 $contentObjectAttribute->setAttribute( 'data_int', 0 );
00302             }
00303             return true;
00304         }
00305         return false;
00306     }
00307 
00308     /*!
00309      \reimp
00310     */
00311     function onPublish( $contentObjectAttribute, $contentObject, $publishedNodes )
00312     {
00313         $contentClassAttribute = $contentObjectAttribute->attribute( 'contentclass_attribute' );
00314         $section = $contentClassAttribute->attribute( self::CLASS_SECTION_FIELD );
00315         $parameter = $contentClassAttribute->attribute( self::CLASS_PARAMETER_FIELD );
00316         $iniInstanceArray = explode( ';', $contentClassAttribute->attribute( self::CLASS_INI_INSTANCE_FIELD ) );
00317         $siteAccessArray = explode( ';', $contentClassAttribute->attribute( self::SITE_ACCESS_LIST_FIELD ) );
00318         $filename = $contentClassAttribute->attribute( self::CLASS_FILE_FIELD );
00319         $makeEmptyArray = $contentObjectAttribute->attribute( 'data_int' );
00320 
00321         foreach ( $iniInstanceArray as $iniInstance )
00322         {
00323             if ( $iniInstance == 0 )
00324                 $path = 'settings/override';
00325             else
00326                 $path = 'settings/siteaccess/' . $siteAccessArray[$iniInstance];
00327 
00328             $config = eZINI::instance( $filename . '.append', $path, null, false, null, true, true );
00329 
00330             if ( $config == null )
00331             {
00332                 eZDebug::writeError( 'Could not open ' . $path . '/' . $filename );
00333                 continue;
00334             }
00335             if ( $contentClassAttribute->attribute( self::CLASS_TYPE_FIELD ) == self::CLASS_TYPE_ARRAY )
00336             {
00337                 if ( $contentObjectAttribute->attribute( 'data_text' ) != null )
00338                 {
00339                     $iniArray = array();
00340                     eZIniSettingType::parseArrayInput( $contentObjectAttribute->attribute( 'data_text' ), $iniArray, $makeEmptyArray );
00341                     $config->setVariable( $section, $parameter, $iniArray );
00342                 }
00343                 else
00344                 {
00345                     $config->removeSetting( $section, $parameter );
00346                 }
00347             }
00348             else
00349             {
00350                 $config->setVariable( $section, $parameter, $contentObjectAttribute->attribute( 'data_text' ) );
00351                 eZDebug::writeNotice( 'Saved ini settings to file: ' . $path . '/' . $filename . "\n" .
00352                                       '                            ['. $section . ']' . "\n" .
00353                                       '                            ' . $parameter . '=' . $contentObjectAttribute->attribute( 'data_text' ),
00354                                       'eZIniSettingType::onPublish' );
00355             }
00356             $config->save();
00357         }
00358     }
00359 
00360     /*!
00361      \private
00362      Parse array input text into array with korrect keys.
00363 
00364      \param input text
00365      \param array to store parsed file to
00366 
00367      \return true if parsed successfully, false if illegal syntax
00368     */
00369     function parseArrayInput( $inputText, &$outputArray, $makeEmptyArray = false )
00370     {
00371         $lineArray = explode( "\n", $inputText );
00372 
00373         if( $makeEmptyArray )
00374         {
00375             $outputArray[] = "";
00376         }
00377 
00378         foreach ( array_keys( $lineArray ) as $key )
00379         {
00380             $line = str_replace( "\r", '', $lineArray[$key] );
00381 
00382             if ( strlen( $line ) <= 2 )
00383                 continue;
00384 
00385             if ( strstr( $line, '=' ) === false )
00386                 return false;
00387 
00388             $lineElements = explode( '=', $line );
00389             if ( count( $lineElements ) == 1 )
00390             {
00391                 $outputArray[] = $lineElements[0];
00392             }
00393             else
00394             {
00395                 if ( $lineElements[0] != '' )
00396                 {
00397                     $outputArray[ $lineElements[0] ] = implode( '=', array_slice( $lineElements, 1 ) );
00398                 }
00399                 else
00400                     $outputArray[] = implode( '=', array_slice( $lineElements, 1 ) );
00401             }
00402         }
00403         return true;
00404     }
00405 
00406     /*!
00407      \reimp
00408     */
00409     function objectAttributeContent( $contentObjectAttribute )
00410     {
00411         $contentClassAttribute = $contentObjectAttribute->attribute( 'contentclass_attribute' );
00412         $section = $contentClassAttribute->attribute( self::CLASS_SECTION_FIELD );
00413         $parameter = $contentClassAttribute->attribute( self::CLASS_PARAMETER_FIELD );
00414 
00415         $iniInstanceArray = explode( ';', $contentClassAttribute->attribute( self::CLASS_INI_INSTANCE_FIELD ) );
00416         $siteAccessArray = explode( ';', $contentClassAttribute->attribute( self::SITE_ACCESS_LIST_FIELD ) );
00417         $filename = $contentClassAttribute->attribute( self::CLASS_FILE_FIELD );
00418 
00419         $modified = array();
00420 
00421         $contentObject = $contentObjectAttribute->attribute( 'object' );
00422         foreach ( $iniInstanceArray as $iniInstance )
00423         {
00424             if ( $iniInstance == 0 )
00425                 $path = 'settings/override';
00426             else
00427                 $path = 'settings/siteaccess/' . $siteAccessArray[$iniInstance];
00428 
00429             if ( !eZINI::parameterSet( $filename, $path, $section, $parameter ) )
00430                 continue;
00431 
00432             $config = eZINI::instance( $filename, $path, null, null, null, true );
00433 
00434             if ( is_array( $config->variable( $section, $parameter ) ) )
00435             {
00436                 $objectIniArray = array();
00437                 eZIniSettingType::parseArrayInput( $contentObjectAttribute->attribute( 'data_text' ), $objectIniArray );
00438                 $existingIniArray = $config->variable( $section, $parameter );
00439                 foreach ( array_keys( $existingIniArray ) as $key )
00440                 {
00441                     if ( !is_int( $key ) && $existingIniArray[$key] != $objectIniArray[$key] )
00442                     {
00443                         $modified[] = array( 'ini_value' => $parameter . '[' . $key . ']=' . $existingIniArray[$key],
00444                                              'file' => $path . '/' . $filename );
00445                     }
00446                 }
00447             }
00448             else if ( $config->variable( $section, $parameter ) != $contentObjectAttribute->attribute( 'data_text' ) )
00449             {
00450                 $modified[] = array( 'ini_value' => $parameter . '=' . $config->variable( $section, $parameter ),
00451                                      'file' => $path . '/' . $filename );
00452             }
00453         }
00454 
00455         $data = array( 'data' => $contentObjectAttribute->attribute( 'data_text' ),
00456                        'modified' => $modified );
00457         return $data;
00458     }
00459 
00460     /*!
00461       \reimp
00462     */
00463     function title( $contentObjectAttribute, $name = null )
00464     {
00465         return $contentObjectAttribute->attribute( 'data_text' );
00466     }
00467 
00468     function hasObjectAttributeContent( $contentObjectAttribute )
00469     {
00470         return true;
00471     }
00472 
00473     /*!
00474      \reimp
00475     */
00476     function serializeContentClassAttribute( $classAttribute, $attributeNode, $attributeParametersNode )
00477     {
00478         $file = $classAttribute->attribute( self::CLASS_FILE_FIELD );
00479         $section = $classAttribute->attribute( self::CLASS_SECTION_FIELD );
00480         $parameter = $classAttribute->attribute( self::CLASS_PARAMETER_FIELD );
00481         $type = $classAttribute->attribute( self::CLASS_TYPE_FIELD );
00482         $iniInstance = $classAttribute->attribute( self::CLASS_INI_INSTANCE_FIELD );
00483         $siteAccess = $classAttribute->attribute( self::SITE_ACCESS_LIST_FIELD );
00484 
00485         $dom = $attributeParametersNode->ownerDocument;
00486         $fileNode = $dom->createElement( 'file' );
00487         $fileNode->appendChild( $dom->createTextNode( $file ) );
00488         $attributeParametersNode->appendChild( $fileNode );
00489         $sectionNode = $dom->createElement( 'section' );
00490         $sectionNode->appendChild( $dom->createTextNode( $section ) );
00491         $attributeParametersNode->appendChild( $sectionNode );
00492         $parameterNode = $dom->createElement( 'parameter' );
00493         $parameterNode->appendChild( $dom->createTextNode( $parameter ) );
00494         $attributeParametersNode->appendChild( $parameterNode );
00495         $typeNode = $dom->createElement( 'type' );
00496         $typeNode->appendChild( $dom->createTextNode( $type ) );
00497         $attributeParametersNode->appendChild( $typeNode );
00498         $iniInstanceNode = $dom->createElement( 'ini_instance' );
00499         $iniInstanceNode->appendChild( $dom->createTextNode( $iniInstance ) );
00500         $attributeParametersNode->appendChild( $iniInstanceNode );
00501         $siteAccessListNode = $dom->createElement( 'site_access_list' );
00502         $siteAccessListNode->appendChild( $dom->createTextNode( $siteAccess ) );
00503         $attributeParametersNode->appendChild( $siteAccessListNode );
00504     }
00505 
00506     /*!
00507      \reimp
00508 
00509      Use Override to do ini alterations if the specified site access does not exist
00510     */
00511     function unserializeContentClassAttribute( $classAttribute, $attributeNode, $attributeParametersNode )
00512     {
00513         $file = $attributeParametersNode->getElementsByTagName( 'file' )->item( 0 )->textContent;
00514         $section = $attributeParametersNode->getElementsByTagName( 'section' )->item( 0 )->textContent;
00515         $parameter = $attributeParametersNode->getElementsByTagName( 'parameter' )->item( 0 )->textContent;
00516         $type = $attributeParametersNode->getElementsByTagName( 'type' )->item( 0 )->textContent;
00517 
00518         $classAttribute->setAttribute( self::CLASS_FILE_FIELD, $file );
00519         $classAttribute->setAttribute( self::CLASS_SECTION_FIELD, $section );
00520         $classAttribute->setAttribute( self::CLASS_PARAMETER_FIELD, $parameter );
00521         $classAttribute->setAttribute( self::CLASS_TYPE_FIELD, $type );
00522 
00523 
00524         /* Get and check if site access settings exist in this setup */
00525         $remoteIniInstanceList = $attributeParametersNode->getElementsByTagName( 'ini_instance' )->item( 0 )->textContent;
00526         $remoteSiteAccessList = $attributeParametersNode->getElementsByTagName( 'site_access_list' )->item( 0 )->textContent;
00527         $remoteIniInstanceArray = explode( ';', $remoteIniInstanceList );
00528         $remoteSiteAccessArray = explode( ';', $remoteSiteAccessList );
00529 
00530         $config = eZINI::instance( 'site.ini' );
00531         $localSiteAccessArray = array_merge( array( 'override' ), $config->variable( 'SiteAccessSettings', 'AvailableSiteAccessList' ) );
00532 
00533         $localIniInstanceArray = array();
00534         foreach ( $remoteIniInstanceArray as $remoteIniInstance )
00535         {
00536             if ( isset( $remoteSiteAccessArray[$remoteIniInstance] ) and in_array( $remoteSiteAccessArray[$remoteIniInstance], $localSiteAccessArray ) )
00537             {
00538                 $localSiteAccessArray[] = array_keys( $localSiteAccessArray, $remoteSiteAccessArray[$remoteIniInstance] );
00539             }
00540         }
00541 
00542         if ( count( $localSiteAccessArray ) == 0 )
00543         {
00544             $localIniInstanceArray = array( 0 );
00545         }
00546 
00547         $iniInstance = '';
00548         foreach( $localIniInstanceArray as $idx => $localIniInstance )
00549         {
00550             if ( $idx > 0 )
00551                 $iniInstance .= ';';
00552             $iniInstance .= $localIniInstance;
00553         }
00554 
00555         $siteAccess = '';
00556         foreach( $localSiteAccessArray as $idx => $localSiteAccess )
00557         {
00558             if ( $idx > 0 )
00559                 $siteAccess .= ';';
00560             $siteAccess .= $localSiteAccess;
00561         }
00562 
00563         $classAttribute->setAttribute( self::CLASS_INI_INSTANCE_FIELD, $iniInstance );
00564         $classAttribute->setAttribute( self::SITE_ACCESS_LIST_FIELD, $siteAccess );
00565     }
00566 
00567 
00568     /*!
00569      \private
00570      Get Ini section parameter name
00571 
00572      \param Content Class Attribute
00573     */
00574     function iniParameterName( $contentClassAttribute )
00575     {
00576         return $contentClassAttribute->attribute( self::CLASS_PARAMETER_FIELD );
00577     }
00578 
00579     /*!
00580      \private
00581      Get ini settings file
00582 
00583      \param Content Class Attribute
00584     */
00585     function iniFile( $contentClassAttribute )
00586     {
00587         return $contentClassAttribute->attribute( self::CLASS_FILE_FIELD );
00588     }
00589 
00590     /*!
00591      \private
00592      Get Ini file section name
00593 
00594      \param Content Class Attribute
00595     */
00596     function iniSection( $contentClassAttribute )
00597     {
00598         return $contentClassAttribute->attribute( self::CLASS_SECTION_FIELD );
00599     }
00600 
00601     /*!
00602      \private
00603      \static
00604      Set site access list, including override option
00605 
00606      \param contentClassAttribute to set site access list and override options
00607     */
00608     function setSiteAccessList( $contentClassAttribute )
00609     {
00610         $config = eZINI::instance( 'site.ini' );
00611         $siteAccessArray = $config->variable( 'SiteAccessSettings', 'AvailableSiteAccessList' );
00612         $siteAccessList = 'override';
00613         foreach ( $siteAccessArray as $idx => $siteAccess )
00614         {
00615             $siteAccessList .= ';' . $siteAccess;
00616         }
00617 
00618         $contentClassAttribute->setAttribute( self::SITE_ACCESS_LIST_FIELD, $siteAccessList );
00619     }
00620 
00621     function toString( $contentObjectAttribute )
00622     {
00623         $makeEmptyArray = $contentObjectAttribute->attribute( 'data_int' );
00624         $value = $contentObjectAttribute->attribute( 'data_text' );
00625         return implode( '|', array( $value, $makeEmptyArray ) );
00626     }
00627 
00628 
00629     function fromString( $contentObjectAttribute, $string )
00630     {
00631         if ( $string == '' )
00632             return true;
00633         $iniData = explode( '|', $string );
00634 
00635         $contentObjectAttribute->setAttribute( 'data_text', $iniData[0] );
00636         if ( isset ( $iniData[1] ) )
00637             $contentObjectAttribute->setAttribute( 'data_int', $iniData[1] );
00638         return true;
00639     }
00640 
00641     /*!
00642      \reimp
00643     */
00644     function serializeContentObjectAttribute( $package, $objectAttribute )
00645     {
00646         $node = $this->createContentObjectAttributeDOMNode( $objectAttribute );
00647         $makeEmptyArray = $objectAttribute->attribute( 'data_int' );
00648         $value = $objectAttribute->attribute( 'data_text' );
00649 
00650         $dom = $node->ownerDocument;
00651 
00652         $makeEmptyArrayNode = $dom->createElement( 'make_empty_array' );
00653         $makeEmptyArrayNode->appendChild( $dom->createTextNode( $makeEmptyArray ) );
00654         $node->appendChild( $makeEmptyArrayNode );
00655         $valueNode = $dom->createElement( 'value' );
00656         $valueNode->appendChild( $dom->createTextNode( $value ) );
00657         $node->appendChild( $valueNode );
00658 
00659         return $node;
00660     }
00661 
00662     /*!
00663      \reimp
00664     */
00665     function unserializeContentObjectAttribute( $package, $objectAttribute, $attributeNode )
00666     {
00667         $makeEmptyArray = $attributeNode->getElementsByTagName( 'make_empty_array' )->item( 0 )->textContent;
00668         $value = $attributeNode->getElementsByTagName( 'value' )->item( 0 )->textContent;
00669 
00670         if ( $makeEmptyArray === false )
00671             $makeEmptyArray = 0;
00672 
00673         if ( $value === false )
00674             $value = '';
00675 
00676         $objectAttribute->setAttribute( 'data_int', $makeEmptyArray );
00677         $objectAttribute->setAttribute( 'data_text', $value );
00678     }
00679 
00680     /*!
00681       \reimp
00682     */
00683     function diff( $old, $new, $options = false )
00684     {
00685         return null;
00686     }
00687 }
00688 
00689 eZDataType::register( eZIniSettingType::DATA_TYPE_STRING, 'eZIniSettingType' );
00690 
00691 ?>