limit meta albums range by date? limit meta albums range by date?
 

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]

Main Menu

limit meta albums range by date?

Started by lamama, September 19, 2007, 12:04:11 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

lamama

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.


Nibbler

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.


                $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


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

lamama

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

Nibbler


lamama

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