Changeset 26180 for extensions/flickr2piwigo/include/ws_functions.inc.php
- Timestamp:
- Dec 24, 2013, 6:23:13 PM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
extensions/flickr2piwigo/include/ws_functions.inc.php
r25790 r26180 1 1 <?php 2 if (!defined('FLICKR_PATH'))die('Hacking attempt!');2 defined('FLICKR_PATH') or die('Hacking attempt!'); 3 3 4 4 function flickr_add_ws_method($arr) 5 5 { 6 6 $service = &$arr[0]; 7 7 8 8 $service->addMethod( 9 9 'pwg.images.addFlickr', … … 14 14 'fills' => array('default' =>null), 15 15 ), 16 'Used by Flickr2Piwigo' 16 'Used by Flickr2Piwigo', 17 null, 18 array('hidden'=>true) 17 19 ); 18 20 } … … 24 26 return new PwgError(403, 'Forbidden'); 25 27 } 26 28 27 29 global $conf; 28 $conf['flickr2piwigo'] = unserialize($conf['flickr2piwigo']); 29 30 if ( empty($conf['flickr2piwigo']['api_key']) or empty($conf['flickr2piwigo']['secret_key']) ) 30 31 if (empty($conf['flickr2piwigo']['api_key']) or empty($conf['flickr2piwigo']['secret_key'])) 31 32 { 32 33 return new PwgError(null, l10n('Please fill your API keys on the configuration tab')); 33 34 } 34 35 35 36 include_once(PHPWG_ROOT_PATH . 'admin/include/functions.php'); 36 37 include_once(PHPWG_ROOT_PATH . 'admin/include/functions_upload.inc.php'); 37 38 include_once(FLICKR_PATH . 'include/functions.inc.php'); 38 39 39 40 if (test_remote_download() === false) 40 41 { 41 42 return new PwgError(null, l10n('No download method available')); 42 43 } 43 44 44 45 // init flickr API 45 46 include_once(FLICKR_PATH . 'include/phpFlickr/phpFlickr.php'); 46 47 $flickr = new phpFlickr($conf['flickr2piwigo']['api_key'], $conf['flickr2piwigo']['secret_key']); 47 48 $flickr->enableCache('fs', FLICKR_FS_CACHE); 48 49 49 50 // user 50 51 $u = $flickr->test_login(); 51 if ( $u === false or empty($_SESSION['phpFlickr_auth_token']))52 if ($u === false or empty($_SESSION['phpFlickr_auth_token'])) 52 53 { 53 54 return new PwgError(403, l10n('API not authenticated')); 54 55 } 55 56 56 57 // photos infos 57 58 $photo_f = $flickr->photos_getInfo($photo['id']); … … 59 60 $photo['url'] = $flickr->get_biggest_size($photo['id'], 'original'); 60 61 $photo['path'] = FLICKR_FS_CACHE . 'flickr-'.$u['username'].'-'.$photo['id'].'.'.get_extension($photo['url']); 61 62 62 63 // copy file 63 64 if (download_remote_file($photo['url'], $photo['path']) == false) … … 65 66 return new PwgError(null, l10n('Can\'t download file')); 66 67 } 67 68 68 69 // category 69 70 if (!preg_match('#^[0-9]+$#', $photo['category'])) 70 71 { 71 72 $categories_names = explode(',', $photo['category']); 72 73 73 74 $photo['category'] = array(); 74 75 foreach ($categories_names as $category_name) … … 79 80 ;'; 80 81 $result = pwg_query($query); 81 82 82 83 if (pwg_db_num_rows($result)) 83 84 { 84 85 list($cat_id) = pwg_db_fetch_row($result); 85 array_push($photo['category'], $cat_id);86 $photo['category'][] = $cat_id; 86 87 } 87 88 else 88 89 { 89 90 90 91 $cat = create_virtual_category($category_name); 91 array_push($photo['category'], $cat['id']);92 $photo['category'][] = $cat['id']; 92 93 } 93 94 } … … 97 98 $photo['category'] = array($photo['category']); 98 99 } 99 100 100 101 // add photo 101 102 $photo['image_id'] = add_uploaded_file($photo['path'], basename($photo['path']), $photo['category']); 102 103 103 104 // do some updates 104 105 if (!empty($photo['fills'])) … … 106 107 $photo['fills'] = rtrim($photo['fills'], ','); 107 108 $photo['fills'] = explode(',', $photo['fills']); 108 109 109 110 $updates = array(); 110 if (in_array('fill_name', $photo['fills'])) $updates['name'] = pwg_db_real_escape_string($photo['title']); 111 if (in_array('fill_name', $photo['fills'])) $updates['name'] = pwg_db_real_escape_string($photo['title']); 111 112 if (in_array('fill_posted', $photo['fills'])) $updates['date_available'] = date('Y-m-d H:i:s', $photo['dates']['posted']); 112 113 if (in_array('fill_taken', $photo['fills'])) $updates['date_creation'] = $photo['dates']['taken']; … … 115 116 if (in_array('fill_geotag', $photo['fills']) and !empty($photo['location']) ) 116 117 { 117 $updates['lat '] = pwg_db_real_escape_string($photo['location']['latitude']);118 $updates['lon '] = pwg_db_real_escape_string($photo['location']['longitude']);118 $updates['latitude'] = pwg_db_real_escape_string($photo['location']['latitude']); 119 $updates['longitude'] = pwg_db_real_escape_string($photo['location']['longitude']); 119 120 } 120 121 121 122 if (count($updates)) 122 123 { … … 127 128 ); 128 129 } 129 130 if ( !empty($photo['tags']['tag']) and in_array('fill_tags', $photo['fills']))130 131 if (!empty($photo['tags']['tag']) and in_array('fill_tags', $photo['fills'])) 131 132 { 132 133 $raw_tags = array_map(create_function('$t', 'return $t["_content"];'), $photo['tags']['tag']); … … 135 136 } 136 137 } 137 138 return sprintf(l10n('Photo "%s" imported'), $photo['title']);138 139 return l10n('Photo "%s" imported', $photo['title']); 139 140 } 140 141 ?>
Note: See TracChangeset
for help on using the changeset viewer.