Results 1 to 3 of 3
  1. #1

    Default Habbo News Feed?

    Im making my own Fansite, and i was wondering if anyone knows, or could help to get the code for displaying a live news feed on a page?

    Thanks

  2. #2
    Join Date
    Feb 2006
    Location
    Scotland
    Posts
    2,087
    Tokens
    138

    Latest Awards:

    Default

    Hey,

    I used to use this code on my website (Wasnt created by me)

    PHP Code:
    <?php

    class xItem {
      var 
    $xTitle;
      var 
    $xLink;
      var 
    $xDescription;
    }

    // general vars
    $sTitle = "";
    $sLink = "";
    $sDescription = "";
    $arItems = array();
    $itemCount = 0;

    // ********* Start User-Defined Vars ************
    // rss url goes here
    $uFile = "http://www.habbo.co.uk/news/rss.xml";
    // descriptions (true or false) goes here
    $bDesc = false;
    // font goes here
    $uFont = "Verdana, Arial, Helvetica, sans-serif";
    $uFontSize = "2";
    // ********* End User-Defined Vars **************

    function startElement($parser, $name, $attrs) {
      global 
    $curTag;

      
    $curTag .= "^$name";

    }

    function 
    endElement($parser, $name) {
      global 
    $curTag;

      
    $caret_pos = strrpos($curTag,'^');

      
    $curTag = substr($curTag,0,$caret_pos);

    }

    function 
    characterData($parser, $data) { global $curTag; // get the Channel information first
      
    global $sTitle, $sLink, $sDescription;  
      
    $titleKey = "^RSS^CHANNEL^TITLE";
      
    $linkKey = "^RSS^CHANNEL^LINK";
      
    $descKey = "^RSS^CHANNEL^DESCRIPTION";
      if (
    $curTag == $titleKey) {
        
    $sTitle = $data;
      }
      elseif (
    $curTag == $linkKey) {
        
    $sLink = $data;
      }
      elseif (
    $curTag == $descKey) {
        
    $sDescription = $data;
      }

      
    // now get the items 
      
    global $arItems, $itemCount;
      
    $itemTitleKey = "^RSS^CHANNEL^ITEM^TITLE";
      
    $itemLinkKey = "^RSS^CHANNEL^ITEM^LINK";
      
    $itemDescKey = "^RSS^CHANNEL^ITEM^DESCRIPTION";

      if (
    $curTag == $itemTitleKey) {
        
    // make new xItem    
        
    $arItems[$itemCount] = new xItem();     

        
    // set new item object's properties    
        
    $arItems[$itemCount]->xTitle = $data;
      }
      elseif (
    $curTag == $itemLinkKey) {
        
    $arItems[$itemCount]->xLink = $data;
      }
      elseif (
    $curTag == $itemDescKey) {
        
    $arItems[$itemCount]->xDescription = $data;
        
    // increment item counter
        
    $itemCount++;
      }
    }

    // main loop
    $xml_parser = xml_parser_create();
    xml_set_element_handler($xml_parser, "startElement", "endElement");
    xml_set_character_data_handler($xml_parser, "characterData");
    if (!(
    $fp = fopen($uFile,"r"))) {
      die (
    "could not open RSS for input");
    }
    while (
    $data = fread($fp, 4096)) {
      if (!
    xml_parse($xml_parser, $data, feof($fp))) {
        die(
    sprintf("XML error: %s at line %d", xml_error_string(xml_get_error_code($xml_parser)), xml_get_current_line_number($xml_parser)));
      }
    }
    xml_parser_free($xml_parser);


    // write out the items
    ?>
    <html>
    <head>
    <body bgcolor = "#FFFFFF">
    <?php
    for ($i=0;$i<count($arItems);$i++) {
      
    $txItem = $arItems[$i];
    ?>
    <font face = "<?php echo($uFont); ?>" size = "<?php echo($uFontSize); ?>"><a href = "<?php echo($txItem->xLink); ?>"><?php echo($txItem->xTitle); ?></a></font>
    <?php
    if ($bDesc) {
    ?>
    <?php 
    echo ($txItem->xDescription); ?>
    <?php
    }
    echo (
    "<br>");
    }
    ?>
    </body>
    </html>
    Editing the user defined variables will let you change what hotel etc.

    .:; Johno

  3. #3

    Default

    Thanks so much!
    One thing, do you know how to edit the code so that it only displays say 1 or 2 of the feed titles?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •