Remove mplayer, delegate technical read to MediaVorus

This commit is contained in:
Romain Neutron
2012-05-04 16:29:05 +02:00
parent ad59dbcb36
commit 516008d84d
20 changed files with 494 additions and 713 deletions

View File

@@ -119,26 +119,37 @@ class Publications implements ControllerProviderInterface
return new Response('ERROR:error while upload'); return new Response('ERROR:error while upload');
} }
$file = new \system_file($fileData['tmp_name']); $media = \MediaVorus\MediaVorus::guess(new \SplFileInfo($fileData['tmp_name']));
if ( ! in_array($file->get_mime(), array('image/jpeg', 'image/jpg', 'image/gif'))) {
if ($media->getType() !== \MediaVorus\Media\Media::TYPE_IMAGE) {
return new Response('ERROR:bad filetype'); return new Response('ERROR:bad filetype');
} }
if ($file->getSize() > 200000) { $spec = new \MediaAlchemyst\Specification\Image();
return new Response('ERROR:file too large');
$spec->setResizeMode(\MediaAlchemyst\Specification\Image::RESIZE_MODE_OUTBOUND);
$spec->setDimensions(32, 32);
$spec->setStrip(true);
$spec->setQuality(72);
$tmpname = tempnam(sys_get_temp_dir(), 'feed_icon');
try {
$app['Core']['media-alchemyst']
->open($media->getFile()->getPathname())
->turnInto($tmpname, $spec)
->close();
} catch (\MediaAlchemyst\Exception\Exception $e) {
return new Response('Error while handling icon');
} }
$datas = $file->get_technical_datas(); $feed->set_icon($tmpname);
if ( ! isset($datas[\system_file::TC_DATAS_WIDTH]) || ! isset($datas[\system_file::TC_DATAS_HEIGHT])) {
return new Response('ERROR:file is not square');
}
if ($datas[\system_file::TC_DATAS_WIDTH] != $datas[\system_file::TC_DATAS_HEIGHT]) { unset($media);
return new Response('ERROR:file is not square');
}
$feed->set_icon($file); unlink($tmpname);
unlink($file->getPathname()); unlink($fileData['tmp_name']);
return new Response('FILEHREF:' . $feed->get_icon_url() . '?' . mt_rand(100000, 999999)); return new Response('FILEHREF:' . $feed->get_icon_url() . '?' . mt_rand(100000, 999999));
})->assert('id', '\d+'); })->assert('id', '\d+');

View File

@@ -234,7 +234,6 @@ class Installer implements ControllerProviderInterface
$registry->set('GV_unoconv', $request->get('binary_unoconv'), \registry::TYPE_STRING); $registry->set('GV_unoconv', $request->get('binary_unoconv'), \registry::TYPE_STRING);
$registry->set('GV_ffmpeg', $request->get('binary_ffmpeg'), \registry::TYPE_STRING); $registry->set('GV_ffmpeg', $request->get('binary_ffmpeg'), \registry::TYPE_STRING);
$registry->set('GV_mp4box', $request->get('binary_MP4Box'), \registry::TYPE_STRING); $registry->set('GV_mp4box', $request->get('binary_MP4Box'), \registry::TYPE_STRING);
$registry->set('GV_mplayer', $request->get('binary_mplayer'), \registry::TYPE_STRING);
$registry->set('GV_pdftotext', $request->get('binary_xpdf'), \registry::TYPE_STRING); $registry->set('GV_pdftotext', $request->get('binary_xpdf'), \registry::TYPE_STRING);
$user = \User_Adapter::create($appbox, $request->get('email'), $request->get('password'), $request->get('email'), true); $user = \User_Adapter::create($appbox, $request->get('email'), $request->get('password'), $request->get('email'), true);

View File

@@ -454,7 +454,6 @@ class API_V1_adapter extends API_V1_Abstract
'unoconv' => $registry->get('GV_unoconv'), 'unoconv' => $registry->get('GV_unoconv'),
'ffmpeg' => $registry->get('GV_ffmpeg'), 'ffmpeg' => $registry->get('GV_ffmpeg'),
'mp4box' => $registry->get('GV_mp4box'), 'mp4box' => $registry->get('GV_mp4box'),
'mplayer' => $registry->get('GV_mplayer'),
'pdftotext' => $registry->get('GV_pdftotext'), 'pdftotext' => $registry->get('GV_pdftotext'),
'pdfmaxpages' => $registry->get('GV_pdfmaxpages'),), 'pdfmaxpages' => $registry->get('GV_pdfmaxpages'),),
'mainConfiguration' => array( 'mainConfiguration' => array(

View File

@@ -150,20 +150,22 @@ class Feed_Adapter extends Feed_Abstract implements Feed_Interface, cache_cachea
/** /**
* *
* @param system_file $file * @param string $file The path to the file
* @return Feed_Adapter * @return Feed_Adapter
*/ */
public function set_icon(system_file $file) public function set_icon($file)
{ {
if ( ! file_exists($file)) {
throw new \Alchemy\Phrasea\Exception\InvalidArgumentException('File does not exists');
}
$registry = registry::get_instance(); $registry = registry::get_instance();
$config_file = $registry->get('GV_RootPath') $config_file = $registry->get('GV_RootPath') . 'config/feed_' . $this->get_id() . '.jpg';
. 'config/feed_' . $this->get_id() . '.jpg'; $www_file = $registry->get('GV_RootPath') . 'www/custom/feed_' . $this->get_id() . '.jpg';
$www_file = $registry->get('GV_RootPath')
. 'www/custom/feed_' . $this->get_id() . '.jpg';
copy($file->getPathname(), $config_file); copy($file, $config_file);
copy($file->getPathname(), $www_file); copy($file, $www_file);
$this->icon_url = null; $this->icon_url = null;
return $this; return $this;

View File

@@ -9,6 +9,9 @@
* file that was distributed with this source code. * file that was distributed with this source code.
*/ */
use MediaVorus\MediaVorus;
use MediaVorus\Media\Media;
/** /**
* *
* @package subdefs * @package subdefs
@@ -101,12 +104,41 @@ class media_subdef extends media_abstract implements cache_cacheableInterface
*/ */
protected $is_physically_present = false; protected $is_physically_present = false;
/**
* Players types constants
*/
const TYPE_VIDEO_MP4 = 'VIDEO_MP4'; const TYPE_VIDEO_MP4 = 'VIDEO_MP4';
const TYPE_VIDEO_FLV = 'VIDEO_FLV'; const TYPE_VIDEO_FLV = 'VIDEO_FLV';
const TYPE_FLEXPAPER = 'FLEXPAPER'; const TYPE_FLEXPAPER = 'FLEXPAPER';
const TYPE_AUDIO_MP3 = 'AUDIO_MP3'; const TYPE_AUDIO_MP3 = 'AUDIO_MP3';
const TYPE_IMAGE = 'IMAGE'; const TYPE_IMAGE = 'IMAGE';
const TYPE_NO_PLAYER = 'UNKNOWN'; const TYPE_NO_PLAYER = 'UNKNOWN';
/**
* Technical datas types constants
*/
const TC_DATA_WIDTH = 'Width';
const TC_DATA_HEIGHT = 'Height';
const TC_DATA_COLORSPACE = 'ColorSpace';
const TC_DATA_CHANNELS = 'Channels';
const TC_DATA_ORIENTATION = 'Orientation';
const TC_DATA_COLORDEPTH = 'ColorDepth';
const TC_DATA_DURATION = 'Duration';
const TC_DATA_AUDIOCODEC = 'AudioCodec';
const TC_DATA_AUDIOSAMPLERATE = 'AudioSamplerate';
const TC_DATA_VIDEOCODEC = 'VideoCodec';
const TC_DATA_FRAMERATE = 'FrameRate';
const TC_DATA_MIMETYPE = 'MimeType';
const TC_DATA_FILESIZE = 'FileSize';
const TC_DATA_LONGITUDE = 'Longitude';
const TC_DATA_LATITUDE = 'Latitude';
const TC_DATA_FOCALLENGTH = 'FocalLength';
const TC_DATA_CAMERAMODEL = 'CameraModel';
const TC_DATA_FLASHFIRED = 'FlashFired';
const TC_DATA_APERTURE = 'Aperture';
const TC_DATA_SHUTTERSPEED = 'ShutterSpeed';
const TC_DATA_HYPERFOCALDISTANCE = 'HyperfocalDistance';
const TC_DATA_ISO = 'ISO';
const TC_DATA_LIGHTVALUE = 'LightValue';
/** /**
* @todo the presence of file is checked on constructor, it would be better * @todo the presence of file is checked on constructor, it would be better
@@ -525,16 +557,15 @@ class media_subdef extends media_abstract implements cache_cacheableInterface
return array(\databox_subdef::DEVICE_ALL); return array(\databox_subdef::DEVICE_ALL);
} }
try try {
{
return $this->record return $this->record
->get_databox() ->get_databox()
->get_subdef_structure() ->get_subdef_structure()
->get_subdef($this->record->get_type(), $this->get_name()) ->get_subdef($this->record->get_type(), $this->get_name())
->getDevices(); ->getDevices();
} } catch (\Exception_Databox_SubdefNotFound $e) {
catch(\Exception_Databox_SubdefNotFound $e)
{
return array(); return array();
} }
} }
@@ -553,7 +584,7 @@ class media_subdef extends media_abstract implements cache_cacheableInterface
$Core = \bootstrap::getCore(); $Core = \bootstrap::getCore();
$specs = new MediaAlchemyst\Specification\Image(); $specs = new \MediaAlchemyst\Specification\Image();
$specs->setRotationAngle($angle); $specs->setRotationAngle($angle);
try { try {
@@ -564,31 +595,100 @@ class media_subdef extends media_abstract implements cache_cacheableInterface
return $this; return $this;
} }
$result = new system_file($this->get_pathfile()); $media = MediaVorus::guess(new SplFileInfo($this->get_pathfile()));
$tc_datas = $result->get_technical_datas(); $sql = "UPDATE subdef
if ($tc_datas[system_file::TC_DATAS_WIDTH] && $tc_datas[system_file::TC_DATAS_HEIGHT]) {
$sql = "UPDATE subdef
SET height = :height , width = :width, updated_on = NOW() SET height = :height , width = :width, updated_on = NOW()
WHERE record_id = :record_id AND name = :name"; WHERE record_id = :record_id AND name = :name";
$params = array( $params = array(
':width' => $tc_datas[system_file::TC_DATAS_WIDTH] ':width' => $media->getWidth(),
, ':height' => $tc_datas[system_file::TC_DATAS_HEIGHT] ':height' => $media->getHeight(),
, ':record_id' => $this->get_record_id() ':record_id' => $this->get_record_id(),
, ':name' => $this->get_name() ':name' => $this->get_name(),
); );
$stmt = $this->record->get_databox()->get_connection()->prepare($sql); unset($media);
$stmt->execute($params);
$stmt->closeCursor(); $stmt = $this->record->get_databox()->get_connection()->prepare($sql);
$this->delete_data_from_cache(); $stmt->execute($params);
} $stmt->closeCursor();
$this->delete_data_from_cache();
return $this; return $this;
} }
/**
* Read the technical datas of the file.
* Returns an empty array for non physical present files
*
* @return array An array of technical datas Key/values
*/
public function readTechnicalDatas()
{
if ( ! $this->is_physically_present()) {
return array();
}
$media = MediaVorus::guess(new \SplFileInfo($this->get_pathfile()));
switch ($media->getType()) {
case Media::TYPE_IMAGE:
$datas = array(
self::TC_DATA_WIDTH => $media->getWidth(),
self::TC_DATA_HEIGHT => $media->getHeight(),
self::TC_DATA_FOCALLENGTH => $media->getFocalLength(),
self::TC_DATA_CHANNELS => $media->getChannels(),
self::TC_DATA_COLORDEPTH => $media->getColorDepth(),
self::TC_DATA_CAMERAMODEL => $media->getCameraModel(),
self::TC_DATA_FLASHFIRED => $media->getFlashFired(),
self::TC_DATA_APERTURE => $media->getAperture(),
self::TC_DATA_SHUTTERSPEED => $media->getShutterSpeed(),
self::TC_DATA_HYPERFOCALDISTANCE => $media->getHyperfocalDistance(),
self::TC_DATA_ISO => $media->getISO(),
self::TC_DATA_LIGHTVALUE => $media->getLightValue(),
self::TC_DATA_COLORSPACE => $media->getColorSpace(),
);
break;
case Media::TYPE_VIDEO:
$datas = array(
self::TC_DATA_WIDTH => $media->getWidth(),
self::TC_DATA_HEIGHT => $media->getHeight(),
self::TC_DATA_FOCALLENGTH => $media->getFocalLength(),
self::TC_DATA_CHANNELS => $media->getChannels(),
self::TC_DATA_COLORDEPTH => $media->getColorDepth(),
self::TC_DATA_CAMERAMODEL => $media->getCameraModel(),
self::TC_DATA_FLASHFIRED => $media->getFlashFired(),
self::TC_DATA_APERTURE => $media->getAperture(),
self::TC_DATA_SHUTTERSPEED => $media->getShutterSpeed(),
self::TC_DATA_HYPERFOCALDISTANCE => $media->getHyperfocalDistance(),
self::TC_DATA_ISO => $media->getISO(),
self::TC_DATA_LIGHTVALUE => $media->getLightValue(),
self::TC_DATA_COLORSPACE => $media->getColorSpace(),
self::TC_DATA_DURATION => $media->getDuration(),
self::TC_DATA_FRAMERATE => $media->getFrameRate(),
self::TC_DATA_AUDIOSAMPLERATE => $media->getAudioSampleRate(),
self::TC_DATA_VIDEOCODEC => $media->getVideoCodec(),
self::TC_DATA_AUDIOCODEC => $media->getAudioCodec(),
);
break;
case Media::TYPE_FLASH:
case Media::TYPE_AUDIO:
case Media::TYPE_DOCUMENT:
default:
break;
}
$datas[self::TC_DATA_LONGITUDE] = $media->getLongitude();
$datas[self::TC_DATA_LATITUDE] = $media->getLatitude();
$datas[self::TC_DATA_MIMETYPE] = $media->getFile()->getMimeType();
$datas[self::TC_DATA_FILESIZE] = $media->getFile()->getSize();
unset($media);
return $datas;
}
/** /**
* *
* @param record_Interface $record * @param record_Interface $record
@@ -602,22 +702,27 @@ class media_subdef extends media_abstract implements cache_cacheableInterface
$databox = $record->get_databox(); $databox = $record->get_databox();
$connbas = $databox->get_connection(); $connbas = $databox->get_connection();
$media = MediaVorus::guess($system_file);
$path = $system_file->getPath(); $path = $system_file->getPath();
$newname = $system_file->getFilename(); $newname = $system_file->getFilename();
$datas = $system_file->get_technical_datas();
$params = array( $params = array(
':path' => $path, ':path' => $path,
':file' => $newname, ':file' => $newname,
':baseurl' => $baseurl, ':baseurl' => $baseurl,
':width' => isset($datas[system_file::TC_DATAS_WIDTH]) ? $datas[system_file::TC_DATAS_WIDTH] : '', ':width' => 0,
':height' => isset($datas[system_file::TC_DATAS_HEIGHT]) ? $datas[system_file::TC_DATAS_HEIGHT] : '', ':height' => 0,
':mime' => $system_file->get_mime(), ':mime' => $system_file->get_mime(),
':size' => $system_file->getSize(), ':size' => $system_file->getSize(),
':dispatched' => 1, ':dispatched' => 1,
); );
if (in_array($media->getType(), array(Media::TYPE_IMAGE, Media::TYPE_VIDEO))) {
$params[':width'] = $media->getWidth();
$params[':height'] = $media->getHeight();
}
try { try {
$subdef = new self($record, $name); $subdef = new self($record, $name);
@@ -653,6 +758,8 @@ class media_subdef extends media_abstract implements cache_cacheableInterface
$subdef->get_permalink()->delete_data_from_cache(); $subdef->get_permalink()->delete_data_from_cache();
} }
unset($media);
return $subdef; return $subdef;
} }

View File

@@ -452,7 +452,7 @@ class record_adapter implements record_Interface, cache_cacheableInterface
public function get_duration() public function get_duration()
{ {
if ( ! $this->duration) { if ( ! $this->duration) {
$this->duration = $this->get_technical_infos(system_file::TC_DATAS_DURATION); $this->duration = $this->get_technical_infos(media_subdef::TC_DATA_DURATION);
} }
return $this->duration; return $this->duration;
@@ -740,12 +740,8 @@ class record_adapter implements record_Interface, cache_cacheableInterface
$stmt->closeCursor(); $stmt->closeCursor();
foreach ($rs as $row) { foreach ($rs as $row) {
switch ($row['name']) { switch (true) {
case 'size': case ctype_digit($row['value']):
case system_file::TC_DATAS_WIDTH:
case system_file::TC_DATAS_COLORDEPTH:
case system_file::TC_DATAS_HEIGHT:
case system_file::TC_DATAS_DURATION:
$this->technical_datas[$row['name']] = (int) $row['value']; $this->technical_datas[$row['name']] = (int) $row['value'];
break; break;
default: default:
@@ -956,6 +952,8 @@ class record_adapter implements record_Interface, cache_cacheableInterface
$base_url = ''; $base_url = '';
$media = MediaVorus\MediaVorus::guess($pathfile);
$original_file = $subdef_def = false; $original_file = $subdef_def = false;
if ($name == 'document') { if ($name == 'document') {
@@ -1016,8 +1014,6 @@ class record_adapter implements record_Interface, cache_cacheableInterface
$connbas = connection::getPDOConnection($this->get_sbas_id()); $connbas = connection::getPDOConnection($this->get_sbas_id());
$image_size = $system_file->get_technical_datas();
$sql = 'UPDATE subdef $sql = 'UPDATE subdef
SET baseurl = :baseurl, SET baseurl = :baseurl,
file = :filename, file = :filename,
@@ -1036,8 +1032,8 @@ class record_adapter implements record_Interface, cache_cacheableInterface
':name' => $name, ':name' => $name,
':baseurl' => $base_url, ':baseurl' => $base_url,
':filename' => $system_file->getFilename(), ':filename' => $system_file->getFilename(),
':width' => $image_size[system_file::TC_DATAS_WIDTH], ':width' => $media->getWidth(),
':height' => $image_size[system_file::TC_DATAS_HEIGHT], ':height' => $media->getHeight(),
':mime' => $system_file->get_mime(), ':mime' => $system_file->get_mime(),
':path' => $system_file->getPath(), ':path' => $system_file->getPath(),
':filesize' => $system_file->getSize() ':filesize' => $system_file->getSize()
@@ -1063,6 +1059,8 @@ class record_adapter implements record_Interface, cache_cacheableInterface
} }
unset($media);
return $this; return $this;
} }
@@ -1365,17 +1363,15 @@ class record_adapter implements record_Interface, cache_cacheableInterface
$system_file2 = new system_file($pathhd . $newname); $system_file2 = new system_file($pathhd . $newname);
$system_file2->write_uuid($uuid); $system_file2->write_uuid($uuid);
media_subdef::create($record, 'document', $system_file2); $subdef = media_subdef::create($record, 'document', $system_file2);
$record->delete_data_from_cache(record_adapter::CACHE_SUBDEFS); $record->delete_data_from_cache(record_adapter::CACHE_SUBDEFS);
$tc_datas = $system_file->get_technical_datas();
$sql = 'REPLACE INTO technical_datas (id, record_id, name, value) $sql = 'REPLACE INTO technical_datas (id, record_id, name, value)
VALUES (null, :record_id, :name, :value)'; VALUES (null, :record_id, :name, :value)';
$stmt = $connbas->prepare($sql); $stmt = $connbas->prepare($sql);
foreach ($tc_datas as $name => $value) { foreach ($subdef->readTechnicalDatas() as $name => $value) {
if (is_null($value)) if (is_null($value))
continue; continue;

View File

@@ -202,7 +202,6 @@ class setup
'xpdf (pdf2text)' => $registry->get('GV_pdftotext'), 'xpdf (pdf2text)' => $registry->get('GV_pdftotext'),
'ImageMagick (composite)' => $registry->get('GV_pathcomposite'), 'ImageMagick (composite)' => $registry->get('GV_pathcomposite'),
'FFmpeg' => $registry->get('GV_ffmpeg'), 'FFmpeg' => $registry->get('GV_ffmpeg'),
'MPlayer' => $registry->get('GV_mplayer')
); );
$constraints = array(); $constraints = array();

View File

@@ -292,101 +292,6 @@ class system_file extends \SplFileInfo
return $this->sha256; return $this->sha256;
} }
public function get_technical_datas()
{
if ( ! $this->technical_datas)
$this->read_technical_datas();
return $this->technical_datas;
}
protected function read_image_datas()
{
$this->technical_datas[self::TC_DATAS_ORIENTATION] = null;
if (in_array(
$this->get_mime(), array(
'image/tif', 'image/tiff',
'image/jpg', 'image/pjpeg', 'image/pjpg', 'image/jpeg'
)
)
) {
if ($ex = @exif_read_data($this->getPathname(), 'FILE')) {
if (array_key_exists('Orientation', $ex))
$this->technical_datas[self::TC_DATAS_ORIENTATION] = $ex['Orientation'];
}
}
$datas = exiftool::extract_metadatas($this, exiftool::EXTRACT_XML_RDF);
$domrdf = new DOMDocument();
$domrdf->recover = true;
$domrdf->preserveWhiteSpace = false;
if ($domrdf->loadXML($datas)) {
$xptrdf = new DOMXPath($domrdf);
$xptrdf->registerNamespace('rdf', 'http://www.w3.org/1999/02/22-rdf-syntax-ns#');
$pattern = "(xmlns:([a-zA-Z-_0-9]+)=[']{1}(https?:[/{2,4}|\\{2,4}][\w:#%/;$()~_?/\-=\\\.&]*)[']{1})";
preg_match_all($pattern, $datas, $matches, PREG_PATTERN_ORDER, 0);
$xptrdf->registerNamespace('XMP-exif', 'http://ns.exiftool.ca/XMP/XMP-exif/1.0/');
$xptrdf->registerNamespace('PHRASEANET', 'http://phraseanet.com/metas/PHRASEANET/1.0/');
foreach ($matches[2] as $key => $value)
$xptrdf->registerNamespace($matches[1][$key], $value);
$descriptionNode = @$xptrdf->query('/rdf:RDF/rdf:Description')->item(0);
if ($descriptionNode) {
for ($x = $descriptionNode->firstChild; $x; $x = $x->nextSibling) {
if ($x->nodeType !== XML_ELEMENT_NODE)
continue;
switch ($x->nodeName) {
case 'Composite:ImageSize':
if ((count($_t = explode('x', $x->textContent))) == 2) {
$this->technical_datas[self::TC_DATAS_WIDTH] = 0 + $_t[0];
$this->technical_datas[self::TC_DATAS_HEIGHT] = 0 + $_t[1];
}
break;
case 'ExifIFD:ExifImageWidth':
if ( ! array_key_exists('width', $this->technical_datas))
$this->technical_datas[self::TC_DATAS_WIDTH] = 0 + $x->textContent;
break;
case 'ExifIFD:ExifImageHeight':
if ( ! array_key_exists('height', $this->technical_datas))
$this->technical_datas[self::TC_DATAS_HEIGHT] = 0 + $x->textContent;
break;
case 'File:ColorComponents':
case 'IFD0:SamplesPerPixel':
if ( ! array_key_exists('channels', $this->technical_datas))
$this->technical_datas[self::TC_DATAS_CHANNELS] = 0 + $x->textContent;
break;
case 'File:BitsPerSample':
case 'IFD0:BitsPerSample':
if ( ! array_key_exists('bits', $this->technical_datas))
$this->technical_datas[self::TC_DATAS_COLORDEPTH] = 0 + $x->textContent;
break;
}
if (count($_t = explode(':', $x->nodeName)) !== 2)
continue;
switch ($_t[1]) {
case 'ImageWidth':
if ( ! array_key_exists('width', $this->technical_datas))
$this->technical_datas[self::TC_DATAS_WIDTH] = 0 + $x->textContent;
break;
case 'ImageHeight':
if ( ! array_key_exists('height', $this->technical_datas))
$this->technical_datas[self::TC_DATAS_HEIGHT] = 0 + $x->textContent;
break;
}
}
}
}
return $this;
}
protected function read_pdf_datas() protected function read_pdf_datas()
{ {
$system = system_server::get_platform(); $system = system_server::get_platform();
@@ -420,129 +325,6 @@ class system_file extends \SplFileInfo
return $pdf_text; return $pdf_text;
} }
protected function read_video_datas()
{
$registry = registry::get_instance();
$retour = array('width' => 0, 'height' => 0, 'CMYK' => false);
$hdPath = $this->getPathname();
$datas = exiftool::get_fields(
$hdPath, array('Duration', 'Image Width', 'Image Height')
);
$duration = 0;
if ($datas['Duration']) {
$data = explode('_', trim($datas['Duration']));
$data = explode(':', $data[0]);
$factor = 1;
while ($segment = array_pop($data)) {
$duration += $segment * $factor;
$factor *=60;
}
}
$width = $height = false;
if ($datas['Image Width']) {
if ((int) $datas['Image Width'] > 0)
$width = $datas['Image Width'];
}
if ($datas['Image Height']) {
if ((int) $datas['Image Height'] > 0)
$height = $datas['Image Height'];
}
$this->technical_datas = array();
if ( ! is_executable($registry->get('GV_mplayer'))) {
return $this;
}
$cmd = $registry->get('GV_mplayer')
. ' -identify '
. escapeshellarg($hdPath)
. ' -ao null -vo null -frames 0 | grep ^ID_';
$docProps = array(
'ID_VIDEO_WIDTH' => self::TC_DATAS_WIDTH,
'ID_VIDEO_HEIGHT' => self::TC_DATAS_HEIGHT,
'ID_VIDEO_FPS' => self::TC_DATAS_FRAMERATE,
'ID_AUDIO_CODEC' => self::TC_DATAS_AUDIOCODEC,
'ID_VIDEO_CODEC' => self::TC_DATAS_VIDEOCODEC,
'ID_VIDEO_BITRATE' => self::TC_DATAS_VIDEOBITRATE,
'ID_AUDIO_BITRATE' => self::TC_DATAS_AUDIOBITRATE,
'ID_AUDIO_RATE' => self::TC_DATAS_AUDIOSAMPLERATE
);
$stdout = shell_exec($cmd);
$this->technical_datas = array();
$stdout = explode("\n", $stdout);
foreach ($stdout as $property) {
$props = explode('=', $property);
if (array_key_exists($props[0], $docProps))
$this->technical_datas[$docProps[$props[0]]] = $props[1];
}
$datas = exiftool::extract_metadatas($this, exiftool::EXTRACT_XML_RDF);
$dom_document = new DOMDocument();
if ($dom_document->loadXML($datas)) {
$xq = new DOMXPath($dom_document);
$xq->registerNamespace('RIFF', 'http://ns.exiftool.ca/RIFF/RIFF/1.0/');
$nodes_width = $xq->query('/rdf:RDF/rdf:Description/RIFF:ImageWidth');
$nodes_height = $xq->query('/rdf:RDF/rdf:Description/RIFF:ImageHeight');
if ($nodes_height->length > 0 && $nodes_width->length > 0) {
$width = $nodes_width->item(0)->nodeValue;
$height = $nodes_height->item(0)->nodeValue;
}
}
$this->technical_datas[self::TC_DATAS_DURATION] = $duration;
if ($width)
$this->technical_datas[self::TC_DATAS_WIDTH] = $width;
if ($height)
$this->technical_datas[self::TC_DATAS_HEIGHT] = $height;
return $this;
}
protected function read_audio_datas()
{
return $this->read_video_datas();
}
protected function read_technical_datas()
{
$this->technical_datas = array();
switch ($this->get_phrasea_type()) {
case 'image' :
$this->read_image_datas();
break;
case 'document';
$this->read_image_datas();
// $this->read_pdf_datas();
break;
case 'video':
$this->read_video_datas();
break;
case 'audio':
$this->read_audio_datas();
break;
default:
break;
}
$this->technical_datas[self::TC_DATAS_MIMETYPE] = $this->get_mime();
$this->technical_datas[self::TC_DATAS_FILESIZE] = $this->getSize();
return;
}
/** /**
* *
* @return string * @return string
@@ -890,7 +672,16 @@ class system_file extends \SplFileInfo
$tfields = array(); $tfields = array();
$technical_datas = $this->get_technical_datas(); $media = MediaVorus\MediaVorus::guess($this);
$width = $height = $channels = $colorDepth = array();
if (in_array($media, array(\MediaVorus\Media\Media::TYPE_IMAGE, \MediaVorus\Media\Media::TYPE_VIDEO))) {
$width[] = $media->getWidth();
$height[] = $media->getHeight();
$channels[] = $media->getChannels();
$colorDepth[] = $media->getColorDepth();
}
$tfields[metadata_description_PHRASEANET_tfmimetype::get_source()] $tfields[metadata_description_PHRASEANET_tfmimetype::get_source()]
= array($this->get_mime()); = array($this->get_mime());
@@ -903,36 +694,24 @@ class system_file extends \SplFileInfo
$tfields[metadata_description_PHRASEANET_tffilename::get_source()] $tfields[metadata_description_PHRASEANET_tffilename::get_source()]
= array($this->get_phrasea_tech_field(self::TECH_FIELD_ORIGINALNAME)); = array($this->get_phrasea_tech_field(self::TECH_FIELD_ORIGINALNAME));
$tfields[metadata_description_PHRASEANET_tfextension::get_source()] $tfields[metadata_description_PHRASEANET_tfextension::get_source()] = array($this->get_extension());
= array($this->get_extension()); $tfields[metadata_description_PHRASEANET_tfwidth::get_source()] = $width;
$tfields[metadata_description_PHRASEANET_tfwidth::get_source()] $tfields[metadata_description_PHRASEANET_tfheight::get_source()] = $height;
= isset($technical_datas[system_file::TC_DATAS_WIDTH]) ? array(($technical_datas[system_file::TC_DATAS_WIDTH])) : array(); $tfields[metadata_description_PHRASEANET_tfbits::get_source()] = $colorDepth;
$tfields[metadata_description_PHRASEANET_tfheight::get_source()] $tfields[metadata_description_PHRASEANET_tfchannels::get_source()] = $channels;
= isset($technical_datas[system_file::TC_DATAS_HEIGHT]) ? array(($technical_datas[system_file::TC_DATAS_HEIGHT])) : array();
$tfields[metadata_description_PHRASEANET_tfbits::get_source()]
= isset($technical_datas[system_file::TC_DATAS_COLORDEPTH]) ? array(($technical_datas[system_file::TC_DATAS_COLORDEPTH])) : array();
$tfields[metadata_description_PHRASEANET_tfchannels::get_source()]
= isset($technical_datas[system_file::TC_DATAS_CHANNELS]) ? array(($technical_datas[system_file::TC_DATAS_CHANNELS])) : array();
$tfields[metadata_description_PHRASEANET_tfctime::get_source()] $tfields[metadata_description_PHRASEANET_tfctime::get_source()] = array(date('Y/m/d H:i:s', $this->getCTime()));
= array(date('Y/m/d H:i:s', $this->getCTime())); $tfields[metadata_description_PHRASEANET_tfmtime::get_source()] = array(date('Y/m/d H:i:s', $this->getMTime()));
$tfields[metadata_description_PHRASEANET_tfmtime::get_source()] $tfields[metadata_description_PHRASEANET_tfatime::get_source()] = array(date('Y/m/d H:i:s', $this->getATime()));
= array(date('Y/m/d H:i:s', $this->getMTime()));
$tfields[metadata_description_PHRASEANET_tfatime::get_source()]
= array(date('Y/m/d H:i:s', $this->getATime()));
$time = time(); $time = time();
$tfields[metadata_description_PHRASEANET_tfarchivedate::get_source()] $tfields[metadata_description_PHRASEANET_tfarchivedate::get_source()] = array(date('Y/m/d H:i:s', $time));
= array(date('Y/m/d H:i:s', $time)); $tfields[metadata_description_PHRASEANET_tfeditdate::get_source()] = array(date('Y/m/d H:i:s', $time));
$tfields[metadata_description_PHRASEANET_tfeditdate::get_source()] $tfields[metadata_description_PHRASEANET_tfchgdocdate::get_source()] = array(date('Y/m/d H:i:s', $time));
= array(date('Y/m/d H:i:s', $time));
$tfields[metadata_description_PHRASEANET_tfchgdocdate::get_source()]
= array(date('Y/m/d H:i:s', $time));
if ($this->get_mime() === 'application/pdf') { if ($this->get_mime() === 'application/pdf') {
$tfields[metadata_description_PHRASEANET_pdftext::get_source()] $tfields[metadata_description_PHRASEANET_pdftext::get_source()] = $this->read_pdf_datas();
= $this->read_pdf_datas();
} }
$datas = exiftool::extract_metadatas($this, exiftool::EXTRACT_XML_RDF); $datas = exiftool::extract_metadatas($this, exiftool::EXTRACT_XML_RDF);

View File

@@ -195,14 +195,9 @@ class task_period_upgradetov32 extends task_abstract
foreach ($rs as $row) { foreach ($rs as $row) {
try { try {
$record = new record_adapter($this->sbas_id, $row['record_id']); $record = new record_adapter($this->sbas_id, $row['record_id']);
$system_file = $record->get_hd_file(); $document = $record->get_subdef('document');
if ( ! $system_file instanceof system_file) foreach ($document->readTechnicalDatas() as $name => $value) {
continue;
$tc_datas = $system_file->get_technical_datas();
foreach ($tc_datas as $name => $value) {
if (is_null($value)) if (is_null($value))
continue; continue;

View File

@@ -475,12 +475,6 @@ $GV = array(
'comment' => _('reglages:: chemin de l\'executable MP4Box'), 'comment' => _('reglages:: chemin de l\'executable MP4Box'),
'default' => '' 'default' => ''
), ),
array(
'type' => 'string',
'name' => 'GV_mplayer',
'comment' => _('reglages:: chemin de l\'executable Mplayer'),
'default' => ''
),
array( array(
'type' => 'string', 'type' => 'string',
'name' => 'GV_pdftotext', 'name' => 'GV_pdftotext',

View File

@@ -61,36 +61,36 @@
{{record.get_formated_duration() }} {{record.get_formated_duration() }}
<br /> <br />
{% endif %} {% endif %}
{% if record.get_technical_infos(constant('system_file::TC_DATAS_FRAMERATE')) is not empty %} {% if record.get_technical_infos(constant('media_subdef::TC_DATA_FRAMERATE')) is not empty %}
{% trans 'Images par secondes' %} : {% trans 'Images par secondes' %} :
{{record.get_technical_infos(constant('system_file::TC_DATAS_FRAMERATE')) }} ips {{record.get_technical_infos(constant('media_subdef::TC_DATA_FRAMERATE')) }} ips
<br /> <br />
{% endif %} {% endif %}
{% if record.get_technical_infos(constant('system_file::TC_DATAS_AUDIOCODEC')) %} {% if record.get_technical_infos(constant('media_subdef::TC_DATA_AUDIOCODEC')) %}
{% trans 'Codec Audio' %} : {% trans 'Codec Audio' %} :
{{record.get_technical_infos(constant('system_file::TC_DATAS_AUDIOCODEC')) }} {{record.get_technical_infos(constant('media_subdef::TC_DATA_AUDIOCODEC')) }}
<br /> <br />
{% endif %} {% endif %}
{% if record.get_technical_infos(constant('system_file::TC_DATAS_VIDEOCODEC')) %} {% if record.get_technical_infos(constant('media_subdef::TC_DATA_VIDEOCODEC')) %}
{% trans 'Codec Video' %} : {% trans 'Codec Video' %} :
{{record.get_technical_infos(constant('system_file::TC_DATAS_VIDEOCODEC')) }} {{record.get_technical_infos(constant('media_subdef::TC_DATA_VIDEOCODEC')) }}
<br /> <br />
{% endif %} {% endif %}
{% if record.get_technical_infos(constant('system_file::TC_DATAS_VIDEOBITRATE')) %} {% if record.get_technical_infos(constant('media_subdef::TC_DATA_VIDEOBITRATE')) %}
{% trans 'Debit video' %} : {% trans 'Debit video' %} :
{% set rate = (record.get_technical_infos(constant('system_file::TC_DATAS_VIDEOBITRATE')) / 1024) %} {% set rate = (record.get_technical_infos(constant('media_subdef::TC_DATA_VIDEOBITRATE')) / 1024) %}
{{rate|round(1)}} kbps {{rate|round(1)}} kbps
<br /> <br />
{% endif %} {% endif %}
{% if record.get_technical_infos(constant('system_file::TC_DATAS_AUDIOBITRATE')) %} {% if record.get_technical_infos(constant('media_subdef::TC_DATA_AUDIOBITRATE')) %}
{% trans 'Debit audio' %} : {% trans 'Debit audio' %} :
{% set rate = (record.get_technical_infos(constant('system_file::TC_DATAS_AUDIOBITRATE')) / 1024) %} {% set rate = (record.get_technical_infos(constant('media_subdef::TC_DATA_AUDIOBITRATE')) / 1024) %}
{{rate|round(1)}} kbps {{rate|round(1)}} kbps
<br /> <br />
{% endif %} {% endif %}
{% if record.get_technical_infos(constant('system_file::TC_DATAS_AUDIOSAMPLERATE')) %} {% if record.get_technical_infos(constant('media_subdef::TC_DATA_AUDIOSAMPLERATE')) %}
{% trans 'Frequence d\'echantillonage' %} : {% trans 'Frequence d\'echantillonage' %} :
{{record.get_technical_infos(constant('system_file::TC_DATAS_AUDIOSAMPLERATE')) }} kHz {{record.get_technical_infos(constant('media_subdef::TC_DATA_AUDIOSAMPLERATE')) }} kHz
<br /> <br />
{% endif %} {% endif %}
{% endif %} {% endif %}
@@ -105,20 +105,20 @@
{{record.get_formated_duration() }} {{record.get_formated_duration() }}
<br /> <br />
{% endif %} {% endif %}
{% if record.get_technical_infos(constant('system_file::TC_DATAS_AUDIOCODEC')) %} {% if record.get_technical_infos(constant('media_subdef::TC_DATA_AUDIOCODEC')) %}
{% trans 'Codec Audio' %} : {% trans 'Codec Audio' %} :
{{record.get_technical_infos(constant('system_file::TC_DATAS_AUDIOCODEC')) }} {{record.get_technical_infos(constant('media_subdef::TC_DATA_AUDIOCODEC')) }}
<br /> <br />
{% endif %} {% endif %}
{% if record.get_technical_infos(constant('system_file::TC_DATAS_AUDIOBITRATE')) %} {% if record.get_technical_infos(constant('media_subdef::TC_DATA_AUDIOBITRATE')) %}
{% trans 'Debit audio' %} : {% trans 'Debit audio' %} :
{% set rate = (record.get_technical_infos(constant('system_file::TC_DATAS_AUDIOBITRATE')) / 1024) %} {% set rate = (record.get_technical_infos(constant('media_subdef::TC_DATA_AUDIOBITRATE')) / 1024) %}
{{rate|round(1)}} kbps {{rate|round(1)}} kbps
<br /> <br />
{% endif %} {% endif %}
{% if record.get_technical_infos(constant('system_file::TC_DATAS_AUDIOSAMPLERATE')) %} {% if record.get_technical_infos(constant('media_subdef::TC_DATA_AUDIOSAMPLERATE')) %}
{% trans 'Frequence d\'echantillonage' %} : {% trans 'Frequence d\'echantillonage' %} :
{{record.get_technical_infos(constant('system_file::TC_DATAS_AUDIOSAMPLERATE')) }} kHz {{record.get_technical_infos(constant('media_subdef::TC_DATA_AUDIOSAMPLERATE')) }} kHz
<br /> <br />
{% endif %} {% endif %}
{% endif %} {% endif %}

View File

@@ -1429,18 +1429,10 @@ class ApiJsonApplication extends PhraseanetWebTestCaseAbstract
$this->assertTrue(is_object($record->technical_informations)); $this->assertTrue(is_object($record->technical_informations));
foreach ($record->technical_informations as $key => $value) { foreach ($record->technical_informations as $key => $value) {
switch ($key) { if(is_string($value))
case system_file::TC_DATAS_DURATION: $this->assertFalse(ctype_digit ($value));
case 'size': else
case system_file::TC_DATAS_WIDTH: $this->assertTrue(is_int($value));
case system_file::TC_DATAS_HEIGHT:
case system_file::TC_DATAS_COLORDEPTH:
$this->assertTrue(is_int($value), 'test technical data ' . $key . ' ' . $value);
break;
default;
$this->assertTrue(is_string($value), 'test technical data ' . $key);
break;
}
} }
} }

View File

@@ -1467,17 +1467,10 @@ class ApiYamlApplication extends PhraseanetWebTestCaseAbstract
$this->assertTrue(is_array($record["technical_informations"])); $this->assertTrue(is_array($record["technical_informations"]));
foreach ($record["technical_informations"] as $key => $value) { foreach ($record["technical_informations"] as $key => $value) {
switch ($key) { if (is_string($value)) {
case system_file::TC_DATAS_DURATION: $this->assertFalse(ctype_digit($value));
case 'size': } else {
case system_file::TC_DATAS_WIDTH: $this->assertTrue(is_int($value));
case system_file::TC_DATAS_HEIGHT:
case system_file::TC_DATAS_COLORDEPTH:
$this->assertTrue(is_int($value), 'test technical data ' . $key . ' ' . $value);
break;
default;
$this->assertTrue(is_string($value), 'test technical data ' . $key);
break;
} }
} }
} }

View File

@@ -54,7 +54,6 @@ class ApplicationSetupTest extends PhraseanetWebTestCaseAbstract
'GV_unoconv', 'GV_unoconv',
'GV_ffmpeg', 'GV_ffmpeg',
'GV_mp4box', 'GV_mp4box',
'GV_mplayer',
'GV_pdftotext', 'GV_pdftotext',
); );

View File

@@ -226,7 +226,7 @@ class Module_Admin_Route_PublicationTest extends PhraseanetWebTestCaseAuthentica
"POST" "POST"
, "/publications/feed/" . $feed->get_id() . "/iconupload/" , "/publications/feed/" . $feed->get_id() . "/iconupload/"
, array() , array()
, array('Filedata' => array('error' => 0, 'tmp_name' => __DIR__ . '/../../../../testfiles/test013.ai')) , array('Filedata' => array('error' => 0, 'tmp_name' => __DIR__ . '/../../../../testfiles/test007.ppt'))
); );
$response = $this->client->getResponse(); $response = $this->client->getResponse();
$this->assertTrue($response->isOk()); $this->assertTrue($response->isOk());
@@ -235,63 +235,6 @@ class Module_Admin_Route_PublicationTest extends PhraseanetWebTestCaseAuthentica
$feed->delete(); $feed->delete();
} }
public function testIconUploadErrorTooLarge()
{
$appbox = appbox::get_instance(\bootstrap::getCore());
$feed = Feed_Adapter::create($appbox, self::$user, "salut", 'coucou');
$this->client->request(
"POST"
, "/publications/feed/" . $feed->get_id() . "/iconupload/"
, array()
, array('Filedata' => array('error' => 0, 'tmp_name' => __DIR__ . '/../../../../testfiles/heavy500.jpg'))
);
$response = $this->client->getResponse();
$this->assertTrue($response->isOk());
$this->assertRegexp("/ERROR:file too large/", $response->getContent());
$feed->delete();
}
public function testIconUploadErrorNotSquareA()
{
$appbox = appbox::get_instance(\bootstrap::getCore());
$feed = Feed_Adapter::create($appbox, self::$user, "salut", 'coucou');
$this->client->request(
"POST"
, "/publications/feed/" . $feed->get_id() . "/iconupload/"
, array()
, array('Filedata' => array('error' => 0, 'tmp_name' => __DIR__ . '/../../../../testfiles/recta_logo.gif'))
);
$response = $this->client->getResponse();
$this->assertTrue($response->isOk());
$this->assertRegexp("/ERROR:file is not square/", $response->getContent());
$feed->delete();
}
public function testIconUploadErrorNotSquareB()
{
$appbox = appbox::get_instance(\bootstrap::getCore());
$feed = Feed_Adapter::create($appbox, self::$user, "salut", 'coucou');
$this->client->request(
"POST"
, "/publications/feed/" . $feed->get_id() . "/iconupload/"
, array()
, array('Filedata' => array('error' => 0, 'tmp_name' => __DIR__ . '/../../../../testfiles/rectb_logo.gif'))
);
$response = $this->client->getResponse();
$this->assertTrue($response->isOk());
$this->assertRegexp("/ERROR:file is not square/", $response->getContent());
$feed->delete();
}
public function testIconUpload() public function testIconUpload()
{ {
$appbox = appbox::get_instance(\bootstrap::getCore()); $appbox = appbox::get_instance(\bootstrap::getCore());

View File

@@ -115,14 +115,14 @@ class ControllerRssFeedTest extends \PhraseanetWebTestCaseAbstract
self::$feed_1_private = Feed_Adapter::create($appbox, self::$user, self::$feed_1_private_title, self::$feed_1_private_subtitle); self::$feed_1_private = Feed_Adapter::create($appbox, self::$user, self::$feed_1_private_title, self::$feed_1_private_subtitle);
self::$feed_1_private->set_public(false); self::$feed_1_private->set_public(false);
self::$feed_1_private->set_icon(new system_file(__DIR__ . '/../../../../testfiles/logocoll.gif')); self::$feed_1_private->set_icon(__DIR__ . '/../../../../testfiles/logocoll.gif');
self::$feed_2_private = Feed_Adapter::create($appbox, self::$user, self::$feed_2_private_title, self::$feed_2_private_subtitle); self::$feed_2_private = Feed_Adapter::create($appbox, self::$user, self::$feed_2_private_title, self::$feed_2_private_subtitle);
self::$feed_2_private->set_public(false); self::$feed_2_private->set_public(false);
self::$feed_3_public = Feed_Adapter::create($appbox, self::$user, self::$feed_3_public_title, self::$feed_3_public_subtitle); self::$feed_3_public = Feed_Adapter::create($appbox, self::$user, self::$feed_3_public_title, self::$feed_3_public_subtitle);
self::$feed_3_public->set_public(true); self::$feed_3_public->set_public(true);
self::$feed_3_public->set_icon(new system_file(__DIR__ . '/../../../../testfiles/logocoll.gif')); self::$feed_3_public->set_icon(__DIR__ . '/../../../../testfiles/logocoll.gif');
self::$feed_4_public = Feed_Adapter::create($appbox, self::$user, self::$feed_4_public_title, self::$feed_4_public_subtitle); self::$feed_4_public = Feed_Adapter::create($appbox, self::$user, self::$feed_4_public_title, self::$feed_4_public_subtitle);
self::$feed_4_public->set_public(true); self::$feed_4_public->set_public(true);

View File

@@ -4,287 +4,268 @@ require_once __DIR__ . '/../PhraseanetPHPUnitAuthenticatedAbstract.class.inc';
class Feed_AdapterTest extends PhraseanetPHPUnitAuthenticatedAbstract class Feed_AdapterTest extends PhraseanetPHPUnitAuthenticatedAbstract
{ {
/**
*
* @var Feed_Adapter
*/
protected static $object;
protected static $title = 'Feed test';
protected static $subtitle = 'Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem. Ut enim ad minima veniam, quis nostrum exercitationem ullam corporis suscipit laboriosam, nisi ut aliquid ex ea commodi consequatur? Quis autem vel eum iure reprehenderit qui in ea voluptate velit esse quam nihil molestiae consequatur, vel illum qui dolorem eum fugiat quo voluptas nulla pariatur?';
/** public static function setUpBeforeClass()
*
* @var Feed_Adapter
*/
protected static $object;
protected static $title = 'Feed test';
protected static $subtitle = 'Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem. Ut enim ad minima veniam, quis nostrum exercitationem ullam corporis suscipit laboriosam, nisi ut aliquid ex ea commodi consequatur? Quis autem vel eum iure reprehenderit qui in ea voluptate velit esse quam nihil molestiae consequatur, vel illum qui dolorem eum fugiat quo voluptas nulla pariatur?';
public static function setUpBeforeClass()
{
parent::setUpBeforeClass();
$appbox = appbox::get_instance(\bootstrap::getCore());
$auth = new Session_Authentication_None(self::$user);
$appbox->get_session()->authenticate($auth);
self::$object = Feed_Adapter::create($appbox, self::$user, self::$title, self::$subtitle);
}
public static function tearDownAfterClass()
{
self::$object->delete();
parent::tearDownAfterClass();
}
public function testGet_icon_url()
{
$this->assertEquals('/skins/icons/rss32.gif', self::$object->get_icon_url());
}
public function testSet_icon()
{
$this->assertEquals('/skins/icons/rss32.gif', self::$object->get_icon_url());
$file = new system_file(__DIR__ . '/../testfiles/p4logo.jpg');
self::$object->set_icon($file);
try
{ {
$file = new system_file(__DIR__ . '/../testfiles/iphone_pic.jpg'); parent::setUpBeforeClass();
self::$object->set_icon($file); $appbox = appbox::get_instance(\bootstrap::getCore());
$this->fail('Should fail'); $auth = new Session_Authentication_None(self::$user);
} $appbox->get_session()->authenticate($auth);
catch (Exception $e) self::$object = Feed_Adapter::create($appbox, self::$user, self::$title, self::$subtitle);
{
}
$this->assertEquals('/custom/feed_' . self::$object->get_id() . '.jpg', self::$object->get_icon_url());
}
public function testIs_aggregated()
{
$this->assertFalse(self::$object->is_aggregated());
}
public function testIs_owner()
{
$this->assertTrue(self::$object->is_owner(self::$user));
}
public function testIs_publisher()
{
$this->assertTrue(self::$object->is_publisher(self::$user));
}
public function testIs_public()
{
$this->assertFalse(self::$object->is_public());
self::$object->set_public(true);
$this->assertTrue(self::$object->is_public());
$coll = null;
$appbox = appbox::get_instance(\bootstrap::getCore());
foreach ($appbox->get_databoxes() as $databox)
{
foreach ($databox->get_collections() as $collection)
{
$coll = $collection;
break;
}
if ($coll instanceof collection)
break;
} }
self::$object->set_collection($coll); public static function tearDownAfterClass()
$this->assertFalse(self::$object->is_public());
self::$object->set_collection(null);
$this->assertTrue(self::$object->is_public());
self::$object->set_public(false);
$this->assertFalse(self::$object->is_public());
}
public function testGet_publishers()
{
$publishers = self::$object->get_publishers();
$this->assertEquals(1, count($publishers));
}
public function testGet_collection()
{
$this->assertNull(self::$object->get_collection());
}
public function testAdd_publisher()
{
self::$object->add_publisher(self::$user);
$publishers = self::$object->get_publishers();
$this->assertEquals(1, count($publishers));
}
public function testGet_id()
{
$this->assertTrue(is_int(self::$object->get_id()));
$this->assertTrue(self::$object->get_id() > 0);
}
public function testSet_collection()
{
$coll = null;
$appbox = appbox::get_instance(\bootstrap::getCore());
foreach ($appbox->get_databoxes() as $databox)
{ {
foreach ($databox->get_collections() as $collection) self::$object->delete();
{ parent::tearDownAfterClass();
$coll = $collection;
break;
}
if ($coll instanceof collection)
break;
} }
self::$object->set_collection($coll); public function testGet_icon_url()
$this->assertInstanceOf('collection', self::$object->get_collection());
self::$object->set_collection(null);
$this->assertNull(self::$object->get_collection());
}
public function testSet_public()
{
self::$object->set_collection(null);
self::$object->set_public(true);
$this->assertTrue(self::$object->is_public());
self::$object->set_public(false);
$this->assertFalse(self::$object->is_public());
}
public function testSet_title()
{
$this->assertEquals(self::$title, self::$object->get_title());
$title = 'GROS NIchONS';
self::$object->set_title($title);
$this->assertEquals($title, self::$object->get_title());
$title = '<i>GROS NIchONS</i>';
self::$object->set_title($title);
$this->assertNotEquals($title, self::$object->get_title());
$this->assertEquals(strip_tags($title), self::$object->get_title());
try
{ {
self::$object->set_title('<a></a> '); $this->assertEquals('/skins/icons/rss32.gif', self::$object->get_icon_url());
$this->fail();
}
catch (Exception $e)
{
}
try
{
self::$object->set_title(' ');
$this->fail();
}
catch (Exception $e)
{
}
try
{
self::$object->set_title('');
$this->fail();
}
catch (Exception $e)
{
} }
self::$object->set_title(self::$title); public function testSet_icon()
}
public function testSet_subtitle()
{
$this->assertEquals(self::$subtitle, self::$object->get_subtitle());
self::$object->set_subtitle('');
$this->assertEquals('', self::$object->get_subtitle());
self::$object->set_subtitle(' un sous titre ');
$this->assertEquals(' un sous titre ', self::$object->get_subtitle());
self::$object->set_subtitle(self::$subtitle);
$this->assertEquals(self::$subtitle, self::$object->get_subtitle());
}
public function testLoad_with_user()
{
$appbox = appbox::get_instance(\bootstrap::getCore());
$this->assertEquals(Feed_Adapter::load_with_user($appbox, self::$user, self::$object->get_id())->get_id(), self::$object->get_id());
}
public function testGet_count_total_entries()
{
$n = self::$object->get_count_total_entries();
$this->assertTrue($n === 0);
}
public function testGet_entries()
{
$entries_coll = self::$object->get_entries(0, 5);
$this->assertInstanceOf('Feed_Entry_Collection', $entries_coll);
$this->assertEquals(0, count($entries_coll->get_entries()));
}
public function testGet_homepage_link()
{
self::$object->set_public(false);
$registry = registry::get_instance();
$link = self::$object->get_homepage_link($registry, Feed_Adapter::FORMAT_ATOM);
$this->assertNull($link);
self::$object->set_public(true);
$link = self::$object->get_homepage_link($registry, Feed_Adapter::FORMAT_ATOM);
$this->assertInstanceOf('Feed_Link', $link);
}
public function testGet_user_link()
{
$registry = registry::get_instance();
$link = self::$object->get_user_link($registry, self::$user, Feed_Adapter::FORMAT_ATOM);
$supposed = '/feeds\/userfeed\/([a-zA-Z0-9]{12})\/' . self::$object->get_id() . '\/atom\//';
$atom = $link->get_href();
$this->assertRegExp($supposed, str_replace($registry->get('GV_ServerName'), '', $atom));
$this->assertEquals($atom, self::$object->get_user_link($registry, self::$user, Feed_Adapter::FORMAT_ATOM)->get_href());
$this->assertEquals($atom, self::$object->get_user_link($registry, self::$user, Feed_Adapter::FORMAT_ATOM)->get_href());
$this->assertNotEquals($atom, self::$object->get_user_link($registry, self::$user, Feed_Adapter::FORMAT_ATOM, null, true)->get_href());
$link = self::$object->get_user_link($registry, self::$user, Feed_Adapter::FORMAT_RSS);
$supposed = '/feeds\/userfeed\/([a-zA-Z0-9]{12})\/' . self::$object->get_id() . '\/rss\//';
$this->assertRegExp($supposed, str_replace($registry->get('GV_ServerName'), '', $link->get_href()));
}
public function testGet_title()
{
$this->assertEquals(self::$object->get_title(), self::$title);
try
{ {
self::$object->set_title(''); $this->assertEquals('/skins/icons/rss32.gif', self::$object->get_icon_url());
$this->fail(); $file = __DIR__ . '/../testfiles/p4logo.jpg';
self::$object->set_icon($file);
$this->assertEquals('/custom/feed_' . self::$object->get_id() . '.jpg', self::$object->get_icon_url());
} }
catch (Exception $e)
/**
* @expectedException \Alchemy\Phrasea\Exception\InvalidArgumentException
*/
public function testSet_iconFail()
{
$file = __DIR__ . '/../testfiles/unknown.jpg';
self::$object->set_icon($file);
}
public function testIs_aggregated()
{
$this->assertFalse(self::$object->is_aggregated());
}
public function testIs_owner()
{
$this->assertTrue(self::$object->is_owner(self::$user));
}
public function testIs_publisher()
{
$this->assertTrue(self::$object->is_publisher(self::$user));
}
public function testIs_public()
{
$this->assertFalse(self::$object->is_public());
self::$object->set_public(true);
$this->assertTrue(self::$object->is_public());
$coll = null;
$appbox = appbox::get_instance(\bootstrap::getCore());
foreach ($appbox->get_databoxes() as $databox) {
foreach ($databox->get_collections() as $collection) {
$coll = $collection;
break;
}
if ($coll instanceof collection)
break;
}
self::$object->set_collection($coll);
$this->assertFalse(self::$object->is_public());
self::$object->set_collection(null);
$this->assertTrue(self::$object->is_public());
self::$object->set_public(false);
$this->assertFalse(self::$object->is_public());
}
public function testGet_publishers()
{
$publishers = self::$object->get_publishers();
$this->assertEquals(1, count($publishers));
}
public function testGet_collection()
{
$this->assertNull(self::$object->get_collection());
}
public function testAdd_publisher()
{
self::$object->add_publisher(self::$user);
$publishers = self::$object->get_publishers();
$this->assertEquals(1, count($publishers));
}
public function testGet_id()
{
$this->assertTrue(is_int(self::$object->get_id()));
$this->assertTrue(self::$object->get_id() > 0);
}
public function testSet_collection()
{ {
$coll = null;
$appbox = appbox::get_instance(\bootstrap::getCore());
foreach ($appbox->get_databoxes() as $databox) {
foreach ($databox->get_collections() as $collection) {
$coll = $collection;
break;
}
if ($coll instanceof collection)
break;
}
self::$object->set_collection($coll);
$this->assertInstanceOf('collection', self::$object->get_collection());
self::$object->set_collection(null);
$this->assertNull(self::$object->get_collection());
} }
}
public function testGet_subtitle() public function testSet_public()
{ {
$this->assertEquals(self::$object->get_subtitle(), self::$subtitle); self::$object->set_collection(null);
self::$object->set_subtitle(''); self::$object->set_public(true);
$this->assertEquals(self::$object->get_subtitle(), ''); $this->assertTrue(self::$object->is_public());
self::$object->set_subtitle(self::$subtitle); self::$object->set_public(false);
} $this->assertFalse(self::$object->is_public());
}
public function testGet_created_on() public function testSet_title()
{ {
$this->assertInstanceOf('DateTime', self::$object->get_created_on()); $this->assertEquals(self::$title, self::$object->get_title());
} $title = 'GROS NIchONS';
self::$object->set_title($title);
$this->assertEquals($title, self::$object->get_title());
$title = '<i>GROS NIchONS</i>';
self::$object->set_title($title);
$this->assertNotEquals($title, self::$object->get_title());
$this->assertEquals(strip_tags($title), self::$object->get_title());
public function testGet_updated_on() try {
{ self::$object->set_title('<a></a> ');
$this->assertInstanceOf('DateTime', self::$object->get_updated_on()); $this->fail();
} } catch (Exception $e) {
}
try {
self::$object->set_title(' ');
$this->fail();
} catch (Exception $e) {
}
try {
self::$object->set_title('');
$this->fail();
} catch (Exception $e) {
}
self::$object->set_title(self::$title);
}
public function testSet_subtitle()
{
$this->assertEquals(self::$subtitle, self::$object->get_subtitle());
self::$object->set_subtitle('');
$this->assertEquals('', self::$object->get_subtitle());
self::$object->set_subtitle(' un sous titre ');
$this->assertEquals(' un sous titre ', self::$object->get_subtitle());
self::$object->set_subtitle(self::$subtitle);
$this->assertEquals(self::$subtitle, self::$object->get_subtitle());
}
public function testLoad_with_user()
{
$appbox = appbox::get_instance(\bootstrap::getCore());
$this->assertEquals(Feed_Adapter::load_with_user($appbox, self::$user, self::$object->get_id())->get_id(), self::$object->get_id());
}
public function testGet_count_total_entries()
{
$n = self::$object->get_count_total_entries();
$this->assertTrue($n === 0);
}
public function testGet_entries()
{
$entries_coll = self::$object->get_entries(0, 5);
$this->assertInstanceOf('Feed_Entry_Collection', $entries_coll);
$this->assertEquals(0, count($entries_coll->get_entries()));
}
public function testGet_homepage_link()
{
self::$object->set_public(false);
$registry = registry::get_instance();
$link = self::$object->get_homepage_link($registry, Feed_Adapter::FORMAT_ATOM);
$this->assertNull($link);
self::$object->set_public(true);
$link = self::$object->get_homepage_link($registry, Feed_Adapter::FORMAT_ATOM);
$this->assertInstanceOf('Feed_Link', $link);
}
public function testGet_user_link()
{
$registry = registry::get_instance();
$link = self::$object->get_user_link($registry, self::$user, Feed_Adapter::FORMAT_ATOM);
$supposed = '/feeds\/userfeed\/([a-zA-Z0-9]{12})\/' . self::$object->get_id() . '\/atom\//';
$atom = $link->get_href();
$this->assertRegExp($supposed, str_replace($registry->get('GV_ServerName'), '', $atom));
$this->assertEquals($atom, self::$object->get_user_link($registry, self::$user, Feed_Adapter::FORMAT_ATOM)->get_href());
$this->assertEquals($atom, self::$object->get_user_link($registry, self::$user, Feed_Adapter::FORMAT_ATOM)->get_href());
$this->assertNotEquals($atom, self::$object->get_user_link($registry, self::$user, Feed_Adapter::FORMAT_ATOM, null, true)->get_href());
$link = self::$object->get_user_link($registry, self::$user, Feed_Adapter::FORMAT_RSS);
$supposed = '/feeds\/userfeed\/([a-zA-Z0-9]{12})\/' . self::$object->get_id() . '\/rss\//';
$this->assertRegExp($supposed, str_replace($registry->get('GV_ServerName'), '', $link->get_href()));
}
public function testGet_title()
{
$this->assertEquals(self::$object->get_title(), self::$title);
try {
self::$object->set_title('');
$this->fail();
} catch (Exception $e) {
}
}
public function testGet_subtitle()
{
$this->assertEquals(self::$object->get_subtitle(), self::$subtitle);
self::$object->set_subtitle('');
$this->assertEquals(self::$object->get_subtitle(), '');
self::$object->set_subtitle(self::$subtitle);
}
public function testGet_created_on()
{
$this->assertInstanceOf('DateTime', self::$object->get_created_on());
}
public function testGet_updated_on()
{
$this->assertInstanceOf('DateTime', self::$object->get_updated_on());
}
} }

View File

@@ -270,4 +270,21 @@ class media_subdefTest extends \PhraseanetPHPUnitAbstract
{ {
self::$objectNotPresent->rotate(90); self::$objectNotPresent->rotate(90);
} }
/**
* @covers media_subdef::readTechnicalDatas
*/
public function testReadTechnicalDatas()
{
$technical_datas = self::$objectPresent->readTechnicalDatas();
$this->assertArrayHasKey(media_subdef::TC_DATA_WIDTH, $technical_datas);
$this->assertArrayHasKey(media_subdef::TC_DATA_HEIGHT, $technical_datas);
$this->assertArrayHasKey(media_subdef::TC_DATA_CHANNELS, $technical_datas);
$this->assertArrayHasKey(media_subdef::TC_DATA_COLORDEPTH, $technical_datas);
$this->assertArrayHasKey(media_subdef::TC_DATA_MIMETYPE, $technical_datas);
$this->assertArrayHasKey(media_subdef::TC_DATA_FILESIZE, $technical_datas);
$technical_datas = self::$objectNotPresent->readTechnicalDatas();
$this->assertEquals(array(), $technical_datas);
}
} }

View File

@@ -198,13 +198,13 @@ class record_adapterTest extends PhraseanetPHPUnitAuthenticatedAbstract
public function testGet_formated_duration() public function testGet_formated_duration()
{ {
$this->assertEquals('00:17', self::$record_23->get_formated_duration()); $this->assertTrue(strpos(self::$record_23->get_formated_duration(), '00:17') === 0);
$this->assertEquals('', self::$record_1->get_formated_duration()); $this->assertEquals('', self::$record_1->get_formated_duration());
} }
public function testGet_duration() public function testGet_duration()
{ {
$this->assertEquals(17, self::$record_23->get_duration()); $this->assertEquals(17, round(self::$record_23->get_duration()));
$this->assertEquals(false, self::$record_1->get_duration()); $this->assertEquals(false, self::$record_1->get_duration());
} }

View File

@@ -45,31 +45,6 @@ class system_fileTest extends PhraseanetPHPUnitAbstract
$this->assertEquals('c08fed0e193a1549c130d79814d30a3ac3fcd81980e261c4947ff45691628f92', $this->objects['jpg']->get_sha256()); $this->assertEquals('c08fed0e193a1549c130d79814d30a3ac3fcd81980e261c4947ff45691628f92', $this->objects['jpg']->get_sha256());
} }
public function testGet_technical_datas()
{
$technical_datas = $this->objects['jpg']->get_technical_datas();
$this->assertArrayHasKey(system_file::TC_DATAS_WIDTH, $technical_datas);
$this->assertArrayHasKey(system_file::TC_DATAS_HEIGHT, $technical_datas);
$this->assertArrayHasKey(system_file::TC_DATAS_CHANNELS, $technical_datas);
$this->assertArrayHasKey(system_file::TC_DATAS_COLORDEPTH, $technical_datas);
$this->assertArrayHasKey(system_file::TC_DATAS_MIMETYPE, $technical_datas);
$this->assertArrayHasKey(system_file::TC_DATAS_FILESIZE, $technical_datas);
$technical_datas = $this->objects['indd']->get_technical_datas();
$this->assertArrayHasKey(system_file::TC_DATAS_MIMETYPE, $technical_datas);
$this->assertArrayHasKey(system_file::TC_DATAS_FILESIZE, $technical_datas);
$registry = registry::get_instance();
if ( ! is_executable($registry->get('GV_mplayer')))
$this->markTestSkipped('MPlayer is not configured');
$technical_datas = $this->objects['wav']->get_technical_datas();
$this->assertArrayHasKey(system_file::TC_DATAS_AUDIOBITRATE, $technical_datas);
$this->assertArrayHasKey(system_file::TC_DATAS_AUDIOSAMPLERATE, $technical_datas);
$this->assertArrayHasKey(system_file::TC_DATAS_AUDIOCODEC, $technical_datas);
$this->assertArrayHasKey(system_file::TC_DATAS_DURATION, $technical_datas);
$this->assertArrayHasKey(system_file::TC_DATAS_MIMETYPE, $technical_datas);
$this->assertArrayHasKey(system_file::TC_DATAS_FILESIZE, $technical_datas);
}
public function testGet_phrasea_type() public function testGet_phrasea_type()
{ {
$this->assertEquals('unknown', $this->objects['indd']->get_phrasea_type()); $this->assertEquals('unknown', $this->objects['indd']->get_phrasea_type());