This commit is contained in:
Shish 2019-11-04 00:42:06 +00:00
parent d17e207984
commit f79eafc91e
11 changed files with 32 additions and 46 deletions

View file

@ -116,17 +116,16 @@ class PageRequestEvent extends Event
}
}
public function try_page_num(int $n): int {
if($this->count_args() > $n) {
public function try_page_num(int $n): int
{
if ($this->count_args() > $n) {
$i = $this->get_arg($n);
if (!is_numeric($i) || $i <= 0) {
return int_escape($i);
}
else {
} else {
return 1;
}
}
else {
} else {
return 1;
}
}

View file

@ -49,7 +49,7 @@ class AliasEditor extends Extension
}
}
} elseif ($event->get_arg(0) == "list") {
if($event->count_args() == 2) {
if ($event->count_args() == 2) {
$page_number = $event->get_arg(1);
if (!is_numeric($page_number)) {
$page_number = 0;
@ -58,8 +58,7 @@ class AliasEditor extends Extension
} else {
$page_number--;
}
}
else {
} else {
$page_number = 0;
}

View file

@ -54,17 +54,16 @@ class ArrowkeyNavigation extends Extension
// get the amount of images per page
$images_per_page = $config->get_int(IndexConfig::IMAGES);
if($event->count_args() > 1) {
// if there are tags, use pages with tags
if ($event->count_args() > 1) {
// if there are tags, use pages with tags
$prefix = url_escape($event->get_arg(0)) . "/";
$page_number = $event->try_page_num(1);
$total_pages = ceil($database->get_one(
"SELECT count FROM tags WHERE tag=:tag",
["tag"=>$event->get_arg(0)]
) / $images_per_page);
}
else {
// if there are no tags, use default
} else {
// if there are no tags, use default
$prefix = "";
$page_number = $event->try_page_num(0);
$total_pages = ceil($database->get_one(

View file

@ -250,7 +250,7 @@ class CommentList extends Extension
private function onPageRequest_beta_search(PageRequestEvent $event)
{
$search = $event->get_arg(1);
$page_num = $event->try_page_num(2);
$page_num = $event->try_page_num(2);
$duser = User::by_name($search);
$i_comment_count = Comment::count_comments_by_user($duser);
$com_per_page = 50;

View file

@ -86,8 +86,8 @@ class DanbooruApi extends Extension
foreach ($namelist as $name) {
$sqlresult = $database->get_all(
$database->scoreql_to_sql(
"SELECT id,tag,count FROM tags WHERE SCORE_STRNORM(tag) = SCORE_STRNORM(?)"
),
"SELECT id,tag,count FROM tags WHERE SCORE_STRNORM(tag) = SCORE_STRNORM(?)"
),
[$name]
);
foreach ($sqlresult as $row) {

View file

@ -60,14 +60,13 @@ class ExtManager extends Extension
}
if ($event->page_matches("ext_doc")) {
if($event->count_args() == 1) {
if ($event->count_args() == 1) {
$ext = $event->get_arg(0);
if (file_exists("ext/$ext/info.php")) {
$info = ExtensionInfo::get_by_key($ext);
$this->theme->display_doc($page, $info);
}
}
else {
} else {
$this->theme->display_table($page, $this->get_extensions(false), false);
}
}

View file

@ -248,7 +248,7 @@ class Forum extends Extension
$threadsPerPage = $config->get_int('forumThreadsPerPage', 15);
$totalPages = ceil($database->get_one("SELECT COUNT(*) FROM forum_threads") / $threadsPerPage);
if($event->count_args() >= 2) {
if ($event->count_args() >= 2) {
$pageNumber = $event->get_arg(1);
if (!is_numeric($pageNumber)) {
$pageNumber = 0;
@ -259,8 +259,7 @@ class Forum extends Extension
} else {
$pageNumber--;
}
}
else {
} else {
$pageNumber = 0;
}
@ -287,7 +286,7 @@ class Forum extends Extension
$totalPages = ceil($database->get_one("SELECT COUNT(*) FROM forum_posts WHERE thread_id = ?", [$threadID]) / $postsPerPage);
$threadTitle = $this->get_thread_title($threadID);
if($event->count_args() >= 3) {
if ($event->count_args() >= 3) {
$pageNumber = $event->get_arg(2);
if (!is_numeric($pageNumber)) {
$pageNumber = 0;
@ -298,8 +297,7 @@ class Forum extends Extension
} else {
$pageNumber--;
}
}
else {
} else {
$pageNumber = 0;
}

View file

@ -39,13 +39,11 @@ class ShimmieApi extends Extension
$page->set_type("text/plain");
if ($event->page_matches("api/shimmie/get_tags")) {
if($event->count_args() > 0) {
if ($event->count_args() > 0) {
$tag = $event->get_arg(0);
}
elseif (isset($_GET['tag'])) {
} elseif (isset($_GET['tag'])) {
$tag = $_GET['tag'];
}
else {
} else {
$tag = null;
}
$res = $this->api_get_tags($tag);

View file

@ -128,13 +128,11 @@ class TranscodeImage extends Extension
global $page, $user;
if ($event->page_matches("transcode") && $user->can(Permissions::EDIT_FILES)) {
if($event->count_args() >= 1) {
if ($event->count_args() >= 1) {
$image_id = int_escape($event->get_arg(0));
}
elseif(isset($_POST['image_id'])) {
} elseif (isset($_POST['image_id'])) {
$image_id = int_escape($_POST['image_id']);
}
else {
} else {
throw new ImageTranscodeException("Can not resize Image: No valid Image ID given.");
}
$image_obj = Image::by_id($image_id);

View file

@ -19,13 +19,11 @@ class Trash extends Extension
if ($event->page_matches("trash_restore") && $user->can(Permissions::VIEW_TRASH)) {
// Try to get the image ID
if($event->count_args() >= 1) {
if ($event->count_args() >= 1) {
$image_id = int_escape($event->get_arg(0));
}
elseif (isset($_POST['image_id'])) {
} elseif (isset($_POST['image_id'])) {
$image_id = $_POST['image_id'];
}
else {
} else {
throw new SCoreException("Can not restore image: No valid Image ID given.");
}

View file

@ -187,13 +187,11 @@ class Upload extends Extension
throw new UploadException("Can not replace Image: disk nearly full");
}
// Try to get the image ID
if($event->count_args() >= 1) {
if ($event->count_args() >= 1) {
$image_id = int_escape($event->get_arg(0));
}
elseif(isset($_POST['image_id'])) {
} elseif (isset($_POST['image_id'])) {
$image_id = $_POST['image_id'];
}
else {
} else {
throw new UploadException("Can not replace Image: No valid Image ID given.");
}