Пример #1
0
         $settings['app_title'] = htmlspecialchars($_POST['app_title']);
         $settings['app_copyright'] = htmlspecialchars($_POST['app_copyright']);
         $settings['app_description'] = empty($_POST['app_description']) ? htmlspecialchars($_POST['app_title']) : htmlspecialchars($_POST['app_description']);
         $settings['app_robots'] = Setting::ParseRobots(in_array('index', $_POST['app_robots']), in_array('follow', $_POST['app_robots']), in_array('archive', $_POST['app_robots']));
         $settings['api_display_doc'] = !empty($_POST['api_display_doc']);
         $settings['api_requests'] = !empty($_POST['api_requests']);
         /*
         if (!empty($_POST['conf_email_sender']) && !filter_var($_POST['conf_email_sender'], FILTER_VALIDATE_EMAIL))
             throw new \Exception('Please enter a valid sender email address.');
         $settings['conf_email_sender'] = htmlspecialchars($_POST['conf_email_sender']);
         */
         foreach ($settings as $key => $value) {
             $s = new Setting($key);
             if ($s->getValue() != $settings[$key]) {
                 $s->setValue($value);
                 if (!$s->save()) {
                     throw new \Exception('Unable to save the new value for ' . $key . '.');
                 }
             }
         }
         $message_success = true;
     } catch (\Exception $e) {
         $this->assign('form_error', $e->getMessage());
     }
 } else {
     $this->assign('form_data', array('app_name' => (new Setting('app_name'))->getValue(), 'app_title' => (new Setting('app_title'))->getValue(), 'app_copyright' => (new Setting('app_copyright'))->getValue(), 'app_description' => (new Setting('app_description'))->getValue(), 'app_robots' => Setting::GetRobots((new Setting('app_robots'))->getValue()), 'conf_email_sender' => (new Setting('conf_email_sender'))->getValue(), 'api_display_doc' => (new Setting('api_display_doc'))->getValue(), 'api_requests' => (new Setting('api_requests'))->getValue()));
 }
 if (isset($message_success)) {
     $this->assign('message', 'Settings have been updated.');
 }
 $this->page('manage/settings');