Skip to content
Extraits de code Groupes Projets
Valider 4f3478fc rédigé par cedric@yterium.com's avatar cedric@yterium.com
Parcourir les fichiers

extraire les methodes de determination des metas data (largeur, hauteur,...

extraire les methodes de determination des metas data (largeur, hauteur, duree, ...) par extension, afin de permettre d'ajouter facilement de nouvelles methodes.
Integrer la methode de lecture de la taille et duree des flv (lapin_malin)
parent 81984540
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
...@@ -71,6 +71,10 @@ lang/medias_fr.php -text ...@@ -71,6 +71,10 @@ lang/medias_fr.php -text
/medias_autoriser.php -text /medias_autoriser.php -text
/medias_fonctions.php -text /medias_fonctions.php -text
/medias_pipelines.php -text /medias_pipelines.php -text
metadata/flv.php -text
metadata/image.php -text
metadata/svg.php -text
metadata/swf.php -text
modalbox/jquery.simplemodal-1.3.3.js -text modalbox/jquery.simplemodal-1.3.3.js -text
modalbox/modal_closebox.png -text modalbox/modal_closebox.png -text
modalbox/modalbox.js -text modalbox/modalbox.js -text
......
...@@ -52,10 +52,14 @@ function renseigner_source_distante($source){ ...@@ -52,10 +52,14 @@ function renseigner_source_distante($source){
* @return <type> * @return <type>
*/ */
function renseigner_taille_dimension_image($fichier,$ext){ function renseigner_taille_dimension_image($fichier,$ext){
$infos = array();
$infos['type_image'] = false;
$infos = array(
'largeur'=>0,
'hauteur'=>0,
'type_image'=>'',
'taille'=>0
);
// Quelques infos sur le fichier // Quelques infos sur le fichier
if ( if (
!$fichier !$fichier
...@@ -65,110 +69,22 @@ function renseigner_taille_dimension_image($fichier,$ext){ ...@@ -65,110 +69,22 @@ function renseigner_taille_dimension_image($fichier,$ext){
return _T('medias:erreur_copie_fichier',array('nom'=> $fichier)); return _T('medias:erreur_copie_fichier',array('nom'=> $fichier));
} }
// VIDEOS : Prevoir traitement specifique ? // chercher une fonction de description
// (http://www.getid3.org/ peut-etre) $meta = array();
if ($ext == "mov") { if ($metadata = charger_fonction($ext,"metadata",true)){
$infos['largeur'] = 0; $meta = $metadata($fichier);
$infos['hauteur'] = 0;
}
// SVG : recuperer les dimensions et supprimer les scripts
elseif ($ext == "svg") {
list($infos['largeur'],$infos['hauteur'])= traite_svg($fichier);
}
// image ?
else {
// Si c'est une image, recuperer sa taille et son type (detecte aussi swf)
$size_image = @getimagesize($fichier);
$infos['largeur'] = intval($size_image[0]);
$infos['hauteur'] = intval($size_image[1]);
$infos['type_image'] = decoder_type_image($size_image[2]);
} }
else {
$media = sql_getfetsel('media','spip_types_documents','extension='.sql_quote($ext));
if ($metadata = charger_fonction($media,"metadata",true)){
$meta = $metadata($fichier);
}
}
foreach($meta as $m=>$v)
if (in_array($m,array('largeur','hauteur','type_image'/*,'duree'*/)))
$infos[$m] = $v;
return $infos; return $infos;
} }
if (!function_exists('traite_svg')){
/**
* Determiner les dimensions d'un svg, et enlever ses scripts si necessaire
*
* @param string $file
* @return array
*/
// http://doc.spip.org/@traite_svg
function traite_svg($file)
{
$texte = spip_file_get_contents($file);
// Securite si pas admin : virer les scripts et les references externes
// sauf si on est en mode javascript 'ok' (1), cf. inc_version
if ($GLOBALS['filtrer_javascript'] < 1
AND $GLOBALS['visiteur_session']['statut'] != '0minirezo') {
include_spip('inc/texte');
$new = trim(safehtml($texte));
// petit bug safehtml
if (substr($new,0,2) == ']>') $new = ltrim(substr($new,2));
if ($new != $texte) ecrire_fichier($file, $texte = $new);
}
$width = $height = 150;
if (preg_match(',<svg[^>]+>,', $texte, $s)) {
$s = $s[0];
if (preg_match(',\WviewBox\s*=\s*.\s*(\d+)\s+(\d+)\s+(\d+)\s+(\d+),i', $s, $r)){
$width = $r[3];
$height = $r[4];
} else {
// si la taille est en centimetre, estimer le pixel a 1/64 de cm
if (preg_match(',\Wwidth\s*=\s*.(\d+)([^"\']*),i', $s, $r)){
if ($r[2] != '%') {
$width = $r[1];
if ($r[2] == 'cm') $width <<=6;
}
}
if (preg_match(',\Wheight\s*=\s*.(\d+)([^"\']*),i', $s, $r)){
if ($r[2] != '%') {
$height = $r[1];
if ($r[2] == 'cm') $height <<=6;
}
}
}
}
return array($width, $height);
}
}
if (!function_exists('decoder_type_image')){
/**
* Convertit le type numerique retourne par getimagesize() en extension fichier
*
* @param int $type
* @param bool $strict
* @return string
*/
// http://doc.spip.org/@decoder_type_image
function decoder_type_image($type, $strict = false) {
switch ($type) {
case 1:
return "gif";
case 2:
return "jpg";
case 3:
return "png";
case 4:
return $strict ? "" : "swf";
case 5:
return "psd";
case 6:
return "bmp";
case 7:
case 8:
return "tif";
default:
return "";
}
}
}
?> ?>
\ No newline at end of file
<?php
/***************************************************************************\
* SPIP, Systeme de publication pour l'internet *
* *
* Copyright (c) 2001-2011 *
* Arnaud Martin, Antoine Pitrou, Philippe Riviere, Emmanuel Saint-James *
* *
* Ce programme est un logiciel libre distribue sous licence GNU/GPL. *
* Pour plus de details voir le fichier COPYING.txt ou l'aide en ligne. *
\***************************************************************************/
if (!defined('_ECRIRE_INC_VERSION')) return;
function metadata_flv_dist($file, $bigindian = true){
$meta = array();
if ($fd = fopen($file, 'r')
AND $raw = fread($fd, 512)){
$keys = array('largeur'=>'width', 'hauteur'=>'height','duree'=>'duration','framerate'=>'framerate');
foreach ($keys as $m=>$k) {
if (($i = strpos($raw, $k))>-1){
$bytes = substr($raw, $i+strlen($k)+1, 8);
if ($bigindian)
$bytes = strrev($bytes);
$zz = unpack("dflt", $bytes); // unpack the bytes
$meta[$m] = $zz['flt']; // return the number from the associative array
}
}
}
return $meta;
}
?>
\ No newline at end of file
<?php
/***************************************************************************\
* SPIP, Systeme de publication pour l'internet *
* *
* Copyright (c) 2001-2011 *
* Arnaud Martin, Antoine Pitrou, Philippe Riviere, Emmanuel Saint-James *
* *
* Ce programme est un logiciel libre distribue sous licence GNU/GPL. *
* Pour plus de details voir le fichier COPYING.txt ou l'aide en ligne. *
\***************************************************************************/
if (!defined('_ECRIRE_INC_VERSION')) return;
function metadata_image_dist($fichier){
$meta = array();
if ($size_image = @getimagesize($fichier)) {
$meta['largeur'] = intval($size_image[0]);
$meta['hauteur'] = intval($size_image[1]);
$meta['type_image'] = decoder_type_image($size_image[2]);
}
return $meta;
}
/**
* Convertit le type numerique retourne par getimagesize() en extension fichier
*
* @param int $type
* @param bool $strict
* @return string
*/
// http://doc.spip.org/@decoder_type_image
function decoder_type_image($type, $strict = false) {
switch ($type) {
case 1:
return "gif";
case 2:
return "jpg";
case 3:
return "png";
case 4:
return $strict ? "" : "swf";
case 5:
return "psd";
case 6:
return "bmp";
case 7:
case 8:
return "tif";
default:
return "";
}
}
?>
\ No newline at end of file
<?php
/***************************************************************************\
* SPIP, Systeme de publication pour l'internet *
* *
* Copyright (c) 2001-2011 *
* Arnaud Martin, Antoine Pitrou, Philippe Riviere, Emmanuel Saint-James *
* *
* Ce programme est un logiciel libre distribue sous licence GNU/GPL. *
* Pour plus de details voir le fichier COPYING.txt ou l'aide en ligne. *
\***************************************************************************/
if (!defined('_ECRIRE_INC_VERSION')) return;
/**
* Determiner les dimensions d'un svg, et enlever ses scripts si necessaire
*
* @param string $file
* @return array
*/
// http://doc.spip.org/@traite_svg
function medata_svg_dist($file){
$meta = array();
$texte = spip_file_get_contents($file);
// Securite si pas admin : virer les scripts et les references externes
// sauf si on est en mode javascript 'ok' (1), cf. inc_version
if ($GLOBALS['filtrer_javascript'] < 1
AND $GLOBALS['visiteur_session']['statut'] != '0minirezo') {
include_spip('inc/texte');
$new = trim(safehtml($texte));
// petit bug safehtml
if (substr($new,0,2) == ']>') $new = ltrim(substr($new,2));
if ($new != $texte) ecrire_fichier($file, $texte = $new);
}
$width = $height = 150;
if (preg_match(',<svg[^>]+>,', $texte, $s)) {
$s = $s[0];
if (preg_match(',\WviewBox\s*=\s*.\s*(\d+)\s+(\d+)\s+(\d+)\s+(\d+),i', $s, $r)){
$width = $r[3];
$height = $r[4];
} else {
// si la taille est en centimetre, estimer le pixel a 1/64 de cm
if (preg_match(',\Wwidth\s*=\s*.(\d+)([^"\']*),i', $s, $r)){
if ($r[2] != '%') {
$width = $r[1];
if ($r[2] == 'cm') $width <<=6;
}
}
if (preg_match(',\Wheight\s*=\s*.(\d+)([^"\']*),i', $s, $r)){
if ($r[2] != '%') {
$height = $r[1];
if ($r[2] == 'cm') $height <<=6;
}
}
}
}
$meta['largeur'] = $width;
$meta['hauteur'] = $height;
return $meta;
}
\ No newline at end of file
<?php
/***************************************************************************\
* SPIP, Systeme de publication pour l'internet *
* *
* Copyright (c) 2001-2011 *
* Arnaud Martin, Antoine Pitrou, Philippe Riviere, Emmanuel Saint-James *
* *
* Ce programme est un logiciel libre distribue sous licence GNU/GPL. *
* Pour plus de details voir le fichier COPYING.txt ou l'aide en ligne. *
\***************************************************************************/
if (!defined('_ECRIRE_INC_VERSION')) return;
function metadata_swf_dist($file){
$metadata = charger_fonction('image','metadata');
return $metadata($file);
}
\ No newline at end of file
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter