Ignore:
Timestamp:
Jan 3, 2012, 9:21:13 PM (12 years ago)
Author:
rvelices
Message:

feature 2548 multisize

  • rewrote local site sync + metadata sync
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/admin/site_reader_local.php

    r12642 r12831  
    3131{
    3232  $this->site_url = $url;
     33  global $conf;
     34  if (!isset($conf['flip_file_ext']))
     35  {
     36    $conf['flip_file_ext'] = array_flip($conf['file_ext']);
     37  }
     38  if (!isset($conf['flip_picture_ext']))
     39  {
     40    $conf['flip_picture_ext'] = array_flip($conf['picture_ext']);
     41  }
    3342}
    3443
     
    6978 * and $conf['picture_ext']
    7079 * @param string $path recurse in this directory
    71  * @return array like "pic.jpg"=>array('tn_ext'=>'jpg' ... )
     80 * @return array like "pic.jpg"=>array('representative_ext'=>'jpg' ... )
    7281 */
    7382function get_elements($path)
    7483{
    7584  global $conf;
    76   if (!isset($conf['flip_file_ext']))
    77   {
    78     $conf['flip_file_ext'] = array_flip($conf['file_ext']);
    79   }
    8085
    8186  $subdirs = array();
     
    9499        if ( isset($conf['flip_file_ext'][$extension]) )
    95100        {
    96           $tn_ext = $this->get_tn_ext($path, $filename_wo_ext);
     101          $representative_ext = null;
     102          if (! isset($conf['flip_picture_ext'][$extension]) )
     103          {
     104            $representative_ext = $this->get_representative_ext($path, $filename_wo_ext);
     105          }
    97106          $fs[ $path.'/'.$node ] = array(
    98             'tn_ext' => $tn_ext,
     107            'representative_ext' => $representative_ext,
    99108            );
    100109        }
     
    124133function get_update_attributes()
    125134{
    126   return array('tn_ext', 'has_high', 'representative_ext');
     135  return array('representative_ext');
    127136}
    128137
     
    133142
    134143  $filename = basename($file);
    135   $dirname = dirname($file);
    136   $filename_wo_ext = get_filename_wo_extension($filename);
    137144  $extension = get_extension($filename);
    138145
    139   $data['tn_ext'] = $this->get_tn_ext($dirname, $filename_wo_ext);
    140   $data['has_high'] = $this->get_has_high($dirname, $filename);
     146  $representative_ext = null;
     147  if (! isset($conf['flip_picture_ext'][$extension]) )
     148  {
     149    $dirname = dirname($file);
     150    $filename_wo_ext = get_filename_wo_extension($filename);
     151    $representative_ext = $this->get_representative_ext($dirname, $filename_wo_ext);
     152  }
    141153
    142   if ( !isset($conf['flip_picture_ext'][$extension]) )
    143   {
    144     $data['representative_ext'] = $this->get_representative_ext(
    145         $dirname, $filename_wo_ext
    146       );
    147   }
     154  $data['representative_ext'] = $representative_ext;
    148155  return $data;
    149156}
     
    153160function get_metadata_attributes()
    154161{
    155   global $conf;
    156 
    157   $update_fields = array('filesize', 'width', 'height', 'high_filesize', 'high_width', 'high_height');
    158 
    159   if ($conf['use_exif'])
    160   {
    161     $update_fields =
    162       array_merge(
    163         $update_fields,
    164         array_keys($conf['use_exif_mapping'])
    165         );
    166   }
    167 
    168   if ($conf['use_iptc'])
    169   {
    170     $update_fields =
    171       array_merge(
    172         $update_fields,
    173         array_keys($conf['use_iptc_mapping'])
    174         );
    175   }
    176 
    177   return $update_fields;
     162  return get_sync_metadata_attributes();
    178163}
    179164
    180165// returns a hash of attributes (metadata+filesize+width,...) for file
    181 function get_element_metadata($file, $has_high = false)
     166function get_element_metadata($infos)
    182167{
    183   global $conf;
    184   if (!is_file($file))
    185   {
    186     return null;
    187   }
    188 
    189   $data = array();
    190 
    191   $data['filesize'] = floor(filesize($file)/1024);
    192 
    193   if ($image_size = @getimagesize($file))
    194   {
    195     $data['width'] = $image_size[0];
    196     $data['height'] = $image_size[1];
    197   }
    198 
    199   if ($has_high)
    200   {
    201     $high_file = dirname($file).'/pwg_high/'.basename($file);
    202     $data['high_filesize'] = floor(filesize($high_file)/1024);
    203    
    204     if ($high_size = @getimagesize($high_file))
    205     {
    206       $data['high_width'] = $high_size[0];
    207       $data['high_height'] = $high_size[1];
    208     }
    209   }
    210 
    211   if ($conf['use_exif'])
    212   {
    213     $exif = get_sync_exif_data($file);
    214     if (count($exif) == 0 and isset($data['high_filesize']))
    215     {
    216       $exif = get_sync_exif_data($high_file);
    217     }
    218     $data = array_merge($data, $exif);
    219   }
    220 
    221   if ($conf['use_iptc'])
    222   {
    223     $iptc = get_sync_iptc_data($file);
    224     if (count($iptc) == 0 and isset($data['high_filesize']))
    225     {
    226       $iptc = get_sync_iptc_data($high_file);
    227     }
    228     $data = array_merge($data, $iptc);
    229   }
    230 
    231   return $data;
     168  return get_sync_metadata($infos);
    232169}
    233170
     
    249186}
    250187
    251 function get_tn_ext($path, $filename_wo_ext)
    252 {
    253   global $conf;
    254 
    255   $base_test =
    256     $path.'/thumbnail/'.$conf['prefix_thumbnail'].$filename_wo_ext.'.';
    257 
    258   foreach ($conf['picture_ext'] as $ext)
    259   {
    260     $test = $base_test.$ext;
    261     if (is_file($test))
    262     {
    263       return $ext;
    264     }
    265   }
    266 
    267   return null;
    268 }
    269 
    270 function get_has_high($path, $filename)
    271 {
    272   if (is_file($path.'/pwg_high/'.$filename))
    273   {
    274     return 'true';
    275   }
    276 
    277   return null;
    278 }
    279188
    280189}
Note: See TracChangeset for help on using the changeset viewer.