Skip to content
Open
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 @@ -79,6 +79,10 @@ For the [tsmap] shortcode:
If this parameter is given, all user tracks that have not been updated in the
last X amount of time, will not be displayed. The value is a time expression in
the form of a number and a unit, for example: '120s', '30m', '2h', '3d'.
* **delay**: the delay of a live track for its locations to appear on the map.
If this parameter is given, all user tracks only show their data up to a point
in time X amount ago. The value is a time expression in
the form of a number and a unit, for example: '120s', '30m', '2h', '3d'.
* **width**: map width, default: 100%.
* **height**: map height, default: 480px.
* **align**: 'left', 'center' or 'right', default: not set.
Expand Down
29 changes: 21 additions & 8 deletions class-trackserver-shortcode.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ public function handle_shortcode1( $atts ) {
'points' => false,
'zoom' => false,
'maxage' => false,
'delay' => false,
);

$atts = shortcode_atts( $defaults, $atts, $this->shortcode1 );
Expand Down Expand Up @@ -117,7 +118,8 @@ public function handle_shortcode1( $atts ) {
$points = $this->get_points( $atts, false ); // result is not used
$markers = $this->get_markers( $atts, false ); // result is not used
$markersize = $this->get_markersize( $atts, false ); // result is not used
$maxage = $this->get_maxage( $atts['maxage'] );
$maxage = $this->get_seconds( $atts['maxage'] );
$delay = $this->get_seconds( $atts['delay'] );

list( $validated_track_ids, $validated_user_ids ) = $this->validate_ids( $atts );

Expand All @@ -144,7 +146,7 @@ public function handle_shortcode1( $atts ) {
$query = base64_encode( $query );
$query_nonce = wp_create_nonce( 'gettrack_' . $query . '_p' . $post_id );
$alltracks_url = $gettrack_url_prefix . '?query=' . rawurlencode( $query ) . "&p=$post_id&format=" .
$this->trackserver->track_format . "&maxage=$maxage&_wpnonce=$query_nonce";
$this->trackserver->track_format . "&maxage=$maxage&delay=$delay&_wpnonce=$query_nonce";
$following = false;

//foreach ( $validated_track_ids as $validated_id ) {
Expand Down Expand Up @@ -189,7 +191,7 @@ public function handle_shortcode1( $atts ) {
$trk['track_type'] = 'polylinexhr';
}
$trk['track_url'] = $gettrack_url_prefix . '?id=' . $validated_id . "&p=$post_id&format=" .
$this->trackserver->track_format . "&maxage=$maxage&_wpnonce=$nonce";
$this->trackserver->track_format . "&maxage=$maxage&delay=$delay&_wpnonce=$nonce";
}

$tracks[] = $trk;
Expand Down Expand Up @@ -327,6 +329,7 @@ public function handle_shortcode3( $atts, $content = '' ) {
'user' => false,
'format' => 'gpx',
'maxage' => false,
'delay' => false,
'href_only' => false,
);

Expand All @@ -343,7 +346,8 @@ public function handle_shortcode3( $atts, $content = '' ) {
$atts['track'] = $atts['id'];
}

$maxage = $this->get_maxage( $atts['maxage'] );
$maxage = $this->get_seconds( $atts['maxage'] );
$delay = $this->get_seconds( $atts['delay'] );

list( $validated_track_ids, $validated_user_ids ) = $this->validate_ids( $atts );

Expand All @@ -364,7 +368,7 @@ public function handle_shortcode3( $atts, $content = '' ) {
);
$query = base64_encode( $query );
$query_nonce = wp_create_nonce( 'gettrack_' . $query . '_p' . $post_id );
$alltracks_url = get_home_url( null, $this->trackserver->url_prefix . '/' . $this->trackserver->options['gettrack_slug'] . '/?query=' . rawurlencode( $query ) . "&p=$post_id&format=$track_format&maxage=$maxage&_wpnonce=$query_nonce" );
$alltracks_url = get_home_url( null, $this->trackserver->url_prefix . '/' . $this->trackserver->options['gettrack_slug'] . '/?query=' . rawurlencode( $query ) . "&p=$post_id&format=$track_format&maxage=$maxage&delay=$delay&_wpnonce=$query_nonce" );

$text = $atts['text'] . $content;
if ( $text === '' ) {
Expand Down Expand Up @@ -521,13 +525,13 @@ private function get_markersize( $atts = false, $shift = true ) {
}

/**
* Return maxage in seconds for a time expression
* Return seconds for a time expression
*
* Takes an expression like 120s, 5m, 3h, 7d and turns it into seconds. No unit equals seconds.
*
* @since 3.1
*/
private function get_maxage( $str ) {
private function get_seconds( $str ) {
if ( $str === false ) {
return 0;
}
Expand Down Expand Up @@ -642,6 +646,7 @@ private function handle_gettrack_query() {

$query_string = stripslashes( $_REQUEST['query'] );
$maxage = ( isset( $_REQUEST['maxage'] ) ? (int) $_REQUEST['maxage'] : 0 );
$delay = ( isset( $_REQUEST['delay'] ) ? (int) $_REQUEST['delay'] : 0 );
$post_id = ( isset( $_REQUEST['p'] ) ? intval( $_REQUEST['p'] ) : 0 );
$format = $_REQUEST['format'];
$is_admin = array_key_exists( 'admin', $_REQUEST ) ? true : false;
Expand Down Expand Up @@ -676,7 +681,15 @@ private function handle_gettrack_query() {
// @codingStandardsIgnoreStart
$sql_in = "('" . implode( "','", $track_ids ) . "')";
$sql = 'SELECT trip_id, latitude, longitude, altitude, speed, occurred, t.user_id, t.name, t.distance, t.comment FROM ' . $this->trackserver->tbl_locations .
' l INNER JOIN ' . $this->trackserver->tbl_tracks . ' t ON l.trip_id = t.id WHERE trip_id IN ' . $sql_in . ' AND l.hidden = 0 ORDER BY trip_id, occurred';
' l INNER JOIN ' . $this->trackserver->tbl_tracks . ' t ON l.trip_id = t.id WHERE trip_id IN ' . $sql_in . ' AND l.hidden = 0';

if ( $delay > 0 ) {
$ts = gmdate( 'Y-m-d H:i:s', ( time() + ( get_option( 'gmt_offset' ) * HOUR_IN_SECONDS ) - $delay ) );
$sql .= " AND l.occurred < '$ts' ";
}

$sql .= " ORDER BY trip_id, occurred";

$res = $wpdb->get_results( $sql, ARRAY_A );
// @codingStandardsIgnoreEnd

Expand Down
1 change: 1 addition & 0 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ For the [tsmap] shortcode:
* user: one or more user IDs, separated by commas, who's latest track to follow 'live'. A literal '@' means the author of the post (you). When viewing the map, the liveupdate feature will follow the track of the first user specified. When the end-marker is enabled for a live track (and why shouldn't it?), clicking it will change the focus of the liveupdate to that track. The map view will follow the latest location and the infobar (if present) will display its information.
* live: true (or 't', 'yes' or 'y'), or false (default), to force live tracking for this map. This can be used for example with an externally updated GPX or KML file.
* maxage: the maximum age of a live track for it to be included on the map. If this parameter is given, all user tracks that have not been updated in the last X amount of time, will not be displayed. The value is a time expression in the form of a number and a unit, for example: '120s', '30m', '2h', '3d'.
* delay: the delay of a live track for its locations to appear on the map. If this parameter is given, all user tracks only show their data up to a point in time X amount ago. The value is a time expression in the form of a number and a unit, for example: '120s', '30m', '2h', '3d'.
* width: map width, default: 100%.
* height: map height, default: 480px.
* align: 'left', 'center' or 'right', default: not set.
Expand Down
2 changes: 1 addition & 1 deletion trackserver.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
define( 'TRACKSERVER_PLUGIN_DIR', plugin_dir_path( __FILE__ ) );
define( 'TRACKSERVER_PLUGIN_URL', plugin_dir_url( __FILE__ ) );
define( 'TRACKSERVER_JSLIB', TRACKSERVER_PLUGIN_URL . 'lib/' );
define( 'TRACKSERVER_VERSION', '4.3-20190906' );
define( 'TRACKSERVER_VERSION', '5.0.2-20230305' );

require_once( TRACKSERVER_PLUGIN_DIR . 'class-trackserver.php' );

Expand Down