Exponential Basic 2.4.0.1 Exponential Basic CMS — PHP Class Reference

ezini.php
Go to the documentation of this file.
1 <?php
45 class eZINI
46 {
52 const CONFIG_CACHE_DIR = 'var/cache/ini/';
53
59 const CONFIG_CACHE_REV = 2;
60
61
68 const INJECTED_PATH = 'injected';
69
78 static protected $checkFileMtime = null;
79
86 static protected $filePermission = null;
87
93 static protected $instances = array();
94
100 static protected $cacheEnabled = true;
101
107 static protected $debugEnabled = true;
108
114 static protected $textCodecEnabled = true;
115
126 static protected $injectedSettings = array();
127
140 static protected $injectedMergeSettings = array();
141
156 public function __construct( $fileName = 'site.ini', $rootDir = '', $useTextCodec = null, $useCache = null, $useLocalOverrides = null, $directAccess = false, $addArrayDefinition = false, $load = true )
157 {
158 $this->Charset = 'utf8';
159 if ( $fileName == '' )
160 $fileName = 'site.ini';
161 if ( $rootDir !== false && $rootDir == '' )
162 $rootDir = 'settings';
163 if ( $useCache === null )
164 $useCache = self::isCacheEnabled();
165 if ( eZINI::isNoCacheAdviced() )
166 {
167 $useCache = false;
168 }
169 if ( $useTextCodec === null )
170 $useTextCodec = self::isTextCodecEnabled();
171
172 $this->UseTextCodec = $useTextCodec;
173 $this->Codec = null;
174 $this->FileName = $fileName;
175 $this->RootDir = $rootDir;
176 $this->UseCache = $useCache;
177 $this->DirectAccess = $directAccess;
178 $this->UseLocalOverrides = $useLocalOverrides;
179 $this->AddArrayDefinition = $addArrayDefinition;
180
181 if ( self::$checkFileMtime === null )
182 {
183 if ( defined('EZP_INI_FILEMTIME_CHECK') )
184 self::$checkFileMtime = EZP_INI_FILEMTIME_CHECK;
185 else
186 self::$checkFileMtime = true;
187 }
188
189 if ( self::$GlobalOverrideDirArray === null )
190 {
191 self::$GlobalOverrideDirArray = self::defaultOverrideDirs();
192 }
193
194 if ( $this->UseLocalOverrides == true )
195 {
196 $this->LocalOverrideDirArray = self::$GlobalOverrideDirArray;
197 }
198
199 if ( self::$filePermission === null )
200 {
201 if ( defined( 'EZP_INI_FILE_PERMISSION' ) )
202 self::$filePermission = EZP_INI_FILE_PERMISSION;
203 else
204 self::$filePermission = 0666;
205 }
206
207 if ( $load )
208 $this->load();
209 }
210
214 function filename()
215 {
216 return $this->FileName;
217 }
218
226 static function isCacheEnabled()
227 {
228 return self::$cacheEnabled;
229 }
230
235 static function isNoCacheAdviced()
236 {
237 if ( !isset( $GLOBALS['eZSiteBasics'] ) )
238 return false;
239 $siteBasics = $GLOBALS['eZSiteBasics'];
240 if ( !isset( $siteBasics['no-cache-adviced'] ) )
241 return false;
242 return $siteBasics['no-cache-adviced'];
243 }
244
253 static function setIsCacheEnabled( $enabled )
254 {
255 self::$cacheEnabled = (bool)$enabled;
256 }
257
267 static function isDebugEnabled()
268 {
269 return self::$debugEnabled;
270 }
271
280 static function setIsDebugEnabled( $enabled )
281 {
282 self::$debugEnabled = (bool)$enabled;
283 }
284
293 static function isTextCodecEnabled()
294 {
295 return self::$textCodecEnabled;
296 }
297
305 static function setIsTextCodecEnabled( $enabled )
306 {
307 self::$textCodecEnabled = (bool)$enabled;
308 }
309
320 static function parameterSet( $fileName = null, $rootDir = null, &$section=false, &$parameter=false )
321 {
322 if( $fileName == null )
323 $fileName = 'site.ini';
324
325 if( $rootDir == null )
326 $fileName = 'settings';
327
328 if ( !eZINI::exists( $fileName, $rootDir ) )
329 return false;
330
331 $iniInstance = eZINI::instance( $fileName, $rootDir, null, null, null, true );
332 return $iniInstance->hasVariable( $section, $parameter );
333 }
334
340 static function exists( $fileName = "site.ini", $rootDir = "settings" )
341 {
342 if ( $fileName == "" )
343 $fileName = "site.ini";
344 if ( $rootDir == "" )
345 $rootDir = "settings";
346 if ( $rootDir[0] !== "/" )
347 $rootDir = __DIR__ . "/../../../" . $rootDir;
348 if ( file_exists( $rootDir . '/' . $fileName ) )
349 return true;
350 else if ( file_exists( $rootDir . '/' . $fileName . '.append.php' ) )
351 return true;
352 else if ( file_exists( $rootDir . '/' . $fileName . '.append' ) )
353 return true;
354 else if ( file_exists( $rootDir . '/' . $fileName . '.php' ) )
355 return true;
356 return false;
357 }
358
365 public function load( $reset = true )
366 {
367 if ( $this->UseCache )
368 {
369 $this->loadCache( $reset );
370 }
371 else
372 {
373 $this->parse( false, false, $reset );
374 }
375 }
376
384 public function loadPlacement( $reset = true )
385 {
386 if ( $this->UseCache )
387 {
388 $this->loadCache( $reset, true );
389 }
390 else
391 {
392 $this->parse( false, false, $reset, true );
393 }
394 if ( isset( self::$injectedSettings[$this->FileName] ) )
395 {
396 foreach ( self::$injectedSettings[$this->FileName] as $blockName => $variables )
397 {
398 foreach ( $variables as $varName => $varValue )
399 {
400 if ( is_array( $varValue ) )
401 {
402 $this->BlockValuesPlacement[$blockName][$varName] = array_fill_keys(
403 array_keys( $varValue ),
404 self::INJECTED_PATH
405 );
406 }
407 else
408 {
409 $this->BlockValuesPlacement[$blockName][$varName] = self::INJECTED_PATH;
410 }
411 }
412 }
413 }
414
415 if ( isset( self::$injectedMergeSettings[$this->FileName] ) )
416 {
417 foreach ( self::$injectedMergeSettings[$this->FileName] as $blockName => $variables )
418 {
419 foreach ( $variables as $varName => $varValue )
420 {
421 if ( !is_array( $varValue ) || !is_array( $this->BlockValuesPlacement[$blockName][$varName] ) )
422 {
423 throw new RuntimeException( "injected-merge-settings can only reference and contain array values" );
424 }
425
426 $this->BlockValuesPlacement[$blockName][$varName] = array_merge(
427 $this->BlockValuesPlacement[$blockName][$varName],
428 array_fill_keys(
429 array_keys( $varValue ),
430 self::INJECTED_PATH
431 )
432 );
433 }
434 }
435 }
436 }
437
444 function findInputFiles( &$inputFiles, &$iniFile )
445 {
446 $iniFile = __DIR__ . "/../../../";
447 if ( $this->RootDir !== false )
448 $iniFile .= eZDir::path( array( $this->RootDir, $this->FileName ) );
449 else
450 $iniFile .= eZDir::path( array( $this->FileName ) );
451
452 $inputFiles = array();
453
454 if ( $this->FileName === 'override.ini' )
455 {
456 eZExtension::prependExtensionSiteAccesses( false, $this, true, false, false );
457 }
458
459 if ( file_exists( $iniFile ) )
460 $inputFiles[] = $iniFile;
461
462 // try the same file name with '.append.php' replace with '.append'
463 if ( strpos($iniFile, '.append.php') !== false && preg_match('#^(.+.append).php$#i', $iniFile, $matches ) && file_exists( $matches[1] ) )
464 $inputFiles[] = $matches[1];
465
466 if ( strpos($iniFile, '.php') === false && file_exists ( $iniFile . '.php' ) )
467 $inputFiles[] = $iniFile . '.php';
468
469 if ( $this->DirectAccess )
470 {
471 if ( file_exists ( $iniFile . '.append' ) )
472 {
473 // recursion eZDebug::writeStrict( "INI files with *.ini.append suffix is DEPRECATED, use *.ini or *.ini.append.php instead: $iniFile.append", __METHOD__ );
474 $inputFiles[] = $iniFile . '.append';
475 }
476
477 if ( file_exists ( $iniFile . '.append.php' ) )
478 $inputFiles[] = $iniFile . '.append.php';
479 }
480 else
481 {
482 $overrideDirs = $this->overrideDirs();
483 $fileName = $this->FileName;
484 $rootDir = $this->RootDir;
485 foreach ( $overrideDirs as $overrideDirItem )
486 {
487 $overrideDir = $overrideDirItem[0];
488 $isGlobal = $overrideDirItem[1];
489 if ( $isGlobal )
490 $overrideFile = eZDir::path( array( $overrideDir, $fileName ) );
491 else
492 $overrideFile = eZDir::path( array( $rootDir, $overrideDir, $fileName ) );
493
494 if ( file_exists( $overrideFile . '.php' ) )
495 {
496 // recursion eZDebug::writeStrict( "INI files with *.ini.php suffix is DEPRECATED, use *.ini or *.ini.append.php instead: $overrideFile.php", __METHOD__ );
497 $inputFiles[] = $overrideFile . '.php';
498 }
499
500 if ( file_exists( $overrideFile ) )
501 {
502 $inputFiles[] = $overrideFile;
503 }
504
505 if ( file_exists( $overrideFile . '.append.php' ) )
506 {
507 $inputFiles[] = $overrideFile . '.append.php';
508 }
509 if ( file_exists( $overrideFile . '.append' ) )
510 {
511 // recursion eZDebug::writeStrict( "INI files with *.ini.append suffix is DEPRECATED, use *.ini or *.ini.append.php instead: $overrideFile.append", __METHOD__ );
512 $inputFiles[] = $overrideFile . '.append';
513 }
514
515 if ( file_exists( $overrideFile . '.php' ) )
516 {
517 $inputFiles[] = $overrideFile . '.php';
518 }
519 }
520 }
521 }
522
527 protected function cacheFileName( $placement = false )
528 {
529 $cacheFileName = $this->FileName . '-' . $this->RootDir . '-' . $this->DirectAccess;
530
531 if ( !$this->DirectAccess )
532 {
533 $cacheFileName .= '-' . serialize( $this->overrideDirs() );
534 }
535 if ( $this->UseTextCodec )
536 {
537 $cacheFileName .= '-' . eZTextCodec::internalCharset();
538 }
539 if ( $placement )
540 {
541 $cacheFileName .= '-placement:' . $placement;
542 }
543 $filePreFix = explode( '.', $this->FileName);
544 return $filePreFix[0] . '-' . md5( $cacheFileName ) . '.php';
545 }
546
556 function loadCache( $reset = true, $placement = false )
557 {
558 eZDebug::accumulatorStart( 'ini', 'Ini load', 'Load cache' );
559 if ( $reset )
560 $this->reset();
561 $cachedDir = __DIR__ . "/../../../" . self::CONFIG_CACHE_DIR;
562
563 $fileName = $this->cacheFileName( $placement );
564 $cachedFile = $cachedDir . $fileName;
565 if ( $placement )
566 {
567 $this->PlacementCacheFile = $cachedFile;
568 }
569 else
570 {
571 $this->CacheFile = $cachedFile;
572 }
573
574 $data = false;// this will contain cache data if cache data is valid
575 if ( file_exists( $cachedFile ) )
576 {
577 if ( self::isDebugEnabled() )
578 eZDebug::writeNotice( "Loading cache '$cachedFile' for file '" . $this->FileName . "'", __METHOD__ );
579
580 include( $cachedFile );
581
582 if ( !isset( $data['rev'] ) || $data['rev'] != eZINI::CONFIG_CACHE_REV )
583 {
584 if ( self::isDebugEnabled() )
585 eZDebug::writeNotice( "Old structure in cache file used, recreating '$cachedFile' to new structure", __METHOD__ );
586 $data = false;
587 $this->reset();
588 }
589 else if ( self::$checkFileMtime === true || self::$checkFileMtime === $this->FileName )
590 {
591 eZDebug::accumulatorStart( 'ini_check_mtime', 'Ini load', 'Check MTime' );
592 $currentTime = time();
593 $cacheCreatedTime = strtotime( $data['created'] );
594 $iniFile = $data['file'];// used by findInputFiles further down
595 $inputFiles = $data['files'];
596 foreach ( $inputFiles as $inputFile )
597 {
598 $fileTime = file_exists( $inputFile ) ? filemtime( $inputFile ) : false;
599 if ( $fileTime === false )// Refresh cache & input files if file is gone
600 {
601 unset( $inputFiles );
602 $data = false;
603 $this->reset();
604 break;
605 }
606 else if ( $fileTime > $currentTime )
607 {
608 eZDebug::writeError( 'Input file "' . $inputFile . '" has a timestamp higher then current time, ignoring to avoid infinite recursion!', __METHOD__ );
609 }
610 else if ( $fileTime > $cacheCreatedTime )// Refresh cache if file has been changed
611 {
612 $data = false;
613 $this->reset();
614 break;
615 }
616 }
617 eZDebug::accumulatorStop( 'ini_check_mtime' );
618 }
619 }
620
621 if ( $data )// if we have cache data on this point, use it
622 {
623 $this->Charset = $data['charset'];
624 $this->ModifiedBlockValues = array();
625 if ( $placement )
626 $this->BlockValuesPlacement = $data['val'];
627 else
628 $this->BlockValues = $data['val'];
629 unset( $data );
630 }
631 else
632 {
633 if ( !isset( $inputFiles ) )// use $inputFiles from cache if defined
634 {
635 eZDebug::accumulatorStart( 'ini_find_files', 'Ini load', 'Find INI Files' );
636 $this->findInputFiles( $inputFiles, $iniFile );
637 eZDebug::accumulatorStop( 'ini_find_files' );
638 if ( count( $inputFiles ) === 0 )
639 {
640 eZDebug::accumulatorStop( 'ini' );
641 return false;
642 }
643 }
644
645 eZDebug::accumulatorStart( 'ini_files_parse', 'Ini load', 'Parse' );
646 $this->parse( $inputFiles, $iniFile, false, $placement );
647 eZDebug::accumulatorStop( 'ini_files_parse' );
648 eZDebug::accumulatorStart( 'ini_files_save', 'Ini load', 'Save Cache' );
649 $cacheSaved = $this->saveCache( $cachedDir, $cachedFile, $placement ? $this->BlockValuesPlacement : $this->BlockValues, $inputFiles, $iniFile );
650 eZDebug::accumulatorStop( 'ini_files_save' );
651
652 if ( $cacheSaved )
653 {
654 // Write log message to storage.log
655 eZLog::writeStorageLog( $fileName, $cachedDir );
656 }
657 }
658
659 eZDebug::accumulatorStop( 'ini' );
660 }
661
672 protected function saveCache( $cachedDir, $cachedFile, array $data, array $inputFiles, $iniFile )
673 {
674 // 7x: Note eZINI::saveCache by default is not very smart when it comes to creating cache directories recursively.
675 // Specifically when the cacheFile is created in a subdirectory of the cacheDir, it will not create the subdirectory.
676 // This is a simple solution to provide for the needed features for Exponential Basic.
677
678 // Get the path to the cache file
679 $tmpFileDir = explode( '/', $cachedFile );
680 array_pop( $tmpFileDir );
681 $tmpFileDir = implode( '/', $tmpFileDir );
682 $tmpFileDirPath = eZDir::cleanPath( $tmpFileDir, 2 );
683
684 // var_dump( "Writing cache file 'cachedFile' in $tmpFileDirPath\n\n", __METHOD__ );
685 // var_dump( eZDir::mkdir( $tmpFileDirPath, 0777, true ) );
686
687 if ( !eZDir::mkdir( $tmpFileDirPath, 0777, true ) )
688 {
689 // Debug::writeError( "Initial attempt: Couldn't create cache directory $tmpFileDir, perhaps wrong permissions", __METHOD__ );
690 }
691
692 if ( !file_exists( $tmpFileDirPath ) )
693 {
694 if ( !eZDir::mkdir( $tmpFileDirPath, 0777, true ) )
695 {
696 eZDebug::writeError( "Main attempt. Couldn't create cache directory $cachedDir, perhaps wrong permissions", __METHOD__ );
697 return false;
698 }
699 }
700
701 // Save the data to a temp cached file
702 $tmpCacheFile = $cachedFile . '_' . substr( md5( mt_rand() ), 0, 8 );
703
704 $fp = @fopen( $tmpCacheFile, "w" );
705 if ( $fp === false )
706 {
707 eZDebug::writeError( "Couldn't create cache file '$cachedFile' in $cachedDir, perhaps wrong permissions?", __METHOD__ );
708 return false;
709 }
710
711 // Write cache data as a php structure with some meta information for use while reading cache
712 fwrite( $fp, "<?php\n// This is a auto generated ini cache file, time created:" . date( DATE_RFC822 ) . "\n" );
713
714 fwrite( $fp, "\$data = array(\n" );
715 fwrite( $fp, "'rev' => " . eZINI::CONFIG_CACHE_REV . ",\n" );
716 fwrite( $fp, "'created' => '" . date('c') . "',\n" );
717
718 if ( $this->Codec )
719 fwrite( $fp, "'charset' => \"".$this->Codec->RequestedOutputCharsetCode."\",\n" );
720 else
721 fwrite( $fp, "'charset' => \"$this->Charset\",\n" );
722
723 fwrite( $fp, "'files' => " . preg_replace( "@\n[\s]+@", '', var_export( $inputFiles, true ) ) . ",\n" );
724 fwrite( $fp, "'file' => '$iniFile',\n" );
725
726 fwrite( $fp, "'val' => " . preg_replace( "@\n[\s]+@", '', var_export( $data, true ) ) . ");" );
727 fwrite( $fp, "\n?>" );
728 fclose( $fp );
729
730 // Rename cache temp file to final desitination and set permissions
731 if( eZFile::rename( $tmpCacheFile, $cachedFile ) )
732 {
733 chmod( $cachedFile, self::$filePermission );
734 }
735
736 // EZP-22579: php5.5 opcache caches php files very aggressively & needs direct call on invalidation in this case
737 clearstatcache( true, $cachedFile );
738 if ( function_exists( 'opcache_invalidate' ) )
739 opcache_invalidate( $cachedFile, true );
740
741 if ( self::isDebugEnabled() )
742 eZDebug::writeNotice( "Wrote cache file '$cachedFile'", __METHOD__ );
743
744 return true;
745 }
746
752 function parse( $inputFiles = false, $iniFile = false, $reset = true, $placement = false )
753 {
754 if ( $inputFiles === false or
755 $iniFile === false )
756 {
757 eZDebug::accumulatorStart( 'ini_parse_find_files', 'Ini load', 'Find INI Files2' );
758 $this->findInputFiles( $inputFiles, $iniFile );
759 eZDebug::accumulatorStop( 'ini_parse_find_files' );
760 }
761
762 if ( $reset )
763 $this->reset();
764
765 foreach ( $inputFiles as $inputFile )
766 {
767 if ( file_exists( $inputFile ) )
768 {
769 $this->parseFile( $inputFile, $placement );
770 }
771 }
772 }
773
778 function parseFile( $file, $placement = false )
779 {
780 if ( self::isDebugEnabled() )
781 eZDebug::writeNotice( "Parsing file '$file'", __METHOD__ );
782
783 $contents = file_get_contents( $file );
784 if ( $contents === false )
785 {
786 eZDebug::writeError( "Failed opening file '$file' for reading", __METHOD__ );
787 return false;
788 }
789
790 $contents = str_replace( "\r", '', $contents );
791 $endOfLine = strpos( $contents, "\n" );
792 $line = substr( $contents, 0, $endOfLine );
793
794 $currentBlock = "";
795 if ( $line )
796 {
797 // check for charset
798 if ( preg_match( "/#\?ini(.+)\?/", $line, $ini_arr ) )
799 {
800 $args = explode( " ", trim( $ini_arr[1] ) );
801 foreach ( $args as $arg )
802 {
803 $vars = explode( '=', trim( $arg ) );
804 if ( $vars[0] == "charset" )
805 {
806 $val = $vars[1];
807 if ( $val[0] == '"' and
808 strlen( $val ) > 0 and
809 $val[strlen($val)-1] == '"' )
810 $val = substr( $val, 1, strlen($val) - 2 );
811 $this->Charset = $val;
812 }
813 }
814 }
815 }
816
817 unset( $this->Codec );
818 if ( $this->UseTextCodec )
819 {
820 $this->Codec = eZTextCodec::instance( $this->Charset, false, false );
821
822 if ( $this->Codec )
823 {
824 eZDebug::accumulatorStart( 'ini_conversion', false, 'INI string conversion' );
825 $contents = $this->Codec->convertString( $contents );
826 eZDebug::accumulatorStop( 'ini_conversion' );
827 }
828 }
829 else
830 $this->Codec = null;
831
832 foreach ( explode( "\n", $contents ) as $line )
833 {
834 if ( $line == '' or $line[0] == '#' )
835 continue;
836 if ( preg_match( "/^(.+)##.*/", $line, $regs ) )
837 $line = $regs[1];
838 if ( trim( $line ) == '' )
839 continue;
840 // check for new block
841 if ( preg_match("#^\[(.+)\]\s*$#", $line, $newBlockNameArray ) )
842 {
843 $newBlockName = trim( $newBlockNameArray[1] );
844 $currentBlock = $newBlockName;
845 continue;
846 }
847
848 // check for variable
849 if ( preg_match("#^([\w_*@-]+)\\[\\]$#", $line, $valueArray ) )
850 {
851 $varName = trim( $valueArray[1] );
852
853 if ( $placement )
854 {
855 if ( isset( $this->BlockValuesPlacement[$currentBlock][$varName] ) &&
856 !is_array( $this->BlockValuesPlacement[$currentBlock][$varName] ) )
857 {
858 eZDebug::writeError( "Wrong operation on the ini setting array '$varName'", __METHOD__ );
859 continue;
860 }
861
862 $this->BlockValuesPlacement[$currentBlock][$varName][] = $file;
863 }
864 else
865 {
866 $this->BlockValues[$currentBlock][$varName] = array();
867
868 // In direct access mode we create empty elements at the beginning of an array
869 // in case it is redefined in this ini file. So when we will save it, definition
870 // will be created as well.
871 if ( $this->AddArrayDefinition )
872 {
873 $this->BlockValues[$currentBlock][$varName][] = "";
874 }
875 }
876 }
877 else if ( preg_match("#^([\w_*@-]+)(\\[([^\\]]*)\\])?=(.*)$#", $line, $valueArray ) )
878 {
879 $varName = trim( $valueArray[1] );
880 $varValue = $valueArray[4];
881
882 if ( $valueArray[2] )
883 {
884 if ( $valueArray[3] )
885 {
886 $keyName = $valueArray[3];
887 if ( $placement )
888 {
889 $this->BlockValuesPlacement[$currentBlock][$varName][$keyName] = $file;
890 }
891 else
892 {
893 $this->BlockValues[$currentBlock][$varName][$keyName] = $varValue;
894 }
895 }
896 else
897 {
898 if ( $placement )
899 {
900 $this->BlockValuesPlacement[$currentBlock][$varName][] = $file;
901 }
902 else
903 {
904 $this->BlockValues[$currentBlock][$varName][] = $varValue;
905 }
906 }
907 }
908 else
909 {
910 if ( $placement )
911 {
912 $this->BlockValuesPlacement[$currentBlock][$varName] = $file;
913 }
914 else
915 {
916 $this->BlockValues[$currentBlock][$varName] = $varValue;
917 }
918 }
919 }
920 }
921 }
922
926 function resetCache()
927 {
928 if ( $this->CacheFile && file_exists( $this->CacheFile ) )
929 unlink( $this->CacheFile );
930 if ( $this->PlacementCacheFile && file_exists( $this->PlacementCacheFile ) )
931 unlink( $this->PlacementCacheFile );
932 }
933
934
941 function save( $fileName = false, $suffix = false, $useOverride = false,
942 $onlyModified = false, $useRootDir = true, $resetArrays = false,
943 $encapsulateInPHP = true )
944 {
945 $lineSeparator = eZSys::lineSeparator();
946 $pathArray = array();
947 $dirArray = array();
948 if ( $fileName === false )
949 $fileName = $this->FileName;
950 if ( $useRootDir === true )
951 {
952 $pathArray[] = $this->RootDir;
953 $dirArray[] = $this->RootDir;
954 }
955 else if ( is_string( $useRootDir ) )
956 {
957 $pathArray[] = $useRootDir;
958 $dirArray[] = $useRootDir;
959 }
960 if ( $useOverride )
961 {
962 $pathArray[] = 'override';
963 $dirArray[] = 'override';
964 }
965 if ( $useOverride === 'append' )
966 $fileName .= '.append';
967 if ( $suffix !== false )
968 $fileName .= $suffix;
969
970 /* Try to guess which filename would fit better: 'xxx.apend' or 'xxx.append.php'.
971 * We choose 'xxx.append.php' in all cases except when
972 * 'xxx.append' exists already and 'xxx.append.php' does not exist.
973 */
974 if( strstr( $fileName, '.append' ) )
975 {
976 $fnAppend = preg_replace( '#\.php$#', '', $fileName );
977 $fnAppendPhp = $fnAppend.'.php';
978 $fpAppend = eZDir::path( array_merge( $pathArray, array( $fnAppend ) ) );
979 $fpAppendPhp = eZDir::path( array_merge( $pathArray, array( $fnAppendPhp ) ) );
980 $fileName = ( file_exists( $fpAppend ) && !file_exists( $fpAppendPhp ) )
981 ? $fnAppend : $fnAppendPhp;
982 }
983
984 $originalFileName = $fileName;
985 $backupFileName = $originalFileName . eZSys::backupFilename();
986 $fileName .= '.tmp';
987
988 $dirPath = eZDir::path( $dirArray );
989 if ( !file_exists( $dirPath ) )
990 eZDir::mkdir( $dirPath, octdec( '777' ), true );
991
992 $filePath = eZDir::path( array_merge( $pathArray, array( $fileName ) ) );
993 $originalFilePath = eZDir::path( array_merge( $pathArray, array( $originalFileName ) ) );
994 $backupFilePath = eZDir::path( array_merge( $pathArray, array( $backupFileName ) ) );
995
996 $fp = @fopen( $filePath, "w+");
997 if ( !$fp )
998 {
999 eZDebug::writeError( "Failed opening file '$filePath' for writing", __METHOD__ );
1000 return false;
1001 }
1002 $writeOK = true;
1003 $written = 0;
1004
1005 $charset = $this->Codec ? $this->Codec->RequestedOutputCharsetCode : $this->Charset;
1006 if ( $encapsulateInPHP )
1007 {
1008 $written = fwrite( $fp, "<?php /* #?ini charset=\"$charset\"?$lineSeparator$lineSeparator" );
1009 }
1010 else
1011 {
1012 $written = fwrite( $fp, "#?ini charset=\"$charset\"?$lineSeparator$lineSeparator" );
1013 }
1014
1015 if ( $written === false )
1016 $writeOK = false;
1017 $i = 0;
1018 if ( $writeOK )
1019 {
1020 foreach( array_keys( $this->BlockValues ) as $blockName )
1021 {
1022 if ( $onlyModified )
1023 {
1024 $groupHasModified = false;
1025 if ( isset( $this->ModifiedBlockValues[$blockName] ) )
1026 {
1027 foreach ( $this->ModifiedBlockValues[$blockName] as $modifiedValue )
1028 {
1029 if ( $modifiedValue )
1030 $groupHasModified = true;
1031 }
1032 }
1033 if ( !$groupHasModified )
1034 continue;
1035 }
1036 $written = 0;
1037 if ( $i > 0 )
1038 $written = fwrite( $fp, "$lineSeparator" );
1039 if ( $written === false )
1040 {
1041 $writeOK = false;
1042 break;
1043 }
1044 $written = fwrite( $fp, "[$blockName]$lineSeparator" );
1045 if ( $written === false )
1046 {
1047 $writeOK = false;
1048 break;
1049 }
1050 foreach( array_keys( $this->BlockValues[$blockName] ) as $blockVariable )
1051 {
1052 if ( $onlyModified )
1053 {
1054 if ( !isset( $this->ModifiedBlockValues[$blockName][$blockVariable] ) or
1055 !$this->ModifiedBlockValues[$blockName][$blockVariable] )
1056 continue;
1057 }
1058 $varKey = $blockVariable;
1059 $varValue = $this->BlockValues[$blockName][$blockVariable];
1060 if ( is_array( $varValue ) )
1061 {
1062 if ( count( $varValue ) > 0 )
1063 {
1064 $customResetArray = ( isset( $this->BlockValues[$blockName]['ResetArrays'] ) and
1065 $this->BlockValues[$blockName]['ResetArrays'] == 'false' )
1066 ? true
1067 : false;
1068 if ( $resetArrays and !$customResetArray )
1069 $written = fwrite( $fp, "$varKey" . "[]$lineSeparator" );
1070 foreach ( $varValue as $varArrayKey => $varArrayValue )
1071 {
1072 if ( is_string( $varArrayKey ) )
1073 $written = fwrite( $fp, "$varKey" . "[$varArrayKey]=$varArrayValue$lineSeparator" );
1074 else
1075 {
1076 if ( $varArrayValue == NULL )
1077 $written = fwrite( $fp, "$varKey" . "[]$lineSeparator" );
1078 else
1079 $written = fwrite( $fp, "$varKey" . "[]=$varArrayValue$lineSeparator" );
1080 }
1081 if ( $written === false )
1082 break;
1083 }
1084 }
1085 else
1086 $written = fwrite( $fp, "$varKey" . "[]$lineSeparator" );
1087 }
1088 else
1089 {
1090 $written = fwrite( $fp, "$varKey=$varValue$lineSeparator" );
1091 }
1092 if ( $written === false )
1093 {
1094 $writeOK = false;
1095 break;
1096 }
1097 }
1098 if ( !$writeOK )
1099 break;
1100 ++$i;
1101 }
1102 }
1103 if ( $writeOK )
1104 {
1105 if ( $encapsulateInPHP )
1106 {
1107 $written = fwrite( $fp, "*/ ?>" );
1108
1109 if ( $written === false )
1110 $writeOK = false;
1111 }
1112 }
1113 @fclose( $fp );
1114 if ( !$writeOK )
1115 {
1116 unlink( $filePath );
1117 return false;
1118 }
1119
1120 chmod( $filePath, self::$filePermission );
1121
1122 if ( file_exists( $backupFilePath ) )
1123 unlink( $backupFilePath );
1124 if ( file_exists( $originalFilePath ) )
1125 {
1126 if ( !rename( $originalFilePath, $backupFilePath ) )
1127 return false;
1128 }
1129 if ( !rename( $filePath, $originalFilePath ) )
1130 {
1131 rename( $backupFilePath, $originalFilePath );
1132 return false;
1133 }
1134
1135 return true;
1136 }
1137
1141 function reset()
1142 {
1143 $this->BlockValues = array();
1144 $this->ModifiedBlockValues = array();
1145 }
1146
1152 function rootDir()
1153 {
1154 return $this->RootDir;
1155 }
1156
1166 function overrideDirs( $scope = null )
1167 {
1168 if ( $this->UseLocalOverrides == true )
1169 $dirs =& $this->LocalOverrideDirArray;
1170 else
1171 $dirs =& self::$GlobalOverrideDirArray;
1172
1173 return self::overrideDirsByScope( $dirs, $scope );
1174 }
1175
1185 public static function globalOverrideDirs( $scope = null )
1186 {
1187 return self::overrideDirsByScope( self::$GlobalOverrideDirArray, $scope );
1188 }
1189
1200 protected static function overrideDirsByScope( array $dirs, $scope = null )
1201 {
1202 if ( $scope !== null )
1203 {
1204 if ( $scope === false )
1205 return $dirs;
1206 if ( isset( $dirs[$scope] ) )
1207 return $dirs[$scope];
1208 eZDebug::writeWarning( "Undefined override dir scope: '$scope'", __METHOD__ );
1209 }
1210
1211 return array_merge( $dirs['sa-extension'], $dirs['siteaccess'], $dirs['extension'], $dirs['override'] );
1212 }
1213
1224 static public function defaultOverrideDirs()
1225 {
1226 static $def = array(
1227 'sa-extension' => array(),
1228 'siteaccess' => array(),
1229 'extension' => array(),
1230 'override' => array( array( 'override', false ) )
1231 );
1232 return $def;
1233 }
1234
1242 function setOverrideDirs( array $newDirs, $scope = false )
1243 {
1244 if ( $this->UseLocalOverrides == true )
1245 $dirs =& $this->LocalOverrideDirArray;
1246 else
1247 $dirs =& self::$GlobalOverrideDirArray;
1248
1249 if ( $scope === false )
1250 $dirs = $newDirs;
1251 else if ( isset( $dirs[$scope] ) )
1252 $dirs[$scope] = $newDirs;
1253 else
1254 eZDebug::writeWarning( "Undefined override dir scope: '$scope'", __METHOD__ );
1255
1256 $this->CacheFile = false;
1257 }
1258
1262 static public function resetGlobalOverrideDirs()
1263 {
1264 self::$GlobalOverrideDirArray = self::defaultOverrideDirs();
1265 }
1266
1270 public function resetOverrideDirs()
1271 {
1272 $this->setOverrideDirs( self::defaultOverrideDirs() );
1273 }
1274
1283 function removeOverrideDir( $identifier, $scope = 'extension' )
1284 {
1285 if ( $this->UseLocalOverrides == true )
1286 $dirs =& $this->LocalOverrideDirArray;
1287 else
1288 $dirs =& self::$GlobalOverrideDirArray;
1289
1290 if ( !$identifier || !is_string( $identifier ) )
1291 {
1292 eZDebug::writeError( "\$identifier must be a string", __METHOD__ );
1293 return false;
1294 }
1295
1296 if ( !isset( $dirs[$scope] ) )
1297 {
1298 eZDebug::writeWarning( "Undefined override dir scope: '$scope'", __METHOD__ );
1299 $scope = 'extension';
1300 }
1301
1302 $overrideRemoved = false;
1303 if ( isset( $dirs[$scope][$identifier] ) )
1304 {
1305 unset( $dirs[$scope][$identifier] );
1306 $overrideRemoved = true;
1307 $this->CacheFile = false;
1308 }
1309
1310 return $overrideRemoved;
1311 }
1312
1324 function prependOverrideDir( $dir, $globalDir = false, $identifier = false, $scope = null )
1325 {
1326 if ( self::isDebugEnabled() )
1327 eZDebug::writeNotice( "Prepending override dir '$dir'", "eZINI" );
1328
1329 if ( $this->UseLocalOverrides == true )
1330 $dirs =& $this->LocalOverrideDirArray;
1331 else
1332 $dirs =& self::$GlobalOverrideDirArray;
1333
1334 $scope = self::selectOverrideScope( $scope, $identifier, $dir, 'extension' );
1335
1336 // Check if the override with the current identifier already exists
1337 $overrideOverwritten = false;
1338 if ( $identifier && isset( $dirs[$scope][$identifier] ) )
1339 {
1340 $dirs[$scope][$identifier] = array( $dir, $globalDir );
1341 $overrideOverwritten = true;
1342 }
1343 else
1344 {
1345 // array_merge() is to be used below instead of the "+" operator because the
1346 // position of elements in this mixed hash/list is important!
1347 if ( $identifier )
1348 $dirs[$scope] = array_merge( array( $identifier => array( $dir, $globalDir ) ), $dirs[$scope] );
1349 else
1350 $dirs[$scope] = array_merge( array( array( $dir, $globalDir ) ), $dirs[$scope] );
1351 }
1352
1353 $this->CacheFile = false;
1354 return $overrideOverwritten === false;
1355 }
1356
1368 function appendOverrideDir( $dir, $globalDir = false, $identifier = false, $scope = null )
1369 {
1370 if ( self::isDebugEnabled() )
1371 eZDebug::writeNotice( "Appending override dir '$dir'", __METHOD__ );
1372
1373 if ( $this->UseLocalOverrides == true )
1374 $dirs =& $this->LocalOverrideDirArray;
1375 else
1376 $dirs =& self::$GlobalOverrideDirArray;
1377
1378 $scope = self::selectOverrideScope( $scope, $identifier, $dir, 'override' );
1379
1380 // Check if the override with the current identifier already exists
1381 $overrideOverwritten = false;
1382 if ( $identifier && isset( $dirs[$scope][$identifier] ) )
1383 {
1384 $dirs[$scope][$identifier] = array( $dir, $globalDir );
1385 $overrideOverwritten = true;
1386 }
1387 else
1388 {
1389 if ( $identifier )
1390 $dirs[$scope][$identifier] = array( $dir, $globalDir );
1391 else
1392 $dirs[$scope][] = array( $dir, $globalDir );
1393 }
1394
1395 $this->CacheFile = false;
1396 return $overrideOverwritten === false;
1397 }
1398
1409 protected static function selectOverrideScope( $scope, $identifier, $dir, $default )
1410 {
1411 if ( $scope !== null )
1412 {
1413 $def = self::defaultOverrideDirs();
1414 if ( isset( $def[$scope] ) )
1415 return $scope;
1416 eZDebug::writeWarning( "Undefined override dir scope: '$scope' with dir: '$dir'", __METHOD__ );
1417 }
1418 if ( $identifier === 'siteaccess' )
1419 return 'siteaccess';
1420 else if ( $identifier && strpos($identifier, 'extension:') === 0 )
1421 return 'extension';
1422 else if ( strpos($dir, 'siteaccess') !== false )
1423 return 'siteaccess';
1424 else if ( strpos($dir, 'extension') !== false )
1425 return 'extension';
1426
1427 eZDebug::writeStrict( "Could not figgure out INI scope for \$identifier: '$identifier' with \$dir: '$dir', falling back to '$default'", __METHOD__ );
1428 return $default;
1429 }
1430
1435 function assign( $blockName, $varName, &$variable )
1436 {
1437 if ( isset( $this->BlockValues[$blockName][$varName] ) )
1438 $variable = $this->BlockValues[$blockName][$varName];
1439 else
1440 return false;
1441 return true;
1442 }
1443
1453 function variable( $blockName, $varName )
1454 {
1455 if ( isset( $this->BlockValues[$blockName][$varName] ) )
1456 {
1457 $value = $this->BlockValues[$blockName][$varName];
1458 }
1459
1460 if ( isset( self::$injectedSettings[$this->FileName][$blockName][$varName] ) )
1461 {
1462 $value = self::$injectedSettings[$this->FileName][$blockName][$varName];
1463 }
1464
1465 if ( isset( $value ) && isset( self::$injectedMergeSettings[$this->FileName][$blockName][$varName] ) )
1466 {
1467 if ( !is_array( $value ) || !is_array( self::$injectedMergeSettings[$this->FileName][$blockName][$varName] ) )
1468 {
1469 throw new RuntimeException( "injected-merge-settings can only reference and contain array values" );
1470 }
1471 $value = array_merge( $value, self::$injectedMergeSettings[$this->FileName][$blockName][$varName] );
1472 }
1473
1474 if ( isset( $value ) )
1475 return $value;
1476
1477 if ( !isset( $this->BlockValues[$blockName] ) )
1478 eZDebug::writeError( "Undefined group: '$blockName' in " . $this->FileName, __METHOD__ );
1479 else
1480 eZDebug::writeError( "Undefined variable: '$varName' in group '$blockName' in " . $this->FileName, __METHOD__ );
1481 return false;
1482 }
1483
1494 function variableMulti( $blockName, $varNames, $signatures = array() )
1495 {
1496 $ret = array();
1497
1498 if ( !isset( $this->BlockValues[$blockName] )
1499 && !isset( self::$injectedSettings[$this->FileName][$blockName] )
1500 )
1501 {
1502 eZDebug::writeError( "Undefined group: '$blockName' in " . $this->FileName, "eZINI" );
1503 return false;
1504 }
1505 foreach ( $varNames as $key => $varName )
1506 {
1507 $ret[$key] = null;
1508
1509 if ( isset( $this->BlockValues[$blockName][$varName] ) )
1510 {
1511 $ret[$key] = $this->BlockValues[$blockName][$varName];
1512 }
1513 if ( isset( self::$injectedSettings[$this->FileName][$blockName][$varName] ) )
1514 {
1515 $ret[$key] = self::$injectedSettings[$this->FileName][$blockName][$varName];
1516 }
1517 if ( isset( self::$injectedMergeSettings[$this->FileName][$blockName][$varName] ) )
1518 {
1519 if ( !is_array( $ret[$key] ) || !is_array( self::$injectedMergeSettings[$this->FileName][$blockName][$varName] ) )
1520 {
1521 throw new RuntimeException( "injected-merge-settings can only reference and contain array values" );
1522 }
1523 $ret[$key] = array_merge(
1524 $this->BlockValues[$blockName][$varName],
1525 self::$injectedMergeSettings[$this->FileName][$blockName][$varName]
1526 );
1527 }
1528
1529 if ( isset( $ret[$key] ) && isset( $signatures[$key] ) )
1530 {
1531 switch ( $signatures[$key] )
1532 {
1533 case 'enabled':
1534 $ret[$key] = $this->BlockValues[$blockName][$varName] == 'enabled';
1535 break;
1536 }
1537 }
1538 }
1539
1540 return $ret;
1541 }
1542
1551 function hasVariable( $blockName, $varName )
1552 {
1553 // 1. Check if the variable is set in either injected or regular settings.
1554 if (
1555 !isset( self::$injectedSettings[$this->FileName][$blockName][$varName] )
1556 && !isset( $this->BlockValues[$blockName][$varName] )
1557 )
1558 {
1559 return false;
1560 }
1561
1562 // 2. Check if injected setting isn't strictly false (false being the default value when a variable doesn't exist).
1563 if (
1564 isset( self::$injectedSettings[$this->FileName][$blockName][$varName] )
1565 && self::$injectedSettings[$this->FileName][$blockName][$varName] === false
1566 )
1567 {
1568 return false;
1569 }
1570
1571 return true;
1572 }
1573
1581 function hasSection( $sectionName )
1582 {
1583 return ( isset( $this->BlockValues[$sectionName] )
1584 || isset( self::$injectedSettings[$this->FileName][$sectionName] ) );
1585 }
1586
1590 function isVariableModified( $blockName, $varName )
1591 {
1592 return ( isset( $this->ModifiedBlockValues[$blockName][$varName] ) and
1593 $this->ModifiedBlockValues[$blockName][$varName] );
1594 }
1595
1604 function variableArray( $blockName, $varName )
1605 {
1606 $ret = $this->variable( $blockName, $varName );
1607
1608 if ( is_array( $ret ) )
1609 {
1610 $arr = array();
1611 foreach ( $ret as $key => $retItem )
1612 {
1613 $arr[$key] = explode( ';', $retItem );
1614 }
1615 $ret = $arr;
1616 }
1617 else if ( $ret !== false )
1618 {
1619 $ret = trim( $ret ) === '' ? array() : explode( ';', $ret );
1620 }
1621
1622 return $ret;
1623 }
1624
1631 function hasGroup( $blockName )
1632 {
1633 return $this->hasSection( $blockName );
1634 }
1635
1644 function group( $blockName )
1645 {
1646 if ( !isset( $this->BlockValues[$blockName] ) )
1647 {
1648 eZDebug::writeError( "Unknown group: '$blockName'", __METHOD__ );
1649 $ret = null;
1650 return $ret;
1651 }
1652 if ( isset( self::$injectedSettings[$this->FileName][$blockName] ) )
1653 {
1654 $ret = array_merge(
1655 $this->BlockValues[$blockName],
1656 self::$injectedSettings[$this->FileName][$blockName]
1657 );
1658 }
1659 else
1660 {
1661 $ret = $this->BlockValues[$blockName];
1662 }
1663
1664 return $ret;
1665 }
1666
1667 function isSettingReadOnly( $fileName = false, $blockName = false, $settingName = false )
1668 {
1669 if ( !$this->readOnlySettingsCheck() )
1670 return true;
1671
1672 $ini = eZINI::instance();
1673 if ( !$ini->hasVariable( 'eZINISettings', 'ReadonlySettingList' ) )
1674 return true;
1675
1676 $fileName = $fileName === false ? $ini->FileName : $fileName;
1677 $fileNameExploded = explode( '.', $fileName );
1678 $realFileName = $fileNameExploded[0] . '.' . $fileNameExploded[1];
1679 $blockName = $blockName === false ? '*' : $blockName;
1680 $settingName = $settingName === false ? '*' : $settingName;
1681 $currentSetting = $realFileName . '/' . $blockName . '/' . $settingName;
1682
1683 $settingList = $ini->variable( 'eZINISettings', 'ReadonlySettingList' );
1684 $settingList[] = 'site.ini/eZINISettings/*';
1685
1686 $result = !( in_array( $realFileName . '/*' , $settingList ) or
1687 in_array( $realFileName . '/' . $blockName . '/*' , $settingList ) or
1688 in_array( $realFileName . '/' . $blockName . '/' . $settingName , $settingList ) );
1689
1690 return $result;
1691 }
1695 function removeGroup( $blockName )
1696 {
1697 unset( $this->BlockValues[$blockName] );
1698 unset( $this->BlockValuesPlacement[$blockName] );
1699 }
1700
1701 function removeSetting( $blockName, $settingName )
1702 {
1703 unset( $this->BlockValues[$blockName][$settingName] );
1704 unset( $this->BlockValuesPlacement[$blockName][$settingName] );
1705 if ( $this->BlockValues[$blockName] == null )
1706 $this->removeGroup( $blockName );
1707 }
1708
1716 function groups()
1717 {
1718 if ( isset( self::$injectedSettings[$this->FileName] ) || isset( self::$injectedMergeSettings[$this->FileName] ) )
1719 {
1720 $result = $this->BlockValues;
1721 foreach ( $result as $blockName => $vars )
1722 {
1723 foreach ( $vars as $varName => $varValue )
1724 {
1725 if ( isset( self::$injectedSettings[$this->FileName][$blockName][$varName] ) )
1726 {
1727 $result[$blockName][$varName] = self::$injectedSettings[$this->FileName][$blockName][$varName];
1728 }
1729 if ( isset( self::$injectedMergeSettings[$this->FileName][$blockName][$varName] ) )
1730 {
1731 if ( !is_array( $result[$blockName][$varName] ) || !is_array( self::$injectedMergeSettings[$this->FileName][$blockName][$varName] ) )
1732 {
1733 throw new RuntimeException( "injected-merge-settings can only reference and contain array values" );
1734 }
1735
1736 $result[$blockName][$varName] = array_merge(
1737 $varValue,
1738 self::$injectedMergeSettings[$this->FileName][$blockName][$varName]
1739 );
1740 }
1741 }
1742 }
1743 foreach ( self::$injectedSettings[$this->FileName] as $blockName => $vars )
1744 {
1745 if ( !isset( $result[$blockName] ) )
1746 {
1747 $result[$blockName] = $vars;
1748 }
1749 }
1750 return $result;
1751 }
1752 return $this->BlockValues;
1753 }
1754
1758 function &groupPlacements()
1759 {
1760 if ( !$this->BlockValuesPlacement )
1761 {
1762 $this->loadPlacement();
1763 }
1764 return $this->BlockValuesPlacement;
1765 }
1766
1776 function findSettingPlacement( $path )
1777 {
1778 if ( is_array( $path ) )
1779 {
1780 if( isset( $path[0] ) )
1781 {
1782 $path = $path[0];
1783 }
1784 else
1785 {
1786 return 'undefined';
1787 }
1788 }
1789
1790 // changing $path so that it's relative the root eZ Publish (legacy)
1791 $path = str_replace( __DIR__ . "/../../../", "", $path );
1792 $exploded = explode( '/', $path );
1793 $directoryCount = count( $exploded );
1794 switch ( $directoryCount )
1795 {
1796 case 2:
1797 $placement = 'default';
1798 break;
1799 case 3:
1800 $placement = 'override';
1801 break;
1802 case 4:
1803 {
1804 if ( $exploded[0] === 'extension' )
1805 $placement = 'extension:' . $exploded[1];
1806 else
1807 $placement = 'siteaccess';
1808 }
1809 break;
1810 case 6:
1811 {
1812 $placement = 'ext-siteaccess:' . $exploded[1];
1813 }
1814 break;
1815 default:
1816 if ( $path === self::INJECTED_PATH )
1817 {
1818 $placement = 'injected';
1819 }
1820 else
1821 {
1822 $placement = 'undefined';
1823 }
1824 break;
1825 }
1826 return $placement;
1827 }
1828
1829 function settingType( $settingValue )
1830 {
1831 if ( is_array( $settingValue ) )
1832 return 'array';
1833
1834 if ( is_numeric( $settingValue ) )
1835 return 'numeric';
1836
1837 if ( $settingValue == 'true' or $settingValue == 'false' )
1838 {
1839 return 'true/false';
1840 }
1841 if ( $settingValue == 'enabled' or $settingValue == 'disabled' )
1842 {
1843 return 'enable/disable';
1844 }
1845
1846 return 'string';
1847 }
1848
1852 function setGroups( $groupArray )
1853 {
1854 $resultArray = array();
1855 // Check for readOnly
1856 foreach ( $groupArray as $blockName => $blockVariables )
1857 {
1858 foreach ( $blockVariables as $variableName => $variableValue )
1859 {
1860 if ( !$this->isSettingReadOnly( $this->FileName, $blockName, $variableName ) )
1861 continue;
1862 $resultArray[$blockName][$variableName] = $variableValue;
1863 }
1864 }
1865 $this->BlockValues = $resultArray;
1866 }
1867
1878 function setVariables( $variables )
1879 {
1880 foreach ( $variables as $blockName => $blockVariables )
1881 {
1882 foreach ( $blockVariables as $variableName => $variableValue )
1883 {
1884 $this->setVariable( $blockName, $variableName, $variableValue );
1885 }
1886 }
1887 }
1888
1896 function setVariable( $blockName, $variableName, $variableValue )
1897 {
1898 if ( !$this->isSettingReadOnly( $this->filename(), $blockName, $variableName ) )
1899 return false;
1900
1901 $this->BlockValues[$blockName][$variableName] = $variableValue;
1902 $this->ModifiedBlockValues[$blockName][$variableName] = true;
1903 }
1904
1910 function getNamedArray()
1911 {
1912 if ( isset( self::$injectedSettings[$this->FileName] ) )
1913 {
1914 return array_merge(
1915 $this->BlockValues,
1916 self::$injectedSettings[$this->FileName]
1917 );
1918 }
1919 return $this->BlockValues;
1920 }
1921
1931 static function isLoaded( $fileName = 'site.ini', $rootDir = 'settings', $useLocalOverrides = null )
1932 {
1933 return isset( self::$instances["$rootDir-$fileName-$useLocalOverrides"] );
1934 }
1935
1953 static function instance( $fileName = 'site.ini', $rootDir = 'settings', $useTextCodec = null, $useCache = null, $useLocalOverrides = null, $directAccess = false, $addArrayDefinition = false )
1954 {
1955 if ( $addArrayDefinition !== false || $directAccess !== false || $useTextCodec !== null || $useCache !== null )
1956 {
1957 // Could have trown strict error here but will cause issues if ini system has not been setup yet..
1958 return new eZINI( $fileName, $rootDir, $useTextCodec, $useCache, $useLocalOverrides, $directAccess, $addArrayDefinition );
1959 }
1960
1961 $key = "$rootDir-$fileName-$useLocalOverrides";
1962 if ( !isset( self::$instances[$key] ) )
1963 {
1964 self::$instances[$key] = new eZINI( $fileName, $rootDir, $useTextCodec, $useCache, $useLocalOverrides, $directAccess, $addArrayDefinition );
1965 }
1966 return self::$instances[$key];
1967 }
1968
1973 static function fetchFromFile( $fileName, $useTextCodec = null )
1974 {
1975 return new eZINI( $fileName, false, $useTextCodec, false, false, true );
1976 }
1977
1986 static function getSiteAccessIni( $siteAccess, $iniFile )
1987 {
1988 $saPath = eZSiteAccess::findPathToSiteAccess( $siteAccess );
1989 return self::fetchFromFile( "$saPath/$iniFile" );
1990 }
1991
1996 static function create( $fileName = 'site.ini', $rootDir = 'settings', $useTextCodec = null, $useCache = null, $useLocalOverrides = null )
1997 {
1998 $impl = new eZINI( $fileName, $rootDir, $useTextCodec, $useCache, $useLocalOverrides );
1999 return $impl;
2000 }
2001
2005 function setReadOnlySettingsCheck( $readOnly = true )
2006 {
2007 $this->ReadOnlySettingsCheck = $readOnly;
2008 }
2009
2013 function readOnlySettingsCheck()
2014 {
2015 return $this->ReadOnlySettingsCheck;
2016 }
2017
2029 static function resetGlobals( $fileName = 'site.ini', $rootDir = 'settings', $useLocalOverrides = null )
2030 {
2031 self::resetInstance( $fileName, $rootDir, $useLocalOverrides );
2032 }
2033
2043 static function resetInstance( $fileName = 'site.ini', $rootDir = 'settings', $useLocalOverrides = null )
2044 {
2045 unset( self::$instances["$rootDir-$fileName-$useLocalOverrides"] );
2046 }
2047
2057 static function resetAllGlobals( $resetGlobalOverrideDirs = true )
2058 {
2059 self::resetAllInstances( $resetGlobalOverrideDirs );
2060 }
2061
2069 static function resetAllInstances( $resetGlobalOverrideDirs = true )
2070 {
2071 self::$instances = array();
2072
2073 if ( $resetGlobalOverrideDirs )
2074 self::resetGlobalOverrideDirs();
2075 }
2076
2086 static function injectSettings( array $settings )
2087 {
2088 self::$injectedSettings = $settings;
2089 }
2090
2100 static function injectMergeSettings( array $settings )
2101 {
2102 self::$injectedMergeSettings = $settings;
2103 }
2104
2107 public $Charset;
2108
2110 public $Codec;
2111
2113 public $BlockValues;
2114
2116 public $BlockValuesPlacement;
2117
2119 public $ModifiedBlockValues;
2120
2122 public $FileName;
2123
2125 public $RootDir;
2126
2128 public $UseTextCodec;
2129
2131 public $CacheFile;
2132
2134 public $PlacementCacheFile;
2135
2137 public $UseCache;
2138
2140 public $UseLocalOverrides;
2141
2143 public $LocalOverrideDirArray;
2144
2146 static protected $GlobalOverrideDirArray = null;
2147
2149 public $DirectAccess;
2150
2152 public $AddArrayDefinition;
2153
2155 public $ReadOnlySettingsCheck = true;
2156
2157 /* PHP8 Required Properties To Boot Exponential Basic Kernel with this package from ezpublish version 6 */
2158
2159 public $Index;
2160 public $WWWDir;
2161 public $SiteDir;
2162
2163 }
2164
2165 ?>
$pathArray
$pathArray
Definition: admin/adlist.php:74
$i
$i
Definition: admin/adlist.php:91
$groupArray
$groupArray
Definition: admin/useredit.php:452
eZDebug\writeStrict
static writeStrict( $string, $label="", $backgroundClass="")
Definition: ezdebug.php:415
eZDebug\writeError
static writeError( $string, $label="", $backgroundClass="")
Definition: ezdebug.php:546
eZDebug\writeNotice
static writeNotice( $string, $label="", $backgroundClass="")
Definition: ezdebug.php:460
eZDebug\writeWarning
static writeWarning( $string, $label="", $backgroundClass="")
Definition: ezdebug.php:503
eZDebug\accumulatorStart
static accumulatorStart( $key, $inGroup=false, $name=false, $recursive=false)
Definition: ezdebug.php:1362
eZDebug\accumulatorStop
static accumulatorStop( $key, $recursive=false)
Definition: ezdebug.php:1390
eZDir\mkdir
static mkdir( $dir, $perm=false, $recursive=false)
Definition: ezdir.php:74
eZDir\cleanPath
static cleanPath( $path, $toType=self::SEPARATOR_UNIX)
Definition: ezdir.php:203
eZDir\path
static path( $names, $includeEndSeparator=false, $type=self::SEPARATOR_UNIX)
Definition: ezdir.php:238
eZExtension\prependExtensionSiteAccesses
static prependExtensionSiteAccesses( $accessName=false, $ini=false, $globalDir=true, $identifier=null, $order=true)
Definition: ezextension.php:230
eZFile\rename
static rename( $srcFile, $destFile, $mkdir=false, $flags=0)
Definition: ezfile.php:153
eZINI
Reads and writes .ini style configuration files.
eZLog\writeStorageLog
static writeStorageLog( $name, $dir=false)
Definition: ezlog.php:72
eZSiteAccess\findPathToSiteAccess
static findPathToSiteAccess( $siteAccess)
Definition: ezsiteaccess.php:67
eZSys\lineSeparator
static lineSeparator()
Definition: ezsys.php:484
eZSys\backupFilename
static backupFilename()
Definition: ezsys.php:474
eZTextCodec\internalCharset
static internalCharset()
Definition: ezi18n/classes/eztextcodec.php:547
eZTextCodec\instance
static instance( $inputCharsetCode, $outputCharsetCode=false, $alwaysReturn=true)
Definition: ezi18n/classes/eztextcodec.php:447
$ini
$ini
Definition: classes/admin/linklist.php:64
$result
$result
Definition: companysearch.php:94
$args
$args
Definition: companytypelist.php:125
$SiteDir
$SiteDir
Definition: eZPBINIFile.php:501
$Index
$Index
Definition: eZPBINIFile.php:499
parse
parse( $inifilename, $append=false)
Definition: eZPBINIFile.php:205
file_exists
static file_exists( $inifilename)
Definition: eZPBINIFile.php:195
$WWWDir
$WWWDir
Definition: eZPBINIFile.php:500
$fp
$fp
Definition: export.php:97
$contents
$contents
Definition: ezarticle/user/extendedsearch.php:52
$fileName
if(eZObjectPermission::hasPermission( $file->id(), "filemanager_file", "r", $user)==false) $fileName
Definition: ezfilemanager/user/filedownload.php:43
$suffix
$suffix
Definition: ezfilemanager/user/filedownload.php:168
$file
$file
Definition: ezfilemanager/user/filedownload.php:35
$filePath
$filePath
Definition: ezfilemanager/user/filedownload.php:50
$originalFileName
else $originalFileName
Definition: ezfilemanager/user/filedownload.php:48
$section
$section
Definition: ezimagecatalogue/user/categoryedit.php:393
$cachedFile
$cachedFile
Definition: eznewsfeed/user/headlines.php:109
$def
$def
Definition: ezprestauthorizedclient.php:12
$dir
$dir
Definition: ezsitemanager/admin/filelist.php:87
$ret
$ret
Definition: ezsitemanager/admin/filelist.php:88
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.