Vbullitin / XML feed?
Sledgehammer70
California Icrontian
Okay call me dumb or stupid, but when it comes to HTML, PHP etc.. I am just that... But I am trying to learn I think it is funny I know how to build and fix comps... but I can't build or mod forums I guess it is always one or the other and for the select few who can do both I appricate your hard work..
I am wanting to show my current top 5 to 10 threads on my home page, and I am also trying to create a section on my forums where I can post news and it shows up on the home page. From what I hear this is a complicated task. But I am dying to learn... I don't know if this is where you use XML feeds or Rss stuff. but any help is appricated. maybe pointing me in the right direction or just slapping me one on one via Vent, or TS.... Like I said any help is appricated. I know the knowledge dwells among this site..... I just need to harness it.
I am wanting to show my current top 5 to 10 threads on my home page, and I am also trying to create a section on my forums where I can post news and it shows up on the home page. From what I hear this is a complicated task. But I am dying to learn... I don't know if this is where you use XML feeds or Rss stuff. but any help is appricated. maybe pointing me in the right direction or just slapping me one on one via Vent, or TS.... Like I said any help is appricated. I know the knowledge dwells among this site..... I just need to harness it.
0
Comments
// ######################################################
// ## configuration
// ##
// ## $xml_file= 'http://www.vbulletin.com/forum/external.php?type=xml';
// ## Adjust this variable to point to your XML feed
$xml_file = 'http://www.vbulletin.com/forum/external.php?type=xml';
// ## configuration end
// ######################################################
$is_item = false;
$tag = '';
$title = '';
$description = '';
$link = '';
$n = 0;
$url_array = parse_url($xml_file);
$filename = strrchr($url_array, '/');
$realpath = substr($url_array, 0, (strlen($url_array) - strlen($filename)));
$forumlink = $url_array . '://' . $url_array . $realpath . '/showthread.php?t=';
function character_data($parser, $data)
{
global $is_item, $tag, $title, $author, $date, $time;
if ($is_item)
{
switch ($tag)
{
case "TITLE":
$title .= $data;
break;
case "AUTHOR":
$author .= $data;
break;
case "DATE":
$date .= $data;
break;
case "TIME":
$time .= $data;
break;
}
}
}
function begin_element($parser, $name, $attribs)
{
global $is_item, $tag, $attribute;
if ($is_item)
{
$tag = $name;
}
else if ($name == "THREAD")
{
$is_item = true;
$attribute = $attribs[ID];
}
}
function end_element($parser, $name)
{
global $is_item, $title, $author, $date, $time, $xml_output, $attribute, $forumlink;
if ($name == "THREAD")
{
$description = $author . " @ " . $date . "/" . $time;
$xml_output .= "<dt><strong><a href='" . $forumlink . $attribute . "'>" . htmlspecialchars(trim($title)) . "</a></strong></dt><dd>" . htmlspecialchars(trim($description)) . "</dd>";
$title = "";
$author = "";
$date = "";
$time = "";
$attribute = "";
$is_item = false;
}
}
$parser = xml_parser_create();
xml_set_element_handler($parser, "begin_element", "end_element");
xml_set_character_data_handler($parser, "character_data");
$fp = fopen($xml_file,"r");
while ($data = fread($fp, 4096))
{
xml_parse($parser, $data, feof($fp));
}
fclose($fp);
xml_parser_free($parser);
Make sure to adjust the $xml_file variable at the very top of the code you just added.
Add the following code to wherever on that page you want to display the output:
echo $xml_output;
and put all the code from your first post in it.. EXCEPT:
Make sure to adjust the $xml_file variable at the very top of the code you just added.
Add the following code to wherever on that page you want to display the output:
echo $xml_output;
Make sure you don't leave any characters out and also that you keep the original formatting from that post on VBulletin that you copied the code from
Also make sure the first line contains
[php]
<?php
[/php]
and the last line has
[php]?>[/php]
Those that the opening and closing "tags" to tell the web server to use PHP
Your homepage will be MUST be a .php page. I am assuming here that it is
Open your homepage. At the very top before any HTML.. add
[php]
<?php
require_once '<pathtoyour_getrss.php>';
[/php]
Those lines tell the webserver processing the page to use PHP and include that getrss.php page. You will need to change < pathtoyour_getrss.php > to reflect where it is really on your server (eg.. /forum/customcode).
Then in your HTML.. wherever you want the threads to go ... simply put...
[php]
<?php echo $xml_output; >?
[/php]
That will then add that content to that spot
I created a new file called getrss.php adding the following and only the following! the entire text above with the PHP tags!
Now I went to my index.php page and added the required PHP line... above all the HTML.
I than added the echo within my HTML and my page fatal errors
Now I just need it to fit and look good