ComradeOPML
Comrade need help with OPML, da? We read and write OPML data together no problem. It to spec & simple too, with PHP., (*1)
, (*2)
Copyright (C) 2014 Brandon Fenning, (*3)
Requirements
Compatible with PHP 5.3+, (*4)
Installation
Add innoscience/comrade-opml to the composer.json file:, (*5)
"require": {
"innoscience/comrade-opml": "dev-master"
}
After this, run composer update, (*6)
ComradeOPML is namespaced to Innoscience\ComradeOPML, use this in the top of any files that require it:, (*7)
use Innoscience\ComradeOPML\ComradeOPML;
Usage
Importing & Reading an OPML File
$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>';
}
}
Creating & Exporting an OPML File
$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');
Manipulating OPML Data
$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');
Classes & Methods
Innoscience\ComradeOPML\ComradeOPML
The ComradeOPML class is just a super-helpful factory class for ComradeOPML components., (*8)
Comrade::importString($string) : Import an OPML file in string format, returns a Document, (*9)
Comrade::importFile($filePath) : Import an OPML file directly, returns a Document, (*10)
Comrade::newDocument() : Creates a new Document instance. It's also a fancy way to write new \Innoscience\ComradeOPML\Resource\Document;, (*11)
Comrade::exportFile(Document $document, $filePath) : Exports a Document to an OPML file, (*12)
Innoscience\ComradeOPML\Resource\Document
The Innoscience\ComradeOPML\Resource\Document class, (we call it Document amongst friends) is where much of the magic happens., (*13)
$document->addCategory($category, $title = '') : Add a category, returns the created Category instance. The required $category argument is the text attribute, the $title is the title attribute., (*14)
$document->getCategory($category) : Get a category by its text attribute, returns the created Category instance., (*15)
$document->getAllCategories() : Get all categories, returns an array of Category instances., (*16)
$document->removeCategory() : Remove a category & its feeds by its text attribute. Returns the Document instance., (*17)
$document->addFeed($category, $text, $xmlUrl, $title = '', $htmlUrl = '', $type = 'rss') : Adds a feed to the given category. Returns Document instance., (*18)
$document->parse($xmlString) : Parses OPML data into the Document instance, appending to the document if it has existing data. Returns the Document instance., (*19)
$document->setDomInstance($instance) : Pass an alternative instance of DOMDocument for exporting., (*20)
$document->output() : Returns the OPML formatted document., (*21)
echo $document : Same as above, returns the OPML formatted document., (*22)
$document->setTitle($string) : Sets the Document title property in head, (*23)
$document->getTitle() : Gets the Document title property in head, (*24)
$document->setDateCreated($string) : Sets the Document dateCreated property in head, (*25)
$document->getDateCreated() : Gets the Document dateCreated property in head, (*26)
$document->setDateModified($string) : Sets the Document dateModified property in head, (*27)
$document->getDateModified() : Gets the Document dateModified property in head, (*28)
$document->setOwnerName($string) : Sets the Document ownerName property in head, (*29)
$document->getOwnerName() : Gets the Document ownerName property in head, (*30)
$document->setOwnerEmail($string) : Sets the Document ownerEmail property in head, (*31)
$document->setOwnerEmail() : Gets the Document ownerEmail property in head, (*32)
$document->setExpansionState($string) : Sets the Document expansionState property in head, (*33)
$document->getExpansionState() : Gets the Document expansionState property in head, (*34)
$document->setVertScrollState($string) : Sets the Document vertScrollState property in head, (*35)
$document->getVertScrollState() : Gets the Document vertScrollState property in head, (*36)
$document->setWindowTop($string) : Sets the Document windowTop property in head, (*37)
$document->getWindowTop() : Gets the Document windowTop property in head, (*38)
$document->setWindowLeft($string) : Sets the Document windowLeft property in head, (*39)
$document->getWindowLeft() : Gets the Document windowLeft property in head, (*40)
$document->setWindowBottom($string) : Sets the Document windowBottom property in head, (*41)
$document->getWindowBottom() : Gets the Document windowBottom property in head, (*42)
$document->setWindowRight($string) : Sets the Document windowRight property in head, (*43)
$document->getWindowRight() : Gets the Document windowRight property in head, (*44)
Innoscience\ComradeOPML\Resource\Category
$category->addFeed($text, $xmlUrl, $title = '', $htmlUrl = '', $type = 'rss') : Add a Feed to the Category, returns the Category instance., (*45)
$category->getFeed($xmlUrl) : Returns a Feed instance for the given feed., (*46)
$category->getAllFeeds() : Returns an array of Feed instances for the given Category, (*47)
$category->removeFeed($xmlurl) : Removes the given feed from the Category, (*48)
$category->setText($string) : Sets the Category text property, which is required. Returns the Category instance., (*49)
$category->getText() : Gets the Category text property., (*50)
$category->setTitle($string) : Sets the Category title property. Returns the Category instance., (*51)
$category->getTitle() : Gets the Category title property., (*52)
Innoscience\ComradeOPML\Resource\Feed
$feed->getCategory() : Returns the feed's Category text property, (*53)
$feed->getText() : Returns the Feed text property, (*54)
$feed->setText($string) : Sets the Feed text property, (*55)
$feed->getXmlUrl() : Returns the Feed xmlUrl property, (*56)
$feed->setXmlUrl($string) : Sets the Feed xmlUrl property, (*57)
$feed->getTitle() : Returns the Feed title property, (*58)
$feed->setTitle($string) : Sets the Feed title property, (*59)
$feed->getHtmlUrl() : Returns the Feed htmlUrl property, (*60)
$feed->setHtmlUrl($string) : Sets the Feed htmlUrl property, (*61)
$feed->getType() : Returns the Feed type property, (*62)
$feed->setType($string) : Sets the Feed type property, (*63)
Tests
ComradeOPML is fully unit tested. Tests are located in the tests directory of the ComradeOPML package and can be run with phpunit in the package's base directory., (*64)
License
ComradeOPML is licensed under GPLv2, (*65)