Results 1 to 3 of 3

Thread: [RESOLVED] Finish making this re-usable! (VisualAD!???)

  1. #1

    Thread Starter
    PowerPoster Static's Avatar
    Join Date
    Oct 2000
    Location
    Rochester, NY
    Posts
    9,390

    Resolved [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
    Attached Files Attached Files
    Last edited by Static; Apr 18th, 2007 at 09:37 AM.
    JPnyc rocks!! (Just ask him!)
    If u have your answer please go to the thread tools and click "Mark Thread Resolved"

  2. #2
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    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:
    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.
    Last edited by penagate; Apr 18th, 2007 at 03:00 PM. Reason: fixed an embarrasing mistake.

  3. #3

    Thread Starter
    PowerPoster Static's Avatar
    Join Date
    Oct 2000
    Location
    Rochester, NY
    Posts
    9,390

    Re: Finish making this re-usable! (VisualAD!???)

    Thank you so very much!
    I owe you!
    JPnyc rocks!! (Just ask him!)
    If u have your answer please go to the thread tools and click "Mark Thread Resolved"

Posting Permissions

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



Click Here to Expand Forum to Full Width