MOON
Server: Apache
System: Linux nserver.cafsindia.com 4.18.0-553.104.1.lve.el8.x86_64 #1 SMP Tue Feb 10 20:07:30 UTC 2026 x86_64
User: cafsindia (1002)
PHP: 8.2.30
Disabled: NONE
Upload Files
File: /home/cafsindia/www/wp-content/plugins/imageseo/src/Actions/Admin/Ajax/Report.php
<?php

namespace ImageSeoWP\Actions\Admin\Ajax;

if (!defined('ABSPATH')) {
    exit;
}

class Report
{
    public function __construct()
    {
        $this->reportImageServices = imageseo_get_service('ReportImage');
        $this->optionServices = imageseo_get_service('Option');
    }

    public function hooks()
    {
        if (!imageseo_allowed()) {
            return;
        }

        add_action('wp_ajax_imageseo_generate_report', [$this, 'generateReport']);
    }

    public function generateReport()
    {
        if (!current_user_can('manage_options')) {
            wp_send_json_error([
                'code' => 'not_authorized',
            ]);
            exit;
        }

        if (!isset($_POST['attachmentId'])) {
            wp_send_json_error([
                'code' => 'missing_parameters',
            ]);

            return;
        }

        $attachmentId = (int) $_POST['attachmentId'];
        $language = isset($_POST['language']) ? sanitize_text_field($_POST['language']) : $this->optionServices->getOption('default_language_ia');

        $report = $this->reportImageServices->getReportByAttachmentId($attachmentId);

        if (apply_filters('imageseo_get_report_cache', false)) {
            $report['ID'] = $attachmentId;
            wp_send_json_success([
                'need_update_counter' => false,
                'report'              => $report,
            ]);

            return;
        }

        try {
            $response = $this->reportImageServices->generateReportByAttachmentId($attachmentId, ['force' => true], $language);
        } catch (\Exception $e) {
            wp_send_json_error([
                'code'    => 'error_generate_report',
                'message' => $e->getMessage(),
            ]);

            return;
        }

        $report = $response['result'];
        $report['ID'] = $attachmentId;
        wp_send_json_success([
            'need_update_counter' => true,
            'report'              => $report,
        ]);
    }
}