adickt
OSNN One Post Wonder
- Joined
- 14 May 2006
- Messages
- 1
Geffy.. thanks for this code, you have saved me loads of time and here is what i ended up doing for the members of my CSS clan..Geffy said:This is the code that I did for the OSNN Latest News banner/sigs
it fetches the information from the RSS feed and parses it, the charData function is the place where it only gets x number of entries
If I get some time, I might polish this code up a bit
PHP:<?php /********************************** * OSNN VirtuaNews RDF Parser * * Author: StealthNinja * eMail: coder@stealth-ninja.co.uk * * Written for: ElectronicPunk * * Description: * Reads the OSNN RDF backend * and then parses that file to * obtain the current headlines * for inclusion into an image **********************************/ // variable definitions // Image Vars $image = "banner_468x60_var1_back.jpg"; // image dimensions 468x60px $font = "verdana.ttf"; $size = 7; $horiz = 185; $vert = 16; $maxlen= 60; // RDF Parsing Vars $url = "http://www.osnn.net/modules.php?modname=backend&action=rdf"; $temp = "temp.xml"; $store = 0; $count = 0; $maxent= 4; $array = array(); // XML parsing functions function openTag($parser, $name, $attrs) { global $store; if ($name == "TITLE") { $store = 1; } else { $store = 0; } } function closeTag($parser, $name) { // w00p de doo } function charData($parser, $data) { global $store, $array; if ($store == 1 && $count <= $maxent) { $array[] = $data; $store = 0; $count++; } } function storeXML($filename, $string) { $string = ereg_replace('&', 'and', $string); $string = ereg_replace('&', 'and', $string); $fp = fopen($filename, "w") or die ("unable to open storage file for writing<br />\nif it exists then chmod {$filename} to 666"); $write = fwrite($fp, $string); fclose($fp); return $write; } // define the parser $parser = xml_parser_create(); xml_set_element_handler($parser, "openTag", "closeTag"); xml_set_character_data_handler($parser, "charData"); if (!(storeXML($temp, file_get_contents($url)))) { die ("Unable to store OSNN RDF Data"); } if (!($handle = fopen($temp, "r"))) { die ("Unable to open Temp store<br />\nif it exists then chmod {$temp} to 666"); } while ($data = fread($handle, filesize($temp))) { if (!xml_parse($parser, $data, feof($handle))) { die (xml_error_string(xml_get_error_code($parser))); } } xml_parser_free($parser); // make sure no strings are too long foreach ($array as $key => $value) { if (strlen($value) > $maxlen) { $array[$key] = substr($value, 0, 45) . ".."; } } reset($array); // Image Creation $imgData = getimagesize($image); if ($imgData[2] == 1) { header("Content-type: image/gif"); $im = ImageCreateFromGIF($image); } else { header("Content-type: image/jpeg"); $im = ImageCreateFromJPEG($image); } $textc = ImageColorAllocate($im,64,89,132); $black = ImageColorAllocate($im,0,0,0); ImageTTFText($im,$size,0,$horiz,$vert,$textc,$font,$array[1]); ImageTTFText($im,$size,0,$horiz,$vert+12,$textc,$font,$array[2]); ImageTTFText($im,$size,0,$horiz,$vert+24,$textc,$font,$array[3]); ImageTTFText($im,$size,0,$horiz,$vert+36,$textc,$font,$array[4]); if ($imgData[2] == 1) { ImageGIF($im); } else { ImageJPEG($im,'',100); } ImageDestroy($im); ?>
http://www.clan-km.com/sig/
and with a few added bits you i got it to import images and change the text
http://www.clan-km.com/sig/?name=[KM]%20ShadowDog&img=http://www.clan-km.com/components/com_simpleboard/avatars/62.gif
ive also sorted it out to take in any rss feed as well..
http://www.clan-km.com/sig/?url=htt.../rss/newsonline_uk_edition/front_page/rss.xml