10 defined(
'JPATH_PLATFORM') or die();
31 class
JFeed implements ArrayAccess
37 protected $properties = array(
42 'categories' => array(),
43 'contributors' => array()
50 protected $entries = array();
61 public function __get($name)
63 return isset($this->properties[$name]) ? $this->properties[$name] : null;
76 public function __set($name, $value)
79 if ((($name ==
'updatedDate') || ($name ==
'publishedDate')) && !($value instanceof
JDate))
81 $value =
new JDate($value);
85 if (($name ==
'author') && (!($value instanceof
JFeedPerson) || ($value === null)))
87 throw new InvalidArgumentException(
'JFeed "author" must be of type JFeedPerson. ' . gettype($value) .
'given.');
91 if (($name ==
'categories') || ($name ==
'contributors'))
93 throw new InvalidArgumentException(
'Cannot directly set JFeed property "' . $name .
'".');
96 $this->properties[$name] = $value;
109 public function addCategory($name, $uri =
'')
111 $this->properties[
'categories'][$name] = $uri;
128 public function addContributor($name, $email, $uri = null, $type = null)
130 $contributor =
new JFeedPerson($name, $email, $uri, $type);
133 foreach ($this->properties[
'contributors'] as $c)
135 if ($c == $contributor)
142 $this->properties[
'contributors'][] = $contributor;
159 foreach ($this->entries as $e)
168 $this->entries[] = $entry;
184 public function offsetExists($offset)
186 return isset($this->entries[$offset]);
199 public function offsetGet($offset)
201 return $this->entries[$offset];
216 public function offsetSet($offset, $value)
220 throw new InvalidArgumentException(
'Cannot set value of type "' . gettype($value) .
'".');
223 $this->entries[$offset] = $value;
238 public function offsetUnset($offset)
240 unset($this->entries[$offset]);
252 public function removeCategory($name)
254 unset($this->properties[
'categories'][$name]);
271 foreach ($this->properties[
'contributors'] as $k => $c)
273 if ($c == $contributor)
275 unset($this->properties[
'contributors'][$k]);
276 $this->properties[
'contributors'] = array_values($this->properties[
'contributors']);
297 foreach ($this->entries as $k => $e)
301 unset($this->entries[$k]);
302 $this->entries = array_values($this->entries);
323 public function setAuthor($name, $email, $uri = null, $type = null)
325 $author =
new JFeedPerson($name, $email, $uri, $type);
327 $this->properties[
'author'] = $author;