123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187 |
- <?php
- namespace Cube\Feed;
- abstract class AbstractFeed
- {
-
- protected $_entries = array();
-
- protected $_channels = array();
-
- public function setEntries($entries)
- {
- foreach ((array)$entries as $entry) {
- $this->addEntry($entry);
- }
- return $this;
- }
-
- public function addEntry(Entry $entry)
- {
- $this->_entries[] = $entry;
- return $this;
- }
-
- public function getEntries()
- {
- return $this->_entries;
- }
-
- public function clearEntries()
- {
- $this->_entries = array();
- return $this;
- }
-
- public function setChannels($channels)
- {
- foreach ((array)$channels as $key => $value) {
- $this->addChannel($key, $value);
- }
- return $this;
- }
-
- public function addChannel($key, $value)
- {
- $this->_channels[$key] = $this->_formatString($value);
- return $this;
- }
-
- public function getChannels()
- {
- return $this->_channels;
- }
-
- protected function _renderArray($array)
- {
- $output = '';
- foreach ($array as $key => $value) {
- if (is_array($value)) {
- $output .= PHP_EOL . "<$key>" . $this->_renderArray($value) . "</$key>" . PHP_EOL;
- }
- else {
- $output .= PHP_EOL . "<$key>" . $this->_formatString($value) . "</$key>" . PHP_EOL;
- }
- }
- return $output;
- }
-
- protected function _formatString($input)
- {
- if (is_array($input)) {
- return $input;
- }
- return strip_tags(
- str_ireplace(
- array('&'), array(' '), $input));
- }
-
- abstract function generateFeed();
- }
|