| 1 | <?php |
|---|
| 2 | /* |
|---|
| 3 | Plugin Name: Exifer |
|---|
| 4 | |
|---|
| 5 | Plugin URI: http://082net.com/tag/exifer/ |
|---|
| 6 | |
|---|
| 7 | Description: Display Exif information of attached images. It works with images uploaded by wordpress upload enviroment. Tested with wordpress 2.0 or later. |
|---|
| 8 | |
|---|
| 9 | Version: 0.7 |
|---|
| 10 | |
|---|
| 11 | Author: Choen, Youngmin |
|---|
| 12 | Author URI: http://082net.com/ |
|---|
| 13 | *//* |
|---|
| 14 | Change Logs :: |
|---|
| 15 | |
|---|
| 16 | |
|---|
| 17 | Lisense : GPL(http://www.gnu.org/copyleft/gpl.html) |
|---|
| 18 | /* Copyright 2006 Cheon, Young-Min (email : 082net@gmail.com, site : http://082net.com) |
|---|
| 19 | ** |
|---|
| 20 | ** This program is free software; you can redistribute it and/or modify |
|---|
| 21 | ** it under the terms of the GNU General Public License as published by |
|---|
| 22 | ** the Free Software Foundation; either version 2 of the License, or |
|---|
| 23 | ** (at your option) any later version. |
|---|
| 24 | ** |
|---|
| 25 | ** This program is distributed in the hope that it will be useful, |
|---|
| 26 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 27 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 28 | ** GNU General Public License for more details. |
|---|
| 29 | ** |
|---|
| 30 | ** You should have received a copy of the GNU General Public License |
|---|
| 31 | ** along with this program; if not, write to the Free Software |
|---|
| 32 | ** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|---|
| 33 | */ |
|---|
| 34 | |
|---|
| 35 | |
|---|
| 36 | include_once('lib/exif.php'); |
|---|
| 37 | |
|---|
| 38 | class WpExif { |
|---|
| 39 | |
|---|
| 40 | var $myImagePath = "wp-content/uploads/images"; // From wordpress install folder |
|---|
| 41 | var $extra_data = false; //show extra exif information |
|---|
| 42 | |
|---|
| 43 | function WpExif() { |
|---|
| 44 | $this->pluginURL = trailingslashit(get_option('siteurl')) . 'wp-content/plugins/exifer'; |
|---|
| 45 | add_filter('the_content', array(&$this, '_filter'), 2); |
|---|
| 46 | add_action('wp_head', array(&$this, 'wp_head')); |
|---|
| 47 | } |
|---|
| 48 | |
|---|
| 49 | function wp_head() { |
|---|
| 50 | echo ' |
|---|
| 51 | <!-- Added by Wp-Exif --> |
|---|
| 52 | <link rel="stylesheet" type="text/css" media="screen" href="'.$this->pluginURL.'/exif.css" /> |
|---|
| 53 | '; |
|---|
| 54 | } |
|---|
| 55 | |
|---|
| 56 | function clean_pre_slash($path="", $trailing = true) { |
|---|
| 57 | $new_path = trim($path); |
|---|
| 58 | $new_path = ( '/' != substr($new_path, 0, 1))?$new_path:substr($new_path, 1, (strlen($new_path) - 1)); |
|---|
| 59 | if($trailing) $new_path = trailingslashit($new_path); |
|---|
| 60 | return $new_path; |
|---|
| 61 | } |
|---|
| 62 | |
|---|
| 63 | function print_exif($name, $extention, $option) { |
|---|
| 64 | $print_exif = ""; |
|---|
| 65 | $file_name = stripslashes(trim($name)) . '.' .stripslashes(trim($extention)); |
|---|
| 66 | $option = stripslashes(trim($option)); |
|---|
| 67 | $img_path = $this->_getImagePath($file_name, $option); |
|---|
| 68 | |
|---|
| 69 | if(!file_exists($img_path)) |
|---|
| 70 | return '<p>Image file not found('.$img_path.')</p>'; |
|---|
| 71 | |
|---|
| 72 | $exif = $this->_getExif($img_path); |
|---|
| 73 | if($exif && !empty($exif)) { |
|---|
| 74 | $print_exif = '<table class="wp-exif" cellpadding="3" cellspacing="3">'; |
|---|
| 75 | $print_exif .= '<tr><th colspan="2">Exif Information</th></tr>'; |
|---|
| 76 | $row = ''; |
|---|
| 77 | foreach ( $exif as $key => $value ) { |
|---|
| 78 | if (isset($exif[$key]) && !empty($exif[$key])) { |
|---|
| 79 | $row = ($row == '')?' class="exif-alt"':''; |
|---|
| 80 | switch($key) { |
|---|
| 81 | /* case 'date_time': case 'date_time_edit': |
|---|
| 82 | $value = date('Y.m.d g:i:s a', $value); |
|---|
| 83 | break;*/ |
|---|
| 84 | case 'flash': |
|---|
| 85 | $value = ("no flash"==strtolower($value)||"off"==strtolower($value))?'Not Fired':'Fired'; |
|---|
| 86 | break; |
|---|
| 87 | case 'shutter_speed': |
|---|
| 88 | $value = $value . ' sec'; |
|---|
| 89 | break; |
|---|
| 90 | case 'dimension': |
|---|
| 91 | $value = $value . ' px'; |
|---|
| 92 | break; |
|---|
| 93 | default: |
|---|
| 94 | break; |
|---|
| 95 | } |
|---|
| 96 | $print_exif .= '<tr'.$row.'>'; |
|---|
| 97 | $print_exif .= '<td class="exif-key">'; |
|---|
| 98 | $print_exif .= ($key == 'iso')?strtoupper($key):ucwords(str_replace(array('_', '-'), ' ' ,$key)); |
|---|
| 99 | $print_exif .= '</td>'; |
|---|
| 100 | $print_exif .= '<td class="exif-value">'.$value.'</td>'; |
|---|
| 101 | $print_exif .= '</tr>'; |
|---|
| 102 | } |
|---|
| 103 | } |
|---|
| 104 | $print_exif .= '</table>'; |
|---|
| 105 | } else $print_exif = '<p>no exif data</p>'; |
|---|
| 106 | return $print_exif; |
|---|
| 107 | } |
|---|
| 108 | |
|---|
| 109 | function pullout($str) { |
|---|
| 110 | $str = stripslashes($str); |
|---|
| 111 | $str = UTF8_decode($str); |
|---|
| 112 | return $str; |
|---|
| 113 | } |
|---|
| 114 | |
|---|
| 115 | function &reduceExif($exifvalue) { |
|---|
| 116 | $vals = split("/",$exifvalue); |
|---|
| 117 | if(count($vals) == 2) { |
|---|
| 118 | // MJS 29092005 - Code to deal with exposure times of > 1 sec |
|---|
| 119 | if ( $vals[1] == 0 ) { |
|---|
| 120 | $exposure = round($vals[0].$vals[1],2); |
|---|
| 121 | } else { |
|---|
| 122 | $exposure = round($vals[0]/$vals[1],2); |
|---|
| 123 | if ( $exposure < 1 ) $exposure = '1/'.round($vals[1]/$vals[0],0); |
|---|
| 124 | } |
|---|
| 125 | } else { |
|---|
| 126 | $exposure = round($vals[0]/$vals[1], 2); |
|---|
| 127 | } |
|---|
| 128 | return $exposure; |
|---|
| 129 | } |
|---|
| 130 | |
|---|
| 131 | function _getImagePath($img_file, $option) { |
|---|
| 132 | $img_path = ""; |
|---|
| 133 | if(!$option) { |
|---|
| 134 | global $wpdb, $post; |
|---|
| 135 | $query = "SELECT `guid` FROM `".$wpdb->posts."`"; |
|---|
| 136 | $query .= " WHERE `post_status` = 'attachment'"; |
|---|
| 137 | $query .= " AND `post_parent` = '".$post->ID."'"; |
|---|
| 138 | $query .= " AND `post_mime_type` = 'image/jpeg'"; |
|---|
| 139 | if( $results = $wpdb->get_results($query) ) { |
|---|
| 140 | foreach($results as $r) { |
|---|
| 141 | if( basename(trim($r->guid)) == $img_file ) { |
|---|
| 142 | $siteurl = trailingslashit(get_option('siteurl')); |
|---|
| 143 | $related_path = str_replace($siteurl, '', $r->guid); |
|---|
| 144 | $img_path = ABSPATH . $related_path; |
|---|
| 145 | break; |
|---|
| 146 | } |
|---|
| 147 | } |
|---|
| 148 | } |
|---|
| 149 | } else { |
|---|
| 150 | if (preg_match('/path="1"/i', $option) || preg_match("/path='1'/i", $option)) { |
|---|
| 151 | $pre_path = ABSPATH . $this->clean_pre_slash($this->myImagePath, true); |
|---|
| 152 | $img_path = $pre_path . $this->clean_pre_slash($img_file, false); |
|---|
| 153 | } elseif (preg_match('/path="(.*?)"/i', $option, $match) || preg_match("/path='(.*?)'/i", $option, $match)) { |
|---|
| 154 | $img_path = $_SERVER['DOCUMENT_ROOT'] . '/' . $this->clean_pre_slash($match[1]) . $img_file; |
|---|
| 155 | } |
|---|
| 156 | } |
|---|
| 157 | return $img_path; |
|---|
| 158 | } |
|---|
| 159 | |
|---|
| 160 | function _getExif($img_path) { |
|---|
| 161 | $info = array(); |
|---|
| 162 | $exif = read_exif_data_raw($img_path,"0"); |
|---|
| 163 | if (isset($exif['IFD0'])) { |
|---|
| 164 | // $info['make'] = trim($exif['IFD0']['Make']); // camera maker |
|---|
| 165 | $info['camera'] = trim($exif['IFD0']['Model']); // camera model |
|---|
| 166 | } |
|---|
| 167 | |
|---|
| 168 | if (isset($exif['SubIFD'])) { |
|---|
| 169 | if(isset($exif['SubIFD']['ShutterSpeedValue'])) |
|---|
| 170 | $info['shutter_speed'] = trim($this->reduceExif($exif['SubIFD']['ShutterSpeedValue'])); |
|---|
| 171 | else |
|---|
| 172 | $info['shutter_speed'] = trim($this->reduceExif($exif['SubIFD']['ExposureTime'])); // exposure time |
|---|
| 173 | |
|---|
| 174 | $info['iso'] = (isset($exif['SubIFD']['ISOSpeedRatings']))?$this->pullout($exif['SubIFD']['ISOSpeedRatings']):''; |
|---|
| 175 | |
|---|
| 176 | if ( isset($exif['SubIFD']['ExifImageWidth']) && isset($exif['SubIFD']['ExifImageHeight']) ) { |
|---|
| 177 | $width = str_replace(' pixels', '', $exif['SubIFD']['ExifImageWidth']); |
|---|
| 178 | $height = str_replace(' pixels', '', $exif['SubIFD']['ExifImageHeight']); |
|---|
| 179 | $info['dimension'] = $width . ' x ' . $height; |
|---|
| 180 | } |
|---|
| 181 | |
|---|
| 182 | $info['focal_length'] = str_replace(" ", "", $exif['SubIFD']['FocalLength']); // focal length |
|---|
| 183 | $info['aperture'] = trim(strtoupper($exif['SubIFD']['FNumber'])); // Aperture |
|---|
| 184 | // $info['date_time'] = strtotime($exif['SubIFD']['DateTimeOriginal'], time()); // Date and Time |
|---|
| 185 | $info['date_time'] = $exif['SubIFD']['DateTimeOriginal']; // Date and Time |
|---|
| 186 | $info['flash'] = $exif['SubIFD']['Flash']; // flash |
|---|
| 187 | //extra exif data |
|---|
| 188 | if($this->extra_data) { |
|---|
| 189 | if (isset($exif['IFD0'])) { |
|---|
| 190 | $info['software'] = trim($exif['IFD0']['Software']); // Edit software |
|---|
| 191 | // $info['date_time_edit'] = strtotime($exif['IFD0']['DateTime'], time()); // Edited Date and Time |
|---|
| 192 | $info['date_time_edit'] = $exif['IFD0']['DateTime']; // Edited Date and Time |
|---|
| 193 | // If hardware(camera) self-edit |
|---|
| 194 | $info['date_time_edit'] = ($info['date_time'] == $info['date_time_edit'])?'':$info['date_time_edit']; |
|---|
| 195 | } |
|---|
| 196 | $info['digital_zoom'] = $exif['SubIFD']['DigitalZoomRatio']; |
|---|
| 197 | $info['exposure_prog'] = isset($exif['SubIFD']['ExposureProgram'])?trim($exif['SubIFD']['ExposureProgram']):''; |
|---|
| 198 | $info['metering_mode'] = trim($exif['SubIFD']['MeteringMode']); |
|---|
| 199 | $info['white_balance'] = trim($exif['SubIFD']['WhiteBalance']); |
|---|
| 200 | $info['white_balance'] = ( $info['white_balance'] == 0 )?'':$info['white_balance'] . " WB"; |
|---|
| 201 | $info['exposure_bias'] = round($exif['SubIFD']['ExposureBiasValue'],2); |
|---|
| 202 | $info['exposure_bias'] = ( $info['exposure_bias'] == 0 )?'':$info['exposure_bias'] . " Ev"; |
|---|
| 203 | $info['orientation'] = $exif['SubIFD']['Orientation']; |
|---|
| 204 | $info['max_aperature'] = $exif['SubIFD']['MaxAperatureValue']; |
|---|
| 205 | $info['brightness'] = $exif['SubIFD']['BrightnessValue']; |
|---|
| 206 | } |
|---|
| 207 | |
|---|
| 208 | // Known Maker Custom |
|---|
| 209 | if($exif['SubIFD']['KnownMaker'] == '1' ) { |
|---|
| 210 | $make = strtolower(trim($exif['IFD0']['Make'])); |
|---|
| 211 | if(eregi("nikon",$make)) { |
|---|
| 212 | $custom = $exif['SubIFD']['MakerNote']; |
|---|
| 213 | $info['quality'] = isset($custom['Quality'])?$custom['Quality']:''; |
|---|
| 214 | } elseif(eregi("olympus",$make)) { |
|---|
| 215 | |
|---|
| 216 | } elseif(eregi("canon",$make)) { |
|---|
| 217 | $custom = $exif['SubIFD']['MakerNote']['Settings_1']; |
|---|
| 218 | $info['iso'] = (isset($custom['ISO']))?$this->pullout($custom['ISO']):$info['iso']; |
|---|
| 219 | $info['quality'] = (isset($custom['Quality']))?$custom['Quality']:''; |
|---|
| 220 | } elseif(eregi("fujifilm",$make)) { |
|---|
| 221 | |
|---|
| 222 | } elseif(eregi("sanyo",$make)) { |
|---|
| 223 | |
|---|
| 224 | } |
|---|
| 225 | } |
|---|
| 226 | } |
|---|
| 227 | return $info; |
|---|
| 228 | } |
|---|
| 229 | |
|---|
| 230 | function _filter($text) { |
|---|
| 231 | $text = preg_replace('#\[exif(.*?)\](.*?)\.(jpg|jpeg)(.*?)\[/exif\]#sie', '$this->print_exif(\'$2\', \'$3\', \'$1\')', $text); |
|---|
| 232 | return $text; |
|---|
| 233 | } |
|---|
| 234 | |
|---|
| 235 | function &get_instance() { |
|---|
| 236 | static $instance = array(); |
|---|
| 237 | if ( empty( $instance ) ) { |
|---|
| 238 | $instance[] =& new WpExif(); |
|---|
| 239 | } |
|---|
| 240 | return $instance[0]; |
|---|
| 241 | } |
|---|
| 242 | |
|---|
| 243 | } |
|---|
| 244 | |
|---|
| 245 | $WpExif =& WpExif::get_instance(); |
|---|
| 246 | ?> |
|---|