Implement lint
This commit is contained in:
+31
-34
@@ -8,13 +8,13 @@ use Franzz\Objects\ToolBox;
|
||||
class Media extends PhpObject {
|
||||
|
||||
//DB Tables
|
||||
const MEDIA_TABLE = 'medias';
|
||||
public const MEDIA_TABLE = 'medias';
|
||||
|
||||
//Media folders (works because /public/files is a symlink of /files)
|
||||
const MEDIA_FOLDER = 'files';
|
||||
const THUMB_FOLDER = self::MEDIA_FOLDER.'/thumbs';
|
||||
public const MEDIA_FOLDER = 'files';
|
||||
public const THUMB_FOLDER = self::MEDIA_FOLDER.'/thumbs';
|
||||
|
||||
const THUMB_MAX_WIDTH = 400;
|
||||
private const THUMB_MAX_WIDTH = 400;
|
||||
|
||||
private Db $oDb;
|
||||
private Project $oProject;
|
||||
@@ -27,8 +27,8 @@ class Media extends PhpObject {
|
||||
parent::__construct(__CLASS__);
|
||||
$this->oDb = &$oDb;
|
||||
$this->oProject = &$oProject;
|
||||
$this->asMedia = array();
|
||||
$this->asMedias = array();
|
||||
$this->asMedia = [];
|
||||
$this->asMedias = [];
|
||||
$this->setMediaId($iMediaId);
|
||||
}
|
||||
|
||||
@@ -46,9 +46,9 @@ class Media extends PhpObject {
|
||||
|
||||
public function setComment($sComment) {
|
||||
$sLangId = '';
|
||||
$asData = array();
|
||||
$asData = [];
|
||||
if($this->iMediaId > 0) {
|
||||
$bResult = $this->oDb->updateRow(self::MEDIA_TABLE, $this->iMediaId, array('comment'=>$sComment));
|
||||
$bResult = $this->oDb->updateRow(self::MEDIA_TABLE, $this->iMediaId, ['comment'=>$sComment]);
|
||||
if(!$bResult) $sLangId = 'error.commit_db';
|
||||
else $asData = $this->getInfo();
|
||||
}
|
||||
@@ -63,11 +63,11 @@ class Media extends PhpObject {
|
||||
|
||||
if($bOwnMedia && empty($this->asMedia) || !$bOwnMedia && empty($this->asMedias) || $bConstraintArray) {
|
||||
if($this->oProject->getProjectId()) {
|
||||
$asParams = array(
|
||||
'select' => array(Db::getId(self::MEDIA_TABLE), 'filename', 'taken_on', 'posted_on', 'timezone', 'latitude', 'longitude', 'altitude', 'width', 'height', 'rotate', 'type AS subtype', 'comment'),
|
||||
$asParams = [
|
||||
'select' => [Db::getId(self::MEDIA_TABLE), 'filename', 'taken_on', 'posted_on', 'timezone', 'latitude', 'longitude', 'altitude', 'width', 'height', 'rotate', 'type AS subtype', 'comment'],
|
||||
'from' => self::MEDIA_TABLE,
|
||||
'constraint'=> array(Db::getId(Project::PROJ_TABLE) => $this->oProject->getProjectId())
|
||||
);
|
||||
'constraint'=> [Db::getId(Project::PROJ_TABLE) => $this->oProject->getProjectId()]
|
||||
];
|
||||
if($bOwnMedia) $asParams['constraint'][Db::getId(self::MEDIA_TABLE)] = $oMediaIds;
|
||||
if($bConstraintArray) $asParams = array_merge($asParams, $oMediaIds);
|
||||
|
||||
@@ -96,12 +96,12 @@ class Media extends PhpObject {
|
||||
|
||||
public function addMedia($sMediaName, $sMethod='upload') {
|
||||
$sLangId = '';
|
||||
$asParams = array();
|
||||
$asParams = [];
|
||||
if(!$this->isProjectEditable() && $sMethod!='sync') {
|
||||
$sLangId = 'upload.mode_archived';
|
||||
$asParams[] = $this->oProject->getProjectCodeName();
|
||||
}
|
||||
elseif($this->oDb->pingValue(self::MEDIA_TABLE, array('filename'=>$sMediaName)) && $sMethod!='sync') {
|
||||
elseif($this->oDb->pingValue(self::MEDIA_TABLE, ['filename'=>$sMediaName]) && $sMethod!='sync') {
|
||||
$sLangId = 'upload.media.exists';
|
||||
$asParams[] = $sMediaName;
|
||||
}
|
||||
@@ -110,7 +110,7 @@ class Media extends PhpObject {
|
||||
|
||||
//Converting times to Site Time Zone, by using date()
|
||||
//Media Timezone is kept in a separate field for later conversion to Local Time
|
||||
$asDbInfo = array(
|
||||
$asDbInfo = [
|
||||
Db::getId(Project::PROJ_TABLE) => $this->oProject->getProjectId(),
|
||||
'filename' => $sMediaName,
|
||||
'taken_on' => date(Db::TIMESTAMP_FORMAT, ($asMediaInfo['taken_ts'] > 0)?$asMediaInfo['taken_ts']:$asMediaInfo['file_ts']),
|
||||
@@ -123,9 +123,9 @@ class Media extends PhpObject {
|
||||
'height' => $asMediaInfo['height'],
|
||||
'rotate' => $asMediaInfo['rotate'],
|
||||
'type' => $asMediaInfo['type']
|
||||
);
|
||||
];
|
||||
|
||||
if($sMethod=='sync') $iMediaId = $this->oDb->insertUpdateRow(self::MEDIA_TABLE, $asDbInfo, array('filename'));
|
||||
if($sMethod=='sync') $iMediaId = $this->oDb->insertUpdateRow(self::MEDIA_TABLE, $asDbInfo, ['filename']);
|
||||
else $iMediaId = $this->oDb->insertRow(self::MEDIA_TABLE, $asDbInfo);
|
||||
|
||||
if(!$iMediaId) $sLangId = 'error.commit_db';
|
||||
@@ -138,8 +138,7 @@ class Media extends PhpObject {
|
||||
return Livetrail::getResult(($sLangId==''), $sLangId, $asParams);
|
||||
}
|
||||
|
||||
private function getMediaInfoFromFile($sMediaName)
|
||||
{
|
||||
private function getMediaInfoFromFile($sMediaName) {
|
||||
$sMediaPath = self::getMediaPath($sMediaName);
|
||||
$sType = self::getMediaType($sMediaName);
|
||||
$iPostedOn = filemtime($sMediaPath);
|
||||
@@ -153,8 +152,8 @@ class Media extends PhpObject {
|
||||
$iAlt = null;
|
||||
switch($sType) {
|
||||
case 'video':
|
||||
$asResult = array();
|
||||
$sParams = implode(' ', array(
|
||||
$asResult = [];
|
||||
$sParams = implode(' ', [
|
||||
'-loglevel error', //Remove comments
|
||||
'-select_streams v:0', //First video channel
|
||||
'-show_entries '. //filter tags : Width, Height, Creation Time, Location & Rotation
|
||||
@@ -163,7 +162,7 @@ class Media extends PhpObject {
|
||||
'stream=width,height',
|
||||
'-print_format json', //output format: json
|
||||
'-i' //input file
|
||||
));
|
||||
]);
|
||||
exec('ffprobe '.$sParams.' '.escapeshellarg($sMediaPath), $asResult);
|
||||
$asExif = json_decode(implode('', $asResult), true);
|
||||
|
||||
@@ -188,7 +187,7 @@ class Media extends PhpObject {
|
||||
break;
|
||||
case 'image':
|
||||
$asExif = @exif_read_data($sMediaPath, 0, true);
|
||||
if($asExif === false) $asExif = array();
|
||||
if($asExif === false) $asExif = [];
|
||||
list($iWidth, $iHeight) = getimagesize($sMediaPath);
|
||||
|
||||
//Posted On
|
||||
@@ -217,8 +216,7 @@ class Media extends PhpObject {
|
||||
|
||||
//Orientation
|
||||
if(array_key_exists('IFD0', $asExif) && array_key_exists('Orientation', $asExif['IFD0'])) {
|
||||
switch($asExif['IFD0']['Orientation'])
|
||||
{
|
||||
switch($asExif['IFD0']['Orientation']) {
|
||||
case 1: $sRotate = '0'; break; //None
|
||||
case 3: $sRotate = '180'; break; //Flip over
|
||||
case 6: $sRotate = '90'; break; //Clockwise
|
||||
@@ -236,7 +234,7 @@ class Media extends PhpObject {
|
||||
$iTakenOn = $oTakenOn->format('U');
|
||||
}
|
||||
|
||||
return array(
|
||||
return [
|
||||
'timezone' => $sTimeZone,
|
||||
'latitude' => $fLat,
|
||||
'longitude' => $fLng,
|
||||
@@ -247,11 +245,10 @@ class Media extends PhpObject {
|
||||
'height' => $iHeight,
|
||||
'rotate' => $sRotate,
|
||||
'type' => $sType
|
||||
);
|
||||
];
|
||||
}
|
||||
|
||||
private function getMediaThumbnail($sMediaName)
|
||||
{
|
||||
private function getMediaThumbnail($sMediaName) {
|
||||
$sMediaPath = self::getMediaPath($sMediaName);
|
||||
$sThumbPath = self::getMediaPath($sMediaName, 'thumbnail');
|
||||
|
||||
@@ -264,13 +261,13 @@ class Media extends PhpObject {
|
||||
case 'video':
|
||||
//Get a screenshot of the video 1 second in
|
||||
$sTempPath = self::getMediaPath(uniqid('temp_').'.png');
|
||||
$asResult = array();
|
||||
$sParams = implode(' ', array(
|
||||
$asResult = [];
|
||||
$sParams = implode(' ', [
|
||||
'-i '.escapeshellarg($sMediaPath), //input file
|
||||
'-ss 00:00:01.000', //Image taken after x seconds
|
||||
'-vframes 1', //number of video frames to output
|
||||
escapeshellarg($sTempPath), //output file
|
||||
));
|
||||
]);
|
||||
exec('ffmpeg '.$sParams, $asResult);
|
||||
|
||||
//Resize
|
||||
@@ -279,7 +276,7 @@ class Media extends PhpObject {
|
||||
}
|
||||
|
||||
}
|
||||
else $asThumbInfo = array('error'=>'', 'out'=>$sThumbPath);
|
||||
else $asThumbInfo = ['error'=>'', 'out'=>$sThumbPath];
|
||||
|
||||
return ($asThumbInfo['error']=='')?$asThumbInfo['out']:$sMediaPath;
|
||||
}
|
||||
@@ -323,6 +320,6 @@ class Media extends PhpObject {
|
||||
|
||||
private static function getLatLngAltFromISO6709($sIso6709) {
|
||||
preg_match('/^(?P<lat>[\+\-][0,1]?\d{2}\.\d+)(?P<lng>[\+\-][0,1]?\d{2}\.\d+)(?P<alt>[\+\-]\d+)?/', $sIso6709, $asMatches);
|
||||
return array(floatval($asMatches['lat']), floatval($asMatches['lng']), floatval($asMatches['alt'] ?? 0));
|
||||
return [floatval($asMatches['lat']), floatval($asMatches['lng']), floatval($asMatches['alt'] ?? 0)];
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user