Constants for index config
This commit is contained in:
parent
de39f3e5d7
commit
6b030c00eb
7 changed files with 88 additions and 73 deletions
|
@ -154,7 +154,7 @@ class PageRequestEvent extends Event
|
||||||
public function get_page_size(): int
|
public function get_page_size(): int
|
||||||
{
|
{
|
||||||
global $config;
|
global $config;
|
||||||
return $config->get_int('index_images');
|
return $config->get_int(IndexConfig::IMAGES);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -150,8 +150,8 @@ class Image
|
||||||
$result = Image::get_accelerated_result($tag_conditions, $img_conditions, $start, $limit);
|
$result = Image::get_accelerated_result($tag_conditions, $img_conditions, $start, $limit);
|
||||||
if (!$result) {
|
if (!$result) {
|
||||||
$querylet = Image::build_search_querylet($tag_conditions, $img_conditions);
|
$querylet = Image::build_search_querylet($tag_conditions, $img_conditions);
|
||||||
$querylet->append(new Querylet(" ORDER BY ".(Image::$order_sql ?: "images.".$config->get_string("index_order"))));
|
$querylet->append(new Querylet(" ORDER BY ".(Image::$order_sql ?: "images.".$config->get_string(IndexConfig::ORDER))));
|
||||||
if ($limit!=null) {
|
if($limit!=null) {
|
||||||
$querylet->append(new Querylet(" LIMIT :limit ", ["limit" => $limit]));
|
$querylet->append(new Querylet(" LIMIT :limit ", ["limit" => $limit]));
|
||||||
$querylet->append(new Querylet(" OFFSET :offset ", ["offset"=>$start]));
|
$querylet->append(new Querylet(" OFFSET :offset ", ["offset"=>$start]));
|
||||||
}
|
}
|
||||||
|
@ -334,7 +334,7 @@ class Image
|
||||||
public static function count_pages(array $tags=[]): float
|
public static function count_pages(array $tags=[]): float
|
||||||
{
|
{
|
||||||
global $config;
|
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
|
private static function terms_to_conditions(array $terms): array
|
||||||
|
|
|
@ -52,7 +52,7 @@ class ArrowkeyNavigation extends Extension
|
||||||
global $config, $database;
|
global $config, $database;
|
||||||
|
|
||||||
// get the amount of images per page
|
// 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 there are no tags, use default
|
||||||
if (is_null($event->get_arg(1))) {
|
if (is_null($event->get_arg(1))) {
|
||||||
|
|
11
ext/index/config.php
Normal file
11
ext/index/config.php
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
|
||||||
|
class IndexConfig
|
||||||
|
{
|
||||||
|
public const IMAGES = "index_images";
|
||||||
|
public const SHOW_PAGE_SIZES = "index_show_page_sizes";
|
||||||
|
public const PAGE_SIZES = "index_page_sizes";
|
||||||
|
public const TIPS = "index_tips";
|
||||||
|
public const ORDER = "index_order";
|
||||||
|
}
|
65
ext/index/events.php
Normal file
65
ext/index/events.php
Normal file
|
@ -0,0 +1,65 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* SearchTermParseEvent:
|
||||||
|
* Signal that a search term needs parsing
|
||||||
|
*/
|
||||||
|
class SearchTermParseEvent extends Event
|
||||||
|
{
|
||||||
|
/** @var null|string */
|
||||||
|
public $term = null;
|
||||||
|
/** @var string[] */
|
||||||
|
public $context = [];
|
||||||
|
/** @var Querylet[] */
|
||||||
|
public $querylets = [];
|
||||||
|
|
||||||
|
public function __construct(string $term=null, array $context=[])
|
||||||
|
{
|
||||||
|
$this->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;
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,68 +1,7 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
/*
|
require_once "config.php";
|
||||||
* SearchTermParseEvent:
|
require_once "events.php";
|
||||||
* Signal that a search term needs parsing
|
|
||||||
*/
|
|
||||||
class SearchTermParseEvent extends Event
|
|
||||||
{
|
|
||||||
/** @var null|string */
|
|
||||||
public $term = null;
|
|
||||||
/** @var string[] */
|
|
||||||
public $context = [];
|
|
||||||
/** @var Querylet[] */
|
|
||||||
public $querylets = [];
|
|
||||||
|
|
||||||
public function __construct(string $term=null, array $context=[])
|
|
||||||
{
|
|
||||||
$this->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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class Index extends Extension
|
class Index extends Extension
|
||||||
{
|
{
|
||||||
|
@ -72,9 +11,9 @@ class Index extends Extension
|
||||||
public function onInitExt(InitExtEvent $event)
|
public function onInitExt(InitExtEvent $event)
|
||||||
{
|
{
|
||||||
global $config;
|
global $config;
|
||||||
$config->set_default_int("index_images", 24);
|
$config->set_default_int(IndexConfig::IMAGES, 24);
|
||||||
$config->set_default_bool("index_tips", true);
|
$config->set_default_bool(IndexConfig::TIPS, true);
|
||||||
$config->set_default_string("index_order", "id DESC");
|
$config->set_default_string(IndexConfig::ORDER, "id DESC");
|
||||||
}
|
}
|
||||||
|
|
||||||
public function onPageRequest(PageRequestEvent $event)
|
public function onPageRequest(PageRequestEvent $event)
|
||||||
|
@ -167,7 +106,7 @@ class Index extends Extension
|
||||||
$sb->position = 20;
|
$sb->position = 20;
|
||||||
|
|
||||||
$sb->add_label("Show ");
|
$sb->add_label("Show ");
|
||||||
$sb->add_int_option("index_images");
|
$sb->add_int_option(IndexConfig::IMAGES);
|
||||||
$sb->add_label(" images on the post list");
|
$sb->add_label(" images on the post list");
|
||||||
|
|
||||||
$event->panel->add_block($sb);
|
$event->panel->add_block($sb);
|
||||||
|
|
|
@ -129,7 +129,7 @@ class NumericScore extends Extension
|
||||||
$sql = "SELECT id FROM images
|
$sql = "SELECT id FROM images
|
||||||
WHERE EXTRACT(YEAR FROM posted) = :year
|
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")) {
|
if ($event->page_matches("popular_by_day")) {
|
||||||
$sql .=
|
$sql .=
|
||||||
|
|
Reference in a new issue