Completed
Push — develop ( 258a62...d62d7a )
by David
02:29
created
src/includes/properties/class-wordlift-property-getter-factory.php 2 patches
Indentation   +51 added lines, -51 removed lines patch added patch discarded remove patch
@@ -26,60 +26,60 @@
 block discarded – undo
26 26
  */
27 27
 class Wordlift_Property_Getter_Factory {
28 28
 
29
-	/**
30
-	 * Create a {@link Wordlift_Property_Getter} instance.
31
-	 *
32
-	 * @return \Wordlift_Property_Getter A {@link Wordlift_Property_Getter} instance.
33
-	 * @since 3.8.0
34
-	 */
35
-	public static function create() {
29
+    /**
30
+     * Create a {@link Wordlift_Property_Getter} instance.
31
+     *
32
+     * @return \Wordlift_Property_Getter A {@link Wordlift_Property_Getter} instance.
33
+     * @since 3.8.0
34
+     */
35
+    public static function create() {
36 36
 
37
-		$property_getter = new Wordlift_Property_Getter( new Wordlift_Simple_Property_Service() );
38
-		$property_getter->register(
39
-			new Wordlift_Entity_Property_Service(),
40
-			array(
41
-				Wordlift_Schema_Service::FIELD_FOUNDER,
42
-				Wordlift_Schema_Service::FIELD_AUTHOR,
43
-				Wordlift_Schema_Service::FIELD_KNOWS,
44
-				Wordlift_Schema_Service::FIELD_BIRTH_PLACE,
45
-				Wordlift_Schema_Service::FIELD_AFFILIATION,
46
-				Wordlift_Schema_Service::FIELD_PERFORMER,
47
-				Wordlift_Schema_Service::FIELD_OFFERS,
48
-				Wordlift_Schema_Service::FIELD_ITEM_OFFERED,
49
-			)
50
-		);
51
-		$property_getter->register(
52
-			new Wordlift_Location_Property_Service(),
53
-			array(
54
-				Wordlift_Schema_Service::FIELD_LOCATION,
55
-			)
56
-		);
57
-		$property_getter->register( new Wordlift_Url_Property_Service(), array( Wordlift_Url_Property_Service::META_KEY ) );
58
-		$property_getter->register(
59
-			new Wordlift_Double_Property_Service(),
60
-			array(
61
-				Wordlift_Schema_Service::FIELD_GEO_LATITUDE,
62
-				Wordlift_Schema_Service::FIELD_GEO_LONGITUDE,
63
-			)
64
-		);
37
+        $property_getter = new Wordlift_Property_Getter( new Wordlift_Simple_Property_Service() );
38
+        $property_getter->register(
39
+            new Wordlift_Entity_Property_Service(),
40
+            array(
41
+                Wordlift_Schema_Service::FIELD_FOUNDER,
42
+                Wordlift_Schema_Service::FIELD_AUTHOR,
43
+                Wordlift_Schema_Service::FIELD_KNOWS,
44
+                Wordlift_Schema_Service::FIELD_BIRTH_PLACE,
45
+                Wordlift_Schema_Service::FIELD_AFFILIATION,
46
+                Wordlift_Schema_Service::FIELD_PERFORMER,
47
+                Wordlift_Schema_Service::FIELD_OFFERS,
48
+                Wordlift_Schema_Service::FIELD_ITEM_OFFERED,
49
+            )
50
+        );
51
+        $property_getter->register(
52
+            new Wordlift_Location_Property_Service(),
53
+            array(
54
+                Wordlift_Schema_Service::FIELD_LOCATION,
55
+            )
56
+        );
57
+        $property_getter->register( new Wordlift_Url_Property_Service(), array( Wordlift_Url_Property_Service::META_KEY ) );
58
+        $property_getter->register(
59
+            new Wordlift_Double_Property_Service(),
60
+            array(
61
+                Wordlift_Schema_Service::FIELD_GEO_LATITUDE,
62
+                Wordlift_Schema_Service::FIELD_GEO_LONGITUDE,
63
+            )
64
+        );
65 65
 
66
-		$property_getter->register(
67
-			new Wordlift_Duration_Property_Service(),
68
-			array(
69
-				Wordlift_Schema_Service::FIELD_PREP_TIME,
70
-				Wordlift_Schema_Service::FIELD_COOK_TIME,
71
-				Wordlift_Schema_Service::FIELD_TOTAL_TIME,
72
-			)
73
-		);
66
+        $property_getter->register(
67
+            new Wordlift_Duration_Property_Service(),
68
+            array(
69
+                Wordlift_Schema_Service::FIELD_PREP_TIME,
70
+                Wordlift_Schema_Service::FIELD_COOK_TIME,
71
+                Wordlift_Schema_Service::FIELD_TOTAL_TIME,
72
+            )
73
+        );
74 74
 
75
-		add_action(
76
-			'after_setup_theme',
77
-			function () use ( $property_getter ) {
78
-				$property_getter->register( new Wordlift_Required_Property_Service(), apply_filters( 'wl_required_property', array() ) );
79
-			}
80
-		);
75
+        add_action(
76
+            'after_setup_theme',
77
+            function () use ( $property_getter ) {
78
+                $property_getter->register( new Wordlift_Required_Property_Service(), apply_filters( 'wl_required_property', array() ) );
79
+            }
80
+        );
81 81
 
82
-		return $property_getter;
83
-	}
82
+        return $property_getter;
83
+    }
84 84
 
85 85
 }
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -34,7 +34,7 @@  discard block
 block discarded – undo
34 34
 	 */
35 35
 	public static function create() {
36 36
 
37
-		$property_getter = new Wordlift_Property_Getter( new Wordlift_Simple_Property_Service() );
37
+		$property_getter = new Wordlift_Property_Getter(new Wordlift_Simple_Property_Service());
38 38
 		$property_getter->register(
39 39
 			new Wordlift_Entity_Property_Service(),
40 40
 			array(
@@ -54,7 +54,7 @@  discard block
 block discarded – undo
54 54
 				Wordlift_Schema_Service::FIELD_LOCATION,
55 55
 			)
56 56
 		);
57
-		$property_getter->register( new Wordlift_Url_Property_Service(), array( Wordlift_Url_Property_Service::META_KEY ) );
57
+		$property_getter->register(new Wordlift_Url_Property_Service(), array(Wordlift_Url_Property_Service::META_KEY));
58 58
 		$property_getter->register(
59 59
 			new Wordlift_Double_Property_Service(),
60 60
 			array(
@@ -74,8 +74,8 @@  discard block
 block discarded – undo
74 74
 
75 75
 		add_action(
76 76
 			'after_setup_theme',
77
-			function () use ( $property_getter ) {
78
-				$property_getter->register( new Wordlift_Required_Property_Service(), apply_filters( 'wl_required_property', array() ) );
77
+			function() use ($property_getter) {
78
+				$property_getter->register(new Wordlift_Required_Property_Service(), apply_filters('wl_required_property', array()));
79 79
 			}
80 80
 		);
81 81
 
Please login to merge, or discard this patch.
src/includes/properties/class-wordlift-simple-property-service.php 2 patches
Indentation   +26 added lines, -26 removed lines patch added patch discarded remove patch
@@ -12,33 +12,33 @@
 block discarded – undo
12 12
  */
13 13
 class Wordlift_Simple_Property_Service {
14 14
 
15
-	/**
16
-	 * The meta key for this property service.
17
-	 *
18
-	 * @since 3.8.0
19
-	 */
20
-	const META_KEY = '*';
15
+    /**
16
+     * The meta key for this property service.
17
+     *
18
+     * @since 3.8.0
19
+     */
20
+    const META_KEY = '*';
21 21
 
22
-	/**
23
-	 * Get the property value for the specified post id and meta with the specified key.
24
-	 *
25
-	 * @param int                   $id The post id.
26
-	 * @param string                $meta_key The meta key.
27
-	 *
28
-	 * @param $type int Post or Term
29
-	 *
30
-	 * @return mixed|null The property value.
31
-	 * @since 3.8.0
32
-	 */
33
-	public function get( $id, $meta_key, $type ) {
22
+    /**
23
+     * Get the property value for the specified post id and meta with the specified key.
24
+     *
25
+     * @param int                   $id The post id.
26
+     * @param string                $meta_key The meta key.
27
+     *
28
+     * @param $type int Post or Term
29
+     *
30
+     * @return mixed|null The property value.
31
+     * @since 3.8.0
32
+     */
33
+    public function get( $id, $meta_key, $type ) {
34 34
 
35
-		if ( Object_Type_Enum::POST === $type ) {
36
-			// Get the value stored in WP.
37
-			return get_post_meta( $id, $meta_key );
38
-		} elseif ( Object_Type_Enum::TERM === $type ) {
39
-			return get_term_meta( $id, $meta_key );
40
-		}
41
-		return null;
42
-	}
35
+        if ( Object_Type_Enum::POST === $type ) {
36
+            // Get the value stored in WP.
37
+            return get_post_meta( $id, $meta_key );
38
+        } elseif ( Object_Type_Enum::TERM === $type ) {
39
+            return get_term_meta( $id, $meta_key );
40
+        }
41
+        return null;
42
+    }
43 43
 
44 44
 }
Please login to merge, or discard this patch.
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -30,13 +30,13 @@
 block discarded – undo
30 30
 	 * @return mixed|null The property value.
31 31
 	 * @since 3.8.0
32 32
 	 */
33
-	public function get( $id, $meta_key, $type ) {
33
+	public function get($id, $meta_key, $type) {
34 34
 
35
-		if ( Object_Type_Enum::POST === $type ) {
35
+		if (Object_Type_Enum::POST === $type) {
36 36
 			// Get the value stored in WP.
37
-			return get_post_meta( $id, $meta_key );
38
-		} elseif ( Object_Type_Enum::TERM === $type ) {
39
-			return get_term_meta( $id, $meta_key );
37
+			return get_post_meta($id, $meta_key);
38
+		} elseif (Object_Type_Enum::TERM === $type) {
39
+			return get_term_meta($id, $meta_key);
40 40
 		}
41 41
 		return null;
42 42
 	}
Please login to merge, or discard this patch.
src/includes/properties/class-wordlift-double-property-service.php 2 patches
Indentation   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -16,18 +16,18 @@
 block discarded – undo
16 16
  */
17 17
 class Wordlift_Double_Property_Service extends Wordlift_Simple_Property_Service {
18 18
 
19
-	/**
20
-	 * @inheritdoc
21
-	 */
22
-	public function get( $id, $meta_key, $type ) {
19
+    /**
20
+     * @inheritdoc
21
+     */
22
+    public function get( $id, $meta_key, $type ) {
23 23
 
24
-		// Map the result to a numeric value when possible.
25
-		return array_map(
26
-			function ( $value ) {
27
-				return is_numeric( $value ) ? (float) $value : $value;
28
-			},
29
-			parent::get( $id, $meta_key, $type )
30
-		);
31
-	}
24
+        // Map the result to a numeric value when possible.
25
+        return array_map(
26
+            function ( $value ) {
27
+                return is_numeric( $value ) ? (float) $value : $value;
28
+            },
29
+            parent::get( $id, $meta_key, $type )
30
+        );
31
+    }
32 32
 
33 33
 }
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -19,14 +19,14 @@
 block discarded – undo
19 19
 	/**
20 20
 	 * @inheritdoc
21 21
 	 */
22
-	public function get( $id, $meta_key, $type ) {
22
+	public function get($id, $meta_key, $type) {
23 23
 
24 24
 		// Map the result to a numeric value when possible.
25 25
 		return array_map(
26
-			function ( $value ) {
27
-				return is_numeric( $value ) ? (float) $value : $value;
26
+			function($value) {
27
+				return is_numeric($value) ? (float) $value : $value;
28 28
 			},
29
-			parent::get( $id, $meta_key, $type )
29
+			parent::get($id, $meta_key, $type)
30 30
 		);
31 31
 	}
32 32
 }
Please login to merge, or discard this patch.
src/includes/class-wordlift-redirect-service.php 2 patches
Spacing   +20 added lines, -20 removed lines patch added patch discarded remove patch
@@ -51,9 +51,9 @@  discard block
 block discarded – undo
51 51
 	 *
52 52
 	 * @since 3.2.0
53 53
 	 */
54
-	public function __construct( $entity_uri_service ) {
54
+	public function __construct($entity_uri_service) {
55 55
 
56
-		$this->log_service = Wordlift_Log_Service::get_logger( 'Wordlift_Redirect_Service' );
56
+		$this->log_service = Wordlift_Log_Service::get_logger('Wordlift_Redirect_Service');
57 57
 
58 58
 		$this->entity_uri_service = $entity_uri_service;
59 59
 
@@ -80,11 +80,11 @@  discard block
 block discarded – undo
80 80
 	public function ajax_redirect() {
81 81
 
82 82
 		// Check the `uri` parameter.
83
-		$entity_uri = filter_input( INPUT_GET, 'uri', FILTER_VALIDATE_URL );
84
-		if ( ! $entity_uri ) {
83
+		$entity_uri = filter_input(INPUT_GET, 'uri', FILTER_VALIDATE_URL);
84
+		if ( ! $entity_uri) {
85 85
 			wp_die(
86
-				esc_html__( 'Invalid URI.', 'wordlift' ),
87
-				esc_html__( 'Invalid URI.', 'wordlift' ),
86
+				esc_html__('Invalid URI.', 'wordlift'),
87
+				esc_html__('Invalid URI.', 'wordlift'),
88 88
 				array(
89 89
 					'response'  => 400,
90 90
 					'back_link' => true,
@@ -93,11 +93,11 @@  discard block
 block discarded – undo
93 93
 		}
94 94
 
95 95
 		// Check the `to` parameter.
96
-		$target = filter_input( INPUT_GET, 'to' );
97
-		if ( ! $target ) {
96
+		$target = filter_input(INPUT_GET, 'to');
97
+		if ( ! $target) {
98 98
 			wp_die(
99
-				esc_html__( 'Invalid `to` parameter.', 'wordlift' ),
100
-				esc_html__( 'Invalid `to` parameter.', 'wordlift' ),
99
+				esc_html__('Invalid `to` parameter.', 'wordlift'),
100
+				esc_html__('Invalid `to` parameter.', 'wordlift'),
101 101
 				array(
102 102
 					'response'  => 400,
103 103
 					'back_link' => true,
@@ -107,12 +107,12 @@  discard block
 block discarded – undo
107 107
 
108 108
 		/** @var Wordpress_Content $content */
109 109
 		$content = Wordpress_Content_Service::get_instance()
110
-											->get_by_entity_id_or_same_as( $entity_uri );
110
+											->get_by_entity_id_or_same_as($entity_uri);
111 111
 
112
-		if ( ! isset( $content ) ) {
112
+		if ( ! isset($content)) {
113 113
 			wp_die(
114
-				esc_html__( 'Entity not found.', 'wordlift' ),
115
-				esc_html__( 'Entity not found.', 'wordlift' ),
114
+				esc_html__('Entity not found.', 'wordlift'),
115
+				esc_html__('Entity not found.', 'wordlift'),
116 116
 				array(
117 117
 					'response'  => 404,
118 118
 					'back_link' => true,
@@ -120,22 +120,22 @@  discard block
 block discarded – undo
120 120
 			);
121 121
 		}
122 122
 
123
-		switch ( $target ) {
123
+		switch ($target) {
124 124
 			case 'edit':
125 125
 				$redirect_url = $content->get_edit_link();
126 126
 				break;
127 127
 			case 'lod':
128
-				$redirect_url = self::LOD_ENDPOINT . '/lodview/?IRI=' . rawurlencode( $entity_uri );
128
+				$redirect_url = self::LOD_ENDPOINT.'/lodview/?IRI='.rawurlencode($entity_uri);
129 129
 				break;
130 130
 			case 'permalink':
131 131
 				$redirect_url = $content->get_permalink();
132 132
 				break;
133 133
 			default:
134
-				wp_die( 'Unsupported redirect target.' );
134
+				wp_die('Unsupported redirect target.');
135 135
 		}
136 136
 
137 137
 		// Perform the redirect
138
-		wp_safe_redirect( $redirect_url );
138
+		wp_safe_redirect($redirect_url);
139 139
 		exit;
140 140
 	}
141 141
 
@@ -148,9 +148,9 @@  discard block
 block discarded – undo
148 148
 	 *
149 149
 	 * @return array permalink.
150 150
 	 */
151
-	public function allowed_redirect_hosts( $content ) {
151
+	public function allowed_redirect_hosts($content) {
152 152
 
153
-		return array_merge( $content, array( self::LOD_HOST ) );
153
+		return array_merge($content, array(self::LOD_HOST));
154 154
 	}
155 155
 
156 156
 }
Please login to merge, or discard this patch.
Indentation   +137 added lines, -137 removed lines patch added patch discarded remove patch
@@ -14,141 +14,141 @@
 block discarded – undo
14 14
  */
15 15
 class Wordlift_Redirect_Service {
16 16
 
17
-	const LOD_ENDPOINT = 'http://www.lodview.it';
18
-	const LOD_HOST     = 'www.lodview.it';
19
-
20
-	/**
21
-	 * The Log service.
22
-	 *
23
-	 * @since 3.2.0
24
-	 * @access private
25
-	 * @var \Wordlift_Log_Service $log_service The Log service.
26
-	 */
27
-	private $log_service;
28
-
29
-	/**
30
-	 * The Entity URI service.
31
-	 *
32
-	 * @since 3.2.0
33
-	 * @access private
34
-	 * @var Wordlift_Entity_Uri_Service $entity_uri_service The Entity service.
35
-	 */
36
-	private $entity_uri_service;
37
-
38
-	/**
39
-	 * A singleton instance of the Redirect service (useful for unit tests).
40
-	 *
41
-	 * @since 3.2.0
42
-	 * @access private
43
-	 * @var \Wordlift_Redirect_Service $instance The singleton instance.
44
-	 */
45
-	private static $instance;
46
-
47
-	/**
48
-	 * Create a Wordlift_Redirect_Service instance.
49
-	 *
50
-	 * @param Wordlift_Entity_Uri_Service $entity_uri_service The Entity service.
51
-	 *
52
-	 * @since 3.2.0
53
-	 */
54
-	public function __construct( $entity_uri_service ) {
55
-
56
-		$this->log_service = Wordlift_Log_Service::get_logger( 'Wordlift_Redirect_Service' );
57
-
58
-		$this->entity_uri_service = $entity_uri_service;
59
-
60
-		self::$instance = $this;
61
-	}
62
-
63
-	/**
64
-	 * Get the singleton instance of the Wordlift_Redirect_Service
65
-	 *
66
-	 * @return \Wordlift_Redirect_Service The singleton instance of the Wordlift_Redirect_Service.
67
-	 * @since 3.2.0
68
-	 */
69
-	public static function get_instance() {
70
-
71
-		return self::$instance;
72
-	}
73
-
74
-	/**
75
-	 * Perform redirect depending on entity uri and target
76
-	 *
77
-	 * @since 3.2.0
78
-	 */
79
-	public function ajax_redirect() {
80
-
81
-		// Check the `uri` parameter.
82
-		$entity_uri = filter_input( INPUT_GET, 'uri', FILTER_VALIDATE_URL );
83
-		if ( ! $entity_uri ) {
84
-			wp_die(
85
-				esc_html__( 'Invalid URI.', 'wordlift' ),
86
-				esc_html__( 'Invalid URI.', 'wordlift' ),
87
-				array(
88
-					'response'  => 400,
89
-					'back_link' => true,
90
-				)
91
-			);
92
-		}
93
-
94
-		// Check the `to` parameter.
95
-		$target = filter_input( INPUT_GET, 'to' );
96
-		if ( ! $target ) {
97
-			wp_die(
98
-				esc_html__( 'Invalid `to` parameter.', 'wordlift' ),
99
-				esc_html__( 'Invalid `to` parameter.', 'wordlift' ),
100
-				array(
101
-					'response'  => 400,
102
-					'back_link' => true,
103
-				)
104
-			);
105
-		}
106
-
107
-		/** @var Wordpress_Content $content */
108
-		$content = Wordpress_Content_Service::get_instance()
109
-											->get_by_entity_id_or_same_as( $entity_uri );
110
-
111
-		if ( ! isset( $content ) ) {
112
-			wp_die(
113
-				esc_html__( 'Entity not found.', 'wordlift' ),
114
-				esc_html__( 'Entity not found.', 'wordlift' ),
115
-				array(
116
-					'response'  => 404,
117
-					'back_link' => true,
118
-				)
119
-			);
120
-		}
121
-
122
-		switch ( $target ) {
123
-			case 'edit':
124
-				$redirect_url = $content->get_edit_link();
125
-				break;
126
-			case 'lod':
127
-				$redirect_url = self::LOD_ENDPOINT . '/lodview/?IRI=' . rawurlencode( $entity_uri );
128
-				break;
129
-			case 'permalink':
130
-				$redirect_url = $content->get_permalink();
131
-				break;
132
-			default:
133
-				wp_die( 'Unsupported redirect target.' );
134
-		}
135
-
136
-		// Perform the redirect
137
-		wp_safe_redirect( $redirect_url );
138
-		exit;
139
-	}
140
-
141
-	/**
142
-	 * Register custom allowed hosts.
143
-	 *
144
-	 * @see https://developer.wordpress.org/reference/functions/wp_safe_redirect/
145
-	 *
146
-	 * @since 3.2.0
147
-	 *
148
-	 * @return array permalink.
149
-	 */
150
-	public function allowed_redirect_hosts( $content ) {
151
-
152
-		return array_merge( $content, array( self::LOD_HOST ) );
153
-	}
17
+    const LOD_ENDPOINT = 'http://www.lodview.it';
18
+    const LOD_HOST     = 'www.lodview.it';
19
+
20
+    /**
21
+     * The Log service.
22
+     *
23
+     * @since 3.2.0
24
+     * @access private
25
+     * @var \Wordlift_Log_Service $log_service The Log service.
26
+     */
27
+    private $log_service;
28
+
29
+    /**
30
+     * The Entity URI service.
31
+     *
32
+     * @since 3.2.0
33
+     * @access private
34
+     * @var Wordlift_Entity_Uri_Service $entity_uri_service The Entity service.
35
+     */
36
+    private $entity_uri_service;
37
+
38
+    /**
39
+     * A singleton instance of the Redirect service (useful for unit tests).
40
+     *
41
+     * @since 3.2.0
42
+     * @access private
43
+     * @var \Wordlift_Redirect_Service $instance The singleton instance.
44
+     */
45
+    private static $instance;
46
+
47
+    /**
48
+     * Create a Wordlift_Redirect_Service instance.
49
+     *
50
+     * @param Wordlift_Entity_Uri_Service $entity_uri_service The Entity service.
51
+     *
52
+     * @since 3.2.0
53
+     */
54
+    public function __construct( $entity_uri_service ) {
55
+
56
+        $this->log_service = Wordlift_Log_Service::get_logger( 'Wordlift_Redirect_Service' );
57
+
58
+        $this->entity_uri_service = $entity_uri_service;
59
+
60
+        self::$instance = $this;
61
+    }
62
+
63
+    /**
64
+     * Get the singleton instance of the Wordlift_Redirect_Service
65
+     *
66
+     * @return \Wordlift_Redirect_Service The singleton instance of the Wordlift_Redirect_Service.
67
+     * @since 3.2.0
68
+     */
69
+    public static function get_instance() {
70
+
71
+        return self::$instance;
72
+    }
73
+
74
+    /**
75
+     * Perform redirect depending on entity uri and target
76
+     *
77
+     * @since 3.2.0
78
+     */
79
+    public function ajax_redirect() {
80
+
81
+        // Check the `uri` parameter.
82
+        $entity_uri = filter_input( INPUT_GET, 'uri', FILTER_VALIDATE_URL );
83
+        if ( ! $entity_uri ) {
84
+            wp_die(
85
+                esc_html__( 'Invalid URI.', 'wordlift' ),
86
+                esc_html__( 'Invalid URI.', 'wordlift' ),
87
+                array(
88
+                    'response'  => 400,
89
+                    'back_link' => true,
90
+                )
91
+            );
92
+        }
93
+
94
+        // Check the `to` parameter.
95
+        $target = filter_input( INPUT_GET, 'to' );
96
+        if ( ! $target ) {
97
+            wp_die(
98
+                esc_html__( 'Invalid `to` parameter.', 'wordlift' ),
99
+                esc_html__( 'Invalid `to` parameter.', 'wordlift' ),
100
+                array(
101
+                    'response'  => 400,
102
+                    'back_link' => true,
103
+                )
104
+            );
105
+        }
106
+
107
+        /** @var Wordpress_Content $content */
108
+        $content = Wordpress_Content_Service::get_instance()
109
+                                            ->get_by_entity_id_or_same_as( $entity_uri );
110
+
111
+        if ( ! isset( $content ) ) {
112
+            wp_die(
113
+                esc_html__( 'Entity not found.', 'wordlift' ),
114
+                esc_html__( 'Entity not found.', 'wordlift' ),
115
+                array(
116
+                    'response'  => 404,
117
+                    'back_link' => true,
118
+                )
119
+            );
120
+        }
121
+
122
+        switch ( $target ) {
123
+            case 'edit':
124
+                $redirect_url = $content->get_edit_link();
125
+                break;
126
+            case 'lod':
127
+                $redirect_url = self::LOD_ENDPOINT . '/lodview/?IRI=' . rawurlencode( $entity_uri );
128
+                break;
129
+            case 'permalink':
130
+                $redirect_url = $content->get_permalink();
131
+                break;
132
+            default:
133
+                wp_die( 'Unsupported redirect target.' );
134
+        }
135
+
136
+        // Perform the redirect
137
+        wp_safe_redirect( $redirect_url );
138
+        exit;
139
+    }
140
+
141
+    /**
142
+     * Register custom allowed hosts.
143
+     *
144
+     * @see https://developer.wordpress.org/reference/functions/wp_safe_redirect/
145
+     *
146
+     * @since 3.2.0
147
+     *
148
+     * @return array permalink.
149
+     */
150
+    public function allowed_redirect_hosts( $content ) {
151
+
152
+        return array_merge( $content, array( self::LOD_HOST ) );
153
+    }
154 154
 }
Please login to merge, or discard this patch.
src/includes/schemaorg/class-wordlift-schemaorg-sync-batch-operation.php 2 patches
Indentation   +114 added lines, -114 removed lines patch added patch discarded remove patch
@@ -16,119 +16,119 @@
 block discarded – undo
16 16
  */
17 17
 class Wordlift_Schemaorg_Sync_Batch_Operation implements Wordlift_Batch_Operation_Interface {
18 18
 
19
-	private static $instance = null;
20
-
21
-	public static function get_instance() {
22
-
23
-		if ( ! isset( self::$instance ) ) {
24
-			self::$instance = new self();
25
-		}
26
-
27
-		return self::$instance;
28
-	}
29
-
30
-	/**
31
-	 * Process the batch operation starting from the specified offset.
32
-	 *
33
-	 * @param int $offset Start from the specified offset (or 0 if not specified).
34
-	 * @param int $limit Process the specified amount of items per call (or 10 if not specified).
35
-	 *
36
-	 * @return array {
37
-	 * The operation result.
38
-	 *
39
-	 * @type int $next The next offset.
40
-	 * @type int $limit The amount of items to process per call.
41
-	 * @type int $remaining The remaining number of elements to process.
42
-	 * }
43
-	 * @since 3.20.0
44
-	 */
45
-	public function process( $offset = 0, $limit = 10 ) {
46
-
47
-		// Get the schema classes.
48
-		$all_schema_classes = $this->get_schema_classes();
49
-
50
-		// Get only the part that we need to process.
51
-		$schema_classes = array_slice( $all_schema_classes, $offset, $limit );
52
-
53
-		// Load the Schema.org classes.
54
-		foreach ( $schema_classes as $schema_class ) {
55
-			$slug = $schema_class['dashname'];
56
-			$term = term_exists( $slug, Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME );
57
-
58
-			$args = array(
59
-				'parent'      => 0,
60
-				'description' => $schema_class['description'],
61
-				'slug'        => $schema_class['dashname'],
62
-			);
63
-			if ( null !== $term ) {
64
-				wp_update_term( $term['term_id'], Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME, $args );
65
-			} else {
66
-				$term = wp_insert_term( $schema_class['name'], Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME, $args );
67
-			}
68
-
69
-			// Update the parents/children relationship.
70
-			delete_term_meta( $term['term_id'], Wordlift_Schemaorg_Class_Service::PARENT_OF_META_KEY );
71
-			foreach ( $schema_class['children'] as $child ) {
72
-				add_term_meta( $term['term_id'], Wordlift_Schemaorg_Class_Service::PARENT_OF_META_KEY, $child['dashname'] );
73
-			}
74
-
75
-			// Update the term name.
76
-			delete_term_meta( $term['term_id'], Wordlift_Schemaorg_Class_Service::NAME_META_KEY );
77
-			update_term_meta( $term['term_id'], Wordlift_Schemaorg_Class_Service::NAME_META_KEY, $schema_class['name'] );
78
-
79
-			// Update the term URI.
80
-			delete_term_meta( $term['term_id'], Wordlift_Schemaorg_Class_Service::URI_META_KEY );
81
-			update_term_meta( $term['term_id'], Wordlift_Schemaorg_Class_Service::URI_META_KEY, "http://schema.org/{$schema_class['name']}" );
82
-
83
-		}
84
-
85
-		// Calculate the return values.
86
-		$next      = $offset + $limit;
87
-		$remaining = $this->count();
88
-
89
-		return array(
90
-			'next'      => $next,
91
-			'limit'     => $limit,
92
-			'complete'  => ( 0 === $remaining ),
93
-			'remaining' => $remaining,
94
-		);
95
-	}
96
-
97
-	/**
98
-	 * Count the number of elements that would be affected by the operation.
99
-	 *
100
-	 * @return int The number of elements that would be affected.
101
-	 * @since 3.20.0
102
-	 */
103
-	public function count() {
104
-
105
-		// Schema Classes count.
106
-		$schema_classes_count = count( $this->get_schema_classes() );
107
-
108
-		// Terms count.
109
-		$terms_count = wp_count_terms( Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME );
110
-
111
-		// Return the difference.
112
-		return $schema_classes_count - $terms_count;
113
-	}
114
-
115
-	/**
116
-	 * Get the schema.org classes from the JSON file.
117
-	 *
118
-	 * @return array An array of schema classes.
119
-	 * @since 3.20.0
120
-	 */
121
-	private function get_schema_classes() {
122
-
123
-		// Load the file contents.
124
-		// phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents
125
-		$contents = file_get_contents( __DIR__ . '/schema-classes.json' );
126
-
127
-		// Decode the JSON contents.
128
-		$json = json_decode( $contents, true );
129
-
130
-		// Return the schema classes or an empty array.
131
-		return isset( $json['schemaClasses'] ) ? $json['schemaClasses'] : array();
132
-	}
19
+    private static $instance = null;
20
+
21
+    public static function get_instance() {
22
+
23
+        if ( ! isset( self::$instance ) ) {
24
+            self::$instance = new self();
25
+        }
26
+
27
+        return self::$instance;
28
+    }
29
+
30
+    /**
31
+     * Process the batch operation starting from the specified offset.
32
+     *
33
+     * @param int $offset Start from the specified offset (or 0 if not specified).
34
+     * @param int $limit Process the specified amount of items per call (or 10 if not specified).
35
+     *
36
+     * @return array {
37
+     * The operation result.
38
+     *
39
+     * @type int $next The next offset.
40
+     * @type int $limit The amount of items to process per call.
41
+     * @type int $remaining The remaining number of elements to process.
42
+     * }
43
+     * @since 3.20.0
44
+     */
45
+    public function process( $offset = 0, $limit = 10 ) {
46
+
47
+        // Get the schema classes.
48
+        $all_schema_classes = $this->get_schema_classes();
49
+
50
+        // Get only the part that we need to process.
51
+        $schema_classes = array_slice( $all_schema_classes, $offset, $limit );
52
+
53
+        // Load the Schema.org classes.
54
+        foreach ( $schema_classes as $schema_class ) {
55
+            $slug = $schema_class['dashname'];
56
+            $term = term_exists( $slug, Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME );
57
+
58
+            $args = array(
59
+                'parent'      => 0,
60
+                'description' => $schema_class['description'],
61
+                'slug'        => $schema_class['dashname'],
62
+            );
63
+            if ( null !== $term ) {
64
+                wp_update_term( $term['term_id'], Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME, $args );
65
+            } else {
66
+                $term = wp_insert_term( $schema_class['name'], Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME, $args );
67
+            }
68
+
69
+            // Update the parents/children relationship.
70
+            delete_term_meta( $term['term_id'], Wordlift_Schemaorg_Class_Service::PARENT_OF_META_KEY );
71
+            foreach ( $schema_class['children'] as $child ) {
72
+                add_term_meta( $term['term_id'], Wordlift_Schemaorg_Class_Service::PARENT_OF_META_KEY, $child['dashname'] );
73
+            }
74
+
75
+            // Update the term name.
76
+            delete_term_meta( $term['term_id'], Wordlift_Schemaorg_Class_Service::NAME_META_KEY );
77
+            update_term_meta( $term['term_id'], Wordlift_Schemaorg_Class_Service::NAME_META_KEY, $schema_class['name'] );
78
+
79
+            // Update the term URI.
80
+            delete_term_meta( $term['term_id'], Wordlift_Schemaorg_Class_Service::URI_META_KEY );
81
+            update_term_meta( $term['term_id'], Wordlift_Schemaorg_Class_Service::URI_META_KEY, "http://schema.org/{$schema_class['name']}" );
82
+
83
+        }
84
+
85
+        // Calculate the return values.
86
+        $next      = $offset + $limit;
87
+        $remaining = $this->count();
88
+
89
+        return array(
90
+            'next'      => $next,
91
+            'limit'     => $limit,
92
+            'complete'  => ( 0 === $remaining ),
93
+            'remaining' => $remaining,
94
+        );
95
+    }
96
+
97
+    /**
98
+     * Count the number of elements that would be affected by the operation.
99
+     *
100
+     * @return int The number of elements that would be affected.
101
+     * @since 3.20.0
102
+     */
103
+    public function count() {
104
+
105
+        // Schema Classes count.
106
+        $schema_classes_count = count( $this->get_schema_classes() );
107
+
108
+        // Terms count.
109
+        $terms_count = wp_count_terms( Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME );
110
+
111
+        // Return the difference.
112
+        return $schema_classes_count - $terms_count;
113
+    }
114
+
115
+    /**
116
+     * Get the schema.org classes from the JSON file.
117
+     *
118
+     * @return array An array of schema classes.
119
+     * @since 3.20.0
120
+     */
121
+    private function get_schema_classes() {
122
+
123
+        // Load the file contents.
124
+        // phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents
125
+        $contents = file_get_contents( __DIR__ . '/schema-classes.json' );
126
+
127
+        // Decode the JSON contents.
128
+        $json = json_decode( $contents, true );
129
+
130
+        // Return the schema classes or an empty array.
131
+        return isset( $json['schemaClasses'] ) ? $json['schemaClasses'] : array();
132
+    }
133 133
 
134 134
 }
Please login to merge, or discard this patch.
Spacing   +21 added lines, -21 removed lines patch added patch discarded remove patch
@@ -20,7 +20,7 @@  discard block
 block discarded – undo
20 20
 
21 21
 	public static function get_instance() {
22 22
 
23
-		if ( ! isset( self::$instance ) ) {
23
+		if ( ! isset(self::$instance)) {
24 24
 			self::$instance = new self();
25 25
 		}
26 26
 
@@ -42,43 +42,43 @@  discard block
 block discarded – undo
42 42
 	 * }
43 43
 	 * @since 3.20.0
44 44
 	 */
45
-	public function process( $offset = 0, $limit = 10 ) {
45
+	public function process($offset = 0, $limit = 10) {
46 46
 
47 47
 		// Get the schema classes.
48 48
 		$all_schema_classes = $this->get_schema_classes();
49 49
 
50 50
 		// Get only the part that we need to process.
51
-		$schema_classes = array_slice( $all_schema_classes, $offset, $limit );
51
+		$schema_classes = array_slice($all_schema_classes, $offset, $limit);
52 52
 
53 53
 		// Load the Schema.org classes.
54
-		foreach ( $schema_classes as $schema_class ) {
54
+		foreach ($schema_classes as $schema_class) {
55 55
 			$slug = $schema_class['dashname'];
56
-			$term = term_exists( $slug, Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME );
56
+			$term = term_exists($slug, Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME);
57 57
 
58 58
 			$args = array(
59 59
 				'parent'      => 0,
60 60
 				'description' => $schema_class['description'],
61 61
 				'slug'        => $schema_class['dashname'],
62 62
 			);
63
-			if ( null !== $term ) {
64
-				wp_update_term( $term['term_id'], Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME, $args );
63
+			if (null !== $term) {
64
+				wp_update_term($term['term_id'], Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME, $args);
65 65
 			} else {
66
-				$term = wp_insert_term( $schema_class['name'], Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME, $args );
66
+				$term = wp_insert_term($schema_class['name'], Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME, $args);
67 67
 			}
68 68
 
69 69
 			// Update the parents/children relationship.
70
-			delete_term_meta( $term['term_id'], Wordlift_Schemaorg_Class_Service::PARENT_OF_META_KEY );
71
-			foreach ( $schema_class['children'] as $child ) {
72
-				add_term_meta( $term['term_id'], Wordlift_Schemaorg_Class_Service::PARENT_OF_META_KEY, $child['dashname'] );
70
+			delete_term_meta($term['term_id'], Wordlift_Schemaorg_Class_Service::PARENT_OF_META_KEY);
71
+			foreach ($schema_class['children'] as $child) {
72
+				add_term_meta($term['term_id'], Wordlift_Schemaorg_Class_Service::PARENT_OF_META_KEY, $child['dashname']);
73 73
 			}
74 74
 
75 75
 			// Update the term name.
76
-			delete_term_meta( $term['term_id'], Wordlift_Schemaorg_Class_Service::NAME_META_KEY );
77
-			update_term_meta( $term['term_id'], Wordlift_Schemaorg_Class_Service::NAME_META_KEY, $schema_class['name'] );
76
+			delete_term_meta($term['term_id'], Wordlift_Schemaorg_Class_Service::NAME_META_KEY);
77
+			update_term_meta($term['term_id'], Wordlift_Schemaorg_Class_Service::NAME_META_KEY, $schema_class['name']);
78 78
 
79 79
 			// Update the term URI.
80
-			delete_term_meta( $term['term_id'], Wordlift_Schemaorg_Class_Service::URI_META_KEY );
81
-			update_term_meta( $term['term_id'], Wordlift_Schemaorg_Class_Service::URI_META_KEY, "http://schema.org/{$schema_class['name']}" );
80
+			delete_term_meta($term['term_id'], Wordlift_Schemaorg_Class_Service::URI_META_KEY);
81
+			update_term_meta($term['term_id'], Wordlift_Schemaorg_Class_Service::URI_META_KEY, "http://schema.org/{$schema_class['name']}");
82 82
 
83 83
 		}
84 84
 
@@ -89,7 +89,7 @@  discard block
 block discarded – undo
89 89
 		return array(
90 90
 			'next'      => $next,
91 91
 			'limit'     => $limit,
92
-			'complete'  => ( 0 === $remaining ),
92
+			'complete'  => (0 === $remaining),
93 93
 			'remaining' => $remaining,
94 94
 		);
95 95
 	}
@@ -103,10 +103,10 @@  discard block
 block discarded – undo
103 103
 	public function count() {
104 104
 
105 105
 		// Schema Classes count.
106
-		$schema_classes_count = count( $this->get_schema_classes() );
106
+		$schema_classes_count = count($this->get_schema_classes());
107 107
 
108 108
 		// Terms count.
109
-		$terms_count = wp_count_terms( Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME );
109
+		$terms_count = wp_count_terms(Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME);
110 110
 
111 111
 		// Return the difference.
112 112
 		return $schema_classes_count - $terms_count;
@@ -122,13 +122,13 @@  discard block
 block discarded – undo
122 122
 
123 123
 		// Load the file contents.
124 124
 		// phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents
125
-		$contents = file_get_contents( __DIR__ . '/schema-classes.json' );
125
+		$contents = file_get_contents(__DIR__.'/schema-classes.json');
126 126
 
127 127
 		// Decode the JSON contents.
128
-		$json = json_decode( $contents, true );
128
+		$json = json_decode($contents, true);
129 129
 
130 130
 		// Return the schema classes or an empty array.
131
-		return isset( $json['schemaClasses'] ) ? $json['schemaClasses'] : array();
131
+		return isset($json['schemaClasses']) ? $json['schemaClasses'] : array();
132 132
 	}
133 133
 
134 134
 }
Please login to merge, or discard this patch.
src/includes/schemaorg/class-wordlift-schemaorg-property-service.php 2 patches
Spacing   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -43,7 +43,7 @@  discard block
 block discarded – undo
43 43
 	 */
44 44
 	public static function get_instance() {
45 45
 
46
-		if ( ! isset( self::$instance ) ) {
46
+		if ( ! isset(self::$instance)) {
47 47
 			self::$instance = new self();
48 48
 		}
49 49
 
@@ -60,32 +60,32 @@  discard block
 block discarded – undo
60 60
 	 * }
61 61
 	 * @since 3.20.0
62 62
 	 */
63
-	public function get_all( $post_id ) {
63
+	public function get_all($post_id) {
64 64
 
65 65
 		// Get all the post metas.
66
-		$post_metas = get_post_meta( $post_id );
66
+		$post_metas = get_post_meta($post_id);
67 67
 
68 68
 		// Cycle through them to get the Schema.org properties.
69 69
 		$props = array();
70
-		foreach ( $post_metas as $key => $values ) {
70
+		foreach ($post_metas as $key => $values) {
71 71
 			$matches = array();
72 72
 
73 73
 			// We're looking for `_wl_prop_propName_uuid_key`.
74
-			if ( 1 === preg_match( '/' . self::PREFIX . '(\w+)_([\w-]+)_(\w+)/i', $key, $matches ) ) {
74
+			if (1 === preg_match('/'.self::PREFIX.'(\w+)_([\w-]+)_(\w+)/i', $key, $matches)) {
75 75
 				$name = $matches[1];
76 76
 				$uuid = $matches[2];
77 77
 				$key  = $matches[3];
78 78
 
79 79
 				// Record the value.
80
-				$props[ $name ][ $uuid ][ $key ] = $values[0];
80
+				$props[$name][$uuid][$key] = $values[0];
81 81
 			}
82 82
 		}
83 83
 
84 84
 		// Remove the UUIDs.
85
-		foreach ( $props as $name => $instance ) {
86
-			foreach ( $instance as $uuid => $keys ) {
85
+		foreach ($props as $name => $instance) {
86
+			foreach ($instance as $uuid => $keys) {
87 87
 				// This way we remove the `uuid`s.
88
-				$props[ $name ] = array_values( $instance );
88
+				$props[$name] = array_values($instance);
89 89
 			}
90 90
 		}
91 91
 
@@ -101,20 +101,20 @@  discard block
 block discarded – undo
101 101
 	 * @return array An array of meta keys.
102 102
 	 * @since 3.20.0
103 103
 	 */
104
-	public function get_keys( $post_id ) {
104
+	public function get_keys($post_id) {
105 105
 
106 106
 		// Get all the post metas to remove the `_wl_prop` ones.
107
-		$post_meta = get_post_meta( $post_id );
107
+		$post_meta = get_post_meta($post_id);
108 108
 
109 109
 		// Get the keys.
110
-		$post_meta_keys = array_unique( array_keys( $post_meta ) );
110
+		$post_meta_keys = array_unique(array_keys($post_meta));
111 111
 
112 112
 		// Get only the `_wl_prop` keys. `array_values` resets the indexes.
113 113
 		$prop_keys = array_values(
114 114
 			array_filter(
115 115
 				$post_meta_keys,
116
-				function ( $item ) {
117
-					return 0 === strpos( $item, Wordlift_Schemaorg_Property_Service::PREFIX );
116
+				function($item) {
117
+					return 0 === strpos($item, Wordlift_Schemaorg_Property_Service::PREFIX);
118 118
 				}
119 119
 			)
120 120
 		);
Please login to merge, or discard this patch.
Indentation   +104 added lines, -104 removed lines patch added patch discarded remove patch
@@ -16,108 +16,108 @@
 block discarded – undo
16 16
  */
17 17
 class Wordlift_Schemaorg_Property_Service {
18 18
 
19
-	/**
20
-	 * The meta key prefix used to store properties. The `_` prefix makes these metas invisible in the
21
-	 * edit screen custom fields metabox.
22
-	 *
23
-	 * @since 3.20.0
24
-	 */
25
-	const PREFIX = '_wl_prop_';
26
-
27
-	/**
28
-	 * Create a {@link Wordlift_Schemaorg_Property_Service} instance.
29
-	 *
30
-	 * @since 3.20.0
31
-	 */
32
-	protected function __construct() {
33
-	}
34
-
35
-	private static $instance = null;
36
-
37
-	/**
38
-	 * Get the singleton instance.
39
-	 *
40
-	 * @return \Wordlift_Schemaorg_Property_Service The singleton instance.
41
-	 * @since 3.20.0
42
-	 */
43
-	public static function get_instance() {
44
-
45
-		if ( ! isset( self::$instance ) ) {
46
-			self::$instance = new self();
47
-		}
48
-
49
-		return self::$instance;
50
-	}
51
-
52
-	/**
53
-	 * Get all the properties bound to the specified post.
54
-	 *
55
-	 * @param int $post_id The post id.
56
-	 *
57
-	 * @return array An array of properties instances keyed by the property name. Each property contains a
58
-	 *  `type` and a `value` and optionally a `language`.
59
-	 * }
60
-	 * @since 3.20.0
61
-	 */
62
-	public function get_all( $post_id ) {
63
-
64
-		// Get all the post metas.
65
-		$post_metas = get_post_meta( $post_id );
66
-
67
-		// Cycle through them to get the Schema.org properties.
68
-		$props = array();
69
-		foreach ( $post_metas as $key => $values ) {
70
-			$matches = array();
71
-
72
-			// We're looking for `_wl_prop_propName_uuid_key`.
73
-			if ( 1 === preg_match( '/' . self::PREFIX . '(\w+)_([\w-]+)_(\w+)/i', $key, $matches ) ) {
74
-				$name = $matches[1];
75
-				$uuid = $matches[2];
76
-				$key  = $matches[3];
77
-
78
-				// Record the value.
79
-				$props[ $name ][ $uuid ][ $key ] = $values[0];
80
-			}
81
-		}
82
-
83
-		// Remove the UUIDs.
84
-		foreach ( $props as $name => $instance ) {
85
-			foreach ( $instance as $uuid => $keys ) {
86
-				// This way we remove the `uuid`s.
87
-				$props[ $name ] = array_values( $instance );
88
-			}
89
-		}
90
-
91
-		// Finally return the props.
92
-		return $props;
93
-	}
94
-
95
-	/**
96
-	 * Get the meta keys for Schema.org properties associated with the specified post.
97
-	 *
98
-	 * @param int $post_id The post id.
99
-	 *
100
-	 * @return array An array of meta keys.
101
-	 * @since 3.20.0
102
-	 */
103
-	public function get_keys( $post_id ) {
104
-
105
-		// Get all the post metas to remove the `_wl_prop` ones.
106
-		$post_meta = get_post_meta( $post_id );
107
-
108
-		// Get the keys.
109
-		$post_meta_keys = array_unique( array_keys( $post_meta ) );
110
-
111
-		// Get only the `_wl_prop` keys. `array_values` resets the indexes.
112
-		$prop_keys = array_values(
113
-			array_filter(
114
-				$post_meta_keys,
115
-				function ( $item ) {
116
-					return 0 === strpos( $item, Wordlift_Schemaorg_Property_Service::PREFIX );
117
-				}
118
-			)
119
-		);
120
-
121
-		return $prop_keys;
122
-	}
19
+    /**
20
+     * The meta key prefix used to store properties. The `_` prefix makes these metas invisible in the
21
+     * edit screen custom fields metabox.
22
+     *
23
+     * @since 3.20.0
24
+     */
25
+    const PREFIX = '_wl_prop_';
26
+
27
+    /**
28
+     * Create a {@link Wordlift_Schemaorg_Property_Service} instance.
29
+     *
30
+     * @since 3.20.0
31
+     */
32
+    protected function __construct() {
33
+    }
34
+
35
+    private static $instance = null;
36
+
37
+    /**
38
+     * Get the singleton instance.
39
+     *
40
+     * @return \Wordlift_Schemaorg_Property_Service The singleton instance.
41
+     * @since 3.20.0
42
+     */
43
+    public static function get_instance() {
44
+
45
+        if ( ! isset( self::$instance ) ) {
46
+            self::$instance = new self();
47
+        }
48
+
49
+        return self::$instance;
50
+    }
51
+
52
+    /**
53
+     * Get all the properties bound to the specified post.
54
+     *
55
+     * @param int $post_id The post id.
56
+     *
57
+     * @return array An array of properties instances keyed by the property name. Each property contains a
58
+     *  `type` and a `value` and optionally a `language`.
59
+     * }
60
+     * @since 3.20.0
61
+     */
62
+    public function get_all( $post_id ) {
63
+
64
+        // Get all the post metas.
65
+        $post_metas = get_post_meta( $post_id );
66
+
67
+        // Cycle through them to get the Schema.org properties.
68
+        $props = array();
69
+        foreach ( $post_metas as $key => $values ) {
70
+            $matches = array();
71
+
72
+            // We're looking for `_wl_prop_propName_uuid_key`.
73
+            if ( 1 === preg_match( '/' . self::PREFIX . '(\w+)_([\w-]+)_(\w+)/i', $key, $matches ) ) {
74
+                $name = $matches[1];
75
+                $uuid = $matches[2];
76
+                $key  = $matches[3];
77
+
78
+                // Record the value.
79
+                $props[ $name ][ $uuid ][ $key ] = $values[0];
80
+            }
81
+        }
82
+
83
+        // Remove the UUIDs.
84
+        foreach ( $props as $name => $instance ) {
85
+            foreach ( $instance as $uuid => $keys ) {
86
+                // This way we remove the `uuid`s.
87
+                $props[ $name ] = array_values( $instance );
88
+            }
89
+        }
90
+
91
+        // Finally return the props.
92
+        return $props;
93
+    }
94
+
95
+    /**
96
+     * Get the meta keys for Schema.org properties associated with the specified post.
97
+     *
98
+     * @param int $post_id The post id.
99
+     *
100
+     * @return array An array of meta keys.
101
+     * @since 3.20.0
102
+     */
103
+    public function get_keys( $post_id ) {
104
+
105
+        // Get all the post metas to remove the `_wl_prop` ones.
106
+        $post_meta = get_post_meta( $post_id );
107
+
108
+        // Get the keys.
109
+        $post_meta_keys = array_unique( array_keys( $post_meta ) );
110
+
111
+        // Get only the `_wl_prop` keys. `array_values` resets the indexes.
112
+        $prop_keys = array_values(
113
+            array_filter(
114
+                $post_meta_keys,
115
+                function ( $item ) {
116
+                    return 0 === strpos( $item, Wordlift_Schemaorg_Property_Service::PREFIX );
117
+                }
118
+            )
119
+        );
120
+
121
+        return $prop_keys;
122
+    }
123 123
 }
Please login to merge, or discard this patch.
src/includes/linked-data/storage/class-wordlift-post-image-storage.php 2 patches
Indentation   +41 added lines, -41 removed lines patch added patch discarded remove patch
@@ -18,46 +18,46 @@
 block discarded – undo
18 18
  */
19 19
 class Wordlift_Post_Image_Storage extends Wordlift_Storage {
20 20
 
21
-	/**
22
-	 * Get the property value.
23
-	 *
24
-	 * @param int $post_id The {@link WP_Post}'s id.
25
-	 *
26
-	 * @return array|string|null A single string, or an array of values or null
27
-	 *                           if the property isn't recognized.
28
-	 * @since 3.15.0
29
-	 */
30
-	public function get( $post_id ) {
31
-
32
-		// Prepare the return array.
33
-		$image_urls = array();
34
-
35
-		// If there is a featured image it has the priority.
36
-		$featured_image_id = get_post_thumbnail_id( $post_id );
37
-		if ( is_numeric( $featured_image_id ) && 0 < $featured_image_id ) {
38
-			$image_url = wp_get_attachment_url( $featured_image_id );
39
-
40
-			$image_urls[] = $image_url;
41
-		}
42
-
43
-		$images = get_children(
44
-			array(
45
-				'post_parent'    => $post_id,
46
-				'post_type'      => 'attachment',
47
-				'post_mime_type' => 'image',
48
-			)
49
-		);
50
-
51
-		// Collect the URLs.
52
-		foreach ( $images as $attachment_id => $attachment ) {
53
-			$image_url = wp_get_attachment_url( $attachment_id );
54
-			// Ensure the URL isn't collected already.
55
-			if ( ! in_array( $image_url, $image_urls, true ) ) {
56
-				array_push( $image_urls, $image_url );
57
-			}
58
-		}
59
-
60
-		return $image_urls;
61
-	}
21
+    /**
22
+     * Get the property value.
23
+     *
24
+     * @param int $post_id The {@link WP_Post}'s id.
25
+     *
26
+     * @return array|string|null A single string, or an array of values or null
27
+     *                           if the property isn't recognized.
28
+     * @since 3.15.0
29
+     */
30
+    public function get( $post_id ) {
31
+
32
+        // Prepare the return array.
33
+        $image_urls = array();
34
+
35
+        // If there is a featured image it has the priority.
36
+        $featured_image_id = get_post_thumbnail_id( $post_id );
37
+        if ( is_numeric( $featured_image_id ) && 0 < $featured_image_id ) {
38
+            $image_url = wp_get_attachment_url( $featured_image_id );
39
+
40
+            $image_urls[] = $image_url;
41
+        }
42
+
43
+        $images = get_children(
44
+            array(
45
+                'post_parent'    => $post_id,
46
+                'post_type'      => 'attachment',
47
+                'post_mime_type' => 'image',
48
+            )
49
+        );
50
+
51
+        // Collect the URLs.
52
+        foreach ( $images as $attachment_id => $attachment ) {
53
+            $image_url = wp_get_attachment_url( $attachment_id );
54
+            // Ensure the URL isn't collected already.
55
+            if ( ! in_array( $image_url, $image_urls, true ) ) {
56
+                array_push( $image_urls, $image_url );
57
+            }
58
+        }
59
+
60
+        return $image_urls;
61
+    }
62 62
 
63 63
 }
Please login to merge, or discard this patch.
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -27,15 +27,15 @@  discard block
 block discarded – undo
27 27
 	 *                           if the property isn't recognized.
28 28
 	 * @since 3.15.0
29 29
 	 */
30
-	public function get( $post_id ) {
30
+	public function get($post_id) {
31 31
 
32 32
 		// Prepare the return array.
33 33
 		$image_urls = array();
34 34
 
35 35
 		// If there is a featured image it has the priority.
36
-		$featured_image_id = get_post_thumbnail_id( $post_id );
37
-		if ( is_numeric( $featured_image_id ) && 0 < $featured_image_id ) {
38
-			$image_url = wp_get_attachment_url( $featured_image_id );
36
+		$featured_image_id = get_post_thumbnail_id($post_id);
37
+		if (is_numeric($featured_image_id) && 0 < $featured_image_id) {
38
+			$image_url = wp_get_attachment_url($featured_image_id);
39 39
 
40 40
 			$image_urls[] = $image_url;
41 41
 		}
@@ -49,11 +49,11 @@  discard block
 block discarded – undo
49 49
 		);
50 50
 
51 51
 		// Collect the URLs.
52
-		foreach ( $images as $attachment_id => $attachment ) {
53
-			$image_url = wp_get_attachment_url( $attachment_id );
52
+		foreach ($images as $attachment_id => $attachment) {
53
+			$image_url = wp_get_attachment_url($attachment_id);
54 54
 			// Ensure the URL isn't collected already.
55
-			if ( ! in_array( $image_url, $image_urls, true ) ) {
56
-				array_push( $image_urls, $image_url );
55
+			if ( ! in_array($image_url, $image_urls, true)) {
56
+				array_push($image_urls, $image_url);
57 57
 			}
58 58
 		}
59 59
 
Please login to merge, or discard this patch.
src/includes/linked-data/storage/class-wordlift-post-taxonomy-storage.php 2 patches
Indentation   +43 added lines, -43 removed lines patch added patch discarded remove patch
@@ -18,52 +18,52 @@
 block discarded – undo
18 18
  */
19 19
 class Wordlift_Post_Taxonomy_Storage extends Wordlift_Storage {
20 20
 
21
-	/**
22
-	 * The taxonomy name.
23
-	 *
24
-	 * @since  3.15.0
25
-	 * @access private
26
-	 * @var string $taxonomy The taxonomy name.
27
-	 */
28
-	private $taxonomy;
21
+    /**
22
+     * The taxonomy name.
23
+     *
24
+     * @since  3.15.0
25
+     * @access private
26
+     * @var string $taxonomy The taxonomy name.
27
+     */
28
+    private $taxonomy;
29 29
 
30
-	/**
31
-	 * Create a {@link Wordlift_Post_Taxonomy_Storage} with the specified
32
-	 * taxonomy name.
33
-	 *
34
-	 * @since 3.15.0
35
-	 *
36
-	 * @param string $taxonomy The taxonomy name.
37
-	 */
38
-	public function __construct( $taxonomy ) {
30
+    /**
31
+     * Create a {@link Wordlift_Post_Taxonomy_Storage} with the specified
32
+     * taxonomy name.
33
+     *
34
+     * @since 3.15.0
35
+     *
36
+     * @param string $taxonomy The taxonomy name.
37
+     */
38
+    public function __construct( $taxonomy ) {
39 39
 
40
-		$this->taxonomy = $taxonomy;
41
-	}
40
+        $this->taxonomy = $taxonomy;
41
+    }
42 42
 
43
-	/**
44
-	 * Get the taxonomy's terms associated with the specified {@link WP_Post}.
45
-	 *
46
-	 * @since 3.15.0
47
-	 *
48
-	 * @param int $post_id The {@link WP_Post}'s id.
49
-	 *
50
-	 * @return array|WP_Error An array of terms or {@link WP_Error} in case of error.
51
-	 */
52
-	public function get( $post_id ) {
43
+    /**
44
+     * Get the taxonomy's terms associated with the specified {@link WP_Post}.
45
+     *
46
+     * @since 3.15.0
47
+     *
48
+     * @param int $post_id The {@link WP_Post}'s id.
49
+     *
50
+     * @return array|WP_Error An array of terms or {@link WP_Error} in case of error.
51
+     */
52
+    public function get( $post_id ) {
53 53
 
54
-		return wp_get_post_terms(
55
-			$post_id,
56
-			$this->taxonomy,
57
-			array(
58
-				'hide_empty' => false,
59
-				// Because of #334 (and the AAM plugin) we changed fields from 'id=>slug' to 'all'.
60
-				// An issue has been opened with the AAM plugin author as well.
61
-				//
62
-				// see https://github.com/insideout10/wordlift-plugin/issues/334
63
-				// see https://wordpress.org/support/topic/idslug-not-working-anymore?replies=1#post-8806863
64
-				'fields'     => 'all',
65
-			)
66
-		);
67
-	}
54
+        return wp_get_post_terms(
55
+            $post_id,
56
+            $this->taxonomy,
57
+            array(
58
+                'hide_empty' => false,
59
+                // Because of #334 (and the AAM plugin) we changed fields from 'id=>slug' to 'all'.
60
+                // An issue has been opened with the AAM plugin author as well.
61
+                //
62
+                // see https://github.com/insideout10/wordlift-plugin/issues/334
63
+                // see https://wordpress.org/support/topic/idslug-not-working-anymore?replies=1#post-8806863
64
+                'fields'     => 'all',
65
+            )
66
+        );
67
+    }
68 68
 
69 69
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -35,7 +35,7 @@  discard block
 block discarded – undo
35 35
 	 *
36 36
 	 * @param string $taxonomy The taxonomy name.
37 37
 	 */
38
-	public function __construct( $taxonomy ) {
38
+	public function __construct($taxonomy) {
39 39
 
40 40
 		$this->taxonomy = $taxonomy;
41 41
 	}
@@ -49,7 +49,7 @@  discard block
 block discarded – undo
49 49
 	 *
50 50
 	 * @return array|WP_Error An array of terms or {@link WP_Error} in case of error.
51 51
 	 */
52
-	public function get( $post_id ) {
52
+	public function get($post_id) {
53 53
 
54 54
 		return wp_get_post_terms(
55 55
 			$post_id,
Please login to merge, or discard this patch.
includes/linked-data/storage/class-wordlift-post-schema-class-storage.php 2 patches
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -27,28 +27,28 @@
 block discarded – undo
27 27
 	 *
28 28
 	 * @return string|array An array of schema classes.
29 29
 	 */
30
-	public function get( $post_id ) {
30
+	public function get($post_id) {
31 31
 
32 32
 		// Get the type names (CamelCase).
33
-		$names = Wordlift_Entity_Type_Service::get_instance()->get_names( $post_id );
33
+		$names = Wordlift_Entity_Type_Service::get_instance()->get_names($post_id);
34 34
 
35 35
 		// If we don't find any type use the legacy function to get the URI.
36
-		if ( empty( $names ) ) {
37
-			$type = Wordlift_Entity_Type_Service::get_instance()->get( $post_id );
36
+		if (empty($names)) {
37
+			$type = Wordlift_Entity_Type_Service::get_instance()->get($post_id);
38 38
 
39 39
 			return $type['uri'];
40 40
 		}
41 41
 
42 42
 		// Prepend the `schema.org` base URI.
43 43
 		$uris = array_map(
44
-			function ( $item ) {
44
+			function($item) {
45 45
 				return "http://schema.org/$item";
46 46
 			},
47 47
 			$names
48 48
 		);
49 49
 
50 50
 		// Finally return the schema uri.
51
-		return 1 === count( $uris ) ? $uris[0] : $uris;
51
+		return 1 === count($uris) ? $uris[0] : $uris;
52 52
 	}
53 53
 
54 54
 }
Please login to merge, or discard this patch.
Indentation   +27 added lines, -27 removed lines patch added patch discarded remove patch
@@ -18,36 +18,36 @@
 block discarded – undo
18 18
  */
19 19
 class Wordlift_Post_Schema_Class_Storage extends Wordlift_Storage {
20 20
 
21
-	/**
22
-	 * Get the schema class for the specified {@link WP_Post}.
23
-	 *
24
-	 * @since 3.15.0
25
-	 *
26
-	 * @param int $post_id The {@link WP_Post}'s id.
27
-	 *
28
-	 * @return string|array An array of schema classes.
29
-	 */
30
-	public function get( $post_id ) {
21
+    /**
22
+     * Get the schema class for the specified {@link WP_Post}.
23
+     *
24
+     * @since 3.15.0
25
+     *
26
+     * @param int $post_id The {@link WP_Post}'s id.
27
+     *
28
+     * @return string|array An array of schema classes.
29
+     */
30
+    public function get( $post_id ) {
31 31
 
32
-		// Get the type names (CamelCase).
33
-		$names = Wordlift_Entity_Type_Service::get_instance()->get_names( $post_id );
32
+        // Get the type names (CamelCase).
33
+        $names = Wordlift_Entity_Type_Service::get_instance()->get_names( $post_id );
34 34
 
35
-		// If we don't find any type use the legacy function to get the URI.
36
-		if ( empty( $names ) ) {
37
-			$type = Wordlift_Entity_Type_Service::get_instance()->get( $post_id );
35
+        // If we don't find any type use the legacy function to get the URI.
36
+        if ( empty( $names ) ) {
37
+            $type = Wordlift_Entity_Type_Service::get_instance()->get( $post_id );
38 38
 
39
-			return $type['uri'];
40
-		}
39
+            return $type['uri'];
40
+        }
41 41
 
42
-		// Prepend the `schema.org` base URI.
43
-		$uris = array_map(
44
-			function ( $item ) {
45
-				return "http://schema.org/$item";
46
-			},
47
-			$names
48
-		);
42
+        // Prepend the `schema.org` base URI.
43
+        $uris = array_map(
44
+            function ( $item ) {
45
+                return "http://schema.org/$item";
46
+            },
47
+            $names
48
+        );
49 49
 
50
-		// Finally return the schema uri.
51
-		return 1 === count( $uris ) ? $uris[0] : $uris;
52
-	}
50
+        // Finally return the schema uri.
51
+        return 1 === count( $uris ) ? $uris[0] : $uris;
52
+    }
53 53
 }
Please login to merge, or discard this patch.