Completed
Push — develop ( aa8228...88124f )
by David
02:48
created

Wordlift_Schema_Service::get_recipe_schema()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 81
Code Lines 60

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 60
nc 1
nop 0
dl 0
loc 81
rs 8.8076
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
 * Services: WordLift Schema Service.
4
 *
5
 * This file defines the Wordlift_Schema_Service class.
6
 *
7
 * @since   3.1.0
8
 * @package Wordlift
9
 */
10
11
/**
12
 * Provides constants and methods related to WordLift's schema.
13
 *
14
 * @since 3.1.0
15
 */
16
class Wordlift_Schema_Service {
17
18
	/**
19
	 * The 'location created' field name.
20
	 *
21
	 * @since 3.5.0
22
	 */
23
	const FIELD_LOCATION_CREATED = 'wl_location_created';
24
25
	/**
26
	 * The 'topic' field name.
27
	 *
28
	 * @since 3.5.0
29
	 */
30
	const FIELD_TOPIC = 'wl_topic';
31
32
	/**
33
	 * The 'author' field name.
34
	 *
35
	 * @since 3.1.0
36
	 */
37
	const FIELD_AUTHOR = 'wl_author';
38
39
	/**
40
	 * The 'same as' field name.
41
	 *
42
	 * @since 3.1.0
43
	 */
44
	const FIELD_SAME_AS = 'entity_same_as';
45
46
	/**
47
	 * The 'date start' field name.
48
	 *
49
	 * @since 3.1.0
50
	 */
51
	const FIELD_DATE_START = 'wl_cal_date_start';
52
53
	/**
54
	 * The 'date end' field name.
55
	 *
56
	 * @since 3.1.0
57
	 */
58
	const FIELD_DATE_END = 'wl_cal_date_end';
59
60
	/**
61
	 * The 'location' field name.
62
	 *
63
	 * @since 3.1.0
64
	 */
65
	const FIELD_LOCATION = 'wl_location';
66
67
	/**
68
	 * The 'founder' field name.
69
	 *
70
	 * @since 3.1.0
71
	 */
72
	const FIELD_FOUNDER = 'wl_founder';
73
74
	/**
75
	 * The 'knows' field name.
76
	 *
77
	 * @since 3.1.0
78
	 */
79
	const FIELD_KNOWS = 'wl_knows';
80
81
	/**
82
	 * The 'birth date' field name.
83
	 *
84
	 * @since 3.1.0
85
	 */
86
	const FIELD_BIRTH_DATE = 'wl_birth_date';
87
88
	/**
89
	 * The 'birth place' field name.
90
	 *
91
	 * @since 3.1.0
92
	 */
93
	const FIELD_BIRTH_PLACE = 'wl_birth_place';
94
95
	/**
96
	 * The 'latitude' field name.
97
	 *
98
	 * @since 3.1.0
99
	 */
100
	const FIELD_GEO_LATITUDE = 'wl_geo_latitude';
101
102
	/**
103
	 * The 'longitude' field name.
104
	 *
105
	 * @since 3.1.0
106
	 */
107
	const FIELD_GEO_LONGITUDE = 'wl_geo_longitude';
108
109
	/**
110
	 * The 'streetAddress' field name.
111
	 *
112
	 * @since 3.1.0
113
	 */
114
	const FIELD_ADDRESS = 'wl_address';
115
116
	/**
117
	 * The 'postOfficeBoxNumber' field name.
118
	 *
119
	 * @since 3.3.0
120
	 */
121
	const FIELD_ADDRESS_PO_BOX = 'wl_address_post_office_box';
122
123
	/**
124
	 * The 'postalCode' field name.
125
	 *
126
	 * @since 3.3.0
127
	 */
128
	const FIELD_ADDRESS_POSTAL_CODE = 'wl_address_postal_code';
129
130
	/**
131
	 * The 'addressLocality' field name.
132
	 *
133
	 * @since 3.3.0
134
	 */
135
	const FIELD_ADDRESS_LOCALITY = 'wl_address_locality';
136
	/**
137
	 * The 'addressRegion' field name.
138
	 *
139
	 * @since 3.3.0
140
	 */
141
	const FIELD_ADDRESS_REGION = 'wl_address_region';
142
143
	/**
144
	 * The 'addressCountry' field name.
145
	 *
146
	 * @since 3.3.0
147
	 */
148
	const FIELD_ADDRESS_COUNTRY = 'wl_address_country';
149
150
	/**
151
	 * The 'entity type' field name.
152
	 *
153
	 * @since 3.1.0
154
	 */
155
	const FIELD_ENTITY_TYPE = 'wl_entity_type_uri';
156
157
	/**
158
	 * The 'email' field name.
159
	 *
160
	 * @since 3.2.0
161
	 */
162
	const FIELD_EMAIL = 'wl_email';
163
164
	/**
165
	 * The 'affiliation' field name.
166
	 *
167
	 * @since 3.2.0
168
	 */
169
	const FIELD_AFFILIATION = 'wl_affiliation';
170
171
	/**
172
	 * The 'telephone' field name.
173
	 *
174
	 * @since 3.8.0
175
	 */
176
	const FIELD_TELEPHONE = 'wl_schema_telephone';
177
178
	/**
179
	 * The 'legalName' field name.
180
	 *
181
	 * @since 3.12.0
182
	 */
183
	const FIELD_LEGAL_NAME = 'wl_schema_legal_name';
184
185
	/**
186
	 * The 'recipeCuisine' field name.
187
	 *
188
	 * @since 3.14.0
189
	 */
190
	const FIELD_RECIPE_CUISINE = 'wl_schema_recipe_cuisine';
191
192
	/**
193
	 * The 'recipeIngredient' field name.
194
	 *
195
	 * @since 3.14.0
196
	 */
197
	const FIELD_RECIPE_INGREDIENT = 'wl_schema_recipe_ingredient';
198
199
	/**
200
	 * The 'recipeInstructions' field name.
201
	 *
202
	 * @since 3.14.0
203
	 */
204
	const FIELD_RECIPE_INSTRUCTIONS = 'wl_schema_recipe_instructions';
205
206
	/**
207
	 * The 'recipeYield' field name.
208
	 *
209
	 * @since 3.14.0
210
	 */
211
	const FIELD_RECIPE_YIELD = 'wl_schema_recipe_yield';
212
213
	/**
214
	 * The 'prepTime' field name.
215
	 *
216
	 * @since 3.14.0
217
	 */
218
	const FIELD_PREP_TIME = 'wl_schema_prep_time';
219
220
	/**
221
	 * The 'totalTime' field name.
222
	 *
223
	 * @since 3.14.0
224
	 */
225
	const FIELD_TOTAL_TIME = 'wl_schema_total_time';
226
227
	/**
228
	 * The 'URI' data type name.
229
	 *
230
	 * @since 3.1.0
231
	 */
232
	const DATA_TYPE_URI = 'uri';
233
234
	/**
235
	 * The 'date' data type name.
236
	 *
237
	 * @since 3.1.0
238
	 */
239
	const DATA_TYPE_DATE = 'date';
240
241
	/**
242
	 * The 'time' data type name.
243
	 *
244
	 * @since 3.14.0
245
	 */
246
	const DATA_TYPE_DURATION = 'duration';
247
248
	/**
249
	 * The 'double' data type name.
250
	 *
251
	 * @since 3.1.0
252
	 */
253
	const DATA_TYPE_DOUBLE = 'double';
254
255
	/**
256
	 * The 'string' data type name.
257
	 *
258
	 * @since 3.1.0
259
	 */
260
	const DATA_TYPE_STRING = 'string';
261
262
	/**
263
	 * The multiline text data type name.
264
	 *
265
	 * @since 3.14.0
266
	 */
267
	const DATA_TYPE_MULTILINE = 'multiline';
268
269
	/**
270
	 * The 'integer' data type name.
271
	 *
272
	 * @since 3.1.0
273
	 */
274
	const DATA_TYPE_INTEGER = 'int';
275
276
	/**
277
	 * The 'boolean' data type name.
278
	 *
279
	 * @since 3.1.0
280
	 */
281
	const DATA_TYPE_BOOLEAN = 'bool';
282
283
	/**
284
	 * The schema.org Event type URI.
285
	 *
286
	 * @since 3.1.0
287
	 */
288
	const SCHEMA_EVENT_TYPE = 'http://schema.org/Event';
289
290
	/**
291
	 * The Schema service singleton instance.
292
	 *
293
	 * @since  3.1.0
294
	 * @access private
295
	 * @var \Wordlift_Schema_Service $instance The Schema service singleton instance.
296
	 */
297
	private static $instance;
298
299
	/**
300
	 * WordLift's schema.
301
	 *
302
	 * @since  3.1.0
303
	 * @access private
304
	 * @var array $schema WordLift's schema.
305
	 */
306
	private $schema;
307
308
	/**
309
	 * The Log service.
310
	 *
311
	 * @since  3.1.0
312
	 * @access private
313
	 * @var \Wordlift_Log_Service $log_service The Log service.
314
	 */
315
	private $log_service;
316
317
	/**
318
	 * Wordlift_Schema_Service constructor.
319
	 *
320
	 * @since 3.1.0
321
	 */
322
	public function __construct() {
323
324
		$this->log_service = Wordlift_Log_Service::get_logger( 'Wordlift_Schema_Service' );
325
326
		// Create a singleton instance of the Schema service, useful to provide static functions to global functions.
327
		self::$instance = $this;
328
329
		// Set the taxonomy data.
330
		// Note: parent types must be defined before child types.
331
		$this->schema = array(
332
			'thing'         => $this->get_thing_schema(),
333
			'creative-work' => $this->get_creative_work_schema(),
334
			'event'         => $this->get_event_schema(),
335
			'organization'  => $this->get_organization_schema(),
336
			'person'        => $this->get_person_schema(),
337
			'place'         => $this->get_place_schema(),
338
			'localbusiness' => $this->get_local_business_schema(),
339
			'recipe'        => $this->get_recipe_schema(),
340
		);
341
342
	}
343
344
	/**
345
	 * Get a reference to the Schema service.
346
	 *
347
	 * @since 3.1.0
348
	 *
349
	 * @return Wordlift_Schema_Service A reference to the Schema service.
350
	 */
351
	public static function get_instance() {
352
353
		return self::$instance;
354
	}
355
356
	/**
357
	 * Get the properties for a field with the specified key. The key is used as
358
	 * meta key when the field's value is stored in WordPress meta data table.
359
	 *
360
	 * @since 3.6.0
361
	 *
362
	 * @param string $key The field's key.
363
	 *
364
	 * @return null|array An array of field's properties or null if the field is not found.
365
	 */
366
	public function get_field( $key ) {
367
368
		// Parse each schema's fields until we find the one we're looking for, then
369
		// return its properties.
370
		foreach ( $this->schema as $_ => $schema ) {
371
372
			if ( ! isset( $schema['custom_fields'] ) ) {
373
				break;
374
			}
375
376
			foreach ( $schema['custom_fields'] as $field => $props ) {
377
				if ( $key === $field ) {
378
					return $props;
379
				}
380
			}
381
		}
382
383
		return null;
384
	}
385
386
	/**
387
	 * Get the WordLift's schema.
388
	 *
389
	 * @param string $name The schema name.
390
	 *
391
	 * @return array|null An array with the schema configuration or NULL if the schema is not found.
392
	 *
393
	 * @since 3.1.0
394
	 */
395
	public function get_schema( $name ) {
396
397
		// Check if the schema exists and, if not, return NULL.
398
		if ( ! isset( $this->schema[ $name ] ) ) {
399
			return null;
400
		}
401
402
		// Return the requested schema.
403
		return $this->schema[ $name ];
404
	}
405
406
	/**
407
	 * Get the WordLift's schema trough schema type uri.
408
	 *
409
	 * @param string $uri The schema uri.
410
	 *
411
	 * @return array|null An array with the schema configuration or NULL if the schema is not found.
412
	 *
413
	 * @since 3.3.0
414
	 */
415
	public function get_schema_by_uri( $uri ) {
416
417
		foreach ( $this->schema as $name => $schema ) {
418
			if ( $schema['uri'] === $uri ) {
419
				return $schema;
420
			}
421
		}
422
423
		return null;
424
	}
425
426
	/**
427
	 * Get the 'thing' schema.
428
	 *
429
	 * @return array An array with the schema configuration.
430
	 *
431
	 * @since 3.1.0
432
	 */
433
	private function get_thing_schema() {
434
435
		return array(
436
			'css_class'     => 'wl-thing',
437
			'uri'           => 'http://schema.org/Thing',
438
			'same_as'       => array( '*' ),
439
			// set as default.
440
			'custom_fields' => array(
441
				self::FIELD_SAME_AS                            => array(
442
					'predicate'   => 'http://schema.org/sameAs',
443
					'type'        => self::DATA_TYPE_URI,
444
					'export_type' => 'http://schema.org/Thing',
445
					'constraints' => array(
446
						'cardinality' => INF,
447
					),
448
					// We need a custom metabox.
449
					'input_field' => 'sameas',
450
				),
451
				// Add the schema:url property.
452
				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...
453
				                                                                                      ->get_compat_definition(),
454
			),
455
			// {{sameAs}} not present in the microdata template,
456
			// because it is treated separately in *wl_content_embed_item_microdata*
457
			'templates'     => array(
458
				'subtitle' => '{{id}}',
459
			),
460
		);
461
462
	}
463
464
	/**
465
	 * Get the 'creative work' schema.
466
	 *
467
	 * @return array An array with the schema configuration.
468
	 *
469
	 * @since 3.1.0
470
	 */
471
	private function get_creative_work_schema() {
472
473
		$schema = array(
474
			'label'         => 'CreativeWork',
475
			'description'   => 'A creative work (or a Music Album).',
476
			'parents'       => array( 'thing' ),
477
			// Give term slug as parent.
478
			'css_class'     => 'wl-creative-work',
479
			'uri'           => 'http://schema.org/CreativeWork',
480
			'same_as'       => array(
481
				'http://schema.org/MusicAlbum',
482
				'http://schema.org/Product',
483
			),
484
			'custom_fields' => array(
485
				self::FIELD_AUTHOR => array(
486
					'predicate'   => 'http://schema.org/author',
487
					'type'        => self::DATA_TYPE_URI,
488
					'export_type' => 'http://schema.org/Person',
489
					'constraints' => array(
490
						'uri_type'    => array( 'Person', 'Organization' ),
491
						'cardinality' => INF,
492
					),
493
				),
494
			),
495
			'templates'     => array(
496
				'subtitle' => '{{id}}',
497
			),
498
		);
499
500
		// Merge the custom fields with those provided by the thing schema.
501
		$thing_schema            = $this->get_thing_schema();
502
		$schema['custom_fields'] = array_merge( $schema['custom_fields'], $thing_schema['custom_fields'] );
503
504
		return $schema;
505
	}
506
507
	/**
508
	 * Get the 'event' schema.
509
	 *
510
	 * @return array An array with the schema configuration.
511
	 *
512
	 * @since 3.1.0
513
	 */
514
	private function get_event_schema() {
515
516
		$schema = array(
517
			'label'         => 'Event',
518
			'description'   => 'An event . ',
519
			'parents'       => array( 'thing' ),
520
			'css_class'     => 'wl-event',
521
			'uri'           => self::SCHEMA_EVENT_TYPE,
522
			'same_as'       => array( 'http://dbpedia.org/ontology/Event' ),
523
			'custom_fields' => array(
524
				self::FIELD_DATE_START => array(
525
					'predicate'   => 'http://schema.org/startDate',
526
					'type'        => self::DATA_TYPE_DATE,
527
					'export_type' => 'xsd:datetime',
528
					'constraints' => '',
529
				),
530
				self::FIELD_DATE_END   => array(
531
					'predicate'   => 'http://schema.org/endDate',
532
					'type'        => self::DATA_TYPE_DATE,
533
					'export_type' => 'xsd:datetime',
534
					'constraints' => '',
535
				),
536
				self::FIELD_LOCATION   => array(
537
					'predicate'   => 'http://schema.org/location',
538
					'type'        => self::DATA_TYPE_URI,
539
					'export_type' => 'http://schema.org/PostalAddress',
540
					'constraints' => array(
541
						'uri_type'    => array( 'Place', 'LocalBusiness' ),
542
						'cardinality' => INF,
543
					),
544
				),
545
			),
546
			'templates'     => array(
547
				'subtitle' => '{{id}}',
548
			),
549
		);
550
551
		// Merge the custom fields with those provided by the thing schema.
552
		$thing_schema            = $this->get_thing_schema();
553
		$schema['custom_fields'] = array_merge( $schema['custom_fields'], $thing_schema['custom_fields'] );
554
555
		return $schema;
556
	}
557
558
	/**
559
	 * Get the 'organization' schema.
560
	 *
561
	 * @return array An array with the schema configuration.
562
	 *
563
	 * @since 3.1.0
564
	 */
565
	private function get_organization_schema() {
566
567
		$schema = array(
568
			'label'         => 'Organization',
569
			'description'   => 'An organization, including a government or a newspaper.',
570
			'parents'       => array( 'thing' ),
571
			'css_class'     => 'wl-organization',
572
			'uri'           => 'http://schema.org/Organization',
573
			'same_as'       => array(
574
				'http://rdf.freebase.com/ns/organization.organization',
575
				'http://rdf.freebase.com/ns/government.government',
576
				'http://schema.org/Newspaper',
577
			),
578
			'custom_fields' => array(
579
				self::FIELD_LEGAL_NAME          => array(
580
					'predicate'   => 'http://schema.org/legalName',
581
					'type'        => self::DATA_TYPE_STRING,
582
					'export_type' => 'xsd:string',
583
					'constraints' => '',
584
				),
585
				self::FIELD_FOUNDER             => array(
586
					'predicate'   => 'http://schema.org/founder',
587
					'type'        => self::DATA_TYPE_URI,
588
					'export_type' => 'http://schema.org/Person',
589
					'constraints' => array(
590
						'uri_type'    => 'Person',
591
						'cardinality' => INF,
592
					),
593
				),
594
				self::FIELD_ADDRESS             => array(
595
					'predicate'   => 'http://schema.org/streetAddress',
596
					'type'        => self::DATA_TYPE_STRING,
597
					'export_type' => 'xsd:string',
598
					'constraints' => '',
599
					// To build custom metabox.
600
					'input_field' => 'address',
601
				),
602
				self::FIELD_ADDRESS_PO_BOX      => array(
603
					'predicate'   => 'http://schema.org/postOfficeBoxNumber',
604
					'type'        => self::DATA_TYPE_STRING,
605
					'export_type' => 'xsd:string',
606
					'constraints' => '',
607
					// To build custom metabox.
608
					'input_field' => 'address',
609
				),
610
				self::FIELD_ADDRESS_POSTAL_CODE => array(
611
					'predicate'   => 'http://schema.org/postalCode',
612
					'type'        => self::DATA_TYPE_STRING,
613
					'export_type' => 'xsd:string',
614
					'constraints' => '',
615
					// To build custom metabox.
616
					'input_field' => 'address',
617
				),
618
				self::FIELD_ADDRESS_LOCALITY    => array(
619
					'predicate'   => 'http://schema.org/addressLocality',
620
					'type'        => self::DATA_TYPE_STRING,
621
					'export_type' => 'xsd:string',
622
					'constraints' => '',
623
					// To build custom metabox.
624
					'input_field' => 'address',
625
				),
626
				self::FIELD_ADDRESS_REGION      => array(
627
					'predicate'   => 'http://schema.org/addressRegion',
628
					'type'        => self::DATA_TYPE_STRING,
629
					'export_type' => 'xsd:string',
630
					'constraints' => '',
631
					// To build custom metabox.
632
					'input_field' => 'address',
633
				),
634
				self::FIELD_ADDRESS_COUNTRY     => array(
635
					'predicate'   => 'http://schema.org/addressCountry',
636
					'type'        => self::DATA_TYPE_STRING,
637
					'export_type' => 'xsd:string',
638
					'constraints' => '',
639
					// To build custom metabox.
640
					'input_field' => 'address',
641
				),
642
				self::FIELD_EMAIL               => array(
643
					'predicate'   => 'http://schema.org/email',
644
					'type'        => self::DATA_TYPE_STRING,
645
					'export_type' => 'xsd:string',
646
					'constraints' => '',
647
				),
648
				self::FIELD_TELEPHONE           => array(
649
					'predicate'   => 'http://schema.org/telephone',
650
					'type'        => self::DATA_TYPE_STRING,
651
					'export_type' => 'xsd:string',
652
					'constraints' => '',
653
				),
654
			),
655
			'templates'     => array(
656
				'subtitle' => '{{id}}',
657
			),
658
		);
659
660
		// Merge the custom fields with those provided by the thing schema.
661
		$thing_schema            = $this->get_thing_schema();
662
		$schema['custom_fields'] = array_merge( $schema['custom_fields'], $thing_schema['custom_fields'] );
663
664
		return $schema;
665
	}
666
667
	/**
668
	 * Get the 'person' schema.
669
	 *
670
	 * @return array An array with the schema configuration.
671
	 *
672
	 * @since 3.1.0
673
	 */
674
	private function get_person_schema() {
675
676
		$schema = array(
677
			'label'         => 'Person',
678
			'description'   => 'A person (or a music artist).',
679
			'parents'       => array( 'thing' ),
680
			'css_class'     => 'wl-person',
681
			'uri'           => 'http://schema.org/Person',
682
			'same_as'       => array(
683
				'http://rdf.freebase.com/ns/people.person',
684
				'http://rdf.freebase.com/ns/music.artist',
685
				'http://dbpedia.org/class/yago/LivingPeople',
686
			),
687
			'custom_fields' => array(
688
				self::FIELD_KNOWS       => array(
689
					'predicate'   => 'http://schema.org/knows',
690
					'type'        => self::DATA_TYPE_URI,
691
					'export_type' => 'http://schema.org/Person',
692
					'constraints' => array(
693
						'uri_type'    => 'Person',
694
						'cardinality' => INF,
695
					),
696
				),
697
				self::FIELD_BIRTH_DATE  => array(
698
					'predicate'   => 'http://schema.org/birthDate',
699
					'type'        => self::DATA_TYPE_DATE,
700
					'export_type' => 'xsd:date',
701
					'constraints' => '',
702
				),
703
				self::FIELD_BIRTH_PLACE => array(
704
					'predicate'   => 'http://schema.org/birthPlace',
705
					'type'        => self::DATA_TYPE_URI,
706
					'export_type' => 'http://schema.org/Place',
707
					'constraints' => array(
708
						'uri_type' => 'Place',
709
					),
710
				),
711
				self::FIELD_AFFILIATION => array(
712
					'predicate'   => 'http://schema.org/affiliation',
713
					'type'        => self::DATA_TYPE_URI,
714
					'export_type' => 'http://schema.org/Organization',
715
					'constraints' => array(
716
						'uri_type'    => array(
717
							'Organization',
718
							'LocalBusiness',
719
						),
720
						'cardinality' => INF,
721
					),
722
				),
723
				self::FIELD_EMAIL       => array(
724
					'predicate'   => 'http://schema.org/email',
725
					'type'        => self::DATA_TYPE_STRING,
726
					'export_type' => 'xsd:string',
727
					'constraints' => array(
728
						'cardinality' => INF,
729
					),
730
				),
731
			),
732
			'templates'     => array(
733
				'subtitle' => '{{id}}',
734
			),
735
		);
736
737
		// Merge the custom fields with those provided by the thing schema.
738
		$thing_schema            = $this->get_thing_schema();
739
		$schema['custom_fields'] = array_merge( $schema['custom_fields'], $thing_schema['custom_fields'] );
740
741
		return $schema;
742
743
	}
744
745
	/**
746
	 * Get the 'place' schema.
747
	 *
748
	 * @return array An array with the schema configuration.
749
	 *
750
	 * @since 3.1.0
751
	 */
752
	private function get_place_schema() {
753
754
		$schema = array(
755
			'label'         => 'Place',
756
			'description'   => 'A place.',
757
			'parents'       => array( 'thing' ),
758
			'css_class'     => 'wl-place',
759
			'uri'           => 'http://schema.org/Place',
760
			'same_as'       => array(
761
				'http://rdf.freebase.com/ns/location.location',
762
				'http://www.opengis.net/gml/_Feature',
763
			),
764
			'custom_fields' => array(
765
				self::FIELD_GEO_LATITUDE        => array(
766
					'predicate'   => 'http://schema.org/latitude',
767
					'type'        => self::DATA_TYPE_DOUBLE,
768
					'export_type' => 'xsd:double',
769
					'constraints' => '',
770
					// To build custom metabox.
771
					'input_field' => 'coordinates',
772
				),
773
				self::FIELD_GEO_LONGITUDE       => array(
774
					'predicate'   => 'http://schema.org/longitude',
775
					'type'        => self::DATA_TYPE_DOUBLE,
776
					'export_type' => 'xsd:double',
777
					'constraints' => '',
778
					// To build custom metabox.
779
					'input_field' => 'coordinates',
780
				),
781
				self::FIELD_ADDRESS             => array(
782
					'predicate'   => 'http://schema.org/streetAddress',
783
					'type'        => self::DATA_TYPE_STRING,
784
					'export_type' => 'xsd:string',
785
					'constraints' => '',
786
					// To build custom metabox.
787
					'input_field' => 'address',
788
				),
789
				self::FIELD_ADDRESS_PO_BOX      => array(
790
					'predicate'   => 'http://schema.org/postOfficeBoxNumber',
791
					'type'        => self::DATA_TYPE_STRING,
792
					'export_type' => 'xsd:string',
793
					'constraints' => '',
794
					// To build custom metabox.
795
					'input_field' => 'address',
796
				),
797
				self::FIELD_ADDRESS_POSTAL_CODE => array(
798
					'predicate'   => 'http://schema.org/postalCode',
799
					'type'        => self::DATA_TYPE_STRING,
800
					'export_type' => 'xsd:string',
801
					'constraints' => '',
802
					// To build custom metabox.
803
					'input_field' => 'address',
804
				),
805
				self::FIELD_ADDRESS_LOCALITY    => array(
806
					'predicate'   => 'http://schema.org/addressLocality',
807
					'type'        => self::DATA_TYPE_STRING,
808
					'export_type' => 'xsd:string',
809
					'constraints' => '',
810
					// To build custom metabox.
811
					'input_field' => 'address',
812
				),
813
				self::FIELD_ADDRESS_REGION      => array(
814
					'predicate'   => 'http://schema.org/addressRegion',
815
					'type'        => self::DATA_TYPE_STRING,
816
					'export_type' => 'xsd:string',
817
					'constraints' => '',
818
					// To build custom metabox.
819
					'input_field' => 'address',
820
				),
821
				self::FIELD_ADDRESS_COUNTRY     => array(
822
					'predicate'   => 'http://schema.org/addressCountry',
823
					'type'        => self::DATA_TYPE_STRING,
824
					'export_type' => 'xsd:string',
825
					'constraints' => '',
826
					// To build custom metabox.
827
					'input_field' => 'address',
828
				),
829
			),
830
			'templates'     => array(
831
				'subtitle' => '{{id}}',
832
			),
833
		);
834
835
		// Merge the custom fields with those provided by the thing schema.
836
		$thing_schema            = $this->get_thing_schema();
837
		$schema['custom_fields'] = array_merge( $schema['custom_fields'], $thing_schema['custom_fields'] );
838
839
		return $schema;
840
	}
841
842
	/**
843
	 * Get the 'local business' schema.
844
	 *
845
	 * @return array An array with the schema configuration.
846
	 *
847
	 * @since 3.1.0
848
	 */
849
	private function get_local_business_schema() {
850
851
		$schema = array(
852
			'label'         => 'LocalBusiness',
853
			'description'   => 'A local business.',
854
			'parents'       => array( 'place', 'organization' ),
855
			'css_class'     => 'wl-local-business',
856
			'uri'           => 'http://schema.org/LocalBusiness',
857
			'same_as'       => array(
858
				'http://rdf.freebase.com/ns/business/business_location',
859
				'https://schema.org/Store',
860
			),
861
			'custom_fields' => array(),
862
			'templates'     => array(
863
				'subtitle' => '{{id}}',
864
			),
865
		);
866
867
		// Merge the custom fields with those provided by the place and organization schema.
868
		$place_schema            = $this->get_place_schema();
869
		$organization_schema     = $this->get_organization_schema();
870
		$schema['custom_fields'] = array_merge( $schema['custom_fields'], $place_schema['custom_fields'], $organization_schema['custom_fields'] );
871
872
		return $schema;
873
	}
874
875
	/**
876
	 * Get the 'recipe' schema.
877
	 *
878
	 * @return array An array with the schema configuration.
879
	 *
880
	 * @since 3.14.0
881
	 */
882
	private function get_recipe_schema() {
883
884
		$schema = array(
885
			'label'         => 'Recipe',
886
			'description'   => 'A Recipe.',
887
			'parents'       => array( 'CreativeWork' ),
888
			'css_class'     => 'wl-recipe',
889
			'uri'           => 'http://schema.org/Recipe',
890
			'same_as'       => array(),
891
			'templates'     => array(
892
				'subtitle' => '{{id}}',
893
			),
894
			'custom_fields' => array(
895
				self::FIELD_RECIPE_CUISINE      => array(
896
					'predicate'   => 'http://schema.org/recipeCuisine',
897
					'type'        => self::DATA_TYPE_STRING,
898
					'export_type' => 'xsd:string',
899
					'constraints' => '',
900
					'metabox'     => array(
901
						'label' => __( 'Recipe cuisine', 'wordlift' ),
902
					),
903
				),
904
				self::FIELD_RECIPE_INGREDIENT   => array(
905
					'predicate'   => 'http://schema.org/recipeIngredient',
906
					'type'        => self::DATA_TYPE_STRING,
907
					'export_type' => 'xsd:string',
908
					'constraints' => array(
909
						'cardinality' => INF,
910
					),
911
					'metabox'     => array(
912
						'label' => __( 'Recipe ingredient', 'wordlift' ),
913
					),
914
				),
915
				self::FIELD_RECIPE_INSTRUCTIONS => array(
916
					'predicate'   => 'http://schema.org/recipeInstructions',
917
					'type'        => self::DATA_TYPE_MULTILINE,
918
					'export_type' => 'xsd:string',
919
					'constraints' => '',
920
					'metabox'     => array(
921
						'class' => 'Wordlift_Metabox_Field_Multiline',
922
						'label' => __( 'Recipe instructions', 'wordlift' ),
923
					),
924
				),
925
				self::FIELD_RECIPE_YIELD        => array(
926
					'predicate'   => 'http://schema.org/recipeYield',
927
					'type'        => self::DATA_TYPE_STRING,
928
					'export_type' => 'xsd:string',
929
					'constraints' => '',
930
					'metabox'     => array(
931
						'label' => __( 'Recipe number of servings', 'wordlift' ),
932
					),
933
				),
934
				self::FIELD_PREP_TIME           => array(
935
					'predicate'   => 'http://schema.org/prepTime',
936
					'type'        => self::DATA_TYPE_DURATION,
937
					'export_type' => 'xsd:time',
938
					'constraints' => '',
939
					'metabox'     => array(
940
						'class' => 'Wordlift_Metabox_Field_Duration',
941
						'label' => __( 'Recipe preparation time', 'wordlift' ),
942
					),
943
				),
944
				self::FIELD_TOTAL_TIME          => array(
945
					'predicate'   => 'http://schema.org/totalTime',
946
					'type'        => self::DATA_TYPE_DURATION,
947
					'export_type' => 'xsd:time',
948
					'constraints' => '',
949
					'metabox'     => array(
950
						'class' => 'Wordlift_Metabox_Field_Duration',
951
						'label' => __( 'Recipe total time', 'wordlift' ),
952
					),
953
				),
954
			),
955
		);
956
957
		// Merge the custom fields with those provided by the parent schema.
958
		$parent_schema           = $this->get_creative_work_schema();
959
		$schema['custom_fields'] = array_merge( $schema['custom_fields'], $parent_schema['custom_fields'] );
960
961
		return $schema;
962
	}
963
964
}
965