totalItems = (int)$value;
}
/**
* @param int $value
*/
public function setTotalPages($value)
{
$this->totalPages = (int)$value;
}
public static function getPageNum()
{
$page = 1;
//phpcs:ignore WordPress.Security.NonceVerification.Recommended
if ( ! empty($_GET['paged'])) {
//phpcs:ignore WordPress.Security.NonceVerification.Recommended
$page = absint(stripslashes_deep($_GET['paged']));
}
return $page;
}
public function makeHtml()
{
$which = 'top';
$totalItems = $this->totalItems;
$totalPages = $this->totalPages;
/* translators: total items count*/
$output = '' . sprintf(_n('%s item', '%s items', $totalItems, 'advanced-dynamic-pricing-for-woocommerce'),
number_format_i18n($totalItems)) . '';
$current = self::getPageNum();
$removableQueryArgs = wp_removable_query_args();
//phpcs:ignore WordPress.Security.ValidatedSanitizedInput
$currentUrl = set_url_scheme('http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']);
$currentUrl = remove_query_arg($removableQueryArgs, $currentUrl);
$pageLinks = array();
$totalPagesBefore = '';
$totalPagesAfter = '';
$disableFirst = $disableLast = $disablePrev = $disableNext = false;
if ($current == 1) {
$disableFirst = true;
$disablePrev = true;
}
if ($current == 2) {
$disableFirst = true;
}
if ($current == $totalPages) {
$disableLast = true;
$disableNext = true;
}
if ($current == $totalPages - 1) {
$disableLast = true;
}
if ($disableFirst) {
$pageLinks[] = '«';
} else {
$pageLinks[] = sprintf(
"%s%s",
esc_url(remove_query_arg('paged', $currentUrl)),
__('First page', 'advanced-dynamic-pricing-for-woocommerce'),
'«'
);
}
if ($disablePrev) {
$pageLinks[] = '‹';
} else {
$pageLinks[] = sprintf(
"%s%s",
esc_url(add_query_arg('paged', max(1, $current - 1), $currentUrl)),
__('Previous page', 'advanced-dynamic-pricing-for-woocommerce'),
'‹'
);
}
if ('bottom' === $which) {
$htmlCurrentPage = $current;
$totalPagesBefore = '' . __('Current Page', 'advanced-dynamic-pricing-for-woocommerce') . '';
} else {
$htmlCurrentPage = sprintf(
"%s",
'',
$current,
strlen($totalPages)
);
}
$htmlTotalPages = sprintf("%s", number_format_i18n($totalPages));
/* translators: Links to previous and next pages*/
$pageLinks[] = $totalPagesBefore . sprintf(_x('%1$s of %2$s', 'paging', 'advanced-dynamic-pricing-for-woocommerce'), $htmlCurrentPage,
$htmlTotalPages) . $totalPagesAfter;
if ($disableNext) {
$pageLinks[] = '›';
} else {
$pageLinks[] = sprintf(
"%s%s",
esc_url(add_query_arg('paged', min($totalPages, $current + 1), $currentUrl)),
__('Next page', 'advanced-dynamic-pricing-for-woocommerce'),
'›'
);
}
if ($disableLast) {
$pageLinks[] = '»';
} else {
$pageLinks[] = sprintf(
"%s%s",
esc_url(add_query_arg('paged', $totalPages, $currentUrl)),
__('Last page', 'advanced-dynamic-pricing-for-woocommerce'),
'»'
);
}
$paginationLinksClass = 'pagination-links';
if ( ! empty($infinite_scroll)) {
$paginationLinksClass .= ' hide-if-js';
}
$output .= "\n';
if ($totalPages) {
$pageClass = $totalPages < 2 ? ' one-page' : '';
} else {
$pageClass = ' no-pages';
}
return "$output
";
}
}