Completed
Push — develop ( cb9160...2b8854 )
by Zack
09:36
created
includes/class-oembed.php 1 patch
Spacing   +40 added lines, -40 removed lines patch added patch discarded remove patch
@@ -35,7 +35,7 @@  discard block
 block discarded – undo
35 35
 		add_action( 'init', array( $this, 'register_handler' ) );
36 36
 		add_action( 'init', array( $this, 'add_provider' ) );
37 37
 
38
-		if ( ! empty( $_GET['gv_oembed_provider'] ) && ! empty( $_GET['url'] ) ) {
38
+		if ( ! empty( $_GET[ 'gv_oembed_provider' ] ) && ! empty( $_GET[ 'url' ] ) ) {
39 39
 			add_action( 'template_redirect', array( $this, 'render_provider_request' ) );
40 40
 		}
41 41
 	}
@@ -46,7 +46,7 @@  discard block
 block discarded – undo
46 46
 	 */
47 47
 	static function getInstance() {
48 48
 
49
-		if( empty( self::$instance ) ) {
49
+		if ( empty( self::$instance ) ) {
50 50
 			self::$instance = new self;
51 51
 
52 52
 			self::$instance->initialize();
@@ -90,8 +90,8 @@  discard block
 block discarded – undo
90 90
 	 * @return void
91 91
 	 */
92 92
 	function render_provider_request() {
93
-		if ( ! empty( $_GET['url'] ) ) {
94
-			$url = $_GET['url'];
93
+		if ( ! empty( $_GET[ 'url' ] ) ) {
94
+			$url = $_GET[ 'url' ];
95 95
 		} else {
96 96
 			header( 'HTTP/1.0 404 Not Found' );
97 97
 			exit;
@@ -100,16 +100,16 @@  discard block
 block discarded – undo
100 100
 		preg_match( $this->get_handler_regex(), $url, $matches );
101 101
 
102 102
 		// If not using permalinks, re-assign values for matching groups
103
-		if ( ! empty( $matches['entry_slug2'] ) ) {
104
-			$matches['is_cpt'] = $matches['is_cpt2'];
105
-			$matches['slug'] = $matches['slug2'];
106
-			$matches['entry_slug'] = $matches['entry_slug2'];
107
-			unset( $matches['is_cpt2'], $matches['slug2'], $matches['entry_slug2'] );
103
+		if ( ! empty( $matches[ 'entry_slug2' ] ) ) {
104
+			$matches[ 'is_cpt' ] = $matches[ 'is_cpt2' ];
105
+			$matches[ 'slug' ] = $matches[ 'slug2' ];
106
+			$matches[ 'entry_slug' ] = $matches[ 'entry_slug2' ];
107
+			unset( $matches[ 'is_cpt2' ], $matches[ 'slug2' ], $matches[ 'entry_slug2' ] );
108 108
 		}
109 109
 
110 110
 		// No Entry was found
111
-		if ( empty( $matches['entry_slug'] ) ) {
112
-			do_action('gravityview_log_error', 'GravityView_oEmbed[render_handler] $entry_slug not parsed by regex.', $matches );
111
+		if ( empty( $matches[ 'entry_slug' ] ) ) {
112
+			do_action( 'gravityview_log_error', 'GravityView_oEmbed[render_handler] $entry_slug not parsed by regex.', $matches );
113 113
 			header( 'HTTP/1.0 404 Not Found' );
114 114
 			exit;
115 115
 		}
@@ -162,7 +162,7 @@  discard block
 block discarded – undo
162 162
 		// Catch either
163 163
 		$match_regex = "(?:{$using_permalinks}|{$not_using_permalinks})";
164 164
 
165
-		return '#'.$match_regex.'#i';
165
+		return '#' . $match_regex . '#i';
166 166
 	}
167 167
 
168 168
 	/**
@@ -183,18 +183,18 @@  discard block
 block discarded – undo
183 183
 
184 184
 		$page_on_front = get_option( 'page_on_front' );
185 185
 
186
-		if( (int) $post_id === (int) $page_on_front || empty( $post_id ) ) {
186
+		if ( (int)$post_id === (int)$page_on_front || empty( $post_id ) ) {
187 187
 
188 188
 			$args = array(
189 189
 				'post_status' => 'publish',
190 190
 				'name' => $slug,
191
-				'post_type' => array('any', 'gravityview'),
191
+				'post_type' => array( 'any', 'gravityview' ),
192 192
 			);
193 193
 
194 194
 			$posts = get_posts( $args );
195 195
 
196
-			if( !empty( $posts ) ) {
197
-				$post_id = $posts[0]->ID;
196
+			if ( ! empty( $posts ) ) {
197
+				$post_id = $posts[ 0 ]->ID;
198 198
 			}
199 199
 		}
200 200
 
@@ -227,17 +227,17 @@  discard block
 block discarded – undo
227 227
 	public function render_handler( $matches, $attr, $url, $rawattr ) {
228 228
 
229 229
 		// If not using permalinks, re-assign values for matching groups
230
-		if( !empty( $matches['entry_slug2'] ) ) {
231
-			$matches['is_cpt'] = $matches['is_cpt2'];
232
-			$matches['slug'] = $matches['slug2'];
233
-			$matches['entry_slug'] = $matches['entry_slug2'];
234
-			unset( $matches['is_cpt2'], $matches['slug2'], $matches['entry_slug2'] );
230
+		if ( ! empty( $matches[ 'entry_slug2' ] ) ) {
231
+			$matches[ 'is_cpt' ] = $matches[ 'is_cpt2' ];
232
+			$matches[ 'slug' ] = $matches[ 'slug2' ];
233
+			$matches[ 'entry_slug' ] = $matches[ 'entry_slug2' ];
234
+			unset( $matches[ 'is_cpt2' ], $matches[ 'slug2' ], $matches[ 'entry_slug2' ] );
235 235
 		}
236 236
 
237 237
 		// No Entry was found
238
-		if( empty( $matches['entry_slug'] ) ) {
238
+		if ( empty( $matches[ 'entry_slug' ] ) ) {
239 239
 
240
-			do_action('gravityview_log_error', 'GravityView_oEmbed[render_handler] $entry_slug not parsed by regex.', $matches );
240
+			do_action( 'gravityview_log_error', 'GravityView_oEmbed[render_handler] $entry_slug not parsed by regex.', $matches );
241 241
 
242 242
 			return '';
243 243
 		}
@@ -247,11 +247,11 @@  discard block
 block discarded – undo
247 247
 		// Setup the data used
248 248
 		$this->set_vars( $matches, $attr, $url, $rawattr );
249 249
 
250
-		if( is_admin() && !$this->is_full_oembed_preview ) {
250
+		if ( is_admin() && ! $this->is_full_oembed_preview ) {
251 251
 			$return = $this->render_admin( $matches, $attr, $url, $rawattr );
252 252
 		} else {
253 253
 
254
-			if( $this->is_full_oembed_preview ) {
254
+			if ( $this->is_full_oembed_preview ) {
255 255
 				$return .= $this->generate_preview_notice();
256 256
 			}
257 257
 
@@ -270,8 +270,8 @@  discard block
 block discarded – undo
270 270
 	private function generate_preview_notice() {
271 271
 		$floaty = GravityView_Admin::get_floaty();
272 272
 		$title = esc_html__( 'This will look better when it is embedded.', 'gravityview' );
273
-		$message = esc_html__('Styles don\'t get loaded when being previewed, so the content below will look strange. Don\'t be concerned!', 'gravityview');
274
-		return '<div class="updated notice">'. $floaty. '<h3>'.$title.'</h3><p>'.$message.'</p><br style="clear:both;" /></div>';
273
+		$message = esc_html__( 'Styles don\'t get loaded when being previewed, so the content below will look strange. Don\'t be concerned!', 'gravityview' );
274
+		return '<div class="updated notice">' . $floaty . '<h3>' . $title . '</h3><p>' . $message . '</p><br style="clear:both;" /></div>';
275 275
 	}
276 276
 
277 277
 	/**
@@ -284,14 +284,14 @@  discard block
 block discarded – undo
284 284
 	 */
285 285
 	private function set_vars( $matches, $attr, $url, $rawattr ) {
286 286
 
287
-		$this->entry_id = $matches['entry_slug'];
287
+		$this->entry_id = $matches[ 'entry_slug' ];
288 288
 
289
-		$post_id = $this->get_postid_from_url_and_slug( $url, $matches['slug'] );
289
+		$post_id = $this->get_postid_from_url_and_slug( $url, $matches[ 'slug' ] );
290 290
 
291 291
 		// The URL didn't have the View Custom Post Type structure.
292
-		if( empty( $matches['is_cpt'] ) || $matches['is_cpt'] !== 'gravityview' ) {
292
+		if ( empty( $matches[ 'is_cpt' ] ) || $matches[ 'is_cpt' ] !== 'gravityview' ) {
293 293
 
294
-			do_action('gravityview_log_debug', 'GravityView_oEmbed[render_handler] Embedding an entry inside a post or page', $matches );
294
+			do_action( 'gravityview_log_debug', 'GravityView_oEmbed[render_handler] Embedding an entry inside a post or page', $matches );
295 295
 
296 296
 			if ( defined( 'GRAVITYVIEW_FUTURE_CORE_LOADED' ) && $post = get_post( $post_id ) ) {
297 297
 				$views = \GV\View_Collection::from_post( $post );
@@ -304,7 +304,7 @@  discard block
 block discarded – undo
304 304
 						}
305 305
 					}
306 306
 
307
-					$this->view_id = $views[0]->ID;
307
+					$this->view_id = $views[ 0 ]->ID;
308 308
 				}
309 309
 			} else {
310 310
 				/** Deprecated. */
@@ -318,7 +318,7 @@  discard block
 block discarded – undo
318 318
 		}
319 319
 
320 320
 		// The inline content has $_POST['type'] set to "embed", while the "Add Media" modal doesn't set that.
321
-		$this->is_full_oembed_preview = ( isset( $_POST['action'] ) && $_POST['action'] === 'parse-embed' && !isset( $_POST['type'] ) );
321
+		$this->is_full_oembed_preview = ( isset( $_POST[ 'action' ] ) && $_POST[ 'action' ] === 'parse-embed' && ! isset( $_POST[ 'type' ] ) );
322 322
 	}
323 323
 
324 324
 	/**
@@ -336,15 +336,15 @@  discard block
 block discarded – undo
336 336
 		// Floaty the astronaut
337 337
 		$image = GravityView_Admin::get_floaty();
338 338
 
339
-		$embed_heading = sprintf( esc_html__('Embed Entry %d', 'gravityview'), $this->entry_id );
339
+		$embed_heading = sprintf( esc_html__( 'Embed Entry %d', 'gravityview' ), $this->entry_id );
340 340
 
341
-		$embed_text = sprintf( esc_html__('This entry will be displayed as it is configured in View %d', 'gravityview'), $this->view_id );
341
+		$embed_text = sprintf( esc_html__( 'This entry will be displayed as it is configured in View %d', 'gravityview' ), $this->view_id );
342 342
 
343 343
 		return '
344 344
 		<div class="loading-placeholder" style="background-color:#e6f0f5;">
345
-			<h3 style="margin:0; padding:0; font-family: -apple-system, BlinkMacSystemFont, \'Segoe UI\', Roboto, Oxygen-Sans, Ubuntu, Cantarell, \'Helvetica Neue\', sans-serif;">'.$image.$embed_heading.'</h3>
345
+			<h3 style="margin:0; padding:0; font-family: -apple-system, BlinkMacSystemFont, \'Segoe UI\', Roboto, Oxygen-Sans, Ubuntu, Cantarell, \'Helvetica Neue\', sans-serif;">'.$image . $embed_heading . '</h3>
346 346
 			<p style="margin:0; padding:0; font-family: -apple-system, BlinkMacSystemFont, \'Segoe UI\', Roboto, Oxygen-Sans, Ubuntu, Cantarell, \'Helvetica Neue\', sans-serif;">
347
-				'.$embed_text.'
347
+				'.$embed_text . '
348 348
 			</p>
349 349
 			<br style="clear: both;">
350 350
 		</div>';
@@ -399,14 +399,14 @@  discard block
 block discarded – undo
399 399
 	private function render_frontend( $matches, $attr, $url, $rawattr ) {
400 400
 
401 401
 		// If it's already been parsed, don't re-output it.
402
-		if( !empty( $this->output[ $this->entry_id ] ) ) {
402
+		if ( ! empty( $this->output[ $this->entry_id ] ) ) {
403 403
 			return $this->output[ $this->entry_id ];
404 404
 		}
405 405
 
406 406
 		$entry_output = $this->generate_entry_output();
407 407
 
408 408
 		// Wrap a container div around the output to allow for custom styling
409
-		$output = sprintf('<div class="gravityview-oembed gravityview-oembed-entry gravityview-oembed-entry-'.$this->entry_id.'">%s</div>', $entry_output );
409
+		$output = sprintf( '<div class="gravityview-oembed gravityview-oembed-entry gravityview-oembed-entry-' . $this->entry_id . '">%s</div>', $entry_output );
410 410
 
411 411
 		/**
412 412
 		 * @filter `gravityview/oembed/entry` Filter the output of the oEmbed entry embed
@@ -419,7 +419,7 @@  discard block
 block discarded – undo
419 419
 		 *  @var string $url The original URL that was matched by the regex. \n
420 420
 		 *  @var array $rawattr The original unmodified attributes.
421 421
 		 */
422
-		$output = apply_filters('gravityview/oembed/entry', $output, $this, compact( $entry_output, $matches, $attr, $url, $rawattr ) );
422
+		$output = apply_filters( 'gravityview/oembed/entry', $output, $this, compact( $entry_output, $matches, $attr, $url, $rawattr ) );
423 423
 
424 424
 		unset( $entry_output );
425 425
 
Please login to merge, or discard this patch.