3 Attachment(s)
[RESOLVED] Finish making this re-usable! (VisualAD!???)
VisualAD was helping me with this, but i havent seen him on MSN! :(
anyway.. I am trying to make this code re-usable. Its an RSS Feed parser to be used on my forum. Right now I need 1 file for each feed, so im using basically 11 files, renaming the function names in each one and passing 1 feed url into each file. the result looks like this: http://staticfx.com/forums/bb3portal.php (rss gaming news section)
now I would like to reuse the code and just loop thru the feed urls..
one thing to keep in mind, this section of code:
(PHP 5.1.4 - Just updated.. was running 4.3.11)
PHP Code:
$template->assign_block_vars('oneup', array(
'LINK' => $val['LINK'],
'TITLE' => $val['TITLE'],
'DESC' => $val['DESCRIPTION'])
);
the 'oneup' variable needs to change with each feed url, because the output is dont in an html file by each variable.. so in this case the output file would use {oneup.LINK} etc...
so when passing in a url, i need to pass in a url & the output variable... or, if there is another way around it
Attached:
Original file: rss_1up.php
Partially completed new file: rss_feeds.php
Output HTML file: rss_feeds.html
Re: Finish making this re-usable! (VisualAD!???)
Now that you've upgraded to PHP 5, you can make use of its improved class syntax. 'var' can be replaced with 'private' and the constructor name with '__construct' - which saves you having to rename it if you decide to change the class name.
It looks to me as though you merely need to write the constructor, which entails simply assigning the private variables. I would pass the URL in to the constructor as well, rather than the runfeed() method. (You can also make that private, by the way.)
You'll need to change these two lines to point to the member functions:
Quote:
PHP Code:
xml_set_element_handler($xml_parser, "startElement", "endElement");
xml_set_character_data_handler($xml_parser, "characterData");
PHP Code:
xml_set_element_handler(
$xml_parser,
array($this, 'startElement'),
array($this, 'endElement')
);
xml_set_character_data_handler(
$xml_parser,
array($this, 'characterData')
);
And of course replace the hardcoded 'oneup' with $this->feed_name or some other variable of your choosing.
Other than that it looks good to go.
Re: Finish making this re-usable! (VisualAD!???)
Thank you so very much!
I owe you!