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-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' ); 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; diff --git a/class-trackserver-shortcode.php b/class-trackserver-shortcode.php index 0ff689e..19f8ef3 100644 --- a/class-trackserver-shortcode.php +++ b/class-trackserver-shortcode.php @@ -13,6 +13,14 @@ class Trackserver_Shortcode { private $shortcode1 = 'tsmap'; private $shortcode2 = 'tsscripts'; private $shortcode3 = 'tslink'; + private $shortcode4 = 'tsprofile'; + private $colors; + private $weights; + private $opacities; + private $dashes; + private $points; + private $markers; + private $markersize; /** * Constructor. @@ -46,6 +54,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 +390,42 @@ 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(); + $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 . '/' . + $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 ); + + return $out; + } + /** * Return a proxy URL for a given URL. * @@ -1044,9 +1089,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; 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';