Михаил

Михаил

Был в сети 01 апреля 2023, 10:47
Заказы не принимаю
Чтобы поменять 302 редирект на 301, не правя исходники и с сохранением возможности обновления pdoTools, нужно:
1. Создать в системных настройках modx настройку pdoPage.class со значением pdotools.pdopagecustom
joxi.ru/Dr8ygaRhoEYjgm
2. Создать в папке core/components/pdotools/model/pdotools файл pdopagecustom.class.php со следующим содержимым:
<?php

require_once MODX_CORE_PATH . 'components/pdotools/model/pdotools/pdopage.class.php';

class pdoPageCustom extends pdoPage
{
    /** @var modX $modx */
    public $modx;
    /** @var pdoTools $pdoTools */
    public $pdoTools;
    /** @var string $req_var */
    protected $req_var = '';


    /**
     * @param modX $modx
     * @param array $config
     */
    public function __construct(modX & $modx, $config = array())
    {
        $this->modx = &$modx;

        $fqn = $modx->getOption('pdoTools.class', null, 'pdotools.pdotools', true);
        $path = $modx->getOption('pdotools_class_path', null, MODX_CORE_PATH . 'components/pdotools/model/', true);
        if ($pdoClass = $modx->loadClass($fqn, $path, false, true)) {
            $this->pdoTools = new $pdoClass($modx, $config);
        } else {
            return;
        }
        $modx->lexicon->load('pdotools:pdopage');
    }
    
    /**
     * Redirect user to the first page of pagination
     *
     * @param $isAjax
     *
     * @return string
     */
    public function redirectToFirst($isAjax = false)
    {
        unset($_GET[$this->pdoTools->config['pageVarKey']]);
        unset($_GET[$this->modx->getOption('request_param_alias', null, 'q')]);
        if (!$isAjax) {
            $this->modx->sendRedirect(
                $this->modx->makeUrl(
                    $this->modx->resource->id,
                    $this->modx->context->key,
                    $_GET,
                    'full'
                ),
                array('responseCode' => 'HTTP/1.1 301 Moved Permanently')
            );

            return '';
        } else {
            $_GET[$this->pdoTools->config['pageVarKey']] = 1;
            $_REQUEST = $_GET;

            return $this->pdoTools->runSnippet('pdoPage', $this->pdoTools->config);
        }
    }

}
В функции redirectToFirst добавлен 301 редирект.