diff --git a/lib/Alchemy/Phrasea/Controller/Admin/Publications.php b/lib/Alchemy/Phrasea/Controller/Admin/Publications.php index 5b18ce999a..ccc69a6958 100644 --- a/lib/Alchemy/Phrasea/Controller/Admin/Publications.php +++ b/lib/Alchemy/Phrasea/Controller/Admin/Publications.php @@ -119,26 +119,37 @@ class Publications implements ControllerProviderInterface return new Response('ERROR:error while upload'); } - $file = new \system_file($fileData['tmp_name']); - if ( ! in_array($file->get_mime(), array('image/jpeg', 'image/jpg', 'image/gif'))) { + $media = \MediaVorus\MediaVorus::guess(new \SplFileInfo($fileData['tmp_name'])); + + if ($media->getType() !== \MediaVorus\Media\Media::TYPE_IMAGE) { + return new Response('ERROR:bad filetype'); } - if ($file->getSize() > 200000) { - return new Response('ERROR:file too large'); + $spec = new \MediaAlchemyst\Specification\Image(); + + $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(); - if ( ! isset($datas[\system_file::TC_DATAS_WIDTH]) || ! isset($datas[\system_file::TC_DATAS_HEIGHT])) { - return new Response('ERROR:file is not square'); - } + $feed->set_icon($tmpname); - if ($datas[\system_file::TC_DATAS_WIDTH] != $datas[\system_file::TC_DATAS_HEIGHT]) { - return new Response('ERROR:file is not square'); - } + unset($media); - $feed->set_icon($file); - unlink($file->getPathname()); + unlink($tmpname); + unlink($fileData['tmp_name']); return new Response('FILEHREF:' . $feed->get_icon_url() . '?' . mt_rand(100000, 999999)); })->assert('id', '\d+'); diff --git a/lib/Alchemy/Phrasea/Controller/Setup/Installer.php b/lib/Alchemy/Phrasea/Controller/Setup/Installer.php index 35ac50ded7..636a603824 100644 --- a/lib/Alchemy/Phrasea/Controller/Setup/Installer.php +++ b/lib/Alchemy/Phrasea/Controller/Setup/Installer.php @@ -234,7 +234,6 @@ class Installer implements ControllerProviderInterface $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_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); $user = \User_Adapter::create($appbox, $request->get('email'), $request->get('password'), $request->get('email'), true); diff --git a/lib/classes/API/V1/adapter.class.php b/lib/classes/API/V1/adapter.class.php index ea9c2b5ba6..9e96e9738c 100644 --- a/lib/classes/API/V1/adapter.class.php +++ b/lib/classes/API/V1/adapter.class.php @@ -454,7 +454,6 @@ class API_V1_adapter extends API_V1_Abstract 'unoconv' => $registry->get('GV_unoconv'), 'ffmpeg' => $registry->get('GV_ffmpeg'), 'mp4box' => $registry->get('GV_mp4box'), - 'mplayer' => $registry->get('GV_mplayer'), 'pdftotext' => $registry->get('GV_pdftotext'), 'pdfmaxpages' => $registry->get('GV_pdfmaxpages'),), 'mainConfiguration' => array( diff --git a/lib/classes/Feed/Adapter.class.php b/lib/classes/Feed/Adapter.class.php index aec34c2a46..fb5ed86f17 100644 --- a/lib/classes/Feed/Adapter.class.php +++ b/lib/classes/Feed/Adapter.class.php @@ -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 */ - 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(); - $config_file = $registry->get('GV_RootPath') - . 'config/feed_' . $this->get_id() . '.jpg'; - $www_file = $registry->get('GV_RootPath') - . 'www/custom/feed_' . $this->get_id() . '.jpg'; + $config_file = $registry->get('GV_RootPath') . 'config/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->getPathname(), $www_file); + copy($file, $config_file); + copy($file, $www_file); $this->icon_url = null; return $this; diff --git a/lib/classes/media/subdef.class.php b/lib/classes/media/subdef.class.php index 9d5a0ee711..0fadf55f65 100644 --- a/lib/classes/media/subdef.class.php +++ b/lib/classes/media/subdef.class.php @@ -9,6 +9,9 @@ * file that was distributed with this source code. */ +use MediaVorus\MediaVorus; +use MediaVorus\Media\Media; + /** * * @package subdefs @@ -101,12 +104,41 @@ class media_subdef extends media_abstract implements cache_cacheableInterface */ protected $is_physically_present = false; + /** + * Players types constants + */ const TYPE_VIDEO_MP4 = 'VIDEO_MP4'; const TYPE_VIDEO_FLV = 'VIDEO_FLV'; const TYPE_FLEXPAPER = 'FLEXPAPER'; const TYPE_AUDIO_MP3 = 'AUDIO_MP3'; const TYPE_IMAGE = 'IMAGE'; 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 @@ -525,16 +557,15 @@ class media_subdef extends media_abstract implements cache_cacheableInterface return array(\databox_subdef::DEVICE_ALL); } - try - { + try { + return $this->record ->get_databox() ->get_subdef_structure() ->get_subdef($this->record->get_type(), $this->get_name()) ->getDevices(); - } - catch(\Exception_Databox_SubdefNotFound $e) - { + } catch (\Exception_Databox_SubdefNotFound $e) { + return array(); } } @@ -553,7 +584,7 @@ class media_subdef extends media_abstract implements cache_cacheableInterface $Core = \bootstrap::getCore(); - $specs = new MediaAlchemyst\Specification\Image(); + $specs = new \MediaAlchemyst\Specification\Image(); $specs->setRotationAngle($angle); try { @@ -564,31 +595,100 @@ class media_subdef extends media_abstract implements cache_cacheableInterface return $this; } - $result = new system_file($this->get_pathfile()); + $media = MediaVorus::guess(new SplFileInfo($this->get_pathfile())); - $tc_datas = $result->get_technical_datas(); - if ($tc_datas[system_file::TC_DATAS_WIDTH] && $tc_datas[system_file::TC_DATAS_HEIGHT]) { - - $sql = "UPDATE subdef + $sql = "UPDATE subdef SET height = :height , width = :width, updated_on = NOW() WHERE record_id = :record_id AND name = :name"; - $params = array( - ':width' => $tc_datas[system_file::TC_DATAS_WIDTH] - , ':height' => $tc_datas[system_file::TC_DATAS_HEIGHT] - , ':record_id' => $this->get_record_id() - , ':name' => $this->get_name() - ); + $params = array( + ':width' => $media->getWidth(), + ':height' => $media->getHeight(), + ':record_id' => $this->get_record_id(), + ':name' => $this->get_name(), + ); - $stmt = $this->record->get_databox()->get_connection()->prepare($sql); - $stmt->execute($params); - $stmt->closeCursor(); - $this->delete_data_from_cache(); - } + unset($media); + + $stmt = $this->record->get_databox()->get_connection()->prepare($sql); + $stmt->execute($params); + $stmt->closeCursor(); + $this->delete_data_from_cache(); 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 @@ -602,22 +702,27 @@ class media_subdef extends media_abstract implements cache_cacheableInterface $databox = $record->get_databox(); $connbas = $databox->get_connection(); + $media = MediaVorus::guess($system_file); + $path = $system_file->getPath(); $newname = $system_file->getFilename(); - $datas = $system_file->get_technical_datas(); - $params = array( ':path' => $path, ':file' => $newname, ':baseurl' => $baseurl, - ':width' => isset($datas[system_file::TC_DATAS_WIDTH]) ? $datas[system_file::TC_DATAS_WIDTH] : '', - ':height' => isset($datas[system_file::TC_DATAS_HEIGHT]) ? $datas[system_file::TC_DATAS_HEIGHT] : '', + ':width' => 0, + ':height' => 0, ':mime' => $system_file->get_mime(), ':size' => $system_file->getSize(), ':dispatched' => 1, ); + if (in_array($media->getType(), array(Media::TYPE_IMAGE, Media::TYPE_VIDEO))) { + $params[':width'] = $media->getWidth(); + $params[':height'] = $media->getHeight(); + } + try { $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(); } + unset($media); + return $subdef; } diff --git a/lib/classes/record/adapter.class.php b/lib/classes/record/adapter.class.php index a72c0587cd..64fbee15c6 100644 --- a/lib/classes/record/adapter.class.php +++ b/lib/classes/record/adapter.class.php @@ -452,7 +452,7 @@ class record_adapter implements record_Interface, cache_cacheableInterface public function get_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; @@ -740,12 +740,8 @@ class record_adapter implements record_Interface, cache_cacheableInterface $stmt->closeCursor(); foreach ($rs as $row) { - switch ($row['name']) { - case 'size': - case system_file::TC_DATAS_WIDTH: - case system_file::TC_DATAS_COLORDEPTH: - case system_file::TC_DATAS_HEIGHT: - case system_file::TC_DATAS_DURATION: + switch (true) { + case ctype_digit($row['value']): $this->technical_datas[$row['name']] = (int) $row['value']; break; default: @@ -956,6 +952,8 @@ class record_adapter implements record_Interface, cache_cacheableInterface $base_url = ''; + $media = MediaVorus\MediaVorus::guess($pathfile); + $original_file = $subdef_def = false; if ($name == 'document') { @@ -1016,8 +1014,6 @@ class record_adapter implements record_Interface, cache_cacheableInterface $connbas = connection::getPDOConnection($this->get_sbas_id()); - $image_size = $system_file->get_technical_datas(); - $sql = 'UPDATE subdef SET baseurl = :baseurl, file = :filename, @@ -1036,8 +1032,8 @@ class record_adapter implements record_Interface, cache_cacheableInterface ':name' => $name, ':baseurl' => $base_url, ':filename' => $system_file->getFilename(), - ':width' => $image_size[system_file::TC_DATAS_WIDTH], - ':height' => $image_size[system_file::TC_DATAS_HEIGHT], + ':width' => $media->getWidth(), + ':height' => $media->getHeight(), ':mime' => $system_file->get_mime(), ':path' => $system_file->getPath(), ':filesize' => $system_file->getSize() @@ -1063,6 +1059,8 @@ class record_adapter implements record_Interface, cache_cacheableInterface } + unset($media); + return $this; } @@ -1365,17 +1363,15 @@ class record_adapter implements record_Interface, cache_cacheableInterface $system_file2 = new system_file($pathhd . $newname); $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); - $tc_datas = $system_file->get_technical_datas(); - $sql = 'REPLACE INTO technical_datas (id, record_id, name, value) VALUES (null, :record_id, :name, :value)'; $stmt = $connbas->prepare($sql); - foreach ($tc_datas as $name => $value) { + foreach ($subdef->readTechnicalDatas() as $name => $value) { if (is_null($value)) continue; diff --git a/lib/classes/setup.class.php b/lib/classes/setup.class.php index 745e7eabb0..b1ceda230f 100644 --- a/lib/classes/setup.class.php +++ b/lib/classes/setup.class.php @@ -202,7 +202,6 @@ class setup 'xpdf (pdf2text)' => $registry->get('GV_pdftotext'), 'ImageMagick (composite)' => $registry->get('GV_pathcomposite'), 'FFmpeg' => $registry->get('GV_ffmpeg'), - 'MPlayer' => $registry->get('GV_mplayer') ); $constraints = array(); diff --git a/lib/classes/system/file.class.php b/lib/classes/system/file.class.php index 4c1e87f93e..fb98195343 100644 --- a/lib/classes/system/file.class.php +++ b/lib/classes/system/file.class.php @@ -292,101 +292,6 @@ class system_file extends \SplFileInfo 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() { $system = system_server::get_platform(); @@ -420,129 +325,6 @@ class system_file extends \SplFileInfo 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 @@ -890,7 +672,16 @@ class system_file extends \SplFileInfo $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()] = array($this->get_mime()); @@ -903,36 +694,24 @@ class system_file extends \SplFileInfo $tfields[metadata_description_PHRASEANET_tffilename::get_source()] = array($this->get_phrasea_tech_field(self::TECH_FIELD_ORIGINALNAME)); - $tfields[metadata_description_PHRASEANET_tfextension::get_source()] - = array($this->get_extension()); - $tfields[metadata_description_PHRASEANET_tfwidth::get_source()] - = isset($technical_datas[system_file::TC_DATAS_WIDTH]) ? array(($technical_datas[system_file::TC_DATAS_WIDTH])) : array(); - $tfields[metadata_description_PHRASEANET_tfheight::get_source()] - = 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_tfextension::get_source()] = array($this->get_extension()); + $tfields[metadata_description_PHRASEANET_tfwidth::get_source()] = $width; + $tfields[metadata_description_PHRASEANET_tfheight::get_source()] = $height; + $tfields[metadata_description_PHRASEANET_tfbits::get_source()] = $colorDepth; + $tfields[metadata_description_PHRASEANET_tfchannels::get_source()] = $channels; - $tfields[metadata_description_PHRASEANET_tfctime::get_source()] - = 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_tfatime::get_source()] - = array(date('Y/m/d H:i:s', $this->getATime())); + $tfields[metadata_description_PHRASEANET_tfctime::get_source()] = 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_tfatime::get_source()] = array(date('Y/m/d H:i:s', $this->getATime())); $time = time(); - $tfields[metadata_description_PHRASEANET_tfarchivedate::get_source()] - = 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_tfchgdocdate::get_source()] - = array(date('Y/m/d H:i:s', $time)); + $tfields[metadata_description_PHRASEANET_tfarchivedate::get_source()] = 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_tfchgdocdate::get_source()] = array(date('Y/m/d H:i:s', $time)); if ($this->get_mime() === 'application/pdf') { - $tfields[metadata_description_PHRASEANET_pdftext::get_source()] - = $this->read_pdf_datas(); + $tfields[metadata_description_PHRASEANET_pdftext::get_source()] = $this->read_pdf_datas(); } $datas = exiftool::extract_metadatas($this, exiftool::EXTRACT_XML_RDF); diff --git a/lib/classes/task/period/upgradetov32.class.php b/lib/classes/task/period/upgradetov32.class.php index 4c02e3f9be..8857497469 100644 --- a/lib/classes/task/period/upgradetov32.class.php +++ b/lib/classes/task/period/upgradetov32.class.php @@ -195,14 +195,9 @@ class task_period_upgradetov32 extends task_abstract foreach ($rs as $row) { try { $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) - continue; - - $tc_datas = $system_file->get_technical_datas(); - - foreach ($tc_datas as $name => $value) { + foreach ($document->readTechnicalDatas() as $name => $value) { if (is_null($value)) continue; diff --git a/lib/conf.d/_GV_template.inc b/lib/conf.d/_GV_template.inc index 5315755290..cd23a91c22 100644 --- a/lib/conf.d/_GV_template.inc +++ b/lib/conf.d/_GV_template.inc @@ -475,12 +475,6 @@ $GV = array( 'comment' => _('reglages:: chemin de l\'executable MP4Box'), 'default' => '' ), - array( - 'type' => 'string', - 'name' => 'GV_mplayer', - 'comment' => _('reglages:: chemin de l\'executable Mplayer'), - 'default' => '' - ), array( 'type' => 'string', 'name' => 'GV_pdftotext', diff --git a/templates/web/common/technical_datas.twig b/templates/web/common/technical_datas.twig index e4be582d65..9ff37ebeaf 100644 --- a/templates/web/common/technical_datas.twig +++ b/templates/web/common/technical_datas.twig @@ -61,36 +61,36 @@ {{record.get_formated_duration() }}
{% 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' %} : - {{record.get_technical_infos(constant('system_file::TC_DATAS_FRAMERATE')) }} ips + {{record.get_technical_infos(constant('media_subdef::TC_DATA_FRAMERATE')) }} ips
{% 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' %} : - {{record.get_technical_infos(constant('system_file::TC_DATAS_AUDIOCODEC')) }} + {{record.get_technical_infos(constant('media_subdef::TC_DATA_AUDIOCODEC')) }}
{% 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' %} : - {{record.get_technical_infos(constant('system_file::TC_DATAS_VIDEOCODEC')) }} + {{record.get_technical_infos(constant('media_subdef::TC_DATA_VIDEOCODEC')) }}
{% 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' %} : - {% 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
{% 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' %} : - {% 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
{% 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' %} : - {{record.get_technical_infos(constant('system_file::TC_DATAS_AUDIOSAMPLERATE')) }} kHz + {{record.get_technical_infos(constant('media_subdef::TC_DATA_AUDIOSAMPLERATE')) }} kHz
{% endif %} {% endif %} @@ -105,20 +105,20 @@ {{record.get_formated_duration() }}
{% 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' %} : - {{record.get_technical_infos(constant('system_file::TC_DATAS_AUDIOCODEC')) }} + {{record.get_technical_infos(constant('media_subdef::TC_DATA_AUDIOCODEC')) }}
{% 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' %} : - {% 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
{% 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' %} : - {{record.get_technical_infos(constant('system_file::TC_DATAS_AUDIOSAMPLERATE')) }} kHz + {{record.get_technical_infos(constant('media_subdef::TC_DATA_AUDIOSAMPLERATE')) }} kHz
{% endif %} {% endif %} diff --git a/tests/Alchemy/Phrasea/Application/ApiJsonTest.php b/tests/Alchemy/Phrasea/Application/ApiJsonTest.php index 3272b2e5f3..aa34115b3c 100644 --- a/tests/Alchemy/Phrasea/Application/ApiJsonTest.php +++ b/tests/Alchemy/Phrasea/Application/ApiJsonTest.php @@ -1429,18 +1429,10 @@ class ApiJsonApplication extends PhraseanetWebTestCaseAbstract $this->assertTrue(is_object($record->technical_informations)); foreach ($record->technical_informations as $key => $value) { - switch ($key) { - case system_file::TC_DATAS_DURATION: - case 'size': - case system_file::TC_DATAS_WIDTH: - 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; - } + if(is_string($value)) + $this->assertFalse(ctype_digit ($value)); + else + $this->assertTrue(is_int($value)); } } diff --git a/tests/Alchemy/Phrasea/Application/ApiYamlTest.php b/tests/Alchemy/Phrasea/Application/ApiYamlTest.php index f526e8791b..77b6310234 100644 --- a/tests/Alchemy/Phrasea/Application/ApiYamlTest.php +++ b/tests/Alchemy/Phrasea/Application/ApiYamlTest.php @@ -1467,17 +1467,10 @@ class ApiYamlApplication extends PhraseanetWebTestCaseAbstract $this->assertTrue(is_array($record["technical_informations"])); foreach ($record["technical_informations"] as $key => $value) { - switch ($key) { - case system_file::TC_DATAS_DURATION: - case 'size': - case system_file::TC_DATAS_WIDTH: - 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; + if (is_string($value)) { + $this->assertFalse(ctype_digit($value)); + } else { + $this->assertTrue(is_int($value)); } } } diff --git a/tests/Alchemy/Phrasea/Application/SetupTest.php b/tests/Alchemy/Phrasea/Application/SetupTest.php index b6988c1e71..cf98d650dd 100644 --- a/tests/Alchemy/Phrasea/Application/SetupTest.php +++ b/tests/Alchemy/Phrasea/Application/SetupTest.php @@ -54,7 +54,6 @@ class ApplicationSetupTest extends PhraseanetWebTestCaseAbstract 'GV_unoconv', 'GV_ffmpeg', 'GV_mp4box', - 'GV_mplayer', 'GV_pdftotext', ); diff --git a/tests/Alchemy/Phrasea/Controller/Admin/PublicationTest.php b/tests/Alchemy/Phrasea/Controller/Admin/PublicationTest.php index 0f4a93da22..15694c8766 100644 --- a/tests/Alchemy/Phrasea/Controller/Admin/PublicationTest.php +++ b/tests/Alchemy/Phrasea/Controller/Admin/PublicationTest.php @@ -226,7 +226,7 @@ class Module_Admin_Route_PublicationTest extends PhraseanetWebTestCaseAuthentica "POST" , "/publications/feed/" . $feed->get_id() . "/iconupload/" , 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(); $this->assertTrue($response->isOk()); @@ -235,63 +235,6 @@ class Module_Admin_Route_PublicationTest extends PhraseanetWebTestCaseAuthentica $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() { $appbox = appbox::get_instance(\bootstrap::getCore()); diff --git a/tests/Alchemy/Phrasea/Controller/Root/RSSFeedTest.php b/tests/Alchemy/Phrasea/Controller/Root/RSSFeedTest.php index 7ecc9bd9de..1aa90b9c51 100644 --- a/tests/Alchemy/Phrasea/Controller/Root/RSSFeedTest.php +++ b/tests/Alchemy/Phrasea/Controller/Root/RSSFeedTest.php @@ -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->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->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->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->set_public(true); diff --git a/tests/Feed/Feed_AdapterTest.php b/tests/Feed/Feed_AdapterTest.php index 3476edc461..5c87f78e9e 100644 --- a/tests/Feed/Feed_AdapterTest.php +++ b/tests/Feed/Feed_AdapterTest.php @@ -4,287 +4,268 @@ require_once __DIR__ . '/../PhraseanetPHPUnitAuthenticatedAbstract.class.inc'; 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?'; - /** - * - * @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 + public static function setUpBeforeClass() { - $file = new system_file(__DIR__ . '/../testfiles/iphone_pic.jpg'); - self::$object->set_icon($file); - $this->fail('Should fail'); - } - catch (Exception $e) - { - - } - $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; + 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); } - 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) + public static function tearDownAfterClass() { - foreach ($databox->get_collections() as $collection) - { - $coll = $collection; - break; - } - if ($coll instanceof collection) - break; + self::$object->delete(); + parent::tearDownAfterClass(); } - 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 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 = 'GROS NIchONS'; - self::$object->set_title($title); - $this->assertNotEquals($title, self::$object->get_title()); - $this->assertEquals(strip_tags($title), self::$object->get_title()); - - try + public function testGet_icon_url() { - self::$object->set_title(' '); - $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) - { - + $this->assertEquals('/skins/icons/rss32.gif', self::$object->get_icon_url()); } - 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 + public function testSet_icon() { - self::$object->set_title(''); - $this->fail(); + $this->assertEquals('/skins/icons/rss32.gif', self::$object->get_icon_url()); + $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() - { - $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 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 testGet_created_on() - { - $this->assertInstanceOf('DateTime', self::$object->get_created_on()); - } + 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 = 'GROS NIchONS'; + 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() - { - $this->assertInstanceOf('DateTime', self::$object->get_updated_on()); - } + try { + self::$object->set_title(' '); + $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()); + } } diff --git a/tests/media/media_subdefTest.php b/tests/media/media_subdefTest.php index 5daa19974c..5eff4b1954 100644 --- a/tests/media/media_subdefTest.php +++ b/tests/media/media_subdefTest.php @@ -270,4 +270,21 @@ class media_subdefTest extends \PhraseanetPHPUnitAbstract { 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); + } } diff --git a/tests/record/adapterTest.php b/tests/record/adapterTest.php index 34f17f3528..87b9b78734 100644 --- a/tests/record/adapterTest.php +++ b/tests/record/adapterTest.php @@ -198,13 +198,13 @@ class record_adapterTest extends PhraseanetPHPUnitAuthenticatedAbstract 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()); } 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()); } diff --git a/tests/system/system_fileTest.php b/tests/system/system_fileTest.php index 0c15329780..df60a67ac7 100644 --- a/tests/system/system_fileTest.php +++ b/tests/system/system_fileTest.php @@ -45,31 +45,6 @@ class system_fileTest extends PhraseanetPHPUnitAbstract $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() { $this->assertEquals('unknown', $this->objects['indd']->get_phrasea_type());