Merge pull request #620 from th-h/thh-plugin-notifier

Add plugin update notifications.
This commit is contained in:
Thomas Hochstein 2019-08-13 22:21:28 +02:00 committed by GitHub
commit 221bd4a4c7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 108 additions and 3 deletions

View File

@ -56,6 +56,11 @@ if (is_array($output)) {
} else {
$data['updateButton'] = $output;
}
if (serendipity_plugin_api::hook_event('backend_plugins_upgradecount', $output)) {
$data['pluginUpdates'] = $output;
} else {
$data['pluginUpdates'] = '';
}
$cjoin = ($serendipity['serendipityUserlevel'] == USERLEVEL_EDITOR) ? "
LEFT JOIN {$serendipity['dbPrefix']}authors a ON (e.authorid = a.authorid)

View File

@ -1,3 +1,11 @@
2.38:
-------
* Add function to count upgradeable plugins.
* Add upgrade notifier to plugin upgrade button.
* Add 'backend_plugins_upgradecount' hook and
language constants for a dashboard upgrade
notification.
2.37.6:
-------
* Fix wrong caching of plugin lists regardless of type.

View File

@ -28,6 +28,9 @@
@define('PLUGIN_EVENT_SPARTACUS_CHECK_EVENT', 'Updates (Ereignis-Plugins)');
@define('PLUGIN_EVENT_SPARTACUS_CHECK_HINT', 'Sie können mehrere Plugins auf einmal installieren indem sie diesen Link in einem neuen Tab öffnen (mittlerer Mausbutton)');
@define('PLUGIN_EVENT_SPARTACUS_DASHBOARD_UPDATE', 'Ein Plugin kann aktualisiert werden.');
@define('PLUGIN_EVENT_SPARTACUS_DASHBOARD_UPDATES', '%u Plugins können aktualisiert werden.');
@define('PLUGIN_EVENT_SPARTACUS_REPOSITORY_ERROR', '<br />(Der Mirror-Speicherort antwortet mit Fehler %s.)<br />');
@define('PLUGIN_EVENT_SPARTACUS_HEALTHCHECK', '<p>Die Daten des Spartacus-Speicherorts konnte nicht empfangen werden. Prüfe Verfügbarkeit der Quelle...</p>');
@define('PLUGIN_EVENT_SPARTACUS_HEALTHERROR', '<p>Die Prüfung der Verfügbarkeit einer Spartacus-Quelle konnte nicht durchgeführt werden (HTTP-Code %s). Bitte probieren Sie es später wieder.</p>');

View File

@ -28,6 +28,9 @@
@define('PLUGIN_EVENT_SPARTACUS_CHECK_EVENT', 'Updates (Ereignis-Plugins)');
@define('PLUGIN_EVENT_SPARTACUS_CHECK_HINT', 'Sie können mehrere Plugins auf einmal installieren indem sie diesen Link in einem neuen Tab öffnen (mittlerer Mausbutton)');
@define('PLUGIN_EVENT_SPARTACUS_DASHBOARD_UPDATE', 'Ein Plugin kann aktualisiert werden.');
@define('PLUGIN_EVENT_SPARTACUS_DASHBOARD_UPDATES', '%u Plugins können aktualisiert werden.');
@define('PLUGIN_EVENT_SPARTACUS_REPOSITORY_ERROR', '<br />(Der Mirror-Speicherort antwortet mit Fehler %s.)<br />');
@define('PLUGIN_EVENT_SPARTACUS_HEALTHCHECK', '<p>Die Daten des Spartacus-Speicherorts konnte nicht empfangen werden. Prüfe Verfügbarkeit der Quelle...</p>');
@define('PLUGIN_EVENT_SPARTACUS_HEALTHERROR', '<p>Die Prüfung der Verfügbarkeit einer Spartacus-Quelle konnte nicht durchgeführt werden (HTTP-Code %s). Bitte probieren Sie es später wieder.</p>');

View File

@ -35,6 +35,9 @@
@define('PLUGIN_EVENT_SPARTACUS_CHECK_EVENT', 'Update event plugins');
@define('PLUGIN_EVENT_SPARTACUS_CHECK_HINT', 'You can upgrade multiple plugins at once by opening the update-link in a new tab (middle mouse button)');
@define('PLUGIN_EVENT_SPARTACUS_DASHBOARD_UPDATE', 'A plugin can be updated.');
@define('PLUGIN_EVENT_SPARTACUS_DASHBOARD_UPDATES', '%u plugins can be updated.');
@define('PLUGIN_EVENT_SPARTACUS_TRYCURL', 'Trying to use cURL library as fallback...');
@define('PLUGIN_EVENT_SPARTACUS_CURLFAIL', 'cURL library returned a failure, too.');
@define('PLUGIN_EVENT_SPARTACUS_HEALTFIREWALLED', 'It was not possible to download the required files from the Spartacus repository, but the health of our repository was retrievable. This means your provider uses a content-based firewall and does not allow to fetch PHP code over the web by using mod_security or other reverse proxies. You either need to ask your provider to turn this off, or you cannot use the Spartacus plugin and need to download files manually.');

View File

@ -27,7 +27,7 @@ class serendipity_event_spartacus extends serendipity_event
$propbag->add('description', PLUGIN_EVENT_SPARTACUS_DESC);
$propbag->add('stackable', false);
$propbag->add('author', 'Garvin Hicking');
$propbag->add('version', '2.37.6');
$propbag->add('version', '2.38');
$propbag->add('requirements', array(
'serendipity' => '1.6',
));
@ -40,6 +40,8 @@ class serendipity_event_spartacus extends serendipity_event
'backend_pluginlisting_header' => true,
'backend_plugins_upgradecount' => true,
'external_plugin' => true,
'backend_directory_create' => true,
@ -1132,6 +1134,58 @@ class serendipity_event_spartacus extends serendipity_event
}
}
function count_plugin_upgrades()
{
// get a list of all installable sidebar and event plugins
$foreignPlugins = $sidebarPlugins = $eventPlugins = array();
$sidebarPlugins = $this->buildList($this->fetchOnline('sidebar'), 'sidebar');
$eventPlugins = $this->buildList($this->fetchOnline('event'), 'event');
$foreignPlugins = array_merge($sidebarPlugins, $eventPlugins);
// get currently installed plugin versions
$currentVersions = [];
$plugins = serendipity_plugin_api::get_installed_plugins();
$classes = serendipity_plugin_api::enum_plugins();
foreach ($classes as $class_data) {
$plugin =& serendipity_plugin_api::load_plugin($class_data['name']);
if (is_object($plugin)) {
// Object is returned when a plugin could not be cached.
$bag = new serendipity_property_bag;
$plugin->introspect($bag);
$pluginname = get_object_vars($plugin)['act_pluginPath'];
$version = $bag->get('version');
} elseif (is_array($plugin)) {
// Array is returned if a plugin could be fetched from info cache
$pluginname = $plugin['class_name'];
$version = $plugin['version'];
} else {
#
}
$currentVersions[$pluginname] = $version;
}
// count upgradable plugins
$upgradeCount = 0;
foreach ($foreignPlugins as $foreignPlugin) {
// plugin installed?
if (isset($currentVersions[$foreignPlugin['class_name']])) {
$currentVersion = $currentVersions[$foreignPlugin['class_name']];
// get current version on Spartacus
if (isset($foreignPlugin['upgrade_version']) && $foreignPlugin['upgrade_version']) {
$upgradeVersion = $foreignPlugin['upgrade_version'];
} else {
$upgradeVersion = $foreignPlugin['version'];
}
// compare versions and increase counter
if (version_compare($currentVersion, $upgradeVersion, '<')) {
$upgradeCount++;
}
}
}
return $upgradeCount++;
}
function event_hook($event, &$bag, &$eventData, $addData = null)
{
global $serendipity;
@ -1269,14 +1323,34 @@ class serendipity_event_spartacus extends serendipity_event
if (version_compare($serendipity['version'], '2.1-alpha3', '<')) {
echo ' <a id="upgrade_sidebar" class="button_link" href="?serendipity[adminModule]=plugins&amp;serendipity[adminAction]=addnew&amp;serendipity[only_group]=UPGRADE">'. PLUGIN_EVENT_SPARTACUS_CHECK_SIDEBAR .'</a>';
echo ' <a id="upgrade_event" class="button_link" href="?serendipity[adminModule]=plugins&amp;serendipity[adminAction]=addnew&amp;serendipity[only_group]=UPGRADE&amp;serendipity[type]=event">'. PLUGIN_EVENT_SPARTACUS_CHECK_EVENT .'</a> ';
} else {
echo ' <a id="upgrade_plugins" class="button_link" href="?serendipity[adminModule]=plugins&amp;serendipity[adminAction]=addnew&amp;serendipity[only_group]=UPGRADE' . '&amp;' . serendipity_setFormToken('url') . '">'. PLUGIN_EVENT_SPARTACUS_CHECK .'</a>';
$upgradeCount = $this->count_plugin_upgrades();
$upgradeBadge = '';
if ($upgradeCount > 0) {
$upgradeBadge = sprintf(' (%u)', $upgradeCount);
}
echo ' <a id="upgrade_plugins" class="button_link" href="?serendipity[adminModule]=plugins&amp;serendipity[adminAction]=addnew&amp;serendipity[only_group]=UPGRADE' . '&amp;' . serendipity_setFormToken('url') . '">'. PLUGIN_EVENT_SPARTACUS_CHECK . $upgradeBadge .'</a>';
}
echo '</div>';
}
break;
case 'backend_plugins_upgradecount':
if (serendipity_db_bool($this->get_config('enable_plugins'))) {
$upgradeCount = $this->count_plugin_upgrades();
if ($upgradeCount > 0) {
if ($upgradeCount > 1) {
$eventData = sprintf(PLUGIN_EVENT_SPARTACUS_DASHBOARD_UPDATES, $upgradeCount);
} else {
$eventData = PLUGIN_EVENT_SPARTACUS_DASHBOARD_UPDATE;
}
$eventData .= ' <a id="upgrade_plugins" class="button_link" href="?serendipity[adminModule]=plugins&amp;serendipity[adminAction]=addnew&amp;serendipity[only_group]=UPGRADE' . '&amp;' . serendipity_setFormToken('url') . '">'. PLUGIN_EVENT_SPARTACUS_CHECK .'</a>';
return true;
}
}
return false;
break;
case 'backend_templates_fetchlist':
if (serendipity_db_bool($this->get_config('enable_themes'))) {
$eventData = $this->buildTemplateList($this->fetchOnline('template', true), 'template');

View File

@ -37,6 +37,15 @@
{/if}
{/if}
{if $pluginUpdates}
<section id="dashboard_plugin_updates">
<h3>{$CONST.UPDATE_NOTIFICATION}</h3>
<span class="msg_notice"><span class="icon-info-circled" aria-hidden="true"></span> {$pluginUpdates}</span>
</section>
<hr class="separator">
{/if}
{if $no_create !== true}
<section id="dashboard_comments" class="equal_heights quick_list dashboard_widget">
<h3>{if 'adminComments'|checkPermission}<a href="serendipity_admin.php?serendipity[adminModule]=comments">{/if}{$CONST.COMMENTS}{if 'adminComments'|checkPermission}</a>{/if}</h3>