innoscience / comrade-opml
Comrade 需要帮助处理 OPML,是吗?我们可以一起读写 OPML 数据,没问题。用 PHP 实现既符合规范又简单。
Requires
- php: >=5.3.0
This package is not auto-updated.
Last update: 2024-09-28 16:02:38 UTC
README
Comrade 需要帮助处理 OPML,是吗?我们可以一起读写 OPML 数据,没问题。用 PHP 实现既符合规范又简单。
版权 (C) 2014 Brandon Fenning
需求
兼容 PHP 5.3+
安装
将 innoscience/comrade-opml
添加到 composer.json
文件中
"require": {
"innoscience/comrade-opml": "dev-master"
}
之后,运行 composer update
ComradeOPML 命名空间为 Innoscience\ComradeOPML
,在需要它的任何文件顶部使用这个
use Innoscience\ComradeOPML\ComradeOPML;
使用方法
导入和读取 OPML 文件
$document = ComradeOPML::importFile('file.opml');
foreach ($document->getAllCategories() as $category) {
echo '<h2>'.$category->getText().'</h2>';
foreach ($category->getAllFeeds() as $feed) {
echo $feed->getText().' - '.$feed->getXmlUrl().'</br>';
}
}
创建和导出 OPML 文件
$document = ComradeOPML::newDocument();
$document->addCategory('News')
->addFeed('Awesome News', 'http//awesome.news/rss')
->addFeed('Good Times', 'http//good.times/rss')
->addFeed('Best News', 'http//best.news/rss');
$document->addFeed('Food', 'Recipe Site', 'http://recipe.site/rss');
$document->addFeed('Food', 'Succulent Soups', 'http://succulent.soups/rss');
echo $document;
// # Or write to a file
ComradeOPML::exportFile($document, __DIR__.'/data/new.opml');
操作 OPML 数据
$document = ComradeOPML::newDocument();
$document->addCategory('Superfluous')
->addFeed('Useless Things', 'http//uselesss.things/rss');
$document->addCategory('News')
->addFeed('Horrible News', 'http//horribe.news/rss')
->addFeed('Good Times', 'http//good.times/rss');
$document->removeCategory('Superfluous');
$document->getCategory('News')->removeFeed('http//horribe.news/rss');
类和方法
Innoscience\ComradeOPML\ComradeOPML
ComradeOPML
类是一个超级有用的 ComradeOPML 组件的工厂类。
Comrade::importString($string)
: 以字符串格式导入 OPML 文件,返回一个 Document
Comrade::importFile($filePath)
: 直接导入 OPML 文件,返回一个 Document
Comrade::newDocument()
: 创建一个新的 Document
实例。这也是一种写 new \Innoscience\ComradeOPML\Resource\Document
的花哨方式;
Comrade::exportFile(Document $document, $filePath)
: 将 Document
导出为 OPML 文件
Innoscience\ComradeOPML\Resource\Document
Innoscience\ComradeOPML\Resource\Document
类(我们称之为 Document
)是许多魔法发生的地方。
$document->addCategory($category, $title = '')
: 添加一个类别,返回创建的 Category
实例。必需的 $category
参数是 text
属性,$title
是 title
属性。
$document->getCategory($category)
: 通过 text
属性获取一个类别,返回创建的 Category
实例。
$document->getAllCategories()
: 获取所有类别,返回一个包含 Category
实例的数组。
$document->removeCategory()
: 通过 text
属性移除一个类别及其订阅源。返回 Document
实例。
$document->addFeed($category, $text, $xmlUrl, $title = '', $htmlUrl = '', $type = 'rss')
: 向给定的类别添加一个订阅源。返回 Document
实例。
$document->parse($xmlString)
: 将 OPML 数据解析到 Document
实例中,如果它有现有数据,则附加到文档中。返回 Document
实例。
$document->setDomInstance($instance)
: 传递一个替代的 DOMDocument
实例以用于导出。
$document->output()
: 返回格式化的 OPML 文档。
echo $document
: 与上面相同,返回格式化的 OPML 文档。
头部属性方法
$document->setTitle($string)
: 设置 Document
在 head
中的 title
属性
$document->getTitle()
: 获取 Document
在 head
中的 title
属性
$document->setDateCreated($string)
: 设置 Document
在 head
中的 dateCreated
属性
$document->getDateCreated()
: 获取 Document
在 head
中的 dateCreated
属性
$document->setDateModified($string)
: 设置 Document
在 head
中的 dateModified
属性
$document->getDateModified()
: 获取 Document
在 head
中的 dateModified
属性
$document->setOwnerName($string)
: 设置 Document
在 head
中的 ownerName
属性
$document->getOwnerName()
: 获取 Document
在 head
中的 ownerName
属性
$document->setOwnerEmail($string)
: 设置 Document
在 head
中的 ownerEmail
属性
$document->setOwnerEmail()
: 获取 Document
在 head
中的 ownerEmail
属性。
$document->setExpansionState($string)
: 设置 Document
在 head
中的 expansionState
属性。
$document->getExpansionState()
: 获取 Document
在 head
中的 expansionState
属性。
$document->setVertScrollState($string)
: 设置 Document
在 head
中的 vertScrollState
属性。
$document->getVertScrollState()
: 获取 Document
在 head
中的 vertScrollState
属性。
$document->setWindowTop($string)
: 设置 Document
在 head
中的 windowTop
属性。
$document->getWindowTop()
: 获取 Document
在 head
中的 windowTop
属性。
$document->setWindowLeft($string)
: 设置 Document
在 head
中的 windowLeft
属性。
$document->getWindowLeft()
: 获取 Document
在 head
中的 windowLeft
属性。
$document->setWindowBottom($string)
: 设置 Document
在 head
中的 windowBottom
属性。
$document->getWindowBottom()
: 获取 Document
在 head
中的 windowBottom
属性。
$document->setWindowRight($string)
: 设置 Document
在 head
中的 windowRight
属性。
$document->getWindowRight()
: 获取 Document
在 head
中的 windowRight
属性。
Innoscience\ComradeOPML\Resource\Category
$category->addFeed($text, $xmlUrl, $title = '', $htmlUrl = '', $type = 'rss')
: 向 Category
添加 Feed
,返回 Category
实例。
$category->getFeed($xmlUrl)
: 返回给定 feed 的 Feed
实例。
$category->getAllFeeds()
: 返回给定 Category
的 Feed
实例数组。
$category->removeFeed($xmlurl)
: 从 Category
中移除给定的 feed。
$category->setText($string)
: 设置 Category
的 text
属性,这是必需的。返回 Category
实例。
$category->getText()
: 获取 Category
的 text
属性。
$category->setTitle($string)
: 设置 Category
的 title
属性。返回 Category
实例。
$category->getTitle()
: 获取 Category
的 title
属性。
Innoscience\ComradeOPML\Resource\Feed
$feed->getCategory()
: 返回 feed 的 Category
text
属性。
$feed->getText()
: 返回 Feed
的 text
属性。
$feed->setText($string)
: 设置 Feed
的 text
属性。
$feed->getXmlUrl()
: 返回 Feed
的 xmlUrl
属性。
$feed->setXmlUrl($string)
: 设置 Feed
的 xmlUrl
属性。
$feed->getTitle()
: 返回 Feed
的 title
属性。
$feed->setTitle($string)
: 设置 Feed
的 title
属性。
$feed->getHtmlUrl()
: 返回 Feed
的 htmlUrl
属性。
$feed->setHtmlUrl($string)
: 设置 Feed
的 htmlUrl
属性。
$feed->getType()
: 返回 Feed
的 type
属性。
$feed->setType($string)
: 设置 Feed
的 type
属性。
测试
ComradeOPML 完全经过单元测试。测试位于 ComradeOPML 包的 tests
目录中,可以在包的基本目录中使用 phpunit
运行。
许可证
ComradeOPML 根据 GPLv2 许可。