View Full Version : Display post element on external page
AlpineZone
02-23-2006, 12:58 PM
Wow. Amazing script!
I just converted from a phpBB forum. I also used to use phpBB Fetch All which was very helpful in pulling forum info and displaying it on pages outside of the forum. I still use this set up on another site. For example, the news "portal" here - http://news.coskiing.com/ - pulls data from the news forum here - http://forums.coskiing.com/viewforum.php?f=6 . I also use the phpBB Fetch All script to display the Latest Headlines and Recent Discussions on the home page here - http://www.coskiing.com/ . Finally, I also use it to create various RSS feeds.
My primary site now uses vBulletin - http://forums.alpinezone.com/ - and I need to replicate all the above functionality for the AlpineZone.com site. I installed vBadvanced which appears to be a much more polished script which does something similar for vBulletin.
I guess what I need to know is, can I simply update my news portal and other site elements to "fetch" various elements from the forum and display them on the respective pages? I'd like to avoid reformatting the way I've set things up drastically. Is there a way to easily pull this off?
AlpineZone
02-24-2006, 11:02 AM
Can anyone provide a basic tutorial here? Essentially what I need to do is pull elements (thread title, first post text, poster name, date/time, etc.) from threads in a specific forum and post them on a page outside the forum. Examples would be helpful. Thanks!
tormodg
02-27-2006, 02:58 AM
Can anyone provide a basic tutorial here? Essentially what I need to do is pull elements (thread title, first post text, poster name, date/time, etc.) from threads in a specific forum and post them on a page outside the forum. Examples would be helpful. Thanks!
This is documented over at vbulletin.com and vbulletin.org. It is a standard feature of vBulletin. The file you're looking for is external.php. There is a neat hack called fps_external which enhances this.
AlpineZone
02-28-2006, 01:24 PM
This is documented over at vbulletin.com and vbulletin.org. It is a standard feature of vBulletin. The file you're looking for is external.php. There is a neat hack called fps_external which enhances this.
Thanks. I took a look at that, but I don't think it's exactly what I want. Let me try to simplify my question with an example. Perhaps then somebody could tell me whether this is possible with vBadvanced, or via some other script/method.
Say I have a specific thread I want to pull the post text from; let's call it thread ID 534. How can I set up an external page in a format like http://www.mysite.com/article.php?t=534 which will simply display an element from that post (e.g. post body text from the first post in the thread). Simply changing the "t" variable in the URL should result in the post text from the specified thread to be displayed. Once I can see how this is done for a single element (post text), I can expand that to other elements (e.g. author, post times, etc.).
Second requirement will be to be able to pull a list of threads from a specified forum and link to them using the above URL format. I should be able to define the number of threads listed and pagination would be useful. Any thoughts?
tormodg
02-28-2006, 04:17 PM
Say I have a specific thread I want to pull the post text from; let's call it thread ID 534. How can I set up an external page in a format like http://www.mysite.com/article.php?t=534 which will simply display an element from that post (e.g. post body text from the first post in the thread). Simply changing the "t" variable in the URL should result in the post text from the specified thread to be displayed.
Something like this:
http://www.hypography.com/sciencearticle.cfm?id=5608
Compare to this:
http://forums.hypography.com/showthread.php?t=5608
?
This is a small change I made to fps_external - it simply checks for "itemid" in the URL string.
Regards,
Tormod
AlpineZone
02-28-2006, 04:27 PM
Exactly! Can you elaborate how you did that?
Also, what did you use to set up this page?
http://www.hypography.com/newsfront.cfm
tormodg
02-28-2006, 06:57 PM
The newsfront page is simply a coldfusion page pulling data from my CMS (not vBulletin).
Look at my index page - http://www.hypography.com/ to see the latest news. Once every hour I read the RSS from external.php and write a static file from the contents. The forums and my portal are on two different servers and as such the RSS is a useful way to grab the data.
The single news articles however are done by calling fps_external.php but with the modifications below. Note that I also write the results to an xml file so before I make the remote call I check if the article has already been fetched. This saves the server some time and also makes the pages faster to load.
Here is what I have added to my fps_external file:
find
$vbulletin->input->clean_array_gpc('r', array(
'forumids' => TYPE_STR,
'type' => TYPE_STR,
'bbcode' => TYPE_STR,
'html' => TYPE_STR,
'postlen' => TYPE_STR,
'qty' => TYPE_STR,
'items' => TYPE_STR
));
After 'forumids' => TYPE_STR,
add
'threadids' => TYPE_STR,
find
// +=============================================================+
// | Select the threads from the database. |
// +=============================================================+
Before it, add:
// +=============================================================+
// | Check to see if there is a thread preference |
// +=============================================================+
if ($vbulletin->GPC['threadids'] != '')
{
$threadchoice = array();
$threadids = explode(',', $vbulletin->GPC['threadids']);
foreach ($threadids AS $threadid)
{
$threadid = intval($threadid);
{
$threadchoice[] = $threadid;
}
}
$number_of_threads = sizeof($threadchoice);
if ($number_of_threads == 1)
{
$title = $vbulletin->threadcache["$threadchoice[0]"]['title'];
}
else if ($number_of_threads > 1)
{
$title = implode(',', $threadchoice);
}
else
{
$title = '';
}
if (!empty($threadchoice))
{
$threadchoice = 'AND thread.threadid IN(' . implode(',', $threadchoice) . ')';
}
else
{
$threadchoice = '';
}
}
else
{
$threadchoice = '';
}
$hook_query_fields = $hook_query_joins = $hook_query_where = '';
($hook = vBulletinHook::fetch_hook('external_query')) ? eval($hook) : false;
$cutoff = (!$vbulletin->options['externalcutoff']) ? TIMENOW - 86400 : TIMENOW - $vbulletin->options['externalcutoff'] * 3600;
Find
WHERE 1=1
$forumchoice
add this on a separate line:
$threadchoice
I *think* that was all - if it does not work let me know. And remember this is about the fps_external.php, NOT the built-in external.php.
tormodg
02-28-2006, 07:01 PM
The format for the item pulling request is:
http://forums.yoursite.com/fps_external.php?type=rss2&threadids=#id#&bbcode=parse&html=yes
...where the threadids=#id# is the threadids (comma separated) of the forum threads you want.
AlpineZone
03-01-2006, 01:46 PM
Thanks I tried all that and it seemed to work. You mention that you "write a static file from the contents" of the RSS feed. How do you do this? What format is the static file? Is it strictly just a copy of the RSS feed; a "snapshot", so to speak? One big issue I had with the phpBB solution was there were so many people hitting the "fetch" script that it would take the mySQL server down. Setting up a CRON to copy the contents of the feed to a static file seems like a great way to reduce this overhead. It would be great to know specifically how you do it.
Secondly, the former phpBB fetching approach would query the database directly. I'm finding that any use of the external.php files makes use of the RSS feed and parses it to display the data on a news article list page. Does anyone have any suggestions for good RSS parsers to be able to read my RSS feed, and display 10 articles at a time on each page, complete with pagination at the bottom? It never occurred to me to utilize *my own* RSS feed to display this article list...
tormodg
03-01-2006, 03:01 PM
Thanks I tried all that and it seemed to work. You mention that you "write a static file from the contents" of the RSS feed. How do you do this? What format is the static file? Is it strictly just a copy of the RSS feed; a "snapshot", so to speak?
I use ColdFusion but you can easily use php. You need to parse the xml content of the javascript feed. Here is a tutorial for parsing xml with php:
http://www.wirelessdevnet.com/channels/wap/features/xmlcast_php.html
The file I write for my front page is a HTML table containing the finished text.
The file I write for each of my news pages is the xml that I fetched from the feed. I then simply use a script to parse the file content rather than the RSS (since it contains the same xml it is the same script).
One big issue I had with the phpBB solution was there were so many people hitting the "fetch" script that it would take the mySQL server down. Setting up a CRON to copy the contents of the feed to a static file seems like a great way to reduce this overhead. It would be great to know specifically how you do it.
I simply use a cron task which uses curl to run a script on my portal server which fetches the rss feed and writes the necessary files for me.
For the portal front it checks once per hour. For the news articles it checks (when a user requests it) whether an xml file has already been written. If it has, it uses it - if not, it fetches it. Saves a lot of cross-server traffic.
Does anyone have any suggestions for good RSS parsers to be able to read my RSS feed, and display 10 articles at a time on each page, complete with pagination at the bottom? It never occurred to me to utilize *my own* RSS feed to display this article list...
Since I use Dreamweaver I can recommend RSS reader/writer from http://www.interaktonline.com
(Edit: Wrong product name used at first)
If you use something else I'm sure there are lots of available xml parser scripts already.
AlpineZone
03-01-2006, 03:10 PM
I use ColdFusion but you can easily use php. You need to parse the xml content of the javascript feed. Here is a tutorial for parsing xml with php:
[url]I simply use a cron task which uses curl to run a script on my portal server which fetches the rss feed and writes the necessary files for me.
For the portal front it checks once per hour. For the news articles it checks (when a user requests it) whether an xml file has already been written. If it has, it uses it - if not, it fetches it. Saves a lot of cross-server traffic.
Care to share some examples here?
tormodg
03-01-2006, 04:11 PM
Do you know ColdFusion? If not it's rather useless to you. I have no problems sharing it - I got most of this information off lists I participate in.
If you still want me to post examples let me know and I'll try to post it tomorrow (sorry but I'm in a rush atm).
AlpineZone
03-01-2006, 04:14 PM
Do you know ColdFusion? If not it's rather useless to you. I have no problems sharing it - I got most of this information off lists I participate in.
If you still want me to post examples let me know and I'll try to post it tomorrow (sorry but I'm in a rush atm).
No I don't. Thanks though. Your posts have been helpful in that conceptually I think I know what I want to do. I just need to make it happen programatically...
Thanks again!
Spinball
05-31-2006, 07:19 AM
tormodg thanks for your help on this.
I want to display an entire thread at the bottom of an external page.
Your example above only retrieves the last post of a thread.
How do I modify it to display all of them, please?
vBulletin® v3.7.4, Copyright ©2000-2009, Jelsoft Enterprises Ltd.