/**
  * @param string $last_posted_timestamp Timestamp
  * @param string $anti_flood_duration seconde
  * @param string $error_message
  */
 public function __construct($last_posted_timestamp, $anti_flood_duration = '', $error_message = '')
 {
     $this->content_management_config = ContentManagementConfig::load();
     $this->last_posted_timestamp = $last_posted_timestamp;
     if (empty($anti_flood_duration)) {
         $anti_flood_duration = $this->content_management_config->get_anti_flood_duration();
     }
     $this->anti_flood_duration = $anti_flood_duration;
     if (empty($error_message)) {
         $error_message = LangLoader::get_message('e_flood', 'errors');
     }
     $this->set_validation_error_message($error_message);
 }
 public function execute(HTTPRequestCustom $request)
 {
     if ($this->check_authorizations()) {
         $pseudo = TextHelper::strprotect(utf8_decode($request->get_string('pseudo', '')));
         $contents = TextHelper::htmlentities($request->get_string('contents', ''), ENT_COMPAT, 'UTF-8');
         $contents = TextHelper::htmlspecialchars_decode(TextHelper::html_entity_decode($contents, ENT_COMPAT, 'windows-1252'));
         if ($pseudo && $contents) {
             //Mod anti-flood, autorisé aux membres qui bénificie de l'autorisation de flooder.
             $check_time = AppContext::get_current_user()->get_id() !== -1 && ContentManagementConfig::load()->is_anti_flood_enabled() ? PersistenceContext::get_querier()->get_column_value(PREFIX . "shoutbox", 'MAX(timestamp)', 'WHERE user_id = :id', array('id' => AppContext::get_current_user()->get_id())) : '';
             if (!empty($check_time) && !AppContext::get_current_user()->check_max_value(AUTH_FLOOD)) {
                 if ($check_time >= time() - ContentManagementConfig::load()->get_anti_flood_duration()) {
                     $code = -1;
                 }
             }
             //Vérifie que le message ne contient pas du flood de lien.
             $config_shoutbox = ShoutboxConfig::load();
             $contents = FormatingHelper::strparse($contents, $config_shoutbox->get_forbidden_formatting_tags());
             if (!TextHelper::check_nbr_links($contents, $config_shoutbox->get_max_links_number_per_message(), true)) {
                 //Nombre de liens max dans le message.
                 $code = -2;
             }
             $shoutbox_message = new ShoutboxMessage();
             $shoutbox_message->init_default_properties();
             $shoutbox_message->set_login($pseudo);
             $shoutbox_message->set_user_id(AppContext::get_current_user()->get_id());
             $shoutbox_message->set_contents($contents);
             $shoutbox_message->set_creation_date(new Date());
             $code = ShoutboxService::add($shoutbox_message);
         } else {
             $code = -3;
         }
     } else {
         $code = -4;
     }
     return new JSONResponse(array('code' => $code));
 }
 private function save()
 {
     $this->content_formatting_config->set_default_editor($this->form->get_value('formatting_language')->get_raw_value());
     $this->content_formatting_config->set_html_tag_auth($this->form->get_value('authorizations')->build_auth_array());
     $forbidden_tags = array();
     foreach ($this->form->get_value('forbidden_tags') as $field => $option) {
         $forbidden_tags[] = $option->get_raw_value();
     }
     $this->content_formatting_config->set_forbidden_tags($forbidden_tags);
     ContentFormattingConfig::save();
     if ($this->form->get_value('anti_flood_enabled')) {
         $this->content_management_config->set_anti_flood_enabled(true);
     } else {
         $this->content_management_config->set_anti_flood_enabled(false);
     }
     $this->content_management_config->set_anti_flood_duration($this->form->get_value('delay_flood'));
     $this->content_management_config->set_used_captcha_module($this->form->get_value('captcha_used')->get_raw_value());
     ContentManagementConfig::save();
     $this->user_accounts_config->set_max_private_messages_number($this->form->get_value('max_pm_number'));
     UserAccountsConfig::save();
 }
 /**
  * @param string $id_module
  */
 public function uninstall_captcha($id_module)
 {
     $captchas = $this->get_available_captchas();
     if (count($captchas) > 1) {
         $default_captcha = $this->get_default_captcha();
         if ($default_captcha !== $id_module) {
             $config = ContentManagementConfig::load();
             $config->set_used_captcha_module($default_captcha);
             ContentManagementConfig::save();
             return null;
         } else {
             return LangLoader::get_message('captcha.is_default', 'status-messages-common');
         }
     }
     return LangLoader::get_message('captcha.last_installed', 'status-messages-common');
 }