403Webshell
Server IP : 192.158.238.246  /  Your IP : 3.17.153.20
Web Server : LiteSpeed
System : Linux uniform.iwebfusion.net 4.18.0-553.27.1.lve.1.el8.x86_64 #1 SMP Wed Nov 20 15:58:00 UTC 2024 x86_64
User : jenniferflocom ( 1321)
PHP Version : 8.1.32
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : ON  |  Sudo : OFF  |  Pkexec : OFF
Directory :  /proc/7779/task/7779/cwd/plugins/give/src/API/Endpoints/Logs/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /proc/7779/task/7779/cwd/plugins/give/src/API/Endpoints/Logs/GetLogs.php
<?php

namespace Give\API\Endpoints\Logs;

use Give\Log\LogRepository;
use Give\Log\ValueObjects\LogType;
use WP_REST_Request;
use WP_REST_Response;

/**
 * Class GetLogs
 * @package Give\API\Endpoints\Logs
 *
 * @since 2.10.0
 */
class GetLogs extends Endpoint
{

    /** @var string */
    protected $endpoint = 'logs/get-logs';

    /**
     * @var LogRepository
     */
    private $logRepository;

    /**
     * GetLogs constructor.
     *
     * @param LogRepository $repository
     */
    public function __construct(LogRepository $repository)
    {
        $this->logRepository = $repository;
    }

    /**
     * @inheritDoc
     */
    public function registerRoute()
    {
        register_rest_route(
            'give-api/v2',
            $this->endpoint,
            [
                [
                    'methods' => 'GET',
                    'callback' => [$this, 'handleRequest'],
                    'permission_callback' => [$this, 'permissionsCheck'],
                    'args' => [
                        'page' => [
                            'validate_callback' => function ($param) {
                                return filter_var($param, FILTER_VALIDATE_INT);
                            },
                            'default' => '1',
                        ],
                        'type' => [
                            'validate_callback' => function ($param) {
                                if (empty($param) || ('all' === $param)) {
                                    return true;
                                }

                                return LogType::isValid($param);
                            },
                            'default' => 'all',
                        ],
                        'category' => [
                            'validate_callback' => function ($param) {
                                return is_string($param);
                            },
                            'default' => '',
                        ],
                        'source' => [
                            'validate_callback' => function ($param) {
                                return is_string($param);
                            },
                            'default' => '',
                        ],
                        'sort' => [
                            'validate_callback' => function ($param) {
                                if (empty($param)) {
                                    return true;
                                }

                                return in_array($param, $this->logRepository->getSortableColumns(), true);
                            },
                            'default' => 'id',
                        ],
                        'direction' => [
                            'validate_callback' => function ($param) {
                                if (empty($param)) {
                                    return true;
                                }

                                return in_array(strtoupper($param), ['ASC', 'DESC'], true);
                            },
                            'default' => 'DESC',
                        ],
                    ],
                ],
                'schema' => [$this, 'getSchema'],
            ]
        );
    }

    /**
     * @return array
     */
    public function getSchema()
    {
        return [
            '$schema' => 'http://json-schema.org/draft-04/schema#',
            'title' => 'logs',
            'type' => 'object',
            'properties' => [
                'page' => [
                    'type' => 'integer',
                    'description' => esc_html__('Current page', 'give'),
                ],
                'type' => [
                    'type' => 'string',
                    'description' => esc_html__('Log type', 'give'),
                ],
                'category' => [
                    'type' => 'string',
                    'description' => esc_html__('Log category', 'give'),
                ],
                'source' => [
                    'type' => 'string',
                    'description' => esc_html__('Log source', 'give'),
                ],
                'direction' => [
                    'type' => 'string',
                    'description' => esc_html__('Sort direction', 'give'),
                ],
                'sort' => [
                    'type' => 'string',
                    'description' => esc_html__('Sort by column', 'give'),
                ],
            ],
        ];
    }

    /**
     * @since 3.12.1 Add 'givewp_log_source_view' filter
     *
     * @param WP_REST_Request $request
     *
     * @return WP_REST_Response
     */
    public function handleRequest(WP_REST_Request $request)
    {
        $data = [];
        $logs = $this->logRepository->getLogsForRequest($request);
        $total = $this->logRepository->getLogCountForRequest($request);

        foreach ($logs as $log) {
            $data[] = [
                'id' => $log->getId(),
                'log_type' => $log->getType(),
                'category' => $log->getCategory(),
                'source' => apply_filters('givewp_log_source_view', $log->getSource(), $log->getContext(),
                    $log->getId()),
                'message' => $log->getMessage(),
                'context' => $log->getContext(),
                'date' => $log->getDate(),
            ];
        }

        return new WP_REST_Response(
            [
                'status' => true,
                'data' => $data,
                'pages' => ceil($total / $this->logRepository->getLogsPerPageLimit()),
                'categories' => $this->logRepository->getCategories(),
                'sources' => $this->logRepository->getSources(),
                'statuses' => LogType::getTypesTranslated(),
            ]
        );
    }

}

Youez - 2016 - github.com/yon3zu
LinuXploit