Пример #1
0
<?php

require_once 'tutorial_autoload.php';
class customLazyUrlConfiguration implements ezcBaseConfigurationInitializer
{
    public static function configureObject($urlCfg)
    {
        // set the basedir and script values
        $urlCfg->basedir = 'mydir';
        $urlCfg->script = 'index.php';
        // define delimiters for unordered parameter names
        $urlCfg->unorderedDelimiters = array('(', ')');
        // define ordered parameters
        $urlCfg->addOrderedParameter('section');
        $urlCfg->addOrderedParameter('group');
        $urlCfg->addOrderedParameter('category');
        $urlCfg->addOrderedParameter('subcategory');
        // define unordered parameters
        $urlCfg->addUnorderedParameter('game');
    }
}
ezcBaseInit::setCallback('ezcUrlConfiguration', 'customLazyUrlConfiguration');
// Classes loaded and configured on first request
$url = new ezcUrl('http://www.example.com/mydir/index.php/groups/Games/Adventure/Adult/(game)/Larry/7', ezcUrlConfiguration::getInstance());
Пример #2
0
 public function testDelayedInit()
 {
     ezcBaseInit::setCallback('ezcUrlConfiguration', 'testDelayedInitUrlConfiguration');
     $urlCfg = ezcUrlConfiguration::getInstance();
     $this->assertEquals(array('section' => 0), $urlCfg->orderedParameters);
     $this->assertEquals(array('article' => 1), $urlCfg->unorderedParameters);
 }
Пример #3
0
 static function runModule()
 {
     if (isset(self::$currentModule[self::$currentView])) {
         $Params = array();
         $Params['module'] = self::$currentModule[self::$currentView];
         $Params['module']['name'] = self::$currentModule;
         $Params['module']['view'] = self::$currentView;
         $urlCfgDefault = ezcUrlConfiguration::getInstance();
         $url = erLhcoreClassURL::getInstance();
         self::$currentModule[self::$currentView]['uparams'][] = 'page';
         foreach (self::$currentModule[self::$currentView]['params'] as $userParameter) {
             $urlCfgDefault->addOrderedParameter($userParameter);
         }
         foreach (self::$currentModule[self::$currentView]['uparams'] as $userParameter) {
             $urlCfgDefault->addUnorderedParameter($userParameter, isset(self::$currentModule[self::$currentView]['multiple_arguments']) && in_array($userParameter, self::$currentModule[self::$currentView]['multiple_arguments']) ? ezcUrlConfiguration::MULTIPLE_ARGUMENTS : null);
         }
         $url->applyConfiguration($urlCfgDefault);
         foreach (array_merge(self::$currentModule[self::$currentView]['uparams'], self::$currentModule[self::$currentView]['params']) as $userParameter) {
             $Params[in_array($userParameter, self::$currentModule[self::$currentView]['params']) ? 'user_parameters' : 'user_parameters_unordered'][$userParameter] = $url->getParam($userParameter);
         }
         // Function set, check permission
         if (isset($Params['module']['functions'])) {
             // Just to start session
             $currentUser = erLhcoreClassUser::instance();
             if (!$currentUser->hasAccessTo('lh' . self::$currentModuleName, $Params['module']['functions'])) {
                 if ($currentUser->isLogged()) {
                     include_once 'modules/lhkernel/nopermission.php';
                     $Result['pagelayout'] = 'login';
                     return $Result;
                 } else {
                     if (isset($Params['module']['ajax']) && $Params['module']['ajax'] == true) {
                         echo json_encode(array('error_url' => erLhcoreClassDesign::baseurl('user/login')));
                         exit;
                     } else {
                         self::redirect('user/login');
                         exit;
                     }
                 }
             }
         }
         if (isset($Params['module']['limitations'])) {
             // Just to start session
             $currentUser = erLhcoreClassUser::instance();
             $access = call_user_func($Params['module']['limitations']['self']['method'], $Params['user_parameters'][$Params['module']['limitations']['self']['param']], $currentUser->hasAccessTo('lh' . self::$currentModuleName, $Params['module']['limitations']['global']));
             if ($access == false) {
                 if ($currentUser->isLogged()) {
                     include_once 'modules/lhkernel/nopermissionobject.php';
                     $Result['pagelayout'] = 'login';
                     return $Result;
                 } else {
                     self::redirect('user/login');
                     exit;
                 }
             } else {
                 $Params['user_object'] = $access;
             }
         }
         try {
             if (isset($currentUser) && $currentUser->isLogged() && ($timeZone = $currentUser->getUserTimeZone()) != '') {
                 self::$defaultTimeZone = $timeZone;
                 date_default_timezone_set(self::$defaultTimeZone);
             } elseif (self::$defaultTimeZone != '') {
                 date_default_timezone_set(self::$defaultTimeZone);
             }
             if (self::$debugEnabled == false) {
                 $includeStatus = @(include self::getModuleFile());
             } else {
                 $includeStatus = (include self::getModuleFile());
             }
             // Inclusion failed
             if ($includeStatus === false) {
                 $CacheManager = erConfigClassLhCacheConfig::getInstance();
                 $CacheManager->expireCache();
                 if (self::$debugEnabled == true) {
                     // Just try reinclude
                     include self::getModuleFile(true);
                 } else {
                     // Just try reinclude
                     @(include self::getModuleFile(true));
                 }
                 if (!isset($Result)) {
                     self::redirect(self::$currentModuleName . '/' . self::$currentView);
                     exit;
                 }
             }
         } catch (Exception $e) {
             $CacheManager = erConfigClassLhCacheConfig::getInstance();
             $CacheManager->expireCache();
             if (erConfigClassLhConfig::getInstance()->getSetting('site', 'debug_output') == true) {
                 echo "<pre>";
                 print_r($e);
                 echo "</pre>";
                 exit;
             }
             if (erConfigClassLhConfig::getInstance()->getSetting('site', 'installed') == false) {
                 header('Location: ' . erLhcoreClassDesign::baseurldirect('site_admin/install/install'));
                 exit;
             }
             header('HTTP/1.1 503 Service Temporarily Unavailable');
             header('Status: 503 Service Temporarily Unavailable');
             header('Retry-After: 300');
             exit;
         }
         if (isset($Params['module']['pagelayout']) && !isset($Result['pagelayout'])) {
             $Result['pagelayout'] = $Params['module']['pagelayout'];
         }
         return $Result;
     } else {
         // Default module view
         if (($viewDefault = self::getModuleDefaultView(self::$currentModuleName)) !== false) {
             self::redirect(self::$currentModuleName . '/' . $viewDefault);
             exit;
         }
         // No sutch module etc, redirect to frontpage
         self::redirect();
         exit;
     }
 }
Пример #4
0
 public static function getInstance()
 {
     if (is_null(self::$instance)) {
         $sysConfiguration = erLhcoreClassSystem::instance();
         $urlCfgDefault = ezcUrlConfiguration::getInstance();
         $urlCfgDefault->basedir = $sysConfiguration->WWWDir;
         $urlCfgDefault->script = $sysConfiguration->IndexFile;
         $urlCfgDefault->unorderedDelimiters = array('(', ')');
         $urlCfgDefault->orderedParameters = array();
         $urlCfgDefault->unorderedParameters = array();
         $urlCfgDefault->addOrderedParameter('siteaccess');
         $urlCfgDefault->addOrderedParameter('module');
         $urlCfgDefault->addOrderedParameter('function');
         $cfgSite = erConfigClassLhConfig::getInstance();
         $urlInstance = new erLhcoreClassURL(($cfgSite->getSetting('site', 'force_virtual_host', false) === false ? 'index.php' : '') . $sysConfiguration->RequestURI, $urlCfgDefault);
         $siteaccess = $urlInstance->getParam('siteaccess');
         $availableSiteaccess = $cfgSite->getSetting('site', 'available_site_access');
         $defaultSiteAccess = $cfgSite->getSetting('site', 'default_site_access');
         if ($defaultSiteAccess != $siteaccess && in_array($siteaccess, $availableSiteaccess)) {
             $optionsSiteAccess = $cfgSite->getSetting('site_access_options', $siteaccess);
             $sysConfiguration->Language = $siteaccess == 'site_admin' ? erLhcoreClassModelUserSetting::getSetting('user_language', $optionsSiteAccess['locale'], false, true) : $optionsSiteAccess['locale'];
             $sysConfiguration->ThemeSite = $optionsSiteAccess['theme'];
             $sysConfiguration->ContentLanguage = $optionsSiteAccess['content_language'];
             $sysConfiguration->WWWDirLang = '/' . $siteaccess;
             $sysConfiguration->SiteAccess = $siteaccess;
             if ($optionsSiteAccess['locale'] != 'en_EN') {
                 $urlInstance->setParam('module', $urlInstance->getParam('module'));
                 $urlInstance->setParam('function', $urlInstance->getParam('function'));
             }
             if (isset($_POST['switchLang']) && in_array($_POST['switchLang'], $availableSiteaccess)) {
                 $optionsSiteAccessOverride = $cfgSite->getSetting('site_access_options', $_POST['switchLang']);
                 $sysConfiguration->Language = $optionsSiteAccessOverride['locale'];
                 $sysConfiguration->SiteAccess = $_POST['switchLang'];
                 if ($defaultSiteAccess != $sysConfiguration->SiteAccess) {
                     $sysConfiguration->WWWDirLang = '/' . $sysConfiguration->SiteAccess;
                 } else {
                     $sysConfiguration->WWWDirLang = '';
                 }
             }
         } else {
             $optionsSiteAccess = $cfgSite->getSetting('site_access_options', $defaultSiteAccess);
             // Falling back
             $sysConfiguration->SiteAccess = $defaultSiteAccess;
             $sysConfiguration->Language = $siteaccess == 'site_admin' ? erLhcoreClassModelUserSetting::getSetting('user_language', $optionsSiteAccess['locale'], false, true) : $optionsSiteAccess['locale'];
             $sysConfiguration->ThemeSite = $optionsSiteAccess['theme'];
             $sysConfiguration->ContentLanguage = $optionsSiteAccess['content_language'];
             if (isset($_POST['switchLang']) && in_array($_POST['switchLang'], $availableSiteaccess)) {
                 $optionsSiteAccessOverride = $cfgSite->getSetting('site_access_options', $_POST['switchLang']);
                 $sysConfiguration->Language = $optionsSiteAccessOverride['locale'];
                 $sysConfiguration->SiteAccess = $_POST['switchLang'];
                 if ($defaultSiteAccess != $sysConfiguration->SiteAccess) {
                     $sysConfiguration->WWWDirLang = '/' . $sysConfiguration->SiteAccess;
                 }
             }
             // To reset possition counter
             $urlCfgDefault->removeOrderedParameter('siteaccess');
             $urlCfgDefault->removeOrderedParameter('module');
             $urlCfgDefault->removeOrderedParameter('function');
             // Reinit parameters
             $urlCfgDefault->addOrderedParameter('module');
             $urlCfgDefault->addOrderedParameter('function');
             //Apply default configuration
             $urlInstance->applyConfiguration($urlCfgDefault);
             if ($optionsSiteAccess['locale'] != 'en_EN') {
                 $urlInstance->setParam('module', $urlInstance->getParam('module'));
                 $urlInstance->setParam('function', $urlInstance->getParam('function'));
             }
         }
         self::$instance = $urlInstance;
     }
     return self::$instance;
 }