| Server IP : 172.67.75.225 / Your IP : 216.73.216.185 Web Server : nginx/1.27.1 System : Linux us-1 5.15.0-131-generic #141-Ubuntu SMP Fri Jan 10 21:18:28 UTC 2025 x86_64 User : vinodai ( 3134) PHP Version : 7.4.33 Disable Function : exec,passthru,shell_exec,system,proc_open,popen,parse_ini_file,show_source MySQL : OFF | cURL : ON | WGET : OFF | Perl : OFF | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : /storage/v1396/themastermynd/public_html/wp-content/plugins/mailpoet/lib/Listing/ |
Upload File : |
<?php // phpcs:ignore SlevomatCodingStandard.TypeHints.DeclareStrictTypes.DeclareStrictTypesMissing
namespace MailPoet\Listing;
if (!defined('ABSPATH')) exit;
class Handler {
public function getListingDefinition(array $data): ListingDefinition {
$data = $this->processData($data);
return new ListingDefinition(
$data['group'],
$data['filter'] ?? [],
$data['search'],
$data['params'] ?? [],
$data['sort_by'],
$data['sort_order'],
$data['offset'],
$data['limit'],
$data['selection'] ?? []
);
}
private function sanitizeSortBy(string $sortBy): string {
$sortBy = trim($sortBy);
if ($sortBy === '') {
return 'id';
}
// Fallback to `id` when there is at least one non-identifier character.
if (strspn($sortBy, 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_') !== strlen($sortBy)) {
return 'id';
}
return $sortBy;
}
private function processData(array $data) {
// check if sort order was specified or default to "asc"
$sortOrder = (!empty($data['sort_order'])) ? $data['sort_order'] : 'asc';
// constrain sort order value to either be "asc" or "desc"
$sortOrder = strtolower(trim((string)$sortOrder));
if ($sortOrder === '') {
$sortOrder = 'asc';
}
$sortOrder = in_array($sortOrder, ['asc', 'desc'], true) ? $sortOrder : 'desc';
// sanitize sort by
$sortBy = (!empty($data['sort_by']))
? $this->sanitizeSortBy((string)$data['sort_by'])
: '';
if (empty($sortBy)) {
$sortBy = 'id';
}
$data = [
// extra parameters
'params' => (isset($data['params']) ? $data['params'] : []),
// pagination
'offset' => (isset($data['offset']) ? (int)$data['offset'] : 0),
'limit' => (isset($data['limit'])
? (int)$data['limit']
: PageLimit::DEFAULT_LIMIT_PER_PAGE
),
// searching
'search' => (isset($data['search']) ? $data['search'] : null),
// sorting
'sort_by' => $sortBy,
'sort_order' => $sortOrder,
// grouping
'group' => (isset($data['group']) ? $data['group'] : null),
// filters
'filter' => (isset($data['filter']) ? $data['filter'] : null),
// selection
'selection' => (isset($data['selection']) ? $data['selection'] : null),
];
return $data;
}
}