Completed
Push — test-vcard ( 6f9394 )
by mw
07:49
created

SRFvCardEntry   A

Complexity

Total Complexity 25

Size/Duplication

Total Lines 115
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 93.55%

Importance

Changes 0
Metric Value
wmc 25
lcom 1
cbo 0
dl 0
loc 115
ccs 58
cts 62
cp 0.9355
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
D __construct() 0 46 10
F text() 0 32 14
A vCardEscape() 0 3 1
1
<?php
2
/**
3
 * Create vCard exports
4
 * @file
5
 * @ingroup SemanticResultFormats
6
 */
7
8
/**
9
 * Printer class for creating vCard exports
10
 * 
11
 * @author Markus Krötzsch
12
 * @author Denny Vrandecic
13
 * @author Frank Dengler
14
 * 
15
 * @ingroup SemanticResultFormats
16
 * 
17
 * TODO: fix the insane case
18
 * TODO: make SRFvCardAddress constructor sane
19
 */
20
class SRFvCard extends SMWExportPrinter {
21
	
22
	protected $m_title = '';
23
	protected $m_description = '';
24
25
	/**
26
	 * @see SMWIExportPrinter::getMimeType
27
	 *
28
	 * @since 1.8
29
	 *
30
	 * @param SMWQueryResult $queryResult
31
	 *
32
	 * @return string
33
	 */
34
	public function getMimeType( SMWQueryResult $queryResult ) {
35
		return 'text/x-vcard';
36
	}
37
38
	/**
39
	 * @see SMWIExportPrinter::getFileName
40
	 *
41
	 * @since 1.8
42
	 *
43
	 * @param SMWQueryResult $queryResult
44
	 *
45
	 * @return string|boolean
46
	 */
47
	public function getFileName( SMWQueryResult $queryResult ) {
48
		if ( $this->getSearchLabel( SMW_OUTPUT_WIKI ) != '' ) {
49
			return str_replace( ' ', '_', $this->getSearchLabel( SMW_OUTPUT_WIKI ) ) . '.vcf';
50
		} else {
51
			return 'vCard.vcf';
52
		}
53
	}
54
55 1
	public function getQueryMode( $context ) {
56 1
		return ( $context == SMWQueryProcessor::SPECIAL_PAGE ) ? SMWQuery::MODE_INSTANCES : SMWQuery::MODE_NONE;
57
	}
58
59
	public function getName() {
60
		return wfMessage( 'srf_printername_vcard' )->text();
61
	}
62
63 1
	protected function getResultText( SMWQueryResult $res, $outputmode ) {
64 1
		global $wgSitename;
65 1
		$result = '';
66 1
		$items = [];
67 1
		if ( $outputmode == SMW_OUTPUT_FILE ) { // make vCard file
68 1
			if ( $this->m_title == '' ) {
69 1
				$this->m_title = $wgSitename;
70
			}
71 1
			$row = $res->getNext();
72 1
			while ( $row !== false ) {
73 1
				$wikipage = $row[0]->getResultSubject(); // get Subject of the Result
74
				// name
75 1
				$prefix = ''; // something like 'Dr.'
76 1
				$firstname = ''; // given name
77 1
				$additionalname = ''; // typically the "middle" name (second first name)
78 1
				$lastname = ''; // family name
79 1
				$suffix = ''; // things like "jun." or "sen."
80 1
				$fullname = ''; // the "formatted name", may be independent from first/lastname & co.
81
				// contacts
82 1
				$emails = [];
83 1
				$tels = [];
84 1
				$addresses = [];
85
				// organisational details:
86 1
				$organization = ''; // any string
87 1
				$jobtitle = '';
88 1
				$role = '';
89 1
				$department = '';
90
				// other stuff
91 1
				$category = '';
92 1
				$birthday = ''; // a date
93 1
				$url = ''; // homepage, a legal URL
94 1
				$note = ''; // any text
95 1
				$workaddress = false;
96 1
				$homeaddress = false;
97
98 1
				$workpostofficebox = '';
99 1
				$workextendedaddress = '';
100 1
				$workstreet = '';
101 1
				$worklocality = '';
102 1
				$workregion = '';
103 1
				$workpostalcode = '';
104 1
				$workcountry = '';
105
106
107 1
				$homepostofficebox = '';
108 1
				$homeextendedaddress = '';
109 1
				$homestreet = '';
110 1
				$homelocality = '';
111 1
				$homeregion = '';
112 1
				$homepostalcode = '';
113 1
				$homecountry = '';
114
115 1
				foreach ( $row as $field ) {
116
					// later we may add more things like a generic
117
					// mechanism to add non-standard vCard properties as well
118
					// (could include funny things like geo, description etc.)
119 1
					$req = $field->getPrintRequest();
120
					
121 1
					switch( strtolower( $req->getLabel() ) ) {
122 1
						case "name":
123 1
							$value = $field->getNextDataValue();
124 1
							if ( $value !== false ) {
125 1
								$fullname = $value->getShortWikiText();
126
							}
127 1
						break;
128
129 1
						case "prefix":
130
							while( $value = $field->getNextDataValue() ) {
131
								$prefix .= ( $prefix ? ',':'' ) . $value->getShortWikiText();
132
							}
133
						break;
134
135 1
						case "suffix":
136
							while( $value = $field->getNextDataValue() ) {
137
								$suffix .= ( $suffix ? ',':'' ) . $value->getShortWikiText();
138
							}
139
						break;
140
141 1
						case "firstname":
142
							$value = $field->getNextDataValue(); // save only the first
143
							if ( $value !== false ) {
144
								$firstname = $value->getShortWikiText();
145
							}
146
						break;
147
148 1
						case "extraname":
149
							while( $value = $field->getNextDataValue() ) {
150
								$additionalname .= ( $additionalname ? ',':'' ) . $value->getShortWikiText();
151
							}
152
						break;
153
154 1
						case "lastname":
155
							$value = $field->getNextDataValue(); // save only the first
156
							if ( $value !== false ) {
157
								$lastname = $value->getShortWikiText();
158
							}
159
						break;
160
161 1
						case "note":
162 1
							while( $value = $field->getNextDataValue() ) {
163 1
								$note .= ( $note ? ', ':'' ) . $value->getShortWikiText();
164
							}
165 1
						break;
166
167 1
						case "email":
168 1
							while( $value = $field->getNextDataValue() ) {
169 1
								$emails[] = new SRFvCardEmail( 'internet', $value->getShortWikiText() );
170
							}
171 1
					 	break;
172
173 1
						case "workphone":
174
							while( $value = $field->getNextDataValue() ) {
175
								$tels[] = new SRFvCardTel( 'WORK', $value->getShortWikiText() );
176
							}
177
					 	break;
178
179 1
						case "cellphone":
180 1
							while( $value = $field->getNextDataValue() ) {
181 1
								$tels[] = new SRFvCardTel( 'CELL', $value->getShortWikiText() );
182
							}
183 1
						break;
184
185 1
						case "homephone":
186 1
							while( $value = $field->getNextDataValue() ) {
187 1
								$tels[] = new SRFvCardTel( 'HOME', $value->getShortWikiText() );
188
							}
189 1
						break;
190
191 1
						case "organization":
192
							$value = $field->getNextDataValue();
193
							if ( $value !== false ) {
194
								$organization = $value->getShortWikiText();
195
							}
196
						break;
197
198 1
						case "workpostofficebox":
199
							$value = $field->getNextDataValue();
200
							if ( $value !== false ) {
201
								$workpostofficebox = $value->getShortWikiText();
202
								$workaddress = true;
203
							}
204
						break;
205
206 1
						case "workextendedaddress":
207
							$value = $field->getNextDataValue();
208
							if ( $value !== false ) {
209
								$workextendedaddress = $value->getShortWikiText();
210
								$workaddress = true;
211
							}
212
						break;
213
214 1
						case "workstreet":
215
							$value = $field->getNextDataValue();
216
							if ( $value !== false ) {
217
								$workstreet = $value->getShortWikiText();
218
								$workaddress = true;
219
							}
220
						break;
221
222 1
						case "worklocality":
223
							$value = $field->getNextDataValue();
224
							if ( $value !== false ) {
225
								$worklocality = $value->getShortWikiText();
226
								$workaddress = true;
227
							}
228
						break;
229
230 1
						case "workregion":
231
							$value = $field->getNextDataValue();
232
							if ( $value !== false ) {
233
								$workregion = $value->getShortWikiText();
234
								$workaddress = true;
235
							}
236
						break;
237
238 1
						case "workpostalcode":
239
							$value = $field->getNextDataValue();
240
							if ( $value !== false ) {
241
								$workpostalcode = $value->getShortWikiText();
242
								$workaddress = true;
243
							}
244
						break;
245
246 1
						case "workcountry":
247
							$value = $field->getNextDataValue();
248
							if ( $value !== false ) {
249
								$workcountry = $value->getShortWikiText();
250
								$workaddress = true;
251
							}
252
						break;
253
254 1
						case "homepostofficebox":
255
							$value = $field->getNextDataValue();
256
							if ( $value !== false ) {
257
								$homepostofficebox = $value->getShortWikiText();
258
								$homeaddress = true;
259
							}
260
						break;
261
262 1
						case "homeextendedaddress":
263
							$value = $field->getNextDataValue();
264
							if ( $value !== false ) {
265
								$homeextendedaddress = $value->getShortWikiText();
266
								$homeaddress = true;
267
							}
268
						break;
269
270 1
						case "homestreet":
271 1
							$value = $field->getNextDataValue();
272 1
							if ( $value !== false ) {
273 1
								$homestreet = $value->getShortWikiText();
274 1
								$homeaddress = true;
275
							}
276 1
						break;
277
278 1
						case "homelocality":
279 1
							$value = $field->getNextDataValue();
280 1
							if ( $value !== false ) {
281 1
								$homelocality = $value->getShortWikiText();
282 1
								$homeaddress = true;
283
							}
284 1
						break;
285
286 1
						case "homeregion":
287
							$value = $field->getNextDataValue();
288
							if ( $value !== false ) {
289
								$homeregion = $value->getShortWikiText();
290
								$homeaddress = true;
291
							}
292
						break;
293
294 1
						case "homepostalcode":
295
							$value = $field->getNextDataValue();
296
							if ( $value !== false ) {
297
								$homepostalcode = $value->getShortWikiText();
298
								$homeaddress = true;
299
							}
300
						break;
301
302 1
						case "homecountry":
303
							$value = $field->getNextDataValue();
304
							if ( $value !== false ) {
305
								$homecountry = $value->getShortWikiText();
306
								$homeaddress = true;
307
							}
308
						break;
309
310 1
						case "birthday":
311 1
							if ( $req->getTypeID() == "_dat" )  {
312 1
								$value = $field->getNextDataValue();
313 1
								if ( $value !== false ) {
314 1
									$birthday =  $value->getXMLSchemaDate();
315
								}
316
							}
317 1
						break;
318
319 1
						case "homepage":
320 1
							if ( $req->getTypeID() == "_uri" )  {
321 1
								$value = $field->getNextDataValue();
322 1
								if ( $value !== false ) {
323 1
									$url =  $value->getWikiValue();
324
								}
325
							}
326 1
						break;
327
					}
328
				}
329 1
				$pagetitle = $wikipage->getTitle();
330 1
				if ( $workaddress ) $addresses[] = new SRFvCardAddress ( 'WORK', $workpostofficebox, $workextendedaddress, $workstreet, $worklocality, $workregion, $workpostalcode, $workcountry );
331 1
				if ( $homeaddress ) $addresses[] = new SRFvCardAddress ( 'HOME', $homepostofficebox, $homeextendedaddress, $homestreet, $homelocality, $homeregion, $homepostalcode, $homecountry );
332 1
				$items[] = new SRFvCardEntry( $pagetitle, $prefix, $firstname, $lastname, $additionalname, $suffix, $fullname, $tels, $addresses, $emails, $birthday, $jobtitle, $role, $organization, $department, $category, $url, $note );
333 1
            	$row = $res->getNext();
334
			}
335 1
            foreach ( $items as $item ) {
336 1
				$result .= $item->text();
337
			}
338
		} else { // just make link to vcard
339
			if ( $this->getSearchLabel( $outputmode ) ) {
340
				$label = $this->getSearchLabel( $outputmode );
341
			} else {
342
				$label = wfMessage( 'srf_vcard_link' )->inContentLanguage()->text();
343
			}
344
			$link = $res->getQueryLink( $label );
0 ignored issues
show
Deprecated Code introduced by
The method SMWQueryResult::getQueryLink() has been deprecated with message: since SMW 1.8

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
345
			$link->setParameter( 'vcard', 'format' );
346
			if ( $this->getSearchLabel( SMW_OUTPUT_WIKI ) != '' ) {
347
				$link->setParameter( $this->getSearchLabel( SMW_OUTPUT_WIKI ), 'searchlabel' );
348
			}
349
			if ( array_key_exists( 'limit', $this->m_params ) ) {
350
				$link->setParameter( $this->m_params['limit'], 'limit' );
351
			} else { // use a reasonable default limit
352
				$link->setParameter( 20, 'limit' );
353
			}
354
			$result .= $link->getText( $outputmode, $this->mLinker );
355
			$this->isHTML = ( $outputmode == SMW_OUTPUT_HTML ); // yes, our code can be viewed as HTML if requested, no more parsing needed
356
		}
357 1
		return $result;
358
	}
359
}
360
361
/**
362
 * Represents a single entry in an vCard
363
 * @ingroup SemanticResultFormats
364
 */
365
class SRFvCardEntry {
366
	private $uri;
367
	private $label;
368
	private $fullname;
0 ignored issues
show
Unused Code introduced by
The property $fullname is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
369
	private $firstname;
370
	private $lastname;
371
	private $additionalname;
372
	private $prefix;
373
	private $suffix;
374
	private $tels = [];
375
	private $addresses = [];
376
	private $emails = [];
377
	private $birthday;
378
	private $dtstamp;
379
	private $title;
380
	private $role;
381
	private $organization;
382
	private $department;
383
	private $category;
384
	private $note;
385
386
	/**
387
	 * Constructor for a single item in the vcard. Requires the URI of the item.
388
	 */
389 1
	public function __construct( Title $t, $prefix, $firstname, $lastname, $additionalname, $suffix, $fullname, $tels, $addresses, $emails, $birthday, $jobtitle, $role, $organization, $department, $category, $url, $note ) {
390 1
		$this->uri = $t->getFullURL();
391 1
		$this->url = $url;
0 ignored issues
show
Bug introduced by
The property url does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
392
		// read fullname or guess it in a simple way from other names that are given
393 1
		if ( $fullname != '' ) {
394 1
			$this->label = $fullname;
395 1
		} elseif ( $firstname . $lastname != '' ) {
396
			$this->label = $firstname . ( ( ( $firstname != '' ) && ( $lastname != '' ) ) ? ' ':'' ) .  $lastname;
397
		} else {
398 1
			$this->label = $t->getText();
399
		}
400 1
		$this->label = SRFVCardEntry::vCardEscape( $this->label );
401
		// read firstname and lastname, or guess it from other names that are given
402 1
		if ( $firstname . $lastname == '' ) { // guessing needed
403 1
			$nameparts = explode( ' ', $this->label );
404
			// Accepted forms for guessing:
405
			// "Lastname"
406
			// "Firstname Lastname"
407
			// "Firstname <Additionalnames> Lastname"
408 1
			$this->lastname = SRFvCardEntry::vCardEscape( array_pop( $nameparts ) );
0 ignored issues
show
Coding Style introduced by
As per coding style, self should be used for accessing local static members.

This check looks for accesses to local static members using the fully qualified name instead of self::.

<?php

class Certificate {
    const TRIPLEDES_CBC = 'ASDFGHJKL';

    private $key;

    public function __construct()
    {
        $this->key = Certificate::TRIPLEDES_CBC;
    }
}

While this is perfectly valid, the fully qualified name of Certificate::TRIPLEDES_CBC could just as well be replaced by self::TRIPLEDES_CBC. Referencing local members with self:: assured the access will still work when the class is renamed, makes it perfectly clear that the member is in fact local and will usually be shorter.

Loading history...
409 1
			if ( count( $nameparts ) > 0 ) $this->firstname = SRFvCardEntry::vCardEscape( array_shift( $nameparts ) );
0 ignored issues
show
Coding Style introduced by
As per coding style, self should be used for accessing local static members.

This check looks for accesses to local static members using the fully qualified name instead of self::.

<?php

class Certificate {
    const TRIPLEDES_CBC = 'ASDFGHJKL';

    private $key;

    public function __construct()
    {
        $this->key = Certificate::TRIPLEDES_CBC;
    }
}

While this is perfectly valid, the fully qualified name of Certificate::TRIPLEDES_CBC could just as well be replaced by self::TRIPLEDES_CBC. Referencing local members with self:: assured the access will still work when the class is renamed, makes it perfectly clear that the member is in fact local and will usually be shorter.

Loading history...
410 1
			foreach ( $nameparts as $name ) {
411 1
				$this->additionalname .= ( $this->additionalname != '' ? ',':'' ) . SRFvCardEntry::vCardEscape( $name );
0 ignored issues
show
Coding Style introduced by
As per coding style, self should be used for accessing local static members.

This check looks for accesses to local static members using the fully qualified name instead of self::.

<?php

class Certificate {
    const TRIPLEDES_CBC = 'ASDFGHJKL';

    private $key;

    public function __construct()
    {
        $this->key = Certificate::TRIPLEDES_CBC;
    }
}

While this is perfectly valid, the fully qualified name of Certificate::TRIPLEDES_CBC could just as well be replaced by self::TRIPLEDES_CBC. Referencing local members with self:: assured the access will still work when the class is renamed, makes it perfectly clear that the member is in fact local and will usually be shorter.

Loading history...
412
			}
413
		} else {
414
			$this->firstname = SRFvCardEntry::vCardEscape( $firstname );
0 ignored issues
show
Coding Style introduced by
As per coding style, self should be used for accessing local static members.

This check looks for accesses to local static members using the fully qualified name instead of self::.

<?php

class Certificate {
    const TRIPLEDES_CBC = 'ASDFGHJKL';

    private $key;

    public function __construct()
    {
        $this->key = Certificate::TRIPLEDES_CBC;
    }
}

While this is perfectly valid, the fully qualified name of Certificate::TRIPLEDES_CBC could just as well be replaced by self::TRIPLEDES_CBC. Referencing local members with self:: assured the access will still work when the class is renamed, makes it perfectly clear that the member is in fact local and will usually be shorter.

Loading history...
415
			$this->lastname = SRFvCardEntry::vCardEscape( $lastname );
0 ignored issues
show
Coding Style introduced by
As per coding style, self should be used for accessing local static members.

This check looks for accesses to local static members using the fully qualified name instead of self::.

<?php

class Certificate {
    const TRIPLEDES_CBC = 'ASDFGHJKL';

    private $key;

    public function __construct()
    {
        $this->key = Certificate::TRIPLEDES_CBC;
    }
}

While this is perfectly valid, the fully qualified name of Certificate::TRIPLEDES_CBC could just as well be replaced by self::TRIPLEDES_CBC. Referencing local members with self:: assured the access will still work when the class is renamed, makes it perfectly clear that the member is in fact local and will usually be shorter.

Loading history...
416
		}
417 1
		if ( $additionalname != '' ) $this->additionalname = $additionalname; // no escape, can be a value list
418
			// ^ overwrite above guessing in that case
419 1
		$this->prefix = SRFvCardEntry::vCardEscape( $prefix );
0 ignored issues
show
Coding Style introduced by
As per coding style, self should be used for accessing local static members.

This check looks for accesses to local static members using the fully qualified name instead of self::.

<?php

class Certificate {
    const TRIPLEDES_CBC = 'ASDFGHJKL';

    private $key;

    public function __construct()
    {
        $this->key = Certificate::TRIPLEDES_CBC;
    }
}

While this is perfectly valid, the fully qualified name of Certificate::TRIPLEDES_CBC could just as well be replaced by self::TRIPLEDES_CBC. Referencing local members with self:: assured the access will still work when the class is renamed, makes it perfectly clear that the member is in fact local and will usually be shorter.

Loading history...
420 1
		$this->suffix = SRFvCardEntry::vCardEscape( $suffix );
0 ignored issues
show
Coding Style introduced by
As per coding style, self should be used for accessing local static members.

This check looks for accesses to local static members using the fully qualified name instead of self::.

<?php

class Certificate {
    const TRIPLEDES_CBC = 'ASDFGHJKL';

    private $key;

    public function __construct()
    {
        $this->key = Certificate::TRIPLEDES_CBC;
    }
}

While this is perfectly valid, the fully qualified name of Certificate::TRIPLEDES_CBC could just as well be replaced by self::TRIPLEDES_CBC. Referencing local members with self:: assured the access will still work when the class is renamed, makes it perfectly clear that the member is in fact local and will usually be shorter.

Loading history...
421 1
		$this->tels = $tels;
422 1
		$this->addresses = $addresses;
423 1
		$this->emails = $emails;
424 1
		$this->birthday = $birthday;
425 1
		$this->title = SRFvCardEntry::vCardEscape( $jobtitle );
0 ignored issues
show
Coding Style introduced by
As per coding style, self should be used for accessing local static members.

This check looks for accesses to local static members using the fully qualified name instead of self::.

<?php

class Certificate {
    const TRIPLEDES_CBC = 'ASDFGHJKL';

    private $key;

    public function __construct()
    {
        $this->key = Certificate::TRIPLEDES_CBC;
    }
}

While this is perfectly valid, the fully qualified name of Certificate::TRIPLEDES_CBC could just as well be replaced by self::TRIPLEDES_CBC. Referencing local members with self:: assured the access will still work when the class is renamed, makes it perfectly clear that the member is in fact local and will usually be shorter.

Loading history...
426 1
		$this->role = SRFvCardEntry::vCardEscape( $role );
0 ignored issues
show
Coding Style introduced by
As per coding style, self should be used for accessing local static members.

This check looks for accesses to local static members using the fully qualified name instead of self::.

<?php

class Certificate {
    const TRIPLEDES_CBC = 'ASDFGHJKL';

    private $key;

    public function __construct()
    {
        $this->key = Certificate::TRIPLEDES_CBC;
    }
}

While this is perfectly valid, the fully qualified name of Certificate::TRIPLEDES_CBC could just as well be replaced by self::TRIPLEDES_CBC. Referencing local members with self:: assured the access will still work when the class is renamed, makes it perfectly clear that the member is in fact local and will usually be shorter.

Loading history...
427 1
		$this->organization = SRFvCardEntry::vCardEscape( $organization );
0 ignored issues
show
Coding Style introduced by
As per coding style, self should be used for accessing local static members.

This check looks for accesses to local static members using the fully qualified name instead of self::.

<?php

class Certificate {
    const TRIPLEDES_CBC = 'ASDFGHJKL';

    private $key;

    public function __construct()
    {
        $this->key = Certificate::TRIPLEDES_CBC;
    }
}

While this is perfectly valid, the fully qualified name of Certificate::TRIPLEDES_CBC could just as well be replaced by self::TRIPLEDES_CBC. Referencing local members with self:: assured the access will still work when the class is renamed, makes it perfectly clear that the member is in fact local and will usually be shorter.

Loading history...
428 1
		$this->department = SRFvCardEntry::vCardEscape( $department );
0 ignored issues
show
Coding Style introduced by
As per coding style, self should be used for accessing local static members.

This check looks for accesses to local static members using the fully qualified name instead of self::.

<?php

class Certificate {
    const TRIPLEDES_CBC = 'ASDFGHJKL';

    private $key;

    public function __construct()
    {
        $this->key = Certificate::TRIPLEDES_CBC;
    }
}

While this is perfectly valid, the fully qualified name of Certificate::TRIPLEDES_CBC could just as well be replaced by self::TRIPLEDES_CBC. Referencing local members with self:: assured the access will still work when the class is renamed, makes it perfectly clear that the member is in fact local and will usually be shorter.

Loading history...
429 1
		$this->category = $category; // allow non-escaped "," in here for making a list of categories
430 1
		$this->note = SRFvCardEntry::vCardEscape( $note );
0 ignored issues
show
Coding Style introduced by
As per coding style, self should be used for accessing local static members.

This check looks for accesses to local static members using the fully qualified name instead of self::.

<?php

class Certificate {
    const TRIPLEDES_CBC = 'ASDFGHJKL';

    private $key;

    public function __construct()
    {
        $this->key = Certificate::TRIPLEDES_CBC;
    }
}

While this is perfectly valid, the fully qualified name of Certificate::TRIPLEDES_CBC could just as well be replaced by self::TRIPLEDES_CBC. Referencing local members with self:: assured the access will still work when the class is renamed, makes it perfectly clear that the member is in fact local and will usually be shorter.

Loading history...
431
432 1
		$article = new Article( $t );
433 1
		$this->dtstamp  = $article->getTimestamp();
434 1
	}
435
436
437
	/**
438
	 * Creates the vCard output for a single item.
439
	 * 
440
	 * CAUTION: this might hurt your eyes
441
	 */
442 1
	public function text() {
443 1
		$text  = "BEGIN:VCARD\r\n";
444 1
		$text .= "VERSION:3.0\r\n";
445
		// N and FN are required properties in vCard 3.0, we need to write something there
446 1
		$text .= "N;CHARSET=UTF-8:$this->lastname;$this->firstname;$this->additionalname;$this->prefix;$this->suffix\r\n";
447 1
		$text .= "FN;CHARSET=UTF-8:$this->label\r\n";
448
		// heuristic for setting confidentiality level of vCard:
449 1
		global $wgGroupPermissions;
450 1
		if ( ( array_key_exists( '*', $wgGroupPermissions ) ) &&
451 1
		     ( array_key_exists( 'read', $wgGroupPermissions['*'] ) ) ) {
452 1
			$public = $wgGroupPermissions['*']['read'];
453
		} else {
454
			$public = true;
455
		}
456 1
		$text .= ( $public ? 'CLASS:PUBLIC':'CLASS:CONFIDENTIAL' ) . "\r\n";
457 1
		if ( $this->birthday !== "" ) $text .= "BDAY:$this->birthday\r\n";
458 1
		if ( $this->title !== "" ) $text .= "TITLE;CHARSET=UTF-8:$this->title\r\n";
459 1
		if ( $this->role !== "" ) $text .= "ROLE;CHARSET=UTF-8:$this->role\r\n";
460 1
		if ( $this->organization !== "" ) $text .= "ORG;CHARSET=UTF-8:$this->organization;$this->department\r\n";
461 1
		if ( $this->category !== "" ) $text .= "CATEGORIES;CHARSET=UTF-8:$this->category\r\n";
462 1
		foreach ( $this->emails as $entry ) $text .= $entry->createVCardEmailText();
463 1
		foreach ( $this->addresses as $entry ) $text .= $entry->createVCardAddressText();
464 1
		foreach ( $this->tels as $entry ) $text .= $entry->createVCardTelText();
465 1
		if ( $this->note !== "" ) $text .= "NOTE;CHARSET=UTF-8:$this->note\r\n";
466 1
		$text .= "SOURCE;CHARSET=UTF-8:$this->uri\r\n";
467 1
		$text .= "PRODID:-////Semantic MediaWiki\r\n";
468 1
		$text .= "REV:$this->dtstamp\r\n";
469 1
		$text .= "URL:" . ( $this->url ? $this->url:$this->uri ) . "\r\n";
470 1
		$text .= "UID:$this->uri\r\n";
471 1
		$text .= "END:VCARD\r\n";
472 1
		return $text;
473
	}
474
475 1
	public static function vCardEscape( $text ) {
476 1
		return str_replace( [ '\\', ',', ':', ';' ], [ '\\\\', '\,', '\:', '\;' ], $text );
477
	}
478
479
}
480
481
/**
482
 * Represents a single address entry in an vCard entry.
483
 * @ingroup SemanticResultFormats
484
 */
485
class SRFvCardAddress {
486
	private $type;
487
	private $postofficebox;
488
	private $extendedaddress;
489
	private $street;
490
	private $locality;
491
	private $region;
492
	private $postalcode;
493
	private $country;
494
495
	/**
496
	 * Constructor for a single address item in the vcard item.
497
	 */
498 1
	public function __construct( $type, $postofficebox, $extendedaddress, $street, $locality, $region, $postalcode, $country ) {
499 1
		$this->type = $type;
500 1
		$this->postofficebox = SRFvCardEntry::vCardEscape( $postofficebox );
501 1
		$this->extendedaddress = SRFvCardEntry::vCardEscape( $extendedaddress );
502 1
		$this->street = SRFvCardEntry::vCardEscape( $street );
503 1
		$this->locality = SRFvCardEntry::vCardEscape( $locality );
504 1
		$this->region = SRFvCardEntry::vCardEscape( $region );
505 1
		$this->postalcode = SRFvCardEntry::vCardEscape( $postalcode );
506 1
		$this->country = SRFvCardEntry::vCardEscape( $country );
507 1
	}
508
509
	/**
510
	 * Creates the vCard output for a single address item.
511
	 */
512 1
	public function createVCardAddressText() {
513 1
		if ( $this->type == "" ) $this->type = "work";
514 1
		$text  =  "ADR;TYPE=$this->type;CHARSET=UTF-8:$this->postofficebox;$this->extendedaddress;$this->street;$this->locality;$this->region;$this->postalcode;$this->country\r\n";
515 1
		return $text;
516
	}
517
}
518
519
/**
520
 * Represents a single telephone entry in an vCard entry.
521
 * @ingroup SemanticResultFormats
522
 */
523
class SRFvCardTel {
524
	private $type;
525
	private $telnumber;
526
527
	/**
528
	 * Constructor for a single telephone item in the vcard item.
529
	 */
530 1
	public function __construct( $type, $telnumber ) {
531 1
		$this->type = $type;  // may be a vCard value list using ",", no escaping
532 1
		$this->telnumber = SRFvCardEntry::vCardEscape( $telnumber ); // escape to be sure
533 1
	}
534
535
	/**
536
	 * Creates the vCard output for a single telephone item.
537
	 */
538 1
	public function createVCardTelText() {
539 1
		if ( $this->type == "" ) $this->type = "work";
540 1
		$text  =  "TEL;TYPE=$this->type:$this->telnumber\r\n";
541 1
		return $text;
542
	}
543
}
544
545
/**
546
 * Represents a single email entry in an vCard entry.
547
 * @ingroup SemanticResultFormats
548
 */
549
class SRFvCardEmail {
550
	private $type;
551
	private $emailaddress;
552
553
	/**
554
	 * Constructor for a email telephone item in the vcard item.
555
	 */
556 1
	public function __construct( $type, $emailaddress ) {
557 1
		$this->type = $type;
558 1
		$this->emailaddress = $emailaddress; // no escape, normally not needed anyway
559 1
	}
560
561
	/**
562
	 * Creates the vCard output for a single email item.
563
	 */
564 1
	public function createVCardEmailText() {
565 1
		if ( $this->type == "" ) $this->type = "internet";
566 1
		$text  =  "EMAIL;TYPE=$this->type:$this->emailaddress\r\n";
567 1
		return $text;
568
	}
569
}
570