/** * {@inheritDoc} */ public function on_changeday(Date $yesterday, Date $today) { $config = ShoutboxConfig::load(); if ($config->is_max_messages_number_enabled()) { PersistenceContext::get_querier()->delete(ShoutboxSetup::$shoutbox_table, 'WHERE id NOT IN (SELECT * FROM (SELECT id FROM ' . ShoutboxSetup::$shoutbox_table . ' ORDER BY id DESC LIMIT ' . $config->get_max_messages_number() . ') AS temp)'); } }
private function save() { $this->config->set_items_number_per_page($this->form->get_value('items_number_per_page')); if ($this->form->get_value('max_messages_number_enabled')) { $this->config->enable_max_messages_number(); $this->config->set_max_messages_number($this->form->get_value('max_messages_number')); } else { $this->config->disable_max_messages_number(); } $this->config->set_max_messages_number($this->form->get_value('max_messages_number')); if ($this->form->get_value('max_links_number_per_message_enabled')) { $this->config->enable_max_links_number_per_message(); $this->config->set_max_links_number_per_message($this->form->get_value('max_links_number_per_message')); } else { $this->config->disable_max_links_number_per_message(); } $forbidden_formatting_tags = array(); foreach ($this->form->get_value('forbidden_formatting_tags') as $field => $option) { $forbidden_formatting_tags[] = $option->get_raw_value(); } $this->config->set_forbidden_formatting_tags($forbidden_formatting_tags); if ($this->form->get_value('automatic_refresh_enabled')) { $this->config->enable_automatic_refresh(); $this->config->set_refresh_delay($this->form->get_value('refresh_delay') * 60000); } else { $this->config->disable_automatic_refresh(); } if ($this->form->get_value('date_displayed')) { $this->config->display_date(); } else { $this->config->hide_date(); } if ($this->form->get_value('shout_max_messages_number_enabled')) { $this->config->enable_shout_max_messages_number(); $this->config->set_shout_max_messages_number($this->form->get_value('shout_max_messages_number')); } else { $this->config->disable_shout_max_messages_number(); } if (ModulesManager::is_module_installed('BBCode')) { if ($this->form->get_value('shout_bbcode_enabled')) { $this->config->enable_shout_bbcode(); } else { $this->config->disable_shout_bbcode(); } } if ($this->form->get_value('validation_onkeypress_enter_enabled')) { $this->config->enable_validation_onkeypress_enter(); } else { $this->config->disable_validation_onkeypress_enter(); } $this->config->set_authorizations($this->form->get_value('authorizations')->build_auth_array()); ShoutboxConfig::save(); }
private function build_form(HTTPRequestCustom $request) { $config = ShoutboxConfig::load(); $formatter = AppContext::get_content_formatting_service()->get_default_factory(); $formatter->set_forbidden_tags($config->get_forbidden_formatting_tags()); $form = new HTMLForm(__CLASS__); $fieldset = new FormFieldsetHTML('message', $this->is_new_message ? $this->lang['shoutbox.add'] : $this->lang['shoutbox.edit']); $form->add_fieldset($fieldset); if (!AppContext::get_current_user()->check_level(User::MEMBER_LEVEL)) { $fieldset->add_field(new FormFieldTextEditor('pseudo', LangLoader::get_message('form.name', 'common'), $this->get_message()->get_login(), array('required' => true, 'maxlength' => 25))); } $fieldset->add_field(new FormFieldRichTextEditor('contents', LangLoader::get_message('message', 'main'), $this->get_message()->get_contents(), array('formatter' => $formatter, 'rows' => 10, 'cols' => 47, 'required' => true), array(new FormFieldConstraintMaxLinks($config->get_max_links_number_per_message(), true), new FormFieldConstraintAntiFlood(ShoutboxService::get_last_message_timestamp_from_user($this->get_message()->get_author_user()->get_id()))))); $fieldset->add_field(new FormFieldHidden('page', $request->get_getint('page', 1))); $this->submit_button = new FormButtonDefaultSubmit(); $form->add_button($this->submit_button); $form->add_button(new FormButtonReset()); $this->form = $form; }
private function build_view() { $this->lang = LangLoader::get('common', 'shoutbox'); $this->view = new FileTemplate('shoutbox/ShoutboxAjaxMessagesBoxController.tpl'); $this->view->add_lang($this->lang); $config = ShoutboxConfig::load(); $this->view->put('C_DISPLAY_DATE', $config->is_date_displayed()); $result = PersistenceContext::get_querier()->select('SELECT * FROM ' . ShoutboxSetup::$shoutbox_table . ' s LEFT JOIN ' . DB_TABLE_MEMBER . ' m ON m.user_id = s.user_id ORDER BY s.timestamp DESC ' . ($config->is_shout_max_messages_number_enabled() ? 'LIMIT ' . $config->get_shout_max_messages_number() : '')); while ($row = $result->fetch()) { $shoutbox_message = new ShoutboxMessage(); $shoutbox_message->set_properties($row); $this->view->assign_block_vars('messages', array_merge($shoutbox_message->get_array_tpl_vars())); } $result->dispose(); }
public function get_menu_content() { //Create file template $tpl = new FileTemplate('shoutbox/ShoutboxModuleMiniMenu.tpl'); //Assign the lang file to the tpl $tpl->add_lang(LangLoader::get('common', 'shoutbox')); $config = ShoutboxConfig::load(); $forbidden_tags = array_flip($config->get_forbidden_formatting_tags()); if ($config->is_shout_bbcode_enabled()) { $smileys_cache = SmileysCache::load(); $smileys_per_line = 5; //Smileys par ligne. $smileys_displayed_number = 0; foreach ($smileys_cache->get_smileys() as $code_smile => $infos) { $smileys_displayed_number++; $tpl->assign_block_vars('smileys', array('C_END_LINE' => $smileys_displayed_number % $smileys_per_line == 0, 'URL' => TPL_PATH_TO_ROOT . '/images/smileys/' . $infos['url_smiley'], 'CODE' => addslashes($code_smile))); } } $tpl->put_all(array('C_MEMBER' => AppContext::get_current_user()->check_level(User::MEMBER_LEVEL), 'C_DISPLAY_FORM' => ShoutboxAuthorizationsService::check_authorizations()->write() && !AppContext::get_current_user()->is_readonly(), 'C_VALIDATE_ONKEYPRESS_ENTER' => $config->is_validation_onkeypress_enter_enabled(), 'C_DISPLAY_SHOUT_BBCODE' => ModulesManager::is_module_installed('BBCode') && $config->is_shout_bbcode_enabled(), 'C_BOLD_DISABLED' => isset($forbidden_tags['b']), 'C_ITALIC_DISABLED' => isset($forbidden_tags['i']), 'C_UNDERLINE_DISABLED' => isset($forbidden_tags['u']), 'C_STRIKE_DISABLED' => isset($forbidden_tags['s']), 'C_AUTOMATIC_REFRESH_ENABLED' => $config->is_automatic_refresh_enabled(), 'SHOUTBOX_PSEUDO' => AppContext::get_current_user()->get_display_name(), 'SHOUT_REFRESH_DELAY' => $config->get_refresh_delay(), 'L_ALERT_LINK_FLOOD' => sprintf(LangLoader::get_message('e_l_flood', 'errors'), $config->get_max_links_number_per_message()), 'SHOUTBOX_MESSAGES' => ShoutboxAjaxRefreshMessagesController::get_view())); return $tpl->render(); }
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 get_pagination($messages_number, $page) { $pagination = new ModulePagination($page, $messages_number, (int) ShoutboxConfig::load()->get_items_number_per_page()); $pagination->set_url(ShoutboxUrlBuilder::home('%d')); if ($pagination->current_page_is_empty() && $page > 1) { $error_controller = PHPBoostErrors::unexisting_page(); DispatchManager::redirect($error_controller); } return $pagination; }
private function get_authorizations($bit) { return AppContext::get_current_user()->check_auth(ShoutboxConfig::load()->get_authorizations(), $bit); }