This repository has been archived on 2024-09-05. You can view files and clone it, but cannot push or open issues or pull requests.
shimmie2/ext/user/main.php

649 lines
19 KiB
PHP
Raw Normal View History

<?php
2010-01-05 10:11:53 +00:00
/*
* Name: User Management
* Author: Shish
* Description: Allows people to sign up to the website
*/
class UserBlockBuildingEvent extends Event {
2014-04-28 22:22:57 +00:00
/** @var array */
public $parts = array();
2017-09-19 17:55:43 +00:00
public function add_link(string $name, string $link, int $position=50) {
while(isset($this->parts[$position])) $position++;
2009-08-03 09:46:40 +00:00
$this->parts[$position] = array("name" => $name, "link" => $link);
}
}
class UserPageBuildingEvent extends Event {
2014-04-28 22:22:57 +00:00
/** @var \User */
public $display_user;
/** @var array */
public $stats = array();
public function __construct(User $display_user) {
2009-01-04 18:31:54 +00:00
$this->display_user = $display_user;
}
2017-09-19 17:55:43 +00:00
public function add_stats(string $html, int $position=50) {
2014-04-28 22:22:57 +00:00
while(isset($this->stats[$position])) { $position++; }
$this->stats[$position] = $html;
}
}
class UserCreationEvent extends Event {
2014-04-28 22:22:57 +00:00
/** @var string */
public $username;
/** @var string */
public $password;
/** @var string */
public $email;
2017-09-19 17:55:43 +00:00
public function __construct(string $name, string $pass, string $email) {
$this->username = $name;
$this->password = $pass;
$this->email = $email;
}
}
class UserDeletionEvent extends Event {
2014-04-28 22:22:57 +00:00
/** @var int */
public $id;
2017-09-19 17:55:43 +00:00
public function __construct(int $id) {
$this->id = $id;
}
}
class UserCreationException extends SCoreException {}
class NullUserException extends SCoreException {}
class UserPage extends Extension {
2015-09-27 01:00:02 +00:00
/** @var UserPageTheme $theme */
2016-06-19 22:05:57 +00:00
public $theme;
2015-09-27 01:00:02 +00:00
2012-02-02 08:07:57 +00:00
public function onInitExt(InitExtEvent $event) {
2009-05-30 13:47:57 +00:00
global $config;
$config->set_default_bool("login_signup_enabled", true);
$config->set_default_int("login_memory", 365);
2010-04-21 16:56:01 +00:00
$config->set_default_string("avatar_host", "none");
$config->set_default_int("avatar_gravatar_size", 80);
$config->set_default_string("avatar_gravatar_default", "");
$config->set_default_string("avatar_gravatar_rating", "g");
2010-01-05 19:06:04 +00:00
$config->set_default_bool("login_tac_bbcode", true);
2009-05-30 13:47:57 +00:00
}
2012-02-02 08:07:57 +00:00
public function onPageRequest(PageRequestEvent $event) {
2017-09-17 17:59:48 +00:00
global $config, $database, $page, $user;
2009-01-04 19:18:37 +00:00
2015-09-27 01:00:02 +00:00
$this->show_user_info();
2009-05-30 13:47:57 +00:00
if($event->page_matches("user_admin")) {
if($event->get_arg(0) == "login") {
if(isset($_POST['user']) && isset($_POST['pass'])) {
2015-09-27 01:00:02 +00:00
$this->page_login($_POST['user'], $_POST['pass']);
}
else {
2009-01-04 19:18:37 +00:00
$this->theme->display_login_page($page);
}
}
2009-07-11 12:38:48 +00:00
else if($event->get_arg(0) == "recover") {
2015-09-27 01:00:02 +00:00
$this->page_recover($_POST['username']);
2009-07-11 12:38:48 +00:00
}
else if($event->get_arg(0) == "create") {
2015-09-27 01:00:02 +00:00
$this->page_create();
}
2009-05-30 13:47:57 +00:00
else if($event->get_arg(0) == "list") {
2017-09-17 17:59:48 +00:00
$limit = 50;
2018-07-22 18:23:34 +00:00
$page_num = int_escape($event->get_arg(1));
if($page_num <= 0) $page_num = 1;
$offset = ($page_num-1) * $limit;
$q = "WHERE 1=1";
$a = array();
2017-09-17 17:59:48 +00:00
if(@$_GET['username']) {
2017-09-17 18:10:10 +00:00
$q .= " AND SCORE_STRNORM(name) LIKE SCORE_STRNORM(:name)";
2017-09-17 17:59:48 +00:00
$a["name"] = '%' . $_GET['username'] . '%';
}
2017-09-17 18:11:51 +00:00
if($user->can('delete_user') && @$_GET['email']) {
2018-07-22 18:23:34 +00:00
$q .= " AND SCORE_STRNORM(email) LIKE SCORE_STRNORM(:email)";
2017-09-17 17:59:48 +00:00
$a["email"] = '%' . $_GET['email'] . '%';
}
if(@$_GET['class']) {
$q .= " AND class LIKE :class";
$a["class"] = $_GET['class'];
}
2018-07-22 18:23:34 +00:00
$where = $database->scoreql_to_sql($q);
2017-09-17 17:59:48 +00:00
2018-07-22 18:23:34 +00:00
$count = $database->get_one("SELECT count(*) FROM users $where", $a);
$a["offset"] = $offset;
$a["limit"] = $limit;
$rows = $database->get_all("SELECT * FROM users $where LIMIT :limit OFFSET :offset", $a);
2017-09-17 17:59:48 +00:00
$users = array_map("_new_user", $rows);
2018-07-22 18:23:34 +00:00
$this->theme->display_user_list($page, $users, $user, $page_num, $count/$limit);
2009-05-30 13:47:57 +00:00
}
2012-03-12 18:04:06 +00:00
else if($event->get_arg(0) == "logout") {
2015-09-27 01:00:02 +00:00
$this->page_logout();
}
2012-03-12 18:04:06 +00:00
if(!$user->check_auth_token()) {
return;
}
2015-07-12 21:14:57 +00:00
else if($event->get_arg(0) == "change_name") {
2015-07-12 21:40:28 +00:00
$input = validate_input(array(
'id' => 'user_id,exists',
'name' => 'user_name',
));
$duser = User::by_id($input['id']);
$this->change_name_wrapper($duser, $input['name']);
2015-07-12 21:14:57 +00:00
}
else if($event->get_arg(0) == "change_pass") {
2015-07-12 21:40:28 +00:00
$input = validate_input(array(
'id' => 'user_id,exists',
'pass1' => 'password',
'pass2' => 'password',
));
$duser = User::by_id($input['id']);
$this->change_password_wrapper($duser, $input['pass1'], $input['pass2']);
}
else if($event->get_arg(0) == "change_email") {
2015-07-12 21:40:28 +00:00
$input = validate_input(array(
'id' => 'user_id,exists',
'address' => 'email',
));
$duser = User::by_id($input['id']);
$this->change_email_wrapper($duser, $input['address']);
}
else if($event->get_arg(0) == "change_class") {
2015-07-12 21:40:28 +00:00
$input = validate_input(array(
'id' => 'user_id,exists',
'class' => 'user_class',
));
$duser = User::by_id($input['id']);
$this->change_class_wrapper($duser, $input['class']);
}
else if($event->get_arg(0) == "delete_user") {
$this->delete_user($page, isset($_POST["with_images"]), isset($_POST["with_comments"]));
}
}
2009-05-30 13:47:57 +00:00
2012-02-02 08:07:57 +00:00
if($event->page_matches("user")) {
$display_user = ($event->count_args() == 0) ? $user : User::by_name($event->get_arg(0));
2009-07-20 05:42:09 +00:00
if($event->count_args() == 0 && $user->is_anonymous()) {
$this->theme->display_error(401, "Not Logged In",
2009-07-20 05:42:09 +00:00
"You aren't logged in. First do that, then you can see your stats.");
}
else if(!is_null($display_user) && ($display_user->id != $config->get_int("anon_id"))) {
2012-04-01 19:47:59 +00:00
$e = new UserPageBuildingEvent($display_user);
send_event($e);
$this->display_stats($e);
}
else {
$this->theme->display_error(404, "No Such User",
"If you typed the ID by hand, try again; if you came from a link on this ".
"site, it might be bug report time...");
}
}
2009-05-30 13:47:57 +00:00
}
2009-01-04 19:18:37 +00:00
2012-02-02 08:07:57 +00:00
public function onUserPageBuilding(UserPageBuildingEvent $event) {
2014-04-28 22:22:57 +00:00
global $user, $config;
$h_join_date = autodate($event->display_user->join_date);
if($event->display_user->can("hellbanned")) {
$h_class = $event->display_user->class->parent->name;
}
else {
$h_class = $event->display_user->class->name;
}
$event->add_stats("Joined: $h_join_date", 10);
$event->add_stats("Class: $h_class", 90);
2009-10-08 11:32:01 +00:00
$av = $event->display_user->get_avatar_html();
2012-03-31 11:38:39 +00:00
if($av) {
$event->add_stats($av, 0);
}
else if((
$config->get_string("avatar_host") == "gravatar") &&
($user->id == $event->display_user->id)
) {
2012-06-10 17:13:22 +00:00
$event->add_stats(
2016-06-18 14:56:24 +00:00
"No avatar? This gallery uses <a href='https://gravatar.com'>Gravatar</a> for avatar hosting, use the".
2013-09-09 12:46:47 +00:00
"<br>same email address here and there to have your avatar synced<br>",
2012-06-10 17:13:22 +00:00
0
);
2012-03-31 11:38:39 +00:00
}
2012-04-01 19:47:59 +00:00
}
private function display_stats(UserPageBuildingEvent $event) {
global $user, $page, $config;
ksort($event->stats);
$this->theme->display_user_page($event->display_user, $event->stats);
2009-05-30 13:47:57 +00:00
if($user->id == $event->display_user->id) {
$ubbe = new UserBlockBuildingEvent();
send_event($ubbe);
ksort($ubbe->parts);
$this->theme->display_user_links($page, $user, $ubbe->parts);
}
if(
2012-02-07 15:15:18 +00:00
($user->can("view_ip") || ($user->is_logged_in() && $user->id == $event->display_user->id)) && # admin or self-user
($event->display_user->id != $config->get_int('anon_id')) # don't show anon's IP list, it is le huge
) {
$this->theme->display_ip_list(
$page,
$this->count_upload_ips($event->display_user),
$this->count_comment_ips($event->display_user));
}
2009-05-30 13:47:57 +00:00
}
2009-01-04 19:18:37 +00:00
2012-02-02 08:07:57 +00:00
public function onSetupBuilding(SetupBuildingEvent $event) {
2010-04-21 16:56:01 +00:00
global $config;
2010-04-21 16:32:32 +00:00
$hosts = array(
"None" => "none",
"Gravatar" => "gravatar"
);
2009-05-30 13:47:57 +00:00
$sb = new SetupBlock("User Options");
$sb->add_bool_option("login_signup_enabled", "Allow new signups: ");
$sb->add_longtext_option("login_tac", "<br>Terms &amp; Conditions:<br>");
2010-04-21 16:56:01 +00:00
$sb->add_choice_option("avatar_host", $hosts, "<br>Avatars: ");
if($config->get_string("avatar_host") == "gravatar") {
$sb->add_label("<br>&nbsp;<br><b>Gravatar Options</b>");
$sb->add_choice_option("avatar_gravatar_type",
array(
'Default'=>'default',
'Wavatar'=>'wavatar',
'Monster ID'=>'monsterid',
'Identicon'=>'identicon'
),
"<br>Type: ");
$sb->add_choice_option("avatar_gravatar_rating",
array('G'=>'g', 'PG'=>'pg', 'R'=>'r', 'X'=>'x'),
"<br>Rating: ");
}
2014-04-28 22:22:57 +00:00
$sb->add_choice_option("user_loginshowprofile", array(
"return to previous page" => 0, // 0 is default
"send to user profile" => 1),
"<br>When user logs in/out");
2009-05-30 13:47:57 +00:00
$event->panel->add_block($sb);
}
2012-02-02 08:07:57 +00:00
public function onUserBlockBuilding(UserBlockBuildingEvent $event) {
global $user;
2009-05-30 13:47:57 +00:00
$event->add_link("My Profile", make_link("user"));
if($user->can("edit_user_class")) {
$event->add_link("User List", make_link("user_admin/list"), 98);
}
2009-05-30 13:47:57 +00:00
$event->add_link("Log Out", make_link("user_admin/logout"), 99);
}
2012-02-02 08:07:57 +00:00
public function onUserCreation(UserCreationEvent $event) {
2009-05-30 13:47:57 +00:00
$this->check_user_creation($event);
$this->create_user($event);
}
2012-02-02 08:07:57 +00:00
public function onSearchTermParse(SearchTermParseEvent $event) {
2011-12-25 12:31:28 +00:00
global $user;
2009-05-30 13:47:57 +00:00
$matches = array();
2015-10-08 17:03:45 +00:00
if(preg_match("/^(?:poster|user)[=|:](.*)$/i", $event->term, $matches)) {
$duser = User::by_name($matches[1]);
2012-03-05 09:55:11 +00:00
if(!is_null($duser)) {
$user_id = $duser->id;
}
2009-05-30 13:47:57 +00:00
else {
$user_id = -1;
}
2009-05-30 13:47:57 +00:00
$event->add_querylet(new Querylet("images.owner_id = $user_id"));
}
2015-10-08 17:03:45 +00:00
else if(preg_match("/^(?:poster|user)_id[=|:]([0-9]+)$/i", $event->term, $matches)) {
$user_id = int_escape($matches[1]);
2009-05-30 13:47:57 +00:00
$event->add_querylet(new Querylet("images.owner_id = $user_id"));
}
2015-10-08 17:03:45 +00:00
else if($user->can("view_ip") && preg_match("/^(?:poster|user)_ip[=|:]([0-9\.]+)$/i", $event->term, $matches)) {
$user_ip = $matches[1]; // FIXME: ip_escape?
2011-12-25 12:31:28 +00:00
$event->add_querylet(new Querylet("images.owner_ip = '$user_ip'"));
}
}
2015-09-27 01:00:02 +00:00
private function show_user_info() {
global $user, $page;
// user info is shown on all pages
if ($user->is_anonymous()) {
$this->theme->display_login_block($page);
} else {
$ubbe = new UserBlockBuildingEvent();
send_event($ubbe);
ksort($ubbe->parts);
$this->theme->display_user_block($page, $user, $ubbe->parts);
}
}
// }}}
// Things done *with* the user {{{
2015-09-27 01:00:02 +00:00
private function page_login($name, $pass) {
global $config, $user, $page;
if(empty($name) || empty($pass)) {
$this->theme->display_error(400, "Error", "Username or password left blank");
return;
}
2014-05-23 23:28:57 +00:00
$duser = User::by_name_and_pass($name, $pass);
if(!is_null($duser)) {
$user = $duser;
2012-12-10 21:28:41 +00:00
$this->set_login_cookie($duser->name, $pass);
2012-03-31 14:43:25 +00:00
log_info("user", "{$user->class->name} logged in");
$page->set_mode("redirect");
2014-04-25 19:38:15 +00:00
// Try returning to previous page
if ($config->get_int("user_loginshowprofile",0) == 0 &&
isset($_SERVER['HTTP_REFERER']) &&
strstr($_SERVER['HTTP_REFERER'], "post/"))
{
$page->set_redirect($_SERVER['HTTP_REFERER']);
} else {
$page->set_redirect(make_link("user"));
}
}
else {
2014-05-23 23:28:57 +00:00
log_warning("user", "Failed to log in as ".html_escape($name));
$this->theme->display_error(401, "Error", "No user with those details was found");
}
}
2015-09-27 01:00:02 +00:00
private function page_logout() {
global $page, $config;
$page->add_cookie("session", "", time() + 60 * 60 * 24 * $config->get_int('login_memory'), "/");
if (CACHE_HTTP || SPEED_HAX) {
# to keep as few versions of content as possible,
# make cookies all-or-nothing
$page->add_cookie("user", "", time() + 60 * 60 * 24 * $config->get_int('login_memory'), "/");
}
log_info("user", "Logged out");
$page->set_mode("redirect");
// Try forwarding to same page on logout unless user comes from registration page
if ($config->get_int("user_loginshowprofile", 0) == 0 &&
isset($_SERVER['HTTP_REFERER']) &&
strstr($_SERVER['HTTP_REFERER'], "post/")
) {
$page->set_redirect($_SERVER['HTTP_REFERER']);
} else {
$page->set_redirect(make_link());
}
}
2017-09-19 17:55:43 +00:00
private function page_recover(string $username) {
2015-09-27 01:00:02 +00:00
$user = User::by_name($username);
if (is_null($user)) {
$this->theme->display_error(404, "Error", "There's no user with that name");
} else if (is_null($user->email)) {
$this->theme->display_error(400, "Error", "That user has no registered email address");
} else {
// send email
}
}
private function page_create() {
global $config, $page;
if (!$config->get_bool("login_signup_enabled")) {
$this->theme->display_signups_disabled($page);
} else if (!isset($_POST['name'])) {
$this->theme->display_signup_page($page);
} else if ($_POST['pass1'] != $_POST['pass2']) {
$this->theme->display_error(400, "Password Mismatch", "Passwords don't match");
} else {
try {
if (!captcha_check()) {
throw new UserCreationException("Error in captcha");
}
$uce = new UserCreationEvent($_POST['name'], $_POST['pass1'], $_POST['email']);
send_event($uce);
$this->set_login_cookie($uce->username, $uce->password);
$page->set_mode("redirect");
$page->set_redirect(make_link("user"));
} catch (UserCreationException $ex) {
$this->theme->display_error(400, "User Creation Error", $ex->getMessage());
}
}
}
private function check_user_creation(UserCreationEvent $event) {
$name = $event->username;
2015-09-12 10:43:28 +00:00
//$pass = $event->password;
//$email = $event->email;
if(strlen($name) < 1) {
throw new UserCreationException("Username must be at least 1 character");
}
else if(!preg_match('/^[a-zA-Z0-9-_]+$/', $name)) {
throw new UserCreationException(
"Username contains invalid characters. Allowed characters are ".
"letters, numbers, dash, and underscore");
}
2015-07-12 21:40:28 +00:00
else if(User::by_name($name)) {
throw new UserCreationException("That username is already taken");
}
}
2015-09-27 01:00:02 +00:00
private function create_user(UserCreationEvent $event) {
2012-12-30 16:04:05 +00:00
global $database, $user;
$email = (!empty($event->email)) ? $event->email : null;
2009-01-22 09:39:44 +00:00
// if there are currently no admins, the new user should be one
2012-02-21 18:37:36 +00:00
$need_admin = ($database->get_one("SELECT COUNT(*) FROM users WHERE class='admin'") == 0);
2012-02-22 13:58:55 +00:00
$class = $need_admin ? 'admin' : 'user';
2009-01-22 09:39:44 +00:00
$database->Execute(
2012-02-21 18:37:36 +00:00
"INSERT INTO users (name, pass, joindate, email, class) VALUES (:username, :hash, now(), :email, :class)",
2014-05-23 23:28:57 +00:00
array("username"=>$event->username, "hash"=>'', "email"=>$email, "class"=>$class));
$uid = $database->get_last_insert_id('users_id_seq');
$user = User::by_name($event->username);
2014-05-23 23:28:57 +00:00
$user->set_password($event->password);
2009-05-08 10:52:29 +00:00
log_info("user", "Created User #$uid ({$event->username})");
}
2009-01-04 19:18:37 +00:00
2017-09-19 17:55:43 +00:00
private function set_login_cookie(string $name, string $pass) {
2015-08-03 13:32:46 +00:00
global $config, $page;
$addr = get_session_ip($config);
2014-05-23 23:28:57 +00:00
$hash = User::by_name($name)->passhash;
2015-08-03 13:32:46 +00:00
$page->add_cookie("user", $name,
time()+60*60*24*365, '/');
2015-08-03 13:32:46 +00:00
$page->add_cookie("session", md5($hash.$addr),
time()+60*60*24*$config->get_int('login_memory'), '/');
}
2009-01-04 19:18:37 +00:00
//}}}
// Things done *to* the user {{{
2017-09-19 17:55:43 +00:00
private function user_can_edit_user(User $a, User $b): bool {
if($a->is_anonymous()) {
$this->theme->display_error(401, "Error", "You aren't logged in");
return false;
}
if(
($a->name == $b->name) ||
($b->can("protected") && $a->class->name == "admin") ||
(!$b->can("protected") && $a->can("edit_user_info"))
) {
return true;
}
else {
$this->theme->display_error(401, "Error", "You need to be an admin to change other people's details");
return false;
2009-08-11 16:07:03 +00:00
}
}
private function redirect_to_user(User $duser) {
global $page, $user;
2009-08-11 16:07:03 +00:00
if($user->id == $duser->id) {
$page->set_mode("redirect");
$page->set_redirect(make_link("user"));
}
else {
$page->set_mode("redirect");
$page->set_redirect(make_link("user/{$duser->name}"));
2009-08-11 16:07:03 +00:00
}
}
2009-08-11 16:07:03 +00:00
2015-07-12 21:14:57 +00:00
private function change_name_wrapper(User $duser, $name) {
global $user;
if($user->can('edit_user_name') && $this->user_can_edit_user($user, $duser)) {
$duser->set_name($name);
flash_message("Username changed");
// TODO: set login cookie if user changed themselves
$this->redirect_to_user($duser);
}
else {
$this->theme->display_error(400, "Error", "Permission denied");
}
}
2017-09-19 17:55:43 +00:00
private function change_password_wrapper(User $duser, string $pass1, string $pass2) {
global $user;
2009-08-11 16:07:03 +00:00
if($this->user_can_edit_user($user, $duser)) {
if($pass1 != $pass2) {
$this->theme->display_error(400, "Error", "Passwords don't match");
2009-08-11 16:07:03 +00:00
}
else {
// FIXME: send_event()
$duser->set_password($pass1);
2009-08-11 16:07:03 +00:00
if($duser->id == $user->id) {
$this->set_login_cookie($duser->name, $pass1);
}
2012-06-10 17:13:22 +00:00
flash_message("Password changed");
$this->redirect_to_user($duser);
}
}
}
2017-09-19 17:55:43 +00:00
private function change_email_wrapper(User $duser, string $address) {
global $user;
2009-01-04 19:18:37 +00:00
if($this->user_can_edit_user($user, $duser)) {
$duser->set_email($address);
2012-06-10 17:13:22 +00:00
flash_message("Email changed");
$this->redirect_to_user($duser);
}
}
2009-01-04 19:18:37 +00:00
2017-09-19 17:55:43 +00:00
private function change_class_wrapper(User $duser, string $class) {
global $user;
if($user->class->name == "admin") {
2012-02-14 20:38:19 +00:00
$duser->set_class($class);
2012-06-10 17:13:22 +00:00
flash_message("Class changed");
$this->redirect_to_user($duser);
}
}
// }}}
// ips {{{
2017-09-19 17:55:43 +00:00
private function count_upload_ips(User $duser): array {
global $database;
2011-01-01 16:28:04 +00:00
$rows = $database->get_pairs("
SELECT
owner_ip,
COUNT(images.id) AS count,
MAX(posted) AS most_recent
FROM images
2011-01-01 16:28:04 +00:00
WHERE owner_id=:id
GROUP BY owner_ip
2011-01-01 16:28:04 +00:00
ORDER BY most_recent DESC", array("id"=>$duser->id));
return $rows;
}
2014-04-28 22:22:57 +00:00
2017-09-19 17:55:43 +00:00
private function count_comment_ips(User $duser): array {
global $database;
2011-01-01 16:28:04 +00:00
$rows = $database->get_pairs("
SELECT
owner_ip,
COUNT(comments.id) AS count,
MAX(posted) AS most_recent
FROM comments
2011-01-01 16:28:04 +00:00
WHERE owner_id=:id
GROUP BY owner_ip
2011-01-01 16:28:04 +00:00
ORDER BY most_recent DESC", array("id"=>$duser->id));
return $rows;
}
2017-09-19 17:55:43 +00:00
private function delete_user(Page $page, bool $with_images=false, bool $with_comments=false) {
global $user, $config, $database;
$page->set_title("Error");
$page->set_heading("Error");
$page->add_block(new NavBlock());
2012-02-07 15:15:18 +00:00
if (!$user->can("delete_user")) {
$page->add_block(new Block("Not Admin", "Only admins can delete accounts"));
}
else if(!isset($_POST['id']) || !is_numeric($_POST['id'])) {
$page->add_block(new Block("No ID Specified",
"You need to specify the account number to edit"));
}
else {
2013-04-28 06:48:10 +00:00
log_warning("user", "Deleting user #{$_POST['id']}");
if($with_images) {
2013-04-28 06:48:10 +00:00
log_warning("user", "Deleting user #{$_POST['id']}'s uploads");
$rows = $database->get_all("SELECT * FROM images WHERE owner_id = :owner_id", array("owner_id" => $_POST['id']));
foreach ($rows as $key => $value) {
$image = Image::by_id($value['id']);
if($image) {
send_event(new ImageDeletionEvent($image));
}
}
}
else {
$database->Execute(
"UPDATE images SET owner_id = :new_owner_id WHERE owner_id = :old_owner_id",
array("new_owner_id" => $config->get_int('anon_id'), "old_owner_id" => $_POST['id'])
);
}
if($with_comments) {
2013-04-28 06:48:10 +00:00
log_warning("user", "Deleting user #{$_POST['id']}'s comments");
$database->execute("DELETE FROM comments WHERE owner_id = :owner_id", array("owner_id" => $_POST['id']));
}
else {
$database->Execute(
"UPDATE comments SET owner_id = :new_owner_id WHERE owner_id = :old_owner_id",
array("new_owner_id" => $config->get_int('anon_id'), "old_owner_id" => $_POST['id'])
);
}
send_event(new UserDeletionEvent($_POST['id']));
$database->execute(
"DELETE FROM users WHERE id = :id",
array("id" => $_POST['id'])
);
$page->set_mode("redirect");
$page->set_redirect(make_link("post/list"));
}
}
// }}}
}