public function getContent() { global $sql; $this->err = new Error(); $this->pager = new Pager('guestbook', Kio::getStat('entries', 'guestbook'), Kio::getConfig('limit', 'guestbook')); $show_form = true; $entries = $this->getEntries(); // Editing entry if (ctype_digit(u2)) { // guestbook/edit/u2 $edited_id = u1 == 'edit' ? u2 : ''; if (!User::hasPermit('guestbook edit')) { $this->note->error(t('You don't have access to edit entries.')); $show_form = false; } else { if ($edited_id) { $row = $sql->query(' SELECT id, added, author, author_id, author_ip, email, website, message FROM ' . DB_PREFIX . 'guestbook WHERE id = ' . $edited_id)->fetch(); // Entry exists if ($row) { $form = $row; $this->edit_mode = true; if (!$row['author']) { $form['author'] = User::getNickname(BY_ID, $row['author_id']); } } else { $this->note->error(t('Selected entry doesn't exist.')); } } } } if (!$this->edit_mode) { $form['author'] = User::$nickname; } // Form action $add = isset($_POST['add']) ? true : false; $edit = isset($_POST['edit']) ? true : false; // On form submit if ($add || $edit) { $form = $this->formSumbit(); } else { if (isset($_POST['delete_id']) && ctype_digit($_POST['delete_id']) && $_POST['auth'] == AUTH && User::hasPermit('guestbook delete')) { $sql->exec(' UPDATE ' . DB_PREFIX . 'stats SET content = content - 1 WHERE name = "guestbook_entries"; DELETE FROM ' . DB_PREFIX . 'guestbook WHERE id = ' . $_POST['delete_id']); $sql->clearCacheGroup('guestbook_*'); } } try { $tpl = new PHPTAL('modules/guestbook/guestbook.tpl.html'); $tpl->message_limit = Kio::getConfig('message_max', 'guestbook'); $tpl->form = $form; $tpl->edit_mode = $this->edit_mode; $tpl->entries = $entries; $tpl->err = $this->err->toArray(); $tpl->show_form = $show_form; $tpl->note = $this->note; $tpl->pagination = $this->pager->getLinks(); return $tpl->execute(); } catch (Exception $e) { return template_error($e); } }
public function getContent() { global $sql; $this->err = new Error(); $pager = new Pager('guestbook', Kio::getStat('entries', 'guestbook'), Kio::getConfig('limit', 'guestbook')); if (Kio::getConfig('order_by', 'guestbook') == 'DESC') { $x = $pager->items + 1 - $pager->offset; $y = '$x--;'; } else { $x = $pager->offset; $y = '$x++;'; } // $entries = $sql->getCache('guestbook_'.$pager->current); if (!$entries) { $stmt = $sql->query(' SELECT gb.id, gb.added, gb.author, gb.email, gb.website, gb.message, gb.author_id, gb.author_ip, u.nickname, u.group_id, u.avatar, u.signature FROM ' . DB_PREFIX . 'guestbook gb LEFT JOIN ' . DB_PREFIX . 'users u ON u.id = gb.author_id ORDER BY gb.id ' . Kio::getConfig('order_by', 'guestbook') . ' LIMIT ' . $pager->limit . ' OFFSET ' . $pager->offset); if ($stmt->rowCount()) { while ($row = $stmt->fetch()) { eval($y); $row['number'] = $x; if ($row['author_id']) { $row['author'] = User::format($row['author_id'], $row['nickname'], $row['group_id']); } $row['message'] = parse($row['message'], Kio::getConfig('parsers', 'guestbook')); $row['signature'] = $row['signature'] ? parse($row['signature'], Kio::getConfig('parsers', 'guestbook')) : ''; $entries[] = $row; } $sql->putCacheContent('guestbook_' . $pager->current, $entries); } else { $this->note->info('Jeszcze nikt nie dodał żadnego wpisu.'); } } // Editing entry if (ctype_digit(u2)) { // guestbook/edit/u2 $edited_id = u1 == 'edit' ? u2 : ''; if (!User::hasPermit('guestbook edit')) { $this->note->error(t('You do not have access to edit entries.')); } else { if ($edited_id) { $row = $sql->query(' SELECT id, added, author, author_id, author_ip, email, website, message FROM ' . DB_PREFIX . 'guestbook WHERE id = ' . $edited_id)->fetch(); // Entry exists if ($row) { $form = $row; $form['edit_mode'] = true; if (!$row['author']) { $form['author'] = User::getNickname(BY_ID, $row['author_id']); } } else { $this->note->error(t('Selected entry doesn't exist.')); } } } } if (!$form['edit_mode']) { $form['author'] = User::$nickname; } // Form action $add = $_POST['add'] ? true : false; $edit = $_POST['edit'] ? true : false; // On form submit if ($add || $edit) { $this->formSumbit(); } else { if (ctype_digit($_POST['delete_id']) && $_POST['auth'] == AUTH && User::hasPermit('guestbook delete')) { $sql->exec(' UPDATE ' . DB_PREFIX . 'stats SET content = content - 1 WHERE name = "guestbook_entries"; DELETE FROM ' . DB_PREFIX . 'guestbook WHERE id = ' . $_POST['delete_id']); $sql->clearCacheGroup('guestbook_*'); } } try { $tpl = new PHPTAL('modules/guestbook/guestbook.tpl.html'); $tpl->message_limit = Kio::getConfig('message_max', 'guestbook'); $tpl->form = $form; $tpl->entries = $entries; $tpl->err = $this->err->toArray(); $tpl->note = $this->note; $tpl->pagination = $pager->getLinks(); return $tpl->execute(); } catch (Exception $e) { return template_error($e); } }