Simplified Voting Hack

myriagon

Joined: 2004-01-22
Posts: 130
Posted: Thu, 2004-01-22 14:00

I've hacked togther some code based on 1.4.1 to make voting work in the way I wanted it to work for my gallery. The basic idea is to simplify it as well as making it look better so that users can click on a "vote" link under an image to register their vote. Next time they view the same image the vote link is disabled. This is session based so by reopening the browser they can vote again but I'm not too worried about that.

To make voting more interesting I have added a stats page to list images with the most votes. I have also added stats pages to show images with the most views (clicks) and also the latest images that have been added to the gallery. These were very easy to do once I had the most votes page working.

The gallery is at http://www.tearoom.me.uk/gallery/albums.php Give it a go and see what you think. My ISP is having problems with their cgi server at the moment so you might get timeouts. If you do then retry later. It's nothing to do with my php code though!

At some point it would be good to get this into Gallery but my hack involved changing lots of files so it may not be a trivial task. Of course anyone is welcome to the code if they want. Maybe if I get enough interest I will have a go at hacking a vanilla 1.4.1 to add this simplified voting.

There are definitely things I could have done better but with only 3 weeks experience my php knowledge is limited. One concern is scaling. With 40 images and a low level of usage it is fine. However it may need a caching solution in the future for the "sort" that's used to display images in the right order for a large gallery.

Login or register to post comments
shoobeedoodoo

Joined: 2004-01-11
Posts: 78
Posted: Thu, 2004-01-22 21:48

Wow! Very nice! I especially like the most viewed and the latest images part, looks great!

Would it be easy for me to somehow integrate the most viewed and the latest images into my gallery?

Thanks!

-Stephen

Login or register to post comments
floridave
floridave's picture

Joined: 2003-12-22
Posts: 16960
Posted: Thu, 2004-01-22 22:13

myriagon,
You did a great job! I bet there is a bunch of people waiting for the mods. I know I am looking for them as well.

Cheers,
Dave

PS I have a Thai wife as well.

Login or register to post comments
shoobeedoodoo

Joined: 2004-01-11
Posts: 78
Posted: Fri, 2004-01-23 18:46

Any updates?

Thanks again!

-Stephen

Login or register to post comments
myriagon

Joined: 2004-01-22
Posts: 130
Posted: Fri, 2004-01-23 22:33

Thanks for the interest - there's a test version of the code here... http://www.tearoom.me.uk/stats.tar.gz This has voting disabled as it needs a new function in util.php to read the votes cast for each image.

I have tried the stats code with a vanilla gallery install and it works ok for me. If you have problems post on here and I will see what I can do.

Cheers, J

Login or register to post comments
shoobeedoodoo

Joined: 2004-01-11
Posts: 78
Posted: Sat, 2004-01-24 03:33

Wow,
Thank you very much, it works great, exactly what I was looking for, thank you very much!

Just a quick question, right now, when I go to the stats page, it displays at the top of the page:

Warning: Failed opening 'layout/meta.inc' for inclusion (include_path='.:/usr/local/lib/php') in /homepages/35/d93413898/htdocs/gallery/util.php on line 789

The rest of it is fine, but it has this error at the top. Any way to get rid of it?
Also, is there any way to restrict the number of images it displays? Because right now I think it's displaying all the images.

Thanks again for everything!

-Stephen

Login or register to post comments
floridave
floridave's picture

Joined: 2003-12-22
Posts: 16960
Posted: Sat, 2004-01-24 04:50

shoobeedoodoo,
Create a file called meta.inc with this content
<META http-equiv=Content-Type content="text/html; charset=iso-8859-1">
save it as 'gallery/layout/meta.inc'
Yo can add other META tags as you wish as well.

myriagon,
Wonderful script!! Thanks! Now you have given me some work because I put the descriptions where the name of the image is supposed to go! :oops: This makes the name of the image too long for the title bar.

Dave

Login or register to post comments
myriagon

Joined: 2004-01-22
Posts: 130
Posted: Sun, 2004-01-25 00:31

shoobeedoodoo,

Glad to hear you have something working. The meta include error is a result of another hack that I did to the vanilla Gallery install. As far as I can tell, Gallery has no general way of specifying meta data in the head section. Meta data is used to help robot spiders such as googlebot find out about a website. Do a quick google search if you want more. Anyway I added the following:

"<?php includeLayout('meta.inc'); ?>"

This includes my meta.inc file that I store in the layout directory. If you remove this line from stats.php it should work with no errors. I have already done this in the latest stats.tar.gz which you can now download from http://www.tearoom.me.uk/stats.tar.gz

As for the number of images displayed, I have hacked some code to limit the total number. On line 36 there's a new variable $totalPhotosToDisplay This is currently set to -1 to display all images. Change this to whatever you want. There's also another variable, $photosPerPage that you might want to change from the default of 10.

floridave,

To get round the problem of descriptions and titles being transposed, if it was me I would be hacking stats.php. You could use the title in the description field and make it the link to view_photo.php. Then leave the title blank. BTW My wife and I enjoyed surfing through your website earlier. She thinks that you have two lovely kids.

Login or register to post comments
shoobeedoodoo

Joined: 2004-01-11
Posts: 78
Posted: Sun, 2004-01-25 20:12

Thank you guys soo much again for all your help myriagon and floridave!

Your script myriagon works pretty much flawlessly now. Thanks again!

Oh, I had one little question, I dunno if it's possible or not, but is there any way to maybe display both the 10 most viewed and the 10 latest added pictures on the same page together? Like maybe the left side of the page would be the top ten viewed, and the right side would be the ten newest?

Anyways, thanks again for everything!

-Stephen

Login or register to post comments
myriagon

Joined: 2004-01-22
Posts: 130
Posted: Mon, 2004-01-26 00:36

Interesting request!

I'm sure it's possible... most things are - what you would need to do is loop through displaying images from two different sorted lists together. My guess is that the code would get messy - maybe I will do it if I have some free time and feel like a challenge...

Login or register to post comments
ryanozawa

Joined: 2003-10-23
Posts: 25
Posted: Wed, 2004-01-28 10:44

myriagon, thanks so much for finding my inquiry on this other thread and pointing me here to your stats.php hack!

I was desperate for a "latest image" hack that could be called via SSI or PHP includes from elsewhere on a site, and was messing for a while with this RSS feed hack. Unfortunately, that setup didn't prune the output file, and I couldn't figure out how to do it on my own.

But even though I know absolutely nothing about PHP, through trial and error I was able to modify your stats.php hack to do exactly what I wanted. Even better, because you built in 'sort by votes' and 'sort by views' functionality as well as the 'latest images' sort, those also work with my SSI/PHP include revision. (Hack hack?)

Check it out! This main page of my site now shows the last eight images posted to my gallery using a standard SSI/SHTML include:
http://www.lightfantastic.org

And I can use the exact same include line to do a variety of things on different pages. By calling the following URLs, I can:

Show the top three most-viewed photos:
http://www.lightfantastic.org/gallery/include.php?type=views&photocount=3

Or show the top five latest photos:
http://www.lightfantastic.org/gallery/include.php?type=date&photocount=5

And on and on. Again, since this is designed to work with includes, I can get these pictures on different pages. I think it would also be able to have a single page call the script several times, so I can have one page for "Most Recent," "Most Viewed" and "Top Rated" at once.

And with another tweak, it would also be possible to let the thumbnail size be specified in the calling URL, so you can have tiny thumbnails on one page, and regular-sized thumbnails somewhere else.

Brilliant work. I'm so happy! And if anyone wants to see the (amateurish, shoddy, rough) modifications I made to the stats.php hack (retaining your coding credit, of course!), let me know.

Login or register to post comments
shoobeedoodoo

Joined: 2004-01-11
Posts: 78
Posted: Wed, 2004-01-28 23:43

I would love to see your modifications!

-Stephen

Login or register to post comments
myriagon

Joined: 2004-01-22
Posts: 130
Posted: Thu, 2004-01-29 08:03

ryanozawa - glad to see someone else hacking gallery - it looks really cool :)

I was thinking of doing something myself but you beat me to it! Anyway I wouldn't mind seeing your hack.

Cheers, J

Login or register to post comments
shoobeedoodoo

Joined: 2004-01-11
Posts: 78
Posted: Fri, 2004-01-30 00:12

Hey Myriagon,
Just wanted to thank you again for everything, to see your script in action, please visit www.shoobeedoodoo.com, and click on top ten, your script works beautifully! Please let me know what you think and if you have any other suggestions.

Again, thank you!

-Stephen

Login or register to post comments
myriagon

Joined: 2004-01-22
Posts: 130
Posted: Fri, 2004-01-30 23:31

Thanks for sharing that - looking good - you guys seem to have lots of fun.

Seeing your website has made me do a quick mod to stop it displaying "Page 1" at the top and bottom if there's only one page. http://www.tearoom.me.uk/stats.tar.gz has been updated.

Cheers, J

Login or register to post comments
shoobeedoodoo

Joined: 2004-01-11
Posts: 78
Posted: Sat, 2004-01-31 20:24

Hi Myriagon,
I updated the stats.php to the new version, and the Page 1 is now gone, which is perfect.

I just had a question though now, if you go to my site, and click on top ten, and click on newest images, the page seems to be shifted over, wheras compared to the most viewed images, the page seems to be aligned perfectly to the left. Is there any way to fix this?

Thanks again!

-Stephen

Login or register to post comments
myriagon

Joined: 2004-01-22
Posts: 130
Posted: Sat, 2004-01-31 20:41

I spent ages looking at that issue. Basically stats.php is a hack based on the albums main page. I reused that code so that I could display the thumbs and text in the same format. The albums mainpage IIRC can suffer the same problem. It's to do with table centering and the length of the description text. If there's an image with a long title or description then the table is filled horizontally forcing all the thumbs to the left.

If I have some spare time now that I know a little more about html tables I will see if I can get it to go to the left no matter how long the title and descriptions are.

Cheers, J

Login or register to post comments
shoobeedoodoo

Joined: 2004-01-11
Posts: 78
Posted: Tue, 2004-02-03 03:34

Hey Myriagon,
Just had another question for ya, is there anyway to see the top ten photos of the month? Like just to see the most viewed images in the past month? Or would I have to reset the counter for all the albums each month to achieve this?

Thanks!

-Stephen

Login or register to post comments
promoview

Joined: 2004-01-28
Posts: 47
Posted: Tue, 2004-02-03 23:40

ryanozawa,

i would really like the source code for your modification of the stats page since i want the output to be exactly as you have it, only the pics, without the gallery "interface". please tell me where i can get your source.

Thanks

Login or register to post comments
myriagon

Joined: 2004-01-22
Posts: 130
Posted: Tue, 2004-02-03 23:55

shoobeedoodoo - I have started a new topic as this one has gone way off the voting subject that it was intended to cover. See the Latest Images / Most Viewed Hack topic for my latest update :)

Login or register to post comments
Raven69
Raven69's picture

Joined: 2004-01-16
Posts: 24
Posted: Fri, 2004-02-13 11:45
myriagon wrote:
Thanks for the interest - there's a test version of the code here... http://www.tearoom.me.uk/stats.tar.gz This has voting disabled as it needs a new function in util.php to read the votes cast for each image.

I have tried the stats code with a vanilla gallery install and it works ok for me. If you have problems post on here and I will see what I can do.

Cheers, J

Could you please post this hack for util.php as I use your stats.php and want to show the "most votes" too (as you do on your website).

tnx in advance

RaVen69

Login or register to post comments
MeLtrA

Joined: 2003-11-23
Posts: 8
Posted: Wed, 2004-03-31 04:02

yea man, i would also appreciate the util.php code that i have there for voting, thanx man.

Login or register to post comments
myriagon

Joined: 2004-01-22
Posts: 130
Posted: Wed, 2004-03-31 22:20

Raven69 and MeLtrA - at the moment stats.php doesn't support the standard Gallery voting. On my website I implemented my own type of voting which required a lot of new code effecting several files. I'll have a look to see what's required to get stats.php working with the Gallery voting. When I get something working I'll post it on here

Cheers, J

Login or register to post comments
Raven69
Raven69's picture

Joined: 2004-01-16
Posts: 24
Posted: Thu, 2004-04-01 06:05
Quote:
.... When I get something working I'll post it on here

Took a long time to get answer but THANX A LOT that you will try to implement the Gallery voting.

got suggestion:

<?php
$statsVersion = 1.70;

// Control variables - the show* ones can be overidden by the url.
if (!$photosPerPage)
   $photosPerPage        = 10;
if (!$totalPhotosToDisplay)
   $totalPhotosToDisplay = -1;   // Set to -1 for all photos.
if (!showCaptureDate)
   $showCaptureDate      = 0;
if (!$showUploadDate)
   $showUploadDate       = 1;
if (!$showViews)
   $showViews            = 1;
if (!showVotes)
   $showVotes            = 0;
if (!showComments)
   $showComments         = 1;

so that you can override the photos to display etc., e.g.:
http://your.domain.com/gallery/stats.php?type=views&totalPhotosToDisplay=5

tried it and it works as far as you have only 1 page displayed.

so if you could have a look on THAT too would be nice.

thanks again,

RaVen

Login or register to post comments
myriagon

Joined: 2004-01-22
Posts: 130
Posted: Thu, 2004-04-01 06:17

Sorry Raven - I thought this discussion was dead so I haven't been checking it recently until it appeared on the first page the other day. The one I do watch is the Latest Images / Most Viewed Hack thread.

Thanks for your suggestion - good to see someone else can read and understand the code - I will get that change in when I next do a release.

Cheers,

Jeremy

Login or register to post comments