'Last upload Date' for albums with Keywords 'Last upload Date' for albums with Keywords
 

News:

CPG Release 1.6.26
Correct PHP8.2 issues with user and language managers.
Additional fixes for PHP 8.2
Correct PHP8 error with SMF 2.0 bridge.
Correct IPTC supplimental category parsing.
Download and info HERE

Main Menu

'Last upload Date' for albums with Keywords

Started by gmc, January 15, 2014, 06:02:47 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

gmc

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

                $query = "SELECT count(pid) AS link_pic_count, max(pid) AS link_last_pid "

with

                $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)

                $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

                $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

                $query = "SELECT count(pid) AS link_pic_count, max(pid) AS link_last_pid " 

with

                $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)

                $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

                $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)

            $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

            $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)

            $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

            $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!
Thanks!
Greg
My Coppermine Gallery
Need a web hosting account? See my gallery for an offer for CPG Forum users.
Send me money

Αndré

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.

gmc

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.
Thanks!
Greg
My Coppermine Gallery
Need a web hosting account? See my gallery for an offer for CPG Forum users.
Send me money

Αndré

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.

gmc

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

                $query = "SELECT count(pid) AS link_pic_count, max(pid) AS link_last_pid "

with

                $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

                $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

                $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)

            $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

            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

                $query = "SELECT count(pid) AS link_pic_count, max(pid) AS link_last_pid " 

with

                $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

                $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

                $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)

            $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

            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!
Thanks!
Greg
My Coppermine Gallery
Need a web hosting account? See my gallery for an offer for CPG Forum users.
Send me money

Αndré

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

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

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

3. Album with just linked files:
Quote0 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.

Αndré

Quote from: Αndré on January 20, 2014, 02:51:54 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
$value['link_pic_count'] == 0
and
$link_stat['link_pic_count'] == 0
both should be
$link_stat['link_pic_count'] > 0
as $value doesn't seem to contain the required data, which itself should be checked if it's greater than 0, right?

Αndré

Fix for #3:

Find
            $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
            $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
            $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
            $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.

Αndré

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.

gmc

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
Thanks!
Greg
My Coppermine Gallery
Need a web hosting account? See my gallery for an offer for CPG Forum users.
Send me money

Αndré

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.

gmc

Α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
Thanks!
Greg
My Coppermine Gallery
Need a web hosting account? See my gallery for an offer for CPG Forum users.
Send me money

Αndré


Αndré

FYI: I replaced some redundant code parts with a new function 'theme_album_info' in SVN revision 8673.