Top Ten Views / Clicks.
jelwell
Joined: 2003-05-29
Posts: 115 |
Posted: Wed, 2003-09-10 10:32 | |||
I wrote a php script to show the top 20 photos that have the most views. 20 is hard coded in the script but can easily be configured to show the top ten. Actually, quite a bit is hard coded, but it works. I might clean up the script later to output more standard display. But running the script must be a tad intensive and letting users compete will only drive up bandwith needlessly, so I might not let anyone on my server know about the link... ;) joe.
|
||||
Posts: 115
I forgot to mention one last thing. I hard coded a memory fail safe that prevents the script from keeping track of images that had less than 20 views. (which is about the cutoff number that includes my top 20).
Anyways, these two lines:
if ($numClicks > 20 ) {
and:
if ($gallery->album->getItemClicks($j) > 20 ) {
need to be modified so that the number "20" represents a good guess at where your cut off point is. I suppose you could just set it to 0, and that would definitely work, but your memory usage might get high if you have thousands of photos.
I'll be cleaning that up so that "20" is determined on the fly later, but for now - it works. ;)
joe.
Posts: 13
hey,
this is a damn nice script - i've been meaning to get around to writing this myself but really not had time. well done though!
one thing, you could write the top 20 to file once the top 20 pics have been found - this would speed things up and reduce the load on the server. you could just reuse the block-random code that does this - i did this when writing the last-updated script - i've got over 3000 pics in my gallery so if a few people request the top 20 it would kill mysever.
if you don't want to or dont have time to add this kind of functionality to your script i might have a go, if you don't mind, sometime this week!?
- pixelchimp
Posts: 115
Totally go for it! I've never worked with PHP until I started hacking extensively on Gallery. I was looking into a way to cache the results into a file for 2 reasons, one you mentioned already. But 2, I don't want users noticing in real time the results of clicking recklessly on their images in an attempt to boost their numbers.
joe.
Posts: 13
hey,
well i've made some changes so it now writes the data to a file and also you can call it within the url with the number of images you want it to display.
it works fine (well for me anyhow) but theres a few more features i want to add to it yet. but if you want to have a look and test the version so far for me - its available at http://www.chaoslibrary.com/gallery/view_top_v3.phps
and you can see it working at http://www.chaoslibrary.com/gallery/view_top_v3.php?display=50
let me know what you think, i want to add a few more features to it yet as i want to create a new section on my site which shows plenty of nice stats for the gallery (top pics/albums, top pics 10 pics in last 30 days etc - if i can)...
...anyhow i'm of on a weekendlong roadtrip...
-pixelchimp
Posts: 13
lo,
ok well i did a bit more on it today and you can see the source at http://www.chaoslibrary.com/gallery/view_top_v5.phps
and the result at
http://www.chaoslibrary.com/gallery/view_top_v5.php?display=20&list=1
as you can see from the URL you can add a 1 or a 0 to the list= to give the results in a list form or in the standard view with a thumbnail.
you can see my other notes in the top of the source file.
the main feature i want to add now is the ability to get a top 10/50 of the last 100 pics or something similar (basically a currently most popular pics feature).
hopefully this version should also work for anyone as well...
-pixelchimp
Posts: 107
Hi, I tried this and the first time I run it I get a slew of errors and when I refresh I then get what you show (list or block) but no numbers or urls...
Do I need to change anything in order to get this going or is it a script that isn't supposed to be edited?
The errors are:
Warning: arsort() expects parameter 1 to be array, null given in /home2/fractal/public_html/.../highest_clicks.php on line 328
Warning: reset(): Passed variable is not an array or object in /home2/fractal/public_html/.../highest_clicks.php on line 163
Warning: key(): Passed variable is not an array or object in /home2/fractal/public_html/.../highest_clicks.php on line 169
Warning: next(): Passed variable is not an array or object in /home2/fractal/public_html/.../highest_clicks.php on line 179
Warning: key(): Passed variable is not an array or object in /home2/fractal/public_html/.../highest_clicks.php on line 169
Warning: next(): Passed variable is not an array or object in /home2/fractal/public_html/.../highest_clicks.php on line 179
[I see the last 2 errors about 40 times and then I get the list]
Is it because I named the file highest_clicks.php? Nope, I just changed the file name to view_top_v5.php and it didn't work either...
Babs
Posts: 144
i tossed it into my /gallery/ dir and ran it and i get this
Fatal error: Call to undefined function: getcachednumphotos() in /home/drazin/public_html/gallery/top20.php on line 40
i dunno...
Posts: 144
ok it works now somehow..... but i sometimes get this error
Warning: Missing argument 3 for editcaption() in /home/drazin/public_html/gallery/util.php on line 48
Warning: Missing argument 3 for editcaption() in /home/drazin/public_html/gallery/util.php on line 48
Warning: Missing argument 3 for editcaption() in /home/drazin/public_html/gallery/util.php on line 48
Warning: Missing argument 3 for editcaption() in /home/drazin/public_html/gallery/util.php on line 48
Warning: Missing argument 3 for editcaption() in /home/drazin/public_html/gallery/util.php on line 48
Warning: Missing argument 3 for editcaption() in /home/drazin/public_html/gallery/util.php on line 48
Warning: Missing argument 3 for editcaption() in /home/drazin/public_html/gallery/util.php on line 48
Warning: Missing argument 3 for editcaption() in /home/drazin/public_html/gallery/util.php on line 48
Warning: Missing argument 3 for editcaption() in /home/drazin/public_html/gallery/util.php on line 48
alot.....
any iddeas?
Posts: 144
ok it works now somehow..... but i sometimes get this error
Warning: Missing argument 3 for editcaption() in /home/drazin/public_html/gallery/util.php on line 48
Warning: Missing argument 3 for editcaption() in /home/drazin/public_html/gallery/util.php on line 48
Warning: Missing argument 3 for editcaption() in /home/drazin/public_html/gallery/util.php on line 48
Warning: Missing argument 3 for editcaption() in /home/drazin/public_html/gallery/util.php on line 48
Warning: Missing argument 3 for editcaption() in /home/drazin/public_html/gallery/util.php on line 48
Warning: Missing argument 3 for editcaption() in /home/drazin/public_html/gallery/util.php on line 48
Warning: Missing argument 3 for editcaption() in /home/drazin/public_html/gallery/util.php on line 48
Warning: Missing argument 3 for editcaption() in /home/drazin/public_html/gallery/util.php on line 48
Warning: Missing argument 3 for editcaption() in /home/drazin/public_html/gallery/util.php on line 48
alot.....
any iddeas?
Posts: 238
I'm seeing the same error as drazin when the cache needs to be refreshed. When it reads from the cache file without rebuilding it, it works fine.
In util.php where editCaption is defined, it expects 3 arguments, but in topXphotos.php (or whatever everyone is naming their file), it only passes 2. $edit is missing. I've been messing with it a little on the side but haven't had time to figure out the issue yet.
At first I thought that editCaption might have changed in v1.4 (I'm still on 1.3.3). I haven't checked CVS yet but I know Drazin is on 1.4. I didn't want to post here until I had spent some time on it to figure it out, but figured I'd pipe in now that my error has made it on here.
Posts: 214
When I run the script directly all I get is
Parse error: parse error in /homepages/28/d66139791/htdocs/postnuke/modules/gallery/view_top.php on line 21
Posts: 144
i have 1.3.3
The script just broke for me....it now shows the NOT TOP 20.
what i mean is it displays 20 picutres but they have alot less then the top 20 do......the other day it was the real 20 now its just lower ones...
how do i delete the chache or something to get this fixed
Posts: 13
hey - sorry for the delay - been on a weekendlong partying spree in NY - even had some damn fine pics but managed to lose my camera.
anyhow, on my servers i'm only running 1.4+ distro's so i've not had chance to test on 1.3+. 1.4's editCaption only requires 2 args. if someone can have a look at this in 1.3+ it would be apreciated.
as for the other errors - im hoping this new version should correct them as i've cleaned the code up a fair bit...
can see it working at
www.chaoslibrary.com/gallery/view_top_v6.php?sort=uploaded&time=year
source at
www.chaoslibrary.com/gallery/view_top_v6.phps
for those that are having probs when cutting and pasting (ive had more than one mail about it) you can grab the code in zip format as well as source from www.pixelchimp.co.uk/scripts
info on the new feature in this version can be found at the top of the script - bascially you can call the script within the url asking for the top viewed pics uploaded or from albums updated in past hour/day/month/year etc. seems to work ok on my galleries - although i've not had all that much time to test.
let me know how you get on....
-pixelchimp
Posts: 13
i forgot to mention that with large sites you'll need to increase the amount of image links that get saved to the cache file (default is 200) as sorting (by uploaded date etc) is only performed on the cached results.
otherwise you may find you get a small number of results returned.
-pixelchimp
Posts: 90
Nice script, I was looking for something along these lines... I'm going to modify it some to fit my site though.
The fix for 1.3x errors is simple. Just open the script in a text editor and search for "editCaption" and then add $edit after $index so the final lines look like this:
and...
And that's it... save the file and upload it again, works fine
J-
www.perfectcell.org
Posts: 90
I'm not done yet, but this is the start of the customization for this script. I use phpNuke and in the end I want this script to look just like any of my other albums, inluding my current customizations...
Here's the start:
http://www.perfectcell.org/modules.php?name=Top_Screensavers
I'll post the link to the finished project when (if) I finish it
J-
www.perfectcell.org
Posts: 144
i use 1.3.3 and i still get that error anyone have any ideas?
Posts: 90
I'm not sure if this has anything to do with it, but it might.
The cache file is rebuilt every 12 hours... so if the "bad" information is still in there... you could still get the errors until the cache file is rebuilt. To force an immediate rebuild, find the line that says "$rebuild = 0" and change it to "$rebuild = 1" and then upload over your current file then view it in your browser to rebuild the cache file. Then change it back to zero so it doesn't rebuild every time someone views the page.
I hope that works for you,
J-
Posts: 13
one thing i noticed is that if you have some strange chars in your comment field it can cause the script to not correctly identify the fields during the sorting by uploaded/updated function.
i noticed when i had put a comment on multiple lines there would be a "^M" char after the "< / br >" which would cause this.
this only happens when you get it to sort by upload etc though.
the next stage for the development of the script is to tie it together with the last-updated scripts and top-10 albums and such to generate a full page of gallery stats. I'll let you know how i get on with this...
-pixelchimp
Posts: 90
Here it is... a "Favorite Album" hack modified for phpNuke. Actually I just made it into a phpNuke module.
Thanks a lot for doing all the hard work on this code... all I did was hack it apart and customize it some to include phpNuke links, interfaces, modules, and a few more gallery variables (date added, name, album name, etc... all of which are written to the cache file.)
You can check it out here:
http://www.perfectcell.org/modules.php?name=Top_Screensavers
And if anyone is interested, let me know and I'll post the source, but beware, you must have at least a general knowledge of php and gallery variables to customize it for your site.
Let me know what you think,
J-
www.perfectcell.org
Posts: 92
Jelwell,
Is it possible to remove the shadow border around the thumbnails, replacing them with a single pixel white border?
Thanks for a handy script.
Hugh
http://www.partyvibe.com/gallery/
Posts: 214
I cannot include the script as a postnuke Block.
As postnuke let's me include a "Block/PHP Script" I thought just to copy the code into it.
But all I get is a block with the following error displayed inside: "Parse error: parse error in /homepages/28/d66139791/htdocs/postnuke/includes/blocks/php.php(101) : eval()'d code on line 1"
I get the same error with the other scripts fom discobug (Latest update ...)
postnuke .726
gallery 1.4-pl1
Posts: 135
Can anyone help me with this error at http://ourphotos.org/view_top.php
"ERROR: requested index [8] out of bounds [7]
Fatal error: Call to a member function on a non-object in /home/www/ourphotos/classes/Album.php on line 1031"
Thanks
Posts: 2
How can I intergrate this into Postnuke with my Theme?
I guess this doesent work becaus of the second '?'
http://www.mysite.com/modules.php?set_albumName=album02&op=modload&name=gallery&file=index&include=view_top.php?display=year
If I call the file like this it works:
http://www.mysite.com/modules/gallery/view_top.php?sort=uploaded&time=year
but like this my Navigation and my Header etc. are no included.
Any ideas?
Posts: 2
I have the same problem with large Gallery.
ERROR: requested index [8] out of bounds [7]
Anyone solved the problem?
Posts: 4
Still no solution to this?
Mine also says:
ERROR: requested index [5] out of bounds [4]
Fatal error: Call to a member function on a non-object in /home/esbjerg/public_html/gallery/classes/Album.php on line 922
Posts: 4
Hmmm seem like I solved the problem...made it run v5 instead and rebuild the cache, then it worked...and now the other version (6+7) also works...wierd
Posts: 1
I've gotten v6 working just fine for viewing the top 20 most viewed pictures. However it only spans the number of galleries i have on a given page. for example, i have 7000 pictures in about 40 different galleries give or take. the top 20 only does the top 20 for a given page. if i have 5 galleries per page it only does it according to the 5 on the page you are viewing. How can this be changed to take the top 20 from EVERY gallery, EVERY picture? or am I doing something wrong right now?
www.gingers.org/gallery/view_top_v6.php
Posts: 115
new version. adds ability to restrict the results to a single owner.
oh, and someone asked, "How can this be changed to take the top 20 from EVERY gallery, EVERY picture? or am I doing something wrong right now? "
answer: ummm, it already should. the script recursively crawls your entire website. Maybe the top 20 only appear to be coming from the first gallery because they're actually the most popular.
joe.
Posts: 10
Do you need to have the click results viewable in the albums for this to work?
I have my viewed #times off and the script shows nothing in the results.
Posts: 3473
Gallery does not increment clicks if it is not displaying them.
Posts: 115
Minor update to support Gallery 1.4.1. This version won't work in 1.3.3.
Joseph Elwell.
Posts: 12
jelwell,
Thanks for the 1.4.1 update. It works great. I have one small bug. If I have gallery set to show 5 albums per page, and I click on a link to the top 20 pics, I get the top 20 from the albums on that page, not the whole website. For now, I have all of my albums on one page to get a "true" top 20. Any ideas on how to go back to mulitple albums per page and keep a "true" top 20? Here is my site, so you can see what I am talking about. Drop me an email if you have time and I can set it back to 5 or so albums per page and show you the top 20 lists. http://www.whitjanes.com
Posts: 115
Ahhh! Thanks for the detail in the bug report. I was wondering why people were running into problems with some albums not being included. I think I've fixed it. Please try this version out and let me know.
joe.
Posts: 12
You got it. Thanks for the quick response and fix. :P
Posts: 130
fix works for me too
Posts: 8
Great work!
First I have problem because i have 4500 pictures an I get error .. time exceed ... than I put $minSearch = 50; and $maxStore = 50; and now is everything OK.
Regards,
Marjan
http://www.slo-foto.com/gallery
Posts: 29
I installed the view_top.php in the Gallery directly, but I can't view it. Does anyone know how to get this installed in postnuke?
If I add a link on the main menu (modules/Gallery/view_top.php), then I get the error: "can't access this file directly"
Thanks.
Posts: 29
Hmm, it works, but now it's displaying it in it's own page. Anyway to change that so users can still see the left block? Also, when someone clicks on one of the top photos, they're getting this error message:
Fatal error: Call to a member function on a non-object in /homepages/26/htdocs/postnuke/html/modules/Gallery/view_photo.php on line 38
Posts: 115
Sounds like you are using something other than 1.4.1? Try one of the earlier releases of view_top.php.
joe.
Posts: 238
I am seeing some strange behavior with this script. When it is accessed at a time when the cache file has to be rebuilt, the formatting is off. My header and footer are in place, the page title is on top of the header instead of below, and the page content is placed to the right of them. However, when the cache file is only read, the formatting works fine.
:-?
To demonstrate what I am seeing I made a copy of the script and set CACHE_EXPIRED to 30 seconds. Please view the page >>here<<. Then hit refresh before the 30 seconds are up, it'll look good. If you wait 30 seconds, it'll be off again.
Looking at which functions are executed in the two cases, I found that commenting out one line in scanAlbums fixes the issue: Line 400:
print "<tr>";
Not sure if anybody else ran into this, but thought I'd post it as an FYI.
Posts: 29
Sorry, but it is currently Powered by Gallery v1.4.1. As soon as I removed the block, the problem disappeared. It seems random as it may display it on one refresh but not another. I also noticed that it will only allow an admin to choose maybe 5 out of 100 albums with some albums being listed multiple times.
Posts: 57
Hi, I am trying to get this to work on my server. I used to get a division by zero error, but i re-ran the configuration script and it fixed this error. Now when I run the php file, I get no thumbnails, some viewed statistics, some do not have viewed, and some have the thumbnail caption where the viewed number should be. Some also have ">116598 " (or some other "random" numbers) where the picture should be. I am using version0.7.4.1 on gallery 1.4.1. It would be a tremendous help to me if I could get this script working! My page is herehttp://www.imagemanagement.ws/gallery/view_top_201.php
Posts: 2
I have exactly the same Problem as zombor ..must be a bug in the script
Posts: 57
That sux...I do not have enough php experience to even try and debug the code, and this would be of vast importance to me if I could get it up and running...
Posts: 1
Here's my small attempt to give back to this site for the excellent code than I've already taken.
Disclaimer - I'm not a coder. I know nothing about php. I've never coded anything for anyone so if this code sucks - well that's why. All the mods made here were pretty much just guesses.
So here are the issues that I ran into with the view_top_v6 code and my mods.
1. the “requested index … out of bounds
Posts: 115
don't know why you're all hacking version 6 when the view_top code is at version 8.
joe.
Posts: 90
..it would be even nicer if the script could be given an option to pick the top 2-3 photos from EACH album..
Why? take a look at my top 20 pics here -
http://mvgals.net/gallery/debug_top.php
(this link is not on my site, btw... just testing this.. may take ~30 seconds or so to load..)
almost all of the top 20 pictures belong to the same 2-3 albums.. Why? because they pop up as front-page searches for common keywords on google (southflorida clubbing pics, amsterdam clubbing pics, and burningman 2003 pics to be percise..). They're definately not the most popular or the best on my site, but google takes people directly to some of the pictures..
Likewise sometimes promoters send out mass emails w/ links to some of my pictures - those albums frequently get ~500-1000 visitors in a day or two.. Best pictures? No, just the most advertised...
How hard would it be to modify this script to show the top x pictures from the top x albums?
-mark
ps - anyone else having problems staying logged into this site? It keeps logging me out, despite telling it to keep me logged in.. and yes, my cookies are on
Posts: 90
btw - where's version 8 that's talked about on here?
-mark
Posts: 54
Is there anyway to get the listing option with the photos captions? Or can I customize this somehow?
If would like it to show off like this:
********
Top 10 viewed pictures
1. (Album Name - Caption name of the picture)
2. (Album Name - Caption name of the picture)
etc...
********
I don't know a frickin shit about PHP, hahaha. But I'll see if I can somehow figure it out how to do
If I somehow succeed I'll post the solution here.
Help IS appreciated hahaha :D
http://www.uvpucko.com