Elgg  Version 2.3
ODD.php
Go to the documentation of this file.
1 <?php
9 abstract class ODD {
13  private $attributes = array();
14 
18  private $body;
19 
23  public function __construct() {
24  $this->body = "";
25  }
26 
32  public function getAttributes() {
33  return $this->attributes;
34  }
35 
44  public function setAttribute($key, $value) {
45  $this->attributes[$key] = $value;
46  }
47 
55  public function getAttribute($key) {
56  if (isset($this->attributes[$key])) {
57  return $this->attributes[$key];
58  }
59 
60  return null;
61  }
62 
70  public function setBody($value) {
71  $this->body = $value;
72  }
73 
79  public function getBody() {
80  return $this->body;
81  }
82 
90  public function setPublished($time) {
91  $this->attributes['published'] = date("r", $time);
92  }
93 
99  public function getPublishedAsTime() {
100  return strtotime($this->attributes['published']);
101  }
102 
108  abstract protected function getTagName();
109 
115  public function __toString() {
116  // Construct attributes
117  $attr = "";
118  foreach ($this->attributes as $k => $v) {
119  $attr .= ($v != "") ? "$k=\"$v\" " : "";
120  }
121 
122  $body = $this->getBody();
123  $tag = $this->getTagName();
124 
125  $end = "/>";
126  if ($body != "") {
127  $end = "><![CDATA[$body]]></{$tag}>";
128  }
129 
130  return "<{$tag} $attr" . $end . "\n";
131  }
132 }
getTagName()
For serialisation, implement to return a string name of the tag eg "header" or "metadata".
getBody()
Gets the body of the ODD.
Definition: ODD.php:79
__construct()
Construct an ODD document with initial values.
Definition: ODD.php:23
getPublishedAsTime()
Return the published time as a unix timestamp.
Definition: ODD.php:99
setBody($value)
Sets the body of the ODD.
Definition: ODD.php:70
$value
Definition: longtext.php:42
getAttributes()
Returns an array of attributes.
Definition: ODD.php:32
getAttribute($key)
Returns an attribute.
Definition: ODD.php:55
__toString()
Magic function to generate valid ODD XML for this item.
Definition: ODD.php:115
$key
Definition: summary.php:34
setPublished($time)
Set the published time.
Definition: ODD.php:90
Definition: ODD.php:9
body
Definition: admin.css.php:36
if(!$limit) $attr
Definition: comments.php:22
setAttribute($key, $value)
Sets an attribute.
Definition: ODD.php:44