code cleaning

This commit is contained in:
2018-04-15 13:14:37 +02:00
parent ffc94cb85a
commit 588f9bb102
2 changed files with 103 additions and 52 deletions

View File

@@ -192,23 +192,12 @@ class Spot extends Main
return $asMessages; return $asMessages;
} }
public function getNewsFeed($iChunk=0) private function getPictures()
{ {
$asFeed = array();
//Messages
$asMessages = $this->getSpotMessages();
foreach($asMessages as $asMessage)
{
$iId = ($asMessage['unix_timestamp']*-1).'.0'.$asMessage[Db::getId(self::MSG_TABLE)];
$asFeed[$iId] = $asMessage;// array('type'=>'message', 'time'=>$asMessage['relative_time'], 'text'=>$asMessage['relative_time']);
$asFeed[$iId]['type'] = 'message';
$asFeed[$iId]['id'] = $asMessage[Db::getId(self::MSG_TABLE)];
}
//Pictures
$asPicPaths = glob('files/*.{jpg,JPG,jpeg,JPEG,png,PNG}', GLOB_BRACE); $asPicPaths = glob('files/*.{jpg,JPG,jpeg,JPEG,png,PNG}', GLOB_BRACE);
foreach($asPicPaths as $iKey=>$sPicPath)
$asPics = array();
foreach($asPicPaths as $sPicPath)
{ {
//Finding picture timestamp //Finding picture timestamp
$asPicInfo = self::getPicInfo($sPicPath); $asPicInfo = self::getPicInfo($sPicPath);
@@ -218,44 +207,80 @@ class Spot extends Main
if( Settings::MODE != self::MODE_HISTO || if( Settings::MODE != self::MODE_HISTO ||
($iPicTimeStamp >= strtotime(Settings::HISTO_SPAN['from']) && $iPicTimeStamp <= strtotime(Settings::HISTO_SPAN['to']))) { ($iPicTimeStamp >= strtotime(Settings::HISTO_SPAN['from']) && $iPicTimeStamp <= strtotime(Settings::HISTO_SPAN['to']))) {
$asPics[($iPicTimeStamp*-1).'.1'.$iKey] = array( $asPics[] = array(
'type' => 'picture',
'path' => $sPicPath, 'path' => $sPicPath,
'rotate' => $asPicInfo['rotate'], 'rotate' => $asPicInfo['rotate'],
'timestamp' => $iPicTimeStamp,
'formatted_time'=> date(self::FORMAT_TIME, $iPicTimeStamp), 'formatted_time'=> date(self::FORMAT_TIME, $iPicTimeStamp),
'relative_time' => Toolbox::getDateTimeDesc($iPicTimeStamp) 'relative_time' => Toolbox::getDateTimeDesc($iPicTimeStamp)
); );
} }
} }
ksort($asPics); return $asPics;
$iCount = count($asPics);
foreach($asPics as $iKey=>$asPic)
{
$asFeed[$iKey] = $asPic;
$asFeed[$iKey]['id'] = $iCount--;
} }
//Post private function getPosts()
{
$asInfo = array('from'=>self::POST_TABLE); $asInfo = array('from'=>self::POST_TABLE);
if(Settings::MODE==self::MODE_HISTO) { if(Settings::MODE==self::MODE_HISTO) {
$asInfo['constraint'] = array('led'=>Settings::HISTO_SPAN); $asInfo['constraint'] = array('led'=>Settings::HISTO_SPAN);
$asInfo['constOpe'] = array('led'=>"BETWEEN"); $asInfo['constOpe'] = array('led'=>"BETWEEN");
} }
$asPosts = $this->oDb->selectRows($asInfo); $asPosts = $this->oDb->selectRows($asInfo);
foreach($asPosts as $asPost) foreach($asPosts as &$asPost) {
{
$iUnixTimeStamp = strtotime($asPost['led']); $iUnixTimeStamp = strtotime($asPost['led']);
$iId = ($iUnixTimeStamp*-1).'.2'.$asPost[Db::getId(self::POST_TABLE)]; $asPost['relative_time'] = Toolbox::getDateTimeDesc($iUnixTimeStamp);
$asFeed[$iId] = array('name'=>Toolbox::mb_ucwords($asPost['name']), 'post'=>$asPost['content'], 'type'=>'post');; $asPost['formatted_time'] = date(self::FORMAT_TIME, $iUnixTimeStamp);
$asFeed[$iId]['relative_time'] = Toolbox::getDateTimeDesc($iUnixTimeStamp); $asPost['formatted_name'] = Toolbox::mb_ucwords($asPost['name']);
$asFeed[$iId]['formatted_time'] = date(self::FORMAT_TIME, $iUnixTimeStamp);
//$asFeed[$iId]['id'] = $asPost[Db::getId(self::POST_TABLE)];
} }
return $asPosts;
}
private static function getJsonId($iTimeStamp, $sPriority='0', $iDbId=0)
{
return ($iTimeStamp * -1).'.'.$sPriority.$iDbId;
}
public function getNewsFeed($iChunk=0)
{
$asFeed = array();
//Messages
$asMessages = $this->getSpotMessages();
foreach($asMessages as $asMessage)
{
$iMsgId = $asMessage[Db::getId(self::MSG_TABLE)];
$iId = self::getJsonId($asMessage['unix_timestamp'], '0', $iMsgId);
$asFeed[$iId] = $asMessage;
$asFeed[$iId]['type'] = 'message';
$asFeed[$iId]['displayed_id'] = $iMsgId;
}
//Pictures
$asPics = $this->getPictures();
foreach($asPics as $iKey=>$asPic)
{
$iId = self::getJsonId($asPic['timestamp'], '1', $iKey);
$asFeed[$iId] = $asPic;
$asFeed[$iId]['type'] = 'picture';
}
//Post
$asPosts = $this->getPosts();
foreach($asPosts as $asPost)
{
$iId = self::getJsonId(strtotime($asPost['led']), '2', $asPost[Db::getId(self::POST_TABLE)]);
$asFeed[$iId] = $asPost;
$asFeed[$iId]['type'] = 'post';
}
//Sort by key
ksort($asFeed); ksort($asFeed);
//split chunks //Split chunks
$asFeed = array_slice($asFeed, $iChunk*self::FEED_CHUNK_SIZE, self::FEED_CHUNK_SIZE); //$asFeed = array_slice($asFeed, $iChunk*self::FEED_CHUNK_SIZE, self::FEED_CHUNK_SIZE);
return self::getJsonResult(true, '', $asFeed); return self::getJsonResult(true, '', $asFeed);
} }
@@ -277,12 +302,15 @@ class Spot extends Main
public static function getPicInfo($sPicPath) public static function getPicInfo($sPicPath)
{ {
$iPicTimeStamp = 0; $iPicTimeStamp = $iPicTakenTimeStamp = $iPicFileTimeStamp = 0;
$asExif = @exif_read_data($sPicPath, 0, true); $asExif = @exif_read_data($sPicPath, 0, true);
//Timestamp //Timestamps
if(!empty($asExif) && array_key_exists('DateTimeOriginal', $asExif['EXIF'])) $iPicTimeStamp = strtotime($asExif['EXIF']['DateTimeOriginal']); if(!empty($asExif) && array_key_exists('DateTimeOriginal', $asExif['EXIF'])) $iPicTakenTimeStamp = strtotime($asExif['EXIF']['DateTimeOriginal']);
else $iPicTimeStamp = $asExif['FILE']['FileDateTime']; if(!empty($asExif) && array_key_exists('FileDateTime', $asExif['FILE'])) $iPicFileTimeStamp = $asExif['FILE']['FileDateTime'];
//Merge timestamps
$iPicTimeStamp = ($iPicTakenTimeStamp > 0)?$iPicTakenTimeStamp:$iPicFileTimeStamp;
//Time Zone //Time Zone
//if($iPicTimeStamp >= self::HONEYMOON_DATE_BEG && $iPicTimeStamp <= self::HONEYMOON_DATE_END) $iPicTimeStamp -= 60*60*(12+1); //timezone + daylight saving //if($iPicTimeStamp >= self::HONEYMOON_DATE_BEG && $iPicTimeStamp <= self::HONEYMOON_DATE_END) $iPicTimeStamp -= 60*60*(12+1); //timezone + daylight saving
@@ -300,7 +328,12 @@ class Spot extends Main
} }
else $sRotate = '0'; else $sRotate = '0';
return array('timestamp'=>$iPicTimeStamp, 'rotate'=>$sRotate); return array(
'timestamp' => $iPicTimeStamp,
'taken_ts' => $iPicTimeStamp,
'file_ts' => $iPicTimeStamp,
'rotate' => $sRotate
);
} }
} }

View File

@@ -118,6 +118,10 @@ oSpot.pageInit = function(asHash)
oMarker.addListener('mouseout', function(){ oMarker.addListener('mouseout', function(){
oInfoWindow.close(oMap, oMarker); oInfoWindow.close(oMap, oMarker);
}); });
oMarker.addListener('click', function(){
self.tmp('map').panTo(oMarker.getPosition());
self.tmp('map').setZoom(15);
});
}); });
//Recenter map once loaded to be at the center of 70% (iMapRatio) of the page //Recenter map once loaded to be at the center of 70% (iMapRatio) of the page
@@ -239,10 +243,10 @@ function getPost(asPost) {
{ {
case 'message': case 'message':
$Body = $('<div>') $Body = $('<div>')
.append($('<p>').addIcon('fa-compass', true).append(asPost.latitude+' | '+asPost.longitude)) .append($('<p>').addIcon('fa-compass', true).append('Latitude '+asPost.latitude+', Longitude '+asPost.longitude))
.append($('<p>').addIcon('fa-clock-o', true).append(sAbsTime)) .append($('<p>').addIcon('fa-clock-o', true).append(sAbsTime))
.append( .append(
$('<img>', {'class':'staticmap', src:'https://maps.googleapis.com/maps/api/staticmap?center='+asPost.latitude+','+asPost.longitude+'&zoom=13&size=400x300&maptype=satellite&markers=color:green|label:|'+asPost.latitude+','+asPost.longitude+'&key='+self.vars('google_api')}) $('<img>', {'class':'staticmap', title: 'Click pour zoomer', src: getStaticMapUrl(asPost.latitude, asPost.longitude)})
.data('lat', asPost.latitude) .data('lat', asPost.latitude)
.data('lng', asPost.longitude) .data('lng', asPost.longitude)
.click(function(){ .click(function(){
@@ -260,8 +264,8 @@ function getPost(asPost) {
break; break;
case 'post': case 'post':
$Body = $('<div>') $Body = $('<div>')
.append($('<p>', {'class':'message'}).text(asPost.post)) .append($('<p>', {'class':'message'}).text(asPost.content))
.append($('<p>', {'class':'signature'}).text('-- '+asPost.name)); .append($('<p>', {'class':'signature'}).text('-- '+asPost.formatted_name));
sClass = 'comment'; sClass = 'comment';
break; break;
case 'poster': case 'poster':
@@ -278,10 +282,24 @@ function getPost(asPost) {
.append($('<span>', {'class':'time', 'title':sAbsTime}).text(sRelTime))) .append($('<span>', {'class':'time', 'title':sAbsTime}).text(sRelTime)))
.append($('<div>', {'class':'body'}).append($Body)); .append($('<div>', {'class':'body'}).append($Body));
if(asPost.id) $Post.find('.index').append(' '+asPost.id); if(asPost.displayed_id) $Post.find('.index').append(' '+asPost.displayed_id);
//if(asPost.type=='picture' && asPost.rotate!='0') $Body.height($Image.height()); //if(asPost.type=='picture' && asPost.rotate!='0') $Body.height($Image.height());
return $Post; return $Post;
} }
function getStaticMapUrl(oCenterLat, oCenterLng){
var sDomain = 'https://maps.googleapis.com/maps/api/staticmap';
var asParams = {
center: oCenterLat+','+oCenterLng,
zoom: '13',
size: '400x300',
maptype: 'satellite',
markers: 'color:green|label:|'+oCenterLat+','+oCenterLng,
key: self.vars('google_api')
};
return sDomain+'?'+Object.keys(asParams).map(k => k+'='+asParams[k]).join('&');
}
</script> </script>