Latest Images / Most Viewed Hack
myriagon
Joined: 2004-01-22
Posts: 130 |
Posted: Tue, 2004-02-03 23:47 |
I've developed a hack to display the newest images added to Gallery and the images with the most views. See www.tearoom.me.uk and click on the "Viewing" and "Latest" links for a demo. The hack can be downloaded from here http://www.tearoom.me.uk/stats.tar.gz There's a readme in the tar that explains how to use the code. The hack requires no changes to existing Gallery code and should run with all recent versions. This was previously covered by the Simplified Voting Hack thread but that was getting way off topic which is why I've started a new one. Cheers, J |
|
Posts: 130
I'm not 100% clear on what you want but if I understand correctly you would need to reset the counters each month. Another option is to start changing Gallery code but then upgrading Gallery becomes a lot more difficult. What would be needed is another clicks (views) count for the past month. It could be done and would be very similar to what I did with my voting counter. However as I say upgrading Gallery later would be difficult.
I have done another hack that allows the stats page to only display images that have been uploaded during the current month, or any number of earlier months. It's in the latest tar on my website. The "period" variable controls what is displayed - for example:
stats.php?type=views&period=0 [current month]
stats.php?type=views&period=1 [last month and this month]
stats.php?type=views&period=6 [last 6 months]
This is documented in the readme.
Mmmm... I've just had another idea about how what I think you really want could be done. Let me think about it some more as implementing it could stretch my php knowledge....
Posts: 9
well i read the readme , and it doesnt say ANYTHING about how to implement this in existing page. it just says how to customize the hack , but in no way it says where to copy what ( of course it's easy to figure out ) and how to implement it into the existing page. With new thread here , i thought you wanted to save folks hassle of digging up old thread , but i guess......
Posts: 130
Wally,
Thanks for your positive contribution - NOT!
Mmmm... enough said... anyway I don't ever remember telling anyone how to get this hack into a standard Gallery install. It seemed too basic for anyone looking through the Customizing forum...
For the record untar the stats.tar.gz file and as a first step type the url to the stats.php in your browsers address field. If it works and adds value to your site and you want to include it, then checkout http://www.eclecticpixels.com/tutorials/gallerytips/ That guide is the one I used myself which is IMHO very good.
Cheers, J
Posts: 9
" There's a readme in the tar that explains how to use the code. "
I thought this was suppoused to let everybody know how to work with the code , not just customize the code. I hope there's no harm done , and i didnt want to offend you.
As in for feedback , i like the code , i like it enough to include it in my gallery so i hope that souds positive enough. Only thing i dont understand why it tries to resize the thumbnail's. I have mine set at 40px (or 60px) in my main gallery , but once i go into "latest: link to see latest additions they stretch to something like 80px or more. Needless to say 40px thumbnail streched to 80px ( or more ) looks horribly blurred.
I tried looking inside stats.php but i didnt find anything , did you include it somehwere in there or is it someplace else ?
Thanks for the hack ( ITS GREAT ) and hopefully we can figure out somehow.
Posts: 9
i found it ... i must have changed "thumb_size" in config accidently to "120" and your hack read it correctly from there. My fault !
Posts: 130
I have added more code to stats.php to display image capture date and to support sorting by capture date. As before the code is at http://www.tearoom.me.uk/stats.tar.gz. More details in the readme.
The capture date format might not be consistent with that used for the upload date. This is because the two dates are stored in different ways by Gallery. How the capture date is displayed can be modified by hacking line 421
echo "<td><span class=\"fineprint\">" . $captureDate["mday"] . "/".$captureDate["mon"]."/".$captureDate["year"]."</span></td></tr>";
Change the mday, mon and year around to suit.
Hope that makes sense.
Cheers,
J
Posts: 14
works great!
Posts: 78
Hey Myriagon,
I was wondering if you could help me out with a little question I have.
Your stats.php was working perfectly and everything, and then I uploaded a bunch of pics at one time, like around 200 new pictures, and now the stats.php page doesn't work, and is just blank, so the top ten and the newest images don't work on my page. Any way to fix this problem?
Thanks!
-Stephen
Posts: 130
The easiest way would be if I can reproduce the problem here. Ideally I could do with a copy of your albums directory. Do you have a tar.gz file of your albums directory that I could download? If that's too large then I will put some debug in stats.php so we can see where the problem is.
Cheers, J
Posts: 78
I'm not sure if this helps or not, but after uploading all those pictures, my random image generator doesn't work either, but everything in Gallery works fine. Does this have something to do with php memory allocation?
If you visit www.shoobeedoodoo.com and click on top ten, and proceed to click on top ten images or newest images, you'll see that it'll just show "Top Ten Images" at the top of the page, but no pictures.
Thanks again for all your help!
-Stephen
Posts: 130
It would be interesting to know if the Gallery search still works. Search uses similar code to stats.php.
I've now added some debug info to stats.php in an effort to find what is failing. The problem with this is that it can be a slow iterative process. My guess is that the code is blowing some php resource limit with the number of photos you have. Anyway try downloading the latest http://www.tearoom.me.uk/stats.tar.gz and opening http://www.shoobeedoodoo.com/gallery/stats.php?type=views&debug=1
I would like to see what debug info that shows. You can also try http://www.shoobeedoodoo.com/gallery/stats.php?type=views&debug=2 but that might produce too much debug info.
Cheers, J
Posts: 78
I tried doing the debugging stuff, and it doesn't show any information, what else should I try?
Thanks!
-Stephen
Posts: 130
That tells me that it is crashing very early in the code. I've added more debugging to try and get closer to the problem. Try downloading the latest version and see what that tells us. Use debug=2. As I said - this will be a slow process unfortunately - if I could reproduce it with my setup it would be a lot quicker.
Cheers, J
Posts: 78
I tried playing around with it, and with the latest version, debug 2 shows no information as well, however, some times when I try to go to the stats page on its own, I sometimes get an internal server 550 error or something from my hosting company, while other times it's just blank, could it be possible that php memory is a problem or something?
Thanks!
-Stephen
Posts: 130
Ok - I have updated stats.php with yet more debug. Try that . I would be surprised if you had nothing this time!
Cheer,s J
Posts: 78
Hey Mryiagon,
Thanks again for doing all this with me, I really appreciate it.
The debug information now shows:
Version = 1.51
Including meta
Including stats.header
Images with the most Views
Included stats.header
Getting album database.
The rest of the page is blank.
Thanks again for all your help!
-Stephen
Posts: 130
Glad that I can be of assistance - your problems help me to learn php.
The debug output this time is much more interesting.
I suspect the problem with stats.php is the same one as with the random image code. I haven't seen that code so can't confirm. Anyway looking at the debug output, it's calling "new AlbumDB()" and never returning. "new AlbumDB()" is a standard Gallery function - not one of mine. This is how I call it in my code:
The reason why albums.php works is that it uses:
The FALSE tells the AlbumDB code not to load photos. I guess albums.php has no need to load them being a simple top level list of albums. If FALSE is not specified then it defaults to TRUE and tries to load the photos.
So the question is why does the code never return from the new AlbumDB() call? It could be a resource issue or possibly data associated with one of your albums is corrupt in some way and it is failing to load and then crashing out silently. To diagnose you need to add debug code to the file "classes/AlbumDB.php" My code looks like this - yours might be different given IIRC you are running different Gallery code:
Try adding the echo as below:
When you run this code it will be interesting to see which album is the last one that gets listed. That is probably where the problem starts. I would then start drilling into the load code itself with echos to tell me what's happening. Alternatively you could try adding code to skip that album or even try deleting it from Gallery. Before doing any of this though I would make sure I had a backup of my albums directory.
BTW on Friday I'm leaving for a 2 week business trip to the US so these posts could stop for a while unless I can get online there.
Posts: 78
Hi Myriagon,
I did as you said, and the last album listed is my new york album, which is the latest album I created, and which is the album which after I created I started to have my problems, so how do I code it to skip that album? Or is there anything else I should try now? When I try running your script, it now shows:
Images with the most Views
Loading album gabby
Loading album maizer
Loading album yathink884
Loading album taranizzy
Loading album ThaBBoyWannaB
Loading album shoobeedoodoo
Loading album lilaznqt02
Loading album harrypitts1784
Loading album term
Loading album heavenly
Loading album maulin
Loading album iwantsomecouch
Loading album jomo
Loading album monsterkwan
Loading album xstrawberri
Loading album california
Loading album michigan
Loading album winterbreak0304
Loading album wintersemester04
Loading album Shoobee!!
Loading album corynneo
Loading album CesarsB-Day
Loading album volleyball
Loading album photography
Loading album lunarball
Loading album newyork
As you can see, the newyork album is the last album, does all this mean that album is corrupt, and perhaps I should reupload it? Because I do remember that I used gallery remote to upload my New York pictures, and it kind of froze when it uploaded, and I had to manually cancel it, could that be the problem?
Again, thank you for everything!
-Stephen
Posts: 130
I had a similar thing happen to me with it freezing during an upload that resulted in a "corrupt" album. I deleted it and then it was ok.
I notice from your site that the NY album has gone so I guess you have already deleted but it hasn't helped. Assuming I'm correct, after you deleted NY did you get the same result when you ran stats.php. ie did it stop after loading album newyork? The reason I ask because maybe there's still a reference to the newyork album.
The next thing to do if you still have problems is to add more "echo" statements to pin point where in the code it is failing. You can safely add
echo "I'm here";
type statements to the code to see where it is going.
Cheers, J
Posts: 78
I haven't tried deleting the New York album yet, it's under homies, under shoobeedoodoo, and the new york album is still there. Should I try deleting the New York album? Is there any way to back it up, like to retain the number of clicks and the comments, or do I just have to reupload all the pictures and start fresh?
Thanks again!
-Stephen
Posts: 130
I didn't think to look for the NY album in Shoobee.... Ok - try coding round that newyork album first.
In AlbumDB.php change:
to
Cheers, J
Posts: 130
I've just realised that you have 187 images in the ny album. I wonder if the number of photos is causing this issue. There is I believe a memory limit setting that you can specify for php which you might be exceeding.
I would try the code I suggested above to bypas the ny album. If that works then you could create a 2nd ny album and move half the photos from the first ny album into the new one.
Cheers, J
Posts: 78
Hey Myriagon,
Once I coded it the way you said, bypassing New York, it worked perfectly. I tried splitting up the New York Album roughly 100 images each, and it still doesn't work however. Is 100 images still too much? Should I try splitting it up again?
Thanks again!
-Stephen
Posts: 130
I'm amazed you managed to move/split it so quickly! If it's that quick and easy then I would try reducing the album size again by half although my suspicion is that it won't help.
From what I've heard my best guess is that something is corrupted in the ny album. By deleting some photos you might fix it. Deleting the album should fix it although I understand why you don't want to go down that route. You could also try putting more echo's in to try to find where the problem is. If you do find a corruption then you could try to fix it but personally I don't fancy hacking the album data files without knowing a lot more about their formats. That leaves deleting individual photos or deleting the complete ny album or stop using my code and the random photos code.
I would be interested to know if the random photos code works with the ny album bypassed?
Cheers, J
BTW I have to leave for my business trip soon. Hopefully I will get online again on Monday
Posts: 78
Thanks a lot for all your help, I guess I'll try moving it around some more and see if it works, but I do think something is probably corrupted with the NY album, as gallery remote did freeze up when uploading. If all else fails, I guess I'll just delete the NY album and reupload it again.
Your random photo code DOES work with the NY album bypassed, so I guess I'll just have to play around with that album some more.
Does anyone know how to backup an album so that it'll have all it's comments and number of clicks still intact? Is there anyway to delete, and reupload an album, and somehow merge the comments and number of clicks back into the album?
Thanks again, and I hope you have a lovely trip!
-Stephen
Posts: 15
Cool! I've been hoping someone would write something like this! Thank you!
I'm using the period filter. Is there any way to only show the photos uploaded in the last 7 days or so? As opposed to a whole month?
Posts: 78
Hi again,
Ok, after playing around for the past day or so with this, I'm still as stumped as ever. I completely deleted the New York album, and it works fine, I reupload all the pictures, and then it doesn't work. So I upload like 20 pictures at a time, and stats.php works until I get to around 50 images or so in the New York album. But at the same time, other users on my site are uploading pictures and Stats.php works fine, so I'm really not sure what the problem is. Right now, I just have albumdb.php bypass the new york album and it works fine, as it doesn't take into account the new york album.
I noticed that when I do include the New York album, the stats.php page just shows at the top, "750 images in the album" or however many images there are, but shows no pictures. Other times, stats.php is just blank.
Also, there was another top ten hack created earlier by someone else (http://gallery.menalto.com/index.php?name=PNphpBB2&file=viewtopic&t=9157&highlight=top+ten)
and that one works fine for me, including the New York album, but I don't quite the layout of this one, and how is that one different from Myriagon's?
Anyways, sorry for this lengthy post, but I'm just so confused, so anyone that can shed some light, it would be greatly appreciated.
Thanks!
-Stephen
Posts: 16
Is it possible to show new images from only one album and all its subalbums?
LEVaK
Posts: 15
Greetings, and thank you for stats.php.
Is it perhaps possible to create a cache file that can be read instead of going through the albums in realtime?
I have ~6000 pictures, and even though this works, it is still very slow.
Thanks!
/Jenny :D
Posts: 78
Hey Myriagon,
Just wondering if you're back yet from your trip?
=)
-Stephen
Posts: 130
Hi Stephen
Yes I'm back and suffering jet lag now... San Francisco was really cool although I'm sure I've put on a few lbs after too many dinners at the Cheesecake Factory!
How are things with you? Still problems with the NY album?
Cheers, J
Posts: 130
Hi Jenny,
Yes anything is possible - well almost!
I thought performance could be an issue but I have seen someone using stats.php with lots of images and it was performing fine on that website. I haven't confirmed this but I suspect performance is worse for large numbers of albums rather than large number of images. If you tell me your site address I'll take a look to see if there's anything obvious causing it to be slow besides the large number of images.
I have thought about caching before but I haven't implemented anything yet because ideally it will need changes to the core Gallery code to mark the cache as dirty when someone adds a new image or views an image.
An alternative that needs no core Gallery changes is to refresh the cache periodically but then the view count won't refresh until after the next cache update which from a user perspective is not so good. If I click to view an image I like to see the view count go up immediately.
Maybe there's another approach that I haven't thought of yet. Anyone with a better idea?
Cheers, J
Posts: 78
Hey Myriagon,
I'm not sure what the problem is now, but stats.php works at times, and at other times it doesn't work, even when I bypass the New York album, now I have no idea what the problem is, maybe it's the number of albums I have? If another user is able to have 6000 pictures, I don't think it's the number of pictures, but perhaps the number of albums? Anyways, any ideas you may have in why I'm having the problems I'm having, please let me know.
I'm glad you had a great trip as well, San Francisco is a wonderful city, next time, drop by SoCal, it's a nice place as well.
Again, thanks for everything!
-Stephen
Posts: 130
Mmmm... I don't like inconsistent problems... any idea what could be changing between when it works and when it doesn't? Does the random photo code stop working too?
I would love to get my hands on your data to reproduce and debug what's going on.
Cheers,
Jeremy
Posts: 78
Hey Jeremy,
Before, stats.php would work sometimes, but the random photo code would always work.
Alas, as of right now, stats.php and the random photo code both do not work, so I have no idea what's going on. I asked the hosting people, and they say it's not a php memory limitation, as gallery is working fine, and everything else is ok.
Is there any way I can get you my data somehow? Should I just zip it all up and send it on over? Any ideas you have will be greatly appreciated.
Thanks again for helping me through all this.
-Stephen
Posts: 47
SWEEEEET mod Jeremy! :D I've got it on my site configured to my needs, but I do have one question:
Why have the "votes" part in there if it doesn't work? I'm running 1.4.2 RC2, and would love it if there's a way to get that operational. I tried messing with it for a bit (un-commenting the getItemSVotes section and some other stuff) but to no avail. I'm just asking because I noticed that it works on YOUR site...
Thanks again for the great hack!
Hollis
WebHollis.Com
Posts: 130
Thanks Hollis for your support - much appreciated.
The details of how stats.php came about and how it relates to voting can be found at... http://gallery.menalto.com/index.php?name=PNphpBB2&file=viewtopic&t=13139&highlight=
I left the voting code in but stopped it from being called because it makes it easier for me to maintain stats.php. The code behind getItemSVotes can be found here http://www.tearoom.me.uk/voting.tar.gz This does not include all the stuff that allows me to select my new "simple" polling type in the voting properties window and also the voting page that I added. If you want that then I will dump all the code into a tar.gz file as there were many changes across several files.
If you want to implement your own version based on rank or order polling then you need to modify getItemSVotes() in AlbumItem.php. This has to return a vote or poll score that corresponds with the Gallery voting mechanism that you are using.
Hope that makes sense.
Cheers, J
Posts: 78
Just a quick question, for those of you with like 6000 or so pictures and with stats.php still working fine, are those pictures spread across a bunch of albums, or just a couple of albums? I'm not sure if it's the number of albums that I have that is causing my problems, I have about 30 or so albums.
Also, is there any way to do a clean install of Gallery, and still have all the pictures and albums intact? I'm really running out of ideas on what my problem could be, so I'm getting kind of desperate =)
Oh and Myriagion, I was just wondering if you could tell me how your stats.php is different from the view_top.php found at http://gallery.menalto.com/index.php?name=PNphpBB2&file=viewtopic&t=9157&start=60 , as that one works for me somehow.
Thanks again for all your help!
-Stephen
Posts: 130
Hi Stephen,
Looking in that code it does not use the same Gallery code that I use. Instead it uses a recursive function (a function that calls itself) to find the number of views for each photo. It would be interesting to adapt stats.php to use the same technique. If I get chance I will see what I can do.
BTW if you want to let me have a look at your gallery, then you will need to log onto you server using telnet or ssh. You can then run a command such as
That command assumes your photos and albums are all stored in the "albums" directory. I think that is the default. You will need lots of spare disk space to do this given the number of photos you have. I should then be able to download all your albums by downloading albums.tar.gz
Cheers,
Jeremy
Posts: 78
Hey Jeremy,
I know I'm asking a lot of you, but do you think that I can create you a FTP account for my site, and so then you can just go in and see all the code?
Would that work out, or would it be better that I do the tar -czvf thing? Anyways, just let me know, and again, I thank you very very very much for helping me through all this!
-Stephen
Posts: 13
Hi
I just installed the script and its working just great 8)
But, however I want to tune it a little bit more and I have no idea how to
do it :roll:
Look at the pics for more info.
This is how its now, http://andreas.spbk.no/.
[img]http://andreas.spbk.no/now.jpg[/img]
And as you all can see, it does not look to good.
This is how it's supposed to look afterwards
[img]http://andreas.spbk.no/after.jpg[/img]
Does it make any sense?
And where do I edit the text? like "latest images" and such? Not to mention the fonts
Is it included in my css-file somewhere?
Maybe this will help as well, since im very new to php, I used the include-syntax to view the script, there maybe other solutions to the problem but that's the only way I know about.
And how come I have a line over "IMG 4030"? The ass pic
Posts: 130
Hi Grimnar
I'm not sure what's happened - it looks like your version of the code has changed and is now trying to display both Latest and Most Viewed in the same page. Looking in the page source it now has two <head>'s which isn't right. Is it possible that you have duplicated the source code in the stats.php file?
Stats.php was not designed to show both Latest and Most Viewed simultaneously. There's no reason why it couldn't do that although I suspect the code would get very messy without a proper rewrite.
As for the fonts and sizes, IIRC they are defined in the css files used by the rest of Gallery. The intention was to have a similar look to the main Gallery page. You can edit the text "Latest" etc. by changing gallery/html_wrap/stats.header.default or defining your own gallery/html_wrap/stats.header. This should work although I haven't tried it.
Regards, J
Posts: 13
Thanks for the reply
I have no clue about the head stuff. Sorry about that. If it's not added with the script, I havent touched it
This is what I did i in the albums.php
So, all I want to to really, is to align stats.php?=date to the right, and
stats.php?views on the left.
[/u]
Posts: 130
Hi Stephen,
I downloaded your albums directory ok and then loaded it into my test setup. Surprisingly I could not reproduce your problem. You can have a look if you want. Try http://www.tearoom.me.uk/testgallery/stats.php?type=views and http://www.tearoom.me.uk/testgallery/stats.php?type=date Given the number of photos it is loading very quickly - at least when my ISP is not going slow.
The fact that it appears to work for me suggests:
- there's no problem with your data (number of photos and albums)
- I don't think there's a problem with stats.php itself - however it's doing something that is failing in your setup
- there could be an issue with your configuration (config.php, etc) - unfortunately our ISP cgi servers are different so I couldn't get your gallery directory working on my site
- there could be an issue with your ISP's cgi server
Sorry that I can't give you a solution. If you really want to make this work, then I would try setting up a new gallery installation like I've done with my testgallery. Setup the testgallery to use your existing album photos. Make the configuration as close to the standard Gallery install as you can, at least initially. If that fails too then I would suggest there's nothing wrong with your current configuration.
If that doesn't help then I would be tempted to try a different host server (ISP?) or temporarily borrow some of a friends web space and see if that helps. I suspect it would.
Cheers,
Jeremy
Posts: 78
Jeremy,
Thank you so much for helping me through all this, you've been such a big help and so friendly about everything, I feel so bad at times for bothering you so much!
Just a quick question, how do I go about setting up a new gallery installation with my exisitng album photos?
Thanks again for everything!
-Stephen
Posts: 130
Hi Grimnar,
The problem is caused by how you are trying to use the stats.php file. It is not designed to be included from another file although I guess it could be hacked to work in this way.
Sorry I cannot be anymore helpful.
Regards, J
Posts: 47
I've got 2100+ items on my site right now, spread over 93 sub-albums and it's running just fine.
Main Gallery Page
My Most Viewed Page
My Latest Items Page
Hope this info helps your problem Shoob!
Hollis
Posts: 78
Sorry to ask this again, but what's the easiest way to install another gallery if I already have one gallery set up, and then how do I proceed to integrate my current photos into the new installation? I believe I create another directory for the new gallery installation, and then do I just pretty much copy my old albums directory into the new installation directory?
Thanks again!
-Stephen
Posts: 130
Hi Stephen
This has probably been discussed before so it could be worth a search on this forum. There might be some issues with my instructions below as I haven't had the time to test them right now. Anyway...
First you need to download the Gallery files from this website. It's probably best to go with the version you are already using if it's still available. Put the files in a "testgallery" or whatever directory. If you have the disk space then copy your album directory files into another new directory, "testalbums" or whatever you want to call it. Then point your web browser to the http://.../testgallery/albums.php and setup the new installation as you did before. You will need to tell it where to find the albums - in this case it will be ".../testalbums". Otherwise it should be very similar to before. IIRC there's a parameter in there to make each installation seperate - can't remember what it's called right now. Make sure that is different from what you used for your old Gallery.
Hope that's enough to get you going.
Cheers,
Jeremy
Posts: 13
Yeah, i know that, but its the only way I know how to include the most viewed and stuff on my page