CoreFiles by mySites.guru
POWCaptcha.php85 lines, 2,048 bytes, from Joomla_6.1.4-Stable-Full_Package.zip
Raw History Compare with 6.1.3
md5
ec1deb04a6cfdd0ab24f4c372cac3fa6
sha1
87536438151962da41f1876e51aae5b1e54a89fc
sha256
79d910d99157bf52ad6e1bf13fb5d00c57914cdec6d140824ebe2d693ebabd4e
<?php

/**
 * @package     Joomla.Plugin
 * @subpackage  Captcha.POWCaptcha
 *
 * @copyright   (C) 2025 Open Source Matters, Inc. <https://www.joomla.org>
 * @license     GNU General Public License version 2 or later; see LICENSE.txt
 */

namespace Joomla\Plugin\Captcha\POWCaptcha\Extension;

use Joomla\CMS\Event\Captcha\CaptchaSetupEvent;
use Joomla\CMS\Event\Plugin\AjaxEvent;
use Joomla\CMS\Plugin\CMSPlugin;
use Joomla\Event\SubscriberInterface;
use Joomla\Plugin\Captcha\POWCaptcha\Provider\POWCaptchaProvider;

// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects

/**
 * Proof of work captcha Plugin
 * Based on the ALTCHA captcha library
 *
 * @since 6.1.0
 */
final class POWCaptcha extends CMSPlugin implements SubscriberInterface
{
    /**
     * Load the language file on instantiation.
     *
     * @var    boolean
     * @since 6.1.0
     */
    protected $autoloadLanguage = true;

    public static function getSubscribedEvents(): array
    {
        return [
            'onAjaxPowcaptcha' => 'handleAjaxRequest',
            'onCaptchaSetup'   => 'setupCaptcha',
        ];
    }

    /**
     * Register Captcha instance
     *
     * @param CaptchaSetupEvent $event
     *
     * @return void
     */
    public function setupCaptcha(CaptchaSetupEvent $event)
    {
        $event->getCaptchaRegistry()->add($this->getProvider());
    }

    /**
     * Handles the ajax request triggered by altcha to fetch the challenge code
     *
     * @param AjaxEvent $event
     */
    public function handleAjaxRequest(AjaxEvent $event)
    {
        $event->updateEventResult(
            json_encode(
                $this->getProvider()->getChallenge()
            )
        );
    }

    /**
     * Returns the actual captcha provider instance
     *
     * @return POWCaptchaProvider
     */
    protected function getProvider(): POWCaptchaProvider
    {
        return new POWCaptchaProvider(
            $this->params,
            $this->getApplication()
        );
    }
}

The same content is in 7 releases, Joomla 6.1.4-rc1 to 6.2.1-rc1. See them all, or every version of this file.