Exemplo n.º 1
0
/**
 * Checks if the installation is valid and returns a module redirect if required.
 * If CheckValidity in SiteAccessSettings is false then no check is done.
 *
 * @deprecated As of 4.4, moved to index.php for now
 * @param array $siteBasics
 * @param eZURI $uri
 */
function eZCheckValidity( array &$siteBasics, eZURI $uri )
{
    eZDebug::writeStrict( 'Function eZCheckValidity() has been deprecated in 4.4', 'Deprecation' );
    $ini = eZINI::instance();
    $checkValidity = ( $ini->variable( "SiteAccessSettings", "CheckValidity" ) == "true" );
    $check = null;
    if ( $checkValidity )
    {
        $check = array( "module" => "setup",
                        'function' => 'init' );
        // Turn off some features that won't bee needed yet
//        $siteBasics['policy-check-required'] = false;
        $siteBasics['policy-check-omit-list'][] = 'setup';
        $siteBasics['url-translator-allowed'] = false;
        $siteBasics['show-page-layout'] = $ini->variable( 'SetupSettings', 'PageLayout' );
        $siteBasics['validity-check-required'] = true;
        $siteBasics['user-object-required'] = false;
        $siteBasics['session-required'] = false;
        $siteBasics['db-required'] = false;
        $siteBasics['no-cache-adviced'] = false;
        $siteBasics['site-design-override'] = $ini->variable( 'SetupSettings', 'OverrideSiteDesign' );
        $access = array( 'name' => 'setup',
                         'type' => eZSiteAccess::TYPE_URI );
        $access = eZSiteAccess::change( $access );

        eZTranslatorManager::enableDynamicTranslations();
    }
    return $check;
}
Exemplo n.º 2
0
 public function __construct(array $settings = array())
 {
     $this->settings = $settings + array('use-cache-headers' => true, 'max-age' => 86400, 'siteaccess' => null, 'use-exceptions' => false);
     unset($settings);
     require_once __DIR__ . '/treemenu_functions.php';
     $this->setUseExceptions($this->settings['use-exceptions']);
     header('X-Powered-By: ' . eZPublishSDK::EDITION . ' (index_treemenu)');
     if ($this->settings['use-cache-headers'] === true) {
         define('MAX_AGE', $this->settings['max-age']);
         if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE'])) {
             header($_SERVER['SERVER_PROTOCOL'] . ' 304 Not Modified');
             header('Expires: ' . gmdate('D, d M Y H:i:s', time() + MAX_AGE) . ' GMT');
             header('Cache-Control: max-age=' . MAX_AGE);
             header('Last-Modified: ' . gmdate('D, d M Y H:i:s', strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE'])) . ' GMT');
             header('Pragma: ');
             exit;
         }
     }
     // Tweaks ini filetime checks if not defined!
     // This makes ini system not check modified time so
     // that index_treemenu.php can assume that index.php does
     // this regular enough, set in config.php to override.
     if (!defined('EZP_INI_FILEMTIME_CHECK')) {
         define('EZP_INI_FILEMTIME_CHECK', false);
     }
     eZExecution::addFatalErrorHandler(function () {
         header($_SERVER['SERVER_PROTOCOL'] . ' 500 Internal Server Error');
     });
     eZDebug::setHandleType(eZDebug::HANDLE_FROM_PHP);
     // Trick to get eZSys working with a script other than index.php (while index.php still used in generated URLs):
     $_SERVER['SCRIPT_FILENAME'] = str_replace('/index_treemenu.php', '/index.php', $_SERVER['SCRIPT_FILENAME']);
     $_SERVER['PHP_SELF'] = str_replace('/index_treemenu.php', '/index.php', $_SERVER['PHP_SELF']);
     $ini = eZINI::instance();
     $timezone = $ini->variable('TimeZoneSettings', 'TimeZone');
     if ($timezone) {
         putenv("TZ={$timezone}");
     }
     // init uri code
     $GLOBALS['eZGlobalRequestURI'] = eZSys::serverVariable('REQUEST_URI');
     eZSys::init('index.php', $ini->variable('SiteAccessSettings', 'ForceVirtualHost') === 'true');
     $this->uri = eZURI::instance(eZSys::requestURI());
     $GLOBALS['eZRequestedURI'] = $this->uri;
     // Check for extension
     eZExtension::activateExtensions('default');
     // load siteaccess
     // Use injected siteaccess if available or match it internally.
     $this->access = isset($this->settings['siteaccess']) ? $this->settings['siteaccess'] : eZSiteAccess::match($this->uri, eZSys::hostname(), eZSys::serverPort(), eZSys::indexFile());
     eZSiteAccess::change($this->access);
     // Check for new extension loaded by siteaccess
     eZExtension::activateExtensions('access');
 }
    /**
     * Parses command line arguments and kicks off the processing if required
     * arguments are passed.
     */
    public function process()
    {
        try
        {
            $this->input->process();
        }
        catch ( ezcConsoleOptionException $e )
        {
            if ( $this->helpOption->value === true )
            {
                $this->cliHelp();
                return;
            }

            echo $e->getMessage() . "\n";
            return;
        }

        if ( $this->helpOption->value === true )
        {
            $this->cliHelp();
            return;
        }

        if ( $this->siteAccessOption->value )
        {
            $access = array( 'name' => $this->siteAccessOption->value,
                             'type' => eZSiteAccess::TYPE_STATIC );
            eZSiteAccess::change( $access );
        }

        $this->_process(
            $this->dryRunOption->value,
            $this->subtreeNodeOption->value,
            $this->actionOption->value
        );
    }
Exemplo n.º 4
0
// init uri code
$GLOBALS['eZGlobalRequestURI'] = eZSys::serverVariable( 'REQUEST_URI' );
eZSys::init( 'index.php', $ini->variable( 'SiteAccessSettings', 'ForceVirtualHost' ) === 'true' );
$uri = eZURI::instance( eZSys::requestURI() );

$GLOBALS['eZRequestedURI'] = $uri;

// Check for extension
eZExtension::activateExtensions( 'default' );

// load siteaccess
$access = eZSiteAccess::match( $uri,
                      eZSys::hostname(),
                      eZSys::serverPort(),
                      eZSys::indexFile() );
$access = eZSiteAccess::change( $access );
$GLOBALS['eZCurrentAccess'] = $access;

// Check for new extension loaded by siteaccess
eZExtension::activateExtensions( 'access' );

$db = eZDB::instance();
if ( $db->isConnected() )
{
    eZSession::start();
}
else
{
    exitWithInternalError();
    return;
}
Exemplo n.º 5
0
 /**
  * @param array $settings
  * @param null $responseWriterClass Name of the ezpRestHttpResponseWriter implementation to use during request
  */
 public function __construct(array $settings = array(), $responseWriterClass = null)
 {
     $this->responseWriterClass = $responseWriterClass;
     if (isset($settings['injected-settings'])) {
         $injectedSettings = array();
         foreach ($settings['injected-settings'] as $keySetting => $injectedSetting) {
             list($file, $section, $setting) = explode('/', $keySetting);
             $injectedSettings[$file][$section][$setting] = $injectedSetting;
         }
         // Those settings override anything else in local .ini files and their overrides
         eZINI::injectSettings($injectedSettings);
     }
     if (isset($settings['injected-merge-settings'])) {
         $injectedSettings = array();
         foreach ($settings['injected-merge-settings'] as $keySetting => $injectedSetting) {
             list($file, $section, $setting) = explode('/', $keySetting);
             $injectedSettings[$file][$section][$setting] = $injectedSetting;
         }
         // Those settings override anything else in local .ini files and their overrides
         eZINI::injectMergeSettings($injectedSettings);
     }
     $this->settings = $settings + array('use-cache-headers' => true, 'max-age' => 86400, 'siteaccess' => null, 'use-exceptions' => false);
     unset($settings, $injectedSettings, $file, $section, $setting, $keySetting, $injectedSetting);
     // lazy loaded database driver
     include __DIR__ . '/lazy.php';
     $this->setUseExceptions($this->settings['use-exceptions']);
     // Tweaks ini filetime checks if not defined!
     // This makes ini system not check modified time so
     // that index_treemenu.php can assume that index.php does
     // this regular enough, set in config.php to override.
     if (!defined('EZP_INI_FILEMTIME_CHECK')) {
         define('EZP_INI_FILEMTIME_CHECK', false);
     }
     eZExecution::addFatalErrorHandler(function () {
         if (!headers_sent()) {
             header($_SERVER['SERVER_PROTOCOL'] . ' 500 Internal Server Error');
         }
     });
     eZDebug::setHandleType(eZDebug::HANDLE_FROM_PHP);
     // Trick to get eZSys working with a script other than index.php (while index.php still used in generated URLs):
     $_SERVER['SCRIPT_FILENAME'] = str_replace('/index_rest.php', '/index.php', $_SERVER['SCRIPT_FILENAME']);
     $_SERVER['PHP_SELF'] = str_replace('/index_rest.php', '/index.php', $_SERVER['PHP_SELF']);
     $ini = eZINI::instance();
     $timezone = $ini->variable('TimeZoneSettings', 'TimeZone');
     if ($timezone) {
         putenv("TZ={$timezone}");
     }
     eZDebug::setHandleType(eZDebug::HANDLE_NONE);
     $GLOBALS['eZGlobalRequestURI'] = eZSys::serverVariable('REQUEST_URI');
     $ini = eZINI::instance();
     eZSys::init('index_rest.php', $ini->variable('SiteAccessSettings', 'ForceVirtualHost') == 'true');
     $uri = eZURI::instance(eZSys::requestURI());
     $GLOBALS['eZRequestedURI'] = $uri;
     // load extensions
     eZExtension::activateExtensions('default');
     require_once __DIR__ . '/restkernel_functions.php';
     // set siteaccess from X-Siteaccess header if given and exists
     if (isset($_SERVER['HTTP_X_SITEACCESS']) && eZSiteAccess::exists($_SERVER['HTTP_X_SITEACCESS'])) {
         $access = array('name' => $_SERVER['HTTP_X_SITEACCESS'], 'type' => eZSiteAccess::TYPE_STATIC);
     } else {
         $access = eZSiteAccess::match($uri, eZSys::hostname(), eZSys::serverPort(), eZSys::indexFile());
     }
     eZSiteAccess::change($access);
     // load siteaccess extensions
     eZExtension::activateExtensions('access');
     // Now that all extensions are activated and siteaccess has been changed, reset
     // all eZINI instances as they may not take into account siteaccess specific settings.
     eZINI::resetAllInstances(false);
     if (ezpRestDebug::isDebugEnabled()) {
         $debug = ezpRestDebug::getInstance();
         $debug->updateDebugSettings();
     }
 }
 /**
  * Sets the current site.
  *
  * From eZ Publish.
  *
  * @param string $site Eg. 'plain_site_user'
  * @todo remove or move in another class?
  */
 public function setCurrentSite($site)
 {
     eZWebDAVContentBackend::appendLogEntry(__FUNCTION__ . '1:' . $site);
     $access = array('name' => $site, 'type' => eZSiteAccess::TYPE_STATIC);
     $access = eZSiteAccess::change($access);
     eZWebDAVContentBackend::appendLogEntry(__FUNCTION__ . '2:' . $site);
     eZDebugSetting::writeDebug('kernel-siteaccess', $access, 'current siteaccess');
     // Clear/flush global database instance.
     $nullVar = null;
     eZDB::setInstance($nullVar);
 }
Exemplo n.º 7
0
    function setCurrentSite( $site )
    {
        $access = array( 'name' => $site,
                         'type' => eZSiteAccess::TYPE_STATIC );

        $access = eZSiteAccess::change( $access );
        eZDebugSetting::writeDebug( 'kernel-siteaccess', $access, 'current siteaccess' );

        // Clear/flush global database instance.
        $nullVar = null;
        eZDB::setInstance( $nullVar );
    }
    /**
     * Get the Sitemap's root node
     */
    $rootNode = eZContentObjectTreeNode::fetch($sitemapRootNodeID, $siteaccess['locale']);
    /**
     * Test for content object fetch (above) failure to return a valid object.
     * Alert the user and terminate execution of script
     */
    if (!is_object($rootNode)) {
        $cli->output("Invalid SitemapRootNodeID in configuration block GeneralSettings; OR SitemapRootNodeID does not not have language translation for current siteaccess language.\n");
        return;
    }
    /**
     * Change siteaccess
     */
    eZSiteAccess::change(array("name" => $siteaccess["siteaccess"], "type" => eZSiteAccess::TYPE_URI));
    /**
     * Fetch the content tree nodes (children) of the above root node (in a given locale)
     */
    $nodeArray[] = $rootNode->subTree(array('Language' => $siteaccess['siteaccessLanguages'], 'ClassFilterType' => $classFilterType, 'ClassFilterArray' => $classFilterArray));
}
// BC: End foreach( $siteaccesses as $siteaccess )
/**
 * Prepare new xml document
 */
$xmlRoot = "urlset";
$xmlNode = "url";
/**
 * Define XML Child Nodes
 */
$xmlSubNodes = array('loc', 'lastmod', 'changefreq', 'priority');
Exemplo n.º 9
0
 private function setSiteAccess( $accessName )
 {
     eZSiteAccess::change( array( 'name' => $accessName,
                                  'type' => eZSiteAccess::TYPE_URI,
                                  'uri_part' => array( $accessName ) ) );
 }
Exemplo n.º 10
0
 function initialize()
 {
     if (ob_get_length() != 0) {
         ob_end_clean();
     }
     $debugINI = eZINI::instance('debug.ini');
     eZDebugSetting::setDebugINI($debugINI);
     // Initialize text codec settings
     $this->updateTextCodecSettings();
     // Initialize debug settings
     $this->updateDebugSettings($this->UseDebugOutput);
     // Set the different permissions/settings.
     $ini = eZINI::instance();
     $iniFilePermission = $ini->variable('FileSettings', 'StorageFilePermissions');
     $iniDirPermission = $ini->variable('FileSettings', 'StorageDirPermissions');
     $iniVarDirectory = eZSys::cacheDirectory();
     eZCodePage::setPermissionSetting(array('file_permission' => octdec($iniFilePermission), 'dir_permission' => octdec($iniDirPermission), 'var_directory' => $iniVarDirectory));
     eZExecution::addCleanupHandler('eZDBCleanup');
     eZExecution::addFatalErrorHandler('eZFatalError');
     eZDebug::setHandleType(eZDebug::HANDLE_FROM_PHP);
     if ($this->UseExtensions) {
         // Check for extension
         eZExtension::activateExtensions('default');
         // Extension check end
     } else {
         if (!$this->isQuiet()) {
             $cli = eZCLI::instance();
             $cli->output("Notice: This script uses 'use-extensions' => false, meaning extension settings are not loaded!");
         }
     }
     $siteaccess = $this->SiteAccess;
     if ($siteaccess) {
         $access = array('name' => $siteaccess, 'type' => eZSiteAccess::TYPE_STATIC);
     } else {
         $ini = eZINI::instance();
         $siteaccess = $ini->variable('SiteSettings', 'DefaultAccess');
         $access = array('name' => $siteaccess, 'type' => eZSiteAccess::TYPE_DEFAULT);
     }
     $access = eZSiteAccess::change($access);
     if ($this->UseExtensions) {
         // Check for siteaccess extension
         eZExtension::activateExtensions('access');
         // Extension check end
     }
     // Now that all extensions are activated and siteaccess has been changed, reset
     // all eZINI instances as they may not take into account siteaccess specific settings.
     eZINI::resetAllInstances(false);
     // Set the global setting which is read by the session lib
     $GLOBALS['eZSiteBasics']['session-required'] = $this->UseSession;
     if ($this->UseSession) {
         $db = eZDB::instance();
         if ($db->isConnected()) {
             eZSession::start();
         } else {
             $this->setIsInitialized(false);
             $this->InitializationErrorMessage = 'database error: ' . $db->errorMessage();
             return;
         }
     }
     if ($this->User) {
         $userLogin = $this->User['login'];
         $userPassword = $this->User['password'];
         if ($userLogin and $userPassword) {
             $userID = eZUser::loginUser($userLogin, $userPassword);
             if (!$userID) {
                 $cli = eZCLI::instance();
                 if ($this->isLoud()) {
                     $cli->warning('Failed to login with user ' . $userLogin);
                 }
                 eZExecution::cleanup();
                 eZExecution::setCleanExit();
             }
         }
     }
     // Initialize module handling
     if ($this->UseModules) {
         $moduleRepositories = eZModule::activeModuleRepositories($this->UseExtensions);
         eZModule::setGlobalPathList($moduleRepositories);
     }
     $this->setIsInitialized(true);
 }
Exemplo n.º 11
0
 protected function requestInit()
 {
     if ($this->isInitialized) {
         return;
     }
     eZExecution::setCleanExit(false);
     $scriptStartTime = microtime(true);
     $GLOBALS['eZRedirection'] = false;
     $this->access = eZSiteAccess::current();
     eZDebug::setScriptStart($scriptStartTime);
     eZDebug::addTimingPoint("Script start");
     $this->uri = eZURI::instance(eZSys::requestURI());
     $GLOBALS['eZRequestedURI'] = $this->uri;
     // Be able to do general events early in process
     ezpEvent::getInstance()->notify('request/preinput', array($this->uri));
     // Initialize module loading
     $this->siteBasics['module-repositories'] = eZModule::activeModuleRepositories();
     eZModule::setGlobalPathList($this->siteBasics['module-repositories']);
     // make sure we get a new $ini instance now that it has been reset
     $ini = eZINI::instance();
     // start: eZCheckValidity
     // pre check, setup wizard related so needs to be before session/db init
     // TODO: Move validity check in the constructor? Setup is not meant to be launched at each (sub)request is it?
     if ($ini->variable('SiteAccessSettings', 'CheckValidity') === 'true') {
         $this->check = array('module' => 'setup', 'function' => 'init');
         // Turn off some features that won't bee needed yet
         $this->siteBasics['policy-check-omit-list'][] = 'setup';
         $this->siteBasics['show-page-layout'] = $ini->variable('SetupSettings', 'PageLayout');
         $this->siteBasics['validity-check-required'] = true;
         $this->siteBasics['session-required'] = $this->siteBasics['user-object-required'] = false;
         $this->siteBasics['db-required'] = $this->siteBasics['no-cache-adviced'] = $this->siteBasics['url-translator-allowed'] = false;
         $this->siteBasics['site-design-override'] = $ini->variable('SetupSettings', 'OverrideSiteDesign');
         $this->access = eZSiteAccess::change(array('name' => 'setup', 'type' => eZSiteAccess::TYPE_URI));
         eZTranslatorManager::enableDynamicTranslations();
     }
     // stop: eZCheckValidity
     if ($this->siteBasics['session-required']) {
         // Check if this should be run in a cronjob
         if ($ini->variable('Session', 'BasketCleanup') !== 'cronjob') {
             eZSession::addCallback('destroy_pre', function (eZDBInterface $db, $key, $escapedKey) {
                 $basket = eZBasket::fetch($key);
                 if ($basket instanceof eZBasket) {
                     $basket->remove();
                 }
             });
             eZSession::addCallback('gc_pre', function (eZDBInterface $db, $time) {
                 eZBasket::cleanupExpired($time);
             });
             eZSession::addCallback('cleanup_pre', function (eZDBInterface $db) {
                 eZBasket::cleanup();
             });
         }
         // addCallBack to update session id for shop basket on session regenerate
         eZSession::addCallback('regenerate_post', function (eZDBInterface $db, $escNewKey, $escOldKey) {
             $db->query("UPDATE ezbasket SET session_id='{$escNewKey}' WHERE session_id='{$escOldKey}'");
         });
         // TODO: Session starting should be made only once in the constructor
         $this->sessionInit();
     }
     // if $this->siteBasics['db-required'], open a db connection and check that db is connected
     if ($this->siteBasics['db-required'] && !eZDB::instance()->isConnected()) {
         $this->warningList[] = array('error' => array('type' => 'kernel', 'number' => eZError::KERNEL_NO_DB_CONNECTION), 'text' => 'No database connection could be made, the system might not behave properly.');
     }
     // eZCheckUser: pre check, RequireUserLogin & FORCE_LOGIN related so needs to be after session init
     if (!isset($this->check)) {
         $this->check = eZUserLoginHandler::preCheck($this->siteBasics, $this->uri);
     }
     ezpEvent::getInstance()->notify('request/input', array($this->uri));
     // Initialize with locale settings
     // TODO: Move to constructor? Is it relevant to init the locale/charset for each (sub)requests?
     $this->languageCode = eZLocale::instance()->httpLocaleCode();
     $phpLocale = trim($ini->variable('RegionalSettings', 'SystemLocale'));
     if ($phpLocale != '') {
         setlocale(LC_ALL, explode(',', $phpLocale));
     }
     $this->httpCharset = eZTextCodec::httpCharset();
     // TODO: are these parameters supposed to vary across potential sub-requests?
     $this->site = array('title' => $ini->variable('SiteSettings', 'SiteName'), 'design' => $ini->variable('DesignSettings', 'SiteDesign'), 'http_equiv' => array('Content-Type' => 'text/html; charset=' . $this->httpCharset, 'Content-language' => $this->languageCode));
     // Read role settings
     $this->siteBasics['policy-check-omit-list'] = array_merge($this->siteBasics['policy-check-omit-list'], $ini->variable('RoleSettings', 'PolicyOmitList'));
     $this->isInitialized = true;
 }
Exemplo n.º 12
0
        if (isset($manualFrequency[$mKey])) {
            $freq = $manualFrequency[$mKey];
        } else {
            $freq = null;
        }
        $sitemap->add($url, null, $freq, $prio);
        if (isset($bar)) {
            $bar->advance();
        }
    }
    // write XML Sitemap to file
    $dir = eZSys::storageDirectory() . '/sitemap';
    if (!file_exists($dir)) {
        mkdir($dir, 0777, true);
    }
    $filename = $dir . '/' . $language['siteaccess'] . '_' . xrowGoogleSiteMap::BASENAME . '.' . xrowGoogleSiteMap::SUFFIX;
    $sitemap->save($filename);
    if (function_exists('gzencode') and $googlesitemapsINI->variable('SiteMapSettings', 'Gzip') == 'enabled') {
        $content = file_get_contents($filename);
        $content = gzencode($content);
        file_put_contents($filename . '.gz', $content);
        unlink($filename);
        $filename .= '.gz';
    }
    if (!$isQuiet) {
        $cli->output();
        $cli->output("Sitemap {$filename} for siteaccess " . $language['siteaccess'] . " (language code " . $language['locale'] . ") has been generated!\n\n");
    }
}
eZSiteAccess::change($old_access);
Exemplo n.º 13
0
/**
 * Changes the site access to what's defined in $access. It will change the
 * access path in eZSys and prepend an override dir to eZINI
 *
 * @see eZSiteAccess::change()
 * @param array $access An associative array with 'name' (string), 'type' (int) and 'uri_part' (array).
 * @return array The $access parameter
 */
function changeAccess(array $access)
{
    return eZSiteAccess::change($access);
}
 /**
  * Test for eZSiteAccess::change(), washing non-latin1 chars from the site access.
  * @dataProvider providerForTestChange
  */
 public function testChange($name, $type, $dirtyUriPart, $washedUriPart)
 {
     $this->assertEquals(array('name' => $name, 'type' => $type, 'uri_part' => array($washedUriPart)), eZSiteAccess::change(array('name' => $name, 'type' => $type, 'uri_part' => array($dirtyUriPart))));
 }
Exemplo n.º 15
0
/**
 * Changes the site access to what's defined in $access. It will change the
 * access path in eZSys and prepend an override dir to eZINI
 *
 * @see eZSiteAccess::change()
 * @deprecated Since 4.4
 * @param array $access An associative array with 'name' (string), 'type' (int) and 'uri_part' (array).
 * @return array The $access parameter
 */
function changeAccess(array $access)
{
    eZDebug::writeStrict('Function changeAccess() has been deprecated in 4.4 in favor of eZSiteAccess::change()', 'Deprecation');
    return eZSiteAccess::change($access);
}