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