コード例 #1
0
ファイル: config.php プロジェクト: rundiz/fuel-start
 public function action_index()
 {
     // check permission
     if (\Model_AccountLevelPermission::checkAdminPermission('config_global', 'config_global') == false) {
         \Session::set_flash('form_status', array('form_status' => 'error', 'form_status_message' => \Lang::get('admin_permission_denied', array('page' => \Uri::string()))));
         \Response::redirect(\Uri::create('admin'));
     }
     // get timezone list for select box
     \Config::load('timezone', 'timezone');
     $output['timezone_list'] = \Config::get('timezone.timezone', array());
     // read flash message for display errors.
     $form_status = \Session::get_flash('form_status');
     if (isset($form_status['form_status']) && isset($form_status['form_status_message'])) {
         $output['form_status'] = $form_status['form_status'];
         $output['form_status_message'] = $form_status['form_status_message'];
     }
     unset($form_status);
     $allowed_field = array();
     // load config to form.
     $result = \DB::select('*')->from(\Model_Config::getTableName())->as_object('Model_Config')->where('config_core', '1')->execute();
     if ((is_array($result) || is_object($result)) && !empty($result)) {
         foreach ($result as $row) {
             $allowed_field[] = $row->config_name;
             $output[$row->config_name] = $row->config_value;
         }
     }
     unset($result, $row);
     // if form submitted
     if (\Input::method() == 'POST') {
         // store data to variable for update to db.
         $data = array();
         foreach (\Input::post() as $key => $value) {
             if (in_array($key, $allowed_field)) {
                 $data[$key] = $value;
             }
         }
         unset($allowed_field);
         // check again for some required default value config data.
         // tab website
         $data['site_name'] = \Security::htmlentities($data['site_name']);
         $data['page_title_separator'] = \Security::htmlentities($data['page_title_separator']);
         // tab account
         if (!isset($data['member_allow_register']) || $data['member_allow_register'] != '1') {
             $data['member_allow_register'] = '0';
         }
         if (!isset($data['member_register_notify_admin']) || $data['member_register_notify_admin'] != '1') {
             $data['member_register_notify_admin'] = '0';
         }
         if (!isset($data['simultaneous_login']) || $data['simultaneous_login'] != '1') {
             $data['simultaneous_login'] = '******';
         }
         if (!is_numeric($data['member_max_login_fail'])) {
             $data['member_max_login_fail'] = '10';
         }
         if (!is_numeric($data['member_login_fail_wait_time'])) {
             $data['member_login_fail_wait_time'] = '30';
         }
         if (!is_numeric($data['member_login_remember_length'])) {
             $data['member_login_remember_length'] = '30';
         }
         if (!is_numeric($data['member_confirm_wait_time'])) {
             $data['member_confirm_wait_time'] = '10';
         }
         if (!isset($data['member_email_change_need_confirm']) || $data['member_email_change_need_confirm'] != '1') {
             $data['member_email_change_need_confirm'] = '0';
         }
         if (!isset($data['allow_avatar']) || $data['allow_avatar'] != '1') {
             $data['allow_avatar'] = '0';
         }
         if (!is_numeric($data['avatar_size'])) {
             $data['avatar_size'] = '200';
         }
         if (empty($data['avatar_allowed_types'])) {
             $data['avatar_allowed_types'] = 'jpg|jpeg';
         }
         if ($data['avatar_path'] == null) {
             unset($data['avatar_path']);
         }
         // tab email
         if ($data['mail_protocol'] == null) {
             $data['mail_protocol'] = 'mail';
         }
         if (!is_numeric($data['mail_smtp_port'])) {
             $data['mail_smtp_port'] = '0';
         }
         // tab content
         if (!is_numeric($data['content_items_perpage'])) {
             $data['content_items_perpage'] = '10';
         }
         if (!is_numeric($data['content_admin_items_perpage'])) {
             $data['content_admin_items_perpage'] = '10';
         }
         // tab media
         if (empty($data['media_allowed_types'])) {
             $data['media_allowed_types'] = 'avi|doc|docx|flv|gif|jpeg|jpg|mid|midi|mov|mp3|mpeg|mpg|pdf|png|swf|xls|xlsx|zip';
         }
         // tab ftp
         if (!is_numeric($data['ftp_port'])) {
             $data['ftp_port'] = '21';
         }
         if (!isset($data['ftp_passive']) || $data['ftp_passive'] != 'false') {
             $data['ftp_passive'] = 'true';
         }
         // validate form.
         $validate = \Validation::forge();
         if (!\Extension\NoCsrf::check()) {
             // validate token failed
             $output['form_status'] = 'error';
             $output['form_status_message'] = \Lang::get('fslang_invalid_csrf_token');
         } elseif (!$validate->run()) {
             // validate failed
             $output['form_status'] = 'error';
             $output['form_status_message'] = $validate->show_errors();
         } else {
             // try to save config.
             $result = \Model_Config::saveData($data);
             // save change site name to sites table
             $site_id = \Model_Sites::getSiteId(false);
             $entry = \Model_Sites::find($site_id);
             $entry->site_name = $data['site_name'];
             $entry->save();
             unset($entry, $site_id);
             if ($result === true) {
                 \Session::set_flash('form_status', array('form_status' => 'success', 'form_status_message' => \Lang::get('admin_saved')));
                 \Response::redirect(\Uri::main());
             } else {
                 $output['form_status'] = 'error';
                 $output['form_status_message'] = $result;
             }
         }
         // re-populate form.
         foreach ($data as $key => $value) {
             $output[$key] = html_entity_decode($value);
         }
     }
     // <head> output ----------------------------------------------------------------------------------------------
     $output['page_title'] = $this->generateTitle(\Lang::get('config_global_configuration'));
     // <head> output ----------------------------------------------------------------------------------------------
     // breadcrumb -------------------------------------------------------------------------------------------------
     $page_breadcrumb = [];
     $page_breadcrumb[0] = ['name' => \Lang::get('admin_admin_home'), 'url' => \Uri::create('admin')];
     $page_breadcrumb[1] = ['name' => \Lang::get('config_global_configuration'), 'url' => \Uri::create('admin/config')];
     $output['page_breadcrumb'] = $page_breadcrumb;
     unset($page_breadcrumb);
     // breadcrumb -------------------------------------------------------------------------------------------------
     return $this->generatePage('admin/templates/config/index_v', $output, false);
 }