Example #1
0
    public function getArchiveFileName( $path, $seeds, $prefix = null, $realm = null )
    {
        $dirElements = array();
        $dirElements[] = $this->ArchiveDir;
        if ( isset( $realm ) )
        {
            $dirElements[]= $realm;
        }
        $seed = implode ( '', $seeds );
        $hash = hash( $this->hashAlgorithm, $seed );
        $multiLevelDir = eZDir::createMultiLevelPath( substr( $hash, 0 , $this->ArchiveDirLevels ), $this->ArchiveDirLevels );
        $dirElements[] = $multiLevelDir;
        $fileDirectory = implode( '/', $dirElements );
        if ( !file_exists( $fileDirectory ) )
        {
            eZDir::mkdir( $fileDirectory, false, true );
        }
        $archiveFileName = $fileDirectory . '/';
        if ( isset( $prefix ) )
        {
            $archiveFileName .= $prefix . '-';
        }
        $archiveFileName .= $hash;

        return $archiveFileName;
    }
Example #2
0
function getContributors( $pathToDir )
{
    $contribFiles = eZDir::recursiveFind( $pathToDir, "php" );
    $contributors = array();
    if ( count( $contribFiles ) )
    {
        foreach ( $contribFiles as $contribFile )
        {
            include_once( $contribFile );
            if ( !isset( $contributorSettings ) )
                continue;

            $tmpFiles = explode( ',', $contributorSettings['files'] );
            $updatedFiles = array();
            foreach ( $tmpFiles as $file )
            {
                if ( trim( $file ) )
                    $updatedFiles[] = trim( $file,"\n\r" );
            }
            $files = implode( ', ', $updatedFiles );
            $contributorSettings['files'] = $files;
            $contributors[] = $contributorSettings;
        }
    }
    return $contributors;
}
 function checkRecurrenceCondition($newsletter)
 {
     if (!$newsletter->attribute('recurrence_condition')) {
         return true;
     }
     if (0 < count($this->conditionExtensions)) {
         foreach ($this->conditionExtensions as $conditionExtension) {
             // TODO: Extend to ask multiple condition extensions to allow more complex checks
             $siteINI = eZINI::instance();
             $siteINI->loadCache();
             $extensionDirectory = $siteINI->variable('ExtensionSettings', 'ExtensionDirectory');
             $extensionDirectories = eZDir::findSubItems($extensionDirectory);
             $directoryList = eZExtension::expandedPathList($extensionDirectories, 'condition_handler');
             foreach ($directoryList as $directory) {
                 $handlerFile = $directory . '/' . strtolower($conditionExtension) . 'handler.php';
                 // we only check one extension for now
                 if ($conditionExtension === $newsletter->attribute('recurrence_condition') && file_exists($handlerFile)) {
                     include_once $handlerFile;
                     $className = $conditionExtension . 'Handler';
                     if (class_exists($className)) {
                         $impl = new $className();
                         // Ask if condition is fullfilled
                         return $impl->checkCondition($newsletter);
                     } else {
                         eZDebug::writeError("Class {$className} not found. Unable to verify recurrence condition. Blocked recurrence.");
                         return false;
                     }
                 }
             }
         }
     }
     // If we have a condition but no match we prevent the sendout
     eZDebug::writeError("Newsletter recurrence condition '" . $newsletter->attribute('recurrence_condition') . "' extension not found ");
     return false;
 }
function moveIfNeeded($oldPath, $newPath) {
    global $fileToRemove;
    
    $success = true;
    $cli = eZCLI::instance();
    
    if (!file_exists($newPath)) {
        if (!file_exists($oldPath)) {
            $cli->warning('Source file not exist : ' . $oldPath);
            return false;
        }
    
        eZDir::mkdir( dirname( $newPath ), false, true );
        $success = copy($oldPath, $newPath);
        
        $cli = eZCLI::instance();
        if ($success) {
            $fileToRemove[] = $oldPath;
            $cli->notice('Move ' . $oldPath . ' => ' . $newPath);
        } else {
            $cli->warning('Fail to move ' . $oldPath . ' => ' . $newPath);
        }
    } else {
        $fileToRemove[] = $oldPath;
    }
    
    return $success;
}
Example #5
0
 static function create($filename, $directory = false, $data = false, $atomic = false)
 {
     $filepath = $filename;
     if ($directory) {
         if (!file_exists($directory)) {
             eZDir::mkdir($directory, false, true);
             //                 eZDebugSetting::writeNotice( 'ezfile-create', "Created directory $directory", 'eZFile::create' );
         }
         $filepath = $directory . '/' . $filename;
     }
     // If atomic creation is needed we will use a temporary
     // file when writing the data, then rename it to the correct path.
     if ($atomic) {
         $realpath = $filepath;
         $dirname = dirname($filepath);
         if (strlen($dirname) != 0) {
             $dirname .= "/";
         }
         $filepath = $dirname . "ezfile-tmp." . md5($filepath . getmypid() . mt_rand());
     }
     $file = fopen($filepath, 'wb');
     if ($file) {
         //             eZDebugSetting::writeNotice( 'ezfile-create', "Created file $filepath", 'eZFile::create' );
         if ($data) {
             fwrite($file, $data);
         }
         fclose($file);
         if ($atomic) {
             eZFile::rename($filepath, $realpath);
         }
         return true;
     }
     //         eZDebugSetting::writeNotice( 'ezfile-create', "Failed creating file $filepath", 'eZFile::create' );
     return false;
 }
Example #6
0
 function eZMutex($name)
 {
     $this->Name = md5($name);
     $mutexPath = eZDir::path(array(eZSys::cacheDirectory(), 'ezmutex'));
     eZDir::mkdir($mutexPath, false, true);
     $this->FileName = eZDir::path(array($mutexPath, $this->Name));
     $this->MetaFileName = eZDir::path(array($mutexPath, $this->Name . '_meta'));
 }
 /**
  * Goes trough the directory path and removes empty directories, starting at
  * the leaf and deleting down until a non empty directory is reached.
  * If the path is not a directory, nothing will happen.
  *
  * @param string $path
  */
 public static function cleanupEmptyDirectories($path)
 {
     $dirpath = eZDir::dirpath($path);
     eZDebugSetting::writeDebug('kernel-clustering', "eZClusterFileHandler::cleanupEmptyDirectories( '{$dirpath}' )");
     if (is_dir($dirpath)) {
         eZDir::cleanupEmptyDirectories($dirpath);
     }
 }
 /**
  * Constructs a new CjwNewsletterTransportFile
  *
  * @param string $mailDir
  * @return void
  */
 public function __construct($mailDir = 'var/log/mail')
 {
     // $this->mailDir = eZSys::siteDir().eZSys::varDirectory().'/log/mail';
     if (is_dir($mailDir) or eZDir::mkdir($mailDir, false, true)) {
         $this->mailDir = $mailDir;
     } else {
         // TODO Fehlerbehandlung wenn verzeichnis nicht angelegt werden kann
     }
 }
function copyDir( $source, $destination )
{
    // Attempt to create destination dir.
    $status = eZDir::mkdir( $destination );

    // If no success: bail out.
    if ( !$status )
    {
        return false;
    }

    // Get the contents of the directory.
    $entries = getDirEntries( $source );

    // Bail if contents is unavailable.
    if ( $entries == false )
    {
        return false;
    }
    // Else: contents is OK:
    else
    {
        // Copy each and every entry:
        foreach ( $entries as $entry )
        {
            if ( $entry )
            {
                $from = "$source/$entry";
                $to   = "$destination/$entry";

                // Is this a directory? -> special case.
                if ( is_dir( $from ) )
                {
                    $status = copyDir( $from, $to );
                    if (!$status)
                    {
                        return false;
                    }
                }
                // Else: simple file case.
                else
                {
                    $status = copy( $from, $to );
                    if (!$status)
                    {
                        return false;
                    }
                }
            }
        }

    }

    // Phew: if we got this far then everything is OK.
    return true;
}
 /**
  * Creates a new cache storage for a given location through eZ Publish cluster mechanism
  * Options can contain the 'ttl' ( Time-To-Life ). This is per default set
  * to 1 day.
  *
  * @param string $location Path to the cache location inside the cluster
  * @param array(string=>string) $options Options for the cache.
  */
 public function __construct($location, $options = array())
 {
     $path = eZSys::cacheDirectory() . '/rest/' . $location;
     if (!file_exists($path)) {
         if (!eZDir::mkdir($path, false, true)) {
             throw new ezcBaseFilePermissionException($path, ezcBaseFileException::WRITE, 'Cache location is not writeable.');
         }
     }
     parent::__construct($path);
     $this->properties['options'] = new ezpCacheStorageClusterOptions($options);
 }
/**
 * eZExtension::nameFromPath( __FILE__ ) executed in any file of an extension
 * can help you to find the path to additional resources
 *
 * @param $path Path to check.
 * @return Name of the extension a path belongs to.
 * @deprecated Since 4.3, use {@link eZExtension::nameFromPath()} instead
 */
function nameFromPath($path)
{
    $path = eZDir::cleanPath($path);
    $base = eZExtension::baseDirectory() . '/';
    $base = preg_quote($base, '/');
    $pattern = '/' . $base . '([^\\/]+)/';
    if (preg_match($pattern, $path, $matches)) {
        return $matches[1];
    } else {
        false;
    }
}
 function store($sub_dir = false, $suffix = false, $mimeData = false)
 {
     if (!$this->IsTemporary) {
         eZDebug::writeError("Cannot store non temporary file: " . $this->Filename, "eZHTTPFile");
         return false;
     }
     $this->IsTemporary = false;
     $ini = eZINI::instance();
     //         $storage_dir = $ini->variable( "FileSettings", "VarDir" ) . '/' . $ini->variable( "FileSettings", "StorageDir" );
     $storage_dir = eZSys::storageDirectory();
     if ($sub_dir !== false) {
         $dir = $storage_dir . "/{$sub_dir}/";
     } else {
         $dir = $storage_dir . "/";
     }
     if ($mimeData) {
         $dir = $mimeData['dirpath'];
     }
     if (!$mimeData) {
         $dir .= $this->MimeCategory;
     }
     if (!file_exists($dir)) {
         if (!eZDir::mkdir($dir, false, true)) {
             return false;
         }
     }
     $suffixString = false;
     if ($suffix != false) {
         $suffixString = ".{$suffix}";
     }
     if ($mimeData) {
         $dest_name = $mimeData['url'];
     } else {
         $dest_name = $dir . "/" . md5(basename($this->Filename) . microtime() . mt_rand()) . $suffixString;
     }
     if (!move_uploaded_file($this->Filename, $dest_name)) {
         eZDebug::writeError("Failed moving uploaded file " . $this->Filename . " to destination {$dest_name}");
         unlink($dest_name);
         $ret = false;
     } else {
         $ret = true;
         $this->Filename = $dest_name;
         $perm = $ini->variable("FileSettings", "StorageFilePermissions");
         $oldumask = umask(0);
         chmod($dest_name, octdec($perm));
         umask($oldumask);
         // Write log message to storage.log
         $storageDir = $dir . "/";
         eZLog::writeStorageLog(basename($this->Filename), $storageDir);
     }
     return $ret;
 }
    /**
     * @return mixed
     */
    public function getCssFilePath()
    {
        if ( is_null($this->_cssFilePath) )
        {
            $cssDirectory = eZSys::cacheDirectory() . '/css';
            $this->_cssFilePath = $cssDirectory .'/' . md5( $this->getLessFilePath() ) . '.css';
            if ( !file_exists( $cssDirectory ))
            {
                eZDir::mkdir( $cssDirectory );
            }
        }

        return $this->_cssFilePath;
    }
 public function tearDown()
 {
     // restore the previous file handler
     if ($this->previousFileHandler !== null) {
         $fileINI = eZINI::instance('file.ini');
         $fileINI->setVariable('ClusteringSettings', 'FileHandler', $this->previousFileHandler);
         $this->previousFileHandler = null;
         eZClusterFileHandler::resetHandler();
     }
     if ($this->haveToRemoveDFSPath) {
         eZDir::recursiveDelete($this->DFSPath);
     }
     parent::tearDown();
 }
Example #15
0
 function add($packageType, $package, $cli, $parameters)
 {
     $siteINI = eZINI::instance();
     $extensionDir = $siteINI->variable('ExtensionSettings', 'ExtensionDirectory');
     //$cli->output( var_export( $parameters, true ) );
     foreach ($parameters as $scriptItem) {
         $cli->output('adding install script ' . $cli->style('dir') . $scriptItem['filename'] . $cli->style('dir-end'));
         $sourceDir = $scriptItem['source-directory'];
         $targetDir = $package->path() . '/' . $scriptItem['sub-directory'];
         eZDir::mkdir($targetDir, false, true);
         eZDir::copy($sourceDir, $targetDir, false);
         $package->appendInstall('ezinstallscript', false, false, true, $scriptItem['filename'], $scriptItem['sub-directory'], array('content' => false));
     }
 }
 /**
  * tmp dir for mail parser
  *    ezvardir / cjw_newsletter/tmp/
  * @return string dirname
  */
 public function getTmpDir($createDirIfNotExists = true)
 {
     $varDir = eZSys::varDirectory();
     // $dir = $varDir . "/cjw_newsletter/tmp/";
     $dir = eZDir::path(array($varDir, 'cjw_newsletter', 'tmp'));
     $fileSep = eZSys::fileSeparator();
     $filePath = $dir . $fileSep;
     if ($createDirIfNotExists === true) {
         if (!file_exists($filePath)) {
             eZDir::mkdir($filePath, false, true);
         }
     }
     return $filePath;
 }
function copyFilesFromDB($excludeScopes, $remove)
{
    global $cli, $fileHandler;
    $cli->output("Exporting files from database:");
    $filePathList = $fileHandler->getFileList($excludeScopes, true);
    foreach ($filePathList as $filePath) {
        $cli->output("- " . $filePath);
        eZDir::mkdir(dirname($filePath), false, true);
        $fileHandler->fileFetch($filePath);
        if ($remove) {
            $fileHandler->fileDelete($filePath);
        }
    }
    $cli->output();
}
 public static function clearCache()
 {
     eZDebug::writeNotice("Clear calendar taxonomy cache", __METHOD__);
     $ini = eZINI::instance();
     if ($ini->hasVariable('SiteAccessSettings', 'RelatedSiteAccessList') && ($relatedSiteAccessList = $ini->variable('SiteAccessSettings', 'RelatedSiteAccessList'))) {
         if (!is_array($relatedSiteAccessList)) {
             $relatedSiteAccessList = array($relatedSiteAccessList);
         }
         $relatedSiteAccessList[] = $GLOBALS['eZCurrentAccess']['name'];
         $siteAccesses = array_unique($relatedSiteAccessList);
     } else {
         $siteAccesses = $ini->variable('SiteAccessSettings', 'AvailableSiteAccessList');
     }
     $cacheBaseDir = eZDir::path(array(eZSys::cacheDirectory(), self::cacheDirectory()));
     $fileHandler = eZClusterFileHandler::instance();
     $fileHandler->fileDeleteByDirList($siteAccesses, $cacheBaseDir, '');
     $fileHandler = eZClusterFileHandler::instance($cacheBaseDir);
     $fileHandler->purge();
 }
Example #19
0
    /**
     * Creates a new cache storage for a given location through eZ Publish cluster mechanism
     * Options can contain the 'ttl' ( Time-To-Life ). This is per default set
     * to 1 day.
     * @param string $location Path to the cache location inside the cluster
     * @param array(string=>string) $options Options for the cache.
     */
    public function __construct( $location, $options = array() )
    {
        $apiName = ezpRestPrefixFilterInterface::getApiProviderName();
        $apiVersion = ezpRestPrefixFilterInterface::getApiVersion();
        $location = eZSys::cacheDirectory().'/rest/'.$location;
        if( !file_exists( $location ) )
        {
            if( !eZDir::mkdir( $location, false, true ) )
            {
                throw new ezcBaseFilePermissionException(
                    $location,
                    ezcBaseFileException::WRITE,
                    'Cache location is not writeable.'
                );
            }
        }

        parent::__construct( $location );
        $this->properties['options'] = new ezpCacheStorageClusterOptions( $options );
    }
 /**
  *
  * http://maps.googleapis.com/maps/api/staticmap?zoom=13&size=600x300&maptype=roadmap&markers=color:blue|{first_set( $attribute.content.latitude, '0.0')},{first_set( $attribute.content.longitude, '0.0')}
  * @param array $parameters
  * @param eZContentObjectAttribute $attribute
  * @return string
  */
 public static function gmapStaticImage(array $parameters, eZContentObjectAttribute $attribute, $extraCacheFileNameStrings = array())
 {
     $cacheParameters = array(serialize($parameters));
     $cacheFile = $attribute->attribute('id') . implode('-', $extraCacheFileNameStrings) . '-' . md5(implode('-', $cacheParameters)) . '.cache';
     $extraPath = eZDir::filenamePath($attribute->attribute('id'));
     $cacheDir = eZDir::path(array(eZSys::cacheDirectory(), 'gmap_static', $extraPath));
     // cacenllo altri file con il medesimo attributo
     $fileList = array();
     $deleteItems = eZDir::recursiveList($cacheDir, $cacheDir, $fileList);
     foreach ($fileList as $file) {
         if ($file['type'] == 'file' && $file['name'] !== $cacheFile) {
             unlink($file['path'] . '/' . $file['name']);
         }
     }
     $cachePath = eZDir::path(array($cacheDir, $cacheFile));
     $args = compact('parameters', 'attribute');
     $cacheFile = eZClusterFileHandler::instance($cachePath);
     $result = $cacheFile->processCache(array('OCOperatorsCollectionsTools', 'gmapStaticImageRetrieve'), array('OCOperatorsCollectionsTools', 'gmapStaticImageGenerate'), null, null, $args);
     return $result;
 }
Example #21
0
 /**
  * Logs the string $logString to the logfile webservices.log
  * in the current log directory (usually var/log).
  * If logging is disabled, nothing is done.
  *
  * In dev mode, also writes to the eZP logs to ease debugging (this happens
  * regardless of the logging level set for the extension itself)
  */
 static function appendLogEntry($logString, $debuglevel)
 {
     $ini = eZINI::instance('site.ini');
     if ($ini->variable('DebugSettings', 'DebugOutput') == 'enabled' && $ini->variable('TemplateSettings', 'DevelopmentMode') == 'enabled') {
         switch ($debuglevel) {
             case 'info':
             case 'notice':
                 eZDebug::writeNotice($logString, 'ggwebservices');
                 break;
             case 'debug':
                 eZDebug::writeDebug($logString, 'ggwebservices');
                 break;
             case 'warning':
                 eZDebug::writeWarning($logString, 'ggwebservices');
                 break;
             case 'error':
             case 'critical':
                 eZDebug::writeError($logString, 'ggwebservices');
                 break;
         }
     }
     if (!self::isLoggingEnabled($debuglevel)) {
         return false;
     }
     $varDir = eZSys::varDirectory();
     $logDir = 'log';
     $logName = 'webservices.log';
     $fileName = $varDir . '/' . $logDir . '/' . $logName;
     if (!file_exists($varDir . '/' . $logDir)) {
         //include_once( 'lib/ezfile/classes/ezdir.php' );
         eZDir::mkdir($varDir . '/' . $logDir, 0775, true);
     }
     if ($logFile = fopen($fileName, 'a')) {
         $nowTime = date("Y-m-d H:i:s : ");
         $text = $nowTime . $logString;
         /*if ( $label )
           $text .= ' [' . $label . ']';*/
         fwrite($logFile, $text . "\n");
         fclose($logFile);
     }
 }
Example #22
0
 static function writeStorageLog($name, $dir = false)
 {
     $ini = eZINI::instance();
     $varDir = $ini->variable('FileSettings', 'VarDir');
     $logDir = $ini->variable('FileSettings', 'LogDir');
     $logName = 'storage.log';
     $fileName = $varDir . '/' . $logDir . '/' . $logName;
     $oldumask = @umask(0);
     clearstatcache(true, $fileName);
     $fileExisted = file_exists($fileName);
     if ($fileExisted and filesize($fileName) > eZLog::maxLogSize()) {
         if (eZLog::rotateLog($fileName)) {
             $fileExisted = false;
         }
     } else {
         if (!$fileExisted and !file_exists($varDir . '/' . $logDir)) {
             eZDir::mkdir($varDir . '/' . $logDir, false, true);
         }
     }
     if ($dir !== false) {
         $dir = preg_replace("#/\$#", "", $dir);
         $dir .= "/";
     } else {
         $dir = "";
     }
     $logFile = @fopen($fileName, "a");
     if ($logFile) {
         $time = strftime("%b %d %Y %H:%M:%S", strtotime("now"));
         $logMessage = "[ " . $time . " ] [" . $dir . $name . "]\n";
         @fwrite($logFile, $logMessage);
         @fclose($logFile);
         if (!$fileExisted) {
             $permissions = octdec($ini->variable('FileSettings', 'LogFilePermissions'));
             @chmod($fileName, $permissions);
         }
         @umask($oldumask);
     } else {
         eZDebug::writeError('Couldn\'t create the log file "' . $fileName . '"', __METHOD__);
     }
 }
Example #23
0
 /**
  * Constructs an empty CjwNewsletterLog instance
  *
  * This constructor is private as this class should be used as a
  * singleton. Use the getInstance() method instead to get an ezcLog instance.
  *
  * @param boolean $isCliMode
  * @return void
  */
 protected function __construct($isCliMode = false)
 {
     if ($isCliMode === true) {
         $this->isCliMode = true;
     }
     $this->reset();
     $log = $this;
     // "var/log"
     $ini = eZINI::instance();
     $varDir = eZSys::varDirectory();
     $iniLogDir = $ini->variable('FileSettings', 'LogDir');
     $permissions = octdec($ini->variable('FileSettings', 'LogFilePermissions'));
     $logDir = eZDir::path(array($varDir, $iniLogDir));
     $logNamePostfix = '';
     // Debug enabled
     $cjwNewsletterIni = eZINI::instance('cjw_newsletter.ini');
     if ($cjwNewsletterIni->variable('DebugSettings', 'Debug') == 'enabled') {
         $this->debug = true;
     }
     if ($isCliMode === true) {
         $logNamePostfix = 'cli_';
     }
     // Create the writers
     $generalFilename = "cjw_newsletter_" . $logNamePostfix . "general.log";
     $errorFilename = "cjw_newsletter_" . $logNamePostfix . "error.log";
     $writeAll = new ezcLogUnixFileWriter($logDir, $generalFilename);
     $writeErrors = new ezcLogUnixFileWriter($logDir, $errorFilename);
     // Check file permissions
     foreach (array($generalFilename, $errorFilename) as $file) {
         $path = eZDir::path(array($logDir, $file));
         if (substr(decoct(fileperms($path)), 2) !== $permissions) {
             @chmod($path, $permissions);
         }
     }
     $errorFilter = new ezcLogFilter();
     $errorFilter->severity = ezcLog::ERROR;
     $log->getMapper()->appendRule(new ezcLogFilterRule($errorFilter, $writeErrors, true));
     $log->getMapper()->appendRule(new ezcLogFilterRule(new ezcLogFilter(), $writeAll, true));
 }
    /**
     * @param string $cluster
     * @param string $path
     * @param bool $clusterizedPath
     * @return bool|string
     */
    public static function clusterFilePath($cluster, $path, $clusterizedPath = true)
    {
        if (!$cluster)
        {
            $cluster = 'default';
        }

        $staticPath = eZDir::path(array(StaticData::directory(), $cluster, $path));
        $fullPath   = self::fileExists($staticPath);

        if ($fullPath)
        {
            return $clusterizedPath ? $fullPath : $staticPath;
        }

        if ($cluster != 'default')
        {
            return self::clusterFilePath('default', $path);
        }

        return false;
    }
Example #25
0
 public function getSettings()
 {
     // Copied from settings/view
     $rootDir = 'settings';
     $iniFiles = eZDir::recursiveFindRelative($rootDir, '', '.ini');
     // find all .ini files in active extensions
     // Note: is this the same algorithm used by ezini? mmm...
     foreach (eZINI::globalOverrideDirs() as $iniDataSet) {
         $iniPath = $iniDataSet[1] ? $iniDataSet[0] : 'settings/' . $iniDataSet[0];
         $iniFiles = array_merge($iniFiles, eZDir::recursiveFindRelative($iniPath, '', '.ini'));
         $iniFiles = array_merge($iniFiles, eZDir::recursiveFindRelative($iniPath, '', '.ini.append.php'));
     }
     // extract all .ini files without path
     $iniFiles = preg_replace('%.*/%', '', $iniFiles);
     // remove *.ini[.append.php] from file name
     $iniFiles = preg_replace('%\\.ini.*%', '.ini', $iniFiles);
     $iniFiles = array_unique($iniFiles);
     sort($iniFiles);
     $siteIni = null;
     foreach ($iniFiles as $key => $ini) {
         if ($this->currentSiteAccess != '' && $GLOBALS['eZCurrentAccess']['name'] !== $this->currentSiteAccess) {
             // create a site ini instance using $useLocalOverrides
             if ($siteIni === null) {
                 $siteIni = eZSiteAccess::getIni($this->currentSiteAccess, 'site.ini');
             }
             // load settings file with $useLocalOverrides = true
             $iniFile = new eZINI($ini, 'settings', null, false, true, false, false, false);
             $iniFile->setOverrideDirs($siteIni->overrideDirs(false));
             $iniFile->load();
         } else {
             $iniFile = new eZINI($ini);
         }
         $iniFiles[$ini] = $iniFile->groups();
         unset($iniFiles[$key]);
     }
     return $iniFiles;
 }
 /**
  * Clears all static cache for a site
  * Removers all static cache, but not the static cache directory itself.
  *
  * Currently, this function only supports 'combined_host_url'
  *
  */
 static function clearStaticCache()
 {
     $ini = eZINI::instance('staticcache.ini');
     $storageDir = $ini->variable('CacheSettings', 'StaticStorageDir');
     // Check that we have combined_host_url hostmatching
     $siteIni = eZINI::instance();
     $matchType = $siteIni->variable('SiteAccessSettings', 'MatchOrder');
     if ($matchType !== 'combined_host_url') {
         throw new Exception('combined_host_url required for this workflow');
     }
     global $eZCurrentAccess;
     $siteAccess = $eZCurrentAccess['name'];
     //Get hostname part from siteaccess name (exclude for instance _eng or _admin)
     if (strpos($siteAccess, '_') === false) {
         $hostName = $siteAccess;
     } else {
         $hostName = substr($siteAccess, 0, strpos($siteAccess, '_'));
     }
     $staticCacheDir = eZDir::path(array($storageDir, $hostName));
     // Sanity checking, make sure we don't remove everyones static cache.
     if ($staticCacheDir == $storageDir) {
         throw new Exception("Failed to find correct static cache directory : {$staticCacheDir} \n");
     }
     $dirs = scandir($staticCacheDir);
     foreach ($dirs as $dir) {
         if ($dir !== '.' && $dir !== '..') {
             $fullPath = eZDir::path(array($staticCacheDir, $dir));
             if (is_dir($fullPath)) {
                 ezcBaseFile::removeRecursive($fullPath);
             } else {
                 if (!unlink($fullPath)) {
                     throw new ezsfFileCouldNotRemoveException($fullPath);
                 }
             }
         }
     }
 }
Example #27
0
}
if (count($missingFileList) > 0 or count($exportMissingFileList) > 0 or count($fileList) > 0 or count($conflictFileList) > 0) {
    if (count($fileList) > 0) {
        foreach ($fileList as $file) {
            print '? ' . $file . "\n";
        }
    }
    if (count($missingFileList) > 0) {
        foreach ($missingFileList as $file) {
            print '! ' . $file . "\n";
        }
    }
    if (count($exportMissingFileList) > 0) {
        foreach ($exportMissingFileList as $file) {
            print 'A ' . $file . "\n";
        }
    }
    if (count($conflictFileList) > 0) {
        foreach ($conflictFileList as $file) {
            print 'C ' . $file . "\n";
        }
    }
    $script->setExitCode(1);
}
if (!$options['no-verify-branches']) {
    // Cleanup any exports
    if (file_exists($exportPath)) {
        eZDir::recursiveDelete($exportPath, false);
    }
}
$script->shutdown();
Example #28
0
{
    $tpl->setVariable( 'settings', false );
    $tpl->setVariable( 'block_count', false );
    $tpl->setVariable( 'setting_count', false );
    $tpl->setVariable( 'ini_file', false );
}

$rootDir = 'settings';
$iniFiles = eZDir::recursiveFindRelative( $rootDir, '', '.ini' );

// find all .ini files in active extensions
foreach ( eZINI::globalOverrideDirs() as $iniDataSet )
{
    $iniPath = $iniDataSet[1] ? $iniDataSet[0] : 'settings/' . $iniDataSet[0];
    $iniFiles = array_merge( $iniFiles, eZDir::recursiveFindRelative( $iniPath, '', '.ini' ) );
    $iniFiles = array_merge( $iniFiles, eZDir::recursiveFindRelative( $iniPath, '', '.ini.append.php' ) );
}

// extract all .ini files without path
$iniFiles = preg_replace('%.*/%', '', $iniFiles );
// remove *.ini[.append.php] from file name
$iniFiles = preg_replace('%\.ini.*%', '.ini', $iniFiles );
sort( $iniFiles );

$tpl->setVariable( 'ini_files', array_unique( $iniFiles ) );
$tpl->setVariable( 'siteaccess_list', $siteAccessList );
$tpl->setVariable( 'current_siteaccess', $currentSiteAccess );

$Result = array();
$Result['content'] = $tpl->fetch( 'design:settings/view.tpl' );
$Result['path'] = array( array( 'text' => ezpI18n::tr( 'settings/view', 'Settings' ),
Example #29
0
function downloadPackages($packageList, $packageURL, $packageDir, $packageRepository)
{
    global $cli;
    showMessage2("Configuring...");
    if (!is_array($packageList) || count($packageList) == 0) {
        showError("Package list is empty. Aborting...");
    }
    // 1. check if packages specified in $packageList exist in $packageRepository(means already downloaded and imported).
    //    if yes - ask user to do download or not. If not - go out
    foreach (array_keys($packageList) as $k) {
        $packageName = $packageList[$k];
        $package = eZPackage::fetch($packageName);
        if (is_object($package)) {
            global $autoMode;
            if ($autoMode == 'on') {
                $action = 'y';
            } else {
                $action = getUserInput("Package '{$packageName}' already imported. Import it anyway? [y/n]: ");
            }
            if (strpos($action, 'n') === 0) {
                unset($packageList[$k]);
            } else {
                eZDir::recursiveDelete(eZPackage::repositoryPath() . "/{$packageRepository}/{$packageName}");
            }
        }
    }
    if (count($packageList) == 0) {
        // all packages are imported.
        return true;
    }
    // 2. check $packgesList exists in $packageDir(means packages downloaded but not imported)
    //    if yes - ask user to import or not. If not - go out
    if (!checkDir($packageDir)) {
        return false;
    }
    $downloadPackageList = array();
    foreach ($packageList as $packageName) {
        if (file_exists("{$packageDir}/{$packageName}.ezpkg")) {
            global $autoMode;
            if ($autoMode == 'on') {
                $action = 'y';
            } else {
                $action = getUserInput("Package '{$packageName}' already downloaded. Download it anyway? [y/n]: ");
            }
            if (strpos($action, 'n') === 0) {
                continue;
            }
        }
        $downloadPackageList[] = $packageName;
    }
    //
    // download
    //
    showMessage2("Downloading...");
    if (count($downloadPackageList) > 0) {
        // TODO: using 'eZStepSiteTypes' is hack.
        //       need to exclude 'downloadFile' from that class.
        $tpl = false;
        $http = false;
        $ini = false;
        $persistenceList = false;
        $downloader = new eZStepSiteTypes($tpl, $http, $ini, $persistenceList);
        foreach ($downloadPackageList as $packageName) {
            showMessage("{$packageName}");
            $archiveName = $downloader->downloadFile("{$packageURL}/{$packageName}.ezpkg", $packageDir);
            if ($archiveName === false) {
                showError("download error - " . $downloader->ErrorMsg);
            }
        }
    }
    //
    // import
    //
    showMessage2("Importing...");
    foreach ($packageList as $packageName) {
        showMessage("{$packageName}");
        $package = eZPackage::import("{$packageDir}/{$packageName}.ezpkg", $packageName, false, $packageRepository);
        if (!is_object($package)) {
            showError("Faild to import '{$packageName}' package: err = {$package}");
        }
    }
    return true;
}
Example #30
0
 static function printReport($newWindow = false, $as_html = true, $returnReport = false, $allowedDebugLevels = false, $useAccumulators = true, $useTiming = true, $useIncludedFiles = false)
 {
     if (!self::isDebugEnabled()) {
         return null;
     }
     $debug = self::instance();
     $report = $debug->printReportInternal($as_html, $returnReport & $newWindow, $allowedDebugLevels, $useAccumulators, $useTiming, $useIncludedFiles);
     if ($newWindow == true) {
         $debugFilePath = eZDir::path(array(eZSys::varDirectory(), 'cache', 'debug.html'));
         $debugFileURL = $debugFilePath;
         eZURI::transformURI($debugFileURL, true);
         print "\n<script type='text/javascript'>\n<!--\n\n(function()\n{\n    var debugWindow;\n\n    if  (navigator.appName == \"Microsoft Internet Explorer\")\n    {\n        //Microsoft Internet Explorer\n        debugWindow = window.open( '{$debugFileURL}', 'ezdebug', 'width=500,height=550,status,scrollbars,resizable,screenX=0,screenY=20,left=20,top=40');\n        debugWindow.document.close();\n        debugWindow.location.reload();\n    }\n    else if (navigator.appName == \"Opera\")\n    {\n        //Opera\n        debugWindow = window.open( '', 'ezdebug', 'width=500,height=550,status,scrollbars,resizable,screenX=0,screenY=20,left=20,top=40');\n        debugWindow.location.href=\"{$debugFileURL}\";\n        debugWindow.navigate(\"{$debugFileURL}\");\n    }\n    else\n    {\n        //Mozilla, Firefox, etc.\n        debugWindow = window.open( '', 'ezdebug', 'width=500,height=550,status,scrollbars,resizable,screenX=0,screenY=20,left=20,top=40');\n        debugWindow.document.location.href=\"{$debugFileURL}\";\n    };\n})();\n\n// -->\n</script>\n";
         $header = "<!DOCTYPE html><html><head><title>eZ debug</title></head><body>";
         $footer = "</body></html>";
         $fullPage = ezpEvent::getInstance()->filter('response/output', $header . $report . $footer);
         file_put_contents($debugFilePath, $fullPage);
     } else {
         if ($returnReport) {
             return $report;
         }
     }
     return null;
 }