-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathPluginUpdateNotificationPlugin.php
More file actions
86 lines (70 loc) · 2.55 KB
/
PluginUpdateNotificationPlugin.php
File metadata and controls
86 lines (70 loc) · 2.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
<?php
/**
* @file plugins/reports/pluginUpdateNotification/PluginUpdateNotificationPlugin.php
*
* Copyright (c) 2023 Lepidus Tecnologia
* Copyright (c) 2023 SciELO
* Distributed under the GNU GPL v3. For full terms see LICENSE or https://www.gnu.org/licenses/gpl-3.0.txt.
*
* @class PluginUpdateNotificationPlugin
* @ingroup plugins_generic_pluginUpdateNotification
*
* @brief 'Plugin Update Notification' plugin
*/
namespace APP\plugins\generic\pluginUpdateNotification;
use PKP\plugins\Hook;
use PKP\plugins\GenericPlugin;
use PKP\plugins\GalleryPlugin;
use PKP\config\Config;
use PKP\db\DAORegistry;
use APP\core\Application;
class PluginUpdateNotificationPlugin extends GenericPlugin
{
public function register($category, $path, $mainContextId = null)
{
$success = parent::register($category, $path, $mainContextId);
if (!Config::getVar('general', 'installed') || defined('RUNNING_UPGRADE')) {
return true;
}
if ($success && $this->getEnabled($mainContextId)) {
Hook::add('Template::Settings::website', array($this, 'websiteSettingsCallback'));
}
return $success;
}
public function getDisplayName()
{
return __('plugins.generic.pluginUpdateNotification.displayName');
}
public function getDescription()
{
return __('plugins.generic.pluginUpdateNotification.description');
}
public function websiteSettingsCallback($hookName, $params)
{
$smarty = &$params[1];
$output = &$params[2];
$pluginsToUpdate = $this->getUpgradablePlugins();
if (!empty($pluginsToUpdate)) {
$smarty->assign([
'stringPlugins' => implode(", ", $pluginsToUpdate)
]);
$output .= sprintf('%s', $smarty->fetch($this->getTemplateResource('updateNotificationPlugins.tpl')));
}
return false;
}
private function getUpgradablePlugins()
{
$pluginGalleryDao = DAORegistry::getDAO('PluginGalleryDAO');
$pluginsGallery = $pluginGalleryDao->getNewestCompatible(Application::get());
$updatePluginsNames = array();
foreach ($pluginsGallery as $plugin) {
if ($plugin->getCurrentStatus() == GalleryPlugin::PLUGIN_GALLERY_STATE_UPGRADABLE) {
$updatePluginsNames[] = $plugin->getLocalizedName();
}
}
return $updatePluginsNames;
}
}
if (!PKP_STRICT_MODE) {
class_alias('\APP\plugins\generic\pluginUpdateNotification\PluginUpdateNotificationPlugin', '\PluginUpdateNotificationPlugin');
}