Subversion Repositories eFlore/Applications.cel

Rev

Rev 617 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

<?php
/**
* PHP Version 5
*  
* Retourne un RDF des images pour eflore
*
* @category  PHP
* @package   jrest
* @author    david <david@tela-botania.org>
* @copyright 2010 Tela-Botanica
* @license   http://www.cecill.info/licences/Licence_CeCILL_V2-fr.txt Licence CECILL
* @version   SVN: <svn_id>
* @link      /doc/jrest/
*/
Class ImageRDF extends DBAccessor {

        var $config;

    function ImageRDF($config) {

        $this->config=$config;
    }

    
    
        /**
         * Recherche des images associee au numero nomenclatural
         * @param numeric $uid [0] : numero nomenclatural obligatoire , $uid[1] (optionnel) : taille image : S , M,  L (default)
         */
    
    
    // TODO : recherche taxon ?
    
        function getElement($uid){

                
                // Taille 
                if (isset($uid[1])) {
                        $taille = $uid[1]; // S , M ou L
                }
                else {
                        $taille = 'L';
                } 
                
                
        $DB=$this->connectDB($this->config,'cel_db');
        
        // Recherche de toutes les observations transmises du taxon pour lesquelles une photo est associee. 
                
        $query = 'SELECT * FROM cel_inventory, cel_obs_images, cel_images '.
                        ' WHERE cel_inventory.num_nom_sel = "'.mysql_escape_string($uid[0]).'"'.
                        ' AND cel_obs_images.coi_ce_utilisateur = cel_inventory.identifiant '.
                        ' AND cel_obs_images.coi_ce_observation = cel_inventory.ordre '.
                                ' AND cel_inventory.transmission =  1 '.
                                ' AND cel_images.ci_ce_utilisateur = cel_obs_images.coi_ce_utilisateur '. 
                                ' AND  ci_id_image = cel_obs_images.coi_ce_image';

        
        $result =& $DB->query($query);

        if (DB::isError($result)) {
            die($result->getMessage());
        }


        $picture_path = $this->config['cel_db']['url_images'];           
                
            
                // Formatage du xml
                $xml = '<?xml version="1.0" encoding="utf-8"?>'."\n";
                $xml .= '<rdf:RDF'."\n";
                $xml .= '       xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"'."\n";
                $xml .= '       xmlns:dc="http://purl.org/dc/elements/1.1/"'."\n";
                $xml .= '       xmlns:dcterms="http://purl.org/dc/terms">'."\n";
                        

        while ($picture =& $result->fetchrow(DB_FETCHMODE_ASSOC)) {
                // Calcul du chemin sur le serveur en fonction de l'identifiant (id)
                
                $id = $picture['ci_id_image'];
                        $id = sprintf('%09s', $id) ;
            $id = wordwrap($id, 3 , '_', true) ;

            $id_fichier = $id.".jpg" ;

            $niveauDossier = split("_", $id) ;

            $dossierNiveau1 = $niveauDossier[0] ;
            $dossierNiveau2 = $niveauDossier[1] ;

            $picture_path_with_level = $picture_path.'/'.$dossierNiveau1.'/'.$dossierNiveau2 ;

         
             
                        $xml .= '       <rdf:Description about="'.$picture_path_with_level.'/'.$taille.'/'.$id.'_'.$taille.'.jpg'.'"'."\n";
                        $xml .= '               dc:identifier="'.'urn:lsid:tela-botanica.org:celpic:'.$picture['ci_id_image'].'"'."\n";
                        $xml .= '               dc:title="'.$picture['nom_sel'].'"'."\n";
                        $xml .= '               dc:description="'.$picture['nom_sel']." - [fichier_origine:".$picture['ci_nom_original'].'][image_identifiant:'.$picture['ci_id_image'].']';
                        $xml .= '[image_ordre:'.$picture['ci_ordre'].']';
                        $xml .= '[observation_identifiant:'.$picture['id'].']';
                        $xml .= '[observation_ordre:'.$picture['ordre'].']'.'"'."\n";
                        $xml .= '               dc:creator="'.$picture['identifiant'].'"'."\n";
                        $xml .= '               dc:publisher="CEL"'."\n";
                        $xml .= '               dcterms:spatial="'.utf8_decode($picture['location'])." (".$picture['id_location'].")".'"'."\n";
                        
                if ($picture['date_observation'] != '0000-00-00 00:00:00') {
                                list($year,$month,$day) = split ('-',$picture['date_observation']);
                    list($day) = split (' ',$day);
                                $created = $day.'/'.$month.'/'.$year;
                                $xml .= '               dcterms:created="'.$created.'"'."\n";
                        }
                        $xml .= '               dcterms:licence="CC BY-SA"/>'."\n";
                }
                
                $xml .= '</rdf:RDF>'."\n";
                
                // Envoi du xml au navigateur
                header("Content-Type: text/xml");
                echo utf8_encode(str_replace(' & ', ' &#38; ', $xml));
                

      }

        function envoyerRequete($url) {
                $contenu = false;
                $contexte = stream_context_create(array(
                                'http' => array(
                        'method' => 'GET',
                            'header' => "Content-type: application/x-www-form-urlencoded\r\n")));
                        
                $flux = @fopen($url, 'r', false, $contexte);
                $contenu = json_decode(stream_get_contents($flux));
                fclose($flux);
                return $contenu;
        }       

}
?>