Changeset 493


Ignore:
Timestamp:
Aug 25, 2004, 11:09:09 PM (20 years ago)
Author:
z0rglub
Message:

"show metadata" feature added : you can ask to show metadata (EXIF and IPTC)
on picture.php page. Metadata read functions were moved from
admin/include/functions_metadata.php to include/functions_metadata.inc.php

Location:
trunk
Files:
3 added
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/admin/configuration.php

    r486 r493  
    211211$use_exif = ($conf['use_exif']=='true')?'USE_EXIF_YES':'USE_EXIF_NO';
    212212$use_iptc = ($conf['use_iptc']=='true')?'USE_IPTC_YES':'USE_IPTC_NO';
     213$show_exif = ($conf['show_exif']=='true')?'SHOW_EXIF_YES':'SHOW_EXIF_NO';
     214$show_iptc = ($conf['show_iptc']=='true')?'SHOW_IPTC_YES':'SHOW_IPTC_NO';
    213215
    214216//----------------------------------------------------- template initialization
     
    245247  $use_exif=>'checked="checked"',
    246248  $use_iptc=>'checked="checked"',
     249  $show_exif=>'checked="checked"',
     250  $show_iptc=>'checked="checked"',
    247251 
    248252  'L_CONFIRM'=>$lang['conf_confirmation'],
     
    314318  'L_USE_IPTC'=>$lang['conf_use_iptc'],
    315319  'L_USE_IPTC_INFO'=>$lang['conf_use_iptc_info'],
     320  'L_SHOW_EXIF'=>$lang['conf_show_exif'],
     321  'L_SHOW_EXIF_INFO'=>$lang['conf_show_exif_info'],
     322  'L_SHOW_IPTC'=>$lang['conf_show_iptc'],
     323  'L_SHOW_IPTC_INFO'=>$lang['conf_show_iptc_info'],
    316324 
    317325  'F_ACTION'=>add_session_id(PHPWG_ROOT_PATH.'admin.php?page=configuration')
  • trunk/admin/include/functions_metadata.php

    r486 r493  
    2626// +-----------------------------------------------------------------------+
    2727
    28 /**
    29  * returns informations from IPTC metadata, mapping is done at the beginning
    30  * of the function
    31  *
    32  * @param string $filename
    33  * @return array
    34  */
    35 function get_iptc_data($filename)
     28include_once(PHPWG_ROOT_PATH.'/include/functions_metadata.inc.php');
     29
     30function get_sync_iptc_data($file)
    3631{
    37   global $getimagesize_time;
    38    
    3932  $map = array(
    4033    'keywords'        => '2#025',
     
    4639  $datefields = array('date_creation', 'date_available');
    4740 
    48   $result = array();
    49  
    50   // Read IPTC data
    51   $iptc = array();
    52  
    53   $start = get_moment();
    54   getimagesize($filename, &$imginfo);
    55   $getimagesize_time+= get_moment() - $start;
    56  
    57   if (is_array($imginfo) and isset($imginfo['APP13']))
    58   {
    59     $iptc = iptcparse($imginfo['APP13']);
    60     if (is_array($iptc))
    61     {
    62       $rmap = array_flip($map);
    63       foreach (array_keys($rmap) as $iptc_key)
    64       {
    65         if (isset($iptc[$iptc_key][0]) and $value = $iptc[$iptc_key][0])
    66         {
    67           // strip leading zeros (weird Kodak Scanner software)
    68           while ($value[0] == chr(0))
    69           {
    70             $value = substr($value, 1);
    71           }
    72           // remove binary nulls
    73           $value = str_replace(chr(0x00), ' ', $value);
    74          
    75           foreach (array_keys($map, $iptc_key) as $pwg_key)
    76           {
    77             if (in_array($pwg_key, $datefields))
    78             {
    79               if ( preg_match('/(\d{4})(\d{2})(\d{2})/', $value, $matches))
    80               {
    81                 $value = $matches[1].'-'.$matches[2].'-'.$matches[3];
    82               }
    83               else
    84               {
    85                 continue;
    86               }
    87             }
    88             $result[$pwg_key] = $value;
    89           }
    90         }
    91       }
    92     }
    93   }
    94   return $result;
     41  $iptc = get_iptc_data($file, $map);
     42
     43  foreach ($iptc as $pwg_key => $value)
     44  {
     45    if (in_array($pwg_key, $datefields))
     46    {
     47      if ( preg_match('/(\d{4})(\d{2})(\d{2})/', $value, $matches))
     48      {
     49        $iptc[$pwg_key] = $matches[1].'-'.$matches[2].'-'.$matches[3];
     50      }
     51    }
     52  }
     53
     54  return $iptc;
    9555}
    9656
     
    9858{
    9959  global $conf;
    100 
    101 //   $conf['use_iptc'] = true;
    102 //   $conf['use_exif'] = true;
    10360 
    10461  $inserts = array();
     
    13390    if ($conf['use_iptc'])
    13491    {
    135       $iptc = get_iptc_data($file);
    136       foreach (array_keys($iptc) as $key)
    137       {
    138         $insert[$key] = "'".addslashes($iptc[$key])."'";
     92      $iptc = get_sync_iptc_data($file);
     93      if (count($iptc) > 0)
     94      {
     95        foreach (array_keys($iptc) as $key)
     96        {
     97          $insert[$key] = "'".addslashes($iptc[$key])."'";
     98        }
    13999      }
    140100    }
  • trunk/include/config.inc.php

    r468 r493  
    5959$conf['max_LOV_categories'] = 50;
    6060
     61// $conf['show_iptc_mapping'] is used for showing IPTC metadata on
     62// picture.php page. For each key of the array, you need to have the same
     63// key in the $lang array. For example, if my first key is 'iptc_keywords'
     64// (associated to '2#025') then you need to have $lang['iptc_keywords'] set
     65// in language/$user['language']/common.lang.php. If you don't have the lang
     66// var set, the key will be simply displayed
     67//
     68// To know how to associated iptc_field with their meaning, use
     69// tools/metadata.php
     70$conf['show_iptc_mapping'] = array(
     71  'iptc_keywords'        => '2#025',
     72  'iptc_caption_writer'  => '2#122',
     73  'iptc_byline_title'    => '2#085',
     74  'iptc_caption'         => '2#120'
     75  );
     76
     77// in EXIF fields, you can choose to display fields in sub-arrays, for
     78// example ['COMPUTED']['ApertureFNumber']. for this, add
     79// 'COMPUTED;ApertureFNumber' in $conf['show_exif_fields']
     80//
     81// The key displayed in picture.php will be $lang['exif_field_Make'] for
     82// example and if it exists. For compound fields, only take into account the
     83// last part : for key 'COMPUTED;ApertureFNumber', you need
     84// $lang['exif_field_ApertureFNumber']
     85$conf['show_exif_fields'] = array('Make',
     86                                  'Model',
     87                                  'DateTime',
     88                                  'COMPUTED;ApertureFNumber');
     89// for PHP version newer than 4.1.2 :
     90// $conf['show_exif_fields'] = array('CameraMake','CameraModel','DateTime');
    6191?>
  • trunk/install/config.sql

    r486 r493  
    3030INSERT INTO phpwebgallery_config (param,value,comment) VALUES ('use_iptc','false','Use IPTC data during database synchronization with files metadata');
    3131INSERT INTO phpwebgallery_config (param,value,comment) VALUES ('use_exif','true','Use EXIF data during database synchronization with files metadata');
     32INSERT INTO phpwebgallery_config (param,value,comment) VALUES ('show_iptc','false','Show IPTC metadata on picture.php if asked by user');
     33INSERT INTO phpwebgallery_config (param,value,comment) VALUES ('show_exif','true','Show EXIF metadata on picture.php if asked by user');
  • trunk/language/en_UK.iso-8859-1/admin.lang.php

    r486 r493  
    160160$lang['conf_use_iptc'] = 'Use IPTC';
    161161$lang['conf_use_iptc_info'] = 'Use IPTC data during metadata synchronization into PhpWebGallery database';
     162$lang['conf_show_exif'] = 'Show EXIF';
     163$lang['conf_show_exif_info'] = 'Give the possibility to show EXIF metadata on visualisation page. See include/config.inc.php for available EXIF fields';
     164$lang['conf_show_iptc'] = 'Show IPTC';
     165$lang['conf_show_iptc_info'] = 'Give the possibility to show IPTC metadata on visualisation page. See include/config.inc.php for available IPTC fields';
    162166
    163167//FAQ
  • trunk/language/en_UK.iso-8859-1/common.lang.php

    r470 r493  
    280280$lang['search_date_creation'] = 'creation date';
    281281$lang['search_one_clause_at_least'] = 'search at least on one search clause';
     282
     283$lang['picture_show_metadata'] = 'Show file metadata ?';
     284$lang['picture_hide_metadata'] = 'Hide file metadata';
    282285?>
  • trunk/picture.php

    r484 r493  
    197197  {
    198198    $picture[$i]['url'].= '&search='.$_GET['search'];
     199  }
     200  if (isset($_GET['show_metadata']))
     201  {
     202    $picture[$i]['url'].= '&show_metadata=1';
    199203  }
    200204}
     
    406410  'L_DOWNLOAD' => $lang['download'],
    407411  'L_DOWNLOAD_HINT' => $lang['download_hint'],
     412  'L_PICTURE_SHOW_METADATA' => $lang['picture_show_metadata'],
     413  'L_PICTURE_HIDE_METADATA' => $lang['picture_hide_metadata'],
    408414 
    409415  'T_DEL_IMG' =>PHPWG_ROOT_PATH.'template/'.$user['template'].'/theme/delete.gif',
     
    571577    'VALUE'=>$picture['current']['hit'].' '.$lang['times']
    572578    ));
    573 
     579//-------------------------------------------------------------------- metadata
     580if ($conf['show_exif'] or $conf['show_iptc'])
     581{
     582  $metadata_showable = true;
     583}
     584else
     585{
     586  $metadata_showable = false;
     587}
     588
     589if ($metadata_showable and !isset($_GET['show_metadata']))
     590{
     591  $url = PHPWG_ROOT_PATH.'picture.php?'.$_SERVER['QUERY_STRING'];
     592  $url.= '&show_metadata=1';
     593  $template->assign_block_vars('show_metadata', array('URL' => $url));
     594}
     595
     596if ($metadata_showable and isset($_GET['show_metadata']))
     597{
     598  $url = PHPWG_ROOT_PATH.'picture.php';
     599 
     600  $str = $_SERVER['QUERY_STRING'];
     601  parse_str($str, $get_vars);
     602  $is_first = true;
     603  foreach ($get_vars as $key => $value)
     604  {
     605    if ($key != 'show_metadata')
     606    {
     607      if ($is_first)
     608      {
     609        $url.= '?';
     610        $is_first = false;
     611      }
     612      else
     613      {
     614        $url.= '&';
     615      }
     616      $url.= $key.'='.$value;
     617    }
     618  }
     619 
     620  $template->assign_block_vars('hide_metadata', array('URL' => $url));
     621 
     622  include_once(PHPWG_ROOT_PATH.'/include/functions_metadata.inc.php');
     623 
     624  $template->assign_block_vars('metadata', array());
     625 
     626  if ($conf['show_exif'])
     627  {
     628    if ($exif = @read_exif_data($picture['current']['src']))
     629    {
     630      $template->assign_block_vars(
     631        'metadata.headline',
     632        array('TITLE' => 'EXIF Metadata')
     633        );
     634     
     635      foreach ($conf['show_exif_fields'] as $field)
     636      {
     637        if (strpos($field, ';') === false)
     638        {
     639          if (isset($exif[$field]))
     640          {
     641            $key = $field;
     642            if (isset($lang['exif_field_'.$field]))
     643            {
     644              $key = $lang['exif_field_'.$field];
     645            }
     646           
     647            $template->assign_block_vars(
     648              'metadata.line',
     649              array(
     650                'KEY' => $key,
     651                'VALUE' => $exif[$field]
     652                )
     653              );
     654          }
     655        }
     656        else
     657        {
     658          $tokens = explode(';', $field);
     659          if (isset($exif[$tokens[0]][$tokens[1]]))
     660          {
     661            $key = $tokens[1];
     662            if (isset($lang['exif_field_'.$tokens[1]]))
     663            {
     664              $key = $lang['exif_field_'.$tokens[1]];
     665            }
     666           
     667            $template->assign_block_vars(
     668              'metadata.line',
     669              array(
     670                'KEY' => $key,
     671                'VALUE' => $exif[$tokens[0]][$tokens[1]]
     672                )
     673              );
     674          }
     675        }
     676      }
     677    }
     678  }
     679
     680  if ($conf['show_iptc'])
     681  {
     682    $iptc = get_iptc_data($picture['current']['src'],
     683                          $conf['show_iptc_mapping']);
     684
     685    if (count($iptc) > 0)
     686    {
     687      $template->assign_block_vars(
     688        'metadata.headline',
     689        array('TITLE' => 'IPTC Metadata')
     690        );
     691    }
     692   
     693    foreach ($iptc as $field => $value)
     694    {
     695      $key = $field;
     696      if (isset($lang[$field]))
     697      {
     698        $key = $lang[$field];
     699      }
     700     
     701      $template->assign_block_vars(
     702        'metadata.line',
     703        array(
     704          'KEY' => $key,
     705          'VALUE' => $value
     706          )
     707        );
     708    }
     709  }
     710}
    574711//------------------------------------------------------- favorite manipulation
    575712if ( !$user['is_the_guest'] )
  • trunk/template/default/admin/configuration.tpl

    r486 r493  
    198198    </td>
    199199  </tr>
     200  <tr>
     201    <td>
     202      <strong>{L_SHOW_EXIF}&nbsp;:</strong>
     203      <br /><span class="small">{L_SHOW_EXIF_INFO}</span>
     204    </td>
     205    <td class="row1">
     206      <input type="radio" class="radio" name="show_exif" value="true" {SHOW_EXIF_YES} />{L_YES}&nbsp;&nbsp;
     207      <input type="radio" class="radio" name="show_exif" value="false" {SHOW_EXIF_NO} />{L_NO}
     208    </td>
     209  </tr>
     210  <tr>
     211    <td>
     212      <strong>{L_SHOW_IPTC}&nbsp;:</strong>
     213      <br /><span class="small">{L_SHOW_IPTC_INFO}</span>
     214    </td>
     215    <td class="row1">
     216      <input type="radio" class="radio" name="show_iptc" value="true" {SHOW_IPTC_YES} />{L_YES}&nbsp;&nbsp;
     217      <input type="radio" class="radio" name="show_iptc" value="false" {SHOW_IPTC_NO} />{L_NO}
     218    </td>
     219  </tr>
    200220    <!-- BEGIN remote_sites -->
    201221    <tr>
  • trunk/template/default/picture.tpl

    r472 r493  
    7070          </div>
    7171          <!-- END favorite -->
     72
     73          <!-- BEGIN show_metadata -->
     74            [ <a href="{show_metadata.URL}">{L_PICTURE_SHOW_METADATA}</a> ]
     75          <!-- END show_metadata -->
     76
     77          <!-- BEGIN hide_metadata -->         
     78            [ <a href="{hide_metadata.URL}">{L_PICTURE_HIDE_METADATA}</a> ]
     79          <!-- END hide_metadata -->
     80
     81          <!-- BEGIN metadata -->
     82          <table class="metadata">
     83            <!-- BEGIN headline -->
     84            <tr>
     85              <th colspan="2">{metadata.headline.TITLE}</th>
     86            </tr>
     87            <!-- END headline -->
     88            <!-- BEGIN line -->
     89            <tr>
     90              <td>{metadata.line.KEY}</td>
     91              <td>{metadata.line.VALUE}</td>
     92            </tr>
     93            <!-- END line -->
     94          </table>
     95          <!-- END metadata -->
    7296          <!-- BEGIN modification -->
    7397          <div class="menu" style="text-align:center;margin:5px;">
Note: See TracChangeset for help on using the changeset viewer.