blob: 684ae0946bc5437a62fe2c4417b59fa56c69e9f2 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
|
<?php
/**
* OpenDD over Atom PHP Library.
* Provides Atom wrappers for
*
* @package Elgg
* @subpackage Core
* @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html GNU Public License version 2
* @author Marcus Povey
* @version 0.1
* @copyright Curverider Ltd 2008
* @link http://elgg.org/
*/
include_once("opendd.php");
/**
* A Wrapper Factory which Constructs a wrapper appropriate for drawing
* ODD elements as Atom.
*/
class ODDAtomWrapperFactory extends ODDWrapperFactory
{
function getElementWrapper($element)
{
if ($element instanceof ODDDocument)
return new ODDAtomDocumentWrapper();
if ($element instanceof ODDEntity)
return new ODDAtomEntityWrapper();
if ($element instanceof ODDMetaData)
return new ODDAtomMetaDataWrapper();
if ($element instanceof ODDRelationship)
return new ODDAtomRelationshipWrapper();
throw new DataFormatException("Element could not be wrapped.");
}
}
/**
* Atom document wrapper
*/
class ODDAtomDocumentWrapper extends ODDDocumentWrapper
{
function wrap($element)
{
global $CONFIG;
$wrapped = "";
// Sanity check
if (!($element instanceof ODDDocument))
throw new DataFormatException("Element being wrapped is not an ODDDocument");
// Create a factory
$factory = new ODDAtomWrapperFactory();
// Head
$wrapped .= "<feed>\n";
$wrapped .= "<id>".urlencode(current_page_url())."</id>\n";
$wrapped .= "<updated>".date(DATE_ATOM)."</updated>\n";
$wrapped .= "<author><name>".$_SESSION['user']->name."</name></author>\n";
$wrapped .= "<title>OpenDD-over-Atom feed</title>\n";
// Itterate
foreach ($element as $e)
{
$wrapper = $factory->getElementWrapper($e);
$wrapped .= $wrapper->wrap($e);
}
// Tail
$wrapped .= "</feed>\n";
return $wrapped;
}
}
/**
* Atom entity wrapper
*/
class ODDAtomEntityWrapper extends ODDEntityWrapper
{
function wrap($element)
{
$wrapped = "";
// Sanity check
if (!($element instanceof ODDEntity))
throw new DataFormatException("Element being wrapped is not an ODDEntity");
$wrapped .= "<entry>\n";
$wrapped .= "<id>".$element->getAttribute('uuid')."?view=atom"."</id>\n";
$wrapped .= "<published>".date(DATE_ATOM)."</published>\n";
$wrapped .= "<title>Entity</title>\n";
$wrapped .= "<author><name>".$_SESSION['user']->name."</name></author>\n";
$wrapped .= "<content type=\"text/xml\">\n";
$wrapped .= "$element\n";
$wrapped .= "</content>\n";
$wrapped .= "</entry>\n";
return $wrapped;
}
}
/**
* Atom metadata wrapper
*/
class ODDAtomMetaDataWrapper extends ODDMetaDataWrapper
{
function wrap($element)
{
$wrapped = "";
// Sanity check
if (!($element instanceof ODDMetaData))
throw new DataFormatException("Element being wrapped is not an ODDMetaData");
$wrapped .= "<entry>\n";
$wrapped .= "<id>".$element->getAttribute('uuid')."?view=atom"."</id>\n";
$wrapped .= "<published>".date(DATE_ATOM)."</published>\n";
$wrapped .= "<title>Entity</title>\n";
$wrapped .= "<author><name>".$_SESSION['user']->name."</name></author>\n";
$wrapped .= "<content type=\"text/xml\">\n";
$wrapped .= "$element\n";
$wrapped .= "</content>\n";
$wrapped .= "</entry>\n";
return $wrapped;
}
}
/**
* Atom Relationship wrapper.
*/
class ODDAtomRelationshipWrapper extends ODDRelationshipWrapper
{
function wrap($element)
{
$wrapped = "";
// Sanity check
if (!($element instanceof ODDRelationship))
throw new DataFormatException("Element being wrapped is not an ODDRelationship");
$wrapped .= "<entry>\n";
$wrapped .= "<id></id>\n";
$wrapped .= "<published>".date(DATE_ATOM)."</published>\n";
$wrapped .= "<title>Entity</title>\n";
$wrapped .= "<author><name>".$_SESSION['user']->name."</name></author>\n";
$wrapped .= "<content type=\"text/xml\">\n";
$wrapped .= "$element\n";
$wrapped .= "</content>\n";
$wrapped .= "</entry>\n";
return $wrapped;
}
}
?>
|