1<?php
2/*************************
3  Coppermine Photo Gallery
4  ************************
5  Copyright (c) 2003-2016 Coppermine Dev Team
6  v1.0 originally written by Gregory Demar
7
8  This program is free software; you can redistribute it and/or modify
9  it under the terms of the GNU General Public License version 3
10  as published by the Free Software Foundation.
11
12  ********************************************
13  Coppermine version: 1.6.03
14  $HeadURL$
15**********************************************/
16
17if (!defined('IN_COPPERMINE')) die('Not in Coppermine...');
18
19require("include/exif.php");
20
21function exif_parse_file($filename, $pid)
22{
23    global $CONFIG, $lang_picinfo;
24
25    if (!is_readable($filename)) {
26        return false;
27    }
28
29    $size = cpg_getimagesize($filename);
30
31    if ($size[2] != 2) {
32        return false; // Not a JPEG file
33    }
34
35    //String containing all the available exif tags.
36    $exif_info = "AFFocusPosition|Adapter|ColorMode|ColorSpace|ComponentsConfiguration|CompressedBitsPerPixel|Contrast|CustomerRender|DateTimeOriginal|DateTimedigitized|DigitalZoom|DigitalZoomRatio|ExifImageHeight|ExifImageWidth|ExifInteroperabilityOffset|ExifOffset|ExifVersion|ExposureBiasValue|ExposureMode|ExposureProgram|ExposureTime|FNumber|FileSource|Flash|FlashPixVersion|FlashSetting|FocalLength|FocusMode|GainControl|IFD1Offset|ISOSelection|ISOSetting|ISOSpeedRatings|ImageAdjustment|ImageDescription|ImageSharpening|LightSource|Make|ManualFocusDistance|MaxApertureValue|MeteringMode|Model|NoiseReduction|Orientation|Quality|ResolutionUnit|Saturation|SceneCaptureMode|SceneType|Sharpness|Software|WhiteBalance|YCbCrPositioning|xResolution|yResolution";
37    $exif_names = explode("|", $exif_info);
38
39    //Check if we have the data of the said file in the table
40    $result = cpg_db_query("SELECT exifData FROM {$CONFIG['TABLE_EXIF']} WHERE pid = $pid");
41    if ($result->numRows() > 0) {
42        $row = $result->fetchAssoc(true);
43        $exif = unserialize($row['exifData']);
44
45        // Convert old EXIF data style to new one
46        if (array_key_exists('Errors', $exif)) {
47            $exif = cpg_exif_strip_data($exif, $exif_names);
48            cpg_db_query("UPDATE {$CONFIG['TABLE_EXIF']} SET exifData = '".addslashes(serialize($exif))."' WHERE pid = '$pid'");
49        }
50    } else { // No data in the table - read it from the image file
51        $exifRawData = read_exif_data_raw($filename, 0);
52
53        $exif = cpg_exif_strip_data($exifRawData, $exif_names);
54
55        // Insert it into table for future reference
56        cpg_db_query("INSERT INTO {$CONFIG['TABLE_EXIF']} (pid, exifData) VALUES ($pid, '".addslashes(serialize($exif))."')");
57    }
58
59    $exifParsed = array();
60    $exifCurrentData = array_keys(array_filter(explode("|", $CONFIG['show_which_exif'])));
61
62    foreach ($exifCurrentData as $i) {
63        $name = $exif_names[$i];
64        if (isset($exif[$name])) {
65            $exifParsed[$lang_picinfo[$name]] = $exif[$name];
66        }
67    }
68
69    ksort($exifParsed);
70
71    return $exifParsed;
72}
73
74//EOF