Advanced search  

News:

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

Pages: [1]   Go Down

Author Topic: 'Last upload Date' for albums with Keywords  (Read 4046 times)

0 Members and 1 Guest are viewing this topic.

gmc

  • Dev Team member
  • Coppermine addict
  • ****
  • Country: us
  • Offline Offline
  • Gender: Male
  • Posts: 623
    • GMC Design Photo Gallery
'Last upload Date' for albums with Keywords
« on: January 15, 2014, 07:02:47 PM »

I've used the album/picture keyword support to link photos to multiple albums.
In some cases, I rarely upload to the album, but regularly add linked photos.

Unfortunately, the album info display makes it appear the album hasn't had any changes (except for the linked count going up - which I doubt a user would remember from their last visit).

Example:
"6 files, last one added on Nov 08, 2007, 138 linked files, 144 files total" - appearing the album hasn't been updated since 2007.

With a couple of simple changes, I've set the date to the max of last uploaded to album, or max last uploaded date of a linked image.
All changes in index.php - based on 1.5.26 code base - $CONFIG['link_pic_count'] must be set for this to have any effect

For display in a category list (index.php?cat=x)
In function list_albums:
replace
Code: [Select]
                $query = "SELECT count(pid) AS link_pic_count, max(pid) AS link_last_pid "
with
Code: [Select]
                $query = "SELECT count(pid) AS link_pic_count, max(pid) AS link_last_pid, max(ctime) AS link_last_upload "    //*GMC -  changed to obtain last upload time via max(ctime) of linked photos

and replace (really an insert of second line only)
Code: [Select]
                $alb_stats[$key]['last_pid'] = ($alb_stats[$key]['last_pid'] > $link_stat['link_last_pid']) ? $alb_stats[$key]['last_pid'] : $link_stat['link_last_pid'];
with
Code: [Select]
                $alb_stats[$key]['last_pid'] = ($alb_stats[$key]['last_pid'] > $link_stat['link_last_pid']) ? $alb_stats[$key]['last_pid'] : $link_stat['link_last_pid'];
                $alb_stats[$key]['last_upload'] = ($alb_stats[$key]['last_upload'] > $link_stat['link_last_upload']) ? $alb_stats[$key]['last_upload'] : $link_stat['link_last_upload'];  //*GMC - update last_upload if linked pic was later...

For display on home page, (index.php) - similar changes - different function...
In function list_cat_albums:
replace
Code: [Select]
                $query = "SELECT count(pid) AS link_pic_count, max(pid) AS link_last_pid " 
with
Code: [Select]
                $query = "SELECT count(pid) AS link_pic_count, max(pid) AS link_last_pid, max(ctime) AS link_last_upload "    //*GMC -  changed to obtain last upload time via max(ctime) of linked photos

and replace (really an insert of second line only)
Code: [Select]
                $catdata['subalbums'][$aid]['last_pid'] = !empty($album['last_pid']) && ($album['last_pid'] > $link_stat['link_last_pid']) ? $album['last_pid'] : $link_stat['link_last_pid'];
with
Code: [Select]
                $catdata['subalbums'][$aid]['last_pid'] = !empty($album['last_pid']) && ($album['last_pid'] > $link_stat['link_last_pid']) ? $album['last_pid'] : $link_stat['link_last_pid'];
                $catdata['subalbums'][$aid]['last_upload'] = ($album['last_upload'] > $link_stat['link_last_upload']) ? $album['last_upload'] : $link_stat['link_last_upload'];  //*GMC - update last_upload if linked pic was later...

The above alone results in (same album as example above):
"6 files, last one added on Jan 29, 2013, 138 linked files, 144 files total" - a little misleading in that last add was linked file...

A couple more changes to reformat the message - in same two functions...
In function list_albums:
replace TWICE
(once in 'if' - again in immediately following 'else' - the two occurrences have a one space (insignificant) difference between current strings)
Code: [Select]
            $alb_list[$alb_idx]['album_info'] = sprintf($lang_list_albums['n_pictures'], $count) . ($count ? sprintf($lang_list_albums['last_added'], $last_upload_date) : "") . (($CONFIG['link_pic_count'] && $link_pic_count > 0 ) ? sprintf(", {$lang_list_albums['n_link_pictures']},  {$lang_list_albums['total_pictures']}", $link_pic_count, $count + $link_pic_count) : "");
with
Code: [Select]
            $alb_list[$alb_idx]['album_info'] = sprintf($lang_list_albums['n_pictures'], $count) . (($CONFIG['link_pic_count'] && $link_pic_count > 0 ) ? sprintf(", {$lang_list_albums['n_link_pictures']},  {$lang_list_albums['total_pictures']}", $link_pic_count, $count + $link_pic_count) : "") . (($count || ($CONFIG['link_pic_count'] && $link_pic_count > 0 )) ? sprintf($lang_list_albums['last_added'], $last_upload_date) : "");   //*GMC reformated message

And again - similar changes - different function...
In function list_cat_albums:
replace TWICE
(once in 'if' - again in immediately following 'else' - the two occurrences have a one space (insignificant) difference between current strings)
Code: [Select]
            $alb_list[$aid]['album_info'] = sprintf($lang_list_albums['n_pictures'], $album['pic_count']) . ($album['pic_count'] ? sprintf($lang_list_albums['last_added'], $last_upload_date) : "") . (($CONFIG['link_pic_count'] && $link_pic_count > 0)  ? sprintf(", {$lang_list_albums['n_link_pictures']}, {$lang_list_albums['total_pictures']}", $link_pic_count, $album['pic_count'] + $link_pic_count) : "");
with
Code: [Select]
            $alb_list[$aid]['album_info'] = sprintf($lang_list_albums['n_pictures'], $album['pic_count']) . (($CONFIG['link_pic_count'] && $link_pic_count > 0 ) ? sprintf(", {$lang_list_albums['n_link_pictures']},  {$lang_list_albums['total_pictures']}", $link_pic_count, $album['pic_count'] + $link_pic_count) : "") . (($album['pic_count'] || ($CONFIG['link_pic_count'] && $link_pic_count > 0 )) ? sprintf($lang_list_albums['last_added'], $last_upload_date) : "");   //*GMC reformated message

This changes the resulting message to read (same album as examples above):
"6 files, 138 linked files, 244 files total, last one added on Jan 29, 2013"

These changes are in place on http://greggallery.gmcdesign.com - specifically a view containing 2 albums with linked files: http://greggallery.gmcdesign.com/index.php?cat=20

If acceptable, I would like to suggest these changes be incorporated into the base?
I think it gives a more accurate view of updates to an album the user will see upon viewing.

(Ideally I'd like to see random and last loaded on the category page include linked files as well if $CONFIG['link_pic_count'] is set - but I haven't gotten that far in the code... Perhaps another thread.. looks like updates to function get_pic_data for meta albums 'lastup' and 'random' at least and maybe others if they consider album and/or cat... Any interest from others?.. :D )

Thanks!
Logged
Thanks!
Greg
My Coppermine Gallery
Need a web hosting account? See my gallery for an offer for CPG Forum users.
Send me money

Αndré

  • Administrator
  • Coppermine addict
  • *****
  • Country: de
  • Offline Offline
  • Gender: Male
  • Posts: 15257
Re: 'Last upload Date' for albums with Keywords
« Reply #1 on: January 16, 2014, 04:52:24 PM »

Could be added as option to cpg1.6.x and even to cpg1.5.x as hidden option (i.e. it won't show up on the config page, as we don't have an appropriate language string).

Please reply to my post so I can have a closer look at it later.
Logged

gmc

  • Dev Team member
  • Coppermine addict
  • ****
  • Country: us
  • Offline Offline
  • Gender: Male
  • Posts: 623
    • GMC Design Photo Gallery
Re: 'Last upload Date' for albums with Keywords
« Reply #2 on: January 16, 2014, 05:39:59 PM »

Replying as requested...

My thought (and the way I coded) was based on the existing config option:
$CONFIG['link_pic_count'] - "Show number of linked files" under "Album List View"

If showing the linked files was requested - then use the last date as 'max' of uploaded and linked data... as that will reflect the actual contents the user will see if they choose to view the album.
If the setting is not selected (or if the album in question does not have linked files), the code change has no effect...

I didn't change any language files to implement - just gathered the additional data and reordered the existing message segments (already separate entries in the language files.)

It could of course be an independent option if desired...

Thanks for taking the time to review.
Logged
Thanks!
Greg
My Coppermine Gallery
Need a web hosting account? See my gallery for an offer for CPG Forum users.
Send me money

Αndré

  • Administrator
  • Coppermine addict
  • *****
  • Country: de
  • Offline Offline
  • Gender: Male
  • Posts: 15257
Re: 'Last upload Date' for albums with Keywords
« Reply #3 on: January 16, 2014, 05:46:38 PM »

We should avoid to change the default layout if not necessary (e.g. for security reasons). You can be sure that it'll cause at least one support thread, that it now looks different and how to undo that change. That's why I want to add it as (hidden) opt-in feature, like I've done it already for several things in cpg1.5.x.
Logged

gmc

  • Dev Team member
  • Coppermine addict
  • ****
  • Country: us
  • Offline Offline
  • Gender: Male
  • Posts: 623
    • GMC Design Photo Gallery
Re: 'Last upload Date' for albums with Keywords
« Reply #4 on: January 16, 2014, 06:55:39 PM »

Understand.. recoded for a new (hidden for now) config option 'link_last_upload' to indicate use the upload date of the last linked file if greater than last upload...
If this new option is set - and link_pic_count is also set, then last upload date will be set to max of last upload and last linked pic upload - and message reformatted.
If this new option is off - or if no linked pictures in the album, this code has no effect.

Even if link_pic_count is NOT set today - it still takes effect if there are ONLY linked pictures in an album (not a change made here...)
This new option will be honored (on or off) in this case as well.

Consolidated to one set of updates for each function.

For display in a category list (index.php?cat=x)
In function list_albums:
replace
Code: [Select]
                $query = "SELECT count(pid) AS link_pic_count, max(pid) AS link_last_pid "
with
Code: [Select]
                $query = "SELECT count(pid) AS link_pic_count, max(pid) AS link_last_pid, max(ctime) AS link_last_upload "    //*GMC -  changed to obtain last upload time via max(ctime) of linked photos

replace
Code: [Select]
                $alb_stats[$key]['last_pid'] = ($alb_stats[$key]['last_pid'] > $link_stat['link_last_pid']) ? $alb_stats[$key]['last_pid'] : $link_stat['link_last_pid'];
with
Code: [Select]
                $alb_stats[$key]['last_pid'] = ($alb_stats[$key]['last_pid'] > $link_stat['link_last_pid']) ? $alb_stats[$key]['last_pid'] : $link_stat['link_last_pid'];
                if ($CONFIG['link_last_upload'] == 1 && $value['link_pic_count'] == 0) {                                                                                                    //*GMC - if  upload date of linked pics requested
                  $alb_stats[$key]['last_upload'] = ($alb_stats[$key]['last_upload'] > $link_stat['link_last_upload']) ? $alb_stats[$key]['last_upload'] : $link_stat['link_last_upload'];  //*GMC - update last_upload if linked pic was later...
                }                                                                                                                                                                           //*GMC

and replace TWICE
(once in 'if' - again in immediately following 'else' - the two occurrences have a one space (insignificant) difference between current strings)
Code: [Select]
            $alb_list[$alb_idx]['album_info'] = sprintf($lang_list_albums['n_pictures'], $count) . ($count ? sprintf($lang_list_albums['last_added'], $last_upload_date) : "") . (($CONFIG['link_pic_count'] && $link_pic_count > 0 ) ? sprintf(", {$lang_list_albums['n_link_pictures']},  {$lang_list_albums['total_pictures']}", $link_pic_count, $count + $link_pic_count) : "");
with
Code: [Select]
            if ($CONFIG['link_last_upload'] == 1) {                                                                                                      //*GMC - if  upload date of linked pics requested
              $alb_list[$alb_idx]['album_info'] = sprintf($lang_list_albums['n_pictures'], $count) . (($CONFIG['link_pic_count'] && $link_pic_count > 0 ) ? sprintf(", {$lang_list_albums['n_link_pictures']},  {$lang_list_albums['total_pictures']}", $link_pic_count, $count + $link_pic_count) : "") . (($count || ($CONFIG['link_pic_count'] && $link_pic_count > 0 )) ? sprintf($lang_list_albums['last_added'], $last_upload_date) : "");   //*GMC reformated message
            } else {                                                                                                                                     //*GMC - current message format if not requested
              $alb_list[$alb_idx]['album_info'] = sprintf($lang_list_albums['n_pictures'], $count) . ($count ? sprintf($lang_list_albums['last_added'], $last_upload_date) : "") . (($CONFIG['link_pic_count'] && $link_pic_count > 0 ) ? sprintf(", {$lang_list_albums['n_link_pictures']},  {$lang_list_albums['total_pictures']}", $link_pic_count, $count + $link_pic_count) : "");   //*GMC current message moved to 'else'
            }                                                                                                                                            //*GMC


For display on home page, (index.php) - similar changes - different function...
In function list_cat_albums:
replace
Code: [Select]
                $query = "SELECT count(pid) AS link_pic_count, max(pid) AS link_last_pid " 
with
Code: [Select]
                $query = "SELECT count(pid) AS link_pic_count, max(pid) AS link_last_pid, max(ctime) AS link_last_upload "    //*GMC -  changed to obtain last upload time via max(ctime) of linked photos

and replace
Code: [Select]
                $catdata['subalbums'][$aid]['last_pid'] = !empty($album['last_pid']) && ($album['last_pid'] > $link_stat['link_last_pid']) ? $album['last_pid'] : $link_stat['link_last_pid'];
with
Code: [Select]
                $catdata['subalbums'][$aid]['last_pid'] = !empty($album['last_pid']) && ($album['last_pid'] > $link_stat['link_last_pid']) ? $album['last_pid'] : $link_stat['link_last_pid'];
                if ($CONFIG['link_last_upload'] == 1 && $link_stat['link_pic_count'] == 0) {                                                                                       //*GMC - if  upload date of linked pics requested
                  $catdata['subalbums'][$aid]['last_upload'] = ($album['last_upload'] > $link_stat['link_last_upload']) ? $album['last_upload'] : $link_stat['link_last_upload'];  //*GMC - update last_upload if linked pic was later...
                }                                                                                                                                                                  //*GMC

and replace TWICE
(once in 'if' - again in immediately following 'else' - the two occurrences have a one space (insignificant) difference between current strings)
Code: [Select]
            $alb_list[$aid]['album_info'] = sprintf($lang_list_albums['n_pictures'], $album['pic_count']) . ($album['pic_count'] ? sprintf($lang_list_albums['last_added'], $last_upload_date) : "") . (($CONFIG['link_pic_count'] && $link_pic_count > 0)  ? sprintf(", {$lang_list_albums['n_link_pictures']}, {$lang_list_albums['total_pictures']}", $link_pic_count, $album['pic_count'] + $link_pic_count) : "");
with
Code: [Select]
            if ($CONFIG['link_last_upload'] == 1) {                                                                                                      //*GMC - if  upload date of linked pics requested
              $alb_list[$aid]['album_info'] = sprintf($lang_list_albums['n_pictures'], $album['pic_count']) . (($CONFIG['link_pic_count'] && $link_pic_count > 0 ) ? sprintf(", {$lang_list_albums['n_link_pictures']},  {$lang_list_albums['total_pictures']}", $link_pic_count, $album['pic_count'] + $link_pic_count) : "") . (($album['pic_count'] || ($CONFIG['link_pic_count'] && $link_pic_count > 0 )) ? sprintf($lang_list_albums['last_added'], $last_upload_date) : "");   //*GMC reformated message
            } else {                                                                                                                                     //*GMC - current message format if not requested
              $alb_list[$aid]['album_info'] = sprintf($lang_list_albums['n_pictures'], $album['pic_count']) . ($album['pic_count'] ? sprintf($lang_list_albums['last_added'], $last_upload_date) : "") . (($CONFIG['link_pic_count'] && $link_pic_count > 0)  ? sprintf(", {$lang_list_albums['n_link_pictures']}, {$lang_list_albums['total_pictures']}", $link_pic_count, $album['pic_count'] + $link_pic_count) : "");   //*GMC current message moved to 'else'
            }                                                                                                                                            //*GMC

This changes the resulting message to read:
"6 files, 138 linked files, 244 files total, last one added on Jan 29, 2013"

These changes are in place on http://greggallery.gmcdesign.com - specifically a view containing 2 albums with linked files: http://greggallery.gmcdesign.com/index.php?cat=20

Thanks!
Logged
Thanks!
Greg
My Coppermine Gallery
Need a web hosting account? See my gallery for an offer for CPG Forum users.
Send me money

Αndré

  • Administrator
  • Coppermine addict
  • *****
  • Country: de
  • Offline Offline
  • Gender: Male
  • Posts: 15257
Re: 'Last upload Date' for albums with Keywords
« Reply #5 on: January 20, 2014, 03:51:54 PM »

Currently we have the following information next to an album (cpg1.5.26 and earlier releases):

1. Album without linked files:
Quote
7 files, last one added on Jan 03, 2014

2. Album with "regular" and linked files:
Quote
14 files, last one added on Dec 18, 2013, 2 linked files, 16 files total

3. Album with just linked files:
Quote
0 files, 2 linked files, 2 files total

I haven't checked yet if your code already considers #3, but will check that soon, while reviewing and implementing your code proposal.
Logged

Αndré

  • Administrator
  • Coppermine addict
  • *****
  • Country: de
  • Offline Offline
  • Gender: Male
  • Posts: 15257
Re: Re: 'Last upload Date' for albums with Keywords
« Reply #6 on: January 20, 2014, 04:22:46 PM »

I haven't checked yet if your code already considers #3
It does, unfortunately $last_upload_date isn't populated in that case.

Additionally, I assume
Code: [Select]
$value['link_pic_count'] == 0and
Code: [Select]
$link_stat['link_pic_count'] == 0both should be
Code: [Select]
$link_stat['link_pic_count'] > 0as $value doesn't seem to contain the required data, which itself should be checked if it's greater than 0, right?
Logged

Αndré

  • Administrator
  • Coppermine addict
  • *****
  • Country: de
  • Offline Offline
  • Gender: Male
  • Posts: 15257
Re: 'Last upload Date' for albums with Keywords
« Reply #7 on: January 20, 2014, 04:31:21 PM »

Fix for #3:

Find
Code: [Select]
            $last_upload_date = $count ? localised_date($alb_stat['last_upload'], $lang_date['lastup']) : '';
            $link_pic_count = !empty($alb_stat['link_pic_count']) ? $alb_stat['link_pic_count'] : 0;
and replace with
Code: [Select]
            $link_pic_count = !empty($alb_stat['link_pic_count']) ? $alb_stat['link_pic_count'] : 0;
            $last_upload_date = ($count || ($CONFIG['link_pic_count'] && $link_pic_count > 0 )) ? localised_date($alb_stat['last_upload'], $lang_date['lastup']) : '';
twice.

Find
Code: [Select]
            $last_upload_date = $album['pic_count'] ? localised_date($album['last_upload'], $lang_date['lastup']) : '';
            $link_pic_count = !empty($album['link_pic_count']) ? $album['link_pic_count'] : 0;
and replace with
Code: [Select]
            $link_pic_count = !empty($album['link_pic_count']) ? $album['link_pic_count'] : 0;
            $last_upload_date = ($album['pic_count'] || ($CONFIG['link_pic_count'] && $link_pic_count > 0 )) ? localised_date($album['last_upload'], $lang_date['lastup']) : '';
twice.
Logged

Αndré

  • Administrator
  • Coppermine addict
  • *****
  • Country: de
  • Offline Offline
  • Gender: Male
  • Posts: 15257
Re: 'Last upload Date' for albums with Keywords
« Reply #8 on: January 20, 2014, 04:34:23 PM »

Patch file for unmodified cpg1.5.26 index.php file attached. Greg, please test that patch (I've applied minor changes) and report any unexpected behavior.
Logged

gmc

  • Dev Team member
  • Coppermine addict
  • ****
  • Country: us
  • Offline Offline
  • Gender: Male
  • Posts: 623
    • GMC Design Photo Gallery
Re: 'Last upload Date' for albums with Keywords
« Reply #9 on: January 20, 2014, 06:21:16 PM »

Seems I had a small 'source control' issue between my local source code I created the post with and my testbed code when testing the last set of changes... as I had found/corrected the $value/$link_stats and the ==/> issues.
I concur with your changes... $value was assigned 'by value' in the foreach - so doesn't contain the new 'link_pic_count' key... and the test should be > 0...
Sorry for that one...

I had not tested the 3rd case of only linked pictures - I saw the code would be invoked regardless of the setting of $CONFIG['link_pic_count'] - and made sure I honored the request of the new field - but my test cases didn't include that scenario. Thank you for finding/correcting that issue.
I've added that test case to my test gallery now...

Downloaded and applied the patch via TortoiseSVN against 1.5.26 - verified file contents on test server - and tested all 3 cases.
All work correctly now.

Thanks again for your time/effort.
Greg
Logged
Thanks!
Greg
My Coppermine Gallery
Need a web hosting account? See my gallery for an offer for CPG Forum users.
Send me money

Αndré

  • Administrator
  • Coppermine addict
  • *****
  • Country: de
  • Offline Offline
  • Gender: Male
  • Posts: 15257
Re: 'Last upload Date' for albums with Keywords
« Reply #10 on: January 21, 2014, 01:19:38 PM »

Added config option (cpg1.6.x) / hidden feature (cpg1.5.x) to regard upload time of linked files in album info in SVN revision 8647.

Marking thread as solved.
Logged

gmc

  • Dev Team member
  • Coppermine addict
  • ****
  • Country: us
  • Offline Offline
  • Gender: Male
  • Posts: 623
    • GMC Design Photo Gallery
Re: 'Last upload Date' for albums with Keywords
« Reply #11 on: January 21, 2014, 06:30:17 PM »

Αndré,
Downloaded the newest SVN and all looks good...
I'd mark the topic solved but you already did...  :D

Thanks for your time/effort!
Greg
Logged
Thanks!
Greg
My Coppermine Gallery
Need a web hosting account? See my gallery for an offer for CPG Forum users.
Send me money

Αndré

  • Administrator
  • Coppermine addict
  • *****
  • Country: de
  • Offline Offline
  • Gender: Male
  • Posts: 15257
Re: 'Last upload Date' for albums with Keywords
« Reply #12 on: January 21, 2014, 08:32:52 PM »

You're welcome :)
Logged

Αndré

  • Administrator
  • Coppermine addict
  • *****
  • Country: de
  • Offline Offline
  • Gender: Male
  • Posts: 15257
Re: 'Last upload Date' for albums with Keywords
« Reply #13 on: March 11, 2014, 01:06:05 PM »

FYI: I replaced some redundant code parts with a new function 'theme_album_info' in SVN revision 8673.
Logged
Pages: [1]   Go Up
 

Page created in 0.09 seconds with 20 queries.