Ignore:
Timestamp:
Dec 24, 2013, 6:23:13 PM (10 years ago)
Author:
mistic100
Message:

update for piwigo 2.6

File:
1 edited

Legend:

Unmodified
Added
Removed
  • extensions/flickr2piwigo/include/ws_functions.inc.php

    r25790 r26180  
    11<?php
    2 if (!defined('FLICKR_PATH')) die('Hacking attempt!');
     2defined('FLICKR_PATH') or die('Hacking attempt!');
    33
    44function flickr_add_ws_method($arr)
    55{
    66  $service = &$arr[0];
    7  
     7
    88  $service->addMethod(
    99    'pwg.images.addFlickr',
     
    1414      'fills' => array('default' =>null),
    1515      ),
    16     'Used by Flickr2Piwigo'
     16    'Used by Flickr2Piwigo',
     17    null,
     18    array('hidden'=>true)
    1719    );
    1820}
     
    2426    return new PwgError(403, 'Forbidden');
    2527  }
    26  
     28
    2729  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']))
    3132  {
    3233    return new PwgError(null, l10n('Please fill your API keys on the configuration tab'));
    3334  }
    34  
     35
    3536  include_once(PHPWG_ROOT_PATH . 'admin/include/functions.php');
    3637  include_once(PHPWG_ROOT_PATH . 'admin/include/functions_upload.inc.php');
    3738  include_once(FLICKR_PATH . 'include/functions.inc.php');
    38  
     39
    3940  if (test_remote_download() === false)
    4041  {
    4142    return new PwgError(null, l10n('No download method available'));
    4243  }
    43  
     44
    4445  // init flickr API
    4546  include_once(FLICKR_PATH . 'include/phpFlickr/phpFlickr.php');
    4647  $flickr = new phpFlickr($conf['flickr2piwigo']['api_key'], $conf['flickr2piwigo']['secret_key']);
    4748  $flickr->enableCache('fs', FLICKR_FS_CACHE);
    48  
     49
    4950  // user
    5051  $u = $flickr->test_login();
    51   if ( $u === false or empty($_SESSION['phpFlickr_auth_token']) )
     52  if ($u === false or empty($_SESSION['phpFlickr_auth_token']))
    5253  {
    5354    return new PwgError(403, l10n('API not authenticated'));
    5455  }
    55  
     56
    5657  // photos infos
    5758  $photo_f = $flickr->photos_getInfo($photo['id']);
     
    5960  $photo['url'] = $flickr->get_biggest_size($photo['id'], 'original');
    6061  $photo['path'] = FLICKR_FS_CACHE . 'flickr-'.$u['username'].'-'.$photo['id'].'.'.get_extension($photo['url']);
    61  
     62
    6263  // copy file
    6364  if (download_remote_file($photo['url'], $photo['path']) == false)
     
    6566    return new PwgError(null, l10n('Can\'t download file'));
    6667  }
    67  
     68
    6869  // category
    6970  if (!preg_match('#^[0-9]+$#', $photo['category']))
    7071  {
    7172    $categories_names = explode(',', $photo['category']);
    72    
     73
    7374    $photo['category'] = array();
    7475    foreach ($categories_names as $category_name)
     
    7980;';
    8081      $result = pwg_query($query);
    81      
     82
    8283      if (pwg_db_num_rows($result))
    8384      {
    8485        list($cat_id) = pwg_db_fetch_row($result);
    85         array_push($photo['category'], $cat_id);
     86        $photo['category'][] = $cat_id;
    8687      }
    8788      else
    8889      {
    89        
     90
    9091        $cat = create_virtual_category($category_name);
    91         array_push($photo['category'], $cat['id']);
     92        $photo['category'][] = $cat['id'];
    9293      }
    9394    }
     
    9798    $photo['category'] = array($photo['category']);
    9899  }
    99  
     100
    100101  // add photo
    101102  $photo['image_id'] = add_uploaded_file($photo['path'], basename($photo['path']), $photo['category']);
    102  
     103
    103104  // do some updates
    104105  if (!empty($photo['fills']))
     
    106107    $photo['fills'] = rtrim($photo['fills'], ',');
    107108    $photo['fills'] = explode(',', $photo['fills']);
    108  
     109
    109110    $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']);
    111112    if (in_array('fill_posted', $photo['fills'])) $updates['date_available'] = date('Y-m-d H:i:s', $photo['dates']['posted']);
    112113    if (in_array('fill_taken', $photo['fills']))  $updates['date_creation'] = $photo['dates']['taken'];
     
    115116    if (in_array('fill_geotag', $photo['fills']) and !empty($photo['location']) )
    116117    {
    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']);
    119120    }
    120    
     121
    121122    if (count($updates))
    122123    {
     
    127128        );
    128129    }
    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']))
    131132    {
    132133      $raw_tags = array_map(create_function('$t', 'return $t["_content"];'), $photo['tags']['tag']);
     
    135136    }
    136137  }
    137  
    138   return sprintf(l10n('Photo "%s" imported'), $photo['title']);
     138
     139  return l10n('Photo "%s" imported', $photo['title']);
    139140}
    140 
    141 ?>
Note: See TracChangeset for help on using the changeset viewer.