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/include/functions_metadata.php

    r11748 r12831  
    4949          $day = 1;
    5050        }
    51        
     51
    5252        $iptc[$pwg_key] = $year.'-'.$month.'-'.$day;
    5353      }
     
    110110}
    111111
    112 function update_metadata($files)
     112
     113function get_sync_metadata_attributes()
     114{
     115  global $conf;
     116
     117  $update_fields = array('filesize', 'width', 'height');
     118
     119  if ($conf['use_exif'])
     120  {
     121    $update_fields =
     122      array_merge(
     123        $update_fields,
     124        array_keys($conf['use_exif_mapping'])
     125        );
     126  }
     127
     128  if ($conf['use_iptc'])
     129  {
     130    $update_fields =
     131      array_merge(
     132        $update_fields,
     133        array_keys($conf['use_iptc_mapping'])
     134        );
     135  }
     136
     137  return array_unique($update_fields);
     138}
     139
     140function get_sync_metadata($infos)
     141{
     142  global $conf;
     143  $file = PHPWG_ROOT_PATH.$infos['path'];
     144  $fs = @filesize($file);
     145
     146  if ($fs===false)
     147  {
     148    return false;
     149  }
     150
     151  $infos['filesize'] = floor($fs/1024);
     152
     153  if (isset($infos['representative_ext']))
     154  {
     155    $file = original_to_representative($file, $infos['representative_ext']);
     156  }
     157
     158  if ($image_size = @getimagesize($file))
     159  {
     160    $infos['width'] = $image_size[0];
     161    $infos['height'] = $image_size[1];
     162  }
     163
     164  if ($conf['use_exif'])
     165  {
     166    $exif = get_sync_exif_data($file);
     167    $infos = array_merge($infos, $exif);
     168  }
     169
     170  if ($conf['use_iptc'])
     171  {
     172    $iptc = get_sync_iptc_data($file);
     173    $infos = array_merge($infos, $iptc);
     174  }
     175
     176  return $infos;
     177}
     178
     179
     180function sync_metadata($ids)
    113181{
    114182  global $conf;
     
    121189  $datas = array();
    122190  $tags_of = array();
    123   $has_high_images = array();
    124 
    125   $image_ids = array();
    126   foreach ($files as $id => $file)
    127   {
    128     array_push($image_ids, $id);
    129   }
    130191
    131192  $query = '
    132 SELECT id
     193SELECT id, path, representative_ext
    133194  FROM '.IMAGES_TABLE.'
    134   WHERE has_high = \'true\'
    135     AND id IN (
    136 '.wordwrap(implode(', ', $image_ids), 80, "\n").'
     195  WHERE id IN (
     196'.wordwrap(implode(', ', $ids), 160, "\n").'
    137197)
    138198;';
    139199
    140   $has_high_images = array_from_query($query, 'id');
    141 
    142   foreach ($files as $id => $file)
    143   {
    144     $data = array();
    145     $data['id'] = $id;
    146     $data['filesize'] = floor(filesize($file)/1024);
    147 
    148     if ($image_size = @getimagesize($file))
    149     {
    150       $data['width'] = $image_size[0];
    151       $data['height'] = $image_size[1];
    152     }
    153 
    154     if (in_array($id, $has_high_images))
    155     {
    156       $high_file = dirname($file).'/pwg_high/'.basename($file);
    157 
    158       $data['high_filesize'] = floor(filesize($high_file)/1024);
    159     }
    160 
    161     if ($conf['use_exif'])
    162     {
    163       $exif = get_sync_exif_data($file);
    164       if (count($exif) == 0 and isset($data['high_filesize']))
    165       {
    166         $exif = get_sync_exif_data($high_file);
    167       }
    168       $data = array_merge($data, $exif);
    169     }
    170 
    171     if ($conf['use_iptc'])
    172     {
    173       $iptc = get_sync_iptc_data($file);
    174       if (count($iptc) == 0 and isset($data['high_filesize']))
    175       {
    176         $iptc = get_sync_iptc_data($high_file);
    177       }
    178       $data = array_merge($data, $iptc);
    179      
    180       if (count($iptc) > 0)
    181       {
    182         foreach (array_keys($iptc) as $key)
     200  $result = pwg_query($query);
     201  while ($data = pwg_db_fetch_assoc($result))
     202  {
     203    $data = get_sync_metadata($data);
     204    if ($data === false)
     205    {
     206      continue;
     207    }
     208
     209    $id = $data['id'];
     210    foreach (array('keywords', 'tags') as $key)
     211    {
     212      if (isset($data[$key]))
     213      {
     214        if (!isset($tags_of[$id]))
    183215        {
    184           if ($key == 'keywords' or $key == 'tags')
    185           {
    186             if (!isset($tags_of[$id]))
    187             {
    188               $tags_of[$id] = array();
    189             }
    190 
    191             foreach (explode(',', $iptc[$key]) as $tag_name)
    192             {
    193               array_push(
    194                 $tags_of[$id],
    195                 tag_id_from_tag_name($tag_name)
    196                 );
    197             }
    198           }
     216          $tags_of[$id] = array();
    199217        }
     218
     219        foreach (explode(',', $data[$key]) as $tag_name)
     220        {
     221          array_push(
     222            $tags_of[$id],
     223            tag_id_from_tag_name($tag_name)
     224            );
     225        }
    200226      }
    201227    }
     
    208234  if (count($datas) > 0)
    209235  {
    210     $update_fields =
    211       array(
    212         'filesize',
    213         'width',
    214         'height',
    215         'high_filesize',
    216         'date_metadata_update'
    217         );
    218 
    219     if ($conf['use_exif'])
    220     {
    221       $update_fields =
    222         array_merge(
    223           $update_fields,
    224           array_keys($conf['use_exif_mapping'])
    225           );
    226     }
    227 
    228     if ($conf['use_iptc'])
    229     {
    230       $update_fields =
    231         array_merge(
    232           $update_fields,
    233           array_diff(
    234             array_keys($conf['use_iptc_mapping']),
    235             array('tags', 'keywords')
    236             )
    237           );
    238     }
     236    $update_fields = get_sync_metadata_attributes();
     237    array_push($update_fields, 'date_metadata_update');
     238
     239    $update_fields = array_diff(
     240      $update_fields,
     241      array('tags', 'keywords')
     242            );
    239243
    240244    mass_updates(
     
    242246      array(
    243247        'primary' => array('id'),
    244         'update'  => array_unique($update_fields)
     248        'update'  => $update_fields
    245249        ),
    246250      $datas,
     
    301305  }
    302306
    303   $files = array();
    304 
    305307  $query = '
    306 SELECT id, path
     308SELECT id, path, representative_ext
    307309  FROM '.IMAGES_TABLE.'
    308310  WHERE storage_category_id IN ('.implode(',', $cat_ids).')';
     
    315317  $query.= '
    316318;';
    317   $result = pwg_query($query);
    318   while ($row = pwg_db_fetch_assoc($result))
    319   {
    320     $files[$row['id']] = $row['path'];
    321   }
    322 
    323   return $files;
     319  return hash_from_query($query, 'id');
    324320}
    325321?>
Note: See TracChangeset for help on using the changeset viewer.