Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
frankiejarrett committed Mar 29, 2014
2 parents 0993466 + e74592f commit ea0c0a7
Show file tree
Hide file tree
Showing 6 changed files with 88 additions and 52 deletions.
30 changes: 16 additions & 14 deletions includes/admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public static function load() {
add_action( 'wp_ajax_wp_stream_uninstall', array( __CLASS__, 'uninstall_plugin' ) );

// Auto purge setup
add_action( 'init', array( __CLASS__, 'purge_schedule_setup' ) );
add_action( 'wp', array( __CLASS__, 'purge_schedule_setup' ) );
add_action( 'wp_stream_auto_purge', array( __CLASS__, 'purge_scheduled_action' ) );

// Admin notices
Expand Down Expand Up @@ -171,6 +171,7 @@ public static function admin_enqueue_scripts( $hook ) {
'confirm_purge' => __( 'Are you sure you want to delete all Stream activity records from the database? This cannot be undone.', 'stream' ),
'confirm_uninstall' => __( 'Are you sure you want to uninstall and deactivate Stream? This will delete all Stream tables from the database and cannot be undone.', 'stream' ),
),
'gmt_offset' => get_option( 'gmt_offset' ),
'current_screen' => $hook,
'current_page' => isset( $_GET['paged'] ) ? esc_js( $_GET['paged'] ) : '1',
'current_order' => isset( $_GET['order'] ) ? esc_js( $_GET['order'] ) : 'desc',
Expand Down Expand Up @@ -416,30 +417,31 @@ public static function uninstall_plugin(){
}

public static function purge_schedule_setup() {
if ( ! wp_next_scheduled( 'stream_auto_purge' ) ) {
wp_schedule_event( time(), 'daily', 'stream_auto_purge' );
if ( ! wp_next_scheduled( 'wp_stream_auto_purge' ) ) {
wp_schedule_event( time(), 'daily', 'wp_stream_auto_purge' );
}
}

public static function purge_scheduled_action() {
global $wpdb;

$days = WP_Stream_Settings::$options['general_records_ttl'];
$options = WP_Stream_Settings::get_options();

$days = $options['general_records_ttl'];
$date = new DateTime( 'now', $timezone = new DateTimeZone( 'UTC' ) );
$date->sub( DateInterval::createFromDateString( "$days days" ) );

$wpdb->query(
$wpdb->prepare(
"
DELETE t1, t2, t3
FROM {$wpdb->stream} as t1
INNER JOIN {$wpdb->streamcontext} as t2
INNER JOIN {$wpdb->streammeta} as t3
WHERE t1.type = 'stream'
AND t1.created < %s
AND t1.ID = t2.record_id
AND t1.ID = t3.record_id;
",
"DELETE `stream`, `context`, `meta`
FROM {$wpdb->stream} AS `stream`
LEFT JOIN {$wpdb->streamcontext} AS `context`
ON `context`.`record_id` = `stream`.`ID`
LEFT JOIN {$wpdb->streammeta} AS `meta`
ON `meta`.`record_id` = `stream`.`ID`
WHERE `stream`.`type` = %s
AND `stream`.`created` < %s;",
'stream',
$date->format( 'Y-m-d H:i:s' )
)
);
Expand Down
61 changes: 38 additions & 23 deletions includes/date-interval.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,67 +31,82 @@ public function __construct() {
* @return mixed|void
*/
public function get_predefined_intervals() {
$timezone = get_option( 'timezone_string' );

if ( empty( $timezone ) ) {
$gmt_offset = (int) get_option( 'gmt_offset' );
$timezone = timezone_name_from_abbr( null, $gmt_offset * 3600, true );
if ( false === $timezone ) {
$timezone = timezone_name_from_abbr( null, $gmt_offset * 3600, false );
}
if ( false === $timezone ) {
$timezone = null;
}
}

return apply_filters(
'wp_stream_predefined_date_intervals',
array(
'today' => array(
'label' => esc_html__( 'Today', 'stream' ),
'start' => Carbon::today(),
'start' => Carbon::today( $timezone )->startOfDay(),
'end' => Carbon::today( $timezone )->startOfDay(),
),
'yesterday' => array(
'label' => esc_html__( 'Yesterday', 'stream' ),
'start' => Carbon::today()->subDay(),
'end' => Carbon::today()->subSecond(),
'start' => Carbon::today( $timezone )->startOfDay()->subDay(),
'end' => Carbon::today( $timezone )->startOfDay()->subSecond(),
),
'last-7-days' => array(
'label' => sprintf( esc_html__( 'Last %d Days', 'stream' ), 7 ),
'start' => Carbon::today()->subDays( 7 ),
'end' => Carbon::today(),
'start' => Carbon::today( $timezone )->subDays( 7 ),
'end' => Carbon::today( $timezone ),
),
'last-14-days' => array(
'label' => sprintf( esc_html__( 'Last %d Days', 'stream' ), 14 ),
'start' => Carbon::today()->subDays( 14 ),
'end' => Carbon::today(),
'start' => Carbon::today( $timezone )->subDays( 14 ),
'end' => Carbon::today( $timezone ),
),
'last-30-days' => array(
'label' => sprintf( esc_html__( 'Last %d Days', 'stream' ), 30 ),
'start' => Carbon::today()->subDays( 30 ),
'end' => Carbon::today(),
'start' => Carbon::today( $timezone )->subDays( 30 ),
'end' => Carbon::today( $timezone ),
),
'this-month' => array(
'label' => esc_html__( 'This Month', 'stream' ),
'start' => Carbon::today()->day( 1 ),
'start' => Carbon::today( $timezone )->day( 1 ),
),
'last-month' => array(
'label' => esc_html__( 'Last Month', 'stream' ),
'start' => Carbon::today()->day( 1 )->subMonth(),
'end' => Carbon::today()->day( 1 )->subSecond(),
'start' => Carbon::today( $timezone )->day( 1 )->subMonth(),
'end' => Carbon::today( $timezone )->day( 1 )->subSecond(),
),
'last-3-months' => array(
'label' => sprintf( esc_html__( 'Last %d Months', 'stream' ), 3 ),
'start' => Carbon::today()->subMonths( 3 ),
'end' => Carbon::today(),
'start' => Carbon::today( $timezone )->subMonths( 3 ),
'end' => Carbon::today( $timezone ),
),
'last-6-months' => array(
'label' => sprintf( esc_html__( 'Last %d Months', 'stream' ), 6 ),
'start' => Carbon::today()->subMonths( 6 ),
'end' => Carbon::today(),
'start' => Carbon::today( $timezone )->subMonths( 6 ),
'end' => Carbon::today( $timezone ),
),
'last-12-months' => array(
'label' => sprintf( esc_html__( 'Last %d Months', 'stream' ), 12 ),
'start' => Carbon::today()->subMonths( 12 ),
'end' => Carbon::today(),
'start' => Carbon::today( $timezone )->subMonths( 12 ),
'end' => Carbon::today( $timezone ),
),
'this-year' => array(
'label' => esc_html__( 'This Year', 'stream' ),
'start' => Carbon::today()->day( 1 )->month( 1 ),
'start' => Carbon::today( $timezone )->day( 1 )->month( 1 ),
),
'last-year' => array(
'label' => esc_html__( 'Last Year', 'stream' ),
'start' => Carbon::today()->day( 1 )->month( 1 )->subYear(),
'end' => Carbon::today()->day( 1 )->month( 1 )->subSecond(),
)
)
'start' => Carbon::today( $timezone )->day( 1 )->month( 1 )->subYear(),
'end' => Carbon::today( $timezone )->day( 1 )->month( 1 )->subSecond(),
),
),
$timezone
);
}

Expand Down
1 change: 0 additions & 1 deletion includes/filters.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ class WP_Stream_Filter_Input {
FILTER_SANITIZE_NUMBER_FLOAT => 'floatval',
FILTER_SANITIZE_NUMBER_INT => 'intval',
FILTER_SANITIZE_SPECIAL_CHARS => 'htmlspecialchars',
FILTER_SANITIZE_FULL_SPECIAL_CHARS => 'htmlspecialchars',
FILTER_SANITIZE_STRING => 'sanitize_text_field',
FILTER_SANITIZE_URL => 'esc_url_raw',
// Other
Expand Down
25 changes: 13 additions & 12 deletions includes/settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,29 +26,30 @@ class WP_Stream_Settings {
*/
public static $fields = array();

/**
* Public constructor
*
* @return \WP_Stream_Settings
*/
public static function load() {

// Parse field information gathering default values
$defaults = self::get_defaults();

public static function get_options() {
/**
* Filter allows for modification of options
*
* @param array array of options
* @return array updated array of options
*/
self::$options = apply_filters(
return apply_filters(
'wp_stream_options',
wp_parse_args(
(array) get_option( self::KEY, array() ),
$defaults
self::get_defaults()
)
);
}

/**
* Public constructor
*
* @return \WP_Stream_Settings
*/
public static function load() {

self::$options = self::get_options();

// Register settings, and fields
add_action( 'admin_init', array( __CLASS__, 'register_settings' ) );
Expand Down
2 changes: 1 addition & 1 deletion tests/tests/test-admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public function test_constructor() {
array( 'admin_enqueue_scripts', self::CLASSNAME, 'admin_enqueue_scripts' ),
array( 'admin_enqueue_scripts', self::CLASSNAME, 'admin_menu_css' ),
array( 'wp_ajax_wp_stream_reset', self::CLASSNAME, 'wp_ajax_reset' ),
array( 'init', self::CLASSNAME, 'purge_schedule_setup' ),
array( 'wp', self::CLASSNAME, 'purge_schedule_setup' ),
array( 'wp_stream_auto_purge', self::CLASSNAME, 'purge_scheduled_action' ),
);

Expand Down
21 changes: 20 additions & 1 deletion ui/admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -440,9 +440,28 @@ jQuery(function($){

if ( jQuery.datepicker ) {

// Apply a GMT offset due to Date() using the visitor's local time
var siteGMTOffsetHours = parseFloat( wp_stream.gmt_offset );
var localGMTOffsetHours = new Date().getTimezoneOffset() / 60 * -1;
var totalGMTOffsetHours = siteGMTOffsetHours - localGMTOffsetHours;

var localTime = new Date();
var siteTime = new Date( localTime.getTime() + ( totalGMTOffsetHours * 60 * 60 * 1000 ) );
var dayOffset = '0';

// check if the site date is different from the local date, and set a day offset
if ( localTime.getDate() !== siteTime.getDate() || localTime.getMonth() !== siteTime.getMonth() ) {
if ( localTime.getTime() < siteTime.getTime() ) {
dayOffset = '+1d';
} else {
dayOffset = '-1d';
}
}

datepickers.datepicker({
dateFormat: 'yy/mm/dd',
maxDate: 0,
maxDate: dayOffset,
defaultDate: siteTime,
beforeShow: function() {
$(this).prop( 'disabled', true );
},
Expand Down

0 comments on commit ea0c0a7

Please sign in to comment.