public function synchronize() { $this->messages = array(); $items_number_per_page = GuestbookConfig::load()->get_items_per_page(); $result = PersistenceContext::get_querier()->select("SELECT g.id, g.login, g.contents, g.timestamp, m.user_id, m.display_name, m.level, m.groups\r\n\t\tFROM " . GuestbookSetup::$guestbook_table . " g\r\n\t\tLEFT JOIN " . DB_TABLE_MEMBER . " m ON m.user_id = g.user_id\r\n\t\tGROUP BY g.id\r\n\t\tORDER BY RAND()\r\n\t\tLIMIT 50"); $page = $i = 1; foreach ($result as $msg) { if ($i > $page * $items_number_per_page) { $page++; } $this->messages[$msg['id']] = array('id' => $msg['id'], 'contents' => strip_tags(FormatingHelper::second_parse($msg['contents'])), 'user_id' => $msg['user_id'], 'login' => $msg['display_name'] ? $msg['display_name'] : $msg['login'], 'level' => $msg['level'], 'groups' => $msg['groups'], 'timestamp' => $msg['timestamp'], 'page' => $page); $i++; } $result->dispose(); }
private function build_form(HTTPRequestCustom $request) { $config = GuestbookConfig::load(); $formatter = AppContext::get_content_formatting_service()->get_default_factory(); $formatter->set_forbidden_tags($config->get_forbidden_tags()); $form = new HTMLForm(__CLASS__); $fieldset = new FormFieldsetHTML('message', $this->is_new_message ? $this->lang['guestbook.add'] : $this->lang['guestbook.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_maximum_links_message(), true), new FormFieldConstraintAntiFlood(GuestbookService::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 get_pagination($messages_number, $page) { $pagination = new ModulePagination($page, $messages_number, (int) GuestbookConfig::load()->get_items_per_page()); $pagination->set_url(GuestbookUrlBuilder::home('%d')); if ($pagination->current_page_is_empty() && $page > 1) { $error_controller = PHPBoostErrors::unexisting_page(); DispatchManager::redirect($error_controller); } return $pagination; }
private function init() { $this->config = GuestbookConfig::load(); $this->lang = LangLoader::get('common', 'guestbook'); $this->admin_common_lang = LangLoader::get('admin-common'); }
private function get_authorizations($bit) { return AppContext::get_current_user()->check_auth(GuestbookConfig::load()->get_authorizations(), $bit); }