Esempio n. 1
0
 /**
  * action: EDIT
  */
 public function action_edit()
 {
     $id = $this->request->param('id');
     $content = new Model_Content($id);
     $type = $content->type;
     $site = $type == 'page' ? __('Page') : __('Email');
     Breadcrumbs::add(Breadcrumb::factory()->set_title(__('Edit') . ' ' . $site));
     $locale = $content->locale;
     if ($content->loaded()) {
         $languages = i18n::get_languages();
         $this->template->content = View::factory('oc-panel/pages/content/edit', array('cont' => $content, 'locale' => $languages));
         if ($p = $this->request->post()) {
             foreach ($p as $name => $value) {
                 if ($name != 'submit') {
                     $content->{$name} = $value;
                 }
             }
             // if status is not checked, it is not set as POST response
             $content->status = isset($p['status']) ? 1 : 0;
             //$content->seotitle = $content->gen_seotitle($this->request->post('title'));
             try {
                 $content->save();
                 Cache::instance()->delete_all();
                 Alert::set(Alert::SUCCESS, $content->type . ' ' . __('is edited'));
                 Request::current()->redirect(Route::url('oc-panel', array('controller' => 'content', 'action' => 'edit', 'id' => $content->id_content)));
             } catch (Exception $e) {
                 Alert::set(Alert::ERROR, $e->getMessage());
             }
         }
     } else {
         Alert::set(Alert::INFO, __('Faild to load content'));
         Request::current()->redirect(Route::url('oc-panel', array('controller' => 'content', 'action' => 'edit')) . '?type=' . $type . '&locale_select=' . $locale);
     }
 }
Esempio n. 2
0
 public function action_index()
 {
     // validation active
     Breadcrumbs::add(Breadcrumb::factory()->set_title(__('List')));
     $this->template->title = __('Translations');
     //scan project files and generate .po
     $parse = $this->request->query('parse');
     if ($parse) {
         //scan script
         require_once Kohana::find_file('vendor', 'POTCreator/POTCreator', 'php');
         $obj = new POTCreator();
         $obj->set_root(DOCROOT);
         $obj->set_exts('php');
         $obj->set_regular('/_[_|e]\\([\\"|\']([^\\"|\']+)[\\"|\']\\)/i');
         $obj->set_base_path('..');
         $obj->set_read_subdir(true);
         $obj->write_pot(i18n::get_language_path());
         Alert::set(Alert::SUCCESS, 'File regenerated');
     }
     //change default site language
     if ($this->request->param('id')) {
         //save language
         $locale = new Model_Config();
         $locale->where('group_name', '=', 'i18n')->where('config_key', '=', 'locale')->limit(1)->find();
         if (!$locale->loaded()) {
             $locale->group_name = 'i18n';
             $locale->config_key = 'locale';
         }
         $locale->config_value = $this->request->param('id');
         try {
             $locale->save();
             Alert::set(Alert::SUCCESS, __('Translations regenarated'));
         } catch (Exception $e) {
             throw HTTP_Exception::factory(500, $e->getMessage());
         }
         HTTP::redirect(Route::url('oc-panel', array('controller' => 'translations')));
     }
     //create language
     if (Core::post('locale')) {
         $language = $this->request->post('locale');
         $folder = DOCROOT . 'languages/' . $language . '/LC_MESSAGES/';
         // if folder does not exist, try to make it
         if (!file_exists($folder) and !@mkdir($folder, 0775, true)) {
             // mkdir not successful ?
             Alert::set(Alert::ERROR, __('Language folder cannot be created with mkdir. Please correct to be able to create new translation.'));
             HTTP::redirect(Route::url('oc-panel', array('controller' => 'translations')));
         }
         // write an empty .po file for $language
         $out = 'msgid ""' . PHP_EOL;
         $out .= 'msgstr ""' . PHP_EOL;
         File::write($folder . 'messages.po', $out);
         Alert::set(Alert::SUCCESS, $this->request->param('id') . ' ' . __('Language saved'));
     }
     $this->template->content = View::factory('oc-panel/pages/translations/index', array('languages' => i18n::get_languages(), 'current_language' => core::config('i18n.locale')));
 }
Esempio n. 3
0
 /**
  * Automatically executed before the widget action. Can be used to set
  * class properties, do authorization checks, and execute other custom code.
  *
  * @return  void
  */
 public function before()
 {
     //we need this option enabled for this plugin to work
     if (Core::config('i18n.allow_query_language') == 0) {
         Model_Config::set_value('i18n', 'allow_query_language', 1);
     }
     if ($this->languages == '') {
         $this->languages = i18n::get_languages();
     } else {
         $this->languages = array_map('trim', explode(',', $this->languages));
     }
 }
Esempio n. 4
0
 public function action_index()
 {
     // validation active
     Breadcrumbs::add(Breadcrumb::factory()->set_title(__('List')));
     $this->template->title = __('Translations');
     //scan project files and generate .po
     if (core::get('parse') !== NULL) {
         //scan script
         require_once Kohana::find_file('vendor', 'POTCreator/POTCreator', 'php');
         $obj = new POTCreator();
         $obj->set_root(DOCROOT);
         $obj->set_exts('php');
         $obj->set_regular('/_[_|e]\\([\\"|\']([^\\"|\']+)[\\"|\']\\)/i');
         $obj->set_base_path('..');
         $obj->set_read_subdir(true);
         $obj->write_pot(i18n::get_language_path());
         Alert::set(Alert::SUCCESS, 'File regenerated');
     }
     //change default site language
     if (($locale = $this->request->param('id')) != NULL and array_key_exists($locale, i18n::get_languages())) {
         //save language
         Model_Config::set_value('i18n', 'locale', $locale);
         //change the cookie if not he will not see the changes
         if (Core::config('i18n.allow_query_language') == 1) {
             Cookie::set('user_language', $locale, Core::config('auth.lifetime'));
         }
         Alert::set(Alert::SUCCESS, __('Language') . ' ' . $locale);
         HTTP::redirect(Route::url('oc-panel', array('controller' => 'translations')));
     }
     //create language
     if (Core::post('locale')) {
         $language = $this->request->post('locale');
         $folder = DOCROOT . 'languages/' . $language . '/LC_MESSAGES/';
         // if folder does not exist, try to make it
         if (!file_exists($folder) and !@mkdir($folder, 0775, true)) {
             // mkdir not successful ?
             Alert::set(Alert::ERROR, __('Language folder cannot be created with mkdir. Please correct to be able to create new translation.'));
             HTTP::redirect(Route::url('oc-panel', array('controller' => 'translations')));
         }
         // write an empty .po file for $language
         $out = 'msgid ""' . PHP_EOL;
         $out .= 'msgstr ""' . PHP_EOL;
         File::write($folder . 'messages.po', $out);
         Alert::set(Alert::SUCCESS, $this->request->param('id') . ' ' . __('Language saved'));
     }
     $this->template->content = View::factory('oc-panel/pages/translations/index', array('languages' => i18n::get_languages(), 'current_language' => core::config('i18n.locale')));
 }
Esempio n. 5
0
 public function action_index()
 {
     // validation active
     Breadcrumbs::add(Breadcrumb::factory()->set_title(__('List')));
     $this->template->title = __('Translations');
     //scan project files and generate .po
     $parse = $this->request->query('parse');
     if ($parse) {
         //scan script
         require_once Kohana::find_file('vendor', 'POTCreator/POTCreator', 'php');
         $obj = new POTCreator();
         $obj->set_root(DOCROOT);
         $obj->set_exts('php');
         $obj->set_regular('/_[_|e]\\([\\"|\']([^\\"|\']+)[\\"|\']\\)/i');
         $obj->set_base_path('..');
         $obj->set_read_subdir(true);
         $obj->write_pot(i18n::get_language_path());
         Alert::set(Alert::SUCCESS, 'File regenerated');
     }
     //change default site language
     if ($this->request->param('id')) {
         //save language
         $locale = new Model_Config();
         $locale->where('group_name', '=', 'i18n')->where('config_key', '=', 'locale')->limit(1)->find();
         if (!$locale->loaded()) {
             $locale->group_name = 'i18n';
             $locale->config_key = 'locale';
         }
         $locale->config_value = $this->request->param('id');
         try {
             $locale->save();
             Alert::set(Alert::SUCCESS, '');
             Request::current()->redirect(Route::url('oc-panel', array('controller' => 'translations')));
         } catch (Exception $e) {
             echo $e;
         }
     }
     $this->template->content = View::factory('oc-panel/pages/translations/index', array('languages' => i18n::get_languages(), 'current_language' => core::config('i18n.locale')));
 }
Esempio n. 6
0
 /**
  * action: EDIT
  */
 public function action_edit()
 {
     $id = $this->request->param('id');
     $content = new Model_Content($id);
     $type = $content->type;
     $site = self::translate_type($type);
     Breadcrumbs::add(Breadcrumb::factory()->set_title($site)->set_url(Route::url('oc-panel', array('controller' => 'content', 'action' => $type))));
     Breadcrumbs::add(Breadcrumb::factory()->set_title(__('Edit') . ' ' . $site));
     $locale = $content->locale;
     if ($content->loaded()) {
         $languages = i18n::get_languages();
         $this->template->content = View::factory('oc-panel/pages/content/edit', array('cont' => $content, 'locale' => $languages));
         if ($p = $this->request->post()) {
             foreach ($p as $name => $value) {
                 //for description we accept the HTML as comes...a bit risky but only admin can
                 if ($name == 'description') {
                     $content->description = Kohana::$_POST_ORIG['description'];
                 } elseif ($name != 'submit') {
                     $content->{$name} = $value;
                 }
             }
             // if status is not checked, it is not set as POST response
             $content->status = isset($p['status']) ? 1 : 0;
             try {
                 $content->save();
                 Alert::set(Alert::SUCCESS, $content->type . ' ' . __('is edited'));
             } catch (Exception $e) {
                 Alert::set(Alert::ERROR, $e->getMessage());
             }
             HTTP::redirect(Route::url('oc-panel', array('controller' => 'content', 'action' => 'edit', 'id' => $content->id_content)));
         }
     } else {
         Alert::set(Alert::INFO, __('Failed to load content'));
         HTTP::redirect(Route::url('oc-panel', array('controller' => 'content', 'action' => 'edit')) . '?type=' . $type . '&locale_select=' . $locale);
     }
 }
Esempio n. 7
0
 public function form_setup($form)
 {
     $form->fields['order']['display_as'] = 'select';
     $form->fields['order']['options'] = range(0, 30);
     $form->fields['locale']['display_as'] = 'select';
     $form->fields['locale']['options'] = i18n::get_languages();
     $form->fields['seotitle']['display_as'] = 'hidden';
 }
Esempio n. 8
0
File: i18n.php Progetto: rair/yacs
 /**
  * get language codes as options of a selectable list
  *
  * This function returns a full <select> tag with the name 'language' and the id 'language'.
  *
  * If no parameter is provided, then surfer language is used.
  *
  * @param string the current language, if any
  * @param string alternate name and id of the returned tag
  * @return the HTML to insert in the page
  */
 public static function &get_languages_select($current = NULL, $id = 'language')
 {
     global $context;
     // use surfer language by default
     if (!$current) {
         $current = $context['language'];
     }
     // all options
     $text = '<select name="' . $id . '" id="' . $id . '">' . "\n";
     // fetch the list of languages
     $languages =& i18n::get_languages();
     // engage surfer
     $text .= '<option value="none">' . i18n::s('Use browser settings') . "</option>\n";
     // current language setting
     if ($current == $context['language']) {
         $text .= '<option value="' . $context['language'] . '" selected="selected">' . i18n::get_language_label($context['language']) . "</option>\n";
     } else {
         $text .= '<option value="' . $context['language'] . '">' . i18n::get_language_label($context['language']) . "</option>\n";
     }
     // all options
     foreach ($languages as $code => $label) {
         // is this the current setting?
         if ($code == $context['language']) {
             continue;
         }
         // the code
         $text .= '<option value="' . $code . '"';
         // is this the current option?
         if ($code == $current) {
             $text .= ' selected="selected"';
         }
         // the label for this language
         $text .= '>' . $label . "</option>\n";
     }
     // return by reference
     $text .= '</select>';
     // job done
     return $text;
 }