PDA

View Full Version : Recent Galleries listing


McDonDem
Nov-12-2007, 05:46 AM
I want to show my seven most recent galleries on my homepage automatically with the first being the medium size and the other six being the tiny size. I know they can be brought up through rss but I don't know javascript well enough to implement it myself. If anyone could help me, it would be a great benefit.

davenortonpics.smugmug.com

darryl
Nov-13-2007, 01:28 PM
(Code for this hack is in this post (http://www.dgrin.com/showpost.php?p=688574&postcount=18))

Ok, it can be done. I borrowed and tweaked an AJAX Feed Reader/Parser from here (http://www.xml.com/pub/a/2006/09/13/rss-and-ajax-a-simple-news-reader.html) and plopped the output into my Bio box.

Check it out: http://gladlee.smugmug.com/

It's super-ugly, as I didn't bother to try to format the output into SmugMug's miniboxes.

You can check my Javascript ugliness by using Firebug. I've hardcoded the rssurl to be my Recent Galleries feed for only the last 8 galleries. (A bug in the RSS feeds includes private, and thus not-visible galleries in the count.)

But anyways, it's a start. Do any actual coders (instead of a hack like me) want to pick up the ball and run with it?

Here's what I think needs to be done:

- Check to make sure you're on the home page before running getRSS this.
- Can miniboxes go in the Bio box? If so, format the output so that it looks like a regular Recent Galleries page, including Title, Description, and Updated.
- Maybe use some other box, because a) people actually want to use the Bio box, b) it screws up the feed. Featured won't work because it doesn't appear unless there's already a gallery featured. :P
- Add "Recent Galleries" boxTitle
- Remove RSS Channel Title and Link.
- Remove RSS Copyright Info and PubDate

Extra-credit:
- Implement multi-page "recent galleries" functionality so that you could page forward/backwards 8 galleries at a time. And because it's AJAX, it wouldn't even need to refresh, right? Man, that'd be sweet.

McDonDem
Nov-14-2007, 01:24 PM
I was thinking that if the rss feed could be parsed to place the gallery # in one array (with most recent in array[1] and least recent of 7 in array[7]) and the name of the gallery in a separate but similar array. Then have the javascript print to the page with the array information, kinda like a form letter. The main problem I have is the parsing of the rss feed due to the fact I don't know javascript that well.

darryl
Nov-14-2007, 04:24 PM
This tutorial walks you through the feed parser:

http://www.xml.com/pub/a/2006/09/13/rss-and-ajax-a-simple-news-reader.html

I may actually sit down and go through it, instead of being lazy and just trying to hack it.

McDonDem
Nov-16-2007, 08:30 AM
I got it to work. :barbI got on the computer and search for info on javascript and used the rss-ajax news reader that darryl pointed out to me and modified it to give me just the information I needed (gallery number and gallery title) so I could display my recent galleries in the different sizes I wanted.

Thanks for the help

This tutorial walks you through the feed parser:

http://www.xml.com/pub/a/2006/09/13/rss-and-ajax-a-simple-news-reader.html

I may actually sit down and go through it, instead of being lazy and just trying to hack it.

darryl
Nov-16-2007, 03:56 PM
Dave -- that looks *great*! Mind if I steal your Javascript?

Well, it's publicly available on your site. But I was thinking of tweaking it and posting something here. Sweet -- time to do some more hacking. ;-}

devbobo
Nov-16-2007, 04:16 PM
I got it to work. :barbI got on the computer and search for info on javascript and used the rss-ajax news reader that darryl pointed out to me and modified it to give me just the information I needed (gallery number and gallery title) so I could display my recent galleries in the different sizes I wanted.

Thanks for the help

did you realise that you can just add &Size=xxx to the feed url to get a different size image ?

eg. &Size=Large

Cheers,

David

McDonDem
Nov-16-2007, 05:19 PM
did you realise that you can just add &Size=xxx to the feed url to get a different size image ?

eg. &Size=Large

Cheers,

David

Yes I did, I just wanted to grab the feed once to pull a random "Medium" picture of my most recent gallery and pull random "Tiny" pictures for the other six next recent galleries as well as the titles of those those galleries.

McDonDem
Nov-16-2007, 05:22 PM
Dave -- that looks *great*! Mind if I steal your Javascript?

Well, it's publicly available on your site. But I was thinking of tweaking it and posting something here. Sweet -- time to do some more hacking. ;-}

go ahead and use it. I think that this rss reader could be used in many good ways for customization.

darryl
Nov-19-2007, 11:29 AM
I got it!

http://gladlee.smugmug.com/

Well, almost. Now I need a better place to put the Recent Galleries listing instead of the Bio Box. On IE, I get two columns. But in Firefox, it's just the one.

I suppose I could use Featured Galleries, but I need some help replacing everything in there with my generated miniboxes. Guess I'll look at devbobo's "recent photos" code, although I think that uses the Yahoo stuff which makes my head spin when I look at it.

[Also, the date format is in RSS format, not standard SmugMug format. I may get around to writing a regexp to fix that. Also, no gallery descriptions. Gah -- they're not in the feed. :-{]

McDonDem
Nov-20-2007, 12:25 PM
I use firefox, so I didn't notice this before. For some reason my images from what my javascript is supposed to display doesn't in Internet Explorer. my text will display fine, but it will not display the images. Any ideas?

darryl
Nov-20-2007, 02:08 PM
Sorry Don, I don't have much help for you. I ended up generating usable Tiny images with the following regexps:


var galimage = RSS.items[i].description ;
var galimage = galimage.replace(/^.+src="(.*?)" .*/m, "$1") ;
var galimage = galimage.replace(/(.*-)Th(-\d+)?(\.jpg)/i, "$1Ti$2$3") ;


But now I'm trying to get fancy and use the Yahoo UI stuff to try and add my recent galleries in the Featured Galleries box. (And ideally I'd like to make the one featured gallery that's required to make the box show up at all go away.)

This isn't working:


divTags = YD.getElementsByClassName("boxBottom", "div", YD.get("featuredBox"));

for (i=0; i<rsscount; i++) {

var galimage = RSS.items[i].description ;
var galimage = galimage.replace(/^.+src="(.*?)" .*/m, "$1") ;
var galimage = galimage.replace(/(.*-)Th(-\d+)?(\.jpg)/i, "$1Ti$2$3") ;

miniBox = document.createElement("div");
miniBox.className = "miniBox";

photoBox = document.createElement("div");
photoBox.className = "photo";
miniBox.appendChild(photoBox);

photoLink = document.createElement("a");
photoLink.setAttribute("href", RSS.items[i].link);
photoBox.appendChild(photoLink);

photoImg = document.createElement("img");
photoImg.setAttribute("border", "0");
photoImg.setAttribute("alt", RSS.items[i].title);
photoImg.setAttribute("title", RSS.items[i].title);
photoImg.src = galimage;
photoImg.className = "imgBorder";
photoLink.appendChild(photoImg);

albumTitle = document.createElement("p");
albumTitle.className = "albumTitle";
miniBox.appendChild(albumTitle);
albumLink = document.createElement("a");
albumLink.className = "nav";
albumLink.setAttribute("href", RSS.items[i].link);
albumTitle.appendChild(albumLink);

albumLinkText = document.createTextNode(RSS.items[i].title);
albumLink.appendChild(albumLinkText);
spacerDiv = document.createElement("div");
spacerDiv.className = "spacer";
miniBox.appendChild(spacerDiv);

divTags[i].insertAfter(miniBox, divTags[i].childNodes[1]);

break;
}


Devbobo, think you could give me a hint?

McDonDem
Nov-21-2007, 01:07 PM
I fixed my problem (must have had a quote mark wrong)

I was wondering why you don't modify your script and page a bit to put your recent galleries in a div tag at the bottom of your header section. This would put it above your featured galleries and categories boxes, but you would also have more control over it.

darryl
Nov-21-2007, 01:33 PM
Well, I kind of want to use the standard SmugMug headers, and such, and if I put it that high it might look weird. But let me give it a try.

darryl
Nov-21-2007, 01:54 PM
Ah ok, tried it in the header, but it didn't work when trying to use the box, boxTop and boxBottom SmugMug styles.

I want to try and use SmugMug's styles because I want this solution to be portable. I'm actually planning to ultimately use this on a different SmugMug site, and I want to be able to just use the code w/o having to modify headers.

Additionally, if I use SmugMug's styles, then any changes to themes and stuff will automatically be applied to the recent galleries "box" as well. If only there was a way to have an arbitrary "box" in there, instead of me trying to "clean out" one of the existing boxes.

darryl
Nov-21-2007, 04:29 PM
SUMMARY: I figured out how to get X number of Recent Galleries to show up on a page where I am showing Galleries by Category as well.

It is a TOTAL HACK, but it works...

http://gladlee.smugmug.com/

Reasons this is a horrible hack:
- You lose your Friends & Family box because I am replacing its contents with Recent Galleries. However because it takes a while to parse the RSS feed, people will still see that box temporarily.
- I couldn't figure out how to retain the "Move Up / Move Down" thing for home page configuration, so you'll have to move other stuff around the new Recent Galleries box to position it.
- JavaScript is still broken because I can't #!@*$(& figure out why it thinks RSS.items[i] has no properties

Other nitpicks:
- Date format does not match regular SmugMug dates. This should be somewhat fixable.
- No gallery descriptions -- they are not in the feed, so I would have to make yet another call to obtain them. Ugh.
- RSS feed for recent galleries still returns an inaccurate number of items when specifying ImageCount because it counts, but does not return Private Galleries. Workaround requires downloading a "buffer" of extra galleries, which slows things down.

But anyways, it works. Please look at my JavaScript and laugh/cry, then give me suggestions on how to fix it. :-}

darryl
Nov-22-2007, 12:43 AM
Fixed a few things:


- You lose your Friends & Family box because I am replacing its contents with Recent Galleries. However because it takes a while to parse the RSS feed, people will still see that box temporarily.


Now I'm plopping the Recent Galleries into the Featured Galleries box. So you lose that box. But it does load a lot more cleanly, I think. However, much like the Recent Photo Gallery Timeline Hack, I haven't figured out how to remove the token Featured Gallery that I need to have so that the enclosing box shows up at all.

- I couldn't figure out how to retain the "Move Up / Move Down" thing for home page configuration, so you'll have to move other stuff around the new Recent Galleries box to position it.


Fixed -- I'm trying to be good and only modify the elements I need.

- JavaScript is still broken because I can't #!@*$(& figure out why it thinks RSS.items[i] has no properties

Fixed -- This was because I wasn't checking to see if (grr), the RSS feed had short-changed me some galleries because of its brokenness w/ Private Galleries.


Other nitpicks:
- Date format does not match regular SmugMug dates. This should be somewhat fixable.

Date format fixed. Still working on military time (ugh). Also, found out a dirty little secret: Timestamps of album updates (at least in RSS) may actually be PST or PDT, but SmugMug just slaps PST on all of them. Oh, that album you uploaded at 8PM in the summer? It's going to be timestamped 7PM.

- No gallery descriptions -- they are not in the feed, so I would have to make yet another call to obtain them. Ugh.

No fix.

- RSS feed for recent galleries still returns an inaccurate number of items when specifying ImageCount because it counts, but does not return Private Galleries. Workaround requires downloading a "buffer" of extra galleries, which slows things down.

Also still broken, and as it turned out, was causing other problems.

Anyways though, I'm a little happier with it, despite it still being a nasty hack.

darryl
Nov-25-2007, 01:11 AM
Ok, all issues pretty much resolved except that Gallery Description is *not* included. I can kind of live with this, but am toying with the idea of making a JSON call to pull it from the API. However, a few hours trying to get JSON to work has made my head hurt. :-{

Anywho, not that anybody cares, but here's of an example of the script in action:

http://gladlee.smugmug.com/

Here is my whole stinking ugly mess:

{edit - fixed IE incompatibility; need to actually *call* getRSS; added tiny bit of CSS to make grouping tighter, since we don't have description anyways; added body tag to call function; didn't *really* want multiline searching; fixed 0:00 (midnight) hours}

Header Javascript section:

// RECENT GALLERIES HACK

// This hack replaces your Featured Galleries with Recent Galleries as determined by the RSS feed.
//
// RSS parsing code from Paul Sobocinski found here:
// http://www.xml.com/pub/a/2006/09/13/rss-and-ajax-a-simple-news-reader.html?page=5

// NOTE: You must have one gallery set to featured, as a placeholder to make the Featured Box show up
// This placeholder gallery will not show up once the hack is in place.

// Rename Featured Galleries to Recent Galleries
YE.onContentReady('featuredTitle', function() {this.innerHTML='recent galleries'});

// Specify how many recent galleries you'd like to see
var rsscount = 6 ;

// Specify your RSS feed for Recent Galleries (replace XXXXXX with your site name)
// ImageCount needs to be "padded" if you have a lot of private galleries mixed in with your public
// galleries. If you are not seeing 6 (or however many) recent galleries, try increasing ImageCount
//
// NOTE: If you are using a CNAME, you need to change http://XXXXXX.smugmug.com to
// http://yourcustomdomain.com

var rssurl = "http://XXXXXX.smugmug.com/hack/feed.mg?Type=nickname&Data=XXXXXX&format=rss200&ImageCount=10";

// Added a line to the doOnLoad function that is also used by the removeLinkFromImg() function and others.
// So you may only need to append the if//getRSS clause below.

function doOnLoad() {
if (YD.hasClass(document.body, "homepage")) //
getRSS();
}

//OBJECTS

//objects inside the RSS2Item object
function RSS2Enclosure(encElement)
{
if (encElement == null)
{
this.url = null;
this.length = null;
this.type = null;
}
else
{
this.url = encElement.getAttribute("url");
this.length = encElement.getAttribute("length");
this.type = encElement.getAttribute("type");
}
}

function RSS2Guid(guidElement)
{
if (guidElement == null)
{
this.isPermaLink = null;
this.value = null;
}
else
{
this.isPermaLink = guidElement.getAttribute("isPermaLink");
this.value = guidElement.childNodes[0].nodeValue;
}
}

function RSS2Source(souElement)
{
if (souElement == null)
{
this.url = null;
this.value = null;
}
else
{
this.url = souElement.getAttribute("url");
this.value = souElement.childNodes[0].nodeValue;
}
}

//object containing the RSS 2.0 item
function RSS2Item(itemxml)
{
//required
this.title;
this.link;
this.description;

//optional vars
this.author;
this.comments;
this.pubDate;

//optional objects
// this.category;
this.enclosure;
this.guid;
this.source;

var properties = new Array("title", "link", "description", "author", "comments", "pubDate");
var tmpElement = null;
for (var i=0; i<properties.length; i++)
{
tmpElement = itemxml.getElementsByTagName(properties[i])[0];
if (tmpElement != null)
eval("this."+properties[i]+"=tmpElement.childNodes[0].nodeValue");
}

// this.category = new RSS2Category(itemxml.getElementsByTagName("category")[0]);
this.enclosure = new RSS2Enclosure(itemxml.getElementsByTagName("enclosure")[0]);
this.guid = new RSS2Guid(itemxml.getElementsByTagName("guid")[0]);
this.source = new RSS2Source(itemxml.getElementsByTagName("source")[0]);
}

//objects inside the RSS2Channel object
function RSS2Category(catElement)
{
if (catElement == null)
{
this.domain = null;
this.value = null;
}
else
{
this.domain = catElement.getAttribute("domain");
this.value = catElement.childNodes[0].nodeValue;
}
}

//object containing RSS image tag info
function RSS2Image(imgElement)
{
if (imgElement == null)
{
this.url = null;
this.link = null;
this.width = null;
this.height = null;
this.description = null;
}
else
{
imgAttribs = new Array("url","title","link","width","height","description");
for (var i=0; i<imgAttribs.length; i++)
if (imgElement.getAttribute(imgAttribs[i]) != null)
eval("this."+imgAttribs[i]+"=imgElement.getAttribute("+imgAttribs[i]+")");
}
}

//object containing the parsed RSS 2.0 channel
function RSS2Channel(rssxml)
{
//required
this.title;
this.link;
this.description;

//array of RSS2Item objects
this.items = new Array();

//optional vars
this.language;
this.copyright;
this.managingEditor;
this.webMaster;
this.pubDate;
this.lastBuildDate;
this.generator;
this.docs;
this.ttl;
this.rating;

//optional objects
// this.category;
this.image;

var chanElement = rssxml.getElementsByTagName("channel")[0];
var itemElements = rssxml.getElementsByTagName("item");

for (var i=0; i<itemElements.length; i++)
{
Item = new RSS2Item(itemElements[i]);
this.items.push(Item);
//chanElement.removeChild(itemElements[i]);
}

var properties = new Array("title", "link", "description", "language", "copyright", "managingEditor", "webMaster", "pubDate", "lastBuildDate", "generator", "docs", "ttl", "rating");
var tmpElement = null;
// this.category = new RSS2Category(chanElement.getElementsByTagName("category")[0]);
this.image = new RSS2Image(chanElement.getElementsByTagName("image")[0]);
}

//PROCESSES

//uses xmlhttpreq to get the raw rss xml
function getRSS()
{
//call the right constructor for the browser being used
if (window.ActiveXObject)
xhr = new ActiveXObject("Microsoft.XMLHTTP");
else if (window.XMLHttpRequest)
xhr = new XMLHttpRequest();
else
alert("not supported");

//prepare the xmlhttprequest object
xhr.open("GET",rssurl,true);
xhr.setRequestHeader("Cache-Control", "no-cache");
xhr.setRequestHeader("Pragma", "no-cache");
xhr.onreadystatechange = function() {
if (xhr.readyState == 4)
{
if (xhr.status == 200)
{
if (xhr.responseText != null)
processRSS(xhr.responseXML);
else
{
alert("Failed to receive RSS file from the server - file not found.");
return false;
}
}
else
alert("Error code " + xhr.status + " received: " + xhr.statusText);
}
}

//send the request
xhr.send(null);
}

//processes the received rss xml
function processRSS(rssxml)
{
RSS = new RSS2Channel(rssxml);
showRSS(RSS);
}

//shows the RSS content in the browser
function showRSS(RSS)
{

divTags = YD.getElementsByClassName("boxBottom", "div", YD.get("featuredBox"));

while(divTags[0].firstChild) divTags[0].removeChild(divTags[0].firstChild);

//populate the items

for (var i=0; i<rsscount && i<RSS.items.length; i++)
{
galimage = RSS.items[i].description;

galimage = galimage.replace(/^.+src="(.*?)" .*/, "$1") ;
galimage = galimage.replace(/(.*-)Th(-\d+)?(\.\w+)/i, "$1Ti$2$3") ;

pubdate = RSS.items[i].pubDate ;
pubdate.match(/^\w{3}, (\d\d) (\w{3}) (\d{4}) (\d\d):(\d\d):\d\d -\d\d\d\d/) ;

// Fix up date formatting
if (RegExp.$4>12) { meridian = 'pm'; hrs = RegExp.$4-12 } else { meridian = 'am'; if (RegExp.$4==0) { hrs = 12 } else { hrs = RegExp.$4-0 }} ;

fixdate = "updated: " + RegExp.$2 + " " + RegExp.$1 + ", " + RegExp.$3 + " " + hrs + ":" + RegExp.$5 + meridian + " PST" ;

miniBox = document.createElement("div");
miniBox.className = "miniBox miniminiBox";

photoBox = document.createElement("div");
photoBox.className = "photo";
miniBox.appendChild(photoBox);

photoLink = document.createElement("a");
photoLink.setAttribute("href", RSS.items[i].link);
photoBox.appendChild(photoLink);

photoImg = document.createElement("img");
photoImg.setAttribute("border", "0");
photoImg.setAttribute("alt", RSS.items[i].title);
photoImg.setAttribute("title", RSS.items[i].title);
photoImg.src = galimage;
photoImg.className = "imgBorder";
photoLink.appendChild(photoImg);

albumTitle = document.createElement("p");
albumTitle.className = "albumTitle";
miniBox.appendChild(albumTitle);
albumLink = document.createElement("a");
albumLink.className = "nav";
albumLink.setAttribute("href", RSS.items[i].link);
albumTitle.appendChild(albumLink);

albumLinkText = document.createTextNode(RSS.items[i].title);
albumLink.appendChild(albumLinkText);

albumUpdated = document.createElement("p");
albumUpdated.className = "updated";
miniBox.appendChild(albumUpdated);
albumUpdatedText = document.createTextNode(fixdate);
albumUpdated.appendChild(albumUpdatedText);

spacerDiv = document.createElement("div");
spacerDiv.className = "spacer";
miniBox.appendChild(spacerDiv);

divTags[0].appendChild(miniBox);
// insertAfter(miniBox, divTags[0].childNodes[divTags[0].childNodes.length-2]);

}
spacerDiv = document.createElement("div");
spacerDiv.className = "spacer";
divTags[0].appendChild(spacerDiv);

//we're done
return true;
}

var xhr;


CSS section:

/* Smaller miniBox for recent galleries */
.miniminiBox {
height:105px;
}


Body tag section:

<body onload="doOnLoad();">


Please note that I am a total hack, so this code is not optimized, and doubtless has a lot of excess stuff in it. I welcome any suggestions on how to clean it up, as well as any tips/code on how to get the Gallery Descriptions in there.

afarber
Jan-10-2008, 01:05 PM
Nice work!

Is there any way to have this appear on another page, not my homepage? I would love to have a link in my banner to my "Recent Updates" or something and have it go to a dedicated page for this.

Thanks

darryl
Jan-10-2008, 01:26 PM
Yes, there is a way, although I have not tried it (it's a great idea though):

http://dgrin.smugmug.com/gallery/2160039

afarber
Jan-10-2008, 01:50 PM
fantastic. I'll have to try this soon.

Yes, there is a way, although I have not tried it (it's a great idea though):

http://dgrin.smugmug.com/gallery/2160039

McDonDem
Jan-10-2008, 02:36 PM
you can set it up approximately the same way you can create a separate galleries page. http://dgrin.smugmug.com/gallery/2160039
just have to change the galleries to recent, etc.

Yes, there is a way, although I have not tried it (it's a great idea though):

http://dgrin.smugmug.com/gallery/2160039

afarber
Jan-11-2008, 09:01 AM
Success! I added another 'homepage' and used this hack to change my featured box to a New Updates box. I then added a button to my nav bar to this page. Thanks so much!

The only problem remaining is that I want the galleries/categories box to appear when I'm logged in on my homepage only and not my galleries (2nd homepage) page. Right now it doesn't appear on either when I'm logged out (which is correect), but it also does appear on both when I'm logged in. Clearly not a huge deal, but I can't figure out how to get rid of it on the galleries page.

PaulSpot
Mar-17-2008, 12:04 PM
Hi; I just tried to get this going but wasn't having much luck (I'll keep trying) but it seemed like a newer solution has come up or something? I checked out gladlee.smugmug.com and I don't see all this javascript in the page source?

PaulSpot
Mar-17-2008, 12:16 PM
Hi; I just tried to get this going but wasn't having much luck (I'll keep trying) but it seemed like a newer solution has come up or something? I checked out gladlee.smugmug.com and I don't see all this javascript in the page source?

Nevermind, I'm dumb, I see how it all works now; the .js is on another page, and I wasn't doing everything right. And I see now that the cool thing to do is have a 'hidden' gallery called "Loading..." that makes it look like it's loading. Smart!

darryl
Mar-17-2008, 02:01 PM
Woot -- glad to see my hack is working for somebody else. Yeah, I figured out that "Loading..." gallery trick after I got tired of seeing "Ignore this" too many times.

Boy though, wouldn't it be great if Smugmug simply supported a "Recent Albums" panel for the front page? Because hacking it this way is kind of slow.

PaulSpot
Mar-17-2008, 02:10 PM
OK I'm stumped... I have it all working except my token gallery I need as a placeholder, which I call "Loading...." stays. I'm not sure what in the code should make it go away, but I see that darrl's does it and mine doesn't ;) Little help??

http://paulspot.smugmug.com

PaulSpot
Mar-17-2008, 02:25 PM
Woot -- glad to see my hack is working for somebody else. Yeah, I figured out that "Loading..." gallery trick after I got tired of seeing "Ignore this" too many times.

Boy though, wouldn't it be great if Smugmug simply supported a "Recent Albums" panel for the front page? Because hacking it this way is kind of slow.

Your "hack" rocks! I really appreciate it. And ignore my "stumped" question. It had not occurrd to me that my loading gallery IS one of myrecent galleries.

darryl
Mar-17-2008, 02:31 PM
Ah yeah, that's tricky. You need to upload 5 new galleries. :-}

Again, it's a sad side-effect of this being a hack, when it should be (IMHO) implemented into the core features of SmugMug.

--Darryl

PaulSpot
Mar-17-2008, 05:38 PM
Ah yeah, that's tricky. You need to upload 5 new galleries. :-}

Again, it's a sad side-effect of this being a hack, when it should be (IMHO) implemented into the core features of SmugMug.

--Darryl

Yeah, it is a bit odd that there is really no facility for recent photos or galleries. The timeline thing isn't really workable because it's in the wrong order. I know smugmug needs to differentiate themselves from flickr but recent photo streams is kind of a commodity and would surely be appreciated. But until then, thank goodness for folks like you ;)

darryl
Mar-17-2008, 06:51 PM
Well, to be honest, SmugMug has had a "recent galleries" function available since... forever. Alas, in choosing it you lose the ability to sort by category, *and* it shows every album you have ever published. Kind of... unwieldy:

http://jt.smugmug.com/

(Again, sorry JT, but since you are one of the few people I know that continue to show all your galleries sorted by most recent on top, you serve as a great example. :-)

PaulSpot
Mar-18-2008, 05:56 AM
Little tip for anybody else out there using this and needing to put that "loading" gallery in there.. if you go to "customize gallery" and mark it as "unlisted", then it won't show up in your RSS feed but it's also not private so you can still feature it. In other words, it makes it work the way you want... shows "Loading..." gallery until the RSS loads, then no "Loading..." gallery in the recent galleries list.

Darrl- you're right, I forgot that if I stopped using categories, I could have recent galleries. Guess I'm just greedy ;)

darryl
Apr-09-2008, 01:09 AM
Little tip for anybody else out there using this and needing to put that "loading" gallery in there.. if you go to "customize gallery" and mark it as "unlisted", then it won't show up in your RSS feed but it's also not private so you can still feature it. In other words, it makes it work the way you want... shows "Loading..." gallery until the RSS loads, then no "Loading..." gallery in the recent galleries list.

Darrl- you're right, I forgot that if I stopped using categories, I could have recent galleries. Guess I'm just greedy ;)

Hey Paul--

I came up with another nice little hack. Put an image into your "Loading..." gallery of an animated loading gif. You can generate one to match your color scheme here: http://www.ajaxload.info/

You end up with a nice bit of animation to let people know something is happening: http://gladlee.smugmug.com/

Re: SmugMug's built-in Arrange by Galleries vs Categories, as noted in my last post, picking Galleries shows *all* of your galleries in reverse chronological order. It gets really unwieldy really fast. Categories are a necessity, but they introduce their own problems. Like, what if you wanted to mix single albums with categories? You can't.

PaulSpot
Apr-09-2008, 07:02 AM
Hey Paul--

I came up with another nice little hack. Put an image into your "Loading..." gallery of an animated loading gif. You can generate one to match your color scheme here: http://www.ajaxload.info/

You end up with a nice bit of animation to let people know something is happening: http://gladlee.smugmug.com/

Re: SmugMug's built-in Arrange by Galleries vs Categories, as noted in my last post, picking Galleries shows *all* of your galleries in reverse chronological order. It gets really unwieldy really fast. Categories are a necessity, but they introduce their own problems. Like, what if you wanted to mix single albums with categories? You can't.

Nice tip! I had used a PNG file I had on hand that I thought looked "loady", but an animated file would be even cooler.

Raina.Rae
May-02-2008, 03:36 PM
Darryl,

Thank you for writing this code and documenting it so someone else knows what going on in the code. It works a lot better and is a lot simpler then any of the other recent gallary hacks I have seen. You saved me hours of fustration. Thanks. :D

Heather
www.munchkinphotos.smugmug.com (http://www.munchkinphotos.smugmug.com)



[quote=darryl]Ok, all issues pretty much resolved except that Gallery Description is *not* included. I can kind of live with this, but am toying with the idea of making a JSON call to pull it from the API. However, a few hours trying to get JSON to work has made my head hurt. :-{

Anywho, not that anybody cares, but:

http://gladlee.smugmug.com/
Here is my whole stinking ugly mess:

{edit - fixed IE incompatibility; need to actually *call* getRSS; added tiny bit of CSS to make grouping tighter, since we don't have description anyways; added body tag to call function; didn't *really* want multiline searching; fixed 0:00 (midnight) hours}

Javascript section:
[code]
// RECENT GALLERIES HACK

// This hack replaces your Featured Galleries with Recent Galleries as determined by the RSS feed.
//

darryl
May-02-2008, 05:38 PM
Darryl,

Thank you for writing this code and documenting it so someone else knows what going on in the code. It works a lot better and is a lot simpler then any of the other recent gallary hacks I have seen. You saved me hours of fustration. Thanks. :D

Heather
www.munchkinphotos.smugmug.com (http://www.munchkinphotos.smugmug.com)


Heather -- while I'm thrilled that somebody is getting use out of my code, I wish that SmugMug would actually build this into their system, because my method is really inefficient and slow.

Unfortunately, since it works (kind of -- no gallery descriptions, which might be a problem for you, looking at your current page), that probably lets them think "Well, hey, somebody can just use Darryl's ugly hack and we don't have to fix it. Yay."

:-{

Tawcan
Jun-06-2008, 11:41 AM
Nm got it working now. :)

hrsa
Jun-07-2008, 11:55 AM
Still some problems...
Now "Recent galleries" is doubled and is over my "bio".
What am i doing wrong?
UPD: Now recent galleries have disappeared :(
What's more - an unlisted gallery is now shown in that box!
I've put this in "Footer Javascript":
// RECENT GALLERIES HACK

// This hack replaces your Featured Galleries with Recent Galleries as determined by the RSS feed.
//
// RSS parsing code from Paul Sobocinski found here:
// http://www.xml.com/pub/a/2006/09/13/rss-and-ajax-a-simple-news-reader.html?page=5

// NOTE: You must have one gallery set to featured, as a placeholder to make the Featured Box show up
// This placeholder gallery will not show up once the hack is in place.

// Rename Featured Galleries to Recent Galleries
YE.onContentReady('featuredTitle', function() {this.innerHTML='Recent uploads'});

// Specify how many recent galleries you'd like to see
var rsscount = 6 ;

// Specify your RSS feed for Recent Galleries (replace XXXXXX with your site name)
// ImageCount needs to be "padded" if you have a lot of private galleries mixed in with your public
// galleries. If you are not seeing 6 (or however many) recent galleries, try increasing ImageCount

var rssurl = "http://hrsa.smugmug.com/hack/feed.mg?Type=nickname&Data=hrsa&format=rss200&ImageCount=18";

// Added a line to the doOnLoad function that is also used by the removeLinkFromImg() function and others.
// So you may only need to append the if//getRSS clause below.

function doOnLoad() {
if (YD.hasClass(document.body, "homepage")) //
getRSS();
}

//OBJECTS

//objects inside the RSS2Item object
function RSS2Enclosure(encElement)
{
if (encElement == null)
{
this.url = null;
this.length = null;
this.type = null;
}
else
{
this.url = encElement.getAttribute("url");
this.length = encElement.getAttribute("length");
this.type = encElement.getAttribute("type");
}
}

function RSS2Guid(guidElement)
{
if (guidElement == null)
{
this.isPermaLink = null;
this.value = null;
}
else
{
this.isPermaLink = guidElement.getAttribute("isPermaLink");
this.value = guidElement.childNodes[0].nodeValue;
}
}

function RSS2Source(souElement)
{
if (souElement == null)
{
this.url = null;
this.value = null;
}
else
{
this.url = souElement.getAttribute("url");
this.value = souElement.childNodes[0].nodeValue;
}
}

//object containing the RSS 2.0 item
function RSS2Item(itemxml)
{
//required
this.title;
this.link;
this.description;

//optional vars
this.author;
this.comments;
this.pubDate;

//optional objects
// this.category;
this.enclosure;
this.guid;
this.source;

var properties = new Array("title", "link", "description", "author", "comments", "pubDate");
var tmpElement = null;
for (var i=0; i<properties.length; i++)
{
tmpElement = itemxml.getElementsByTagName(properties[i])[0];
if (tmpElement != null)
eval("this."+properties[i]+"=tmpElement.childNodes[0].nodeValue");
}

// this.category = new RSS2Category(itemxml.getElementsByTagName("category")[0]);
this.enclosure = new RSS2Enclosure(itemxml.getElementsByTagName("enclosure")[0]);
this.guid = new RSS2Guid(itemxml.getElementsByTagName("guid")[0]);
this.source = new RSS2Source(itemxml.getElementsByTagName("source")[0]);
}

//objects inside the RSS2Channel object
function RSS2Category(catElement)
{
if (catElement == null)
{
this.domain = null;
this.value = null;
}
else
{
this.domain = catElement.getAttribute("domain");
this.value = catElement.childNodes[0].nodeValue;
}
}

//object containing RSS image tag info
function RSS2Image(imgElement)
{
if (imgElement == null)
{
this.url = null;
this.link = null;
this.width = null;
this.height = null;
this.description = null;
}
else
{
imgAttribs = new Array("url","title","link","width","height","description");
for (var i=0; i<imgAttribs.length; i++)
if (imgElement.getAttribute(imgAttribs[i]) != null)
eval("this."+imgAttribs[i]+"=imgElement.getAttribute("+imgAttribs[i]+")");
}
}

//object containing the parsed RSS 2.0 channel
function RSS2Channel(rssxml)
{
//required
this.title;
this.link;
this.description;

//array of RSS2Item objects
this.items = new Array();

//optional vars
this.language;
this.copyright;
this.managingEditor;
this.webMaster;
this.pubDate;
this.lastBuildDate;
this.generator;
this.docs;
this.ttl;
this.rating;

//optional objects
// this.category;
this.image;

var chanElement = rssxml.getElementsByTagName("channel")[0];
var itemElements = rssxml.getElementsByTagName("item");

for (var i=0; i<itemElements.length; i++)
{
Item = new RSS2Item(itemElements[i]);
this.items.push(Item);
//chanElement.removeChild(itemElements[i]);
}

var properties = new Array("title", "link", "description", "language", "copyright", "managingEditor", "webMaster", "pubDate", "lastBuildDate", "generator", "docs", "ttl", "rating");
var tmpElement = null;
// this.category = new RSS2Category(chanElement.getElementsByTagName("category")[0]);
this.image = new RSS2Image(chanElement.getElementsByTagName("image")[0]);
}

//PROCESSES

//uses xmlhttpreq to get the raw rss xml
function getRSS()
{
//call the right constructor for the browser being used
if (window.ActiveXObject)
xhr = new ActiveXObject("Microsoft.XMLHTTP");
else if (window.XMLHttpRequest)
xhr = new XMLHttpRequest();
else
alert("not supported");

//prepare the xmlhttprequest object
xhr.open("GET",rssurl,true);
xhr.setRequestHeader("Cache-Control", "no-cache");
xhr.setRequestHeader("Pragma", "no-cache");
xhr.onreadystatechange = function() {
if (xhr.readyState == 4)
{
if (xhr.status == 200)
{
if (xhr.responseText != null)
processRSS(xhr.responseXML);
else
{
alert("Failed to receive RSS file from the server - file not found.");
return false;
}
}
else
alert("Error code " + xhr.status + " received: " + xhr.statusText);
}
}

//send the request
xhr.send(null);
}

//processes the received rss xml
function processRSS(rssxml)
{
RSS = new RSS2Channel(rssxml);
showRSS(RSS);
}

//shows the RSS content in the browser
function showRSS(RSS)
{

divTags = YD.getElementsByClassName("boxBottom", "div", YD.get("featuredBox"));

while(divTags[0].firstChild) divTags[0].removeChild(divTags[0].firstChild);

//populate the items

for (var i=0; i<rsscount && i<RSS.items.length; i++)
{
galimage = RSS.items[i].description;

galimage = galimage.replace(/^.+src="(.*?)" .*/, "$1") ;
galimage = galimage.replace(/(.*-)Th(-\d+)?(\.\w+)/i, "$1Ti$2$3") ;

pubdate = RSS.items[i].pubDate ;
pubdate.match(/^\w{3}, (\d\d) (\w{3}) (\d{4}) (\d\d):(\d\d):\d\d -\d\d\d\d/) ;

// Fix up date formatting
if (RegExp.$4>12) { meridian = 'pm'; hrs = RegExp.$4-12 } else { meridian = 'am'; if (RegExp.$4==0) { hrs = 12 } else { hrs = RegExp.$4-0 }} ;

fixdate = "updated: " + RegExp.$2 + " " + RegExp.$1 + ", " + RegExp.$3 + " " + hrs + ":" + RegExp.$5 + meridian + " PST" ;

miniBox = document.createElement("div");
miniBox.className = "miniBox miniminiBox";

photoBox = document.createElement("div");
photoBox.className = "photo";
miniBox.appendChild(photoBox);

photoLink = document.createElement("a");
photoLink.setAttribute("href", RSS.items[i].link);
photoBox.appendChild(photoLink);

photoImg = document.createElement("img");
photoImg.setAttribute("border", "0");
photoImg.setAttribute("alt", RSS.items[i].title);
photoImg.setAttribute("title", RSS.items[i].title);
photoImg.src = galimage;
photoImg.className = "imgBorder";
photoLink.appendChild(photoImg);

albumTitle = document.createElement("p");
albumTitle.className = "albumTitle";
miniBox.appendChild(albumTitle);
albumLink = document.createElement("a");
albumLink.className = "nav";
albumLink.setAttribute("href", RSS.items[i].link);
albumTitle.appendChild(albumLink);

albumLinkText = document.createTextNode(RSS.items[i].title);
albumLink.appendChild(albumLinkText);

albumUpdated = document.createElement("p");
albumUpdated.className = "updated";
miniBox.appendChild(albumUpdated);
albumUpdatedText = document.createTextNode(fixdate);
albumUpdated.appendChild(albumUpdatedText);

spacerDiv = document.createElement("div");
spacerDiv.className = "spacer";
miniBox.appendChild(spacerDiv);

divTags[0].appendChild(miniBox);
// insertAfter(miniBox, divTags[0].childNodes[divTags[0].childNodes.length-2]);

}
spacerDiv = document.createElement("div");
spacerDiv.className = "spacer";
divTags[0].appendChild(spacerDiv);

//we're done
return true;
}

var xhr;

darryl
Jun-07-2008, 08:01 PM
Still some problems...
Now "Recent galleries" is doubled and is over my "bio".
What am i doing wrong?
UPD: Now recent galleries have disappeared :(
What's more - an unlisted gallery is now shown in that box!
I've put this in "Footer Javascript":


Hi:

It needs to be in Header Javascript. Footer Javascript is something new and I never tested the script there. As it happens, it *does* work in Footer Javascript, but takes a really long time.

Before moving it, you should click on [don't feature] under your unlisted gallery.

There is a use for an unlisted gallery though. It lets you put a "loading" graphic up there while people wait for the recent galleries to load. See post #33 (http://www.dgrin.com/showthread.php?p=800093#post800093) up above.

--Darryl

hrsa
Jun-07-2008, 10:01 PM
I've put the code in header javascript.
it worked, but after i've refreshed the page - only caption changes, recent galleries don't show up :(

darryl
Jun-07-2008, 10:46 PM
I've put the code in header javascript.
it worked, but after i've refreshed the page - only caption changes, recent galleries don't show up :(

It's working for me, after multiple reloads on Firefox 2.0.0.14 and IE 7.0.5730.13.

I hate to say this -- but maybe try clearing your cache? Also, try logging out of your SmugMug account to see what it'll look like to other users.

Clearing .smugmug.com cookies might be worthwhile.

--Darryl

hrsa
Jun-07-2008, 11:10 PM
Hm, i've tried to load this page from 5 different computers - all of them seem to stuck on "Loading"

hrsa
Jun-08-2008, 12:01 AM
You were right about CNAME, it's working perfectly on hrsa.smugmug.com.

Unfortunately, that change didn't help, although the link for the feed is alright - it can be opened in any rss reader. It's strange that it doesn't work

darryl
Jun-08-2008, 12:55 AM
You were right about CNAME, it's working perfectly on hrsa.smugmug.com.

Unfortunately, that change didn't help, although the link for the feed is alright - it can be opened in any rss reader. It's strange that it doesn't work

Whoops. Another fix:


var rssurl = "http://hrsa.ru/hack/feed.mg?Type=nickname&Data=XXXXXX&format=rss200&ImageCount=10";


That should do it.

hrsa
Jun-08-2008, 01:00 AM
Whoops. Another fix:


var rssurl = "http://hrsa.ru/hack/feed.mg?Type=nickname&Data=XXXXXX&format=rss200&ImageCount=10";

That should do it.
Indeed! Works perfectly, thank you very much! :clap