Advertisement
Guest User

image_meta.php

a guest
Dec 26th, 2012
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.52 KB | None | 0 0
  1. <?php
  2.  
  3. function bfa_image_size() {
  4.     $meta = wp_get_attachment_metadata();
  5.     echo $meta['width']. '&times;' . $meta['height'];
  6. }
  7.  
  8.  
  9. function bfa_image_meta( $args = '' ) {
  10.  
  11.     $defaults = array(
  12.         'keys' => '',
  13.         'before' => '',
  14.         'after' => '',
  15.         'item_before' => '',
  16.         'item_after' => '',
  17.         'item_sep' => ' &middot; ',
  18.         'key_before' => '',
  19.         'key_after' => ': ',
  20.         'value_before' => '',
  21.         'value_after' => '',
  22.         'display_empty' => FALSE   
  23.     );
  24.  
  25.     $r = wp_parse_args( $args, $defaults );
  26.     extract( $r, EXTR_SKIP );
  27.    
  28.     $meta = wp_get_attachment_metadata();
  29.    
  30.     $string_array = array();
  31.    
  32.     // All keys, alphabetically sorted, as provided by wp_get_attachment_metadata()
  33.     if( $keys == '' ) {
  34.         $array_keys = array_keys( $meta['image_meta'] );       
  35.     // Only keys specificed in parameter:
  36.     } else {
  37.         $array_keys = array_map( 'trim', explode( ',', $keys ) );
  38.     }
  39.  
  40.     foreach( $array_keys as $key ) {
  41.    
  42.         $value = $meta['image_meta'][$key];
  43.  
  44.         if( $display_empty === TRUE || ( $value != '' && $value != '0' ) ) {
  45.        
  46.             if( $key == 'created_timestamp' )
  47.                 // Transform timestamp into readable date, based on default WP date/time settings:
  48.                 $value = date( get_option('date_format') . ' - ' . get_option('time_format'), $value );
  49.                
  50.             // Prettify key
  51.             $key = ucwords( str_replace( '_', ' ', $key ) );
  52.             $key = $key == 'Iso' ? 'ISO' : $key;
  53.            
  54.            
  55.             $key = str_replace(
  56.                 array(
  57.                     'Aperture',
  58.                     'Credit',
  59.                     'Camera',
  60.                     'Caption',
  61.                     'Created Timestamp',
  62.                     'Copyright',
  63.                     'Focal Length',
  64.                     'ISO',
  65.                     'Shutter Speed',
  66.                     'Title'
  67.                 ),
  68.                 array(
  69.                     __( 'Aperture', 'montezuma' ),
  70.                     __( 'Credit', 'montezuma' ),
  71.                     __( 'Camera', 'montezuma' ),
  72.                     __( 'Caption', 'montezuma' ),
  73.                     __( 'Timestamp', 'montezuma' ),
  74.                     __( 'Copyright', 'montezuma' ),
  75.                     __( 'Focal Length', 'montezuma' ),
  76.                     __( 'ISO', 'montezuma' ),
  77.                     __( 'Shutter Speed', 'montezuma' ),
  78.                     __( 'Title', 'montezuma' )
  79.                 ),     
  80.                 $key
  81.             );
  82.            
  83.            
  84.             // Glue it together
  85.             $string = $item_before
  86.                         . $key_before
  87.                         . $key
  88.                         . $key_after
  89.                         . $value_before
  90.                         . $value
  91.                         . $value_after
  92.                         . $item_after;
  93.                        
  94.             $string_array[] = $string;
  95.         }  
  96.     }
  97.    
  98.     $final_string = '';
  99.    
  100.     // Glue together with item separator
  101.     if( ! empty( $string_array ) )
  102.         $final_string = implode( $item_sep, $string_array );
  103.        
  104.     // Wrap into parent container
  105.     if( $final_string != '' )
  106.         $final_string = $before . $final_string . $after;
  107.    
  108.     echo $final_string;
  109. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement