/** @noinspection PhpUnusedPrivateMethodInspection * @param Request $request * * @return bool */ private function delete(Request $request) { $confirmed = Validator::sanitizeBoolean($request->post('delete')); if (!$confirmed) { $this->errors[] = 'Please confirm the deletion'; return false; } $this->model->delete($this->user->getId()); $this->redirect(Request::createUrl(array('p' => 'logout'))); exit; }
/** @noinspection PhpUnusedPrivateMethodInspection * @param Request $request * * @return bool * @throws PermissionRequiredException * @throws exceptions\LoginRequiredException */ private function delete(Request $request) { if (!$this->auth->checkPermission(Auth::DELETE_KEYWORD)) { throw new PermissionRequiredException(Auth::DELETE_KEYWORD); } $id = Validator::sanitizeNumber($request->get('id')); if (!$id) { throw new UnexpectedValueException(); } $confirmed = Validator::sanitizeBoolean($request->post('delete')); if (!$confirmed) { $this->errors[] = 'Please confirm the deletion'; return false; } $this->model->delete($id); $this->redirect(Request::createUrl(array('p' => 'browse', 'by' => 'keyword'))); exit; }
/** @noinspection PhpUnusedPrivateMethodInspection * @param Request $request * * @return bool * @throws PermissionRequiredException * @throws exceptions\LoginRequiredException */ private function delete(Request $request) { if (!$this->auth->checkPermission(Auth::DELETE_PUBLICATION)) { throw new PermissionRequiredException(Auth::DELETE_PUBLICATION); } $id = Validator::sanitizeNumber($request->get('id')); if (!$id) { throw new UnexpectedValueException(); } $confirmed = Validator::sanitizeBoolean($request->post('delete')); if (!$confirmed) { $this->errors[] = 'Please confirm the deletion'; return false; } try { $this->model->delete($id); $this->redirect(Request::createUrl(array('p' => 'browse', 'by' => 'recent'))); exit; } catch (DBForeignKeyException $e) { // TODO: remove this once files are deleted automatically $this->errors[] = 'Please remove the files before deleting'; return false; } }
/** @noinspection PhpUnusedPrivateMethodInspection * @param Request $request * * @return bool */ private function import(Request $request) { $format = Validator::sanitizeText($request->post('format')); $bulkimport = Validator::sanitizeBoolean($request->post('bulkimport')); $input = $request->post('input'); if ($input && $format) { try { if ($bulkimport && filter_var($input, FILTER_VALIDATE_URL)) { $input = $this->getInputFromUrl($input); if ($input == false) { $this->errors[] = 'Could not get content from URL.'; return false; } } $entries = FormatHandler::import($input, $format); if ($bulkimport) { $_SESSION['bulkimport_msg'] = $this->bulkimport($entries); return true; } $_SESSION['input_raw'] = $input; $_SESSION['input_format'] = $format; $this->setInputAndRestInSession($entries); return true; } catch (Exception $e) { $this->errors[] = $e->getMessage(); } } else { $this->errors[] = 'No input to import given'; } return false; }