name) == 'rss') { ShowFeed_RSS($XmlRoot); } else if (strtolower($XmlRoot->name) == 'feed') { ShowFeed_Atom($XmlRoot); } else if (strtolower($XmlRoot->name) == 'rdf:rdf') { ShowFeed_RDF($XmlRoot); } else if (strtolower($XmlRoot->name) == 'smf:xml-feed') { ShowFeed_SMFXMLFEED($XmlRoot, 'http://www.your-smf-forum.tld/', 'Forum title', 'Your SMF...'); } } } // ############################################################################# function ShowFeed_RSS($XmlRoot) { global $Feed_NoTitle; global $Feed_RSS_ShowEnclosure; global $Feed_MaxItems; global $Feed_ShowInfo; global $Feed_ShowDescription; $title = GetFirstChildContentByPath($XmlRoot, 'channel/title'); $link = GetFirstChildContentByPath($XmlRoot, 'channel/link'); $desc = GetFirstChildContentByPath($XmlRoot, 'channel/description'); if (!$title) $title = $Feed_NoTitle; if ($link) { $outTitle = ''.htmlentities($title).''; } else { $outTitle = ''.htmlentities($title).''; } echo '
Powered by RSS Reader (www.gaijin.at)
'; } // ############################################################################# function ShowFeed_Atom($XmlRoot) { global $Feed_NoTitle; global $Feed_RSS_ShowEnclosure; global $Feed_MaxItems; global $Feed_ShowInfo; global $Feed_ShowDescription; $title = GetFirstChildContentByPath($XmlRoot, 'title'); $link = GetFirstChildContentByPath($XmlRoot, 'link'); $desc = GetFirstChildContentByPath($XmlRoot, 'subtitle'); if (!$title) $title = $Feed_NoTitle; if ($link) { $outTitle = ''.htmlentities($title).''; } else { $outTitle = ''.htmlentities($title).''; } echo 'Powered by RSS Reader (www.gaijin.at)
'; } // ############################################################################# function ShowFeed_RDF($XmlRoot) { global $Feed_NoTitle; global $Feed_MaxItems; global $Feed_ShowInfo; global $Feed_ShowDescription; $title = GetFirstChildContentByPath($XmlRoot, "channel/title"); $link = GetFirstChildContentByPath($XmlRoot, "channel/link"); $desc = GetFirstChildContentByPath($XmlRoot, "channel/description"); if (!$title) $title = $Feed_NoTitle; if ($link) { $outTitle = ''.htmlentities($title).''; } else { $outTitle = ''.htmlentities($title).''; } echo 'Powered by RSS Reader (www.gaijin.at)
'; } // ############################################################################# function ShowFeed_SMFXMLFEED($XmlRoot, $link, $title, $desc) { global $Feed_NoTitle; global $Feed_MaxItems; global $Feed_ShowInfo; global $Feed_ShowDescription; if (!$title) $title = $Feed_NoTitle; if ($link) { $outTitle = ''.htmlentities($title).''; } else { $outTitle = ''.htmlentities($title).''; } echo 'Powered by RSS Reader (www.gaijin.at)
'; } // ############################################################################# function GetAttribByName($XmlNode, $sName, $bCase = false) { if (!$bCase) $sName = strtolower($sName); if (!$bCase) $aAttributes = array_change_key_case($XmlNode->attributes, CASE_LOWER); if (isset($aAttributes[$sName])) return $aAttributes[$sName]; else return false; } // ############################################################################# function GetChildrenByPathAndName($XmlRoot, $sPath, $sName, $bCase = false) { $oRes = array(); $oNode = $XmlRoot; if ($sPath != '') { $aPath = GetPath($sPath); foreach ($aPath as $p) { $oNode = GetFirstChildByName($oNode, $p); if (!$oNode) return false; } } foreach ($oNode->children as $c) { if ($bCase) { if (strcmp($c->name, $sName) == 0) $oRes[count($oRes)] = $c; } else { if (strcasecmp($c->name, $sName) == 0) $oRes[count($oRes)] = $c; } } return $oRes; } // ############################################################################# function GetChildrenByPath($XmlRoot, $sPath, $bCase = false) { $aPath = GetPath($sPath); $oNode = $XmlRoot; foreach ($aPath as $p) { $oNode = GetFirstChildByName($oNode, $p, $bCase); if (!$oNode) return false; } return $oNode->children; } // ############################################################################# function GetFirstChildContentByPath($XmlRoot, $sPath, $bCase = false) { $oNode = GetFirstChildByPath($XmlRoot, $sPath, $bCase); if ($oNode) return $oNode->content; else return ''; } // ############################################################################# function GetFirstChildByPath($XmlRoot, $sPath, $bCase = false) { $aPath = GetPath($sPath); $oNode = $XmlRoot; foreach ($aPath as $p) { $oNode = GetFirstChildByName($oNode, $p, $bCase); if (!$oNode) return false; } return $oNode; } // ############################################################################# function GetFirstChildContentByName($oParent, $sName, $bCase = False) { $oNode = GetFirstChildByName($oParent, $sName, $bCase); if ($oNode) return $oNode->content; else return ''; } // ############################################################################# function GetFirstChildByName($oParent, $sName, $bCase = false) { if (count($oParent->children) < 1) return 0; if ($bCase) $sName = strtolower($sName); foreach ($oParent->children as $c) { if ($bCase) { if (strcmp($c->name, $sName) == 0) return $c; } else { if (strcasecmp($c->name, $sName) == 0) return $c; } } return false; } // ############################################################################# function GetPath($sPath, $iMax = 32) { return explode('/', $sPath, $iMax); } // ############################################################################# class XmlElement { var $name; var $attributes; var $content; var $children; }; // ############################################################################# function ParseXmlFile($sFileName) { $handle = @fopen($sFileName, 'rb'); $xml = ''; if (!$handle) return false; while (!feof($handle)) { $xml .= fread($handle, 4096); } fclose($handle); $parser = xml_parser_create(); xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0); xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 1); xml_parser_set_option($parser, XML_OPTION_TARGET_ENCODING, 'iso-8859-1'); xml_parse_into_struct($parser, $xml, $tags); xml_parser_free($parser); $elements = array(); $stack = array(); $iItemCount = 0; foreach ($tags as $tag) { $index = count($elements); if ( ($tag['type'] == 'complete') || ($tag['type'] == 'open') ) { $elements[$index] = new XmlElement; if (isset($tag['tag'])) $elements[$index]->name = $tag['tag']; if (isset($tag['attributes'])) $elements[$index]->attributes = $tag['attributes']; if (isset($tag['value'])) $elements[$index]->content = $tag['value']; if ($tag['type'] == 'open') { $elements[$index]->children = array(); $stack[count($stack)] = &$elements; $elements = &$elements[$index]->children; } } if ($tag['type'] == 'close') { $elements = &$stack[count($stack) - 1]; unset($stack[count($stack) - 1]); } } return $elements[0]; } ?>LONE-SOFT Ügyviteli Tanácsadó Bt.www.lonesoft.hu Email: info@lonesoft.hu |
|
|