Completed
Push — master ( 143196...bf137f )
by Naveen
02:12 queued 01:12
created
src/wordlift/jsonld/class-mentions.php 2 patches
Indentation   +127 added lines, -127 removed lines patch added patch discarded remove patch
@@ -16,132 +16,132 @@
 block discarded – undo
16 16
 
17 17
 class Mentions {
18 18
 
19
-	private $schema_descendants = array(
20
-		'Drawing',
21
-		'MusicPlaylist',
22
-		'Quotation',
23
-		'ShortStory',
24
-		'DigitalDocument',
25
-		'DataCatalog',
26
-		'SoftwareApplication',
27
-		'CreativeWorkSeason',
28
-		'VisualArtwork',
29
-		'PublicationIssue',
30
-		'SoftwareSourceCode',
31
-		'Message',
32
-		'Collection',
33
-		'WebPage',
34
-		'WebSite',
35
-		'HyperTocEntry',
36
-		'Guide',
37
-		'Course',
38
-		'MusicComposition',
39
-		'AmpStory',
40
-		'SpecialAnnouncement',
41
-		'HowToTip',
42
-		'Season',
43
-		'HowTo',
44
-		'ExercisePlan',
45
-		'HowToStep',
46
-		'Review',
47
-		'HowToDirection',
48
-		'Sculpture',
49
-		'Thesis',
50
-		'Book',
51
-		'Diet',
52
-		'Manuscript',
53
-		'Legislation',
54
-		'Clip',
55
-		'Atlas',
56
-		'Article',
57
-		'MathSolver',
58
-		'Game',
59
-		'Blog',
60
-		'LearningResource',
61
-		'Code',
62
-		'MusicRecording',
63
-		'WebContent',
64
-		'TvSeries',
65
-		'Menu',
66
-		'MenuSection',
67
-		'HowToSection',
68
-		'Dataset',
69
-		'PublicationVolume',
70
-		'EducationalOccupationalCredential',
71
-		'TvSeason',
72
-		'Poster',
73
-		'Play',
74
-		'ComicStory',
75
-		'MediaObject',
76
-		'Movie',
77
-		'ArchiveComponent',
78
-		'Comment',
79
-		'SheetMusic',
80
-		'Conversation',
81
-		'Map',
82
-		'Photograph',
83
-		'HyperToc',
84
-		'Episode',
85
-		'Chapter',
86
-		'Painting',
87
-		'WebPageElement',
88
-		'CreativeWorkSeries',
89
-		'Claim',
90
-		'DefinedTermSet',
91
-	);
92
-
93
-	public function __construct() {
94
-		add_filter( 'wl_after_get_jsonld', array( $this, 'wl_after_get_jsonld' ), 10, 2 );
95
-	}
96
-
97
-	public function wl_after_get_jsonld( $jsonld, $post_id ) {
98
-
99
-		if ( count( $jsonld ) === 0 || ! array_key_exists( '@type', $jsonld[0] ) || array_key_exists( 'mentions', $jsonld[0] ) ) {
100
-			return $jsonld;
101
-		}
102
-
103
-
104
-		$type = $jsonld[0]['@type'];
105
-
106
-
107
-		if ( ! $this->entity_is_descendant_of_creative_work( $type ) && ! $this->entity_is_creative_work( $type ) ) {
108
-			return $jsonld;
109
-		}
110
-
111
-		$entity_references = Object_Relation_Service::get_instance()
112
-		                                            ->get_references( $post_id, Object_Type_Enum::POST );
113
-
114
-
115
-		$jsonld[0]['mentions'] = array_values( array_filter( array_map( function ( $item ) {
116
-			$id = \Wordlift_Entity_Service::get_instance()->get_uri( $item->get_id() );
117
-			if ( ! $id ) {
118
-				return false;
119
-			}
120
-
121
-			return array( '@id' => $id );
122
-
123
-		}, $entity_references ) ) );
124
-
125
-		// Remove mentions if the count is zero.
126
-		if ( count( $jsonld[0]['mentions'] ) === 0 ) {
127
-			unset( $jsonld[0]['mentions'] );
128
-		}
129
-
130
-
131
-		return $jsonld;
132
-	}
133
-
134
-
135
-	private function entity_is_descendant_of_creative_work( $type ) {
136
-		if ( is_string( $type ) ) {
137
-			$type = array( $type );
138
-		}
139
-
140
-		return count( array_intersect( $type, $this->schema_descendants ) ) > 0;
141
-	}
142
-
143
-	private function entity_is_creative_work( $type ) {
144
-		return ( $type === 'CreativeWork' ) || ( is_array( $type ) && in_array( 'CreativeWork', $type ) );
145
-	}
19
+    private $schema_descendants = array(
20
+        'Drawing',
21
+        'MusicPlaylist',
22
+        'Quotation',
23
+        'ShortStory',
24
+        'DigitalDocument',
25
+        'DataCatalog',
26
+        'SoftwareApplication',
27
+        'CreativeWorkSeason',
28
+        'VisualArtwork',
29
+        'PublicationIssue',
30
+        'SoftwareSourceCode',
31
+        'Message',
32
+        'Collection',
33
+        'WebPage',
34
+        'WebSite',
35
+        'HyperTocEntry',
36
+        'Guide',
37
+        'Course',
38
+        'MusicComposition',
39
+        'AmpStory',
40
+        'SpecialAnnouncement',
41
+        'HowToTip',
42
+        'Season',
43
+        'HowTo',
44
+        'ExercisePlan',
45
+        'HowToStep',
46
+        'Review',
47
+        'HowToDirection',
48
+        'Sculpture',
49
+        'Thesis',
50
+        'Book',
51
+        'Diet',
52
+        'Manuscript',
53
+        'Legislation',
54
+        'Clip',
55
+        'Atlas',
56
+        'Article',
57
+        'MathSolver',
58
+        'Game',
59
+        'Blog',
60
+        'LearningResource',
61
+        'Code',
62
+        'MusicRecording',
63
+        'WebContent',
64
+        'TvSeries',
65
+        'Menu',
66
+        'MenuSection',
67
+        'HowToSection',
68
+        'Dataset',
69
+        'PublicationVolume',
70
+        'EducationalOccupationalCredential',
71
+        'TvSeason',
72
+        'Poster',
73
+        'Play',
74
+        'ComicStory',
75
+        'MediaObject',
76
+        'Movie',
77
+        'ArchiveComponent',
78
+        'Comment',
79
+        'SheetMusic',
80
+        'Conversation',
81
+        'Map',
82
+        'Photograph',
83
+        'HyperToc',
84
+        'Episode',
85
+        'Chapter',
86
+        'Painting',
87
+        'WebPageElement',
88
+        'CreativeWorkSeries',
89
+        'Claim',
90
+        'DefinedTermSet',
91
+    );
92
+
93
+    public function __construct() {
94
+        add_filter( 'wl_after_get_jsonld', array( $this, 'wl_after_get_jsonld' ), 10, 2 );
95
+    }
96
+
97
+    public function wl_after_get_jsonld( $jsonld, $post_id ) {
98
+
99
+        if ( count( $jsonld ) === 0 || ! array_key_exists( '@type', $jsonld[0] ) || array_key_exists( 'mentions', $jsonld[0] ) ) {
100
+            return $jsonld;
101
+        }
102
+
103
+
104
+        $type = $jsonld[0]['@type'];
105
+
106
+
107
+        if ( ! $this->entity_is_descendant_of_creative_work( $type ) && ! $this->entity_is_creative_work( $type ) ) {
108
+            return $jsonld;
109
+        }
110
+
111
+        $entity_references = Object_Relation_Service::get_instance()
112
+                                                    ->get_references( $post_id, Object_Type_Enum::POST );
113
+
114
+
115
+        $jsonld[0]['mentions'] = array_values( array_filter( array_map( function ( $item ) {
116
+            $id = \Wordlift_Entity_Service::get_instance()->get_uri( $item->get_id() );
117
+            if ( ! $id ) {
118
+                return false;
119
+            }
120
+
121
+            return array( '@id' => $id );
122
+
123
+        }, $entity_references ) ) );
124
+
125
+        // Remove mentions if the count is zero.
126
+        if ( count( $jsonld[0]['mentions'] ) === 0 ) {
127
+            unset( $jsonld[0]['mentions'] );
128
+        }
129
+
130
+
131
+        return $jsonld;
132
+    }
133
+
134
+
135
+    private function entity_is_descendant_of_creative_work( $type ) {
136
+        if ( is_string( $type ) ) {
137
+            $type = array( $type );
138
+        }
139
+
140
+        return count( array_intersect( $type, $this->schema_descendants ) ) > 0;
141
+    }
142
+
143
+    private function entity_is_creative_work( $type ) {
144
+        return ( $type === 'CreativeWork' ) || ( is_array( $type ) && in_array( 'CreativeWork', $type ) );
145
+    }
146 146
 
147 147
 }
148 148
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -91,12 +91,12 @@  discard block
 block discarded – undo
91 91
 	);
92 92
 
93 93
 	public function __construct() {
94
-		add_filter( 'wl_after_get_jsonld', array( $this, 'wl_after_get_jsonld' ), 10, 2 );
94
+		add_filter('wl_after_get_jsonld', array($this, 'wl_after_get_jsonld'), 10, 2);
95 95
 	}
96 96
 
97
-	public function wl_after_get_jsonld( $jsonld, $post_id ) {
97
+	public function wl_after_get_jsonld($jsonld, $post_id) {
98 98
 
99
-		if ( count( $jsonld ) === 0 || ! array_key_exists( '@type', $jsonld[0] ) || array_key_exists( 'mentions', $jsonld[0] ) ) {
99
+		if (count($jsonld) === 0 || ! array_key_exists('@type', $jsonld[0]) || array_key_exists('mentions', $jsonld[0])) {
100 100
 			return $jsonld;
101 101
 		}
102 102
 
@@ -104,27 +104,27 @@  discard block
 block discarded – undo
104 104
 		$type = $jsonld[0]['@type'];
105 105
 
106 106
 
107
-		if ( ! $this->entity_is_descendant_of_creative_work( $type ) && ! $this->entity_is_creative_work( $type ) ) {
107
+		if ( ! $this->entity_is_descendant_of_creative_work($type) && ! $this->entity_is_creative_work($type)) {
108 108
 			return $jsonld;
109 109
 		}
110 110
 
111 111
 		$entity_references = Object_Relation_Service::get_instance()
112
-		                                            ->get_references( $post_id, Object_Type_Enum::POST );
112
+		                                            ->get_references($post_id, Object_Type_Enum::POST);
113 113
 
114 114
 
115
-		$jsonld[0]['mentions'] = array_values( array_filter( array_map( function ( $item ) {
116
-			$id = \Wordlift_Entity_Service::get_instance()->get_uri( $item->get_id() );
117
-			if ( ! $id ) {
115
+		$jsonld[0]['mentions'] = array_values(array_filter(array_map(function($item) {
116
+			$id = \Wordlift_Entity_Service::get_instance()->get_uri($item->get_id());
117
+			if ( ! $id) {
118 118
 				return false;
119 119
 			}
120 120
 
121
-			return array( '@id' => $id );
121
+			return array('@id' => $id);
122 122
 
123
-		}, $entity_references ) ) );
123
+		}, $entity_references)));
124 124
 
125 125
 		// Remove mentions if the count is zero.
126
-		if ( count( $jsonld[0]['mentions'] ) === 0 ) {
127
-			unset( $jsonld[0]['mentions'] );
126
+		if (count($jsonld[0]['mentions']) === 0) {
127
+			unset($jsonld[0]['mentions']);
128 128
 		}
129 129
 
130 130
 
@@ -132,16 +132,16 @@  discard block
 block discarded – undo
132 132
 	}
133 133
 
134 134
 
135
-	private function entity_is_descendant_of_creative_work( $type ) {
136
-		if ( is_string( $type ) ) {
137
-			$type = array( $type );
135
+	private function entity_is_descendant_of_creative_work($type) {
136
+		if (is_string($type)) {
137
+			$type = array($type);
138 138
 		}
139 139
 
140
-		return count( array_intersect( $type, $this->schema_descendants ) ) > 0;
140
+		return count(array_intersect($type, $this->schema_descendants)) > 0;
141 141
 	}
142 142
 
143
-	private function entity_is_creative_work( $type ) {
144
-		return ( $type === 'CreativeWork' ) || ( is_array( $type ) && in_array( 'CreativeWork', $type ) );
143
+	private function entity_is_creative_work($type) {
144
+		return ($type === 'CreativeWork') || (is_array($type) && in_array('CreativeWork', $type));
145 145
 	}
146 146
 
147 147
 }
148 148
\ No newline at end of file
Please login to merge, or discard this patch.