', $data, 1);
}
$data = preg_replace("/<(\/)?$this->xhtml_prefix:/msiU", '<\\1', $data);
}
} else {
if (empty($attribs['SPENCODED']) || $attribs['SPENCODED'] != 'false') {
$data = $this->entities_decode($data);
}
}
$data = trim($data);
$data = str_replace(' spencoded="false">', '>', $data);
// Strip out HTML tags and attributes that might cause various security problems.
// Based on recommendations by Mark Pilgrim at:
// http://diveintomark.org/archives/2003/06/12/how_to_consume_rss_safely
if ($this->strip_htmltags) {
$tags_to_strip = explode(',', $this->strip_htmltags);
foreach ($tags_to_strip as $tag) {
if ($this->encode_instead_of_strip) {
// For encoded angled brackets (do these first)
$data = preg_replace('/<(!)?(\/)?'. trim($tag) .'(\w|\s|=|-|"|\'|"|:|;|%|\/|\.|\?|&|,|#|!|\+|\(|\))*>/i', '<\\0>', $data);
$data = str_replace('<<', '<', $data);
$data = str_replace('>>', '>', $data);
// For angled brackets
$data = preg_replace('/<(!)?(\/)?'. trim($tag) .'(\w|\s|=|-|"|\'|"|:|;|%|\/|\.|\?|&|,|#|!|\+|\(|\))*>/i', '<\\0>', $data);
$data = str_replace('<<', '<', $data);
$data = str_replace('>>', '>', $data);
}
else {
$data = preg_replace('/(<|<)(!)?(\/)?'. trim($tag) .'(\w|\s|=|-|"|\'|"|:|;|%|\/|\.|\?|&|,|#|!|\+|\(|\))*(>|>)/i', '', $data);
}
}
}
if ($this->strip_attributes) {
$attribs_to_strip = explode(',', $this->strip_attributes);
foreach ($attribs_to_strip as $attrib) {
$data = preg_replace('/ '. trim($attrib) .'=(\'|'|"|")?(\w|\s|=|-|:|;|\/|\.|\?|&|,|#|!|\(|\)|\'|'|<|>|\+|{|})*(\'|'|"|")?/i', '', $data);
}
}
// Replace H1, H2, and H3 tags with the less important H4 tags.
// This is because on a site, the more important headers might make sense,
// but it most likely doesn't fit in the context of RSS-in-a-webpage.
if ($this->replace_headers) {
$data = preg_replace('/
/msiU', '', $data);
$data = preg_replace('/<\/h[1-3]>/i', '
', $data);
}
// If Strip Ads is enabled, strip them.
if ($this->strip_ads) {
$data = preg_replace('/(<|<)a(.*)href=("|")(.*)\\/\/(www\.)?pheedo.com\/(.*).phdo\?s=(.*)(>|>)(\s*|.*)((<|<).*(>|>)|.*)(\s*|.*)(<|<)\/a(>|>)/i', '', $data); // Pheedo links (tested with Dooce.com)
$data = preg_replace('/(<|<)a(\w|\s|\=|"|")*href=("|")http:\/\/ad.doubleclick.net\/(.*)(>|>)(\s*|.*)((<|<).*(>|>)|.*)(\s*|.*)(<|<)\/a(>|>)/i', '', $data); // Doubleclick links (tested with InfoWorld.com)
$data = preg_replace('/(<|<)map(\w|\s|=|-|"|\'|")*name=("|\'|")google_ad_map(\w|\s|=|-)*("|\'|")(\w|\s|=|-|"|\'|")*(^gt;|>)(.*)(<|<)\/map(>|>)(<|<)img(\w|\s|=|-|"|\'|")*usemap=("|\'|")#google_ad_map(\w|\s|=|-)*("|\'|")(\w|\s|=|-|"|\'|"|:|;|\/|\.|\?|&)*(>|>)/i', '', $data); // Google AdSense for Feeds (tested with tuaw.com).
// Feedflare, from Feedburner
}
if ($is_url) {
$data = $this->replace_urls($data, true);
} else {
$data = preg_replace_callback('/<(.+)>/msiU', array(&$this, 'replace_urls'), $data);
}
// If Bypass Image Hotlink is enabled, rewrite all the image tags.
if ($this->bypass_image_hotlink != false) {
$data = preg_replace_callback('/src=("|"|\'|')?(\w|=|-|:|;|\/|\.|\?|&|,|#|!|\(|\)|\'|')*("|"|\'|')?/', create_function('$m', 'return "src=\"".rawurlencode(str_replace("\"", "", str_replace("src=", "", html_entity_decode($m[0]))))."\"";'), $data);
if ($this->bypass_image_hotlink_page != false) {
$data = preg_replace('/bypass_image_hotlink_page.'?i=', $data);
}
else $data = preg_replace('/attribs['XML:BASE'])) {
if (!empty($this->item_xmlbase)) {
$attrib_xmlbase = parse_url($this->absolutize_url($this->attribs['XML:BASE'], $this->item_xmlbase));
} else {
$attrib_xmlbase = parse_url($this->absolutize_url($this->attribs['XML:BASE'], $this->feed_xmlbase));
}
}
else if (!empty($this->attribs[$this->namespaces['xml'] . ':BASE'])) {
if (!empty($this->item_xmlbase)) {
$attrib_xmlbase = parse_url($this->absolutize_url($this->attribs[$this->namespaces['xml'] . ':BASE'], $this->item_xmlbase));
} else {
$attrib_xmlbase = parse_url($this->absolutize_url($this->attribs[$this->namespaces['xml'] . ':BASE'], $this->feed_xmlbase));
}
}
if (!empty($attrib_xmlbase)) {
$xmlbase = $attrib_xmlbase;
} else if (!empty($this->item_xmlbase)) {
$xmlbase = $this->item_xmlbase;
} else {
$xmlbase = $this->feed_xmlbase;
}
if ($raw_url) {
return $this->absolutize_url($data, $xmlbase);
} else {
$attributes = array(
'background',
'href',
'src',
'longdesc',
'usemap',
'codebase',
'data',
'classid',
'cite',
'action',
'profile',
'for'
);
foreach ($attributes as $attribute) {
$attrib = $this->get_attribute($data[0], $attribute);
$new_tag = str_replace($attrib[1], $this->absolutize_url($attrib[1], $xmlbase), $attrib[0]);
$data[0] = str_replace($attrib[0], $new_tag, $data[0]);
}
return $data[0];
}
}
function entities_decode($data) {
return preg_replace_callback('/&(#)?(x)?([0-9a-z]+);/mi', array(&$this, 'do_entites_decode'), $data);
}
function do_entites_decode($data)
{
$entity = "&$data[1]$data[2]$data[3];";
$entity_html = html_entity_decode($entity, ENT_QUOTES);
if ($entity == $entity_html) {
return preg_replace_callback('/([0-9a-fx]+);/mi', array(&$this, 'replace_num_entity'), $entity);
} else {
return $entity_html;
}
}
/*
* Escape numeric entities
* From a PHP Manual note (on html_entity_decode())
* Copyright (c) 2005 by "php dot net at c dash ovidiu dot tk",
* "emilianomartinezluque at yahoo dot com" and "hurricane at cyberworldz dot org".
*
* This material may be distributed only subject to the terms and conditions set forth in
* the Open Publication License, v1.0 or later (the latest version is presently available at
* http://www.opencontent.org/openpub/).
*/
function replace_num_entity($ord) {
$ord = $ord[1];
if (preg_match('/^x([0-9a-f]+)$/i', $ord, $match))
$ord = hexdec($match[1]);
else
$ord = intval($ord);
$no_bytes = 0;
$byte = array();
if ($ord < 128)
return chr($ord);
if ($ord < 2048)
$no_bytes = 2;
else if ($ord < 65536)
$no_bytes = 3;
else if ($ord < 1114112)
$no_bytes = 4;
else return;
switch ($no_bytes) {
case 2:
$prefix = array(31, 192);
break;
case 3:
$prefix = array(15, 224);
break;
case 4:
$prefix = array(7, 240);
break;
}
for ($i=0; $i < $no_bytes; ++$i)
$byte[$no_bytes-$i-1] = (($ord & (63 * pow(2,6*$i))) / pow(2,6*$i)) & 63 | 128;
$byte[0] = ($byte[0] & $prefix[0]) | $prefix[1];
$ret = '';
for ($i=0; $i < $no_bytes; ++$i)
$ret .= chr($byte[$i]);
return $ret;
}
function parse_date($date) {
if (preg_match('/([0-9]{2,4})-([0-9][0-9])-([0-9][0-9])T([0-9][0-9]):([0-9][0-9]):([0-9][0-9])(\.[0-9][0-9])?Z/i', $date, $matches)) {
if (isset($matches[7]) && substr($matches[7], 1) >= 50)
$matches[6]++;
return strtotime("$matches[1]-$matches[2]-$matches[3] $matches[4]:$matches[5]:$matches[6] -0000");
} else if (preg_match('/([0-9]{2,4})-([0-9][0-9])-([0-9][0-9])T([0-9][0-9]):([0-9][0-9]):([0-9][0-9])(\.[0-9][0-9])?(\+|-)([0-9][0-9]):([0-9][0-9])/i', $date, $matches)) {
if (isset($matches[7]) && substr($matches[7], 1) >= 50)
$matches[6]++;
return strtotime("$matches[1]-$matches[2]-$matches[3] $matches[4]:$matches[5]:$matches[6] $matches[8]$matches[9]$matches[10]");
} else {
return strtotime($date);
}
}
/****************************************************
FUNCTIONS FOR XML_PARSE
****************************************************/
function startHandler($parser, $name, $attribs) {
$this->tagName = $name;
$this->attribs = $attribs;
$this->is_first = true;
switch ($this->tagName) {
case 'ITEM':
case $this->namespaces['rss2'] . ':ITEM':
case $this->namespaces['rss1'] . ':ITEM':
case 'ENTRY':
case $this->namespaces['atom'] . ':ENTRY':
$this->insideItem = true;
$this->do_add_content($this->xmldata['items'][$this->itemNumber], '');
break;
case 'CHANNEL':
case $this->namespaces['rss2'] . ':CHANNEL':
case $this->namespaces['rss1'] . ':CHANNEL':
$this->insideChannel = true;
break;
case 'RSS':
case $this->namespaces['rss2'] . ':RSS':
$this->xmldata['feedinfo']['type'] = 'RSS';
$this->do_add_content($this->xmldata['feeddata'], '');
if (!empty($attribs['VERSION'])) {
$this->xmldata['feedinfo']['version'] = trim($attribs['VERSION']);
}
break;
case $this->namespaces['rdf'] . ':RDF':
$this->xmldata['feedinfo']['type'] = 'RSS';
$this->do_add_content($this->xmldata['feeddata'], '');
$this->xmldata['feedinfo']['version'] = 1;
break;
case 'FEED':
case $this->namespaces['atom'] . ':FEED':
$this->xmldata['feedinfo']['type'] = 'Atom';
$this->do_add_content($this->xmldata['feeddata'], '');
if (!empty($attribs['VERSION'])) {
$this->xmldata['feedinfo']['version'] = trim($attribs['VERSION']);
}
break;
case 'IMAGE':
case $this->namespaces['rss2'] . ':IMAGE':
case $this->namespaces['rss1'] . ':IMAGE':
if ($this->insideChannel) $this->insideImage = true;
break;
}
if (isset($this->xmldata['feedinfo']['type']) && $this->xmldata['feedinfo']['type'] == 'Atom') {
switch ($this->tagName) {
case 'AUTHOR':
case $this->namespaces['atom'] . ':AUTHOR':
$this->insideAuthor = true;
break;
}
}
$this->dataHandler($this->xml, '');
}
function dataHandler($parser, $data) {
if ($this->insideItem) {
switch ($this->tagName) {
case 'TITLE':
case $this->namespaces['rss1'] . ':TITLE':
case $this->namespaces['rss2'] . ':TITLE':
case $this->namespaces['atom'] . ':TITLE':
$this->do_add_content($this->xmldata['items'][$this->itemNumber]['title'], $data);
break;
case $this->namespaces['dc'] . ':TITLE':
$this->do_add_content($this->xmldata['items'][$this->itemNumber]['dc:title'], $data);
break;
case 'CONTENT':
case $this->namespaces['atom'] . ':CONTENT':
$this->do_add_content($this->xmldata['items'][$this->itemNumber]['content'], $data);
break;
case $this->namespaces['content'] . ':ENCODED':
$this->do_add_content($this->xmldata['items'][$this->itemNumber]['encoded'], $data);
break;
case 'SUMMARY':
case $this->namespaces['atom'] . ':SUMMARY':
$this->do_add_content($this->xmldata['items'][$this->itemNumber]['summary'], $data);
break;
case 'LONGDESC':
$this->do_add_content($this->xmldata['items'][$this->itemNumber]['longdesc'], $data);
break;
case 'DESCRIPTION':
case $this->namespaces['rss1'] . ':DESCRIPTION':
case $this->namespaces['rss2'] . ':DESCRIPTION':
$this->do_add_content($this->xmldata['items'][$this->itemNumber]['description'], $data);
break;
case $this->namespaces['dc'] . ':DESCRIPTION':
$this->do_add_content($this->xmldata['items'][$this->itemNumber]['dc:description'], $data);
break;
case 'LINK':
case $this->namespaces['rss1'] . ':LINK':
case $this->namespaces['rss2'] . ':LINK':
case $this->namespaces['atom'] . ':LINK':
$this->do_add_content($this->xmldata['items'][$this->itemNumber]['link'][$this->itemLinkNumber], $data);
break;
case 'ENCLOSURE':
case $this->namespaces['rss1'] . ':ENCLOSURE':
case $this->namespaces['rss2'] . ':ENCLOSURE':
$this->do_add_content($this->xmldata['items'][$this->itemNumber]['enclosure'][$this->enclosureNumber], $data);
break;
case 'GUID':
case $this->namespaces['rss1'] . ':GUID':
case $this->namespaces['rss2'] . ':GUID':
$this->do_add_content($this->xmldata['items'][$this->itemNumber]['guid'], $data);
break;
case 'ID':
case $this->namespaces['atom'] . ':ID':
$this->do_add_content($this->xmldata['items'][$this->itemNumber]['id'], $data);
break;
case 'PUBDATE':
case $this->namespaces['rss1'] . ':PUBDATE':
case $this->namespaces['rss2'] . ':PUBDATE':
$this->do_add_content($this->xmldata['items'][$this->itemNumber]['pubdate'], $data);
break;
case $this->namespaces['dc'] . ':DATE':
$this->do_add_content($this->xmldata['items'][$this->itemNumber]['dc:date'], $data);
break;
case 'ISSUED':
case $this->namespaces['atom'] . ':ISSUED':
$this->do_add_content($this->xmldata['items'][$this->itemNumber]['issued'], $data);
break;
case 'PUBLISHED':
case $this->namespaces['atom'] . ':PUBLISHED':
$this->do_add_content($this->xmldata['items'][$this->itemNumber]['published'], $data);
break;
case 'MODIFIED':
case $this->namespaces['atom'] . ':MODIFIED':
$this->do_add_content($this->xmldata['items'][$this->itemNumber]['modified'], $data);
break;
case 'UPDATED':
case $this->namespaces['atom'] . ':UPDATED':
$this->do_add_content($this->xmldata['items'][$this->itemNumber]['updated'], $data);
break;
case 'CATEGORY':
case $this->namespaces['rss1'] . ':CATEGORY':
case $this->namespaces['rss2'] . ':CATEGORY':
case $this->namespaces['atom'] . ':CATEGORY':
$this->do_add_content($this->xmldata['items'][$this->itemNumber]['category'][$this->categoryNumber], $data);
break;
case $this->namespaces['dc'] . ':SUBJECT':
$this->do_add_content($this->xmldata['items'][$this->itemNumber]['subject'][$this->categoryNumber], $data);
break;
case $this->namespaces['dc'] . ':CREATOR':
$this->do_add_content($this->xmldata['items'][$this->itemNumber]['creator'][$this->authorNumber], $data);
break;
case 'AUTHOR':
case $this->namespaces['rss1'] . ':AUTHOR':
case $this->namespaces['rss2'] . ':AUTHOR':
$this->do_add_content($this->xmldata['items'][$this->itemNumber]['author'][$this->authorNumber]['rss'], $data);
break;
}
if ($this->insideAuthor) {
switch ($this->tagName) {
case 'NAME':
case $this->namespaces['atom'] . ':NAME':
$this->do_add_content($this->xmldata['items'][$this->itemNumber]['author'][$this->authorNumber]['name'], $data);
break;
case 'URL':
case $this->namespaces['atom'] . ':URL':
$this->do_add_content($this->xmldata['items'][$this->itemNumber]['author'][$this->authorNumber]['url'], $data);
break;
case 'URI':
case $this->namespaces['atom'] . ':URI':
$this->do_add_content($this->xmldata['items'][$this->itemNumber]['author'][$this->authorNumber]['uri'], $data);
break;
case 'HOMEPAGE':
case $this->namespaces['atom'] . ':HOMEPAGE':
$this->do_add_content($this->xmldata['items'][$this->itemNumber]['author'][$this->authorNumber]['homepage'], $data);
break;
case 'EMAIL':
case $this->namespaces['atom'] . ':EMAIL':
$this->do_add_content($this->xmldata['items'][$this->itemNumber]['author'][$this->authorNumber]['email'], $data);
break;
}
}
}
else if (($this->insideChannel && !$this->insideImage) || (isset($this->xmldata['feedinfo']['type']) && $this->xmldata['feedinfo']['type'] == 'Atom')) {
switch ($this->tagName) {
case 'TITLE':
case $this->namespaces['rss1'] . ':TITLE':
case $this->namespaces['rss2'] . ':TITLE':
case $this->namespaces['atom'] . ':TITLE':
$this->do_add_content($this->xmldata['info']['title'], $data);
break;
case 'LINK':
case $this->namespaces['rss1'] . ':LINK':
case $this->namespaces['rss2'] . ':LINK':
case $this->namespaces['atom'] . ':LINK':
$this->do_add_content($this->xmldata['info']['link'][$this->linkNumber], $data);
break;
case 'DESCRIPTION':
case $this->namespaces['rss1'] . ':DESCRIPTION':
case $this->namespaces['rss2'] . ':DESCRIPTION':
$this->do_add_content($this->xmldata['info']['description'], $data);
break;
case $this->namespaces['dc'] . ':DESCRIPTION':
$this->do_add_content($this->xmldata['info']['dc:description'], $data);
break;
case 'TAGLINE':
case $this->namespaces['atom'] . ':TAGLINE':
$this->do_add_content($this->xmldata['info']['tagline'], $data);
break;
case 'SUBTITLE':
case $this->namespaces['atom'] . ':SUBTITLE':
$this->do_add_content($this->xmldata['info']['subtitle'], $data);
break;
case 'COPYRIGHT':
case $this->namespaces['rss1'] . ':COPYRIGHT':
case $this->namespaces['rss2'] . ':COPYRIGHT':
case $this->namespaces['atom'] . ':COPYRIGHT':
$this->do_add_content($this->xmldata['info']['copyright'], $data);
break;
case 'LANGUAGE':
case $this->namespaces['rss1'] . ':LANGUAGE':
case $this->namespaces['rss2'] . ':LANGUAGE':
$this->do_add_content($this->xmldata['info']['language'], $data);
break;
case 'LOGO':
case $this->namespaces['atom'] . ':LOGO':
$this->do_add_content($this->xmldata['info']['logo'], $data);
break;
}
}
else if ($this->insideChannel && $this->insideImage) {
switch ($this->tagName) {
case 'TITLE':
case $this->namespaces['rss1'] . ':TITLE':
case $this->namespaces['rss2'] . ':TITLE':
$this->do_add_content($this->xmldata['info']['image']['title'], $data);
break;
case 'URL':
case $this->namespaces['rss1'] . ':URL':
case $this->namespaces['rss2'] . ':URL':
$this->do_add_content($this->xmldata['info']['image']['url'], $data);
break;
case 'LINK':
case $this->namespaces['rss1'] . ':LINK':
case $this->namespaces['rss2'] . ':LINK':
$this->do_add_content($this->xmldata['info']['image']['link'], $data);
break;
case 'WIDTH':
case $this->namespaces['rss1'] . ':WIDTH':
case $this->namespaces['rss2'] . ':WIDTH':
$this->do_add_content($this->xmldata['info']['image']['width'], $data);
break;
case 'HEIGHT':
case $this->namespaces['rss1'] . ':HEIGHT':
case $this->namespaces['rss2'] . ':HEIGHT':
$this->do_add_content($this->xmldata['info']['image']['height'], $data);
break;
}
}
$this->is_first = false;
}
function endHandler($parser, $name) {
$this->tagName = '';
switch ($name) {
case 'ITEM':
case $this->namespaces['rss1'] . ':ITEM':
case $this->namespaces['rss2'] . ':ITEM':
case 'ENTRY':
case $this->namespaces['atom'] . ':ENTRY':
$this->insideItem = false;
$this->itemNumber++;
$this->authorNumber = 0;
$this->categoryNumber = 0;
$this->enclosureNumber = 0;
$this->itemLinkNumber = 0;
break;
case 'CHANNEL':
case $this->namespaces['rss1'] . ':CHANNEL':
case $this->namespaces['rss2'] . ':CHANNEL':
$this->insideChannel = false;
break;
case 'IMAGE':
case $this->namespaces['rss1'] . ':IMAGE':
case $this->namespaces['rss2'] . ':IMAGE':
if ($this->insideChannel) $this->insideImage = false;
break;
case 'AUTHOR':
case $this->namespaces['rss1'] . ':AUTHOR':
case $this->namespaces['rss2'] . ':AUTHOR':
case $this->namespaces['atom'] . ':AUTHOR':
$this->authorNumber++;
if ($this->xmldata['feedinfo']['type'] == 'Atom') $this->insideAuthor = false;
break;
case 'CATEGORY':
case $this->namespaces['rss1'] . ':CATEGORY':
case $this->namespaces['rss2'] . ':CATEGORY':
case $this->namespaces['atom'] . ':CATEGORY':
case $this->namespaces['dc'] . ':SUBJECT':
$this->categoryNumber++;
break;
case 'ENCLOSURE':
case $this->namespaces['rss1'] . ':ENCLOSURE':
case $this->namespaces['rss2'] . ':ENCLOSURE':
$this->enclosureNumber++;
break;
case 'LINK':
case $this->namespaces['rss1'] . ':LINK':
case $this->namespaces['rss2'] . ':LINK':
case $this->namespaces['atom'] . ':LINK':
if ($this->insideItem)
$this->itemLinkNumber++;
else
$this->linkNumber++;
break;
}
}
function startNameSpace($parser, $prefix, $uri = null) {
$prefix = strtoupper($prefix);
$uri = strtoupper($uri);
if ($prefix == 'ATOM' || $uri == 'HTTP://WWW.W3.ORG/2005/ATOM' || $uri == 'HTTP://PURL.ORG/ATOM/NS#') {
$this->namespaces['atom'] = $uri;
}
else if ($prefix == 'RSS2' || $uri == 'HTTP://BACKEND.USERLAND.COM/RSS2') {
$this->namespaces['rss2'] = $uri;
}
else if ($prefix == 'RDF' || $uri == 'HTTP://WWW.W3.ORG/1999/02/22-RDF-SYNTAX-NS#') {
$this->namespaces['rdf'] = $uri;
}
else if ($prefix == 'RSS' || $uri == 'HTTP://PURL.ORG/RSS/1.0/') {
$this->namespaces['rss1'] = $uri;
}
else if ($prefix == 'DC' || $uri == 'HTTP://PURL.ORG/DC/ELEMENTS/1.1/') {
$this->namespaces['dc'] = $uri;
}
else if ($prefix == 'XHTML' || $uri == 'HTTP://WWW.W3.ORG/1999/XHTML') {
$this->namespaces['xhtml'] = $uri;
$this->xhtml_prefix = $prefix;
}
else if ($prefix == 'CONTENT' || $uri == 'HTTP://PURL.ORG/RSS/1.0/MODULES/CONTENT/') {
$this->namespaces['content'] = $uri;
}
}
function endNameSpace($parser, $prefix) {
if ($key = array_search(strtoupper($prefix), $this->namespaces)) {
if ($key == 'atom') {
$this->namespaces['atom'] = 'ATOM';
}
else if ($key == 'rss2') {
$this->namespaces['rss2'] = 'RSS';
}
else if ($key == 'rdf') {
$this->namespaces['rdf'] = 'RDF';
}
else if ($key == 'rss1') {
$this->namespaces['rss1'] = 'RSS';
}
else if ($key == 'dc') {
$this->namespaces['dc'] = 'DC';
}
else if ($key == 'xhtml') {
$this->namespaces['xhtml'] = 'XHTML';
$this->xhtml_prefix = 'XHTML';
}
else if ($key == 'content') {
$this->namespaces['content'] = 'CONTENT';
}
}
}
}
class SimplePie_Item
{
function SimplePie_Item($id, $title, $description, $category, $author, $date, $links, $enclosure) {
$this->id = $id;
$this->title = $title;
$this->description = $description;
$this->category = $category;
$this->author = $author;
$this->date = $date;
$this->links = $links;
$this->enclosure = $enclosure;
}
/****************************************************
PARSE OUT ITEM-RELATED DATA
****************************************************/
// Get the id of the item
function get_id() {
return (empty($this->id)) ? false : $this->id;
}
// Get the title of the item
function get_title() {
return (empty($this->title)) ? false : $this->title;
}
// Get the description of the item
function get_description() {
return (empty($this->description)) ? false : $this->description;
}
// Get the category of the item
function get_category() {
return (empty($this->category)) ? false : $this->category;
}
// Get the author of the item
function get_author($key) {
return (empty($this->author[$key])) ? false : $this->author[$key];
}
// Get the author of the item
function get_authors() {
return (empty($this->author)) ? false : $this->author;
}
// Get the date of the item
// Also, allow users to set the format of how dates are displayed on a webpage.
function get_date($date_format = 'j F Y, g:i a') {
return (empty($this->date)) ? false : date($date_format, $this->date);
}
// Get the Permalink of the item
function get_permalink() {
// If there is a link, take it. Fine.
if (!empty($this->links[0])) {
return $this->links[0];
}
// If there isn't, check for an enclosure, if that exists, give that.
else if ($this->get_enclosure(0)) {
return $this->get_enclosure(0);
}
else return false;
}
// Get all links
function get_links() {
return (empty($this->links)) ? false : $this->links;
}
// Get the enclosure of the item
function get_enclosure($key) {
return (empty($this->enclosure[$key])) ? false : $this->enclosure[$key];
}
// Get the enclosure of the item
function get_enclosures() {
return (empty($this->enclosure)) ? false : $this->enclosure;
}
/****************************************************
"ADD TO" LINKS
Allows people to easily add news postings to social bookmarking sites.
****************************************************/
function add_to_blinklist() {
return "http://www.blinklist.com/index.php?Action=Blink/addblink.php&Description=&Url=" . rawurlencode($this->get_permalink()) . "&Title=" . rawurlencode($this->get_title());
}
function add_to_delicious() {
return "http://del.icio.us/post/?v=3&url=" . rawurlencode($this->get_permalink()) . "&title=" . rawurlencode($this->get_title());
}
function add_to_digg() {
return "http://digg.com/submit?phase=2&URL=" . rawurlencode($this->get_permalink());
}
function add_to_furl() {
return "http://www.furl.net/storeIt.jsp?u=" . rawurlencode($this->get_permalink()) . "&t=" . rawurlencode($this->get_title());
}
function add_to_magnolia() {
return "http://ma.gnolia.com/bookmarklet/add?url=" . rawurlencode($this->get_permalink()) . "&title=" . rawurlencode($this->get_title());
}
function add_to_myweb20() {
return "http://myweb2.search.yahoo.com/myresults/bookmarklet?u=" . rawurlencode($this->get_permalink()) . "&t=" . rawurlencode($this->get_title());
}
function add_to_newsvine() {
return "http://www.newsvine.com/_wine/save?u=" . rawurlencode($this->get_permalink()) . "&h=" . rawurlencode($this->get_title());
}
function add_to_reddit() {
return 'http://reddit.com/submit?url=' . rawurlencode($this->get_permalink()) . "&title=" . rawurlencode($this->get_title());
}
function add_to_spurl() {
return "http://www.spurl.net/spurl.php?v=3&url=" . rawurlencode($this->get_permalink()) . "&title=" . rawurlencode($this->get_title());
}
/****************************************************
SEARCHES
Metadata searches
****************************************************/
function search_technorati() {
return 'http://www.technorati.com/search/' . rawurlencode($this->get_permalink());
}
}
class SimplePie_Author
{
var $name;
var $link;
var $email;
// Constructor, used to input the data
function SimplePie_Author($name, $link, $email) {
$this->name = $name;
$this->link = $link;
$this->email = $email;
}
function get_name() {
return (empty($this->name)) ? false : $this->name;
}
function get_link() {
return (empty($this->link)) ? false : $this->link;
}
function get_email() {
return (empty($this->email)) ? false : $this->email;
}
}
class SimplePie_Enclosure
{
var $link;
var $type;
var $length;
// Constructor, used to input the data
function SimplePie_Enclosure($link, $type, $length) {
$this->link = $link;
$this->type = $type;
$this->length = $length;
}
function get_link() {
return (empty($this->link)) ? false : $this->link;
}
function get_extension() {
if (!empty($this->link)) {
return pathinfo($this->link, PATHINFO_EXTENSION);
} else {
return false;
}
}
function get_type() {
return (empty($this->type)) ? false : $this->type;
}
function get_length() {
return (empty($this->length)) ? false : $this->length;
}
function get_size() {
return (empty($this->length)) ? false : round(($this->length/1048576), 2);
}
function embed($options) {
// Set up defaults
$audio='';
$video='';
$alt='';
$altclass='';
$loop='false';
$width='auto';
$height='auto';
$bgcolor='#ffffff';
$embed='';
// Process options and reassign values as necessary
$options = explode(',', $options);
foreach($options as $option) {
$opt = explode(':', trim($option));
if ($opt[0] == 'audio') $audio=$opt[1];
else if ($opt[0] == 'video') $video=$opt[1];
else if ($opt[0] == 'alt') $alt=$opt[1];
else if ($opt[0] == 'altclass') $altclass=$opt[1];
else if ($opt[0] == 'loop') $loop=$opt[1];
else if ($opt[0] == 'width') $width=$opt[1];
else if ($opt[0] == 'height') $height=$opt[1];
else if ($opt[0] == 'bgcolor') $bgcolor=$opt[1];
}
// Process values for 'auto'
if ($width == 'auto') {
if (stristr($this->type, 'audio/')) $width='100%';
else if (stristr($this->type, 'video/')) $width='320';
else $width='100%';
}
if ($height == 'auto') {
if (stristr($this->type, 'audio/')) $height=0;
else if (stristr($this->type, 'video/')) $height=240;
else $height=256;
}
// Set proper placeholder value
if (stristr($this->type, 'audio/')) $placeholder=$audio;
else if (stristr($this->type, 'video/')) $placeholder=$video;
// Make sure the JS library is included
// (I know it'll be included multiple times, but I can't think of a better way to do this automatically)
$embed.='';
// Odeo Feed MP3's
if (substr(strtolower($this->link), 0, 15) == 'http://odeo.com') {
$embed.='';
}
// QuickTime 7 file types. Need to test with QuickTime 6.
else if ($this->type == 'audio/3gpp' || $this->type == 'audio/3gpp2' || $this->type == 'audio/aac' || $this->type == 'audio/x-aac' || $this->type == 'audio/aiff' || $this->type == 'audio/x-aiff' || $this->type == 'audio/mid' || $this->type == 'audio/midi' || $this->type == 'audio/x-midi' || $this->type == 'audio/mpeg' || $this->type == 'audio/x-mpeg' || $this->type == 'audio/mp3' || $this->type == 'x-audio/mp3' || $this->type == 'audio/mp4' || $this->type == 'audio/m4a' || $this->type == 'audio/x-m4a' || $this->type == 'audio/wav' || $this->type == 'audio/x-wav' || $this->type == 'video/3gpp' || $this->type == 'video/3gpp2' || $this->type == 'video/m4v' || $this->type == 'video/x-m4v' || $this->type == 'video/mp4' || $this->type == 'video/mpeg' || $this->type == 'video/x-mpeg' || $this->type == 'video/quicktime' || $this->type == 'video/sd-video') {
$height+=16;
$embed.='';
}
// Flash
else if ($this->type == 'application/x-shockwave-flash' || $this->type == 'application/futuresplash') {
$embed.='';
}
// Windows Media
else if ($this->type == 'application/asx' || $this->type == 'application/x-mplayer2' || $this->type == 'audio/x-ms-wma' || $this->type == 'audio/x-ms-wax' || $this->type == 'video/x-ms-asf-plugin' || $this->type == 'video/x-ms-asf' || $this->type == 'video/x-ms-wm' || $this->type == 'video/x-ms-wmv' || $this->type == 'video/x-ms-wvx') {
$height+=45;
$embed.='';
}
// Everything else
else $embed.='' . $alt . '';
return $embed;
}
}
?>