diff --git a/core/event.php b/core/event.php index 5ae1ad55..248bf6ae 100644 --- a/core/event.php +++ b/core/event.php @@ -154,7 +154,7 @@ class PageRequestEvent extends Event public function get_page_size(): int { global $config; - return $config->get_int('index_images'); + return $config->get_int(IndexConfig::IMAGES); } } diff --git a/core/imageboard/image.php b/core/imageboard/image.php index 4277443c..c268266e 100644 --- a/core/imageboard/image.php +++ b/core/imageboard/image.php @@ -150,8 +150,8 @@ class Image $result = Image::get_accelerated_result($tag_conditions, $img_conditions, $start, $limit); if (!$result) { $querylet = Image::build_search_querylet($tag_conditions, $img_conditions); - $querylet->append(new Querylet(" ORDER BY ".(Image::$order_sql ?: "images.".$config->get_string("index_order")))); - if ($limit!=null) { + $querylet->append(new Querylet(" ORDER BY ".(Image::$order_sql ?: "images.".$config->get_string(IndexConfig::ORDER)))); + if($limit!=null) { $querylet->append(new Querylet(" LIMIT :limit ", ["limit" => $limit])); $querylet->append(new Querylet(" OFFSET :offset ", ["offset"=>$start])); } @@ -334,7 +334,7 @@ class Image public static function count_pages(array $tags=[]): float { global $config; - return ceil(Image::count_images($tags) / $config->get_int('index_images')); + return ceil(Image::count_images($tags) / $config->get_int(IndexConfig::IMAGES)); } private static function terms_to_conditions(array $terms): array diff --git a/ext/arrowkey_navigation/main.php b/ext/arrowkey_navigation/main.php index 640d2b12..6464f592 100644 --- a/ext/arrowkey_navigation/main.php +++ b/ext/arrowkey_navigation/main.php @@ -52,7 +52,7 @@ class ArrowkeyNavigation extends Extension global $config, $database; // get the amount of images per page - $images_per_page = $config->get_int('index_images'); + $images_per_page = $config->get_int(IndexConfig::IMAGES); // if there are no tags, use default if (is_null($event->get_arg(1))) { diff --git a/ext/index/config.php b/ext/index/config.php new file mode 100644 index 00000000..91329926 --- /dev/null +++ b/ext/index/config.php @@ -0,0 +1,11 @@ +term = $term; + $this->context = $context; + } + + public function is_querylet_set(): bool + { + return (count($this->querylets) > 0); + } + + public function get_querylets(): array + { + return $this->querylets; + } + + public function add_querylet(Querylet $q) + { + $this->querylets[] = $q; + } +} + +class SearchTermParseException extends SCoreException +{ +} + +class PostListBuildingEvent extends Event +{ + /** @var array */ + public $search_terms = []; + + /** @var array */ + public $parts = []; + + /** + * #param string[] $search + */ + public function __construct(array $search) + { + $this->search_terms = $search; + } + + public function add_control(string $html, int $position=50) + { + while (isset($this->parts[$position])) { + $position++; + } + $this->parts[$position] = $html; + } +} diff --git a/ext/index/main.php b/ext/index/main.php index 7a116df2..1e084f21 100644 --- a/ext/index/main.php +++ b/ext/index/main.php @@ -1,68 +1,7 @@ term = $term; - $this->context = $context; - } - - public function is_querylet_set(): bool - { - return (count($this->querylets) > 0); - } - - public function get_querylets(): array - { - return $this->querylets; - } - - public function add_querylet(Querylet $q) - { - $this->querylets[] = $q; - } -} - -class SearchTermParseException extends SCoreException -{ -} - -class PostListBuildingEvent extends Event -{ - /** @var array */ - public $search_terms = []; - - /** @var array */ - public $parts = []; - - /** - * #param string[] $search - */ - public function __construct(array $search) - { - $this->search_terms = $search; - } - - public function add_control(string $html, int $position=50) - { - while (isset($this->parts[$position])) { - $position++; - } - $this->parts[$position] = $html; - } -} +require_once "config.php"; +require_once "events.php"; class Index extends Extension { @@ -72,9 +11,9 @@ class Index extends Extension public function onInitExt(InitExtEvent $event) { global $config; - $config->set_default_int("index_images", 24); - $config->set_default_bool("index_tips", true); - $config->set_default_string("index_order", "id DESC"); + $config->set_default_int(IndexConfig::IMAGES, 24); + $config->set_default_bool(IndexConfig::TIPS, true); + $config->set_default_string(IndexConfig::ORDER, "id DESC"); } public function onPageRequest(PageRequestEvent $event) @@ -167,7 +106,7 @@ class Index extends Extension $sb->position = 20; $sb->add_label("Show "); - $sb->add_int_option("index_images"); + $sb->add_int_option(IndexConfig::IMAGES); $sb->add_label(" images on the post list"); $event->panel->add_block($sb); diff --git a/ext/numeric_score/main.php b/ext/numeric_score/main.php index bff6701b..5e6d0f22 100644 --- a/ext/numeric_score/main.php +++ b/ext/numeric_score/main.php @@ -129,7 +129,7 @@ class NumericScore extends Extension $sql = "SELECT id FROM images WHERE EXTRACT(YEAR FROM posted) = :year "; - $args = ["limit" => $config->get_int("index_images"), "year" => $year]; + $args = ["limit" => $config->get_int(IndexConfig::IMAGES), "year" => $year]; if ($event->page_matches("popular_by_day")) { $sql .=