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

Made some strutural changes. #4

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
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
Binary file added icons/download-speed.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added icons/mia.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added icons/mountain.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added icons/speed.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
91 changes: 91 additions & 0 deletions includes/class.utils.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
<?php
if (!class_exists('UTILS')) {
class UTILS
{
function timeAgo($dateTime, $sendUnis = true)
{
if ($dateTime == "")
return "";

$dateTime = time() - strtotime($dateTime);

$tokens = array(
31536000 => array(_YEAR, _YEARS),
2592000 => array(_MONTH, _MONTHS),
604800 => array(_WEEK, _WEEKS),
86400 => array(_DAY, _DAYS),
3600 => array(_HOUR, _HOURS),
60 => array(_MINUTE, _MINUTES),
1 => array(_SECOND, _SECONDS)
);

foreach ($tokens as $unit => $text) {
if ($dateTime < $unit) continue;
$numberOfUnits = floor($dateTime / $unit);
return $numberOfUnits . "" . ($sendUnis ? (($numberOfUnits > 1) ? " " . $text[1] : " " . $text[0]) : "") . "";
}
}

function convertUnit($meterPerSec,$unit='kilometer_per_hour',$label=false){
$units=array(
"kilometer_per_hour"=>"0.2777778",
"mile_per_hour"=>"0.44704"
);
$unitsLabels=array(
"kilometer_per_hour"=>"km/h",
"mile_per_hour"=>" mi/h"
);
if($label){
return number_format(($meterPerSec*$units[$unit]),0,",","")." ".$unitsLabels[$unit];
}else{
return number_format(($meterPerSec*$units[$unit]),0,",","");
}

}

function generateRandomPoint($centre, $radius="") {
$radius_earth = 5; //miles

//Pick random distance within $distance;
$distance = lcg_value()*$radius;

//Convert degrees to radians.
$centre_rads = array_map( 'deg2rad', $centre );

//First suppose our point is the north pole.
//Find a random point $distance miles away
$lat_rads = (pi()/2) - $distance/$radius_earth;
$lng_rads = lcg_value()*2*pi();


//($lat_rads,$lng_rads) is a point on the circle which is
//$distance miles from the north pole. Convert to Cartesian
$x1 = cos( $lat_rads ) * sin( $lng_rads );
$y1 = cos( $lat_rads ) * cos( $lng_rads );
$z1 = sin( $lat_rads );


//Rotate that sphere so that the north pole is now at $centre.

//Rotate in x axis by $rot = (pi()/2) - $centre_rads[0];
$rot = (pi()/2) - $centre_rads[0];
$x2 = $x1;
$y2 = $y1 * cos( $rot ) + $z1 * sin( $rot );
$z2 = -$y1 * sin( $rot ) + $z1 * cos( $rot );

//Rotate in z axis by $rot = $centre_rads[1]
$rot = $centre_rads[1];
$x3 = $x2 * cos( $rot ) + $y2 * sin( $rot );
$y3 = -$x2 * sin( $rot ) + $y2 * cos( $rot );
$z3 = $z2;


//Finally convert this point to polar co-ords
$lng_rads = atan2( $x3, $y3 );
$lat_rads = asin( $z3 );

return array_map( 'rad2deg', array( $lat_rads, $lng_rads ) );
}

}
}
50 changes: 50 additions & 0 deletions includes/settings.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php
date_default_timezone_set('Europe/Lisbon');
putenv("TZ=Europe/Lisbon");

include_once(__DIR__."/class.utils.php");
$ClassUtils = new UTILS();

//Getting the Language from the browser
$lang = substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2);
$acceptLang = ['pt', 'en'];
$lang = in_array($lang, $acceptLang) ? $lang : 'en';
require_once(__DIR__ . "/../languages/" . $lang . ".php");

// This key must be entered in OsmAnd's tracking URL as &key=
$secretKey = '';
// This key must be entered in OsmAnd's tracking URL as &realgpskey=
$secretRealGPSKey="";

// API key from MapQuest. Get one from developer.mapquest.com
$apikey = '';

//Where the Tracker is
$trackerURL="";

// Used to round the lat/lon values so you aren't sharing your *exact* location
$accuracy = 2; // in number of decimal positions

// Random name for the file to avoid being downloaded ( Change this value )
$fileName="";
// Where to store your last location
$filePath = __DIR__ . "/../" .$fileName;

//Default Unit for speed
$unitForSpeed="kilometer_per_hour";
//$unitForSpeed="mile_per_hour";

//Time in seconds when the page gets updates automatically. Zero means no refresh
$refreshTime=60;

// Used in page title
$yourName = 'Jonh Doe';
// Used in page title
$pageTitle = $yourName;

// Zoom on the map
// 8 gives a high overview; 12 gives a more zoomed-in map. Lower or higher values also possible.
$zoom = "15";

$height = "600";
$width = "900";
5 changes: 0 additions & 5 deletions index.html

This file was deleted.

71 changes: 71 additions & 0 deletions index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<?php
require_once __DIR__."/includes/settings.php";

if ($secretKey=='') {
die(_WARNING_NEED_TO_CHANGE_SECRET_KEY);
}
if ($apikey == '') {
die(_WARNING_NEED_TO_GET_APIKEY);
}

if(file_exists($filePath)){
$loc_string = file_get_contents($filePath);
$info = unserialize($loc_string);
$timeAgo=$ClassUtils->timeAgo(date("Y-m-d H:i:s",substr($info['timestamp'],0,-3)));
$altitude=number_format($info['altitude'],0,",","")." m";
$speedLabel=$ClassUtils->convertUnit($info['speed'],$unitForSpeed,true);
$speed=$ClassUtils->convertUnit($info['speed'],$unitForSpeed);

if($_GET['realgps']==$secretRealGPSKey){
$lat = $info['reallat'];
$lon = $info['reallon'];
}else{
$lat = $info['fakelat'];
$lon = $info['fakelon'];
}

if($speed>0){
$statusIcon="marker-lg-417505-$speed";
}else{
$statusIcon="marker-lg-f2231f-$speed";
}
//$statusIcon=$trackerURL."icons/mia.png";

$staticUrl = 'https://www.mapquestapi.com/staticmap/v5/map?';
$staticUrl = $staticUrl."size=$width,$height&type=map&imagetype=jpeg&key=$apikey";
$staticUrl = $staticUrl . "&locations=$lat,$lon|".$statusIcon."&size=@2x|&zoom=$zoom&center=$lat,$lon";
$mapUrl = 'https://www.openstreetmap.org';
$mapUrl = $mapUrl . "?mlat=$lat&mlon=$lon";
}else{
die(_LOCATION_FILE_DOES_NOT_EXIST);
}

/* Note that you can embed an interactive map using:
$bbox = 0.01; // Zoom. 0.1 gives an overview, 0.01 is quite zoomed in, 0.001 is street-level.
$bboxleft = $lon - $bbox;
$bboxbottom = $lat - $bbox;
$bboxright = $lon + $bbox;
$bboxtop = $lat + $bbox;
$bb = urlencode($bboxleft . ',' . $bboxbottom . ',' . $bboxright . ',' . $bboxtop);
<iframe src="http://www.openstreetmap.org/export/embed.html?m&bbox=$bb&amp;layer=mapnik" width=800 height=600></iframe>
The issue is that you cannot place a marker (not that I have found).
*/
echo "<html>
<head>
<title>$pageTitle</title>
".($refreshTime>0?"<meta http-equiv='refresh' content='$refreshTime'/>":"")."
</head>
<body>
<center>
".($timeAgo>0?"<h3>".$yourName." "._STATUS_AS_OF." ".$timeAgo."</h3>":"")."
<h4><img src='icons/download-speed.png' width='24px'>
".($speed>0?"".$speedLabel."":""._IT_IS_STOPPED."")."
<img src='icons/mountain.png' width='24px'> ".$altitude."</h4>
<p><a href='".$mapUrl."'><img src='".$staticUrl."'></a></p>
<p>"._CLICK_TO_SEE_INTERACTIVE_MAP."</p>
<small>"._PAGE_GENERATED_AT." ".date("H:i")."</small>
</center>
</body>
</html>";


31 changes: 31 additions & 0 deletions languages/en.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

DEFINE ("_STATUS_AS_OF", "status as of");
DEFINE ("_MINUTES_AGO", "minutes ago");
DEFINE ("_SPEED", "Speed");
DEFINE ("_IT_IS_STOPPED", "Taking a break.");
DEFINE ("_TIMEZONE", "Timezone");
DEFINE ("_PAGE_GENERATED_AT", "Page generated at");
DEFINE ("_CLICK_TO_SEE_INTERACTIVE_MAP", "Click for an interactive map");
DEFINE ("_WARNING_INVALID_SECRET_KEY", "The used key is invalid");
DEFINE ("_WARNING_NEED_TO_GET_APIKEY", "You must create and API key at <a href='https://developer.mapquest.com/'>https://developer.mapquest.com/</a>");

DEFINE ("_WARNING_NEED_TO_CHANGE_SECRET_KEY", "This application is not functional yet. See the README how to set it up (hint: edit settings.php).");
DEFINE ("_LOCATION_FILE_DOES_NOT_EXIST", "The localtion file needed to run this application is not yet available, please return later.");

DEFINE ("_YEAR", "year");
DEFINE ("_YEARS", "years");
DEFINE ("_MONTH", "month");
DEFINE ("_MONTHS", "months");
DEFINE ("_WEEK", "week");
DEFINE ("_WEEKS", "weeks");
DEFINE ("_DAY", "day");
DEFINE ("_DAYS", "days");
DEFINE ("_HOUR", "hour");
DEFINE ("_HOURS", "hours");
DEFINE ("_MINUTE", "minute");
DEFINE ("_MINUTES", "minutes");
DEFINE ("_SECOND", "second");
DEFINE ("_SECONDS", "seconds");


29 changes: 29 additions & 0 deletions languages/pt.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

DEFINE ("_STATUS_AS_OF", " esteve aqui à");
DEFINE ("_MINUTES_AGO", "minutos atrás");
DEFINE ("_SPEED", "Velocidade");
DEFINE ("_IT_IS_STOPPED", "A Descansar!!");
DEFINE ("_TIMEZONE", "Fuso Horário");
DEFINE ("_PAGE_GENERATED_AT", "Página gerada às");

DEFINE ("_CLICK_TO_SEE_INTERACTIVE_MAP", "Clicar para ver mapa interativo");
DEFINE ("_WARNING_INVALID_SECRET_KEY", "A chave utilizade é inválida");
DEFINE ("_WARNING_NEED_TO_GET_APIKEY", "É necessário criar uma chave de API em <a href='https://developer.mapquest.com/'>https://developer.mapquest.com/</a>");
DEFINE ("_WARNING_NEED_TO_CHANGE_SECRET_KEY", "Este aplicativo ainda não está funcional. Veja o README como configurá-lo (dica: edite o settings.php e altere a chave secreta).");
DEFINE ("_LOCATION_FILE_DOES_NOT_EXIST", "O arquivo de localização necessário para executar este aplicativo ainda não está disponível, por favor volte mais tarde.");

DEFINE ("_YEAR", "ano");
DEFINE ("_YEARS", "anos");
DEFINE ("_MONTH", "mês");
DEFINE ("_MONTHS", "meses");
DEFINE ("_WEEK", "semana");
DEFINE ("_WEEKS", "semanas");
DEFINE ("_DAY", "dia");
DEFINE ("_DAYS", "dias");
DEFINE ("_HOUR", "hora");
DEFINE ("_HOURS", "horas");
DEFINE ("_MINUTE", "minuto");
DEFINE ("_MINUTES", "minutos");
DEFINE ("_SECOND", "segundo");
DEFINE ("_SECONDS", "segundos");
46 changes: 0 additions & 46 deletions map.php

This file was deleted.

25 changes: 0 additions & 25 deletions settings.php

This file was deleted.

27 changes: 27 additions & 0 deletions tests/generatePoint.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php
require_once __DIR__."/../includes/settings.php";

//Generate GPS point
$point = array(
'x' => random_int(-90, 90 - 1) + (random_int(0, PHP_INT_MAX - 1) / PHP_INT_MAX ),
'y' => random_int(-180, 180 - 1) + (random_int(0, PHP_INT_MAX - 1) / PHP_INT_MAX )
);

$min=1;
$max=300;
$hdop=($min+lcg_value()*(abs($max-$min)));
$altitude=($min+lcg_value()*(abs($max-$min)));
$speed=($min+lcg_value()*(abs($max-$min)));
$timestamp=time();

$info['lat'] = round($point['x'], $accuracy);
$info['lon'] = round($point['y'], $accuracy);
$info['timestamp'] = intval($timestamp)."000";
$info['hdop'] = floatval($hdop);
$info['altitude'] = floatval($altitude);
$info['speed'] = floatval($speed);
$url=$trackerURL."/tracker.php?lat=".$info['lat']."&lon=".$info['lon']."&timestamp=".$info['timestamp']."&hdop=".$info['hdop']."&altitude=".$info['altitude']."&speed=".$info['speed']."&key=".$secretKey;
echo "<a href='$url' target='_blank'>$url</a>";
$fh = fopen($filePath, 'w');
fwrite($fh, serialize($info));
fclose($fh);
Loading