Video support
This commit is contained in:
72
inc/spot.php
72
inc/spot.php
@@ -7,7 +7,7 @@
|
||||
* - unix_time: UNIX (int) in UTC
|
||||
* - site_time: timestamp in site time (see Settings::TIMEZONE)
|
||||
* - iso_time: raw ISO 8601 in local timezone
|
||||
* - Pictures (table `pictures`):
|
||||
* - Medias (table `medias`):
|
||||
* - posted_on: timestamp in site time (see Settings::TIMEZONE)
|
||||
* - taken_on: timestamp in site time (see Settings::TIMEZONE)
|
||||
* - Posts (table `posts`):
|
||||
@@ -30,23 +30,23 @@ class Spot extends Main
|
||||
private $oProject;
|
||||
|
||||
/**
|
||||
* Picture Class
|
||||
* @var Picture
|
||||
* Media Class
|
||||
* @var Media
|
||||
*/
|
||||
private $oPicture;
|
||||
private $oMedia;
|
||||
|
||||
public function __construct($oClassManagement, $sProcessPage)
|
||||
{
|
||||
$asClasses = array(
|
||||
array('name'=>'feed', 'project'=>true),
|
||||
array('name'=>'project', 'project'=>true),
|
||||
array('name'=>'picture', 'project'=>true),
|
||||
array('name'=>'media', 'project'=>true),
|
||||
array('name'=>'converter', 'project'=>true)
|
||||
);
|
||||
parent::__construct($oClassManagement, $sProcessPage, $asClasses);
|
||||
|
||||
$this->oProject = new Project($this->oDb);
|
||||
$this->oPicture = new Picture($this->oDb, $this->oProject);
|
||||
$this->oMedia = new Media($this->oDb, $this->oProject);
|
||||
}
|
||||
|
||||
protected function install()
|
||||
@@ -66,7 +66,7 @@ class Spot extends Main
|
||||
Feed::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', 'site_time'),
|
||||
Picture::PIC_TABLE => array(Db::getId(Project::PROJ_TABLE), 'filename', 'taken_on', 'posted_on', 'rotate')
|
||||
Media::MEDIA_TABLE => array(Db::getId(Project::PROJ_TABLE), 'filename', 'type', 'taken_on', 'posted_on', 'rotate')
|
||||
),
|
||||
'types' => array
|
||||
(
|
||||
@@ -105,7 +105,7 @@ class Spot extends Main
|
||||
Feed::FEED_TABLE => "INDEX(`ref_feed_id`)",
|
||||
Feed::SPOT_TABLE => "INDEX(`ref_spot_id`)",
|
||||
Project::PROJ_TABLE => "UNIQUE KEY `uni_proj_name` (`codename`)",
|
||||
Picture::PIC_TABLE => "UNIQUE KEY `uni_file_name` (`filename`)"
|
||||
Media::MEDIA_TABLE=> "UNIQUE KEY `uni_file_name` (`filename`)"
|
||||
),
|
||||
'cascading_delete' => array
|
||||
(
|
||||
@@ -162,25 +162,25 @@ class Spot extends Main
|
||||
$bSuccess = !empty($asMessages);
|
||||
$sDesc = $bSuccess?'':self::NO_DATA;
|
||||
|
||||
//Add pictures
|
||||
//Add medias
|
||||
if($bSuccess) {
|
||||
$asPics = $this->getPictures('taken_on');
|
||||
$asMedias = $this->getMedias('taken_on');
|
||||
|
||||
//Assign pictures to closest message
|
||||
//Assign medias to closest message
|
||||
$iIndex = 0;
|
||||
$iMaxIndex = count($asMessages) - 1;
|
||||
foreach($asPics as $asPic) {
|
||||
while($iIndex <= $iMaxIndex && $asPic['unix_time'] > $asMessages[$iIndex]['unix_time']) {
|
||||
foreach($asMedias as $asMedia) {
|
||||
while($iIndex <= $iMaxIndex && $asMedia['unix_time'] > $asMessages[$iIndex]['unix_time']) {
|
||||
$iIndex++;
|
||||
}
|
||||
if($iIndex == 0) $iMsgIndex = $iIndex;
|
||||
elseif($iIndex > $iMaxIndex) $iMsgIndex = $iMaxIndex;
|
||||
else {
|
||||
$iHalfWayPoint = ($asMessages[$iIndex - 1]['unix_time'] + $asMessages[$iIndex]['unix_time'])/2;
|
||||
$iMsgIndex = ($asPic['unix_time'] >= $iHalfWayPoint)?$iIndex:($iIndex - 1);
|
||||
$iMsgIndex = ($asMedia['unix_time'] >= $iHalfWayPoint)?$iIndex:($iIndex - 1);
|
||||
}
|
||||
|
||||
$asMessages[$iMsgIndex]['pics'][] = $asPic;
|
||||
$asMessages[$iMsgIndex]['medias'][] = $asMedia;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -211,29 +211,29 @@ class Spot extends Main
|
||||
}
|
||||
|
||||
/**
|
||||
* Get valid pictures based on $sTimeRefField (both are on site time):
|
||||
* - taken_on: Date/time on which the picture was taken
|
||||
* - posted_on: Date/time on which the picture was uploaded
|
||||
* Get valid medias based on $sTimeRefField (both are on site time):
|
||||
* - taken_on: Date/time on which the media was taken
|
||||
* - posted_on: Date/time on which the media was uploaded
|
||||
* @param String $sTimeRefField Field to calculate relative times
|
||||
* @return Array Pictures info
|
||||
* @return Array Medias info
|
||||
*/
|
||||
private function getPictures($sTimeRefField)
|
||||
private function getMedias($sTimeRefField)
|
||||
{
|
||||
$asPics = $this->oPicture->getPicsInfo();
|
||||
$asValidPics = array();
|
||||
foreach($asPics as $iIndex=>$asPic) {
|
||||
$sTimeRef = $asPic[$sTimeRefField];
|
||||
$asMedias = $this->oMedia->getMediasInfo();
|
||||
$asValidMedias = array();
|
||||
foreach($asMedias as $iIndex=>$asMedia) {
|
||||
$sTimeRef = $asMedia[$sTimeRefField];
|
||||
if($sTimeRef >= $this->oProject->getActivePeriod('from') && $sTimeRef <= $this->oProject->getActivePeriod('to')) {
|
||||
$asPic['taken_on_formatted'] = date(self::FORMAT_TIME, strtotime($asPic['taken_on']));
|
||||
$asPic['displayed_id'] = 'N°'.($iIndex + 1);
|
||||
$asMedia['taken_on_formatted'] = date(self::FORMAT_TIME, strtotime($asMedia['taken_on']));
|
||||
$asMedia['displayed_id'] = 'N°'.($iIndex + 1);
|
||||
|
||||
$this->addTimeStamp($asPic, strtotime($sTimeRef));
|
||||
$asValidPics[] = $asPic;
|
||||
$this->addTimeStamp($asMedia, strtotime($sTimeRef));
|
||||
$asValidMedias[] = $asMedia;
|
||||
}
|
||||
}
|
||||
usort($asValidPics, function($a, $b){return $a['unix_time'] > $b['unix_time'];});
|
||||
usort($asValidMedias, function($a, $b){return $a['unix_time'] > $b['unix_time'];});
|
||||
|
||||
return $asValidPics;
|
||||
return $asValidMedias;
|
||||
}
|
||||
|
||||
private function getPosts()
|
||||
@@ -276,9 +276,9 @@ class Spot extends Main
|
||||
'feed' => $this->getSpotMessages(),
|
||||
'priority' => 0
|
||||
),
|
||||
'picture' => array(
|
||||
'table' => Picture::PIC_TABLE,
|
||||
'feed' => $this->getPictures('posted_on'),
|
||||
'media' => array(
|
||||
'table' => Media::MEDIA_TABLE,
|
||||
'feed' => $this->getMedias('posted_on'),
|
||||
'priority' => 1
|
||||
),
|
||||
'post' => array(
|
||||
@@ -308,8 +308,8 @@ class Spot extends Main
|
||||
return self::getJsonResult(true, '', $asFeeds);
|
||||
}
|
||||
|
||||
public function syncPics() {
|
||||
return $this->oPicture->syncFileFolder();
|
||||
public function syncMedias() {
|
||||
return $this->oMedia->syncFileFolder();
|
||||
}
|
||||
|
||||
public function addPost($sName, $sPost)
|
||||
@@ -327,7 +327,7 @@ class Spot extends Main
|
||||
public function upload()
|
||||
{
|
||||
$this->oClassManagement->incClass('uploader', true);
|
||||
$oUploader = new Uploader($this->oPicture);
|
||||
$oUploader = new Uploader($this->oMedia);
|
||||
|
||||
return $oUploader->sBody;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user