Completed
Pull Request — master (#1530)
by Naveen
01:12
created
wordlift/content/wordpress/class-wordpress-permalink-content-service.php 2 patches
Indentation   +125 added lines, -125 removed lines patch added patch discarded remove patch
@@ -8,62 +8,62 @@  discard block
 block discarded – undo
8 8
 
9 9
 class Wordpress_Permalink_Content_Service implements Content_Service {
10 10
 
11
-	private static $instance = null;
12
-
13
-	protected function __construct() {
14
-	}
15
-
16
-	/**
17
-	 * The singleton instance.
18
-	 *
19
-	 * @return Content_Service
20
-	 */
21
-	public static function get_instance() {
22
-		if ( ! isset( self::$instance ) ) {
23
-			self::$instance = new self();
24
-		}
25
-
26
-		return self::$instance;
27
-	}
28
-
29
-	/**
30
-	 * @param $uri string In the form https://example.org/path/post#post/1
31
-	 *
32
-	 * @return Wordpress_Content|null
33
-	 */
34
-	function get_by_entity_id( $uri ) {
35
-		if ( ! preg_match( '@.*#(\w+)/(\d+)@', $uri, $matches ) ) {
36
-			return null;
37
-		}
38
-
39
-		$type_name = $matches[1];
40
-		$id        = $matches[2];
41
-		switch ( Object_Type_Enum::from_string( $type_name ) ) {
42
-			case Object_Type_Enum::POST:
43
-				return new Wordpress_Content( get_post( $id ) );
44
-			case Object_Type_Enum::TERM:
45
-				return new Wordpress_Content( get_term( $id ) );
46
-			case Object_Type_Enum::USER:
47
-				return new Wordpress_Content( get_user_by( 'ID', $id ) );
48
-		}
49
-
50
-		return null;
51
-	}
52
-
53
-	/**
54
-	 * Get a
55
-	 * @throws Exception
56
-	 */
57
-	function get_by_entity_id_or_same_as( $uri ) {
58
-		// If the URL is in the local site URL, then try to find a corresponding post.
59
-		if ( 0 === strpos( $uri, site_url() ) ) {
60
-			return $this->get_by_entity_id( $uri );
61
-		}
62
-
63
-		// Otherwise look in sameAs.
64
-		global $wpdb;
65
-
66
-		$row = $wpdb->get_row( $wpdb->prepare( "
11
+    private static $instance = null;
12
+
13
+    protected function __construct() {
14
+    }
15
+
16
+    /**
17
+     * The singleton instance.
18
+     *
19
+     * @return Content_Service
20
+     */
21
+    public static function get_instance() {
22
+        if ( ! isset( self::$instance ) ) {
23
+            self::$instance = new self();
24
+        }
25
+
26
+        return self::$instance;
27
+    }
28
+
29
+    /**
30
+     * @param $uri string In the form https://example.org/path/post#post/1
31
+     *
32
+     * @return Wordpress_Content|null
33
+     */
34
+    function get_by_entity_id( $uri ) {
35
+        if ( ! preg_match( '@.*#(\w+)/(\d+)@', $uri, $matches ) ) {
36
+            return null;
37
+        }
38
+
39
+        $type_name = $matches[1];
40
+        $id        = $matches[2];
41
+        switch ( Object_Type_Enum::from_string( $type_name ) ) {
42
+            case Object_Type_Enum::POST:
43
+                return new Wordpress_Content( get_post( $id ) );
44
+            case Object_Type_Enum::TERM:
45
+                return new Wordpress_Content( get_term( $id ) );
46
+            case Object_Type_Enum::USER:
47
+                return new Wordpress_Content( get_user_by( 'ID', $id ) );
48
+        }
49
+
50
+        return null;
51
+    }
52
+
53
+    /**
54
+     * Get a
55
+     * @throws Exception
56
+     */
57
+    function get_by_entity_id_or_same_as( $uri ) {
58
+        // If the URL is in the local site URL, then try to find a corresponding post.
59
+        if ( 0 === strpos( $uri, site_url() ) ) {
60
+            return $this->get_by_entity_id( $uri );
61
+        }
62
+
63
+        // Otherwise look in sameAs.
64
+        global $wpdb;
65
+
66
+        $row = $wpdb->get_row( $wpdb->prepare( "
67 67
 			SELECT content_type, content_id
68 68
 			FROM (
69 69
 			    SELECT %d AS content_type, post_id AS content_id
@@ -80,73 +80,73 @@  discard block
 block discarded – undo
80 80
 			) _tmp_same_as 
81 81
 			LIMIT 1
82 82
 		",
83
-			Object_Type_Enum::POST, $uri,
84
-			Object_Type_Enum::TERM, $uri,
85
-			Object_Type_Enum::USER, $uri ) );
86
-
87
-		if ( ! isset( $row ) ) {
88
-			return null;
89
-		}
90
-
91
-		switch ( (int) $row->content_type ) {
92
-			case Object_Type_Enum::POST:
93
-				return new Wordpress_Content( get_post( $row->content_id ) );
94
-			case Object_Type_Enum::TERM:
95
-				return new Wordpress_Content( get_term( $row->content_id ) );
96
-			case Object_Type_Enum::USER:
97
-				return new Wordpress_Content( get_user_by( 'ID', $row->content_id ) );
98
-			default:
99
-				return null;
100
-		}
101
-
102
-	}
103
-
104
-	/**
105
-	 * @param Wordpress_Content_Id $content_id
106
-	 *
107
-	 * @return string|void|null
108
-	 */
109
-	function get_entity_id( $content_id ) {
110
-		$type = $content_id->get_type();
111
-		$id   = $content_id->get_id();
112
-
113
-		switch ( $type ) {
114
-			case Object_Type_Enum::POST:
115
-				$base_uri = get_permalink( $id );
116
-				break;
117
-			case Object_Type_Enum::TERM:
118
-				$base_uri = get_term_link( $id );
119
-				break;
120
-			case Object_Type_Enum::USER:
121
-				$base_uri = get_author_posts_url( $id );
122
-				break;
123
-			default:
124
-				return null;
125
-		}
126
-
127
-		$type_name = Object_Type_Enum::to_string( $type );
128
-
129
-		return "$base_uri#$type_name/$id";
130
-	}
131
-
132
-	function set_entity_id( $content_id, $uri ) {
133
-		// do nothing.
134
-	}
135
-
136
-	/**
137
-	 * @param Wordpress_Content_Id $content_id
138
-	 *
139
-	 * @return bool|void
140
-	 */
141
-	function supports( $content_id ) {
142
-		return in_array( $content_id->get_type(), array(
143
-			Object_Type_Enum::POST,
144
-			Object_Type_Enum::TERM,
145
-			Object_Type_Enum::USER,
146
-		) );
147
-	}
148
-
149
-	function delete( $content_id ) {
150
-		// Ignore, we don't store any data.
151
-	}
83
+            Object_Type_Enum::POST, $uri,
84
+            Object_Type_Enum::TERM, $uri,
85
+            Object_Type_Enum::USER, $uri ) );
86
+
87
+        if ( ! isset( $row ) ) {
88
+            return null;
89
+        }
90
+
91
+        switch ( (int) $row->content_type ) {
92
+            case Object_Type_Enum::POST:
93
+                return new Wordpress_Content( get_post( $row->content_id ) );
94
+            case Object_Type_Enum::TERM:
95
+                return new Wordpress_Content( get_term( $row->content_id ) );
96
+            case Object_Type_Enum::USER:
97
+                return new Wordpress_Content( get_user_by( 'ID', $row->content_id ) );
98
+            default:
99
+                return null;
100
+        }
101
+
102
+    }
103
+
104
+    /**
105
+     * @param Wordpress_Content_Id $content_id
106
+     *
107
+     * @return string|void|null
108
+     */
109
+    function get_entity_id( $content_id ) {
110
+        $type = $content_id->get_type();
111
+        $id   = $content_id->get_id();
112
+
113
+        switch ( $type ) {
114
+            case Object_Type_Enum::POST:
115
+                $base_uri = get_permalink( $id );
116
+                break;
117
+            case Object_Type_Enum::TERM:
118
+                $base_uri = get_term_link( $id );
119
+                break;
120
+            case Object_Type_Enum::USER:
121
+                $base_uri = get_author_posts_url( $id );
122
+                break;
123
+            default:
124
+                return null;
125
+        }
126
+
127
+        $type_name = Object_Type_Enum::to_string( $type );
128
+
129
+        return "$base_uri#$type_name/$id";
130
+    }
131
+
132
+    function set_entity_id( $content_id, $uri ) {
133
+        // do nothing.
134
+    }
135
+
136
+    /**
137
+     * @param Wordpress_Content_Id $content_id
138
+     *
139
+     * @return bool|void
140
+     */
141
+    function supports( $content_id ) {
142
+        return in_array( $content_id->get_type(), array(
143
+            Object_Type_Enum::POST,
144
+            Object_Type_Enum::TERM,
145
+            Object_Type_Enum::USER,
146
+        ) );
147
+    }
148
+
149
+    function delete( $content_id ) {
150
+        // Ignore, we don't store any data.
151
+    }
152 152
 }
Please login to merge, or discard this patch.
Spacing   +28 added lines, -28 removed lines patch added patch discarded remove patch
@@ -19,7 +19,7 @@  discard block
 block discarded – undo
19 19
 	 * @return Content_Service
20 20
 	 */
21 21
 	public static function get_instance() {
22
-		if ( ! isset( self::$instance ) ) {
22
+		if ( ! isset(self::$instance)) {
23 23
 			self::$instance = new self();
24 24
 		}
25 25
 
@@ -31,20 +31,20 @@  discard block
 block discarded – undo
31 31
 	 *
32 32
 	 * @return Wordpress_Content|null
33 33
 	 */
34
-	function get_by_entity_id( $uri ) {
35
-		if ( ! preg_match( '@.*#(\w+)/(\d+)@', $uri, $matches ) ) {
34
+	function get_by_entity_id($uri) {
35
+		if ( ! preg_match('@.*#(\w+)/(\d+)@', $uri, $matches)) {
36 36
 			return null;
37 37
 		}
38 38
 
39 39
 		$type_name = $matches[1];
40 40
 		$id        = $matches[2];
41
-		switch ( Object_Type_Enum::from_string( $type_name ) ) {
41
+		switch (Object_Type_Enum::from_string($type_name)) {
42 42
 			case Object_Type_Enum::POST:
43
-				return new Wordpress_Content( get_post( $id ) );
43
+				return new Wordpress_Content(get_post($id));
44 44
 			case Object_Type_Enum::TERM:
45
-				return new Wordpress_Content( get_term( $id ) );
45
+				return new Wordpress_Content(get_term($id));
46 46
 			case Object_Type_Enum::USER:
47
-				return new Wordpress_Content( get_user_by( 'ID', $id ) );
47
+				return new Wordpress_Content(get_user_by('ID', $id));
48 48
 		}
49 49
 
50 50
 		return null;
@@ -54,16 +54,16 @@  discard block
 block discarded – undo
54 54
 	 * Get a
55 55
 	 * @throws Exception
56 56
 	 */
57
-	function get_by_entity_id_or_same_as( $uri ) {
57
+	function get_by_entity_id_or_same_as($uri) {
58 58
 		// If the URL is in the local site URL, then try to find a corresponding post.
59
-		if ( 0 === strpos( $uri, site_url() ) ) {
60
-			return $this->get_by_entity_id( $uri );
59
+		if (0 === strpos($uri, site_url())) {
60
+			return $this->get_by_entity_id($uri);
61 61
 		}
62 62
 
63 63
 		// Otherwise look in sameAs.
64 64
 		global $wpdb;
65 65
 
66
-		$row = $wpdb->get_row( $wpdb->prepare( "
66
+		$row = $wpdb->get_row($wpdb->prepare("
67 67
 			SELECT content_type, content_id
68 68
 			FROM (
69 69
 			    SELECT %d AS content_type, post_id AS content_id
@@ -82,19 +82,19 @@  discard block
 block discarded – undo
82 82
 		",
83 83
 			Object_Type_Enum::POST, $uri,
84 84
 			Object_Type_Enum::TERM, $uri,
85
-			Object_Type_Enum::USER, $uri ) );
85
+			Object_Type_Enum::USER, $uri));
86 86
 
87
-		if ( ! isset( $row ) ) {
87
+		if ( ! isset($row)) {
88 88
 			return null;
89 89
 		}
90 90
 
91
-		switch ( (int) $row->content_type ) {
91
+		switch ((int) $row->content_type) {
92 92
 			case Object_Type_Enum::POST:
93
-				return new Wordpress_Content( get_post( $row->content_id ) );
93
+				return new Wordpress_Content(get_post($row->content_id));
94 94
 			case Object_Type_Enum::TERM:
95
-				return new Wordpress_Content( get_term( $row->content_id ) );
95
+				return new Wordpress_Content(get_term($row->content_id));
96 96
 			case Object_Type_Enum::USER:
97
-				return new Wordpress_Content( get_user_by( 'ID', $row->content_id ) );
97
+				return new Wordpress_Content(get_user_by('ID', $row->content_id));
98 98
 			default:
99 99
 				return null;
100 100
 		}
@@ -106,30 +106,30 @@  discard block
 block discarded – undo
106 106
 	 *
107 107
 	 * @return string|void|null
108 108
 	 */
109
-	function get_entity_id( $content_id ) {
109
+	function get_entity_id($content_id) {
110 110
 		$type = $content_id->get_type();
111 111
 		$id   = $content_id->get_id();
112 112
 
113
-		switch ( $type ) {
113
+		switch ($type) {
114 114
 			case Object_Type_Enum::POST:
115
-				$base_uri = get_permalink( $id );
115
+				$base_uri = get_permalink($id);
116 116
 				break;
117 117
 			case Object_Type_Enum::TERM:
118
-				$base_uri = get_term_link( $id );
118
+				$base_uri = get_term_link($id);
119 119
 				break;
120 120
 			case Object_Type_Enum::USER:
121
-				$base_uri = get_author_posts_url( $id );
121
+				$base_uri = get_author_posts_url($id);
122 122
 				break;
123 123
 			default:
124 124
 				return null;
125 125
 		}
126 126
 
127
-		$type_name = Object_Type_Enum::to_string( $type );
127
+		$type_name = Object_Type_Enum::to_string($type);
128 128
 
129 129
 		return "$base_uri#$type_name/$id";
130 130
 	}
131 131
 
132
-	function set_entity_id( $content_id, $uri ) {
132
+	function set_entity_id($content_id, $uri) {
133 133
 		// do nothing.
134 134
 	}
135 135
 
@@ -138,15 +138,15 @@  discard block
 block discarded – undo
138 138
 	 *
139 139
 	 * @return bool|void
140 140
 	 */
141
-	function supports( $content_id ) {
142
-		return in_array( $content_id->get_type(), array(
141
+	function supports($content_id) {
142
+		return in_array($content_id->get_type(), array(
143 143
 			Object_Type_Enum::POST,
144 144
 			Object_Type_Enum::TERM,
145 145
 			Object_Type_Enum::USER,
146
-		) );
146
+		));
147 147
 	}
148 148
 
149
-	function delete( $content_id ) {
149
+	function delete($content_id) {
150 150
 		// Ignore, we don't store any data.
151 151
 	}
152 152
 }
Please login to merge, or discard this patch.