Categories > TinyButStrong general >

Any using XML/RSS feed as a data source for MergeBlock() ??

The forum is closed. Please use Stack Overflow for submitting new questions. Use tags: tinybutstrong , opentbs
By: TomH
Date: 2007-04-05
Time: 13:03

Any using XML/RSS feed as a data source for MergeBlock() ??

Has anyone here done any work to have MergeBlock() accept an XML file/url as the data source ???

I have been trying to adapt an RSS parser (the "class_RSS_feed.php" from Timothy Sakach - which I have used for parsing RSS feeds successfully in the past)

Trying to modify Sakach script to produce an array, like this snippet
     switch ($element)
    {
      case 'channel':  // major elements -- define closing event
        // put channel information on the top. This should work even if the channel close
        //  element occurs before the item tags
        if ($this->showimage && $this->image["link"])
        {

         // === TomH=== here is old way generates HTML output
         //$outbuffer .= '<a href="' . $this->image["link"] . '" target="_blank"><img src="'
         //           . $this->image["url"] . '" border=0 alt="' . $this->image["title"]
                 //           . '"></a><br>';

         // === TomH=== here is my NEW way to make array
     $outbuffer[$element]['imagelink'] = $this->image["link"];
     $outbuffer[$element]['imageurl'] = $this->image["url"];
     $outbuffer[$element]['imagetitle'] = $this->image["title"];
        }
               
        // $outbuffer .= '<a href="' . $this->channel["link"] . '" target="_blank">'
        //               . $this->channel["title"] . '</a><br>';

     $outbuffer[$element]['link'] = $this->channel["link"];
     $outbuffer[$element]['title'] = $this->channel["title"];

        if ($this->showdesc)
/*      $outbuffer .= $this->channel["desc"];
        $outbuffer .= $this->output;
        $this->output = $outbuffer;
*/
        $this->channel["link"] = "";
        $this->channel["title"] = "";
        $this->channel["desc"] = "";

        $this->channelclosed = true;

     $outbuffer[$element]['desc'] = $this->channel["desc"];
         $this->channelclosed = true;


        break;
...
// at end of class
$this->output = $outbuffer;
}

// Using class like this
include_once ("./class_array_from_RSS_feed.php");

$file="http://rss.azstarnet.com/index.php?section=s1a";

$px = new RSS_feed();
$px->Set_URL($file);
$px->Set_Limit("0"); // 0 = Default = All
$px->Show_Image(true); // Default = false
$px->Show_Description(true); // Default = false
$r = $px->Get_Results();

//echo $r;
// then I make a simple var to test if any contents in the array
// but never any result shows in template so not surprised no result
// in any MergeBlock()
$testvar = print_r($r,true);


Yes, this is a poor man's way - I don't really understand how to build classes so I really don't know how to modify classes - but it not working at all.

So, I cannot get any output from the new array.

Any ideas how to correct this, or BETTER if someone has a code contribution that does this already working :)

Thanks for TBS,
TomH

By: TomH
Date: 2007-04-05
Time: 16:11

Fuhgeddaboutit Re: Any using XML/RSS feed as a data source for MergeBlock() ??

Sorry I didn't do my home work... forget the previous post!!!

Some searching of PHP classes finally gave me some prebuilt classes that will slurp RSS XML into a PHP array -- without me havnig to show how little PHP I can write :(

As a penance (Easter season here) for cluttering the TBS forum -- I'll report back when I chose a class and have some TBS templates for display of RSS and XML.

Thanks for TBS,
TomH

By: TomH
Date: 2007-04-05
Time: 22:22

More on: New: Using XML/RSS feed as a data source for MergeBlock()

Back to this...
I now do have an array parsed from an RSS feed (via HTTP)

However I am getting lost in referencing the elements inside the array when I do the TBS blocks

For my php...
include('tbs_class.php');
include('xml_parser_KD.php');

$xml = implode('', file($url));
$xmlobj = XML_unserialize(&$xml);
$print_xmlobj = print_r($xmlobj,true);

$TBS->MergeBlock('blk1', 'array', $xmlobj );
$TBS->Show();

For the template I am trying this...
<tr><th align=left colspan=2>
<a href="[blk1.rss.channel.link;block=tr;parentgroup=rss.channel.title]"> [blk1.rss.channel.title;.]</a>
</th></tr>

<tr><td>[blk1.rss.channel.item.$.title;block=tr;.]</td><td valign=top> [blk1.rss.channel.item.$.description;.]</td></tr>

My errors
TinyButStrong Error in field [blk1.rss.channel.title...] : item 'rss' is not an existing key in the array. This message can be cancelled using parameter 'noerr'.

TinyButStrong Error in field [blk1.rss.channel.link...] : item 'rss' is not an existing key in the array. This message can be cancelled using parameter 'noerr'.

TinyButStrong Error in field [blk1.rss.channel.item.$.description...] : item 'rss' is not an existing key in the array. This message can be cancelled using parameter 'noerr'.

TinyButStrong Error in field [blk1.rss.channel.item.#.title...] : item 'rss' is not an existing key in the array. This message can be cancelled using parameter 'noerr'.

As you can see -- I can't make sense of how to "properly" address the block elements.

The array looks like this when print_r()
Array
(
    [rss attr] => Array
        (
            [version] => 2.0
        )

    [rss] => Array
        (
            [channel attr] => Array
                (
                    [version] => 2.0
                )

            [channel] => Array
                (
                    [title] => Daily Star Front Page
                    [link] => http://www.azstarnet.com/sn/dailystar/
                    [description] => Daily Star Front Page headlines from the Arizona Daily Star
                    [language] => en-us
                    [pubDate] => 2007-04-05
                    [ttl] => 60
                    [item] => Array
                        (
                            [0] => Array
                                (
                                    [title] => Surrender! Comics have taken over
                                    [link] => http://www.azstarnet.com/sn/dailystar/176983.php
                                    [description] => Fans, artists in Tucson's lively scene  caliente
                                    [category] => 0x00000000
                                )

                            [1] => Array
                                (
                                    [title] => Council gives speedy OK to $130M arena
                                    [link] => http://www.azstarnet.com/sn/dailystar/176981.php
                                    [description] => Seemingly out of nowhere, a Downtown arena became Rio Nuevo's top project Wednesday, as the City Council voted unanimously to approve the $130 million project. 
                                    [category] => 0x07080800
                                    [enclosure attr] => Array
                                        (
                                            [url] => http://www.azstarnet.com/ss/2007/04/05/176981-1.jpg
                                            [type] => image/jpeg
                                        )

                                    [enclosure] =>
                                )

                            [2] => Array
                                (
                                    [title] => City expands search for developer to build luxury Downtown hotel
                                    [link] => http://www.azstarnet.com/sn/dailystar/176979.php
                                    [description] => Tucson is looking for a developer who can use the city's favorable financing to build a posh Downtown hotel. On Wednesday the City Council voted to give city staffers 30 days to come back with a plan to make it a reality.  
                                    [category] => 0x07080800
                                    [enclosure attr] => Array
                                        (
                                            [url] => http://www.azstarnet.com/ss/2007/04/05/176979-2.jpg
                                            [type] => image/jpeg
                                        )

                                    [enclosure] =>
                                )

                            [3] => Array
                                (
                                    [title] => 2 burglary suspects stab each other; 1 in hospital, other flees
                                    [link] => http://www.azstarnet.com/sn/dailystar/176969.php
                                    [description] => In a new twist on crime fighting, two men authorities linked to a burglary got into a bloody fight that landed one man in the hospital Wednesday and prompted a search for the other, a Pima County Sheriff's Department spokeswoman said.
                                    [category] => 0x07030000
                                )

                            [4] => Array
                                (
                                    [title] => 'Friendly fire' may have killed GI from Tucson
                                    [link] => http://www.azstarnet.com/sn/dailystar/176968.php
                                    [description] => WASHINGTON — Two soldiers, including one from Tucson, who died in Iraq in February may have been killed by their own comrades, the Army said Wednesday.
                                    [category] => 0x07000000
                                    [enclosure attr] => Array
                                        (
                                            [url] => http://www.azstarnet.com/ss/2007/04/05/176968-1.jpg
                                            [type] => image/jpeg
                                        )

                                    [enclosure] =>
                                )

                        )

                )

        )

)