예제 #1
0
    /**
     * @param string $name
     * @param mixed $value
     * @param string $cacheFileName
     * @return mixed|null
     */
    public static function dailyValue( $name, $value = null, $cacheFileName = null )
    {
        if ( $value === null && isset($memoryCache[$name]) && $cacheFileName === null )
        {
            return self::$memoryCache[$name];
        }
        else
        {
            if (is_null($cacheFileName))
            {
                $cacheFileName = self::DAILY_CACHE_FILE . '_' . ClusterTool::clusterIdentifier();
            }

            $cache = new eZPHPCreator(
                eZSys::cacheDirectory(),
                $cacheFileName . '.php',
                '',
                array()
            );

            $expiryTime = time() - 24 * 3600;

            // reading
            if ($cache->canRestore($expiryTime))
            {
                $values = $cache->restore(array('cacheTable' => 'cacheTable'));

                if (is_null($value))
                {
                    if (isset($values['cacheTable'][$name]))
                    {
                        return $values['cacheTable'][$name];
                    }
                    else
                    {
                        return null;
                    }
                }
            }
            else
            {
                $values = array('cacheTable' => array());
            }

            $values['cacheTable'][$name] = $value;
            if ( $cacheFileName == self::DAILY_CACHE_FILE . '_' . ClusterTool::clusterIdentifier() )
                self::$memoryCache = $values['cacheTable'];

            // writing
            $cache->addVariable('cacheTable', $values['cacheTable']);
            $cache->store(true);
            $cache->close();
        }

        return null;
    }
    /**
     * @param string $name
     * @param mixed $value
     * @return array
     */
    public static function dailyValue( $name, $value = null)
    {
        if ( $value === null && isset($memoryCache[$name]) )
        {
            return self::$memoryCache[$name];
        }
        else
        {
            $cache = new eZPHPCreator(
                eZSys::cacheDirectory(),
                self::GLOBAL_CACHE_FILE . '.php',
                '',
                array() // removed clustering
            );

            $expiryTime = time() - 24 * 3600;

            // reading
            if ($cache->canRestore($expiryTime))
            {
                $values = $cache->restore(array('cacheTable' => 'cacheTable'));
                self::$memoryCache = $values['cacheTable'];

                if (is_null($value))
                {
                    if (isset($values['cacheTable'][$name]))
                    {
                        return $values['cacheTable'][$name];
                    }
                    else
                    {
                        return null;
                    }
                }
            }
            else
            {
                $values = array('cacheTable' => array());
            }

            if ( !is_null($value) )
            {
                $values['cacheTable'][$name] = $value;
                $cache->addVariable('cacheTable', $values['cacheTable']);
                $cache->store(true);
                $cache->close();
            }
        }

        return null;
    }
예제 #3
0
 static function createCommonCompileTemplate()
 {
     $php = new eZPHPCreator(eZTemplateCompiler::compilationDirectory(), 'common.php');
     if ($php->exists()) {
         return;
     }
     $php->addComment("This file contains functions which are common to all compiled templates.\n\n" . 'NOTE: This file is autogenerated and should not be modified, any changes will be lost!');
     $php->addSpace();
     $php->addDefine('EZ_TEMPLATE_COMPILER_COMMON_CODE', true);
     $php->addSpace();
     $namespaceStack = array();
     $php->addCodePiece("if ( !isset( \$namespaceStack ) )\n");
     $php->addVariable('namespaceStack', $namespaceStack, eZPHPCreator::VARIABLE_ASSIGNMENT, array('spacing' => 4));
     $php->addSpace();
     $lbracket = '{';
     $rbracket = '}';
     $initText = "if ( !function_exists( 'compiledfetchvariable' ) )\n{$lbracket}\n    function compiledFetchVariable( \$vars, \$namespace, \$name )\n    {$lbracket}\n        \$exists = ( array_key_exists( \$namespace, \$vars ) and\n                    array_key_exists( \$name, \$vars[\$namespace] ) );\n        if ( \$exists )\n        {$lbracket}\n            return \$vars[\$namespace][\$name];\n        {$rbracket}\n        return null;\n    {$rbracket}\n{$rbracket}\nif ( !function_exists( 'compiledfetchtext' ) )\n{$lbracket}\n    function compiledFetchText( \$tpl, \$rootNamespace, \$currentNamespace, \$namespace, \$var )\n    {$lbracket}\n        \$text = '';\n        \$tpl->appendElement( \$text, \$var, \$rootNamespace, \$currentNamespace );\n        return \$text;\n    {$rbracket}\n{$rbracket}\nif ( !function_exists( 'compiledAcquireResource' ) )\n{$lbracket}\n    function compiledAcquireResource( \$phpScript, \$key, &\$originalText,\n                                      \$tpl, \$rootNamespace, \$currentNamespace )\n    {\n        include( '" . eZTemplateCompiler::TemplatePrefix() . "' . \$phpScript );\n        if ( isset( \$text ) )\n        {\n            \$originalText .= \$text;\n            return true;\n        }\n        return false;\n    }\n{$rbracket}\nif ( !function_exists( 'compiledfetchattribute' ) )\n{$lbracket}\n    function compiledFetchAttribute( \$value, \$attributeValue )\n    {$lbracket}\n        if ( is_object( \$value ) )\n        {$lbracket}\n            if ( method_exists( \$value, \"attribute\" ) and\n                 method_exists( \$value, \"hasattribute\" ) )\n            {$lbracket}\n                if ( \$value->hasAttribute( \$attributeValue ) )\n                {$lbracket}\n                    return \$value->attribute( \$attributeValue );\n                {$rbracket}\n            {$rbracket}\n        {$rbracket}\n        else if ( is_array( \$value ) )\n        {$lbracket}\n            if ( isset( \$value[\$attributeValue] ) )\n            {$lbracket}\n                return \$value[\$attributeValue];\n            {$rbracket}\n        {$rbracket}\n        return null;\n    {$rbracket}\n{$rbracket}\n";
     $php->addCodePiece($initText);
     $php->store(true);
 }
예제 #4
0
 /**
  * Returns the class identifier hash for the current database.
  * If it is outdated or non-existent, the method updates/generates the file
  *
  * @static
  * @since Version 4.1
  * @access protected
  * @return array Returns hash of classidentifier => classid
  */
 protected static function classIdentifiersHash()
 {
     if (self::$identifierHash === null) {
         $db = eZDB::instance();
         $dbName = md5($db->DB);
         $cacheDir = eZSys::cacheDirectory();
         $phpCache = new eZPHPCreator($cacheDir, 'classidentifiers_' . $dbName . '.php', '', array('clustering' => 'classidentifiers'));
         eZExpiryHandler::registerShutdownFunction();
         $handler = eZExpiryHandler::instance();
         $expiryTime = 0;
         if ($handler->hasTimestamp('class-identifier-cache')) {
             $expiryTime = $handler->timestamp('class-identifier-cache');
         }
         if ($phpCache->canRestore($expiryTime)) {
             $var = $phpCache->restore(array('identifierHash' => 'identifier_hash'));
             self::$identifierHash = $var['identifierHash'];
         } else {
             // Fetch identifier/id pair from db
             $query = "SELECT id, identifier FROM ezcontentclass where version=0";
             $identifierArray = $db->arrayQuery($query);
             self::$identifierHash = array();
             foreach ($identifierArray as $identifierRow) {
                 self::$identifierHash[$identifierRow['identifier']] = $identifierRow['id'];
             }
             // Store identifier list to cache file
             $phpCache->addVariable('identifier_hash', self::$identifierHash);
             $phpCache->store();
         }
     }
     return self::$identifierHash;
 }
예제 #5
0
    /**
     * Return an array with activated extensions.
     *
     * @note Default extensions are those who are loaded before a siteaccess are determined while access extensions
     *       are loaded after siteaccess is set.
     *
     * @param false|string $extensionType Decides which extension to include in the list, the follow values are possible:
     *                                    - false - Means add both default and access extensions
     *                                    - 'default' - Add only default extensions
     *                                    - 'access' - Add only access extensions
     * @param eZINI|null $siteINI Optional parameter to be able to only do change on specific instance of site.ini
     * @return array
     */
    public static function activeExtensions( $extensionType = false, eZINI $siteINI = null )
    {
        if ( $siteINI === null )
        {
            $siteINI = eZINI::instance();
        }

        $activeExtensions = array();
        if ( !$extensionType || $extensionType === 'default' )
        {
            $activeExtensions = $siteINI->variable( 'ExtensionSettings', 'ActiveExtensions' );
        }

        if ( !$extensionType || $extensionType === 'access' )
        {
            $activeExtensions = array_merge( $activeExtensions,
                                             $siteINI->variable( 'ExtensionSettings', 'ActiveAccessExtensions' ) );
        }

        if ( isset( $GLOBALS['eZActiveExtensions'] ) )
        {
            $activeExtensions = array_merge( $activeExtensions,
                                             $GLOBALS['eZActiveExtensions'] );
        }

        // return empty array as is to avoid further unneeded overhead
        if ( !isset( $activeExtensions[0] ) )
        {
            return $activeExtensions;
        }

        // return array as is if ordering is disabled to avoid cache overhead
        $activeExtensions = array_unique( $activeExtensions );
        if ( $siteINI->variable( 'ExtensionSettings', 'ExtensionOrdering' ) !== 'enabled' )
        {
            // @todo Introduce a debug setting or re use existing dev mods to check that all extensions exists
            return $activeExtensions;
        }

        $cacheIdentifier = md5( serialize( $activeExtensions ) );
        if ( isset ( self::$activeExtensionsCache[$cacheIdentifier] ) )
        {
            return self::$activeExtensionsCache[$cacheIdentifier];
        }

        // cache has to be stored by siteaccess + $extensionType
        $extensionDirectory = self::baseDirectory();
        $expiryHandler = eZExpiryHandler::instance();
        $phpCache = new eZPHPCreator( self::CACHE_DIR, "active_extensions_{$cacheIdentifier}.php" );
        $expiryTime = $expiryHandler->hasTimestamp( 'active-extensions-cache' ) ? $expiryHandler->timestamp( 'active-extensions-cache' ) : 0;

        if ( !$phpCache->canRestore( $expiryTime ) )
        {
            self::$activeExtensionsCache[$cacheIdentifier] = self::extensionOrdering( $activeExtensions );

            // Check that all extensions defined actually exists before storing cache
            foreach ( self::$activeExtensionsCache[$cacheIdentifier] as $activeExtension )
            {
                if ( !file_exists( $extensionDirectory . '/' . $activeExtension ) )
                {
                    eZDebug::writeError( "Extension '$activeExtension' does not exist, looked for directory '" . $extensionDirectory . '/' . $activeExtension . "'", __METHOD__ );
                }
            }

            $phpCache->addVariable( 'activeExtensions', self::$activeExtensionsCache[$cacheIdentifier] );
            $phpCache->store();
        }
        else
        {
            $data = $phpCache->restore( array( 'activeExtensions' => 'activeExtensions' ) );
            self::$activeExtensionsCache[$cacheIdentifier] = $data['activeExtensions'];
        }

        return self::$activeExtensionsCache[$cacheIdentifier];
    }
예제 #6
0
 static function storeCache($key, $templateFilepath)
 {
     if (!eZTemplateTreeCache::isCacheEnabled()) {
         return false;
     }
     $templateCache =& eZTemplateTreeCache::cacheTable();
     $key = eZTemplateTreeCache::internalKey($key);
     if (!isset($templateCache[$key])) {
         eZDebug::writeDebug("Template cache for key '{$key}' does not exist, cannot store cache", __METHOD__);
         return;
     }
     $cacheFileName = eZTemplateTreeCache::treeCacheFilename($key, $templateFilepath);
     $cache =& $templateCache[$key];
     $php = new eZPHPCreator(eZTemplateTreeCache::cacheDirectory(), $cacheFileName);
     $php->addVariable('eZTemplateTreeCacheCodeDate', eZTemplateTreeCache::CODE_DATE);
     $php->addSpace();
     $php->addVariable('TemplateInfo', $cache['info']);
     $php->addSpace();
     $php->addVariable('TemplateRoot', $cache['root']);
     $php->store();
 }
 /**
  * Returns an array of limitations useable by the policy system
  *
  * @return array
  */
 public static function limitations()
 {
     static $limitations;
     if ($limitations === null) {
         $db = eZDB::instance();
         $dbName = md5($db->DB);
         $cacheDir = eZSys::cacheDirectory();
         $phpCache = new eZPHPCreator($cacheDir, 'statelimitations_' . $dbName . '.php', '', array('clustering' => 'statelimitations'));
         $handler = eZExpiryHandler::instance();
         $storedTimeStamp = $handler->hasTimestamp('state-limitations') ? $handler->timestamp('state-limitations') : false;
         $expiryTime = $storedTimeStamp !== false ? $storedTimeStamp : 0;
         if ($phpCache->canRestore($expiryTime)) {
             $var = $phpCache->restore(array('state_limitations' => 'state_limitations'));
             $limitations = $var['state_limitations'];
         } else {
             $limitations = array();
             $groups = self::fetchByConditions(array("identifier NOT LIKE 'ez%'"), false, false);
             foreach ($groups as $group) {
                 $name = 'StateGroup_' . $group->attribute('identifier');
                 $limitations[$name] = array('name' => $name, 'values' => array(), 'class' => __CLASS__, 'function' => 'limitationValues', 'parameter' => array($group->attribute('id')));
             }
             $phpCache->addVariable('state_limitations', $limitations);
             $phpCache->store();
         }
         if ($storedTimeStamp === false) {
             $handler->setTimestamp('state-limitations', time());
         }
     }
     return $limitations;
 }
예제 #8
0
 function storeCache($directory = false)
 {
     if (!file_exists($directory)) {
         eZDir::mkdir($directory, false, true);
     }
     $php = new eZPHPCreator($directory, 'package.php');
     $php->addComment("Automatically created cache file for the package format\n" . "Do not modify this file");
     $php->addSpace();
     $php->addVariable('CacheCodeDate', eZPackage::CACHE_CODE_DATE);
     $php->addSpace();
     $php->addVariable('Parameters', $this->Parameters, eZPHPCreator::VARIABLE_ASSIGNMENT, array('full-tree' => true));
     $php->addVariable('InstallData', $this->InstallData, eZPHPCreator::VARIABLE_ASSIGNMENT, array('full-tree' => true));
     $php->addVariable('RepositoryPath', $this->RepositoryPath);
     $php->store();
 }
예제 #9
0
 function storeCacheObject($filename, $permissionArray)
 {
     $dir = dirname($filename);
     $file = basename($filename);
     $php = new eZPHPCreator($dir, $file);
     $php->addVariable("umap", array());
     $php->addVariable("utf8map", array());
     $php->addVariable("cmap", array());
     $php->addVariable("utf8cmap", array());
     reset($this->UnicodeMap);
     while (($key = key($this->UnicodeMap)) !== null) {
         $item = $this->UnicodeMap[$key];
         $php->addVariable("umap[{$key}]", $item);
         next($this->UnicodeMap);
     }
     reset($this->UTF8Map);
     while (($key = key($this->UTF8Map)) !== null) {
         $item = $this->UTF8Map[$key];
         if ($item == 0) {
             $php->addCodePiece("\$utf8map[0] = chr(0);\n");
         } else {
             $val = str_replace(array("\\", "'"), array("\\\\", "\\'"), $item);
             $php->addVariable("utf8map[{$key}]", $val);
         }
         next($this->UTF8Map);
     }
     reset($this->CodeMap);
     while (($key = key($this->CodeMap)) !== null) {
         $item = $this->CodeMap[$key];
         $php->addVariable("cmap[{$key}]", $item);
         next($this->CodeMap);
     }
     reset($this->UTF8CodeMap);
     while (($key = key($this->UTF8CodeMap)) !== null) {
         $item = $this->UTF8CodeMap[$key];
         if ($item == 0) {
             $php->addVariable("utf8cmap[chr(0)]", 0);
         } else {
             $val = str_replace(array("\\", "'"), array("\\\\", "\\'"), $key);
             $php->addVariable("utf8cmap['{$val}']", $item);
         }
         next($this->UTF8CodeMap);
     }
     reset($this->ReadExtraMap);
     while (($key = key($this->ReadExtraMap)) !== null) {
         $item = $this->ReadExtraMap[$key];
         $php->addVariable("read_extra[{$key}]", $item);
         next($this->ReadExtraMap);
     }
     $php->addVariable("eZCodePageCacheCodeDate", self::CACHE_CODE_DATE);
     $php->addVariable("min_char", $this->MinCharValue);
     $php->addVariable("max_char", $this->MaxCharValue);
     $php->store(true);
     if (file_exists($filename)) {
         // Store the old umask and set a new one.
         $oldPermissionSetting = umask(0);
         // Change the permission setting.
         @chmod($filename, $permissionArray['file_permission']);
         // Restore the old umask.
         umask($oldPermissionSetting);
     }
 }
 /**
  * Returns the class attribute identifier hash for the current database.
  * If it is outdated or non-existent, the method updates/generates the file
  *
  * @static
  * @since Version 4.1
  * @access protected
  * @return array Returns hash of classattributeidentifier => classattributeid
  */
 protected static function classAttributeIdentifiersHash()
 {
     if (self::$identifierHash === null) {
         $db = eZDB::instance();
         $dbName = md5($db->DB);
         $cacheDir = eZSys::cacheDirectory();
         $phpCache = new eZPHPCreator($cacheDir, 'classattributeidentifiers_' . $dbName . '.php', '', array('clustering' => 'classattridentifiers'));
         $handler = eZExpiryHandler::instance();
         $expiryTime = 0;
         if ($handler->hasTimestamp('class-identifier-cache')) {
             $expiryTime = $handler->timestamp('class-identifier-cache');
         }
         if ($phpCache->canRestore($expiryTime)) {
             $var = $phpCache->restore(array('identifierHash' => 'identifier_hash'));
             self::$identifierHash = $var['identifierHash'];
         } else {
             // Fetch identifier/id pair from db
             $query = "SELECT ezcontentclass_attribute.id as attribute_id, ezcontentclass_attribute.identifier as attribute_identifier, ezcontentclass.identifier as class_identifier\n                          FROM ezcontentclass_attribute, ezcontentclass\n                          WHERE ezcontentclass.id=ezcontentclass_attribute.contentclass_id";
             $identifierArray = $db->arrayQuery($query);
             self::$identifierHash = array();
             foreach ($identifierArray as $identifierRow) {
                 $combinedIdentifier = $identifierRow['class_identifier'] . '/' . $identifierRow['attribute_identifier'];
                 self::$identifierHash[$combinedIdentifier] = (int) $identifierRow['attribute_id'];
             }
             // Store identifier list to cache file
             $phpCache->addVariable('identifier_hash', self::$identifierHash);
             $phpCache->store();
         }
     }
     return self::$identifierHash;
 }