/**
  * Display PHPIDS Intrusions
  *
  * @return void
  */
 public function intrusions()
 {
     global $wpdb;
     // Current page number, items per page
     $per_page = HMWP_MS_Utils::hmwp_ms_intrusions_per_page();
     $pagenum = isset($_GET['paged']) ? absint($_GET['paged']) : 0;
     if (empty($pagenum)) {
         $pagenum = 1;
     }
     // Offset, limit
     $limit = $per_page;
     $offset = $pagenum * $limit - $limit;
     $offset = $offset < 0 ? 0 : $offset;
     // Get results
     $search = isset($_GET['intrusions_search']) ? stripslashes($_GET['intrusions_search']) : '';
     $search_title = '';
     if ($search) {
         $search_title = sprintf('<span class="subtitle">' . __('Search results for &#8220;%s&#8221;', 'mute-screamer') . '</span>', esc_html($search));
         $token = '%' . $search . '%';
         $sql = $wpdb->prepare('SELECT SQL_CALC_FOUND_ROWS * FROM ' . $wpdb->hmwp_ms_intrusions . ' WHERE (name LIKE %s OR page LIKE %s OR user_id LIKE %s OR ip LIKE %s OR total_impact LIKE %s) ORDER BY created DESC LIMIT %d, %d', $token, $token, $token, $token, $token, $offset, $limit);
     } else {
         $sql = $wpdb->prepare('SELECT SQL_CALC_FOUND_ROWS * FROM ' . $wpdb->hmwp_ms_intrusions . ' ORDER BY created DESC LIMIT %d, %d', $offset, $limit);
     }
     $intrusions = $wpdb->get_results($sql);
     $total_intrusions = $wpdb->get_var('SELECT FOUND_ROWS();');
     // Construct pagination links
     $num_pages = ceil($total_intrusions / $per_page);
     $pagination = HMWP_MS_Utils::pagination($pagenum, $num_pages, $per_page, $total_intrusions);
     // Columns
     $columns = array('name' => __('Name', 'mute-screamer'), 'value' => __('Value', 'mute-screamer'), 'page' => __('Page', 'mute-screamer'), 'impact' => __('Impact / Total', 'mute-screamer'), 'ip' => __('IP / User', 'mute-screamer'), 'date' => __('Date', 'mute-screamer'));
     $columns = apply_filters('hmwp_ms_admin_intrusions_columns', $columns);
     // Was something deleted?
     $deleted = isset($_GET['deleted']) ? (int) $_GET['deleted'] : 0;
     // Was something excluded?
     $excluded = isset($_GET['excluded']) ? (int) $_GET['excluded'] : 0;
     $all_deleted = isset($_GET['all_deleted']) ? (int) $_GET['all_deleted'] : 0;
     //hassan
     $data['message'] = false;
     $data['intrusions'] = $intrusions;
     $data['style'] = '';
     $data['columns'] = $columns;
     $data['page'] = $_GET['page'];
     $data['pagination'] = $pagination;
     $data['intrusions_search'] = $search;
     $data['search_title'] = $search_title;
     $data['time_offset'] = get_option('gmt_offset') * 3600;
     $data['date_format'] = get_option('date_format');
     $data['time_format'] = get_option('time_format');
     if ($deleted) {
         $data['message'] = sprintf(_n('Item permanently deleted.', '%s items permanently deleted.', $deleted, 'mute-screamer'), number_format_i18n($deleted));
     }
     if ($excluded) {
         $data['message'] = sprintf(_n('Item added to the exceptions list.', '%s items added to the exceptions list.', $excluded, 'mute-screamer'), number_format_i18n($excluded));
     }
     if ($all_deleted) {
         $data['message'] = __('All logs have been deleted!', 'mute-screamer');
     }
     HMWP_MS_Utils::view('admin_intrusions', $data);
 }
 /**
  * Display diff of files to be upgraded
  *
  * @return void
  */
 public function do_upgrade_diff()
 {
     $diff_files = array();
     if (!current_user_can('update_plugins')) {
         wp_die(__('You do not have sufficient permissions to update Mute Screamer for this site.', 'mute-screamer'));
     }
     check_admin_referer('upgrade-core');
     $files = (array) HMWP_MS_Utils::post('checked');
     // Valid files to upgrade?
     foreach ($files as $file) {
         if (!isset($this->updates['updates'][$file])) {
             continue;
         }
         // Get local file
         $local = HMWP_MS_PATH . '/libraries/IDS/' . $file;
         if (!file_exists($local)) {
             wp_die(new WP_Error('hmwp_ms_upgrade_file_missing', sprintf(__('%s does not exist.', 'mute-screamer'), esc_html($file))));
         }
         if (!@is_readable($local)) {
             wp_die(new WP_Error('hmwp_ms_upgrade_file_read_error', sprintf(__('Can not read file %s.', 'mute-screamer'), esc_html($file))));
         }
         $local = file_get_contents($local);
         // Fetch remote file
         $remote = $this->remote_get($this->updates['updates'][$file]->revision_file_url);
         if ($remote['body'] == '') {
             wp_die(new WP_Error('hmwp_ms_upgrade_error', __('Could not connect to phpids.org, please try again later.', 'mute-screamer')));
         }
         $remote = $remote['body'];
         $diff_files[$file] = new stdClass();
         $diff_files[$file]->name = $file;
         $diff_files[$file]->diff = HMWP_MS_Utils::text_diff($local, $remote);
     }
     if (empty($diff_files)) {
         wp_redirect(admin_url('update-core.php'));
         exit;
     }
     $url = 'update.php?action=hmwp_ms_upgrade_run&files=' . urlencode(implode(',', $files));
     $url = wp_nonce_url($url, 'bulk-update-hmwp_ms');
     $this->admin_header(__('Update Mute Screamer', 'mute-screamer'));
     $data['url'] = $url;
     $data['diff_files'] = $diff_files;
     HMWP_MS_Utils::view('admin_update_diff', $data);
     include ABSPATH . 'wp-admin/admin-footer.php';
 }