PDA

View Full Version : How to create a Ajax Sidebar with Recent Posts


Mauu
13 Sep 2006, 01:50
At YoungCoders (http://www.youngcoders.com), I recently wrote an ajax enabled recent posts widget, and I thought I would post it here. I do not recommended this for high traffic forums, as you'll be running a lot of queries.

I'm going to forget to check back here and update this with any changes. So, please see here (http://www.youngcoders.com/showthread.php?p=95288), which is where I will maintain and try to provide support.

I) Setting up the Feed
1) First, you need the improved external.php file from vBulletin.org. The link is here: http://www.vbulletin.org/forum/showthread.php?t=105008&highlight=fps_external

2) This new external file lacks some of the documented features, and the feature we need is the latest posts (not latest threads). The attached file resolves that and may only be used if you have a valid vBulletin license. The reason we may not use the built-in one is because it does not have support for permissions and will therefore treat every user as a guest. Credit for fps_external.php goes to the original authors; my revision was trivial.

3) Upload fps_external.php into your forum directory.

II) Setting up the Ajax
1) Our threads are going to appear in an unordered list. So, let's setup our default list: <ul id="latestthreads">
<li>Please wait while the feed updates.</li>
</ul>
We have to throw in the please wait to make our page validate and also to notify our users that we're fetching the feed.

2) You then need some JavaScript. I'm not going to document this as it's pretty self-explanatory:
/*
* Ajax sidebar for vBulletin.
* Depends: hacked fps_external.php
* Created for: www.youngcoders.com
*/


function createRequestObject() {
var ro;
var browser = navigator.appName;
if(browser == "Microsoft Internet Explorer"){
ro = new ActiveXObject("Microsoft.XMLHTTP");
}else{
ro = new XMLHttpRequest();
}
return ro;
}

var http = createRequestObject();

function updateSidebarResponse() {
if(http.readyState == 4){
var length = document.getElementById('latestthreads').getElementsByTagName('li').length;
for (var y = 0; y < length; y++)
{
document.getElementById('latestthreads').removeChild( document.getElementById('latestthreads').getElementsByTagName('li')[0] );
}


var response = http.responseXML.getElementsByTagName('source')[0].getElementsByTagName('thread');
var length = response.length;
for (var x = 0; x < length; x++)
{
var id = response[x].getAttribute('id');
var title = response[x].getElementsByTagName('title')[0].childNodes[0].nodeValue;
var author = response[x].getElementsByTagName('author')[0].childNodes[0].nodeValue;
var when = response[x].getElementsByTagName('time')[0].childNodes[0].nodeValue;

var top = document.createElement('div');
var bottom = document.createElement('div');

var option = document.createElement('li');
var link = document.createElement('a');
link.href = 'showthread.php?goto=newpost&t=' + id;
link.appendChild(document.createTextNode(title));
var by = document.createElement('small');
by.appendChild(document.createTextNode(' by ' + author + ' at ' + when));

option.appendChild(link);
option.appendChild(by);

document.getElementById('latestthreads').appendChild(option);
}
}
}

function updateSidebar() {
http.open('get', 'fps_external.php?type=xml&qty=20&items=active');
http.onreadystatechange = updateSidebarResponse;
http.send(null);
}


updateSidebar();


The above code will fetch the sidebar just once. To make it update, you must have it run through intervals:setInterval('updateSidebar()', 60000 * 1); // Update every minute
setInterval('updateSidebar()', 60000 * 3); // Update every 3 minutes

Terms of Use: For each site you deploy this on, you must tell one friend about YoungCoders.com ;)

For a preview and more discussion: http://www.youngcoders.com/showthread.php?p=95288&styleid=19

snowlion
13 Sep 2006, 02:02
sidebar doesn't use for 1024x768 resolution hehe j/k
thanks Mauu
------------------------
November Rain

SilverSiR
13 Sep 2006, 15:52
Thanks for the script, I have a small issue though because I can't modify the link to a directory. It points to www.domain.com, instead of www.domain.com/forum. I put all the files in the forum directory instead of the root to see if that solved it but it didn't.

SilverSiR
13 Sep 2006, 16:01
Actually it doesn't even matter because the

http://www.domain.com/forum/thread4->newpost link throw a 404.

Mauu
13 Sep 2006, 20:38
Sorry, I had forgotton that we had a special setup on our forum. Change:

link.href = 'thread' + id + '->newpost'

to

link.href = '/forum/showthread.php?goto=newpost&t=' + id;

aveon
14 Sep 2006, 02:15
could you simplify this better, and then giving the code in which I need to implement into the template ?

Mauu
14 Sep 2006, 23:51
It really can't get much simpler: upload patched fps_external, stick HTML in, stick JavaScript in, done. Granted, basic web-design knowledge is required. :)

aveon
14 Sep 2006, 23:55
when i go to the website of you i saw this left bar you cam make it visible and invisible as well so i want to make it just like that if you can help me on it please

Mauu
15 Sep 2006, 04:55
Hi,
I designed that sidebar specially for our site. My modification here should be easy enough to drop into any sidebar solution; I'm not prepared to release our sidebar code because it still requires extensive testing and polishing.

aveon
15 Sep 2006, 11:52
hmm what can i say then all the good mods are not releaseable :(

Snake
16 Sep 2006, 13:08
Awesome! :D

Kihon Kata
17 Sep 2006, 15:19
I do not recommended this for high traffic forums, as you'll be running a lot of queries.I'm out :(

t3nt3tion
21 Oct 2006, 23:10
The full bar would be ok though. I know it`s easy to replicate :D

Kungfu
23 Oct 2006, 00:04
any idea why nothing is showing up?

i do fps_external.php?type=xml&qty=1&items=active
just from the browser and its blank and im not sure why. any ideas?

t3nt3tion
23 Oct 2006, 05:21
A link to your site maybe ? :)

Illustrious
03 Nov 2006, 08:02
It really can't get much simpler: upload patched fps_external, stick HTML in, stick JavaScript in, done. Granted, basic web-design knowledge is required. :)

The problem is where do you "stick HTML/JavaScript in" and how do you link this to the sidebar. A guide does that, explain what you have to do in reasonably simple terms so that people who are unable to do it without the guide can. One way you could go about is write up the guide so that you give one generic example solution of how to install it.

Judging by the replies on your own website, it seems like a lot of others are confused.

For example, I can easily point out:

II) Setting up the Ajax
1) Our threads are going to appear in an unordered list. So, let's setup our default list:

Set up the default list where?

2) You then need some JavaScript. I'm not going to document this as it's pretty self-explanatory:

And where does this javascript go?

t3nt3tion
03 Nov 2006, 15:35
All you need is to add a left/right comun code, and add the code in there. That`s it.

AMD_Warrior
24 Nov 2006, 03:17
Where do we add it?
which template??

ManagerJosh
24 Nov 2006, 16:36
While I'm no coder, I took a look at the code and it appears you put it in the header template. That's my best guess.

Either way, I'm echoing the same problems with this template release and that the installation is rather vague. Moreso, you didn't release any code for your AJAX sidebar I'd like to point out :).

fatwillie
25 Nov 2006, 17:38
How to create a Ajax Sidebar

I don't see any ajax code nor do I see sidebar code...

category
25 Nov 2006, 22:54
very confused so i put the fps that i download here to the forum directory

than i put the java in my column with style tags which i did but how does it load the posts? do i need to specify somewhere what forum ids?

Jezlad
26 Aug 2008, 17:34
Any chance this can be used toadd ajax latest threads without external?

Like inferno shoutbox does - updates new threads as they're posted

GDA
29 Aug 2008, 17:25
how come I can't download the fps file?