Completed
Push — develop ( bdd4f3...23ebeb )
by David
04:27
created

Wordlift_Schema_Service::get_field()   B

Complexity

Conditions 5
Paths 3

Size

Total Lines 19
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 5
eloc 8
nc 3
nop 1
dl 0
loc 19
rs 8.8571
c 0
b 0
f 0
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
			),
377
			// {{sameAs}} not present in the microdata template,
378
			// because it is treated separately in *wl_content_embed_item_microdata*
379
			'microdata_template' => '',
380
			'templates'          => array(
381
				'subtitle' => '{{id}}'
382
			)
383
		);
384
385
	}
386
387
	/**
388
	 * Get the 'creative work' schema.
389
	 *
390
	 * @return array An array with the schema configuration.
391
	 *
392
	 * @since 3.1.0
393
	 */
394
	private function get_creative_work_schema() {
395
396
		$schema = array(
397
			'label'              => 'CreativeWork',
398
			'description'        => 'A creative work (or a Music Album).',
399
			'parents'            => array( 'thing' ),
400
			// give term slug as parent
401
			'css_class'          => 'wl-creative-work',
402
			'uri'                => 'http://schema.org/CreativeWork',
403
			'same_as'            => array(
404
				'http://schema.org/MusicAlbum',
405
				'http://schema.org/Product'
406
			),
407
			'custom_fields'      => array(
408
				self::FIELD_AUTHOR => array(
409
					'predicate'   => 'http://schema.org/author',
410
					'type'        => self::DATA_TYPE_URI,
411
					'export_type' => 'http://schema.org/Person',
412
					'constraints' => array(
413
						'uri_type'    => array( 'Person', 'Organization' ),
414
						'cardinality' => INF
415
					)
416
				),
417
			),
418
			'microdata_template' => '{{author}}',
419
			'templates'          => array(
420
				'subtitle' => '{{id}}'
421
			)
422
		);
423
424
		// Merge the custom fields with those provided by the thing schema.
425
		$thing_schema            = $this->get_thing_schema();
426
		$schema['custom_fields'] = array_merge( $schema['custom_fields'], $thing_schema['custom_fields'] );
427
428
		return $schema;
429
	}
430
431
	/**
432
	 * Get the 'event' schema.
433
	 *
434
	 * @return array An array with the schema configuration.
435
	 *
436
	 * @since 3.1.0
437
	 */
438
	private function get_event_schema() {
439
440
		$schema = array(
441
			'label'              => 'Event',
442
			'description'        => 'An event . ',
443
			'parents'            => array( 'thing' ),
444
			'css_class'          => 'wl-event',
445
			'uri'                => self::SCHEMA_EVENT_TYPE,
446
			'same_as'            => array( 'http://dbpedia.org/ontology/Event' ),
447
			'custom_fields'      => array(
448
				self::FIELD_DATE_START => array(
449
					'predicate'   => 'http://schema.org/startDate',
450
					'type'        => self::DATA_TYPE_DATE,
451
					'export_type' => 'xsd:datetime',
452
					'constraints' => ''
453
				),
454
				self::FIELD_DATE_END   => array(
455
					'predicate'   => 'http://schema.org/endDate',
456
					'type'        => self::DATA_TYPE_DATE,
457
					'export_type' => 'xsd:datetime',
458
					'constraints' => ''
459
				),
460
				self::FIELD_LOCATION   => array(
461
					'predicate'   => 'http://schema.org/location',
462
					'type'        => self::DATA_TYPE_URI,
463
					'export_type' => 'http://schema.org/PostalAddress',
464
					'constraints' => array(
465
						'uri_type'    => array( 'Place', 'LocalBusiness' ),
466
						'cardinality' => INF
467
					)
468
				)
469
			),
470
			'microdata_template' =>
471
				'{{startDate}}
472
                                {{endDate}}
473
                                {{location}}',
474
			'templates'          => array(
475
				'subtitle' => '{{id}}'
476
			)
477
		);
478
479
		// Merge the custom fields with those provided by the thing schema.
480
		$thing_schema            = $this->get_thing_schema();
481
		$schema['custom_fields'] = array_merge( $schema['custom_fields'], $thing_schema['custom_fields'] );
482
483
		return $schema;
484
	}
485
486
	/**
487
	 * Get the 'organization' schema.
488
	 *
489
	 * @return array An array with the schema configuration.
490
	 *
491
	 * @since 3.1.0
492
	 */
493 View Code Duplication
	private function get_organization_schema() {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
494
495
		$schema = array(
496
			'label'              => 'Organization',
497
			'description'        => 'An organization, including a government or a newspaper.',
498
			'parents'            => array( 'thing' ),
499
			'css_class'          => 'wl-organization',
500
			'uri'                => 'http://schema.org/Organization',
501
			'same_as'            => array(
502
				'http://rdf.freebase.com/ns/organization.organization',
503
				'http://rdf.freebase.com/ns/government.government',
504
				'http://schema.org/Newspaper'
505
			),
506
			'custom_fields'      => array(
507
				self::FIELD_FOUNDER             => array(
508
					'predicate'   => 'http://schema.org/founder',
509
					'type'        => self::DATA_TYPE_URI,
510
					'export_type' => 'http://schema.org/Person',
511
					'constraints' => array(
512
						'uri_type'    => 'Person',
513
						'cardinality' => INF
514
					)
515
				),
516
				self::FIELD_ADDRESS             => array(
517
					'predicate'   => 'http://schema.org/streetAddress',
518
					'type'        => self::DATA_TYPE_STRING,
519
					'export_type' => 'xsd:string',
520
					'constraints' => '',
521
					'input_field' => 'address'   // to build custom metabox
522
				),
523
				self::FIELD_ADDRESS_PO_BOX      => array(
524
					'predicate'   => 'http://schema.org/postOfficeBoxNumber',
525
					'type'        => self::DATA_TYPE_STRING,
526
					'export_type' => 'xsd:string',
527
					'constraints' => '',
528
					'input_field' => 'address'   // to build custom metabox
529
				),
530
				self::FIELD_ADDRESS_POSTAL_CODE => array(
531
					'predicate'   => 'http://schema.org/postalCode',
532
					'type'        => self::DATA_TYPE_STRING,
533
					'export_type' => 'xsd:string',
534
					'constraints' => '',
535
					'input_field' => 'address'   // to build custom metabox
536
				),
537
				self::FIELD_ADDRESS_LOCALITY    => array(
538
					'predicate'   => 'http://schema.org/addressLocality',
539
					'type'        => self::DATA_TYPE_STRING,
540
					'export_type' => 'xsd:string',
541
					'constraints' => '',
542
					'input_field' => 'address'   // to build custom metabox
543
				),
544
				self::FIELD_ADDRESS_REGION      => array(
545
					'predicate'   => 'http://schema.org/addressRegion',
546
					'type'        => self::DATA_TYPE_STRING,
547
					'export_type' => 'xsd:string',
548
					'constraints' => '',
549
					'input_field' => 'address'   // to build custom metabox
550
				),
551
				self::FIELD_ADDRESS_COUNTRY     => array(
552
					'predicate'   => 'http://schema.org/addressCountry',
553
					'type'        => self::DATA_TYPE_STRING,
554
					'export_type' => 'xsd:string',
555
					'constraints' => '',
556
					'input_field' => 'address'   // to build custom metabox
557
				),
558
				self::FIELD_EMAIL               => array(
559
					'predicate'   => 'http://schema.org/email',
560
					'type'        => self::DATA_TYPE_STRING,
561
					'export_type' => 'xsd:string',
562
					'constraints' => ''
563
				)
564
			),
565
			'microdata_template' =>
566
				'{{founder}}
567
				<span itemprop="address" itemscope itemtype="http://schema.org/PostalAddress">
568
					{{streetAddress}}{{postOfficeBoxNumber}}{{postalCode}}{{addressLocality}}{{addressRegion}}{{addressCountry}}{{email}}
569
				</span>',
570
			'templates'          => array(
571
				'subtitle' => '{{id}}'
572
			)
573
		);
574
575
		// Merge the custom fields with those provided by the thing schema.
576
		$thing_schema            = $this->get_thing_schema();
577
		$schema['custom_fields'] = array_merge( $schema['custom_fields'], $thing_schema['custom_fields'] );
578
579
		return $schema;
580
	}
581
582
	/**
583
	 * Get the 'person' schema.
584
	 *
585
	 * @return array An array with the schema configuration.
586
	 *
587
	 * @since 3.1.0
588
	 */
589
	private function get_person_schema() {
590
591
		$schema = array(
592
			'label'              => 'Person',
593
			'description'        => 'A person (or a music artist).',
594
			'parents'            => array( 'thing' ),
595
			'css_class'          => 'wl-person',
596
			'uri'                => 'http://schema.org/Person',
597
			'same_as'            => array(
598
				'http://rdf.freebase.com/ns/people.person',
599
				'http://rdf.freebase.com/ns/music.artist',
600
				'http://dbpedia.org/class/yago/LivingPeople'
601
			),
602
			'custom_fields'      => array(
603
				self::FIELD_KNOWS       => array(
604
					'predicate'   => 'http://schema.org/knows',
605
					'type'        => self::DATA_TYPE_URI,
606
					'export_type' => 'http://schema.org/Person',
607
					'constraints' => array(
608
						'uri_type'    => 'Person',
609
						'cardinality' => INF
610
					)
611
				),
612
				self::FIELD_BIRTH_DATE  => array(
613
					'predicate'   => 'http://schema.org/birthDate',
614
					'type'        => self::DATA_TYPE_DATE,
615
					'export_type' => 'xsd:date',
616
					'constraints' => ''
617
				),
618
				self::FIELD_BIRTH_PLACE => array(
619
					'predicate'   => 'http://schema.org/birthPlace',
620
					'type'        => self::DATA_TYPE_URI,
621
					'export_type' => 'http://schema.org/Place',
622
					'constraints' => array(
623
						'uri_type' => 'Place'
624
					)
625
				),
626
				self::FIELD_AFFILIATION => array(
627
					'predicate'   => 'http://schema.org/affiliation',
628
					'type'        => self::DATA_TYPE_URI,
629
					'export_type' => 'http://schema.org/Organization',
630
					'constraints' => array(
631
						'uri_type'    => array(
632
							'Organization',
633
							'LocalBusiness'
634
						),
635
						'cardinality' => INF
636
					)
637
				),
638
				self::FIELD_EMAIL       => array(
639
					'predicate'   => 'http://schema.org/email',
640
					'type'        => self::DATA_TYPE_STRING,
641
					'export_type' => 'xsd:string',
642
					'constraints' => array(
643
						'cardinality' => INF
644
					)
645
				)
646
			),
647
			'microdata_template' =>
648
				'{{birthDate}}
649
                 {{birthPlace}}
650
                 {{knows}}
651
				 {{affiliation}}
652
				 {{email}}',
653
			'templates'          => array(
654
				'subtitle' => '{{id}}'
655
			)
656
		);
657
658
		// Merge the custom fields with those provided by the thing schema.
659
		$thing_schema            = $this->get_thing_schema();
660
		$schema['custom_fields'] = array_merge( $schema['custom_fields'], $thing_schema['custom_fields'] );
661
662
		return $schema;
663
664
	}
665
666
	/**
667
	 * Get the 'place' schema.
668
	 *
669
	 * @return array An array with the schema configuration.
670
	 *
671
	 * @since 3.1.0
672
	 */
673 View Code Duplication
	private function get_place_schema() {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
674
675
		$schema = array(
676
			'label'              => 'Place',
677
			'description'        => 'A place.',
678
			'parents'            => array( 'thing' ),
679
			'css_class'          => 'wl-place',
680
			'uri'                => 'http://schema.org/Place',
681
			'same_as'            => array(
682
				'http://rdf.freebase.com/ns/location.location',
683
				'http://www.opengis.net/gml/_Feature'
684
			),
685
			'custom_fields'      => array(
686
				self::FIELD_GEO_LATITUDE        => array(
687
					'predicate'   => 'http://schema.org/latitude',
688
					'type'        => self::DATA_TYPE_DOUBLE,
689
					'export_type' => 'xsd:double',
690
					'constraints' => '',
691
					'input_field' => 'coordinates'   // to build custom metabox
692
				),
693
				self::FIELD_GEO_LONGITUDE       => array(
694
					'predicate'   => 'http://schema.org/longitude',
695
					'type'        => self::DATA_TYPE_DOUBLE,
696
					'export_type' => 'xsd:double',
697
					'constraints' => '',
698
					'input_field' => 'coordinates'   // to build custom metabox
699
				),
700
				self::FIELD_ADDRESS             => array(
701
					'predicate'   => 'http://schema.org/streetAddress',
702
					'type'        => self::DATA_TYPE_STRING,
703
					'export_type' => 'xsd:string',
704
					'constraints' => '',
705
					'input_field' => 'address'   // to build custom metabox
706
				),
707
				self::FIELD_ADDRESS_PO_BOX      => array(
708
					'predicate'   => 'http://schema.org/postOfficeBoxNumber',
709
					'type'        => self::DATA_TYPE_STRING,
710
					'export_type' => 'xsd:string',
711
					'constraints' => '',
712
					'input_field' => 'address'   // to build custom metabox
713
				),
714
				self::FIELD_ADDRESS_POSTAL_CODE => array(
715
					'predicate'   => 'http://schema.org/postalCode',
716
					'type'        => self::DATA_TYPE_STRING,
717
					'export_type' => 'xsd:string',
718
					'constraints' => '',
719
					'input_field' => 'address'   // to build custom metabox
720
				),
721
				self::FIELD_ADDRESS_LOCALITY    => array(
722
					'predicate'   => 'http://schema.org/addressLocality',
723
					'type'        => self::DATA_TYPE_STRING,
724
					'export_type' => 'xsd:string',
725
					'constraints' => '',
726
					'input_field' => 'address'   // to build custom metabox
727
				),
728
				self::FIELD_ADDRESS_REGION      => array(
729
					'predicate'   => 'http://schema.org/addressRegion',
730
					'type'        => self::DATA_TYPE_STRING,
731
					'export_type' => 'xsd:string',
732
					'constraints' => '',
733
					'input_field' => 'address'   // to build custom metabox
734
				),
735
				self::FIELD_ADDRESS_COUNTRY     => array(
736
					'predicate'   => 'http://schema.org/addressCountry',
737
					'type'        => self::DATA_TYPE_STRING,
738
					'export_type' => 'xsd:string',
739
					'constraints' => '',
740
					'input_field' => 'address'   // to build custom metabox
741
				)
742
			),
743
			'microdata_template' =>
744
				'<span itemprop="geo" itemscope itemtype="http://schema.org/GeoCoordinates">
745
					{{latitude}}
746
					{{longitude}}
747
				</span>
748
				<span itemprop="address" itemscope itemtype="http://schema.org/PostalAddress">
749
					{{streetAddress}}{{postOfficeBoxNumber}}{{postalCode}}{{addressLocality}}{{addressRegion}}{{addressCountry}}
750
				</span>',
751
			'templates'          => array(
752
				'subtitle' => '{{id}}'
753
			)
754
		);
755
756
		// Merge the custom fields with those provided by the thing schema.
757
		$thing_schema            = $this->get_thing_schema();
758
		$schema['custom_fields'] = array_merge( $schema['custom_fields'], $thing_schema['custom_fields'] );
759
760
		return $schema;
761
	}
762
763
	/**
764
	 * Get the 'local business' schema.
765
	 *
766
	 * @return array An array with the schema configuration.
767
	 *
768
	 * @since 3.1.0
769
	 */
770
	private function get_local_business_schema() {
771
772
		$schema = array(
773
			'label'              => 'LocalBusiness',
774
			'description'        => 'A local business.',
775
			'parents'            => array( 'place', 'organization' ),
776
			'css_class'          => 'wl-local-business',
777
			'uri'                => 'http://schema.org/LocalBusiness',
778
			'same_as'            => array(
779
				'http://rdf.freebase.com/ns/business/business_location',
780
				'https://schema.org/Store'
781
			),
782
			'custom_fields'      => array(),
783
			'microdata_template' => '<span itemprop="geo" itemscope itemtype="http://schema.org/GeoCoordinates">
784
                                    {{latitude}}
785
                                    {{longitude}}
786
                                </span>
787
                                <span itemprop="address" itemscope itemtype="http://schema.org/PostalAddress">
788
									{{streetAddress}}{{postOfficeBoxNumber}}{{postalCode}}{{addressLocality}}{{addressRegion}}{{addressCountry}}
789
								</span>
790
                                {{founder}}
791
								{{email}}',
792
			'templates'          => array(
793
				'subtitle' => '{{id}}'
794
			)
795
		);
796
797
		// Merge the custom fields with those provided by the place and organization schema.
798
		$place_schema            = $this->get_place_schema();
799
		$organization_schema     = $this->get_organization_schema();
800
		$schema['custom_fields'] = array_merge( $schema['custom_fields'], $place_schema['custom_fields'], $organization_schema['custom_fields'] );
801
802
		return $schema;
803
	}
804
805
}
806