Completed
Push — develop ( df3f0b...88eeb8 )
by David
07:56 queued 02:04
created

Wordlift_Schema_Service::get_person_schema()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 71
Code Lines 51

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 51
nc 1
nop 0
dl 0
loc 71
rs 9.1369
c 0
b 0
f 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
/**
4
 * Provides constants and methods related to WordLift's schema.
5
 *
6
 * @since 3.1.0
7
 */
8
class Wordlift_Schema_Service {
9
10
	/**
11
	 * The 'location created' field name.
12
	 *
13
	 * @since 3.5.0
14
	 */
15
	const FIELD_LOCATION_CREATED = 'wl_location_created';
16
17
	/**
18
	 * The 'topic' field name.
19
	 *
20
	 * @since 3.5.0
21
	 */
22
	const FIELD_TOPIC = 'wl_topic';
23
24
	/**
25
	 * The 'author' field name.
26
	 *
27
	 * @since 3.1.0
28
	 */
29
	const FIELD_AUTHOR = 'wl_author';
30
31
	/**
32
	 * The 'same as' field name.
33
	 *
34
	 * @since 3.1.0
35
	 */
36
	const FIELD_SAME_AS = 'entity_same_as';
37
38
	/**
39
	 * The 'date start' field name.
40
	 *
41
	 * @since 3.1.0
42
	 */
43
	const FIELD_DATE_START = 'wl_cal_date_start';
44
45
	/**
46
	 * The 'date end' field name.
47
	 *
48
	 * @since 3.1.0
49
	 */
50
	const FIELD_DATE_END = 'wl_cal_date_end';
51
52
	/**
53
	 * The 'location' field name.
54
	 *
55
	 * @since 3.1.0
56
	 */
57
	const FIELD_LOCATION = 'wl_location';
58
59
	/**
60
	 * The 'founder' field name.
61
	 *
62
	 * @since 3.1.0
63
	 */
64
	const FIELD_FOUNDER = 'wl_founder';
65
66
	/**
67
	 * The 'knows' field name.
68
	 *
69
	 * @since 3.1.0
70
	 */
71
	const FIELD_KNOWS = 'wl_knows';
72
73
	/**
74
	 * The 'birth date' field name.
75
	 *
76
	 * @since 3.1.0
77
	 */
78
	const FIELD_BIRTH_DATE = 'wl_birth_date';
79
80
	/**
81
	 * The 'birth place' field name.
82
	 *
83
	 * @since 3.1.0
84
	 */
85
	const FIELD_BIRTH_PLACE = 'wl_birth_place';
86
87
	/**
88
	 * The 'latitude' field name.
89
	 *
90
	 * @since 3.1.0
91
	 */
92
	const FIELD_GEO_LATITUDE = 'wl_geo_latitude';
93
94
	/**
95
	 * The 'longitude' field name.
96
	 *
97
	 * @since 3.1.0
98
	 */
99
	const FIELD_GEO_LONGITUDE = 'wl_geo_longitude';
100
101
	/**
102
	 * The 'streetAddress' field name.
103
	 *
104
	 * @since 3.1.0
105
	 */
106
	const FIELD_ADDRESS = 'wl_address';
107
108
	/**
109
	 * The 'postOfficeBoxNumber' field name.
110
	 *
111
	 * @since 3.3.0
112
	 */
113
	const FIELD_ADDRESS_PO_BOX = 'wl_address_post_office_box';
114
115
	/**
116
	 * The 'postalCode' field name.
117
	 *
118
	 * @since 3.3.0
119
	 */
120
	const FIELD_ADDRESS_POSTAL_CODE = 'wl_address_postal_code';
121
122
	/**
123
	 * The 'addressLocality' field name.
124
	 *
125
	 * @since 3.3.0
126
	 */
127
	const FIELD_ADDRESS_LOCALITY = 'wl_address_locality';
128
	/**
129
	 * The 'addressRegion' field name.
130
	 *
131
	 * @since 3.3.0
132
	 */
133
	const FIELD_ADDRESS_REGION = 'wl_address_region';
134
135
	/**
136
	 * The 'addressCountry' field name.
137
	 *
138
	 * @since 3.3.0
139
	 */
140
	const FIELD_ADDRESS_COUNTRY = 'wl_address_country';
141
142
	/**
143
	 * The 'entity type' field name.
144
	 *
145
	 * @since 3.1.0
146
	 */
147
	const FIELD_ENTITY_TYPE = 'wl_entity_type_uri';
148
149
	/**
150
	 * The 'email' field name.
151
	 *
152
	 * @since 3.2.0
153
	 */
154
	const FIELD_EMAIL = 'wl_email';
155
156
	/**
157
	 * The 'affiliation' field name.
158
	 *
159
	 * @since 3.2.0
160
	 */
161
	const FIELD_AFFILIATION = 'wl_affiliation';
162
163
	/**
164
	 * The 'URI' data type name.
165
	 *
166
	 * @since 3.1.0
167
	 */
168
	const DATA_TYPE_URI = 'uri';
169
170
	/**
171
	 * The 'date' data type name.
172
	 *
173
	 * @since 3.1.0
174
	 */
175
	const DATA_TYPE_DATE = 'date';
176
177
	/**
178
	 * The 'double' data type name.
179
	 *
180
	 * @since 3.1.0
181
	 */
182
	const DATA_TYPE_DOUBLE = 'double';
183
184
	/**
185
	 * The 'string' data type name.
186
	 *
187
	 * @since 3.1.0
188
	 */
189
	const DATA_TYPE_STRING = 'string';
190
191
	/**
192
	 * The 'integer' data type name.
193
	 *
194
	 * @since 3.1.0
195
	 */
196
	const DATA_TYPE_INTEGER = 'int';
197
198
	/**
199
	 * The 'boolean' data type name.
200
	 *
201
	 * @since 3.1.0
202
	 */
203
	const DATA_TYPE_BOOLEAN = 'bool';
204
205
	/**
206
	 * The schema.org Event type URI.
207
	 *
208
	 * @since 3.1.0
209
	 */
210
	const SCHEMA_EVENT_TYPE = 'http://schema.org/Event';
211
212
	/**
213
	 * The Schema service singleton instance.
214
	 *
215
	 * @since 3.1.0
216
	 * @access private
217
	 * @var \Wordlift_Schema_Service $instance The Schema service singleton instance.
218
	 */
219
	private static $instance;
220
221
	/**
222
	 * WordLift's schema.
223
	 *
224
	 * @since 3.1.0
225
	 * @access private
226
	 * @var array $schema WordLift's schema.
227
	 */
228
	private $schema;
229
230
	/**
231
	 * The Log service.
232
	 *
233
	 * @since 3.1.0
234
	 * @access private
235
	 * @var \Wordlift_Log_Service $log_service The Log service.
236
	 */
237
	private $log_service;
238
239
	/**
240
	 * Wordlift_Schema_Service constructor.
241
	 *
242
	 * @since 3.1.0
243
	 */
244
	public function __construct() {
245
246
		$this->log_service = Wordlift_Log_Service::get_logger( 'Wordlift_Schema_Service' );
247
248
		// Create a singleton instance of the Schema service, useful to provide static functions to global functions.
249
		self::$instance = $this;
250
251
		// Set the taxonomy data.
252
		// Note: parent types must be defined before child types.
253
		$this->schema = array(
254
			'thing'         => $this->get_thing_schema(),
255
			'creative-work' => $this->get_creative_work_schema(),
256
			'event'         => $this->get_event_schema(),
257
			'organization'  => $this->get_organization_schema(),
258
			'person'        => $this->get_person_schema(),
259
			'place'         => $this->get_place_schema(),
260
			'localbusiness' => $this->get_local_business_schema()
261
		);
262
263
	}
264
265
	/**
266
	 * Get a reference to the Schema service.
267
	 *
268
	 * @since 3.1.0
269
	 *
270
	 * @return Wordlift_Schema_Service A reference to the Schema service.
271
	 */
272
	public static function get_instance() {
273
274
		return self::$instance;
275
	}
276
277
	/**
278
	 * Get the properties for a field with the specified key. The key is used as
279
	 * meta key when the field's value is stored in WordPress meta data table.
280
	 *
281
	 * @since 3.6.0
282
	 *
283
	 * @param string $key The field's key.
284
	 *
285
	 * @return null|array An array of field's properties or null if the field is not found.
286
	 */
287
	public function get_field( $key ) {
288
289
		// Parse each schema's fields until we find the one we're looking for, then
290
		// return its properties.
291
		foreach ( $this->schema as $_ => $schema ) {
292
293
			if ( ! isset( $schema['custom_fields'] ) ) {
294
				break;
295
			}
296
297
			foreach ( $schema['custom_fields'] as $field => $props ) {
298
				if ( $key === $field ) {
299
					return $props;
300
				}
301
			}
302
		}
303
304
		return NULL;
305
	}
306
307
	/**
308
	 * Get the WordLift's schema.
309
	 *
310
	 * @param string $name The schema name.
311
	 *
312
	 * @return array|null An array with the schema configuration or NULL if the schema is not found.
313
	 *
314
	 * @since 3.1.0
315
	 */
316
	public function get_schema( $name ) {
317
318
		// $this->log_service->trace( "Get schema [ name :: $name ]" );
0 ignored issues
show
Unused Code Comprehensibility introduced by
59% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
319
320
		// Check if the schema exists and, if not, return NULL.
321
		if ( ! isset( $this->schema[ $name ] ) ) {
322
			return NULL;
323
		}
324
325
		// Return the requested schema.
326
		return $this->schema[ $name ];
327
	}
328
329
	/**
330
	 * Get the WordLift's schema trough schema type uri.
331
	 *
332
	 * @param string $uri The schema uri.
333
	 *
334
	 * @return array|null An array with the schema configuration or NULL if the schema is not found.
335
	 *
336
	 * @since 3.3.0
337
	 */
338
	public function get_schema_by_uri( $uri ) {
339
340
		foreach ( $this->schema as $name => $schema ) {
341
			if ( $schema['uri'] === $uri ) {
342
				return $schema;
343
			}
344
		}
345
346
		return NULL;
347
348
		// Return the requested schema.
349
		return $this->schema[ $name ];
0 ignored issues
show
Unused Code introduced by
// Return the requested ...n $this->schema[$name]; does not seem to be reachable.

This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.

Unreachable code is most often the result of return, die or exit statements that have been added for debug purposes.

function fx() {
    try {
        doSomething();
        return true;
    }
    catch (\Exception $e) {
        return false;
    }

    return false;
}

In the above example, the last return false will never be executed, because a return statement has already been met in every possible execution path.

Loading history...
350
	}
351
352
	/**
353
	 * Get the 'thing' schema.
354
	 *
355
	 * @return array An array with the schema configuration.
356
	 *
357
	 * @since 3.1.0
358
	 */
359
	private function get_thing_schema() {
360
361
		return array(
362
			'css_class'          => 'wl-thing',
363
			'uri'                => 'http://schema.org/Thing',
364
			'same_as'            => array( '*' ),
365
			// set as default.
366
			'custom_fields'      => array(
367
				self::FIELD_SAME_AS                            => array(
368
					'predicate'   => 'http://schema.org/sameAs',
369
					'type'        => self::DATA_TYPE_URI,
370
					'export_type' => 'http://schema.org/Thing',
371
					'constraints' => array(
372
						'cardinality' => INF
373
					),
374
					'input_field' => 'sameas'   // we need a custom metabox
375
				),
376
				// Add the schema:url property.
377
				Wordlift_Schema_Url_Property_Service::META_KEY => Wordlift_Schema_Url_Property_Service::get_instance()
0 ignored issues
show
Deprecated Code introduced by
The method Wordlift_Property_Service::get_compat_definition() has been deprecated.

This method has been deprecated.

Loading history...
378
				                                                                                      ->get_compat_definition()
379
			),
380
			// {{sameAs}} not present in the microdata template,
381
			// because it is treated separately in *wl_content_embed_item_microdata*
382
			'microdata_template' => '',
383
			'templates'          => array(
384
				'subtitle' => '{{id}}'
385
			)
386
		);
387
388
	}
389
390
	/**
391
	 * Get the 'creative work' schema.
392
	 *
393
	 * @return array An array with the schema configuration.
394
	 *
395
	 * @since 3.1.0
396
	 */
397
	private function get_creative_work_schema() {
398
399
		$schema = array(
400
			'label'              => 'CreativeWork',
401
			'description'        => 'A creative work (or a Music Album).',
402
			'parents'            => array( 'thing' ),
403
			// give term slug as parent
404
			'css_class'          => 'wl-creative-work',
405
			'uri'                => 'http://schema.org/CreativeWork',
406
			'same_as'            => array(
407
				'http://schema.org/MusicAlbum',
408
				'http://schema.org/Product'
409
			),
410
			'custom_fields'      => array(
411
				self::FIELD_AUTHOR => array(
412
					'predicate'   => 'http://schema.org/author',
413
					'type'        => self::DATA_TYPE_URI,
414
					'export_type' => 'http://schema.org/Person',
415
					'constraints' => array(
416
						'uri_type'    => array( 'Person', 'Organization' ),
417
						'cardinality' => INF
418
					)
419
				),
420
			),
421
			'microdata_template' => '{{author}}',
422
			'templates'          => array(
423
				'subtitle' => '{{id}}'
424
			)
425
		);
426
427
		// Merge the custom fields with those provided by the thing schema.
428
		$thing_schema            = $this->get_thing_schema();
429
		$schema['custom_fields'] = array_merge( $schema['custom_fields'], $thing_schema['custom_fields'] );
430
431
		return $schema;
432
	}
433
434
	/**
435
	 * Get the 'event' schema.
436
	 *
437
	 * @return array An array with the schema configuration.
438
	 *
439
	 * @since 3.1.0
440
	 */
441
	private function get_event_schema() {
442
443
		$schema = array(
444
			'label'              => 'Event',
445
			'description'        => 'An event . ',
446
			'parents'            => array( 'thing' ),
447
			'css_class'          => 'wl-event',
448
			'uri'                => self::SCHEMA_EVENT_TYPE,
449
			'same_as'            => array( 'http://dbpedia.org/ontology/Event' ),
450
			'custom_fields'      => array(
451
				self::FIELD_DATE_START => array(
452
					'predicate'   => 'http://schema.org/startDate',
453
					'type'        => self::DATA_TYPE_DATE,
454
					'export_type' => 'xsd:datetime',
455
					'constraints' => ''
456
				),
457
				self::FIELD_DATE_END   => array(
458
					'predicate'   => 'http://schema.org/endDate',
459
					'type'        => self::DATA_TYPE_DATE,
460
					'export_type' => 'xsd:datetime',
461
					'constraints' => ''
462
				),
463
				self::FIELD_LOCATION   => array(
464
					'predicate'   => 'http://schema.org/location',
465
					'type'        => self::DATA_TYPE_URI,
466
					'export_type' => 'http://schema.org/PostalAddress',
467
					'constraints' => array(
468
						'uri_type'    => array( 'Place', 'LocalBusiness' ),
469
						'cardinality' => INF
470
					)
471
				)
472
			),
473
			'microdata_template' =>
474
				'{{startDate}}
475
                                {{endDate}}
476
                                {{location}}',
477
			'templates'          => array(
478
				'subtitle' => '{{id}}'
479
			)
480
		);
481
482
		// Merge the custom fields with those provided by the thing schema.
483
		$thing_schema            = $this->get_thing_schema();
484
		$schema['custom_fields'] = array_merge( $schema['custom_fields'], $thing_schema['custom_fields'] );
485
486
		return $schema;
487
	}
488
489
	/**
490
	 * Get the 'organization' schema.
491
	 *
492
	 * @return array An array with the schema configuration.
493
	 *
494
	 * @since 3.1.0
495
	 */
496
	private function get_organization_schema() {
497
498
		$schema = array(
499
			'label'              => 'Organization',
500
			'description'        => 'An organization, including a government or a newspaper.',
501
			'parents'            => array( 'thing' ),
502
			'css_class'          => 'wl-organization',
503
			'uri'                => 'http://schema.org/Organization',
504
			'same_as'            => array(
505
				'http://rdf.freebase.com/ns/organization.organization',
506
				'http://rdf.freebase.com/ns/government.government',
507
				'http://schema.org/Newspaper'
508
			),
509
			'custom_fields'      => array(
510
				self::FIELD_FOUNDER             => array(
511
					'predicate'   => 'http://schema.org/founder',
512
					'type'        => self::DATA_TYPE_URI,
513
					'export_type' => 'http://schema.org/Person',
514
					'constraints' => array(
515
						'uri_type'    => 'Person',
516
						'cardinality' => INF
517
					)
518
				),
519
				self::FIELD_ADDRESS             => array(
520
					'predicate'   => 'http://schema.org/streetAddress',
521
					'type'        => self::DATA_TYPE_STRING,
522
					'export_type' => 'xsd:string',
523
					'constraints' => '',
524
					'input_field' => 'address'   // to build custom metabox
525
				),
526
				self::FIELD_ADDRESS_PO_BOX      => array(
527
					'predicate'   => 'http://schema.org/postOfficeBoxNumber',
528
					'type'        => self::DATA_TYPE_STRING,
529
					'export_type' => 'xsd:string',
530
					'constraints' => '',
531
					'input_field' => 'address'   // to build custom metabox
532
				),
533
				self::FIELD_ADDRESS_POSTAL_CODE => array(
534
					'predicate'   => 'http://schema.org/postalCode',
535
					'type'        => self::DATA_TYPE_STRING,
536
					'export_type' => 'xsd:string',
537
					'constraints' => '',
538
					'input_field' => 'address'   // to build custom metabox
539
				),
540
				self::FIELD_ADDRESS_LOCALITY    => array(
541
					'predicate'   => 'http://schema.org/addressLocality',
542
					'type'        => self::DATA_TYPE_STRING,
543
					'export_type' => 'xsd:string',
544
					'constraints' => '',
545
					'input_field' => 'address'   // to build custom metabox
546
				),
547
				self::FIELD_ADDRESS_REGION      => array(
548
					'predicate'   => 'http://schema.org/addressRegion',
549
					'type'        => self::DATA_TYPE_STRING,
550
					'export_type' => 'xsd:string',
551
					'constraints' => '',
552
					'input_field' => 'address'   // to build custom metabox
553
				),
554
				self::FIELD_ADDRESS_COUNTRY     => array(
555
					'predicate'   => 'http://schema.org/addressCountry',
556
					'type'        => self::DATA_TYPE_STRING,
557
					'export_type' => 'xsd:string',
558
					'constraints' => '',
559
					'input_field' => 'address'   // to build custom metabox
560
				),
561
				self::FIELD_EMAIL               => array(
562
					'predicate'   => 'http://schema.org/email',
563
					'type'        => self::DATA_TYPE_STRING,
564
					'export_type' => 'xsd:string',
565
					'constraints' => ''
566
				),
567
				'wl_schema_telephone'           => array(
568
					'predicate'   => 'http://schema.org/telephone',
569
					'type'        => self::DATA_TYPE_STRING,
570
					'export_type' => 'xsd:string',
571
					'constraints' => ''
572
				),
573
			),
574
			'microdata_template' => '{{founder}}'
575
			                        . '<span itemprop="address" itemscope itemtype="http://schema.org/PostalAddress">{{streetAddress}}{{postOfficeBoxNumber}}{{postalCode}}{{addressLocality}}{{addressRegion}}{{addressCountry}}{{email}}</span>',
576
			'templates'          => array(
577
				'subtitle' => '{{id}}'
578
			)
579
		);
580
581
		// Merge the custom fields with those provided by the thing schema.
582
		$thing_schema            = $this->get_thing_schema();
583
		$schema['custom_fields'] = array_merge( $schema['custom_fields'], $thing_schema['custom_fields'] );
584
585
		return $schema;
586
	}
587
588
	/**
589
	 * Get the 'person' schema.
590
	 *
591
	 * @return array An array with the schema configuration.
592
	 *
593
	 * @since 3.1.0
594
	 */
595
	private function get_person_schema() {
596
597
		$schema = array(
598
			'label'              => 'Person',
599
			'description'        => 'A person (or a music artist).',
600
			'parents'            => array( 'thing' ),
601
			'css_class'          => 'wl-person',
602
			'uri'                => 'http://schema.org/Person',
603
			'same_as'            => array(
604
				'http://rdf.freebase.com/ns/people.person',
605
				'http://rdf.freebase.com/ns/music.artist',
606
				'http://dbpedia.org/class/yago/LivingPeople'
607
			),
608
			'custom_fields'      => array(
609
				self::FIELD_KNOWS       => array(
610
					'predicate'   => 'http://schema.org/knows',
611
					'type'        => self::DATA_TYPE_URI,
612
					'export_type' => 'http://schema.org/Person',
613
					'constraints' => array(
614
						'uri_type'    => 'Person',
615
						'cardinality' => INF
616
					)
617
				),
618
				self::FIELD_BIRTH_DATE  => array(
619
					'predicate'   => 'http://schema.org/birthDate',
620
					'type'        => self::DATA_TYPE_DATE,
621
					'export_type' => 'xsd:date',
622
					'constraints' => ''
623
				),
624
				self::FIELD_BIRTH_PLACE => array(
625
					'predicate'   => 'http://schema.org/birthPlace',
626
					'type'        => self::DATA_TYPE_URI,
627
					'export_type' => 'http://schema.org/Place',
628
					'constraints' => array(
629
						'uri_type' => 'Place'
630
					)
631
				),
632
				self::FIELD_AFFILIATION => array(
633
					'predicate'   => 'http://schema.org/affiliation',
634
					'type'        => self::DATA_TYPE_URI,
635
					'export_type' => 'http://schema.org/Organization',
636
					'constraints' => array(
637
						'uri_type'    => array(
638
							'Organization',
639
							'LocalBusiness'
640
						),
641
						'cardinality' => INF
642
					)
643
				),
644
				self::FIELD_EMAIL       => array(
645
					'predicate'   => 'http://schema.org/email',
646
					'type'        => self::DATA_TYPE_STRING,
647
					'export_type' => 'xsd:string',
648
					'constraints' => array(
649
						'cardinality' => INF
650
					)
651
				)
652
			),
653
			'microdata_template' => '{{birthDate}}{{birthPlace}}{{knows}}{{affiliation}}{{email}}',
654
			'templates'          => array(
655
				'subtitle' => '{{id}}'
656
			)
657
		);
658
659
		// Merge the custom fields with those provided by the thing schema.
660
		$thing_schema            = $this->get_thing_schema();
661
		$schema['custom_fields'] = array_merge( $schema['custom_fields'], $thing_schema['custom_fields'] );
662
663
		return $schema;
664
665
	}
666
667
	/**
668
	 * Get the 'place' schema.
669
	 *
670
	 * @return array An array with the schema configuration.
671
	 *
672
	 * @since 3.1.0
673
	 */
674
	private function get_place_schema() {
675
676
		$schema = array(
677
			'label'              => 'Place',
678
			'description'        => 'A place.',
679
			'parents'            => array( 'thing' ),
680
			'css_class'          => 'wl-place',
681
			'uri'                => 'http://schema.org/Place',
682
			'same_as'            => array(
683
				'http://rdf.freebase.com/ns/location.location',
684
				'http://www.opengis.net/gml/_Feature'
685
			),
686
			'custom_fields'      => array(
687
				self::FIELD_GEO_LATITUDE        => array(
688
					'predicate'   => 'http://schema.org/latitude',
689
					'type'        => self::DATA_TYPE_DOUBLE,
690
					'export_type' => 'xsd:double',
691
					'constraints' => '',
692
					'input_field' => 'coordinates'   // to build custom metabox
693
				),
694
				self::FIELD_GEO_LONGITUDE       => array(
695
					'predicate'   => 'http://schema.org/longitude',
696
					'type'        => self::DATA_TYPE_DOUBLE,
697
					'export_type' => 'xsd:double',
698
					'constraints' => '',
699
					'input_field' => 'coordinates'   // to build custom metabox
700
				),
701
				self::FIELD_ADDRESS             => array(
702
					'predicate'   => 'http://schema.org/streetAddress',
703
					'type'        => self::DATA_TYPE_STRING,
704
					'export_type' => 'xsd:string',
705
					'constraints' => '',
706
					'input_field' => 'address'   // to build custom metabox
707
				),
708
				self::FIELD_ADDRESS_PO_BOX      => array(
709
					'predicate'   => 'http://schema.org/postOfficeBoxNumber',
710
					'type'        => self::DATA_TYPE_STRING,
711
					'export_type' => 'xsd:string',
712
					'constraints' => '',
713
					'input_field' => 'address'   // to build custom metabox
714
				),
715
				self::FIELD_ADDRESS_POSTAL_CODE => array(
716
					'predicate'   => 'http://schema.org/postalCode',
717
					'type'        => self::DATA_TYPE_STRING,
718
					'export_type' => 'xsd:string',
719
					'constraints' => '',
720
					'input_field' => 'address'   // to build custom metabox
721
				),
722
				self::FIELD_ADDRESS_LOCALITY    => array(
723
					'predicate'   => 'http://schema.org/addressLocality',
724
					'type'        => self::DATA_TYPE_STRING,
725
					'export_type' => 'xsd:string',
726
					'constraints' => '',
727
					'input_field' => 'address'   // to build custom metabox
728
				),
729
				self::FIELD_ADDRESS_REGION      => array(
730
					'predicate'   => 'http://schema.org/addressRegion',
731
					'type'        => self::DATA_TYPE_STRING,
732
					'export_type' => 'xsd:string',
733
					'constraints' => '',
734
					'input_field' => 'address'   // to build custom metabox
735
				),
736
				self::FIELD_ADDRESS_COUNTRY     => array(
737
					'predicate'   => 'http://schema.org/addressCountry',
738
					'type'        => self::DATA_TYPE_STRING,
739
					'export_type' => 'xsd:string',
740
					'constraints' => '',
741
					'input_field' => 'address'   // to build custom metabox
742
				)
743
			),
744
			'microdata_template' => '<span itemprop="geo" itemscope itemtype="http://schema.org/GeoCoordinates">{{latitude}}{{longitude}}</span>'
745
			                        . '<span itemprop="address" itemscope itemtype="http://schema.org/PostalAddress">{{streetAddress}}{{postOfficeBoxNumber}}{{postalCode}}{{addressLocality}}{{addressRegion}}{{addressCountry}}</span>',
746
			'templates'          => array(
747
				'subtitle' => '{{id}}'
748
			)
749
		);
750
751
		// Merge the custom fields with those provided by the thing schema.
752
		$thing_schema            = $this->get_thing_schema();
753
		$schema['custom_fields'] = array_merge( $schema['custom_fields'], $thing_schema['custom_fields'] );
754
755
		return $schema;
756
	}
757
758
	/**
759
	 * Get the 'local business' schema.
760
	 *
761
	 * @return array An array with the schema configuration.
762
	 *
763
	 * @since 3.1.0
764
	 */
765
	private function get_local_business_schema() {
766
767
		$schema = array(
768
			'label'              => 'LocalBusiness',
769
			'description'        => 'A local business.',
770
			'parents'            => array( 'place', 'organization' ),
771
			'css_class'          => 'wl-local-business',
772
			'uri'                => 'http://schema.org/LocalBusiness',
773
			'same_as'            => array(
774
				'http://rdf.freebase.com/ns/business/business_location',
775
				'https://schema.org/Store'
776
			),
777
			'custom_fields'      => array(),
778
			'microdata_template' => '<span itemprop="geo" itemscope itemtype="http://schema.org/GeoCoordinates">{{latitude}}{{longitude}}</span>'
779
			                        . '<span itemprop="address" itemscope itemtype="http://schema.org/PostalAddress">{{streetAddress}}{{postOfficeBoxNumber}}{{postalCode}}{{addressLocality}}{{addressRegion}}{{addressCountry}}</span>'
780
			                        . '{{founder}}'
781
			                        . '{{email}}',
782
			'templates'          => array(
783
				'subtitle' => '{{id}}'
784
			)
785
		);
786
787
		// Merge the custom fields with those provided by the place and organization schema.
788
		$place_schema            = $this->get_place_schema();
789
		$organization_schema     = $this->get_organization_schema();
790
		$schema['custom_fields'] = array_merge( $schema['custom_fields'], $place_schema['custom_fields'], $organization_schema['custom_fields'] );
791
792
		return $schema;
793
	}
794
795
}
796