Ejemplo n.º 1
0
 /**
  * @throws HTTP_Exception_401
  * @since 1.0
  */
 public function before()
 {
     parent::before();
     // Check request signature
     if (Kohana::$config->load('hapi.require_signature') && !HAPI_Security::is_request_signature_valid($this->request)) {
         HAPI_Security::require_auth('Request signature was invalid');
     }
     // Login using basic auth
     if (array_key_exists('authorization', $this->request->headers())) {
         HAPI_Security::login($this->request->headers('authorization'));
     }
     // Check that user is authenticated
     if ($this->_require_login && !HAPI_Security::is_request_authenticated($this->request)) {
         HAPI_Security::require_auth();
     }
     // Instantiate the encoder object for the response (based on the Accept header)
     $this->response_encoder = $this->_get_response_encoder();
     // Set current language
     $supported_languages = Kohana::$config->load('hapi.supported_languages');
     $preferred_language = $this->request->headers()->preferred_language($supported_languages);
     if ($preferred_language) {
         I18n::lang($preferred_language);
     }
     $extract_array = function ($keys) {
         if (empty($keys)) {
             return [];
         }
         return explode(',', $keys);
     };
     // Filter response keys
     $this->_paths = $extract_array($this->request->query('paths'));
 }
Ejemplo n.º 2
0
 public function before()
 {
     parent::before();
     I18n::lang('ru');
     //Cookie::$salt = 'assfr423dsf';
     Session::$default = 'cookie';
     $this->cache = Cache::instance('file');
     $this->auth = Auth::instance();
     $this->user = $this->auth->get_user();
     $this->session = Session::instance();
     $site_name = Kohana::$config->load('myconf.site_name');
     $site_description = Kohana::$config->load('myconf.site_description');
     $footer = Kohana::$config->load('myconf.footer');
     //Вывод в шаблон
     $this->template->site_name = $site_name;
     $this->template->site_description = $site_description;
     $this->template->page_title = null;
     $this->template->page_footer = $footer;
     //Подключение стилий и скриптов
     $this->template->styles = array('');
     $this->template->scripts = array();
     //Подключаем блоки
     $this->template->block_left = null;
     $this->template->block_center = null;
     $this->template->block_right = null;
     $this->template->block_headerRight = null;
 }
Ejemplo n.º 3
0
 public function before()
 {
     parent::before();
     $lang = $this->request->param('lang');
     // Make sure we have a valid language
     if (!in_array($lang, array_keys(Kohana::config('kohana')->languages))) {
         $this->request->action = 'error';
         throw new Kohana_Request_Exception('Unable to find a route to match the URI: :uri (specified language was not found in config)', array(':uri' => $this->request->uri));
     }
     I18n::$lang = $lang;
     if (isset($this->page_titles[$this->request->action])) {
         // Use the defined page title
         $title = $this->page_titles[$this->request->action];
     } else {
         // Use the page name as the title
         $title = ucwords(str_replace('_', ' ', $this->request->action));
     }
     $this->template->title = $title;
     if (!kohana::find_file('views', 'pages/' . $this->request->action)) {
         $this->request->action = 'error';
     }
     $this->template->content = View::factory('pages/' . $this->request->action);
     $this->template->set_global('request', $this->request);
     $this->template->meta_tags = array();
 }
Ejemplo n.º 4
0
 public function before()
 {
     parent::before();
     // Borrowed from userguide
     if (isset($_GET['lang'])) {
         $lang = $_GET['lang'];
         // Make sure the translations is valid
         $translations = Kohana::message('langify', 'translations');
         if (in_array($lang, array_keys($translations))) {
             // Set the language cookie
             Cookie::set('langify_language', $lang, Date::YEAR);
         }
         // Reload the page
         $this->request->redirect($this->request->uri());
     }
     // Set the translation language
     I18n::$lang = Cookie::get('langify_language', Kohana::config('langify')->lang);
     // Borrowed from Vendo
     // Automaticly load a view class based on action.
     $view_name = $this->view_prefix . Request::current()->action();
     if (Kohana::find_file('classes', strtolower(str_replace('_', '/', $view_name)))) {
         $this->view = new $view_name();
         $this->view->set('version', $this->version);
     }
 }
Ejemplo n.º 5
0
 public function before()
 {
     I18n::lang('pl-pl');
     $this->session = Session::instance();
     if ($this->auto_render === TRUE and $this->template !== NULL and !in_array($this->request->action, $this->no_view)) {
         if (!in_array($this->request->action, $this->no_template)) {
             $this->template = new View((!empty($this->request->directory) ? $this->request->directory . '/' : NULL) . $this->template);
             if (Request::$is_ajax) {
                 $this->template = new View('common/ajax');
             }
             if ($this->content === TRUE) {
                 $this->template->content = new View((!empty($this->request->directory) ? $this->request->directory . '/' : NULL) . $this->request->controller . '/' . $this->request->action);
                 $this->content =& $this->template->content;
             }
         } else {
             if ($this->content === TRUE) {
                 $this->content = new View((!empty($this->request->directory) ? $this->request->directory . '/' : NULL) . $this->request->controller . '/' . $this->request->action);
             }
             $this->template =& $this->content;
             if (Request::$is_ajax) {
                 $this->template = new View('common/ajax');
                 $this->template->content = $this->content;
             }
         }
     }
 }
Ejemplo n.º 6
0
 public function before()
 {
     $this->session = Session::instance();
     $this->config = Kohana::$config->load('settings');
     $this->language = Lang::get_accepted_language($this->config->language);
     /**
      * Sets the default timezone used by all date/time functions
      *
      * @link http://kohanaframework.org/guide/using.configuration
      * @link http://www.php.net/manual/timezones
      */
     date_default_timezone_set($this->config->timezone);
     /**
      * Set locale information
      *
      * @link http://kohanaframework.org/guide/using.configuration
      * @link http://www.php.net/manual/function.setlocale
      */
     setlocale(LC_ALL, $this->config->languages[$this->language] . '.' . Kohana::$charset);
     /**
      * Set app language
      * Provides loading of language and translation
      */
     I18n::lang($this->language);
 }
Ejemplo n.º 7
0
 public static function setup()
 {
     language::$available_languages = Kohana::config('locale.languages');
     if (Router::$language === NULL) {
         $redirect = NULL;
         if (empty(Router::$current_uri)) {
             if (($lang = language::browser_language()) !== '') {
                 $redirect = $lang;
             } else {
                 reset(language::$available_languages);
                 $redirect = key(language::$available_languages);
             }
         } else {
             if (($lang = language::browser_language()) !== '') {
                 $redirect = $lang . '/' . Router::$current_uri;
             } else {
                 reset(language::$available_languages);
                 $redirect = key(language::$available_languages) . '/' . Router::$current_uri;
             }
         }
         url::redirect($redirect);
     }
     Kohana::config_set('locale.language', language::$available_languages[Router::$language]['language']);
     I18n::$lang = language::$available_languages[Router::$language]['language'][0];
 }
Ejemplo n.º 8
0
 public function before()
 {
     if ($this->request->action === 'media') {
         // Do not template media files
         $this->auto_render = FALSE;
     } else {
         // Grab the necessary routes
         $this->media = Route::get('docs/media');
         $this->api = Route::get('docs/api');
         $this->guide = Route::get('docs/guide');
         if (isset($_GET['lang'])) {
             $lang = $_GET['lang'];
             // Load the accepted language list
             $translations = array_keys(Kohana::message('userguide', 'translations'));
             if (in_array($lang, $translations)) {
                 // Set the language cookie
                 Cookie::set('userguide_language', $lang, Date::YEAR);
             }
             // Reload the page
             $this->request->redirect($this->request->uri);
         }
         // Set the translation language
         I18n::$lang = Cookie::get('userguide_language', Kohana::config('userguide')->lang);
         // Use customized Markdown parser
         define('MARKDOWN_PARSER_CLASS', 'Kodoc_Markdown');
         // Load Markdown support
         require Kohana::find_file('vendor', 'markdown/markdown');
         // Set the base URL for links and images
         Kodoc_Markdown::$base_url = URL::site($this->guide->uri()) . '/';
         Kodoc_Markdown::$image_url = URL::site($this->media->uri()) . '/';
     }
     parent::before();
 }
Ejemplo n.º 9
0
 public static function lang($lang = NULL)
 {
     if ($lang) {
         I18n::$lang = strtolower(str_replace(array(' ', '_'), '-', $lang));
     }
     return I18n::$lang;
 }
Ejemplo n.º 10
0
 public function action_index2()
 {
     I18n::lang('ru');
     //                echo __('Hello, world!');
     $username = '******';
     echo __('Hello, :user', array(':user' => $username));
 }
Ejemplo n.º 11
0
Archivo: docs.php Proyecto: nexeck/docs
	public function before()
	{
		parent::before();

		// Load the configuration settings
		$config = $this->_config = Kohana::config('docs')->as_array();

		// The language is part of the route
		if ($lang = $this->request->param('lang'))
		{
			// Set the language and locale
			I18n::lang($lang);
			setlocale(LC_ALL, $config['language']['supported'][$lang]['locale']);

			// Remember the preferred language
			Cookie::set('lang', $this->lang = $lang);
		}
		else
		{
			// We need a language, try the cookie or use the default
			$lang = Cookie::get('lang', $config['language']['default']);

			// Redirect with a chosen language
			$this->request->redirect($this->request->uri(array('lang' => $lang)));
		}
	}
Ejemplo n.º 12
0
 public static function lang($lang = NULL)
 {
     if ($lang) {
         I18n::$lang = strtolower(str_replace(array(" ", "_"), "-", $lang));
     }
     return I18n::$lang;
 }
Ejemplo n.º 13
0
 /**
  * Application initialization
  *     - Loads the plugins
  *     - Sets the cookie configuration
  */
 public static function init()
 {
     // Set defaule cache configuration
     Cache::$default = Kohana::$config->load('site')->get('default_cache');
     try {
         $cache = Cache::instance()->get('dummy' . rand(0, 99));
     } catch (Exception $e) {
         // Use the dummy driver
         Cache::$default = 'dummy';
     }
     // Load the plugins
     Swiftriver_Plugins::load();
     // Add the current default theme to the list of modules
     $theme = Swiftriver::get_setting('site_theme');
     if (isset($theme) and $theme != "default") {
         Kohana::modules(array_merge(array('themes/' . $theme->value => THEMEPATH . $theme->value), Kohana::modules()));
     }
     // Clean up
     unset($active_plugins, $theme);
     // Load the cookie configuration
     $cookie_config = Kohana::$config->load('cookie');
     Cookie::$httponly = TRUE;
     Cookie::$salt = $cookie_config->get('salt', Swiftriver::DEFAULT_COOKIE_SALT);
     Cookie::$domain = $cookie_config->get('domain') or '';
     Cookie::$secure = $cookie_config->get('secure') or FALSE;
     Cookie::$expiration = $cookie_config->get('expiration') or 0;
     // Set the default site locale
     I18n::$lang = Swiftriver::get_setting('site_locale');
 }
Ejemplo n.º 14
0
 public function before()
 {
     parent::before();
     I18n::lang('ru');
     Cookie::$salt = 'eqw67dakbs';
     Session::$default = 'cookie';
     //$this->cache = Cache::instance('file');
     $this->session = Session::instance();
     $this->auth = Auth::instance();
     $this->user = $this->auth->get_user();
     //  $captcha = Captcha::instance();
     // Подключаем стили и скрипты
     $this->template->styles = array();
     $this->template->scripts = array();
     //Вывод в шаблон
     $this->template->title = null;
     $this->template->site_name = null;
     $this->template->description = null;
     $this->template->page_title = null;
     //Подключаем главный шаблон
     $this->template->main = null;
     $this->template->userarea = null;
     $this->template->top_menu = View::factory('v_top_menu');
     $this->template->manufactures = null;
     $this->template->left_categories = null;
     $this->template->slider_banner = null;
     $this->template->block_left = array();
     $this->template->block_center = array();
     $this->template->block_right = array();
     $this->template->block_footer = null;
 }
Ejemplo n.º 15
0
 public function __isset($column)
 {
     if (in_array($column, $this->_i18n_fields)) {
         $column .= '_' . I18n::lang();
     }
     return parent::__isset($column);
 }
Ejemplo n.º 16
0
 /**
  * 
  * Initializes the php-gettext
  * Remember to load first php-gettext
  * @param string $locale
  * @param string $charset
  * @param string $domain
  */
 public static function initialize($locale = 'en_UK', $charset = 'utf-8', $domain = 'messages')
 {
     /**
      * setting the statics so later we can access them from anywhere
      */
     //we allow to choose lang from the url
     if (Core::config('i18n.allow_query_language') == 1) {
         if (Core::get('language') !== NULL) {
             $locale = Core::get('language');
         } elseif (Cookie::get('user_language') !== NULL) {
             $locale = Cookie::get('user_language');
         }
         Cookie::set('user_language', $locale, Core::config('auth.lifetime'));
     }
     self::$lang = $locale;
     //used in i18n kohana
     self::$locale = $locale;
     self::$charset = $charset;
     self::$domain = $domain;
     //time zone set in the config
     date_default_timezone_set(Kohana::$config->load('i18n')->timezone);
     //Kohana core charset, used in the HTML templates as well
     Kohana::$charset = self::$charset;
     /**
      * In Windows LC_MESSAGES are not recognized by any reason.
      * So we check if LC_MESSAGES is defined to avoid bugs,
      * and force using gettext
      */
     if (defined('LC_MESSAGES')) {
         $locale_res = setlocale(LC_MESSAGES, self::$locale);
     } else {
         $locale_res = FALSE;
     }
     // used with a function money_format
     setlocale(LC_MONETARY, self::$locale);
     /**
      * check if gettext exists if not uses gettext dropin
      */
     if (!function_exists('_') or $locale_res === FALSE or empty($locale_res)) {
         /**
          * gettext override
          * v 1.0.11
          * https://launchpad.net/php-gettext/
          * We load php-gettext here since Kohana_I18n tries to create the function __() function when we extend it.
          * PHP-gettext already does this.
          */
         require Kohana::find_file('vendor', 'php-gettext/gettext', 'inc');
         T_setlocale(LC_MESSAGES, self::$locale);
         T_bindtextdomain(self::$domain, DOCROOT . 'languages');
         T_bind_textdomain_codeset(self::$domain, self::$charset);
         T_textdomain(self::$domain);
         //force to use the gettext dropin
         self::$dropin = TRUE;
     } else {
         bindtextdomain(self::$domain, DOCROOT . 'languages');
         bind_textdomain_codeset(self::$domain, self::$charset);
         textdomain(self::$domain);
     }
 }
Ejemplo n.º 17
0
 private static function loadLang($lang)
 {
     if (!file_exists(__DIR__ . "/../I18n/{$lang}.json")) {
         ErrorManager::push("No I18n file for lang '{$lang}'", ErrorManager::ERROR_I18N_NO_LANG_FILE_FOUND);
     }
     self::$sentences = json_decode(file_get_contents(__DIR__ . "/../I18n/{$lang}.json"), true);
     self::$lang = $lang;
 }
Ejemplo n.º 18
0
 /**
  * Tests i18n::get()
  *
  * @test
  * @dataProvider provider_get
  * @param boolean $input  Input for File::mime
  * @param boolean $expected Output for File::mime
  */
 public function test_get($lang, $input, $expected)
 {
     I18n::lang($lang);
     $this->assertSame($expected, I18n::get($input));
     // Test immediate translation, issue #3085
     I18n::lang('en-us');
     $this->assertSame($expected, I18n::get($input, $lang));
 }
Ejemplo n.º 19
0
 /**
  * Get and set the target language.
  *
  *     // Get the current language
  *     $lang = I18n::lang();
  *
  *     // Change the current language to Spanish
  *     I18n::lang('es-es');
  *
  * @param   string $lang new language setting
  *
  * @return  string
  * @since   3.0.2
  */
 public static function lang($lang = null)
 {
     if ($lang) {
         // Normalize the language
         I18n::$lang = strtolower(str_replace([' ', '_'], '-', $lang));
     }
     return I18n::$lang;
 }
Ejemplo n.º 20
0
 public function before()
 {
     parent::before();
     if (file_exists(CMSPATH . FileSystem::normalize_path('media/js/i18n/' . I18n::lang() . '-message.js'))) {
         Assets::js('i18n', ADMIN_RESOURCES . 'js/i18n/' . I18n::lang() . '-message.js', 'global');
     }
     if ($this->request->action() != 'logout' and Auth::is_logged_in()) {
         $this->go_home();
     }
 }
Ejemplo n.º 21
0
 protected function detect_language()
 {
     $this->language = mb_strtolower((string) Request::initial()->param('language', false));
     if (!$this->language) {
         $this->language = 'ru';
     }
     I18n::lang($this->language);
     URL::$language = $this->language;
     return $this->language;
 }
Ejemplo n.º 22
0
function SearchFormView($arr_search_field, $arr_order_field, $arr_order_select, $url_options)
{
    $form_search = '<form method="get" action="' . Routes::add_get_parameters($url_options, array()) . '">';
    $form_search .= Utils::set_csrf_key();
    $form_search .= I18n::lang('common', 'order_by', 'Order by') . ': ' . SelectForm('order_field', '', $arr_order_field) . ' ' . I18n::lang('common', 'in_order', 'By order') . ': ' . SelectForm('order_desc', '', $arr_order_select);
    $arr_order_field[0] = $_GET['search_field'];
    $form_search .= '<p>' . I18n::lang('common', 'search', 'Search') . ': ' . TextForm('search_word', '', $_GET['search_word']) . ' ' . I18n::lang('common', 'search_by', 'Search by') . ': ' . SelectForm('search_field', '', $arr_search_field) . '</p><p><input type="submit" value="' . I18n::lang('common', 'send', 'Send') . '"/> <input type="button" value="' . I18n::lang('common', 'reset', 'Reset') . '" onclick="javascript:location.href=\'' . $url_options . '\'"/>';
    $form_search .= '</form></p>';
    echo View::load_view(array(I18n::lang('common', 'order_and_search', 'Order and search'), $form_search), 'content');
}
Ejemplo n.º 23
0
 /**
  * Generate the cache key name for a fragment.
  *
  *     $key = Fragment::_cache_key('footer', TRUE);
  *
  * @param   string  $name   fragment name
  * @param   boolean $i18n   multilingual fragment support
  * @return  string
  * @uses    I18n::lang
  * @since   3.0.4
  */
 protected static function _cache_key($name, $i18n = NULL)
 {
     if ($i18n === NULL) {
         // Use the default setting
         $i18n = Fragment::$i18n;
     }
     // Language prefix for cache key
     $i18n = $i18n === TRUE ? I18n::lang() : '';
     // Note: $i18n and $name need to be delimited to prevent naming collisions
     return 'Fragment::cache(' . $i18n . '+' . $name . ')';
 }
Ejemplo n.º 24
0
 public function before()
 {
     parent::before();
     $this->request->headers['Content-Type'] = 'text/plain';
     if ($lang = Kohana::config('torn')->default_controller_lang) {
         I18n::lang($lang);
     }
     if (class_exists('FirePHP_Profiler')) {
         FirePHP_Profiler::instance()->set_config('enabled', FALSE);
     }
 }
Ejemplo n.º 25
0
 /**
  * Generate the cache key name for a fragment
  *
  * [!!] Note: $i18n and $name need to be delimited to prevent naming collisions
  *
  * Example:
  * ~~~
  * $key = Fragment::_cache_key('footer', TRUE);
  * ~~~
  *
  * @param   string   $name  Fragment name
  * @param   boolean  $i18n  Multilingual fragment support [Optional]
  *
  * @return  string
  *
  * @uses    I18n::lang
  */
 protected static function _cache_key($name, $i18n = NULL)
 {
     if (is_null($i18n)) {
         // Use the default setting
         $i18n = Fragment::$i18n;
     }
     // Language prefix for cache key
     $i18n = $i18n === TRUE ? I18n::lang() : '';
     $separator = Cache::SEPARATOR;
     return "Fragment::cache({$i18n}{$separator}{$name})";
 }
Ejemplo n.º 26
0
 public function loadData($controllersArray, $language, $modoTraduccion, $deleteFiles)
 {
     for ($j = 0; $j < count($controllersArray); $j++) {
         $nombre_a = $controllersArray[$j];
         if ($deleteFiles == 1) {
             FuncionesAyuda::delete('application/i18n/' . $nombre_a . '.php');
         }
         if (file_exists('application/i18n/' . $nombre_a . '.php') == false) {
             $conection = ManualConectionUtil::conection();
             mysql_query("SET NAMES utf8");
             //$sql = "SELECT * FROM `languages` WHERE `lang`='" . $language . "' AND controller='" . $nombre_a . "'";
             //echo $sql;
             //die();
             //$result = mysql_query("SELECT * FROM `languages` WHERE `lang`='" . $language . "' AND controller='" . $nombre_a . "'", $conection);
             $result = mysql_query("SELECT * FROM `translate` WHERE `language`='" . $language . "' AND controller='" . $nombre_a . "'", $conection);
             $nfilas = mysql_num_rows($result);
             if ($nfilas > 0) {
                 $controllerFile = fopen('application/i18n/' . $nombre_a . ".php", 'a') or die("problemas al crear archivo");
                 fputs($controllerFile, "<?php \n /*" . $nombre_a . ".php -- archivo de idiomas Kohana " . strtoupper($language) . " \n");
                 fputs($controllerFile, " Author: Solman Vaisman Gonzalez \n");
                 fputs($controllerFile, " Kohana Framework 3.0 Todos los derecho reservados */ \n\n");
                 fputs($controllerFile, "defined('SYSPATH') or die('No direct script access.'); \n\n");
                 fputs($controllerFile, "return array\n");
                 fputs($controllerFile, "(\n");
                 for ($i = 0; $i < $nfilas - 1; $i++) {
                     $row = mysql_fetch_array($result);
                     if ($modoTraduccion == 0) {
                         $text = $row["text"];
                         $textTranslate = $row["textTranslate"];
                     } else {
                         $text = $row["textTranslate"];
                         $textTranslate = $row["text"];
                     }
                     fputs($controllerFile, "\t'" . $text . "' => '" . $textTranslate . "', \n");
                 }
                 $row = mysql_fetch_array($result);
                 if ($modoTraduccion == 0) {
                     $text = $row["text"];
                     $textTranslate = $row["textTranslate"];
                 } else {
                     $text = $row["textTranslate"];
                     $textTranslate = $row["text"];
                 }
                 fputs($controllerFile, "\t'" . $text . "' => '" . $textTranslate . "' \n");
                 fputs($controllerFile, " \n); \n");
                 fputs($controllerFile, " \n ?> ");
                 fclose($controllerFile);
             }
             mysql_close($conection);
         }
         I18n::lang($nombre_a);
     }
 }
Ejemplo n.º 27
0
 public function action_index()
 {
     I18n::lang('ru');
     $text = Model::factory('index')->showIndex();
     $user = Model::factory('index')->showUser();
     $block_center = View::factory('v_index', array('text' => $text, 'username' => $user));
     $messag = Kohana::message('forms/contact', 'errors.user_not_found');
     //вывод шаблона
     // $this->template->page_title = 'Главная';
     $this->template->page_title = Kohana::$config->load('myconf.page_title');
     $this->template->block_center = array($block_center, $messag);
 }
Ejemplo n.º 28
0
 public function before()
 {
     // Do not template media files
     if ($this->request->action === 'media') {
         $this->auto_render = FALSE;
     }
     // Do not require login for media or login/logout
     if ($this->request->action === 'media' or $this->request->action === 'login' or $this->request->action === 'logout') {
         $this->requires_login = FALSE;
     }
     // Set the default view
     $this->view = new View('kohanut/admin');
     if ($this->requires_login) {
         $this->auth = Auth::instance();
         if (!$this->auth->logged_in('login')) {
             $this->request->redirect(Route::get('kohanut-login')->uri(array('action' => 'login')));
         }
         $this->user = $this->auth->get_user();
         if ($this->user) {
             $this->view->user = $this->user->username;
         }
     }
     // plug-in default scripts and styles
     $this->view->bind('styles', $this->styles);
     $this->view->bind('scripts', $this->scripts);
     $this->styles = array(Route::get('kohanut-media')->uri(array('file' => 'css/960.css')) => array('media' => 'screen', 'charset' => 'utf-8'), Route::get('kohanut-media')->uri(array('file' => 'css/template.css')) => array('media' => 'screen', 'charset' => 'utf-8'), Route::get('kohanut-media')->uri(array('file' => 'css/color.css')) => array('media' => 'screen', 'charset' => 'utf-8'), Route::get('kohanut-media')->uri(array('file' => 'css/kohanut.css')) => array('media' => 'screen', 'charset' => 'utf-8'));
     $this->scripts = array(Route::get('kohanut-media')->uri(array('file' => 'jquery/jquery-1.4.2.min.js')) => NULL, Route::get('kohanut-media')->uri(array('file' => 'jquery/jquery.treeview.js')) => NULL, Route::get('kohanut-media')->uri(array('file' => 'jquery/jquery.cookie.js')) => NULL);
     // Route::get('kohanut-media')->uri(array('file'=>'elfinder/js/i18n/elfinder.ru.js'))
     // Check for language change
     if (isset($_GET['lang'])) {
         $lang = $_GET['lang'];
         // Load the accepted language list
         $translations = array_keys(Kohana::message('kohanut', 'translations'));
         if (in_array($lang, $translations)) {
             // Set the language cookie
             Cookie::set('kohanut_language', $lang, Date::YEAR);
         }
         // Reload the page
         $this->request->redirect(Route::get('kohanut-admin')->uri(array('controller' => 'pages')));
     }
     // Set the translation language
     I18n::$lang = Cookie::get('kohanut_language', Kohana::config('kohanut')->lang);
     // Include Twig if it hasn't been yet
     if (!class_exists('Twig_Autoloader')) {
         require Kohana::find_file('vendor', 'Twig/lib/Twig/Autoloader');
         Twig_Autoloader::register();
     }
     // Include Markdown Extra, if it hasn't been yet
     if (!function_exists('Markdown')) {
         require Kohana::find_file('vendor', 'Markdown/markdown');
     }
 }
Ejemplo n.º 29
0
 public function before()
 {
     //$this->redirect('http://ehistory.kz/manage');
     parent::before();
     $this->response->headers('cache-control', 'private');
     // creating and attaching page metadata
     $this->metadata = new Model_Metadata();
     $this->metadata->title(__(Application::instance()->get('title')), false);
     $this->set('_metadata', $this->metadata);
     Auth::instance()->auto_login();
     if (!Auth::instance()->logged_in()) {
         $this->redirect('manage/auth/login');
     } else {
         $id = Auth::instance()->get_user()->id;
         $user = ORM::factory('user', $id);
         $input = $user->has('roles', ORM::factory('role', array('name' => 'admin'))) || $user->has('roles', ORM::factory('Role', array('name' => 'moderator')));
         $input_redactor = $user->has('roles', ORM::factory('Role', array('name' => 'redactor')));
         if (!$input && !$input_redactor) {
             $this->redirect('/manage/auth/logout');
         }
         if (!$input && (strtolower($this->request->controller()) != 'ehistory' && strtolower($this->request->controller()) != 'language')) {
             $this->redirect('manage/ehistory');
         }
     }
     $this->user = Auth::instance()->get_user();
     if (Request::$initial === Request::$current) {
         $messages = Notify::instance()->get_all_once();
         $this->set('_notifications', $messages);
     }
     $language = Session::instance()->get('_language', 'ru');
     $this->language = in_array($language, array('ru', 'en', 'kz')) ? $language : 'ru';
     I18n::lang($this->language);
     $rr = Request::initial()->uri() . urlencode(URL::query(null, true));
     $rr = trim($rr, '/');
     //$this->metadata->title('Sharua.kz', false);
     $countcomm = ORM::factory('Comment')->where('status', '=', '0')->count_all();
     //смотрим сколько новых коментов
     $this->set('_user', $this->user)->set('_language', $this->language)->set('_return_url', $rr)->set('_countcomm', $countcomm);
     //вносим в переменную количество новых коментов
     $knigi = ORM::factory('Book')->where('category_id', '=', '0')->find_all();
     //смотрим сколько книг без категории
     if ($knigi) {
         if (count($knigi) > 0) {
             $this->set('_uncatcount', count($knigi));
             //вносим в переменную количество книг без категории
         }
     }
     $this->referrer = Request::initial()->referrer();
     if (Message::get()) {
         $this->set('basic_message', Message::display('/message/basic'));
     }
 }
Ejemplo n.º 30
0
 public function before()
 {
     // Do not template media files
     if ($this->request->action === 'media') {
         $this->auto_render = FALSE;
     }
     // Do not require login for media or login/logout
     if ($this->request->action === 'media' or $this->request->action === 'login' or $this->request->action === 'logout') {
         $this->requires_login = FALSE;
     }
     // Set the default view
     $this->view = new View('kohanut/admin');
     if ($this->requires_login) {
         // Check if user is logged in
         if ($id = Cookie::get('user')) {
             $user = Sprig::factory('kohanut_user')->values(array('id' => $id))->load();
             if ($user->loaded()) {
                 // user is logged in
                 $this->user = $user;
                 // bind username to view so we can say hello
                 $this->view->user = $user->username;
             }
         }
         // If they aren't logged in, and the page requires login, redirect to login screen
         if (!$this->user) {
             $this->request->redirect(Route::get('kohanut-login')->uri(array('action' => 'login')));
         }
     }
     // Check for language change
     if (isset($_GET['lang'])) {
         $lang = $_GET['lang'];
         // Load the accepted language list
         $translations = array_keys(Kohana::message('kohanut', 'translations'));
         if (in_array($lang, $translations)) {
             // Set the language cookie
             Cookie::set('kohanut_language', $lang, Date::YEAR);
         }
         // Reload the page
         $this->request->redirect(Route::get('kohanut-admin')->uri(array('controller' => 'pages')));
     }
     // Set the translation language
     I18n::$lang = Cookie::get('kohanut_language', Kohana::config('kohanut')->lang);
     // Include Twig if it hasn't been yet
     if (!class_exists('Twig_Autoloader')) {
         require Kohana::find_file('vendor', 'Twig/lib/Twig/Autoloader');
         Twig_Autoloader::register();
     }
     // Include Markdown Extra, if it hasn't been yet
     if (!function_exists('Markdown')) {
         require Kohana::find_file('vendor', 'Markdown/markdown');
     }
 }