Completed
Pull Request — master (#1641)
by Naveen
01:35
created
src/wordlift/videoobject/filters/class-jw-player-capture.php 2 patches
Indentation   +28 added lines, -28 removed lines patch added patch discarded remove patch
@@ -13,33 +13,33 @@
 block discarded – undo
13 13
 
14 14
 class Jw_Player_Capture {
15 15
 
16
-	public function init() {
17
-		add_filter( 'wl_videoobject_embedded_videos', array( $this, 'wl_videoobject_embedded_videos' ), 10, 2 );
18
-	}
19
-
20
-	public function wl_videoobject_embedded_videos( $embedded_videos, $post_id ) {
21
-		// we cant reliably determine count for external plugin without
22
-		// this method.
23
-		global $wpdb;
24
-		$video_ids = $wpdb->get_col(
25
-			$wpdb->prepare(
26
-				"SELECT meta_value FROM {$wpdb->postmeta} WHERE meta_key LIKE %s AND post_id=%d",
27
-				'_jwppp-video-url-%',
28
-				$post_id
29
-			)
30
-		);
31
-		if ( ! $video_ids ) {
32
-			return $embedded_videos;
33
-		}
34
-
35
-		$jw_player_videos = array_map(
36
-			function ( $video_id ) {
37
-				return new Default_Embedded_Video( 'https://cdn.jwplayer.com/v2/media/' . $video_id );
38
-			},
39
-			$video_ids
40
-		);
41
-
42
-		return array_merge( $embedded_videos, $jw_player_videos );
43
-	}
16
+    public function init() {
17
+        add_filter( 'wl_videoobject_embedded_videos', array( $this, 'wl_videoobject_embedded_videos' ), 10, 2 );
18
+    }
19
+
20
+    public function wl_videoobject_embedded_videos( $embedded_videos, $post_id ) {
21
+        // we cant reliably determine count for external plugin without
22
+        // this method.
23
+        global $wpdb;
24
+        $video_ids = $wpdb->get_col(
25
+            $wpdb->prepare(
26
+                "SELECT meta_value FROM {$wpdb->postmeta} WHERE meta_key LIKE %s AND post_id=%d",
27
+                '_jwppp-video-url-%',
28
+                $post_id
29
+            )
30
+        );
31
+        if ( ! $video_ids ) {
32
+            return $embedded_videos;
33
+        }
34
+
35
+        $jw_player_videos = array_map(
36
+            function ( $video_id ) {
37
+                return new Default_Embedded_Video( 'https://cdn.jwplayer.com/v2/media/' . $video_id );
38
+            },
39
+            $video_ids
40
+        );
41
+
42
+        return array_merge( $embedded_videos, $jw_player_videos );
43
+    }
44 44
 
45 45
 }
Please login to merge, or discard this patch.
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -14,10 +14,10 @@  discard block
 block discarded – undo
14 14
 class Jw_Player_Capture {
15 15
 
16 16
 	public function init() {
17
-		add_filter( 'wl_videoobject_embedded_videos', array( $this, 'wl_videoobject_embedded_videos' ), 10, 2 );
17
+		add_filter('wl_videoobject_embedded_videos', array($this, 'wl_videoobject_embedded_videos'), 10, 2);
18 18
 	}
19 19
 
20
-	public function wl_videoobject_embedded_videos( $embedded_videos, $post_id ) {
20
+	public function wl_videoobject_embedded_videos($embedded_videos, $post_id) {
21 21
 		// we cant reliably determine count for external plugin without
22 22
 		// this method.
23 23
 		global $wpdb;
@@ -28,18 +28,18 @@  discard block
 block discarded – undo
28 28
 				$post_id
29 29
 			)
30 30
 		);
31
-		if ( ! $video_ids ) {
31
+		if ( ! $video_ids) {
32 32
 			return $embedded_videos;
33 33
 		}
34 34
 
35 35
 		$jw_player_videos = array_map(
36
-			function ( $video_id ) {
37
-				return new Default_Embedded_Video( 'https://cdn.jwplayer.com/v2/media/' . $video_id );
36
+			function($video_id) {
37
+				return new Default_Embedded_Video('https://cdn.jwplayer.com/v2/media/'.$video_id);
38 38
 			},
39 39
 			$video_ids
40 40
 		);
41 41
 
42
-		return array_merge( $embedded_videos, $jw_player_videos );
42
+		return array_merge($embedded_videos, $jw_player_videos);
43 43
 	}
44 44
 
45 45
 }
Please login to merge, or discard this patch.
src/wordlift/synonym/class-rest-field.php 2 patches
Indentation   +57 added lines, -57 removed lines patch added patch discarded remove patch
@@ -6,62 +6,62 @@
 block discarded – undo
6 6
 
7 7
 class Rest_Field {
8 8
 
9
-	public function __construct() {
10
-		add_action( 'rest_api_init', array( $this, 'register_rest_field' ) );
11
-	}
12
-
13
-	public function register_rest_field() {
14
-
15
-		if ( ! function_exists( 'register_rest_field' ) ) {
16
-			return;
17
-		}
18
-
19
-		$post_types = Wordlift_Entity_Service::valid_entity_post_types();
20
-
21
-		foreach ( $post_types as $post_type ) {
22
-
23
-			register_rest_field(
24
-				$post_type,
25
-				\Wordlift_Entity_Service::ALTERNATIVE_LABEL_META_KEY,
26
-				array(
27
-					'get_callback'    => array( $this, 'get_value' ),
28
-					'update_callback' => array( $this, 'update_value' ),
29
-				)
30
-			);
31
-
32
-		}
33
-
34
-	}
35
-
36
-	/**
37
-	 * @param $meta_values array
38
-	 * @param $post \WP_Post
39
-	 * @param $meta_key string
40
-	 */
41
-	// phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
42
-	public function update_value( $meta_values, $post, $meta_key ) {
43
-
44
-		if ( ! is_array( $meta_values ) ) {
45
-			return;
46
-		}
47
-
48
-		$entity_service = Wordlift_Entity_Service::get_instance();
49
-
50
-		$entity_service->set_alternative_labels( $post->ID, $meta_values );
51
-	}
52
-
53
-	/**
54
-	 * @param $post array Post array.
55
-	 *
56
-	 * @return array|mixed
57
-	 */
58
-	public function get_value( $post ) {
59
-		$data = get_post_meta( (int) $post['id'], \Wordlift_Entity_Service::ALTERNATIVE_LABEL_META_KEY );
60
-		if ( ! is_array( $data ) ) {
61
-			return array();
62
-		}
63
-
64
-		return $data;
65
-	}
9
+    public function __construct() {
10
+        add_action( 'rest_api_init', array( $this, 'register_rest_field' ) );
11
+    }
12
+
13
+    public function register_rest_field() {
14
+
15
+        if ( ! function_exists( 'register_rest_field' ) ) {
16
+            return;
17
+        }
18
+
19
+        $post_types = Wordlift_Entity_Service::valid_entity_post_types();
20
+
21
+        foreach ( $post_types as $post_type ) {
22
+
23
+            register_rest_field(
24
+                $post_type,
25
+                \Wordlift_Entity_Service::ALTERNATIVE_LABEL_META_KEY,
26
+                array(
27
+                    'get_callback'    => array( $this, 'get_value' ),
28
+                    'update_callback' => array( $this, 'update_value' ),
29
+                )
30
+            );
31
+
32
+        }
33
+
34
+    }
35
+
36
+    /**
37
+     * @param $meta_values array
38
+     * @param $post \WP_Post
39
+     * @param $meta_key string
40
+     */
41
+    // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
42
+    public function update_value( $meta_values, $post, $meta_key ) {
43
+
44
+        if ( ! is_array( $meta_values ) ) {
45
+            return;
46
+        }
47
+
48
+        $entity_service = Wordlift_Entity_Service::get_instance();
49
+
50
+        $entity_service->set_alternative_labels( $post->ID, $meta_values );
51
+    }
52
+
53
+    /**
54
+     * @param $post array Post array.
55
+     *
56
+     * @return array|mixed
57
+     */
58
+    public function get_value( $post ) {
59
+        $data = get_post_meta( (int) $post['id'], \Wordlift_Entity_Service::ALTERNATIVE_LABEL_META_KEY );
60
+        if ( ! is_array( $data ) ) {
61
+            return array();
62
+        }
63
+
64
+        return $data;
65
+    }
66 66
 
67 67
 }
Please login to merge, or discard this patch.
Spacing   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -7,25 +7,25 @@  discard block
 block discarded – undo
7 7
 class Rest_Field {
8 8
 
9 9
 	public function __construct() {
10
-		add_action( 'rest_api_init', array( $this, 'register_rest_field' ) );
10
+		add_action('rest_api_init', array($this, 'register_rest_field'));
11 11
 	}
12 12
 
13 13
 	public function register_rest_field() {
14 14
 
15
-		if ( ! function_exists( 'register_rest_field' ) ) {
15
+		if ( ! function_exists('register_rest_field')) {
16 16
 			return;
17 17
 		}
18 18
 
19 19
 		$post_types = Wordlift_Entity_Service::valid_entity_post_types();
20 20
 
21
-		foreach ( $post_types as $post_type ) {
21
+		foreach ($post_types as $post_type) {
22 22
 
23 23
 			register_rest_field(
24 24
 				$post_type,
25 25
 				\Wordlift_Entity_Service::ALTERNATIVE_LABEL_META_KEY,
26 26
 				array(
27
-					'get_callback'    => array( $this, 'get_value' ),
28
-					'update_callback' => array( $this, 'update_value' ),
27
+					'get_callback'    => array($this, 'get_value'),
28
+					'update_callback' => array($this, 'update_value'),
29 29
 				)
30 30
 			);
31 31
 
@@ -39,15 +39,15 @@  discard block
 block discarded – undo
39 39
 	 * @param $meta_key string
40 40
 	 */
41 41
 	// phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
42
-	public function update_value( $meta_values, $post, $meta_key ) {
42
+	public function update_value($meta_values, $post, $meta_key) {
43 43
 
44
-		if ( ! is_array( $meta_values ) ) {
44
+		if ( ! is_array($meta_values)) {
45 45
 			return;
46 46
 		}
47 47
 
48 48
 		$entity_service = Wordlift_Entity_Service::get_instance();
49 49
 
50
-		$entity_service->set_alternative_labels( $post->ID, $meta_values );
50
+		$entity_service->set_alternative_labels($post->ID, $meta_values);
51 51
 	}
52 52
 
53 53
 	/**
@@ -55,9 +55,9 @@  discard block
 block discarded – undo
55 55
 	 *
56 56
 	 * @return array|mixed
57 57
 	 */
58
-	public function get_value( $post ) {
59
-		$data = get_post_meta( (int) $post['id'], \Wordlift_Entity_Service::ALTERNATIVE_LABEL_META_KEY );
60
-		if ( ! is_array( $data ) ) {
58
+	public function get_value($post) {
59
+		$data = get_post_meta((int) $post['id'], \Wordlift_Entity_Service::ALTERNATIVE_LABEL_META_KEY);
60
+		if ( ! is_array($data)) {
61 61
 			return array();
62 62
 		}
63 63
 
Please login to merge, or discard this patch.
src/wordlift/synonym/class-loader.php 1 patch
Indentation   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -9,15 +9,15 @@
 block discarded – undo
9 9
  */
10 10
 class Loader extends Default_Loader {
11 11
 
12
-	public function init_all_dependencies() {
13
-		new Rest_Field();
14
-	}
12
+    public function init_all_dependencies() {
13
+        new Rest_Field();
14
+    }
15 15
 
16
-	protected function get_feature_slug() {
17
-		return 'add-synonyms';
18
-	}
16
+    protected function get_feature_slug() {
17
+        return 'add-synonyms';
18
+    }
19 19
 
20
-	protected function get_feature_default_value() {
21
-		return true;
22
-	}
20
+    protected function get_feature_default_value() {
21
+        return true;
22
+    }
23 23
 }
Please login to merge, or discard this patch.
src/wordlift/jsonld/class-jsonld-service.php 2 patches
Indentation   +73 added lines, -73 removed lines patch added patch discarded remove patch
@@ -10,78 +10,78 @@
 block discarded – undo
10 10
 
11 11
 class Jsonld_Service {
12 12
 
13
-	/**
14
-	 * @var Jsonld_Service
15
-	 */
16
-	private static $instance;
17
-
18
-	/**
19
-	 * @var Wordlift_Jsonld_Service
20
-	 */
21
-	private $legacy_jsonld_service;
22
-
23
-	/**
24
-	 * @var Wordlift_Term_JsonLd_Adapter
25
-	 */
26
-	private $term_jsonld_service;
27
-
28
-	/**
29
-	 * @var Jsonld_User_Service
30
-	 */
31
-	private $jsonld_user_service;
32
-
33
-	/**
34
-	 * Jsonld_Service constructor.
35
-	 *
36
-	 * @param Wordlift_Jsonld_Service      $legacy_jsonld_service
37
-	 * @param Wordlift_Term_JsonLd_Adapter $term_jsonld_adapter
38
-	 * @param Jsonld_User_Service          $jsonld_user_service
39
-	 *
40
-	 * @throws Exception when an error occurs.
41
-	 */
42
-	public function __construct( $legacy_jsonld_service, $term_jsonld_adapter, $jsonld_user_service ) {
43
-
44
-		Assertions::assert_of_type( $legacy_jsonld_service, 'Wordlift_Jsonld_Service' );
45
-		Assertions::assert_of_type( $term_jsonld_adapter, 'Wordlift_Term_JsonLd_Adapter' );
46
-		Assertions::assert_of_type( $jsonld_user_service, 'Wordlift\Jsonld\Jsonld_User_Service' );
47
-
48
-		$this->legacy_jsonld_service = $legacy_jsonld_service;
49
-		$this->term_jsonld_service   = $term_jsonld_adapter;
50
-		$this->jsonld_user_service   = $jsonld_user_service;
51
-		$this->jsonld_user_service->set_jsonld_service( $this );
52
-
53
-		self::$instance = $this;
54
-	}
55
-
56
-	public static function get_instance() {
57
-		return self::$instance;
58
-	}
59
-
60
-	/**
61
-	 * Get the JSON-LD structure for the specified type and id.
62
-	 *
63
-	 * @param int      $type The requested type, one of 'HOMEPAGE', 'POST' or 'TERM'. Default 'POST'.
64
-	 * @param int|null $id The id. Default `null`.
65
-	 * @param int      $context A context for the JSON-LD generation, valid values in Jsonld_Context_Enum.
66
-	 *
67
-	 * @return array The JSON-LD structure.
68
-	 * @throws Exception Throws an exception if the type isn't recognized.
69
-	 */
70
-	public function get( $type = Object_Type_Enum::POST, $id = null, $context = Jsonld_Context_Enum::UNKNOWN ) {
71
-
72
-		switch ( $type ) {
73
-			case Object_Type_Enum::HOMEPAGE:
74
-				return $this->legacy_jsonld_service->get_jsonld( true, $id, $context );
75
-			case Object_Type_Enum::POST:
76
-				return $this->legacy_jsonld_service->get_jsonld( false, $id, $context );
77
-			case Object_Type_Enum::TERM:
78
-				return $this->term_jsonld_service->get( $id, $context );
79
-			case Object_Type_Enum::USER:
80
-				return $this->jsonld_user_service->get( $id );
81
-			default:
82
-				throw new Exception( "Unknown type $type. Allowed types: 'HOMEPAGE', 'POST', 'TERM', 'USER'." );
83
-		}
84
-
85
-	}
13
+    /**
14
+     * @var Jsonld_Service
15
+     */
16
+    private static $instance;
17
+
18
+    /**
19
+     * @var Wordlift_Jsonld_Service
20
+     */
21
+    private $legacy_jsonld_service;
22
+
23
+    /**
24
+     * @var Wordlift_Term_JsonLd_Adapter
25
+     */
26
+    private $term_jsonld_service;
27
+
28
+    /**
29
+     * @var Jsonld_User_Service
30
+     */
31
+    private $jsonld_user_service;
32
+
33
+    /**
34
+     * Jsonld_Service constructor.
35
+     *
36
+     * @param Wordlift_Jsonld_Service      $legacy_jsonld_service
37
+     * @param Wordlift_Term_JsonLd_Adapter $term_jsonld_adapter
38
+     * @param Jsonld_User_Service          $jsonld_user_service
39
+     *
40
+     * @throws Exception when an error occurs.
41
+     */
42
+    public function __construct( $legacy_jsonld_service, $term_jsonld_adapter, $jsonld_user_service ) {
43
+
44
+        Assertions::assert_of_type( $legacy_jsonld_service, 'Wordlift_Jsonld_Service' );
45
+        Assertions::assert_of_type( $term_jsonld_adapter, 'Wordlift_Term_JsonLd_Adapter' );
46
+        Assertions::assert_of_type( $jsonld_user_service, 'Wordlift\Jsonld\Jsonld_User_Service' );
47
+
48
+        $this->legacy_jsonld_service = $legacy_jsonld_service;
49
+        $this->term_jsonld_service   = $term_jsonld_adapter;
50
+        $this->jsonld_user_service   = $jsonld_user_service;
51
+        $this->jsonld_user_service->set_jsonld_service( $this );
52
+
53
+        self::$instance = $this;
54
+    }
55
+
56
+    public static function get_instance() {
57
+        return self::$instance;
58
+    }
59
+
60
+    /**
61
+     * Get the JSON-LD structure for the specified type and id.
62
+     *
63
+     * @param int      $type The requested type, one of 'HOMEPAGE', 'POST' or 'TERM'. Default 'POST'.
64
+     * @param int|null $id The id. Default `null`.
65
+     * @param int      $context A context for the JSON-LD generation, valid values in Jsonld_Context_Enum.
66
+     *
67
+     * @return array The JSON-LD structure.
68
+     * @throws Exception Throws an exception if the type isn't recognized.
69
+     */
70
+    public function get( $type = Object_Type_Enum::POST, $id = null, $context = Jsonld_Context_Enum::UNKNOWN ) {
71
+
72
+        switch ( $type ) {
73
+            case Object_Type_Enum::HOMEPAGE:
74
+                return $this->legacy_jsonld_service->get_jsonld( true, $id, $context );
75
+            case Object_Type_Enum::POST:
76
+                return $this->legacy_jsonld_service->get_jsonld( false, $id, $context );
77
+            case Object_Type_Enum::TERM:
78
+                return $this->term_jsonld_service->get( $id, $context );
79
+            case Object_Type_Enum::USER:
80
+                return $this->jsonld_user_service->get( $id );
81
+            default:
82
+                throw new Exception( "Unknown type $type. Allowed types: 'HOMEPAGE', 'POST', 'TERM', 'USER'." );
83
+        }
84
+
85
+    }
86 86
 
87 87
 }
Please login to merge, or discard this patch.
Spacing   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -39,16 +39,16 @@  discard block
 block discarded – undo
39 39
 	 *
40 40
 	 * @throws Exception when an error occurs.
41 41
 	 */
42
-	public function __construct( $legacy_jsonld_service, $term_jsonld_adapter, $jsonld_user_service ) {
42
+	public function __construct($legacy_jsonld_service, $term_jsonld_adapter, $jsonld_user_service) {
43 43
 
44
-		Assertions::assert_of_type( $legacy_jsonld_service, 'Wordlift_Jsonld_Service' );
45
-		Assertions::assert_of_type( $term_jsonld_adapter, 'Wordlift_Term_JsonLd_Adapter' );
46
-		Assertions::assert_of_type( $jsonld_user_service, 'Wordlift\Jsonld\Jsonld_User_Service' );
44
+		Assertions::assert_of_type($legacy_jsonld_service, 'Wordlift_Jsonld_Service');
45
+		Assertions::assert_of_type($term_jsonld_adapter, 'Wordlift_Term_JsonLd_Adapter');
46
+		Assertions::assert_of_type($jsonld_user_service, 'Wordlift\Jsonld\Jsonld_User_Service');
47 47
 
48 48
 		$this->legacy_jsonld_service = $legacy_jsonld_service;
49 49
 		$this->term_jsonld_service   = $term_jsonld_adapter;
50 50
 		$this->jsonld_user_service   = $jsonld_user_service;
51
-		$this->jsonld_user_service->set_jsonld_service( $this );
51
+		$this->jsonld_user_service->set_jsonld_service($this);
52 52
 
53 53
 		self::$instance = $this;
54 54
 	}
@@ -67,19 +67,19 @@  discard block
 block discarded – undo
67 67
 	 * @return array The JSON-LD structure.
68 68
 	 * @throws Exception Throws an exception if the type isn't recognized.
69 69
 	 */
70
-	public function get( $type = Object_Type_Enum::POST, $id = null, $context = Jsonld_Context_Enum::UNKNOWN ) {
70
+	public function get($type = Object_Type_Enum::POST, $id = null, $context = Jsonld_Context_Enum::UNKNOWN) {
71 71
 
72
-		switch ( $type ) {
72
+		switch ($type) {
73 73
 			case Object_Type_Enum::HOMEPAGE:
74
-				return $this->legacy_jsonld_service->get_jsonld( true, $id, $context );
74
+				return $this->legacy_jsonld_service->get_jsonld(true, $id, $context);
75 75
 			case Object_Type_Enum::POST:
76
-				return $this->legacy_jsonld_service->get_jsonld( false, $id, $context );
76
+				return $this->legacy_jsonld_service->get_jsonld(false, $id, $context);
77 77
 			case Object_Type_Enum::TERM:
78
-				return $this->term_jsonld_service->get( $id, $context );
78
+				return $this->term_jsonld_service->get($id, $context);
79 79
 			case Object_Type_Enum::USER:
80
-				return $this->jsonld_user_service->get( $id );
80
+				return $this->jsonld_user_service->get($id);
81 81
 			default:
82
-				throw new Exception( "Unknown type $type. Allowed types: 'HOMEPAGE', 'POST', 'TERM', 'USER'." );
82
+				throw new Exception("Unknown type $type. Allowed types: 'HOMEPAGE', 'POST', 'TERM', 'USER'.");
83 83
 		}
84 84
 
85 85
 	}
Please login to merge, or discard this patch.
src/wordlift/jsonld/class-jsonld-article-wrapper.php 2 patches
Indentation   +128 added lines, -128 removed lines patch added patch discarded remove patch
@@ -6,142 +6,142 @@
 block discarded – undo
6 6
 
7 7
 class Jsonld_Article_Wrapper {
8 8
 
9
-	public static $article_types = array(
10
-		'Article',
11
-		'AdvertiserContentArticle',
12
-		'NewsArticle',
13
-		'AnalysisNewsArticle',
14
-		'AskPublicNewsArticle',
15
-		'BackgroundNewsArticle',
16
-		'OpinionNewsArticle',
17
-		'ReportageNewsArticle',
18
-		'ReviewNewsArticle',
19
-		'Report',
20
-		'SatiricalArticle',
21
-		'ScholarlyArticle',
22
-		'MedicalScholarlyArticle',
23
-		'SocialMediaPosting',
24
-		'BlogPosting',
25
-		'LiveBlogPosting',
26
-		'DiscussionForumPosting',
27
-		'TechArticle',
28
-		'APIReference',
29
-	);
30
-
31
-	/**
32
-	 * @var Wordlift_Post_To_Jsonld_Converter
33
-	 */
34
-	private $post_to_jsonld_converter;
35
-	/**
36
-	 * @var \Wordlift_Cached_Post_Converter
37
-	 */
38
-	private $cached_postid_to_jsonld_converter;
39
-	/**
40
-	 * @var \Wordlift_Entity_Uri_Service
41
-	 */
42
-	private $entity_uri_service;
43
-
44
-	/**
45
-	 * Jsonld_Article_Wrapper constructor.
46
-	 *
47
-	 * @param Wordlift_Post_To_Jsonld_Converter $post_to_jsonld_converter
48
-	 * @param $cached_postid_to_jsonld_converter
49
-	 */
50
-	public function __construct( $post_to_jsonld_converter, $cached_postid_to_jsonld_converter ) {
51
-
52
-		$this->post_to_jsonld_converter = $post_to_jsonld_converter->new_instance_with_filters_disabled();
53
-
54
-		add_filter( 'wl_after_get_jsonld', array( $this, 'after_get_jsonld' ), PHP_INT_MAX - 100, 3 );
55
-
56
-		$this->cached_postid_to_jsonld_converter = $cached_postid_to_jsonld_converter;
57
-
58
-		$this->entity_uri_service = \Wordlift_Entity_Uri_Service::get_instance();
59
-	}
60
-
61
-	public function after_get_jsonld( $jsonld, $post_id, $context ) {
62
-
63
-		if ( Jsonld_Context_Enum::PAGE !== $context || ! is_array( $jsonld ) || ! isset( $jsonld[0] )
64
-			 || ! is_array( $jsonld[0] ) ) {
65
-			return $jsonld;
66
-		}
67
-
68
-		// Copy the 1st array element
69
-		$post_jsonld = $jsonld[0];
70
-
71
-		// Don't wrap in article if the json-ld is already about an Article (or its descendants). `@type` must be
72
-		// in the schema.org context, i.e. `Article`, not `http://schema.org/Article`.
73
-		if ( ! isset( $post_jsonld['@id'] ) || ! isset( $post_jsonld['@type'] ) || $this->is_article( $post_jsonld['@type'] ) ) {
74
-			return $jsonld;
75
-		}
76
-
77
-		// Convert the post as Article.
78
-		$article_jsonld = $this->post_to_jsonld_converter->convert( $post_id );
79
-
80
-		$article_jsonld['@id'] = $post_jsonld['@id'] . '#article';
81
-		// Reset the type, since by default the type assigned via the Entity Type taxonomy is used.
82
-		$article_jsonld['@type'] = 'Article';
83
-		$article_jsonld['about'] = array( '@id' => $post_jsonld['@id'] );
84
-
85
-		// Copy over the URLs.
86
-		if ( isset( $post_jsonld['url'] ) ) {
87
-			$article_jsonld['url'] = $post_jsonld['url'];
88
-		}
89
-
90
-		array_unshift( $jsonld, $article_jsonld );
91
-
92
-		$author_jsonld = $this->get_author_linked_entity( $article_jsonld );
93
-
94
-		/**
95
-		 * The author entities can be present in graph for some entity types
96
-		 * for Person and Organization, so check before we add it to graph.
97
-		 * reference : https://schema.org/author
98
-		 */
99
-		if ( $author_jsonld && ! $this->is_author_entity_present_in_graph( $jsonld, $article_jsonld['author']['@id'] ) ) {
100
-			$jsonld[] = $author_jsonld;
101
-		}
102
-
103
-		return $jsonld;
104
-	}
105
-
106
-	private function is_article( $schema_types ) {
107
-
108
-		$array_intersect = array_intersect( self::$article_types, (array) $schema_types );
109
-
110
-		return ! empty( $array_intersect );
111
-	}
112
-
113
-	private function get_author_linked_entity( $article_jsonld ) {
114
-		if ( ! array_key_exists( 'author', $article_jsonld ) ) {
115
-			return false;
116
-		}
117
-
118
-		$author = $article_jsonld['author'];
9
+    public static $article_types = array(
10
+        'Article',
11
+        'AdvertiserContentArticle',
12
+        'NewsArticle',
13
+        'AnalysisNewsArticle',
14
+        'AskPublicNewsArticle',
15
+        'BackgroundNewsArticle',
16
+        'OpinionNewsArticle',
17
+        'ReportageNewsArticle',
18
+        'ReviewNewsArticle',
19
+        'Report',
20
+        'SatiricalArticle',
21
+        'ScholarlyArticle',
22
+        'MedicalScholarlyArticle',
23
+        'SocialMediaPosting',
24
+        'BlogPosting',
25
+        'LiveBlogPosting',
26
+        'DiscussionForumPosting',
27
+        'TechArticle',
28
+        'APIReference',
29
+    );
30
+
31
+    /**
32
+     * @var Wordlift_Post_To_Jsonld_Converter
33
+     */
34
+    private $post_to_jsonld_converter;
35
+    /**
36
+     * @var \Wordlift_Cached_Post_Converter
37
+     */
38
+    private $cached_postid_to_jsonld_converter;
39
+    /**
40
+     * @var \Wordlift_Entity_Uri_Service
41
+     */
42
+    private $entity_uri_service;
43
+
44
+    /**
45
+     * Jsonld_Article_Wrapper constructor.
46
+     *
47
+     * @param Wordlift_Post_To_Jsonld_Converter $post_to_jsonld_converter
48
+     * @param $cached_postid_to_jsonld_converter
49
+     */
50
+    public function __construct( $post_to_jsonld_converter, $cached_postid_to_jsonld_converter ) {
51
+
52
+        $this->post_to_jsonld_converter = $post_to_jsonld_converter->new_instance_with_filters_disabled();
53
+
54
+        add_filter( 'wl_after_get_jsonld', array( $this, 'after_get_jsonld' ), PHP_INT_MAX - 100, 3 );
55
+
56
+        $this->cached_postid_to_jsonld_converter = $cached_postid_to_jsonld_converter;
57
+
58
+        $this->entity_uri_service = \Wordlift_Entity_Uri_Service::get_instance();
59
+    }
60
+
61
+    public function after_get_jsonld( $jsonld, $post_id, $context ) {
62
+
63
+        if ( Jsonld_Context_Enum::PAGE !== $context || ! is_array( $jsonld ) || ! isset( $jsonld[0] )
64
+             || ! is_array( $jsonld[0] ) ) {
65
+            return $jsonld;
66
+        }
67
+
68
+        // Copy the 1st array element
69
+        $post_jsonld = $jsonld[0];
70
+
71
+        // Don't wrap in article if the json-ld is already about an Article (or its descendants). `@type` must be
72
+        // in the schema.org context, i.e. `Article`, not `http://schema.org/Article`.
73
+        if ( ! isset( $post_jsonld['@id'] ) || ! isset( $post_jsonld['@type'] ) || $this->is_article( $post_jsonld['@type'] ) ) {
74
+            return $jsonld;
75
+        }
76
+
77
+        // Convert the post as Article.
78
+        $article_jsonld = $this->post_to_jsonld_converter->convert( $post_id );
79
+
80
+        $article_jsonld['@id'] = $post_jsonld['@id'] . '#article';
81
+        // Reset the type, since by default the type assigned via the Entity Type taxonomy is used.
82
+        $article_jsonld['@type'] = 'Article';
83
+        $article_jsonld['about'] = array( '@id' => $post_jsonld['@id'] );
84
+
85
+        // Copy over the URLs.
86
+        if ( isset( $post_jsonld['url'] ) ) {
87
+            $article_jsonld['url'] = $post_jsonld['url'];
88
+        }
89
+
90
+        array_unshift( $jsonld, $article_jsonld );
91
+
92
+        $author_jsonld = $this->get_author_linked_entity( $article_jsonld );
93
+
94
+        /**
95
+         * The author entities can be present in graph for some entity types
96
+         * for Person and Organization, so check before we add it to graph.
97
+         * reference : https://schema.org/author
98
+         */
99
+        if ( $author_jsonld && ! $this->is_author_entity_present_in_graph( $jsonld, $article_jsonld['author']['@id'] ) ) {
100
+            $jsonld[] = $author_jsonld;
101
+        }
102
+
103
+        return $jsonld;
104
+    }
105
+
106
+    private function is_article( $schema_types ) {
107
+
108
+        $array_intersect = array_intersect( self::$article_types, (array) $schema_types );
109
+
110
+        return ! empty( $array_intersect );
111
+    }
112
+
113
+    private function get_author_linked_entity( $article_jsonld ) {
114
+        if ( ! array_key_exists( 'author', $article_jsonld ) ) {
115
+            return false;
116
+        }
117
+
118
+        $author = $article_jsonld['author'];
119 119
 
120
-		if ( count( array_keys( $author ) ) !== 1 || ! array_key_exists( '@id', $author ) ) {
121
-			return false;
122
-		}
120
+        if ( count( array_keys( $author ) ) !== 1 || ! array_key_exists( '@id', $author ) ) {
121
+            return false;
122
+        }
123 123
 
124
-		$author_linked_entity_id = $author['@id'];
124
+        $author_linked_entity_id = $author['@id'];
125 125
 
126
-		$author_entity_post = $this->entity_uri_service->get_entity( $author_linked_entity_id );
126
+        $author_entity_post = $this->entity_uri_service->get_entity( $author_linked_entity_id );
127 127
 
128
-		if ( ! $author_entity_post instanceof \WP_Post ) {
129
-			return false;
130
-		}
128
+        if ( ! $author_entity_post instanceof \WP_Post ) {
129
+            return false;
130
+        }
131 131
 
132
-		return $this->cached_postid_to_jsonld_converter->convert( $author_entity_post->ID );
132
+        return $this->cached_postid_to_jsonld_converter->convert( $author_entity_post->ID );
133 133
 
134
-	}
134
+    }
135 135
 
136
-	private function is_author_entity_present_in_graph( $jsonld, $author_entity_id ) {
136
+    private function is_author_entity_present_in_graph( $jsonld, $author_entity_id ) {
137 137
 
138
-		foreach ( $jsonld as $item ) {
139
-			if ( $item && array_key_exists( '@id', $item ) && $item['@id'] === $author_entity_id ) {
140
-				return true;
141
-			}
142
-		}
138
+        foreach ( $jsonld as $item ) {
139
+            if ( $item && array_key_exists( '@id', $item ) && $item['@id'] === $author_entity_id ) {
140
+                return true;
141
+            }
142
+        }
143 143
 
144
-		return false;
145
-	}
144
+        return false;
145
+    }
146 146
 
147 147
 }
Please login to merge, or discard this patch.
Spacing   +25 added lines, -25 removed lines patch added patch discarded remove patch
@@ -47,21 +47,21 @@  discard block
 block discarded – undo
47 47
 	 * @param Wordlift_Post_To_Jsonld_Converter $post_to_jsonld_converter
48 48
 	 * @param $cached_postid_to_jsonld_converter
49 49
 	 */
50
-	public function __construct( $post_to_jsonld_converter, $cached_postid_to_jsonld_converter ) {
50
+	public function __construct($post_to_jsonld_converter, $cached_postid_to_jsonld_converter) {
51 51
 
52 52
 		$this->post_to_jsonld_converter = $post_to_jsonld_converter->new_instance_with_filters_disabled();
53 53
 
54
-		add_filter( 'wl_after_get_jsonld', array( $this, 'after_get_jsonld' ), PHP_INT_MAX - 100, 3 );
54
+		add_filter('wl_after_get_jsonld', array($this, 'after_get_jsonld'), PHP_INT_MAX - 100, 3);
55 55
 
56 56
 		$this->cached_postid_to_jsonld_converter = $cached_postid_to_jsonld_converter;
57 57
 
58 58
 		$this->entity_uri_service = \Wordlift_Entity_Uri_Service::get_instance();
59 59
 	}
60 60
 
61
-	public function after_get_jsonld( $jsonld, $post_id, $context ) {
61
+	public function after_get_jsonld($jsonld, $post_id, $context) {
62 62
 
63
-		if ( Jsonld_Context_Enum::PAGE !== $context || ! is_array( $jsonld ) || ! isset( $jsonld[0] )
64
-			 || ! is_array( $jsonld[0] ) ) {
63
+		if (Jsonld_Context_Enum::PAGE !== $context || ! is_array($jsonld) || ! isset($jsonld[0])
64
+			 || ! is_array($jsonld[0])) {
65 65
 			return $jsonld;
66 66
 		}
67 67
 
@@ -70,73 +70,73 @@  discard block
 block discarded – undo
70 70
 
71 71
 		// Don't wrap in article if the json-ld is already about an Article (or its descendants). `@type` must be
72 72
 		// in the schema.org context, i.e. `Article`, not `http://schema.org/Article`.
73
-		if ( ! isset( $post_jsonld['@id'] ) || ! isset( $post_jsonld['@type'] ) || $this->is_article( $post_jsonld['@type'] ) ) {
73
+		if ( ! isset($post_jsonld['@id']) || ! isset($post_jsonld['@type']) || $this->is_article($post_jsonld['@type'])) {
74 74
 			return $jsonld;
75 75
 		}
76 76
 
77 77
 		// Convert the post as Article.
78
-		$article_jsonld = $this->post_to_jsonld_converter->convert( $post_id );
78
+		$article_jsonld = $this->post_to_jsonld_converter->convert($post_id);
79 79
 
80
-		$article_jsonld['@id'] = $post_jsonld['@id'] . '#article';
80
+		$article_jsonld['@id'] = $post_jsonld['@id'].'#article';
81 81
 		// Reset the type, since by default the type assigned via the Entity Type taxonomy is used.
82 82
 		$article_jsonld['@type'] = 'Article';
83
-		$article_jsonld['about'] = array( '@id' => $post_jsonld['@id'] );
83
+		$article_jsonld['about'] = array('@id' => $post_jsonld['@id']);
84 84
 
85 85
 		// Copy over the URLs.
86
-		if ( isset( $post_jsonld['url'] ) ) {
86
+		if (isset($post_jsonld['url'])) {
87 87
 			$article_jsonld['url'] = $post_jsonld['url'];
88 88
 		}
89 89
 
90
-		array_unshift( $jsonld, $article_jsonld );
90
+		array_unshift($jsonld, $article_jsonld);
91 91
 
92
-		$author_jsonld = $this->get_author_linked_entity( $article_jsonld );
92
+		$author_jsonld = $this->get_author_linked_entity($article_jsonld);
93 93
 
94 94
 		/**
95 95
 		 * The author entities can be present in graph for some entity types
96 96
 		 * for Person and Organization, so check before we add it to graph.
97 97
 		 * reference : https://schema.org/author
98 98
 		 */
99
-		if ( $author_jsonld && ! $this->is_author_entity_present_in_graph( $jsonld, $article_jsonld['author']['@id'] ) ) {
99
+		if ($author_jsonld && ! $this->is_author_entity_present_in_graph($jsonld, $article_jsonld['author']['@id'])) {
100 100
 			$jsonld[] = $author_jsonld;
101 101
 		}
102 102
 
103 103
 		return $jsonld;
104 104
 	}
105 105
 
106
-	private function is_article( $schema_types ) {
106
+	private function is_article($schema_types) {
107 107
 
108
-		$array_intersect = array_intersect( self::$article_types, (array) $schema_types );
108
+		$array_intersect = array_intersect(self::$article_types, (array) $schema_types);
109 109
 
110
-		return ! empty( $array_intersect );
110
+		return ! empty($array_intersect);
111 111
 	}
112 112
 
113
-	private function get_author_linked_entity( $article_jsonld ) {
114
-		if ( ! array_key_exists( 'author', $article_jsonld ) ) {
113
+	private function get_author_linked_entity($article_jsonld) {
114
+		if ( ! array_key_exists('author', $article_jsonld)) {
115 115
 			return false;
116 116
 		}
117 117
 
118 118
 		$author = $article_jsonld['author'];
119 119
 
120
-		if ( count( array_keys( $author ) ) !== 1 || ! array_key_exists( '@id', $author ) ) {
120
+		if (count(array_keys($author)) !== 1 || ! array_key_exists('@id', $author)) {
121 121
 			return false;
122 122
 		}
123 123
 
124 124
 		$author_linked_entity_id = $author['@id'];
125 125
 
126
-		$author_entity_post = $this->entity_uri_service->get_entity( $author_linked_entity_id );
126
+		$author_entity_post = $this->entity_uri_service->get_entity($author_linked_entity_id);
127 127
 
128
-		if ( ! $author_entity_post instanceof \WP_Post ) {
128
+		if ( ! $author_entity_post instanceof \WP_Post) {
129 129
 			return false;
130 130
 		}
131 131
 
132
-		return $this->cached_postid_to_jsonld_converter->convert( $author_entity_post->ID );
132
+		return $this->cached_postid_to_jsonld_converter->convert($author_entity_post->ID);
133 133
 
134 134
 	}
135 135
 
136
-	private function is_author_entity_present_in_graph( $jsonld, $author_entity_id ) {
136
+	private function is_author_entity_present_in_graph($jsonld, $author_entity_id) {
137 137
 
138
-		foreach ( $jsonld as $item ) {
139
-			if ( $item && array_key_exists( '@id', $item ) && $item['@id'] === $author_entity_id ) {
138
+		foreach ($jsonld as $item) {
139
+			if ($item && array_key_exists('@id', $item) && $item['@id'] === $author_entity_id) {
140 140
 				return true;
141 141
 			}
142 142
 		}
Please login to merge, or discard this patch.
src/wordlift/jsonld/class-jsonld-by-id-endpoint.php 2 patches
Indentation   +118 added lines, -118 removed lines patch added patch discarded remove patch
@@ -23,123 +23,123 @@
 block discarded – undo
23 23
  */
24 24
 class Jsonld_By_Id_Endpoint {
25 25
 
26
-	/**
27
-	 * The {@link Wordlift_Jsonld_Service} instance.
28
-	 *
29
-	 * @var Wordlift_Jsonld_Service The {@link Wordlift_Jsonld_Service} instance.
30
-	 */
31
-	private $jsonld_service;
32
-
33
-	/**
34
-	 * @var \Wordlift_Entity_Uri_Service
35
-	 */
36
-	private $entity_uri_service;
37
-
38
-	/**
39
-	 * Jsonld_Endpoint constructor.
40
-	 *
41
-	 * @param \Wordlift_Jsonld_Service     $jsonld_service
42
-	 * @param \Wordlift_Entity_Uri_Service $entity_uri_service
43
-	 */
44
-	public function __construct( $jsonld_service, $entity_uri_service ) {
45
-
46
-		$this->jsonld_service     = $jsonld_service;
47
-		$this->entity_uri_service = $entity_uri_service;
48
-
49
-		add_action( 'rest_api_init', array( $this, 'register_routes' ) );
50
-
51
-	}
52
-
53
-	/**
54
-	 * Get the JSON-LD.
55
-	 *
56
-	 * @param \WP_REST_Request $request The incoming {@link \WP_REST_Request}.
57
-	 *
58
-	 * @return WP_REST_Response The outgoing {@link WP_REST_Response}.
59
-	 * @throws \Exception when an error occurs.
60
-	 */
61
-	public function jsonld_by_id( $request ) {
62
-
63
-		// Get the ids.
64
-		$ids = (array) $request->get_param( 'id' );
65
-
66
-		// Preload the URIs to reduce the number of DB roundtrips.
67
-		$this->entity_uri_service->preload_uris( array_map( 'urldecode', $ids ) );
68
-
69
-		$that = $this;
70
-
71
-		// Get the posts, filtering out those not found.
72
-		$posts = array_filter(
73
-			array_map(
74
-				function ( $item ) use ( $that ) {
75
-					return $that->entity_uri_service->get_entity( urldecode( $item ) );
76
-				},
77
-				$ids
78
-			)
79
-		);
80
-
81
-		// Get the posts' IDs and make the unique.
82
-		$post_ids = array_unique(
83
-			array_map(
84
-				function ( $item ) {
85
-					return $item->ID;
86
-				},
87
-				$posts
88
-			)
89
-		);
90
-
91
-		// Get the JSON-LD.
92
-		$data = array();
93
-		foreach ( $post_ids as $post_id ) {
94
-			$data = array_merge( $data, $that->jsonld_service->get_jsonld( false, $post_id ) );
95
-		}
96
-
97
-		// Add the WebSite fragment if requested.
98
-		if ( $request->get_param( 'website' ) ) {
99
-			$data[] = $this->jsonld_service->get_jsonld( true );
100
-		}
101
-
102
-		return Jsonld_Response_Helper::to_response( $data );
103
-	}
104
-
105
-	public function register_routes() {
106
-
107
-		register_rest_route(
108
-			WL_REST_ROUTE_DEFAULT_NAMESPACE,
109
-			'/jsonld',
110
-			array(
111
-				'methods'             => WP_REST_Server::READABLE,
112
-				'callback'            => array( $this, 'jsonld_by_id' ),
113
-				'permission_callback' => '__return_true',
114
-				'args'                => array(
115
-					'id'      => array(
116
-						'description'       => __( 'One ore more itemids (e.g. http://data.wordlift.io/wordlift).', 'wordlift' ),
117
-						// We expect an array of strings.
118
-						'type'              => 'array',
119
-						'items'             => array(
120
-							'type' => 'string',
121
-						),
122
-						// phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
123
-						'validate_callback' => function ( $values, $request, $param ) {
124
-
125
-							if ( ! is_array( $values ) ) {
126
-								return new WP_Error( 'rest_invalid_param', esc_html__( 'The id argument must be an array (try passing `id[]=...`.', 'wordlift' ), array( 'status' => 400 ) );
127
-							}
128
-
129
-							foreach ( $values as $value ) {
130
-								if ( 0 !== strpos( $value, 'http' ) ) {
131
-									return new WP_Error( 'rest_invalid_param', esc_html__( 'Ids must start with http.', 'wordlift' ), array( 'status' => 400 ) );
132
-								}
133
-							}
134
-						},
135
-					),
136
-					'website' => array(
137
-						'description' => __( 'Whether to include the WebSite markup.', 'wordlift' ),
138
-					),
139
-				),
140
-			)
141
-		);
142
-
143
-	}
26
+    /**
27
+     * The {@link Wordlift_Jsonld_Service} instance.
28
+     *
29
+     * @var Wordlift_Jsonld_Service The {@link Wordlift_Jsonld_Service} instance.
30
+     */
31
+    private $jsonld_service;
32
+
33
+    /**
34
+     * @var \Wordlift_Entity_Uri_Service
35
+     */
36
+    private $entity_uri_service;
37
+
38
+    /**
39
+     * Jsonld_Endpoint constructor.
40
+     *
41
+     * @param \Wordlift_Jsonld_Service     $jsonld_service
42
+     * @param \Wordlift_Entity_Uri_Service $entity_uri_service
43
+     */
44
+    public function __construct( $jsonld_service, $entity_uri_service ) {
45
+
46
+        $this->jsonld_service     = $jsonld_service;
47
+        $this->entity_uri_service = $entity_uri_service;
48
+
49
+        add_action( 'rest_api_init', array( $this, 'register_routes' ) );
50
+
51
+    }
52
+
53
+    /**
54
+     * Get the JSON-LD.
55
+     *
56
+     * @param \WP_REST_Request $request The incoming {@link \WP_REST_Request}.
57
+     *
58
+     * @return WP_REST_Response The outgoing {@link WP_REST_Response}.
59
+     * @throws \Exception when an error occurs.
60
+     */
61
+    public function jsonld_by_id( $request ) {
62
+
63
+        // Get the ids.
64
+        $ids = (array) $request->get_param( 'id' );
65
+
66
+        // Preload the URIs to reduce the number of DB roundtrips.
67
+        $this->entity_uri_service->preload_uris( array_map( 'urldecode', $ids ) );
68
+
69
+        $that = $this;
70
+
71
+        // Get the posts, filtering out those not found.
72
+        $posts = array_filter(
73
+            array_map(
74
+                function ( $item ) use ( $that ) {
75
+                    return $that->entity_uri_service->get_entity( urldecode( $item ) );
76
+                },
77
+                $ids
78
+            )
79
+        );
80
+
81
+        // Get the posts' IDs and make the unique.
82
+        $post_ids = array_unique(
83
+            array_map(
84
+                function ( $item ) {
85
+                    return $item->ID;
86
+                },
87
+                $posts
88
+            )
89
+        );
90
+
91
+        // Get the JSON-LD.
92
+        $data = array();
93
+        foreach ( $post_ids as $post_id ) {
94
+            $data = array_merge( $data, $that->jsonld_service->get_jsonld( false, $post_id ) );
95
+        }
96
+
97
+        // Add the WebSite fragment if requested.
98
+        if ( $request->get_param( 'website' ) ) {
99
+            $data[] = $this->jsonld_service->get_jsonld( true );
100
+        }
101
+
102
+        return Jsonld_Response_Helper::to_response( $data );
103
+    }
104
+
105
+    public function register_routes() {
106
+
107
+        register_rest_route(
108
+            WL_REST_ROUTE_DEFAULT_NAMESPACE,
109
+            '/jsonld',
110
+            array(
111
+                'methods'             => WP_REST_Server::READABLE,
112
+                'callback'            => array( $this, 'jsonld_by_id' ),
113
+                'permission_callback' => '__return_true',
114
+                'args'                => array(
115
+                    'id'      => array(
116
+                        'description'       => __( 'One ore more itemids (e.g. http://data.wordlift.io/wordlift).', 'wordlift' ),
117
+                        // We expect an array of strings.
118
+                        'type'              => 'array',
119
+                        'items'             => array(
120
+                            'type' => 'string',
121
+                        ),
122
+                        // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
123
+                        'validate_callback' => function ( $values, $request, $param ) {
124
+
125
+                            if ( ! is_array( $values ) ) {
126
+                                return new WP_Error( 'rest_invalid_param', esc_html__( 'The id argument must be an array (try passing `id[]=...`.', 'wordlift' ), array( 'status' => 400 ) );
127
+                            }
128
+
129
+                            foreach ( $values as $value ) {
130
+                                if ( 0 !== strpos( $value, 'http' ) ) {
131
+                                    return new WP_Error( 'rest_invalid_param', esc_html__( 'Ids must start with http.', 'wordlift' ), array( 'status' => 400 ) );
132
+                                }
133
+                            }
134
+                        },
135
+                    ),
136
+                    'website' => array(
137
+                        'description' => __( 'Whether to include the WebSite markup.', 'wordlift' ),
138
+                    ),
139
+                ),
140
+            )
141
+        );
142
+
143
+    }
144 144
 
145 145
 }
Please login to merge, or discard this patch.
Spacing   +22 added lines, -22 removed lines patch added patch discarded remove patch
@@ -41,12 +41,12 @@  discard block
 block discarded – undo
41 41
 	 * @param \Wordlift_Jsonld_Service     $jsonld_service
42 42
 	 * @param \Wordlift_Entity_Uri_Service $entity_uri_service
43 43
 	 */
44
-	public function __construct( $jsonld_service, $entity_uri_service ) {
44
+	public function __construct($jsonld_service, $entity_uri_service) {
45 45
 
46 46
 		$this->jsonld_service     = $jsonld_service;
47 47
 		$this->entity_uri_service = $entity_uri_service;
48 48
 
49
-		add_action( 'rest_api_init', array( $this, 'register_routes' ) );
49
+		add_action('rest_api_init', array($this, 'register_routes'));
50 50
 
51 51
 	}
52 52
 
@@ -58,21 +58,21 @@  discard block
 block discarded – undo
58 58
 	 * @return WP_REST_Response The outgoing {@link WP_REST_Response}.
59 59
 	 * @throws \Exception when an error occurs.
60 60
 	 */
61
-	public function jsonld_by_id( $request ) {
61
+	public function jsonld_by_id($request) {
62 62
 
63 63
 		// Get the ids.
64
-		$ids = (array) $request->get_param( 'id' );
64
+		$ids = (array) $request->get_param('id');
65 65
 
66 66
 		// Preload the URIs to reduce the number of DB roundtrips.
67
-		$this->entity_uri_service->preload_uris( array_map( 'urldecode', $ids ) );
67
+		$this->entity_uri_service->preload_uris(array_map('urldecode', $ids));
68 68
 
69 69
 		$that = $this;
70 70
 
71 71
 		// Get the posts, filtering out those not found.
72 72
 		$posts = array_filter(
73 73
 			array_map(
74
-				function ( $item ) use ( $that ) {
75
-					return $that->entity_uri_service->get_entity( urldecode( $item ) );
74
+				function($item) use ($that) {
75
+					return $that->entity_uri_service->get_entity(urldecode($item));
76 76
 				},
77 77
 				$ids
78 78
 			)
@@ -81,7 +81,7 @@  discard block
 block discarded – undo
81 81
 		// Get the posts' IDs and make the unique.
82 82
 		$post_ids = array_unique(
83 83
 			array_map(
84
-				function ( $item ) {
84
+				function($item) {
85 85
 					return $item->ID;
86 86
 				},
87 87
 				$posts
@@ -90,16 +90,16 @@  discard block
 block discarded – undo
90 90
 
91 91
 		// Get the JSON-LD.
92 92
 		$data = array();
93
-		foreach ( $post_ids as $post_id ) {
94
-			$data = array_merge( $data, $that->jsonld_service->get_jsonld( false, $post_id ) );
93
+		foreach ($post_ids as $post_id) {
94
+			$data = array_merge($data, $that->jsonld_service->get_jsonld(false, $post_id));
95 95
 		}
96 96
 
97 97
 		// Add the WebSite fragment if requested.
98
-		if ( $request->get_param( 'website' ) ) {
99
-			$data[] = $this->jsonld_service->get_jsonld( true );
98
+		if ($request->get_param('website')) {
99
+			$data[] = $this->jsonld_service->get_jsonld(true);
100 100
 		}
101 101
 
102
-		return Jsonld_Response_Helper::to_response( $data );
102
+		return Jsonld_Response_Helper::to_response($data);
103 103
 	}
104 104
 
105 105
 	public function register_routes() {
@@ -109,32 +109,32 @@  discard block
 block discarded – undo
109 109
 			'/jsonld',
110 110
 			array(
111 111
 				'methods'             => WP_REST_Server::READABLE,
112
-				'callback'            => array( $this, 'jsonld_by_id' ),
112
+				'callback'            => array($this, 'jsonld_by_id'),
113 113
 				'permission_callback' => '__return_true',
114 114
 				'args'                => array(
115 115
 					'id'      => array(
116
-						'description'       => __( 'One ore more itemids (e.g. http://data.wordlift.io/wordlift).', 'wordlift' ),
116
+						'description'       => __('One ore more itemids (e.g. http://data.wordlift.io/wordlift).', 'wordlift'),
117 117
 						// We expect an array of strings.
118 118
 						'type'              => 'array',
119 119
 						'items'             => array(
120 120
 							'type' => 'string',
121 121
 						),
122 122
 						// phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
123
-						'validate_callback' => function ( $values, $request, $param ) {
123
+						'validate_callback' => function($values, $request, $param) {
124 124
 
125
-							if ( ! is_array( $values ) ) {
126
-								return new WP_Error( 'rest_invalid_param', esc_html__( 'The id argument must be an array (try passing `id[]=...`.', 'wordlift' ), array( 'status' => 400 ) );
125
+							if ( ! is_array($values)) {
126
+								return new WP_Error('rest_invalid_param', esc_html__('The id argument must be an array (try passing `id[]=...`.', 'wordlift'), array('status' => 400));
127 127
 							}
128 128
 
129
-							foreach ( $values as $value ) {
130
-								if ( 0 !== strpos( $value, 'http' ) ) {
131
-									return new WP_Error( 'rest_invalid_param', esc_html__( 'Ids must start with http.', 'wordlift' ), array( 'status' => 400 ) );
129
+							foreach ($values as $value) {
130
+								if (0 !== strpos($value, 'http')) {
131
+									return new WP_Error('rest_invalid_param', esc_html__('Ids must start with http.', 'wordlift'), array('status' => 400));
132 132
 								}
133 133
 							}
134 134
 						},
135 135
 					),
136 136
 					'website' => array(
137
-						'description' => __( 'Whether to include the WebSite markup.', 'wordlift' ),
137
+						'description' => __('Whether to include the WebSite markup.', 'wordlift'),
138 138
 					),
139 139
 				),
140 140
 			)
Please login to merge, or discard this patch.
src/wordlift/jsonld/class-jsonld-context-enum.php 1 patch
Indentation   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -4,13 +4,13 @@
 block discarded – undo
4 4
 
5 5
 class Jsonld_Context_Enum {
6 6
 
7
-	const UNKNOWN = 0;
8
-	/** Web Page output (typically in the head). */
9
-	const PAGE = 1;
10
-	/** Carousel. */
11
-	const CAROUSEL = 2;
12
-	const FAQ      = 3;
13
-	/** REST services. */
14
-	const REST = 3;
7
+    const UNKNOWN = 0;
8
+    /** Web Page output (typically in the head). */
9
+    const PAGE = 1;
10
+    /** Carousel. */
11
+    const CAROUSEL = 2;
12
+    const FAQ      = 3;
13
+    /** REST services. */
14
+    const REST = 3;
15 15
 
16 16
 }
Please login to merge, or discard this patch.
src/wordlift/jsonld/class-reference-processor.php 2 patches
Indentation   +35 added lines, -35 removed lines patch added patch discarded remove patch
@@ -12,40 +12,40 @@
 block discarded – undo
12 12
 
13 13
 class Reference_Processor extends Singleton {
14 14
 
15
-	public function serialize_references( $references ) {
16
-
17
-		return array_map(
18
-			function ( $reference ) {
19
-				if ( $reference instanceof Post_Reference ) {
20
-					  return 'post_' . $reference->get_id();
21
-				} elseif ( $reference instanceof Term_Reference ) {
22
-					return 'term_' . $reference->get_id();
23
-				}
24
-				// Backward compatibility with other hooks pushing
25
-				// references in to the cache.
26
-				return $reference;
27
-			},
28
-			$references
29
-		);
30
-	}
31
-
32
-	public function deserialize_references( $references ) {
33
-
34
-		return array_map(
35
-			function ( $reference ) {
36
-
37
-				if ( strpos( $reference, 'post_' ) !== false ) {
38
-					  return new Post_Reference( (int) str_replace( 'post_', '', $reference ) );
39
-				} elseif ( strpos( $reference, 'term_' ) !== false ) {
40
-					return new Term_Reference( (int) str_replace( 'term_', '', $reference ) );
41
-				}
42
-				// Backward compatibility with other hooks pushing
43
-				// references in to the cache.
44
-				return new Post_Reference( (int) $reference );
45
-			},
46
-			$references
47
-		);
48
-
49
-	}
15
+    public function serialize_references( $references ) {
16
+
17
+        return array_map(
18
+            function ( $reference ) {
19
+                if ( $reference instanceof Post_Reference ) {
20
+                        return 'post_' . $reference->get_id();
21
+                } elseif ( $reference instanceof Term_Reference ) {
22
+                    return 'term_' . $reference->get_id();
23
+                }
24
+                // Backward compatibility with other hooks pushing
25
+                // references in to the cache.
26
+                return $reference;
27
+            },
28
+            $references
29
+        );
30
+    }
31
+
32
+    public function deserialize_references( $references ) {
33
+
34
+        return array_map(
35
+            function ( $reference ) {
36
+
37
+                if ( strpos( $reference, 'post_' ) !== false ) {
38
+                        return new Post_Reference( (int) str_replace( 'post_', '', $reference ) );
39
+                } elseif ( strpos( $reference, 'term_' ) !== false ) {
40
+                    return new Term_Reference( (int) str_replace( 'term_', '', $reference ) );
41
+                }
42
+                // Backward compatibility with other hooks pushing
43
+                // references in to the cache.
44
+                return new Post_Reference( (int) $reference );
45
+            },
46
+            $references
47
+        );
48
+
49
+    }
50 50
 
51 51
 }
Please login to merge, or discard this patch.
Spacing   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -12,14 +12,14 @@  discard block
 block discarded – undo
12 12
 
13 13
 class Reference_Processor extends Singleton {
14 14
 
15
-	public function serialize_references( $references ) {
15
+	public function serialize_references($references) {
16 16
 
17 17
 		return array_map(
18
-			function ( $reference ) {
19
-				if ( $reference instanceof Post_Reference ) {
20
-					  return 'post_' . $reference->get_id();
21
-				} elseif ( $reference instanceof Term_Reference ) {
22
-					return 'term_' . $reference->get_id();
18
+			function($reference) {
19
+				if ($reference instanceof Post_Reference) {
20
+					  return 'post_'.$reference->get_id();
21
+				} elseif ($reference instanceof Term_Reference) {
22
+					return 'term_'.$reference->get_id();
23 23
 				}
24 24
 				// Backward compatibility with other hooks pushing
25 25
 				// references in to the cache.
@@ -29,19 +29,19 @@  discard block
 block discarded – undo
29 29
 		);
30 30
 	}
31 31
 
32
-	public function deserialize_references( $references ) {
32
+	public function deserialize_references($references) {
33 33
 
34 34
 		return array_map(
35
-			function ( $reference ) {
35
+			function($reference) {
36 36
 
37
-				if ( strpos( $reference, 'post_' ) !== false ) {
38
-					  return new Post_Reference( (int) str_replace( 'post_', '', $reference ) );
39
-				} elseif ( strpos( $reference, 'term_' ) !== false ) {
40
-					return new Term_Reference( (int) str_replace( 'term_', '', $reference ) );
37
+				if (strpos($reference, 'post_') !== false) {
38
+					  return new Post_Reference((int) str_replace('post_', '', $reference));
39
+				} elseif (strpos($reference, 'term_') !== false) {
40
+					return new Term_Reference((int) str_replace('term_', '', $reference));
41 41
 				}
42 42
 				// Backward compatibility with other hooks pushing
43 43
 				// references in to the cache.
44
-				return new Post_Reference( (int) $reference );
44
+				return new Post_Reference((int) $reference);
45 45
 			},
46 46
 			$references
47 47
 		);
Please login to merge, or discard this patch.
src/wordlift/jsonld/class-abstract-reference.php 2 patches
Indentation   +26 added lines, -26 removed lines patch added patch discarded remove patch
@@ -10,35 +10,35 @@
 block discarded – undo
10 10
  */
11 11
 abstract class Abstract_Reference implements Reference {
12 12
 
13
-	/**
14
-	 * @var int
15
-	 */
16
-	private $id;
13
+    /**
14
+     * @var int
15
+     */
16
+    private $id;
17 17
 
18
-	/**
19
-	 * Abstract_Reference constructor.
20
-	 *
21
-	 * @param $id int Identifier for the reference.
22
-	 */
23
-	public function __construct( $id ) {
24
-		$this->id = $id;
25
-	}
18
+    /**
19
+     * Abstract_Reference constructor.
20
+     *
21
+     * @param $id int Identifier for the reference.
22
+     */
23
+    public function __construct( $id ) {
24
+        $this->id = $id;
25
+    }
26 26
 
27
-	abstract public function get_type();
27
+    abstract public function get_type();
28 28
 
29
-	public function get_id() {
30
-		return $this->id;
31
-	}
29
+    public function get_id() {
30
+        return $this->id;
31
+    }
32 32
 
33
-	/**
34
-	 * This function is necessary because array_unique can be applied
35
-	 * on the references, we prepend the id with the type, for example
36
-	 * post reference with post id 1 would be equal to {@link Object_Type_Enum::POST."_1"}
37
-	 *
38
-	 * @return string
39
-	 */
40
-	public function __toString() {
41
-		return $this->get_type() . '_' . $this->get_id();
42
-	}
33
+    /**
34
+     * This function is necessary because array_unique can be applied
35
+     * on the references, we prepend the id with the type, for example
36
+     * post reference with post id 1 would be equal to {@link Object_Type_Enum::POST."_1"}
37
+     *
38
+     * @return string
39
+     */
40
+    public function __toString() {
41
+        return $this->get_type() . '_' . $this->get_id();
42
+    }
43 43
 
44 44
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -20,7 +20,7 @@  discard block
 block discarded – undo
20 20
 	 *
21 21
 	 * @param $id int Identifier for the reference.
22 22
 	 */
23
-	public function __construct( $id ) {
23
+	public function __construct($id) {
24 24
 		$this->id = $id;
25 25
 	}
26 26
 
@@ -38,7 +38,7 @@  discard block
 block discarded – undo
38 38
 	 * @return string
39 39
 	 */
40 40
 	public function __toString() {
41
-		return $this->get_type() . '_' . $this->get_id();
41
+		return $this->get_type().'_'.$this->get_id();
42 42
 	}
43 43
 
44 44
 }
Please login to merge, or discard this patch.