| Server IP : 89.108.64.180 / Your IP : 216.73.216.208 Web Server : Apache/2.4.41 (Ubuntu) System : Linux 89-108-64-180.cloudvps.regruhosting.ru 5.4.0-216-generic #236-Ubuntu SMP Fri Apr 11 19:53:21 UTC 2025 x86_64 User : www-root ( 1010) PHP Version : 8.0.30 Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority, MySQL : OFF | cURL : ON | WGET : OFF | Perl : OFF | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : /var/www/www-root/data/www/жемчужина.online/wp-content/plugins/mphb-reviews/includes/ |
Upload File : |
<?php
namespace MPHBR;
use MPHBR\Views\ReviewView;
use MPHB\Utils\ValidateUtils;
class Ajax
{
public function __construct()
{
add_action('wp_ajax_mphbr_load_more', [$this, 'mphbr_load_more']);
add_action('wp_ajax_nopriv_mphbr_load_more', [$this, 'mphbr_load_more']);
}
public function mphbr_load_more()
{
$input = $_GET;
// Verify nonce
$nonce = isset($input['nonce']) ? $input['nonce'] : '';
if (!wp_verify_nonce($nonce, __FUNCTION__)) {
// It's a technical message, no need to translate it - nobody will see it
wp_send_json_error(['message' => 'Request did not pass security verification.']);
}
// Number or "all" for shortcode (in some cases)
$accommodation = mphb_clean($input['accommodation_id']);
// Get and validate the inputs
$roomTypeId = $accommodation !== 'all' ? (int)ValidateUtils::validateInt($accommodation) : 0;
$offset = (int)ValidateUtils::validateInt($input['offset']);
$count = (int)ValidateUtils::validateInt($input['per_page']);
$items = '';
$itemsCount = 0;
$hasMore = false;
if (($roomTypeId > 0 || $accommodation === 'all') && $offset > 0 && $count > 0) {
// Query reviews
$queryArgs = MPHBR()->getReviewRepository()->getCommentsQueryArgs([
'post_id' => $roomTypeId,
'count' => $count,
'offset' => $offset
]);
if ($accommodation === 'all') {
// Get rid of 0 or current post ID
unset($queryArgs['post_id']);
}
$query = new \WP_Comment_Query();
$comments = $query->query($queryArgs);
$itemsCount = count($comments);
$hasMore = ($offset + $itemsCount) < $query->found_comments;
// Render reviews
ob_start();
ReviewView::displayComments($comments);
$items = ob_get_clean();
}
wp_send_json_success([
'items' => $items,
'count' => $itemsCount,
'hasMore' => $hasMore
]);
}
}