public function setUp() { parent::setUp(); I18n::setLanguage(''); Session::destroy(); if ($s = UserSession::get()) { $s->delete(); } Session::$site = 'http://www.test.info/'; Session::$referrer = 'http://www.test.info/some/part/of/the/site'; unlink(COORG_TEST_CONFIG); copy(COORG_TEST_CONFIG_CLEAN, COORG_TEST_CONFIG); $config = new Config(COORG_TEST_CONFIG); $config->set('site/title', 'The Site'); $config->set('defaultLanguage', ''); CoOrg::init($config, 'app', 'plugins'); CoOrgSmarty::clearAll(); Header::$redirect = '__none__'; }
public static function process($request, $params = array(), $post = false) { self::$_resourceTheme = 'default'; include 'static/default/resources.coorg.php'; $theme = self::$_config->get('theme'); if (!$theme) $theme = 'default'; if ($theme != 'default') { self::$_resourceTheme = $theme; if (file_exists('static/'.$theme.'/resources.coorg.php')) { include 'static/'.$theme.'/resources.coorg.php'; } } self::normalizeRequest($request); $url = $request; if ($request == '/' || $request == '') $request = 'home'; $requestParams = explode('/', $request); $controllerName = ucfirst(array_shift($requestParams)); $prefix = null; $requestWithoutPrefix = $request; if (strlen($controllerName) == 2) { $prefix = strtolower($controllerName).'/'; I18n::setLanguage(strtolower($controllerName)); $requestWithoutPrefix = implode('/', $requestParams); if (count($requestParams) > 0) { $controllerName = ucfirst(array_shift($requestParams)); } else { $controllerName = 'Home'; } } else { $found = false; //TODO: move Language DB to default install // and unittest this... (in the CoOrg tests). if (class_exists('Language')) { $preferredLanguages = Session::getPreferredLanguages(); $installedLanguages = Language::languageCodes(); // This is in the admin class, but should really be in the default instal foreach ($preferredLanguages as $lc) { if (in_array($lc, $installedLanguages)) { $found = true; I18n::setLanguage($lc); break; } else if (strpos($lc, '-')) { $slc = substr($lc, 0, strpos($lc, '-')); if (in_array($slc, $installedLanguages)) { $found = true; I18n::setLanguage($slc); break; } } } } if (!$found && self::$_config->has('defaultLanguage')) { I18n::setLanguage(self::$_config->get('defaultLanguage')); } } try { list($controllerClass, $action, $params, $request, $parentClasses) = self::findController($controllerName, $requestParams, $params, $post); $controllerClass->coorgRequest = $requestWithoutPrefix; $coorgUrl = self::config()->get('path').$prefix.$requestWithoutPrefix; self::normalizeRequest($coorgUrl); $controllerClass->coorgUrl = $coorgUrl; $controllerClass->staticPath = self::$_config->get('path').'static/'; $controllerClass->coorgLanguage = self::getLanguage(); if (!$post && $controllerClass->isPost($action)) { throw new WrongRequestMethodException(); } if ($post && strpos(Session::getReferrer(), Session::getSite()) === false) { throw new WrongRequestMethodException(); } self::$_request = $request; self::$_requestParameters = $params; $continue = true; foreach ($parentClasses as $pClassName) { $pClass = new $pClassName; $continue = $pClass->beforeFilters(null, self::$_beforeFilters, $params); if (!$continue) { break; } } if ($continue && $controllerClass->beforeFilters($action, self::$_beforeFilters, $params)) { try { call_user_func_array(array($controllerClass, $action), $params); } catch (Exception $e) { $controllerClass->systemError($request, Session::getReferrer(), $e); } } $controllerClass->done(); } catch (RequestNotFoundException $e) { $controller = new Controller(); $controller->init('.', self::$_appdir); $controller->notFound($request, Session::getReferrer(), $e); return; } catch (Exception $e) { $controller = new Controller(); $controller->init('.', self::$_appdir); $controller->systemError($request, Session::getReferrer(), $e); return; } }
/** * i18n.php * * Defines i18n l10n constants and initializes OPEN_LANGUAGE settings * * Licensed under the GNU GPL. For full terms see the file LICENSE. * * @package OpenClinic * @copyright 2002-2013 jact * @license http://www.gnu.org/copyleft/gpl.html GNU GPL * @version CVS: $Id: i18n.php,v 1.4 2013/01/07 18:14:34 jact Exp $ * @author jact <*****@*****.**> * @since 0.7 */ require_once dirname(__FILE__) . "/../lib/exe_protect.php"; executionProtection(__FILE__); require_once "../lib/I18n.php"; $nls = I18n::getNLS(); if (!defined("OPEN_LANGUAGE")) { define("OPEN_LANGUAGE", I18n::setLanguage()); } else { I18n::setLanguage(OPEN_LANGUAGE); } define("OPEN_CHARSET", isset($nls['charset'][OPEN_LANGUAGE]) ? $nls['charset'][OPEN_LANGUAGE] : $nls['default']['charset']); define("OPEN_DIRECTION", isset($nls['direction'][OPEN_LANGUAGE]) ? $nls['charset'][OPEN_LANGUAGE] : $nls['default']['direction']); define("OPEN_ENCODING", isset($nls['encoding'][OPEN_LANGUAGE]) ? $nls['encoding'][OPEN_LANGUAGE] : $nls['default']['encoding']); I18n::initLanguage(OPEN_LANGUAGE); if (!defined("OPEN_TIME_ZONE")) { define("OPEN_TIME_ZONE", "Europe/Madrid"); } date_default_timezone_set(OPEN_TIME_ZONE);
public function testI18nManual() { I18n::setLanguage('nl'); CoOrg::process('alpha/sub/i18ntest'); $this->assertEquals('Google is leuk', AlphaSubController::$i18ntest1); $this->assertEquals('shit van Google', AlphaSubController::$i18ntest2); $this->assertEquals('Dit bericht komt van alpha', AlphaSubController::$i18nfromAlpha); $this->assertEquals('Message not found with 1 paramaters', AlphaSubController::$notFoundWithParams); AlphaSubController::$i18ntest1 = ''; AlphaSubController::$i18ntest2 = ''; AlphaSubController::$i18nfromAlpha = ''; AlphaSubController::$notFoundWithParams = ''; }