first commit
This commit is contained in:
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
class WPML_Admin_URL {
|
||||
|
||||
public static function multilingual_setup( $section = null ) {
|
||||
if ( defined( 'WPML_TM_VERSION' ) ) {
|
||||
$url = admin_url( 'admin.php?page=' . WPML_TM_FOLDER . WPML_Translation_Management::PAGE_SLUG_SETTINGS . '&sm=mcsetup' );
|
||||
} else {
|
||||
$url = admin_url( 'admin.php?page=' . ICL_PLUGIN_FOLDER . '/menu/translation-options.php' );
|
||||
}
|
||||
|
||||
if ( $section ) {
|
||||
$url .= '#ml-content-setup-sec-' . $section;
|
||||
}
|
||||
|
||||
return $url;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
class WPML_Admin_Pagination_Factory {
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
private $items_per_page;
|
||||
|
||||
public function __construct( $items_per_page ) {
|
||||
$this->items_per_page = $items_per_page;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return WPML_Admin_Pagination_Render
|
||||
*/
|
||||
public function create( $total_items, $page_param_name = 'paged' ) {
|
||||
$pagination = new WPML_Admin_Pagination();
|
||||
$pagination->set_total_items( $total_items );
|
||||
$pagination->set_items_per_page( $this->items_per_page );
|
||||
$pagination->set_page_param_name( $page_param_name );
|
||||
|
||||
$page = 1;
|
||||
if ( isset( $_GET[ $page_param_name ] ) ) {
|
||||
$page = filter_var( $_GET[ $page_param_name ], FILTER_SANITIZE_NUMBER_INT );
|
||||
}
|
||||
$pagination->set_current_page( $page );
|
||||
|
||||
$template = new WPML_Twig_Template_Loader(
|
||||
array(
|
||||
WPML_PLUGIN_PATH . '/templates/pagination',
|
||||
)
|
||||
);
|
||||
|
||||
return new WPML_Admin_Pagination_Render( $template->get_template(), $pagination );
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
|
||||
class WPML_Admin_Pagination_Render {
|
||||
|
||||
const TEMPLATE = 'pagination.twig';
|
||||
|
||||
/**
|
||||
* @var IWPML_Template_Service
|
||||
*/
|
||||
private $template;
|
||||
|
||||
/**
|
||||
* @var WPML_Admin_Pagination
|
||||
*/
|
||||
private $pagination;
|
||||
|
||||
public function __construct( IWPML_Template_Service $template, WPML_Admin_Pagination $pagination ) {
|
||||
$this->template = $template;
|
||||
$this->pagination = $pagination;
|
||||
}
|
||||
|
||||
public function get_model() {
|
||||
return [
|
||||
'strings' => self::get_strings( $this->pagination->get_total_items() ),
|
||||
'pagination' => $this->pagination,
|
||||
'total_items' => $this->pagination->get_total_items(),
|
||||
];
|
||||
}
|
||||
|
||||
public static function get_strings( $totalItems ) {
|
||||
return [
|
||||
'listNavigation' => __( 'Navigation', 'sitepress' ),
|
||||
'firstPage' => __( 'First page', 'sitepress' ),
|
||||
'previousPage' => __( 'Previous page', 'sitepress' ),
|
||||
'nextPage' => __( 'Next page', 'sitepress' ),
|
||||
'lastPage' => __( 'Last page', 'sitepress' ),
|
||||
'currentPage' => __( 'Current page', 'sitepress' ),
|
||||
'of' => __( 'of', 'sitepress' ),
|
||||
'totalItemsText' => sprintf(
|
||||
_n( '%s item', '%s items', $totalItems, 'sitepress' ),
|
||||
$totalItems
|
||||
),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $items
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function paginate( $items ) {
|
||||
$total = count( $items );
|
||||
$limit = $this->pagination->get_items_per_page(); // per page
|
||||
$total_pages = ceil( $total / $limit );
|
||||
$page = max( $this->pagination->get_current_page(), 1 );
|
||||
$page = min( $page, $total_pages );
|
||||
$offset = ( $page - 1 ) * $limit;
|
||||
|
||||
if ( $offset < 0 ) {
|
||||
$offset = 0;
|
||||
}
|
||||
|
||||
return array_slice( $items, $offset, $limit );
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,152 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Class WPML_Admin_Pagination
|
||||
*
|
||||
* @author OnTheGoSystems
|
||||
*/
|
||||
class WPML_Admin_Pagination {
|
||||
|
||||
/** @var int $items_per_page */
|
||||
private $items_per_page;
|
||||
|
||||
/** @var int $total_items */
|
||||
private $total_items;
|
||||
|
||||
/** @var int $current_page */
|
||||
private $current_page;
|
||||
|
||||
/** @var string $current_url */
|
||||
private $current_url;
|
||||
|
||||
/** @var string */
|
||||
private $page_param_name = 'paged';
|
||||
|
||||
/**
|
||||
* @param string $page_param_name
|
||||
*/
|
||||
public function set_page_param_name( $page_param_name ) {
|
||||
$this->page_param_name = $page_param_name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function get_page_param_name() {
|
||||
return $this->page_param_name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $items_per_page
|
||||
*/
|
||||
public function set_items_per_page( $items_per_page ) {
|
||||
$this->items_per_page = (int) $items_per_page;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function get_items_per_page() {
|
||||
return $this->items_per_page;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $total_items
|
||||
*/
|
||||
public function set_total_items( $total_items ) {
|
||||
$this->total_items = (int) $total_items;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function get_total_items() {
|
||||
return $this->total_items;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function get_total_pages() {
|
||||
return ceil( $this->get_total_items() / $this->get_items_per_page() );
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $page
|
||||
*/
|
||||
public function set_current_page( $page ) {
|
||||
$this->current_page = (int) $page;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function get_current_page() {
|
||||
return $this->current_page;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return null|string
|
||||
*/
|
||||
public function get_first_page_url() {
|
||||
$url = null;
|
||||
|
||||
if ( 2 < $this->get_current_page() ) {
|
||||
$url = remove_query_arg( $this->page_param_name, $this->get_current_url() );
|
||||
}
|
||||
|
||||
return $url;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return null|string
|
||||
*/
|
||||
public function get_previous_page_url() {
|
||||
$url = null;
|
||||
|
||||
if ( 1 < $this->get_current_page() ) {
|
||||
$url = add_query_arg( $this->page_param_name, $this->get_current_page() - 1, $this->get_current_url() );
|
||||
}
|
||||
|
||||
return $url;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return null|string
|
||||
*/
|
||||
public function get_next_page_url() {
|
||||
$url = null;
|
||||
|
||||
if ( $this->get_current_page() < $this->get_total_pages() ) {
|
||||
$url = add_query_arg( $this->page_param_name, $this->get_current_page() + 1, $this->get_current_url() );
|
||||
}
|
||||
|
||||
return $url;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return null|string
|
||||
*/
|
||||
public function get_last_page_url() {
|
||||
$url = null;
|
||||
|
||||
if ( $this->get_current_page() < $this->get_total_pages() - 1 ) {
|
||||
$url = add_query_arg( $this->page_param_name, $this->get_total_pages(), $this->get_current_url() );
|
||||
}
|
||||
|
||||
return $url;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
private function get_current_url() {
|
||||
if ( ! $this->current_url ) {
|
||||
$removable_query_args = wp_removable_query_args();
|
||||
$this->current_url = set_url_scheme( 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] );
|
||||
$this->current_url = remove_query_arg( $removable_query_args, $this->current_url );
|
||||
}
|
||||
|
||||
return $this->current_url;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,135 @@
|
||||
<?php
|
||||
|
||||
class WPML_Admin_Table_Sort {
|
||||
|
||||
/** @var string $primary_column */
|
||||
private $primary_column;
|
||||
|
||||
/** @var string $url_args */
|
||||
private $url_args;
|
||||
|
||||
/** @var string $current_url */
|
||||
private $current_url;
|
||||
|
||||
/** @var string */
|
||||
private $orderby_param;
|
||||
|
||||
/** @var string */
|
||||
private $order_param;
|
||||
|
||||
/**
|
||||
* @param string $orderby_param
|
||||
* @param string $order_param
|
||||
*/
|
||||
public function __construct( $orderby_param = 'orderby', $order_param = 'order' ) {
|
||||
$this->orderby_param = $orderby_param;
|
||||
$this->order_param = $order_param;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param string $primary_column
|
||||
*/
|
||||
public function set_primary_column( $primary_column ) {
|
||||
$this->primary_column = $primary_column;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $column
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_column_url( $column ) {
|
||||
$query_args = array(
|
||||
$this->orderby_param => $column,
|
||||
$this->order_param => 'desc',
|
||||
);
|
||||
|
||||
if ( $this->get_current_orderby() === $column && $this->get_current_order() === 'desc' ) {
|
||||
$query_args[ $this->order_param ] = 'asc';
|
||||
}
|
||||
|
||||
return add_query_arg( $query_args, $this->get_current_url() );
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $column
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_column_classes( $column ) {
|
||||
$classes = 'manage-column column-' . $column;
|
||||
|
||||
if ( $this->is_primary( $column ) ) {
|
||||
$classes .= ' column-primary';
|
||||
}
|
||||
|
||||
if ( $this->get_current_orderby() === $column ) {
|
||||
$classes .= ' sorted ' . $this->get_current_order();
|
||||
} else {
|
||||
$classes .= ' sortable asc';
|
||||
}
|
||||
|
||||
return $classes;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $column
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
private function is_primary( $column ) {
|
||||
return $this->primary_column === $column;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string|null
|
||||
*/
|
||||
private function get_current_orderby() {
|
||||
$url_args = $this->get_url_args();
|
||||
return isset( $url_args[ $this->orderby_param ] ) ? $url_args[ $this->orderby_param ] : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string|null
|
||||
*/
|
||||
private function get_current_order() {
|
||||
$url_args = $this->get_url_args();
|
||||
return isset( $url_args[ $this->order_param ] ) ? $url_args[ $this->order_param ] : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function get_current_sorters() {
|
||||
return array(
|
||||
$this->orderby_param => $this->get_current_orderby(),
|
||||
$this->order_param => $this->get_current_order(),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
private function get_url_args() {
|
||||
if ( ! $this->url_args ) {
|
||||
$this->url_args = array();
|
||||
$url_query = wpml_parse_url( $this->get_current_url(), PHP_URL_QUERY );
|
||||
parse_str( $url_query, $this->url_args );
|
||||
}
|
||||
|
||||
return $this->url_args;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
private function get_current_url() {
|
||||
if ( ! $this->current_url ) {
|
||||
$this->current_url = set_url_scheme( 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] );
|
||||
$this->current_url = remove_query_arg( 'paged', $this->current_url );
|
||||
}
|
||||
|
||||
return $this->current_url;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user