/
bitrix-dev
/
Starter-kit
Обзор
Документация
Войти
/
bitrix-dev
/
Starter-kit
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
main
local/ajax/review.php
77 строк
2 KB
Alexey Karizhenskiy
Первая сборка (из ранее используемого)
19 янв 2026, 21:00
19 янв 2026, 21:00
d843e36
Код
Авторство
О чём код?
<?php require($_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/main/include/prolog_before.php"); use Bitrix\Main\Application; use Bitrix\Main\Web\PostDecoder; use Bitrix\Main\Web\Json; $response = []; $request = Application::getInstance()->getContext()->getRequest(); if ($request->isPost()) { $post = $request->getPostList()->toArray(); $files = $request->getFileList()->toArray(); if (class_exists('MWI\SmartCaptcha')) { $smartCaptcha = \MWI\SmartCaptcha::verify($post['smart-token'] ?? ''); if (!$smartCaptcha) { $response = [ 'success' => false, 'message' => 'Ошибка при проверке бота' ]; echo Json::encode($response); return; } } // Обработка загруженных изображений $images = []; if (!empty($files['images'])) { $fileInfo = $files['images']; if (is_array($fileInfo['name'])) { // Множественная загрузка файлов foreach ($fileInfo['name'] as $index => $name) { if ($fileInfo['error'][$index] === UPLOAD_ERR_OK) { $images[] = [ 'name' => $name, 'type' => $fileInfo['type'][$index], 'tmp_name' => $fileInfo['tmp_name'][$index], 'error' => $fileInfo['error'][$index], 'size' => $fileInfo['size'][$index] ]; } } } else { // Одиночная загрузка файла if ($fileInfo['error'] === UPLOAD_ERR_OK) { $images[] = $fileInfo; } } } $params = [ 'productId' => htmlspecialcharsbx($post['productId']), 'name' => htmlspecialcharsbx($post['name']), 'rating' => (int)$post['rating'], 'comment' => htmlspecialcharsbx($post['comment']), 'images' => $images ]; if ($params['name'] && $params['rating'] /*&& $params['comment']*/) { $reviewManager = new MWI\ReviewManager(); $response = $reviewManager->addReview($params); } else { $response = [ 'success' => false, 'message' => 'Заполните все обязательные поля' ]; } } else { $response = [ 'success' => false, 'message' => 'Неверный метод запроса' ]; } echo Json::encode($response);