Jump to content

Search the Community

Showing results for tags 'class structure'.



More search options

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • W3Schools
    • General
    • Suggestions
    • Critiques
  • HTML Forums
    • HTML/XHTML
    • CSS
  • Browser Scripting
    • JavaScript
    • VBScript
  • Server Scripting
    • Web Servers
    • Version Control
    • SQL
    • ASP
    • PHP
    • .NET
    • ColdFusion
    • Java/JSP/J2EE
    • CGI
  • XML Forums
    • XML
    • XSLT/XSL-FO
    • Schema
    • Web Services
  • Multimedia
    • Multimedia
    • FLASH

Calendars

  • Community Calendar

Group


AIM


MSN


Website URL


ICQ


Yahoo


Jabber


Skype


Location


Interests


Languages

Found 1 result

  1. BACKGROUND: Please find below a portion of a PHP class used to create an RSS feed. Included are only the constructor function and the function used to create the actual document. All other functions have been omitted so as to focus on the question at hand. My reason for posting this code is to better understand the proper way to create a class. As you can readily see from the __construct( ) function of this class each new instance of the class requires six parameter values. Although the author lists these parameters at the beginning of the class definition, he comments them out, rather than initializing them. QUESTION: Is this standard practice? What is to be gained by not declaring them outside of the __construct( ) function? It appears to create an unnecessary repetitious use of the pseudo $this variable. <?php /** * rss_feed (simple rss 2.0 feed creator php class) * * @author Christos Pontikis http://pontikis.net * @copyright Christos Pontikis * @license MIT http://opensource.org/licenses/MIT * @version 0.1.0 (28 July 2013) * */ class rss_feed { /** * Constructor * * @param array $a_db database settings * @param string $xmlns XML namespace * @param array $a_channel channel properties * @param string $site_url the URL of your site * @param string $site_name the name of your site * @param bool $full_feed flag for full feed (all topic content) */ public function __construct($a_db, $xmlns, $a_channel, $site_url, $site_name, $full_feed = false) { // initialize $this->db_settings = $a_db; $this->xmlns = ($xmlns ? ' ' . $xmlns : ''); $this->channel_properties = $a_channel; $this->site_url = $site_url; $this->site_name = $site_name; $this->full_feed = $full_feed; } /** * Generate RSS 2.0 feed * * @return string RSS 2.0 xml */ public function create_feed() { $xml = '<?xml version="1.0" encoding="utf-8"?>' . "\n"; $xml .= '<rss version="2.0"' . $this->xmlns . '>' . "\n"; // channel required properties $xml .= '<channel>' . "\n"; $xml .= '<title>' . $this->channel_properties["title"] . '</title>' . "\n"; $xml .= '<link>' . $this->channel_properties["link"] . '</link>' . "\n"; $xml .= '<description>' . $this->channel_properties["description"] . '</description>' . "\n"; // channel optional properties if(array_key_exists("language", $this->channel_properties)) { $xml .= '<language>' . $this->channel_properties["language"] . '</language>' . "\n"; } if(array_key_exists("image_title", $this->channel_properties)) { $xml .= '<image>' . "\n"; $xml .= '<title>' . $this->channel_properties["image_title"] . '</title>' . "\n"; $xml .= '<link>' . $this->channel_properties["image_link"] . '</link>' . "\n"; $xml .= '<url>' . $this->channel_properties["image_url"] . '</url>' . "\n"; $xml .= '</image>' . "\n"; } // get RSS channel items $now = date("YmdHis"); // get current time // configure appropriately to your environment $rss_items = $this->get_feed_items($now); foreach($rss_items as $rss_item) { $xml .= '<item>' . "\n"; $xml .= '<title>' . $rss_item['title'] . '</title>' . "\n"; $xml .= '<link>' . $rss_item['link'] . '</link>' . "\n"; $xml .= '<description>' . $rss_item['description'] . '</description>' . "\n"; $xml .= '<pubDate>' . $rss_item['pubDate'] . '</pubDate>' . "\n"; $xml .= '<category>' . $rss_item['category'] . '</category>' . "\n"; $xml .= '<source>' . $rss_item['source'] . '</source>' . "\n"; if($this->full_feed) { $xml .= '<content:encoded>' . $rss_item['content'] . '</content:encoded>' . "\n"; } $xml .= '</item>' . "\n"; } $xml .= '</channel>'; $xml .= '</rss>'; return $xml; } } ?>
×