pictures table

This commit is contained in:
2019-02-03 01:26:56 +01:00
parent 0239bb0551
commit 3c4bafec64
14 changed files with 1751 additions and 1550 deletions

View File

@@ -13,10 +13,6 @@ class Spot extends Main
const SPOT_TABLE = 'spots';
const POST_TABLE = 'posts';
//Picture folders
const PIC_FOLDER = 'files/';
const THUMB_FOLDER = self::PIC_FOLDER.'thumbs/';
const FORMAT_TIME = 'd/m/Y à H:i';
const FEED_CHUNK_SIZE = 15;
@@ -27,15 +23,23 @@ class Spot extends Main
*/
private $oProject;
/**
* Picture Class
* @var Picture
*/
private $oPicture;
public function __construct($oClassManagement, $sProcessPage)
{
$asClasses = array(
array('name'=>'project', 'project'=>true),
array('name'=>'picture', 'project'=>true),
array('name'=>'cacher', 'project'=>true)
);
parent::__construct($oClassManagement, $sProcessPage, $asClasses);
$this->oProject = new Project($this->oDb);
$this->oPicture = new Picture($this->oDb, $this->oProject);
}
protected function install()
@@ -54,7 +58,8 @@ class Spot extends Main
self::FEED_TABLE => array('ref_feed_id', Db::getId(self::SPOT_TABLE), Db::getId(Project::PROJ_TABLE), 'name', 'description', 'status', 'last_update'),
self::SPOT_TABLE => array('ref_spot_id', 'name', 'model'),
Project::PROJ_TABLE => array('name', 'codename', 'active_from', 'active_to', 'geofile', 'timezone'),
self::POST_TABLE => array(Db::getId(Project::PROJ_TABLE), 'name', 'content', 'timestamp')
self::POST_TABLE => array(Db::getId(Project::PROJ_TABLE), 'name', 'content', 'timestamp'),
Picture::PIC_TABLE => array(Db::getId(Project::PROJ_TABLE), 'filename', 'taken_on', 'timestamp', 'rotate')
),
'types' => array
(
@@ -77,7 +82,10 @@ class Spot extends Main
'active_to' => "DATETIME",
'geofile' => "VARCHAR(50)",
'timezone' => "VARCHAR(100)",
'last_update' => "DATETIME"
'last_update' => "DATETIME",
'filename' => "VARCHAR(100) NOT NULL",
'taken_on' => "DATETIME",
'rotate' => "SMALLINT"
),
'constraints' => array
(
@@ -88,6 +96,7 @@ class Spot extends Main
self::FEED_TABLE => "INDEX(`ref_feed_id`)",
self::SPOT_TABLE => "INDEX(`ref_spot_id`)",
Project::PROJ_TABLE => "UNIQUE KEY `uni_proj_name` (`codename`)",
Picture::PIC_TABLE => "UNIQUE KEY `uni_file_name` (`filename`)"
),
'cascading_delete' => array
(
@@ -180,7 +189,7 @@ class Spot extends Main
}
}
public function getMessages()
public function getMarkers()
{
/* Adding another point to test
$test = $this->oDb->selectRow(self::MSG_TABLE, 1);
@@ -196,7 +205,7 @@ class Spot extends Main
//Add pictures
if($bSuccess) {
$asPics = $this->getPictures();
$asPics = $this->getPictures('taken_on');
//Sort messages and pictures chronologically
uasort($asPics, function($a, $b){return $a['unix_timestamp'] > $b['unix_timestamp'];});
@@ -255,13 +264,13 @@ class Spot extends Main
$asMessages = $this->oDb->selectRows($asInfo);
foreach($asMessages as $asMessage)
{
$asMessage['unix_timestamp'] = (int) $asMessage['unix_timestamp'];
$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['relative_time'] = Toolbox::getDateTimeDesc($asMessage['unix_timestamp'], 'fr');
$asMessage['formatted_time'] = date(self::FORMAT_TIME, $asMessage['unix_timestamp']);
$this->addTimeStamp($asMessage, $asMessage['unix_timestamp']);
$asAllFeedMessages[] = $asMessage;
}
}
@@ -269,34 +278,20 @@ class Spot extends Main
return $asAllFeedMessages;
}
private function getPictures()
private function getPictures($sTimeRefField)
{
$asPicPaths = glob(self::PIC_FOLDER.'*.{jpg,JPG,jpeg,JPEG,png,PNG}', GLOB_BRACE);
$asPics = array();
foreach($asPicPaths as $sPicPath)
{
//Finding picture timestamp
$asPicInfo = self::getPicInfo($sPicPath);
$iPicTimeStamp = $asPicInfo['timestamp'];
//Get/Create thumbnail
$sThumbnailPath = self::getPicThumbnail($sPicPath);
//Filter on valid time interval
if($iPicTimeStamp >= strtotime($this->oProject->getActivePeriod('from')) && $iPicTimeStamp <= strtotime($this->oProject->getActivePeriod('to'))) {
$asPics[] = array(
'path' => $sPicPath,
'thumb_path' => $sThumbnailPath,
'rotate' => $asPicInfo['rotate'],
'unix_timestamp'=> $iPicTimeStamp,
'formatted_time'=> date(self::FORMAT_TIME, $iPicTimeStamp),
'relative_time' => Toolbox::getDateTimeDesc($iPicTimeStamp, 'fr')
);
$asPics = $this->oPicture->getPicsInfo();
$asValidPics = array();
foreach($asPics as &$asPic) {
$sTimeRef = $asPic[$sTimeRefField];
if($sTimeRef >= $this->oProject->getActivePeriod('from') && $sTimeRef <= $this->oProject->getActivePeriod('to')) {
$asPic['taken_on_formatted'] = date(self::FORMAT_TIME, strtotime($asPic['taken_on']));
$this->addTimeStamp($asPic, strtotime($sTimeRef));
$asValidPics[] = $asPic;
}
}
return $asPics;
return $asValidPics;
}
private function getPosts()
@@ -314,10 +309,9 @@ class Spot extends Main
foreach($asPosts as &$asPost) {
$iUnixTimeStamp = strtotime($asPost['timestamp']);
$asPost['unix_timestamp'] = $iUnixTimeStamp;
$asPost['relative_time'] = Toolbox::getDateTimeDesc($iUnixTimeStamp, 'fr');
$asPost['formatted_time'] = date(self::FORMAT_TIME, $iUnixTimeStamp);
$asPost['formatted_name'] = Toolbox::mb_ucwords($asPost['name']);
$this->addTimeStamp($asPost, $iUnixTimeStamp);
}
return $asPosts;
@@ -328,23 +322,28 @@ class Spot extends Main
return ($iTimeStamp * -1).'.'.$sPriority.$iDbId;
}
private function addTimeStamp(&$asData, $iTime) {
$asData['unix_timestamp'] = (int) $iTime;
$asData['relative_time'] = Toolbox::getDateTimeDesc($iTime, 'fr');
$asData['formatted_time'] = date(self::FORMAT_TIME, $iTime);
}
public function getNewsFeed($iChunk=0)
{
$asFeed = array();
//Messages
$asMessages = $this->getSpotMessages();
foreach($asMessages as $asMessage)
foreach($asMessages as $iIndex=>$asMessage)
{
$iMsgId = $asMessage[Db::getId(self::MSG_TABLE)];
$iId = self::getJsonId($asMessage['unix_timestamp'], '0', $iMsgId);
$iId = self::getJsonId($asMessage['unix_timestamp'], '0', $asMessage[Db::getId(self::MSG_TABLE)]);
$asFeed[$iId] = $asMessage;
$asFeed[$iId]['type'] = 'message';
$asFeed[$iId]['displayed_id'] = $iMsgId;
$asFeed[$iId]['displayed_id'] = 'N°'.$iIndex;
}
//Pictures
$asPics = $this->getPictures();
$asPics = $this->getPictures('added_on');
foreach($asPics as $iKey=>$asPic)
{
$iId = self::getJsonId($asPic['unix_timestamp'], '1', $iKey);
@@ -370,6 +369,10 @@ class Spot extends Main
return self::getJsonResult(true, '', $asFeed);
}
public function syncPics() {
return $this->oPicture->syncFileFolder();
}
public function addPost($sName, $sPost)
{
$asData = array(
@@ -385,9 +388,9 @@ class Spot extends Main
public function upload()
{
$this->oClassManagement->incClass('uploader', true);
$oUploader = new Uploader(array('image_versions'=>array(), 'accept_file_types'=>'/\.(gif|jpe?g|png)$/i'));
$oUploader->init();
return $oUploader->getBody();
$oUploader = new Uploader($this->oPicture);
return self::getJsonResult(true, '');
}
public function getTile($sMapId, $iX, $iY, $iZ)
@@ -432,54 +435,6 @@ class Spot extends Main
}
}
public static function getPicInfo($sPicPath)
{
$iPicTimeStamp = $iPicTakenTimeStamp = $iPicFileTimeStamp = 0;
$asExif = @exif_read_data($sPicPath, 0, true);
if(!$asExif) $asExif['FILE']['FileDateTime'] = filemtime($sPicPath);
//Timestamps
if(array_key_exists('EXIF', $asExif) && array_key_exists('DateTimeOriginal', $asExif['EXIF'])) $iPicTakenTimeStamp = strtotime($asExif['EXIF']['DateTimeOriginal']);
if(array_key_exists('FILE', $asExif) && array_key_exists('FileDateTime', $asExif['FILE'])) $iPicFileTimeStamp = $asExif['FILE']['FileDateTime'];
//Merge timestamps
$iPicTimeStamp = ($iPicTakenTimeStamp > 0)?$iPicTakenTimeStamp:$iPicFileTimeStamp;
//Time Zone
//if($iPicTimeStamp >= self::HONEYMOON_DATE_BEG && $iPicTimeStamp <= self::HONEYMOON_DATE_END) $iPicTimeStamp -= 60*60*(12+1); //timezone + daylight saving
//Orientation
if(array_key_exists('IFD0', $asExif) && array_key_exists('Orientation', $asExif['IFD0'])) {
switch($asExif['IFD0']['Orientation'])
{
case 1: $sRotate = '0'; break; //None
case 3: $sRotate = '180'; break; //Flip over
case 6: $sRotate = '90'; break; //Clockwise
case 8: $sRotate = '-90'; break; //Trigo
default: $sRotate = $asExif['IFD0']['Orientation'];
}
}
else $sRotate = '0';
return array(
'timestamp' => $iPicTimeStamp,
'taken_ts' => $iPicTakenTimeStamp,
'file_ts' => $iPicFileTimeStamp,
'rotate' => $sRotate
);
}
public static function getPicThumbnail($sPicPath)
{
$sPicName = pathinfo($sPicPath, PATHINFO_BASENAME);
$sThumbPath = self::THUMB_FOLDER.$sPicName;
if(!file_exists($sThumbPath)) $asThumbInfo = ToolBox::createThumbnail($sPicPath, 400, 0, $sThumbPath/*, false, array('jpg', 'jpeg', 'gif', 'png'), true*/);
else $asThumbInfo = array('error'=>'', 'out'=>$sThumbPath);
return ($asThumbInfo['error']=='')?$asThumbInfo['out']:$sPicPath;
}
public static function DecToDMS($dValue, $sType='lat') {
if($sType=='lat') $sDirection = ($dValue >= 0)?'N':'S';
else $sDirection = ($dValue >= 0)?'E':'W';