예제 #1
0
 public function getCurrentLocale()
 {
     static $current_locale;
     if (empty($current_locale)) {
         $current_locale = Ak::lang();
         $available_locales = $this->getAvailableLocales();
         if (!in_array($current_locale, $available_locales)) {
             $current_locale = array_shift($available_locales);
         }
     }
     return $current_locale;
 }
예제 #2
0
 /**
  * Attempts to render a static error page based on the
  * <tt>$this->getStatusCode</tt> thrown, or just return headers if no such file
  * exists. At first, it will try to render a localized static page.
  * For example, if a 500 error is being handled Rails and locale is :da,
  * it will first attempt to render the file at <tt>public/500.da.html</tt>
  * then attempt to render <tt>public/500.html</tt>. If none of them exist,
  * the body of the response will be left empty.
  */
 public function rescueActionInPublic($Exception)
 {
     $status = $this->getStatusCode($Exception);
     $locale_path = AkConfig::getDir('public') . '/' . $status . '_' . Ak::lang() . '.html';
     $path = AkConfig::getDir('public') . '/' . $status . '.html';
     if (file_exists($locale_path)) {
         $this->render($status, file_get_contents($locale_path));
     } elseif (file_exists($path)) {
         $this->render($status, file_get_contents($path));
     } else {
         $this->render($status, '');
     }
 }
예제 #3
0
 public function get_doc_contents($doc_name)
 {
     $doc_file = $this->_getdocPath($doc_name, Ak::lang());
     if (file_exists($doc_file)) {
         return file_get_contents($doc_file);
     }
     $doc_file = $this->_getTodoDocPath($doc_name, Ak::lang());
     if (file_exists($doc_file)) {
         $this->is_todo = true;
         return file_get_contents($doc_file);
     }
     $doc_file = $this->_getdocPath($doc_name, 'en');
     return @file_get_contents($doc_file);
 }
예제 #4
0
 public function get_doc_contents($doc_name)
 {
     $doc_file = $this->_getdocPath($doc_name, Ak::lang());
     return file_exists($doc_file) ? file_get_contents($doc_file) : @file_get_contents($this->_getdocPath($doc_name, 'en'));
 }
예제 #5
0
 function expire()
 {
     $this->expireAction(array('controller' => 'action_caching', 'action' => 'index', 'lang' => Ak::lang()));
     $this->expireAction(array('controller' => 'action_caching', 'action' => 'skip'));
     $this->renderNothing(200);
 }
예제 #6
0
파일: Ak.php 프로젝트: joeymetal/v1
 function encoding()
 {
     static $encoding;
     if (empty($encoding)) {
         // This will force system language settings
         Ak::t('Akelos');
         $encoding = Ak::locale('charset', Ak::lang());
         $encoding = empty($encoding) ? 'UTF-8' : $encoding;
     }
     return $encoding;
 }
예제 #7
0
 function _getLocaleForRequest(&$Request)
 {
     $lang = $this->getNavigationLanguage();
     if ($url_locale = $this->getLangFromUrl($Request)) {
         $lang = $this->getLocaleFromAlias($url_locale);
     }
     if (!$this->_canUseLocaleOnCurrentRequest($lang, $Request)) {
         $lang = array_shift($this->getPublicLocales());
     } elseif (empty($lang)) {
         $lang = array_shift($this->getPublicLocales());
     }
     // This way we store on get_url_locale and on lang the value of $lang on
     // a static variable for accessing it application wide
     empty($url_locale) ? null : Ak::get_url_locale($url_locale);
     Ak::lang($lang);
     return $lang;
 }
예제 #8
0
 public function test_normalized_action_paths()
 {
     $this->assertTrue(true,'Need to test that /page is the same cache as /page/index');
     $this->_flushCache('xinc.eu');
     $cache_this_xinc = date('Y-m-d, H:i:s', time()+30);
     $this->get('http://xinc.eu/action_caching/',array(),array(),array('cache_this'=>$cache_this_xinc));
     $xinc_cached_normalized = $this->_getActionCache('/'.Ak::lang().'/action_caching/index',array('host'=>'xinc.eu'));
     $this->assertTextMatch($cache_this_xinc);
     $this->assertEqual($cache_this_xinc,$xinc_cached_normalized);
     
     $this->get('http://xinc.eu/action_caching/index',array(),array(),array('cache_this'=>$cache_this_xinc));
     $this->assertTextMatch($cache_this_xinc);
 }
예제 #9
0
 function get_language()
 {
     $this->renderText(Ak::lang());
 }
예제 #10
0
파일: _sweeper.php 프로젝트: bermi/akelos
 public function test_update_sweeper_except()
 {
     $this->post('http://www.example.com/cache_sweeper2/create', array('first_name' => 'Max', 'last_name' => 'Mustermann'));
     $this->assertResponse(302);
     $url = $this->getHeader('Location');
     $parts = parse_url($url);
     $this->showUrl = 'http://www.example.com' . $parts['path'];
     $params = preg_split('/\\//', rtrim($this->showUrl, '/'));
     $this->userId = $params[count($params) - 1];
     $this->_assertCacheNotExists('/' . Ak::lang() . '/cache_sweeper2/show/' . $this->userId, array('host' => 'www.example.com'));
     $this->get($this->showUrl);
     $this->_assertCacheExists('/' . Ak::lang() . '/cache_sweeper2/show/' . $this->userId, array('host' => 'www.example.com'));
     /**
      * delete does not call the sweeper, so cache should still exist
      */
     $this->post('http://www.example.com/cache_sweeper2/delete/' . $this->userId);
     $this->get('http://www.example.com/page_caching/');
     $this->_assertCacheExists('/' . Ak::lang() . '/cache_sweeper2/show/' . $this->userId, array('host' => 'www.example.com'));
     /**
      * but user does not exist anymore
      */
     $this->post('http://www.example.com/cache_sweeper2/update/' . $this->userId, array());
     $this->assertResponse(404);
 }
예제 #11
0
    function _pathFor($options = array(), $normalize = true)
    {
        $options = empty($options)?$this->_controller->Request->_route_params:$options;
        $options['controller'] = !isset($options['controller']) ? (isset($this->_controller->params['controller']) ?
        $this->_controller->params['controller']:null):
        $options['controller'];
        $options['action'] = !isset($options['action']) ?
            (isset($this->_controller->params['action']) ? $this->_controller->params['action'] : null ) :
            $options['action'];
        $options['id'] = isset($options['id']) ? $options['id']: false;
		$options['lang'] = isset($options['lang']) ? $options['lang'] : Ak::lang();
        $options['skip_relative_url_root']=true;
        $url = $this->_controller->rewrite($this->_controller->rewriteOptions($options));

        $parts = parse_url($url);
        $path = isset($parts['path'])?$parts['path']:'';

        if ($normalize && (!isset($options['action']) || (isset($options['action']) && $options['action']==AK_DEFAULT_ACTION && !strstr($path,'/'.AK_DEFAULT_ACTION)))) {
            $path = rtrim($path,'/');
            $parts = preg_split('/\/+/',$path);
            if(!empty($options['format']) && preg_match('/(\.'.$options['format'].')$/',$parts[count($parts)-1],$matches)) {
                $parts[count($parts)-1] = str_replace($matches[1],'',$parts[count($parts)-1]);
            }
            $parts[] = AK_DEFAULT_ACTION;
            $path = implode('/', $parts);
        }
        $path = rtrim($path,'/');
		if(!empty($options['module'])) {
			$path.='?module='.$options['module'];
		}

        return $path;
    }
예제 #12
0
 function _getDefaultLocale()
 {
     return Ak::lang();
 }
예제 #13
0
 public function getDefaultLocale()
 {
     return Ak::lang();
 }
예제 #14
0
파일: request.php 프로젝트: bermi/akelos
 public function checkForRoutedRequests(AkRouter &$Router)
 {
     $this->parameters_from_url = $params = $Router->match($this);
     if (!isset($params['controller']) || !$this->isValidControllerName($params['controller'])) {
         throw new NoMatchingRouteException('No route matches "' . $this->getPath() . '" with {:method=>:' . $this->getMethod() . '}');
     }
     if (empty($params['action'])) {
         $params['action'] = 'index';
     }
     if (!$this->isValidActionName($params['action'])) {
         throw new NoMatchingRouteException('No action was specified.');
     }
     if (!empty($params['module'])) {
         if (!$this->isValidModuleName($params['module'])) {
             throw new DispatchException('Invalid module ' . $params['module'] . '.');
         }
     } else {
         unset($this->_request['module']);
     }
     isset($params['module']) ? $this->module = $params['module'] : null;
     $this->controller = $params['controller'];
     $this->action = $params['action'];
     if (isset($params['lang'])) {
         AkLocaleManager::rememberNavigationLanguage($params['lang']);
         Ak::lang($params['lang']);
     }
     $this->_request = array_merge($this->_request, $params);
 }
예제 #15
0
파일: AkRequest.php 프로젝트: joeymetal/v1
 function checkForRoutedRequests(AkRouter &$Router)
 {
     $this->parameters_from_url = $params = $Router->match($this);
     if (!isset($params['controller']) || !$this->isValidControllerName($params['controller'])) {
         throw new DispatchException('No controller was specified.');
     }
     if (!isset($params['action']) || !$this->isValidActionName($params['action'])) {
         throw new DispatchException('No action was specified.');
     }
     if (isset($params['module']) && !$this->isValidModuleName($params['module'])) {
         throw new DispatchException('Invalid module.');
     }
     isset($params['module']) ? $this->module = $params['module'] : null;
     $this->controller = $params['controller'];
     $this->action = $params['action'];
     if (isset($params['lang'])) {
         AkLocaleManager::rememberNavigationLanguage($params['lang']);
         Ak::lang($params['lang']);
     }
     $this->_request = array_merge($this->_request, $params);
 }