Пример #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;
}
Пример #2
0
 static function initialize()
 {
     if (!isset($GLOBALS['eZ1337Translator']) || !$GLOBALS['eZ1337Translator'] instanceof eZ1337Translator) {
         $GLOBALS['eZ1337Translator'] = new eZ1337Translator();
     }
     $man = eZTranslatorManager::instance();
     $man->registerHandler($GLOBALS['eZ1337Translator']);
     return $GLOBALS['eZ1337Translator'];
 }
 function display()
 {
     $result = array();
     $languages = false;
     $defaultLanguage = false;
     $defaultExtraLanguages = false;
     eZSetupLanguageList($languages, $defaultLanguage, $defaultExtraLanguages);
     eZTranslatorManager::setActiveTranslation($defaultLanguage, false);
     $this->Tpl->setVariable('language_list', $languages);
     $this->Tpl->setVariable('primary_language', $defaultLanguage);
     $this->Tpl->setVariable('optional_test', array('result' => $this->OptionalResult, 'results' => $this->OptionalResults));
     $result['content'] = $this->Tpl->fetch('design:setup/init/welcome.tpl');
     $result['path'] = array(array('text' => ezpI18n::tr('design/standard/setup/init', 'Welcome to eZ Publish'), 'url' => false));
     return $result;
 }
Пример #4
0
 function i18nTrans($operatorName, &$node, $tpl, &$resourceData, $element, $lastElement, $elementList, $elementTree, &$parameters)
 {
     // i18n( $input, $context, $comment, $arguments )
     // Check if if the three first parameters are constants, if not we cannot compile it
     foreach (array_slice($parameters, 0, 3) as $parameter) {
         if ($parameter !== null && !eZTemplateNodeTool::isConstantElement($parameter)) {
             return false;
         }
     }
     $value = eZTemplateNodeTool::elementConstantValue($parameters[0]);
     $numParameters = count($parameters);
     $context = $numParameters > 1 ? eZTemplateNodeTool::elementConstantValue($parameters[1]) : null;
     $comment = $numParameters > 2 ? eZTemplateNodeTool::elementConstantValue($parameters[2]) : null;
     if ($numParameters < 4) {
         return array(eZTemplateNodeTool::createStringElement(ezpI18n::tr($context, $value, $comment, null)));
     }
     $values = array();
     $ini = eZINI::instance();
     if ($ini->variable('RegionalSettings', 'TextTranslation') != 'disabled') {
         $language = eZLocale::instance()->localeFullCode();
         if ($language != "eng-GB") {
             $file = 'translation.ts';
             $ini = eZINI::instance();
             $useCache = $ini->variable('RegionalSettings', 'TranslationCache') != 'disabled';
             eZTSTranslator::initialize($context, $language, $file, $useCache);
             $man = eZTranslatorManager::instance();
             $newValue = $man->translate($context, $value, $comment);
             if ($newValue) {
                 $value = $newValue;
             }
         }
     }
     $values[] = array(eZTemplateNodeTool::createStringElement($value));
     $values[] = $parameters[3];
     $code = '%tmp1% = array();' . "\n" . 'foreach ( %2% as %tmp2% => %tmp3% )' . "\n" . '{' . "\n" . '  if ( is_int( %tmp2% ) )' . "\n" . '    %tmp1%[\'%\' . ( (%tmp2%%9) + 1 )] = %tmp3%;' . "\n" . '  else' . "\n" . '    %tmp1%[%tmp2%] = %tmp3%;' . "\n" . '}' . "\n" . '%output% = strtr( %1%, %tmp1% );' . "\n";
     return array(eZTemplateNodeTool::createCodePieceElement($code, $values, false, 3));
 }
 function findMessage( $context, $source, $comment = null )
 {
     $man = eZTranslatorManager::instance();
     $translation = $this->shuffleText( $source );
     return $man->createMessage( $context, $source, $comment, $translation );
 }
Пример #6
0
 /**
  * Removes the translation message with context $context and source $source.
  *
  * If you have the translation key use removeKey() instead.
  *
  * @param string $context
  * @param string $source
  * @param string $message
  *
  * @return bool true if the message was removed, false otherwise
  */
 function remove($context, $source, $message = null)
 {
     if ($context == "") {
         $context = "default";
     }
     $man = eZTranslatorManager::instance();
     $key = $man->createKey($context, $source, $message);
     if (isset($this->Messages[$key])) {
         unset($this->Messages[$key]);
     }
 }
Пример #7
0
 /**
  * Translates the source \a $source with context \a $context and optional comment \a $comment
  * and returns the translation if locale code is not eng-GB.
  * Uses {@link eZTranslatorMananger::translate()} to do the actual translation
  *
  * Example:
  * translateText( 'content/view', 'There are %count nodes in this list out of %total total nodes.', 'Children view of nodes for whole site', array( '%count' => $c, '%total' => $t ) );
  *
  * @param string $context
  * @param string $source
  * @param string|null $comment
  * @param array|null $arguments
  * @return string
  */
 protected static function translateText($context, $source, $comment = null, $arguments = null)
 {
     $localeCode = eZLocale::instance()->localeFullCode();
     if ($localeCode == 'eng-GB') {
         // we don't have ts-file for 'eng-GB'.
         return self::insertArguments($source, $arguments);
     }
     $ini = eZINI::instance();
     $useCache = $ini->variable('RegionalSettings', 'TranslationCache') != 'disabled';
     eZTSTranslator::initialize($context, $localeCode, 'translation.ts', $useCache);
     // Bork translation: Makes it easy to see what is not translated.
     // If no translation is found in the eZTSTranslator, a Bork translation will be returned.
     // Bork is different than, but similar to, eng-GB, and is enclosed in square brackets [].
     $developmentMode = $ini->variable('RegionalSettings', 'DevelopmentMode') != 'disabled';
     if ($developmentMode) {
         eZBorkTranslator::initialize();
     }
     $man = eZTranslatorManager::instance();
     $trans = $man->translate($context, $source, $comment);
     if ($trans !== null) {
         return self::insertArguments($trans, $arguments);
     }
     if ($comment != null and strlen($comment) > 0) {
         eZDebug::writeDebug("Missing translation for message in context: '{$context}' with comment: '{$comment}'. The untranslated message is: '{$source}'", __METHOD__);
     } else {
         eZDebug::writeDebug("Missing translation for message in context: '{$context}'. The untranslated message is: '{$source}'", __METHOD__);
     }
     return self::insertArguments($source, $arguments);
 }
Пример #8
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;
 }
Пример #9
0
 static function setActiveTranslation($locale, $permanently = true)
 {
     if (!eZTranslatorManager::dynamicTranslationsEnabled()) {
         return;
     }
     if ($permanently) {
         $siteINI = eZINI::instance('site.ini.append', 'settings/override', null, null, false, true);
     } else {
         $siteINI = eZINI::instance();
     }
     $siteINI->setVariable('RegionalSettings', 'Locale', $locale);
     $siteINI->setVariable('RegionalSettings', 'TextTranslation', 'enabled');
     if ($permanently) {
         $siteINI->save('site.ini.append', '.php', false, false);
         eZINI::resetInstance("site.ini");
     }
     eZTranslatorManager::resetTranslations();
 }
    static function initialize( $context, $locale, $useCache = true )
    {
        if ( !isset( $GLOBALS['eZBorkTranslator'] ) ||
             !( $GLOBALS['eZBorkTranslator'] instanceof eZBorkTranslator ) )
        {
            $GLOBALS['eZBorkTranslator'] = new eZBorkTranslator();
        }

        $man = eZTranslatorManager::instance();
        $man->registerHandler( $GLOBALS['eZBorkTranslator'] );
        return $GLOBALS['eZBorkTranslator'];
    }
Пример #11
0
    if ($contentINI->hasVariable('VersionView', 'DefaultPreviewDesign')) {
        $siteAccess = $contentINI->variable('VersionView', 'DefaultPreviewDesign');
    } else {
        $siteAccess = eZTemplateDesignResource::designSetting('site');
    }
}
$access = $GLOBALS['eZCurrentAccess'];
$access['name'] = $siteAccess;
if ($access['type'] === eZSiteAccess::TYPE_URI) {
    $access['uri_part'] = array($siteAccess);
}
eZSiteAccess::load($access);
eZDebug::checkDebugByUser();
// Change content object default language
$GLOBALS['eZContentObjectDefaultLanguage'] = $LanguageCode;
eZTranslatorManager::resetTranslations();
ezpI18n::reset();
eZContentObject::clearCache();
eZContentLanguage::expireCache();
$Module->setTitle('View ' . $class->attribute('name') . ' - ' . $contentObject->attribute('name'));
$ini = eZINI::instance();
$res = eZTemplateDesignResource::instance();
$res->setDesignSetting($ini->variable('DesignSettings', 'SiteDesign'), 'site');
$res->setOverrideAccess($siteAccess);
$tpl = eZTemplate::factory();
if ($http->hasSessionVariable('LastAccessesVersionURI')) {
    $tpl->setVariable('redirect_uri', $http->sessionVariable('LastAccessesVersionURI'));
}
$designKeys = array(array('object', $contentObject->attribute('id')), array('node', $virtualNodeID), array('remote_id', $contentObject->attribute('remote_id')), array('class', $class->attribute('id')), array('class_identifier', $class->attribute('identifier')), array('viewmode', 'full'));
// View mode
if ($assignment) {
Пример #12
0
// 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
if ($ini->variable('SiteAccessSettings', 'CheckValidity') === 'true') {
    $check = array('module' => 'setup', 'function' => 'init');
    // Turn off some features that won't bee needed yet
    $siteBasics['policy-check-omit-list'][] = 'setup';
    $siteBasics['show-page-layout'] = $ini->variable('SetupSettings', 'PageLayout');
    $siteBasics['validity-check-required'] = true;
    $siteBasics['session-required'] = $siteBasics['user-object-required'] = false;
    $siteBasics['db-required'] = $siteBasics['no-cache-adviced'] = $siteBasics['url-translator-allowed'] = false;
    $siteBasics['site-design-override'] = $ini->variable('SetupSettings', 'OverrideSiteDesign');
    $access = array('name' => 'setup', 'type' => eZSiteAccess::TYPE_URI);
    $access = eZSiteAccess::change($access);
    eZTranslatorManager::enableDynamicTranslations();
}
// stop: eZCheckValidity
if ($sessionRequired) {
    // Check if this should be run in a cronjob
    if ($ini->variable('Session', 'BasketCleanup') !== 'cronjob') {
        // Functions for session to make sure baskets are cleaned up
        function eZSessionBasketDestroy($db, $key, $escapedKey)
        {
            $basket = eZBasket::fetch($key);
            if (is_object($basket)) {
                $basket->remove();
            }
        }
        function eZSessionBasketGarbageCollector($db, $time)
        {
Пример #13
0
    /**
     * Translates the source \a $source with context \a $context and optional comment \a $comment
     * and returns the translation if locale code is not eng-GB.
     * Uses {@link eZTranslatorMananger::translate()} to do the actual translation
     *
     * Example:
     * translateText( 'content/view', 'There are %count nodes in this list out of %total total nodes.', 'Children view of nodes for whole site', array( '%count' => $c, '%total' => $t ) );
     *
     * @param string $context
     * @param string $source
     * @param string|null $comment
     * @param array|null $arguments
     * @return string
     */
    protected static function translateText( $context, $source, $comment = null, $arguments = null )
    {
        $localeCode = eZLocale::instance()->localeFullCode();
        if ( $localeCode == 'eng-GB' )
        {
            // we don't have ts-file for 'eng-GB'.
            return self::insertArguments( $source, $arguments );
        }

        // Load all TranslatorHandlers from settings
        $ini = eZINI::instance();
        $useCache = $ini->variable( 'RegionalSettings', 'TranslationCache' ) != 'disabled';
        $handlerClassList = $ini->variable( 'RegionalSettings', 'TranslatorHandlers' );
        foreach( $handlerClassList as $handlerClass )
        {
            call_user_func_array( array( $handlerClass, 'initialize' ), array( $context, $localeCode, $useCache ) );
        }

        // Bork translation: Makes it easy to see what is not translated.
        // If no translation is found in the eZTSTranslator, a Bork translation will be returned.
        // Bork is different than, but similar to, eng-GB, and is enclosed in square brackets [].
        $developmentMode = $ini->variable( 'RegionalSettings', 'DevelopmentMode' ) != 'disabled';
        if ( $developmentMode && ! in_array( 'eZBorkTranslator', $handlerClassList ) )
        {
            eZBorkTranslator::initialize( $context, $localeCode, $useCache );
        }

        $man = eZTranslatorManager::instance();
        $trans = $man->translate( $context, $source, $comment );
        if ( $trans !== null ) {
            return self::insertArguments( $trans, $arguments );
        }

        if ( $comment != null and strlen( $comment ) > 0 )
            eZDebug::writeDebug( "Missing translation for message in context: '$context' with comment: '$comment'. The untranslated message is: '$source'", __METHOD__ );
        else
            eZDebug::writeDebug( "Missing translation for message in context: '$context'. The untranslated message is: '$source'", __METHOD__ );

        return self::insertArguments( $source, $arguments );
    }