Changeset 16071
- Timestamp:
- Jun 27, 2012, 1:53:21 AM (12 years ago)
- Location:
- extensions/flickr2piwigo
- Files:
-
- 1 added
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
extensions/flickr2piwigo/admin/config.php
r16063 r16071 7 7 'api_key' => trim($_POST['api_key']), 8 8 'secret_key' => trim($_POST['secret_key']), 9 'username' => trim($_POST['username']),10 9 ); 11 10 unset($_SESSION['phpFlickr_auth_token']); … … 14 13 15 14 16 $template->assign('flickr2piwigo', $conf['flickr2piwigo']);17 18 15 $template->assign(array( 16 'flickr2piwigo' => $conf['flickr2piwigo'], 19 17 'FLICKR_HELP_CONTENT' => load_language('help_api_key.html', FLICKR_PATH, array('return'=>true)), 20 'FLICKR_CALLBACK' => get_absolute_root_url() .FLICKR_ADMIN.'-import',18 'FLICKR_CALLBACK' => get_absolute_root_url() . FLICKR_ADMIN . '-import', 21 19 )); 22 20 23 21 24 $template->set_filename('flickr2piwigo', dirname(__FILE__).'/template/config.tpl'); 25 22 $template->set_filename('flickr2piwigo', dirname(__FILE__) . '/template/config.tpl'); 26 23 27 24 ?> -
extensions/flickr2piwigo/admin/import.php
r16070 r16071 3 3 4 4 // check API parameters and connect to flickr 5 if ( empty($conf['flickr2piwigo']['api_key']) or empty($conf['flickr2piwigo']['secret_key']) or empty($conf['flickr2piwigo']['username']))5 if ( empty($conf['flickr2piwigo']['api_key']) or empty($conf['flickr2piwigo']['secret_key']) ) 6 6 { 7 7 array_push($page['warnings'], l10n('Please fill your API keys on the configuration tab')); … … 16 16 17 17 // must authenticate 18 if (empty($_SESSION['phpFlickr_auth_token']) and @$_GET['action']!='login') 18 $u = $flickr->test_login(); 19 if ( ($u === false or empty($_SESSION['phpFlickr_auth_token'])) and @$_GET['action']!='login' ) 19 20 { 20 21 $_GET['action'] = 'init_login'; 21 22 } 22 else23 {24 // get user id25 $u = $flickr->people_findByUsername($conf['flickr2piwigo']['username']);26 if ($u === false)27 {28 array_push($page['errors'], l10n('Unknown username, please verify your configuration'));29 $_GET['action'] = 'error';30 }31 }32 33 23 34 24 // generate token after authentication … … 48 38 case 'init_login': 49 39 { 50 $template->assign('flickr_login', FLICKR_ADMIN .'-import&action=login');40 $template->assign('flickr_login', FLICKR_ADMIN . '-import&action=login'); 51 41 break; 52 42 } … … 63 53 { 64 54 $_SESSION['page_infos'][] = l10n('Successfully logued to you Flickr account'); 65 redirect(FLICKR_ADMIN .'-import');55 redirect(FLICKR_ADMIN . '-import'); 66 56 break; 67 57 } … … 72 62 unset($_SESSION['phpFlickr_auth_token']); 73 63 $_SESSION['page_infos'][] = l10n('Logued out'); 74 redirect(FLICKR_ADMIN .'-import');64 redirect(FLICKR_ADMIN . '-import'); 75 65 break; 76 66 } … … 81 71 $u = $flickr->people_getInfo($u['id']); 82 72 $template->assign(array( 83 'username' => $ conf['flickr2piwigo']['username'],84 'profile_url' => $u['p hotosurl'],85 'logout_url' => FLICKR_ADMIN .'-import&action=logout',86 'list_albums_url' => FLICKR_ADMIN .'-import&action=list_albums',87 'import_all_url' => FLICKR_ADMIN .'-import&action=list_all',73 'username' => $u['username'], 74 'profile_url' => $u['profileurl'], 75 'logout_url' => FLICKR_ADMIN . '-import&action=logout', 76 'list_albums_url' => FLICKR_ADMIN . '-import&action=list_albums', 77 'import_all_url' => FLICKR_ADMIN . '-import&action=list_all', 88 78 )); 89 79 break; … … 100 90 foreach ($albums as &$album) 101 91 { 102 //$album['U_IMPORT_ALL'] = FLICKR_ADMIN.'-import&action=import_album&album='.$album['id']; 103 $album['U_LIST'] = FLICKR_ADMIN.'-import&action=list_photos&album='.$album['id']; 92 $album['U_LIST'] = FLICKR_ADMIN . '-import&action=list_photos&album='.$album['id']; 104 93 } 105 94 unset($album); … … 114 103 'description' => null, 115 104 'photos' => $wo_albums['photos']['total'], 116 //'U_IMPORT_ALL' => FLICKR_ADMIN.'-import&action=import_album&album='.$album['id'], 117 'U_LIST' => FLICKR_ADMIN.'-import&action=list_photos&album=not_in_set', 105 'U_LIST' => FLICKR_ADMIN . '-import&action=list_photos&album=not_in_set', 118 106 )); 119 107 } … … 129 117 case 'list_photos': 130 118 { 119 $self_url = FLICKR_ADMIN . '-import&action=list_photos&album='.$_GET['album']; 120 $flickr_prefix = 'flickr-'.$u['username'].'-'; 121 $flickr_root_url = $flickr->urls_getUserPhotos($u['id']); 122 123 // pagination 131 124 if (isset($_GET['start'])) $page['start'] = intval($_GET['start']); 132 125 else $page['start'] = 0; … … 134 127 else $page['display'] = 20; 135 128 136 $self_url = FLICKR_ADMIN.'-import&action=list_photos&album='.$_GET['album']; 137 $flickr_prefix = 'flickr-'.$conf['flickr2piwigo']['username'].'-'; 138 $flickr_root_url = $flickr->urls_getUserPhotos($u['id']); 129 // get photos 130 if ($_GET['album'] == 'not_in_set') 131 { 132 $all_photos = $flickr->photos_getNotInSet(NULL, NULL, NULL, NULL, 'photos', NULL, NULL, 500); 133 $all_photos = $all_photos['photos']['photo']; 134 } 135 else 136 { 137 $all_photos = $flickr->photosets_getPhotos($_GET['album'], NULL, NULL, 500, NULL, 'photos'); 138 $all_photos = $all_photos['photoset']['photo']; 139 } 139 140 140 141 // get existing photos … … 147 148 $existing_photos = array_map(create_function('$p', '$p=preg_replace("#^'.$flickr_prefix.'([0-9]+)\.([a-z]{3,4})$#i", "$1", $p); return $p;'), $existing_photos); 148 149 149 // get photos 150 if ($_GET['album'] == 'not_in_set') 151 { 152 $all_photos = $flickr->photos_getNotInSet(NULL, NULL, NULL, NULL, 'photos', NULL, NULL, 500); 153 $all_photos = $all_photos['photos']['photo']; 154 } 155 else 156 { 157 $all_photos = $flickr->photosets_getPhotos($_GET['album'], NULL, NULL, 500, NULL, 'photos'); 158 $all_photos = $all_photos['photoset']['photo']; 159 } 160 161 // remove existing 150 // remove existing photos 162 151 $duplicates = 0; 163 152 foreach ($all_photos as $i => $photo) … … 169 158 } 170 159 } 160 171 161 if ($duplicates>0) 172 162 { … … 214 204 break; 215 205 } 216 206 207 // list all photos of the user 217 208 case 'list_all': 218 209 { 219 $flickr_prefix = 'flickr-'.$ conf['flickr2piwigo']['username'].'-';210 $flickr_prefix = 'flickr-'.$u['username'].'-'; 220 211 221 212 // get all photos in all albums … … 246 237 $existing_photos = array_map(create_function('$p', '$p=preg_replace("#^'.$flickr_prefix.'([0-9]+)\.([a-z]{3,4})$#i", "$1", $p); return $p;'), $existing_photos); 247 238 248 // remove duplicates239 // remove existing photos 249 240 $duplicates = 0; 250 241 foreach ($all_photos as $id => &$photo) … … 264 255 } 265 256 unset($photo); 257 $all_photos = array_values($all_photos); 258 266 259 if ($duplicates>0) 267 260 { 268 261 array_push($page['infos'], l10n_dec('%d picture is not displayed because already existing in the database.', '%d pictures are not displayed because already existing in the database.', $duplicates)); 269 262 } 270 $all_photos = array_values($all_photos);271 263 272 264 $template->assign(array( 273 265 'nb_elements' => count($all_photos), 274 266 'all_elements' => json_encode($all_photos), 275 'F_ACTION' => FLICKR_ADMIN .'-import&action=import_set',267 'F_ACTION' => FLICKR_ADMIN . '-import&action=import_set', 276 268 )); 277 269 … … 293 285 $_SESSION['page_infos'][] = sprintf(l10n('%d pictures imported'), $_POST['done']); 294 286 } 295 redirect(FLICKR_ADMIN .'-import');287 redirect(FLICKR_ADMIN . '-import'); 296 288 } 297 289 } 298 290 291 299 292 $template->assign('ACTION', $_GET['action']); 300 293 301 $template->set_filename('flickr2piwigo', dirname(__FILE__) .'/template/import.tpl');294 $template->set_filename('flickr2piwigo', dirname(__FILE__) . '/template/import.tpl'); 302 295 303 296 ?> -
extensions/flickr2piwigo/admin/template/config.tpl
r16063 r16071 23 23 </label> 24 24 </li> 25 26 <li>27 <label>28 <span class="property">{'Username'|@translate}</span>29 <input type="text" name="username" value="{$flickr2piwigo.username}" size="20"></label>30 </label>31 </li>32 25 </ul> 33 26 </fieldset> -
extensions/flickr2piwigo/admin/template/import.list_photos.tpl
r16063 r16071 330 330 /* pagination loader */ 331 331 jQuery('#navigation a').click(function() { 332 $("#loader_display").fadeIn() 332 $("#loader_display").fadeIn(); 333 333 }); 334 334 }); -
extensions/flickr2piwigo/admin/template/import.tpl
r16064 r16071 5 5 </div> 6 6 7 {* <!-- LOGIN --> *} 7 8 {if $ACTION == 'init_login'} 8 9 <p><input type="submit" onClick="javascript:window.location.href ='{$flickr_login}';" value="{'Login'|@translate}"></p> 9 10 11 {* <!-- MAIN MENU --> *} 10 12 {elseif $ACTION == 'main'} 13 {footer_script}{literal} 14 jQuery('input[type="submit"]').click(function() { 15 window.location.href = $(this).attr("data"); 16 }); 17 jQuery('.load').click(function() { 18 $("#loader_import").fadeIn(); 19 }); 20 {/literal}{/footer_script} 21 11 22 <p> 12 23 <b>{'Logued as'|@translate}</b> : <a href="{$profile_url}" target="_blank">{$username}</a><br><br> 13 <input type="submit" onClick="javascript:window.location.href ='{$logout_url}';" value="{'Logout'|@translate}">24 <input type="submit" data="{$logout_url}" value="{'Logout'|@translate}"> 14 25 </p> 15 26 <br> 16 27 <p> 17 <input type="submit" onClick="javascript:window.location.href ='{$list_albums_url}';" value="{'List my albums'|@translate}"> 18 <input type="submit" onClick="javascript:window.location.href ='{$import_all_url}';" value="{'Import all my pictures'|@translate}"> 28 <input type="submit" data="{$list_albums_url}" class="load" value="{'List my albums'|@translate}"> 29 <input type="submit" data="{$import_all_url}" class="load" value="{'Import all my pictures'|@translate}"> 30 <br> 31 <span id="loader_import" style="display:none;"><img src="admin/themes/default/images/ajax-loader.gif"> <i>{'Processing...'|@translate}</i></span> 19 32 </p> 20 33 34 {* <!-- ALBUMS LIST --> *} 21 35 {elseif $ACTION == 'list_albums'} 36 {footer_script}{literal} 37 jQuery('.load').click(function() { 38 $("#loader_import").fadeIn(); 39 }); 40 {/literal}{/footer_script} 41 22 42 <h3>{'%d albums'|@translate|@sprintf:$total_albums}</h3> 23 43 <ul id="albumsList"> 24 44 {foreach from=$albums item=album} 25 45 <li {if $album.id == "not_in_set"}class="not_in_set"{/if}> 26 <b><a href="{$album.U_LIST}" >{$album.title}</a></b> <i>{'(%d photos)'|@translate|@sprintf:$album.photos}</i> {if $album.description}- {$album.description|@truncate:100}{/if}27 { *- <a href="{$album.U_IMPORT_ALL}">{'Import all pictures of this album'|@translate}</a>*}46 <b><a href="{$album.U_LIST}" class="load">{$album.title}</a></b> <i>{'(%d photos)'|@translate|@sprintf:$album.photos}</i> 47 {if $album.description}- {$album.description|@truncate:100}{/if} 28 48 </li> 29 49 {/foreach} 30 50 </ul> 51 <span id="loader_import" style="display:none;"><img src="admin/themes/default/images/ajax-loader.gif"> <i>{'Processing...'|@translate}</i></span> 31 52 53 {* <!-- PHOTOS LIST --> *} 32 54 {elseif $ACTION == 'list_photos'} 33 55 {include file=$FLICKR_ABS_PATH|@cat:'admin/template/import.list_photos.tpl'} 34 56 57 {* <!-- IMPORT ALL --> *} 35 58 {elseif $ACTION == 'list_all'} 36 59 {include file=$FLICKR_ABS_PATH|@cat:'admin/template/import.list_all.tpl'} -
extensions/flickr2piwigo/language/en_UK/help_api_key.html
r16063 r16071 8 8 <li>Click <b>Edit auth flow for this app</b></li> 9 9 <li>Enter a desciption again, past in <b>Callback URL</b> the above URL and click <b>Save changes</b></li> 10 <li>Don't forget to write your exact username in Flickr2Piwigo configuration</li>11 10 <li>You're done!</li> 12 11 </ol> -
extensions/flickr2piwigo/language/en_UK/plugin.lang.php
r16063 r16071 25 25 $lang['(%d photos)'] = '(%d photos)'; 26 26 $lang['%d albums'] = '%d albums'; 27 //$lang['Import all pictures of this album'] = 'Import all pictures of this album';28 27 $lang['List pictures of this album'] = 'List pictures of this album'; 29 28 $lang['Begin transfert'] = 'Begin transfert'; -
extensions/flickr2piwigo/language/fr_FR/help_api_key.html
r16063 r16071 8 8 <li>Cliquez sur <b>Modifier le flux d'authentification</b></li> 9 9 <li>Entrer à nouveau une description, collez dans <b>URL de rappel</b> l'URL ci-dessus et cliquez sur <b>Save changes</b></li> 10 <li>N'oubliez pas de renseigner votre nom d'utilisateur exact dans la configuration de Flickr2Piwigo</li>11 10 <li>Terminé!</li> 12 11 </ol> -
extensions/flickr2piwigo/language/fr_FR/plugin.lang.php
r16063 r16071 25 25 $lang['(%d photos)'] = '(%d photos)'; 26 26 $lang['%d albums'] = '%d albums'; 27 //$lang['Import all pictures of this album'] = 'Importer toutes les photos de cet album';28 27 $lang['List pictures of this album'] = 'Lister les photos de cet album'; 29 28 $lang['Begin transfert'] = 'Commencer les transfert'; -
extensions/flickr2piwigo/main.inc.php
r16063 r16071 17 17 define('FLICKR_FS_CACHE', $conf['data_location'].'flickr_cache/'); 18 18 19 add_event_handler('get_admin_plugin_menu_links', 'flickr2_admin_menu');20 19 21 function flickr2_admin_menu($menu) 20 add_event_handler('get_admin_plugin_menu_links', 'flickr_admin_menu'); 21 22 function flickr_admin_menu($menu) 22 23 { 23 24 array_push($menu, array( … … 28 29 } 29 30 30 add_event_handler('ws_add_methods', 'flickr2_add_ws_method');31 31 32 function flickr2_add_ws_method($arr) 33 { 34 $service = &$arr[0]; 35 36 $service->addMethod( 37 'pwg.images.addFlickr', 38 'ws_images_addFlickr', 39 array( 40 'category' => array('default' => null), 41 'id' => array('default' => null), 42 'fills' => array('default' =>null), 43 ), 44 'Used by Flickr2Piwigo, fills (fill_name,fill_posted,fill_taken,fill_author,fill_tags)' 45 ); 46 } 32 include_once(FLICKR_PATH . 'include/ws_functions.inc.php'); 47 33 48 function ws_images_addFlickr($photo, &$service) 49 { 50 global $conf; 51 52 if (!is_admin()) 53 { 54 return new PwgError(403, 'Forbidden'); 55 } 56 57 $conf['flickr2piwigo'] = unserialize($conf['flickr2piwigo']); 58 59 if (empty($conf['flickr2piwigo']['api_key']) or empty($conf['flickr2piwigo']['secret_key']) or empty($conf['flickr2piwigo']['username'])) 60 { 61 return new PwgError(500, l10n('Please fill your API keys on the configuration tab')); 62 } 63 64 if (empty($_SESSION['phpFlickr_auth_token'])) 65 { 66 return new PwgError(403, l10n('API not authenticated')); 67 } 68 69 // category 70 if (!preg_match('#^[0-9]+$#', $photo['category'])) 71 { 72 $categories_names = explode(',', $photo['category']); 73 74 $photo['category'] = array(); 75 foreach ($categories_names as $category_name) 76 { 77 $query = ' 78 SELECT id FROM '.CATEGORIES_TABLE.' 79 WHERE LOWER(name) = "'.strtolower($category_name).'" 80 ;'; 81 $result = pwg_query($query); 82 83 if (pwg_db_num_rows($result)) 84 { 85 list($cat_id) = pwg_db_fetch_row($result); 86 array_push($photo['category'], $cat_id); 87 } 88 else 89 { 90 include_once(PHPWG_ROOT_PATH . 'admin/include/functions.php'); 91 $cat = create_virtual_category($category_name); 92 array_push($photo['category'], $cat_id['id']); 93 } 94 } 95 } 96 else 97 { 98 $photo['category'] = array($photo['category']); 99 } 100 101 // init flickr API 102 include_once(FLICKR_PATH . 'include/phpFlickr/phpFlickr.php'); 103 $flickr = new phpFlickr($conf['flickr2piwigo']['api_key'], $conf['flickr2piwigo']['secret_key']); 104 $flickr->enableCache('fs', FLICKR_FS_CACHE); 105 106 // photos infos 107 $photo_f = $flickr->photos_getInfo($photo['id']); 108 $photo = array_merge($photo, $photo_f['photo']); 109 $photo['url'] = $flickr->get_biggest_size($photo['id'], 'original'); 110 $photo['path'] = FLICKR_FS_CACHE . 'flickr-'.$conf['flickr2piwigo']['username'].'-'.$photo['id'].'.'.get_extension($photo['url']); 111 112 // copy file 113 $file = fopen($photo['url'], "rb"); 114 $newf = fopen($photo['path'], "wb"); 115 while (!feof($file)) 116 { 117 fwrite($newf, fread($file, 1024 * 8 ), 1024 * 8 ); 118 } 119 fclose($file); 120 fclose($newf); 121 122 // add to database 123 include_once(PHPWG_ROOT_PATH . 'admin/include/functions_upload.inc.php'); 124 $photo['image_id'] = add_uploaded_file($photo['path'], basename($photo['path']), $photo['category']); 125 126 // do some updates 127 if (!empty($photo['fills'])) 128 { 129 $photo['fills'] = rtrim($photo['fills'], ','); 130 $photo['fills'] = explode(',', $photo['fills']); 131 132 $updates = array(); 133 if (in_array('fill_name', $photo['fills'])) $updates['name'] = $photo['title']; 134 if (in_array('fill_posted', $photo['fills'])) $updates['date_available'] = date('Y-d-m H:i:s', $photo['dates']['posted']); 135 if (in_array('fill_taken', $photo['fills'])) $updates['date_creation'] = $photo['dates']['taken']; 136 if (in_array('fill_author', $photo['fills'])) $updates['author'] = $conf['flickr2piwigo']['username']; 137 138 if (count($updates)) 139 { 140 single_update( 141 IMAGES_TABLE, 142 $updates, 143 array('id' => $photo['image_id']) 144 ); 145 } 146 147 if ( !empty($photo['tags']['tag']) and in_array('fill_tags', $photo['fills']) ) 148 { 149 $raw_tags = array_map(create_function('$t', 'return $t["_content"];'), $photo['tags']['tag']); 150 $raw_tags = implode(',', $raw_tags); 151 set_tags(get_tag_ids($raw_tags), $photo['image_id']); 152 } 153 } 154 155 return sprintf(l10n('%s imported'), $photo['title']); 156 } 34 add_event_handler('ws_add_methods', 'flickr_add_ws_method'); 157 35 158 36 ?> -
extensions/flickr2piwigo/maintain.inc.php
r16070 r16071 7 7 'api_key' => null, 8 8 'secret_key' => null, 9 'username' => null,10 9 )) 11 10 ); 12 11 13 12 14 13 function plugin_install() 15 14 { 16 15 global $conf; 16 17 17 conf_update_param('flickr2piwigo', flickr2piwigo_default_config); 18 18 19 mkdir($conf['data_location'].'flickr_cache/', 0755); 19 20 } … … 30 31 if (!file_exists($conf['data_location'].'flickr_cache/')) 31 32 { 32 m dir($conf['data_location'].'flickr_cache/', 0755);33 mkdir($conf['data_location'].'flickr_cache/', 0755); 33 34 } 34 35 } … … 37 38 { 38 39 pwg_query('DELETE FROM `'. CONFIG_TABLE .'` WHERE param = "flickr2piwigo" LIMIT 1;'); 40 41 rrmdir($conf['data_location'].'flickr_cache/'); 39 42 } 40 43 44 function rrmdir($dir) 45 { 46 if (!is_dir($dir)) 47 { 48 return false; 49 } 50 $dir = rtrim($dir, '/'); 51 $objects = scandir($dir); 52 $return = true; 53 54 foreach ($objects as $object) 55 { 56 if ($object !== '.' && $object !== '..') 57 { 58 $path = $dir.'/'.$object; 59 if (filetype($path) == 'dir') 60 { 61 $return = $return && rrmdir($path); 62 } 63 else 64 { 65 $return = $return && @unlink($path); 66 } 67 } 68 } 69 70 return $return && @rmdir($dir); 71 } 72 41 73 ?>
Note: See TracChangeset
for help on using the changeset viewer.