1 | <?php |
---|
2 | |
---|
3 | function action_flickr_ajouter_documents() { |
---|
4 | include_spip('base/abstract_sql'); |
---|
5 | include_spip('inc/flickr_api'); |
---|
6 | include_spip('inc/securiser_action'); |
---|
7 | |
---|
8 | |
---|
9 | $hash = _request('hash'); |
---|
10 | $id = intval(_request('id')); |
---|
11 | $type = addslashes(_request('type')); |
---|
12 | $action = _request('action'); |
---|
13 | $arg = _request('arg'); |
---|
14 | $redirect = _request('redirect'); |
---|
15 | $id_auteur = intval($GLOBALS['auteur_session']['id_auteur']); |
---|
16 | |
---|
17 | if (!verifier_action_auteur("$action-$arg", $hash,$id_auteur)) { |
---|
18 | include_spip('inc/minipres'); |
---|
19 | minipres(_T('info_acces_interdit')); |
---|
20 | } else { |
---|
21 | $from = array('spip_auteurs'); |
---|
22 | $select = array('flickr_token','flickr_nsid'); |
---|
23 | $where = array('id_auteur='.$id_auteur); |
---|
24 | $row = spip_abstract_fetsel($select,$from,$where); |
---|
25 | $photos = array(); |
---|
26 | if($row['flickr_nsid'] != '' && $row['flickr_token'] != '') { |
---|
27 | $set = _request('set'); |
---|
28 | if($set == 'oui') { |
---|
29 | $sets = _request('sets'); |
---|
30 | foreach($sets as $s) { |
---|
31 | $allphotos = flickr_photosets_getPhotos($s,'','',$row['auth_token']); |
---|
32 | foreach($allphotos->photos as $photo) { |
---|
33 | $photos[] = $photo->id.'@#@'.$photo->secret; |
---|
34 | } |
---|
35 | } |
---|
36 | } else { |
---|
37 | $photos = _request('photos'); |
---|
38 | } |
---|
39 | |
---|
40 | include_spip('inc/ajouter_documents'); |
---|
41 | foreach($photos as $info) { |
---|
42 | list($id_photo,$secret) = split('@#@',$info); |
---|
43 | $id_photo= intval($id_photo); |
---|
44 | $photo_details = flickr_photos_getInfo($id_photo,$secret,$row['auth_token']); |
---|
45 | if($photo_details->id) { |
---|
46 | $empty = array(); |
---|
47 | $url = $photo_details->source('o'); |
---|
48 | $cnt =spip_abstract_fetsel(array('id_document'),array('spip_documents'),array("fichier='$url'","distant='oui'")); |
---|
49 | if(!$cnt) { |
---|
50 | $date = date('Y-m-d H:i:s'); |
---|
51 | ajouter_un_document($url,$photo_details->title,$type,$id,'distant',0,$empty); |
---|
52 | $date2 = date('Y-m-d H:i:s'); |
---|
53 | $from = array('spip_documents'); |
---|
54 | $select = array('id_document'); |
---|
55 | $where = array("distant='oui'","fichier='$url'","maj >= '$date'","maj <= '$date2'"); |
---|
56 | $doc_row = spip_abstract_fetsel($select,$from,$where); |
---|
57 | if($doc_row['id_document']) { |
---|
58 | global $table_prefix; |
---|
59 | $title = $photo_details->title; |
---|
60 | if($photo_details->owner_nsid != $row['flickr_nsid']) { |
---|
61 | $title = _T('fpipr:par',array('title'=>$title,'user'=>(($photo_details->owner_username)?$photo_details->owner_username:$photo_details->owner_nsid),'url'=>'http://www.flickr.com/people/'.$photo_details->owner_nsid)); |
---|
62 | } |
---|
63 | include_spip('inc/filtres'); |
---|
64 | $q = "UPDATE ".$table_prefix."_documents SET titre = '<html>"._q($title)."</html>', descriptif = '<html>"._q(filtrer_entites($photo_details->description))."</html>'"; |
---|
65 | if($photo_details->date_taken) $q .=", date= '"._q($photo_details->date_taken)."'"; |
---|
66 | $q .=" WHERE id_document=".$doc_row['id_document']; |
---|
67 | spip_query($q); |
---|
68 | include_spip('inc/plugin'); |
---|
69 | //ATTENTION TODO, on s'attend a trouver tag-machine dans _dev_, mauvaise idee. |
---|
70 | if(in_array('_dev_/tag-machine',liste_plugin_actifs())) { |
---|
71 | include_spip('inc/tag-machine'); |
---|
72 | foreach($photo_details->tags as $tag) { |
---|
73 | if($tag->raw) { |
---|
74 | $t = new Tag($tag->raw,'FlickrTag'); |
---|
75 | $t->ajouter($doc_row['id_document'],'documents','id_document'); |
---|
76 | } |
---|
77 | } |
---|
78 | } |
---|
79 | } |
---|
80 | } else { |
---|
81 | $link =spip_abstract_fetsel(array('id_document,id_article'),array('spip_documents_'.$type.'s'),array("id_$type=$id","id_document=".$cnt['id_document'])); |
---|
82 | if(!$link) { |
---|
83 | spip_abstract_insert('spip_documents_'.$type.'s',"(id_$type,id_document)","($id,".$cnt['id_document'].')'); |
---|
84 | } |
---|
85 | } |
---|
86 | } |
---|
87 | } |
---|
88 | |
---|
89 | if(!$redirect) { |
---|
90 | $redirect = generer_url_ecrire($type.'s',"id_$type=$id",true); |
---|
91 | } |
---|
92 | redirige_par_entete(urldecode($redirect)); |
---|
93 | } |
---|
94 | } |
---|
95 | } |
---|
96 | |
---|
97 | ?> |
---|