Skip to content

Commit

Permalink
Merge pull request #8371 from live627/pages
Browse files Browse the repository at this point in the history
  • Loading branch information
Sesquipedalian authored Dec 28, 2024
2 parents 2eeafd1 + b7fe484 commit 5a0150e
Showing 1 changed file with 56 additions and 7 deletions.
63 changes: 56 additions & 7 deletions Sources/PageIndex.php
Original file line number Diff line number Diff line change
Expand Up @@ -202,18 +202,26 @@ class PageIndex implements \Stringable
* "url;start=offset". Default: false.
* @param bool $show_prevnext Whether the Previous and Next links should be
* shown. Default: true.
* @param array $template_overrides Array of template strings to override defaults.
* Supported keys: extra_before, previous_page, current_page, page,
* expand_pages, next_page, extra_after.
*/
public function __construct(string $base_url, int &$start, int $max_value, int $num_per_page, bool $short_format = false, bool $show_prevnext = true)
{
public function __construct(
string $base_url,
int &$start,
int $max_value,
int $num_per_page,
bool $short_format = false,
bool $show_prevnext = true,
array $template_overrides = []
) {
$this->base_url = $base_url;
$this->max_value = $max_value;
$this->num_per_page = $num_per_page;
$this->short_format = $short_format;
$this->show_prevnext = $show_prevnext;
$this->start = $start = $this->fixStart($start);

$this->extra_before = str_replace('{txt_pages}', Lang::$txt['pages'], $this->extra_before);

if (isset(Theme::$current->settings['page_index'])) {
foreach (Theme::$current->settings['page_index'] as $key => $value) {
if (property_exists($this, $key)) {
Expand All @@ -225,6 +233,26 @@ public function __construct(string $base_url, int &$start, int $max_value, int $
if (!isset(Utils::$context['current_page'])) {
Utils::$context['current_page'] = $this->start / $this->num_per_page;
}

$this->setTemplateOverrides($template_overrides);

$this->extra_before = str_replace('{txt_pages}', Lang::$txt['pages'], $this->extra_before);
}

/**
* Sets template overrides.
*
* @param array $template_overrides Array of template strings to override defaults.
* Supported keys: extra_before, previous_page, current_page, page,
* expand_pages, next_page, extra_after.
*/
public function setTemplateOverrides(array $template_overrides = []): void
{
foreach ($template_overrides as $key => $value) {
if (property_exists($this, $key)) {
$this->{$key} = $value;
}
}
}

/**
Expand Down Expand Up @@ -276,11 +304,32 @@ public function __toString(): string
/**
* Static wrapper for constructor.
*
* @param string $base_url The basic URL to be used for each link.
* @param int &$start The start position, by reference. If this is not a
* multiple of the number of items per page, it is sanitized to be so and
* the value will persist upon the function's return.
* @param int $max_value The total number of items you are paginating for.
* @param int $num_per_page The number of items to be displayed on a given
* page. $start will be forced to be a multiple of this value.
* @param bool $short_format Whether to use "url.offset" instead of
* "url;start=offset". Default: false.
* @param bool $show_prevnext Whether the Previous and Next links should be
* shown. Default: true.
* @param array $template_overrides Array of template strings to override defaults.
* Supported keys: extra_before, previous_page, current_page, page,
* expand_pages, next_page, extra_after.
* @return self An instance of this class.
*/
public static function load(string $base_url, int &$start, int $max_value, int $num_per_page, bool $short_format = false, bool $show_prevnext = true): self
{
return new self($base_url, $start, $max_value, $num_per_page, $short_format, $show_prevnext);
public static function load(
string $base_url,
int &$start,
int $max_value,
int $num_per_page,
bool $short_format = false,
bool $show_prevnext = true,
array $template_overrides = []
): self {
return new self($base_url, $start, $max_value, $num_per_page, $short_format, $show_prevnext, $template_overrides);
}

/******************
Expand Down

0 comments on commit 5a0150e

Please sign in to comment.