@@ -202,18 +202,26 @@ class PageIndex implements \Stringable
202202 * "url;start=offset". Default: false.
203203 * @param bool $show_prevnext Whether the Previous and Next links should be
204204 * shown. Default: true.
205+ * @param array $template_overrides Array of template strings to override defaults.
206+ * Supported keys: extra_before, previous_page, current_page, page,
207+ * expand_pages, next_page, extra_after.
205208 */
206- public function __construct (string $ base_url , int &$ start , int $ max_value , int $ num_per_page , bool $ short_format = false , bool $ show_prevnext = true )
207- {
209+ public function __construct (
210+ string $ base_url ,
211+ int &$ start ,
212+ int $ max_value ,
213+ int $ num_per_page ,
214+ bool $ short_format = false ,
215+ bool $ show_prevnext = true ,
216+ array $ template_overrides = []
217+ ) {
208218 $ this ->base_url = $ base_url ;
209219 $ this ->max_value = $ max_value ;
210220 $ this ->num_per_page = $ num_per_page ;
211221 $ this ->short_format = $ short_format ;
212222 $ this ->show_prevnext = $ show_prevnext ;
213223 $ this ->start = $ start = $ this ->fixStart ($ start );
214224
215- $ this ->extra_before = str_replace ('{txt_pages} ' , Lang::$ txt ['pages ' ], $ this ->extra_before );
216-
217225 if (isset (Theme::$ current ->settings ['page_index ' ])) {
218226 foreach (Theme::$ current ->settings ['page_index ' ] as $ key => $ value ) {
219227 if (property_exists ($ this , $ key )) {
@@ -225,6 +233,26 @@ public function __construct(string $base_url, int &$start, int $max_value, int $
225233 if (!isset (Utils::$ context ['current_page ' ])) {
226234 Utils::$ context ['current_page ' ] = $ this ->start / $ this ->num_per_page ;
227235 }
236+
237+ $ this ->setTemplateOverrides ($ template_overrides );
238+
239+ $ this ->extra_before = str_replace ('{txt_pages} ' , Lang::$ txt ['pages ' ], $ this ->extra_before );
240+ }
241+
242+ /**
243+ * Sets template overrides.
244+ *
245+ * @param array $template_overrides Array of template strings to override defaults.
246+ * Supported keys: extra_before, previous_page, current_page, page,
247+ * expand_pages, next_page, extra_after.
248+ */
249+ public function setTemplateOverrides (array $ template_overrides = []): void
250+ {
251+ foreach ($ template_overrides as $ key => $ value ) {
252+ if (property_exists ($ this , $ key )) {
253+ $ this ->{$ key } = $ value ;
254+ }
255+ }
228256 }
229257
230258 /**
@@ -276,11 +304,32 @@ public function __toString(): string
276304 /**
277305 * Static wrapper for constructor.
278306 *
307+ * @param string $base_url The basic URL to be used for each link.
308+ * @param int &$start The start position, by reference. If this is not a
309+ * multiple of the number of items per page, it is sanitized to be so and
310+ * the value will persist upon the function's return.
311+ * @param int $max_value The total number of items you are paginating for.
312+ * @param int $num_per_page The number of items to be displayed on a given
313+ * page. $start will be forced to be a multiple of this value.
314+ * @param bool $short_format Whether to use "url.offset" instead of
315+ * "url;start=offset". Default: false.
316+ * @param bool $show_prevnext Whether the Previous and Next links should be
317+ * shown. Default: true.
318+ * @param array $template_overrides Array of template strings to override defaults.
319+ * Supported keys: extra_before, previous_page, current_page, page,
320+ * expand_pages, next_page, extra_after.
279321 * @return self An instance of this class.
280322 */
281- 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
282- {
283- return new self ($ base_url , $ start , $ max_value , $ num_per_page , $ short_format , $ show_prevnext );
323+ public static function load (
324+ string $ base_url ,
325+ int &$ start ,
326+ int $ max_value ,
327+ int $ num_per_page ,
328+ bool $ short_format = false ,
329+ bool $ show_prevnext = true ,
330+ array $ template_overrides = []
331+ ): self {
332+ return new self ($ base_url , $ start , $ max_value , $ num_per_page , $ short_format , $ show_prevnext , $ template_overrides );
284333 }
285334
286335 /******************
0 commit comments