[ Index ] |
PHP Cross Reference of Joomla 4.2.2 documentation |
[Summary view] [Print] [Text view]
1 <?php 2 3 /** 4 * @package Joomla.Plugin 5 * @subpackage Quickicon.phpversioncheck 6 * 7 * @copyright (C) 2016 Open Source Matters, Inc. <https://www.joomla.org> 8 * @license GNU General Public License version 2 or later; see LICENSE.txt 9 10 * @phpcs:disable PSR1.Classes.ClassDeclaration.MissingNamespace 11 */ 12 13 use Joomla\CMS\Date\Date; 14 use Joomla\CMS\Language\Text; 15 use Joomla\CMS\Plugin\CMSPlugin; 16 17 // phpcs:disable PSR1.Files.SideEffects 18 \defined('_JEXEC') or die; 19 // phpcs:enable PSR1.Files.SideEffects 20 21 /** 22 * Plugin to check the PHP version and display a warning about its support status 23 * 24 * @since 3.7.0 25 */ 26 class PlgQuickiconPhpVersionCheck extends CMSPlugin 27 { 28 /** 29 * Constant representing the active PHP version being fully supported 30 * 31 * @var integer 32 * @since 3.7.0 33 */ 34 public const PHP_SUPPORTED = 0; 35 36 /** 37 * Constant representing the active PHP version receiving security support only 38 * 39 * @var integer 40 * @since 3.7.0 41 */ 42 public const PHP_SECURITY_ONLY = 1; 43 44 /** 45 * Constant representing the active PHP version being unsupported 46 * 47 * @var integer 48 * @since 3.7.0 49 */ 50 public const PHP_UNSUPPORTED = 2; 51 52 /** 53 * Application object. 54 * 55 * @var \Joomla\CMS\Application\CMSApplication 56 * @since 3.7.0 57 */ 58 protected $app; 59 60 /** 61 * Load plugin language files automatically 62 * 63 * @var boolean 64 * @since 3.7.0 65 */ 66 protected $autoloadLanguage = true; 67 68 /** 69 * Check the PHP version after the admin component has been dispatched. 70 * 71 * @param string $context The calling context 72 * 73 * @return array 74 * 75 * @since 3.7.0 76 */ 77 public function onGetIcons($context) 78 { 79 if (!$this->shouldDisplayMessage()) { 80 return []; 81 } 82 83 $supportStatus = $this->getPhpSupport(); 84 85 if ($supportStatus['status'] !== self::PHP_SUPPORTED) { 86 // Enqueue the notification message; set a warning if receiving security support or "error" if unsupported 87 switch ($supportStatus['status']) { 88 case self::PHP_SECURITY_ONLY: 89 $this->app->enqueueMessage($supportStatus['message'], 'warning'); 90 91 break; 92 93 case self::PHP_UNSUPPORTED: 94 $this->app->enqueueMessage($supportStatus['message'], 'danger'); 95 96 break; 97 } 98 } 99 100 return []; 101 } 102 103 /** 104 * Gets PHP support status. 105 * 106 * @return array Array of PHP support data 107 * 108 * @since 3.7.0 109 * @note The dates used in this method should correspond to the dates given on PHP.net 110 * @link https://www.php.net/supported-versions.php 111 * @link https://www.php.net/eol.php 112 */ 113 private function getPhpSupport() 114 { 115 $phpSupportData = array( 116 '7.2' => array( 117 'security' => '2019-11-30', 118 'eos' => '2020-11-30', 119 ), 120 '7.3' => array( 121 'security' => '2020-12-06', 122 'eos' => '2021-12-06', 123 ), 124 '7.4' => array( 125 'security' => '2021-11-28', 126 'eos' => '2022-11-28', 127 ), 128 '8.0' => array( 129 'security' => '2022-11-26', 130 'eos' => '2023-11-26', 131 ), 132 '8.1' => array( 133 'security' => '2023-11-25', 134 'eos' => '2024-11-25', 135 ), 136 ); 137 138 // Fill our return array with default values 139 $supportStatus = array( 140 'status' => self::PHP_SUPPORTED, 141 'message' => null, 142 ); 143 144 // Check the PHP version's support status using the minor version 145 $activePhpVersion = PHP_MAJOR_VERSION . '.' . PHP_MINOR_VERSION; 146 147 // Handle non standard strings like PHP 7.2.34-8+ubuntu18.04.1+deb.sury.org+1 148 $phpVersion = preg_split('/-/', PHP_VERSION)[0]; 149 150 // Do we have the PHP version's data? 151 if (isset($phpSupportData[$activePhpVersion])) { 152 // First check if the version has reached end of support 153 $today = new Date(); 154 $phpEndOfSupport = new Date($phpSupportData[$activePhpVersion]['eos']); 155 156 if ($phpNotSupported = $today > $phpEndOfSupport) { 157 /* 158 * Find the oldest PHP version still supported that is newer than the current version, 159 * this is our recommendation for users on unsupported platforms 160 */ 161 foreach ($phpSupportData as $version => $versionData) { 162 $versionEndOfSupport = new Date($versionData['eos']); 163 164 if (version_compare($version, $activePhpVersion, 'ge') && ($today < $versionEndOfSupport)) { 165 $supportStatus['status'] = self::PHP_UNSUPPORTED; 166 $supportStatus['message'] = Text::sprintf( 167 'PLG_QUICKICON_PHPVERSIONCHECK_UNSUPPORTED', 168 $phpVersion, 169 $version, 170 $versionEndOfSupport->format(Text::_('DATE_FORMAT_LC4')) 171 ); 172 173 return $supportStatus; 174 } 175 } 176 177 // PHP version is not supported and we don't know of any supported versions. 178 $supportStatus['status'] = self::PHP_UNSUPPORTED; 179 $supportStatus['message'] = Text::sprintf( 180 'PLG_QUICKICON_PHPVERSIONCHECK_UNSUPPORTED_JOOMLA_OUTDATED', 181 $phpVersion 182 ); 183 184 return $supportStatus; 185 } 186 187 // If the version is still supported, check if it has reached eol minus 3 month 188 $securityWarningDate = clone $phpEndOfSupport; 189 $securityWarningDate->sub(new DateInterval('P3M')); 190 191 if (!$phpNotSupported && $today > $securityWarningDate) { 192 $supportStatus['status'] = self::PHP_SECURITY_ONLY; 193 $supportStatus['message'] = Text::sprintf( 194 'PLG_QUICKICON_PHPVERSIONCHECK_SECURITY_ONLY', 195 $phpVersion, 196 $phpEndOfSupport->format(Text::_('DATE_FORMAT_LC4')) 197 ); 198 } 199 } 200 201 return $supportStatus; 202 } 203 204 /** 205 * Determines if the message should be displayed 206 * 207 * @return boolean 208 * 209 * @since 3.7.0 210 */ 211 private function shouldDisplayMessage() 212 { 213 // Only on admin app 214 if (!$this->app->isClient('administrator')) { 215 return false; 216 } 217 218 // Only if authenticated 219 if ($this->app->getIdentity()->guest) { 220 return false; 221 } 222 223 // Only on HTML documents 224 if ($this->app->getDocument()->getType() !== 'html') { 225 return false; 226 } 227 228 // Only on full page requests 229 if ($this->app->input->getCmd('tmpl', 'index') === 'component') { 230 return false; 231 } 232 233 // Only to com_cpanel 234 if ($this->app->input->get('option') !== 'com_cpanel') { 235 return false; 236 } 237 238 return true; 239 } 240 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Wed Sep 7 05:41:13 2022 | Chilli.vc Blog - For Webmaster,Blog-Writer,System Admin and Domainer |