Skip to content

Commit

Permalink
Docs added. Travis fixed.
Browse files Browse the repository at this point in the history
  • Loading branch information
alexandergull committed Sep 8, 2023
1 parent 6e5f586 commit c2f1aeb
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 8 deletions.
12 changes: 12 additions & 0 deletions inc/spbc-admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -989,6 +989,12 @@ function spbc_admin__change_plugin_description($all_plugins)
return $all_plugins;
}


/**
* Add the statistics widget to the dashboard.
* @return void
* @psalm-suppress UndefinedFunction
*/
function spbc_dashboard_statistics_widget()
{
global $spbc;
Expand All @@ -1007,6 +1013,12 @@ function spbc_dashboard_statistics_widget()
}
}

/**
* Generate statistics widget output HTML.
* @param $_post
* @param $_callback_args
* @return void
*/
function spbc_dashboard_statistics_widget_output($_post, $_callback_args)
{
global $spbc, $current_user;
Expand Down
50 changes: 43 additions & 7 deletions inc/spbc-tools.php
Original file line number Diff line number Diff line change
Expand Up @@ -485,19 +485,27 @@ function spbc_get_custom_scanner_launch_data($first_start = false, $settings = a
);
}

/**
* Enqueue JS scripts, css and localization for widget.
* @return void
*/
function spbc_widget_scripts_init()
{
global $spbc;
wp_enqueue_script('spbc-widget-chart-js',
wp_enqueue_script(
'spbc-widget-chart-js',
SPBC_PATH . '/js/lib/chart/spbc-dashboard-widget--chartjs.min.js',
array('jquery'),
SPBC_VERSION,
false);
wp_enqueue_script('spbc-widget-dashboard',
false
);
wp_enqueue_script(
'spbc-widget-dashboard',
SPBC_PATH . '/js/spbc-dashboard-widget.min.js',
array('spbc-widget-chart-js'),
SPBC_VERSION,
false);
false
);
wp_enqueue_style(
'spbc_admin_css_widget_dashboard',
SPBC_PATH . '/css/spbc-dashboard-widget.min.css',
Expand All @@ -519,7 +527,12 @@ function spbc_widget_scripts_init()
));
}

function spbc_get_brief_data($direct_call = false)
/**
* Set brief data for widget to the State.
* @param bool $direct_call if direct call (from the frontend)
* @return void
*/
function spbc_set_brief_data($direct_call = false)
{
global $spbc;

Expand All @@ -544,7 +557,7 @@ function spbc_get_brief_data($direct_call = false)
? $spbc->data['brief_data']['last_actions']
: array();

$out_last_actions = spbc_get_brief_data_for_last_actions($current_last_actions);
$out_last_actions = spbc_update_brief_data_last_actions($current_last_actions);
$out_firewalls_data = spbc_get_brief_data_for_firewalls($current_fw_data, $current_bfp_data, $logs_scanned_ts);

//save data to state
Expand All @@ -557,7 +570,12 @@ function spbc_get_brief_data($direct_call = false)
$spbc->save('data');
}

function spbc_get_brief_data_for_last_actions($current_last_actions)
/**
* Update widget brief data for last actions
* @param array $current_last_actions before updated
* @return array updated last action
*/
function spbc_update_brief_data_last_actions($current_last_actions)
{
global $spbc;
/**
Expand Down Expand Up @@ -605,6 +623,19 @@ function spbc_get_brief_data_for_last_actions($current_last_actions)
return $current_last_actions;
}

/**
* Update widget brief data Firewall records.
* @param array $current_fw_data current firewall blocks data excluding BFP
* @param array $current_bfp_data current BFP blocks data
* @param array $logs_scanned_ts array of timestamps when the appropriate data scanned for changes last time,
* ['fw' => 0,'bfp' => 0]
* @return array array(
* 'fw_data' => [],
* 'bfp_data' => [],
* 'total_count',
* 'logs_scanned_ts' => ['fw' => 0,'bfp' => 0] ,
* );
*/
function spbc_get_brief_data_for_firewalls($current_fw_data, $current_bfp_data, $logs_scanned_ts)
{
$days_limit = SPBC_BRIEF_DATA_DAYS_LIMIT;
Expand Down Expand Up @@ -704,6 +735,11 @@ function spbc_get_brief_data_for_firewalls($current_fw_data, $current_bfp_data,
return $out_data;
}

/**
* Parse URL to find human-readable description.
* @param string $url
* @return array ['parsed_action' => '', 'add_time' => bool]
*/
function spbc_parse_action_from_admin_page_uri($url)
{
$out = array('parsed_action' => 'Unknown', 'add_time' => true);
Expand Down
2 changes: 1 addition & 1 deletion security-malware-firewall.php
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ function spbc_change_author_name($link, $_author_id, $_author_nicename)

// Getting dashboard widget statistics by click
if ( (int) Post::get('spbc_brief_refresh') === 1 ) {
spbc_get_brief_data(true);
spbc_set_brief_data(true);
}

if ( $spbc->settings['wp__dashboard_widget__show'] ) {
Expand Down

0 comments on commit c2f1aeb

Please sign in to comment.