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'))); }
public static function save($items) { // save widget to DB $conf = new Model_Config(); $conf->where('group_name', '=', 'general')->where('config_key', '=', 'menu')->limit(1)->find(); if (!$conf->loaded()) { $conf->group_name = 'general'; $conf->config_key = 'menu'; } $conf->config_value = json_encode($items); try { $conf->save(); return TRUE; } catch (Exception $e) { throw HTTP_Exception::factory(500, $e->getMessage()); } return FALSE; }
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'))); }
/** * saves thme options as json 'theme.NAMETHEME' = array json * @param string $theme theme to save at * @param array $data to save * @return void */ public static function save($theme = NULL, $data = NULL) { if ($theme === NULL) { $theme = self::$theme; } if ($data === NULL) { $data = self::$data; } // save theme to DB $conf = new Model_Config(); $conf->where('group_name', '=', 'theme')->where('config_key', '=', $theme)->limit(1)->find(); if (!$conf->loaded()) { $conf->group_name = 'theme'; $conf->config_key = $theme; } $conf->config_value = json_encode($data); try { $conf->save(); } catch (Exception $e) { throw new HTTP_Exception_500(); } }
/** * changes the order to display fields * @param array $order * @return bool */ public function change_order(array $order) { $fields = self::get_all(); $new_fields = array(); //using order they send us foreach ($order as $name) { if (isset($fields[$name])) { $new_fields[$name] = $fields[$name]; } } //save configs $conf = new Model_Config(); $conf->where('group_name', '=', 'advertisement')->where('config_key', '=', 'fields')->limit(1)->find(); if ($conf->loaded()) { try { $conf->config_value = json_encode($new_fields); $conf->save(); return TRUE; } catch (Exception $e) { throw HTTP_Exception::factory(500, $e->getMessage()); } } return FALSE; }
/** * delete current widget data from the DB config * @return boolean */ public function delete() { if ($this->loaded) { // save widget to DB $confw = new Model_Config(); $confw->where('group_name', '=', 'widget')->where('config_key', '=', $this->widget_name)->limit(1)->find(); if ($confw->loaded()) { try { $confw->delete(); //remove from previous placeholder, only if they are different $confp = new Model_Config(); $confp->where('group_name', '=', 'placeholder')->where('config_key', '=', $this->placeholder)->limit(1)->find(); if ($confp->loaded()) { //remove the key $wid = json_decode($confp->config_value); if (is_array($wid)) { $wid = array_diff($wid, array($this->widget_name)); $confp->config_value = json_encode(array_values($wid)); $confp->save(); } } $this->data = array(); $this->loaded = FALSE; return TRUE; } catch (Exception $e) { throw HTTP_Exception::factory(500, $e->getMessage()); } } } return FALSE; }
public function action_saveplaceholders() { //deleting the fragment cache...a bit ugly but works. View::delete_fragment('sidebar_front'); View::delete_fragment('footer_front'); $this->auto_render = FALSE; $this->template = View::factory('js'); DB::delete('config')->where('group_name', '=', 'placeholder')->execute(); //for each placeholder foreach ($_GET as $placeholder => $widgets) { if (!is_array($widgets)) { $widgets = array($widgets); } // save palceholder to DB $confp = new Model_Config(); $confp->where('group_name', '=', 'placeholder')->where('config_key', '=', $placeholder)->limit(1)->find(); if (!$confp->loaded()) { $confp->group_name = 'placeholder'; $confp->config_key = $placeholder; } $confp->config_value = json_encode($widgets); $confp->save(); //edit each widget change placeholder foreach ($widgets as $wname) { $w = Widget::factory($wname); if ($w !== NULL) { if ($w->loaded and $w->placeholder != $placeholder) { $w->placeholder = $placeholder; $w->save(); } } } } $this->template->content = __('Saved'); }
/** * delete current widget data from the DB config * @return boolean */ public function delete() { if ($this->loaded) { // save widget to DB $confw = new Model_Config(); $confw->where('group_name', '=', 'widget')->where('config_key', '=', $this->widget_name)->limit(1)->find(); if ($confw->loaded()) { try { $confw->delete(); //remove from previous placeholder, only if they are different $confp = new Model_Config(); $confp->where('group_name', '=', 'placeholder')->where('config_key', '=', $this->placeholder)->limit(1)->find(); if ($confp->loaded()) { //remove the key $wid = json_decode($confp->config_value); if (is_array($wid)) { $key = array_search($this->widget_name, $wid); if ($key !== FALSE) { unset($wid[$key]); } $confp->config_value = json_encode($wid); $confp->save(); } } $this->data = array(); $this->loaded = FALSE; return TRUE; } catch (Exception $e) { throw new HTTP_Exception_500($e); } } } return FALSE; }