/** * Update a user's role * * @param string $newgroup * * @return bool */ function updateRole(string $newgroup) : bool { global $Database; $response = $Database->where('id', $this->id)->update('users', array('role' => $newgroup)); if ($response) { Logs::action('rolechange', array('target' => $this->id, 'oldrole' => $this->role, 'newrole' => $newgroup)); } return (bool) $response; }
Response::dbError('Episode tag creation failed'); } } } } } if ($editing) { $logentry = array('target' => $Episode->formatTitle(AS_ARRAY, 'id')); $changes = 0; if (!empty($Episode->airs)) { $Episode->airs = date('c', strtotime($Episode->airs)); } foreach (array('season', 'episode', 'twoparter', 'title', 'airs') as $k) { if (isset($insert[$k]) && $insert[$k] != $Episode->{$k}) { $logentry["old{$k}"] = $Episode->{$k}; $logentry["new{$k}"] = $insert[$k]; $changes++; } } if ($changes > 0) { Logs::action('episode_modify', $logentry); } } else { Logs::action('episodes', array('action' => 'add', 'season' => $insert['season'], 'episode' => $insert['episode'], 'twoparter' => isset($insert['twoparter']) ? $insert['twoparter'] : 0, 'title' => $insert['title'], 'airs' => $insert['airs'])); } if ($editing) { Response::done(); } Response::done(array('url' => (new Episode($insert))->formatURL())); break; }
if ($Post->reserved_by !== $currentUser->id) { Response::fail(); } break; } } $image_url = (new Input('image_url', 'string', array(Input::CUSTOM_ERROR_MESSAGES => array(Input::ERROR_MISSING => 'Image URL is missing'))))->out(); $Image = Posts::checkImage($image_url, $Post); // Check image availability if (!DeviantArt::isImageAvailable($Image->preview)) { Response::fail("<p class='align-center'>The specified image doesn't seem to exist. Please verify that you can reach the URL below and try again.<br><a href='{$Image->preview}' target='_blank'>{$Image->preview}</a></p>"); } if (!$Database->where('id', $Post->id)->update("{$thing}s", array('preview' => $Image->preview, 'fullsize' => $Image->fullsize))) { Response::dbError(); } Logs::action('img_update', array('id' => $Post->id, 'thing' => $thing, 'oldpreview' => $Post->preview, 'oldfullsize' => $Post->fullsize, 'newpreview' => $Image->preview, 'newfullsize' => $Image->fullsize)); Response::done(array('preview' => $Image->preview)); } else { if (preg_match(new RegExp('^fix-(request|reservation)-stash/(\\d+)$'), $data, $_match)) { if (!Permission::sufficient('staff')) { Response::fail(); } $thing = $_match[1]; $Post = $Database->where('id', $_match[2])->getOne("{$thing}s"); if (empty($Post)) { Response::fail("The specified {$thing} does not exist"); } // Link is already full size, we're done if (preg_match($FULLSIZE_MATCH_REGEX, $Post->fullsize)) { Response::done(array('fullsize' => $Post->fullsize)); }
if ($data['label'] !== $Group['label']) { $logdata['oldlabel'] = $Group['label']; $logdata['newlabel'] = $data['label']; } } $origColors = ColorGroups::stringifyColors($origColors); $recvColors = ColorGroups::stringifyColors($recvColors); $colorsChanged = $origColors !== $recvColors; if ($colorsChanged) { $logdata['oldcolors'] = $origColors; $logdata['newcolors'] = $recvColors; } if (!empty($logdata)) { $logdata['groupid'] = $Group['groupid']; $logdata['ponyid'] = $AppearanceID; Logs::action('cg_modify', $logdata); } Response::done($response); } else { CoreUtils::notFound(); } } } } // Tag list if (preg_match(new RegExp('^tags'), $data)) { $Pagination = new Pagination("cg/tags", 20, $CGDb->count('tags')); CoreUtils::fixPath("/cg/tags/{$Pagination->page}"); $heading = "Tags"; $title = "Page {$Pagination->page} - {$heading} - {$Color} Guide"; $Tags = Tags::getFor(null, $Pagination->getLimit(), true);
/** * User Information Fetching * ------------------------- * Fetch user info from dA upon request to nonexistant user * * @param string $username * @param string $dbcols * * @return User|null|false */ function fetch($username, $dbcols = null) { global $Database, $USERNAME_REGEX; if (!$USERNAME_REGEX->match($username)) { return null; } $oldName = $Database->where('old', $username)->getOne('log__da_namechange', 'id'); if (!empty($oldName)) { return self::get($oldName['id'], 'id', $dbcols); } try { $userdata = DeviantArt::request('user/whois', null, array('usernames[0]' => $username)); } catch (CURLRequestException $e) { return null; } if (empty($userdata['results'][0])) { return false; } $userdata = $userdata['results'][0]; $ID = strtolower($userdata['userid']); /** @var $DBUser User */ $DBUser = $Database->where('id', $ID)->getOne('users', 'name'); $userExists = !empty($DBUser); $insert = array('name' => $userdata['username'], 'avatar_url' => URL::makeHttps($userdata['usericon'])); if (!$userExists) { $insert['id'] = $ID; } if (!($userExists ? $Database->where('id', $ID)->update('users', $insert) : $Database->insert('users', $insert))) { throw new \Exception('Saving user data failed' . (Permission::sufficient('developer') ? ': ' . $Database->getLastError() : '')); } if (!$userExists) { Logs::action('userfetch', array('userid' => $insert['id'])); } $names = array($username); if ($userExists && $DBUser->name !== $username) { $names[] = $DBUser->name; } foreach ($names as $name) { if (strcasecmp($name, $insert['name']) !== 0) { if (UserPrefs::get('discord_token', $ID) === 'true') { UserPrefs::set('discord_token', '', $ID); } Logs::action('da_namechange', array('old' => $name, 'new' => $insert['name'], 'id' => $ID), Logs::FORCE_INITIATOR_WEBSERVER); } } return self::get($insert['name'], 'name', $dbcols); }
if (empty($targetUser)) { Response::fail('User not found'); } if ($targetUser->id === $currentUser->id) { Response::fail("You cannot {$action} yourself"); } if (Permission::sufficient('staff', $targetUser->role)) { Response::fail("You cannot {$action} people within the assistant or any higher group"); } if ($action == 'banish' && $targetUser->role === 'ban' || $action == 'un-banish' && $targetUser->role !== 'ban') { Response::fail("This user has already been {$action}ed"); } $reason = (new Input('reason', 'string', array(Input::IN_RANGE => [5, 255], Input::CUSTOM_ERROR_MESSAGES => array(Input::ERROR_MISSING => 'Please specify a reason', Input::ERROR_RANGE => 'Reason length must be between @min and @max characters'))))->out(); $changes = array('role' => $action == 'banish' ? 'ban' : 'user'); $Database->where('id', $targetUser->id)->update('users', $changes); Logs::action($action, array('target' => $targetUser->id, 'reason' => $reason)); $changes['role'] = Permission::ROLES_ASSOC[$changes['role']]; $changes['badge'] = Permission::labelInitials($changes['role']); if ($action == 'banish') { Response::done($changes); } Response::success("We welcome {$targetUser->name} back with open hooves!", $changes); } else { CoreUtils::notFound(); } } } if (strtolower($data) === 'immortalsexgod') { $data = 'DJDavid98'; } if (empty($data)) {
/** * Approves a specific post and optionally notifies it's author * * @param string $type request/reservation * @param int $id post id * @param string $notifyUserID id of user to notify * * @return array */ static function approve($type, $id, $notifyUserID = null) { global $Database; if (!$Database->where('id', $id)->update("{$type}s", array('lock' => true))) { Response::dbError(); } $postdata = array('type' => $type, 'id' => $id); Logs::action('post_lock', $postdata); if (!empty($notifyUserID)) { Notifications::send($notifyUserID, 'post-approved', $postdata); } return $postdata; }
switch ($Notif['type']) { case "post-passon": $Post = $Database->where('id', $data['id'])->getOne("{$data['type']}s"); if (empty($Post)) { Posts::clearTransferAttempts($Post, $data['type'], 'del'); Response::fail("The {$data['type']} doesn't exist or has been deleted"); } if ($read_action === 'true') { if ($Post['reserved_by'] !== $currentUser->id) { Posts::clearTransferAttempts($Post, $data['type'], 'perm', null, $currentUser->id); Response::fail('You are not allowed to transfer this reservation'); } Notifications::safeMarkRead($Notif['id'], $read_action); Notifications::send($data['user'], "post-passallow", array('id' => $data['id'], 'type' => $data['type'], 'by' => $currentUser->id)); $Database->where('id', $data['id'])->update("{$data['type']}s", array('reserved_by' => $data['user'], 'reserved_at' => date('c'))); Posts::clearTransferAttempts($Post, $data['type'], 'deny'); Logs::action('res_transfer', array('id' => $data['id'], 'type' => $data['type'], 'to' => $data['user'])); } else { Notifications::safeMarkRead($Notif['id'], $read_action); Notifications::send($data['user'], "post-passdeny", array('id' => $data['id'], 'type' => $data['type'], 'by' => $currentUser->id)); } Response::done(); break; default: Notifications::safeMarkRead($Notif['id'], $read_action); } } else { Notifications::safeMarkRead($Notif['id']); } Response::done(); }