Hello Everyone!
I thought I'd post a quick edit I put into my own Coppermine gallery for displaying and sorting on the date a picture was taken as opposed to uploaded. The approach I have taken is to load the DateTimedigitized Exif field and added it to the cpg148_pictures result set as if it was part of the sql query. I don't store the field on the cpg148_pictures table as in other mods I have seen, so I then have to do any sorting in memory as opposed to using orderby sql. I guess the tradeoff is that the mod is quicker to implement, but suffers in performance - the modified code can also be harder to follow since multiple sorting approaches are being mixed.
The changes below require changing core files, so please keep track of them to ease in future upgrades.1. copy the attached file "tmb.inc.php" to your /include directory. This basically keeps any new functions I added off to the side and easy to edit. You can name this whatever you want, just make sure step #2 is in sync
2. add "include_once("include/tmb.inc.php");" to the bottom of your function.inc.php file - now you will have access to new functions addDatePictureTaken(), sortByDatePictureTaken(), and array_key_multi_sort()
3. change the exif and iptc "include" lines in displayImage.php to be "include_once" (for cpg1.4.8 these are displayImage.php lines 40 and 43). This will keep you from getting a duplicate definition error since I had to include these files elsewhere.
4. make sure both line 84 and 85 are uncommented in exif_php.inc.php - I may have been able to avoid this and I'm not sure the history behind this file, but like I said above, this mod is meant to be quick and dirty to get the functionality to work...
$exifParsed[$lang_picinfo[$key]] = $val;
$exifParsed[$key] = $val;
5. now that the supporting files are in place, let's make the big changes to functions.inc.php. get_pic_data() is the function that queries the pictures table and populates a resultset already sorted. For any "album type" we want, we need to add a new variable (calling it 'ptime' as I have seen this used elsewhere in these forums) to the rowset, add ptime to the thumbnail caption, and then re-sort based on ptime if the user clicked one of the Date +/- sort headers:
5a. add the following line right before each call to build_caption() in get_pic_data() where you want to have access to ptime:
addDatePictureTaken($rowset);
5b. add the following to the bottom of the "build_caption" function (line 869) to allow display of the Date Taken field.
if (in_array('ptime',$must_have)) {
$caption .= "<span class=\"thumb_caption\">".$row['ptime'].'</span>';
}
5b. edit the build_caption call you located in 5a to include ptime. Here would be an example:
if ($set_caption) build_caption($rowset, array('ptime'));
5c. right before returning the $rowset, re-sort based on ptime by calling the following:
sortByDatePictureTaken(&$rowset, $sort_code);
Some notes/limitations:
- If you are on cpg148 and don't want to edit your functions.inc.php (steps #2 and #5 above), I have attached a version with the above edits
- The date is crudely formatted i.e. 2006:06:01 11:22:33. Feel free to edit step 5b above with php date functions to format nicely in the caption as it will not affect the sorting.
- My pictures were taken with Canon or were scanned pics that I used the application Exifer to add DateTimedigitized to the picture's exif data. I don't know of any problems you would have as the exif tags should be consistent, but just thought I'd mention it.
That's about it - let me know if you have any problems!
Tim
===