From 974c5d49879a617d9db9f949ffb9445c080343f8 Mon Sep 17 00:00:00 2001 From: John Barrett Date: Tue, 10 Oct 2023 18:03:03 +0200 Subject: [PATCH 01/10] Add new [tsprofile] function to allow the user's personal tracking url to be displayed on the the front end in the user's profile page. Also support added for user=@@ in [tsmap]. This will display the tracks for the currently logged in user. This allows a template page to be created that can be used by all users. Without this, all users would have needed their own personal page so they could be 'the author'. --- class-trackserver-shortcode.php | 36 +++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/class-trackserver-shortcode.php b/class-trackserver-shortcode.php index 0ff689e..5891170 100644 --- a/class-trackserver-shortcode.php +++ b/class-trackserver-shortcode.php @@ -13,6 +13,7 @@ class Trackserver_Shortcode { private $shortcode1 = 'tsmap'; private $shortcode2 = 'tsscripts'; private $shortcode3 = 'tslink'; + private $shortcode4 = 'tsprofile'; /** * Constructor. @@ -46,6 +47,7 @@ private function add_actions() { add_shortcode( $this->shortcode1, array( $this, 'handle_shortcode1' ) ); add_shortcode( $this->shortcode2, array( $this, 'handle_shortcode2' ) ); add_shortcode( $this->shortcode3, array( $this, 'handle_shortcode3' ) ); + add_shortcode( $this->shortcode4, array( $this, 'handle_shortcode4' ) ); } /** @@ -381,6 +383,32 @@ public function handle_shortcode3( $atts, $content = '' ) { return $out; } + /** + * Handle the [tsprofile] shortcode + * + * Handler for the 'tsprofile' shortcode. It returns profile information to allow a user to + * see the trackserver url they should use in their tracking app from the front end + * + */ + + public function handle_shortcode4( $atts, $content = '' ) { + + $current_user = wp_get_current_user(); + $app_passwords = get_user_meta( $current_user->ID, 'ts_app_passwords', true ); + $user_name = $current_user->user_login; + + if( $app_passwords !== '' ) { + $user_app_password = $app_passwords[0]['password']; + } + + $personal_url = get_home_url( null, $this->trackserver->url_prefix . '/' . + $user_name . '/' . $user_app_password . + '/?lat={0}&lon={1},×tamp={2},&altitude={4},&speed={5},&bearing={6}' ); + $out = htmlspecialchars ( $personal_url ); + + return $out; + } + /** * Return a proxy URL for a given URL. * @@ -1044,9 +1072,17 @@ private function validate_user_ids( $user_ids, $author_id ) { * @since 3.0 */ private function get_user_id( $user, $property = 'ID' ) { + + // @ For the page author if ( $user === '@' ) { $user = get_the_author_meta( 'ID' ); } + + // @@ For the current logged in user + if( $user === '@@' ) { + $user = get_current_user_id(); + } + if ( is_numeric( $user ) ) { $field = 'id'; $user = (int) $user; From 58a6d1af307d6081ce2137ff96b3ffadf078c41e Mon Sep 17 00:00:00 2001 From: John Barrett Date: Tue, 10 Oct 2023 21:07:11 +0200 Subject: [PATCH 02/10] Fix the case of a new user without ts_app_passwords set --- class-trackserver-shortcode.php | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/class-trackserver-shortcode.php b/class-trackserver-shortcode.php index 5891170..cfda208 100644 --- a/class-trackserver-shortcode.php +++ b/class-trackserver-shortcode.php @@ -392,22 +392,31 @@ public function handle_shortcode3( $atts, $content = '' ) { */ public function handle_shortcode4( $atts, $content = '' ) { - - $current_user = wp_get_current_user(); - $app_passwords = get_user_meta( $current_user->ID, 'ts_app_passwords', true ); - $user_name = $current_user->user_login; - - if( $app_passwords !== '' ) { - $user_app_password = $app_passwords[0]['password']; + $current_user = wp_get_current_user(); + $user_name = $current_user->user_login; + $user_app_password = '{password}'; + + $app_passwords = get_user_meta( $current_user->ID, 'ts_app_passwords', true ); + if ( empty( $app_passwords ) ) { + /* No user app password - so add one */ + $passwords[] = array( + 'password' => substr( md5( uniqid() ), -8 ), + 'permissions' => array( 'write' ), + ); + if ( update_user_meta( $current_user->ID, 'ts_app_passwords', $passwords ) !== false ) { + $user_app_password = $passwords[0]['password']; + } + } else { + $user_app_password = $app_passwords[0]['password']; } $personal_url = get_home_url( null, $this->trackserver->url_prefix . '/' . $user_name . '/' . $user_app_password . '/?lat={0}&lon={1},×tamp={2},&altitude={4},&speed={5},&bearing={6}' ); - $out = htmlspecialchars ( $personal_url ); + $out = htmlspecialchars ( $personal_url ); - return $out; - } + return $out; + } /** * Return a proxy URL for a given URL. From cd1117716ac287d050a9575e0dae1edf71decc66 Mon Sep 17 00:00:00 2001 From: John Barrett Date: Wed, 11 Oct 2023 14:20:09 +0200 Subject: [PATCH 03/10] Fix a lot of deprecation warnings when using PHP 8.2 --- class-trackserver.php | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/class-trackserver.php b/class-trackserver.php index eae285f..e4631da 100644 --- a/class-trackserver.php +++ b/class-trackserver.php @@ -60,6 +60,15 @@ class Trackserver { var $track_format = 'polyline'; // 'polyline' or 'geojson' var $trackserver_scripts = array(); var $trackserver_styles = array(); + var $tbl_tracks; + var $tbl_locations; + var $options; + var $mapdata; + var $tracks_list_table; + var $bulk_action_result_msg; + var $url_prefix; + var $have_scripts; + var $need_scripts; public $permissions; @@ -642,7 +651,7 @@ public function parse_request( $wp ) { */ private function get_request_uri() { global $wp_rewrite; - $home_path = trim( parse_url( home_url(), PHP_URL_PATH ), '/' ) . $this->url_prefix; + $home_path = trim( (string) parse_url( home_url(), PHP_URL_PATH ), '/' ) . $this->url_prefix; $home_path_regex = sprintf( '|^%s|i', preg_quote( $home_path, '|' ) ); $pathinfo = isset( $_SERVER['PATH_INFO'] ) ? $_SERVER['PATH_INFO'] : ''; @@ -1745,7 +1754,7 @@ function get_tsmap_404_template( $template ) { global $wp; $slug = $this->options['embedded_slug']; if ( - ( substr( $wp->request, 0, strlen( $slug ) + 1 ) === "${slug}/" ) || // match trailing slash to not match it as a prefix + ( substr( $wp->request, 0, strlen( $slug ) + 1 ) === "{$slug}/" ) || // match trailing slash to not match it as a prefix ( isset( $_REQUEST['post_type'] ) && $_REQUEST['post_type'] === $slug ) ) { $template = dirname( __FILE__ ) . '/embedded-404.php'; From dae482a7b188769e02eaf3c3aa1368dc90197e8d Mon Sep 17 00:00:00 2001 From: John Barrett Date: Wed, 11 Oct 2023 14:34:38 +0200 Subject: [PATCH 04/10] Fix more deprecation warnings when using PHP 8.2 --- class-trackserver-admin.php | 2 ++ class-trackserver-profile.php | 10 ++++++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/class-trackserver-admin.php b/class-trackserver-admin.php index 3f96b15..0f9a7eb 100644 --- a/class-trackserver-admin.php +++ b/class-trackserver-admin.php @@ -18,6 +18,8 @@ class Trackserver_Admin { private $tbl_tracks; private $tbl_locations; private $trashcan_icon = ' '; + private $options_page; + private $options_page_url; public function __construct( $trackserver ) { $this->trackserver = $trackserver; diff --git a/class-trackserver-profile.php b/class-trackserver-profile.php index cbeb7ad..d072694 100644 --- a/class-trackserver-profile.php +++ b/class-trackserver-profile.php @@ -11,6 +11,13 @@ class Trackserver_Profile { private $trackserver; // Reference to the main object private $p_index = 3; // A counter used for numbering HTML elements + private $current_user; + private $app_passwords; + private $username; + private $slug; + private $url; + private $url2; + private $password; public function __construct( $trackserver ) { $this->trackserver = $trackserver; @@ -69,7 +76,6 @@ public function yourprofile_html() { // translators: placeholder is for a user's display name $title = __( 'Trackserver profile for %s', 'trackserver' ); $title = sprintf( $title, $user->display_name ); - $url = menu_page_url( 'trackserver-yourprofile', false ); ?>
@@ -524,7 +530,7 @@ private function profile_html( $description, $with_creds, $suffix = null ) { } $format = <<%1\$s:
-
${url}
+
{$url}


EOF; From 1dfb9a0501809bba3c4de5dfa6ed05886d5b44b6 Mon Sep 17 00:00:00 2001 From: John Barrett Date: Wed, 11 Oct 2023 14:37:53 +0200 Subject: [PATCH 05/10] Fix more deprecation warnings when using PHP 8.2 --- class-trackserver-shortcode.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/class-trackserver-shortcode.php b/class-trackserver-shortcode.php index cfda208..55298ec 100644 --- a/class-trackserver-shortcode.php +++ b/class-trackserver-shortcode.php @@ -14,6 +14,13 @@ class Trackserver_Shortcode { private $shortcode2 = 'tsscripts'; private $shortcode3 = 'tslink'; private $shortcode4 = 'tsprofile'; + private $colors; + private $weights; + private $opacities; + private $dashes; + private $points; + private $markers; + private $markersize; /** * Constructor. From 2f6dc8eb550a6c1aad1e6ac6f1aee46ec3693422 Mon Sep 17 00:00:00 2001 From: John Barrett Date: Wed, 11 Oct 2023 16:43:53 +0200 Subject: [PATCH 06/10] Fix more deprecation warnings when using PHP 8.2 --- class-trackserver-getrequest.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/class-trackserver-getrequest.php b/class-trackserver-getrequest.php index 10af9b7..b451a80 100644 --- a/class-trackserver-getrequest.php +++ b/class-trackserver-getrequest.php @@ -12,6 +12,8 @@ class Trackserver_Getrequest { private $trackserver; // Reference to the calling object private $user_id; // WP user ID doing the request private $permissions; // The used password's associated permissions + private $username; + private $password; /** * Constructor. @@ -72,7 +74,7 @@ public function handle_request() { // Get track name from strftime format string. Use the 'osmand' format. This format should be renamed. // The 'sendlocation' format is now deprecated. - $trackname = strftime( str_replace( '{source}', $source, $this->trackserver->options['osmand_trackname_format'] ), $ts ); + $trackname = date( str_replace( '{source}', $source, $this->trackserver->options['osmand_trackname_format'] ), $ts ); if ( ! empty( $trackname ) ) { $track = new Trackserver_Track( $this->trackserver, $trackname, $user_id, 'name' ); From 191fe65f601e59e5f3d40630fa5859498a1f03b3 Mon Sep 17 00:00:00 2001 From: John Barrett Date: Wed, 11 Oct 2023 17:13:45 +0200 Subject: [PATCH 07/10] Fix more deprecation warnings when using PHP 8.2 --- class-trackserver-shortcode.php | 1 + 1 file changed, 1 insertion(+) diff --git a/class-trackserver-shortcode.php b/class-trackserver-shortcode.php index 55298ec..b9c30ca 100644 --- a/class-trackserver-shortcode.php +++ b/class-trackserver-shortcode.php @@ -418,6 +418,7 @@ public function handle_shortcode4( $atts, $content = '' ) { } $personal_url = get_home_url( null, $this->trackserver->url_prefix . '/' . + $this->trackserver->options['trackserver_slug'] . '/' . $user_name . '/' . $user_app_password . '/?lat={0}&lon={1},×tamp={2},&altitude={4},&speed={5},&bearing={6}' ); $out = htmlspecialchars ( $personal_url ); From c0cb5c4ae32d14c147045daca9da51c31ecc982f Mon Sep 17 00:00:00 2001 From: John Barrett Date: Wed, 11 Oct 2023 17:14:21 +0200 Subject: [PATCH 08/10] Allow site subscriber role access to trackserver --- class-trackserver-admin.php | 1 + 1 file changed, 1 insertion(+) diff --git a/class-trackserver-admin.php b/class-trackserver-admin.php index 0f9a7eb..b9537cd 100644 --- a/class-trackserver-admin.php +++ b/class-trackserver-admin.php @@ -162,6 +162,7 @@ private function set_capabilities() { 'administrator' => array( 'use_trackserver', 'trackserver_publish', 'trackserver_admin' ), 'editor' => array( 'use_trackserver', 'trackserver_publish' ), 'author' => array( 'use_trackserver' ), + 'subscriber' => array( 'use_trackserver' ), ); foreach ( $roles as $rolename => $capnames ) { From 6d57df6ee108c72d1cd801c4d95c1dbcce12b3ae Mon Sep 17 00:00:00 2001 From: John Barrett Date: Wed, 11 Oct 2023 17:57:07 +0200 Subject: [PATCH 09/10] Fix missing comma in URL --- class-trackserver-shortcode.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/class-trackserver-shortcode.php b/class-trackserver-shortcode.php index b9c30ca..19f8ef3 100644 --- a/class-trackserver-shortcode.php +++ b/class-trackserver-shortcode.php @@ -420,7 +420,7 @@ public function handle_shortcode4( $atts, $content = '' ) { $personal_url = get_home_url( null, $this->trackserver->url_prefix . '/' . $this->trackserver->options['trackserver_slug'] . '/' . $user_name . '/' . $user_app_password . - '/?lat={0}&lon={1},×tamp={2},&altitude={4},&speed={5},&bearing={6}' ); + '/?lat={0},&lon={1},×tamp={2},&altitude={4},&speed={5},&bearing={6}' ); $out = htmlspecialchars ( $personal_url ); return $out; From d8de26ed9281090d7b9cc1ca40b8150fedaec7d5 Mon Sep 17 00:00:00 2001 From: John Barrett Date: Fri, 13 Oct 2023 08:13:17 +0200 Subject: [PATCH 10/10] Revert "Allow site subscriber role access to trackserver" This reverts commit c0cb5c4ae32d14c147045daca9da51c31ecc982f. --- class-trackserver-admin.php | 1 - 1 file changed, 1 deletion(-) diff --git a/class-trackserver-admin.php b/class-trackserver-admin.php index b9537cd..0f9a7eb 100644 --- a/class-trackserver-admin.php +++ b/class-trackserver-admin.php @@ -162,7 +162,6 @@ private function set_capabilities() { 'administrator' => array( 'use_trackserver', 'trackserver_publish', 'trackserver_admin' ), 'editor' => array( 'use_trackserver', 'trackserver_publish' ), 'author' => array( 'use_trackserver' ), - 'subscriber' => array( 'use_trackserver' ), ); foreach ( $roles as $rolename => $capnames ) {