[Mod] "Most viewed albums" meta album [Mod] "Most viewed albums" meta album
 

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

[Mod] "Most viewed albums" meta album

Started by Ludo, May 23, 2008, 10:09:14 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Ludo

This mod adds a new meta album to show most viewed albums.

Demo: http://vanrokken.altervista.org/thumbnails.php?album=topnalb

Usage: to include this meta album in Main page/Album list display, add 'topnalb' code to your Configuration > Album list view > Main page content list (E.g. anycontent/breadcrumb/catlist/alblist/lastalb,1/topnalb,1).
To add a link "Most viewed albums" to your Gallery sub menu, enter "Most viewed albums" in "Name of your custom link" field, "thumbnails.php?album=topnalb" in "URL of your custom link" field under Configuration > Themes settings

Files to edit:
index.php
include/functions.inc.php
lang/english.php
(repeat for all the desired language files)
themes/your_theme/theme.php


OPEN
index.php

FIND
                    case 'lastalb':
                        display_thumbnails('lastalb', $cat, 1, $CONFIG['thumbcols'], max(1, $matches[2]), false);
                        break;


AFTER, ADD
                       
                    case 'topnalb':
                        display_thumbnails('topnalb', $cat, 1, $CONFIG['thumbcols'], max(1, $matches[2]), false);
                        break;                       



OPEN
include/functions.inc.php

FIND
                $rowset = CPGPluginAPI::filter('thumb_caption_favpics',$rowset);

                return $rowset;
                break;


AFTER, ADD
               
        case 'topnalb': // Last albums to which uploads
                if ($META_ALBUM_SET && $CURRENT_CAT_NAME) {
                        $album_name = $lang_meta_album_names['topnalb'].' - '. $CURRENT_CAT_NAME;
                } else {
                        $album_name = $lang_meta_album_names['topnalb'];
                }

                $META_ALBUM_SET_MWA = str_replace( "aid", $CONFIG['TABLE_PICTURES'].".aid" , $META_ALBUM_SET );

                $query = "SELECT count({$CONFIG['TABLE_ALBUMS']}.aid) FROM {$CONFIG['TABLE_PICTURES']},{$CONFIG['TABLE_ALBUMS']} WHERE {$CONFIG['TABLE_PICTURES']}.aid = {$CONFIG['TABLE_ALBUMS']}.aid AND approved = 'YES' $META_ALBUM_SET_MWA GROUP BY {$CONFIG['TABLE_PICTURES']}.aid";

                $result = cpg_db_query($query);
                $count = mysql_num_rows($result);
                mysql_free_result($result);

                $query = "SELECT *, SUM({$CONFIG['TABLE_PICTURES']}.hits) AS hits, {$CONFIG['TABLE_ALBUMS']}.title AS title, {$CONFIG['TABLE_ALBUMS']}.aid AS aid FROM {$CONFIG['TABLE_ALBUMS']},{$CONFIG['TABLE_PICTURES']} WHERE {$CONFIG['TABLE_PICTURES']}.aid = {$CONFIG['TABLE_ALBUMS']}.aid AND {$CONFIG['TABLE_PICTURES']}.approved = 'YES' AND hits > 0 $META_ALBUM_SET_MWA GROUP BY {$CONFIG['TABLE_ALBUMS']}.aid ORDER BY hits DESC $limit";
               
                $result = cpg_db_query($query);
                $rowset = cpg_db_fetch_rowset($result);
                mysql_free_result($result);

                if ($set_caption) build_caption($rowset,array('hits'));               

                $rowset = CPGPluginAPI::filter('thumb_caption_topnalb',$rowset);

                return $rowset;
                break;



OPEN
lang/english.php

FIND
  'favpics'=> 'Favorite Files',  //cpg1.4

AFTER, ADD
  'topnalb' => 'Most viewed Albums', 


OPEN
themes/your_theme/theme.php

FIND
function theme_display_thumbnails
(if absent, copy and paste it from themes/sample/theme.php)

FIND
        $theme_thumb_tab_tmpl['left_text'] = strtr($theme_thumb_tab_tmpl['left_text'], array('{LEFT_TEXT}' => $aid == 'lastalb' ? $lang_album_list['album_on_page'] : $lang_thumb_view['pic_on_page']));

REPLACE WITH
        $theme_thumb_tab_tmpl['left_text'] = strtr($theme_thumb_tab_tmpl['left_text'], array('{LEFT_TEXT}' => ($aid == 'lastalb' || $aid == 'topnalb') ? $lang_album_list['album_on_page'] : $lang_thumb_view['pic_on_page']));

FIND
            if ($aid == 'lastalb') {

REPLACE WITH
            if ($aid == 'lastalb' || $aid == 'topnalb') {

SAVE AND CLOSE ALL FILES

Joachim Müller

Thanks for your contribution; looks very promising. I'd like to hear some test results. If the feedback is positive, I'd like to consider this mod to go into the core for cpg1.5.x, so everybody please test thoroughly and post feedback.

Ludo

Thank you very much for your appreciation, GauGau  :-[ ;)
Mod was witten from scratch yesterday night, so it lacks testing nearly at all.  :-\ :)

Hein Traag

"There was an error while processing a database query "

Database gone for lunch ?

Ludo

#4
Huh, new meta album seems to work only for registered users...definitely lacks testing!  :-[  ;D
I'm going to try to fix it ASAP, sorry


Edit: bug fixed and mod code above edited accordingly

Ludo

SQL queries rewritten to comply with CPG layer

armus

Hi Ludo, i am using your this Mod and "album views in albums stats on Album list" http://forum.coppermine-gallery.net/index.php?topic=29118.0

And also directly linking to the full size images(files of jpeg,etc) from the album thumbnails "no indermediate pages nor full size image pages"

Ofcourse Album View count is not working by these ways however it is possible to add counter to the aid (album id) instead pid (picture id), if i can clear, we should be able to add counter raise according to album views (whenever an album page opened) not the full-size image view page opened.

Have you did it? Or do you know how to do it?

Ludo

To accomplish that, you should add a counter field for album views to albums table in db, and a function to increase that counter at every visit in thumbnail page.

armus

I think i can not do that, wheneve i add or edit a field in MySQL , entire Coppermine gives failure.