Skip to content
2 changes: 2 additions & 0 deletions class-trackserver-admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ class Trackserver_Admin {
private $tbl_tracks;
private $tbl_locations;
private $trashcan_icon = '<svg version="1.1" id="Capa_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="16" height="16" x="0px" y="0px" viewBox="0 0 172.541 172.541" style="enable-background:new 0 0 172.541 172.541;" xml:space="preserve"><g><path d="M166.797,25.078h-13.672h-29.971V0H49.388v25.078H19.417H5.744v15h14.806l10,132.463h111.443l10-132.463h14.805V25.078z M64.388,15h43.766v10.078H64.388V15z M128.083,157.541H44.46L35.592,40.078h13.796h73.766h13.796L128.083,157.541z"/><rect x="80.271" y="65.693" width="12" height="66.232"/><rect x="57.271" y="65.693" width="12" height="66.232"/><rect x="103.271" y="65.693" width="12" height="66.232"/></g> <g> </g> <g> </g> <g> </g> <g> </g> <g> </g> <g> </g> <g> </g> <g> </g> <g> </g> <g> </g> <g> </g> <g> </g> <g> </g> <g> </g> <g> </g> </svg>';
private $options_page;
private $options_page_url;

public function __construct( $trackserver ) {
$this->trackserver = $trackserver;
Expand Down
4 changes: 3 additions & 1 deletion class-trackserver-getrequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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' );
Expand Down
10 changes: 8 additions & 2 deletions class-trackserver-profile.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 );

?>
<div class="wrap">
Expand Down Expand Up @@ -524,7 +530,7 @@ private function profile_html( $description, $with_creds, $suffix = null ) {
}
$format = <<<EOF
<strong>%1\$s:</strong><br>
<div class="trackserver-info" id="trackserver-url{$this->p_index}">${url}</div>
<div class="trackserver-info" id="trackserver-url{$this->p_index}">{$url}</div>
<input id="trackserver-copy-url-button{$this->p_index}" type="button" class="button trackserver-copy-url" value="%2\$s" style="margin-top: 5px">
<br><br>
EOF;
Expand Down
53 changes: 53 additions & 0 deletions class-trackserver-shortcode.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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' ) );
}

/**
Expand Down Expand Up @@ -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},&timestamp={2},&altitude={4},&speed={5},&bearing={6}' );
$out = htmlspecialchars ( $personal_url );

return $out;
}

/**
* Return a proxy URL for a given URL.
*
Expand Down Expand Up @@ -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;
Expand Down
13 changes: 11 additions & 2 deletions class-trackserver.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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'] : '';
Expand Down Expand Up @@ -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';
Expand Down