Skip to content

Commit 208f7d8

Browse files
Merge pull request #638 from CleanTalk/psc_on_plugins_list.ag
Upd. Vulnerability Alarm. Show badge for PSC safe plugins on the installed plugins list.
2 parents 9fda77e + ecdff8a commit 208f7d8

10 files changed

Lines changed: 416 additions & 58 deletions

File tree

css/spbc-admin.min.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

css/src/spbc-admin.css

Lines changed: 64 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -148,19 +148,32 @@ span.green_dot{
148148
#spbct-upload-checker-details li:nth-child(2n+1) {
149149
background: #CCC;
150150
}
151+
152+
/*--------Vulnerability alarm section--------*/
153+
151154
.plugins .update + .spbc-vulnerable-notice td {
152155
box-shadow: none !important;
153156
}
154157
.themes .spbc-vulnerable-notice {
155158
top: auto;
156159
bottom: 45px;
157160
}
161+
/*Badge itself*/
158162
.spbct-safe-extension-badge {
159163
cursor: pointer;
160164
}
165+
.spbct-safe-extension-badge[data-type="installed_plugins"] {
166+
display: inline-flex;
167+
position: relative;
168+
min-width: 100px;
169+
}
170+
171+
/*Description placeholder*/
161172
.spbct-safe-extension-badge-description-placeholder {
162173
position: relative;
163174
}
175+
176+
/*Description body*/
164177
.spbct-safe-extension-badge-description {
165178
display: none;
166179
position: absolute;
@@ -169,11 +182,59 @@ span.green_dot{
169182
color: white;
170183
text-align: center;
171184
top: 2px;
172-
right: 0;
173-
padding: 5px;
185+
padding: 10px;
174186
animation: fadeInFromNone 0.3s ease-in-out;
175187
z-index: 9999;
188+
width: max-content;
189+
}
190+
.spbct-safe-extension-badge-description[data-type="installed_plugins"] {
191+
top: 20px;
192+
left: -18px;
193+
}
194+
.spbct-safe-extension-badge-description[data-type="before_install"] {
195+
top: -1px;
196+
right: 0;
197+
}
198+
199+
/*Description body angle*/
200+
.spbct-safe-extension-badge-description:before {
201+
content: '';
202+
position: absolute;
203+
top: -9px;
204+
border: 5px solid transparent;
205+
border-bottom: 5px solid rgba(0, 0, 0, 0.5);
206+
}
207+
.spbct-safe-extension-badge-description[data-type="installed_plugins"]:before {
208+
left: 6px;
209+
}
210+
.spbct-safe-extension-badge-description[data-type="before_install"]:before {
211+
right: 6px;
212+
}
213+
/*Description body link style*/
214+
.spbct-safe-extension-badge-description > a {
215+
color: white;
216+
text-decoration: underline;
176217
}
218+
/*Description popup behavior for list of installed plugins*/
219+
.spbct-safe-extension-badge[data-type="installed_plugins"]:hover > .spbct-safe-extension-badge-description-placeholder[data-type="installed_plugins"] > .spbct-safe-extension-badge-description[data-type="installed_plugins"],
220+
.spbct-safe-extension-badge-description[data-type="installed_plugins"]:hover {
221+
display: block;
222+
}
223+
/*Description popup behavior for search*/
224+
.spbct-safe-extension-badge[data-type="before_install"]:hover + .spbct-safe-extension-badge-description-placeholder[data-type="before_install"] > .spbct-safe-extension-badge-description[data-type="before_install"],
225+
.spbct-safe-extension-badge-description[data-type="before_install"]:hover {
226+
display: block;
227+
}
228+
229+
@media screen and (max-width: 600px) {
230+
.spbct-safe-extension-badge-description[data-type="installed_plugins"]
231+
{
232+
min-width: unset;
233+
width: unset;
234+
}
235+
}
236+
237+
/*Description popup animation rules*/
177238
@keyframes fadeInFromNone {
178239
0% {
179240
display: none;
@@ -188,22 +249,7 @@ span.green_dot{
188249
opacity: 1;
189250
}
190251
}
191-
.spbct-safe-extension-badge-description:before {
192-
content: '';
193-
position: absolute;
194-
top: -10px;
195-
right: 6px;
196-
border: 5px solid transparent;
197-
border-bottom: 5px solid rgba(0, 0, 0, 0.5);
198-
}
199-
.spbct-safe-extension-badge:hover + .spbct-safe-extension-badge-description-placeholder > .spbct-safe-extension-badge-description,
200-
.spbct-safe-extension-badge-description:hover{
201-
display: block;
202-
}
203-
.spbct-safe-extension-badge-description > a {
204-
color: white;
205-
text-decoration: underline;
206-
}
252+
207253

208254
#menu-settings {
209255
position: relative;

inc/spbc-admin.php

Lines changed: 24 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -305,46 +305,39 @@ function spbc_plugin_list_show_vulnerability($plugin_file, $plugin_data, $_statu
305305

306306
if (isset($spbc->settings['vulnerability_check__show_reports']) && $spbc->settings['vulnerability_check__show_reports'] == true) {
307307
add_filter('plugins_api_result', 'spbc_plugin_install_show_safety', 10, 3);
308-
add_filter('plugin_row_meta', 'spbc_plugin_list_show_safety', 10, 3);
308+
add_action('current_screen', 'spbc_plugin_list_add_psc_badge_buffer_handler', 1);
309309
}
310310

311311
/**
312-
* Show safety link for plugins
313-
* @param array $links
314-
* @param string $file
315-
* @param array $plugin_data
316-
* @return array
317-
* @psalm-suppress UnusedParam
312+
* Hook handler. Run buffer intercept to add PSC badges for any safe plugin.
313+
* @param \WP_Screen $screen current_screen hook arg
314+
* @return void
318315
*/
319-
function spbc_plugin_list_show_safety($links, $file, $plugin_data)
316+
function spbc_plugin_list_add_psc_badge_buffer_handler($screen)
320317
{
321-
global $spbc;
322-
323-
if (!isset($plugin_data, $plugin_data['slug'], $plugin_data['Version'])) {
324-
return $links;
318+
// exit if screen is not of plugins
319+
if (!$screen || $screen->id !== 'plugins') {
320+
return;
325321
}
326322

327-
$slug = $plugin_data['slug'];
328-
$version = $plugin_data['Version'];
329-
330-
$report = VulnerabilityAlarmService::getItemReportStatic($slug, $version, true, false);
331-
332-
$do_show = (
333-
isset($spbc->settings['vulnerability_check__show_reports']) &&
334-
$spbc->settings['vulnerability_check__show_reports'] == true
335-
);
336-
337-
if ($do_show && isset($report, $report->psc, $report->id, $slug)) {
338-
$links[] = sprintf(
339-
'<a href="https://research.cleantalk.org/reports/app/%s#%s" target="_blank" title="%s">%s</a>',
340-
$slug,
341-
$report->id,
342-
$report->psc,
343-
__('Security certified plugin', 'security-malware-firewall')
344-
);
323+
// exit if no PSC safe plugins found
324+
$safe_plugins_data = VulnerabilityAlarm::getSafePlugins(get_plugins(), false);
325+
if (empty($safe_plugins_data)) {
326+
return;
345327
}
346328

347-
return $links;
329+
// start buffering
330+
ob_start(function ($html) use ($safe_plugins_data) {
331+
$handler_result = VulnerabilityAlarmView::addPSCBadgeToInstalledPluginsList($html, $safe_plugins_data);
332+
if (
333+
is_array($handler_result) &&
334+
empty($handler_result['error']) &&
335+
!empty($handler_result['html'])
336+
) {
337+
$html = $handler_result['html'];
338+
}
339+
return $html;
340+
});
348341
}
349342

350343
function spbc_plugin_install_show_safety($res, $action, $_args)

lib/CleantalkSP/Common/Scanner/HeuristicAnalyser/Modules/Strings.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ public function convertFileGetContentsToString($current_file_path)
146146
}
147147
}
148148

149-
if ( $path && file_exists($path) ) {
149+
if ( $path && file_exists($path) && is_file($path) ) {
150150
// Delete tokens which contained the file_get_contents expression
151151
for ( $i = $start_position; $i <= $closing_bracket_position; $i++ ) {
152152
$this->tokens->unsetTokens($i);
Lines changed: 16 additions & 0 deletions
Loading
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<div class="spbct-safe-extension-badge" data-tooltip="SPBCT safe plugin" data-type="installed_plugins">
2+
&nbsp;
3+
<img src="{{ASSETS_URL}}/approved_psc_small.svg" alt="Approved"/>
4+
<div class="spbct-safe-extension-badge-description-placeholder" data-type="installed_plugins">
5+
<div class="spbct-safe-extension-badge-description" data-type="installed_plugins">
6+
{{DESCRIPTION}}
7+
<br>
8+
{{MORE_DETAILS_LINK}}
9+
</div>
10+
</div>
11+
</div>

lib/CleantalkSP/SpbctWP/VulnerabilityAlarm/View/PluginIsSafePSCBadge.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
<div class="spbct-safe-extension-badge" data-tooltip="SPBCT safe plugin">
1+
<div class="spbct-safe-extension-badge" data-tooltip="SPBCT safe plugin" data-type="before_install">
22
<img src="{{ASSETS_URL}}/approved_psc.svg" alt="Approved"/>
33
</div>
4-
<div class="spbct-safe-extension-badge-description-placeholder">
5-
<div class="spbct-safe-extension-badge-description">
4+
<div class="spbct-safe-extension-badge-description-placeholder" data-type="before_install">
5+
<div class="spbct-safe-extension-badge-description" data-type="before_install">
66
{{DESCRIPTION}}
77
<br>
88
{{MORE_DETAILS_LINK}}

lib/CleantalkSP/SpbctWP/VulnerabilityAlarm/VulnerabilityAlarm.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,10 @@ public static function sendReport()
5151
* @param string $research_url
5252
* @return string|null
5353
*/
54-
public static function showSafeBadge($module_type = 'plugin', $plugin_slug = '', $plugin_id = '', $psc_cert_name = '', $research_url = '')
54+
public static function showSafeBadge($module_type = 'plugin', $plugin_slug = '', $plugin_id = '', $psc_cert_name = '', $research_url = '', $placed_on_installed_list = false)
5555
{
5656
if ( ! empty($psc_cert_name) ) {
57-
return VulnerabilityAlarmView::showSafeBadgePSC($module_type, $plugin_slug, $plugin_id, $psc_cert_name, $research_url);
57+
return VulnerabilityAlarmView::showSafeBadgePSC($module_type, $plugin_slug, $plugin_id, $psc_cert_name, $research_url, $placed_on_installed_list);
5858
}
5959
return null;
6060
}

0 commit comments

Comments
 (0)