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

update for piwigo 2.6

Location:
extensions/flickr2piwigo/include
Files:
2 edited

Legend:

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

    r21288 r26180  
    11<?php
    2 if (!defined('FLICKR_PATH')) die('Hacking attempt!');
     2defined('FLICKR_PATH') or die('Hacking attempt!');
    33
    44/**
     
    3030      return false;
    3131    }
    32    
     32
    3333    $return = ($dest === true) ? true : false;
    34    
     34
    3535    /* curl */
    3636    if (function_exists('curl_init'))
     
    4141      }
    4242      $ch = curl_init();
    43      
     43
    4444      curl_setopt($ch, CURLOPT_URL, $src);
    4545      curl_setopt($ch, CURLOPT_HEADER, false);
     
    6565        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    6666      }
    67      
     67
    6868      $out = curl_exec($ch);
    6969      curl_close($ch);
    70      
     70
    7171      if ($out === false)
    7272      {
     
    9090        return false;
    9191      }
    92      
     92
    9393      $opts = array(
    9494        'http' => array(
     
    100100
    101101      $context = stream_context_create($opts);
    102      
     102
    103103      if (($file = file_get_contents($src, false, $context)) === false)
    104104      {
    105105        return 'file_error';
    106106      }
    107      
     107
    108108      if (!$return)
    109109      {
     
    116116      }
    117117    }
    118    
     118
    119119    return false;
    120120  }
    121121}
    122 
    123 ?>
  • 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.