HEX
Server: Apache
System: Linux uyu7574470001-7d78c9ff74-xfpwm 4.19.91-21.al7.x86_64 #1 SMP Wed Sep 2 19:47:49 CST 2020 x86_64
User: ()
PHP: 7.4.16
Disabled: chmod,exec,system,passthru,shell_exec,escapeshellarg,escapeshellcmd,proc_close,proc_open,ini_alter,dl,popen,pcntl_exec,socket_accept,socket_bind,socket_clear_error,socket_close,socket_connect,socket_create_listen,socket_create_pair,socket_create,socket_get_option,socket_getpeername,socket_getsockname,socket_last_error,socket_listen,socket_read,socket_recv,socket_recvfrom,socket_select,socket_send,socket_sendto,socket_set_block,socket_set_nonblock,socket_set_option,socket_shutdown,socket_strerror,socket_write,stream_socket_client,stream_socket_server,pfsockopen,disk_total_space,disk_free_space,chown,diskfreespace,getrusage,get_current_user,getmyuid,getmypid,dl,leak,listen,chgrp,link,symlink,dlopen,proc_nice,proc_get_stats,proc_terminate,shell_exec,sh2_exec,posix_getpwuid,posix_getgrgid,posix_kill,ini_restore,mkfifo,dbmopen,dbase_open,filepro,filepro_rowcount,posix_mkfifo,putenv,sleep,fsockopen
Upload Files
File: /usr/home/uyu7574470001/htdocs/wp-content/plugins/newsletter/includes/paginator.php
<?php
require_once NEWSLETTER_INCLUDES_DIR . '/controls.php';

class TNP_Pagination_Controller {

    private $items_per_page;
    private $total_items;
    private $filters;
    private $columns;
    private $controls;
    private $items;
    private $current_page;
    private $last_page;
    private $table;
    private $orderby_column;

    public function __construct($table, $orderby_column, $filters = [], $items_per_page = 20, $columns = []) {
        $this->table = $table;
        $this->orderby_column = $orderby_column;
        $this->items_per_page = $items_per_page;
        $this->columns = $columns;
        $this->filters = $filters;
        $this->total_items = $this->get_total_items();
        $this->controls = new NewsletterControls();
        $this->current_page = $this->compute_current_page();
    }

    public function get_current_page() {
        return $this->current_page;
    }

    private function compute_current_page() {

        $current_page = !empty($this->controls->data['search_page']) ? (int) $this->controls->data['search_page'] : 1;

        if ($this->controls->is_action('last')) {
            $current_page = $this->get_last_page();
        }
        if ($this->controls->is_action('first') || $this->controls->is_action('search')) {
            $current_page = 1;
        }
        if ($this->controls->is_action('next')) {
            $current_page++;
        }
        if ($this->controls->is_action('prev')) {
            $current_page--;
        }

        // Eventually fix the page
        if ($current_page <= 0) {
            $current_page = 1;
        }

        if ($current_page > $this->get_last_page()) {
            $current_page = $this->get_last_page();
        }

        $this->controls->data['search_page'] = $current_page;

        return $current_page;
    }

    public function get_last_page() {

        if (is_null($this->last_page)) {
            $this->last_page = (int) floor($this->total_items / $this->items_per_page) + ( $this->total_items % $this->items_per_page > 0 ? 1 : 0 );
        }

        return $this->last_page;
    }

    public function get_items() {

        if (is_null($this->items)) {
            if ($this->total_items > 0) {
                global $wpdb;
                $query = $wpdb->prepare("SELECT " . $this->get_columns_query() . " FROM " . $this->table . $this->get_where_clause() . " ORDER BY " . $this->orderby_column . " DESC LIMIT %d,%d",
                        ( $this->current_page - 1 ) * $this->items_per_page, $this->items_per_page);

                $this->items = $wpdb->get_results($query, OBJECT);
            } else {
                $this->items = [];
            }
        }

        return $this->items;
    }

    private function get_columns_query() {
        if (empty($this->columns)) {
            return " * ";
        } else {
            return " " . implode(',', $this->columns) . " ";
        }
    }

    public function get_total_items() {

        if (is_null($this->total_items)) {
            $this->total_items = Newsletter::instance()->store->get_count($this->table, $this->get_where_clause());
        }

        return $this->total_items;
    }

    private function get_where_clause() {
        if (empty($this->filters)) {
            return ' ';
        }

        $where = ' where ';
        foreach ($this->filters as $column => $value) {
            $where .= "$column=%s ";
        }

        global $wpdb;
        $where = $wpdb->prepare($where, array_values($this->filters));

        return $where;
    }

    public function display_paginator() {
        ?>

        <div class="tnp-paginator">
            <?php $this->controls->btn('first', '«', ['tertiary' => true]); ?>
            <?php $this->controls->btn('prev', '‹', ['tertiary' => true]); ?>
            <?php $this->controls->text('search_page', 3); ?>
            /<?php echo (int) $this->last_page ?> <?php $this->controls->btn('go', esc_html__('Go', 'newsletter'), ['secondary' => true]); ?>
            <?php $this->controls->btn('next', '›', ['tertiary' => true]); ?>
            <?php $this->controls->btn('last', '»', ['tertiary' => true]); ?>
            <?php echo (int) $this->get_total_items() ?> <?php esc_html_e('item(s) found', 'newsletter') ?>
        </div>

        <?php
    }
}