Completed
Pull Request — develop (#1082)
by Naveen
02:31
created
src/wordlift/autocomplete/class-local-autocomplete-service.php 2 patches
Indentation   +49 added lines, -49 removed lines patch added patch discarded remove patch
@@ -15,59 +15,59 @@
 block discarded – undo
15 15
 
16 16
 class Local_Autocomplete_Service extends Abstract_Autocomplete_Service {
17 17
 
18
-	/**
19
-	 * @inheritDoc
20
-	 */
21
-	public function query( $query, $scope, $excludes ) {
22
-		global $wpdb;
18
+    /**
19
+     * @inheritDoc
20
+     */
21
+    public function query( $query, $scope, $excludes ) {
22
+        global $wpdb;
23 23
 
24
-		$posts = $wpdb->get_results( $wpdb->prepare(
25
-			"SELECT * FROM {$wpdb->posts} p"
26
-			. " INNER JOIN {$wpdb->term_relationships} tr"
27
-			. "  ON tr.object_id = p.ID"
28
-			. " INNER JOIN {$wpdb->term_taxonomy} tt"
29
-			. "  ON tt.taxonomy = %s AND tt.term_taxonomy_id = tr.term_taxonomy_id"
30
-			. " INNER JOIN {$wpdb->terms} t"
31
-			. "  ON t.term_id = tt.term_id AND t.name != %s"
32
-			. " LEFT OUTER JOIN {$wpdb->postmeta} pm"
33
-			. "  ON pm.meta_key = %s AND pm.post_id = p.ID"
34
-			. " WHERE p.post_type IN ( '" . implode( "', '", array_map( 'esc_sql', Wordlift_Entity_Service::valid_entity_post_types() ) ) . "' )"
35
-			. "  AND ( p.post_title LIKE %s OR pm.meta_value LIKE %s )"
36
-			. " LIMIT %d",
37
-			Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME,
38
-			'article',
39
-			Wordlift_Entity_Service::ALTERNATIVE_LABEL_META_KEY,
40
-			// `prepare` doesn't support argument number, hence we must repeat the query.
41
-			'%' . $wpdb->esc_like( $query ) . '%',
42
-			'%' . $wpdb->esc_like( $query ) . '%',
43
-			50
44
-		) );
24
+        $posts = $wpdb->get_results( $wpdb->prepare(
25
+            "SELECT * FROM {$wpdb->posts} p"
26
+            . " INNER JOIN {$wpdb->term_relationships} tr"
27
+            . "  ON tr.object_id = p.ID"
28
+            . " INNER JOIN {$wpdb->term_taxonomy} tt"
29
+            . "  ON tt.taxonomy = %s AND tt.term_taxonomy_id = tr.term_taxonomy_id"
30
+            . " INNER JOIN {$wpdb->terms} t"
31
+            . "  ON t.term_id = tt.term_id AND t.name != %s"
32
+            . " LEFT OUTER JOIN {$wpdb->postmeta} pm"
33
+            . "  ON pm.meta_key = %s AND pm.post_id = p.ID"
34
+            . " WHERE p.post_type IN ( '" . implode( "', '", array_map( 'esc_sql', Wordlift_Entity_Service::valid_entity_post_types() ) ) . "' )"
35
+            . "  AND ( p.post_title LIKE %s OR pm.meta_value LIKE %s )"
36
+            . " LIMIT %d",
37
+            Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME,
38
+            'article',
39
+            Wordlift_Entity_Service::ALTERNATIVE_LABEL_META_KEY,
40
+            // `prepare` doesn't support argument number, hence we must repeat the query.
41
+            '%' . $wpdb->esc_like( $query ) . '%',
42
+            '%' . $wpdb->esc_like( $query ) . '%',
43
+            50
44
+        ) );
45 45
 
46
-		$results = array_map( function ( $item ) {
46
+        $results = array_map( function ( $item ) {
47 47
 
48
-			$entity_service = Wordlift_Entity_Service::get_instance();
49
-			$uri            = $entity_service->get_uri( $item->ID );
48
+            $entity_service = Wordlift_Entity_Service::get_instance();
49
+            $uri            = $entity_service->get_uri( $item->ID );
50 50
 
51
-			return array(
52
-				// see #1074: The value property is needed for autocomplete in category page
53
-				// to function correctly, if value is not provided, then the entity
54
-				// wont be correctly saved.
55
-				'value'        => $uri,
56
-				'id'           => $uri,
57
-				'label'        => array( $item->post_title ),
58
-				'labels'       => $entity_service->get_alternative_labels( $item->ID ),
59
-				'descriptions' => array( Wordlift_Post_Excerpt_Helper::get_text_excerpt( $item ) ),
60
-				'scope'        => 'local',
61
-				'sameAss'      => get_post_meta( $item->ID, \Wordlift_Schema_Service::FIELD_SAME_AS ),
62
-				// The following properties are less relevant because we're linking entities that exist already in the
63
-				// vocabulary. That's why we don't make an effort to load the real data.
64
-				'types'        => array( 'http://schema.org/Thing' ),
65
-				'urls'         => array(),
66
-				'images'       => array(),
67
-			);
68
-		}, $posts );
51
+            return array(
52
+                // see #1074: The value property is needed for autocomplete in category page
53
+                // to function correctly, if value is not provided, then the entity
54
+                // wont be correctly saved.
55
+                'value'        => $uri,
56
+                'id'           => $uri,
57
+                'label'        => array( $item->post_title ),
58
+                'labels'       => $entity_service->get_alternative_labels( $item->ID ),
59
+                'descriptions' => array( Wordlift_Post_Excerpt_Helper::get_text_excerpt( $item ) ),
60
+                'scope'        => 'local',
61
+                'sameAss'      => get_post_meta( $item->ID, \Wordlift_Schema_Service::FIELD_SAME_AS ),
62
+                // The following properties are less relevant because we're linking entities that exist already in the
63
+                // vocabulary. That's why we don't make an effort to load the real data.
64
+                'types'        => array( 'http://schema.org/Thing' ),
65
+                'urls'         => array(),
66
+                'images'       => array(),
67
+            );
68
+        }, $posts );
69 69
 
70
-		return $this->filter( $results, $excludes );
71
-	}
70
+        return $this->filter( $results, $excludes );
71
+    }
72 72
 
73 73
 }
Please login to merge, or discard this patch.
Spacing   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -18,10 +18,10 @@  discard block
 block discarded – undo
18 18
 	/**
19 19
 	 * @inheritDoc
20 20
 	 */
21
-	public function query( $query, $scope, $excludes ) {
21
+	public function query($query, $scope, $excludes) {
22 22
 		global $wpdb;
23 23
 
24
-		$posts = $wpdb->get_results( $wpdb->prepare(
24
+		$posts = $wpdb->get_results($wpdb->prepare(
25 25
 			"SELECT * FROM {$wpdb->posts} p"
26 26
 			. " INNER JOIN {$wpdb->term_relationships} tr"
27 27
 			. "  ON tr.object_id = p.ID"
@@ -31,22 +31,22 @@  discard block
 block discarded – undo
31 31
 			. "  ON t.term_id = tt.term_id AND t.name != %s"
32 32
 			. " LEFT OUTER JOIN {$wpdb->postmeta} pm"
33 33
 			. "  ON pm.meta_key = %s AND pm.post_id = p.ID"
34
-			. " WHERE p.post_type IN ( '" . implode( "', '", array_map( 'esc_sql', Wordlift_Entity_Service::valid_entity_post_types() ) ) . "' )"
34
+			. " WHERE p.post_type IN ( '".implode("', '", array_map('esc_sql', Wordlift_Entity_Service::valid_entity_post_types()))."' )"
35 35
 			. "  AND ( p.post_title LIKE %s OR pm.meta_value LIKE %s )"
36 36
 			. " LIMIT %d",
37 37
 			Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME,
38 38
 			'article',
39 39
 			Wordlift_Entity_Service::ALTERNATIVE_LABEL_META_KEY,
40 40
 			// `prepare` doesn't support argument number, hence we must repeat the query.
41
-			'%' . $wpdb->esc_like( $query ) . '%',
42
-			'%' . $wpdb->esc_like( $query ) . '%',
41
+			'%'.$wpdb->esc_like($query).'%',
42
+			'%'.$wpdb->esc_like($query).'%',
43 43
 			50
44
-		) );
44
+		));
45 45
 
46
-		$results = array_map( function ( $item ) {
46
+		$results = array_map(function($item) {
47 47
 
48 48
 			$entity_service = Wordlift_Entity_Service::get_instance();
49
-			$uri            = $entity_service->get_uri( $item->ID );
49
+			$uri            = $entity_service->get_uri($item->ID);
50 50
 
51 51
 			return array(
52 52
 				// see #1074: The value property is needed for autocomplete in category page
@@ -54,20 +54,20 @@  discard block
 block discarded – undo
54 54
 				// wont be correctly saved.
55 55
 				'value'        => $uri,
56 56
 				'id'           => $uri,
57
-				'label'        => array( $item->post_title ),
58
-				'labels'       => $entity_service->get_alternative_labels( $item->ID ),
59
-				'descriptions' => array( Wordlift_Post_Excerpt_Helper::get_text_excerpt( $item ) ),
57
+				'label'        => array($item->post_title),
58
+				'labels'       => $entity_service->get_alternative_labels($item->ID),
59
+				'descriptions' => array(Wordlift_Post_Excerpt_Helper::get_text_excerpt($item)),
60 60
 				'scope'        => 'local',
61
-				'sameAss'      => get_post_meta( $item->ID, \Wordlift_Schema_Service::FIELD_SAME_AS ),
61
+				'sameAss'      => get_post_meta($item->ID, \Wordlift_Schema_Service::FIELD_SAME_AS),
62 62
 				// The following properties are less relevant because we're linking entities that exist already in the
63 63
 				// vocabulary. That's why we don't make an effort to load the real data.
64
-				'types'        => array( 'http://schema.org/Thing' ),
64
+				'types'        => array('http://schema.org/Thing'),
65 65
 				'urls'         => array(),
66 66
 				'images'       => array(),
67 67
 			);
68
-		}, $posts );
68
+		}, $posts);
69 69
 
70
-		return $this->filter( $results, $excludes );
70
+		return $this->filter($results, $excludes);
71 71
 	}
72 72
 
73 73
 }
Please login to merge, or discard this patch.