Solution: top 10 albums and last updates including sub-album
ppmnt
Joined: 2003-01-12
Posts: 238 |
Posted: Mon, 2003-02-03 00:31 |
June 11 2004 - ========================================= March 1 2004- I have also updated the code and improved the scripts some, as well as made it easier to customize. For example, it is now easy to set the number of albums to be displayed. You can also display the top X albums with a rank (like on >> my web site <<). Unless you already have it working and you are happy with it, please download the new versions. I will leave the info below so that this thread still makes sense. But please check the more detailed instructions on my >> help pages <<. ========================================= Feb 23, 2004 - I updated this post to make it a little easier to read. Since the boards update the code sections was just too messy looking I know some of you said you were working on this, so I didn't want to keep bugging you. But since I just reorganized my gallery into only 3 top level albums (for now), it was urgent for me to try to fix the top 10 / last updated scripts so that they include sub-albums. Check out >> my web site <<to see the new top 10 script in action. I haven't updated the last-updated one yet, but here's what you need to do to make top10albums.php get a list of all albums, not only the top-level albums: 1.) Download the script you want >> here <<. Credit still goes to pixelchimp, all I did was change some function calls to call new modified functions (see next step) and take out the double isRoot() check. March 1, 2004 - By now I've made more changes than that... 2.) Add 3 custom functions to AlbumDB.php. They are modified copies of functions that already exist and that are used by top10. You can add these anywhere within AlbumDB.php in the functions section (except in the middle of another function, of course). One way is to add all custom functions at the very bottom, just before the last } ?> Add these 3 functions: // --------- BEGIN CUSTOMIZATIONS --------- // /* 20040218: Added numAllAlbums, getAllAlbum, and getAllVisibleAlbums to also scan sub-albums (not just root albums) to be used by top 10, most recently updated, etc mods */ function numAllAlbums($user) { return sizeof($this->getAllVisibleAlbums($user)); } function getAllAlbum($user, $index) { global $gallery; $list = $this->getAllVisibleAlbums($user); if (!$list[$index-1]->transient->photosloaded) { $list[$index-1]->loadPhotos($gallery->app->albumDir . "/" . $list[$index-1]->fields["name"]); } return $list[$index-1]; } function getAllVisibleAlbums($user) { global $gallery; $list = array(); foreach ($this->albumList as $album) { if ($user->canReadAlbum($album)) { array_push($list, $album); } } return $list; } // --------- END CUSTOMIZATIONS --------- // That's it! Have fun! ~Eva |
|
Posts: 238
Post not needed anymore...
Posts: 18
This is great! Thank you for taking the time!
With that said..I'm having one problem ...
When I add it to my page I get an error "Object Expected" on line 29.
The page works fine without the include. ==> http://www.Picolio.com/
The include works fine without the page ==> http://www.Picolio.com/test.php
But when I put the include into the page I get the error on page ==> http://www.Picolio.com/indexTest.php
(you can see the little error message at the bottom of IE5.5 especially if you mouse over the links in the 'last updated' area.
When viewing the code itself line 29 falls in the IFRAMEs for the random images...
<IFRAME id="blockrandom"
onLoad="iFrameHeight();"
src="http://www.picolio.com/Gallery/block-random.php?&target=_top"
width="180"
height="130" align=center valign=middle scrolling=no frameborder=0>
[This feature requires IFRAME.]
</IFRAME>
Any ideas?
Thanks again!
Deb
Posts: 238
Deb,
If you look at the source of my page you'll see that I'm actually using an iFrame for the latest updates, not an include:
<!-- BBCode Start --><TABLE BORDER=0 ALIGN=CENTER WIDTH=85%><TR><TD><font class="pn-sub">Code:</font><HR></TD></TR><TR><TD><FONT class="pn-sub"><PRE>
<iframe width="300" height="250" frameborder="0" src="http://www.discobug.com/gallery/last-updates.php">
Your browser does not support IFrames.<br>
Yhis section would show you the latest updated albums in the
<a href="/gallery"> photo gallery</a>.<br></iframe>
</TD></TR></TABLE><!-- BBCode End -->
I didn't try an include. I'm on my way out, but I can try it later. Otherwise, would an iFrame be an option for you?
~Eva
Posts: 18
Hmmm, I'm not versed enough with IFRAMEs to understand it but I removed the following line from both of the IFRAMEs on top of the page for the random images
onLoad="iFrameHeight();"
Now it all works :razz: http://www.Picolio.com/ <<== shows it
Thanks very much for taking the time to provide this enhanced feature!
Deb
Posts: 238
All the did is take away the functionality to resize the iFrame automatically depending on the height of the thumbnail. If you took that out you can also remove this:
<!-- BBCode Start --><TABLE BORDER=0 ALIGN=CENTER WIDTH=85%><TR><TD><font class="pn-sub">Code:</font><HR></TD></TR><TR><TD><FONT class="pn-sub"><PRE>
<script language="JavaScript">
// Credit goes to user kenny9336 on "http://www.experts-exchange.com"
function iFrameHeight() {
if(document.getElementById && !(document.all)) {
var h = document.getElementById('blockrandom').contentDocument.body.scrollHeight;
document.getElementById('blockrandom').style.height = h;
}
else if(document.all) {
h = document.frames('blockrandom').document.body.scrollHeight;
document.all.blockrandom.style.height = h;
}
}
</script>
</TD></TR></TABLE><!-- BBCode End -->
That should be somewhere between your <head> ... </head> tags, that was the function that one line in the iFrame was calling.
I think on your page that's not imortant anyway, because the Pic Olio image on top is higher than your random thumbnails. If you look at <!-- BBCode Start --><A HREF="http://www.discobug.com/" TARGET="_blank">>> my page <<</A><!-- BBCode End --> again, as it loads you can see that the left side moves up once the thumbnail appears. Otherwise there'd be too much space underneath the image when it loads a landscape photo.
By the way, if you never had the code above in your <head> area, then that would explain the error you were getting, as it was calling a javascript function that wasn't defined. :razz:
Anyway, it looks great!
Posts: 238
I was just looking at your pictures (Nikki and MacDonalds is a crack up!), and noticed you actually seem to have that error on every page. The random image iFrames in the header still have this line in them:
onLoad="iFrameHeight();"
But when I did a view source I couldn't find the function defined in your <head> tags.
Posts: 18
Yeah I'm a slowpoke (spend too much time with Nikki at McDonalds hehe) but it's all fixed now :grin:
I didn't use an include so needed to make the same edit within all of the header files in Gallery.. I got preoccupied with your other mods though LOL
Posts: 238
LOL - no problem, just thought I'd mention it, as I was worried how the last-updated block could have caused that error. :grin:
Posts: 8
Ok, I must be dumb or something but I can't figure this one out.
For some reason this is what I get when I call last-updates.php:
<!-- BBCode Start --><TABLE BORDER=0 ALIGN=CENTER WIDTH=85%><TR><TD><font class="pn-sub">Code:</font><HR></TD></TR><TR><TD><FONT class="pn-sub"><PRE> 215 photos in 8 albums:
Vacations<a href="#" onClick="javascript:nw=window.open('http:
last updated:
Caving Clarsville<a href="#" onClick="javascript:nw=window.open('http:
last updated:
Outdoor<a href="#" onClick="javascript:nw=window.open('http:
last updated:
Outdoor<a href="#" onClick="javascript:nw=window.open('http:
last updated:
My dad's hydroplane<a href="#" onClick="javascript:nw=window.open('http:
last updated:
</TD></TR></TABLE><!-- BBCode End -->
You can check it out at <!-- BBCode Start --><A HREF="http://www.ngray.com/gallery2/last-updates.php" TARGET="_blank">http://www.ngray.com/gallery2/last-updates.php</A><!-- BBCode End -->
Any guesses as to what’s going on?
- Nebular
Posts: 238
Nebular -
I get that same problem when I'm logged into the gallery as admin. I followed your link and it looks fine for me, so I think this is the same problem. Try logging off and look at it again.
This is some problem with the original code, I never tried to figure it out once I realized it looked fine to everyone else. I don't have any users with login IDs on my gallery, so I'm not sure if it also affects non-admin users.
Also, as a tip, it also breaks if you have a "/" anywhere in your album title, because the cache file is /-delimited.
Posts: 8
Ohhh... that's better! Thanks!
btw, wonderful addin!
Posts: 50
First of all, thanks for your coding, ppmnt, it's a good improvement for a lot of galleries, including mine :smile:
I see some people want it to work with an "include" instead of an "iframe", though. I've had to do this in my gallery. It's as simple as commenting the following lines:
<!-- BBCode Start --><TABLE BORDER=0 ALIGN=CENTER WIDTH=85%><TR><TD><font class="pn-sub">Code:</font><HR></TD></TR><TR><TD><FONT class="pn-sub"><PRE>require($GALLERY_BASEDIR . "init.php");
readfile("header.html");</TD></TR></TABLE><!-- BBCode End -->
Also, it can be useful editing the last lines of the PHP page, so it integrates better in the gallery web page. Something like this:
<!-- BBCode Start --><TABLE BORDER=0 ALIGN=CENTER WIDTH=85%><TR><TD><font class="pn-sub">Code:</font><HR></TD></TR><TR><TD><FONT class="pn-sub"><PRE>[...]
$numAllAlbums = $albumDB->numAllAlbums($gallery->user);
$numPhotos = $albumDB->numPhotos($gallery->user);
?>
<span class="title">Last updates</span><br>
<?
// for loop reads the data from the arrays and renders it on screen
for ($i = 0; $i <= 4; $i++) {
$albumURL = makeGalleryUrl($cacheName[$i]);
if (strcmp($cacheRealName[$i],"")) {
echo ("&nbsp&nbsp<a href=" . $albumURL . ">" . $cacheRealName[$i] . "</a> (" . $cacheDate[$i] . ")<br>");
}
}
}
echo ("<br>");
?>
</table></TD></TR></TABLE><!-- BBCode End -->
You can see it working (in Spanish :roll: ) in <!-- BBCode Start --><A HREF="http://ganso.org" TARGET="_blank">my web page</A><!-- BBCode End -->.
Posts: 11
Hi
I use this functions with iframe, but can't see the album when I click on the link in recent updates and top 10 albums.
My folder setings for Gallery is:
Standard configuration
gallery/
gallery/last-updates.php
gallery/top10albums.php
gallery/albums
Here is the link to the test file: http://mitgalleri.com/recent.html
or
Here is the link to the test file: http://mitgalleri.com/gallery/last-updates.php
or
Here is the link to the test file: http://mitgalleri.com/gallery/top10albums.php
What to do?
Posts: 314
You're getting this error because your Gallery doesn't have mod_rewrite enabled. This script assumes you have mod_rewrite enabled (not that good). You could solve it by rewriting the part of the script where URLs are created to use the non-mod_rewrite URLS, e.g. inserting "view_album.php?set_albumName=" in the code.
Posts: 11
Hi Again
PHP is very new for me, could you please explain and show me how to make the changes?
Thx
Posts: 238
Thanks, TheGoose, I'll try that out. Might look a little better loading over a slow connection.
Posts: 238
TheGoose -
Two things: I went to your page and clicked on the Andalucia album, and found the following:
Warning: Failed opening 'last_updates.php' for inclusion (include_path='.:/usr/local/lib/php') in /usr/people/goose/public_html/gallery/view_album.php on line 591
Also, when you comment out those two lines, you miss a lot of function definitions, so I get the following:
Fatal error: Call to undefined function: fs_file_exists() in /path/to/gallery/top10albums-noi.php on line 63
I saw the same thing when I went to the URL of <!-- BBCode Start --><A HREF="http://ganso.org/last-updates.php" TARGET="_blank">your last-updates script</A><!-- BBCode End -->
I remember I was trying to mess with this last night. including the required class files directly in the album instead of init.php, or using different functions. I was tired and finally gave up.
Has anybody else got this working with a php include instead of an iframe?
Posts: 50
Oops !! I tried to keep it just in the main gallery page, and I though view_album.php was the right file. I'll try to correct it later at home.
I don't use the top10 albums feature, as I have less than 10 albums :wink:
Again, I'll try to look at this afterwards. Anyway, as the PHP code is included inside the original code, which already inclused init.php, it should work, at last when included only in the main page (as I tried to do :roll: )
Posts: 50
I have corrected the "Failed opening 'last_updates.php' for inclusion" error. I had left an wrong include-line in view_album.php, since a couple of test I did some time ago. I didn't have anything to do with the latest modifications.
Posts: 13
thanks ppmnt for fixing this issue for me, i was trying to find time to get around to making these changes to the scripts, as i don't use sub-albums on my site it wasn't a priority for me unfortunatly.
good work though, pat on back well deserved!
- pixelchimp
[<!-- BBCode Start --><A HREF="http://www.chaoslibrary.com" TARGET="_blank">www.chaoslibrary.com</A><!-- BBCode End -->]
Posts: 238
Thanks pixelchimp. I didn't want to step on anybody's feet by doing this, I knew you said you were going to get to it at some point... I just couldn't wait! :grin:
Thanks for the original scripts!
Posts: 18
Hi -- This is really great! I am pretty new to this but I was having a little bit of trouble making the links work within my phpnuke-powered site. Anyway, after a little tweaking, I finally got it to work and I also added a photograph (although that had to be manually selected.). If anyone is interested, I will make the revised code available. If you want to see it, look at http://www.kalorama.net. Anyway, thanks ppmnt and pixelchimp for a very useful script.
Posts: 185
I can't access discobug for the last-updates.php code. Can anyone else? or point me to someone else that has it for download? Thanks!
Posts: 238
discobug is back up now, try again: <!-- BBCode Start --><A HREF="http://www.discobug.com/last-updates.phps" TARGET="_blank">>>last-updates.php <<</A><!-- BBCode End --> and <!-- BBCode Start --><A HREF="http://www.discobug.com/top10albums.phps" TARGET="_blank"> >> top10albums.php <<</A><!-- BBCode End -->
Well, I've been with this host for 2 years, this is the first time Apache has gone down. That's a pretty good record, I guess. :smile:
~Eva
Posts: 185
Thanks! I'll be playing today, and yes, that is a good long time to have things working well.... :wink:
Posts: 185
Works perfectly in tests. I don't know if anyone else does this, but I use / in my dates on the album names like:
NYC - 5/5/99 and save/read cache functions use / as the separator for each item so the data getting pulled from the cache cut off..
I deleted my cache, changed the lines in the code to use | (since I never use pipe ever) for the save cache function to be (make sure you get all of them):
fwrite($fd, "$nameArray[$currentKey]|$albumName[$currentKey]|$clickArray[$currentKey]n");
and in your read cache function, look for the explode and change it to whatever character you're using, like:
explode("|", $line);
....and no, don't tell me to write my title dates differently, it's easier to do this, then rename all my albums :wink:
Posts: 238
dtdgoomba -
Yeah, I noticed that too, but then I forgot that I meant to change that before I put them up. Both the top 10 & last updates cache are slash-delimited. And dates are pretty common for album names, I would think...
Thanks for sharing!
Posts: 144
hello all!
i'm having a problem with the top 10 and last updates addin.... when i try to use the php i get this error
Warning: readfile(header.html) [function.readfile]: failed to create stream: No such file or directory in /home/drazin/public_html/gallery/last-updates.php on line 87
1917 photos in 47 albums:
and
Warning: readfile(header.html) [function.readfile]: failed to create stream: No such file or directory in /home/drazin/public_html/gallery/top10albums.php on line 72
any ideas?
edit: i took out the line of code that refers to header.html and now it sorta works but it donsent have any info like how many clicks....or when it was updated.....plz help
Posts: 6
I was wondering if any of you could help me. I have successfully implemented the last updated code now for sometime. But just now for some reason it seems to be freaking out.
Could anyone look at
http://www.cyberlok.org/cyberlok/
tell me what you think let me know in any way I can help with the info.
I just cant seem to figure out what could be causing this bug.
Posts: 8
nice hacks, cheers
Posts: 3
ppmnt, who did you feature your sub albums on the main page like that? please help.
Posts: 8
where about exactly does that code go?
Posts: 12
I'm going to try to bump this because I don't have the foggiest where the mod_rewrite section of code is and whether I should be enabling or disabling it.
More specifically, I am getting the same header errors that drazin was getting:
)
...which you can see <!-- BBCode Start --><A HREF="http://www.trystery.com/gallery/lastupdates.php" TARGET="_blank">here</A><!-- BBCode End -->and <!-- BBCode Start --><A HREF="http://www.trystery.com/gallery/top10albums.php" TARGET="_blank">here</A><!-- BBCode End -->.
Can anyone help? Where is this header file supposed to be? I load other people's lastupdates.php and it does not come with a header errror...
Posts: 18
I also had the admin seing an odd album name with a javascript edit when I used the last updated mod.
I added the following when getting the album name...
$albumName[$i] = strip_tags(editField($gallery->album, "title", $edit));
$albumName[$i] = str_replace("[edit title]", "", $albumName[$i]);
Which just cleans it up in case the admin happens to be the person who renews the cache.
Posts: 239
ppmnt: which method did you use to count the total albums on your site on the main page?
Posts: 238
This thread should help you:
<!-- BBCode Start --><A HREF="http://gallery.menalto.com/modules.php?op=modload&name=phpBB_14&file=index&action=viewtopic&topic=2317&start=0" TARGET="_blank">http://gallery.menalto.com/modules.php?op=modload&name=phpBB_14&file=index&action=viewtopic&topic=2317&start=0</A><!-- BBCode End -->
Posts: 238
simplythi -
Check out <!-- BBCode Start --><A HREF="http://gallery.menalto.com/modules.php?op=modload&name=phpBB_14&file=index&action=viewtopic&topic=1127&9601" TARGET="_blank">>> this thread <<</A><!-- BBCode End --> for info on how to change how many levels of sub-albums are displayed in the sub-albums list. I have mine se to "1", it got to crowded.
Then I made some changes to util.php. I wanted to be able to display the number of clicks in other places, but not in the list of sub-albums on the main gallery page. For me this is around line 1273 int he printChildren function that you modified if you followed the instructions in the linke above. Basically I just commented out the part that gets the number of clicks:
<!-- BBCode Start --><TABLE BORDER=0 ALIGN=CENTER WIDTH=85%><TR><TD><font class="pn-sub">Code:</font><HR></TD></TR><TR><TD><FONT class="pn-sub"><PRE>/* ------ don't display # of hits in sub-album tree!
if (!strcmp($nestedAlbum->fields['display_clicks'], 'yes')) {
$val3 = "(" . pluralize($nestedAlbum->getClicks(), "hit", "0") . ")";
} else {
$val3 = "";
}
------ */ </TD></TR></TABLE><!-- BBCode End -->
I think that should get you started. I also commented out 'echo "<span class=fineprint>";' to make the links a little bigger.
Is this what you were looking for?
Posts: 18
I have been using this script for the past week and just took it out, I was looking at my httpd processes (1.3.27) and noticed that they were all chewing up a ton of memory.
I did an 'apachectl graceful' and they go back to normal - but as soon as I refresh my top10.php they jump up to about 60mb/process and stay there.
I can refresh my main page without the top10.php include() and the processes stay at the normal 15mb/process.
So - I suspect there is something wrong with the code - especially since it causes the mem jump even when its reading from the cache file (ie not scanning the albums).
http://jadz.com/last10.phps is the code I'm using (with the added functions at the beginning of this thread).
Posts: 238
adams -
That's strange, I had no such problems (also running 1.3.27). I tried to go check but unfortunatley my web host just implemented jailshell so I can't monitor processes other than my own anymore.
The code itself would be a bit memory intesive, kind of like doing a complicated awk or sort or something that needs through text files. But like you said, that should not be the case if the cache file isn't expired.
Sorry, I can't help you trouble-shoot as I can't monitor Apache anymore. But I know that I didn't have any problems before...
~ppmnt
Posts: 238
Sorry it took so long for you to get a response, I didn't see your question right away.
Just comment out the line where it calls header.html:
It's line 90 for me. Put "//" in front of the second line.
You seem to have another problem as well:
Warning: fopen("/home/virtual/site147/fst/var/www/html/gallery/albums/last-updated.cache", "w") - Permission denied in /home/virtual/site147/fst/var/www/html/gallery/platform/fs_unix.php on line 53
Make sure the cache files are writable by the ID that runs your web server (usually www or nobody).
Posts: 238
Thanks for the tip!
Posts: 3
hey everybody, i have 2 quick questions that i haven't been able to find a definitive answer for:
1. http://www.anothersaab.com/gallery/top10albums.php
- what is causing just "Visits" to appear. what am I missing?
2. http://www.anothersaab.com/gallery/last-updates.php
- why are my dates showing up incorrectly. the order is correct, but 3 of the 5show up right and 2 show just a number and 2 have long titles and they are getting chopped.
thoughts?
Posts: 238
anothersaab -
Looks like you got last-updates to work by now. What was the problem?
Regarding top10albums, can you show your top10albums.php? Just make a copy of it and call it .phps, so we can view the code in the browser.
PS: Great dogs!!! :D
Posts: 3
yes, i did get the last-updates corrected. the problem with that was simple. 2 of the albums contained dates with slashes (01/01/2001) and the slashes caused the album name to be truncated and the last update date to read just a number.
here is my top10albums.php: http://www.anothersaab.com/gallery/top10albums.phps
thanks for the dog compliment. as a matter of fact, i just got home from walking them to the coffee shop and i saw your post. thanks for the compliment *and* helping me out.
Tim
Posts: 238
anothersaab,
OK, thanks for showing your top10albums code, I was hoping it would be fairly obvious. The problem is that you added all those additional functions to the top10albums.php instead of to AlbumDB.php .
Go back to the very first post on this thread and read through it. Then add only the numAllAlbums, getAllAlbum, and getAllVisibleAlbums to AlbumDB.php. I am only showing the other functions as a reference point.
I updated the top10albums.phps file on my site. it now uses pipes ("|") as a delimiter, and even if you are logged in as admin when you refresh the cache you won't get funny characters in your links (thanks to dtdgoomba and adams).
Let me know if it works out for you!
~Eva
Posts: 238
cyberlok -
Interesting layout you have at that link. Looks familiar somehow (especially when I do a view source!)
Anyway. To trouble-shoot your problem, go to last-updates.php on your site in a browser (> here <). Then do a "view source" on it. You'll see that it's a bit messed up:
Your stylesheet reference is not inside a <head> tag. It starts table rows but there is no <table> tag. However, at the end there is a close table tag.
When I do the same thing at my site, a view source shows this:
It looks like maybe at some point you tried to change the way it is displayed and some tags got screwed up.
This is how the for loop at the end of last-updates.php looks for me:
Looks like you need to tweak yours some to make sure you open and close all the tags you need...
Tip: when something goes wrong, a view source usually helps trouble-shoot.
~Eva
Posts: 25
This script is wonderful and works great. I do have an issue tho, the gallery I am working with is 95% user only and it has a sample gallery. It seems that if a non-user hits the page after the 10 minutes, then they generate a new cache file that shows only the sample gallery as new. Is there a way to specify that the cache is only updated by users?
Thank you
Posts: 3236
Just wanted to say I updated to your version (with some minor modifications so it fits my site) and its super, thanks for asking. I was hoping something like this would appear and it did. Glad you could do the coding, cause asside from minor cosmetic tweaks I am lost in gallery code
If anyone wants to see how it was applied, http://fryfrog.com/ on the left side
Posts: 25
So is that a no?
Posts: 238
Kyliedog,
I was moving and didn't see your post until now. I apologize. It should be as simple as changing this:
to this:
This would make it so that the cache is only rebuild if the user viewing the page is logged in. I haven't tested this yet, but it should work fine. Is that what you wanted?
~Eva