本文整理汇总了PHP中Zend_Feed_Abstract类的典型用法代码示例。如果您正苦于以下问题:PHP Zend_Feed_Abstract类的具体用法?PHP Zend_Feed_Abstract怎么用?PHP Zend_Feed_Abstract使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Zend_Feed_Abstract类的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __wakeup
/**
* Override Zend_Feed_Abstract to set up the $_element and $_entries aliases.
*/
public function __wakeup()
{
parent::__wakeup();
// Find the base feed element and create an alias to it.
$this->_element = $this->_element->getElementsByTagName('channel')->item(0);
if (!$this->_element) {
throw new Zend_Feed_Exception('No root <channel> element found, cannot parse feed.');
}
// Find the entries and save a pointer to them for speed and
// simplicity.
$this->_buildEntryCache();
}
示例2: __wakeup
/**
* Override Zend_Feed_Abstract to set up the $_element and $_entries aliases.
*/
public function __wakeup()
{
parent::__wakeup();
// Find the base feed element and create an alias to it.
$element = $this->_element->getElementsByTagName('feed')->item(0);
if (!$element) {
// Try to find a single <entry> instead.
$element = $this->_element->getElementsByTagName($this->_entryElementName)->item(0);
if (!$element) {
throw new Zend_Feed_Exception('No root <feed> or <' . $this->_entryElementName . '> element found, cannot parse feed.');
}
$doc = new DOMDocument($this->_element->version, $this->_element->actualEncoding);
$feed = $doc->appendChild($doc->createElement('feed'));
$feed->appendChild($doc->importNode($element, true));
$element = $feed;
}
$this->_element = $element;
// Find the entries and save a pointer to them for speed and
// simplicity.
$this->_buildEntryCache();
}
示例3: 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;
}
示例4: __get
/**
* Make accessing some individual elements of the channel easier.
*
* Special accessors 'item' and 'items' are provided so that if
* you wish to iterate over an RSS channel's items, you can do so
* using foreach ($channel->items as $item) or foreach
* ($channel->item as $item).
*
* @param string $var The property to access.
* @return mixed
*/
public function __get($var)
{
switch ($var) {
case 'item':
// fall through to the next case
// fall through to the next case
case 'items':
return $this;
default:
return parent::__get($var);
}
}