Skip to content

Commit

Permalink
Merge pull request #508 from WPWhiteSecurity/develop
Browse files Browse the repository at this point in the history
Release v4.0.1
  • Loading branch information
William Patton authored Feb 11, 2020
2 parents 8a07808 + 1963d77 commit fc2abeb
Show file tree
Hide file tree
Showing 13 changed files with 540 additions and 52 deletions.
59 changes: 48 additions & 11 deletions classes/AlertManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -433,27 +433,56 @@ public function Register( $info ) {
* Register a whole group of items.
*
* @param array $groups - An array with group name as the index and an array of group items as the value.
* Item values is an array of [type, code, description, message] respectively.
* Item values is an array of [type, code, description, message, object, event type] respectively.
*/
public function RegisterGroup( $groups ) {
foreach ( $groups as $name => $group ) {
foreach ( $group as $subname => $subgroup ) {
foreach ( $subgroup as $item ) {
if ( ! isset( $item[4] ) ) {
$item[4] = ''; // Set default event object.
}
// Check to see if this ground has any subgroups
if( $this->GetArrayDepth( $group ) > 1 ) {
foreach ( $subgroup as $item ) {
if ( ! isset( $item[4] ) ) {
$item[4] = ''; // Set default event object.
}

if ( ! isset( $item[5] ) ) {
$item[5] = ''; // Set default event type.
}

if ( ! isset( $item[5] ) ) {
$item[5] = ''; // Set default event type.
list( $type, $code, $desc, $mesg, $object, $event_type ) = $item;
$this->Register( array( $type, $code, $name, $subname, $desc, $mesg, $object, $event_type ) );
}
// If no subgroups are found, process them accordingly.
} else {
foreach ( $group as $item ) {
if ( ! isset( $item[4] ) ) {
$item[4] = ''; // Set default event object.
}

if ( ! isset( $item[5] ) ) {
$item[5] = ''; // Set default event type.
}

list( $type, $code, $desc, $mesg, $object, $event_type ) = $item;
$this->Register( array( $type, $code, $name, $subname, $desc, $mesg, $object, $event_type ) );
list( $type, $code, $desc, $mesg, $object, $event_type ) = $item;
$this->Register( array( $type, $code, $name, $subname, $desc, $mesg, $object, $event_type ) );
}
}
}
}
}

public function GetArrayDepth( $array ) {
$depth = 0;
$iteIte = new RecursiveIteratorIterator( new RecursiveArrayIterator( $array ) );

foreach ($iteIte as $ite) {
$d = $iteIte->getDepth();
$depth = $d > $depth ? $d : $depth;
}

return $depth;
}

/**
* Duplicate Event Notice
*
Expand Down Expand Up @@ -1187,7 +1216,7 @@ public function get_display_object_text( $object ) {
break;
}

return $display;
return apply_filters( 'wsal_event_object_text', $display, $object );
}

/**
Expand Down Expand Up @@ -1223,6 +1252,8 @@ public function get_event_type_data() {
'stopped' => __( 'Stopped', 'wp-security-audit-log' ),
'removed' => __( 'Removed', 'wp-security-audit-log' ),
'unblocked' => __( 'Unblocked', 'wp-security-audit-log' ),
'renamed' => __( 'Renamed', 'wp-security-audit-log' ),
'duplicated' => __( 'Duplicated', 'wp-security-audit-log' ),
);
// sort the types alphabetically.
asort( $types );
Expand Down Expand Up @@ -1320,11 +1351,17 @@ public function get_display_event_type_text( $event_type ) {
case 'unblocked':
$display = __( 'Unblocked', 'wp-security-audit-log' );
break;
case 'renamed':
$display = __( 'Renamed', 'wp-security-audit-log' );
break;
case 'duplicated':
$display = __( 'Duplicated', 'wp-security-audit-log' );
break;
default:
break;
}

return $display;
return apply_filters( 'wsal_event_type_text', $display, $event_type );
}

/**
Expand Down
1 change: 1 addition & 0 deletions classes/Sensors/Content.php
Original file line number Diff line number Diff line change
Expand Up @@ -541,6 +541,7 @@ public function event_update_term_data( $data, $term_id, $taxonomy, $args ) {
'old_name' => $old_name,
'new_name' => $new_name,
'TagLink' => $term_link,
'Slug' => $new_slug,
)
);
}
Expand Down
11 changes: 9 additions & 2 deletions classes/Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -1748,7 +1748,12 @@ public function meta_formatter( $name, $value, $occ_id, $highlight ) {

case strncmp( $value, 'http://', 7 ) === 0:
case strncmp( $value, 'https://', 8 ) === 0:
return '<a href="' . esc_html( $value ) . '" title="' . esc_html( $value ) . '" target="_blank">' . esc_html( $value ) . '</a>';
$updated_line = apply_filters( 'wsal_link_filter', $value, $name );
if ( $updated_line !== $value ) {
return $updated_line;
} else {
return '<a href="' . esc_html( $value ) . '" title="' . esc_html( $value ) . '" target="_blank">' . esc_html( $value ) . '</a>';
}

case in_array( $name, array( '%PostStatus%', '%ProductStatus%' ), true ):
if ( ! empty( $value ) && 'publish' === $value ) {
Expand Down Expand Up @@ -1802,7 +1807,9 @@ public function meta_formatter( $name, $value, $occ_id, $highlight ) {
return $highlight_start_tag . dirname( $value ) . $highlight_end_tag;

default:
return $highlight_start_tag . esc_html( $value ) . $highlight_end_tag;
// if we didn't get a match already try get one via a filter.
$filtered_formatted_value = apply_filters( 'wsal_meta_formatter_custom_formatter', $value, $name );
return ( $value !== $filtered_formatted_value ) ? $filtered_formatted_value : $highlight_start_tag . esc_html( $value ) . $highlight_end_tag;
}
}

Expand Down
150 changes: 150 additions & 0 deletions classes/Utilities/PluginInstallAndActivate.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
<?php
/**
* Handler to install activate plugins.
*
* Provides the allowed plugins data as well as a render method to display the
* items inside of a table with install/actiavte buttons.
*
* @package Wsal
* @since 4.0.1
*/

if ( ! class_exists( 'WSAL_PluginInstallAndActivate' ) ) {

/**
* Class to handle checking plugin status and rendering data about any that
* are installable.
*
* @since 4.0.1
*/
class WSAL_PluginInstallAndActivate {

/**
* Checks if the plugin is already available/installed on the site.
*
* @method is_plugin_installed
* @since 4.0.1
* @param string $plugin_slug installed plugin slug.
* @return void|bool
*/
public function is_plugin_installed( $plugin_slug = '' ) {
// bail early if we don't have a slug to work with.
if ( empty( $plugin_slug ) ) {
return;
}

// check if the slug is in the installable list.
$is_allowed_slug = false;
$allowed_plugins = self::get_installable_plugins();
if ( is_array( $allowed_plugins ) ) {
foreach ( $allowed_plugins as $allowed_plugin ) {
// if we alredy found an allowed slug then break.
if ( true === $is_allowed_slug ) {
break;
}
$is_allowed_slug = ( isset( $allowed_plugin['plugin_slug'] ) && $allowed_plugin['plugin_slug'] === $plugin_slug ) ? true : false;
}
}

// bail early if this is not an allowed plugin slug.
if ( ! $is_allowed_slug ) {
return;
}

// get core plugin functions if they are not already in runtime.
if ( ! function_exists( 'get_plugins' ) ) {
require_once ABSPATH . 'wp-admin/includes/plugin.php';
}
$all_plugins = get_plugins();

if ( ! empty( $all_plugins[ $plugin_slug ] ) ) {
return true;
} else {
return false;
}
}


/**
* Renders a table containing info about each of the installable
* plugins and a button to install them.
*
* @method render
* @since 4.0.1
*/
public function render() {
$our_plugins = $this->get_installable_plugins();
?>
<table id="tab-third-party-plugins" class="form-table wp-list-table wsal-tab widefat fixed" style="display: table;" cellspacing="0">
<p class="description"><?php esc_html_e( 'WP Security Audit Log can keep a log of changes done on other plugins. Install the relevant add-on from the below list to keep a log of changes done on that plugin.', 'wp-security-audit-log' ); ?></p>
<tbody>
<tr>
<td class="addon-td">
<?php
// Create a nonce to pass through via data attr.
$nonce = wp_create_nonce( 'wsal-install-addon' );
// Loop through plugins and output.
foreach ( $our_plugins as $details ) {
$disable_button = '';
if ( is_plugin_active( $details['plugin_slug'] ) ) {
$disable_button = 'disabled';
}
?>

<div class="addon-wrapper">
<img src="<?php echo esc_url( trailingslashit( WSAL_BASE_URL ) . 'img/addons/' . $details['image_filename'] ); ?>">
<h4><?php esc_html_e( 'Add-on for ', 'wp-security-audit-log' ); ?><?php echo esc_html( $details['title'] ); ?></h4>
<p><?php echo sanitize_text_field( $details['plugin_description'] ); ?></p><br>
<p><button class="install-addon button button-primary <?php echo esc_attr( $disable_button ); ?>" data-nonce="<?php echo esc_attr( $nonce ); ?>" data-plugin-slug="<?php echo esc_attr( $details['plugin_slug'] ); ?>" data-plugin-download-url="<?php echo esc_url( $details['plugin_url'] ); ?>" data-plugin-event-tab-id="<?php echo esc_attr( $details['event_tab_id'] ); ?>">
<?php
if ( $this->is_plugin_installed( $details['plugin_slug'] ) && ! is_plugin_active( $details['plugin_slug'] ) ) {
esc_html_e( 'Add-on installed, activate now?', 'wp-security-audit-log' );
} elseif ( $this->is_plugin_installed( $details['plugin_slug'] ) && is_plugin_active( $details['plugin_slug'] ) ) {
esc_html_e( 'Add-on installed', 'wp-security-audit-log' );
} else {
esc_html_e( 'Install Add-on', 'wp-security-audit-log' );
}
?>
</button><span class="spinner" style="display: none; visibility: visible; float: none; margin: 0 0 0 8px;"></span></p>
</div>

<?php
}
?>
</td>
</tr>
</tbody>
</table>
<?php
}

/**
* Get a list of the data for the plugins that are allowable.
*
* @method get_installable_plugins
* @since 4.0.1
*/
public static function get_installable_plugins() {
$plugins = array(
// array(
// 'title' => 'BBPress Add-on',
// 'image_filename' => 'bbpress.png',
// 'plugin_slug' => 'wp-bootstrap-blocks/wp-bootstrap-blocks.php',
// 'plugin_url' => 'https://downloads.wordpress.org/plugin/wp-bootstrap-blocks.latest-stable.zip', // TODO: make this match live url.
// 'event_tab_id' => '#tab-bbpress-forums',
// ),
array(
'title' => 'WPForms',
'image_filename' => 'wpforms.png',
'plugin_slug' => 'wp-security-audit-log-add-on-for-wpforms/wsal-wpforms.php',
'plugin_url' => 'https://downloads.wordpress.org/plugin/wp-security-audit-log-add-on-for-wpforms.latest-stable.zip',
'event_tab_id' => '#tab-wpforms',
'plugin_description' => 'Keep a record of when someone adds, modified or delete forms, entries and more in the WPForms plugin.',
),
);
// runs through a filter so it can be added to programatically.
// NOTE: this means when using we need to test it's still an array.
return apply_filters( 'wsal_filter_installable_plugins', $plugins );
}
}
}
Loading

0 comments on commit fc2abeb

Please sign in to comment.