X7ROOT File Manager
Current Path:
/home/iptvzxij/public_html/wp-content/plugins/wp-statistics/includes
home
/
iptvzxij
/
public_html
/
wp-content
/
plugins
/
wp-statistics
/
includes
/
📁
..
📁
admin
📁
api
📄
class-wp-statistics-admin-bar.php
(9.23 KB)
📄
class-wp-statistics-country.php
(4.1 KB)
📄
class-wp-statistics-db.php
(7.73 KB)
📄
class-wp-statistics-exclusion.php
(15.38 KB)
📄
class-wp-statistics-frontend.php
(5.5 KB)
📄
class-wp-statistics-geoip.php
(2.41 KB)
📄
class-wp-statistics-helper.php
(81.85 KB)
📄
class-wp-statistics-historical.php
(1.49 KB)
📄
class-wp-statistics-hits.php
(5.55 KB)
📄
class-wp-statistics-install.php
(19.51 KB)
📄
class-wp-statistics-ip.php
(14.32 KB)
📄
class-wp-statistics-mail.php
(9.67 KB)
📄
class-wp-statistics-menus.php
(8.76 KB)
📄
class-wp-statistics-meta-box.php
(1.42 KB)
📄
class-wp-statistics-option.php
(11.46 KB)
📄
class-wp-statistics-pages.php
(21.99 KB)
📄
class-wp-statistics-privacy-erasers.php
(1.13 KB)
📄
class-wp-statistics-privacy-exporter.php
(1.59 KB)
📄
class-wp-statistics-purge.php
(9.14 KB)
📄
class-wp-statistics-referred.php
(8.86 KB)
📄
class-wp-statistics-rest-api.php
(2.68 KB)
📄
class-wp-statistics-schedule.php
(12.56 KB)
📄
class-wp-statistics-search-engine.php
(2.71 KB)
📄
class-wp-statistics-shortcode.php
(12.71 KB)
📄
class-wp-statistics-timezone.php
(12.43 KB)
📄
class-wp-statistics-uninstall.php
(3.52 KB)
📄
class-wp-statistics-user-agent.php
(1.38 KB)
📄
class-wp-statistics-user-online.php
(3.71 KB)
📄
class-wp-statistics-user.php
(9.93 KB)
📄
class-wp-statistics-visitor.php
(17.29 KB)
📄
class-wp-statistics-widget.php
(23.48 KB)
📄
class-wp-statistics.php
(14.07 KB)
📁
defines
📄
defines.php
(509 B)
📁
libraries
📄
template-functions.php
(27.58 KB)
Editing: class-wp-statistics-purge.php
<?php namespace WP_STATISTICS; class Purge { public static function purge_data($purge_days) { global $wpdb; // Table Name $historical_table = DB::table('historical'); // If it's less than 30 days, don't do anything. if ($purge_days >= apply_filters('wp_statistics_schedule_db_maint_days', 30)) { /** * Store visits data. */ $table_name = DB::table('visitor'); $date_string = TimeZone::getCurrentDate('Y-m-d', '-' . $purge_days); // Get sum of visits $result = $wpdb->get_var($wpdb->prepare("SELECT SUM(hits) FROM {$table_name} WHERE `last_counter` < %s", $date_string)); if ($result) { // Update the historical count with what we purged. $historical_result = $wpdb->query($wpdb->prepare("UPDATE {$historical_table} SET value = value + %d WHERE `category` = 'visits'", intval($result))); // Insert if ($historical_result == 0) { $insert = $wpdb->insert( DB::table('historical'), array( 'value' => $result, 'category' => 'visits', 'page_id' => -2, 'uri' => '-2', ) ); if (!$insert) { if (!empty($wpdb->last_error)) { \WP_Statistics::log($wpdb->last_error, 'warning'); } } } $result_string = sprintf(__('Data from %1$s Older Than %2$s Days Successfully Purged.', 'wp-statistics'), '<code>' . $table_name . '</code>', '<code>' . $purge_days . '</code>'); } else { $result_string = sprintf(__('No Records to Purge from %s!', 'wp-statistics'), '<code>' . $table_name . '</code>'); } /** * Purge the visitors data. */ $table_name = DB::table('visitor'); $result = $wpdb->query($wpdb->prepare("DELETE FROM {$table_name} WHERE `last_counter` < %s", $date_string)); if ($result) { // Update the historical count with what we purged. $historical_result = $wpdb->query($wpdb->prepare("UPDATE {$historical_table} SET value = value + %d WHERE `category` = 'visitors'", $result)); if ($historical_result == 0) { $insert = $wpdb->insert( DB::table('historical'), array( 'value' => $result, 'category' => 'visitors', 'page_id' => -1, 'uri' => '-1', ) ); if (!$insert) { if (!empty($wpdb->last_error)) { \WP_Statistics::log($wpdb->last_error, 'warning'); } } } // Delete relationship record $table_name = DB::table('visitor_relationships'); $wpdb->query($wpdb->prepare("DELETE FROM {$table_name} WHERE `date` < %s", $date_string)); $result_string .= '<br>' . sprintf(__('Data from %1$s Older Than %2$s Days Successfully Purged.', 'wp-statistics'), '<code>' . $table_name . '</code>', '<code>' . $purge_days . '</code>'); } else { $result_string .= '<br>' . sprintf(__('No Records to Purge from %s!', 'wp-statistics'), '<code>' . $table_name . '</code>'); } /** * Purge the exclusions data. */ $table_name = DB::table('exclusions'); $result = $wpdb->query($wpdb->prepare("DELETE FROM {$table_name} WHERE `date` < %s", $date_string)); if ($result) { $result_string .= '<br>' . sprintf(__('Data from %1$s Older Than %2$s Days Successfully Purged.', 'wp-statistics'), '<code>' . $table_name . '</code>', '<code>' . $purge_days . '</code>'); } else { $result_string .= '<br>' . sprintf(__('No Records to Purge from %s!', 'wp-statistics'), '<code>' . $table_name . '</code>'); } /** * Purge the pages data, this is more complex as we want to save the historical data per page. */ $table_name = DB::table('pages'); $historical = 0; // The first thing we need to do is update the historical data by finding all the unique pages. $result = $wpdb->get_results( $wpdb->prepare("SELECT DISTINCT uri FROM {$table_name} WHERE `date` < %s", $date_string) ); // If we have a result, let's store the historical data. if ($result) { // Loop through all the unique rows that were returned. foreach ($result as $row) { // Use the unique rows to get a total count from the database of all the data from the given URIs/Pageids that we're going to delete later. $historical = $wpdb->get_var( $wpdb->prepare( "SELECT sum(count) FROM {$table_name} WHERE `uri` = %s AND `date` < %s", $row->uri, $date_string ) ); // Do an update of the historical data. $uresult = $wpdb->query( $wpdb->prepare( "UPDATE {$historical_table} SET `value` = value + %d WHERE `uri` = %s AND `category` = 'uri'", $historical, $row->uri ) ); // If we failed it's because this is the first time we've seen this URI/pageid so let's create a historical row for it. if ($uresult == 0) { $insert = $wpdb->insert( DB::table('historical'), array( 'value' => $historical, 'category' => 'uri', 'uri' => $row->uri, 'page_id' => Pages::uri_to_id($row->uri), ) ); if (!$insert) { if (!empty($wpdb->last_error)) { \WP_Statistics::log($wpdb->last_error, 'warning'); } } } } } /** * Now that we've done all of the required historical data storage, we can actually delete the data from the database. */ $result = $wpdb->query($wpdb->prepare("DELETE FROM {$table_name} WHERE `date` < %s", $date_string)); if ($result) { $result_string .= '<br>' . sprintf(__('Data from %1$s Older Than %2$s Days Successfully Purged.', 'wp-statistics'), '<code>' . $table_name . '</code>', '<code>' . $purge_days . '</code>'); } else { $result_string .= '<br>' . sprintf(__('No Records to Purge from %s!', 'wp-statistics'), '<code>' . $table_name . '</code>'); } return $result_string; } else { return __('Please select a value over 30 days.', 'wp-statistics'); } } public static function purge_visitor_hits($purge_hits) { global $wpdb; $visitor_table = DB::table('visitor'); // If it's less than 10 hits, don't do anything. if ($purge_hits > 9) { // Purge the visitor's with more than the defined hits. $result = $wpdb->get_results( $wpdb->prepare("SELECT * FROM {$visitor_table} WHERE `hits` > %s", $purge_hits) ); $to_delete = array(); // Loop through the results and store the requried information in an array. We don't just process it now as deleting // the rows from the visitor table will mess up the results from our first query. foreach ($result as $row) { $to_delete[] = array($row->ID, $row->last_counter, $row->hits); } if (count($to_delete) > 0) { foreach ($to_delete as $item) { $wpdb->query( $wpdb->prepare("DELETE FROM {$visitor_table} WHERE `id` = %s;", $item[0]) ); } $result_string = sprintf( __('%s Records Successfully Purged.', 'wp-statistics'), '<code>' . count($to_delete) . '</code>' ); } else { $result_string = __('No Visitor Records Found for Purging.', 'wp-statistics'); } } else { $result_string = __('Number of views must be greater than or equal to 10!', 'wp-statistics'); } return $result_string; } }
Upload File
Create Folder