Advanced search  

News:

cpg1.5.48 Security release - upgrade mandatory!
The Coppermine development team is releasing a security update for Coppermine in order to counter a recently discovered vulnerability. It is important that all users who run version cpg1.5.46 or older update to this latest version as soon as possible.
[more]

Pages: [1]   Go Down

Author Topic: Sort by EXIF date mod port  (Read 32025 times)

0 Members and 1 Guest are viewing this topic.

crabboy

  • Contributor
  • Coppermine newbie
  • ***
  • Offline Offline
  • Posts: 5
Sort by EXIF date mod port
« on: April 22, 2007, 05:16:22 am »

I just upgraded my coppermine from 1.3.x to 1.4.10 the other day and I was horrified to find out that I still can't sort by EXIF date.  I had used a fantastic mod many years ago to accomplish this and it was now gone.  I searched around quite a bit and there was no port of the Dannisk mod or similar, there seems to be only a script that can accomplish the same task.  Not wanting to deal with the script, I ported the 1.3 mod to 1.4.10.

This is a direct port of the Dannisk 'Sort by EXIF date or Upload Date per Album' mod.  Please read the features, caveats and instructions for this mod at the below link.

http://forum.coppermine-gallery.net/index.php?topic=9360.0


I will be using steps from his original post to save time and so all the steps will be below.  If you have previously modded 1.3 and upgraded to 1.4, as I did, you may skip Step 1. 


Step 1: Modifying the database

Change {$CONFIG['TABLE_PICTURES']} for your pictures tables (ex: cpg133_pictures):

Code: [Select]
ALTER TABLE `{$CONFIG['TABLE_PICTURES']}` ADD `ptime` INT NOT NULL AFTER `ctime`;

Step 2: Modifying file "include/functions.inc.php"

2.1 Replace (line 899,900):

Code: [Select]
           'da' => 'pid ASC',
           'dd' => 'pid DESC',

with:

Code: [Select]
           'da' => 'ptime ASC, pid ASC',
           'dd' => 'ptime DESC, pid DESC',

Step 3: Modifying file "include/picmgmt.inc.php"

3.1 Add after (line 22 )

Code: [Select]
if($CONFIG['read_iptc_data'] ){
        include("include/iptc.inc.php");
}

this:

Code: [Select]
if($CONFIG['read_exif_data'] ){
        include("include/exif_php.inc.php");
}

3.2 Add before (line 97 )

Code: [Select]
    // Test if picture requires approval
    if (GALLERY_ADMIN_MODE) {

this:

Code: [Select]
     if ( $CONFIG['read_exif_data'])
     {
         $exif = exif_parse_file($image, 1);


         $size = count($exif);
     }

     if (isset($exif) && is_array($exif) && isset($exif['DateTime'])) {
         // Transform EXIF date format to unixtime
         $picture_time = mktime(substr($exif['DateTime'], 11, 2), substr($exif['DateTime'], 14, 2), substr($exif['DateTime'], 17, 2), substr($exif['DateTime'], 5, 2), substr($exif['DateTime'], 8, 2),   substr($exif['DateTime'], 0, 4) );
       $creation_time = time();
     }
     else
     {
         $picture_time = time();
         $creation_time = $picture_time;
     }


3.3 Add after  (line 142) (line 114 before above additions)

Code: [Select]
$CURRENT_PIC_DATA['pheight'] = $imagesize[1];

this:

Code: [Select]
    $CURRENT_PIC_DATA['ptime'] = $picture_time;
   
3.4 Replace ( line 158 ) (line 130 before above additions )

Code: [Select]
    $query = "INSERT INTO {$CONFIG['TABLE_PICTURES']} (aid, filepath, filename, filesize, total_filesize, pwidth, pheight, ctime, owner_id, owner_name, title, caption, keywords, approved, user1, user2, user3, user4, pic_raw_ip, pic_hdr_ip, position) VALUES ('{$CURRENT_PIC_DATA['aid']}', '" . addslashes($CURRENT_PIC_DATA['filepath']) . "', '" . addslashes($CURRENT_PIC_DATA['filename']) . "', '{$CURRENT_PIC_DATA['filesize']}', '{$CURRENT_PIC_DATA['total_filesize']}', '{$CURRENT_PIC_DATA['pwidth']}', '{$CURRENT_PIC_DATA['pheight']}', '" . time() . "', '{$CURRENT_PIC_DATA['owner_id']}', '{$CURRENT_PIC_DATA['owner_name']}','{$CURRENT_PIC_DATA['title']}', '{$CURRENT_PIC_DATA['caption']}', '{$CURRENT_PIC_DATA['keywords']}', '{$CURRENT_PIC_DATA['approved']}', '{$CURRENT_PIC_DATA['user1']}', '{$CURRENT_PIC_DATA['user2']}', '{$CURRENT_PIC_DATA['user3']}', '{$CURRENT_PIC_DATA['user4']}', '{$CURRENT_PIC_DATA['pic_raw_ip']}', '{$CURRENT_PIC_DATA['pic_hdr_ip']}', '{$CURRENT_PIC_DATA['position']}')";

with:

Code: [Select]
     $query = "INSERT INTO {$CONFIG['TABLE_PICTURES']} (aid, filepath, filename, filesize, total_filesize, pwidth, pheight, ctime, ptime, owner_id, owner_name, title, caption, keywords, approved, user1, user2, user3, user4, pic_raw_ip, pic_hdr_ip, position) VALUES ('{$CURRENT_PIC_DATA['aid']}', '" . addslashes($CURRENT_PIC_DATA['filepath']) . "', '" . addslashes($CURRENT_PIC_DATA['filename']) . "', '{$CURRENT_PIC_DATA['filesize']}', '{$CURRENT_PIC_DATA['total_filesize']}', '{$CURRENT_PIC_DATA['pwidth']}', '{$CURRENT_PIC_DATA['pheight']}', '" . time() . "', '{$CURRENT_PIC_DATA['ptime']}', '{$CURRENT_PIC_DATA['owner_id']}', '{$CURRENT_PIC_DATA['owner_name']}','{$CURRENT_PIC_DATA['title']}', '{$CURRENT_PIC_DATA['caption']}', '{$CURRENT_PIC_DATA['keywords']}', '{$CURRENT_PIC_DATA['approved']}', '{$CURRENT_PIC_DATA['user1']}', '{$CURRENT_PIC_DATA['user2']}', '{$CURRENT_PIC_DATA['user3']}', '{$CURRENT_PIC_DATA['user4']}', '{$CURRENT_PIC_DATA['pic_raw_ip']}', '{$CURRENT_PIC_DATA['pic_hdr_ip']}', '{$CURRENT_PIC_DATA['position']}')";


Step 4: Modifying file "include/exif_php.inc.php"

This step is necessary since only selected elements of the exif data are returned for display.  When calling the exif method when adding a file, all the exif data needs to be returned.

4.1 Replace (line 27)

Code: [Select]
  function exif_parse_file($filename)

with:

Code: [Select]
  function exif_parse_file($filename, $addfile )

4.2 Replace for loop: (line 85 )

Code: [Select]
         foreach ($exif as $key => $val) {
           if (strpos($showExifStr,"|".$key) && isset($val)){
                 $exifParsed[$lang_picinfo[$key]] = $val;
                 //$exifParsed[$key] = $val;
           }

with:

Code: [Select]
         foreach ($exif as $key => $val)
         {
             if ( $addfile == 0 )
             {
                if (strpos($showExifStr,"|".$key) && isset($val))
                {
                    $exifParsed[$lang_picinfo[$key]] = $val;
                }
             }
             else
                $exifParsed[$key] = $val;

Step 5: Modifying file "displayimage.php"

5.1 Replace ( line 152 )

Code: [Select]
     if ($CONFIG['read_exif_data']) $exif = exif_parse_file($path_to_pic);

with:

Code: [Select]
     if ($CONFIG['read_exif_data']) $exif = exif_parse_file($path_to_pic, 0);

Step 6: Modifying file "util.php"

6.1 Add Before: (line 54 )

Code: [Select]
        'del_titles' => array('del_titles', $lang_util_php['delete_title'], $lang_
util_php['delete_title_explanation']),

this:

Code: [Select]
'exif_date' => array('updatesortingdate', $lang_util_php['update_sort'],'<b>'. $lang_util_php['update_sort_what'] .' (2):</b><br />
        <input type="radio" name="dateselect" checked="checked" value="0" id="exif" class="nobg" /><label for="exif" accesskey="x" class="labelradio">'. $lang_util_php['update_sort_exif'] .'</label><br />
        <input type="radio" name="dateselect" value="1" id="cdate" class="nobg" /><label for="cdate" accesskey="c" class="labelradio">'.$lang_util_php['update_sort_creation'] .'</label><br /> <br />'),

6.2 Add Before:  (line 217)

Code: [Select]
function filloptions()

this:

Code: [Select]
function updatesortingdate()
{
     $albumid = $_POST['albumid'];
     $dateselect = $_POST['dateselect'];
     global $lang_util_php, $CONFIG;

     $query = "SELECT UNIX_TIMESTAMP(mtime) as mtime, {$CONFIG['TABLE_PICTURES']}.* FROM {$CONFIG['TABLE_PICTURES']} WHERE aid = '$albumid'";
     $result = MYSQL_QUERY($query);
     $num = mysql_numrows($result);

     $i = 0;
     while ($i < $num) {
         $filename = $CONFIG['fullpath'] . mysql_result($result, $i, "filepath") . mysql_result($result, $i, "filename");
         $pid = mysql_result($result, $i, "pid");
       $pdate = mysql_result($result, $i, "ctime");

         if($dateselect == '0')
         {
             $query = "SELECT * FROM {$CONFIG['TABLE_EXIF']} WHERE filename='$filename' ";
             $result2 = MYSQL_QUERY($query);

             if(mysql_numrows($result2) == 1)
             {
                 $exif = unserialize(mysql_result($result2, 0, "exifData"));

                 if (isset($exif) && is_array($exif) && isset($exif['DateTime']))
                 {
                     $pdate = mktime(substr($exif['DateTime'], 11, 2), substr($exif['DateTime'], 14, 2), substr($exif['DateTime'], 17, 2), substr($exif['DateTime'], 5, 2), substr($exif['DateTime'], 8, 2),       substr($exif['DateTime'], 0, 4) );
                 }

                 $newdate = date('Y:m:d H:i:s', $pdate);
             }
          else
         {
             $newdate = $lang_util_php['update_sort_no_exif'];
         }
     }
         else // Creation date
         {
               $newdate = date('Y:m:d H:i:s', $pdate);
         }

         print $lang_util_php['file'] . ': '. $filename.' &rArr; '. $newdate .'<br />';
         my_flush();

         $query = "UPDATE {$CONFIG['TABLE_PICTURES']} SET ptime='$pdate' WHERE pid='$pid' ";
         MYSQL_QUERY($query);

         ++$i;
     }
}

Step 7: Modifying the language files lang/english.php

7.1 Add after ( line 1907)

Code: [Select]
$lang_util_php = array(

this:

Code: [Select]
  'update_sort' => 'Update Sorting Date Filed',
  'update_sort_what' => 'Choose which date will be used to sort the pictures',
  'update_sort_exif' => 'Picture taken date - EXIF (If no date if found the upload
 date will be used.)',
  'update_sort_creation' => 'Upload date',
  'update_sort_no_exif' => 'No EXIF data',


Step 8: Modifying the sorting date for your old pictures

Log in as Admin, go to the Admin Tools and follow the instruction for Update Sorting Date Field


I'll attempt to attach a patch file that will patch the 1.4.10 version.  Drop the file into the coppermine directory and run with:
Code: [Select]
patch -b -p1 < patch-sortByEXIF-1.4.10.txt

Thanks to Dannisk for this great mod 3 years ago.  I spent about an hour hacking the mod in and another hour creating the patch and writing this doc, ugh...

Gary

// Edit Apr 24 - Updated to include bioman's corrections below.  Thanks bioman
« Last Edit: May 07, 2007, 05:47:58 pm by GauGau »
Logged

bioman

  • Coppermine newbie
  • Offline Offline
  • Posts: 16
Re: Sort by EXIF date mod port
« Reply #1 on: April 23, 2007, 06:55:31 pm »

Wow !!

THAT IS GREAT NEWS !

Moderators, it might be a good idea to PIN this thread for a while...

SO many people begged for a good soul to port Dannisk's work for 1.4.x :-)

Now, I can upgrade (and test your work Crabboy :-) ) !
Talk about chance, I was currently working on changing ALL my directory names and picture table accordingly to remove all special characters... in order to plan this upgrade anyway !

Thanx again Crabboy (I'll soon come back to report my feedback)
Logged

bioman

  • Coppermine newbie
  • Offline Offline
  • Posts: 16
Re: Sort by EXIF date mod port
« Reply #2 on: April 24, 2007, 02:19:32 pm »

Hi again !

It didn't take long before I cuold check !

The overall work seems to work perfectly FINE !
I have 2 galleries : one 1.3 (modified)... and one 1.4.10.
After this mod, the photos are shown the same way which, TO ME, is vital !!!!

Thanx again Crabboy !!!

ALTHOUGH, there are a few typos that need to be corrected...

In the util.php
1- The text area side has been cut so it's not that easy to import it if your a beginner...
Replace
Code: [Select]
'exif_date' => array('updatesortingdate', $lang_util_php['update_sort'],'
                <b>'. $lang_util_php['update_sort_what'] .' (2):<br />
        <input type="radio" name="dateselect" checked="checked" value="0" id="exif
" class="nobg" /><label for="exif" accesskey="x" class="labelradio">'. $lang_util_
php['update_sort_exif'] .'</label><br />
        <input type="radio" name="dateselect" value="1" id="cdate" class="nobg" />
<label for="cdate" accesskey="c" class="labelradio">'. $lang_util_php['update_sort
_creation'] .'</label><br /> <br />'),

By :
Code: [Select]
'exif_date' => array('updatesortingdate', $lang_util_php['update_sort'],'<b>'. $lang_util_php['update_sort_what'] .' (2):</b><br />
        <input type="radio" name="dateselect" checked="checked" value="0" id="exif" class="nobg" /><label for="exif" accesskey="x" class="labelradio">'. $lang_util_php['update_sort_exif'] .'</label><br />
        <input type="radio" name="dateselect" value="1" id="cdate" class="nobg" /><label for="cdate" accesskey="c" class="labelradio">'.$lang_util_php['update_sort_creation'] .'</label><br /> <br />'),<br />'),

2- the updatesortingdate function has { problems... MEANING YOU CAN'T EVEN OPEN THE UTIL PAGE !!!!

Replace
Code: [Select]
function updatesortingdate()
 {
     $albumid = $_POST['albumid'];
     $dateselect = $_POST['dateselect'];
     global $lang_util_php, $CONFIG;

     $query = "SELECT UNIX_TIMESTAMP(mtime) as mtime, {$CONFIG['TABLE_PICTURES']}.* FROM $CONFIG['TABLE_PICTURES']} WHERE aid = '$albumid'";
     $result = MYSQL_QUERY($query);
     $num = mysql_numrows($result);

     $i = 0;
     while ($i < $num) {
         $filename = $CONFIG['fullpath'] . mysql_result($result, $i, "filepath") . mysql_result($result, $i, "filename");
         $pid = mysql_result($result, $i, "pid");
       $pdate = mysql_result($result, $i, "ctime");

         if($dateselect == '0')
         {
             $query = "SELECT * FROM {$CONFIG['TABLE_EXIF']} WHERE filename='$filename' ";
             $result2 = MYSQL_QUERY($query);

             if(mysql_numrows($result2) == 1)
             {
                 $exif = unserialize(mysql_result($result2, 0, "exifData"));

                 if (isset($exif) && is_array($exif) && isset($exif['DateTime']))
                 {
                     $pdate = mktime(substr($exif['DateTime'], 11, 2), substr($exif['DateTime'], 14, 2), substr($exif['DateTime'], 17, 2), substr($exif['DateTime'], 5, 2), substr($exif['DateTime'], 8, 2),       substr($exif['DateTime'], 0, 4) );
                 }

                 $newdate = date('Y:m:d H:i:s', $pdate);
           }
         else
         {
             $newdate = $lang_util_php['update_sort_no_exif'];
         }
                               else // Creation date
                               {
                                       $newdate = date('Y:m:d H:i:s', $pdate);
                               }

         print $lang_util_php['file'] . ': '. $filename.' &rArr; '. $newdate .'<br />';
         my_flush();

         $query = "UPDATE {$CONFIG['TABLE_PICTURES']} SET ptime='$pdate' WHERE pid='$pid' ";
         MYSQL_QUERY($query);

         ++$i;
     }
 }

By :
Code: [Select]
function updatesortingdate()
{
     $albumid = $_POST['albumid'];
     $dateselect = $_POST['dateselect'];
     global $lang_util_php, $CONFIG;

     $query = "SELECT UNIX_TIMESTAMP(mtime) as mtime, {$CONFIG['TABLE_PICTURES']}.* FROM {$CONFIG['TABLE_PICTURES']} WHERE aid = '$albumid'";
     $result = MYSQL_QUERY($query);
     $num = mysql_numrows($result);

     $i = 0;
     while ($i < $num) {
         $filename = $CONFIG['fullpath'] . mysql_result($result, $i, "filepath") . mysql_result($result, $i, "filename");
         $pid = mysql_result($result, $i, "pid");
       $pdate = mysql_result($result, $i, "ctime");

         if($dateselect == '0')
         {
             $query = "SELECT * FROM {$CONFIG['TABLE_EXIF']} WHERE filename='$filename' ";
             $result2 = MYSQL_QUERY($query);

             if(mysql_numrows($result2) == 1)
             {
                 $exif = unserialize(mysql_result($result2, 0, "exifData"));

                 if (isset($exif) && is_array($exif) && isset($exif['DateTime']))
                 {
                     $pdate = mktime(substr($exif['DateTime'], 11, 2), substr($exif['DateTime'], 14, 2), substr($exif['DateTime'], 17, 2), substr($exif['DateTime'], 5, 2), substr($exif['DateTime'], 8, 2),       substr($exif['DateTime'], 0, 4) );
                 }

                 $newdate = date('Y:m:d H:i:s', $pdate);
             }
          else
         {
             $newdate = $lang_util_php['update_sort_no_exif'];
         }
     }
         else // Creation date
         {
               $newdate = date('Y:m:d H:i:s', $pdate);
         }

         print $lang_util_php['file'] . ': '. $filename.' &rArr; '. $newdate .'<br />';
         my_flush();

         $query = "UPDATE {$CONFIG['TABLE_PICTURES']} SET ptime='$pdate' WHERE pid='$pid' ";
         MYSQL_QUERY($query);

         ++$i;
     }
}

Finally, a smal addon if you're using the French language :
On the French.php, after line 1904 :
Code: [Select]
$lang_util_php = array(
Add :
Code: [Select]
  'update_sort' => 'Mettre ŕ jour le champs qui permet de trier par date',
  'update_sort_what' => 'Choisir la date qui servira pour trier les photos',
  'update_sort_exif' => 'Date de la prise de photo - EXIF (S\'il n\'y a pas de date, la date du téléchargement sera utilisée.)',
  'update_sort_creation' => 'Date du téléchargement',
  'update_sort_no_exif' => 'Aucune donnée EXIF',

Now, if you're lazy ( :-) ), here's a zip file containing the 7 modified files :

Bye and thanx again Crabboy !
Logged

crabboy

  • Contributor
  • Coppermine newbie
  • ***
  • Offline Offline
  • Posts: 5
Re: Sort by EXIF date mod port
« Reply #3 on: April 24, 2007, 03:22:40 pm »

Thanks bioman.  I built the post by cutting and pasting from the diff displayed in Putty and it looks like it wrapped some of the longer lines.  I also tried to preserve the ^M characters since many use it on Windows, but  it's difficult to keep track of them in the Linux shell.

I've Updated the exif_date and the updatesortingdate() sections to include your changes so the users only have to do it once.

The patchfile is still untested, but I think it should work.  it doesn't contain the handy work of human error. :)

Logged

Nick99

  • Coppermine newbie
  • Offline Offline
  • Posts: 1
Re: Sort by EXIF date mod port
« Reply #4 on: May 05, 2007, 11:00:05 am »

Hi,

i c&p the hack out off the posting and it is not working.

If i add new pictures it works fine but i can't update the old ones.

But first i had to correct this ...

Code: [Select]
'exif_date' => array('updatesortingdate', $lang_util_php['update_sort'],'<b>'. $lang_util_php['update_sort_what'] .' (2):</b><br />
        <input type="radio" name="dateselect" checked="checked" value="0" id="exif" class="nobg" /><label for="exif" accesskey="x" class="labelradio">'. $lang_util_php['update_sort_exif'] .'</label><br />
        <input type="radio" name="dateselect" value="1" id="cdate" class="nobg" /><label for="cdate" accesskey="c" class="labelradio">'.$lang_util_php['update_sort_creation'] .'</label><br /> <br />'),<br />'),

This "<br />')," at the end seems wrong because it causes a syntax error.

I replaced 'DateTime' with 'DateTimedigitized' because it works better for me.

I can't figure out why the admin tool doesn't work but it seems to me that the function is not called. Please check this.

Bye Nick

Logged

crabboy

  • Contributor
  • Coppermine newbie
  • ***
  • Offline Offline
  • Posts: 5
Re: Sort by EXIF date mod port
« Reply #5 on: May 07, 2007, 04:07:52 pm »

Quote
This "<br />')," at the end seems wrong because it causes a syntax error.
Yes, it seems you are correct, I took a look at my source and I did not have the extra <br />

Here is the section as it appears on my machine:
Code: [Select]
        'exif_date' => array('updatesortingdate', $lang_util_php['update_sort'],'

                <b>'. $lang_util_php['update_sort_what'] .' (2):<br />       
                <input type="radio" name="dateselect" checked="checked" value="0" id="exif" class="nobg" /><label for="exif" accesskey="x" class="labelradio">'. $lang_util_php['update_sort_exif'] .'</label><br />       
                <input type="radio" name="dateselect" value="1" id="cdate" class="nobg" /><label for="cdate" accesskey="c" class="labelradio">'. $lang_util_php['update_sort_creation'] .'</label><br /> <br />'),
Logged

Forrest Gump

  • Coppermine newbie
  • Offline Offline
  • Posts: 3
Re: Sort by EXIF date mod port
« Reply #6 on: September 11, 2007, 03:07:41 pm »

Hello, first of all thanx for great programming.

i c&p the hack out off the posting and it is not working.

If i add new pictures it works fine but i can't update the old ones.

Is there a solution meanwhile? Sorry, but I can't figure it out. After successfuly doing the mod and updating the sortorder by exif in the admin-tools, there's no change at all.

`ptime` int(11) NOT NULL COMMENT 'exifmod',
`position` int(11) NOT NULL default '0',

All above fields in the DB table pictures were filled with "0"

With new pics it works fine, thanx again.

Gruß, Forrest  :-*

http://hellraisers.web157.webgo24-server11.de/hr-coppermine/thumbnails.php?album=4
Logged

Forrest Gump

  • Coppermine newbie
  • Offline Offline
  • Posts: 3
Re: Sort by EXIF date mod port
« Reply #7 on: September 14, 2007, 02:26:17 am »

 ;D Hello again,

I've found some errors and modified the "Sort by EXIF date mod port" so that it now works as it was indended to do. It's primarily desinged for "old" pictures, that have been in the DB before doing the "Sort by EXIF date mod port".


Affected files:

util.php, english.php (+ german.php + german_sie.php)


Step 1. regarding to Step 6: Modifying file "util.php" 6.1

Probably here I've found the biggest error, the old function updatesortingdate() never could be executed due to this part of the code:

Code: [Select]
'exif_date' => array('updatesortingdate',
It had to be the same name. I've corrected it and by the way use another name for the function, regarding to what it really does. Also I've added another option. Now there are 3 options:

  • EXIF DateTimeOriginal or nothing
  • EXIF DateTimeOriginal or Upload Date
  • Upload Date

Replace the code below with the one in Step 6: Modifying file "util.php" 6.1

Code: [Select]
// exifmod
  'put_date_to_ptime' => array(
                                'put_date_to_ptime',
                                $lang_util_php['put_ptime'],
                                '<b>'. $lang_util_php['put_ptime_what'].' (2):</b><br />
                                <input type="radio" name="choice" checked="checked" value="0" id="exif" class="nobg" /><label for="exif" class="labelradio">'. $lang_util_php['put_ptime_exif'] .'</label><br />
                                <input type="radio" name="choice" value="1" id="exif_or_upload" class="nobg" /><label for="exif_or_upload" class="labelradio">'. $lang_util_php['put_ptime_exif_or_upload'] .'</label><br />
                                <input type="radio" name="choice" value="2" id="upload" class="nobg" /><label for="upload" class="labelradio">'. $lang_util_php['put_ptime_upload'] .'</label><br /> <br />'
                              ),
// exifmodend


Step 2. regarding to Step 6: Modifying file "util.php" 6.2

Replace the code below with the one in Step 6: Modifying file "util.php" 6.2

Code: [Select]
// exifmod
function put_date_to_ptime()
{
  global $CONFIG, $lang_util_php;

  echo "<b>{$lang_util_php['put_ptime_wait']}</b><br /><br />";

  $choice = $_POST['choice'];
  $albumid = (isset($_POST['albumid'])) ? $_POST['albumid'] : 0;
  $albstr = ($albumid) ? "WHERE aid = $albumid" : '';
  $result = cpg_db_query("SELECT * FROM {$CONFIG['TABLE_PICTURES']} $albstr");

  while ($row = mysql_fetch_assoc($result)){
    $fileadr = $CONFIG['fullpath'] . $row['filepath'] . $row['filename'];
    $pid = $row['pid'];
    $ctime = $row['ctime'];
    $filename = $row['filename'];

    switch ($choice){
      case 0: // put_ptime_exif
              if(read_exif_data("$fileadr")) {
                $exif = read_exif_data("$fileadr");
                $date = $exif['DateTimeOriginal'] ? $exif['DateTimeOriginal'] : '';
                $message = $date;
              }
              else {
                $date = '';
                $message = $date;
              }
              break;
      case 1: // put_ptime_exif_or_upload
              if(read_exif_data("$fileadr")) {
                $exif = read_exif_data("$fileadr");
                if($exif['DateTimeOriginal']) {
                  $date = $exif['DateTimeOriginal'];
                  $message = $date;
                }
                else {
                  $date = $ctime ? $ctime : '';
                  $message = $date . " <b>ctime</b>";
                }
              }
              break;
      case 2: // put_ptime_upload
              $date = date("Y:m:d H:i:s", $ctime);
              $message = $date . " <b>ctime</b>";
              break;
    }
    $date = mktime(substr($date, 11, 2), substr($date, 14, 2), substr($date, 17, 2), substr($date, 5, 2), substr($date, 8, 2), substr($date, 0, 4) );
    $query = cpg_db_query("UPDATE {$CONFIG['TABLE_PICTURES']} SET ptime = '$date' WHERE pid = '$pid'");
    if ($query) echo "<span style='white-space:nowrap'>" . $message . " => ptime (" . $filename . ")<span><br />";
  }
  echo "<br /><br /><b>{$lang_util_php['put_ptime_success']}</b><br /><br />";
}
// exifmodend

What the function does?

It just reads the EXIF DateTimeOriginal if present out of the original file, using the php function read_exif_data(), transforms it in UnixTimeStamp and writes it in the TABLE_PICTURES field ptime. Optionaly (and/or) reads the value of TABLE_PICTURES field ctime and writes it to ptime.

Thats all.

Comment:

It was much easier for me to read the EXIF data directly from the file, than out of the TABLE_EXIF, most of all only EXIF data of already seen pictures exist in TABLE_EXIF. Above all I used the DateTimeOriginal instead of DateTime, since some software seams to change the EXIF DateTime, but not the EXIF DateTimeOriginal.


Step 3. regarding to Step 7: Modifying the language files lang/english.php 7.1

Use code below instead

Code: [Select]
// exifmod
  'put_ptime' => 'Put date in DB (TABLES_PICTURES ptime) per feature "sort by date"',
  'put_ptime_what' => 'Choose which date will be used',
  'put_ptime_exif' => 'EXIF DateTimeOriginal (shooting date) (If not present - <b>empty field</b>)',
  'put_ptime_exif_or_upload' => 'EXIF DateTimeOriginal (shooting date) (If not present - <b>upload date</b>)',
  'put_ptime_upload' => 'upload date',
  'put_ptime_success' => 'Putting date in DB (TABLES_PICTURES ptime) succeeded',
// exifmodend

for german.php use code below

Code: [Select]
// exifmod
  'put_ptime' => 'Schreibe Datum in DB (TABLES_PICTURES ptime). Betrifft "Sortierung nach Datum"',
  'put_ptime_what' => 'W&auml;hle das gew&uuml;nschte Datum',
  'put_ptime_exif' => 'EXIF DateTimeOriginal (Aufnahmedatum) (Wenn nicht vorhanden, <b>leeres Feld</b>.)',
  'put_ptime_exif_or_upload' => 'EXIF DateTimeOriginal (Aufnahmedatum) (Wenn nicht vorhanden, <b>Upload Datum</b>.)',
  'put_ptime_upload' => 'Upload Datum',
  'put_ptime_wait' => 'Bitte warten, Felder "TABLES_PICTURES ptime" werden geschrieben',
  'put_ptime_success' => 'Daten erfolgreich in Datenbank (TABLES_PICTURES ptime) eingetragen',
// exifmodend

for german_sie.php use code below

Code: [Select]
/ /exifmod
  'put_ptime' => 'Schreibe Datum in DB (TABLES_PICTURES ptime). Betrifft "Sortierung nach Datum"',
  'put_ptime_what' => 'W&auml;hlen Sie das gew&uuml;nschte Datum',
  'put_ptime_exif' => 'EXIF DateTimeOriginal (Aufnahmedatum) (Wenn nicht vorhanden, <b>leeres Feld</b>.)',
  'put_ptime_exif_or_upload' => 'EXIF DateTimeOriginal (Aufnahmedatum) (Wenn nicht vorhanden, <b>Upload Datum</b>.)',
  'put_ptime_upload' => 'Upload Datum',
  'put_ptime_wait' => 'Bitte warten, Felder "TABLES_PICTURES ptime" werden geschrieben',
  'put_ptime_success' => 'Daten erfolgreich in Datenbank (TABLES_PICTURES ptime) eingetragen',
// exifmodend


Finally, but only if you want to show a hint to the new function on top of the admin-tools page, add the code below into english.php

after:

Code: [Select]
if (defined('UTIL_PHP')) {
$lang_util_desc_php = array(

add:

Code: [Select]
// exifmod
'Puts shooting date (EXIF DateTimeOriginal) <b>or</b> upload date to DB, per feature "sort by date"',
// exifmodend

into german.php and german_sie.php add:

Code: [Select]
// exifmod
'Schreibt Aufnahme-Datum (EXIF DateTimeOriginal) <b>oder</b> Upload-Datum in die DB, zur Sortierung nach Datum',
// exifmodend

Please let me know if it works, bye and thanxs to all, Forrest
Logged

apassio

  • Coppermine novice
  • *
  • Offline Offline
  • Posts: 35
    • Christine & Son's website
Re: Sort by EXIF date mod port
« Reply #8 on: November 19, 2007, 07:04:54 pm »

I saw several incremental upgrades to this mod. I have just upgraded to cpg1.4.14.

Is there a total package / patch that can be used in one step to get this functionality of sorting by exif date.

Also, I am confused whether the mod will only apply to old pictures or also to newly uploaded ones.

Thanks
Logged

Joachim Müller

  • Dev Team member
  • Coppermine addict
  • ****
  • Offline Offline
  • Gender: Male
  • Posts: 47843
  • aka "GauGau"
    • gaugau.de
Re: Sort by EXIF date mod port
« Reply #9 on: November 19, 2007, 07:22:47 pm »

Is there a total package / patch that can be used in one step to get this functionality of sorting by exif date.
No.
Logged

Megachip

  • Coppermine novice
  • *
  • Offline Offline
  • Posts: 35
Re: Sort by EXIF date mod port
« Reply #10 on: February 09, 2008, 05:26:48 pm »

Is it possible to create one? e.g. a plugin? Or include this directly into cpg?
Logged

Joachim Müller

  • Dev Team member
  • Coppermine addict
  • ****
  • Offline Offline
  • Gender: Male
  • Posts: 47843
  • aka "GauGau"
    • gaugau.de
Re: Sort by EXIF date mod port
« Reply #11 on: February 10, 2008, 12:31:13 am »

This is not the feature requests board. This thread deals with a mod. Per definition, a mod requires code to be edited. You're welcome to convert this into a plugin. Currently, there is only this mod available, but no plugin that does the same. Please keep the discussion on this thread to what it was meant for.
Logged

diedhert

  • Coppermine novice
  • *
  • Offline Offline
  • Posts: 35
Re: Sort by EXIF date mod port
« Reply #12 on: September 19, 2008, 06:56:07 am »

Can someone explain me how to alter a database (step1). Sorry if this is a dumb question.
Logged

Joachim Müller

  • Dev Team member
  • Coppermine addict
  • ****
  • Offline Offline
  • Gender: Male
  • Posts: 47843
  • aka "GauGau"
    • gaugau.de
Re: Sort by EXIF date mod port
« Reply #13 on: September 19, 2008, 07:52:42 am »

You run a query in a third party tool like phpMyAdmin or in a custom PHP file. Might not be obvious to everyone: the stuff in curly brackets has to be replaced with the actual table name of coppermine's config table when running the query in phpMyAdmin.
Logged

diedhert

  • Coppermine novice
  • *
  • Offline Offline
  • Posts: 35
Re: Sort by EXIF date mod port
« Reply #14 on: September 19, 2008, 08:06:47 am »

Thanks,

I applied all changes but the MOD does not seem to work.
I do not get any errors, but EXIF date (capture time, etc...) is not shown when viewing pictures, but it is shown when I replace the files with the ones where the mod is not installed.  The pictures are not sorted by capturer time.

So I presume something is wrong. However, I have poor knowledge of all these things. Where should I start to see why this mod is not working ? 

Thanks for any help.
Logged

ff

  • Coppermine frequent poster
  • ***
  • Offline Offline
  • Gender: Male
  • Posts: 108
Re: Sort by EXIF date mod port
« Reply #15 on: December 21, 2008, 09:31:44 am »

Thanks,

I applied all changes but the MOD does not seem to work.
I do not get any errors, but EXIF date (capture time, etc...) is not shown when viewing pictures, but it is shown when I replace the files with the ones where the mod is not installed.  The pictures are not sorted by capturer time.

So I presume something is wrong. However, I have poor knowledge of all these things. Where should I start to see why this mod is not working ? 

Thanks for any help.

In util.php I had to replace "DateTimeOriginal" by "DateTimedigitized" as my DateTimeOriginal is empty.
I now have entries in my records. But can't see if the sorting is working.

I had my pictures sorted by title which have the date typed in.
Logged

ThunderBoy

  • Coppermine newbie
  • Offline Offline
  • Gender: Male
  • Posts: 5
    • Photograph
Re: Sort by EXIF date mod port
« Reply #16 on: October 13, 2010, 05:29:28 pm »

This i need to implant in version 1.5.8.
I tried it, but the source is already different and so good and i'm not a programmer.
I wonder why it is not yet been added to the new version.
Someone did not do a new version of some kind of mod? ???

In the gallery i have several albums in which i or one type of shift does not work correctly.
Photos of me throws all sorts, but not in the order, as were shot.

Also, i wonder why it is not already solved and the order for each album separately.
I had just recently done in http://www.gallery2.org/ photo gallery and have it there the treated perfectly.
I do not know why the coppermine do not use the information from Exif.. To go with the times.  ::)
Logged
I apologize for my english :)

Joachim Müller

  • Dev Team member
  • Coppermine addict
  • ****
  • Offline Offline
  • Gender: Male
  • Posts: 47843
  • aka "GauGau"
    • gaugau.de
Re: Sort by EXIF date mod port
« Reply #17 on: October 13, 2010, 06:29:21 pm »

Don't ask for other versions. You need it -> you port it.
Locking.
Logged
Pages: [1]   Go Up
 

Page created in 0.039 seconds with 20 queries.