Dragonfly CMS v9 ⇒ Coppermine ⇒ "Random pictures" function in Coppermine functions.inc ⇒ Community Forums ⇒ CPG Dragonfly™ CMS
Forum IndexModules & BlocksCoppermine

"Random pictures" function in Coppermine functions.inc Reply to topic


I'm using the Coppermine Random Gallery Pix block and would like to filter the files selected so the thumbnails of the pix returned do not exceed a certain width. I have panoramic pix in my albums and if a couple of panos get pulled for display in the Random block, my page width increases and the browser puts up a scroll bar for the page with an extra wide table produced by Coppermine.

K, so I went over to the Coppermine forum and they are sending people with questions about Coppermine 1.3.1 in Dragonfly back here. But I did find a good lead in this post: coppermine-gallery.net...#msg45369. I looked at the functions.inc file in /includes/coppermine and located this code:

$result = $db->sql_query("SELECT $select_columns FROM {$CONFIG['TABLE_PICTURES']} AS p INNER JOIN {$CONFIG['TABLE_ALBUMS']} ON (".VIS_GROUPS." AND $thisalbum) WHERE randpos IN ($random_num_set) AND approved = 1 GROUP BY p.pid, p.filepath, p.filename, p.title, p.keywords, p.url_prefix, p.filesize, p.pwidth, p.pheight, p.ctime, p.aid ORDER BY RAND() $limit"); } else { $result = $db->sql_query("SELECT $select_columns FROM {$CONFIG['TABLE_PICTURES']} AS p INNER JOIN {$CONFIG['TABLE_ALBUMS']} AS a ON (p.aid = a.aid AND ".VIS_GROUPS." AND $thisalbum) WHERE approved=1 GROUP BY p.pid, p.filepath, p.filename, p.title, p.keywords, p.url_prefix, p.filesize, p.pwidth, p.pheight, p.ctime, p.aid ORDER BY RAND() $limit");

Not being very experienced with php or SQL I don't know how to alter the WHERE statement to filter based on an image pwidth property.

Can someone please help with altering those queries to filter out any results over a given width? Thanks!!

Server specs (Server OS / Apache / MySQL / PHP / DragonflyCMS):
Linux/1.3.37/4.1.21/4.4.7/9.1.2.1


Resolved... surprisingly simple fix.

The random gallery pix is in the main Gallery page (as I have it configured) and is a block I've placed on most of my main pages. The thumbnails of the randomly selected pix are sized the same as the original pic. For panos, with dimensions like 1000x250, it produces a thumbnail of uniform height, but proportional width. The thumbnails are always 100px high, so panos like the one with a 4 to 1 dimension were sizing to 400 x 100. With four thumbnails in the table, you could have a table that was, for example, 1600px wide... which was causing the browser to add a horizontal scroll bar and pushing the my right blocks off the screen.

The fix was to set a conditional up for the WHERE clause that selects random records. I thought it best to just address the proportions and not pull and pix that were more than 2x wider than tall.

This conditional, inserted right after WHERE, worked to set that contraint, with an AND in there to keep the other clauses of the WHERE statement:
(p.pheight/p.pwidth)>.5 AND

I changed two files for this: the block-CPG-center-Random_pictures.php block (which I'm using to show random pix on my index and most other pages) as well as the /includes/coppermine/functions.inc file, which governs the random pix "block" that is included in the default main gallery page with the out of box install of Dragonfly/Coppermine.

Hope that helps others who want to address this issue...

Server specs (Server OS / Apache / MySQL / PHP / DragonflyCMS):
Linux/1.3.37/4.1.21/4.4.7/9.1.2.1


Note to mods... u may want to correct my misspelling in the Subject of the above posts so "random pictures" comes up in a search by Subject.

Server specs (Server OS / Apache / MySQL / PHP / DragonflyCMS):
Linux/1.3.37/4.1.21/4.4.7/9.1.2.1


Cool - I've got one in mine that does that and it seems to come up more often than any other picture! Now I can stop being lazy and actually fix that! Smile

Admin - Great Lakes Web Designs
Theme Designer - WebSite Guru Designs
Site Admin - Families with Food Allergies

Server specs (Server OS / Apache / MySQL / PHP / DragonflyCMS):
Linux 2.6.27-grsec/Apache 2.2.11/MySQL 5.0.67-community-log/PHP 5.2.8/DF 9.2.1


Just found this via a search as it's been bugging me - should be added to the next DF release!

Thanks Motowriter

Server specs (Server OS / Apache / MySQL / PHP / DragonflyCMS):

All times are UTC


Jump to: