<?php
// variable definitions
// Image Vars
$image = "sig.jpg"; // image dimensions 301x100px
$font = "verdana.ttf";
$size = 7;
$horiz = 185;
$vert = 16;
$maxlen= 60;
// RDF Parsing Vars
$url = "[URL="http://djrcs.com/blog/?feed=rss2"]http://djrcs.com/blog/?feed=rss2[/URL]";
$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);
?>