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