Advanced search  

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

Pages: [1]   Go Down

Author Topic: limit meta albums range by date?  (Read 7283 times)

0 Members and 1 Guest are viewing this topic.

lamama

  • Contributor
  • Coppermine frequent poster
  • ***
  • Offline Offline
  • Gender: Male
  • Posts: 404
limit meta albums range by date?
« on: September 19, 2007, 12:04:11 am »

Hmmm. I guess this is going to be some kind of mod- or feature request, but maybe it's already done by someone and I've been to blind to find it...

Initially i was looking for something like a meta-album "last/recently rated".

Problem: our gallery is running for several years now, with a lot of pictures.
Now "top rated" shows a mixture of old and some new pics, but the new pics rarely get enough votes to reach first or second page of the metaalbum. Wouldn't it be nice to limit the time range of the best voted pictures to the last few days, weeks, month, year...?

The same functionality would IMO make sense with the "most viewed" meta album too.

My coding skills are not that billiant, but maybe someone around here likes the idea and is able to enhance the existing code.

« Last Edit: September 20, 2007, 08:39:08 am by GauGau »
Logged

Nibbler

  • Guest
Re: limit meta albums range by date?
« Reply #1 on: September 19, 2007, 12:16:19 am »

Meta album code is in include/functions.inc.php get_pic_data(). You need to add a restriction based on ctime which is a unix timestamp.

Code: [Select]
                $query = "SELECT COUNT(*) from {$CONFIG['TABLE_PICTURES']} WHERE approved = 'YES' AND votes >= '{$CONFIG['min_votes_for_rating']}' $META_ALBUM_SET";
                $result = cpg_db_query($query);
                $nbEnr = mysql_fetch_array($result);
                $count = $nbEnr[0];
                mysql_free_result($result);

                //if($select_columns != '*') $select_columns .= ', pic_rating, votes, aid, owner_id, owner_name';
                $select_columns = '*'; //allows building any data into any thumbnail caption

                $query = "SELECT $select_columns FROM {$CONFIG['TABLE_PICTURES']} WHERE approved = 'YES' AND votes >= '{$CONFIG['min_votes_for_rating']}' $META_ALBUM_SET ORDER BY pic_rating DESC, votes DESC, pid DESC $limit";
                $result = cpg_db_query($query);
                $rowset = cpg_db_fetch_rowset($result);
                mysql_free_result($result);

Becomes something like this

Code: [Select]
                $query = "SELECT COUNT(*) from {$CONFIG['TABLE_PICTURES']} WHERE approved = 'YES' AND votes >= '{$CONFIG['min_votes_for_rating']}'  AND ctime > UNIX_TIMESTAMP() - 86400 $META_ALBUM_SET";
                $result = cpg_db_query($query);
                $nbEnr = mysql_fetch_array($result);
                $count = $nbEnr[0];
                mysql_free_result($result);

                //if($select_columns != '*') $select_columns .= ', pic_rating, votes, aid, owner_id, owner_name';
                $select_columns = '*'; //allows building any data into any thumbnail caption

                $query = "SELECT $select_columns FROM {$CONFIG['TABLE_PICTURES']} WHERE approved = 'YES' AND votes >= '{$CONFIG['min_votes_for_rating']}' AND ctime > UNIX_TIMESTAMP() - 86400 $META_ALBUM_SET ORDER BY pic_rating DESC, votes DESC, pid DESC $limit";
                $result = cpg_db_query($query);
                $rowset = cpg_db_fetch_rowset($result);
                mysql_free_result($result);

Change 86400 to the number of seconds you want to filter on.
Logged

lamama

  • Contributor
  • Coppermine frequent poster
  • ***
  • Offline Offline
  • Gender: Male
  • Posts: 404
Re: limit meta albums range by date?
« Reply #2 on: September 19, 2007, 05:05:49 am »

Works! Thanks a lot.

I created a new meta album "lastrated" - unfortunatly it only works via link (thumbnails.php?album=lastrated), but not as a part of the albumlist ("Contents of the main page"). Is this setting parsed in another function?

(argh! sorry for my limited english...)
Logged

Nibbler

  • Guest
Re: limit meta albums range by date?
« Reply #3 on: September 19, 2007, 09:43:14 am »

Yeah, index.php. Look for the switch.
Logged

lamama

  • Contributor
  • Coppermine frequent poster
  • ***
  • Offline Offline
  • Gender: Male
  • Posts: 404
Re: limit meta albums range by date?
« Reply #4 on: September 19, 2007, 03:17:04 pm »

If you know how it works it's quite simple.  ;D

Thanks again, works perfect.


If someone wants to try this hack too:

- choose a unique name for your new meta-album (like 'lastrated')

- copy the 'toprated' block in include/functions.inc.php get_pic_data() and modify it like Nibbler suggested above

- modify index.php (search for 'main code'), copy the code for 'toprated' and modify it like this:
Code: [Select]
        case 'lastrated':                           
                        display_thumbnails('lastrated', $cat, 1, $CONFIG['thumbcols'], max(1, $matches[2]), false);
                        flush();
                        break;

- enhance the language file at least for your default language ($lang_meta_album_names, $lang_main_menu)
Example:
Code: [Select]
$lang_meta_album_names = array(
  'random' => 'Random files',
  'lastup' => 'Last additions',
  'lastalb'=> 'Last updated albums',
  'lastcom' => 'Last comments',
  'topn' => 'Most viewed',
  'toprated' => 'Top rated',
  'lastrated' => 'Recently rated',
  'lasthits' => 'Last viewed',
  'search' => 'Search results',
  'favpics'=> 'Favorite Files',  //cpg1.4
);
(likewise for $lang_main_menu)

- Don't forget to mod your theme.php to make the new meta album available for your visitors:
(just an example, make it fit for your own theme)
Code: [Select]
<li class="sidebar_menu"><a href="{TOPRATED_TGT}" title="{TOPRATED_LNK}" class="navmenu">{TOPRATED_LNK}</a></li>
<li class="sidebar_menu"><a href="{LASTRATED_TGT}" title="{LASTRATED_LNK}" class="navmenu">{LASTRATED_LNK}</a></li>

I guess, that's all.  :)
Logged
Pages: [1]   Go Up
 

Page created in 0.024 seconds with 20 queries.