Changeset 26180
- Timestamp:
- Dec 24, 2013, 6:23:13 PM (10 years ago)
- Location:
- extensions/flickr2piwigo
- Files:
-
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
extensions/flickr2piwigo/admin.php
r16070 r26180 1 1 <?php 2 if (!defined('FLICKR_PATH'))die('Hacking attempt!');2 defined('FLICKR_PATH') or die('Hacking attempt!'); 3 3 4 4 global $template, $page, $conf; 5 5 6 $conf['flickr2piwigo'] = unserialize($conf['flickr2piwigo']);7 6 load_language('plugin.lang', FLICKR_PATH); 8 7 … … 15 14 include_once(PHPWG_ROOT_PATH.'admin/include/tabsheet.class.php'); 16 15 $page['tab'] = (isset($_GET['tab'])) ? $_GET['tab'] : $page['tab'] = 'import'; 17 16 18 17 $tabsheet = new tabsheet(); 19 18 $tabsheet->add('import', l10n('Import'), FLICKR_ADMIN . '-import'); … … 31 30 'FLICKR_ADMIN' => FLICKR_ADMIN, 32 31 )); 32 33 33 $template->assign_var_from_handle('ADMIN_CONTENT', 'flickr2piwigo'); 34 35 ?> -
extensions/flickr2piwigo/admin/config.php
r24815 r26180 1 1 <?php 2 if (!defined('FLICKR_PATH'))die('Hacking attempt!');2 defined('FLICKR_PATH') or die('Hacking attempt!'); 3 3 4 4 if (isset($_POST['save_config'])) … … 21 21 22 22 23 $template->set_filename('flickr2piwigo', dirname(__FILE__) . '/template/config.tpl'); 24 25 ?> 23 $template->set_filename('flickr2piwigo', realpath(FLICKR_PATH . 'admin/template/config.tpl')); -
extensions/flickr2piwigo/admin/import.php
r25789 r26180 1 1 <?php 2 if (!defined('FLICKR_PATH'))die('Hacking attempt!');2 defined('FLICKR_PATH') or die('Hacking attempt!'); 3 3 4 4 set_time_limit(600); … … 7 7 8 8 // check API parameters and connect to flickr 9 if ( empty($conf['flickr2piwigo']['api_key']) or empty($conf['flickr2piwigo']['secret_key']))10 { 11 array_push($page['warnings'], l10n('Please fill your API keys on the configuration tab'));9 if (empty($conf['flickr2piwigo']['api_key']) or empty($conf['flickr2piwigo']['secret_key'])) 10 { 11 $page['warnings'][] = l10n('Please fill your API keys on the configuration tab'); 12 12 $_GET['action'] = 'error'; 13 13 } 14 else if ( !test_remote_download())15 { 16 array_push($page['errors'], l10n('No download method available'));14 else if (!test_remote_download()) 15 { 16 $page['errors'][] = l10n('No download method available'); 17 17 $_GET['action'] = 'error'; 18 18 } … … 23 23 $flickr = new phpFlickr($conf['flickr2piwigo']['api_key'], $conf['flickr2piwigo']['secret_key']); 24 24 $flickr->enableCache('fs', FLICKR_FS_CACHE); 25 25 26 26 // must authenticate 27 27 $u = $flickr->test_login(); … … 30 30 $_GET['action'] = 'init_login'; 31 31 } 32 32 33 33 // generate token after authentication 34 34 if (!empty($_GET['frob'])) 35 35 { 36 36 $flickr->auth_getToken($_GET['frob']); 37 $_GET['action'] = 'logued'; 38 } 39 } 40 41 42 if (!isset($_GET['action'])) $_GET['action'] = 'main'; 37 $_GET['action'] = 'logged'; 38 } 39 } 40 41 42 if (!isset($_GET['action'])) 43 { 44 $_GET['action'] = 'main'; 45 } 43 46 44 47 … … 51 54 break; 52 55 } 53 56 54 57 // call flickr login procedure 55 58 case 'login': … … 58 61 break; 59 62 } 60 63 61 64 // message after login 62 case 'log ued':65 case 'logged': 63 66 { 64 67 $_SESSION['page_infos'][] = l10n('Successfully logged in to you Flickr account'); … … 66 69 break; 67 70 } 68 71 69 72 // logout 70 73 case 'logout': … … 75 78 break; 76 79 } 77 80 78 81 // main menu 79 82 case 'main': … … 89 92 break; 90 93 } 91 94 92 95 // list user albums 93 96 case 'list_albums': … … 97 100 $total_albums = $albums['total']; 98 101 $albums = $albums['photoset']; 99 102 100 103 foreach ($albums as &$album) 101 104 { … … 103 106 } 104 107 unset($album); 105 108 106 109 // not classed 107 110 $wo_albums = $flickr->photos_getNotInSet(NULL, NULL, NULL, NULL, 'photos', NULL, NULL, 1); 108 111 if ($wo_albums['photos']['total'] > 0) 109 112 { 110 array_push($albums,array(113 $albums[] = array( 111 114 'id' => 'not_in_set', 112 115 'title' => l10n('Pictures without album'), … … 114 117 'photos' => $wo_albums['photos']['total'], 115 118 'U_LIST' => FLICKR_ADMIN . '-import&action=list_photos&album=not_in_set', 116 ) );117 } 118 119 ); 120 } 121 119 122 $template->assign(array( 120 123 'total_albums' => $total_albums, … … 123 126 break; 124 127 } 125 128 126 129 // list photos of an album 127 130 case 'list_photos': … … 130 133 $flickr_prefix = 'flickr-'.$u['username'].'-'; 131 134 $flickr_root_url = $flickr->urls_getUserPhotos($u['id']); 132 135 133 136 // pagination 134 137 if (isset($_GET['start'])) $page['start'] = intval($_GET['start']); … … 136 139 if (isset($_GET['display'])) $page['display'] = $_GET['display']=='all' ? 500 : intval($_GET['display']); 137 140 else $page['display'] = 20; 138 141 139 142 // get photos 140 143 if ($_GET['album'] == 'not_in_set') … … 148 151 $all_photos = $all_photos['photoset']['photo']; 149 152 } 150 153 151 154 // get existing photos 152 155 $query = ' … … 157 160 $existing_photos = simple_hash_from_query($query, 'id', 'file'); 158 161 $existing_photos = array_map(create_function('$p', 'return preg_replace("#^'.$flickr_prefix.'([0-9]+)\.([a-z]{3,4})$#i", "$1", $p);'), $existing_photos); 159 162 160 163 // remove existing photos 161 164 $duplicates = 0; … … 168 171 } 169 172 } 170 173 171 174 if ($duplicates>0) 172 175 { 173 $page['infos'][] = '<a href="admin.php?page=batch_manager&prefilter=flickr">' 174 .l10n_dec('One picture is not displayed because already existing in the database.', '%d pictures are not displayed because already existing in the database.', $duplicates) 176 $page['infos'][] = '<a href="admin.php?page=batch_manager&filter=prefilter-flickr">' 177 .l10n_dec( 178 'One picture is not displayed because already existing in the database.', 179 '%d pictures are not displayed because already existing in the database.', 180 $duplicates) 175 181 .'</a>'; 176 182 } 177 183 178 184 // displayed photos 179 185 $page_photos = array_slice($all_photos, $page['start'], $page['display']); 180 186 $all_elements = array_map(create_function('$p', 'return \'"\'.$p["id"].\'"\';'), $all_photos); 181 187 182 188 foreach ($page_photos as &$photo) 183 189 { … … 187 193 } 188 194 unset($photo); 189 195 190 196 $template->assign(array( 191 197 'nb_thumbs_set' => count($all_photos), … … 197 203 'U_DISPLAY' => $self_url, 198 204 )); 199 205 200 206 // get piwigo categories 201 207 $query = ' … … 204 210 ;'; 205 211 display_select_cat_wrapper($query, array(), 'category_parent_options'); 206 212 207 213 // get navbar 208 214 $nav_bar = create_navigation_bar( … … 215 221 break; 216 222 } 217 223 218 224 // list all photos of the user 219 225 case 'list_all': 220 226 { 221 227 $flickr_prefix = 'flickr-'.$u['username'].'-'; 222 228 223 229 // get all photos in all albums 224 230 $all_albums = $flickr->photosets_getList($u['id']); 225 231 $all_albums = $all_albums['photoset']; 226 232 227 233 $all_photos = array(); 228 234 foreach ($all_albums as $album) … … 230 236 $album_photos = $flickr->photosets_getPhotos($album['id'], NULL, NULL, 500, NULL, 'photos'); 231 237 $album_photos = $album_photos['photoset']['photo']; 232 238 233 239 foreach ($album_photos as $photo) 234 240 { … … 236 242 } 237 243 } 238 244 239 245 // get existing photos 240 246 $query = ' … … 245 251 $existing_photos = simple_hash_from_query($query, 'id', 'file'); 246 252 $existing_photos = array_map(create_function('$p', 'return preg_replace("#^'.$flickr_prefix.'([0-9]+)\.([a-z]{3,4})$#i", "$1", $p);'), $existing_photos); 247 253 248 254 // remove existing photos 249 255 $duplicates = 0; … … 265 271 unset($photo); 266 272 $all_photos = array_values($all_photos); 267 273 268 274 if ($duplicates>0) 269 275 { 270 $page['infos'][] = '<a href="admin.php?page=batch_manager&prefilter=flickr">' 271 .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) 276 $page['infos'][] = '<a href="admin.php?page=batch_manager&filter=prefilter-flickr">' 277 .l10n_dec( 278 'One picture is not displayed because already existing in the database.', 279 '%d pictures are not displayed because already existing in the database.', 280 $duplicates) 272 281 .'</a>'; 273 282 } 274 283 275 284 $template->assign(array( 276 285 'nb_elements' => count($all_photos), 277 'all_elements' => json_encode($all_photos),286 'all_elements' => $all_photos, 278 287 'F_ACTION' => FLICKR_ADMIN . '-import&action=import_set', 279 288 )); 280 289 281 290 // get piwigo categories 282 291 $query = ' … … 287 296 break; 288 297 } 289 298 290 299 // success message after import 291 300 case 'import_set': … … 293 302 if (isset($_POST['done'])) 294 303 { 295 $_SESSION['page_infos'][] = sprintf(l10n('%d pictures imported'), $_POST['done']);304 $_SESSION['page_infos'][] = l10n('%d pictures imported', $_POST['done']); 296 305 } 297 306 redirect(FLICKR_ADMIN . '-import'); … … 300 309 301 310 302 $template->assign(array( 303 'ACTION' => $_GET['action'], 304 'GMAPS_LOADED' => !empty($pwg_loaded_plugins['rv_gmaps']) || !empty($pwg_loaded_plugins['piwigo-openstreetmap']), 305 )); 306 307 $template->set_filename('flickr2piwigo', dirname(__FILE__) . '/template/import.tpl'); 308 309 ?> 311 $template->assign('ACTION', $_GET['action']); 312 313 $template->set_filename('flickr2piwigo', realpath(FLICKR_PATH . 'admin/template/import.tpl')); -
extensions/flickr2piwigo/admin/template/config.tpl
r16071 r26180 1 {combine_css path=$FLICKR_PATH| @cat:"admin/template/style.css"}1 {combine_css path=$FLICKR_PATH|cat:'admin/template/style.css'} 2 2 3 3 <div class="titrePage"> … … 7 7 <form method="post" action="" class="properties"> 8 8 <fieldset> 9 <legend>{'Flickr logins'| @translate}</legend>10 9 <legend>{'Flickr logins'|translate}</legend> 10 11 11 <ul> 12 12 <li> 13 13 <label> 14 <span class="property">{'API key'| @translate}</span>14 <span class="property">{'API key'|translate}</span> 15 15 <input type="text" name="api_key" value="{$flickr2piwigo.api_key}" size="40"> 16 16 </label> … … 19 19 <li> 20 20 <label> 21 <span class="property">{'API secret'| @translate}</span>21 <span class="property">{'API secret'|translate}</span> 22 22 <input type="text" name="secret_key" value="{$flickr2piwigo.secret_key}" size="20"> 23 23 </label> … … 26 26 </fieldset> 27 27 28 <p><input type="submit" name="save_config" value="{'Save Settings'| @translate}"></p>28 <p><input type="submit" name="save_config" value="{'Save Settings'|translate}"></p> 29 29 30 30 <fieldset> 31 <legend>{'How do I get my Flickr API key?'| @translate}</legend>32 33 <p><b>{'Callback URL'| @translate} :</b> <span style="font-family:monospace;font-size:14px;">{$FLICKR_CALLBACK}</span></p>31 <legend>{'How do I get my Flickr API key?'|translate}</legend> 32 33 <p><b>{'Callback URL'|translate} :</b> <span style="font-family:monospace;font-size:14px;">{$FLICKR_CALLBACK}</span></p> 34 34 {$FLICKR_HELP_CONTENT} 35 35 </fieldset> 36 36 37 37 </form> -
extensions/flickr2piwigo/admin/template/import.list_all.tpl
r25789 r26180 1 1 {footer_script require='jquery.ajaxmanager,jquery.jgrowl'} 2 /* global vars */ 3 var errorHead = '{'ERROR'|@translate|@escape:'javascript'}'; 4 var errorMsg = '{'an error happened'|@translate|@escape:'javascript'}'; 5 var successHead = '{'Success'|@translate|@escape:'javascript'}'; 2 (function($){ 3 /* global vars */ 4 var all_elements = [{if !empty($all_elements)}{','|@implode:$all_elements}{/if}]; 5 var import_done = 0; 6 var import_selected = {$nb_elements}; 7 var queuedManager = $.manageAjax.create('queued', { 8 queue: true, 9 maxRequests: 1 10 }); 6 11 7 var import_done = 0; 8 var import_selected = {$nb_elements}; 9 var queuedManager = jQuery.manageAjax.create('queued', {ldelim} 10 queue: true, 11 maxRequests: 1 12 }); 12 /* import queue */ 13 function performImport(photo, album, fills) { 14 queuedManager.add({ 15 type: 'GET', 16 dataType: 'json', 17 url: 'ws.php', 18 data: { 19 method: 'pwg.images.addFlickr', 20 id: photo, 21 category: album, 22 fills: fills, 23 format: 'json' 24 }, 25 success: function(data) { 26 if (data['stat'] == 'ok') { 27 $.jGrowl(data['result'], { 28 theme: 'success', life: 4000, sticky: false, 29 header: '{'Success'|translate}', 30 }); 31 $("#photo-"+photo.id).fadeOut(function(){ $(this).remove(); }); 32 } 33 else { 34 $.jGrowl(data['result'], { 35 theme: 'error', sticky: true, 36 header: '{'ERROR'|translate}' 37 }); 38 } 13 39 14 {literal} 15 /* import queue */ 16 function performImport(photo, album, fills) { 17 queuedManager.add({ 18 type: 'GET', 19 dataType: 'json', 20 url: 'ws.php', 21 data: { method: 'pwg.images.addFlickr', id: photo, category: album, fills: fills, format: 'json' }, 22 success: function(data) { 23 if (data['stat'] == 'ok') { 24 jQuery.jGrowl(data['result'], { theme: 'success', header: successHead, life: 4000, sticky: false }); 25 jQuery("#photo-"+photo.id).fadeOut(function(){ $(this).remove(); }); 26 } else { 27 jQuery.jGrowl(data['result'], { theme: 'error', header: errorHead, sticky: true }); 40 import_done++; 41 $("#progress").html(import_done +"/"+ import_selected); 42 43 if (import_done == import_selected) { 44 $("#import_form").append('<input type="hidden" name="done" value="' + import_done + '">'); 45 $("#import_form").submit(); 46 } 47 }, 48 error: function(data) { 49 $.jGrowl('{'an error happened'|translate|escape:'javascript'}', { 50 theme: 'error', sticky: true, 51 header: '{'ERROR'|translate}' 52 }); 28 53 } 29 30 import_done++; 31 $("#progress").html(import_done +"/"+ import_selected); 32 33 if (import_done == import_selected) { 34 $("#import_form").append('<input type="hidden" name="done" value="' + import_done + '">'); 35 $("#import_form").submit(); 36 } 37 }, 38 error: function(data) { 39 jQuery.jGrowl(errorMsg, { theme: 'error', header: errorHead, sticky: true }); 40 } 41 }); 42 } 54 }); 55 } 43 56 57 /* begin import */ 58 $('#beginImport').click(function() { 59 $("#loader_import").fadeIn(); 44 60 45 $(document).ready(function() {46 //var all_elements = jQuery.parseJSON('{/literal}{$all_elements}{literal}');47 var all_elements = {/literal}{$all_elements}{literal};48 49 /* begin import */50 jQuery('#beginImport').click(function() {51 $("#loader_import").fadeIn();52 53 61 if ($("input[name='album_mode']:checked").val() == 'identical') { 54 62 var album = 0; 55 } else { 63 } 64 else { 56 65 var album = $("#albumSelect option:selected").val(); 57 66 } 58 67 59 68 var fills = ''; 60 69 $("input[name^='fill_']:checked").each(function() { 61 70 fills+= $(this).attr("name") +','; 62 }); 63 71 }); 72 64 73 import_selected = all_elements.length; 65 74 $("#progress").html("0/"+ import_selected); 66 75 67 76 for (var i in all_elements) { 68 77 if (album == 0) this_album = all_elements[i]['albums']; 69 78 else this_album = album; 70 79 71 80 performImport(all_elements[i]['id'], this_album, fills); 72 81 } 73 82 74 83 return false; 75 84 }); 76 85 77 86 /* album mode */ 78 87 $("input[name='album_mode']").change(function() { 79 88 if ($(this).val() == 'one_album') { 80 89 $("#albumSelectWrapper").slideDown(); 81 } else { 90 } 91 else { 82 92 $("#albumSelectWrapper").slideUp(); 83 93 } 84 94 }); 85 }); 86 {/literal} 95 }(jQuery)); 87 96 {/footer_script} 97 88 98 89 99 <form action="{$F_ACTION}" method="post" id="import_form"> 90 100 91 101 <fieldset> 92 <legend>{'Selection'| @translate}</legend>102 <legend>{'Selection'|translate}</legend> 93 103 94 104 {if $nb_elements} 95 {'%d elements ready for importation'| @translate|@sprintf:$nb_elements}105 {'%d elements ready for importation'|translate:$nb_elements} 96 106 {else} 97 <div>{'No photo in the current set.'| @translate}</div>107 <div>{'No photo in the current set.'|translate}</div> 98 108 {/if} 99 109 </fieldset> 100 110 101 111 <fieldset> 102 <legend>{'Import options'| @translate}</legend>103 112 <legend>{'Import options'|translate}</legend> 113 104 114 <p> 105 <label><input type="radio" name="album_mode" value="identical" checked="checked"> {'Reproduce flickr albums'| @translate}</label><br>106 <label><input type="radio" name="album_mode" value="one_album"> {'Import all photos in this album'| @translate} :</label>115 <label><input type="radio" name="album_mode" value="identical" checked="checked"> {'Reproduce flickr albums'|translate}</label><br> 116 <label><input type="radio" name="album_mode" value="one_album"> {'Import all photos in this album'|translate} :</label> 107 117 </p> 108 118 … … 111 121 {html_options options=$category_parent_options} 112 122 </select> 113 {'... or '| @translate}<a href="#" class="addAlbumOpen" title="{'create a new album'|@translate}">{'create a new album'|@translate}</a>123 {'... or '|translate}<a href="#" class="addAlbumOpen" title="{'create a new album'|translate}">{'create a new album'|translate}</a> 114 124 </p> 115 125 116 126 <p> 117 <b>{'Fill these fields from Flickr datas'| @translate}:</b>118 <label><input type="checkbox" name="fill_name" checked="checked"> {'Photo name'| @translate}</label>119 <label><input type="checkbox" name="fill_author" checked="checked"> {'Author'| @translate}</label>120 <label><input type="checkbox" name="fill_tags" checked="checked"> {'Tags'| @translate}</label>121 <label><input type="checkbox" name="fill_taken" checked="checked"> {'Creation date'| @translate}</label>122 <label><input type="checkbox" name="fill_posted"> {'Post date'| @translate}</label>127 <b>{'Fill these fields from Flickr datas'|translate}:</b> 128 <label><input type="checkbox" name="fill_name" checked="checked"> {'Photo name'|translate}</label> 129 <label><input type="checkbox" name="fill_author" checked="checked"> {'Author'|translate}</label> 130 <label><input type="checkbox" name="fill_tags" checked="checked"> {'Tags'|translate}</label> 131 <label><input type="checkbox" name="fill_taken" checked="checked"> {'Creation date'|translate}</label> 132 <label><input type="checkbox" name="fill_posted"> {'Post date'|translate}</label> 123 133 <label><input type="checkbox" name="fill_description" checked="checked"> {'Description'|@translate}</label> 124 {if $GMAPS_LOADED}<label><input type="checkbox" name="fill_geotag" checked="checked"> {'Geolocalization'|@translate}</label>{/if}134 <label><input type="checkbox" name="fill_geotag" checked="checked"> {'Geolocalization'|@translate}</label> 125 135 </p> 126 136 127 137 <p> 128 <input type="submit" name="import_set" id="beginImport" value="{'Begin transfer'| @translate}" {if not $nb_elements}style="display:none;"{/if}>129 <span id="loader_import" style="display:none;"><img src="admin/themes/default/images/ajax-loader.gif"> <i>{'Processing...'| @translate}</i> <span id="progress"></span></span>138 <input type="submit" name="import_set" id="beginImport" value="{'Begin transfer'|translate}" {if not $nb_elements}style="display:none;"{/if}> 139 <span id="loader_import" style="display:none;"><img src="admin/themes/default/images/ajax-loader.gif"> <i>{'Processing...'|translate}</i> <span id="progress"></span></span> 130 140 </p> 131 141 </fieldset> -
extensions/flickr2piwigo/admin/template/import.list_photos.tpl
r25789 r26180 1 1 {footer_script require='jquery.ajaxmanager,jquery.jgrowl'} 2 /* global vars */ 3 var nb_thumbs_page = {$nb_thumbs_page}; 4 var nb_thumbs_set = {$nb_thumbs_set}; 5 var all_elements = [{if !empty($all_elements)}{','|@implode:$all_elements}{/if}]; 6 7 var errorHead = '{'ERROR'|@translate|@escape:'javascript'}'; 8 var errorMsg = '{'an error happened'|@translate|@escape:'javascript'}'; 9 var successHead = '{'Success'|@translate|@escape:'javascript'}'; 10 var selectedMessage_pattern = "{'%d of %d photos selected'|@translate}"; 11 var selectedMessage_none = "{'No photo selected, %d photos in current set'|@translate}"; 12 var selectedMessage_all = "{'All %d photos are selected'|@translate}"; 13 var applyOnDetails_pattern = "{'on the %d selected photos'|@translate}"; 14 15 var import_done = 0; 16 var import_selected = 0; 17 var queuedManager = jQuery.manageAjax.create('queued', {ldelim} 18 queue: true, 19 maxRequests: 1 20 }); 21 22 {literal} 23 /* Shift-click: select all photos between the click and the shift+click */ 24 jQuery(document).ready(function() { 2 (function($){ 3 /* global vars */ 4 var nb_thumbs_set = {$nb_thumbs_set}; 5 var all_elements = [{if !empty($all_elements)}{','|@implode:$all_elements}{/if}]; 6 var import_done = 0; 7 var import_selected = 0; 8 var queuedManager = $.manageAjax.create('queued', {ldelim} 9 queue: true, 10 maxRequests: 1 11 }); 12 13 /* Shift-click: select all photos between the click and the shift+click */ 25 14 var last_clicked=0; 26 15 var last_clickedstatus=true; 27 jQuery.fn.enableShiftClick = function() {16 $.fn.enableShiftClick = function() { 28 17 var inputs = []; 29 18 var count=0; … … 44 33 input = $(inputs[i]); 45 34 $(input).attr('checked', last_clickedstatus); 46 if (last_clickedstatus) 47 { 35 if (last_clickedstatus) { 48 36 $(input).siblings("span.wrap2").addClass("thumbSelected"); 49 37 } 50 else 51 { 38 else { 52 39 $(input).siblings("span.wrap2").removeClass("thumbSelected"); 53 40 } … … 60 47 return true; 61 48 }); 62 $(this).click(function(event) { $(this).triggerHandler("shclick",event)});49 $(this).click(function(event) { $(this).triggerHandler("shclick",event); }); 63 50 }); 64 51 } 65 }); 66 67 /* sprintf */ 68 function str_repeat(i, m) { 69 for (var o = []; m > 0; o[--m] = i); 70 return o.join(''); 71 } 72 73 function sprintf() { 74 var i = 0, a, f = arguments[i++], o = [], m, p, c, x, s = ''; 75 while (f) { 76 if (m = /^[^\x25]+/.exec(f)) { 77 o.push(m[0]); 78 } 79 else if (m = /^\x25{2}/.exec(f)) { 80 o.push('%'); 81 } 82 else if (m = /^\x25(?:(\d+)\$)?(\+)?(0|'[^$])?(-)?(\d+)?(?:\.(\d+))?([b-fosuxX])/.exec(f)) { 83 if (((a = arguments[m[1] || i++]) == null) || (a == undefined)) { 84 throw('Too few arguments.'); 85 } 86 if (/[^s]/.test(m[7]) && (typeof(a) != 'number')) { 87 throw('Expecting number but found ' + typeof(a)); 88 } 89 switch (m[7]) { 90 case 'b': a = a.toString(2); break; 91 case 'c': a = String.fromCharCode(a); break; 92 case 'd': a = parseInt(a); break; 93 case 'e': a = m[6] ? a.toExponential(m[6]) : a.toExponential(); break; 94 case 'f': a = m[6] ? parseFloat(a).toFixed(m[6]) : parseFloat(a); break; 95 case 'o': a = a.toString(8); break; 96 case 's': a = ((a = String(a)) && m[6] ? a.substring(0, m[6]) : a); break; 97 case 'u': a = Math.abs(a); break; 98 case 'x': a = a.toString(16); break; 99 case 'X': a = a.toString(16).toUpperCase(); break; 100 } 101 a = (/[def]/.test(m[7]) && m[2] && a >= 0 ? '+'+ a : a); 102 c = m[3] ? m[3] == '0' ? '0' : m[3].charAt(1) : ' '; 103 x = m[5] - String(a).length - s.length; 104 p = m[5] ? str_repeat(c, x) : ''; 105 o.push(s + (m[4] ? a + p : p + a)); 106 } 107 else { 108 throw('Huh ?!'); 109 } 110 f = f.substring(m[0].length); 111 } 112 return o.join(''); 113 } 114 115 /* update displaying */ 116 function checkPermitAction() { 117 var nbSelected = 0; 118 if ($("input[name=setSelected]").is(':checked')) { 119 nbSelected = nb_thumbs_set; 120 } else { 121 $(".thumbnails input[type=checkbox]").each(function() { 122 if ($(this).is(':checked')) nbSelected++; 123 }); 124 } 125 126 if (nbSelected == 0) { 127 $("#beginImport").hide(); 128 } else { 129 $("#beginImport").show(); 130 } 131 132 $("#applyOnDetails").text( 133 sprintf( 134 applyOnDetails_pattern, 135 nbSelected 136 ) 137 ); 138 139 // display the number of currently selected photos in the "Selection" fieldset 140 if (nbSelected == 0) { 141 $("#selectedMessage").text( 52 53 /* update displaying */ 54 function checkPermitAction() { 55 var nbSelected = 0; 56 if ($("input[name=setSelected]").is(':checked')) { 57 nbSelected = nb_thumbs_set; 58 } 59 else { 60 $(".thumbnails input[type=checkbox]").each(function() { 61 if ($(this).is(':checked')) nbSelected++; 62 }); 63 } 64 65 if (nbSelected == 0) { 66 $("#beginImport").hide(); 67 } 68 else { 69 $("#beginImport").show(); 70 } 71 72 $("#applyOnDetails").text( 142 73 sprintf( 143 selectedMessage_none,144 nb _thumbs_set74 '{'on the %d selected photos'|translate|escape:javascript}', 75 nbSelected 145 76 ) 146 77 ); 147 } else if (nbSelected == nb_thumbs_set) { 148 $("#selectedMessage").text( 149 sprintf( 150 selectedMessage_all, 151 nb_thumbs_set 152 ) 153 ); 154 } else { 155 $("#selectedMessage").text( 156 sprintf( 157 selectedMessage_pattern, 158 nbSelected, 159 nb_thumbs_set 160 ) 161 ); 78 79 // display the number of currently selected photos in the "Selection" fieldset 80 if (nbSelected == 0) { 81 $("#selectedMessage").text( 82 sprintf( 83 '{'No photo selected, %d photos in current set'|translate|escape:javascript}', 84 nb_thumbs_set 85 ) 86 ); 87 } 88 else if (nbSelected == nb_thumbs_set) { 89 $("#selectedMessage").text( 90 sprintf( 91 '{'All %d photos are selected'|translate|escape:javascript}', 92 nb_thumbs_set 93 ) 94 ); 95 } 96 else { 97 $("#selectedMessage").text( 98 sprintf( 99 '{'%d of %d photos selected'|translate|escape:javascript}', 100 nbSelected, 101 nb_thumbs_set 102 ) 103 ); 104 } 162 105 } 163 } 164 165 /* import queue */ 166 function performImport(photo, album, fills) { 167 queuedManager.add({ 168 type: 'GET', 169 dataType: 'json', 170 url: 'ws.php', 171 data: { method: 'pwg.images.addFlickr', id: photo, category: album, fills: fills, format: 'json' }, 172 success: function(data) { 173 if (data['stat'] == 'ok') { 174 jQuery.jGrowl(data['result'], { theme: 'success', header: successHead, life: 4000, sticky: false }); 175 jQuery("#photo-"+photo).fadeOut(function(){ $(this).remove(); }); 176 } else { 177 jQuery.jGrowl(data['result'], { theme: 'error', header: errorHead, sticky: true }); 106 107 /* import queue */ 108 function performImport(photo, album, fills) { 109 queuedManager.add({ 110 type: 'GET', 111 dataType: 'json', 112 url: 'ws.php', 113 data: { 114 method: 'pwg.images.addFlickr', 115 id: photo, 116 category: album, 117 fills: fills, 118 format: 'json' 119 }, 120 success: function(data) { 121 if (data['stat'] == 'ok') { 122 jQuery.jGrowl(data['result'], { 123 theme: 'success', life: 4000, sticky: false, 124 header: '{'Success'|translate}' 125 }); 126 jQuery("#photo-"+photo).fadeOut(function(){ $(this).remove(); }); 127 } 128 else { 129 jQuery.jGrowl(data['result'], { 130 theme: 'error', sticky: true, 131 header: '{'ERROR'|translate}' 132 }); 133 } 134 135 import_done++; 136 $("#progress").html(import_done +"/"+ import_selected); 137 138 if (import_done == import_selected) { 139 $("#import_form").append('<input type="hidden" name="done" value="' + import_done + '">'); 140 $("#import_form").submit(); 141 } 142 }, 143 error: function(data) { 144 jQuery.jGrowl('{'an error happened'|translate|@escape:'javascript'}', { 145 theme: 'error', sticky: true, 146 header: '{'ERROR'|translate}' 147 }); 178 148 } 179 180 import_done++; 181 $("#progress").html(import_done +"/"+ import_selected); 182 183 if (import_done == import_selected) { 184 $("#import_form").append('<input type="hidden" name="done" value="' + import_done + '">'); 185 $("#import_form").submit(); 186 } 187 }, 188 error: function(data) { 189 jQuery.jGrowl(errorMsg, { theme: 'error', header: errorHead, sticky: true }); 190 } 191 }); 192 } 193 194 195 $(document).ready(function() { 149 }); 150 } 151 152 196 153 checkPermitAction(); 197 154 $("a.preview-box").colorbox(); … … 206 163 207 164 /* thumbnail click */ 208 $(".wrap1 label").click(function 209 $("input[name=setSelected]"). attr('checked', false);165 $(".wrap1 label").click(function(event) { 166 $("input[name=setSelected]").prop('checked', false); 210 167 211 168 var wrap2 = $(this).children(".wrap2"); … … 215 172 216 173 if ($(checkbox).is(':checked')) { 217 $(wrap2).addClass("thumbSelected"); 218 } 219 else { 220 $(wrap2).removeClass('thumbSelected'); 174 $(wrap2).addClass("thumbSelected"); 175 } 176 else { 177 $(wrap2).removeClass('thumbSelected'); 221 178 } 222 179 … … 225 182 226 183 /* select all */ 227 $("#selectAll").click(function 228 $("input[name=setSelected]"). attr('checked', false);229 184 $("#selectAll").click(function() { 185 $("input[name=setSelected]").prop('checked', false); 186 230 187 $(".thumbnails label").each(function() { 231 188 var wrap2 = $(this).children(".wrap2"); 232 189 var checkbox = $(this).children("input[type=checkbox]"); 233 190 234 $(checkbox). attr('checked', true);235 $(wrap2).addClass("thumbSelected"); 236 }); 237 191 $(checkbox).prop('checked', true); 192 $(wrap2).addClass("thumbSelected"); 193 }); 194 238 195 checkPermitAction(); 239 196 return false; … … 241 198 242 199 /* select none */ 243 $("#selectNone").click(function 244 $("input[name=setSelected]"). attr('checked', false);245 200 $("#selectNone").click(function() { 201 $("input[name=setSelected]").prop('checked', false); 202 246 203 $(".thumbnails label").each(function() { 247 204 var wrap2 = $(this).children(".wrap2"); 248 205 var checkbox = $(this).children("input[type=checkbox]"); 249 206 250 $(checkbox). attr('checked', false);251 $(wrap2).removeClass("thumbSelected"); 252 }); 253 207 $(checkbox).prop('checked', false); 208 $(wrap2).removeClass("thumbSelected"); 209 }); 210 254 211 checkPermitAction(); 255 212 return false; … … 257 214 258 215 /* select invert */ 259 $("#selectInvert").click(function 260 $("input[name=setSelected]"). attr('checked', false);261 216 $("#selectInvert").click(function() { 217 $("input[name=setSelected]").prop('checked', false); 218 262 219 $(".thumbnails label").each(function() { 263 220 var wrap2 = $(this).children(".wrap2"); 264 221 var checkbox = $(this).children("input[type=checkbox]"); 265 222 266 $(checkbox). attr('checked', !$(checkbox).is(':checked'));223 $(checkbox).prop('checked', !$(checkbox).is(':checked')); 267 224 268 225 if ($(checkbox).is(':checked')) { 269 $(wrap2).addClass("thumbSelected"); 270 } else { 271 $(wrap2).removeClass('thumbSelected'); 226 $(wrap2).addClass("thumbSelected"); 272 227 } 273 }); 274 275 checkPermitAction(); 276 return false; 277 }); 278 228 else { 229 $(wrap2).removeClass('thumbSelected'); 230 } 231 }); 232 233 checkPermitAction(); 234 return false; 235 }); 236 279 237 /* select set */ 280 $("#selectSet").click(function 281 $("input[name=setSelected]"). attr('checked', true);282 238 $("#selectSet").click(function() { 239 $("input[name=setSelected]").prop('checked', true); 240 283 241 $(".thumbnails label").each(function() { 284 242 var wrap2 = $(this).children(".wrap2"); 285 243 var checkbox = $(this).children("input[type=checkbox]"); 286 244 287 $(checkbox). attr('checked', true);288 $(wrap2).addClass("thumbSelected"); 289 }); 290 291 checkPermitAction(); 292 return false; 293 }); 294 245 $(checkbox).prop('checked', true); 246 $(wrap2).addClass("thumbSelected"); 247 }); 248 249 checkPermitAction(); 250 return false; 251 }); 252 295 253 /* begin import */ 296 254 jQuery('#beginImport').click(function() { 297 255 $("#loader_import").fadeIn(); 298 256 var album = $("#albumSelect option:selected").val(); 299 257 300 258 var fills = ''; 301 259 $("input[name^='fill_']:checked").each(function() { 302 260 fills+= $(this).attr("name") +','; 303 }); 304 261 }); 262 305 263 if (jQuery('input[name="setSelected"]').attr('checked')) { 306 264 import_selected = all_elements.length; 307 265 $("#progress").html("0/"+ import_selected); 308 266 309 267 for (var i in all_elements) { 310 268 performImport(all_elements[i], album, fills); 311 269 } 312 } else { 270 } 271 else { 313 272 import_selected = $("input[name='selection[]']:checked").length; 314 273 $("#progress").html("0/"+ import_selected); 315 274 316 275 jQuery("input[name='selection[]']:checked").each(function() { 317 276 performImport(jQuery(this).attr('value'), album, fills); 318 277 }); 319 278 } 320 321 return false; 322 }); 323 279 280 return false; 281 }); 282 324 283 /* pagination loader */ 325 284 jQuery('#navigation a').click(function() { 326 285 $("#loader_display").fadeIn(); 327 286 }); 328 }); 329 {/literal} 287 }(jQuery)); 330 288 {/footer_script} 289 331 290 332 291 <div id="batchManagerGlobal"> … … 334 293 335 294 <fieldset> 336 <legend>{'Selection'| @translate}</legend>295 <legend>{'Selection'|translate}</legend> 337 296 338 297 {if !empty($thumbnails)} 339 298 <p id="checkActions"> 340 {'Select:'| @translate}299 {'Select:'|translate} 341 300 {if $nb_thumbs_set > $nb_thumbs_page} 342 <a href="#" id="selectAll">{'The whole page'| @translate}</a>,343 <a href="#" id="selectSet">{'The whole set'| @translate}</a>,301 <a href="#" id="selectAll">{'The whole page'|translate}</a>, 302 <a href="#" id="selectSet">{'The whole set'|translate}</a>, 344 303 {else} 345 <a href="#" id="selectAll">{'All'| @translate}</a>,304 <a href="#" id="selectAll">{'All'|translate}</a>, 346 305 {/if} 347 <a href="#" id="selectNone">{'None'| @translate}</a>,348 <a href="#" id="selectInvert">{'Invert'| @translate}</a>306 <a href="#" id="selectNone">{'None'|translate}</a>, 307 <a href="#" id="selectInvert">{'Invert'|translate}</a> 349 308 350 309 <span id="selectedMessage"></span> 351 310 <input type="checkbox" name="setSelected" style="display:none"> 352 <span id="loader_display" style="display:none;"><img src="admin/themes/default/images/ajax-loader.gif"> <i>{'Processing...'| @translate}</i></span>311 <span id="loader_display" style="display:none;"><img src="admin/themes/default/images/ajax-loader.gif"> <i>{'Processing...'|translate}</i></span> 353 312 </p> 354 313 … … 359 318 <label> 360 319 <span class="wrap2"> 361 <div class="actions"><a href="{$thumbnail.src}" class="preview-box">{'Zoom'| @translate}</a> · <a href="{$thumbnail.url}" target="_blank" title="{'Open Flickr page in a new tab'|@translate}">Flickr</a></div>320 <div class="actions"><a href="{$thumbnail.src}" class="preview-box">{'Zoom'|translate}</a> · <a href="{$thumbnail.url}" target="_blank" title="{'Open Flickr page in a new tab'|translate}">Flickr</a></div> 362 321 <span> 363 <img src="{$thumbnail.thumb}" alt="{$thumbnail.title}" title="{$thumbnail.title| @escape:'html'}" class="thumbnail">322 <img src="{$thumbnail.thumb}" alt="{$thumbnail.title}" title="{$thumbnail.title|escape:'html'}" class="thumbnail"> 364 323 </span> 365 324 </span> … … 370 329 {/foreach} 371 330 </ul> 372 373 331 332 374 333 <div style="clear:both;" id="navigation"> 375 334 {if !empty($navbar) } 376 335 <div style="float:left"> 377 {include file='navigation_bar.tpl'| @get_extent:'navbar'}336 {include file='navigation_bar.tpl'|get_extent:'navbar'} 378 337 </div> 379 338 {/if} 380 381 <div style="float:right;margin-top:10px;">{'display'| @translate}339 340 <div style="float:right;margin-top:10px;">{'display'|translate} 382 341 <a href="{$U_DISPLAY}&display=20">20</a> 383 342 · <a href="{$U_DISPLAY}&display=50">50</a> 384 343 · <a href="{$U_DISPLAY}&display=100">100</a> 385 · <a href="{$U_DISPLAY}&display=all">{'all'| @translate}</a>386 {'photos per page'| @translate}344 · <a href="{$U_DISPLAY}&display=all">{'all'|translate}</a> 345 {'photos per page'|translate} 387 346 </div> 388 347 </div> 389 348 390 349 {else} 391 <div>{'No photo in the current set.'| @translate}</div>350 <div>{'No photo in the current set.'|translate}</div> 392 351 {/if} 393 352 </fieldset> 394 353 395 354 <fieldset> 396 <legend>{'Import options'| @translate}</legend>355 <legend>{'Import options'|translate}</legend> 397 356 398 357 <p> 399 <label for="albumSelect"><b>{'Album'| @translate}:</b></label>358 <label for="albumSelect"><b>{'Album'|translate}:</b></label> 400 359 <select style="width:400px" name="associate" id="albumSelect" size="1"> 401 360 {html_options options=$category_parent_options} 402 361 </select> 403 {'... or '| @translate}<a href="#" class="addAlbumOpen" title="{'create a new album'|@translate}">{'create a new album'|@translate}</a>362 {'... or '|translate}<a href="#" class="addAlbumOpen" title="{'create a new album'|translate}">{'create a new album'|translate}</a> 404 363 </p> 405 364 406 365 <p> 407 <b>{'Fill these fields from Flickr datas'| @translate}:</b>408 <label><input type="checkbox" name="fill_name" checked="checked"> {'Photo name'| @translate}</label>409 <label><input type="checkbox" name="fill_author" checked="checked"> {'Author'| @translate}</label>410 <label><input type="checkbox" name="fill_tags" checked="checked"> {'Tags'| @translate}</label>411 <label><input type="checkbox" name="fill_taken" checked="checked"> {'Creation date'| @translate}</label>412 <label><input type="checkbox" name="fill_posted"> {'Post date'| @translate}</label>366 <b>{'Fill these fields from Flickr datas'|translate}:</b> 367 <label><input type="checkbox" name="fill_name" checked="checked"> {'Photo name'|translate}</label> 368 <label><input type="checkbox" name="fill_author" checked="checked"> {'Author'|translate}</label> 369 <label><input type="checkbox" name="fill_tags" checked="checked"> {'Tags'|translate}</label> 370 <label><input type="checkbox" name="fill_taken" checked="checked"> {'Creation date'|translate}</label> 371 <label><input type="checkbox" name="fill_posted"> {'Post date'|translate}</label> 413 372 <label><input type="checkbox" name="fill_description" checked="checked"> {'Description'|@translate}</label> 414 {if $GMAPS_LOADED}<label><input type="checkbox" name="fill_geotag" checked="checked"> {'Geolocalization'|@translate}</label>{/if}373 <label><input type="checkbox" name="fill_geotag" checked="checked"> {'Geolocalization'|@translate}</label> 415 374 </p> 416 375 417 376 <p> 418 377 <input type="hidden" name="album" value="{$album}"> 419 <input type="submit" name="import_set" id="beginImport" value="{'Begin transfer'| @translate}" style="display:none;">420 <span id="loader_import" style="display:none;"><img src="admin/themes/default/images/ajax-loader.gif"> <i>{'Processing...'| @translate}</i> <span id="progress"></span></span>378 <input type="submit" name="import_set" id="beginImport" value="{'Begin transfer'|translate}" style="display:none;"> 379 <span id="loader_import" style="display:none;"><img src="admin/themes/default/images/ajax-loader.gif"> <i>{'Processing...'|translate}</i> <span id="progress"></span></span> 421 380 </p> 422 381 </fieldset> -
extensions/flickr2piwigo/admin/template/import.tpl
r25789 r26180 1 {combine_css path=$FLICKR_PATH| @cat:"admin/template/style.css"}1 {combine_css path=$FLICKR_PATH|cat:'admin/template/style.css'} 2 2 3 3 {include file='include/colorbox.inc.tpl'} 4 4 {include file='include/add_album.inc.tpl'} 5 {combine_script id='common' load='footer' path='admin/themes/default/js/common.js'} 5 6 {combine_script id='jquery.ajaxmanager' load='footer' path='themes/default/js/plugins/jquery.ajaxmanager.js'} 6 7 {combine_script id='jquery.jgrowl' load='footer' require='jquery' path='themes/default/js/plugins/jquery.jgrowl_minimized.js'} … … 13 14 {* <!-- LOGIN --> *} 14 15 {if $ACTION == 'init_login'} 15 <p><input type="submit" on Click="javascript:window.location.href ='{$flickr_login}';" value="{'Login'|@translate}"></p>16 <p><input type="submit" onclick="javascript:window.location.href ='{$flickr_login}';" value="{'Login'|translate}"></p> 16 17 17 18 {* <!-- MAIN MENU --> *} 18 {elseif $ACTION == 'main'} 19 {footer_script}{literal} 19 {else if $ACTION == 'main'} 20 21 {footer_script} 20 22 jQuery('input[type="submit"]').click(function() { 21 23 window.location.href = $(this).attr("data"); … … 24 26 $("#loader_import").fadeIn(); 25 27 }); 26 {/ literal}{/footer_script}28 {/footer_script} 27 29 28 30 <p> 29 <b>{'Logged in as'| @translate}</b> : <a href="{$profile_url}" target="_blank">{$username}</a><br><br>30 <input type="submit" data="{$logout_url}" value="{'Logout'| @translate}">31 <b>{'Logged in as'|translate}</b> : <a href="{$profile_url}" target="_blank">{$username}</a><br><br> 32 <input type="submit" data="{$logout_url}" value="{'Logout'|translate}"> 31 33 </p> 32 34 <br> 33 35 <p> 34 <input type="submit" data="{$list_albums_url}" class="load" value="{'List my albums'| @translate}">35 <input type="submit" data="{$import_all_url}" class="load" value="{'Import all my pictures'| @translate}">36 <input type="submit" data="{$list_albums_url}" class="load" value="{'List my albums'|translate}"> 37 <input type="submit" data="{$import_all_url}" class="load" value="{'Import all my pictures'|translate}"> 36 38 <br> 37 <span id="loader_import" style="display:none;"><img src="admin/themes/default/images/ajax-loader.gif"> <i>{'Processing...'| @translate}</i></span>39 <span id="loader_import" style="display:none;"><img src="admin/themes/default/images/ajax-loader.gif"> <i>{'Processing...'|translate}</i></span> 38 40 </p> 39 41 40 42 {* <!-- ALBUMS LIST --> *} 41 {elseif $ACTION == 'list_albums'} 42 {footer_script}{literal} 43 {else if $ACTION == 'list_albums'} 44 45 {footer_script} 43 46 jQuery('.load').click(function() { 44 47 $("#loader_import").fadeIn(); 45 48 }); 46 {/ literal}{/footer_script}49 {/footer_script} 47 50 48 <h3>{'%d albums'| @translate|@sprintf:$total_albums}</h3>51 <h3>{'%d albums'|translate:$total_albums}</h3> 49 52 <ul id="albumsList"> 50 53 {foreach from=$albums item=album} 51 54 <li {if $album.id == "not_in_set"}class="not_in_set"{/if}> 52 <b><a href="{$album.U_LIST}" class="load">{$album.title}</a></b> <i>{'(%d photos)'| @translate|@sprintf:$album.photos}</i>53 {if $album.description}- {$album.description| @truncate:100}{/if}55 <b><a href="{$album.U_LIST}" class="load">{$album.title}</a></b> <i>{'(%d photos)'|translate:$album.photos}</i> 56 {if $album.description}- {$album.description|truncate:100}{/if} 54 57 </li> 55 58 {/foreach} 56 59 </ul> 57 <span id="loader_import" style="display:none;"><img src="admin/themes/default/images/ajax-loader.gif"> <i>{'Processing...'| @translate}</i></span>60 <span id="loader_import" style="display:none;"><img src="admin/themes/default/images/ajax-loader.gif"> <i>{'Processing...'|translate}</i></span> 58 61 59 62 {* <!-- PHOTOS LIST --> *} 60 {else if $ACTION == 'list_photos'}61 {include file=$FLICKR_ABS_PATH| @cat:'admin/template/import.list_photos.tpl'}63 {else if $ACTION == 'list_photos'} 64 {include file=$FLICKR_ABS_PATH|cat:'admin/template/import.list_photos.tpl'} 62 65 63 66 {* <!-- IMPORT ALL --> *} 64 {else if $ACTION == 'list_all'}65 {include file=$FLICKR_ABS_PATH| @cat:'admin/template/import.list_all.tpl'}67 {else if $ACTION == 'list_all'} 68 {include file=$FLICKR_ABS_PATH|cat:'admin/template/import.list_all.tpl'} 66 69 67 70 {/if} -
extensions/flickr2piwigo/include/functions.inc.php
r21288 r26180 1 1 <?php 2 if (!defined('FLICKR_PATH'))die('Hacking attempt!');2 defined('FLICKR_PATH') or die('Hacking attempt!'); 3 3 4 4 /** … … 30 30 return false; 31 31 } 32 32 33 33 $return = ($dest === true) ? true : false; 34 34 35 35 /* curl */ 36 36 if (function_exists('curl_init')) … … 41 41 } 42 42 $ch = curl_init(); 43 43 44 44 curl_setopt($ch, CURLOPT_URL, $src); 45 45 curl_setopt($ch, CURLOPT_HEADER, false); … … 65 65 curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 66 66 } 67 67 68 68 $out = curl_exec($ch); 69 69 curl_close($ch); 70 70 71 71 if ($out === false) 72 72 { … … 90 90 return false; 91 91 } 92 92 93 93 $opts = array( 94 94 'http' => array( … … 100 100 101 101 $context = stream_context_create($opts); 102 102 103 103 if (($file = file_get_contents($src, false, $context)) === false) 104 104 { 105 105 return 'file_error'; 106 106 } 107 107 108 108 if (!$return) 109 109 { … … 116 116 } 117 117 } 118 118 119 119 return false; 120 120 } 121 121 } 122 123 ?> -
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 ?> -
extensions/flickr2piwigo/main.inc.php
r24815 r26180 1 <?php 1 <?php 2 2 /* 3 3 Plugin Name: Flickr2Piwigo … … 9 9 */ 10 10 11 if (!defined('PHPWG_ROOT_PATH'))die('Hacking attempt!');11 defined('PHPWG_ROOT_PATH') or die('Hacking attempt!'); 12 12 13 13 global $conf; 14 14 15 define('FLICKR_PATH', PHPWG_PLUGINS_PATH . basename(dirname(__FILE__)) . '/'); 16 define('FLICKR_ADMIN', get_root_url() . 'admin.php?page=plugin-' . basename(dirname(__FILE__))); 15 define('FLICKR_ID', basename(dirname(__FILE__))); 16 define('FLICKR_PATH', PHPWG_PLUGINS_PATH . FLICKR_ID . '/'); 17 define('FLICKR_ADMIN', get_root_url() . 'admin.php?page=plugin-' . FLICKR_ID); 17 18 define('FLICKR_FS_CACHE', PHPWG_ROOT_PATH . $conf['data_location'] . 'flickr_cache/'); 19 define('FLICKR_VERSION', 'auto'); 18 20 21 22 include_once(FLICKR_PATH . 'include/ws_functions.inc.php'); 23 24 25 add_event_handler('init', 'flickr_init'); 26 add_event_handler('ws_add_methods', 'flickr_add_ws_method'); 19 27 20 28 if (defined('IN_ADMIN')) 21 29 { 22 30 add_event_handler('get_admin_plugin_menu_links', 'flickr_admin_menu'); 31 23 32 add_event_handler('get_batch_manager_prefilters', 'flickr_add_batch_manager_prefilters'); 24 33 add_event_handler('perform_batch_manager_prefilters', 'flickr_perform_batch_manager_prefilters', EVENT_HANDLER_PRIORITY_NEUTRAL, 2); 25 add_event_handler('loc_begin_admin_page', 'flickr_prefilter_from_url');26 34 27 function flickr_admin_menu($menu) 35 function flickr_admin_menu($menu) 28 36 { 29 array_push($menu,array(37 $menu[] = array( 30 38 'NAME' => 'Flickr2Piwigo', 31 39 'URL' => FLICKR_ADMIN, 32 ));40 ); 33 41 return $menu; 34 42 } 35 43 36 44 function flickr_add_batch_manager_prefilters($prefilters) 37 45 { 38 array_push($prefilters,array(46 $prefilters[] = array( 39 47 'ID' => 'flickr', 40 48 'NAME' => l10n('Imported from Flickr'), 41 ));49 ); 42 50 return $prefilters; 43 51 } … … 54 62 $filter_sets[] = array_from_query($query, 'id'); 55 63 } 56 64 57 65 return $filter_sets; 58 }59 60 function flickr_prefilter_from_url()61 {62 global $page;63 if ($page['page'] == 'batch_manager' && @$_GET['prefilter'] == 'flickr')64 {65 $_SESSION['bulk_manager_filter'] = array('prefilter' => 'flickr');66 unset($_GET['prefilter']);67 }68 66 } 69 67 } 70 68 71 69 72 include_once(FLICKR_PATH . 'include/ws_functions.inc.php'); 70 function flickr_init() 71 { 72 global $conf; 73 include_once(FLICKR_PATH . 'maintain.inc.php'); 74 $maintain = new flickr2piwigo_maintain(FLICKR_ID); 75 $maintain->autoUpdate(FLICKR_VERSION, 'install'); 73 76 74 add_event_handler('ws_add_methods', 'flickr_add_ws_method'); 75 76 ?> 77 $conf['flickr2piwigo'] = unserialize($conf['flickr2piwigo']); 78 } -
extensions/flickr2piwigo/maintain.inc.php
r24815 r26180 1 1 <?php 2 if (!defined('PHPWG_ROOT_PATH'))die('Hacking attempt!');2 defined('PHPWG_ROOT_PATH') or die('Hacking attempt!'); 3 3 4 define( 5 'flickr2piwigo_default_config', 6 serialize(array( 4 class flickr2piwigo_maintain extends PluginMaintain 5 { 6 private $installed = false; 7 8 private $default_conf = array( 7 9 'api_key' => null, 8 10 'secret_key' => null, 9 )) 10 ); 11 ); 11 12 13 function install($plugin_version, &$errors=array()) 14 { 15 global $conf; 12 16 13 function plugin_install() 14 { 15 global $conf; 16 17 conf_update_param('flickr2piwigo', flickr2piwigo_default_config); 18 19 mkgetdir(PHPWG_ROOT_PATH . $conf['data_location'] . 'flickr_cache/', MKGETDIR_DEFAULT&~MKGETDIR_DIE_ON_ERROR); 20 } 17 if (empty($conf['flickr2piwigo'])) 18 { 19 $conf['flickr2piwigo'] = serialize($this->default_conf); 20 conf_update_param('flickr2piwigo', $conf['flickr2piwigo']); 21 } 21 22 22 function plugin_activate() 23 { 24 global $conf; 23 mkgetdir(PHPWG_ROOT_PATH . $conf['data_location'] . 'flickr_cache/', MKGETDIR_DEFAULT&~MKGETDIR_DIE_ON_ERROR); 25 24 26 if (empty($conf['flickr2piwigo'])) 25 $this->installed = true; 26 } 27 28 function activate($plugin_version, &$errors=array()) 27 29 { 28 conf_update_param('flickr2piwigo', flickr2piwigo_default_config); 30 if (!$this->installed) 31 { 32 $this->install($plugin_version, $errors); 33 } 29 34 } 30 31 if (!file_exists(PHPWG_ROOT_PATH . $conf['data_location'] . 'flickr_cache/'))35 36 function deactivate() 32 37 { 33 mkgetdir(PHPWG_ROOT_PATH . $conf['data_location'] . 'flickr_cache/', MKGETDIR_DEFAULT&~MKGETDIR_DIE_ON_ERROR); 38 } 39 40 function uninstall() 41 { 42 global $conf; 43 44 conf_delete_param('flickr2piwigo'); 45 46 self::rrmdir(PHPWG_ROOT_PATH . $conf['data_location'] . 'flickr_cache/'); 47 } 48 49 static function rrmdir($dir) 50 { 51 if (!is_dir($dir)) 52 { 53 return false; 54 } 55 $dir = rtrim($dir, '/'); 56 $objects = scandir($dir); 57 $return = true; 58 59 foreach ($objects as $object) 60 { 61 if ($object !== '.' && $object !== '..') 62 { 63 $path = $dir.'/'.$object; 64 if (filetype($path) == 'dir') 65 { 66 $return = $return && self::rrmdir($path); 67 } 68 else 69 { 70 $return = $return && @unlink($path); 71 } 72 } 73 } 74 75 return $return && @rmdir($dir); 34 76 } 35 77 } 36 37 function plugin_uninstall()38 {39 global $conf;40 41 pwg_query('DELETE FROM `'. CONFIG_TABLE .'` WHERE param = "flickr2piwigo";');42 unset($conf['flickr2piwigo']);43 44 rrmdir(PHPWG_ROOT_PATH . $conf['data_location'] . 'flickr_cache/');45 }46 47 function rrmdir($dir)48 {49 if (!is_dir($dir))50 {51 return false;52 }53 $dir = rtrim($dir, '/');54 $objects = scandir($dir);55 $return = true;56 57 foreach ($objects as $object)58 {59 if ($object !== '.' && $object !== '..')60 {61 $path = $dir.'/'.$object;62 if (filetype($path) == 'dir')63 {64 $return = $return && rrmdir($path);65 }66 else67 {68 $return = $return && @unlink($path);69 }70 }71 }72 73 return $return && @rmdir($dir);74 }75 76 ?>
Note: See TracChangeset
for help on using the changeset viewer.