| Server IP : 54.36.91.62 / Your IP : 216.73.217.112 Web Server : Apache System : Linux webm013.cluster127.gra.hosting.ovh.net 5.15.206-ovh-vps-grsec-zfs-classid #1 SMP Fri May 15 02:41:25 UTC 2026 x86_64 User : coopiak ( 151928) PHP Version : 8.3.23 Disable Function : _dyuweyrj4,_dyuweyrj4r,dl MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : OFF | Pkexec : OFF Directory : /home/coopiak/amisdesseniors-fr/aix/plugins/system/aimycanonical/helpers/ |
Upload File : |
<?php
/*
* Copyright (c) 2024-2025 Aimy Extensions, Netzum Sorglos Software GmbH
*
* https://www.aimy-extensions.com/
*
* License: GNU GPLv2, see LICENSE.txt within distribution and/or
* http://www.aimy-extensions.com/software-license.html
*/
namespace AimyCanonical\Helpers; defined( '_JEXEC' ) or die(); use Joomla\CMS\Factory; use Joomla\CMS\Http\HttpFactory; use Joomla\CMS\Language\Text; use Joomla\CMS\HTML\HTMLHelper; use Joomla\Registry\Registry; abstract class DownloadKeyHelper { const V_KEY_MISSING = 0; const V_KEY_INVALID = 1; const V_KEY_DENIED = 2; const V_KEY_EXPIRED = 3; const V_KEY_GRANTED = 4; const V_KEY_FAILED = 5; static private $lastError = ''; static private $lastResponseData = array(); static private $serverBaseUrl = 'http://dl.aimy-extensions.com'; static public function getUpdatesiteId() { $db = Factory::getDbo(); $q = $db->getQuery( true ); $q->select( $db->quoteName( 'update_site_id' ) ) ->from( $db->quoteName( '#__update_sites' ) ) ->where( $db->quoteName( 'name' ) . ' = ' . $db->quote( self::getUpdateServerName() ) ); $db->setQuery( $q ); return $db->loadResult(); } static public function getExtensionId() { $db = Factory::getDbo(); $q = $db->getQuery( true ); $q->select( $db->quoteName( 'extension_id' ) ) ->from( $db->quoteName( '#__extensions' ) ) ->where( $db->quoteName( 'element' ) . ' = ' . $db->quote( self::getElementName() ) ); $db->setQuery( $q ); return $db->loadResult(); } static public function getEditLink() { if ( self::isJoomla3() ) { if ( 'plg' == 'com' ) { return 'index.php?option=com_config&view=component&' . 'component=com_aimycanonical'; } $link = 'index.php?option=com_plugins'; if ( ! empty( $id = self::getExtensionId() ) ) { return $link . '&task=plugin.edit&extension_id=' . $id; } return $link . '&view=plugins'; } if ( $id = self::getUpdatesiteId() ) { return 'index.php?option=com_installer&' . 'task=updatesite.edit&update_site_id=' . $id; } return 'index.php?option=com_installer&view=updatesite'; } static public function passKeyToUpdatesites( $key ) { $id = self::getUpdateSiteId(); if ( ! $id ) { throw new \RuntimeException( 'Failed to determine update site id of AimyCanonical' ); } $eqVal = ''; if ( ! empty( $key ) ) { $key = trim( $key ); if ( ! empty( $key ) ) { $eqVal = 'dl_key=' . $key; } } $db = Factory::getDbo(); $q = $db->getQuery( true ); $q->update( $db->quoteName( '#__update_sites' ) ) ->set( $db->quoteName( 'extra_query' ) . ' = ' . $db->quote( $eqVal ) ) ->where( $db->quoteName( 'update_site_id' ) . ' = ' . $db->quote( $id ) ); $db->setQuery( $q ); return $db->execute(); } static public function getKey() { $key = self::getKeyFromUpdatesites(); if ( self::isJoomla3() && empty( $key ) ) { $key = self::getKeyFromParams(); } return $key; } static public function getKeyFromUpdatesites() { $db = Factory::getDbo(); $q = $db->getQuery( true ); $q->select( $db->quoteName( 'extra_query' ) ) ->from( $db->quoteName( '#__update_sites' ) ) ->where( $db->quoteName( 'name' ) . ' = ' . $db->quote( self::getUpdateServerName() ) ); $db->setQuery( $q ); $rv = $db->loadResult(); if ( ! empty( $rv ) && preg_match( '#dl_key=(\S+)#', $rv, $m ) ) { return $m[ 1 ]; } return false; } static public function getKeyFromParams() { $params = self::getParams(); if ( $params->exists( 'dl_key' ) ) { return trim( $params->get( 'dl_key' ) ); } return false; } static public function validateKey( $key = false ) { if ( empty( $key ) ) { $key = self::getKey(); } $rv = new \StdClass(); $rv->state = self::sendValidationRequest( $key ); $rv->msg = false; $rv->data = self::$lastResponseData; $rv->valid = false; self::loadLanguageStrings(); switch ( $rv->state ) { case self::V_KEY_GRANTED: $rv->valid = true; break; case self::V_KEY_MISSING: $rv->msg = Text::sprintf( 'AIMY_CNCL_DL_KEY_MISSING', htmlspecialchars( self::getEditLink() ) ); break; case self::V_KEY_INVALID: $rv->msg = Text::sprintf( 'AIMY_CNCL_DL_KEY_INVALID', htmlspecialchars( self::getEditLink() ) ); break; case self::V_KEY_EXPIRED: $rv->msg = Text::sprintf( 'AIMY_CNCL_DL_KEY_EXPIRED', HtmlHelper::date( isset( $rv->data[ 'since' ] ) ? $rv->data[ 'since' ] : 'now', Text::_( 'DATE_FORMAT_FILTER_DATE' ) ), htmlspecialchars( 'https://www.aimy-extensions.com/joomla/canonical.html' ) ); if ( isset( $rv->data[ 'code' ] ) ) { $rv->msg .= ' ' . Text::sprintf( 'AIMY_CNCL_DL_KEY_CODE', $rv->data[ 'code'] ); } break; case self::V_KEY_DENIED: $rv->msg = Text::sprintf( 'AIMY_CNCL_DL_KEY_DENIED', htmlspecialchars( 'https://www.aimy-extensions.com/joomla/canonical.html' ) ); break; case self::V_KEY_FAILED: $rv->msg = Text::sprintf( 'AIMY_CNCL_DL_KEY_VALIDATION_FAILED', self::$lastError ); break; } return $rv; } static private function sendValidationRequest( $key ) { if ( empty( $key ) ) { return self::V_KEY_MISSING; } try { self::$lastError = self::$lastResponseData = ''; $resp = HttpFactory::getHttp()->get( self::$serverBaseUrl . '/check/key/plg_AimyCanonical/' . $key ); if ( is_object( $resp ) ) { if ( $resp->code != 200 ) { self::$lastError = 'HTTP ' . $resp->code; return self::V_KEY_FAILED; } $json = json_decode( $resp->body, true ); if ( ! is_array( $json ) or ! isset( $json[ 'rv' ] ) ) { throw new \RuntimeException( 'Failed to parse JSON data' ); } self::$lastResponseData = $json; switch( $json[ 'rv' ] ) { case 'invalid key': return self::V_KEY_INVALID; case 'expired': return self::V_KEY_EXPIRED; case 'denied': return self::V_KEY_DENIED; case 'granted': return self::V_KEY_GRANTED; } } } catch ( \Exception $e ) { self::$lastError = $e->getMessage(); return self::V_KEY_FAILED; } return self::V_KEY_FAILED; } static private function getUpdateServerName() { return 'Aimy Canonical PRO Update Server'; } static private function getElementName() { if ( 'plg' == 'com' ) { return 'com_aimycanonical'; } return 'aimycanonical'; } static private function loadLanguageStrings() { $n = 'plg_'; if ( ! empty( $jp = 'system' ) ) { $n .= $jp . '_'; } $n .= 'aimycanonical'; Factory::getLanguage()->load( $n, JPATH_ADMINISTRATOR ); } static private function isJoomla3() { return ( strpos( JVERSION, '3.' ) === 0 ); } static public function getParams() { $db = Factory::getDbo(); $q = $db->getQuery( true ); $q->select( $db->quoteName( 'params' ) ) ->from( $db->quoteName( '#__extensions' ) ) ->where( $db->quoteName( 'element' ) . ' = ' . $db->quote( self::getElementName() ) ); $db->setQuery( $q ); $rv = $db->loadResult(); if ( empty( $rv ) ) { return false; } $params = new Registry(); $params->loadString( $rv ); return $params; } }