Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a plugin with a nag message to update PHP
- Loading branch information
Michael Babker
committed
Aug 6, 2016
1 parent
59ef2fb
commit 0df937f
Showing
11 changed files
with
221 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 2 additions & 0 deletions
2
administrator/components/com_admin/sql/updates/mysql/3.7.0-2016-08-06.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
INSERT INTO `#__extensions` (`extension_id`, `name`, `type`, `element`, `folder`, `client_id`, `enabled`, `access`, `protected`, `manifest_cache`, `params`, `custom_data`, `system_data`, `checked_out`, `checked_out_time`, `ordering`, `state`) VALUES | ||
(458, 'plg_system_phpversioncheck', 'plugin', 'phpversioncheck', 'system', 0, 1, 1, 1, '', '', '', '', 0, '0000-00-00 00:00:00', 0, 0); |
2 changes: 2 additions & 0 deletions
2
administrator/components/com_admin/sql/updates/postgresql/3.7.0-2016-08-06.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
INSERT INTO "#__extensions" ("extension_id", "name", "type", "element", "folder", "client_id", "enabled", "access", "protected", "manifest_cache", "params", "custom_data", "system_data", "checked_out", "checked_out_time", "ordering", "state") VALUES | ||
(458, 'plg_system_phpversioncheck', 'plugin', 'phpversioncheck', 'system', 0, 1, 1, 1, '', '', '', '', 0, '1970-01-01 00:00:00', 0, 0); |
6 changes: 6 additions & 0 deletions
6
administrator/components/com_admin/sql/updates/sqlazure/3.7.0-2016-08-06.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
SET IDENTITY_INSERT #__extensions ON; | ||
|
||
INSERT INTO #__extensions ([extension_id], [name], [type], [element], [folder], [client_id], [enabled], [access], [protected], [manifest_cache], [params], [custom_data], [system_data], [checked_out], [checked_out_time], [ordering], [state]) | ||
SELECT 458, 'plg_system_phpversioncheck', 'plugin', 'phpversioncheck', 'system', 0, 1, 1, 1, '', '', '', '', 0, '1900-01-01 00:00:00', 0, 0; | ||
|
||
SET IDENTITY_INSERT #__extensions OFF; |
9 changes: 9 additions & 0 deletions
9
administrator/language/en-GB/en-GB.plg_system_phpversioncheck.ini
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
; Joomla! Project | ||
; Copyright (C) 2005 - 2016 Open Source Matters. All rights reserved. | ||
; License GNU General Public License version 2 or later; see LICENSE.txt, see LICENSE.php | ||
; Note : All ini files need to be saved as UTF-8 | ||
|
||
PLG_SYSTEM_PHPVERSIONCHECK="System - PHP Version Check" | ||
PLG_SYSTEM_PHPVERSIONCHECK_SECURITY_ONLY="Your PHP version, %1$s, is only receiving security fixes at this time. This means your PHP version will soon no longer be supported. We recommend planning to upgrade to a newer PHP version before it reaches end of support on %2$s. Please contact your host for upgrade instructions." | ||
PLG_SYSTEM_PHPVERSIONCHECK_UNSUPPORTED="Your PHP version, %1$s, is no longer supported by the PHP project. Support for this version of PHP ended on %2$s. We highly recommend upgrading your server to a newer PHP version. Please contact your host for upgrade instructions." | ||
PLG_SYSTEM_PHPVERSIONCHECK_XML_DESCRIPTION="Checks the support status of your installation's PHP version and raises a warning if not fully supported." |
7 changes: 7 additions & 0 deletions
7
administrator/language/en-GB/en-GB.plg_system_phpversioncheck.sys.ini
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
; Joomla! Project | ||
; Copyright (C) 2005 - 2016 Open Source Matters. All rights reserved. | ||
; License GNU General Public License version 2 or later; see LICENSE.txt, see LICENSE.php | ||
; Note : All ini files need to be saved as UTF-8 | ||
|
||
PLG_SYSTEM_PHPVERSIONCHECK="System - PHP Version Check" | ||
PLG_SYSTEM_PHPVERSIONCHECK_XML_DESCRIPTION="Checks the support status of your installation's PHP version and raises a warning if not fully supported." |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,166 @@ | ||
<?php | ||
/** | ||
* @package Joomla.Plugin | ||
* @subpackage System.phpversioncheck | ||
* | ||
* @copyright Copyright (C) 2005 - 2016 Open Source Matters, Inc. All rights reserved. | ||
* @license GNU General Public License version 2 or later; see LICENSE.txt | ||
*/ | ||
|
||
defined('_JEXEC') or die; | ||
|
||
/** | ||
* Plugin to check the PHP version and display a warning about its support status | ||
* | ||
* @since __DEPLOY_VERSION__ | ||
*/ | ||
class PlgSystemPhpVersionCheck extends JPlugin | ||
{ | ||
/** | ||
* Constant representing the active PHP version being fully supported | ||
* | ||
* @var integer | ||
* @since __DEPLOY_VERSION__ | ||
*/ | ||
const PHP_SUPPORTED = 0; | ||
|
||
/** | ||
* Constant representing the active PHP version receiving security support only | ||
* | ||
* @var integer | ||
* @since __DEPLOY_VERSION__ | ||
*/ | ||
const PHP_SECURITY_ONLY = 1; | ||
|
||
/** | ||
* Constant representing the active PHP version being unsupported | ||
* | ||
* @var integer | ||
* @since __DEPLOY_VERSION__ | ||
*/ | ||
const PHP_UNSUPPORTED = 2; | ||
|
||
/** | ||
* Application object. | ||
* | ||
* @var JApplicationCms | ||
* @since __DEPLOY_VERSION__ | ||
*/ | ||
protected $app; | ||
|
||
/** | ||
* Load plugin language files automatically | ||
* | ||
* @var boolean | ||
* @since __DEPLOY_VERSION__ | ||
*/ | ||
protected $autoloadLanguage = true; | ||
|
||
/** | ||
* Check the PHP version after the admin component has been dispatched. | ||
* | ||
* @return void | ||
* | ||
* @since __DEPLOY_VERSION__ | ||
*/ | ||
public function onAfterDispatch() | ||
{ | ||
if (!$this->app->isAdmin() || $this->app->getDocument()->getType() !== 'html') | ||
{ | ||
return; | ||
} | ||
|
||
$supportStatus = $this->getPhpSupport(); | ||
|
||
if ($supportStatus['status'] !== self::PHP_SUPPORTED) | ||
{ | ||
// Enqueue the notification message; set a warning if receiving security support or "error" if unsupported | ||
switch ($supportStatus['status']) | ||
{ | ||
case self::PHP_SECURITY_ONLY: | ||
$this->app->enqueueMessage($supportStatus['message'], 'warning'); | ||
|
||
break; | ||
|
||
case self::PHP_UNSUPPORTED: | ||
$this->app->enqueueMessage($supportStatus['message'], 'error'); | ||
|
||
break; | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* Gets PHP support status. | ||
* | ||
* @return array Array of PHP support data | ||
* | ||
* @since __DEPLOY_VERSION__ | ||
* @note The dates used in this method should correspond to the dates given on PHP.net | ||
* @see https://secure.php.net/supported-versions.php | ||
* @see https://secure.php.net/eol.php | ||
*/ | ||
private function getPhpSupport() | ||
{ | ||
$phpSupportData = array( | ||
'5.3' => array( | ||
'security' => '2013-07-11', | ||
'eos' => '2014-08-14', | ||
), | ||
'5.4' => array( | ||
'security' => '2014-09-14', | ||
'eos' => '2015-09-14', | ||
), | ||
'5.5' => array( | ||
'security' => '2015-07-10', | ||
'eos' => '2016-07-21' | ||
), | ||
'5.6' => array( | ||
'security' => '2016-12-31', | ||
'eos' => '2018-12-31' | ||
), | ||
'7.0' => array( | ||
'security' => '2017-12-03', | ||
'eos' => '2018-12-03' | ||
), | ||
); | ||
|
||
// Fill our return array with default values | ||
$supportStatus = array( | ||
'status' => self::PHP_SUPPORTED, | ||
'message' => null, | ||
); | ||
|
||
// Check the PHP version's support status using the minor version | ||
$activePhpVersion = PHP_MAJOR_VERSION . '.' . PHP_MINOR_VERSION; | ||
|
||
// Do we have the PHP version's data? | ||
if (isset($phpSupportData[$activePhpVersion])) | ||
{ | ||
// First check if the version has reached end of support | ||
$today = new JDate; | ||
$phpEndOfSupport = new JDate($phpSupportData[$activePhpVersion]['eos']); | ||
|
||
if ($phpNotSupported = $today > $phpEndOfSupport) | ||
{ | ||
$supportStatus['status'] = self::PHP_UNSUPPORTED; | ||
$supportStatus['message'] = JText::sprintf( | ||
'PLG_SYSTEM_PHPVERSIONCHECK_UNSUPPORTED', PHP_VERSION, $phpEndOfSupport->format(JText::_('DATE_FORMAT_LC4')) | ||
); | ||
} | ||
|
||
// If the version is still supported, check if it has reached security support only | ||
$phpSecurityOnlyDate = new JDate($phpSupportData[$activePhpVersion]['security']); | ||
|
||
if (!$phpNotSupported && $today > $phpSecurityOnlyDate) | ||
{ | ||
$supportStatus['status'] = self::PHP_SECURITY_ONLY; | ||
$supportStatus['message'] = JText::sprintf( | ||
'PLG_SYSTEM_PHPVERSIONCHECK_SECURITY_ONLY', PHP_VERSION, $phpEndOfSupport->format(JText::_('DATE_FORMAT_LC4')) | ||
); | ||
} | ||
} | ||
|
||
return $supportStatus; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<extension version="3.7" type="plugin" group="system" method="upgrade"> | ||
<name>plg_system_phpversioncheck</name> | ||
<author>Joomla! Project</author> | ||
<creationDate>August 2016</creationDate> | ||
<copyright>Copyright (C) 2005 - 2016 Open Source Matters. All rights reserved.</copyright> | ||
<license>GNU General Public License version 2 or later; see LICENSE.txt</license> | ||
<authorEmail>admin@joomla.org</authorEmail> | ||
<authorUrl>www.joomla.org</authorUrl> | ||
<version>3.7.0</version> | ||
<description>PLG_SYSTEM_PHPVERSIONCHECK_XML_DESCRIPTION</description> | ||
<files> | ||
<filename plugin="phpversioncheck">phpversioncheck.php</filename> | ||
</files> | ||
<languages> | ||
<language tag="en-GB">en-GB.plg_system_phpversioncheck.ini</language> | ||
<language tag="en-GB">en-GB.plg_system_phpversioncheck.sys.ini</language> | ||
</languages> | ||
</extension> |