Passed
Pull Request — master (#6)
by Mark
03:21 queued 44s
created

clean()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 5
Bugs 2 Features 3
Metric Value
cc 2
eloc 3
c 5
b 2
f 3
nc 2
nop 2
dl 0
loc 9
rs 10
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
14
define('AUTHORS_NODE', 'authors');
15
16
define('EXPORTER_URL', 'http://wiki.sioc-project.org/index.php/PHPExportAPI');
17
define('EXPORTER_VERSION', '1.01');
18
19
20
/**
21
 * Main exporter class.
22
 *
23
 * Generates RDF/XML content of SIOC export.
24
 * - Sets up parameters for generating RDF/XML  
25
 * - Sets up parameters for SIOC URL generation
26
 */
27
class SIOCExporter {
28
29
    private $_title;
30
    private $_blog_url;
31
    private $_sioc_url;
32
    private $_profile_url;
33
    private $_encoding;
34
    private $_generator;
35
    private $_urlseparator;
36
    private $_urlequal;
37
    private $_url4type; // e.g. type   or   sioc_type
38
    private $_url4id; // TS e. g.  id    or sioc_id
39
    private $_url4page;
40
    private $_url_usetype; // TS: if true: appends the "type" of a class to the _url4id in order to compose the string for the "id part" of the siocURL. e. g. for a forum that could produce "forum_id=" or "forum_sioc_id="
41
    private $_url_suffix; // TS:  custom parameter to be appended at the end of a siocURL
42
    private $_type_table;
43
    private $_ignore_suffix; // TS: for types in this table the _url_suffix  won't be appended to their siocURL
44
    private $_export_email;
45
46
    private $_objects;
47
48
    function SIOCExporter() {
49
        $this->_urlseparator = '&';
50
        $this->_urlequal = '=';
51
        $this->_url4type = 'type';
52
        $this->_url4id = 'id';
53
        $this->_url4page = 'page';
54
        $this->_url_usetype = true;
55
        $this->_url_suffix = '';
56
        $this->_type_table = array();
57
        $this->_ignore_suffix = array();
58
        $this->_export_email = false;
59
        $this->_encoding = 'UTF-8';
60
        $this->_objects = array();
61
    }
62
63
    function setURLParameters($type = 'type', $id = 'id', $page = 'page', $url_usetype = true, $urlseparator = '&', $urlequal = '=', $suffix = '') {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
64
        $this->_urlseparator = $urlseparator;
65
        $this->_urlequal = $urlequal;
66
        $this->_url4type = $type;
67
        $this->_url4id = $id;
68
        $this->_url4page = $page;
69
        $this->_url_usetype = $url_usetype;
70
        $this->_url_suffix = $suffix;
71
    }
72
73
    function setParameters($title, $url, $sioc_url, $encoding, $generator, $export_email = false) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
74
        $this->_title = $title;
75
        $this->_blog_url = $url;
76
        $this->_sioc_url = $sioc_url;
77
        $this->_encoding = $encoding;
78
        $this->_generator = $generator;
79
  $this->_export_email = $export_email;
80
    }
81
	
82
    // Assigns some objects to the exporter
83
    function addObject(&$obj) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
84
        $this->_objects[] = &$obj;
85
    }
86
87
  // TS: Used to replace _url4id in the siocURL for a given type (site, forum, etc.) with a parameter ($name) of your choice 
88
  // E.g. b2evo exporter uses "blog=" instead of "sioc_id=" in the siocURL of a forum
89
    function setURLTypeParm($type, $name) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
90
        $this->_type_table[$type] = $name;
91
    } 
92
93
    function setSuffixIgnore($type) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
94
        $this->_ignore_suffix[$type] = 1;
95
    }
96
97
  function siocURL($type, $id, $page = "") {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
98
    $type_part = $this->_url4type.$this->_urlequal.$type;
99
			
100
    if ($id) {
101
      if (isset($this->_type_table[$type])) 
102
              $myID = $this->_type_table[$type]; 
103
          else 
104
              $myID = (($this->_url_usetype) ? $type.'_' : '').$this->_url4id;
105
				
106
      $id_part = $this->_urlseparator.$myID.$this->_urlequal.$id;
107
    } else {
108
      $id_part = '';
109
    }
110
		
111
    ($page) ? $page_part = $this->_urlseparator.$this->_url4page.$this->_urlequal.$page : $page_part = '';
112
			
113
    ($this->_url_suffix && !isset($this->_ignore_suffix[$type])) ? $suffix = $this->_urlseparator.$this->_url_suffix : $suffix = '';
114
		
115
    $siocURL = $this->_sioc_url.$type_part.$id_part.$page_part.$suffix;
116
    return clean($siocURL, true);
117
  }
118
	
119
    function export($rdf_content = '') {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
120
        header('Content-Type: application/rdf+xml; charset='.$this->_encoding, true, 200);
121
        echo $this->makeRDF($rdf_content);
122
    }
123
124
    function makeRDF($rdf_content = '') {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
125
        $rdf = '<?xml version="1.0" encoding="'.$this->_encoding.'" ?>'."\n";
126
        $rdf .= ' 
127
<rdf:RDF
128
    xmlns="http://xmlns.com/foaf/0.1/"
129
    xmlns:foaf="http://xmlns.com/foaf/0.1/"
130
    xmlns:admin="http://webns.net/mvcb/"
131
    xmlns:content="http://purl.org/rss/1.0/modules/content/"
132
    xmlns:dc="http://purl.org/dc/elements/1.1/"
133
    xmlns:dcterms="http://purl.org/dc/terms/"
134
    xmlns:dcmitype="http://purl.org/dc/dcmitype/"
135
    xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
136
    xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
137
    xmlns:sioc="http://rdfs.org/sioc/ns#"
138
    xmlns:sioct="http://rdfs.org/sioc/types#"
139
    xmlns:owl="http://www.w3.org/2002/07/owl">
140
<foaf:Document rdf:about="'.clean($this->_profile_url, true).'">
141
	<dc:title>"'.clean($this->_title).'" (SIOC profile)</dc:title>
142
	<foaf:primaryTopic rdf:resource="'.clean($this->_objects[0]->_url, true).'"/>
143
	<admin:generatorAgent rdf:resource="'.clean($this->_generator, true).'"/>
144
	<admin:generatorAgent rdf:resource="'.clean(EXPORTER_URL, true).'?version='.EXPORTER_VERSION.'"/>
145
</foaf:Document>'."\n";
146
        if ($rdf_content) {
147
          $rdf .= $rdf_content;
148
        }
149
        if (sizeof($this->_objects)) {
150
            foreach ($this->_objects as $object) {
151
                if ($object) {
152
                  $rdf .= $object->getContent($this);
153
                }
154
            }
155
        }
156
        $rdf .= "\n</rdf:RDF>";
157
        return $rdf;
158
    }
159
}
160
161
/**
162
 * Generic SIOC Object
163
 *
164
 * All SIOC objects are derived from this.
165
 */
166
class SIOCObject {
167
    var $_note = '';
168
169
    function addNote($note) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
170
        $this->_note = $note;
171
    }
172
173
    function getContent(&$exp) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
174
        $rdf = "<sioc:Object>\n";
175
        $rdf .= "\t<rdfs:comment>Generic SIOC Object</rdfs:comment>\n";
176
        $rdf .= "</sioc:Object>\n";
177
        return $rdf;
178
    }
179
}
180
181
/**
182
 * SIOC::Site object
183
 *
184
 * Contains information about main SIOC page including:
185
 *  - site description
186
 *  - list of forums
187
 *  - list of users
188
 */
189
class SIOCSite extends SIOCObject {
190
191
    var $type = 'site';
192
193
    var $_url;
194
    var $_name;
195
    var $_description;
196
    var $_forums;
197
    var $_users;
198
    var $_page;
199
    var $_next_users;
200
    var $_next_forums;
201
    var $_usergroup_uri;
202
203
    function SIOCSite($url, $name, $description, $page = '', $usergroup_uri = '') {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
204
        $this->_url = $url;
205
        $this->_name = $name;
206
        $this->_description = $description;
207
        $this->_forums = array();
208
        $this->_users = array();
209
  $this->_page = $page;
210
  $this->_next_users = false;
211
          $this->_next_forums = false;
212
          $this->_usergroup_uri = $usergroup_uri;
213
    }
214
    
215
    function addForum($id, $url) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
216
        $this->_forums[$id] = $url;
217
    }
218
219
    function addUser($id, $url) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
220
        $this->_users[$id] = $url;
221
    } 
222
	
223
  function setNextPageUsers($next) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
224
        $this->_next_users = $next;
225
    }
226
	
227
    function setNextPageForums($next) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
228
        $this->_next_forums = $next;
229
    }
230
	
231
    function getContent(&$exp) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
232
        $rdf = "<sioc:Site rdf:about=\"".clean($this->_url)."\">\n";
233
        $rdf .= "\t<dc:title>".clean($this->_name)."</dc:title>\n";
234
        $rdf .= "\t<dc:description>".clean($this->_description)."</dc:description>\n";
235
        $rdf .= "\t<sioc:link rdf:resource=\"".clean($this->_url)."\"/>\n";
236
        if ($this->_forums) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $this->_forums of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

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.

Loading history...
237
            foreach ($this->_forums as $id => $url) { 
238
                $rdf .= "\t<sioc:host_of rdf:resource=\"".clean($url)."\"/>\n";
239
            }
240
        }  
241
    if ($this->_next_forums) {
242
            $rdf .= "\t<rdfs:seeAlso rdf:resource=\"".$exp->siocURL('site', "", $this->_page + 1)."\"/>\n";
243
        }	
244
    if ($this->_usergroup_uri) {
245
      $rdf .= "\t<sioc:has_Usergroup rdf:resource=\"".$this->_usergroup_uri."\"/>\n";
246
    } else {
247
      $rdf .= "\t<sioc:has_Usergroup rdf:nodeID=\"".AUTHORS_NODE."\"/>\n";
248
    }
249
        $rdf .= "</sioc:Site>\n";
250
        // Forums
251
        if ($this->_forums) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $this->_forums of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

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.

Loading history...
252
            $rdf .= "\n";
253
            foreach ($this->_forums as $id => $url) { 
254
                $rdf .= '<sioc:Forum rdf:about="'.clean($url)."\">\n";
255
                $rdf .= "\t<sioc:link rdf:resource=\"".clean($url)."\"/>\n";
256
                $rdf .= "\t<rdfs:seeAlso rdf:resource=\"".$exp->siocURL('forum', $id)."\"/>\n";
257
                $rdf .= "</sioc:Forum>\n";
258
            }
259
        }
260
        // Usergroup
261
        if ($this->_users) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $this->_users of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

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.

Loading history...
262
            $rdf .= "\n";
263
      if ($this->_usergroup_uri) {
264
        $rdf .= '<sioc:UserAccountgroup rdf:about="'.$this->_usergroup_uri."\">\n";
265
      } else {
266
        $rdf .= '<sioc:UserAccountgroup rdf:nodeID="'.AUTHORS_NODE."\">\n";
267
      }
268
            $rdf .= "\t<sioc:name>Authors for \"".clean($this->_name)."\"</sioc:name>\n";
269
                foreach ($this->_users as $id => $url) {
270
                    $rdf .= "\t<sioc:has_member>\n";
271
                    $rdf .= "\t\t<sioc:UserAccount rdf:about=\"".clean($url)."\">\n";
272
                    $rdf .= "\t\t\t<rdfs:seeAlso rdf:resource=\"".$exp->siocURL('user', $id)."\"/>\n";
273
                    $rdf .= "\t\t</sioc:UserAccount>\n";
274
                    $rdf .= "\t</sioc:has_member>\n";
275
                }
276
      if ($this->_next_users) {
277
            $rdf .= "\t<rdfs:seeAlso rdf:resource=\"".$exp->siocURL('site', "", $this->_page + 1)."\"/>\n";
278
      }
279
            $rdf .= "</sioc:UserAccountgroup>\n";
280
        }
281
		
282
        return $rdf;
283
    }
284
}
285
286
// Export detaille d'un utilisateur
287
/** 
288
 * SIOC::User object
289
 *
290
 * Contains user profile information
291
 */
292
class SIOCUser extends SIOCObject {
293
294
    var $type = 'user';
295
296
    var $_id;
297
    var $_nick;
298
    var $_uri;
299
    var $_name;
300
    var $_email;
301
    var $_sha1;
302
    var $_homepage;
303
    var $_foaf_uri;
304
    var $_role;
305
    var $_sioc_url;
306
    var $_foaf_url;
307
308
    function SIOCUser($id, $uri, $name, $email, $homepage = '', $foaf_uri = '', $role = false, $nick = '', $sioc_url = '', $foaf_url = '') {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
309
        $this->_id = $id;
310
        $this->_uri = $uri;
311
        $this->_name = $name;
312
        
313
        if (preg_match_all('/^.+@.+\..+$/Ui', $email, $check, PREG_SET_ORDER)) {
314
            if (preg_match_all('/^mailto:(.+@.+\..+$)/Ui', $email, $matches, PREG_SET_ORDER)) {
315
                $this->_email = $email; 
316
                $this->_sha1 = sha1($email);
317
            } else {
318
                $this->_email = "mailto:".$email; 
319
                $this->_sha1 = sha1("mailto:".$email);
320
            }
321
        }
322
        $this->_homepage = $homepage;
323
        $this->_foaf_uri = $foaf_uri;
324
        $this->_url = $foaf_uri;
0 ignored issues
show
Bug Best Practice introduced by
The property _url does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
325
        $this->_role = $role;
326
        $this->_nick = $nick;
327
        $this->_foaf_url = $foaf_url;
328
        $this->_sioc_url = $sioc_url;
329
    }
330
331
    function getContent(&$exp) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
332
        $rdf = "<foaf:Person rdf:about=\"".clean($this->_foaf_uri)."\">\n";
333
        if ($this->_name) {
334
          $rdf .= "\t<foaf:name>".$this->_name."</foaf:name>\n";
335
        }
336
        if ($this->_email) { $rdf .= "\t<foaf:mbox_sha1sum>".$this->_sha1."</foaf:mbox_sha1sum>\n"; }
337
        if ($this->_foaf_url) { $rdf .= "\t<rdfs:seeAlso rdf:resource=\"".$this->_foaf_url."\"/>\n"; }
338
        $rdf .= "\t<foaf:holdsAccount>\n";
339
        $rdf .= "\t\t<sioc:UserAccount rdf:about=\"".clean($this->_uri)."\">\n";
340
        if ($this->_nick) {
341
          $rdf .= "\t\t\t<sioc:name>".$this->_nick."</sioc:name>\n";
342
        }
343
        if ($this->_email) {
344
            if ($exp->_export_email) { $rdf .= "\t\t\t<sioc:email rdf:resource=\"".$this->_email."\"/>\n"; }
345
            $rdf .= "\t\t\t<sioc:email_sha1>".$this->_sha1."</sioc:email_sha1>\n";
346
        }
347
        if ($this->_role) {
348
            $rdf .= "\t\t\t<sioc:has_function>\n";
349
            $rdf .= "\t\t\t\t<sioc:Role>\n";
350
            $rdf .= "\t\t\t\t\t<sioc:name>".$this->_role."</sioc:name>\n";
351
            $rdf .= "\t\t\t\t</sioc:Role>\n";
352
            $rdf .= "\t\t\t</sioc:has_function>\n";
353
        }
354
        if ($this->_sioc_url) { $rdf .= "\t\t\t<rdfs:seeAlso rdf:resource=\"".$this->_sioc_url."\"/>\n"; }
355
        $rdf .= "\t\t</sioc:UserAccount>\n";    
356
        $rdf .= "\t</foaf:holdsAccount>\n";    
357
        $rdf .= "</foaf:Person>\n";  
358
        return $rdf;
359
    }
360
}
361
362
// Export detaille d'un utilisateur
363
/** 
364
 * SIOC::Thread object
365
 *
366
 * Contains information about a SIOC Thread in a SIOC Forum
367
  - list of posts in that thread
368
 */
369
370
class SIOCThread extends SIOCObject {
371
372
    var $type = 'thread';
373
    var $_id;
374
    var $_url;
375
    var $_page;
376
    var $_posts;
377
    var $_next;
378
    var $_views;
379
    var $_tags;
380
    var $_related;
381
    var $_title;
382
    var $_created;
383
    var $_parents;
384
385
    function SIOCThread($id, $url, $page, $views = '', $tags = array(), $subject = '', $created = '') {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
386
        $this->_id = $id;
387
        $this->_url = $url;
388
        $this->_page = $page;
389
        $this->_posts = array();
390
        $this->_next = false;
391
        $this->_views = $views;
392
        $this->_tags = $tags;
393
        $this->_related = array();
394
        $this->_subject = $subject;
0 ignored issues
show
Bug Best Practice introduced by
The property _subject does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
395
        $this->_created = $created;
396
    }
397
398
    function addPost($id, $url, $prev = '', $next = '') {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
399
        $this->_posts[$id] = array("url" => $url, "prev" => $prev, "next" => $next);
400
    }
401
402
  // add links to things that are similar to this via sioc:related_to 
403
    function addRelated($id, $url) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
404
        $this->_related[$id] = $url;
405
    }
406
	
407
    function setNextPage($next) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
408
        $this->_next = $next;
409
    }
410
	
411
  function addParentForum($id, $url) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
412
        $this->_parents[$id] = $url;
413
    }
414
415
    function getContent(&$exp) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
416
        $rdf .= '<sioc:Thread rdf:about="'.clean($this->_url)."\">\n";
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $rdf seems to be never defined.
Loading history...
417
        $rdf .= "\t<sioc:link rdf:resource=\"".clean($this->_url)."\"/>\n";
418
        if ($this->_views)  $rdf .= "\t<sioc:num_views>".$this->_views."</sioc:num_views>\n";
419
        if ($this->_note)   $rdf .= "\t<rdfs:comment>".$this->_note."</rdfs:comment>\n";
420
    if ($this->_subject) { $rdf .= "\t<dc:title>".$this->_subject."</dc:title>\n"; }
421
        if ($this->_created) { $rdf .= "\t<dcterms:created>".$this->_created."</dcterms:created>\n"; }
422
        if ($this->_parents) {
423
      foreach ($this->_parents as $id => $uri) {
424
        $rdf .= "\t<sioc:has_parent>\n";
425
        $rdf .= "\t\t<sioc:Forum rdf:about=\"".clean($uri)."\">\n";
426
        $rdf .= "\t\t\t<rdfs:seeAlso rdf:resource=\"".$exp->siocURL('forum', $id)."\"/>\n";
427
        $rdf .= "\t\t</sioc:Forum>\n";
428
        $rdf .= "\t</sioc:has_parent>\n";
429
      }
430
    }
431
    // here the tags are just used as keywords for dc:subject
432
        if ($this->_tags) { 
433
            foreach ($this->_tags as $id => $tag) {
434
                $rdf .= "\t<dc:subject>".$tag."</dc:subject>\n"; 
435
            }
436
        }
437
    // here the tags are used by creating a tag object with a blank node, with the keyword as moat:name - if you use this insert prefixes for moat and tags
438
    // if ($this->_tags) { 
439
      // $i=1;
440
            // foreach ($this->_tags as $id => $tag) {
441
        // $rdf .= "\t<tags:taggedWithTag>\n";
442
        // $rdf .= "\t\t<moat:tag rdf:nodeID=\"b$i\">\n";
443
        // // actually, the best way is to have 'reference URIs' for tags, e.g. URIs for all the platform (http://tags.example.org/tag/soccer
444
                // $rdf .= "\t\t\t<moat:name>" . $tag . "</moat:name>\n";  
445
        // $rdf .= "\t\t</moat:tag>\n";
446
        // $rdf .= "\t</moat:taggedWithTag>\n";
447
        // $i++;
448
            // }
449
        // }
450
		
451
    // here the tags are used are used for sioc:topic, each topic needs to have a URI
452
    /*if($this->_tags) {
453
            foreach($this->_tags as $url=>$topic) {
454
                $rdf .= "\t<sioc:topic rdfs:label=\"$topic\" rdf:resource=\"" . clean($url) ."\"/>\n";
455
            }
456
        }
457
		*/
458
    if ($this->_related) { 
0 ignored issues
show
Bug Best Practice introduced by
The expression $this->_related of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

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.

Loading history...
459
      foreach ($this->_related as $id => $url) {
460
          $rdf .= "\t<sioc:related_to>\n";
461
          $rdf .= "\t\t<sioc:Thread rdf:about=\"".clean($url)."\"/>\n";
462
          $rdf .= "\t</sioc:related_to>\n"; // todo - each topic needs to have a URI
463
      }
464
    }		
465
		
466
        if ($this->_posts) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $this->_posts of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

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.

Loading history...
467
            foreach ($this->_posts as $id => $data) {
468
                $rdf .= "\t<sioc:container_of>\n";
469
                $rdf .= "\t\t<sioc:Post rdf:about=\"".clean($data[url])."\">\n";
0 ignored issues
show
Bug introduced by
The constant url was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
470
                $rdf .= "\t\t\t<rdfs:seeAlso rdf:resource=\"".$exp->siocURL('post', $id)."\"/>\n";
471
                if ($data[prev]) { $rdf .= "\t\t\t<sioc:previous_by_date rdf:resource=\"".clean($data[prev])."\"/>\n"; }
0 ignored issues
show
Bug introduced by
The constant prev was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
472
                if ($data[next]) { $rdf .= "\t\t\t<sioc:next_by_date rdf:resource=\"".clean($data[next])."\"/>\n"; }
0 ignored issues
show
Bug introduced by
The constant next was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
473
                $rdf .= "\t\t</sioc:Post>\n";
474
                $rdf .= "\t</sioc:container_of>\n";
475
            }
476
        }
477
        if ($this->_next) {
478
            $rdf .= "\r<rdfs:seeAlso rdf:resource=\"".$exp->siocURL('thread', $this->_id, $this->_page + 1)."\"/>\n";
479
        }
480
        $rdf .= "</sioc:Thread>\n";
481
        return $rdf;
482
    }
483
}
484
485
// Export d'un forum avec une liste de posts -variable (next with seeAlso)
486
/**
487
 * SIOC::Forum object
488
 *
489
 * Contains information about SIOC Forum (blog, ...):
490
 *  - description of a forum
491
 *  - list of posts within a forum [partial, paged]
492
 */
493
494
class SIOCForum extends SIOCObject {
495
496
    var $type = 'forum';
497
498
    var $_id;
499
    var $_url;    
500
    var $_page;
501
    var $_posts;
502
    var $_next;
503
    var $_blog_title;
504
    var $_description;
505
    var $_threads;
506
    var $_parents;
507
    var $_type;
508
    var $_creator;
509
    var $_administrator;
510
	
511
    function SIOCForum($id, $url, $page, $title = '', $descr = '', $type = 'sioc:Forum', $creator = '', $admin = '', $links = array()) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
512
        $this->_id = $id;
513
        $this->_url = $url;
514
        $this->_page = $page;
515
        $this->_posts = array();
516
        $this->_next = false;
517
        $this->_blog_title = $title;
518
        $this->_description = $descr;
519
          $this->_threads = array();
520
          $this->_parents = array();
521
          $this->_type = $type;
522
          $this->_creator = $creator;
523
          $this->_administrator = $admin;
524
          $this->_links = $links;
0 ignored issues
show
Bug Best Practice introduced by
The property _links does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
525
    }
526
	
527
    function addPost($id, $url) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
528
        $this->_posts[$id] = $url;
529
    }
530
	
531
  function addThread($id, $url) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
532
        $this->_threads[$id] = $url;
533
    }
534
	
535
  function addParentForum($id, $url) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
536
        $this->_parents[$id] = $url;
537
    }
538
539
    function setNextPage($next) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
540
        $this->_next = $next;
541
    }
542
543
    function getContent(&$exp) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
544
        $rdf .= '<'.$this->_type.' rdf:about="'.clean($this->_url)."\">\n";
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $rdf seems to be never defined.
Loading history...
545
    if ($this->_type != 'sioc:Forum') $rdf .= "\t<rdf:type rdf:resource=\"http://rdfs.org/sioc/ns#Forum\" />\n";
546
        $rdf .= "\t<sioc:link rdf:resource=\"".clean($this->_url)."\"/>\n";
547
        if ($this->_blog_title)  $rdf .= "\t<dc:title>".$this->_blog_title."</dc:title>\n";
548
        if ($this->_description) $rdf .= "\t<dc:description>".$this->_description."</dc:description>\n";
549
        if ($this->_note)        $rdf .= "\t<rdfs:comment>".$this->_note."</rdfs:comment>\n";
550
		
551
    if ($this->_parents) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $this->_parents of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

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.

Loading history...
552
      foreach ($this->_parents as $id => $uri) {
553
        $rdf .= "\t<sioc:has_parent>\n";
554
        $rdf .= "\t\t<sioc:Forum rdf:about=\"".clean($uri)."\">\n";
555
        $rdf .= "\t\t\t<rdfs:seeAlso rdf:resource=\"".$exp->siocURL('forum', $id)."\"/>\n";
556
        $rdf .= "\t\t</sioc:Forum>\n";
557
        $rdf .= "\t</sioc:has_parent>\n";
558
            }
559
    }
560
		
561
    if ($this->_threads) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $this->_threads of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

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.

Loading history...
562
      foreach ($this->_threads as $id => $uri) {
563
        $rdf .= "\t<sioc:parent_of>\n";
564
        $rdf .= "\t\t<sioc:Thread rdf:about=\"".clean($uri)."\">\n";
565
        $rdf .= "\t\t\t<rdfs:seeAlso rdf:resource=\"".$exp->siocURL('thread', $id)."\"/>\n";
566
        $rdf .= "\t\t</sioc:Thread>\n";
567
        $rdf .= "\t</sioc:parent_of>\n";
568
            }
569
    }
570
		
571
        if ($this->_posts) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $this->_posts of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

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.

Loading history...
572
            foreach ($this->_posts as $id => $url) {
573
                $rdf .= "\t<sioc:container_of>\n";
574
                $rdf .= "\t\t<sioc:Post rdf:about=\"".clean($url)."\">\n";
575
                $rdf .= "\t\t\t<rdfs:seeAlso rdf:resource=\"".$exp->siocURL('post', $id)."\"/>\n";
576
                $rdf .= "\t\t</sioc:Post>\n";
577
                $rdf .= "\t</sioc:container_of>\n";
578
            }
579
        }
580
		
581
    if ($this->_creator) {
582
            if ($this->_creator->_id) {
583
                $rdf .= "\t<sioc:has_creator>\n";
584
                $rdf .= "\t\t<sioc:UserAccount rdf:about=\"".clean($this->_creator->_uri)."\">\n";
585
                if ($this->_creator->_sioc_url) { $rdf .= "\t\t\t<rdfs:seeAlso rdf:resource=\"".$this->_creator->_sioc_url."\"/>\n"; } else {
586
                  $rdf .= "\t\t\t<rdfs:seeAlso rdf:resource=\"".$exp->siocURL('user', $this->_creator->_id)."\"/>\n";
587
                }
588
                $rdf .= "\t\t</sioc:UserAccount>\n";
589
                $rdf .= "\t</sioc:has_creator>\n";
590
                $rdf .= "\t<foaf:maker>\n";
591
                $rdf .= "\t\t<foaf:Person rdf:about=\"".clean($this->_creator->_foaf_uri)."\">\n";
592
                if ($this->_creator->_foaf_url) { $rdf .= "\t\t\t<rdfs:seeAlso rdf:resource=\"".$this->_creator->_foaf_url."\"/>\n"; } else {
593
                  $rdf .= "\t\t\t<rdfs:seeAlso rdf:resource=\"".$exp->siocURL('user', $this->_creator->_id)."\"/>\n";
594
                }
595
                $rdf .= "\t\t</foaf:Person>\n";
596
                $rdf .= "\t</foaf:maker>\n";
597
            } else {
598
                $rdf .= "\t<foaf:maker>\n";
599
                $rdf .= "\t\t<foaf:Person";
600
                if ($this->_creator->_name) {
601
                  $rdf .= " foaf:name=\"".$this->_creator->_name."\"";
602
                }
603
                if ($this->_creator->_sha1) {
604
                  $rdf .= " foaf:mbox_sha1sum=\"".$this->_creator->_sha1."\"";
605
                }
606
                if ($this->_creator->_name) {
607
                  $rdf .= ">\n\t\t\t<foaf:homepage rdf:resource=\"".$this->_creator->_homepage."\"/>\n\t\t</foaf:Person>\n";
608
                } else {
609
                  $rdf .= "/>\n";
610
                }
611
                $rdf .= "\t</foaf:maker>\n";
612
            }
613
        }
614
		
615
    if ($this->_administrator) {
616
            if ($this->_administrator->_id) {
617
                $rdf .= "\t<sioc:has_administrator>\n";
618
                $rdf .= "\t\t<sioc:UserAccount rdf:about=\"".clean($this->_administrator->_uri)."\">\n";
619
                if ($this->_administrator->_sioc_url) { $rdf .= "\t\t\t<rdfs:seeAlso rdf:resource=\"".$this->_administrator->_sioc_url."\"/>\n"; }
620
                else $rdf .= "\t\t\t<rdfs:seeAlso rdf:resource=\"".$exp->siocURL('user', $this->_administrator->_id)."\"/>\n";
621
                $rdf .= "\t\t</sioc:UserAccount>\n";
622
                $rdf .= "\t</sioc:has_administrator>\n";
623
            } 
624
        }
625
    if ($this->_links) {
626
            foreach ($this->_links as $url=>$link) {
627
                $rdf .= "\t<sioc:links_to rdfs:label=\"$link\" rdf:resource=\"".clean($url)."\"/>\n";
628
            }
629
        }
630
631
        if ($this->_next) {
632
            $rdf .= "\r<rdfs:seeAlso rdf:resource=\"".$exp->siocURL('forum', $this->_id, $this->_page + 1)."\"/>\n";
633
        }
634
    $rdf .= "</".$this->_type.">";
635
		
636
        return $rdf;
637
    }
638
}
639
640
/**
641
 * SIOC::Post object
642
 *
643
 * Contains information about a post
644
 */
645
class SIOCPost extends SIOCObject {
646
647
    var $type = 'post';
648
	
649
    var $_url;
650
    var $_subject;
651
    var $_content;
652
    var $_encoded;
653
    var $_creator;
654
    var $_created;
655
    var $_updated;
656
    var $_topics;
657
    var $_links;
658
    var $_comments;
659
    var $_reply_of;
660
    var $_type;
661
    var $_has_part;
662
663
    function SIOCPost($url, $subject, $content, $encoded, $creator, $created, $updated = "", $topics = array(), $links = array(), $type = 'sioc:Post', $has_part = array()) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
664
        $this->_url = $url;
665
        $this->_subject = $subject;
666
        $this->_content = $content;
667
        $this->_encoded = $encoded;
668
        $this->_creator = $creator;
669
        $this->_created = $created;
670
        $this->_updated = $updated;
671
        $this->_topics = $topics;
672
        $this->_links = $links;
673
        $this->_comments = array();
674
        $this->_reply_of = array();
675
          $this->_type = $type;
676
          $this->_has_part = $has_part;
677
    }
678
679
    function addComment($id, $url) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
680
        $this->_comments[$id] = $url;
681
    }
682
683
    function addReplyOf($id, $url) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
684
        $this->_reply_of[$id] = $url;    
685
    }
686
687
    function getContent(&$exp) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
688
        $rdf = '<'.$this->_type." rdf:about=\"".clean($this->_url)."\">\n";
689
        if ($this->_type != 'sioc:Post') $rdf .= "\t<rdf:type rdf:resource=\"http://rdfs.org/sioc/ns#Post\" />\n";
690
        if ($this->_subject) { $rdf .= "\t<dc:title>".$this->_subject."</dc:title>\n"; }
691
        if ($this->_creator) {
692
            if ($this->_creator->_id) {
693
                $rdf .= "\t<sioc:has_creator>\n";
694
                $rdf .= "\t\t<sioc:UserAccount rdf:about=\"".clean($this->_creator->_uri)."\">\n";
695
                if ($this->_creator->_sioc_url) { $rdf .= "\t\t\t<rdfs:seeAlso rdf:resource=\"".$this->_creator->_sioc_url."\"/>\n"; } else {
696
                  $rdf .= "\t\t\t<rdfs:seeAlso rdf:resource=\"".$exp->siocURL('user', $this->_creator->_id)."\"/>\n";
697
                }
698
                $rdf .= "\t\t</sioc:UserAccount>\n";
699
                $rdf .= "\t</sioc:has_creator>\n";
700
                $rdf .= "\t<foaf:maker>\n";
701
                $rdf .= "\t\t<foaf:Person rdf:about=\"".clean($this->_creator->_foaf_uri)."\">\n";
702
                if ($this->_creator->_foaf_url) { $rdf .= "\t\t\t<rdfs:seeAlso rdf:resource=\"".$this->_creator->_foaf_url."\"/>\n"; } else {
703
                  $rdf .= "\t\t\t<rdfs:seeAlso rdf:resource=\"".$exp->siocURL('user', $this->_creator->_id)."\"/>\n";
704
                }
705
                $rdf .= "\t\t</foaf:Person>\n";
706
                $rdf .= "\t</foaf:maker>\n";
707
            } else {
708
                $rdf .= "\t<foaf:maker>\n";
709
                $rdf .= "\t\t<foaf:Person";
710
                if ($this->_creator->_name) {
711
                  $rdf .= " foaf:name=\"".$this->_creator->_name."\"";
712
                }
713
                if ($this->_creator->_sha1) {
714
                  $rdf .= " foaf:mbox_sha1sum=\"".$this->_creator->_sha1."\"";
715
                }
716
                if ($this->_creator->_name) {
717
                  $rdf .= ">\n\t\t\t<foaf:homepage rdf:resource=\"".$this->_creator->_homepage."\"/>\n\t\t</foaf:Person>\n";
718
                } else {
719
                  $rdf .= "/>\n";
720
                }
721
                $rdf .= "\t</foaf:maker>\n";
722
            }
723
        }
724
        $rdf .= "\t<dcterms:created>".$this->_created."</dcterms:created>\n";
725
        if ($this->_updated AND ($this->_created != $this->_updated)) $rdf .= "\t<dcterms:modified>".$this->_updated."</dcterms:modified>\n";
726
        $rdf .= "\t<sioc:content>".pureContent($this->_content)."</sioc:content>\n";
727
			
728
        $rdf .= "\t<content:encoded><![CDATA[".$this->_encoded."]]></content:encoded>\n";
729
        if ($this->_topics) {
730
            foreach ($this->_topics as $url=>$topic) {
731
                $rdf .= "\t<sioc:topic rdfs:label=\"$topic\" rdf:resource=\"".clean($url)."\"/>\n";
732
            }
733
        }
734
        if ($this->_links) {
735
            foreach ($this->_links as $url=>$link) {
736
                $rdf .= "\t<sioc:links_to rdfs:label=\"$link\" rdf:resource=\"".clean($url)."\"/>\n";
737
            }
738
        }
739
    if ($this->_has_part) {
740
            foreach ($this->_has_part as $id=>$url) {
741
                $rdf .= "\t<dcterms:hasPart>\n";
742
        $rdf .= "\t\t<dcmitype:Image rdf:about=\"".clean($url)."\"/>\n";
743
        $rdf .= "\t</dcterms:hasPart>\n";
744
            }
745
        }
746
        if ($this->_reply_of) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $this->_reply_of of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

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.

Loading history...
747
            foreach ($this->_reply_of as $id => $url) {
748
                $rdf .= "\t<sioc:reply_of>\n";
749
                $rdf .= "\t\t<sioc:Post rdf:about=\"".clean($url)."\">\n";
750
                $rdf .= "\t\t\t<rdfs:seeAlso rdf:resource=\"".$exp->siocURL('post', $id)."\"/>\n";
751
                $rdf .= "\t\t</sioc:Post>\n";
752
                $rdf .= "\t</sioc:reply_of>\n";
753
            }
754
        }
755
        if ($this->_comments) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $this->_comments of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

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.

Loading history...
756
            foreach ($this->_comments as $id => $url) {
757
                $rdf .= "\t<sioc:has_reply>\n";
758
                $rdf .= "\t\t<sioc:Post rdf:about=\"".clean($url)."\">\n";
759
        //        if($comments->f('comment_trackback')) $rdf .= "\t\t\t<sioc:type>" . POST_TRACKBACK . "</sioc:type>\n"; 
760
        //        else $rdf .= "\t\t\t<sioc:type>" . POST_COMMENT  . "</sioc:type>\n";
761
                $rdf .= "\t\t\t<rdfs:seeAlso rdf:resource=\"".$exp->siocURL('comment', $id)."\"/>\n";
762
                $rdf .= "\t\t</sioc:Post>\n";
763
                $rdf .= "\t</sioc:has_reply>\n";
764
            }
765
        }
766
        $rdf .= "</".$this->_type.">\n";
767
        return $rdf;    
768
    }
769
}
770
771
/**
772
 * SIOC::WikiArticle object
773
 *
774
 * Contains information about a wiki article
775
 */
776
class SIOCWikiArticle extends SIOCObject {
777
778
    var $type = 'sioct:WikiArticle';
779
780
    var $_url;
781
    var $_api = null;
782
    var $_subject;
783
    var $_redirpage;
784
    var $_creator;
785
    var $_created;
786
    var $_topics;
787
    var $_links;
788
    var $_ext_links;
789
    var $_type;
790
    var $_previous_version;
791
    var $_next_version;
792
    var $_latest_version;
793
    var $_has_discussion;
794
    var $_has_container;
795
796
    function SIOCWikiArticle($url, $api, $subject, $redir, $user, $created, $prev_vers, $next_vers, $latest_vers, $has_discuss, $container, $topics = array(), $links = array(), $ext_links = array(), $type = 'sioct:WikiArticle') {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
797
        $this->_url = $url;
798
        $this->_api = $api;
799
        $this->_subject = $subject;
800
        $this->_redirpage = $redir;
801
        $this->_creator = $user;
802
        $this->_created = $created;
803
        $this->_topics = $topics;
804
        $this->_links = $links;
805
        $this->_ext_links = $ext_links;
806
          $this->_type = $type;
807
        $this->_previous_version = $prev_vers;
808
          $this->_next_version = $next_vers;
809
        $this->_latest_version = $latest_vers;
810
        $this->_has_discussion = $has_discuss;
811
        $this->_has_container = $container;
812
    }
813
814
    function getContent(&$exp) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
815
        $rdf = '<'.$this->_type." rdf:about=\"".clean($this->_url)."\">\n";
816
        if ($this->_subject)
817
        {
818
            $rdf .= "\t<dc:title>".clean($this->_subject)."</dc:title>\n";
819
            if (strcmp($this->_has_container, 'http://en.wikipedia.org') === 0) {
820
                            $rdf .= "\t<foaf:primaryTopic rdf:resource=\"".clean('http://dbpedia.org/resource/'.$this->_subject)."\"/>\n";
821
            }
822
        }
823
        if ($this->_creator->_nick) {
824
            /*if ($this->_creator->_id) {
825
                $rdf .= "\t<sioc:has_creator>\n";
826
                $rdf .= "\t\t<sioc:UserAccount rdf:about=\"" . clean($this->_creator->_uri) ."\">\n";
827
                if($this->_creator->_sioc_url) { $rdf .= "\t\t\t<rdfs:seeAlso rdf:resource=\"". $this->_creator->_sioc_url ."\"/>\n"; }
828
                else $rdf .= "\t\t\t<rdfs:seeAlso rdf:resource=\"" . $exp->siocURL('user', $this->_creator->_id). "\"/>\n";
829
                $rdf .= "\t\t</sioc:UserAccount>\n";
830
                $rdf .= "\t</sioc:has_creator>\n";
831
                $rdf .= "\t<foaf:maker>\n";
832
                $rdf .= "\t\t<foaf:Person rdf:about=\"" . clean($this->_creator->_foaf_uri) ."\">\n";
833
                if($this->_creator->_foaf_url) { $rdf .= "\t\t\t<rdfs:seeAlso rdf:resource=\"". $this->_creator->_foaf_url ."\"/>\n"; }
834
                else $rdf .= "\t\t\t<rdfs:seeAlso rdf:resource=\"" . $exp->siocURL('user', $this->_creator->_id). "\"/>\n";
835
                $rdf .= "\t\t</foaf:Person>\n";
836
                $rdf .= "\t</foaf:maker>\n";
837
            } else {*/
838
                $rdf .= "\t<sioc:has_creator>\n";
839
                $rdf .= "\t\t<sioc:UserAccount rdf:about=\"".clean($this->_creator->_uri)."\">\n";
840
                $rdf .= "\t\t\t<rdfs:seeAlso rdf:resource=\"".
841
                        clean('http://ws.sioc-project.org/mediawiki/mediawiki.php?wiki='.$this->_creator->_uri);
842
                if ($this->_api) {
843
                  $rdf .= clean("&api=".$this->_api);
844
                }
845
                $rdf .= "\"/>\n";
846
                $rdf .= "\t\t</sioc:UserAccount>\n";
847
                $rdf .= "\t</sioc:has_creator>\n";
848
                $rdf .= "\t<dc:contributor>".clean($this->_creator->_nick)."</dc:contributor>\n";
849
                /*$rdf .= "\t<foaf:maker>\n";
850
                $rdf .= "\t\t<foaf:Person";
851
                if($this->_creator->_name) $rdf .= " foaf:name=\"" . $this->_creator->_name ."\"";
852
                if($this->_creator->_sha1) $rdf .= " foaf:mbox_sha1sum=\"" . $this->_creator->_sha1 ."\"";
853
                if($this->_creator->_homepage) $rdf .= ">\n\t\t\t<foaf:homepage rdf:resource=\"" . $this->_creator->_homepage ."\"/>\n\t\t</foaf:Person>\n";
854
                else $rdf .= "/>\n";
855
                $rdf .= "\t</foaf:maker>\n";
856
            }*/
857
        } else {
858
            if ($this->_creator !== 'void')
859
            {
860
                $rdf .= "\t<sioc:has_creator>\n";
861
                $rdf .= "\t\t<sioc:UserAccount>\n";
862
                $rdf .= "\t\t</sioc:UserAccount>\n";
863
                $rdf .= "\t</sioc:has_creator>\n";
864
            }
865
        }
866
        if ($this->_created) {
867
            $rdf .= "\t<dcterms:created>".$this->_created."</dcterms:created>\n";
868
        }
869
        if (is_array($this->_topics)) {
870
            foreach ($this->_topics as $topic=>$url) {
871
                $rdf .= "\t<sioc:topic>\n";
872
                $rdf .= "\t\t<sioct:Category rdf:about=\"".clean($url)."\">\n";
873
                $rdf .= "\t\t\t<rdfs:seeAlso rdf:resource=\"".
874
                        clean('http://ws.sioc-project.org/mediawiki/mediawiki.php?wiki='.$url);
875
                if ($this->_api) {
876
                  $rdf .= clean("&api=".$this->_api);
877
                }
878
                $rdf .= "\"/>\n";
879
                $rdf .= "\t\t</sioct:Category>\n";
880
                $rdf .= "\t</sioc:topic>\n";
881
            }
882
        }
883
        if (is_array($this->_links)) {
884
            foreach ($this->_links as $label=>$url) {
885
                $rdf .= "\t<sioc:links_to>\n";
886
                $rdf .= "\t\t<sioct:WikiArticle rdf:about=\"".clean($url)."\">\n";
887
                $rdf .= "\t\t\t<rdfs:seeAlso rdf:resource=\"".
888
                        clean('http://ws.sioc-project.org/mediawiki/mediawiki.php?wiki='.$url);
889
                if ($this->_api) {
890
                  $rdf .= clean("&api=".$this->_api);
891
                }
892
                $rdf .= "\"/>\n";
893
                $rdf .= "\t\t</sioct:WikiArticle>\n";
894
                $rdf .= "\t</sioc:links_to>\n";
895
            }
896
        } else
897
        { if ($this->_links)
898
            {
899
                $rdf .= "\t<sioc:links_to>\n";
900
                $rdf .= "\t\t<sioct:WikiArticle rdf:about=\"".clean($this->_links)."\">\n";
901
                $rdf .= "\t\t\t<rdfs:seeAlso rdf:resource=\"".
902
                        clean('http://ws.sioc-project.org/mediawiki/mediawiki.php?wiki='.$this->_links);
903
                if ($this->_api) {
904
                  $rdf .= clean("&api=".$this->_api);
905
                }
906
                $rdf .= "\"/>\n";
907
                $rdf .= "\t\t</sioct:WikiArticle>\n";
908
                $rdf .= "\t</sioc:links_to>\n";
909
            }
910
        }
911
        if (is_array($this->_ext_links)) {
912
            foreach ($this->_ext_links as $label=>$url) {
913
                $rdf .= "\t<sioc:links_to rdf:resource=\"".clean($url)."\"/>\n";
914
            }
915
        }
916
        if ($this->_previous_version) {
917
                $rdf .= "\t<sioc:previous_version>\n";
918
                $rdf .= "\t\t<sioct:WikiArticle rdf:about=\"".clean($this->_previous_version)."\">\n";
919
                $rdf .= "\t\t\t<rdfs:seeAlso rdf:resource=\"".
920
                        clean('http://ws.sioc-project.org/mediawiki/mediawiki.php?wiki='.$this->_previous_version);
921
                if ($this->_api) {
922
                  $rdf .= clean("&api=".$this->_api);
923
                }
924
                $rdf .= "\"/>\n";
925
                $rdf .= "\t\t</sioct:WikiArticle>\n";
926
                $rdf .= "\t</sioc:previous_version>\n";
927
                /*If there is support for inference and transitivity the following is not needed
928
                $rdf .= "\t<sioc:earlier_version>\n";
929
                $rdf .= "\t\t<sioct:WikiArticle rdf:about=\"" . clean($this->_previous_version) ."\">\n";
930
                $rdf .= "\t\t\t<rdfs:seeAlso rdf:resource=\"" .
931
                        clean('http://ws.sioc-project.org/mediawiki/mediawiki.php?wiki='.$this->_previous_version);
932
                if ($this->_api) {
933
                  $rdf .= clean("&api=" . $this->_api);
934
                }
935
                $rdf .= "\"/>\n";
936
                $rdf .= "\t\t</sioct:WikiArticle>\n";
937
                $rdf .= "\t</sioc:earlier_version>\n";
938
                 */
939
        }
940
        if ($this->_next_version) {
941
                $rdf .= "\t<sioc:next_version>\n";
942
                $rdf .= "\t\t<sioct:WikiArticle rdf:about=\"".clean($this->_next_version)."\">\n";
943
                $rdf .= "\t\t\t<rdfs:seeAlso rdf:resource=\"".
944
                        clean('http://ws.sioc-project.org/mediawiki/mediawiki.php?wiki='.$this->_next_version);
945
                if ($this->_api) {
946
                  $rdf .= clean("&api=".$this->_api);
947
                }
948
                $rdf .= "\"/>\n";
949
                $rdf .= "\t\t</sioct:WikiArticle>\n";
950
                $rdf .= "\t</sioc:next_version>\n";
951
                /*If there is support for inference and transitivity the following is not needed
952
                $rdf .= "\t<sioc:later_version>\n";
953
                $rdf .= "\t\t<sioct:WikiArticle rdf:about=\"" . clean($this->_next_version) ."\">\n";
954
                $rdf .= "\t\t\t<rdfs:seeAlso rdf:resource=\"" .
955
                        clean('http://ws.sioc-project.org/mediawiki/mediawiki.php?wiki='.$this->_next_version);
956
                if ($this->_api) {
957
                  $rdf .= clean("&api=" . $this->_api);
958
                }
959
                $rdf .= "\"/>\n";
960
                $rdf .= "\t\t</sioct:WikiArticle>\n";
961
                $rdf .= "\t</sioc:later_version>\n";
962
                 */
963
        }
964
        if ($this->_latest_version) {
965
                $rdf .= "\t<sioc:latest_version>\n";
966
                $rdf .= "\t\t<sioct:WikiArticle rdf:about=\"".clean($this->_latest_version)."\">\n";
967
                $rdf .= "\t\t\t<rdfs:seeAlso rdf:resource=\"".
968
                        clean('http://ws.sioc-project.org/mediawiki/mediawiki.php?wiki='.$this->_latest_version);
969
                if ($this->_api) {
970
                  $rdf .= clean("&api=".$this->_api);
971
                }
972
                $rdf .= "\"/>\n";
973
                $rdf .= "\t\t</sioct:WikiArticle>\n";
974
                $rdf .= "\t</sioc:latest_version>\n";
975
        }
976
        if ($this->_has_discussion && (strpos($this->_has_discussion, 'Talk:Talk:') == FALSE)) {
0 ignored issues
show
Bug Best Practice introduced by
It seems like you are loosely comparing strpos($this->_has_discussion, 'Talk:Talk:') of type integer to the boolean FALSE. If you are specifically checking for 0, consider using something more explicit like === 0 instead.
Loading history...
977
                $rdf .= "\t<sioc:has_discussion>\n";
978
                $rdf .= "\t\t<sioct:WikiArticle rdf:about=\"".clean($this->_has_discussion)."\">\n";
979
                $rdf .= "\t\t\t<rdfs:seeAlso rdf:resource=\"".
980
                        clean('http://ws.sioc-project.org/mediawiki/mediawiki.php?wiki='.$this->_has_discussion);
981
                if ($this->_api) {
982
                  $rdf .= clean("&api=".$this->_api);
983
                }
984
                $rdf .= "\"/>\n";
985
                $rdf .= "\t\t</sioct:WikiArticle>\n";
986
                $rdf .= "\t</sioc:has_discussion>\n";
987
        }
988
        if ($this->_has_container) {
989
                $rdf .= "\t<sioc:has_container>\n";
990
                $rdf .= "\t\t<sioct:Wiki rdf:about=\"".clean($this->_has_container)."\"/>\n";
991
                $rdf .= "\t</sioc:has_container>\n";
992
        }
993
        if ($this->_redirpage)
994
        {
995
            $rdf .= "\t<owl:sameAs rdf:resource=\"".clean($this->_redirpage)."\"/>\n";
996
            $rdf .= "\t<rdfs:seeAlso rdf:resource=\"". 
997
                        clean('http://ws.sioc-project.org/mediawiki/mediawiki.php?wiki='.$this->_redirpage);
998
            if ($this->_api) {
999
              $rdf .= clean("&api=".$this->_api);
1000
            }
1001
            $rdf .= "\"/>\n";
1002
        }
1003
1004
        $rdf .= "</".$this->_type.">\n";
1005
        return $rdf;
1006
    }
1007
}
1008
1009
/**
1010
 * SIOC::Wiki object
1011
 *
1012
 * Contains information about a wiki site
1013
 */
1014
class SIOCWiki extends SIOCObject {
1015
1016
    var $_url;
1017
    var $_type;
1018
1019
    function SIOCWiki($url, $type = 'sioct:Wiki') {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
1020
        $this->_url = $url;
1021
          $this->_type = $type;
1022
    }
1023
1024
    function getContent(&$exp) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
1025
        $rdf = '<'.$this->_type." rdf:about=\"".clean($this->_url)."\"/>\n";
1026
        return $rdf;
1027
    }
1028
}
1029
1030
/**
1031
 * SIOC::Category object
1032
 *
1033
 * Contains information about the category which is object of the sioc:topic property
1034
 */
1035
class SIOCCategory extends SIOCObject {
1036
1037
    var $_url;
1038
    var $_type;
1039
1040
    function SIOCCategory($url, $type = 'sioct:Category') {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
1041
        $this->_url = $url;
1042
          $this->_type = $type;
1043
    }
1044
1045
    function getContent(&$exp) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
1046
        $rdf = '<'.$this->_type." rdf:about=\"".clean($this->_url)."\"/>\n";
1047
        return $rdf;
1048
    }
1049
}
1050
1051
1052
/**
1053
 * "Clean" text
1054
 *
1055
 * Transforms text so that it can be safely put into XML markup
1056
 */
1057
if (!function_exists('clean')) {
1058
  function clean($text, $url = false) {
1059
#    return htmlentities( $text );
1060
#    return htmlentities2( $text );
1061
    // double encoding is preventable now
1062
    // $text = htmlspecialchars_decode($text, ENT_COMPAT);
1063
    if ($url) {
1064
      $text = str_replace('&amp;', '&', $text);
1065
    }
1066
    return htmlspecialchars($text, ENT_COMPAT, 'UTF-8');
1067
  }
1068
}
1069
1070
/**
1071
 * HTML Entities 2
1072
 *
1073
 * Same a HTMLEntities, but avoids double-encoding of entities
1074
 */
1075
if (!function_exists('htmlentities2')) {
1076
  function htmlentities2($myHTML) {
1077
    $translation_table = get_html_translation_table(HTML_ENTITIES, ENT_QUOTES);
1078
    $translation_table[chr(38)] = '&';
1079
    return preg_replace("/&(?![A-Za-z]{0,4}\w{2,3};|#[0-9]{2,3};)/", "&amp;", strtr($myHTML, $translation_table));
1080
    //return htmlentities(strtr(str_replace(' ', '%20', $myHTML), $translation_table));
1081
  }
1082
}
1083
1084
/**
1085
 * pureContent
1086
 *
1087
 * Prepares text-only representation of HTML content
1088
 */
1089
if (!function_exists('pureContent')) {
1090
  function pureContent($content) {
1091
    // Remove HTML tags 
1092
    // May add more cleanup code later, if validation errors are found
1093
    return strip_tags($content);
1094
  }
1095
}
1096
?>
0 ignored issues
show
Best Practice introduced by
It is not recommended to use PHP's closing tag ?> in files other than templates.

Using a closing tag in PHP files that only contain PHP code is not recommended as you might accidentally add whitespace after the closing tag which would then be output by PHP. This can cause severe problems, for example headers cannot be sent anymore.

A simple precaution is to leave off the closing tag as it is not required, and it also has no negative effects whatsoever.

Loading history...
1097