本文整理汇总了PHP中Zend_Feed_Abstract::getDomDocument方法的典型用法代码示例。如果您正苦于以下问题:PHP Zend_Feed_Abstract::getDomDocument方法的具体用法?PHP Zend_Feed_Abstract::getDomDocument怎么用?PHP Zend_Feed_Abstract::getDomDocument使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend_Feed_Abstract
的用法示例。
在下文中一共展示了Zend_Feed_Abstract::getDomDocument方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: detectType
/**
* Detect the feed type of the provided feed
*
* @param Zend_Feed_Abstract|DOMDocument|string $feed
* @return string
*/
public static function detectType($feed, $specOnly = false)
{
if ($feed instanceof Zend_Feed_Reader_FeedInterface) {
$dom = $feed->getDomDocument();
} elseif ($feed instanceof DOMDocument) {
$dom = $feed;
} elseif (is_string($feed) && !empty($feed)) {
@ini_set('track_errors', 1);
$dom = new DOMDocument();
$status = @$dom->loadXML($feed);
@ini_restore('track_errors');
if (!$status) {
if (!isset($php_errormsg)) {
if (function_exists('xdebug_is_enabled')) {
$php_errormsg = '(error message not available, when XDebug is running)';
} else {
$php_errormsg = '(error message not available)';
}
}
require_once 'Zend/Feed/Exception.php';
throw new Zend_Feed_Exception("DOMDocument cannot parse XML: {$php_errormsg}");
}
} else {
require_once 'Zend/Feed/Exception.php';
throw new Zend_Feed_Exception('Invalid object/scalar provided: must' . ' be of type Zend_Feed_Reader_FeedInterface, DomDocument or string');
}
$xpath = new DOMXPath($dom);
if ($xpath->query('/rss')->length) {
$type = self::TYPE_RSS_ANY;
$version = $xpath->evaluate('string(/rss/@version)');
if (strlen($version) > 0) {
switch ($version) {
case '2.0':
$type = self::TYPE_RSS_20;
break;
case '0.94':
$type = self::TYPE_RSS_094;
break;
case '0.93':
$type = self::TYPE_RSS_093;
break;
case '0.92':
$type = self::TYPE_RSS_092;
break;
case '0.91':
$type = self::TYPE_RSS_091;
break;
}
}
return $type;
}
$xpath->registerNamespace('rdf', self::NAMESPACE_RDF);
if ($xpath->query('/rdf:RDF')->length) {
$xpath->registerNamespace('rss', self::NAMESPACE_RSS_10);
if ($xpath->query('/rdf:RDF/rss:channel')->length || $xpath->query('/rdf:RDF/rss:image')->length || $xpath->query('/rdf:RDF/rss:item')->length || $xpath->query('/rdf:RDF/rss:textinput')->length) {
return self::TYPE_RSS_10;
}
$xpath->registerNamespace('rss', self::NAMESPACE_RSS_090);
if ($xpath->query('/rdf:RDF/rss:channel')->length || $xpath->query('/rdf:RDF/rss:image')->length || $xpath->query('/rdf:RDF/rss:item')->length || $xpath->query('/rdf:RDF/rss:textinput')->length) {
return self::TYPE_RSS_090;
}
}
$type = self::TYPE_ATOM_ANY;
$xpath->registerNamespace('atom', self::NAMESPACE_ATOM_10);
if ($xpath->query('//atom:feed')->length) {
return self::TYPE_ATOM_10;
}
if ($xpath->query('//atom:entry')->length) {
if ($specOnly == true) {
return self::TYPE_ATOM_10;
} else {
return self::TYPE_ATOM_10_ENTRY;
}
}
$xpath->registerNamespace('atom', self::NAMESPACE_ATOM_03);
if ($xpath->query('//atom:feed')->length) {
return self::TYPE_ATOM_03;
}
return self::TYPE_ANY;
}