any help with rss appreciated

From: Date: Thu, 06 Jul 2006 20:28:04 +0000
Subject: any help with rss appreciated
Groups: php.gtk.dev 
Request: Send a blank email to php-gtk-dev+get-3202@lists.php.net to get a copy of this message
hi all, i am redscouse, i am relatively new to php (around 18months) i can do most things i want to using php (take the long way round sometimes but im getting there) i am trying now to learn php-gtk, the reason is i am trying to create my own rss reader for a club that i belong to, i only want it to read the one feed just my clubs so when can gets any urgent news about upcoming events. I have so far created the window and buttons, put them all together and its looking good - from my point of view ;) i have used a rss parser inthere but i can't seem to get it to work, and i was hoping i might be able to get some tips here. Here is the code below: - (please note the current feed url is just one im using to test) <?php /***********************************************************/ // Check if the module is loaded // if (!extension_loaded('gtk')) { // dl( 'php_gtk.' . PHP_SHLIB_SUFFIX); // } // // This must be loaded for script to work // /***********************************************************/ // // Create the Variables // // How many records to display $show = 1; // + 1 -- Don't first is 0 ( zero ) set_time_limit(0); $file = "http://z.about.com/6/g/martialarts/b/index.xml"; $rss_channel = array(); $currently_writing = ""; $main = ""; $item_counter = 0; // // Create the functions // // Shutdown function function shutdown() { // Show message print "Closing Newsreader,\r\n Please wait...\r\n"; // Quit the program Gtk::main_quit(); } // Start the Rss Parser - ( Via Update Button ) function startElement($parser, $name, $attrs) { global $rss_channel, $currently_writing, $main; switch($name) { case "RSS": case "RDF:RDF": case "ITEMS": $currently_writing = ""; break; case "CHANNEL": $main = "CHANNEL"; break; case "IMAGE": $main = "IMAGE"; $rss_channel["IMAGE"] = array(); break; case "ITEM": $main = "ITEMS"; break; default: $currently_writing = $name; break; } endElement(); } function endElement($parser, $name) { global $rss_channel, $currently_writing, $item_counter; $currently_writing = ""; if ($name == "ITEM") { $item_counter++; } characterData(); } function characterData($parser, $data) { global $rss_channel, $currently_writing, $main, $item_counter; if ($currently_writing != "") { switch($main) { case "CHANNEL": if (isset($rss_channel[$currently_writing])) { $rss_channel[$currently_writing] .= $data; } else { $rss_channel[$currently_writing] = $data; } break; case "IMAGE": if (isset($rss_channel[$main][$currently_writing])) { $rss_channel[$main][$currently_writing] .= $data; } else { $rss_channel[$main][$currently_writing] = $data; } break; case "ITEMS": if (isset($rss_channel[$main][$item_counter][$currently_writing])) { $rss_channel[$main][$item_counter][$currently_writing] .= $data; } else { //print ("rss_channel[$main][$item_counter][$currently_writing] = $data<br>"); $rss_channel[$main][$item_counter][$currently_writing] = $data; } break; } } showTheResults(); } function showTheResults() { $xml_parser = xml_parser_create(); xml_set_element_handler($xml_parser, "startElement", "endElement"); xml_set_character_data_handler($xml_parser, "characterData"); if (!($fp = fopen($file, "r"))) { die("could not open XML 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); // output as HTML if (isset($rss_channel["IMAGE"])) { print (" \"" &nbsp;&nbsp;<br /><br />"); } else { print (""); } //print ("" . $rss_channel["DESCRIPTION"] . "<br><br>"); if (isset($rss_channel["ITEMS"])) { if (count($rss_channel["ITEMS"]) > 0) { for( $i = 0; $i <=$show; $i++ ) // Change number in $i <=X to change how many ad's shown where X being number { print (" " . $rss_channel["ITEMS"][$i]["TITLE"] . " <br />"); print ("" . html_entity_decode($rss_channel["ITEMS"][$i]["DESCRIPTION"]) . ""); print ("<hr width=\"60%\" />"); } } else { print ("There are no articles in this feed."); } } } // // Create the widgets // // Create the Main window $window = new GtkWindow(); // Set the title $window->set_title("Rss Newsreader - Created by Redscouse"); // Connect 'Destroy' command with 'Shutdown' function $window->connect('destroy', 'shutdown'); // Set the window size $window->set_usize(380, 270); // Create Vertical box - To hold everything $box1 = &new GtkVBox(); // Add box 1 to window $window->add($box1); // Create Horizontal box - For the frame, label and text window $box2 = &new GtkHBox(false, 5); // Set the border $box2->set_border_width(10); // Pack the boxes together ( box 2 into box 1 ) $box1->pack_start($box2); // Create a frame $frame = &new GtkFrame('Latest News'); // Pack the frame into box 2 $box2->pack_start($frame); // Create a text window $data = &new GtkText($updatedNews); // Add the window to the frame $frame->add($data); // Create a Separator - To split the window in two $separator = &new GtkHSeparator(); // Pack the separator into box 1 $box1->pack_start($separator, false); // Create Horizontal box - For the buttons $box2 = &new GtkHBox(false, 10); // Set the border $box2->set_border_width(10); // Pack the boxes $box1->pack_start($box2, false); // Create Update button $button = &new GtkButton('Update'); // Connect update button with update function $button->connect('clicked', 'startElement'); // Pack the button into box 2 $box2->pack_start($button); // Create Close button $button = &new GtkButton('Close'); // Connect close button with shutdown function $button->connect('clicked', 'shutdown'); // Pack the button into box 2 $box2->pack_start($button); // // Show everything & run loop // // Show all $window->show_all(); // Run loop Gtk::main(); ?> -------------- END OF CODE ---------------- Any help with this would be appreciated very much as i seem to have hit a brick wall. Thanks in advance Red. -- View this message in context: http://www.nabble.com/any-help-with-rss-appreciated-tf1902856.html#a5206995 Sent from the Php - GTK - Dev forum at Nabble.com.

« previous php.gtk.dev (#3202) next »