Skip to content

Commit

Permalink
Add support for multiple categories in Atom1.0, fixes #7
Browse files Browse the repository at this point in the history
  • Loading branch information
flack committed Oct 3, 2018
1 parent d59c638 commit cc22b97
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
14 changes: 8 additions & 6 deletions lib/Creator/AtomCreator10.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,14 +102,16 @@ public function createFeed()
$feed .= " </author>\n";
}

if ($this->items[$i]->category != "") {
$feed .= " <category ";
if (!empty($this->items[$i]->category)) {
foreach ((array) $this->items[$i]->category as $category) {
$feed .= " <category ";

if ($this->items[$i]->categoryScheme != "") {
$feed .= " scheme=\"".htmlspecialchars($this->items[$i]->categoryScheme)."\" ";
}
if ($this->items[$i]->categoryScheme != "") {
$feed .= " scheme=\"".htmlspecialchars($this->items[$i]->categoryScheme)."\" ";
}

$feed .= " term=\"".htmlspecialchars($this->items[$i]->category)."\" />\n";
$feed .= " term=\"".htmlspecialchars($category)."\" />\n";
}
}

if ($this->items[$i]->description != "") {
Expand Down
5 changes: 5 additions & 0 deletions test/Creator/AtomCreator10Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ public function test_create_empty_feed()
{
$creator = new UniversalFeedCreator;
$creator->description = 'Feed Description';
$item = new FeedItem();
$item->date = time();
$item->category = array('1', '2');
$creator->addItem($item);

$feed = $creator->createFeed('ATOM1.0');

$parsed = simplexml_load_string($feed);
Expand Down

0 comments on commit cc22b97

Please sign in to comment.