Skip to content

Commit

Permalink
Add a plugin with a nag message to update PHP
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Babker committed Aug 6, 2016
1 parent 59ef2fb commit 0df937f
Show file tree
Hide file tree
Showing 11 changed files with 221 additions and 5 deletions.
7 changes: 4 additions & 3 deletions administrator/components/com_admin/script.php
Expand Up @@ -343,9 +343,10 @@ protected function updateManifestCaches()
array('plugin', 'updatenotification', 'system', 0),
array('plugin', 'module', 'editors-xtd', 0),
array('plugin', 'stats', 'system', 0),
array('plugin', 'packageinstaller','installer',0),
array('plugin', 'folderinstaller','installer', 0),
array('plugin', 'urlinstaller','installer', 0),
array('plugin', 'packageinstaller', 'installer', 0),
array('plugin', 'folderinstaller', 'installer', 0),
array('plugin', 'urlinstaller', 'installer', 0),
array('plugin', 'phpversioncheck', 'system', 0),

// Templates
array('template', 'beez3', '', 0),
Expand Down
@@ -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);
@@ -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);
@@ -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;
@@ -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."
@@ -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."
1 change: 1 addition & 0 deletions installation/sql/mysql/joomla.sql
Expand Up @@ -614,6 +614,7 @@ INSERT INTO `#__extensions` (`extension_id`, `name`, `type`, `element`, `folder`
(455, 'plg_installer_packageinstaller', 'plugin', 'packageinstaller', 'installer', 0, 1, 1, 1, '', '', '', '', 0, '0000-00-00 00:00:00', 1, 0),
(456, 'plg_installer_folderinstaller', 'plugin', 'folderinstaller', 'installer', 0, 1, 1, 1, '', '', '', '', 0, '0000-00-00 00:00:00', 2, 0),
(457, 'plg_installer_urlinstaller', 'plugin', 'urlinstaller', 'installer', 0, 1, 1, 1, '', '', '', '', 0, '0000-00-00 00:00:00', 3, 0),
(458, 'plg_system_phpversioncheck', 'plugin', 'phpversioncheck', 'system', 0, 1, 1, 1, '', '', '', '', 0, '0000-00-00 00:00:00', 0, 0),
(503, 'beez3', 'template', 'beez3', '', 0, 1, 1, 0, '', '{"wrapperSmall":"53","wrapperLarge":"72","sitetitle":"","sitedescription":"","navposition":"center","templatecolor":"nature"}', '', '', 0, '0000-00-00 00:00:00', 0, 0),
(504, 'hathor', 'template', 'hathor', '', 1, 1, 1, 0, '', '{"showSiteName":"0","colourChoice":"0","boldText":"0"}', '', '', 0, '0000-00-00 00:00:00', 0, 0),
(506, 'protostar', 'template', 'protostar', '', 0, 1, 1, 0, '', '{"templateColor":"","logoFile":"","googleFont":"1","googleFontName":"Open+Sans","fluidContainer":"0"}', '', '', 0, '0000-00-00 00:00:00', 0, 0),
Expand Down
3 changes: 2 additions & 1 deletion installation/sql/postgresql/joomla.sql
Expand Up @@ -613,7 +613,8 @@ INSERT INTO "#__extensions" ("extension_id", "name", "type", "element", "folder"
(454, 'plg_system_stats', 'plugin', 'stats', 'system', 0, 1, 1, 0, '', '', '', '', 0, '1970-01-01 00:00:00', 0, 0),
(455, 'plg_installer_packageinstaller', 'plugin', 'packageinstaller', 'installer', 0, 1, 1, 1, '', '', '', '', 0, '1970-01-01 00:00:00', 1, 0),
(456, 'plg_installer_folderinstaller', 'plugin', 'folderinstaller', 'installer', 0, 1, 1, 1, '', '', '', '', 0, '1970-01-01 00:00:00', 2, 0),
(457, 'plg_installer_urlinstaller', 'plugin', 'urlinstaller', 'installer', 0, 1, 1, 1, '', '', '', '', 0, '1970-01-01 00:00:00', 3, 0);
(457, 'plg_installer_urlinstaller', 'plugin', 'urlinstaller', 'installer', 0, 1, 1, 1, '', '', '', '', 0, '1970-01-01 00:00:00', 3, 0),
(458, 'plg_system_phpversioncheck', 'plugin', 'phpversioncheck', 'system', 0, 1, 1, 1, '', '', '', '', 0, '1970-01-01 00:00:00', 0, 0);

-- Templates
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
Expand Down
4 changes: 3 additions & 1 deletion installation/sql/sqlazure/joomla.sql
Expand Up @@ -1007,7 +1007,9 @@ SELECT 455, 'plg_installer_packageinstaller', 'plugin', 'packageinstaller', 'ins
UNION ALL
SELECT 456, 'plg_installer_folderinstaller', 'plugin', 'folderinstaller', 'installer', 0, 1, 1, 1, '', '', '', '', 0, '1900-01-01 00:00:00', 2, 0
UNION ALL
SELECT 457, 'plg_installer_urlinstaller', 'plugin', 'urlinstaller', 'installer', 0, 1, 1, 1, '', '', '', '', 0, '1900-01-01 00:00:00', 3, 0;
SELECT 457, 'plg_installer_urlinstaller', 'plugin', 'urlinstaller', 'installer', 0, 1, 1, 1, '', '', '', '', 0, '1900-01-01 00:00:00', 3, 0
UNION ALL
SELECT 458, 'plg_system_phpversioncheck', 'plugin', 'phpversioncheck', 'system', 0, 1, 1, 1, '', '', '', '', 0, '1900-01-01 00:00:00', 0, 0;

INSERT [#__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 503, 'beez3', 'template', 'beez3', '', 0, 1, 1, 0, '', '{"wrapperSmall":"53","wrapperLarge":"72","sitetitle":"","sitedescription":"","navposition":"center","templatecolor":"nature"}', '', '', 0, '1900-01-01 00:00:00', 0, 0
Expand Down
166 changes: 166 additions & 0 deletions plugins/system/phpversioncheck/phpversioncheck.php
@@ -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;
}
}
19 changes: 19 additions & 0 deletions plugins/system/phpversioncheck/phpversioncheck.xml
@@ -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>

0 comments on commit 0df937f

Please sign in to comment.