public function getContent() { global $sql; //Lang::load('blocks/shoutbox/lang.*.php'); $err = new Error(); $note = new Notifier('note-shoutbox'); $form['author'] = LOGGED ? User::$nickname : ''; $form['message'] = ''; if (isset($_POST['reply-shoutbox'])) { $form['author'] = LOGGED ? User::$nickname : filter($_POST['author-shoutbox'], 100); $form['message'] = filter($_POST['message-shoutbox'], Kio::getConfig('message_max', 'shoutbox')); $err->setError('author_empty', t('Author field is required.'))->condition(!$form['author']); $err->setError('author_exists', t('Entered nickname is registered.'))->condition(!LOGGED && is_registered($form['author'])); $err->setError('message_empty', t('Message field is required.'))->condition(!$form['message']); // No errors if ($err->noErrors()) { $sql->exec(' INSERT INTO ' . DB_PREFIX . 'shoutbox (added, author, message, author_id, author_ip) VALUES ( ' . TIMESTAMP . ', "' . $form['author'] . '", "' . cut($form['message'], Kio::getConfig('message_max', 'shoutbox')) . '", ' . UID . ', "' . IP . '")'); $sql->clearCache('shoutbox'); $note->success(t('Entry was added successfully.')); redirect(HREF . PATH . '#shoutbox'); } else { $note->error($err->toArray()); } } // If cache for shoutbox doesn't exists if (!($entries = $sql->getCache('shoutbox'))) { $query = $sql->query(' SELECT u.nickname, u.group_id, s.added, s.author, s.author_id, s.message FROM ' . DB_PREFIX . 'shoutbox s LEFT JOIN ' . DB_PREFIX . 'users u ON u.id = s.author_id ORDER BY s.id DESC LIMIT ' . Kio::getConfig('limit', 'shoutbox')); while ($row = $query->fetch()) { if ($row['author_id']) { $row['author'] = User::format($row['author_id'], $row['nickname'], $row['group_id']); $row['message'] = parse($row['message'], Kio::getConfig('parser', 'shoutbox')); } $entries[] = $row; } $sql->putCacheContent('shoutbox', $entries); } try { $tpl = new PHPTAL('blocks/shoutbox/shoutbox.tpl.html'); $tpl->entries = $entries; $tpl->err = $err->toArray(); $tpl->form = $form; $tpl->note = $note; return $tpl->execute(); } catch (Exception $e) { return template_error($e->getMessage()); //echo Note::error($e->getMessage()); } }
public static function getForm($errors = array()) { global $cfg; if (LOGGED) { redirect(REFERER); } $note = new Notifier(); $err = new Error(); if ($errors) { $note->error($errors); } if ($_POST['login'] && $_POST['module']) { $form = array('logname' => $_POST['logname-session'] ? filter($_POST['logname-session'], 100) : '', 'password' => $_POST['password-session'] ? filter($_POST['password-session'], 100) : ''); $err->setError('empty_logname', t('Logname field is required.'))->condition(!$form['logname']); $err->setError('logname_not_exists', t('The logname you used isn't registered.'))->condition($form['logname'] && !User::loginNameRegistered($form['logname'])); $err->setError('password_empty', t('Password field is required.'))->condition(!$form['password']); $err->setError('password_invalid', t('Password is invalid.'))->condition($form['password'] && !User::loginPasswordCorrect($form['password'])); $err->noErrors() ? redirect(REFERER) : $note->restore()->error($err->toArray()); } $tpl = new PHPTAL('modules/login/form.html'); $tpl->form = $form; $tpl->err = $err->toArray(); $tpl->note = $note; echo $tpl->execute(); }
public function getContent() { // User is logged in if (LOGGED) { $this->subcodename = 'logged'; $tpl = new PHPTAL('blocks/user_panel/logged.html'); $tpl->user = User::format(User::$id, User::$nickname, User::$groupId); $pm_item = User::$pmNew ? array(t('Messages <strong>(New: %new)</strong>', array('%new' => $user->pm_new)), 'pm/inbox') : array(t('Messages'), 'pm'); $tpl->items = items(array($pm_item[0] => HREF . $pm_item[1], t('Administration') => HREF . 'admin', t('Edit profile') => HREF . 'edit_profile', t('Log out') => HREF . 'logout')); return $tpl->execute(); } else { $err = new Error(); $note = new Notifier('note-user_panel'); $this->subcodename = 'not_logged'; $form = array('logname' => null, 'password' => null); if ($_POST['login'] && $_POST['user_panel']) { $form['logname'] = $_POST['logname-session'] ? filter($_POST['logname-session'], 100) : ''; $form['password'] = $_POST['password-session'] ? $_POST['password-session'] : ''; $err->setError('logname_empty', t('Logname field is required.'))->condition(!$form['logname']); $err->setError('logname_not_exists', t('Entered logname is not registered.'))->condition(!User::loginNameRegistered($form['logname'])); $err->setError('password_empty', t('Password field is required.'))->condition(!$form['password']); $err->setError('password_incorrect', t('ERROR_PASS_INCORRECT'))->condition($form['password'] && !User::loginPasswordCorrect($form['password'])); if ($err->noErrors()) { redirect('./'); } else { $note->error($err->toArray()); } } $tpl = new PHPTAL('blocks/user_panel/not_logged.html'); $tpl->note = $note; $tpl->form = $form; $tpl->err = $err->toArray(); return $tpl->execute(); } }
/** * @return array */ public function toArray() { $output = ['jsonrpc' => $this->jsonrpc, 'id' => $this->id]; if ($this->hasError()) { $output['error'] = $this->error->toArray(); } else { if ($this->result instanceof Jsonable) { $output['result'] = json_decode($this->result->toJson()); } else { $output['result'] = $this->result; } } return $output; }
public function merge(Error $error) { $data = $error->toArray(); $count = 0; if (count($data['trace']) > 0) { foreach ($data['trace'] as $trace) { $this->trace($trace); $count++; } } if ($data['info']) { $this->trace($data['info']); $count++; } return $count; }
public function getContent() { $err = new Error(); $note = new Notifier('note-newsletter'); $form = array(); $tpl = 'blocks/newsletter/newsletter_form.html'; if (isset($_POST['add-newsletter']) || isset($_POST['delete-newsletter']) || isset($_POST['delete2-newsletter'])) { include_once ROOT . 'blocks/newsletter/action.php'; } try { $tpl = new PHPTAL($tpl); $tpl->err = $err->toArray(); $tpl->note = $note; $tpl->form = $form; return $tpl->execute(); } catch (Exception $e) { return template_error($e->getMessage()); } }
public function getContent() { global $sql; $err = new Error(); $form = array(); if (Kio::getConfig('informations', 'contact')) { $info = Notifier::factory('note-contact_info')->info(parse(Kio::getConfig('informations', 'contact'), BBCODE . AUTOLINKS . EMOTICONS . CENSURE . PRE)); } if (isset($_POST['send'])) { // Form values $form = array('receiver' => filter($_POST['receiver'], 100), 'sender' => LOGGED ? User::$nickname : filter($_POST['sender'], 100), 'email' => LOGGED ? User::$email : filter($_POST['email'], 100), 'subject' => filter($_POST['subject'], 100), 'message' => filter($_POST['message'], 250)); if (!empty($_COOKIE[COOKIE . '-flood-contact']) && Kio::getConfig('flood_interval')) { $err->setError('flood', t('ERROR_FLOOD')); } else { // Errors if (!LOGGED) { $err->setError('sender_empty', t('Sender field is required.'))->condition(!$form['sender']); $err->setError('sender_exists', t('ERROR_SENDER_EXISTS'))->condition(is_registered($form['sender'], 'nickname')); $err->setError('email_empty', t('E-mail address field is required.'))->condition(!$form['email']); $err->setError('email_invalid', t('ERROR_EMAIL_INVALID'))->condition($form['email'] && !is_email($form['email'])); } // $err->setError('phone_invalid', t('ERROR_PHONE_INVALID')) // ->condition($form['phone'] && !preg_match('#^[0-9 ()+-]+$#', $form['phone'])); $err->setError('subject_empty', t('Subject field is required.'))->condition(!$form['subject']); $err->setError('message_empty', t('Message field is required.'))->condition(!$form['message']); } if ($err->noErrors()) { $from = "From: {$form['email']}2"; $msg = "Imię: {$imie}\nE-Mail: {$form['email']}2\nTelefon: {$telefon}\n\nTreść wiadomości:\n{$form['message']}\n\n\n----\nWiadomość została wysłana ze strony {$adres}\nIP: {$ip}"; echo mail($form['email'], $temat, $msg, $from) ? $note->success(t('SUCCESS')) . redirect() : $note->error(t('Wystąpił błąd, spróbuj wysłać później')); if (Kio::getConfig('flood_interval')) { setcookie(COOKIE . '-contact', 'true', TIMESTAMP + Kio::getConfig('flood_interval') + 1, '/'); } $to = "*****@*****.**"; $subject = "Test mail"; $message = "Hello! This is a simple email message."; $from = "*****@*****.**"; $headers = "From: {$from}"; mail($to, $subject, $message, $headers); } else { $this->note->error($err->toArray()); } } $stmt = $sql->setCache('contact')->prepare(' SELECT id, nickname, group_id FROM ' . DB_PREFIX . 'users WHERE id IN (:receivers)'); $stmt->bindParam(':receivers', Kio::getConfig('receivers', 'contact')); $stmt->execute(); while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) { $row['g_name'] = Kio::getGroup($row['group_id'], 'name'); $receivers[] = $row; } try { $tpl = new PHPTAL('modules/contact/contact.tpl.html'); $tpl->message_limit = Kio::getConfig('message_max', 'contact'); $tpl->form = $form; $tpl->user = User::toArray(); $tpl->receivers = $receivers; $tpl->err = $err->toArray(); $tpl->note = $this->note; $tpl->info = isset($info) ? $info : ''; return $tpl->execute(); } catch (Exception $e) { return template_error($e); } }
function toDatabase(Error $error) { $data = $error->toArray(); $sql = 'INSERT INTO messages (' . join(',', array_keys($data)) . ') VALUES (' . join(',' . $data) . ')'; return ($db = sqlite_open(DIR_ROOT . '/data/system.db')) && sqlite_query($db, $sql) && sqlite_close($db); }
public function getContent() { global $sql; $this->note = new Notifier(); $err = new Error(); // Redirect logged users to front page // Activate account // registration/activate/234/sfs9fsefsef36dsdgesefe4td if (u1 == 'activate' && ctype_digit(u2)) { return $this->accountActivation(); } else { if (Kio::getConfig('type', 'registration') == 0) { return $this->note->error('Rejestracja została <strong>wstrzymana</strong>.'); } else { // Kio::addJsCode('$(\'#check_logname\').click(function(){alert();});'); // Registering if (isset($_POST['register'])) { // filter(string, limit) $form = array('logname' => $_POST['logname'] ? filter($_POST['logname'], 100) : '', 'nickname' => $_POST['nickname'] ? filter($_POST['nickname'], 100) : '', 'pass' => $_POST['pass'] ? filter($_POST['pass'], 100) : '', 'pass2' => $_POST['pass2'] ? filter($_POST['pass2'], 100) : '', 'email' => strtolower(filter($_POST['email'], 100)), 'rules' => $_POST['rules'] ? true : false, 'newsletter' => $_POST['newsletter'] ? 1 : 0, 'pm_notify' => $_POST['pm_notify'] ? 1 : 0, 'hide_email' => $_POST['hide_email'] ? 1 : 0); // Errors $err->setError('logname_empty', t('Logname field is required.'))->condition(!$form['logname']); $err->setError('logname_exists', t('The logname you used is already registered.'))->condition(is_registered($form['logname'], 'logname')); $err->setError('nickname_empty', t('Nickname field is required.'))->condition(!$form['nickname']); $err->setError('nickname_exists', t('The nickname you used is already registered.'))->condition(is_registered($form['nickname'], 'nickname')); $err->setError('pass_empty', t('Password field is required.'))->condition(!$form['pass']); $err->setError('pass_not_match', t('Passwords do not match.'))->condition($form['pass'] != $form['pass2'] && $form['pass']); $err->setError('email_empty', t('E-mail field is required.'))->condition(!$form['email']); $err->setError('email_invalid', t('E-mail address you entered is invalid.'))->condition($form['email'] && !is_email($form['email'])); $err->setError('email_exists', t('The e-mail you used is already registered.'))->condition(is_registered($form['email'], 'email')); $err->setError('rules_not_accepted', t('Accepting the rules is required.'))->condition(!$form['rules'] && Kio::getConfig('show_rules', 'registration')); // No errors if ($err->noErrors()) { $blocked = 1; switch (Kio::getConfig('type', 'registration')) { case 1: $blocked = 'NULL'; $message = 'Rejestracja przebiegła pomyślnie, możesz się teraz zalogować.'; break; case 2: $message = 'Rejestracja przebiegła pomyślnie.<br />Wymagana jest aktywacja konta poprzez kliknięcie w odnośnik wysłany na Twoją skrzynkę e-mail.'; break; default: $message = 'Rejestracja przebiegła pomyślnie.<br />Wymagana jest aktywacja konta przez administratora, wówczas zostaniesz powiadomiony e-mail'em.'; } // Detect country $form['country'] = end(explode('.', gethostbyaddr(IP))); $form['country'] = $lang_system['COUNTRIES'][$form['country']] ? $form['country'] : ''; $stmt = $sql->prepare(' INSERT INTO ' . DB_PREFIX . 'users SET logname = :logname, nickname = :nickname, email = :email, pass = :pass, registered = :registered, country = :country, newsletter = :newsletter, pm_notify = :pm_notify, hide_email = :hide_email, blocked = :blocked, time_zone = :time_zone, ip = :ip, auth_code = :auth_code, http_agent = :http_agent; UPDATE ' . DB_PREFIX . 'stats SET content = content + 1 WHERE name = "registered_users"'); $stmt->execute(array('logname' => $form['logname'], 'nickname' => $form['nickname'], 'email' => $form['email'], 'pass' => md5($form['pass']), 'registered' => TIMESTAMP, 'country' => $form['country'], 'newsletter' => $form['newsletter'], 'pm_notify' => $form['pm_notify'], 'hide_email' => $form['hide_email'], 'blocked' => 1, 'time_zone' => Kio::getConfig('time_zone'), 'ip' => IP, 'auth_code' => auth_code($form['logname']), 'http_agent' => filter($_SERVER['HTTP_USER_AGENT'], 250))); $this->note->success($message); redirect(HREF . 'registration'); } else { $this->note->error($err->toArray()); } } // // No action // else // { // $this->note->info(array(t('Register and enjoy additional services.'))); // } try { $tpl = new PHPTAL('modules/registration/registration.tpl.html'); $tpl->form = $form; $tpl->entries = $entries; $tpl->err = $err->toArray(); $tpl->note = $this->note; return $tpl->execute(); } catch (Exception $e) { return template_error($e); } } } }
} else { $velden = json_decode(stripslashes($_GET["velden"])); $waarden = json_decode(stripslashes($_GET["waarden"])); //query opbouwen $q = "SELECT id FROM error WHERE "; foreach ($waarden as $key => $value) { $q .= $velden[$key] . " LIKE '%" . $value . "%' AND "; } $q = substr($q, 0, -6); } $q .= " ORDER BY datum DESC"; $_SESSION["query"] = $q; //eerste een query voor het aantal resultaten $statement = DB::getDB()->prepare($q); $statement->execute(); $statement->store_result(); $paginering['aantal_rijen'] = $statement->num_rows; $q .= " LIMIT {$vanaf}, {$AANTAL_PER_PAGINA}"; $lijst = array(); $statement = DB::getDB()->prepare($q); $statement->execute(); $statement->store_result(); $statement->bind_result($id); while ($statement->fetch()) { $e = new Error($id); $lijst[] = $e->toArray(); } $statement->close(); $paginering["aantal_paginas"] = ceil($paginering['aantal_rijen'] / $AANTAL_PER_PAGINA); $uitvoer = array($paginering, $lijst); echo json_encode($uitvoer);
function login($errors = array()) { global $cfg; if (LOGGED) { redirect(REFERER); } if ($errors) { $note = new Notifier(); $note->error($errors); } $err = new Error(); if ($_POST['login'] && $_POST['module']) { include_once ROOT . 'modules/login/action.php'; } $tpl = new PHPTAL('modules/login/form.html'); $tpl->form = $form; $tpl->err = $err->toArray(); $tpl->note = $note; echo $tpl->execute(); }
public function getContent() { global $sql; if (!LOGGED) { return no_access('By mieć dostęp do edycji profilu musisz się zalogować.'); } $note = new Notifier(); $err = new Error(); $edit = isset($_POST['edit']) ? true : false; $countries = (include 'lang/countries.php'); asort($countries); //Edit user by ID if (ctype_digit(u1)) { $profile = $sql->query(' SELECT u.* FROM ' . DB_PREFIX . 'users u WHERE u.id = ' . u1)->fetch(PDO::FETCH_ASSOC); if ($profile) { Kio::addTitle(t('Users')); Kio::addBreadcrumb(t('Users'), 'users'); Kio::addTitle($profile['nickname'] . ' - ' . t('Edit profile')); Kio::addBreadcrumb($profile['nickname'], 'profile/' . u1); Kio::addBreadcrumb(t('Edit profile'), 'edit_profile/' . u1); $form = $profile; } else { return not_found(t('Selected user doesn't exists.'), array(t('This person was deleted from database.'), t('Entered URL is invalid.'))); } } else { $profile = User::toArray(); Kio::addTitle(t('Edit profile')); Kio::addBreadcrumb(t('Edit profile'), 'edit_profile'); } $form = $profile; $form['password'] = ''; $form['password2'] = ''; $form['birthdate'] = explode('-', $profile['birthdate']); $form['newsletter'] = $profile['newsletter'] ? 1 : 0; $form['pm_notify'] = $profile['pm_notify'] ? 1 : 0; $form['hide_email'] = $profile['hide_email'] ? 1 : 0; if (!u1 || $profile) { // Edit profile if (!empty($edit)) { $form = array('nickname' => Kio::getConfig('allow_change_nick', 'edit_profile') ? filter($_POST['nickname'], 100) : User::$nickname, 'password' => filter($_POST['password'], 100), 'password2' => filter($_POST['password2'], 100), 'email' => strtolower(filter($_POST['email'], 100)), 'forename' => $_POST['forename'], 'surname' => $_POST['surname'], 'gender' => $_POST['gender'], 'locality' => $_POST['locality'], 'country' => !empty($countries[$_POST['country']]) ? $_POST['country'] : '', 'communicator' => $_POST['communicator'], 'website' => $_POST['website'], 'birthdate' => array_map('intval', (array) $_POST['birthdate']), 'newsletter' => isset($_POST['newsletter']) ? 1 : 0, 'pm_notify' => isset($_POST['pm_notify']) ? 1 : 0, 'hide_email' => isset($_POST['hide_email']) ? 1 : 0, 'avatar' => $_FILES['avatar']['error'] == 0 && !$_POST['delete_avatar'] ? $_FILES['avatar'] : array(), 'delete_avatar' => isset($_POST['delete_avatar']) ? 1 : 0, 'photo' => isset($_FILES['photo']) ? $_FILES['photo'] : null, 'delete_photo' => isset($_POST['delete_photo']) ? 1 : 0, 'title' => $_POST['title'], 'interests' => $_POST['interests'], 'signature' => $_POST['signature']); $allowed_types = array('image/png' => 'png', 'image/jpeg' => 'jpg', 'image/gif' => 'gif'); // Nickname $err->setError('nickname_empty', t('ERROR_NICKNAME_EMPTY'))->condition(!$form['nickname']); $err->setError('nickname_exists', t('ERROR_NICKNAME_EXISTS'))->condition(Kio::getConfig('allow_change_nick', 'edit_profile') && $form['nickname'] && strtolower($form['nickname']) != strtolower($profile['nickname']) && is_registered($form['nickname'])); // Password $err->setError('password_differ', t('ERROR_PASSWORD_DIFFER'))->condition($form['password'] != $form['password2']); // E-mail $err->setError('email_empty', t('ERROR_EMAIL_EMPTY'))->condition(!$form['email']); if ($form['email']) { $err->setError('email_invalid', t('ERROR_EMAIL_INVALID'))->condition($form['email'] && !is_email($form['email'])); $err->setError('email_exists', t('ERROR_EMAIL_EXISTS'))->condition($form['email'] != $profile['email'] && is_email($form['email']) && is_registered($form['email'], 'email')); } // Birthdate $err->setError('birthdate_invalid', t('ERROR_BIRTHDATE'))->condition(array_sum($form['birthdate']) > 0 && !is_date('Y-n-j', $form['birthdate'][0] . '-' . $form['birthdate'][1] . '-' . $form['birthdate'][2])); // Avatar if ($form['avatar']) { $err->avatar_invalid_type(t('ERROR_ava'))->condition(!in_array($form['avatar']['type'], array_keys($allowed_types))); $err->avatar_exceeded_max_size(t('ERROR_ava'))->condition(Kio::getConfig('avatar_size_max', 'edit_profile') && !$err->isError('avatar_invalid_type') && $form['avatar']['size'] > Kio::getConfig('avatar_size_max', 'edit_profile')); } // No errors if ($err->noErrors()) { if ($form['delete_avatar']) { unlink(ROOT . 'images/avatars/' . $profile['id'] . '.' . User::$avatar); } if ($form['avatar']) { move_uploaded_file($_FILES['avatar']['tmp_name'], ROOT . 'images/avatars/' . $profile['id'] . '.' . $allowed_types[$form['avatar']['type']]); if ($allowed_types[$form['avatar']['type']] != User::$avatar) { unlink(ROOT . 'images/avatars/' . $profile['id'] . '.' . User::$avatar); } } $form['birthdate'] = array_sum($form['birthdate']) > 0 ? $form['birthdate'][0] . '-' . $form['birthdate'][1] . '-' . $form['birthdate'][2] : ''; $sql->exec(' UPDATE ' . DB_PREFIX . 'users SET nickname = "' . (Kio::getConfig('allow_change_nick', 'edit_profile') ? $form['nickname'] : User::$nickname) . '", ' . ($form['password'] ? 'pass = "******",' : '') . ' email = "' . $form['email'] . '", forename = "' . $form['forename'] . '", surname = "' . $form['surname'] . '", gender = ' . ($form['gender'] == 1 || $form['gender'] == 2 ? (int) $form['gender'] : 0) . ', locality = "' . $form['locality'] . '", country = "' . $form['country'] . '", communicator = "' . $form['communicator'] . '", website = "' . $form['website'] . '", birthdate = "' . $form['birthdate'] . '", newsletter = ' . $form['newsletter'] . ', pm_notify = ' . $form['pm_notify'] . ', hide_email = ' . $form['hide_email'] . ', ' . ($form['avatar'] ? 'avatar = "' . $allowed_types[$form['avatar']['type']] . '",' : ($form['delete_avatar'] ? 'avatar = "",' : '')) . ' title = "' . $form['title'] . '", interests = "' . $form['interests'] . '", signature = "' . $form['signature'] . '" WHERE id = ' . $profile['id']); $note->success(t('Your profile was modified successfully.')); redirect(HREF . 'edit_profile'); } else { $note->error($err->toArray()); } } try { $tpl = new PHPTAL('modules/edit_profile/edit_profile.tpl.html'); $tpl->profile = $profile; $tpl->countries = $countries; $tpl->allow_change_nick = Kio::getConfig('allow_change_nick', 'edit_profile'); $tpl->form = $form; $tpl->err = $err->toArray(); $tpl->note = $note; return $tpl->execute(); } catch (Exception $e) { return template_error($e); } } }
function getContent() { global $cfg, $user, $sql, $plug; $note = new Notifier(); $tpl = new PHPTAL('plugins/comments/comments.tpl.html'); $err = new Error(); $tpl->entries = ''; if ($this->total_comments != -1 && !Kio::getConfig('view_only_logged', 'comments')) { if ($this->total_comments > 0) { $tpl->backlink = $this->backlink; $tpl->cfg = $cfg; $tpl->user = $user; $tpl->entries = $this->getEntries(); } else { $note->info('There is no comments.'); } if (!Kio::getConfig('add_only_logged', 'comments') || LOGGED) { if ($this->edited) { $form = array('id' => $this->edited['comment_id'], 'author' => $this->edited['comment_author'], 'author_id' => $this->edited['comment_author_id'], 'message' => $this->edited['comment_message']); if (!$form['author']) { $form['author'] = User::getNickname(BY_ID, $this->edited['comment_author_id']); } $this->edit_mode = true; } else { $form['author'] = User::$nickname; } $add = isset($_POST['add']) ? true : false; $edit = isset($_POST['edit']) ? true : false; // Add or delete if (isset($_POST['add']) || $edit) { $form['author'] = isset($_POST['add']) && LOGGED ? User::$nickname : filter($_POST['author'], 100); $form['message'] = filter($_POST['message'], Kio::getConfig('message_max', 'comments')); $err->setError('author_empty', t('Author field is required.'))->condition(!$form['author']); $err->setError('author_exists', t('Entered nickname is registered.'))->condition($add && !LOGGED && is_registered($form['author'], 'nickname')); $err->setError('message_empty', t('Message field is required.'))->condition(!$form['message']); // No errors if ($err->noErrors()) { // Add if (isset($_POST['add'])) { $sql->exec(' INSERT INTO ' . DB_PREFIX . 'comments ( comment_owner, comment_owner_child_id, comment_author, comment_author_id, comment_author_ip, comment_added, comment_message, comment_backlink) VALUES( "' . u0 . '", ' . $this->connector_id . ', "' . (!LOGGED || isset($_POST['edit']) ? $form['author'] : '') . '", ' . UID . ', "' . IP . '", ' . TIMESTAMP . ', "' . $form['message'] . '", "' . $this->backlink . '")'); $last = $sql->lastInsertId(); $sql->exec(' UPDATE ' . DB_PREFIX . $this->owner . ' SET comments = (comments + 1) WHERE id = ' . $this->connector_id); setcookie(COOKIE . '-comments', 'true', TIMESTAMP + Kio::getConfig('flood_interval', 'comments') + 1, '/'); redirect(HREF . PATH . '#comment-' . $last); } else { if (isset($_POST['edit'])) { if ($form['author_id'] = User::getId(BY_NICKNAME, $form['author'])) { $form['author'] = ''; } else { $form['author_id'] = 0; } $sql->exec(' UPDATE ' . DB_PREFIX . 'comments SET comment_author = "' . $form['author'] . '", comment_author_id = ' . $form['author_id'] . ', comment_message = "' . $form['message'] . '" WHERE comment_id = ' . $this->edited['comment_id']); redirect(HREF . $this->edited['comment_backlink'] . '#comment-' . $this->edited['comment_id']); } } } else { $note->error($err->toArray()); } } else { if (isset($_POST['delete_id']) && ctype_digit($_POST['delete_id'])) { $sql->exec(' DELETE FROM ' . DB_PREFIX . 'comments WHERE comment_id = ' . $_POST['delete_id'] . '; UPDATE ' . DB_PREFIX . $this->owner . ' SET comments = (comments - 1) WHERE id = ' . $this->connector_id); redirect(strpos(REFERER, 'admin') ? REFERER : '#comments'); } } //$tpl->comments = $comments; $tpl->form = $form; $tpl->err = $err->toArray(); } else { $note->error(sprintf('Dodawanie komentarzy jest możliwe tylko dla <a href="%1$slogin">zalogowanych</a> osób, <a href="%1$sregistration">zarejestruj się</a> jeśli nie masz jeszcze konta.', HREF)); } } else { if ($this->total_comments != -1) { $note->error(array('Komentarze są widoczne tylko dla zalogowanych osób.', '<a href="' . HREF . 'registration">Zarejestruj się</a> jeśli nie masz jeszcze konta.')); } } $tpl->edit_mode = $this->edit_mode; $tpl->total_comments = $this->total_comments; $tpl->note = $note; return $tpl->execute(); }
private function getComposeForm() { global $sql; Kio::addTitle(t('Compose message')); Kio::addBreadcrumb(t('Compose message'), 'pm/write'); $err = new Error(); $note = new Notifier(); if ((u2 == 'resend' || u2 == 'reply') && ctype_digit(u3)) { if (u2 == 'reply') { $message = $sql->query(' SELECT connector_id, subject FROM ' . DB_PREFIX . 'pm WHERE id = ' . u3 . ' AND folder != 1')->fetch(PDO::FETCH_ASSOC); $form['subject'] = 'Re: ' . $message['subject']; } else { $message = $sql->query(' SELECT connector_id, subject, message FROM ' . DB_PREFIX . 'pm WHERE id = ' . (int) u3 . ' AND folder = 1')->fetch(PDO::FETCH_ASSOC); $form['subject'] = $message['subject']; $form['message'] = $message['message']; } $form['receiver'] = User::getNickname(BY_ID, $message['connector_id']); } else { if (ctype_digit(u2)) { $form['receiver'] = User::getNickname(BY_ID, u2); } } if (isset($_POST['send'])) { // Form values $form = array('receiver' => filter($_POST['receiver'], 100), 'subject' => filter($_POST['subject'], 100), 'save' => $_POST['save'], 'bbcode' => $_POST['bbcode'] ? BBCODE : 0, 'emoticons' => $_POST['emoticons'] ? EMOTICONS : 0, 'autolinks' => $_POST['autolinks'] ? AUTOLINKS : 0, 'message' => filter($_POST['message'], 250)); $err->setError('receiver_empty', t('ERROR_RECEIVER_EMPTY'))->condition(!$form['receiver']); $err->setError('receiver_not_exists', t('ERROR_RECEIVER_NOT_EXISTS'))->condition($form['receiver'] && !User::getId(BY_NICKNAME, $form['receiver'])); $err->setError('subject_empty', t('ERROR_SUBJECT_EMPTY'))->condition(!$form['subject']); $err->setError('message_empty', t('ERROR_MESSAGE_EMPTY'))->condition(!$form['message']); // No errors if ($err->noErrors()) { $form['receiver'] = User::getId(BY_NICKNAME, $form['receiver']); $form['message'] = cut($form['message'], Kio::getConfig('message_max', 'pm')); $form['parsers'] = $form['bbcode'] . $form['autolinks'] . $form['emoticons'] . CENSURE . PRE; $stmt = $sql->prepare(' INSERT INTO ' . DB_PREFIX . 'pm (sent, owner_id, connector_id, subject, message, folder, is_read, parsers) VALUES (:sent, :owner_id, :connector_id, :subject, :message, :folder, :is_read, :parsers)' . ($form['save'] ? ', (:sent, :owner_id, :connector_id, :subject, :message, :folder, :is_read, :parsers)' : '')); $stmt->execute(array('sent' => TIMESTAMP, 'owner_id' => $form['receiver'], 'connector_id' => UID, 'subject' => $form['subject'], 'message' => $form['message'], 'folder' => 0, 'is_read' => 0, 'parsers' => $form['parsers'])); setcookie(COOKIE . '-pm', 'true', TIMESTAMP + Kio::getConfig('flood_interval', 'pm') + 1, '/'); $note->success('Wiadomość została wysłana.'); redirect(HREF . 'pm/inbox'); } else { $note->error($err->toArray()); } } else { $note->info(array(t('WELCOME_MESSAGE'), t('REQUIRED'))); } try { $tpl = new PHPTAL('modules/pm/write.tpl.html'); $tpl->err = $err->toArray(); $tpl->form = $form; $tpl->note = $note; return $tpl->execute(); } catch (Exception $e) { return template_error($e); } }