Compare commits

...

2 Commits

Author SHA1 Message Date
73f2e6c6e4 Video support 2019-06-30 21:46:41 +02:00
e1aac63ae0 Allow upload of videos 2019-06-28 22:17:46 +02:00
15 changed files with 448 additions and 262 deletions

2
.gitignore vendored
View File

@@ -12,4 +12,6 @@
/files/**/*.JPEG
/files/**/*.png
/files/**/*.PNG
/files/**/*.mov
/files/**/*.MOV
/geo/*.geojson

View File

@@ -0,0 +1,4 @@
RENAME TABLE pictures TO medias;
ALTER TABLE medias CHANGE COLUMN id_picture id_media INT(10) UNSIGNED NOT NULL auto_increment;
ALTER TABLE medias ADD COLUMN type VARCHAR(20) AFTER filename;
UPDATE medias SET type = 'image';

222
inc/media.php Normal file
View File

@@ -0,0 +1,222 @@
<?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
*/
private $oProject;
private $asMedias;
private $sSystemType;
public function __construct(Db &$oDb, &$oProject) {
parent::__construct(__CLASS__, Settings::DEBUG);
$this->oDb = &$oDb;
$this->oProject = &$oProject;
$this->sSystemType = (substr(php_uname(), 0, 7) == "Windows")?'win':'unix';
}
public function getMediasInfo() {
if(empty($this->asMedias)) {
if($this->oProject->getProjectId()) {
$asMedias = $this->oDb->selectRows(array(
'select' => array(Db::getId(self::MEDIA_TABLE), 'filename', 'taken_on', 'posted_on', 'rotate'),
'from' => self::MEDIA_TABLE,
'constraint'=> array(Db::getId(Project::PROJ_TABLE) => $this->oProject->getProjectId())
));
foreach($asMedias as &$asMedia) {
$asMedia['pic_path'] = self::getMediaPath($asMedia['filename']);
$asMedia['thumb_path'] = $this->getMediaThumbnail($asMedia['filename']);
}
$this->asMedias = $asMedias;
}
}
return $this->asMedias;
}
public function isProjectModeValid() {
return ($this->oProject->getMode() == Project::MODE_BLOG);
}
public function addMedia($sMediaName, $sMethod='upload') {
$sError = '';
if(!$this->isProjectModeValid() && $sMethod!='sync') $sError = 'Le projet (id='.$this->oProject->getProjectId().') n\'est pas en mode "blog"';
elseif($this->oDb->pingValue(self::MEDIA_TABLE, array('filename'=>$sMediaName)) && $sMethod!='sync') $sError = 'l\'image existe déjà';
else {
//Add media to DB
$asMediaInfo = $this->getMediaInfoFromFile($sMediaName);
$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 (Settings::TIMEZONE)
'posted_on' => date(Db::TIMESTAMP_FORMAT, $asMediaInfo['file_ts']), //Site Time
'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 = 'l\'image n\'a pas pu être entrée en base';
else {
//Create thumbnail
$this->getMediaThumbnail($sMediaName);
}
}
if($sError!='') {
$sError = 'Erreur lors de l\'ajout de "'.$sMediaName.'" : '.$sError;
$this->addError($sError);
}
return $sError;
}
/**
* One-shot function to initialize DB with existing images
*/
public function syncFileFolder() {
$asMediaPaths = glob(self::getMediaPath('*.{jpg,JPG,jpeg,JPEG,png,PNG,mov,MOV}'), GLOB_BRACE);
foreach($asMediaPaths as $sMediaPath)
{
$sMediaName = pathinfo($sMediaPath, PATHINFO_BASENAME);
$this->addMedia($sMediaName, 'sync');
}
$this->setExtractMode(PhpObject::MODE_HTML);
return $this->getCleanMessageStack();
}
private function getMediaInfoFromFile($sMediaName)
{
$sMediaPath = self::getMediaPath($sMediaName);
$sType = self::getMediaType($sMediaName);
$iTimeStamp = $iTakenOn = $iPostedOn = 0;
$sRotate = '0';
$sTakenOn = '';
switch($sType) {
case 'video':
$asResult = array();
$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
'-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);
//Orientation
if(isset($asResult['streams'][0]['tags']['rotate'])) $sRotate = $asResult['streams'][0]['tags']['rotate'];
break;
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'];
if(array_key_exists('FILE', $asExif) && array_key_exists('FileDateTime', $asExif['FILE'])) $iPostedOn = $asExif['FILE']['FileDateTime'];
//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
}
}
break;
}
//Media info do not have any TZ: Interpreting date time using project timezone (assuming all medias have been taken in this time zone)
if($sTakenOn != '') {
$oTakenOn = new DateTime($sTakenOn, new DateTimeZone($this->oProject->getTimeZone()));
$iTakenOn = $oTakenOn->format('U');
}
//Merge timestamps
$iTimeStamp = ($iTakenOn > 0)?$iTakenOn:$iPostedOn;
return array(
'timestamp' => $iTimeStamp,
'taken_ts' => $iTakenOn,
'file_ts' => $iPostedOn,
'rotate' => $sRotate,
'type' => $sType
);
}
private function getMediaThumbnail($sMediaName)
{
$sMediaPath = self::getMediaPath($sMediaName);
$sThumbPath = self::getMediaPath($sMediaName, 'thumbnail');
$sType = self::getMediaType($sMediaName);
if(!file_exists($sThumbPath)) {
switch($sType) {
case 'image':
$asThumbInfo = ToolBox::createThumbnail($sMediaPath, self::THUMB_MAX_WIDTH, 0, $sThumbPath, false, array('jpg', 'jpeg', 'gif', 'png'), false, true);
break;
case 'video':
//Get a screenshot of the video 1 second in
$sTempPath = self::getMediaPath(uniqid('temp_').'.png');
$asResult = array();
$sParams = implode(' ', array(
'-i "'.$sMediaPath.'"', //input file
'-ss 00:00:01.000', //Image taken after x seconds
'-vframes 1', //number of video frames to output
'"'.$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.(self::getMediaType($sMediaName)=='video'?'.png':'');
else return self::MEDIA_FOLDER.$sMediaName;
}
private static function getMediaType($sMediaName) {
$sMediaPath = self::getMediaPath($sMediaName);
$sMediaMime = mime_content_type($sMediaPath);
switch($sMediaMime) {
case 'video/quicktime': $sType = 'video'; break;
default: $sType = 'image'; break;
}
return $sType;
}
}

View File

@@ -1,157 +0,0 @@
<?php
class Picture extends PhpObject {
//DB Tables
const PIC_TABLE = 'pictures';
//Picture folders
const PIC_FOLDER = 'files/';
const THUMB_FOLDER = self::PIC_FOLDER.'thumbs/';
/**
* Database Handle
* @var Db
*/
private $oDb;
/**
* Picture Project
* @var Project
*/
private $oProject;
private $asPics;
public function __construct(Db &$oDb, &$oProject) {
parent::__construct(__CLASS__, Settings::DEBUG);
$this->oDb = &$oDb;
$this->oProject = &$oProject;
}
public function getPicsInfo() {
if(empty($this->asPics)) {
if($this->oProject->getProjectId()) {
$asPics = $this->oDb->selectRows(array(
'select' => array(Db::getId(self::PIC_TABLE), 'filename', 'taken_on', 'posted_on', 'rotate'),
'from' => self::PIC_TABLE,
'constraint'=> array(Db::getId(Project::PROJ_TABLE) => $this->oProject->getProjectId())
));
foreach($asPics as &$asPic) {
$asPic['pic_path'] = self::getPicPath($asPic['filename']);
$asPic['thumb_path'] = self::getPicThumbnail($asPic['filename']);
}
$this->asPics = $asPics;
}
}
return $this->asPics;
}
public function isProjectModeValid() {
return ($this->oProject->getMode() == Project::MODE_BLOG);
}
public function addPic($sPicName, $sMethod='upload') {
$sError = '';
if(!$this->isProjectModeValid() && $sMethod!='sync') $sError = 'Le projet (id='.$this->oProject->getProjectId().') n\'est pas en mode "blog"';
elseif($this->oDb->pingValue(self::PIC_TABLE, array('filename'=>$sPicName)) && $sMethod!='sync') $sError = 'l\'image existe déjà';
else {
//Add picture to DB
$asPicInfo = $this->getPicInfoFromFile($sPicName);
$asDbInfo = array(
Db::getId(Project::PROJ_TABLE) => $this->oProject->getProjectId(),
'filename' => $sPicName,
'taken_on' => ($asPicInfo['taken_ts'] > 0)?date(Db::TIMESTAMP_FORMAT, $asPicInfo['taken_ts']):0, //Site Time (Settings::TIMEZONE)
'posted_on' => date(Db::TIMESTAMP_FORMAT, $asPicInfo['file_ts']), //Site Time
'rotate' => $asPicInfo['rotate']
);
if($sMethod=='sync') $iPicId = $this->oDb->insertUpdateRow(self::PIC_TABLE, $asDbInfo, array(Db::getId(Project::PROJ_TABLE), 'filename'));
else $iPicId = $this->oDb->insertRow(self::PIC_TABLE, $asDbInfo);
if(!$iPicId) $sError = 'l\'image n\'a pas pu être entrée en base';
else {
//Create thumbnail
self::getPicThumbnail($sPicName);
}
}
if($sError!='') {
$sError = 'Erreur lors de l\'ajout de "'.$sPicName.'" : '.$sError;
$this->addError($sError);
}
return $sError;
}
/**
* One-shot function to initialize DB with existing images
*/
public function syncFileFolder() {
$asPicPaths = glob(self::getPicPath('*.{jpg,JPG,jpeg,JPEG,png,PNG}'), GLOB_BRACE);
foreach($asPicPaths as $sPicPath)
{
$sPicName = pathinfo($sPicPath, PATHINFO_BASENAME);
$this->addPic($sPicName, 'sync');
}
$this->setExtractMode(PhpObject::MODE_HTML);
return $this->getCleanMessageStack();
}
private function getPicInfoFromFile($sPicName)
{
$sPicPath = self::getPicPath($sPicName);
$iTimeStamp = $iTakenOn = $iPostedOn = 0;
$sTakenOn = '';
$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'])) $sTakenOn = $asExif['EXIF']['DateTimeOriginal'];
if(array_key_exists('FILE', $asExif) && array_key_exists('FileDateTime', $asExif['FILE'])) $iPostedOn = $asExif['FILE']['FileDateTime'];
//Picture info do not have any TZ: Interpreting date time using project timezone (assuming all pictures have been taken in this time zone)
if($sTakenOn != '') {
$oTakenOn = new DateTime($sTakenOn, new DateTimeZone($this->oProject->getTimeZone()));
$iTakenOn = $oTakenOn->format('U');
}
//Merge timestamps
$iTimeStamp = ($iTakenOn > 0)?$iTakenOn:$iPostedOn;
//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 = '0';
}
}
else $sRotate = '0';
return array(
'timestamp' => $iTimeStamp,
'taken_ts' => $iTakenOn,
'file_ts' => $iPostedOn,
'rotate' => $sRotate
);
}
private static function getPicThumbnail($sPicName)
{
$sPicPath = self::getPicPath($sPicName);
$sThumbPath = self::getPicPath($sPicName, 'thumbnail');
if(!file_exists($sThumbPath)) $asThumbInfo = ToolBox::createThumbnail($sPicPath, 400, 0, $sThumbPath, false, array('jpg', 'jpeg', 'gif', 'png'), false, true);
else $asThumbInfo = array('error'=>'', 'out'=>$sThumbPath);
return ($asThumbInfo['error']=='')?$asThumbInfo['out']:$sPicPath;
}
private static function getPicPath($sPicName, $sFileType='picture') {
return ($sFileType=='thumbnail'?self::THUMB_FOLDER:self::PIC_FOLDER).$sPicName;
}
}

View File

@@ -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;
}

View File

@@ -3,26 +3,26 @@
class Uploader extends UploadHandler
{
/**
* Pictures Management
* @var Picture
* Medias Management
* @var Media
*/
private $oPicture;
private $oMedia;
public $sBody;
function __construct(&$oPicture)
function __construct(&$oMedia)
{
$this->error_messages['wrong_project_mode'] = 'Le projet n\'est pas en mode "blog".';
$this->oPicture = &$oPicture;
$this->oMedia = &$oMedia;
$this->sBody = '';
parent::__construct(array('image_versions'=>array(), 'accept_file_types'=>'/\.(gif|jpe?g|png)$/i'));
parent::__construct(array('image_versions'=>array(), 'accept_file_types'=>'/\.(gif|jpe?g|png|mov)$/i'));
}
protected function validate($uploaded_file, $file, $error, $index) {
$bResult = parent::validate($uploaded_file, $file, $error, $index);
//Check project mode
if(!$this->oPicture->isProjectModeValid()) {
if(!$this->oMedia->isProjectModeValid()) {
$file->error = $this->get_error_message('wrong_project_mode');
$bResult = false;
}
@@ -34,7 +34,7 @@ class Uploader extends UploadHandler
$file = parent::handle_file_upload($uploaded_file, $name, $size, $type, $error, $index, $content_range);
if(empty($file->error)) {
$sError = $this->oPicture->addPic($file->name);
$sError = $this->oMedia->addMedia($file->name);
if($sError!='') {
$file->error = $this->get_error_message($sError);
}

View File

@@ -88,7 +88,8 @@ function initPage(asHash) {
albumLabel: "Photo %1 sur %2",
fadeDuration: 300,
imageFadeDuration: 400,
resizeDuration: 600
resizeDuration: 600,
hasVideo: true
});
//Assign Track Type Colors
@@ -391,7 +392,7 @@ function initSpotMessages(aoMessages, aoTracks) {
.append('Lat : '+oMsg.latitude+', Lng : '+oMsg.longitude));
//Tooltip pictures
if(oMsg.pics) {
if(oMsg.medias) {
var $Pics = $('<div>', {'class':'pics'});
$.each(oMsg.pics, function(iKey, asPic){
$Pics.append($('<a>', {href: asPic.pic_path, 'data-lightbox': 'marker-pictures', 'data-title': 'Photo prise le '+asPic.formatted_time+self.tmp('site_tz_notice'), 'data-orientation': asPic.rotate})
@@ -500,10 +501,11 @@ function getPost(asPost) {
}
);
break;
case 'picture':
case 'media':
var sTakenOn = (asPost.taken_on == '0000-00-00 00:00:00')?'':' et prise le '+asPost.taken_on_formatted+self.tmp('site_tz_notice');
var $Image = $('<img>', {'src': asPost.thumb_path, title: 'Click pour zoomer'});
$Body = $('<a>', {href: asPost.pic_path, 'data-lightbox': 'post-pictures', 'data-title': 'Photo ajoutée le '+sAbsTime+sTakenOn, 'data-orientation': asPost.rotate}).append($Image);
var sVideo = asPost.pic_path.toLowerCase().split('.').pop()=='mov'?'true':'false';
$Body = $('<a>', {href: asPost.pic_path, 'data-video': sVideo, 'data-lightbox': 'post-pictures', 'data-title': 'Photo ajoutée le '+sAbsTime+sTakenOn, 'data-orientation': asPost.rotate}).append($Image);
break;
case 'post':
$Body = $('<div>')

View File

@@ -1,5 +1,5 @@
<div id="upload">
<h1>Pictures upload</h1>
<h1>Picture &amp; Video Uploads</h1>
<input id="fileupload" type="file" name="files[]" multiple>
<div id="progress">
<div class="bar" style="width: 0%;"></div>
@@ -15,7 +15,7 @@ oSpot.pageInit = function(asHash)
.attr('data-url', self.getActionLink('upload'))
.fileupload({
dataType: 'json',
acceptFileTypes: /(\.|\/)(gif|jpe?g|png)$/i,
acceptFileTypes: /(\.|\/)(gif|jpe?g|png|mov)$/i,
done: function (e, asData) {
var $Status = $('#status');
$.each(asData.result.files, function(iKey, oFile) {

View File

@@ -3,10 +3,7 @@
## Dependencies
* php-mbstring
* php-imagick
* ffprobe (ffmpeg)
## To Do List
* require js
* Video support
* Upload
* Preloader
* Resize
* Navigation
* Video support on markers

View File

@@ -62,6 +62,9 @@
to prevent xss and other injection attacks.
*/
sanitizeTitle: false
//ADDED-START
, hasVideo: false
//ADDED-END
};
Lightbox.prototype.option = function(options) {
@@ -109,6 +112,19 @@
this.$image = this.$lightbox.find('.lb-image');
this.$nav = this.$lightbox.find('.lb-nav');
//ADDED-START
if(self.options.hasVideo) {
this.$video = $('<video class="lb-video" src="" controls autoplay></video>');
this.$image.after(this.$video);
this.videoBorderWidth = {
top: parseInt(this.$video.css('border-top-width'), 10),
right: parseInt(this.$video.css('border-right-width'), 10),
bottom: parseInt(this.$video.css('border-bottom-width'), 10),
left: parseInt(this.$video.css('border-left-width'), 10)
};
}
//ADDED-END
// Store css values for future lookup
this.containerPadding = {
top: parseInt(this.$container.css('padding-top'), 10),
@@ -217,6 +233,7 @@
title: $link.attr('data-title') || $link.attr('title')
//ADDED-START
, orientation: $link.attr('data-orientation')
, video: (self.options.hasVideo && typeof $link.attr('data-video') !== 'undefined' && $link.attr('data-video') === 'true')
//ADDED-END
});
}
@@ -248,7 +265,7 @@
}
}
}
// Position Lightbox
var top = $window.scrollTop() + this.options.positionFromTop;
var left = $window.scrollLeft();
@@ -275,9 +292,67 @@
this.$overlay.fadeIn(this.options.fadeDuration);
$('.lb-loader').fadeIn('slow');
this.$lightbox.find('.lb-image, .lb-nav, .lb-prev, .lb-next, .lb-dataContainer, .lb-numbers, .lb-caption').hide();
//ADDED-START
//this.$lightbox.find('.lb-image, .lb-nav, .lb-prev, .lb-next, .lb-dataContainer, .lb-numbers, .lb-caption').hide();
this.$lightbox.find('.lb-image, .lb-video, .lb-nav, .lb-prev, .lb-next, .lb-dataContainer, .lb-numbers, .lb-caption').hide();
//ADDED-END
this.$outerContainer.addClass('animating');
//ADDED-START
if(self.options.hasVideo) {
var $video = this.$lightbox.find('.lb-video');
var $lbContainer = this.$lightbox.find('.lb-container');
var $hasVideoNav = $lbContainer.hasClass('lb-video-nav');
if(self.album[imageNumber].video) {
$video.on('loadedmetadata', function(){
var $This = $(this);
//TODO merge with image
if(self.options.fitImagesInViewport) {
windowWidth = $(window).width();
windowHeight = $(window).height();
maxVideoWidth = windowWidth - self.containerPadding.left - self.containerPadding.right - self.videoBorderWidth.left - self.videoBorderWidth.right - 20;
maxVideoHeight = windowHeight - self.containerPadding.top - self.containerPadding.bottom - self.videoBorderWidth.top - self.videoBorderWidth.bottom - 120;
//Check if image size is larger then maxWidth|maxHeight in settings
if(self.options.maxWidth && self.options.maxWidth < maxVideoWidth) maxVideoWidth = self.options.maxWidth;
if(self.options.maxHeight && self.options.maxHeight < maxVideoWidth) maxVideoHeight = self.options.maxHeight;
//Is the current image's width or height is greater than the maxImageWidth or maxImageHeight
//option than we need to size down while maintaining the aspect ratio.
if((this.videoWidth > maxVideoWidth) || (this.videoHeight > maxVideoHeight)) {
if ((this.videoWidth / maxVideoWidth) > (this.videoHeight / maxVideoHeight)) {
videoWidth = maxVideoWidth;
videoHeight = parseInt(this.videoHeight / (this.videoWidth / videoWidth), 10);
$This.width(videoWidth);
$This.height(videoHeight);
} else {
videoHeight = maxVideoHeight;
videoWidth = parseInt(this.videoWidth / (this.videoHeight / videoHeight), 10);
$This.width(videoWidth);
$This.height(videoHeight);
}
}
}
self.sizeContainer($This.width(), $This.height(), 'video');
$This.off('loadedmetadata');
});
this.currentImageIndex = imageNumber;
$video.attr('src', self.album[imageNumber].link);
if(!$hasVideoNav) $lbContainer.addClass('lb-video-nav');
return;
}
else {
$video.attr('src', '');
if($hasVideoNav) $lbContainer.removeClass('lb-video-nav');
}
}
//ADDED-END
// When image to show is preloaded, we send the width and height to sizeContainer()
var preloader = new Image();
@@ -341,7 +416,10 @@
}
}
}
self.sizeContainer($image.width(), $image.height());
//ADDED-START
//self.sizeContainer($image.width(), $image.height());
self.sizeContainer($image.width(), $image.height(), 'image');
//ADDED-END
};
preloader.src = this.album[imageNumber].link;
@@ -356,14 +434,23 @@
};
// Animate the size of the lightbox to fit the image we are showing
Lightbox.prototype.sizeContainer = function(imageWidth, imageHeight) {
var self = this;
//ADDED-START
//Lightbox.prototype.sizeContainer = function(imageWidth, imageHeight) {
Lightbox.prototype.sizeContainer = function(imageWidth, imageHeight, media) {
media = media || 'image';
//ADDED-END
var self = this;
var oldWidth = this.$outerContainer.outerWidth();
var oldHeight = this.$outerContainer.outerHeight();
var newWidth = imageWidth + this.containerPadding.left + this.containerPadding.right + this.imageBorderWidth.left + this.imageBorderWidth.right;
var newHeight = imageHeight + this.containerPadding.top + this.containerPadding.bottom + this.imageBorderWidth.top + this.imageBorderWidth.bottom;
//ADDED-START
//var newWidth = imageWidth + this.containerPadding.left + this.containerPadding.right + this.imageBorderWidth.left + this.imageBorderWidth.right;
//var newHeight = imageHeight + this.containerPadding.top + this.containerPadding.bottom + this.imageBorderWidth.top + this.imageBorderWidth.bottom;
var mediaBorderWidth = (media=='image')?this.imageBorderWidth:this.videoBorderWidth;
var newWidth = imageWidth + this.containerPadding.left + this.containerPadding.right + mediaBorderWidth.left + mediaBorderWidth.right;
var newHeight = imageHeight + this.containerPadding.top + this.containerPadding.bottom + mediaBorderWidth.top + mediaBorderWidth.bottom;
//ADDED-END
function postResize() {
self.$lightbox.find('.lb-dataContainer').width(newWidth);
self.$lightbox.find('.lb-prevLink').height(newHeight);
@@ -386,8 +473,13 @@
// Display the image and its details and begin preload neighboring images.
Lightbox.prototype.showImage = function() {
this.$lightbox.find('.lb-loader').stop(true).hide();
this.$lightbox.find('.lb-image').fadeIn(this.options.imageFadeDuration);
//ADDED-START
//this.$lightbox.find('.lb-image').fadeIn(this.options.imageFadeDuration);
if(this.options.hasVideo && this.album[this.currentImageIndex].video) this.$lightbox.find('.lb-video').fadeIn(this.options.imageFadeDuration);
else this.$lightbox.find('.lb-image').fadeIn(this.options.imageFadeDuration);
//ADDED-END
this.updateNav();
this.updateDetails();
this.preloadNeighboringImages();
@@ -433,7 +525,7 @@
// Display caption, image number, and closing button.
Lightbox.prototype.updateDetails = function() {
var self = this;
// Enable anchor clicks in the injected caption html.
// Thanks Nate Wright for the fix. @https://github.com/NateWr
if (typeof this.album[this.currentImageIndex].title !== 'undefined' &&
@@ -515,6 +607,18 @@
// Closing time. :-(
Lightbox.prototype.end = function() {
this.disableKeyboardNav();
//ADDED-START
if(this.options.hasVideo) {
var $video = this.$lightbox.find('.lb-video');
var $lbContainer = this.$lightbox.find('.lb-container');
var $hasVideoNav = $lbContainer.hasClass('lb-video-nav');
$video.attr('src', '');
if($hasVideoNav) $lbContainer.removeClass('lb-video-nav');
}
//ADDED-END
$(window).off('resize', this.sizeOverlay);
this.$lightbox.fadeOut(this.options.fadeDuration);
this.$overlay.fadeOut(this.options.fadeDuration);

View File

@@ -7,40 +7,42 @@
@extend .#{$fa-css-prefix}-#{$icon};
}
.lb-cancel {
@include lightbox-icon(cancel);
@extend .flicker;
color: #CCC;
}
.lb-nav a.lb-prev, .lb-nav a.lb-next {
color: white;
text-decoration: none;
.lightbox {
.lb-cancel {
@include lightbox-icon(cancel);
@extend .flicker;
color: #CCC;
}
&:before {
position: absolute;
top: calc(50% - 1em);
.lb-nav a.lb-prev, .lb-nav a.lb-next {
color: white;
text-decoration: none;
&:before {
position: absolute;
top: calc(50% - 1em);
}
}
.lb-nav a.lb-prev {
@include lightbox-icon(prev);
&:before {
left: 2em;
}
}
}
.lb-nav a.lb-prev {
@include lightbox-icon(prev);
&:before {
left: 2em;
.lb-nav a.lb-next {
@include lightbox-icon(next);
&:before {
right: 2em;
}
}
}
.lb-nav a.lb-next {
@include lightbox-icon(next);
&:before {
right: 2em;
.lb-data .lb-close {
@include lightbox-icon(close);
}
.lb-image {
image-orientation: from-image;
}
}
.lb-data .lb-close {
@include lightbox-icon(close);
}
.lb-image {
image-orientation: from-image;
}

View File

@@ -9,8 +9,8 @@ $post-color: #323268;
$post-bg: #B4BDFF;
$message-color: #326526;
$message-bg: #6DFF58;
$picture-color: #635C28;
$picture-bg: #F3EC9F;
$media-color: #635C28;
$media-bg: #F3EC9F;
//Legend colors
$track-main-color: #00ff78;
@@ -302,9 +302,9 @@ $legend-color: #222;
padding-top: 0.5em;
}
}
&.picture {
background: $picture-bg;
color: $picture-color;
&.media {
background: $media-bg;
color: $media-color;
a {
display: inline-block;

View File

@@ -38,6 +38,16 @@ html.lb-disable-scrolling {
border: 4px solid white;
}
//ADDED-START
.lightbox .lb-video {
border-radius: 4px;
box-sizing: content-box;
}
.lightbox .lb-video-nav .lb-nav {
height: calc(100% - 45px);
}
//ADDED-END
.lightbox a img {
border: none;
}

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long