[SPIP Zone] r4337 - in /_plugins_/_contenu_editorial_/FpipR: action/flickr_ajouter_documents.php exec/flickr_choix_photos.php inc/flickr_api.php

Author: pierre.andrews@gmail.com
Date: Tue Aug 1 00:20:22 2006
New Revision: 4337

Log:
si tag-machine est active, alors on ajoute aussi les tags Flickr aux documents, dans le groupe FlickrTag (cree si besoin).

Modified:
    _plugins_/_contenu_editorial_/FpipR/action/flickr_ajouter_documents.php
    _plugins_/_contenu_editorial_/FpipR/exec/flickr_choix_photos.php
    _plugins_/_contenu_editorial_/FpipR/inc/flickr_api.php

Modified: _plugins_/_contenu_editorial_/FpipR/action/flickr_ajouter_documents.php

--- _plugins_/_contenu_editorial_/FpipR/action/flickr_ajouter_documents.php (original)
+++ _plugins_/_contenu_editorial_/FpipR/action/flickr_ajouter_documents.php Tue Aug 1 00:20:22 2006
@@ -62,9 +62,18 @@
       if($photo_details->date_taken) $q .=", date= '".$photo_details->date_taken."'";
       $q .=" WHERE id_document=".$doc_row['id_document'];
       spip_query($q);
+ if(in_array('tag-machine',liste_plugin_actifs())) {
+ include_spip('inc/tag-machine');
+ foreach($photo_details->tags as $tag) {
+ var_dump($tag->raw);
+ $t = new Tag($tag->raw,'FlickrTag');
+ $t->ajouter($doc_row['id_document'],'documents','id_document');
       }
     }
     }
+ }
+ }
+
     redirige_par_entete(urldecode($redirect));
   }
   }

Modified: _plugins_/_contenu_editorial_/FpipR/exec/flickr_choix_photos.php

--- _plugins_/_contenu_editorial_/FpipR/exec/flickr_choix_photos.php (original)
+++ _plugins_/_contenu_editorial_/FpipR/exec/flickr_choix_photos.php Tue Aug 1 00:20:22 2006
@@ -75,10 +75,11 @@
     if($i != $page) {
       echo '<a href="'.generer_url_ecrire('flickr_choix_photos',"page=$i&type="._request('type')."&id="._request('id')."&sort=$sort".(_request('text_search')?"&text_search="._request('text_search'):'')).'">';
     }
- echo $i.'|';
+ echo $i;
     if($i != $page) {
       echo '</a>';
     }
+ echo (($i == $photos->pages)?'':'&nbsp;|');
     echo "\n";
     }
   }

Modified: _plugins_/_contenu_editorial_/FpipR/inc/flickr_api.php

--- _plugins_/_contenu_editorial_/FpipR/inc/flickr_api.php (original)
+++ _plugins_/_contenu_editorial_/FpipR/inc/flickr_api.php Tue Aug 1 00:20:22 2006
@@ -91,7 +91,7 @@

//======================================================================

-class Photos {
+class FlickrPhotos {
   var $page;
   var $per_page;
   var $total;
@@ -100,7 +100,7 @@
   var $photos = array();
}

-class PhotoDetails {
+class FlickrPhotoDetails {
   var $id;
   var $secret;
   var $server;
@@ -139,7 +139,7 @@

}

-class Photo {
+class FlickrPhoto {
   var $id;
   var $owner;
   var $secret;
@@ -167,7 +167,7 @@
   }
}

-class PhotoSet {
+class FlickrPhotoSet {
   var $owner;
   var $id;
   var $primary;
@@ -194,12 +194,19 @@

}

-class License {
+class FlickrLicense {
   var $url;
   var $name;
   var $id;
}

+class FlickrTag {
+ var $id;
+ var $author;
+ var $raw;
+ var $safe;
+}
+
//======================================================================

function flickr_photos_search(
@@ -234,7 +241,7 @@
   else $params['extras'] = "original_format";

   $photos = flickr_check_error(flickr_api_call('flickr.photos.search',$params,$auth_token));
- $resp = new Photos;
+ $resp = new FlickrPhotos;
   if($photos) {
   $rez = array_keys($photos);
   $photos = array_keys($photos[$rez[0]][0]);
@@ -245,7 +252,7 @@

   foreach($photos as $photo) {
- $new_p = new Photo;
+ $new_p = new FlickrPhoto;
     if(preg_match_all('#([a-zA-Z_]+)="(.*?)"#',$photo,$matches,PREG_SET_ORDER)) {
     foreach($matches as $m) $new_p->$m[1] = $m[2];
     }
@@ -278,7 +285,7 @@
   $photosets = $photosets[$rez[0]][0];

   foreach($photosets as $set => $data) {
- $new_p = new PhotoSet;
+ $new_p = new FlickrPhotoSet;
     $new_p->owner = $user_id;
     if(preg_match_all('#([a-zA-Z_]+)="(.*?)"#',$set,$matches,PREG_SET_ORDER)) {
     foreach($matches as $m) {
@@ -309,7 +316,7 @@
   $photos = array_keys($photos[$rez[0]][0]);

   foreach($photos as $photo) {
- $new_p = new Photo;
+ $new_p = new FlickrPhoto;
     if(preg_match_all('#([a-zA-Z_]+)="(.*?)"#',$photo,$matches,PREG_SET_ORDER)) {
     foreach($matches as $m)
       $new_p->$m[1] = $m[2];
@@ -325,7 +332,7 @@
   $params = array('photo_id'=>$photo_id,'secret'=>$secret);

   $photo = flickr_check_error(flickr_api_call('flickr.photos.getInfo',$params,$auth_token));
- $resp = new PhotoDetails;
+ $resp = new FlickrPhotoDetails;
   if($photo) {
   $rez = array_keys($photo);
   // $details = array_keys($photo[$rez[0]][0]);
@@ -361,7 +368,14 @@
     }
     } else if(strpos($tag,'tags') === 0) {
     foreach($v[0] as $taginfo => $tag) {
- $resp->tags[] = $tag[0];
+ $t = new FlickrTag;
+ $t->safe = $tag[0];
+ if(preg_match_all('#(id|raw|author)="(.*?)"#',$taginfo,$matches,PREG_SET_ORDER)) {
+ foreach($matches as $m) {
+ $t->$m[1] = $m[2];
+ }
+ }
+ $resp->tags[] = $t;
     }
     } else if(strpos($tag,'urls') === 0) {
     foreach($v[0] as $urltype => $url) {
@@ -408,7 +422,7 @@
   if($licenses = $licenses['licenses']) {
   foreach(array_keys($licenses[0]) as $l) {
     if(preg_match_all('#(name|url|id)="(.*?)"#',$l,$matches,PREG_SET_ORDER)) {
- $lic = new License;
+ $lic = new FlickrLicense;
     foreach($matches as $m) {
       $lic->$m[1] = $m[2];
     }