Пример #1
0
 /**
  * Returns the translation table for a given language.
  *
  *     // Get all defined Spanish messages
  *     $messages = I18n::load('es-es');
  * 
  * После генерации таблицы происходит создание Javascript файла с таблицей
  * перевода для загружаемого языка.
  *
  * @param   string  $lang   language to load
  * @return  array
  */
 public static function load($lang)
 {
     $table = parent::load($lang);
     $filename = Kohana::$cache_dir . DIRECTORY_SEPARATOR . implode(DIRECTORY_SEPARATOR, array('i18n', NULL)) . $lang . '.js';
     if (!file_exists($filename) or file_exists($filename) and time() - filemtime($filename) > Date::DAY) {
         if (Kohana::$profiling === TRUE and class_exists('Profiler', FALSE)) {
             // Start a new benchmark
             $benchmark = Profiler::start('i18n', 'Generate file for lang - ' . $lang);
         }
         try {
             // Create the log file
             file_put_contents($filename, '// Auto generated i18n lang file for lang ' . $lang . ". Created on " . date('Y-m-d H:i:s') . "\n");
             file_put_contents($filename, 'cms.addTranslation(' . json_encode($table) . ');', FILE_APPEND);
             // Allow anyone to write to log files
             chmod($filename, 0777);
         } catch (Exception $e) {
             // do something
         }
         if (isset($benchmark)) {
             // Stop the benchmark
             Profiler::stop($benchmark);
         }
     }
     return $table;
 }
Пример #2
0
 public function action_view()
 {
     $id = $this->request->param('id', 0);
     $item = ORM::factory('First', $id);
     if (!$item->loaded()) {
         throw new HTTP_Exception_404();
     }
     $this->set('item', $item);
     $this->add_cumb(Kohana_I18n::get('Хроника деятельности Первого Президента'), 'first');
     $this->add_cumb($item->title, '');
 }
Пример #3
0
 /**
  * Load lang from db table
  * @param string $lang
  * @return array
  */
 public static function load($lang)
 {
     if (Kohana::$environment == Kohana::DEVELOPMENT) {
         if (isset(I18n::$_cache[$lang])) {
             return I18n::$_cache[$lang];
         }
         I18n::$_cache[$lang] = array();
         $language = ORM::factory('language')->find_all()->as_array();
         foreach ($language as $item) {
             I18n::$_cache[$lang][$item->view . '|' . $item->key] = $item->{$lang};
         }
         return I18n::$_cache[$lang];
     } else {
         return parent::load($lang);
     }
 }
Пример #4
0
 public function action_materials()
 {
     if (!Auth::instance()->logged_in()) {
         $this->redirect('/', 301);
     }
     $user_id = $this->user->id;
     $materials = ORM::factory('Material')->where('user_id', '=', $user_id);
     $paginate = Paginate::factory($materials)->paginate(NULL, NULL, 3)->render();
     $materials = $materials->find_all();
     $this->set('materials', $materials);
     $this->set('paginate', $paginate);
     $uploader = View::factory('storage/materials')->set('user_id', $user_id)->render();
     $this->set('uploader', $uploader);
     if ($this->request->method() == Request::POST) {
         $journal = (int) Arr::get($_POST, 'material_type', 0);
         if ($journal !== 1) {
             $journal = 0;
         }
         try {
             $material = ORM::factory('Material');
             $material->theme = substr(Arr::get($_POST, 'theme', ''), 0, 250);
             $material->message = substr(Arr::get($_POST, 'message', ''), 0, 500);
             $material->user_id = $user_id;
             $material->date = date('Y-m-d H:i:s');
             $material->lang_notice = strtolower(Kohana_I18n::lang());
             if ($journal) {
                 $material->is_journal = 1;
                 $material->is_moderator = 0;
             }
             $material->save();
             $files = Arr::get($_POST, 'files', '');
             if ($files) {
                 foreach ($files as $key => $file) {
                     if ($key > 7) {
                         break;
                     }
                     if ($file) {
                         $storage = ORM::factory('Storage', (int) $file);
                         try {
                             $upload = ORM::factory('Material_File');
                             $upload->user_id = $user_id;
                             $upload->material_id = $material->id;
                             $upload->date = date('Y-m-d H:i:s');
                             $upload->storage_id = (int) $file;
                             $upload->filesize = filesize($storage->file_path);
                             $upload->save();
                         } catch (ORM_Validation_Exception $e) {
                         }
                     }
                 }
             }
             Message::success(i18n::get('The material sent to the moderator. Thank you!'));
             $user = ORM::factory('User', $user_id);
             $user_email = $user->email;
             Email::connect();
             Email::View('review_now_' . i18N::lang());
             Email::set(array('message' => I18n::get('Оставленный вами материал находится на рассмотрении редакционной коллегии портала')));
             Email::send($user_email, array('*****@*****.**', 'e-history.kz'), I18n::get('Рассмотрение материала на портале "История Казахстана" e-history.kz'), '', true);
             if ($journal != 1) {
                 $material_type = 'Интересные материалы';
                 $url = URL::media('/manage/materials', TRUE);
             } else {
                 $material_type = 'Журнал e-history';
                 $url = URL::media('/manage/materials/ehistory', TRUE);
             }
             $user_profile = ORM::factory('User_Profile', $user_id);
             if ($user_profile->first_name != '') {
                 $user_name = $user_profile->first_name . ' ' . $user_profile->last_name;
             } else {
                 $user_name = $user->username;
             }
             $email = '*****@*****.**';
             Email::connect();
             Email::View('new_material');
             Email::set(array('url' => $url, 'material_type' => $material_type, 'username' => $user_name));
             Email::send($email, array('*****@*****.**', 'e-history.kz'), "Новый материал на e-history.kz", '', true);
             $this->redirect('profile/materials', 301);
         } catch (ORM_Validation_Exception $e) {
             $errors = $e->errors($e->alias());
             $files = Arr::get($_POST, 'files', '');
             $this->set('errors', $errors)->set('material', $_POST)->set('files', $files);
         }
     }
     $this->add_cumb('User profile', 'profile');
     $this->add_cumb('Downloaded Content', '/');
 }