|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* SIOC Exporter API. |
|
4
|
|
|
* |
|
5
|
|
|
* Allow people to easilly create their own SIOC Exporter for any PHP application |
|
6
|
|
|
* |
|
7
|
|
|
* @package sioc_inc |
|
8
|
|
|
* @author Alexandre Passant <[email protected]> |
|
9
|
|
|
* @author Uldis Bojars <[email protected]> (adaptation to PHP4) |
|
10
|
|
|
* @author Thomas Schandl <[email protected]> (addition of SIOCThread) |
|
11
|
|
|
* @author Fabrizio Orlandi <[email protected]> (addition of SIOCWIki SIOCWikiArticle SIOCCategory) |
|
12
|
|
|
* |
|
13
|
|
|
* @phpcs:disable PSR1.Classes.ClassDeclaration.MultipleClasses |
|
14
|
|
|
*/ |
|
15
|
|
|
|
|
16
|
|
|
define('AUTHORS_NODE', 'authors'); |
|
17
|
|
|
define('EXPORTER_URL', 'http://wiki.sioc-project.org/index.php/PHPExportAPI'); |
|
18
|
|
|
define('EXPORTER_VERSION', '1.01'); |
|
19
|
|
|
|
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* Main exporter class. |
|
23
|
|
|
* |
|
24
|
|
|
* Generates RDF/XML content of SIOC export. |
|
25
|
|
|
* - Sets up parameters for generating RDF/XML |
|
26
|
|
|
* - Sets up parameters for SIOC URL generation |
|
27
|
|
|
*/ |
|
28
|
|
|
class SIOCExporter { |
|
29
|
|
|
|
|
30
|
|
|
public $profile_url; |
|
31
|
|
|
private $title; |
|
32
|
|
|
private $blog_url; |
|
33
|
|
|
private $sioc_url; |
|
34
|
|
|
private $encoding; |
|
35
|
|
|
private $generator; |
|
36
|
|
|
private $urlseparator; |
|
37
|
|
|
private $urlequal; |
|
38
|
|
|
private $url4type; // e.g. type or sioc_type |
|
39
|
|
|
private $url4id; // TS e. g. id or sioc_id |
|
40
|
|
|
private $url4page; |
|
41
|
|
|
// TS: if true: appends the "type" of a class to the url4id in order to compose the string for the "id part" |
|
42
|
|
|
// of the siocURL. e. g. for a forum that could produce "forum_id=" or "forum_sioc_id=" |
|
43
|
|
|
private $url_usetype; |
|
44
|
|
|
private $url_suffix; // TS: custom parameter to be appended at the end of a siocURL |
|
45
|
|
|
private $type_table; |
|
46
|
|
|
private $ignore_suffix; // TS: for types in this table the url_suffix won't be appended to their siocURL |
|
47
|
|
|
private $export_email; |
|
48
|
|
|
private $objects; |
|
49
|
|
|
|
|
50
|
|
|
public function __construct() { |
|
51
|
|
|
$this->urlseparator = '&'; |
|
52
|
|
|
$this->urlequal = '='; |
|
53
|
|
|
$this->url4type = 'type'; |
|
54
|
|
|
$this->url4id = 'id'; |
|
55
|
|
|
$this->url4page = 'page'; |
|
56
|
|
|
$this->url_usetype = true; |
|
57
|
|
|
$this->url_suffix = ''; |
|
58
|
|
|
$this->type_table = array(); |
|
59
|
|
|
$this->ignore_suffix = array(); |
|
60
|
|
|
$this->export_email = false; |
|
61
|
|
|
$this->encoding = 'UTF-8'; |
|
62
|
|
|
$this->objects = array(); |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
public function setURLParameters( |
|
66
|
|
|
$type = 'type', |
|
67
|
|
|
$id = 'id', |
|
68
|
|
|
$page = 'page', |
|
69
|
|
|
$url_usetype = true, |
|
70
|
|
|
$urlseparator = '&', |
|
71
|
|
|
$urlequal = '=', |
|
72
|
|
|
$suffix = '' |
|
73
|
|
|
) { |
|
74
|
|
|
$this->urlseparator = $urlseparator; |
|
75
|
|
|
$this->urlequal = $urlequal; |
|
76
|
|
|
$this->url4type = $type; |
|
77
|
|
|
$this->url4id = $id; |
|
78
|
|
|
$this->url4page = $page; |
|
79
|
|
|
$this->url_usetype = $url_usetype; |
|
80
|
|
|
$this->url_suffix = $suffix; |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
public function setParameters($title, $url, $sioc_url, $encoding, $generator, $export_email = false) { |
|
84
|
|
|
$this->title = $title; |
|
85
|
|
|
$this->blog_url = $url; |
|
86
|
|
|
$this->sioc_url = $sioc_url; |
|
87
|
|
|
$this->encoding = $encoding; |
|
88
|
|
|
$this->generator = $generator; |
|
89
|
|
|
$this->export_email = $export_email; |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
// Assigns some objects to the exporter |
|
93
|
|
|
public function addObject(&$obj) { |
|
94
|
|
|
$this->objects[] = &$obj; |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
// TS: Used to replace url4id in the siocURL for a given type (site, forum, etc.) with a |
|
98
|
|
|
// parameter ($name) of your choice |
|
99
|
|
|
// E.g. b2evo exporter uses "blog=" instead of "sioc_id=" in the siocURL of a forum |
|
100
|
|
|
public function setURLTypeParm($type, $name) { |
|
101
|
|
|
$this->type_table[$type] = $name; |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
|
|
public function setSuffixIgnore($type) { |
|
105
|
|
|
$this->ignore_suffix[$type] = 1; |
|
106
|
|
|
} |
|
107
|
|
|
|
|
108
|
|
|
public function siocURL($type, $id, $page = "") { |
|
109
|
|
|
$type_part = $this->url4type . $this->urlequal . $type; |
|
110
|
|
|
|
|
111
|
|
|
if($id) { |
|
112
|
|
|
if(isset($this->type_table[$type])) |
|
113
|
|
|
$myID = $this->type_table[$type]; |
|
114
|
|
|
else |
|
115
|
|
|
$myID = (($this->url_usetype) ? $type . '_' : '') . $this->url4id; |
|
116
|
|
|
|
|
117
|
|
|
$id_part = $this->urlseparator . $myID . $this->urlequal . $id; |
|
118
|
|
|
} else { |
|
119
|
|
|
$id_part = ''; |
|
120
|
|
|
} |
|
121
|
|
|
|
|
122
|
|
|
($page) ? $page_part = $this->urlseparator . $this->url4page . $this->urlequal . $page : $page_part = ''; |
|
123
|
|
|
|
|
124
|
|
|
($this->url_suffix && !isset($this->ignore_suffix[$type])) ? $suffix = $this->urlseparator |
|
125
|
|
|
. $this->url_suffix : $suffix = ''; |
|
126
|
|
|
|
|
127
|
|
|
$siocURL = $this->sioc_url . $type_part . $id_part . $page_part . $suffix; |
|
128
|
|
|
return clean($siocURL, true); |
|
129
|
|
|
} |
|
130
|
|
|
|
|
131
|
|
|
public function export($rdf_content = '') { |
|
132
|
|
|
header('Content-Type: application/rdf+xml; charset=' . $this->encoding, true, 200); |
|
133
|
|
|
echo $this->makeRDF($rdf_content); |
|
134
|
|
|
} |
|
135
|
|
|
|
|
136
|
|
|
public function makeRDF($rdf_content = '') { |
|
137
|
|
|
$rdf = '<?xml version="1.0" encoding="' . $this->encoding . '" ?>' . "\n"; |
|
138
|
|
|
$rdf .= ' |
|
139
|
|
|
<rdf:RDF |
|
140
|
|
|
xmlns="http://xmlns.com/foaf/0.1/" |
|
141
|
|
|
xmlns:foaf="http://xmlns.com/foaf/0.1/" |
|
142
|
|
|
xmlns:admin="http://webns.net/mvcb/" |
|
143
|
|
|
xmlns:content="http://purl.org/rss/1.0/modules/content/" |
|
144
|
|
|
xmlns:dc="http://purl.org/dc/elements/1.1/" |
|
145
|
|
|
xmlns:dcterms="http://purl.org/dc/terms/" |
|
146
|
|
|
xmlns:dcmitype="http://purl.org/dc/dcmitype/" |
|
147
|
|
|
xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#" |
|
148
|
|
|
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" |
|
149
|
|
|
xmlns:sioc="http://rdfs.org/sioc/ns#" |
|
150
|
|
|
xmlns:sioct="http://rdfs.org/sioc/types#" |
|
151
|
|
|
xmlns:owl="http://www.w3.org/2002/07/owl"> |
|
152
|
|
|
<foaf:Document rdf:about="' . clean($this->profile_url, true) . '"> |
|
153
|
|
|
<dc:title>"' . clean($this->title) . '" (SIOC profile)</dc:title> |
|
154
|
|
|
<foaf:primaryTopic rdf:resource="' . clean($this->objects[0]->_url, true) . '"/> |
|
155
|
|
|
<admin:generatorAgent rdf:resource="' . clean($this->generator, true) . '"/> |
|
156
|
|
|
<admin:generatorAgent rdf:resource="' . clean(EXPORTER_URL, true) . '?version=' . EXPORTER_VERSION . '"/> |
|
157
|
|
|
</foaf:Document>' . "\n"; |
|
158
|
|
|
if($rdf_content) { |
|
159
|
|
|
$rdf .= $rdf_content; |
|
160
|
|
|
} |
|
161
|
|
|
if(count($this->objects)) { |
|
162
|
|
|
foreach($this->objects as $object) { |
|
163
|
|
|
if($object) { |
|
164
|
|
|
$rdf .= $object->getContent($this); |
|
165
|
|
|
} |
|
166
|
|
|
} |
|
167
|
|
|
} |
|
168
|
|
|
$rdf .= "\n</rdf:RDF>"; |
|
169
|
|
|
return $rdf; |
|
170
|
|
|
} |
|
171
|
|
|
} |
|
172
|
|
|
|
|
173
|
|
|
/** |
|
174
|
|
|
* Generic SIOC Object |
|
175
|
|
|
* |
|
176
|
|
|
* All SIOC objects are derived from this. |
|
177
|
|
|
*/ |
|
178
|
|
|
class SIOCObject { |
|
179
|
|
|
protected $note = ''; |
|
180
|
|
|
|
|
181
|
|
|
public function addNote($note) { |
|
182
|
|
|
$this->note = $note; |
|
183
|
|
|
} |
|
184
|
|
|
|
|
185
|
|
|
public function getContent(&$exp): string { |
|
186
|
|
|
$rdf = "<sioc:Object>\n"; |
|
187
|
|
|
$rdf .= "\t<rdfs:comment>Generic SIOC Object</rdfs:comment>\n"; |
|
188
|
|
|
$rdf .= "</sioc:Object>\n"; |
|
189
|
|
|
return $rdf; |
|
190
|
|
|
} |
|
191
|
|
|
} |
|
192
|
|
|
|
|
193
|
|
|
/** |
|
194
|
|
|
* SIOC::Site object |
|
195
|
|
|
* |
|
196
|
|
|
* Contains information about main SIOC page including: |
|
197
|
|
|
* - site description |
|
198
|
|
|
* - list of forums |
|
199
|
|
|
* - list of users |
|
200
|
|
|
*/ |
|
201
|
|
|
class SIOCSite extends SIOCObject { |
|
202
|
|
|
|
|
203
|
|
|
private $type = 'site'; |
|
204
|
|
|
|
|
205
|
|
|
private $url; |
|
206
|
|
|
private $name; |
|
207
|
|
|
private $description; |
|
208
|
|
|
private $forums; |
|
209
|
|
|
private $users; |
|
210
|
|
|
private $page; |
|
211
|
|
|
private $next_users; |
|
212
|
|
|
private $next_forums; |
|
213
|
|
|
private $usergroup_uri; |
|
214
|
|
|
|
|
215
|
|
|
public function __construct($url, $name, $description, $page = '', $usergroup_uri = '') { |
|
216
|
|
|
$this->url = $url; |
|
217
|
|
|
$this->name = $name; |
|
218
|
|
|
$this->description = $description; |
|
219
|
|
|
$this->forums = array(); |
|
220
|
|
|
$this->users = array(); |
|
221
|
|
|
$this->page = $page; |
|
222
|
|
|
$this->next_users = false; |
|
223
|
|
|
$this->next_forums = false; |
|
224
|
|
|
$this->usergroup_uri = $usergroup_uri; |
|
225
|
|
|
} |
|
226
|
|
|
|
|
227
|
|
|
public function addForum($id, $url) { |
|
228
|
|
|
$this->forums[$id] = $url; |
|
229
|
|
|
} |
|
230
|
|
|
|
|
231
|
|
|
public function addUser($id, $url) { |
|
232
|
|
|
$this->users[$id] = $url; |
|
233
|
|
|
} |
|
234
|
|
|
|
|
235
|
|
|
public function setNextPageUsers($next) { |
|
236
|
|
|
$this->next_users = $next; |
|
237
|
|
|
} |
|
238
|
|
|
|
|
239
|
|
|
public function setNextPageForums($next) { |
|
240
|
|
|
$this->next_forums = $next; |
|
241
|
|
|
} |
|
242
|
|
|
|
|
243
|
|
|
public function getContent(&$exp): string { |
|
244
|
|
|
$rdf = "<sioc:Site rdf:about=\"" . clean($this->url) . "\">\n"; |
|
245
|
|
|
$rdf .= "\t<dc:title>" . clean($this->name) . "</dc:title>\n"; |
|
246
|
|
|
$rdf .= "\t<dc:description>" . clean($this->description) . "</dc:description>\n"; |
|
247
|
|
|
$rdf .= "\t<sioc:link rdf:resource=\"" . clean($this->url) . "\"/>\n"; |
|
248
|
|
|
if($this->forums) { |
|
|
|
|
|
|
249
|
|
|
foreach($this->forums as $id => $url) { |
|
250
|
|
|
$rdf .= "\t<sioc:host_of rdf:resource=\"" . clean($url) . "\"/>\n"; |
|
251
|
|
|
} |
|
252
|
|
|
} |
|
253
|
|
|
if($this->next_forums) { |
|
254
|
|
|
$rdf .= "\t<rdfs:seeAlso rdf:resource=\"" . $exp->siocURL('site', "", $this->page + 1) . "\"/>\n"; |
|
255
|
|
|
} |
|
256
|
|
|
if($this->usergroup_uri) { |
|
257
|
|
|
$rdf .= "\t<sioc:has_Usergroup rdf:resource=\"" . $this->usergroup_uri . "\"/>\n"; |
|
258
|
|
|
} else { |
|
259
|
|
|
$rdf .= "\t<sioc:has_Usergroup rdf:nodeID=\"" . AUTHORS_NODE . "\"/>\n"; |
|
260
|
|
|
} |
|
261
|
|
|
$rdf .= "</sioc:Site>\n"; |
|
262
|
|
|
// Forums |
|
263
|
|
|
if($this->forums) { |
|
|
|
|
|
|
264
|
|
|
$rdf .= "\n"; |
|
265
|
|
|
foreach($this->forums as $id => $url) { |
|
266
|
|
|
$rdf .= '<sioc:Forum rdf:about="' . clean($url) . "\">\n"; |
|
267
|
|
|
$rdf .= "\t<sioc:link rdf:resource=\"" . clean($url) . "\"/>\n"; |
|
268
|
|
|
$rdf .= "\t<rdfs:seeAlso rdf:resource=\"" . $exp->siocURL('forum', $id) . "\"/>\n"; |
|
269
|
|
|
$rdf .= "</sioc:Forum>\n"; |
|
270
|
|
|
} |
|
271
|
|
|
} |
|
272
|
|
|
// Usergroup |
|
273
|
|
|
if($this->users) { |
|
|
|
|
|
|
274
|
|
|
$rdf .= "\n"; |
|
275
|
|
|
if($this->usergroup_uri) { |
|
276
|
|
|
$rdf .= '<sioc:UserAccountgroup rdf:about="' . $this->usergroup_uri . "\">\n"; |
|
277
|
|
|
} else { |
|
278
|
|
|
$rdf .= '<sioc:UserAccountgroup rdf:nodeID="' . AUTHORS_NODE . "\">\n"; |
|
279
|
|
|
} |
|
280
|
|
|
$rdf .= "\t<sioc:name>Authors for \"" . clean($this->name) . "\"</sioc:name>\n"; |
|
281
|
|
|
foreach($this->users as $id => $url) { |
|
282
|
|
|
$rdf .= "\t<sioc:has_member>\n"; |
|
283
|
|
|
$rdf .= "\t\t<sioc:UserAccount rdf:about=\"" . clean($url) . "\">\n"; |
|
284
|
|
|
$rdf .= "\t\t\t<rdfs:seeAlso rdf:resource=\"" . $exp->siocURL('user', $id) . "\"/>\n"; |
|
285
|
|
|
$rdf .= "\t\t</sioc:UserAccount>\n"; |
|
286
|
|
|
$rdf .= "\t</sioc:has_member>\n"; |
|
287
|
|
|
} |
|
288
|
|
|
if($this->next_users) { |
|
289
|
|
|
$rdf .= "\t<rdfs:seeAlso rdf:resource=\"" . $exp->siocURL('site', "", $this->page + 1) . "\"/>\n"; |
|
290
|
|
|
} |
|
291
|
|
|
$rdf .= "</sioc:UserAccountgroup>\n"; |
|
292
|
|
|
} |
|
293
|
|
|
|
|
294
|
|
|
return $rdf; |
|
295
|
|
|
} |
|
296
|
|
|
} |
|
297
|
|
|
|
|
298
|
|
|
// Export detaille d'un utilisateur |
|
299
|
|
|
|
|
300
|
|
|
/** |
|
301
|
|
|
* SIOC::User object |
|
302
|
|
|
* |
|
303
|
|
|
* Contains user profile information |
|
304
|
|
|
*/ |
|
305
|
|
|
class SIOCUser extends SIOCObject { |
|
306
|
|
|
|
|
307
|
|
|
private $type = 'user'; |
|
308
|
|
|
|
|
309
|
|
|
private $id; |
|
310
|
|
|
private $nick; |
|
311
|
|
|
private $uri; |
|
312
|
|
|
private $name; |
|
313
|
|
|
private $email; |
|
314
|
|
|
private $sha1; |
|
315
|
|
|
private $homepage; |
|
316
|
|
|
private $foaf_uri; |
|
317
|
|
|
private $role; |
|
318
|
|
|
private $sioc_url; |
|
319
|
|
|
private $foaf_url; |
|
320
|
|
|
|
|
321
|
|
|
public function __construct( |
|
322
|
|
|
$id, |
|
323
|
|
|
$uri, |
|
324
|
|
|
$name, |
|
325
|
|
|
$email, |
|
326
|
|
|
$homepage = '', |
|
327
|
|
|
$foaf_uri = '', |
|
328
|
|
|
$role = false, |
|
329
|
|
|
$nick = '', |
|
330
|
|
|
$sioc_url = '', |
|
331
|
|
|
$foaf_url = '' |
|
332
|
|
|
) { |
|
333
|
|
|
$this->id = $id; |
|
334
|
|
|
$this->uri = $uri; |
|
335
|
|
|
$this->name = $name; |
|
336
|
|
|
|
|
337
|
|
|
if(preg_match_all('/^.+@.+\..+$/Ui', $email, $check, PREG_SET_ORDER)) { |
|
338
|
|
|
if(preg_match_all('/^mailto:(.+@.+\..+$)/Ui', $email, $matches, PREG_SET_ORDER)) { |
|
339
|
|
|
$this->email = $email; |
|
340
|
|
|
$this->sha1 = sha1($email); |
|
341
|
|
|
} else { |
|
342
|
|
|
$this->email = "mailto:" . $email; |
|
343
|
|
|
$this->sha1 = sha1("mailto:" . $email); |
|
344
|
|
|
} |
|
345
|
|
|
} |
|
346
|
|
|
$this->homepage = $homepage; |
|
347
|
|
|
$this->foaf_uri = $foaf_uri; |
|
348
|
|
|
$this->_url = $foaf_uri; |
|
|
|
|
|
|
349
|
|
|
$this->role = $role; |
|
350
|
|
|
$this->nick = $nick; |
|
351
|
|
|
$this->foaf_url = $foaf_url; |
|
352
|
|
|
$this->sioc_url = $sioc_url; |
|
353
|
|
|
} |
|
354
|
|
|
|
|
355
|
|
|
public function getContent(&$exp): string { |
|
356
|
|
|
$rdf = "<foaf:Person rdf:about=\"" . clean($this->foaf_uri) . "\">\n"; |
|
357
|
|
|
if($this->name) { |
|
358
|
|
|
$rdf .= "\t<foaf:name>" . $this->name . "</foaf:name>\n"; |
|
359
|
|
|
} |
|
360
|
|
|
if($this->email) { |
|
361
|
|
|
$rdf .= "\t<foaf:mbox_sha1sum>" . $this->sha1 . "</foaf:mbox_sha1sum>\n"; |
|
362
|
|
|
} |
|
363
|
|
|
if($this->foaf_url) { |
|
364
|
|
|
$rdf .= "\t<rdfs:seeAlso rdf:resource=\"" . $this->foaf_url . "\"/>\n"; |
|
365
|
|
|
} |
|
366
|
|
|
$rdf .= "\t<foaf:holdsAccount>\n"; |
|
367
|
|
|
$rdf .= "\t\t<sioc:UserAccount rdf:about=\"" . clean($this->uri) . "\">\n"; |
|
368
|
|
|
if($this->nick) { |
|
369
|
|
|
$rdf .= "\t\t\t<sioc:name>" . $this->nick . "</sioc:name>\n"; |
|
370
|
|
|
} |
|
371
|
|
|
if($this->email) { |
|
372
|
|
|
if($exp->_export_email) { |
|
373
|
|
|
$rdf .= "\t\t\t<sioc:email rdf:resource=\"" . $this->email . "\"/>\n"; |
|
374
|
|
|
} |
|
375
|
|
|
$rdf .= "\t\t\t<sioc:email_sha1>" . $this->sha1 . "</sioc:email_sha1>\n"; |
|
376
|
|
|
} |
|
377
|
|
|
if($this->role) { |
|
378
|
|
|
$rdf .= "\t\t\t<sioc:has_function>\n"; |
|
379
|
|
|
$rdf .= "\t\t\t\t<sioc:Role>\n"; |
|
380
|
|
|
$rdf .= "\t\t\t\t\t<sioc:name>" . $this->role . "</sioc:name>\n"; |
|
381
|
|
|
$rdf .= "\t\t\t\t</sioc:Role>\n"; |
|
382
|
|
|
$rdf .= "\t\t\t</sioc:has_function>\n"; |
|
383
|
|
|
} |
|
384
|
|
|
if($this->sioc_url) { |
|
385
|
|
|
$rdf .= "\t\t\t<rdfs:seeAlso rdf:resource=\"" . $this->sioc_url . "\"/>\n"; |
|
386
|
|
|
} |
|
387
|
|
|
$rdf .= "\t\t</sioc:UserAccount>\n"; |
|
388
|
|
|
$rdf .= "\t</foaf:holdsAccount>\n"; |
|
389
|
|
|
$rdf .= "</foaf:Person>\n"; |
|
390
|
|
|
return $rdf; |
|
391
|
|
|
} |
|
392
|
|
|
} |
|
393
|
|
|
|
|
394
|
|
|
// Export detaille d'un utilisateur |
|
395
|
|
|
|
|
396
|
|
|
/** |
|
397
|
|
|
* SIOC::Thread object |
|
398
|
|
|
* |
|
399
|
|
|
* Contains information about a SIOC Thread in a SIOC Forum |
|
400
|
|
|
* - list of posts in that thread |
|
401
|
|
|
*/ |
|
402
|
|
|
class SIOCThread extends SIOCObject { |
|
403
|
|
|
|
|
404
|
|
|
private $type = 'thread'; |
|
405
|
|
|
private $id; |
|
406
|
|
|
private $url; |
|
407
|
|
|
private $page; |
|
408
|
|
|
private $posts; |
|
409
|
|
|
private $next; |
|
410
|
|
|
private $views; |
|
411
|
|
|
private $tags; |
|
412
|
|
|
private $related; |
|
413
|
|
|
private $title; |
|
414
|
|
|
private $created; |
|
415
|
|
|
private $parents; |
|
416
|
|
|
/** |
|
417
|
|
|
* @var mixed|string |
|
418
|
|
|
*/ |
|
419
|
|
|
private $subject; |
|
420
|
|
|
|
|
421
|
|
|
public function __construct($id, $url, $page, $views = '', $tags = array(), $subject = '', $created = '') { |
|
422
|
|
|
$this->id = $id; |
|
423
|
|
|
$this->url = $url; |
|
424
|
|
|
$this->page = $page; |
|
425
|
|
|
$this->posts = array(); |
|
426
|
|
|
$this->next = false; |
|
427
|
|
|
$this->views = $views; |
|
428
|
|
|
$this->tags = $tags; |
|
429
|
|
|
$this->related = array(); |
|
430
|
|
|
$this->subject = $subject; |
|
431
|
|
|
$this->created = $created; |
|
432
|
|
|
} |
|
433
|
|
|
|
|
434
|
|
|
public function addPost($id, $url, $prev = '', $next = '') { |
|
435
|
|
|
$this->posts[$id] = array("url" => $url, "prev" => $prev, "next" => $next); |
|
436
|
|
|
} |
|
437
|
|
|
|
|
438
|
|
|
// add links to things that are similar to this via sioc:related_to |
|
439
|
|
|
public function addRelated($id, $url) { |
|
440
|
|
|
$this->related[$id] = $url; |
|
441
|
|
|
} |
|
442
|
|
|
|
|
443
|
|
|
public function setNextPage($next) { |
|
444
|
|
|
$this->next = $next; |
|
445
|
|
|
} |
|
446
|
|
|
|
|
447
|
|
|
public function addParentForum($id, $url) { |
|
448
|
|
|
$this->parents[$id] = $url; |
|
449
|
|
|
} |
|
450
|
|
|
|
|
451
|
|
|
public function getContent(&$exp): string { |
|
452
|
|
|
$rdf = '<sioc:Thread rdf:about="' . clean($this->url) . "\">\n"; |
|
453
|
|
|
$rdf .= "\t<sioc:link rdf:resource=\"" . clean($this->url) . "\"/>\n"; |
|
454
|
|
|
if($this->views) $rdf .= "\t<sioc:num_views>" . $this->views . "</sioc:num_views>\n"; |
|
455
|
|
|
if($this->note) $rdf .= "\t<rdfs:comment>" . $this->note . "</rdfs:comment>\n"; |
|
456
|
|
|
if($this->subject) { |
|
457
|
|
|
$rdf .= "\t<dc:title>" . $this->subject . "</dc:title>\n"; |
|
458
|
|
|
} |
|
459
|
|
|
if($this->created) { |
|
460
|
|
|
$rdf .= "\t<dcterms:created>" . $this->created . "</dcterms:created>\n"; |
|
461
|
|
|
} |
|
462
|
|
|
if($this->parents) { |
|
463
|
|
|
foreach($this->parents as $id => $uri) { |
|
464
|
|
|
$rdf .= "\t<sioc:has_parent>\n"; |
|
465
|
|
|
$rdf .= "\t\t<sioc:Forum rdf:about=\"" . clean($uri) . "\">\n"; |
|
466
|
|
|
$rdf .= "\t\t\t<rdfs:seeAlso rdf:resource=\"" . $exp->siocURL('forum', $id) . "\"/>\n"; |
|
467
|
|
|
$rdf .= "\t\t</sioc:Forum>\n"; |
|
468
|
|
|
$rdf .= "\t</sioc:has_parent>\n"; |
|
469
|
|
|
} |
|
470
|
|
|
} |
|
471
|
|
|
// here the tags are just used as keywords for dc:subject |
|
472
|
|
|
if($this->tags) { |
|
473
|
|
|
foreach($this->tags as $id => $tag) { |
|
474
|
|
|
$rdf .= "\t<dc:subject>" . $tag . "</dc:subject>\n"; |
|
475
|
|
|
} |
|
476
|
|
|
} |
|
477
|
|
|
// here the tags are used by creating a tag object with a blank node, with the keyword as moat:name - if you |
|
478
|
|
|
// use this insert prefixes for moat and tags |
|
479
|
|
|
// if ($this->tags) { |
|
480
|
|
|
// $i=1; |
|
481
|
|
|
// foreach ($this->tags as $id => $tag) { |
|
482
|
|
|
// $rdf .= "\t<tags:taggedWithTag>\n"; |
|
483
|
|
|
// $rdf .= "\t\t<moat:tag rdf:nodeID=\"b$i\">\n"; |
|
484
|
|
|
// // actually, the best way is to have 'reference URIs' for tags, e.g. URIs for all the platform |
|
485
|
|
|
// (http://tags.example.org/tag/soccer |
|
486
|
|
|
// $rdf .= "\t\t\t<moat:name>" . $tag . "</moat:name>\n"; |
|
487
|
|
|
// $rdf .= "\t\t</moat:tag>\n"; |
|
488
|
|
|
// $rdf .= "\t</moat:taggedWithTag>\n"; |
|
489
|
|
|
// $i++; |
|
490
|
|
|
// } |
|
491
|
|
|
// } |
|
492
|
|
|
|
|
493
|
|
|
// here the tags are used are used for sioc:topic, each topic needs to have a URI |
|
494
|
|
|
/*if($this->tags) { |
|
495
|
|
|
foreach($this->tags as $url=>$topic) { |
|
496
|
|
|
$rdf .= "\t<sioc:topic rdfs:label=\"$topic\" rdf:resource=\"" . clean($url) ."\"/>\n"; |
|
497
|
|
|
} |
|
498
|
|
|
} |
|
499
|
|
|
*/ |
|
500
|
|
|
if($this->related) { |
|
|
|
|
|
|
501
|
|
|
foreach($this->related as $id => $url) { |
|
502
|
|
|
$rdf .= "\t<sioc:related_to>\n"; |
|
503
|
|
|
$rdf .= "\t\t<sioc:Thread rdf:about=\"" . clean($url) . "\"/>\n"; |
|
504
|
|
|
$rdf .= "\t</sioc:related_to>\n"; // todo - each topic needs to have a URI |
|
505
|
|
|
} |
|
506
|
|
|
} |
|
507
|
|
|
|
|
508
|
|
|
if($this->posts) { |
|
|
|
|
|
|
509
|
|
|
foreach($this->posts as $id => $data) { |
|
510
|
|
|
$rdf .= "\t<sioc:container_of>\n"; |
|
511
|
|
|
$rdf .= "\t\t<sioc:Post rdf:about=\"" . clean($data[url]) . "\">\n"; |
|
|
|
|
|
|
512
|
|
|
$rdf .= "\t\t\t<rdfs:seeAlso rdf:resource=\"" . $exp->siocURL('post', $id) . "\"/>\n"; |
|
513
|
|
|
if($data[prev]) { |
|
|
|
|
|
|
514
|
|
|
$rdf .= "\t\t\t<sioc:previous_by_date rdf:resource=\"" . clean($data[prev]) . "\"/>\n"; |
|
515
|
|
|
} |
|
516
|
|
|
if($data[next]) { |
|
|
|
|
|
|
517
|
|
|
$rdf .= "\t\t\t<sioc:next_by_date rdf:resource=\"" . clean($data[next]) . "\"/>\n"; |
|
518
|
|
|
} |
|
519
|
|
|
$rdf .= "\t\t</sioc:Post>\n"; |
|
520
|
|
|
$rdf .= "\t</sioc:container_of>\n"; |
|
521
|
|
|
} |
|
522
|
|
|
} |
|
523
|
|
|
if($this->next) { |
|
524
|
|
|
$rdf .= "\r<rdfs:seeAlso rdf:resource=\"" . $exp->siocURL('thread', $this->id, $this->page + 1) |
|
525
|
|
|
. "\"/>\n"; |
|
526
|
|
|
} |
|
527
|
|
|
$rdf .= "</sioc:Thread>\n"; |
|
528
|
|
|
return $rdf; |
|
529
|
|
|
} |
|
530
|
|
|
} |
|
531
|
|
|
|
|
532
|
|
|
// Export d'un forum avec une liste de posts -variable (next with seeAlso) |
|
533
|
|
|
|
|
534
|
|
|
/** |
|
535
|
|
|
* SIOC::Forum object |
|
536
|
|
|
* |
|
537
|
|
|
* Contains information about SIOC Forum (blog, ...): |
|
538
|
|
|
* - description of a forum |
|
539
|
|
|
* - list of posts within a forum [partial, paged] |
|
540
|
|
|
*/ |
|
541
|
|
|
class SIOCForum extends SIOCObject { |
|
542
|
|
|
|
|
543
|
|
|
private $type = 'forum'; |
|
544
|
|
|
|
|
545
|
|
|
private $id; |
|
546
|
|
|
private $url; |
|
547
|
|
|
private $page; |
|
548
|
|
|
private $posts; |
|
549
|
|
|
private $next; |
|
550
|
|
|
private $blog_title; |
|
551
|
|
|
private $description; |
|
552
|
|
|
private $threads; |
|
553
|
|
|
private $parents; |
|
554
|
|
|
private $creator; |
|
555
|
|
|
private $administrator; |
|
556
|
|
|
/** |
|
557
|
|
|
* @var array|mixed |
|
558
|
|
|
*/ |
|
559
|
|
|
private $links; |
|
560
|
|
|
|
|
561
|
|
|
public function __construct( |
|
562
|
|
|
$id, |
|
563
|
|
|
$url, |
|
564
|
|
|
$page, |
|
565
|
|
|
$title = '', |
|
566
|
|
|
$descr = '', |
|
567
|
|
|
$type = 'sioc:Forum', |
|
568
|
|
|
$creator = '', |
|
569
|
|
|
$admin = '', |
|
570
|
|
|
$links = array() |
|
571
|
|
|
) { |
|
572
|
|
|
$this->id = $id; |
|
573
|
|
|
$this->url = $url; |
|
574
|
|
|
$this->page = $page; |
|
575
|
|
|
$this->posts = array(); |
|
576
|
|
|
$this->next = false; |
|
577
|
|
|
$this->blog_title = $title; |
|
578
|
|
|
$this->description = $descr; |
|
579
|
|
|
$this->threads = array(); |
|
580
|
|
|
$this->parents = array(); |
|
581
|
|
|
$this->_type = $type; |
|
|
|
|
|
|
582
|
|
|
$this->creator = $creator; |
|
583
|
|
|
$this->administrator = $admin; |
|
584
|
|
|
$this->links = $links; |
|
585
|
|
|
} |
|
586
|
|
|
|
|
587
|
|
|
public function addPost($id, $url) { |
|
588
|
|
|
$this->posts[$id] = $url; |
|
589
|
|
|
} |
|
590
|
|
|
|
|
591
|
|
|
public function addThread($id, $url) { |
|
592
|
|
|
$this->threads[$id] = $url; |
|
593
|
|
|
} |
|
594
|
|
|
|
|
595
|
|
|
public function addParentForum($id, $url) { |
|
596
|
|
|
$this->parents[$id] = $url; |
|
597
|
|
|
} |
|
598
|
|
|
|
|
599
|
|
|
public function setNextPage($next) { |
|
600
|
|
|
$this->next = $next; |
|
601
|
|
|
} |
|
602
|
|
|
|
|
603
|
|
|
public function getContent(&$exp): string { |
|
604
|
|
|
$rdf = '<' . $this->_type . ' rdf:about="' . clean($this->url) . "\">\n"; |
|
605
|
|
|
if($this->_type != 'sioc:Forum') $rdf .= "\t<rdf:type rdf:resource=\"http://rdfs.org/sioc/ns#Forum\" />\n"; |
|
606
|
|
|
$rdf .= "\t<sioc:link rdf:resource=\"" . clean($this->url) . "\"/>\n"; |
|
607
|
|
|
if($this->blog_title) $rdf .= "\t<dc:title>" . $this->blog_title . "</dc:title>\n"; |
|
608
|
|
|
if($this->description) $rdf .= "\t<dc:description>" . $this->description . "</dc:description>\n"; |
|
609
|
|
|
if($this->note) $rdf .= "\t<rdfs:comment>" . $this->note . "</rdfs:comment>\n"; |
|
610
|
|
|
|
|
611
|
|
|
if($this->parents) { |
|
|
|
|
|
|
612
|
|
|
foreach($this->parents as $id => $uri) { |
|
613
|
|
|
$rdf .= "\t<sioc:has_parent>\n"; |
|
614
|
|
|
$rdf .= "\t\t<sioc:Forum rdf:about=\"" . clean($uri) . "\">\n"; |
|
615
|
|
|
$rdf .= "\t\t\t<rdfs:seeAlso rdf:resource=\"" . $exp->siocURL('forum', $id) . "\"/>\n"; |
|
616
|
|
|
$rdf .= "\t\t</sioc:Forum>\n"; |
|
617
|
|
|
$rdf .= "\t</sioc:has_parent>\n"; |
|
618
|
|
|
} |
|
619
|
|
|
} |
|
620
|
|
|
|
|
621
|
|
|
if($this->threads) { |
|
|
|
|
|
|
622
|
|
|
foreach($this->threads as $id => $uri) { |
|
623
|
|
|
$rdf .= "\t<sioc:parent_of>\n"; |
|
624
|
|
|
$rdf .= "\t\t<sioc:Thread rdf:about=\"" . clean($uri) . "\">\n"; |
|
625
|
|
|
$rdf .= "\t\t\t<rdfs:seeAlso rdf:resource=\"" . $exp->siocURL('thread', $id) . "\"/>\n"; |
|
626
|
|
|
$rdf .= "\t\t</sioc:Thread>\n"; |
|
627
|
|
|
$rdf .= "\t</sioc:parent_of>\n"; |
|
628
|
|
|
} |
|
629
|
|
|
} |
|
630
|
|
|
|
|
631
|
|
|
if($this->posts) { |
|
|
|
|
|
|
632
|
|
|
foreach($this->posts as $id => $url) { |
|
633
|
|
|
$rdf .= "\t<sioc:container_of>\n"; |
|
634
|
|
|
$rdf .= "\t\t<sioc:Post rdf:about=\"" . clean($url) . "\">\n"; |
|
635
|
|
|
$rdf .= "\t\t\t<rdfs:seeAlso rdf:resource=\"" . $exp->siocURL('post', $id) . "\"/>\n"; |
|
636
|
|
|
$rdf .= "\t\t</sioc:Post>\n"; |
|
637
|
|
|
$rdf .= "\t</sioc:container_of>\n"; |
|
638
|
|
|
} |
|
639
|
|
|
} |
|
640
|
|
|
|
|
641
|
|
|
if($this->creator) { |
|
642
|
|
|
if($this->creator->_id) { |
|
643
|
|
|
$rdf .= "\t<sioc:has_creator>\n"; |
|
644
|
|
|
$rdf .= "\t\t<sioc:UserAccount rdf:about=\"" . clean($this->creator->_uri) . "\">\n"; |
|
645
|
|
|
if($this->creator->_sioc_url) { |
|
646
|
|
|
$rdf .= "\t\t\t<rdfs:seeAlso rdf:resource=\"" . $this->creator->_sioc_url . "\"/>\n"; |
|
647
|
|
|
} else { |
|
648
|
|
|
$rdf .= "\t\t\t<rdfs:seeAlso rdf:resource=\"" . $exp->siocURL('user', $this->creator->_id) |
|
649
|
|
|
. "\"/>\n"; |
|
650
|
|
|
} |
|
651
|
|
|
$rdf .= "\t\t</sioc:UserAccount>\n"; |
|
652
|
|
|
$rdf .= "\t</sioc:has_creator>\n"; |
|
653
|
|
|
$rdf .= "\t<foaf:maker>\n"; |
|
654
|
|
|
$rdf .= "\t\t<foaf:Person rdf:about=\"" . clean($this->creator->_foaf_uri) . "\">\n"; |
|
655
|
|
|
if($this->creator->_foaf_url) { |
|
656
|
|
|
$rdf .= "\t\t\t<rdfs:seeAlso rdf:resource=\"" . $this->creator->_foaf_url . "\"/>\n"; |
|
657
|
|
|
} else { |
|
658
|
|
|
$rdf .= "\t\t\t<rdfs:seeAlso rdf:resource=\"" . $exp->siocURL('user', $this->creator->_id) |
|
659
|
|
|
. "\"/>\n"; |
|
660
|
|
|
} |
|
661
|
|
|
$rdf .= "\t\t</foaf:Person>\n"; |
|
662
|
|
|
$rdf .= "\t</foaf:maker>\n"; |
|
663
|
|
|
} else { |
|
664
|
|
|
$rdf .= "\t<foaf:maker>\n"; |
|
665
|
|
|
$rdf .= "\t\t<foaf:Person"; |
|
666
|
|
|
if($this->creator->_name) { |
|
667
|
|
|
$rdf .= " foaf:name=\"" . $this->creator->_name . "\""; |
|
668
|
|
|
} |
|
669
|
|
|
if($this->creator->_sha1) { |
|
670
|
|
|
$rdf .= " foaf:mbox_sha1sum=\"" . $this->creator->_sha1 . "\""; |
|
671
|
|
|
} |
|
672
|
|
|
if($this->creator->_name) { |
|
673
|
|
|
$rdf .= ">\n\t\t\t<foaf:homepage rdf:resource=\"" . $this->creator->_homepage |
|
674
|
|
|
. "\"/>\n\t\t</foaf:Person>\n"; |
|
675
|
|
|
} else { |
|
676
|
|
|
$rdf .= "/>\n"; |
|
677
|
|
|
} |
|
678
|
|
|
$rdf .= "\t</foaf:maker>\n"; |
|
679
|
|
|
} |
|
680
|
|
|
} |
|
681
|
|
|
|
|
682
|
|
|
if($this->administrator) { |
|
683
|
|
|
if($this->administrator->_id) { |
|
684
|
|
|
$rdf .= "\t<sioc:has_administrator>\n"; |
|
685
|
|
|
$rdf .= "\t\t<sioc:UserAccount rdf:about=\"" . clean($this->administrator->_uri) . "\">\n"; |
|
686
|
|
|
if($this->administrator->_sioc_url) { |
|
687
|
|
|
$rdf .= "\t\t\t<rdfs:seeAlso rdf:resource=\"" . $this->administrator->_sioc_url . "\"/>\n"; |
|
688
|
|
|
} else $rdf .= "\t\t\t<rdfs:seeAlso rdf:resource=\"" . $exp->siocURL('user', $this->administrator->_id) |
|
689
|
|
|
. "\"/>\n"; |
|
690
|
|
|
$rdf .= "\t\t</sioc:UserAccount>\n"; |
|
691
|
|
|
$rdf .= "\t</sioc:has_administrator>\n"; |
|
692
|
|
|
} |
|
693
|
|
|
} |
|
694
|
|
|
if($this->links) { |
|
695
|
|
|
foreach($this->links as $url => $link) { |
|
696
|
|
|
$rdf .= "\t<sioc:links_to rdfs:label=\"$link\" rdf:resource=\"" . clean($url) . "\"/>\n"; |
|
697
|
|
|
} |
|
698
|
|
|
} |
|
699
|
|
|
|
|
700
|
|
|
if($this->next) { |
|
701
|
|
|
$rdf .= "\r<rdfs:seeAlso rdf:resource=\"" . $exp->siocURL('forum', $this->id, $this->page + 1) . "\"/>\n"; |
|
702
|
|
|
} |
|
703
|
|
|
$rdf .= "</" . $this->_type . ">"; |
|
704
|
|
|
|
|
705
|
|
|
return $rdf; |
|
706
|
|
|
} |
|
707
|
|
|
} |
|
708
|
|
|
|
|
709
|
|
|
/** |
|
710
|
|
|
* SIOC::Post object |
|
711
|
|
|
* |
|
712
|
|
|
* Contains information about a post |
|
713
|
|
|
*/ |
|
714
|
|
|
class SIOCPost extends SIOCObject { |
|
715
|
|
|
|
|
716
|
|
|
private $type = 'post'; |
|
717
|
|
|
|
|
718
|
|
|
private $url; |
|
719
|
|
|
private $subject; |
|
720
|
|
|
private $content; |
|
721
|
|
|
private $encoded; |
|
722
|
|
|
private $creator; |
|
723
|
|
|
private $created; |
|
724
|
|
|
private $updated; |
|
725
|
|
|
private $topics; |
|
726
|
|
|
private $links; |
|
727
|
|
|
private $comments; |
|
728
|
|
|
private $reply_of; |
|
729
|
|
|
private $has_part; |
|
730
|
|
|
|
|
731
|
|
|
public function __construct( |
|
732
|
|
|
$url, |
|
733
|
|
|
$subject, |
|
734
|
|
|
$content, |
|
735
|
|
|
$encoded, |
|
736
|
|
|
$creator, |
|
737
|
|
|
$created, |
|
738
|
|
|
$updated = "", |
|
739
|
|
|
$topics = array(), |
|
740
|
|
|
$links = array(), |
|
741
|
|
|
$type = 'sioc:Post', |
|
742
|
|
|
$has_part = array() |
|
743
|
|
|
) { |
|
744
|
|
|
$this->url = $url; |
|
745
|
|
|
$this->subject = $subject; |
|
746
|
|
|
$this->content = $content; |
|
747
|
|
|
$this->encoded = $encoded; |
|
748
|
|
|
$this->creator = $creator; |
|
749
|
|
|
$this->created = $created; |
|
750
|
|
|
$this->updated = $updated; |
|
751
|
|
|
$this->topics = $topics; |
|
752
|
|
|
$this->links = $links; |
|
753
|
|
|
$this->comments = array(); |
|
754
|
|
|
$this->reply_of = array(); |
|
755
|
|
|
$this->_type = $type; |
|
|
|
|
|
|
756
|
|
|
$this->has_part = $has_part; |
|
757
|
|
|
} |
|
758
|
|
|
|
|
759
|
|
|
public function addComment($id, $url) { |
|
760
|
|
|
$this->comments[$id] = $url; |
|
761
|
|
|
} |
|
762
|
|
|
|
|
763
|
|
|
public function addReplyOf($id, $url) { |
|
764
|
|
|
$this->reply_of[$id] = $url; |
|
765
|
|
|
} |
|
766
|
|
|
|
|
767
|
|
|
public function getContent(&$exp): string { |
|
768
|
|
|
$rdf = '<' . $this->_type . " rdf:about=\"" . clean($this->url) . "\">\n"; |
|
769
|
|
|
if($this->_type != 'sioc:Post') $rdf .= "\t<rdf:type rdf:resource=\"http://rdfs.org/sioc/ns#Post\" />\n"; |
|
770
|
|
|
if($this->subject) { |
|
771
|
|
|
$rdf .= "\t<dc:title>" . $this->subject . "</dc:title>\n"; |
|
772
|
|
|
} |
|
773
|
|
|
if($this->creator) { |
|
774
|
|
|
if($this->creator->_id) { |
|
775
|
|
|
$rdf .= "\t<sioc:has_creator>\n"; |
|
776
|
|
|
$rdf .= "\t\t<sioc:UserAccount rdf:about=\"" . clean($this->creator->_uri) . "\">\n"; |
|
777
|
|
|
if($this->creator->_sioc_url) { |
|
778
|
|
|
$rdf .= "\t\t\t<rdfs:seeAlso rdf:resource=\"" . $this->creator->_sioc_url . "\"/>\n"; |
|
779
|
|
|
} else { |
|
780
|
|
|
$rdf .= "\t\t\t<rdfs:seeAlso rdf:resource=\"" . $exp->siocURL('user', $this->creator->_id) |
|
781
|
|
|
. "\"/>\n"; |
|
782
|
|
|
} |
|
783
|
|
|
$rdf .= "\t\t</sioc:UserAccount>\n"; |
|
784
|
|
|
$rdf .= "\t</sioc:has_creator>\n"; |
|
785
|
|
|
$rdf .= "\t<foaf:maker>\n"; |
|
786
|
|
|
$rdf .= "\t\t<foaf:Person rdf:about=\"" . clean($this->creator->_foaf_uri) . "\">\n"; |
|
787
|
|
|
if($this->creator->_foaf_url) { |
|
788
|
|
|
$rdf .= "\t\t\t<rdfs:seeAlso rdf:resource=\"" . $this->creator->_foaf_url . "\"/>\n"; |
|
789
|
|
|
} else { |
|
790
|
|
|
$rdf .= "\t\t\t<rdfs:seeAlso rdf:resource=\"" . $exp->siocURL('user', $this->creator->_id) |
|
791
|
|
|
. "\"/>\n"; |
|
792
|
|
|
} |
|
793
|
|
|
$rdf .= "\t\t</foaf:Person>\n"; |
|
794
|
|
|
$rdf .= "\t</foaf:maker>\n"; |
|
795
|
|
|
} else { |
|
796
|
|
|
$rdf .= "\t<foaf:maker>\n"; |
|
797
|
|
|
$rdf .= "\t\t<foaf:Person"; |
|
798
|
|
|
if($this->creator->_name) { |
|
799
|
|
|
$rdf .= " foaf:name=\"" . $this->creator->_name . "\""; |
|
800
|
|
|
} |
|
801
|
|
|
if($this->creator->_sha1) { |
|
802
|
|
|
$rdf .= " foaf:mbox_sha1sum=\"" . $this->creator->_sha1 . "\""; |
|
803
|
|
|
} |
|
804
|
|
|
if($this->creator->_name) { |
|
805
|
|
|
$rdf .= ">\n\t\t\t<foaf:homepage rdf:resource=\"" . $this->creator->_homepage |
|
806
|
|
|
. "\"/>\n\t\t</foaf:Person>\n"; |
|
807
|
|
|
} else { |
|
808
|
|
|
$rdf .= "/>\n"; |
|
809
|
|
|
} |
|
810
|
|
|
$rdf .= "\t</foaf:maker>\n"; |
|
811
|
|
|
} |
|
812
|
|
|
} |
|
813
|
|
|
$rdf .= "\t<dcterms:created>" . $this->created . "</dcterms:created>\n"; |
|
814
|
|
|
if($this->updated and ($this->created != $this->updated)) $rdf .= "\t<dcterms:modified>" |
|
815
|
|
|
. $this->updated . "</dcterms:modified>\n"; |
|
816
|
|
|
$rdf .= "\t<sioc:content>" . pureContent($this->content) . "</sioc:content>\n"; |
|
817
|
|
|
|
|
818
|
|
|
$rdf .= "\t<content:encoded><![CDATA[" . $this->encoded . "]]></content:encoded>\n"; |
|
819
|
|
|
if($this->topics) { |
|
820
|
|
|
foreach($this->topics as $url => $topic) { |
|
821
|
|
|
$rdf .= "\t<sioc:topic rdfs:label=\"$topic\" rdf:resource=\"" . clean($url) . "\"/>\n"; |
|
822
|
|
|
} |
|
823
|
|
|
} |
|
824
|
|
|
if($this->links) { |
|
825
|
|
|
foreach($this->links as $url => $link) { |
|
826
|
|
|
$rdf .= "\t<sioc:links_to rdfs:label=\"$link\" rdf:resource=\"" . clean($url) . "\"/>\n"; |
|
827
|
|
|
} |
|
828
|
|
|
} |
|
829
|
|
|
if($this->has_part) { |
|
830
|
|
|
foreach($this->has_part as $id => $url) { |
|
831
|
|
|
$rdf .= "\t<dcterms:hasPart>\n"; |
|
832
|
|
|
$rdf .= "\t\t<dcmitype:Image rdf:about=\"" . clean($url) . "\"/>\n"; |
|
833
|
|
|
$rdf .= "\t</dcterms:hasPart>\n"; |
|
834
|
|
|
} |
|
835
|
|
|
} |
|
836
|
|
|
if($this->reply_of) { |
|
|
|
|
|
|
837
|
|
|
foreach($this->reply_of as $id => $url) { |
|
838
|
|
|
$rdf .= "\t<sioc:reply_of>\n"; |
|
839
|
|
|
$rdf .= "\t\t<sioc:Post rdf:about=\"" . clean($url) . "\">\n"; |
|
840
|
|
|
$rdf .= "\t\t\t<rdfs:seeAlso rdf:resource=\"" . $exp->siocURL('post', $id) . "\"/>\n"; |
|
841
|
|
|
$rdf .= "\t\t</sioc:Post>\n"; |
|
842
|
|
|
$rdf .= "\t</sioc:reply_of>\n"; |
|
843
|
|
|
} |
|
844
|
|
|
} |
|
845
|
|
|
if($this->comments) { |
|
|
|
|
|
|
846
|
|
|
foreach($this->comments as $id => $url) { |
|
847
|
|
|
$rdf .= "\t<sioc:has_reply>\n"; |
|
848
|
|
|
$rdf .= "\t\t<sioc:Post rdf:about=\"" . clean($url) . "\">\n"; |
|
849
|
|
|
// if($comments->f('comment_trackback')) $rdf .= "\t\t\t<sioc:type>" |
|
850
|
|
|
// . POST_TRACKBACK . "</sioc:type>\n"; |
|
851
|
|
|
// else $rdf .= "\t\t\t<sioc:type>" . POST_COMMENT . "</sioc:type>\n"; |
|
852
|
|
|
$rdf .= "\t\t\t<rdfs:seeAlso rdf:resource=\"" . $exp->siocURL('comment', $id) . "\"/>\n"; |
|
853
|
|
|
$rdf .= "\t\t</sioc:Post>\n"; |
|
854
|
|
|
$rdf .= "\t</sioc:has_reply>\n"; |
|
855
|
|
|
} |
|
856
|
|
|
} |
|
857
|
|
|
$rdf .= "</" . $this->_type . ">\n"; |
|
858
|
|
|
return $rdf; |
|
859
|
|
|
} |
|
860
|
|
|
} |
|
861
|
|
|
|
|
862
|
|
|
/** |
|
863
|
|
|
* SIOC::WikiArticle object |
|
864
|
|
|
* |
|
865
|
|
|
* Contains information about a wiki article |
|
866
|
|
|
*/ |
|
867
|
|
|
class SIOCWikiArticle extends SIOCObject { |
|
868
|
|
|
|
|
869
|
|
|
private $type = 'sioct:WikiArticle'; |
|
870
|
|
|
|
|
871
|
|
|
private $url; |
|
872
|
|
|
private $api = null; |
|
873
|
|
|
private $subject; |
|
874
|
|
|
private $redirpage; |
|
875
|
|
|
private $creator; |
|
876
|
|
|
private $created; |
|
877
|
|
|
private $topics; |
|
878
|
|
|
private $links; |
|
879
|
|
|
private $ext_links; |
|
880
|
|
|
private $previous_version; |
|
881
|
|
|
private $next_version; |
|
882
|
|
|
private $latest_version; |
|
883
|
|
|
private $has_discussion; |
|
884
|
|
|
private $has_container; |
|
885
|
|
|
|
|
886
|
|
|
public function __construct( |
|
887
|
|
|
$url, |
|
888
|
|
|
$api, |
|
889
|
|
|
$subject, |
|
890
|
|
|
$redir, |
|
891
|
|
|
$user, |
|
892
|
|
|
$created, |
|
893
|
|
|
$prev_vers, |
|
894
|
|
|
$next_vers, |
|
895
|
|
|
$latest_vers, |
|
896
|
|
|
$has_discuss, |
|
897
|
|
|
$container, |
|
898
|
|
|
$topics = array(), |
|
899
|
|
|
$links = array(), |
|
900
|
|
|
$ext_links = array(), |
|
901
|
|
|
$type = 'sioct:WikiArticle' |
|
902
|
|
|
) { |
|
903
|
|
|
$this->url = $url; |
|
904
|
|
|
$this->api = $api; |
|
905
|
|
|
$this->subject = $subject; |
|
906
|
|
|
$this->redirpage = $redir; |
|
907
|
|
|
$this->creator = $user; |
|
908
|
|
|
$this->created = $created; |
|
909
|
|
|
$this->topics = $topics; |
|
910
|
|
|
$this->links = $links; |
|
911
|
|
|
$this->ext_links = $ext_links; |
|
912
|
|
|
$this->_type = $type; |
|
|
|
|
|
|
913
|
|
|
$this->previous_version = $prev_vers; |
|
914
|
|
|
$this->next_version = $next_vers; |
|
915
|
|
|
$this->latest_version = $latest_vers; |
|
916
|
|
|
$this->has_discussion = $has_discuss; |
|
917
|
|
|
$this->has_container = $container; |
|
918
|
|
|
} |
|
919
|
|
|
|
|
920
|
|
|
public function getContent(&$exp): string { |
|
921
|
|
|
$rdf = '<' . $this->_type . " rdf:about=\"" . clean($this->url) . "\">\n"; |
|
922
|
|
|
if($this->subject) { |
|
923
|
|
|
$rdf .= "\t<dc:title>" . clean($this->subject) . "</dc:title>\n"; |
|
924
|
|
|
if(strcmp($this->has_container, 'http://en.wikipedia.org') === 0) { |
|
925
|
|
|
$rdf .= "\t<foaf:primaryTopic rdf:resource=\"" . clean( |
|
926
|
|
|
'http://dbpedia.org/resource/' |
|
927
|
|
|
. $this->subject |
|
928
|
|
|
) . "\"/>\n"; |
|
929
|
|
|
} |
|
930
|
|
|
} |
|
931
|
|
|
if($this->creator->_nick) { |
|
932
|
|
|
/*if ($this->creator->id) { |
|
933
|
|
|
$rdf .= "\t<sioc:has_creator>\n"; |
|
934
|
|
|
$rdf .= "\t\t<sioc:UserAccount rdf:about=\"" . clean($this->creator->uri) ."\">\n"; |
|
935
|
|
|
if($this->creator->sioc_url) { $rdf .= "\t\t\t<rdfs:seeAlso rdf:resource=\"". $this->creator->sioc_url |
|
936
|
|
|
."\"/>\n"; } |
|
937
|
|
|
else $rdf .= "\t\t\t<rdfs:seeAlso rdf:resource=\"" . $exp->siocURL('user', $this->creator->id) |
|
938
|
|
|
. "\"/>\n"; |
|
939
|
|
|
$rdf .= "\t\t</sioc:UserAccount>\n"; |
|
940
|
|
|
$rdf .= "\t</sioc:has_creator>\n"; |
|
941
|
|
|
$rdf .= "\t<foaf:maker>\n"; |
|
942
|
|
|
$rdf .= "\t\t<foaf:Person rdf:about=\"" . clean($this->creator->foaf_uri) ."\">\n"; |
|
943
|
|
|
if($this->creator->foaf_url) { $rdf .= "\t\t\t<rdfs:seeAlso rdf:resource=\"". $this->creator->foaf_url |
|
944
|
|
|
."\"/>\n"; } |
|
945
|
|
|
else $rdf .= "\t\t\t<rdfs:seeAlso rdf:resource=\"" . $exp->siocURL('user', $this->creator->id) |
|
946
|
|
|
. "\"/>\n"; |
|
947
|
|
|
$rdf .= "\t\t</foaf:Person>\n"; |
|
948
|
|
|
$rdf .= "\t</foaf:maker>\n"; |
|
949
|
|
|
} else {*/ |
|
950
|
|
|
$rdf .= "\t<sioc:has_creator>\n"; |
|
951
|
|
|
$rdf .= "\t\t<sioc:UserAccount rdf:about=\"" . clean($this->creator->_uri) . "\">\n"; |
|
952
|
|
|
$rdf .= "\t\t\t<rdfs:seeAlso rdf:resource=\"" . |
|
953
|
|
|
clean('http://ws.sioc-project.org/mediawiki/mediawiki.php?wiki=' . $this->creator->_uri); |
|
954
|
|
|
if($this->api) { |
|
955
|
|
|
$rdf .= clean("&api=" . $this->api); |
|
956
|
|
|
} |
|
957
|
|
|
$rdf .= "\"/>\n"; |
|
958
|
|
|
$rdf .= "\t\t</sioc:UserAccount>\n"; |
|
959
|
|
|
$rdf .= "\t</sioc:has_creator>\n"; |
|
960
|
|
|
$rdf .= "\t<dc:contributor>" . clean($this->creator->_nick) . "</dc:contributor>\n"; |
|
961
|
|
|
/*$rdf .= "\t<foaf:maker>\n"; |
|
962
|
|
|
$rdf .= "\t\t<foaf:Person"; |
|
963
|
|
|
if($this->creator->name) $rdf .= " foaf:name=\"" . $this->creator->name ."\""; |
|
964
|
|
|
if($this->creator->sha1) $rdf .= " foaf:mbox_sha1sum=\"" . $this->creator->sha1 ."\""; |
|
965
|
|
|
if($this->creator->homepage) $rdf .= ">\n\t\t\t<foaf:homepage rdf:resource=\"" |
|
966
|
|
|
. $this->creator->homepage ."\"/>\n\t\t</foaf:Person>\n"; |
|
967
|
|
|
else $rdf .= "/>\n"; |
|
968
|
|
|
$rdf .= "\t</foaf:maker>\n"; |
|
969
|
|
|
}*/ |
|
970
|
|
|
} else { |
|
971
|
|
|
if($this->creator !== 'void') { |
|
972
|
|
|
$rdf .= "\t<sioc:has_creator>\n"; |
|
973
|
|
|
$rdf .= "\t\t<sioc:UserAccount>\n"; |
|
974
|
|
|
$rdf .= "\t\t</sioc:UserAccount>\n"; |
|
975
|
|
|
$rdf .= "\t</sioc:has_creator>\n"; |
|
976
|
|
|
} |
|
977
|
|
|
} |
|
978
|
|
|
if($this->created) { |
|
979
|
|
|
$rdf .= "\t<dcterms:created>" . $this->created . "</dcterms:created>\n"; |
|
980
|
|
|
} |
|
981
|
|
|
if(is_array($this->topics)) { |
|
982
|
|
|
foreach($this->topics as $topic => $url) { |
|
983
|
|
|
$rdf .= "\t<sioc:topic>\n"; |
|
984
|
|
|
$rdf .= "\t\t<sioct:Category rdf:about=\"" . clean($url) . "\">\n"; |
|
985
|
|
|
$rdf .= "\t\t\t<rdfs:seeAlso rdf:resource=\"" . |
|
986
|
|
|
clean('http://ws.sioc-project.org/mediawiki/mediawiki.php?wiki=' . $url); |
|
987
|
|
|
if($this->api) { |
|
988
|
|
|
$rdf .= clean("&api=" . $this->api); |
|
989
|
|
|
} |
|
990
|
|
|
$rdf .= "\"/>\n"; |
|
991
|
|
|
$rdf .= "\t\t</sioct:Category>\n"; |
|
992
|
|
|
$rdf .= "\t</sioc:topic>\n"; |
|
993
|
|
|
} |
|
994
|
|
|
} |
|
995
|
|
|
if(is_array($this->links)) { |
|
996
|
|
|
foreach($this->links as $label => $url) { |
|
997
|
|
|
$rdf .= "\t<sioc:links_to>\n"; |
|
998
|
|
|
$rdf .= "\t\t<sioct:WikiArticle rdf:about=\"" . clean($url) . "\">\n"; |
|
999
|
|
|
$rdf .= "\t\t\t<rdfs:seeAlso rdf:resource=\"" . |
|
1000
|
|
|
clean('http://ws.sioc-project.org/mediawiki/mediawiki.php?wiki=' . $url); |
|
1001
|
|
|
if($this->api) { |
|
1002
|
|
|
$rdf .= clean("&api=" . $this->api); |
|
1003
|
|
|
} |
|
1004
|
|
|
$rdf .= "\"/>\n"; |
|
1005
|
|
|
$rdf .= "\t\t</sioct:WikiArticle>\n"; |
|
1006
|
|
|
$rdf .= "\t</sioc:links_to>\n"; |
|
1007
|
|
|
} |
|
1008
|
|
|
} else { |
|
1009
|
|
|
if($this->links) { |
|
1010
|
|
|
$rdf .= "\t<sioc:links_to>\n"; |
|
1011
|
|
|
$rdf .= "\t\t<sioct:WikiArticle rdf:about=\"" . clean($this->links) . "\">\n"; |
|
1012
|
|
|
$rdf .= "\t\t\t<rdfs:seeAlso rdf:resource=\"" . |
|
1013
|
|
|
clean('http://ws.sioc-project.org/mediawiki/mediawiki.php?wiki=' . $this->links); |
|
1014
|
|
|
if($this->api) { |
|
1015
|
|
|
$rdf .= clean("&api=" . $this->api); |
|
1016
|
|
|
} |
|
1017
|
|
|
$rdf .= "\"/>\n"; |
|
1018
|
|
|
$rdf .= "\t\t</sioct:WikiArticle>\n"; |
|
1019
|
|
|
$rdf .= "\t</sioc:links_to>\n"; |
|
1020
|
|
|
} |
|
1021
|
|
|
} |
|
1022
|
|
|
if(is_array($this->ext_links)) { |
|
1023
|
|
|
foreach($this->ext_links as $label => $url) { |
|
1024
|
|
|
$rdf .= "\t<sioc:links_to rdf:resource=\"" . clean($url) . "\"/>\n"; |
|
1025
|
|
|
} |
|
1026
|
|
|
} |
|
1027
|
|
|
if($this->previous_version) { |
|
1028
|
|
|
$rdf .= "\t<sioc:previous_version>\n"; |
|
1029
|
|
|
$rdf .= "\t\t<sioct:WikiArticle rdf:about=\"" . clean($this->previous_version) . "\">\n"; |
|
1030
|
|
|
$rdf .= "\t\t\t<rdfs:seeAlso rdf:resource=\"" . |
|
1031
|
|
|
clean('http://ws.sioc-project.org/mediawiki/mediawiki.php?wiki=' . $this->previous_version); |
|
1032
|
|
|
if($this->api) { |
|
1033
|
|
|
$rdf .= clean("&api=" . $this->api); |
|
1034
|
|
|
} |
|
1035
|
|
|
$rdf .= "\"/>\n"; |
|
1036
|
|
|
$rdf .= "\t\t</sioct:WikiArticle>\n"; |
|
1037
|
|
|
$rdf .= "\t</sioc:previous_version>\n"; |
|
1038
|
|
|
/*If there is support for inference and transitivity the following is not needed |
|
1039
|
|
|
$rdf .= "\t<sioc:earlier_version>\n"; |
|
1040
|
|
|
$rdf .= "\t\t<sioct:WikiArticle rdf:about=\"" . clean($this->previous_version) ."\">\n"; |
|
1041
|
|
|
$rdf .= "\t\t\t<rdfs:seeAlso rdf:resource=\"" . |
|
1042
|
|
|
clean('http://ws.sioc-project.org/mediawiki/mediawiki.php?wiki='.$this->previous_version); |
|
1043
|
|
|
if ($this->api) { |
|
1044
|
|
|
$rdf .= clean("&api=" . $this->api); |
|
1045
|
|
|
} |
|
1046
|
|
|
$rdf .= "\"/>\n"; |
|
1047
|
|
|
$rdf .= "\t\t</sioct:WikiArticle>\n"; |
|
1048
|
|
|
$rdf .= "\t</sioc:earlier_version>\n"; |
|
1049
|
|
|
*/ |
|
1050
|
|
|
} |
|
1051
|
|
|
if($this->next_version) { |
|
1052
|
|
|
$rdf .= "\t<sioc:next_version>\n"; |
|
1053
|
|
|
$rdf .= "\t\t<sioct:WikiArticle rdf:about=\"" . clean($this->next_version) . "\">\n"; |
|
1054
|
|
|
$rdf .= "\t\t\t<rdfs:seeAlso rdf:resource=\"" . |
|
1055
|
|
|
clean('http://ws.sioc-project.org/mediawiki/mediawiki.php?wiki=' . $this->next_version); |
|
1056
|
|
|
if($this->api) { |
|
1057
|
|
|
$rdf .= clean("&api=" . $this->api); |
|
1058
|
|
|
} |
|
1059
|
|
|
$rdf .= "\"/>\n"; |
|
1060
|
|
|
$rdf .= "\t\t</sioct:WikiArticle>\n"; |
|
1061
|
|
|
$rdf .= "\t</sioc:next_version>\n"; |
|
1062
|
|
|
/*If there is support for inference and transitivity the following is not needed |
|
1063
|
|
|
$rdf .= "\t<sioc:later_version>\n"; |
|
1064
|
|
|
$rdf .= "\t\t<sioct:WikiArticle rdf:about=\"" . clean($this->next_version) ."\">\n"; |
|
1065
|
|
|
$rdf .= "\t\t\t<rdfs:seeAlso rdf:resource=\"" . |
|
1066
|
|
|
clean('http://ws.sioc-project.org/mediawiki/mediawiki.php?wiki='.$this->next_version); |
|
1067
|
|
|
if ($this->api) { |
|
1068
|
|
|
$rdf .= clean("&api=" . $this->api); |
|
1069
|
|
|
} |
|
1070
|
|
|
$rdf .= "\"/>\n"; |
|
1071
|
|
|
$rdf .= "\t\t</sioct:WikiArticle>\n"; |
|
1072
|
|
|
$rdf .= "\t</sioc:later_version>\n"; |
|
1073
|
|
|
*/ |
|
1074
|
|
|
} |
|
1075
|
|
|
if($this->latest_version) { |
|
1076
|
|
|
$rdf .= "\t<sioc:latest_version>\n"; |
|
1077
|
|
|
$rdf .= "\t\t<sioct:WikiArticle rdf:about=\"" . clean($this->latest_version) . "\">\n"; |
|
1078
|
|
|
$rdf .= "\t\t\t<rdfs:seeAlso rdf:resource=\"" . |
|
1079
|
|
|
clean('http://ws.sioc-project.org/mediawiki/mediawiki.php?wiki=' . $this->latest_version); |
|
1080
|
|
|
if($this->api) { |
|
1081
|
|
|
$rdf .= clean("&api=" . $this->api); |
|
1082
|
|
|
} |
|
1083
|
|
|
$rdf .= "\"/>\n"; |
|
1084
|
|
|
$rdf .= "\t\t</sioct:WikiArticle>\n"; |
|
1085
|
|
|
$rdf .= "\t</sioc:latest_version>\n"; |
|
1086
|
|
|
} |
|
1087
|
|
|
if($this->has_discussion && (strpos($this->has_discussion, 'Talk:Talk:') == false)) { |
|
|
|
|
|
|
1088
|
|
|
$rdf .= "\t<sioc:has_discussion>\n"; |
|
1089
|
|
|
$rdf .= "\t\t<sioct:WikiArticle rdf:about=\"" . clean($this->has_discussion) . "\">\n"; |
|
1090
|
|
|
$rdf .= "\t\t\t<rdfs:seeAlso rdf:resource=\"" . |
|
1091
|
|
|
clean('http://ws.sioc-project.org/mediawiki/mediawiki.php?wiki=' . $this->has_discussion); |
|
1092
|
|
|
if($this->api) { |
|
1093
|
|
|
$rdf .= clean("&api=" . $this->api); |
|
1094
|
|
|
} |
|
1095
|
|
|
$rdf .= "\"/>\n"; |
|
1096
|
|
|
$rdf .= "\t\t</sioct:WikiArticle>\n"; |
|
1097
|
|
|
$rdf .= "\t</sioc:has_discussion>\n"; |
|
1098
|
|
|
} |
|
1099
|
|
|
if($this->has_container) { |
|
1100
|
|
|
$rdf .= "\t<sioc:has_container>\n"; |
|
1101
|
|
|
$rdf .= "\t\t<sioct:Wiki rdf:about=\"" . clean($this->has_container) . "\"/>\n"; |
|
1102
|
|
|
$rdf .= "\t</sioc:has_container>\n"; |
|
1103
|
|
|
} |
|
1104
|
|
|
if($this->redirpage) { |
|
1105
|
|
|
$rdf .= "\t<owl:sameAs rdf:resource=\"" . clean($this->redirpage) . "\"/>\n"; |
|
1106
|
|
|
$rdf .= "\t<rdfs:seeAlso rdf:resource=\"" . |
|
1107
|
|
|
clean('http://ws.sioc-project.org/mediawiki/mediawiki.php?wiki=' . $this->redirpage); |
|
1108
|
|
|
if($this->api) { |
|
1109
|
|
|
$rdf .= clean("&api=" . $this->api); |
|
1110
|
|
|
} |
|
1111
|
|
|
$rdf .= "\"/>\n"; |
|
1112
|
|
|
} |
|
1113
|
|
|
|
|
1114
|
|
|
$rdf .= "</" . $this->_type . ">\n"; |
|
1115
|
|
|
return $rdf; |
|
1116
|
|
|
} |
|
1117
|
|
|
} |
|
1118
|
|
|
|
|
1119
|
|
|
/** |
|
1120
|
|
|
* SIOC::Wiki object |
|
1121
|
|
|
* |
|
1122
|
|
|
* Contains information about a wiki site |
|
1123
|
|
|
*/ |
|
1124
|
|
|
class SIOCWiki extends SIOCObject { |
|
1125
|
|
|
|
|
1126
|
|
|
private $url; |
|
1127
|
|
|
private $type; |
|
1128
|
|
|
|
|
1129
|
|
|
public function __construct($url, $type = 'sioct:Wiki') { |
|
1130
|
|
|
$this->url = $url; |
|
1131
|
|
|
$this->type = $type; |
|
1132
|
|
|
} |
|
1133
|
|
|
|
|
1134
|
|
|
public function getContent(&$exp): string { |
|
1135
|
|
|
$rdf = '<' . $this->type . " rdf:about=\"" . clean($this->url) . "\"/>\n"; |
|
1136
|
|
|
return $rdf; |
|
1137
|
|
|
} |
|
1138
|
|
|
} |
|
1139
|
|
|
|
|
1140
|
|
|
/** |
|
1141
|
|
|
* SIOC::Category object |
|
1142
|
|
|
* |
|
1143
|
|
|
* Contains information about the category which is object of the sioc:topic property |
|
1144
|
|
|
*/ |
|
1145
|
|
|
class SIOCCategory extends SIOCObject { |
|
1146
|
|
|
|
|
1147
|
|
|
private $url; |
|
1148
|
|
|
private $type; |
|
1149
|
|
|
|
|
1150
|
|
|
public function __construct($url, $type = 'sioct:Category') { |
|
1151
|
|
|
$this->url = $url; |
|
1152
|
|
|
$this->type = $type; |
|
1153
|
|
|
} |
|
1154
|
|
|
|
|
1155
|
|
|
public function getContent(&$exp): string { |
|
1156
|
|
|
$rdf = '<' . $this->type . " rdf:about=\"" . clean($this->url) . "\"/>\n"; |
|
1157
|
|
|
return $rdf; |
|
1158
|
|
|
} |
|
1159
|
|
|
} |
|
1160
|
|
|
|
|
1161
|
|
|
/** |
|
1162
|
|
|
* "Clean" text |
|
1163
|
|
|
* |
|
1164
|
|
|
* Transforms text so that it can be safely put into XML markup |
|
1165
|
|
|
*/ |
|
1166
|
|
|
if(!function_exists('clean')) { |
|
1167
|
|
|
function clean($text, $url = false) { |
|
1168
|
|
|
# return htmlentities( $text ); |
|
1169
|
|
|
# return htmlentities2( $text ); |
|
1170
|
|
|
// double encoding is preventable now |
|
1171
|
|
|
// $text = htmlspecialchars_decode($text, ENT_COMPAT); |
|
1172
|
|
|
if($url) { |
|
1173
|
|
|
$text = str_replace('&', '&', $text); |
|
1174
|
|
|
} |
|
1175
|
|
|
return htmlspecialchars($text, ENT_COMPAT, 'UTF-8'); |
|
1176
|
|
|
} |
|
1177
|
|
|
} |
|
1178
|
|
|
|
|
1179
|
|
|
/** |
|
1180
|
|
|
* HTML Entities 2 |
|
1181
|
|
|
* |
|
1182
|
|
|
* Same a HTMLEntities, but avoids double-encoding of entities |
|
1183
|
|
|
*/ |
|
1184
|
|
|
if(!function_exists('htmlentities2')) { |
|
1185
|
|
|
function htmlentities2($myHTML) { |
|
1186
|
|
|
$translation_table = get_html_translation_table(HTML_ENTITIES, ENT_QUOTES); |
|
1187
|
|
|
$translation_table[chr(38)] = '&'; |
|
1188
|
|
|
return preg_replace( |
|
1189
|
|
|
"/&(?![A-Za-z]{0,4}\w{2,3};|#[0-9]{2,3};)/", "&", |
|
1190
|
|
|
strtr($myHTML, $translation_table) |
|
1191
|
|
|
); |
|
1192
|
|
|
//return htmlentities(strtr(str_replace(' ', '%20', $myHTML), $translation_table)); |
|
1193
|
|
|
} |
|
1194
|
|
|
} |
|
1195
|
|
|
|
|
1196
|
|
|
/** |
|
1197
|
|
|
* pureContent |
|
1198
|
|
|
* |
|
1199
|
|
|
* Prepares text-only representation of HTML content |
|
1200
|
|
|
*/ |
|
1201
|
|
|
if(!function_exists('pureContent')) { |
|
1202
|
|
|
function pureContent($content) { |
|
1203
|
|
|
// Remove HTML tags |
|
1204
|
|
|
// May add more cleanup code later, if validation errors are found |
|
1205
|
|
|
return strip_tags($content); |
|
1206
|
|
|
} |
|
1207
|
|
|
} |
|
1208
|
|
|
|
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.
Consider making the comparison explicit by using
empty(..)or! empty(...)instead.