Add Local Time Zone
This commit is contained in:
@@ -8,44 +8,44 @@ require_once 'inc/PHPMailer/PHPMailer.php';
|
||||
require_once 'inc/PHPMailer/SMTP.php';
|
||||
|
||||
class Email extends PhpObject {
|
||||
|
||||
|
||||
private $sServName;
|
||||
private $sTemplateName;
|
||||
|
||||
|
||||
/**
|
||||
* Email Template
|
||||
* @var Mask
|
||||
*/
|
||||
public $oTemplate;
|
||||
|
||||
|
||||
private $asDests;
|
||||
|
||||
|
||||
public function __construct($sServName, $sTemplateName='') {
|
||||
$this->sServName = $sServName;
|
||||
$this->setTemplate($sTemplateName);
|
||||
$this->asDests = array();
|
||||
}
|
||||
|
||||
|
||||
public function setTemplate($sTemplateName) {
|
||||
$this->sTemplateName = $sTemplateName;
|
||||
$this->oTemplate = new Mask($this->sTemplateName);
|
||||
$this->oTemplate->setTag('local_server', $this->sServName);
|
||||
$this->oTemplate->setTag('geo_server', Settings::GEO_SERVER);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set Target User Info
|
||||
* @param array $asDests Contains: id_user, name, email, language, active
|
||||
* @param array $asDests Contains: id_user, name, email, language, timezone, active
|
||||
*/
|
||||
public function setDestInfo($asDests) {
|
||||
if(array_key_exists('email', $asDests)) $asDests = array($asDests);
|
||||
$this->asDests = $asDests;
|
||||
}
|
||||
|
||||
|
||||
public function send() {
|
||||
foreach($this->asDests as $asDest) {
|
||||
$oPHPMailer = new PHPMailer(true);
|
||||
|
||||
|
||||
//Server settings
|
||||
if(Settings::DEBUG) $oPHPMailer->SMTPDebug = SMTP::DEBUG_SERVER;//Enable verbose debug output
|
||||
$oPHPMailer->isSMTP(); //Send using SMTP
|
||||
@@ -59,31 +59,31 @@ class Email extends PhpObject {
|
||||
$oPHPMailer->Port = 587; //TCP port to connect to, use 465 for `PHPMailer::ENCRYPTION_SMTPS` above
|
||||
$oPHPMailer->setFrom(Settings::MAIL_FROM, 'Spotty');
|
||||
$oPHPMailer->addReplyTo(Settings::MAIL_FROM, 'Spotty');
|
||||
|
||||
|
||||
//Message
|
||||
$this->oTemplate->setLanguage($asDest['language'], Spot::DEFAULT_LANG);
|
||||
$this->oTemplate->setTimezone($asDest['timezone']);
|
||||
|
||||
|
||||
//Unsubscribe Link
|
||||
$sUnsubLink = $this->sServName.'?a=unsubscribe_email&id='.$asDest['id_user'];
|
||||
$this->oTemplate->setTag('unsubscribe_link', htmlspecialchars($sUnsubLink));
|
||||
$oPHPMailer->addCustomHeader('List-Unsubscribe','<mailto:'.Settings::MAIL_FROM.'?subject=unsubscribe>, <'.$sUnsubLink.'>');
|
||||
$oPHPMailer->addCustomHeader('List-Unsubscribe-Post','List-Unsubscribe=One-Click');
|
||||
|
||||
|
||||
//Email Content
|
||||
$this->oTemplate->setTag('timezone', 'lang:city_time', self::getTimeZoneCity($asDest['timezone']));
|
||||
$sHtmlMessage = $this->oTemplate->getMask();
|
||||
$sPlainMessage = strip_tags(str_replace('<br />', "\n", $sHtmlMessage));
|
||||
|
||||
|
||||
//Recipients
|
||||
$oPHPMailer->addAddress($asDest['email'], $asDest['name']);
|
||||
|
||||
|
||||
//Content
|
||||
$oPHPMailer->isHTML(true);
|
||||
$oPHPMailer->Subject = $this->oTemplate->getTranslator()->getTranslation($this->sTemplateName.'_subject');
|
||||
$oPHPMailer->Body = $sHtmlMessage;
|
||||
$oPHPMailer->AltBody = $sPlainMessage;
|
||||
|
||||
|
||||
try {
|
||||
$oPHPMailer->send();
|
||||
}
|
||||
@@ -92,8 +92,8 @@ class Email extends PhpObject {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private static function getTimeZoneCity($sTimeZone) {
|
||||
return (strpos($sTimeZone, '/')!==false)?str_replace('_', ' ', explode('/', $sTimeZone)[1]):$sTimeZone;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
18
inc/feed.php
18
inc/feed.php
@@ -90,7 +90,7 @@ class Feed extends PhpObject {
|
||||
|
||||
public function getMessages($asActivePeriod = array()) {
|
||||
$asInfo = array(
|
||||
'select' => array('id_message', 'ref_msg_id', 'type', 'latitude', 'longitude', 'site_time', 'unix_time'),
|
||||
'select' => array('id_message', 'ref_msg_id', 'type', 'latitude', 'longitude', 'site_time', 'timezone', 'unix_time'),
|
||||
'from' => self::MSG_TABLE,
|
||||
'constraint'=> array(Db::getId(self::FEED_TABLE) => $this->getFeedId()),
|
||||
'constOpe' => array(Db::getId(self::FEED_TABLE) => "="),
|
||||
@@ -163,7 +163,8 @@ class Feed extends PhpObject {
|
||||
'latitude' => $asMsg['latitude'],
|
||||
'longitude' => $asMsg['longitude'],
|
||||
'iso_time' => $asMsg['dateTime'], //ISO 8601 time (backup)
|
||||
'site_time' => date(Db::TIMESTAMP_FORMAT, $asMsg['unixTime']), //Conversion to Site Time (default timezone, see Settings::TIMEZONE)
|
||||
'site_time' => date(Db::TIMESTAMP_FORMAT, $asMsg['unixTime']), //Conversion to Site Time
|
||||
'timezone' => Spot::getTimeZoneFromDate($asMsg['dateTime']), //Local Time Zone
|
||||
'unix_time' => $asMsg['unixTime'], //UNIX Time (backup)
|
||||
'content' => $asMsg['messageContent'],
|
||||
'battery_state' => $asMsg['batteryState']
|
||||
@@ -200,13 +201,16 @@ class Feed extends PhpObject {
|
||||
}
|
||||
|
||||
public function delete() {
|
||||
$sDesc = '';
|
||||
$asResult = array();
|
||||
if($this->getFeedId() > 0) {
|
||||
$bSuccess = $this->oDb->deleteRow(self::FEED_TABLE, $this->getFeedId());
|
||||
if(!$bSuccess) $sDesc = $this->oDb->getLastError();
|
||||
$asResult = array(
|
||||
'id' => $this->getFeedId(),
|
||||
'del' => $this->oDb->deleteRow(self::FEED_TABLE, $this->getFeedId()),
|
||||
'desc' => $this->oDb->getLastError()
|
||||
);
|
||||
}
|
||||
else $sDesc = 'Error while setting project: no Feed ID';
|
||||
else $asResult = array('del'=>false, 'desc'=>'Error while setting project: no Feed ID');
|
||||
|
||||
return $sDesc;
|
||||
return $asResult;
|
||||
}
|
||||
}
|
||||
|
||||
136
inc/media.php
136
inc/media.php
@@ -1,22 +1,22 @@
|
||||
<?php
|
||||
|
||||
class Media extends PhpObject {
|
||||
|
||||
|
||||
//DB Tables
|
||||
const MEDIA_TABLE = 'medias';
|
||||
|
||||
|
||||
//Media folders
|
||||
const MEDIA_FOLDER = 'files/';
|
||||
const THUMB_FOLDER = self::MEDIA_FOLDER.'thumbs/';
|
||||
|
||||
|
||||
const THUMB_MAX_WIDTH = 400;
|
||||
|
||||
|
||||
/**
|
||||
* Database Handle
|
||||
* @var Db
|
||||
*/
|
||||
private $oDb;
|
||||
|
||||
|
||||
/**
|
||||
* Media Project
|
||||
* @var Project
|
||||
@@ -25,9 +25,9 @@ class Media extends PhpObject {
|
||||
private $asMedia;
|
||||
private $asMedias;
|
||||
private $sSystemType;
|
||||
|
||||
|
||||
private $iMediaId;
|
||||
|
||||
|
||||
public function __construct(Db &$oDb, &$oProject, $iMediaId=0) {
|
||||
parent::__construct(__CLASS__, Settings::DEBUG);
|
||||
$this->oDb = &$oDb;
|
||||
@@ -37,19 +37,19 @@ class Media extends PhpObject {
|
||||
$this->sSystemType = (substr(php_uname(), 0, 7) == "Windows")?'win':'unix';
|
||||
$this->setMediaId($iMediaId);
|
||||
}
|
||||
|
||||
|
||||
public function setMediaId($iMediaId) {
|
||||
$this->iMediaId = $iMediaId;
|
||||
}
|
||||
|
||||
|
||||
public function getMediaId() {
|
||||
return $this->iMediaId;
|
||||
}
|
||||
|
||||
|
||||
public function getProjectCodeName() {
|
||||
return $this->oProject->getProjectCodeName();
|
||||
}
|
||||
|
||||
|
||||
public function setComment($sComment) {
|
||||
$sError = '';
|
||||
$asData = array();
|
||||
@@ -59,27 +59,27 @@ class Media extends PhpObject {
|
||||
else $asData = $this->getInfo();
|
||||
}
|
||||
else $sError = 'media_no_id';
|
||||
|
||||
|
||||
return Spot::getResult(($sError==''), $sError, $asData);
|
||||
}
|
||||
|
||||
|
||||
public function getMediasInfo($iMediaId=0) {
|
||||
$bOwnMedia = ($iMediaId > 0);
|
||||
if($bOwnMedia && empty($this->asMedia) || !$bOwnMedia && empty($this->asMedias)) {
|
||||
if($this->oProject->getProjectId()) {
|
||||
$asParams = array(
|
||||
'select' => array(Db::getId(self::MEDIA_TABLE), 'filename', 'taken_on', 'posted_on', 'rotate', 'type AS subtype', 'comment'),
|
||||
'select' => array(Db::getId(self::MEDIA_TABLE), 'filename', 'taken_on', 'posted_on', 'timezone', 'rotate', 'type AS subtype', 'comment'),
|
||||
'from' => self::MEDIA_TABLE,
|
||||
'constraint'=> array(Db::getId(Project::PROJ_TABLE) => $this->oProject->getProjectId())
|
||||
);
|
||||
if($bOwnMedia) $asParams['constraint'][Db::getId(self::MEDIA_TABLE)] = $iMediaId;
|
||||
|
||||
|
||||
$asMedias = $this->oDb->selectRows($asParams);
|
||||
foreach($asMedias as &$asMedia) {
|
||||
$asMedia['media_path'] = self::getMediaPath($asMedia['filename']);
|
||||
$asMedia['thumb_path'] = $this->getMediaThumbnail($asMedia['filename']);
|
||||
}
|
||||
|
||||
|
||||
if(!empty($asMedias)) {
|
||||
if($bOwnMedia) $this->asMedia = array_shift($asMedias);
|
||||
else $this->asMedias = $asMedias;
|
||||
@@ -88,15 +88,15 @@ class Media extends PhpObject {
|
||||
}
|
||||
return $bOwnMedia?$this->asMedia:$this->asMedias;
|
||||
}
|
||||
|
||||
|
||||
public function getInfo() {
|
||||
return $this->getMediasInfo($this->iMediaId);
|
||||
}
|
||||
|
||||
|
||||
public function isProjectModeValid() {
|
||||
return ($this->oProject->getMode() == Project::MODE_BLOG);
|
||||
}
|
||||
|
||||
|
||||
public function addMedia($sMediaName, $sMethod='upload') {
|
||||
$sError = '';
|
||||
$asParams = array();
|
||||
@@ -109,30 +109,32 @@ class Media extends PhpObject {
|
||||
$asParams[] = $sMediaName;
|
||||
}
|
||||
else {
|
||||
//Add media to DB
|
||||
$asMediaInfo = $this->getMediaInfoFromFile($sMediaName);
|
||||
|
||||
//Converting times to DB Time Zone, by using date()
|
||||
$asDbInfo = array(
|
||||
Db::getId(Project::PROJ_TABLE) => $this->oProject->getProjectId(),
|
||||
'filename' => $sMediaName,
|
||||
'taken_on' => ($asMediaInfo['taken_ts'] > 0)?date(Db::TIMESTAMP_FORMAT, $asMediaInfo['taken_ts']):0, //Site Time
|
||||
'posted_on' => date(Db::TIMESTAMP_FORMAT, $asMediaInfo['file_ts']), //Site Time
|
||||
'taken_on' => ($asMediaInfo['taken_ts'] > 0)?date(Db::TIMESTAMP_FORMAT, $asMediaInfo['taken_ts']):0,
|
||||
'posted_on' => date(Db::TIMESTAMP_FORMAT, $asMediaInfo['file_ts']),
|
||||
'timezone' => $asMediaInfo['timezone'],
|
||||
'rotate' => $asMediaInfo['rotate'],
|
||||
'type' => $asMediaInfo['type']
|
||||
);
|
||||
|
||||
|
||||
if($sMethod=='sync') $iMediaId = $this->oDb->insertUpdateRow(self::MEDIA_TABLE, $asDbInfo, array(Db::getId(Project::PROJ_TABLE), 'filename'));
|
||||
else $iMediaId = $this->oDb->insertRow(self::MEDIA_TABLE, $asDbInfo);
|
||||
|
||||
|
||||
if(!$iMediaId) $sError = 'error_commit_db';
|
||||
else {
|
||||
$this->setMediaId($iMediaId);
|
||||
$asParams = $this->getInfo(); //Creates thumbnail
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return Spot::getResult(($sError==''), $sError, $asParams);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* One-shot function to initialize DB with existing images
|
||||
*/
|
||||
@@ -146,13 +148,15 @@ class Media extends PhpObject {
|
||||
$this->setExtractMode(PhpObject::MODE_HTML);
|
||||
return $this->getCleanMessageStack();
|
||||
}
|
||||
|
||||
|
||||
private function getMediaInfoFromFile($sMediaName)
|
||||
{
|
||||
$sMediaPath = self::getMediaPath($sMediaName);
|
||||
$sType = self::getMediaType($sMediaName);
|
||||
|
||||
$iTimeStamp = $iTakenOn = $iPostedOn = 0;
|
||||
|
||||
$iTimeStamp = $iTakenOn = 0;
|
||||
$iPostedOn = filemtime($sMediaPath);
|
||||
$sTimeZone = date_default_timezone_get();
|
||||
$sRotate = '0';
|
||||
$sTakenOn = '';
|
||||
switch($sType) {
|
||||
@@ -161,28 +165,44 @@ class Media extends PhpObject {
|
||||
$sParams = implode(' ', array(
|
||||
'-loglevel error', //Remove comments
|
||||
'-select_streams v:0', //First video channel
|
||||
'-show_entries stream_tags=rotate,creation_time', //filter tags :rotation & creation time only
|
||||
'-show_entries '. //filter tags : Creation Time & Rotation
|
||||
'format_tags=creation_time,com.apple.quicktime.creationdate'.':'.
|
||||
'stream_tags=rotate,creation_time',
|
||||
'-print_format json', //output format: json
|
||||
'-i' //input file
|
||||
));
|
||||
exec('ffprobe '.$sParams.' "'.$sMediaPath.'"', $asResult);
|
||||
$asResult = json_decode(implode('', $asResult), true);
|
||||
|
||||
//Timestamps
|
||||
$sTakenOn = date(Db::TIMESTAMP_FORMAT, strtotime($asResult['streams'][0]['tags']['creation_time']));
|
||||
$iPostedOn = filemtime($sMediaPath);
|
||||
|
||||
$asExif = json_decode(implode('', $asResult), true);
|
||||
|
||||
//Taken On
|
||||
if(isset($asExif['format']['tags']['com.apple.quicktime.creationdate'])) {
|
||||
$sTakenOn = $asExif['format']['tags']['com.apple.quicktime.creationdate']; //contains Time Zone
|
||||
$sTimeZone = Spot::getTimeZoneFromDate($sTakenOn) ?? $sTimeZone;
|
||||
}
|
||||
else $sTakenOn = $asExif['format']['tags']['creation_time'] ?? $asExif['streams'][0]['tags']['creation_time'];
|
||||
|
||||
//Orientation
|
||||
if(isset($asResult['streams'][0]['tags']['rotate'])) $sRotate = $asResult['streams'][0]['tags']['rotate'];
|
||||
if(isset($asExif['streams'][0]['tags']['rotate'])) $sRotate = $asExif['streams'][0]['tags']['rotate'];
|
||||
break;
|
||||
case 'image':
|
||||
case 'image':
|
||||
$asExif = @exif_read_data($sMediaPath, 0, true);
|
||||
if(!$asExif) $asExif['FILE']['FileDateTime'] = filemtime($sMediaPath);
|
||||
|
||||
//Timestamps
|
||||
if(array_key_exists('EXIF', $asExif) && array_key_exists('DateTimeOriginal', $asExif['EXIF'])) $sTakenOn = $asExif['EXIF']['DateTimeOriginal'];
|
||||
|
||||
//Posted On
|
||||
if(array_key_exists('FILE', $asExif) && array_key_exists('FileDateTime', $asExif['FILE'])) $iPostedOn = $asExif['FILE']['FileDateTime'];
|
||||
|
||||
|
||||
//Taken On & Timezone
|
||||
if(array_key_exists('EXIF', $asExif)) {
|
||||
if(array_key_exists('DateTimeOriginal', $asExif['EXIF'])) $sTakenOn = $asExif['EXIF']['DateTimeOriginal'];
|
||||
|
||||
/* Priorities:
|
||||
* 1. OffsetTimeOriginal: timezone for DateTimeOriginal (exif version >= 2.31)
|
||||
* 2. 0x9011: same as above, but unidentified
|
||||
* 3. Timezone extracted from DateTimeOriginal
|
||||
* 4. Uploader Browser Time Zone (PHP Default Time Zone)
|
||||
*/
|
||||
$sTimeZone = $asExif['EXIF']['OffsetTimeOriginal'] ?? $asExif['EXIF']['UndefinedTag:0x9011'] ?? Spot::getTimeZoneFromDate($sTakenOn) ?? $sTimeZone;
|
||||
}
|
||||
|
||||
//Orientation
|
||||
if(array_key_exists('IFD0', $asExif) && array_key_exists('Orientation', $asExif['IFD0'])) {
|
||||
switch($asExif['IFD0']['Orientation'])
|
||||
@@ -195,30 +215,32 @@ class Media extends PhpObject {
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
//Media info do not have any TZ: Interpreting date time using project timezone (assuming all medias have been taken in this time zone)
|
||||
|
||||
//Assign the correct Time Zone to $sTakenOn if it is not already contained in it. Then get Unix Timestamp
|
||||
//Time Zone (2nd parameter) will be ignored if already contained in $sTakenOn
|
||||
if($sTakenOn != '') {
|
||||
$oTakenOn = new DateTime($sTakenOn, new DateTimeZone($this->oProject->getTimeZone()));
|
||||
$oTakenOn = new DateTime($sTakenOn, new DateTimeZone($sTimeZone));
|
||||
$iTakenOn = $oTakenOn->format('U');
|
||||
}
|
||||
|
||||
|
||||
//Merge timestamps
|
||||
$iTimeStamp = ($iTakenOn > 0)?$iTakenOn:$iPostedOn;
|
||||
|
||||
|
||||
return array(
|
||||
'timestamp' => $iTimeStamp,
|
||||
'timezone' => $sTimeZone,
|
||||
'taken_ts' => $iTakenOn,
|
||||
'file_ts' => $iPostedOn,
|
||||
'rotate' => $sRotate,
|
||||
'type' => $sType
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
private function getMediaThumbnail($sMediaName)
|
||||
{
|
||||
$sMediaPath = self::getMediaPath($sMediaName);
|
||||
$sThumbPath = self::getMediaPath($sMediaName, 'thumbnail');
|
||||
|
||||
|
||||
if(!file_exists($sThumbPath)) {
|
||||
$sType = self::getMediaType($sMediaName);
|
||||
switch($sType) {
|
||||
@@ -236,23 +258,23 @@ class Media extends PhpObject {
|
||||
'"'.$sTempPath.'"', //output file
|
||||
));
|
||||
exec('ffmpeg '.$sParams, $asResult);
|
||||
|
||||
|
||||
//Resize
|
||||
$asThumbInfo = ToolBox::createThumbnail($sTempPath, self::THUMB_MAX_WIDTH, 0, $sThumbPath, true);
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
else $asThumbInfo = array('error'=>'', 'out'=>$sThumbPath);
|
||||
|
||||
|
||||
return ($asThumbInfo['error']=='')?$asThumbInfo['out']:$sMediaPath;
|
||||
}
|
||||
|
||||
|
||||
private static function getMediaPath($sMediaName, $sFileType='media') {
|
||||
if($sFileType=='thumbnail') return self::THUMB_FOLDER.$sMediaName.(strtolower(substr($sMediaName, -3))=='mov'?'.png':'');
|
||||
else return self::MEDIA_FOLDER.$sMediaName;
|
||||
}
|
||||
|
||||
|
||||
private static function getMediaType($sMediaName) {
|
||||
$sMediaPath = self::getMediaPath($sMediaName);
|
||||
$sMediaMime = mime_content_type($sMediaPath);
|
||||
@@ -260,7 +282,7 @@ class Media extends PhpObject {
|
||||
case 'video/quicktime': $sType = 'video'; break;
|
||||
default: $sType = 'image'; break;
|
||||
}
|
||||
|
||||
|
||||
return $sType;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -66,7 +66,7 @@ class Project extends PhpObject {
|
||||
}
|
||||
|
||||
public function createProjectId() {
|
||||
$this->setProjectId($this->oDb->insertRow(self::PROJ_TABLE, array('timezone'=>Settings::TIMEZONE)));
|
||||
$this->setProjectId($this->oDb->insertRow(self::PROJ_TABLE, array('codename'=>'')));
|
||||
return $this->getProjectId();
|
||||
}
|
||||
|
||||
@@ -104,14 +104,6 @@ class Project extends PhpObject {
|
||||
}
|
||||
}
|
||||
|
||||
public function getTimeZone() {
|
||||
return $this->asGeo['timezone'];
|
||||
}
|
||||
|
||||
public function setTimeZone($sTimeZone) {
|
||||
return $this->updateField('timezone', $sTimeZone);
|
||||
}
|
||||
|
||||
public function getFeedIds() {
|
||||
return $this->oDb->selectColumn(
|
||||
Feed::FEED_TABLE,
|
||||
@@ -129,8 +121,7 @@ class Project extends PhpObject {
|
||||
'name',
|
||||
'active_from',
|
||||
'active_to',
|
||||
"IF(NOW() BETWEEN active_from AND active_to, 1, IF(NOW() < active_from, 0, 2)) AS mode",
|
||||
'timezone'
|
||||
"IF(NOW() BETWEEN active_from AND active_to, 1, IF(NOW() < active_from, 0, 2)) AS mode"
|
||||
),
|
||||
'from' => self::PROJ_TABLE
|
||||
);
|
||||
@@ -186,7 +177,7 @@ class Project extends PhpObject {
|
||||
$this->asActive = array('from'=>$asProject['active_from'], 'to'=>$asProject['active_to']);
|
||||
$this->sCodeName = $asProject['codename'];
|
||||
$this->sName = $asProject['name'];
|
||||
$this->asGeo = array('geofile'=>$asProject['geofilepath'], 'gpxfile'=>$asProject['gpxfilepath'], 'timezone'=>$asProject['timezone']);
|
||||
$this->asGeo = array('geofile'=>$asProject['geofilepath'], 'gpxfile'=>$asProject['gpxfilepath']);
|
||||
}
|
||||
else $this->addError('Error while setting project: no project ID');
|
||||
}
|
||||
@@ -199,13 +190,21 @@ class Project extends PhpObject {
|
||||
}
|
||||
|
||||
public function delete() {
|
||||
$sDesc = '';
|
||||
$asResult = array();
|
||||
if($this->getProjectId() > 0) {
|
||||
$bSuccess = $this->oDb->deleteRow(self::PROJ_TABLE, $this->getProjectId());
|
||||
if(!$bSuccess) $sDesc = $this->oDb->getLastError();
|
||||
}
|
||||
else $sDesc = 'Error while setting project: no project ID';
|
||||
$asFeedIds = $this->getFeedIds();
|
||||
foreach($asFeedIds as $iFeedId) {
|
||||
$asResult['feed'][] = (new Feed($this->oDb, $iFeedId))->delete();
|
||||
}
|
||||
|
||||
return $sDesc;
|
||||
$asResult['project'][] = array(
|
||||
'id' => $this->getProjectId(),
|
||||
'del' => $this->oDb->deleteRow(self::PROJ_TABLE, $this->getProjectId()),
|
||||
'desc' => $this->oDb->getLastError()
|
||||
);
|
||||
}
|
||||
else $asResult['project'][] = array('del'=>false, 'desc'=>'Error while setting project: no project ID');
|
||||
|
||||
return $asResult;
|
||||
}
|
||||
}
|
||||
|
||||
121
inc/spot.php
121
inc/spot.php
@@ -1,17 +1,21 @@
|
||||
<?php
|
||||
|
||||
/* Timezones
|
||||
* ---------
|
||||
* Site Time: Time Zone in which the User is viewing the Site (default PHP/SQL Timezone)
|
||||
* Local Time: Time Zone in which the Spot Owner is
|
||||
*
|
||||
* - Feeds (table `feeds`):
|
||||
* - last_update: timestamp in site time (see Settings::TIMEZONE)
|
||||
* - last_update: timestamp in Site Time
|
||||
* - Spot Messages (table `messages`):
|
||||
* - unix_time: UNIX (int) in UTC
|
||||
* - site_time: timestamp in site time (see Settings::TIMEZONE)
|
||||
* - iso_time: raw ISO 8601 in local timezone
|
||||
* - site_time: timestamp in Site Time
|
||||
* - iso_time: raw ISO 8601 in Local Time
|
||||
* - Medias (table `medias`):
|
||||
* - posted_on: timestamp in site time (see Settings::TIMEZONE)
|
||||
* - taken_on: timestamp in site time (see Settings::TIMEZONE)
|
||||
* - posted_on: timestamp in Site Time
|
||||
* - taken_on: timestamp in Site Time
|
||||
* - Posts (table `posts`):
|
||||
* - site_time: timestamp in site time (see Settings::TIMEZONE)
|
||||
* - site_time: timestamp in Site Time
|
||||
*/
|
||||
|
||||
class Spot extends Main
|
||||
@@ -71,18 +75,24 @@ class Spot extends Main
|
||||
$this->oDb->install();
|
||||
}
|
||||
|
||||
public function syncPics() {
|
||||
if(Settings::DEBUG) {
|
||||
return (new Media($this->oDb, $this->oProject))->syncFileFolder();
|
||||
}
|
||||
}
|
||||
|
||||
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', 'unix_time', 'content', 'battery_state'),
|
||||
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'),
|
||||
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', 'timezone'),
|
||||
self::POST_TABLE => array(Db::getId(Project::PROJ_TABLE), Db::getId(User::USER_TABLE), 'name', 'content', 'site_time'),
|
||||
Media::MEDIA_TABLE => array(Db::getId(Project::PROJ_TABLE), 'filename', 'type', 'taken_on', 'posted_on', 'rotate', 'comment'),
|
||||
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', 'rotate', 'comment'),
|
||||
User::USER_TABLE => array('name', 'email', 'gravatar', 'language', 'timezone', 'active'),
|
||||
self::MAP_TABLE => array('codename', 'geo_name', 'min_zoom', 'max_zoom', 'attribution'),
|
||||
self::MAPPING_TABLE => array(Db::getId(self::MAP_TABLE) , Db::getId(Project::PROJ_TABLE))
|
||||
@@ -235,11 +245,11 @@ class Spot extends Main
|
||||
public function getMarkers()
|
||||
{
|
||||
$asMessages = $this->getSpotMessages();
|
||||
$bSuccess = !empty($this->getMedias('posted_on') + $asMessages + $this->getPosts());
|
||||
$sDesc = $bSuccess?'':self::NO_DATA;
|
||||
$bEmptyProject = empty($this->getMedias('posted_on') + $asMessages + $this->getPosts());
|
||||
$sDesc = '';
|
||||
|
||||
//Add medias
|
||||
if($bSuccess) {
|
||||
if(!empty($asMessages)) {
|
||||
$asMedias = $this->getMedias('taken_on');
|
||||
|
||||
//Assign medias to closest message
|
||||
@@ -264,10 +274,12 @@ class Spot extends Main
|
||||
$asLastUpdate = array();
|
||||
$this->addTimeStamp($asLastUpdate, $this->oProject->getLastUpdate());
|
||||
|
||||
return self::getJsonResult($bSuccess, $sDesc, array(
|
||||
return self::getJsonResult(true, $sDesc, array(
|
||||
'messages' => $asMessages,
|
||||
'maps' => $this->oProject->getMaps(),
|
||||
'last_update' => $asLastUpdate));
|
||||
'last_update' => $asLastUpdate,
|
||||
'empty_project' => $bEmptyProject
|
||||
));
|
||||
}
|
||||
|
||||
public function subscribe($sEmail) {
|
||||
@@ -315,7 +327,7 @@ class Spot extends Main
|
||||
$asMessage['lat_dms'] = self::decToDms($asMessage['latitude'], 'lat');
|
||||
$asMessage['lon_dms'] = self::decToDms($asMessage['longitude'], 'lon');
|
||||
|
||||
$this->addTimeStamp($asMessage, $asMessage['unix_time']);
|
||||
$this->addTimeStamp($asMessage, $asMessage['unix_time'], $asMessage['timezone']);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -343,10 +355,14 @@ class Spot extends Main
|
||||
foreach($asMedias as $asMedia) {
|
||||
$sTimeRef = $asMedia[$sTimeRefField];
|
||||
if($sTimeRef >= $this->oProject->getActivePeriod('from') && $sTimeRef <= $this->oProject->getActivePeriod('to')) {
|
||||
$asMedia['taken_on_formatted'] = $this->getTimeFormat(strtotime($asMedia['taken_on']));
|
||||
$asMedia['posted_on_formatted'] = $this->getTimeFormat(strtotime($asMedia['posted_on']));
|
||||
$iTimeStampTakenOn = strtotime($asMedia['taken_on']);
|
||||
$iTimeStampPostedOn = strtotime($asMedia['posted_on']);
|
||||
$asMedia['taken_on_formatted'] = $this->getTimeFormat($iTimeStampTakenOn);
|
||||
$asMedia['taken_on_formatted_local'] = $this->getTimeFormat($iTimeStampTakenOn, $asMedia['timezone']);
|
||||
$asMedia['posted_on_formatted'] = $this->getTimeFormat($iTimeStampPostedOn);
|
||||
$asMedia['posted_on_formatted_local'] = $this->getTimeFormat($iTimeStampPostedOn, $asMedia['timezone']);
|
||||
|
||||
$this->addTimeStamp($asMedia, strtotime($sTimeRef));
|
||||
$this->addTimeStamp($asMedia, strtotime($sTimeRef), $asMedia['timezone']);
|
||||
$asValidMedias[] = $asMedia;
|
||||
}
|
||||
}
|
||||
@@ -379,17 +395,18 @@ class Spot extends Main
|
||||
$asPost['formatted_name'] = Toolbox::mb_ucwords($asPost['name']);
|
||||
unset($asPost[Db::getId(User::USER_TABLE)]);
|
||||
|
||||
$this->addTimeStamp($asPost, $iUnixTimeStamp);
|
||||
$this->addTimeStamp($asPost, $iUnixTimeStamp, $asPost['timezone']);
|
||||
}
|
||||
usort($asPosts, function($a, $b){return $a['unix_time'] > $b['unix_time'];});
|
||||
|
||||
return $asPosts;
|
||||
}
|
||||
|
||||
private function addTimeStamp(&$asData, $iTime) {
|
||||
private function addTimeStamp(&$asData, $iTime, $sTimeZone='') {
|
||||
$asData['unix_time'] = (int) $iTime;
|
||||
$asData['relative_time'] = Toolbox::getDateTimeDesc($iTime, $this->oLang->getLanguage());
|
||||
$asData['formatted_time'] = $this->getTimeFormat($iTime);
|
||||
if($sTimeZone != '') $asData['formatted_time_local'] = $this->getTimeFormat($iTime, $sTimeZone);
|
||||
}
|
||||
|
||||
public function getNewsFeed($iChunk=0, $bInternal=false)
|
||||
@@ -446,7 +463,8 @@ class Spot extends Main
|
||||
Db::getId(Project::PROJ_TABLE) => $this->oProject->getProjectId(),
|
||||
'name' => mb_strtolower(trim($sName)),
|
||||
'content' => trim($sPost),
|
||||
'site_time' => date(Db::TIMESTAMP_FORMAT) //site time (Settings::TIMEZONE)
|
||||
'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();
|
||||
|
||||
@@ -471,13 +489,19 @@ class Spot extends Main
|
||||
return self::getJsonResult($asResult['result'], $asResult['desc'], $asResult['data']);
|
||||
}
|
||||
|
||||
public function getAdminSettings() {
|
||||
public function getAdminSettings($sType='') {
|
||||
$oFeed = new Feed($this->oDb);
|
||||
$asData = array(
|
||||
'project' => $this->oProject->getProjects(),
|
||||
'feed' => $oFeed->getFeeds(),
|
||||
'spot' => $oFeed->getSpots()
|
||||
);
|
||||
|
||||
foreach($asData['project'] as &$asProject) {
|
||||
$asProject['active_from'] = substr($asProject['active_from'], 0, 10);
|
||||
$asProject['active_to'] = substr($asProject['active_to'], 0, 10);
|
||||
}
|
||||
|
||||
return self::getJsonResult(true, '', $asData);
|
||||
}
|
||||
|
||||
@@ -502,30 +526,32 @@ class Spot extends Main
|
||||
case 'active_to':
|
||||
$bSuccess = $oProject->setActivePeriod($sValue.' 23:59:59', 'to');
|
||||
break;
|
||||
case 'timezone':
|
||||
$bSuccess = $oProject->setTimeZone($sValue);
|
||||
break;
|
||||
default:
|
||||
$sDesc = $this->oLang->getTranslation('unknown_field', $sField);
|
||||
}
|
||||
$asResult = $oProject->getProject();
|
||||
$asResult['active_from'] = substr($asResult['active_from'], 0, 10);
|
||||
$asResult['active_to'] = substr($asResult['active_to'], 0, 10);
|
||||
break;
|
||||
case 'feed':
|
||||
case 'spot':
|
||||
$oFeed = new Feed($this->oDb, $iId);
|
||||
switch($sField) {
|
||||
case 'ref_feed_id':
|
||||
$bSuccess = $oFeed->setRefFeedId($sValue);
|
||||
break;
|
||||
case 'spot_id':
|
||||
case 'id_spot':
|
||||
$bSuccess = $oFeed->setSpotId($sValue);
|
||||
break;
|
||||
case 'project_id':
|
||||
case 'id_project':
|
||||
$bSuccess = $oFeed->setProjectId($sValue);
|
||||
break;
|
||||
default:
|
||||
$sDesc = $this->oLang->getTranslation('unknown_field', $sField);
|
||||
}
|
||||
$asResult = $oFeed->getFeed();
|
||||
break;
|
||||
}
|
||||
if(!$bSuccess) $sDesc = Mask::LANG_PREFIX.'error_commit_db';
|
||||
if(!$bSuccess && $sDesc=='') $sDesc = Mask::LANG_PREFIX.'error_commit_db';
|
||||
|
||||
return self::getJsonResult($bSuccess, $sDesc, array($sType=>array($asResult)));
|
||||
}
|
||||
@@ -537,16 +563,18 @@ class Spot extends Main
|
||||
switch($sType) {
|
||||
case 'project':
|
||||
$oProject = new Project($this->oDb, $iId);
|
||||
$sDesc = $oProject->delete();
|
||||
$asResult = $oProject->delete();
|
||||
$sDesc = $asResult['project'][0]['desc'];
|
||||
break;
|
||||
case 'feed':
|
||||
$oFeed = new Feed($this->oDb, $iId);
|
||||
$sDesc = $oFeed->delete();
|
||||
$asResult = array('feed'=>array($oFeed->delete()));
|
||||
$sDesc = $asResult['feed'][0]['desc'];
|
||||
break;
|
||||
}
|
||||
$bSuccess = ($sDesc=='');
|
||||
|
||||
return self::getJsonResult($bSuccess, $sDesc, array($sType=>array(array('id'=>$iId, 'del'=>$bSuccess))));
|
||||
return self::getJsonResult($bSuccess, $sDesc, $asResult);
|
||||
}
|
||||
|
||||
public function createProject() {
|
||||
@@ -586,9 +614,30 @@ class Spot extends Main
|
||||
return $iDegree.'°'.$iMinute."'".$fSecond.'"'.$sDirection;
|
||||
}
|
||||
|
||||
public function getTimeFormat($iTime) {
|
||||
$sDate = date('d/m/Y', $iTime);
|
||||
$sTime = date('H:i', $iTime);
|
||||
public function getTimeFormat($iTime, $sTimeZone='') {
|
||||
if($sTimeZone=='') $sTimeZone = date_default_timezone_get();
|
||||
|
||||
$oDate = new DateTime('@'.$iTime);
|
||||
$oDate->setTimezone(new DateTimeZone($sTimeZone));
|
||||
|
||||
$sDate = $oDate->format('d/m/Y');
|
||||
$sTime = $oDate->format('H:i');
|
||||
return $this->oLang->getTranslation('date_time', array($sDate, $sTime));
|
||||
}
|
||||
|
||||
public function getTimeZoneFromDate($sDate) {
|
||||
$sTimeZone = null;
|
||||
|
||||
preg_match('/(?<timezone>(\+|\-)\d{2}:?(\d{2}|))$/', $sDate, $asMatch);
|
||||
if(array_key_exists('timezone', $asMatch)) {
|
||||
$sTimeZone = $asMatch['timezone'];
|
||||
|
||||
//Complete short form: +12 => +1200
|
||||
if(strlen($sTimeZone) == 3) $sTimeZone .= '00';
|
||||
|
||||
//Add colon: +1200 => +12:00
|
||||
if(!strpos($sTimeZone, ':')) $sTimeZone = substr_replace($sTimeZone, ':', 3, 0);
|
||||
}
|
||||
return $sTimeZone;
|
||||
}
|
||||
}
|
||||
|
||||
2939
inc/uploader.php
2939
inc/uploader.php
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user