Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use GMT timestamp for dynamic update #3

Merged
merged 1 commit into from
Nov 24, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ However the AJAX update will fetch the latest ticks and update cached tickers d

## Changelog

### 1.1.0 - unreleased

* Use GMT for automatic updates

### 1.0.0 - 2018-11-02

* Initial release
2 changes: 1 addition & 1 deletion includes/class-scliveticker-widget.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public function widget( $args, $instance ) {
echo ' sclt-widget-ajax" '
. 'data-sclt-ticker="' . esc_attr( $category ) . '" '
. 'data-sclt-limit="' . esc_attr( $count ) . '" '
. 'data-sclt-last="' . esc_attr( current_time( 'timestamp' ) );
. 'data-sclt-last="' . esc_attr( current_datetime()->getTimestamp() );
}
echo '">';

Expand Down
24 changes: 19 additions & 5 deletions includes/class-scliveticker.php
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ public static function shortcode_ticker_show( $atts ) {
$output .= ' sclt-ticker-ajax" '
. 'data-sclt-ticker="' . $ticker . '" '
. 'data-sclt-limit="' . $limit . '" '
. 'data-sclt-last="' . current_time( 'timestamp' );
. 'data-sclt-last="' . current_datetime()->getTimestamp();
}
$output .= '">';

Expand Down Expand Up @@ -317,7 +317,13 @@ public static function ajax_update() {
}

$limit = ( isset( $update_req['l'] ) ) ? intval( $update_req['l'] ) : - 1;
$last_poll = ( isset( $update_req['t'] ) ) ? intval( $update_req['t'] ) : 0;
$last_poll = explode(
',',
gmdate(
'Y,m,d,H,i,s',
( isset( $update_req['t'] ) ) ? intval( $update_req['t'] ) : 0
)
);

// Query new ticks from DB.
$query_args = array(
Expand All @@ -331,7 +337,15 @@ public static function ajax_update() {
),
),
'date_query' => array(
'after' => date( 'c', $last_poll ),
'column' => 'post_date_gmt',
'after' => array(
'year' => intval( $last_poll[0] ),
'month' => intval( $last_poll[1] ),
'day' => intval( $last_poll[2] ),
'hour' => intval( $last_poll[3] ),
'minute' => intval( $last_poll[4] ),
'second' => intval( $last_poll[5] ),
),
),
);

Expand All @@ -351,13 +365,13 @@ public static function ajax_update() {
$res[] = array(
'w' => $slug,
'h' => $out,
't' => current_time( 'timestamp' ),
't' => current_datetime()->getTimestamp(),
);
} else {
$res[] = array(
's' => $slug,
'h' => $out,
't' => current_time( 'timestamp' ),
't' => current_datetime()->getTimestamp(),
);
}
}
Expand Down