Implement lint
This commit is contained in:
+20
-33
@@ -6,9 +6,8 @@ use Franzz\Objects\PhpObject;
|
||||
use Franzz\Objects\ToolBox;
|
||||
|
||||
//TODO Keep only local specificities and move bulk to Franzz\Objects\Controller
|
||||
class Controller extends PhpObject
|
||||
{
|
||||
const MUTATING_ACTIONS = array(
|
||||
class Controller extends PhpObject {
|
||||
private const MUTATING_ACTIONS = [
|
||||
'add_post',
|
||||
'subscribe',
|
||||
'unsubscribe',
|
||||
@@ -21,34 +20,31 @@ class Controller extends PhpObject
|
||||
'admin_set',
|
||||
'admin_create',
|
||||
'admin_delete'
|
||||
);
|
||||
const SESSION_WRITING_ACTIONS = array(
|
||||
];
|
||||
private const SESSION_WRITING_ACTIONS = [
|
||||
'login',
|
||||
'logout'
|
||||
);
|
||||
];
|
||||
|
||||
private Livetrail $oLivetrail;
|
||||
private array $asReq;
|
||||
private string $sCsrfToken = '';
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
public function __construct() {
|
||||
parent::__construct(__CLASS__);
|
||||
}
|
||||
|
||||
private function setReqVal(string $sKey, $oValue, string $sValidation=''): void
|
||||
{
|
||||
private function setReqVal(string $sKey, $oValue, string $sValidation=''): void {
|
||||
$this->asReq[$sKey] = $this->validateValue($sValidation, $oValue);
|
||||
}
|
||||
|
||||
public function handle($sProcessPage, array $argv = array()): string
|
||||
{
|
||||
public function handle($sProcessPage, array $argv = []): string {
|
||||
//Start buffering so warnings/notices can be collected
|
||||
ob_start();
|
||||
|
||||
//Parse variables
|
||||
$asReq = ToolBox::getRequest($argv);
|
||||
$this->asReq = array();
|
||||
$this->asReq = [];
|
||||
$sAction = $asReq['a'] ?? '';
|
||||
$this->setReqVal('t', $asReq['t'] ?? '');
|
||||
$this->setReqVal('name', $asReq['name'] ?? '');
|
||||
@@ -90,8 +86,7 @@ class Controller extends PhpObject
|
||||
return $sResult;
|
||||
}
|
||||
|
||||
private function validateMutationRequest(string $sAction): bool
|
||||
{
|
||||
private function validateMutationRequest(string $sAction): bool {
|
||||
return
|
||||
PHP_SAPI === 'cli'
|
||||
||
|
||||
@@ -101,44 +96,38 @@ class Controller extends PhpObject
|
||||
;
|
||||
}
|
||||
|
||||
private function getCsrfToken(): string
|
||||
{
|
||||
private function getCsrfToken(): string {
|
||||
if($this->sCsrfToken === '') $this->initCsrfToken();
|
||||
return $this->sCsrfToken;
|
||||
}
|
||||
|
||||
private function setCsrfToken(): void
|
||||
{
|
||||
private function setCsrfToken(): void {
|
||||
if(empty($_SESSION['csrf_token'])) $_SESSION['csrf_token'] = bin2hex(random_bytes(32));
|
||||
$this->sCsrfToken = $_SESSION['csrf_token'];
|
||||
}
|
||||
|
||||
private function initCsrfToken(): void
|
||||
{
|
||||
private function initCsrfToken(): void {
|
||||
if(PHP_SAPI === 'cli') return;
|
||||
|
||||
if(session_status() !== PHP_SESSION_ACTIVE) {
|
||||
$bSecure = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off') || (($_SERVER['HTTP_X_FORWARDED_PROTO'] ?? '') === 'https');
|
||||
session_set_cookie_params(array('httponly' => true, 'secure' => $bSecure, 'samesite' => 'Lax'));
|
||||
session_set_cookie_params(['httponly' => true, 'secure' => $bSecure, 'samesite' => 'Lax']);
|
||||
session_start();
|
||||
}
|
||||
|
||||
$this->setCsrfToken();
|
||||
}
|
||||
|
||||
private function checkCsrfToken(string $sClientToken): bool
|
||||
{
|
||||
private function checkCsrfToken(string $sClientToken): bool {
|
||||
$sServerToken = $this->getCsrfToken();
|
||||
return PHP_SAPI === 'cli' || ($sServerToken !== '' && is_string($sClientToken) && hash_equals($sServerToken, $sClientToken));
|
||||
}
|
||||
|
||||
private function closeSession(): void
|
||||
{
|
||||
private function closeSession(): void {
|
||||
if(session_status() === PHP_SESSION_ACTIVE) session_write_close();
|
||||
}
|
||||
|
||||
private function dispatch(string $sAction): string
|
||||
{
|
||||
private function dispatch(string $sAction): string {
|
||||
return match($sAction) {
|
||||
'markers' => $this->oLivetrail->getMarkers(),
|
||||
'last_update' => $this->oLivetrail->getLastUpdate(),
|
||||
@@ -154,8 +143,7 @@ class Controller extends PhpObject
|
||||
};
|
||||
}
|
||||
|
||||
private function dispatchAdmin(string $sAction): string
|
||||
{
|
||||
private function dispatchAdmin(string $sAction): string {
|
||||
if(!$this->oLivetrail->checkUserClearance(User::CLEARANCE_ADMIN)) {
|
||||
return Livetrail::getJsonResult(false, Livetrail::NOT_FOUND);
|
||||
}
|
||||
@@ -173,11 +161,10 @@ class Controller extends PhpObject
|
||||
};
|
||||
}
|
||||
|
||||
private static function validateValue(string $sValidation, $oValue=0)
|
||||
{
|
||||
private static function validateValue(string $sValidation, $oValue=0) {
|
||||
return match($sValidation) {
|
||||
'' => $oValue,
|
||||
'positiveInt' => filter_var($oValue, FILTER_VALIDATE_INT, array('options' => array('default' => 0, 'min_range' => 0)))
|
||||
'positiveInt' => filter_var($oValue, FILTER_VALIDATE_INT, ['options' => ['default' => 0, 'min_range' => 0]])
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -25,7 +25,7 @@ class Email extends PhpObject {
|
||||
parent::__construct(__CLASS__);
|
||||
$this->sServName = $sServName;
|
||||
$this->setTemplate($sTemplateName);
|
||||
$this->asDests = array();
|
||||
$this->asDests = [];
|
||||
}
|
||||
|
||||
public function setTemplate($sTemplateName) {
|
||||
@@ -39,7 +39,7 @@ class Email extends PhpObject {
|
||||
* @param array $asDests Contains: id_user, name, email, language, timezone, active
|
||||
*/
|
||||
public function setDestInfo($asDests) {
|
||||
if(array_key_exists('email', $asDests)) $asDests = array($asDests);
|
||||
if(array_key_exists('email', $asDests)) $asDests = [$asDests];
|
||||
$this->asDests = $asDests;
|
||||
}
|
||||
|
||||
|
||||
+51
-51
@@ -13,32 +13,32 @@ use \Settings;
|
||||
class Feed extends PhpObject {
|
||||
|
||||
//Spot feed
|
||||
const FEED_HOOK = 'https://api.findmespot.com/spot-main-web/consumer/rest-api/2.0/public/feed/';
|
||||
const FEED_TYPE_XML = '/message.xml';
|
||||
const FEED_TYPE_JSON = '/message.json';
|
||||
const FEED_MAX_REFRESH = 5 * 60; //Seconds
|
||||
private const FEED_HOOK = 'https://api.findmespot.com/spot-main-web/consumer/rest-api/2.0/public/feed/';
|
||||
private const FEED_TYPE_XML = '/message.xml';
|
||||
private const FEED_TYPE_JSON = '/message.json';
|
||||
private const FEED_MAX_REFRESH = 5 * 60; //Seconds
|
||||
|
||||
//Weather
|
||||
const WEATHER_HOOK = 'https://weather.visualcrossing.com/VisualCrossingWebServices/rest/services/timeline';
|
||||
const WEATHER_PARAM = array(
|
||||
private const WEATHER_HOOK = 'https://weather.visualcrossing.com/VisualCrossingWebServices/rest/services/timeline';
|
||||
private const WEATHER_PARAM = [
|
||||
'key' => Settings::WEATHER_TOKEN,
|
||||
'unitGroup' => 'metric',
|
||||
'lang' => 'en',
|
||||
'include' => 'current',
|
||||
'iconSet' => 'icons2'
|
||||
);
|
||||
];
|
||||
|
||||
//Timezone
|
||||
const TIMEZONE_HOOK = 'http://api.geonames.org/timezoneJSON';
|
||||
|
||||
private const TIMEZONE_HOOK = 'http://api.geonames.org/timezoneJSON';
|
||||
|
||||
//DB Tables
|
||||
const SPOT_TABLE = 'spots';
|
||||
const FEED_TABLE = 'feeds';
|
||||
const MSG_TABLE = 'messages';
|
||||
public const SPOT_TABLE = 'spots';
|
||||
public const FEED_TABLE = 'feeds';
|
||||
public const MSG_TABLE = 'messages';
|
||||
|
||||
//Hide/Display values
|
||||
const MSG_HIDDEN = 0;
|
||||
const MSG_DISPLAYED = 1;
|
||||
public const MSG_HIDDEN = 0;
|
||||
public const MSG_DISPLAYED = 1;
|
||||
|
||||
/**
|
||||
* Database Handle
|
||||
@@ -72,10 +72,10 @@ class Feed extends PhpObject {
|
||||
}
|
||||
|
||||
public function createFeedId($oProjectId) {
|
||||
$this->setFeedId($this->oDb->insertRow(self::FEED_TABLE, array(
|
||||
$this->setFeedId($this->oDb->insertRow(self::FEED_TABLE, [
|
||||
Db::getId(Project::PROJ_TABLE) => $oProjectId,
|
||||
'status' => 'INACTIVE'
|
||||
)));
|
||||
]));
|
||||
return $this->getFeedId();
|
||||
}
|
||||
|
||||
@@ -92,14 +92,14 @@ class Feed extends PhpObject {
|
||||
}
|
||||
|
||||
public function getSpots() {
|
||||
$asSpots = $this->oDb->selectRows(array('from'=>self::SPOT_TABLE));
|
||||
$asSpots = $this->oDb->selectRows(['from'=>self::SPOT_TABLE]);
|
||||
foreach($asSpots as &$asSpot) $asSpot['id'] = $asSpot[Db::getId(self::SPOT_TABLE)];
|
||||
return $asSpots;
|
||||
}
|
||||
|
||||
public function getFeeds($iFeedId=0) {
|
||||
$asInfo = array('from'=>self::FEED_TABLE);
|
||||
if($iFeedId > 0) $asInfo['constraint'] = array(Db::getId(self::FEED_TABLE)=>$iFeedId);
|
||||
$asInfo = ['from'=>self::FEED_TABLE];
|
||||
if($iFeedId > 0) $asInfo['constraint'] = [Db::getId(self::FEED_TABLE)=>$iFeedId];
|
||||
$asFeeds = $this->oDb->selectRows($asInfo);
|
||||
|
||||
foreach($asFeeds as &$asFeed) $asFeed['id'] = $asFeed[Db::getId(self::FEED_TABLE)];
|
||||
@@ -111,21 +111,21 @@ class Feed extends PhpObject {
|
||||
return array_shift($asFeeds);
|
||||
}
|
||||
|
||||
public function getMessages($asConstraints=array()) {
|
||||
public function getMessages($asConstraints=[]) {
|
||||
$sFeedIdCol = Db::getId(self::FEED_TABLE, true);
|
||||
$asInfo = array(
|
||||
'select' => array(
|
||||
$asInfo = [
|
||||
'select' => [
|
||||
Db::getId(self::MSG_TABLE), 'ref_msg_id', 'type', //ID
|
||||
'latitude', 'longitude', //Position
|
||||
'site_time', 'timezone', 'unix_time', //Time
|
||||
'weather_icon', 'weather_cond', 'weather_temp' //Weather
|
||||
),
|
||||
],
|
||||
'from' => self::MSG_TABLE,
|
||||
'join' => array(self::FEED_TABLE => Db::getId(self::FEED_TABLE)),
|
||||
'constraint'=> array($sFeedIdCol => $this->getFeedId(), 'display' => self::MSG_DISPLAYED),
|
||||
'constOpe' => array($sFeedIdCol => "=", 'display' => "="),
|
||||
'orderBy' => array('site_time'=>'ASC')
|
||||
);
|
||||
'join' => [self::FEED_TABLE => Db::getId(self::FEED_TABLE)],
|
||||
'constraint'=> [$sFeedIdCol => $this->getFeedId(), 'display' => self::MSG_DISPLAYED],
|
||||
'constOpe' => [$sFeedIdCol => '=', 'display' => '='],
|
||||
'orderBy' => ['site_time'=>'ASC']
|
||||
];
|
||||
if(!empty($asConstraints)) $asInfo = array_merge($asInfo, $asConstraints);
|
||||
|
||||
$asResult = $this->oDb->selectRows($asInfo);
|
||||
@@ -134,7 +134,7 @@ class Feed extends PhpObject {
|
||||
$iCount = 0;
|
||||
foreach($asResult as &$asMsg) {
|
||||
if($asMsg['weather_icon'] == '' && $iCount < 3) {
|
||||
$asWeather = $this->getWeather(array($asMsg['latitude'], $asMsg['longitude']), $asMsg['unix_time']);
|
||||
$asWeather = $this->getWeather([$asMsg['latitude'], $asMsg['longitude']], $asMsg['unix_time']);
|
||||
$asMsg = array_merge($asMsg, $asWeather);
|
||||
$this->oDb->updateRow(self::MSG_TABLE, $asMsg[Db::getId(self::MSG_TABLE)], $asWeather, false);
|
||||
$iCount++;
|
||||
@@ -145,7 +145,7 @@ class Feed extends PhpObject {
|
||||
return $asResult;
|
||||
}
|
||||
|
||||
public function getLastMessageId($asConstraints=array()) {
|
||||
public function getLastMessageId($asConstraints=[]) {
|
||||
$asMessages = $this->getMessages($asConstraints);
|
||||
return end($asMessages)[Db::getId(self::MSG_TABLE)] ?? 0;
|
||||
}
|
||||
@@ -169,7 +169,7 @@ class Feed extends PhpObject {
|
||||
$sTimeZone = date_default_timezone_get();
|
||||
$oDateTime = new \DateTime('@'.$iTimestamp);
|
||||
$oDateTime->setTimezone(new \DateTimeZone($sTimeZone));
|
||||
$asWeather = $this->getWeather(array($sLat, $sLng), $iTimestamp);
|
||||
$asWeather = $this->getWeather([$sLat, $sLng], $iTimestamp);
|
||||
|
||||
$asMsg = [
|
||||
'ref_msg_id' => $iTimestamp.'/man',
|
||||
@@ -200,33 +200,33 @@ class Feed extends PhpObject {
|
||||
|
||||
//Fix unstable Spot API Structure
|
||||
if(array_key_exists('message', $asMsgs)) $asMsgs = $asMsgs['message']; //Sometimes adds an extra "message" level
|
||||
if(!array_key_exists(0, $asMsgs)) $asMsgs = array($asMsgs); //Jumps a level when there is only 1 message
|
||||
if(!array_key_exists(0, $asMsgs)) $asMsgs = [$asMsgs]; //Jumps a level when there is only 1 message
|
||||
|
||||
//Update Spot, Feed & Messages
|
||||
if(!empty($asMsgs) && array_key_exists('messengerId', $asMsgs[0])) {
|
||||
|
||||
//Update Spot Info from the first message
|
||||
$asSpotInfo = array(
|
||||
$asSpotInfo = [
|
||||
'ref_spot_id' => $asMsgs[0]['messengerId'],
|
||||
'name' => $asMsgs[0]['messengerName'],
|
||||
'model' => $asMsgs[0]['modelId']
|
||||
);
|
||||
$iSpotId = $this->oDb->insertUpdateRow(self::SPOT_TABLE, $asSpotInfo, array('ref_spot_id'));
|
||||
];
|
||||
$iSpotId = $this->oDb->insertUpdateRow(self::SPOT_TABLE, $asSpotInfo, ['ref_spot_id']);
|
||||
|
||||
//Update Feed Info and last update date
|
||||
$asFeedInfo = array(
|
||||
$asFeedInfo = [
|
||||
'ref_feed_id' => $asFeed['id'],
|
||||
Db::getId(self::SPOT_TABLE) => $iSpotId,
|
||||
'name' => $asFeed['name'],
|
||||
'description' => $asFeed['description'],
|
||||
'status' => $asFeed['status'],
|
||||
'last_update' => $sNow
|
||||
);
|
||||
$iFeedId = $this->oDb->insertUpdateRow(self::FEED_TABLE, $asFeedInfo, array('ref_feed_id'));
|
||||
];
|
||||
$iFeedId = $this->oDb->insertUpdateRow(self::FEED_TABLE, $asFeedInfo, ['ref_feed_id']);
|
||||
|
||||
//Update Messages
|
||||
foreach($asMsgs as $asMsg) {
|
||||
$asMsg = array(
|
||||
$asMsg = [
|
||||
'ref_msg_id' => $asMsg['id'],
|
||||
Db::getId(self::FEED_TABLE) => $iFeedId,
|
||||
'type' => $asMsg['messageType'],
|
||||
@@ -238,15 +238,15 @@ class Feed extends PhpObject {
|
||||
'unix_time' => $asMsg['unixTime'], //UNIX Time (backup)
|
||||
'content' => $asMsg['messageContent'],
|
||||
'battery_state' => $asMsg['batteryState']
|
||||
);
|
||||
];
|
||||
|
||||
$iMsgId = $this->oDb->selectId(self::MSG_TABLE, array('ref_msg_id'=>$asMsg['ref_msg_id']));
|
||||
$iMsgId = $this->oDb->selectId(self::MSG_TABLE, ['ref_msg_id'=>$asMsg['ref_msg_id']]);
|
||||
if(!$iMsgId) {
|
||||
//First Catch
|
||||
$asMsg['posted_on'] = $sNow;
|
||||
|
||||
//Weather Data
|
||||
$asMsg = array_merge($asMsg, $this->getWeather(array($asMsg['latitude'], $asMsg['longitude']), $asMsg['unix_time']));
|
||||
$asMsg = array_merge($asMsg, $this->getWeather([$asMsg['latitude'], $asMsg['longitude']], $asMsg['unix_time']));
|
||||
|
||||
$this->oDb->insertRow(self::MSG_TABLE, $asMsg);
|
||||
$bNewMsg = true;
|
||||
@@ -255,7 +255,7 @@ class Feed extends PhpObject {
|
||||
}
|
||||
}
|
||||
}
|
||||
else $this->oDb->updateRow(self::FEED_TABLE, $this->getFeedId(), array('last_update'=>$sNow));
|
||||
else $this->oDb->updateRow(self::FEED_TABLE, $this->getFeedId(), ['last_update'=>$sNow]);
|
||||
|
||||
return $bNewMsg;
|
||||
}
|
||||
@@ -281,19 +281,19 @@ class Feed extends PhpObject {
|
||||
//Get Condition Language ID
|
||||
$sCondLangId = (new Translator(self::WEATHER_PARAM['lang']))->getTranslationKey($sWeatherCond);
|
||||
|
||||
return array(
|
||||
return [
|
||||
'weather_icon' => $sWeatherIcon,
|
||||
'weather_cond' => $sCondLangId,
|
||||
'weather_temp' => floatval($sWeatherTemp)
|
||||
);
|
||||
];
|
||||
}
|
||||
|
||||
private function getTimeZone($iLat, $iLng) {
|
||||
$asParams = array(
|
||||
$asParams = [
|
||||
'username' => Settings::TIMEZONE_USER,
|
||||
'lat' => $iLat,
|
||||
'lng' => $iLng
|
||||
);
|
||||
];
|
||||
$sApiUrl = self::TIMEZONE_HOOK.'?'.http_build_query($asParams);
|
||||
|
||||
$asTimeZone = json_decode(file_get_contents($sApiUrl), true);
|
||||
@@ -314,7 +314,7 @@ class Feed extends PhpObject {
|
||||
}
|
||||
|
||||
private function updateField($sField, $oValue) {
|
||||
$bResult = ($this->oDb->updateRow(self::FEED_TABLE, $this->getFeedId(), array($sField=>$oValue)) > 0);
|
||||
$bResult = ($this->oDb->updateRow(self::FEED_TABLE, $this->getFeedId(), [$sField=>$oValue]) > 0);
|
||||
$this->setFeedId($this->getFeedId());
|
||||
|
||||
return $bResult;
|
||||
@@ -323,8 +323,8 @@ class Feed extends PhpObject {
|
||||
public function delete() {
|
||||
$bSuccess = false;
|
||||
$sLangId = '';
|
||||
$asLangParams = array();
|
||||
$asData = array();
|
||||
$asLangParams = [];
|
||||
$asData = [];
|
||||
|
||||
if($this->getFeedId() > 0) {
|
||||
$asData['id'] = $this->getFeedId();
|
||||
@@ -333,7 +333,7 @@ class Feed extends PhpObject {
|
||||
}
|
||||
else {
|
||||
$sLangId = 'error.impossible_value';
|
||||
$asLangParams = array($this->getFeedId(), 'feed ID');
|
||||
$asLangParams = [$this->getFeedId(), 'feed ID'];
|
||||
}
|
||||
|
||||
return Livetrail::getResult($bSuccess, $sLangId, $asData, $asLangParams);
|
||||
|
||||
+4
-4
@@ -7,8 +7,8 @@ use \Settings;
|
||||
abstract class Geo extends PhpObject {
|
||||
protected const EXT = '';
|
||||
|
||||
const GEO_FOLDER = 'geo';
|
||||
const OPT_SIMPLE = 'simplification';
|
||||
private const GEO_FOLDER = 'geo';
|
||||
private const OPT_SIMPLE = 'simplification';
|
||||
|
||||
protected array $asTracks;
|
||||
protected string $sFilePath;
|
||||
@@ -16,7 +16,7 @@ abstract class Geo extends PhpObject {
|
||||
public function __construct(string $sCodeName) {
|
||||
parent::__construct(get_class($this), Settings::DEBUG, PhpObject::MODE_HTML);
|
||||
$this->sFilePath = self::getBackEndFilePath($sCodeName);
|
||||
$this->asTracks = array();
|
||||
$this->asTracks = [];
|
||||
}
|
||||
|
||||
//Access from backend
|
||||
@@ -32,4 +32,4 @@ abstract class Geo extends PhpObject {
|
||||
public function getLog() {
|
||||
return $this->getCleanMessageStack(PhpObject::NOTICE_TAB);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+24
-24
@@ -3,11 +3,11 @@
|
||||
namespace Franzz\Livetrail;
|
||||
|
||||
class GeoJson extends Geo {
|
||||
protected const EXT = '.geojson';
|
||||
|
||||
const EXT = '.geojson';
|
||||
const MAX_FILESIZE = 2; //MB
|
||||
const MAX_DEVIATION_FLAT = 0.1; //10%
|
||||
const MAX_DEVIATION_ELEV = 0.1; //10%
|
||||
private const MAX_FILESIZE = 2; //MB
|
||||
private const MAX_DEVIATION_FLAT = 0.1; //10%
|
||||
private const MAX_DEVIATION_ELEV = 0.1; //10%
|
||||
|
||||
public function __construct($sCodeName) {
|
||||
parent::__construct($sCodeName);
|
||||
@@ -38,7 +38,7 @@ class GeoJson extends Geo {
|
||||
$iGlobalInvalidPointCount = 0;
|
||||
$iGlobalPointCount = 0;
|
||||
|
||||
$this->asTracks = array();
|
||||
$this->asTracks = [];
|
||||
foreach($asTracks as $asTrackProps) {
|
||||
$asOptions = $this->parseOptions($asTrackProps['cmt']);
|
||||
|
||||
@@ -64,18 +64,18 @@ class GeoJson extends Geo {
|
||||
continue 2; //discard tracks
|
||||
}
|
||||
|
||||
$asTrack = array(
|
||||
$asTrack = [
|
||||
'type' => 'Feature',
|
||||
'properties' => array(
|
||||
'properties' => [
|
||||
'name' => $asTrackProps['name'],
|
||||
'type' => $sType,
|
||||
'description' => $asTrackProps['desc']
|
||||
),
|
||||
'geometry' => array(
|
||||
],
|
||||
'geometry' => [
|
||||
'type' => 'LineString',
|
||||
'coordinates' => array()
|
||||
)
|
||||
);
|
||||
'coordinates' => []
|
||||
]
|
||||
];
|
||||
|
||||
if($sType != 'hitchhiking' && str_contains($asTrackProps['desc'], ' ➜ ')) {
|
||||
list($sFrom, $sTo) = explode(' ➜ ', $asTrackProps['desc']);
|
||||
@@ -86,9 +86,9 @@ class GeoJson extends Geo {
|
||||
$asTrackPoints = $asTrackProps['points'];
|
||||
$iPointCount = count($asTrackPoints);
|
||||
$iInvalidPointCount = 0;
|
||||
$asPrevPoint = array();
|
||||
$asPrevPoint = [];
|
||||
foreach($asTrackPoints as $iIndex=>$asPoint) {
|
||||
$asNextPoint = ($iIndex < ($iPointCount - 1))?$asTrackPoints[$iIndex + 1]:array();
|
||||
$asNextPoint = ($iIndex < ($iPointCount - 1))?$asTrackPoints[$iIndex + 1]:[];
|
||||
if($bSimplify && !empty($asPrevPoint) && !empty($asNextPoint)) {
|
||||
if(!$this->isPointValid($asPrevPoint, $asPoint, $asNextPoint)) {
|
||||
$iInvalidPointCount++;
|
||||
@@ -112,11 +112,11 @@ class GeoJson extends Geo {
|
||||
$this->addNotice('Sorting off-tracks');
|
||||
|
||||
//Find first & last track points
|
||||
$asTracksEnds = array();
|
||||
$asTracks = array();
|
||||
$asTracksEnds = [];
|
||||
$asTracks = [];
|
||||
foreach($this->asTracks as $iTrackId=>$asTrack) {
|
||||
$sTrackId = 't'.$iTrackId;
|
||||
$asTracksEnds[$sTrackId] = array('first'=>reset($asTrack['geometry']['coordinates']), 'last'=>end($asTrack['geometry']['coordinates']));
|
||||
$asTracksEnds[$sTrackId] = ['first'=>reset($asTrack['geometry']['coordinates']), 'last'=>end($asTrack['geometry']['coordinates'])];
|
||||
$asTracks[$sTrackId] = $asTrack;
|
||||
}
|
||||
|
||||
@@ -153,14 +153,14 @@ class GeoJson extends Geo {
|
||||
//Move track
|
||||
unset($asTracks[$sTrackId]);
|
||||
$iOffset = array_search($sConnectedTrackId, array_keys($asTracks)) + $iPosition;
|
||||
$asTracks = array_slice($asTracks, 0, $iOffset) + array($sTrackId => $asTrack) + array_slice($asTracks, $iOffset);
|
||||
$asTracks = array_slice($asTracks, 0, $iOffset) + [$sTrackId => $asTrack] + array_slice($asTracks, $iOffset);
|
||||
}
|
||||
|
||||
$this->asTracks = array_values($asTracks);
|
||||
}
|
||||
|
||||
public function getCenter() {
|
||||
$asCoords = array();
|
||||
$asCoords = [];
|
||||
$asMainTracks = array_filter($this->asTracks, function ($astrack) {return $astrack['properties']['type'] == 'main';});
|
||||
foreach($asMainTracks as $asMainTrack) {
|
||||
foreach($asMainTrack['geometry']['coordinates'] as $aiCoords) {
|
||||
@@ -173,7 +173,7 @@ class GeoJson extends Geo {
|
||||
|
||||
private function parseOptions($sComment) {
|
||||
$sComment = strip_tags(html_entity_decode($sComment));
|
||||
$asOptions = array(self::OPT_SIMPLE=>'');
|
||||
$asOptions = [self::OPT_SIMPLE=>''];
|
||||
foreach(explode("\n", $sComment) as $sLine) {
|
||||
$asOptions[mb_strtolower(trim(mb_strstr($sLine, ':', true)))] = mb_strtolower(trim(mb_substr(mb_strstr($sLine, ':'), 1)));
|
||||
}
|
||||
@@ -189,8 +189,8 @@ class GeoJson extends Geo {
|
||||
|
||||
//Path Turn Check -> -> -> ->
|
||||
//Law of Cosines (vector): angle = arccos(OA.OB / ||OA||.||OB||)
|
||||
$fVectorOA = array('lon'=>($asPointA['lon'] - $asPointO['lon']), 'lat'=> ($asPointA['lat'] - $asPointO['lat']));
|
||||
$fVectorOB = array('lon'=>($asPointB['lon'] - $asPointO['lon']), 'lat'=> ($asPointB['lat'] - $asPointO['lat']));
|
||||
$fVectorOA = ['lon'=>($asPointA['lon'] - $asPointO['lon']), 'lat'=> ($asPointA['lat'] - $asPointO['lat'])];
|
||||
$fVectorOB = ['lon'=>($asPointB['lon'] - $asPointO['lon']), 'lat'=> ($asPointB['lat'] - $asPointO['lat'])];
|
||||
|
||||
$fLengthOA = sqrt(pow($asPointA['lon'] - $asPointO['lon'], 2) + pow($asPointA['lat'] - $asPointO['lat'], 2));
|
||||
$fLengthOB = sqrt(pow($asPointO['lon'] - $asPointB['lon'], 2) + pow($asPointO['lat'] - $asPointB['lat'], 2));
|
||||
@@ -210,10 +210,10 @@ class GeoJson extends Geo {
|
||||
}
|
||||
|
||||
private function buildGeoJson() {
|
||||
return json_encode(array('type'=>'FeatureCollection', 'features'=>$this->asTracks));
|
||||
return json_encode(['type'=>'FeatureCollection', 'features'=>$this->asTracks]);
|
||||
}
|
||||
|
||||
private static function getDistance($asPointA, $asPointB) {
|
||||
private static function getDistance($asPointA, $asPointB) {
|
||||
$fLatFrom = $asPointA[1];
|
||||
$fLonFrom = $asPointA[0];
|
||||
$fLatTo = $asPointB[1];
|
||||
|
||||
+7
-7
@@ -5,7 +5,7 @@ use Franzz\Objects\ToolBox;
|
||||
|
||||
class Gpx extends Geo {
|
||||
|
||||
const EXT = '.gpx';
|
||||
public const EXT = '.gpx';
|
||||
|
||||
public function __construct($sCodeName) {
|
||||
parent::__construct($sCodeName);
|
||||
@@ -25,21 +25,21 @@ class Gpx extends Geo {
|
||||
//Tracks
|
||||
$this->addNotice('Converting '.count($oXml->trk).' tracks');
|
||||
foreach($oXml->trk as $aoTrack) {
|
||||
$asTrack = array(
|
||||
$asTrack = [
|
||||
'name' => (string) $aoTrack->name,
|
||||
'desc' => str_replace("\n", '', ToolBox::fixEOL((strip_tags($aoTrack->desc)))),
|
||||
'cmt' => ToolBox::fixEOL((strip_tags($aoTrack->cmt))),
|
||||
'color' => (string) $aoTrack->extensions->children('gpxx', true)->TrackExtension->DisplayColor,
|
||||
'points'=> array()
|
||||
);
|
||||
'points'=> []
|
||||
];
|
||||
|
||||
foreach($aoTrack->trkseg as $asSegment) {
|
||||
foreach($asSegment as $asPoint) {
|
||||
$asTrack['points'][] = array(
|
||||
$asTrack['points'][] = [
|
||||
'lon' => (float) $asPoint['lon'],
|
||||
'lat' => (float) $asPoint['lat'],
|
||||
'ele' => (int) $asPoint->ele
|
||||
);
|
||||
];
|
||||
}
|
||||
}
|
||||
$this->asTracks[] = $asTrack;
|
||||
@@ -49,4 +49,4 @@ class Gpx extends Geo {
|
||||
$this->addNotice('Ignoring '.count($oXml->wpt).' waypoints');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+205
-217
@@ -5,7 +5,6 @@ use Franzz\Objects\Db;
|
||||
use Franzz\Objects\Main;
|
||||
use Franzz\Objects\Translator;
|
||||
use Franzz\Objects\ToolBox;
|
||||
use Franzz\Objects\Mask;
|
||||
use \Settings;
|
||||
|
||||
/* Timezones
|
||||
@@ -32,27 +31,25 @@ use \Settings;
|
||||
* - timezone: Site Timezone (stored user's timezone for emails)
|
||||
*/
|
||||
|
||||
class Livetrail extends Main
|
||||
{
|
||||
class Livetrail extends Main {
|
||||
//Database
|
||||
const POST_TABLE = 'posts';
|
||||
public const POST_TABLE = 'posts';
|
||||
|
||||
const FEED_CHUNK_SIZE = 15;
|
||||
const MAIL_CHUNK_SIZE = 5;
|
||||
private const FEED_CHUNK_SIZE = 15;
|
||||
private const MAIL_CHUNK_SIZE = 5;
|
||||
|
||||
const DEFAULT_LANG = 'en';
|
||||
const PROJECT_NAME = 'LiveTrail';
|
||||
public const DEFAULT_LANG = 'en';
|
||||
public const PROJECT_NAME = 'LiveTrail';
|
||||
|
||||
const MAIN_PAGE = 'index';
|
||||
const VITE_APP = 'src/app.js';
|
||||
private const MAIN_PAGE = 'index';
|
||||
private const VITE_APP = 'src/app.js';
|
||||
|
||||
private Project $oProject;
|
||||
private Media $oMedia;
|
||||
private User $oUser;
|
||||
private Map $oMap;
|
||||
private Map $oMap;
|
||||
|
||||
public function __construct($sProcessPage, $sTimezone)
|
||||
{
|
||||
public function __construct($sProcessPage, $sTimezone) {
|
||||
parent::__construct($sProcessPage, true, $sTimezone);
|
||||
|
||||
$this->oUser = new User($this->oDb);
|
||||
@@ -65,116 +62,114 @@ class Livetrail extends Main
|
||||
$this->oMap = new Map($this->oDb);
|
||||
}
|
||||
|
||||
protected function install()
|
||||
{
|
||||
protected function install() {
|
||||
//Install DB
|
||||
$this->oDb->install();
|
||||
|
||||
//Add first user
|
||||
$iUserId = $this->oDb->insertRow(User::USER_TABLE, array(
|
||||
$iUserId = $this->oDb->insertRow(User::USER_TABLE, [
|
||||
'name' => 'Admin',
|
||||
'email' => 'admin@admin.com',
|
||||
'language' => self::DEFAULT_LANG,
|
||||
'timezone' => date_default_timezone_get(),
|
||||
'subscribed'=> User::USER_SUBSCRIBED,
|
||||
'clearance' => User::CLEARANCE_ADMIN
|
||||
));
|
||||
]);
|
||||
$this->oUser->setUserId($iUserId);
|
||||
}
|
||||
|
||||
protected function getSqlOptions()
|
||||
{
|
||||
return array
|
||||
(
|
||||
'tables' => array
|
||||
(
|
||||
Feed::MSG_TABLE => array('ref_msg_id', Db::getId(Feed::FEED_TABLE), 'type', 'latitude', 'longitude', 'iso_time', 'site_time', 'timezone', 'unix_time', 'content', 'battery_state', 'posted_on', 'weather_icon', 'weather_cond', 'weather_temp', 'display'),
|
||||
Feed::FEED_TABLE => array('ref_feed_id', Db::getId(Feed::SPOT_TABLE), Db::getId(Project::PROJ_TABLE), 'name', 'description', 'status', 'last_update'),
|
||||
Feed::SPOT_TABLE => array('ref_spot_id', 'name', 'model'),
|
||||
Project::PROJ_TABLE => array('name', 'codename', 'active_from', 'active_to'),
|
||||
self::POST_TABLE => array(Db::getId(Project::PROJ_TABLE), Db::getId(User::USER_TABLE), 'name', 'content', 'site_time', 'timezone'),
|
||||
Media::MEDIA_TABLE => array(Db::getId(Project::PROJ_TABLE), 'filename', 'type', 'taken_on', 'posted_on', 'timezone', 'latitude', 'longitude', 'altitude', 'width', 'height', 'rotate', 'comment'),
|
||||
User::USER_TABLE => array('name', 'email', 'password', 'token', 'token_exp', 'gravatar', 'language', 'timezone', 'subscribed', 'clearance'),
|
||||
Map::MAP_TABLE => array('codename', 'pattern', 'token', 'tile_size', 'min_zoom', 'max_zoom', 'attribution'),
|
||||
Map::MAPPING_TABLE => array(Db::getId(Map::MAP_TABLE) , Db::getId(Project::PROJ_TABLE))
|
||||
),
|
||||
'types' => array
|
||||
(
|
||||
'clearance' => "TINYINT(1) DEFAULT ".User::CLEARANCE_USER,
|
||||
'active_from' => "TIMESTAMP DEFAULT 0",
|
||||
'active_to' => "TIMESTAMP DEFAULT 0",
|
||||
'battery_state' => "VARCHAR(10)",
|
||||
'codename' => "VARCHAR(100)",
|
||||
'content' => "LONGTEXT",
|
||||
'comment' => "LONGTEXT",
|
||||
'description' => "VARCHAR(100)",
|
||||
'email' => "VARCHAR(320) NOT NULL",
|
||||
'filename' => "VARCHAR(100) NOT NULL",
|
||||
'iso_time' => "VARCHAR(24)",
|
||||
'language' => "VARCHAR(2)",
|
||||
'last_update' => "TIMESTAMP DEFAULT 0",
|
||||
'latitude' => "DECIMAL(8,6)",
|
||||
'longitude' => "DECIMAL(9,6)",
|
||||
'altitude' => "SMALLINT",
|
||||
'model' => "VARCHAR(20)",
|
||||
'name' => "VARCHAR(100)",
|
||||
'pattern' => "VARCHAR(200) NOT NULL",
|
||||
protected function getSqlOptions() {
|
||||
return
|
||||
[
|
||||
'tables' =>
|
||||
[
|
||||
Feed::MSG_TABLE => ['ref_msg_id', Db::getId(Feed::FEED_TABLE), 'type', 'latitude', 'longitude', 'iso_time', 'site_time', 'timezone', 'unix_time', 'content', 'battery_state', 'posted_on', 'weather_icon', 'weather_cond', 'weather_temp', 'display'],
|
||||
Feed::FEED_TABLE => ['ref_feed_id', Db::getId(Feed::SPOT_TABLE), Db::getId(Project::PROJ_TABLE), 'name', 'description', 'status', 'last_update'],
|
||||
Feed::SPOT_TABLE => ['ref_spot_id', 'name', 'model'],
|
||||
Project::PROJ_TABLE => ['name', 'codename', 'active_from', 'active_to'],
|
||||
self::POST_TABLE => [Db::getId(Project::PROJ_TABLE), Db::getId(User::USER_TABLE), 'name', 'content', 'site_time', 'timezone'],
|
||||
Media::MEDIA_TABLE => [Db::getId(Project::PROJ_TABLE), 'filename', 'type', 'taken_on', 'posted_on', 'timezone', 'latitude', 'longitude', 'altitude', 'width', 'height', 'rotate', 'comment'],
|
||||
User::USER_TABLE => ['name', 'email', 'password', 'token', 'token_exp', 'gravatar', 'language', 'timezone', 'subscribed', 'clearance'],
|
||||
Map::MAP_TABLE => ['codename', 'pattern', 'token', 'tile_size', 'min_zoom', 'max_zoom', 'attribution'],
|
||||
Map::MAPPING_TABLE => [Db::getId(Map::MAP_TABLE) , Db::getId(Project::PROJ_TABLE)]
|
||||
],
|
||||
'types' =>
|
||||
[
|
||||
'clearance' => 'TINYINT(1) DEFAULT '.User::CLEARANCE_USER,
|
||||
'active_from' => 'TIMESTAMP DEFAULT 0',
|
||||
'active_to' => 'TIMESTAMP DEFAULT 0',
|
||||
'battery_state' => 'VARCHAR(10)',
|
||||
'codename' => 'VARCHAR(100)',
|
||||
'content' => 'LONGTEXT',
|
||||
'comment' => 'LONGTEXT',
|
||||
'description' => 'VARCHAR(100)',
|
||||
'email' => 'VARCHAR(320) NOT NULL',
|
||||
'filename' => 'VARCHAR(100) NOT NULL',
|
||||
'iso_time' => 'VARCHAR(24)',
|
||||
'language' => 'VARCHAR(2)',
|
||||
'last_update' => 'TIMESTAMP DEFAULT 0',
|
||||
'latitude' => 'DECIMAL(8,6)',
|
||||
'longitude' => 'DECIMAL(9,6)',
|
||||
'altitude' => 'SMALLINT',
|
||||
'model' => 'VARCHAR(20)',
|
||||
'name' => 'VARCHAR(100)',
|
||||
'pattern' => 'VARCHAR(200) NOT NULL',
|
||||
'password' => "VARCHAR(255) NOT NULL DEFAULT ''",
|
||||
'posted_on' => "TIMESTAMP DEFAULT 0",
|
||||
'ref_feed_id' => "VARCHAR(40)",
|
||||
'ref_msg_id' => "VARCHAR(15)",
|
||||
'ref_spot_id' => "VARCHAR(10)",
|
||||
'rotate' => "SMALLINT",
|
||||
'site_time' => "TIMESTAMP DEFAULT 0", //DEFAULT 0 removes auto-set to current time
|
||||
'status' => "VARCHAR(10)",
|
||||
'subscribed' => "BOOLEAN DEFAULT ".User::USER_UNSUBSCRIBED,
|
||||
'taken_on' => "TIMESTAMP DEFAULT 0",
|
||||
'timezone' => "CHAR(64) NOT NULL", //see mysql.time_zone_name
|
||||
'token' => "VARCHAR(4096)",
|
||||
'token_exp' => "TIMESTAMP DEFAULT 0",
|
||||
'type' => "VARCHAR(20)",
|
||||
'unix_time' => "INT",
|
||||
'min_zoom' => "TINYINT UNSIGNED",
|
||||
'max_zoom' => "TINYINT UNSIGNED",
|
||||
'attribution' => "VARCHAR(100)",
|
||||
'gravatar' => "LONGTEXT",
|
||||
'weather_icon' => "VARCHAR(30)",
|
||||
'weather_cond' => "VARCHAR(30)",
|
||||
'weather_temp' => "DECIMAL(3,1)",
|
||||
'tile_size' => "SMALLINT UNSIGNED DEFAULT 256",
|
||||
'width' => "INT",
|
||||
'height' => "INT",
|
||||
'display' => "BOOLEAN DEFAULT ".Feed::MSG_DISPLAYED
|
||||
),
|
||||
'constraints' => array
|
||||
(
|
||||
Feed::MSG_TABLE => array("UNIQUE KEY `uni_ref_msg_id` (`ref_msg_id`)", "INDEX(`ref_msg_id`)"),
|
||||
Feed::FEED_TABLE => array("UNIQUE KEY `uni_ref_feed_id` (`ref_feed_id`)", "INDEX(`ref_feed_id`)"),
|
||||
Feed::SPOT_TABLE => array("UNIQUE KEY `uni_ref_spot_id` (`ref_spot_id`)", "INDEX(`ref_spot_id`)"),
|
||||
Project::PROJ_TABLE => "UNIQUE KEY `uni_proj_name` (`codename`)",
|
||||
Media::MEDIA_TABLE => "UNIQUE KEY `uni_file_name` (`filename`)",
|
||||
User::USER_TABLE => "UNIQUE KEY `uni_email` (`email`)",
|
||||
Map::MAP_TABLE => "UNIQUE KEY `uni_map_name` (`codename`)",
|
||||
Map::MAPPING_TABLE => "default_on_generic_map_only CHECK (`default_map` = 0 OR `id_project` IS NULL)"
|
||||
),
|
||||
'cascading_delete' => array
|
||||
(
|
||||
Feed::SPOT_TABLE => array(Feed::FEED_TABLE),
|
||||
Feed::FEED_TABLE => array(Feed::MSG_TABLE),
|
||||
Project::PROJ_TABLE => array(Feed::FEED_TABLE, Media::MEDIA_TABLE, self::POST_TABLE, Map::MAPPING_TABLE),
|
||||
Map::MAP_TABLE => array(Map::MAPPING_TABLE)
|
||||
)
|
||||
);
|
||||
'posted_on' => 'TIMESTAMP DEFAULT 0',
|
||||
'ref_feed_id' => 'VARCHAR(40)',
|
||||
'ref_msg_id' => 'VARCHAR(15)',
|
||||
'ref_spot_id' => 'VARCHAR(10)',
|
||||
'rotate' => 'SMALLINT',
|
||||
'site_time' => 'TIMESTAMP DEFAULT 0', //DEFAULT 0 removes auto-set to current time
|
||||
'status' => 'VARCHAR(10)',
|
||||
'subscribed' => 'BOOLEAN DEFAULT '.User::USER_UNSUBSCRIBED,
|
||||
'taken_on' => 'TIMESTAMP DEFAULT 0',
|
||||
'timezone' => 'CHAR(64) NOT NULL', //see mysql.time_zone_name
|
||||
'token' => 'VARCHAR(4096)',
|
||||
'token_exp' => 'TIMESTAMP DEFAULT 0',
|
||||
'type' => 'VARCHAR(20)',
|
||||
'unix_time' => 'INT',
|
||||
'min_zoom' => 'TINYINT UNSIGNED',
|
||||
'max_zoom' => 'TINYINT UNSIGNED',
|
||||
'attribution' => 'VARCHAR(100)',
|
||||
'gravatar' => 'LONGTEXT',
|
||||
'weather_icon' => 'VARCHAR(30)',
|
||||
'weather_cond' => 'VARCHAR(30)',
|
||||
'weather_temp' => 'DECIMAL(3,1)',
|
||||
'tile_size' => 'SMALLINT UNSIGNED DEFAULT 256',
|
||||
'width' => 'INT',
|
||||
'height' => 'INT',
|
||||
'display' => 'BOOLEAN DEFAULT '.Feed::MSG_DISPLAYED
|
||||
],
|
||||
'constraints' =>
|
||||
[
|
||||
Feed::MSG_TABLE => ['UNIQUE KEY `uni_ref_msg_id` (`ref_msg_id`)', 'INDEX(`ref_msg_id`)'],
|
||||
Feed::FEED_TABLE => ['UNIQUE KEY `uni_ref_feed_id` (`ref_feed_id`)', 'INDEX(`ref_feed_id`)'],
|
||||
Feed::SPOT_TABLE => ['UNIQUE KEY `uni_ref_spot_id` (`ref_spot_id`)', 'INDEX(`ref_spot_id`)'],
|
||||
Project::PROJ_TABLE => 'UNIQUE KEY `uni_proj_name` (`codename`)',
|
||||
Media::MEDIA_TABLE => 'UNIQUE KEY `uni_file_name` (`filename`)',
|
||||
User::USER_TABLE => 'UNIQUE KEY `uni_email` (`email`)',
|
||||
Map::MAP_TABLE => 'UNIQUE KEY `uni_map_name` (`codename`)',
|
||||
Map::MAPPING_TABLE => 'default_on_generic_map_only CHECK (`default_map` = 0 OR `id_project` IS NULL)'
|
||||
],
|
||||
'cascading_delete' =>
|
||||
[
|
||||
Feed::SPOT_TABLE => [Feed::FEED_TABLE],
|
||||
Feed::FEED_TABLE => [Feed::MSG_TABLE],
|
||||
Project::PROJ_TABLE => [Feed::FEED_TABLE, Media::MEDIA_TABLE, self::POST_TABLE, Map::MAPPING_TABLE],
|
||||
Map::MAP_TABLE => [Map::MAPPING_TABLE]
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
public function getAppMainPage(string $sCsrfToken='') {
|
||||
$asViteAssets = $this->getViteAssets();
|
||||
|
||||
return parent::getMainPage(
|
||||
array(
|
||||
[
|
||||
'projects' => $this->oProject->getProjects(),
|
||||
'user' => $this->oUser->getUserInfo(),
|
||||
'consts' => array(
|
||||
'consts' => [
|
||||
'modes' => Project::MODES,
|
||||
'clearances' => User::CLEARANCES,
|
||||
'default_timezone' => Settings::TIMEZONE,
|
||||
@@ -184,10 +179,10 @@ class Livetrail extends Main
|
||||
'title' => self::PROJECT_NAME,
|
||||
'default_page' => 'project',
|
||||
'csrf_token' => $sCsrfToken
|
||||
)
|
||||
),
|
||||
]
|
||||
],
|
||||
self::MAIN_PAGE,
|
||||
array(
|
||||
[
|
||||
'tags' => [
|
||||
'language' => $this->oLang->getLanguage(),
|
||||
'title' => self::PROJECT_NAME,
|
||||
@@ -197,7 +192,7 @@ class Livetrail extends Main
|
||||
'css' => $asViteAssets['css'],
|
||||
'module' => $asViteAssets['module']
|
||||
]
|
||||
)
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
@@ -206,31 +201,31 @@ class Livetrail extends Main
|
||||
$asAppImport = $asManifest[self::VITE_APP];
|
||||
|
||||
//Recursive search for chunk imports
|
||||
$asImports = array();
|
||||
$asSeenImports = array(self::VITE_APP => true);
|
||||
$asImports = [];
|
||||
$asSeenImports = [self::VITE_APP => true];
|
||||
$this->appendViteImportedChunks($asManifest, $asAppImport, $asSeenImports, $asImports);
|
||||
|
||||
//CSS
|
||||
$asCssFiles = array();
|
||||
foreach(array_merge(array($asAppImport), $asImports) as $asChunk) {
|
||||
foreach($asChunk['css'] ?? array() as $sCssFile) $asCssFiles[] = $sCssFile;
|
||||
$asCssFiles = [];
|
||||
foreach(array_merge([$asAppImport], $asImports) as $asChunk) {
|
||||
foreach($asChunk['css'] ?? [] as $sCssFile) $asCssFiles[] = $sCssFile;
|
||||
}
|
||||
|
||||
//Modules
|
||||
$asModuleFiles = array();
|
||||
$asModuleFiles = [];
|
||||
foreach($asImports as $asImport) {
|
||||
if(str_ends_with($asImport['file'] ?? '', '.js')) $asModuleFiles[] = $asImport['file'];
|
||||
}
|
||||
|
||||
return array(
|
||||
return [
|
||||
'app' => $asAppImport['file'],
|
||||
'css' => $this->getViteAssetInstances($asCssFiles),
|
||||
'module' => $this->getViteAssetInstances($asModuleFiles)
|
||||
);
|
||||
];
|
||||
}
|
||||
|
||||
private function appendViteImportedChunks($asManifest, $asChunk, &$asSeenImports, &$asImports) {
|
||||
foreach($asChunk['imports'] ?? array() as $sImport) {
|
||||
foreach($asChunk['imports'] ?? [] as $sImport) {
|
||||
if(isset($asSeenImports[$sImport]) || !isset($asManifest[$sImport])) continue;
|
||||
|
||||
$asSeenImports[$sImport] = true;
|
||||
@@ -241,7 +236,7 @@ class Livetrail extends Main
|
||||
|
||||
private function getViteAssetInstances($asFilePaths) {
|
||||
return array_map(
|
||||
function($sFilePath) { return array('filename' => $sFilePath); },
|
||||
function($sFilePath) { return ['filename' => $sFilePath]; },
|
||||
$asFilePaths
|
||||
);
|
||||
}
|
||||
@@ -283,7 +278,7 @@ class Livetrail extends Main
|
||||
$oEmail->setDestInfo($this->oUser->getSubscribedUsersInfo());
|
||||
|
||||
//Add Position
|
||||
$asSpotMessages = $this->getSpotMessages(array($this->oProject->getLastMessageId($this->getFeedConstraints(Feed::MSG_TABLE))));
|
||||
$asSpotMessages = $this->getSpotMessages([$this->oProject->getLastMessageId($this->getFeedConstraints(Feed::MSG_TABLE))]);
|
||||
$asLastMessage = array_shift($asSpotMessages);
|
||||
$oEmail->oTemplate->setTags($asLastMessage);
|
||||
$oEmail->oTemplate->setTag('date_time', 'time:'.$asLastMessage['unix_time'], 'd/m/Y, H:i');
|
||||
@@ -294,11 +289,11 @@ class Livetrail extends Main
|
||||
foreach($asNews as $asPost) {
|
||||
if($asPost['type'] != 'message') {
|
||||
$oEmail->oTemplate->newInstance('news');
|
||||
$oEmail->oTemplate->setInstanceTags('news', array(
|
||||
$oEmail->oTemplate->setInstanceTags('news', [
|
||||
'local_server' => $this->asContext['serv_name'],
|
||||
'project' => $this->oProject->getProjectCodeName(),
|
||||
'type' => $asPost['type'],
|
||||
'id' => $asPost['id_'.$asPost['type']])
|
||||
'id' => $asPost['id_'.$asPost['type']]]
|
||||
);
|
||||
$oEmail->oTemplate->addInstance($asPost['type'], $asPost);
|
||||
$oEmail->oTemplate->setInstanceTag($asPost['type'], 'local_server', $this->asContext['serv_name']);
|
||||
@@ -310,8 +305,7 @@ class Livetrail extends Main
|
||||
return $oEmail->send();
|
||||
}
|
||||
|
||||
public function getMarkers($asMessageIds=array(), $asMediaIds=array(), $bInternal=false)
|
||||
{
|
||||
public function getMarkers($asMessageIds=[], $asMediaIds=[], $bInternal=false) {
|
||||
//Get messages
|
||||
$asMessages = $this->getSpotMessages($asMessageIds);
|
||||
foreach($asMessages as &$asMessage) {
|
||||
@@ -337,8 +331,8 @@ class Livetrail extends Main
|
||||
|
||||
//Assign medias to closest message
|
||||
if(!empty($asMessages)) {
|
||||
usort($asMessages, function($a, $b){return (int) $a['unix_time'] <=> (int) $b['unix_time'];});
|
||||
usort($asMedias, function($a, $b){return (int) $a['unix_time'] <=> (int) $b['unix_time'];});
|
||||
usort($asMessages, function($a, $b) {return (int) $a['unix_time'] <=> (int) $b['unix_time'];});
|
||||
usort($asMedias, function($a, $b) {return (int) $a['unix_time'] <=> (int) $b['unix_time'];});
|
||||
|
||||
$iIndex = 0;
|
||||
$iMaxIndex = count($asMessages) - 1;
|
||||
@@ -359,18 +353,18 @@ class Livetrail extends Main
|
||||
|
||||
//Combine markers
|
||||
$asMarkers = [...$asMessages, ...$asGeoMedias];
|
||||
usort($asMarkers, function($a, $b){return (int) $a['unix_time'] <=> (int) $b['unix_time'];});
|
||||
usort($asMarkers, function($a, $b) {return (int) $a['unix_time'] <=> (int) $b['unix_time'];});
|
||||
|
||||
$asResult = array(
|
||||
$asResult = [
|
||||
'markers' => $asMarkers,
|
||||
'maps' => $this->oMap->getProjectMaps($this->oProject->getProjectId())
|
||||
);
|
||||
];
|
||||
|
||||
return $bInternal?$asResult:self::getJsonResult(true, '', $asResult);
|
||||
}
|
||||
|
||||
public function getLastUpdate() {
|
||||
$asLastUpdate = array();
|
||||
$asLastUpdate = [];
|
||||
$this->addTimeStamp($asLastUpdate, $this->oProject->getLastUpdate());
|
||||
return self::getJsonResult(true, '', $asLastUpdate);
|
||||
}
|
||||
@@ -403,30 +397,28 @@ class Livetrail extends Main
|
||||
return self::getJsonResult($asResult['result'], $asResult['desc_lang_id'], $this->oUser->getUserInfo(), $asResult['desc_lang_params']);
|
||||
}
|
||||
|
||||
private function getSpotMessages($asMsgIds=array())
|
||||
{
|
||||
private function getSpotMessages($asMsgIds=[]) {
|
||||
$asConstraints = $this->getFeedConstraints(Feed::MSG_TABLE);
|
||||
if(!empty($asMsgIds)) {
|
||||
$asConstraints['constraint'][Db::getId(Feed::MSG_TABLE)] = $asMsgIds;
|
||||
$asConstraints['constOpe'][Db::getId(Feed::MSG_TABLE)] = 'IN';
|
||||
}
|
||||
|
||||
$asCombinedMessages = array();
|
||||
$asCombinedMessages = [];
|
||||
|
||||
//Get messages from all feeds belonging to the project
|
||||
$asFeeds = $this->oProject->getFeedIds();
|
||||
foreach($asFeeds as $iFeedId) {
|
||||
$oFeed = new Feed($this->oDb, $iFeedId);
|
||||
$asMessages = $oFeed->getMessages($asConstraints);
|
||||
foreach($asMessages as $asMessage)
|
||||
{
|
||||
foreach($asMessages as $asMessage) {
|
||||
$asMessage['latitude'] = floatval($asMessage['latitude']);
|
||||
$asMessage['longitude'] = floatval($asMessage['longitude']);
|
||||
$asMessage['lat_dms'] = self::decToDms($asMessage['latitude'], 'lat');
|
||||
$asMessage['lon_dms'] = self::decToDms($asMessage['longitude'], 'lon');
|
||||
$asMessage['displayed_id'] = $asMessage[Db::getId(Feed::MSG_TABLE)];
|
||||
$asMessage['static_img_url'] = $this->oMap->getMapUrl('static', array('x'=>$asMessage['longitude'], 'y'=>$asMessage['latitude']));
|
||||
$asMessage['marker_img_url'] = $this->oMap->getMapUrl('static_marker', array('x'=>$asMessage['longitude'], 'y'=>$asMessage['latitude']));
|
||||
$asMessage['static_img_url'] = $this->oMap->getMapUrl('static', ['x'=>$asMessage['longitude'], 'y'=>$asMessage['latitude']]);
|
||||
$asMessage['marker_img_url'] = $this->oMap->getMapUrl('static_marker', ['x'=>$asMessage['longitude'], 'y'=>$asMessage['latitude']]);
|
||||
|
||||
$this->addTimeStamp($asMessage, $asMessage['unix_time'], $asMessage['timezone']);
|
||||
$asCombinedMessages[] = $asMessage;
|
||||
@@ -443,8 +435,7 @@ class Livetrail extends Main
|
||||
* @param String $sTimeRefField Field to calculate relative times: 'taken_on' or 'posted_on'
|
||||
* @return Array Medias info
|
||||
*/
|
||||
private function getMedias($sTimeRefField, $asMediaIds=array(), $bOnlyGeoMedia=false)
|
||||
{
|
||||
private function getMedias($sTimeRefField, $asMediaIds=[], $bOnlyGeoMedia=false) {
|
||||
//Constraints
|
||||
$asConstraints = $this->getFeedConstraints(Media::MEDIA_TABLE, $sTimeRefField);
|
||||
if(!empty($asMediaIds)) {
|
||||
@@ -478,13 +469,12 @@ class Livetrail extends Main
|
||||
return $asMedias;
|
||||
}
|
||||
|
||||
private function getPosts($asPostIds=array())
|
||||
{
|
||||
$asInfo = array(
|
||||
'select' => array(Db::getFullColumnName(self::POST_TABLE, '*'), 'gravatar'),
|
||||
private function getPosts($asPostIds=[]) {
|
||||
$asInfo = [
|
||||
'select' => [Db::getFullColumnName(self::POST_TABLE, '*'), 'gravatar'],
|
||||
'from' => self::POST_TABLE,
|
||||
'join' => array(User::USER_TABLE => Db::getId(User::USER_TABLE))
|
||||
);
|
||||
'join' => [User::USER_TABLE => Db::getId(User::USER_TABLE)]
|
||||
];
|
||||
$asInfo = array_merge($asInfo, $this->getFeedConstraints(self::POST_TABLE));
|
||||
|
||||
if(!empty($asPostIds)) {
|
||||
@@ -518,35 +508,35 @@ class Livetrail extends Main
|
||||
}
|
||||
|
||||
private function getFeedConstraints($sType, $sTimeField='site_time', $sReturnFormat='array') {
|
||||
$asConsArray = array();
|
||||
$sConsSql = "";
|
||||
$asConsArray = [];
|
||||
$sConsSql = '';
|
||||
$asActPeriod = $this->oProject->getActivePeriod();
|
||||
|
||||
//Filter on Project ID
|
||||
$sConsSql = "WHERE ".Db::getId(Project::PROJ_TABLE)." = ".$this->oProject->getProjectId();
|
||||
$asConsArray = array(
|
||||
'constraint'=> array(Db::getId(Project::PROJ_TABLE) => $this->oProject->getProjectId()),
|
||||
'constOpe' => array(Db::getId(Project::PROJ_TABLE) => "=")
|
||||
);
|
||||
$sConsSql = 'WHERE '.Db::getId(Project::PROJ_TABLE).' = '.$this->oProject->getProjectId();
|
||||
$asConsArray = [
|
||||
'constraint'=> [Db::getId(Project::PROJ_TABLE) => $this->oProject->getProjectId()],
|
||||
'constOpe' => [Db::getId(Project::PROJ_TABLE) => '=']
|
||||
];
|
||||
|
||||
//Time Filter
|
||||
switch($sType) {
|
||||
case Feed::MSG_TABLE:
|
||||
$asConsArray['constraint'][$sTimeField] = $asActPeriod;
|
||||
$asConsArray['constOpe'][$sTimeField] = "BETWEEN";
|
||||
$asConsArray['constOpe'][$sTimeField] = 'BETWEEN';
|
||||
$asConsArray['constraint']['display'] = Feed::MSG_DISPLAYED;
|
||||
$asConsArray['constOpe']['display'] = "=";
|
||||
$sConsSql .= " AND ".$sTimeField." BETWEEN '".$asActPeriod['from']."' AND '".$asActPeriod['to']."' AND display = ".Feed::MSG_DISPLAYED;
|
||||
$asConsArray['constOpe']['display'] = '=';
|
||||
$sConsSql .= ' AND '.$sTimeField." BETWEEN '".$asActPeriod['from']."' AND '".$asActPeriod['to']."' AND display = ".Feed::MSG_DISPLAYED;
|
||||
break;
|
||||
case Media::MEDIA_TABLE:
|
||||
$asConsArray['constraint'][$sTimeField] = $asActPeriod['to'];
|
||||
$asConsArray['constOpe'][$sTimeField] = "<=";
|
||||
$sConsSql .= " AND ".$sTimeField." <= '".$asActPeriod['to']."'";
|
||||
$asConsArray['constOpe'][$sTimeField] = '<=';
|
||||
$sConsSql .= ' AND '.$sTimeField." <= '".$asActPeriod['to']."'";
|
||||
break;
|
||||
case self::POST_TABLE:
|
||||
$asConsArray['constraint'][$sTimeField] = $asActPeriod['to'];
|
||||
$asConsArray['constOpe'][$sTimeField] = "<=";
|
||||
$sConsSql .= " AND ".$sTimeField." <= '".$asActPeriod['to']."'";
|
||||
$asConsArray['constOpe'][$sTimeField] = '<=';
|
||||
$sConsSql .= ' AND '.$sTimeField." <= '".$asActPeriod['to']."'";
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -554,14 +544,14 @@ class Livetrail extends Main
|
||||
}
|
||||
|
||||
public function getNewFeed($iRefIdFirst) {
|
||||
$asResult = array();
|
||||
$asResult = [];
|
||||
$sLangId = '';
|
||||
|
||||
if($this->oProject->isEditable()) {
|
||||
$asMessageIds = $asMediaIds = array();
|
||||
$asMessageIds = $asMediaIds = [];
|
||||
|
||||
//New Feed Items
|
||||
$asResult = $this->getFeed($iRefIdFirst, ">", "DESC");
|
||||
$asResult = $this->getFeed($iRefIdFirst, '>', 'DESC');
|
||||
foreach($asResult['feed'] as $asItem) {
|
||||
switch($asItem['type']) {
|
||||
case 'message':
|
||||
@@ -575,8 +565,8 @@ class Livetrail extends Main
|
||||
|
||||
//New Markers
|
||||
$asMarkers = $this->getMarkers(
|
||||
empty($asMessageIds)?array(0):$asMessageIds,
|
||||
empty($asMediaIds)?array(0):$asMediaIds,
|
||||
empty($asMessageIds)?[0]:$asMessageIds,
|
||||
empty($asMediaIds)?[0]:$asMediaIds,
|
||||
true
|
||||
);
|
||||
|
||||
@@ -589,12 +579,12 @@ class Livetrail extends Main
|
||||
|
||||
public function getNextFeed($iRefIdLast=0, $bInternal=false) {
|
||||
if($this->oProject->getMode() == Project::MODE_HISTO) {
|
||||
$sDirection = ">";
|
||||
$sSort = "ASC";
|
||||
$sDirection = '>';
|
||||
$sSort = 'ASC';
|
||||
}
|
||||
else {
|
||||
$sDirection = "<";
|
||||
$sSort = "DESC";
|
||||
$sDirection = '<';
|
||||
$sSort = 'DESC';
|
||||
}
|
||||
$asResult = $this->getFeed($iRefIdLast, $sDirection, $sSort);
|
||||
return $bInternal?$asResult['feed']:self::getJsonResult(true, '', $asResult);
|
||||
@@ -610,26 +600,26 @@ class Livetrail extends Main
|
||||
$sMediaIdField = Db::getId(Media::MEDIA_TABLE);
|
||||
$sPostIdField = Db::getId(self::POST_TABLE);
|
||||
$sFeedIdField = Db::getId(Feed::FEED_TABLE);
|
||||
$sQuery = implode(" ", array(
|
||||
"SELECT type, id, ref",
|
||||
"FROM (",
|
||||
$sQuery = implode(' ', [
|
||||
'SELECT type, id, ref',
|
||||
'FROM (',
|
||||
"SELECT {$sProjectIdField}, {$sMsgIdField} AS id, 'message' AS type, CONCAT(UNIX_TIMESTAMP(site_time), '.0', {$sMsgIdField}) AS ref",
|
||||
"FROM ".Feed::MSG_TABLE,
|
||||
"INNER JOIN ".Feed::FEED_TABLE." USING({$sFeedIdField})",
|
||||
'FROM '.Feed::MSG_TABLE,
|
||||
'INNER JOIN '.Feed::FEED_TABLE." USING({$sFeedIdField})",
|
||||
$this->getFeedConstraints(Feed::MSG_TABLE, 'site_time', 'sql'),
|
||||
"UNION",
|
||||
'UNION',
|
||||
"SELECT {$sProjectIdField}, {$sMediaIdField} AS id, 'media' AS type, CONCAT(UNIX_TIMESTAMP(posted_on), '.1', {$sMediaIdField}) AS ref",
|
||||
"FROM ".Media::MEDIA_TABLE,
|
||||
'FROM '.Media::MEDIA_TABLE,
|
||||
$this->getFeedConstraints(Media::MEDIA_TABLE, 'posted_on', 'sql'),
|
||||
"UNION",
|
||||
'UNION',
|
||||
"SELECT {$sProjectIdField}, {$sPostIdField} AS id, 'post' AS type, CONCAT(UNIX_TIMESTAMP(site_time), '.2', {$sPostIdField}) AS ref",
|
||||
"FROM ".self::POST_TABLE,
|
||||
'FROM '.self::POST_TABLE,
|
||||
$this->getFeedConstraints(self::POST_TABLE, 'site_time', 'sql'),
|
||||
") AS items",
|
||||
($sRefId !== '0')?("WHERE ref ".$sDirection." ".$sRefId):"",
|
||||
"ORDER BY ref ".$sSort,
|
||||
"LIMIT ".self::FEED_CHUNK_SIZE
|
||||
));
|
||||
') AS items',
|
||||
($sRefId !== '0')?('WHERE ref '.$sDirection.' '.$sRefId):'',
|
||||
'ORDER BY ref '.$sSort,
|
||||
'LIMIT '.self::FEED_CHUNK_SIZE
|
||||
]);
|
||||
|
||||
//Get new chunk
|
||||
$asItems = $this->oDb->getArrayQuery($sQuery, true);
|
||||
@@ -642,22 +632,22 @@ class Livetrail extends Main
|
||||
}
|
||||
|
||||
//Sort Table IDs by type & Get attributes
|
||||
$asFeedIds = array('message'=>array(), 'media'=>array(), 'post'=>array());
|
||||
$asFeedIds = ['message'=>[], 'media'=>[], 'post'=>[]];
|
||||
foreach($asItems as $asItem) {
|
||||
$asFeedIds[$asItem['type']][$asItem['id']] = $asItem;
|
||||
}
|
||||
$asFeedAttrs = array(
|
||||
'message' => empty($asFeedIds['message'])?array():$this->getSpotMessages(array_keys($asFeedIds['message'])),
|
||||
'media' => empty($asFeedIds['media'])?array():$this->getMedias('posted_on', array_keys($asFeedIds['media'])),
|
||||
'post' => empty($asFeedIds['post'])?array():$this->getPosts(array_keys($asFeedIds['post']))
|
||||
);
|
||||
$asFeedAttrs = [
|
||||
'message' => empty($asFeedIds['message'])?[]:$this->getSpotMessages(array_keys($asFeedIds['message'])),
|
||||
'media' => empty($asFeedIds['media'])?[]:$this->getMedias('posted_on', array_keys($asFeedIds['media'])),
|
||||
'post' => empty($asFeedIds['post'])?[]:$this->getPosts(array_keys($asFeedIds['post']))
|
||||
];
|
||||
|
||||
//Replace Array Key with Item ID
|
||||
$asFeeds = array();
|
||||
$asFeeds = [];
|
||||
foreach($asFeedAttrs as $sType=>$asFeedAttr) {
|
||||
foreach($asFeedAttr as $asFeed) {
|
||||
$asFeeds[$sType][$asFeed['id_'.$sType]] = $asFeed;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//Assign
|
||||
@@ -665,22 +655,21 @@ class Livetrail extends Main
|
||||
$asItem = array_merge($asFeeds[$asItem['type']][$asItem['id']], $asItem);
|
||||
}
|
||||
|
||||
return array('ref_id_last'=>$iRefIdLast, 'ref_id_first'=>$iRefIdFirst, 'sort'=>$sSort, 'feed'=>$asItems);
|
||||
return ['ref_id_last'=>$iRefIdLast, 'ref_id_first'=>$iRefIdFirst, 'sort'=>$sSort, 'feed'=>$asItems];
|
||||
}
|
||||
|
||||
public function addPost($sName, $sPost)
|
||||
{
|
||||
public function addPost($sName, $sPost) {
|
||||
$iPostId = 0;
|
||||
$sLangId = '';
|
||||
|
||||
if($this->oProject->isEditable()) {
|
||||
$asData = array(
|
||||
$asData = [
|
||||
Db::getId(Project::PROJ_TABLE) => $this->oProject->getProjectId(),
|
||||
'name' => mb_strtolower(trim($sName)),
|
||||
'content' => trim($sPost),
|
||||
'site_time' => date(Db::TIMESTAMP_FORMAT), //Now in Site Time
|
||||
'timezone' => date_default_timezone_get() //Site Time Zone
|
||||
);
|
||||
];
|
||||
if($this->oUser->getUserId() > 0) $asData[Db::getId(User::USER_TABLE)] = $this->oUser->getUserId();
|
||||
|
||||
$iPostId = $this->oDb->insertRow(self::POST_TABLE, $asData);
|
||||
@@ -693,8 +682,7 @@ class Livetrail extends Main
|
||||
return self::getJsonResult(($iPostId > 0), $sLangId);
|
||||
}
|
||||
|
||||
public function upload()
|
||||
{
|
||||
public function upload() {
|
||||
$oUploader = new Uploader($this->oMedia);
|
||||
|
||||
return $oUploader->sBody;
|
||||
@@ -721,12 +709,12 @@ class Livetrail extends Main
|
||||
|
||||
public function getAdminSettings() {
|
||||
$oFeed = new Feed($this->oDb);
|
||||
$asData = array(
|
||||
$asData = [
|
||||
'project' => $this->oProject->getProjects(),
|
||||
'feed' => $oFeed->getFeeds(),
|
||||
'spot' => $oFeed->getSpots(),
|
||||
'user' => $this->oUser->getSubscribedUsersInfo()
|
||||
);
|
||||
];
|
||||
|
||||
foreach($asData['project'] as &$asProject) {
|
||||
$asProject['active_from'] = substr($asProject['active_from'], 0, 10);
|
||||
@@ -739,10 +727,10 @@ class Livetrail extends Main
|
||||
public function setAdminSettings($sType, $iId, $sField, $sValue) {
|
||||
$bSuccess = false;
|
||||
$sLangId = '';
|
||||
$asLangParams = array();
|
||||
$asResult = array();
|
||||
$asLangParams = [];
|
||||
$asResult = [];
|
||||
|
||||
if($this->oDb->isId($sField) && $sValue <= 0) return self::getJsonResult(false, 'error.impossible_value', array(), array($sValue, $sField));
|
||||
if($this->oDb->isId($sField) && $sValue <= 0) return self::getJsonResult(false, 'error.impossible_value', [], [$sValue, $sField]);
|
||||
|
||||
switch($sType) {
|
||||
case 'project':
|
||||
@@ -763,7 +751,7 @@ class Livetrail extends Main
|
||||
break;
|
||||
default:
|
||||
$sLangId = 'error.unknown_field';
|
||||
$asLangParams = array($sField);
|
||||
$asLangParams = [$sField];
|
||||
}
|
||||
|
||||
//Identify missing GPX file
|
||||
@@ -771,7 +759,7 @@ class Livetrail extends Main
|
||||
if(!Converter::hasGpxFile($sProjectCodeName)) {
|
||||
$bSuccess = true;
|
||||
$sLangId = 'error.file_missing';
|
||||
$asLangParams = array('GPX', $sProjectCodeName.Gpx::EXT);
|
||||
$asLangParams = ['GPX', $sProjectCodeName.Gpx::EXT];
|
||||
}
|
||||
|
||||
$asResult = $oProject->getProject();
|
||||
@@ -792,7 +780,7 @@ class Livetrail extends Main
|
||||
break;
|
||||
default:
|
||||
$sLangId = 'error.unknown_field';
|
||||
$asLangParams = array($sField);
|
||||
$asLangParams = [$sField];
|
||||
}
|
||||
$asResult = $oFeed->getFeed();
|
||||
break;
|
||||
@@ -806,20 +794,20 @@ class Livetrail extends Main
|
||||
break;
|
||||
default:
|
||||
$sLangId = 'error.unknown_field';
|
||||
$asLangParams = array($sField);
|
||||
$asLangParams = [$sField];
|
||||
}
|
||||
$asResult = $this->oUser->getUserById($iId);
|
||||
break;
|
||||
}
|
||||
if(!$bSuccess && $sLangId=='') $sLangId = 'error.commit_db';
|
||||
|
||||
return self::getJsonResult($bSuccess, $sLangId, array($sType=>array($asResult)), $asLangParams);
|
||||
return self::getJsonResult($bSuccess, $sLangId, [$sType=>[$asResult]], $asLangParams);
|
||||
}
|
||||
|
||||
public function createAdminSettings($sType) {
|
||||
$bSuccess = false;
|
||||
$sLangId = '';
|
||||
$asResult = array();
|
||||
$asResult = [];
|
||||
|
||||
switch($sType) {
|
||||
case 'project':
|
||||
@@ -830,18 +818,18 @@ class Livetrail extends Main
|
||||
$oFeed->createFeedId($iNewProjectId);
|
||||
|
||||
$bSuccess = $iNewProjectId > 0;
|
||||
$asResult = array(
|
||||
'project' => array($oProject->getProject()),
|
||||
'feed' => array($oFeed->getFeed())
|
||||
);
|
||||
$asResult = [
|
||||
'project' => [$oProject->getProject()],
|
||||
'feed' => [$oFeed->getFeed()]
|
||||
];
|
||||
break;
|
||||
case 'feed':
|
||||
$oFeed = new Feed($this->oDb);
|
||||
$iNewFeedId = $oFeed->createFeedId($this->oProject->getProjectId());
|
||||
$bSuccess = $iNewFeedId > 0;
|
||||
$asResult = array(
|
||||
'feed' => array($oFeed->getFeed())
|
||||
);
|
||||
$asResult = [
|
||||
'feed' => [$oFeed->getFeed()]
|
||||
];
|
||||
break;
|
||||
}
|
||||
if(!$bSuccess && $sLangId=='') $sLangId = 'error.commit_db';
|
||||
@@ -852,8 +840,8 @@ class Livetrail extends Main
|
||||
public function deleteAdminSettings($sType, $iId) {
|
||||
$bSuccess = false;
|
||||
$sLangId = '';
|
||||
$asLangParams = array();
|
||||
$asResult = array();
|
||||
$asLangParams = [];
|
||||
$asResult = [];
|
||||
|
||||
switch($sType) {
|
||||
case 'project':
|
||||
@@ -865,7 +853,7 @@ class Livetrail extends Main
|
||||
break;
|
||||
case 'feed':
|
||||
$oFeed = new Feed($this->oDb, $iId);
|
||||
$asResult = array('feed' => array($oFeed->delete()));
|
||||
$asResult = ['feed' => [$oFeed->delete()]];
|
||||
$sLangId = $asResult['feed'][0]['desc_lang_id'];
|
||||
$asLangParams = $asResult['feed'][0]['desc_lang_params'];
|
||||
$bSuccess = $asResult['feed'][0]['result'];
|
||||
@@ -900,8 +888,8 @@ class Livetrail extends Main
|
||||
$sDirection;
|
||||
}
|
||||
|
||||
public static function getNumberWithLeadingZeros($fValue, $iNbLeadingZeros, $iNbDigits){
|
||||
$sDecimalSeparator = ".";
|
||||
public static function getNumberWithLeadingZeros($fValue, $iNbLeadingZeros, $iNbDigits) {
|
||||
$sDecimalSeparator = '.';
|
||||
if($iNbDigits > 0) $iNbLeadingZeros += mb_strlen($sDecimalSeparator) + $iNbDigits;
|
||||
$sPattern = '%0'.$iNbLeadingZeros.$sDecimalSeparator.$iNbDigits.'f';
|
||||
return sprintf($sPattern, $fValue);
|
||||
@@ -915,7 +903,7 @@ class Livetrail extends Main
|
||||
|
||||
$sDate = $oDate->format('d/m/Y');
|
||||
$sTime = $oDate->format('H:i');
|
||||
return $this->oLang->getTranslation('time.date_time', array($sDate, $sTime));
|
||||
return $this->oLang->getTranslation('time.date_time', [$sDate, $sTime]);
|
||||
}
|
||||
|
||||
public static function getTimeZoneDayOffset($iTime, $sLocalTimeZone) {
|
||||
|
||||
+9
-9
@@ -6,8 +6,8 @@ use Franzz\Objects\Db;
|
||||
|
||||
class Map extends PhpObject {
|
||||
|
||||
const MAP_TABLE = 'maps';
|
||||
const MAPPING_TABLE = 'mappings';
|
||||
public const MAP_TABLE = 'maps';
|
||||
public const MAPPING_TABLE = 'mappings';
|
||||
|
||||
private Db $oDb;
|
||||
private $asMaps;
|
||||
@@ -15,11 +15,11 @@ class Map extends PhpObject {
|
||||
public function __construct(Db &$oDb) {
|
||||
parent::__construct(__CLASS__);
|
||||
$this->oDb = &$oDb;
|
||||
$this->asMaps = array();
|
||||
$this->asMaps = [];
|
||||
}
|
||||
|
||||
private function setMaps() {
|
||||
$asMaps = $this->oDb->selectRows(array('from'=>self::MAP_TABLE));
|
||||
$asMaps = $this->oDb->selectRows(['from'=>self::MAP_TABLE]);
|
||||
foreach($asMaps as $asMap) $this->asMaps[$asMap['codename']] = $asMap;
|
||||
}
|
||||
|
||||
@@ -30,15 +30,15 @@ class Map extends PhpObject {
|
||||
|
||||
public function getProjectMaps($iProjectId) {
|
||||
$asMappings = $this->oDb->selectRows(
|
||||
array(
|
||||
'select' => array(Db::getId(self::MAP_TABLE), 'default_map'),
|
||||
[
|
||||
'select' => [Db::getId(self::MAP_TABLE), 'default_map'],
|
||||
'from' => self::MAPPING_TABLE,
|
||||
'constraint'=> array("IFNULL(id_project, {$iProjectId})" => $iProjectId)
|
||||
),
|
||||
'constraint'=> ["IFNULL(id_project, {$iProjectId})" => $iProjectId]
|
||||
],
|
||||
Db::getId(self::MAP_TABLE)
|
||||
);
|
||||
|
||||
$asProjectMaps = array();
|
||||
$asProjectMaps = [];
|
||||
foreach($this->getMaps() as $asMap) {
|
||||
if(array_key_exists($asMap['id_map'], $asMappings)) {
|
||||
$asMap['default_map'] = $asMappings[$asMap['id_map']];
|
||||
|
||||
+31
-34
@@ -8,13 +8,13 @@ use Franzz\Objects\ToolBox;
|
||||
class Media extends PhpObject {
|
||||
|
||||
//DB Tables
|
||||
const MEDIA_TABLE = 'medias';
|
||||
public const MEDIA_TABLE = 'medias';
|
||||
|
||||
//Media folders (works because /public/files is a symlink of /files)
|
||||
const MEDIA_FOLDER = 'files';
|
||||
const THUMB_FOLDER = self::MEDIA_FOLDER.'/thumbs';
|
||||
public const MEDIA_FOLDER = 'files';
|
||||
public const THUMB_FOLDER = self::MEDIA_FOLDER.'/thumbs';
|
||||
|
||||
const THUMB_MAX_WIDTH = 400;
|
||||
private const THUMB_MAX_WIDTH = 400;
|
||||
|
||||
private Db $oDb;
|
||||
private Project $oProject;
|
||||
@@ -27,8 +27,8 @@ class Media extends PhpObject {
|
||||
parent::__construct(__CLASS__);
|
||||
$this->oDb = &$oDb;
|
||||
$this->oProject = &$oProject;
|
||||
$this->asMedia = array();
|
||||
$this->asMedias = array();
|
||||
$this->asMedia = [];
|
||||
$this->asMedias = [];
|
||||
$this->setMediaId($iMediaId);
|
||||
}
|
||||
|
||||
@@ -46,9 +46,9 @@ class Media extends PhpObject {
|
||||
|
||||
public function setComment($sComment) {
|
||||
$sLangId = '';
|
||||
$asData = array();
|
||||
$asData = [];
|
||||
if($this->iMediaId > 0) {
|
||||
$bResult = $this->oDb->updateRow(self::MEDIA_TABLE, $this->iMediaId, array('comment'=>$sComment));
|
||||
$bResult = $this->oDb->updateRow(self::MEDIA_TABLE, $this->iMediaId, ['comment'=>$sComment]);
|
||||
if(!$bResult) $sLangId = 'error.commit_db';
|
||||
else $asData = $this->getInfo();
|
||||
}
|
||||
@@ -63,11 +63,11 @@ class Media extends PhpObject {
|
||||
|
||||
if($bOwnMedia && empty($this->asMedia) || !$bOwnMedia && empty($this->asMedias) || $bConstraintArray) {
|
||||
if($this->oProject->getProjectId()) {
|
||||
$asParams = array(
|
||||
'select' => array(Db::getId(self::MEDIA_TABLE), 'filename', 'taken_on', 'posted_on', 'timezone', 'latitude', 'longitude', 'altitude', 'width', 'height', 'rotate', 'type AS subtype', 'comment'),
|
||||
$asParams = [
|
||||
'select' => [Db::getId(self::MEDIA_TABLE), 'filename', 'taken_on', 'posted_on', 'timezone', 'latitude', 'longitude', 'altitude', 'width', 'height', 'rotate', 'type AS subtype', 'comment'],
|
||||
'from' => self::MEDIA_TABLE,
|
||||
'constraint'=> array(Db::getId(Project::PROJ_TABLE) => $this->oProject->getProjectId())
|
||||
);
|
||||
'constraint'=> [Db::getId(Project::PROJ_TABLE) => $this->oProject->getProjectId()]
|
||||
];
|
||||
if($bOwnMedia) $asParams['constraint'][Db::getId(self::MEDIA_TABLE)] = $oMediaIds;
|
||||
if($bConstraintArray) $asParams = array_merge($asParams, $oMediaIds);
|
||||
|
||||
@@ -96,12 +96,12 @@ class Media extends PhpObject {
|
||||
|
||||
public function addMedia($sMediaName, $sMethod='upload') {
|
||||
$sLangId = '';
|
||||
$asParams = array();
|
||||
$asParams = [];
|
||||
if(!$this->isProjectEditable() && $sMethod!='sync') {
|
||||
$sLangId = 'upload.mode_archived';
|
||||
$asParams[] = $this->oProject->getProjectCodeName();
|
||||
}
|
||||
elseif($this->oDb->pingValue(self::MEDIA_TABLE, array('filename'=>$sMediaName)) && $sMethod!='sync') {
|
||||
elseif($this->oDb->pingValue(self::MEDIA_TABLE, ['filename'=>$sMediaName]) && $sMethod!='sync') {
|
||||
$sLangId = 'upload.media.exists';
|
||||
$asParams[] = $sMediaName;
|
||||
}
|
||||
@@ -110,7 +110,7 @@ class Media extends PhpObject {
|
||||
|
||||
//Converting times to Site Time Zone, by using date()
|
||||
//Media Timezone is kept in a separate field for later conversion to Local Time
|
||||
$asDbInfo = array(
|
||||
$asDbInfo = [
|
||||
Db::getId(Project::PROJ_TABLE) => $this->oProject->getProjectId(),
|
||||
'filename' => $sMediaName,
|
||||
'taken_on' => date(Db::TIMESTAMP_FORMAT, ($asMediaInfo['taken_ts'] > 0)?$asMediaInfo['taken_ts']:$asMediaInfo['file_ts']),
|
||||
@@ -123,9 +123,9 @@ class Media extends PhpObject {
|
||||
'height' => $asMediaInfo['height'],
|
||||
'rotate' => $asMediaInfo['rotate'],
|
||||
'type' => $asMediaInfo['type']
|
||||
);
|
||||
];
|
||||
|
||||
if($sMethod=='sync') $iMediaId = $this->oDb->insertUpdateRow(self::MEDIA_TABLE, $asDbInfo, array('filename'));
|
||||
if($sMethod=='sync') $iMediaId = $this->oDb->insertUpdateRow(self::MEDIA_TABLE, $asDbInfo, ['filename']);
|
||||
else $iMediaId = $this->oDb->insertRow(self::MEDIA_TABLE, $asDbInfo);
|
||||
|
||||
if(!$iMediaId) $sLangId = 'error.commit_db';
|
||||
@@ -138,8 +138,7 @@ class Media extends PhpObject {
|
||||
return Livetrail::getResult(($sLangId==''), $sLangId, $asParams);
|
||||
}
|
||||
|
||||
private function getMediaInfoFromFile($sMediaName)
|
||||
{
|
||||
private function getMediaInfoFromFile($sMediaName) {
|
||||
$sMediaPath = self::getMediaPath($sMediaName);
|
||||
$sType = self::getMediaType($sMediaName);
|
||||
$iPostedOn = filemtime($sMediaPath);
|
||||
@@ -153,8 +152,8 @@ class Media extends PhpObject {
|
||||
$iAlt = null;
|
||||
switch($sType) {
|
||||
case 'video':
|
||||
$asResult = array();
|
||||
$sParams = implode(' ', array(
|
||||
$asResult = [];
|
||||
$sParams = implode(' ', [
|
||||
'-loglevel error', //Remove comments
|
||||
'-select_streams v:0', //First video channel
|
||||
'-show_entries '. //filter tags : Width, Height, Creation Time, Location & Rotation
|
||||
@@ -163,7 +162,7 @@ class Media extends PhpObject {
|
||||
'stream=width,height',
|
||||
'-print_format json', //output format: json
|
||||
'-i' //input file
|
||||
));
|
||||
]);
|
||||
exec('ffprobe '.$sParams.' '.escapeshellarg($sMediaPath), $asResult);
|
||||
$asExif = json_decode(implode('', $asResult), true);
|
||||
|
||||
@@ -188,7 +187,7 @@ class Media extends PhpObject {
|
||||
break;
|
||||
case 'image':
|
||||
$asExif = @exif_read_data($sMediaPath, 0, true);
|
||||
if($asExif === false) $asExif = array();
|
||||
if($asExif === false) $asExif = [];
|
||||
list($iWidth, $iHeight) = getimagesize($sMediaPath);
|
||||
|
||||
//Posted On
|
||||
@@ -217,8 +216,7 @@ class Media extends PhpObject {
|
||||
|
||||
//Orientation
|
||||
if(array_key_exists('IFD0', $asExif) && array_key_exists('Orientation', $asExif['IFD0'])) {
|
||||
switch($asExif['IFD0']['Orientation'])
|
||||
{
|
||||
switch($asExif['IFD0']['Orientation']) {
|
||||
case 1: $sRotate = '0'; break; //None
|
||||
case 3: $sRotate = '180'; break; //Flip over
|
||||
case 6: $sRotate = '90'; break; //Clockwise
|
||||
@@ -236,7 +234,7 @@ class Media extends PhpObject {
|
||||
$iTakenOn = $oTakenOn->format('U');
|
||||
}
|
||||
|
||||
return array(
|
||||
return [
|
||||
'timezone' => $sTimeZone,
|
||||
'latitude' => $fLat,
|
||||
'longitude' => $fLng,
|
||||
@@ -247,11 +245,10 @@ class Media extends PhpObject {
|
||||
'height' => $iHeight,
|
||||
'rotate' => $sRotate,
|
||||
'type' => $sType
|
||||
);
|
||||
];
|
||||
}
|
||||
|
||||
private function getMediaThumbnail($sMediaName)
|
||||
{
|
||||
private function getMediaThumbnail($sMediaName) {
|
||||
$sMediaPath = self::getMediaPath($sMediaName);
|
||||
$sThumbPath = self::getMediaPath($sMediaName, 'thumbnail');
|
||||
|
||||
@@ -264,13 +261,13 @@ class Media extends PhpObject {
|
||||
case 'video':
|
||||
//Get a screenshot of the video 1 second in
|
||||
$sTempPath = self::getMediaPath(uniqid('temp_').'.png');
|
||||
$asResult = array();
|
||||
$sParams = implode(' ', array(
|
||||
$asResult = [];
|
||||
$sParams = implode(' ', [
|
||||
'-i '.escapeshellarg($sMediaPath), //input file
|
||||
'-ss 00:00:01.000', //Image taken after x seconds
|
||||
'-vframes 1', //number of video frames to output
|
||||
escapeshellarg($sTempPath), //output file
|
||||
));
|
||||
]);
|
||||
exec('ffmpeg '.$sParams, $asResult);
|
||||
|
||||
//Resize
|
||||
@@ -279,7 +276,7 @@ class Media extends PhpObject {
|
||||
}
|
||||
|
||||
}
|
||||
else $asThumbInfo = array('error'=>'', 'out'=>$sThumbPath);
|
||||
else $asThumbInfo = ['error'=>'', 'out'=>$sThumbPath];
|
||||
|
||||
return ($asThumbInfo['error']=='')?$asThumbInfo['out']:$sMediaPath;
|
||||
}
|
||||
@@ -323,6 +320,6 @@ class Media extends PhpObject {
|
||||
|
||||
private static function getLatLngAltFromISO6709($sIso6709) {
|
||||
preg_match('/^(?P<lat>[\+\-][0,1]?\d{2}\.\d+)(?P<lng>[\+\-][0,1]?\d{2}\.\d+)(?P<alt>[\+\-]\d+)?/', $sIso6709, $asMatches);
|
||||
return array(floatval($asMatches['lat']), floatval($asMatches['lng']), floatval($asMatches['alt'] ?? 0));
|
||||
return [floatval($asMatches['lat']), floatval($asMatches['lng']), floatval($asMatches['alt'] ?? 0)];
|
||||
}
|
||||
}
|
||||
|
||||
+35
-36
@@ -7,13 +7,13 @@ use Franzz\Objects\Db;
|
||||
class Project extends PhpObject {
|
||||
|
||||
//Spot Mode
|
||||
const MODE_PREVIZ = 'P';
|
||||
const MODE_BLOG = 'B';
|
||||
const MODE_HISTO = 'H';
|
||||
const MODES = array('previz'=>self::MODE_PREVIZ, 'blog'=>self::MODE_BLOG, 'histo'=>self::MODE_HISTO);
|
||||
public const MODE_PREVIZ = 'P';
|
||||
public const MODE_BLOG = 'B';
|
||||
public const MODE_HISTO = 'H';
|
||||
public const MODES = ['previz'=>self::MODE_PREVIZ, 'blog'=>self::MODE_BLOG, 'histo'=>self::MODE_HISTO];
|
||||
|
||||
//DB Tables
|
||||
const PROJ_TABLE = 'projects';
|
||||
public const PROJ_TABLE = 'projects';
|
||||
|
||||
/**
|
||||
* Database Handle
|
||||
@@ -21,7 +21,6 @@ class Project extends PhpObject {
|
||||
*/
|
||||
private $oDb;
|
||||
|
||||
|
||||
private $iProjectId;
|
||||
private $sName;
|
||||
private $sCodeName;
|
||||
@@ -51,17 +50,17 @@ class Project extends PhpObject {
|
||||
* Mode --P--][--------B--------][--P--][-----------B---------------][---P---][-----B-----][---------H----------
|
||||
*/
|
||||
$sQuery =
|
||||
"SELECT MAX(id_project) ".
|
||||
"FROM projects ".
|
||||
"WHERE active_to = (".
|
||||
"SELECT MIN(active_to) ". //Select closest project in the future
|
||||
"FROM projects ".
|
||||
"WHERE active_to > NOW() ". //Select Next project
|
||||
"OR active_to = (". //In case there is no next project, select the last one
|
||||
"SELECT MAX(active_to) ".
|
||||
"FROM projects".
|
||||
")".
|
||||
")";
|
||||
'SELECT MAX(id_project) '.
|
||||
'FROM projects '.
|
||||
'WHERE active_to = ('.
|
||||
'SELECT MIN(active_to) '. //Select closest project in the future
|
||||
'FROM projects '.
|
||||
'WHERE active_to > NOW() '. //Select Next project
|
||||
'OR active_to = ('. //In case there is no next project, select the last one
|
||||
'SELECT MAX(active_to) '.
|
||||
'FROM projects'.
|
||||
')'.
|
||||
')';
|
||||
$asResult = $this->oDb->getArrayQuery($sQuery, true);
|
||||
$this->iProjectId = array_shift($asResult);
|
||||
}
|
||||
@@ -70,7 +69,7 @@ class Project extends PhpObject {
|
||||
}
|
||||
|
||||
public function createProjectId() {
|
||||
$this->setProjectId($this->oDb->insertRow(self::PROJ_TABLE, array('codename'=>'')));
|
||||
$this->setProjectId($this->oDb->insertRow(self::PROJ_TABLE, ['codename'=>'']));
|
||||
return $this->getProjectId();
|
||||
}
|
||||
|
||||
@@ -112,28 +111,28 @@ class Project extends PhpObject {
|
||||
return $this->oDb->selectColumn(
|
||||
Feed::FEED_TABLE,
|
||||
Db::getId(Feed::FEED_TABLE),
|
||||
array(Db::getId(self::PROJ_TABLE) => $this->getProjectId())
|
||||
[Db::getId(self::PROJ_TABLE) => $this->getProjectId()]
|
||||
);
|
||||
}
|
||||
|
||||
public function getProjects($iProjectId=0) {
|
||||
$bSpecificProj = ($iProjectId > 0);
|
||||
$sDefaultProjectCodeName = $this->getProjectCodeName();
|
||||
$asInfo = array(
|
||||
'select'=> array(
|
||||
Db::getId(self::PROJ_TABLE)." AS id",
|
||||
$asInfo = [
|
||||
'select'=> [
|
||||
Db::getId(self::PROJ_TABLE).' AS id',
|
||||
'codename',
|
||||
'name',
|
||||
'latitude',
|
||||
'longitude',
|
||||
'active_from',
|
||||
'active_to',
|
||||
"IF(NOW() BETWEEN active_from AND active_to, 1, IF(NOW() < active_from, 0, 2)) AS mode"
|
||||
),
|
||||
'IF(NOW() BETWEEN active_from AND active_to, 1, IF(NOW() < active_from, 0, 2)) AS mode'
|
||||
],
|
||||
'from' => self::PROJ_TABLE,
|
||||
'orderBy' => array('active_from' => 'ASC')
|
||||
);
|
||||
if($bSpecificProj) $asInfo['constraint'] = array(Db::getId(self::PROJ_TABLE)=>$iProjectId);
|
||||
'orderBy' => ['active_from' => 'ASC']
|
||||
];
|
||||
if($bSpecificProj) $asInfo['constraint'] = [Db::getId(self::PROJ_TABLE)=>$iProjectId];
|
||||
|
||||
$asProjects = $this->oDb->selectRows($asInfo, 'codename');
|
||||
foreach($asProjects as $sCodeName => &$asProject) {
|
||||
@@ -174,7 +173,7 @@ class Project extends PhpObject {
|
||||
return $iLastUpdate;
|
||||
}
|
||||
|
||||
public function getLastMessageId($asConstraints=array()): int {
|
||||
public function getLastMessageId($asConstraints=[]): int {
|
||||
$iLastMsg = 0;
|
||||
|
||||
$asFeedIds = $this->getFeedIds();
|
||||
@@ -192,20 +191,20 @@ class Project extends PhpObject {
|
||||
$this->sName = $asProject['name'];
|
||||
$this->sCodeName = $asProject['codename'];
|
||||
$this->sMode = $asProject['mode'];
|
||||
$this->asActive = array('from'=>$asProject['active_from'], 'to'=>$asProject['active_to']);
|
||||
$this->asActive = ['from'=>$asProject['active_from'], 'to'=>$asProject['active_to']];
|
||||
}
|
||||
else $this->addError('Error while setting project: no project ID');
|
||||
}
|
||||
|
||||
private function updateField($sField, $oValue) {
|
||||
$bResult = ($this->oDb->updateRow(self::PROJ_TABLE, $this->getProjectId(), array($sField=>$oValue)) > 0);
|
||||
$bResult = ($this->oDb->updateRow(self::PROJ_TABLE, $this->getProjectId(), [$sField=>$oValue]) > 0);
|
||||
$this->setProjectInfo();
|
||||
|
||||
return $bResult;
|
||||
}
|
||||
|
||||
public function delete() {
|
||||
$asResult = array();
|
||||
$asResult = [];
|
||||
if($this->getProjectId() > 0) {
|
||||
$asFeedIds = $this->getFeedIds();
|
||||
foreach($asFeedIds as $iFeedId) {
|
||||
@@ -213,14 +212,14 @@ class Project extends PhpObject {
|
||||
}
|
||||
|
||||
$bDeleted = $this->oDb->deleteRow(self::PROJ_TABLE, $this->getProjectId());
|
||||
$asResult['project'][] = array(
|
||||
$asResult['project'][] = [
|
||||
'id' => $this->getProjectId(),
|
||||
'del' => $bDeleted,
|
||||
'desc_lang_id' => $bDeleted?'':'error.commit_db',
|
||||
'desc_lang_params' => array()
|
||||
);
|
||||
'desc_lang_params' => []
|
||||
];
|
||||
}
|
||||
else $asResult['project'][] = array('del'=>false, 'desc_lang_id'=>'error.impossible_value', 'desc_lang_params'=>array($this->getProjectId(), 'project ID'));
|
||||
else $asResult['project'][] = ['del'=>false, 'desc_lang_id'=>'error.impossible_value', 'desc_lang_params'=>[$this->getProjectId(), 'project ID']];
|
||||
|
||||
return $asResult;
|
||||
}
|
||||
@@ -229,7 +228,7 @@ class Project extends PhpObject {
|
||||
return self::isModeEditable($this->getMode());
|
||||
}
|
||||
|
||||
static public function isModeEditable($sMode) {
|
||||
public static function isModeEditable($sMode) {
|
||||
return ($sMode != self::MODE_HISTO);
|
||||
}
|
||||
}
|
||||
|
||||
+8
-10
@@ -3,22 +3,20 @@
|
||||
namespace Franzz\Livetrail;
|
||||
use Franzz\Objects\UploadHandler;
|
||||
|
||||
class Uploader extends UploadHandler
|
||||
{
|
||||
class Uploader extends UploadHandler {
|
||||
private Media $oMedia;
|
||||
|
||||
public string $sBody;
|
||||
|
||||
function __construct(Media &$oMedia)
|
||||
{
|
||||
public function __construct(Media &$oMedia) {
|
||||
$this->oMedia = &$oMedia;
|
||||
$this->sBody = '';
|
||||
|
||||
parent::__construct(array(
|
||||
parent::__construct([
|
||||
'upload_dir' => Media::MEDIA_FOLDER.'/',
|
||||
'image_versions' => array(),
|
||||
'image_versions' => [],
|
||||
'accept_file_types' => '/\.(gif|jpe?g|png|mov|mp4)$/i'
|
||||
));
|
||||
]);
|
||||
}
|
||||
|
||||
protected function validate($uploaded_file, $file, $error, $index, $content_range) {
|
||||
@@ -28,7 +26,7 @@ class Uploader extends UploadHandler
|
||||
if(!$this->oMedia->isProjectEditable()) {
|
||||
$file->error = true;
|
||||
$file->desc_lang_id = 'upload.mode_archived';
|
||||
$file->desc_lang_params = array($this->oMedia->getProjectCodeName());
|
||||
$file->desc_lang_params = [$this->oMedia->getProjectCodeName()];
|
||||
$bResult = false;
|
||||
}
|
||||
|
||||
@@ -55,7 +53,7 @@ class Uploader extends UploadHandler
|
||||
}
|
||||
if(!empty($file->error)) {
|
||||
if(empty($file->desc_lang_id)) $file->desc_lang_id = is_string($file->error)?$file->error:'upload.error';
|
||||
if(empty($file->desc_lang_params)) $file->desc_lang_params = array();
|
||||
if(empty($file->desc_lang_params)) $file->desc_lang_params = [];
|
||||
$file->error = true;
|
||||
}
|
||||
|
||||
@@ -66,7 +64,7 @@ class Uploader extends UploadHandler
|
||||
$this->sBody .= $sBodyPart;
|
||||
}
|
||||
|
||||
protected function get_error_message($sLangId, $asParams=array()) {
|
||||
protected function get_error_message($sLangId, $asParams=[]) {
|
||||
return array_key_exists($sLangId, $this->error_messages)?'upload.error':$sLangId;
|
||||
}
|
||||
}
|
||||
|
||||
+45
-46
@@ -7,23 +7,17 @@ use Franzz\Objects\Db;
|
||||
class User extends PhpObject {
|
||||
|
||||
//DB Tables
|
||||
const USER_TABLE = 'users';
|
||||
public const USER_TABLE = 'users';
|
||||
|
||||
//Clearance Levels
|
||||
const CLEARANCE_USER = 0;
|
||||
const CLEARANCE_ADMIN = 9;
|
||||
const CLEARANCES = array('user'=>self::CLEARANCE_USER, 'admin'=>self::CLEARANCE_ADMIN);
|
||||
public const CLEARANCE_USER = 0;
|
||||
public const CLEARANCE_ADMIN = 9;
|
||||
public const CLEARANCES = ['user'=>self::CLEARANCE_USER, 'admin'=>self::CLEARANCE_ADMIN];
|
||||
|
||||
const USER_SUBSCRIBED = 1;
|
||||
const USER_UNSUBSCRIBED = 0;
|
||||
public const USER_SUBSCRIBED = 1;
|
||||
public const USER_UNSUBSCRIBED = 0;
|
||||
|
||||
//Session & Cookie
|
||||
const SESSION_ID_USER = 'id_user';
|
||||
const SESSION_ADMIN = 'admin_authenticated';
|
||||
const COOKIE_TOKEN = 'login';
|
||||
const COOKIE_DURATION = 60 * 60 * 24 * 365; //1 year
|
||||
|
||||
const DEFAULT_USER = array(
|
||||
public const DEFAULT_USER = [
|
||||
'id' => 0,
|
||||
'id_user' => 0,
|
||||
'name' => '',
|
||||
@@ -32,7 +26,13 @@ class User extends PhpObject {
|
||||
'timezone' => '',
|
||||
'subscribed'=> self::USER_UNSUBSCRIBED,
|
||||
'clearance' => self::CLEARANCE_USER
|
||||
);
|
||||
];
|
||||
|
||||
//Session & Cookie
|
||||
private const SESSION_ID_USER = 'id_user';
|
||||
private const SESSION_ADMIN = 'admin_authenticated';
|
||||
private const COOKIE_TOKEN = 'login';
|
||||
private const COOKIE_DURATION = 60 * 60 * 24 * 365; //1 year
|
||||
|
||||
/**
|
||||
* Database Handle
|
||||
@@ -73,22 +73,22 @@ class User extends PhpObject {
|
||||
}
|
||||
|
||||
public function getUserById($iUserId) {
|
||||
$asUsersInfo = array();
|
||||
$asUsersInfo = [];
|
||||
if($iUserId > 0) $asUsersInfo = $this->getUsersInfo($iUserId);
|
||||
return empty($asUsersInfo)?array():array_shift($asUsersInfo);
|
||||
return empty($asUsersInfo)?[]:array_shift($asUsersInfo);
|
||||
}
|
||||
|
||||
public function getUsersInfo($iUserId=-1) {
|
||||
|
||||
//Mapping between user fields and DB fields
|
||||
$asSelect = array_keys($this->asUserInfo);
|
||||
$asSelect[array_search('id', $asSelect)] = Db::getId(self::USER_TABLE)." AS id";
|
||||
$asSelect[array_search('id', $asSelect)] = Db::getId(self::USER_TABLE).' AS id';
|
||||
|
||||
$asInfo = array(
|
||||
$asInfo = [
|
||||
'select' => $asSelect,
|
||||
'from' => self::USER_TABLE
|
||||
);
|
||||
if($iUserId != -1) $asInfo['constraint'] = array(Db::getId(self::USER_TABLE) => $iUserId);
|
||||
];
|
||||
if($iUserId != -1) $asInfo['constraint'] = [Db::getId(self::USER_TABLE) => $iUserId];
|
||||
|
||||
return $this->oDb->selectRows($asInfo);
|
||||
}
|
||||
@@ -103,7 +103,7 @@ class User extends PhpObject {
|
||||
|
||||
$iUserId = $this->oDb->insertRow(
|
||||
self::USER_TABLE,
|
||||
array('email'=>$sEmail, 'language'=>$sLang, 'timezone'=>$sTimezone)
|
||||
['email'=>$sEmail, 'language'=>$sLang, 'timezone'=>$sTimezone]
|
||||
);
|
||||
|
||||
if($iUserId == 0) $sLangId = 'error.commit_db';
|
||||
@@ -121,7 +121,7 @@ class User extends PhpObject {
|
||||
public function setSubscription($bSubscribed) {
|
||||
if($this->getUserId() > 0) {
|
||||
$iSubscribed = $bSubscribed?1:0;
|
||||
$iUserId = $this->oDb->updateRow(self::USER_TABLE, $this->getUserId(), array('subscribed'=>$iSubscribed));
|
||||
$iUserId = $this->oDb->updateRow(self::USER_TABLE, $this->getUserId(), ['subscribed'=>$iSubscribed]);
|
||||
if(!$iUserId) return Livetrail::getResult(false, 'error.commit_db');
|
||||
$this->asUserInfo['subscribed'] = $iSubscribed;
|
||||
return Livetrail::getResult(true, $iSubscribed?'account.subscribed':'account.unsubscribed');
|
||||
@@ -131,11 +131,11 @@ class User extends PhpObject {
|
||||
public function getSubscribedUsersInfo() {
|
||||
$asSelect = array_keys($this->asUserInfo);
|
||||
$asSelect[array_search('id', $asSelect)] = Db::getId(self::USER_TABLE).' AS id';
|
||||
return $this->oDb->selectRows(array(
|
||||
return $this->oDb->selectRows([
|
||||
'select'=>$asSelect,
|
||||
'from'=>self::USER_TABLE,
|
||||
'constraint'=>array('subscribed'=>self::USER_SUBSCRIBED)
|
||||
));
|
||||
'constraint'=>['subscribed'=>self::USER_SUBSCRIBED]
|
||||
]);
|
||||
}
|
||||
|
||||
public function login($sEmail, $sPassword, $sLang, $sTimezone, $sNickName='') {
|
||||
@@ -152,8 +152,8 @@ class User extends PhpObject {
|
||||
//Check Email presence in DB
|
||||
$asDBUser = $this->oDb->selectRow(
|
||||
self::USER_TABLE,
|
||||
array('email' => $sEmail),
|
||||
array(Db::getId(self::USER_TABLE), 'password', 'clearance')
|
||||
['email' => $sEmail],
|
||||
[Db::getId(self::USER_TABLE), 'password', 'clearance']
|
||||
);
|
||||
$iUserId = $asDBUser[Db::getId(self::USER_TABLE)] ?? 0;
|
||||
|
||||
@@ -166,18 +166,18 @@ class User extends PhpObject {
|
||||
|
||||
//Set password
|
||||
elseif(empty($asDBUser['password'])) {
|
||||
if(!$this->oDb->updateRow(self::USER_TABLE, $iUserId, array('password' => password_hash($sPassword, PASSWORD_DEFAULT)))) $sLangId = 'error.commit_db';
|
||||
if(!$this->oDb->updateRow(self::USER_TABLE, $iUserId, ['password' => password_hash($sPassword, PASSWORD_DEFAULT)])) $sLangId = 'error.commit_db';
|
||||
else {
|
||||
$sLangId = 'account.password_set';
|
||||
$bSuccess = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//Check password
|
||||
elseif(password_verify($sPassword, $asDBUser['password'])) {
|
||||
$bSuccess = true;
|
||||
$sLangId = 'account.logged_in';
|
||||
}
|
||||
}
|
||||
else $sLangId = 'account.invalid_credentials';
|
||||
}
|
||||
else {
|
||||
@@ -192,7 +192,7 @@ class User extends PhpObject {
|
||||
$bSubscribe = $bSuccess;
|
||||
$sLangId = $bSuccess?'':$asAddResult['desc_lang_id'];
|
||||
$iUserId = $asAddResult['data'][Db::getId(self::USER_TABLE)] ?? 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if($bSuccess) {
|
||||
@@ -201,11 +201,11 @@ class User extends PhpObject {
|
||||
$this->setTokenCookie();
|
||||
}
|
||||
|
||||
return Livetrail::getResult($bSuccess, $sLangId, array('subscribe'=>$bSubscribe));
|
||||
return Livetrail::getResult($bSuccess, $sLangId, ['subscribe'=>$bSubscribe]);
|
||||
}
|
||||
|
||||
public function logout() {
|
||||
if($this->getUserId() > 0) $this->oDb->updateRow(self::USER_TABLE, $this->getUserId(), array('token' => '', 'token_exp' => '0000-00-00 00:00:00'));
|
||||
if($this->getUserId() > 0) $this->oDb->updateRow(self::USER_TABLE, $this->getUserId(), ['token' => '', 'token_exp' => '0000-00-00 00:00:00']);
|
||||
$this->clearSession();
|
||||
$this->clearCookie();
|
||||
$this->setUserId(0);
|
||||
@@ -213,38 +213,37 @@ class User extends PhpObject {
|
||||
}
|
||||
|
||||
public function updateNickname($sNickname) {
|
||||
if($this->getUserId() > 0 && $sNickname!='') $this->oDb->updateRow(self::USER_TABLE, $this->getUserId(), array('name'=>$sNickname));
|
||||
if($this->getUserId() > 0 && $sNickname!='') $this->oDb->updateRow(self::USER_TABLE, $this->getUserId(), ['name'=>$sNickname]);
|
||||
}
|
||||
|
||||
private function updateGravatar($iUserId, $sEmail) {
|
||||
$sImage = ($sEmail != '')?@file_get_contents('https://www.gravatar.com/avatar/'.md5($sEmail).'.png?d=404&s=24'):'';
|
||||
$this->oDb->updateRow(self::USER_TABLE, $iUserId, array('gravatar' => base64_encode($sImage)));
|
||||
$this->oDb->updateRow(self::USER_TABLE, $iUserId, ['gravatar' => base64_encode($sImage)]);
|
||||
}
|
||||
|
||||
public function checkUserClearance($iClearance)
|
||||
{
|
||||
public function checkUserClearance($iClearance) {
|
||||
return ($this->asUserInfo['clearance'] >= $iClearance);
|
||||
}
|
||||
|
||||
public function setUserClearance($iUserId, $iClearance) {
|
||||
$bSuccess = false;
|
||||
$sLangId = '';
|
||||
$asLangParams = array();
|
||||
$asLangParams = [];
|
||||
|
||||
if(!$this->checkUserClearance(self::CLEARANCE_ADMIN)) $sLangId = 'error.no_auth';
|
||||
else {
|
||||
if(!in_array($iClearance, self::CLEARANCES)) {
|
||||
$sLangId = 'error.impossible_value';
|
||||
$asLangParams = array($iClearance, 'clearance');
|
||||
$asLangParams = [$iClearance, 'clearance'];
|
||||
}
|
||||
else {
|
||||
$iUserId = $this->oDb->updateRow(self::USER_TABLE, $iUserId, array('clearance'=>$iClearance));
|
||||
$iUserId = $this->oDb->updateRow(self::USER_TABLE, $iUserId, ['clearance'=>$iClearance]);
|
||||
if(!$iUserId) $sLangId = 'error.commit_db';
|
||||
else $bSuccess = true;
|
||||
}
|
||||
}
|
||||
|
||||
return Livetrail::getResult($bSuccess, $sLangId, array(), $asLangParams);
|
||||
return Livetrail::getResult($bSuccess, $sLangId, [], $asLangParams);
|
||||
}
|
||||
|
||||
/* Session */
|
||||
@@ -285,7 +284,7 @@ class User extends PhpObject {
|
||||
$asUser = $this->oDb->selectRow(
|
||||
self::USER_TABLE,
|
||||
$iUserId,
|
||||
array('clearance', 'token', 'token_exp')
|
||||
['clearance', 'token', 'token_exp']
|
||||
);
|
||||
|
||||
//Check token value
|
||||
@@ -308,10 +307,10 @@ class User extends PhpObject {
|
||||
$this->oDb->updateRow(
|
||||
self::USER_TABLE,
|
||||
$this->getUserId(),
|
||||
array(
|
||||
[
|
||||
'token' => hash('sha256', $sCookieValue),
|
||||
'token_exp' => date(Db::TIMESTAMP_FORMAT, time() + self::COOKIE_DURATION)
|
||||
)
|
||||
]
|
||||
);
|
||||
|
||||
$this->setCookie($sCookieValue, time() + self::COOKIE_DURATION);
|
||||
@@ -325,13 +324,13 @@ class User extends PhpObject {
|
||||
setcookie(
|
||||
self::COOKIE_TOKEN,
|
||||
$sValue,
|
||||
array(
|
||||
[
|
||||
'expires' => $iExpires,
|
||||
'path' => '/',
|
||||
'secure' => (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off') || (($_SERVER['HTTP_X_FORWARDED_PROTO'] ?? '') === 'https'),
|
||||
'httponly' => true,
|
||||
'samesite' => 'Lax'
|
||||
)
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user