Completed
Pull Request — master (#836)
by Zack
06:36 queued 03:13
created
includes/class-oembed.php 2 patches
Spacing   +30 added lines, -30 removed lines patch added patch discarded remove patch
@@ -42,7 +42,7 @@  discard block
 block discarded – undo
42 42
 	 */
43 43
 	static function getInstance() {
44 44
 
45
-		if( empty( self::$instance ) ) {
45
+		if ( empty( self::$instance ) ) {
46 46
 			self::$instance = new self;
47 47
 
48 48
 			self::$instance->initialize();
@@ -99,7 +99,7 @@  discard block
 block discarded – undo
99 99
 		// Catch either
100 100
 		$match_regex = "(?:{$using_permalinks}|{$not_using_permalinks})";
101 101
 
102
-		return '#'.$match_regex.'#i';
102
+		return '#' . $match_regex . '#i';
103 103
 	}
104 104
 
105 105
 	/**
@@ -118,18 +118,18 @@  discard block
 block discarded – undo
118 118
 
119 119
 		$post_id = url_to_postid( $url );
120 120
 
121
-		if( empty( $post_id ) ) {
121
+		if ( empty( $post_id ) ) {
122 122
 
123 123
 			$args = array(
124 124
 				'post_status' => 'publish',
125 125
 				'name' => $slug,
126
-				'post_type' => array('any', 'gravityview'),
126
+				'post_type' => array( 'any', 'gravityview' ),
127 127
 			);
128 128
 
129 129
 			$posts = get_posts( $args );
130 130
 
131
-			if( !empty( $posts ) ) {
132
-				$post_id = $posts[0]->ID;
131
+			if ( ! empty( $posts ) ) {
132
+				$post_id = $posts[ 0 ]->ID;
133 133
 			}
134 134
 		}
135 135
 
@@ -162,17 +162,17 @@  discard block
 block discarded – undo
162 162
 	public function render_handler( $matches, $attr, $url, $rawattr ) {
163 163
 
164 164
 		// If not using permalinks, re-assign values for matching groups
165
-		if( !empty( $matches['entry_slug2'] ) ) {
166
-			$matches['is_cpt'] = $matches['is_cpt2'];
167
-			$matches['slug'] = $matches['slug2'];
168
-			$matches['entry_slug'] = $matches['entry_slug2'];
169
-			unset( $matches['is_cpt2'], $matches['slug2'], $matches['entry_slug2'] );
165
+		if ( ! empty( $matches[ 'entry_slug2' ] ) ) {
166
+			$matches[ 'is_cpt' ] = $matches[ 'is_cpt2' ];
167
+			$matches[ 'slug' ] = $matches[ 'slug2' ];
168
+			$matches[ 'entry_slug' ] = $matches[ 'entry_slug2' ];
169
+			unset( $matches[ 'is_cpt2' ], $matches[ 'slug2' ], $matches[ 'entry_slug2' ] );
170 170
 		}
171 171
 
172 172
 		// No Entry was found
173
-		if( empty( $matches['entry_slug'] ) ) {
173
+		if ( empty( $matches[ 'entry_slug' ] ) ) {
174 174
 
175
-			do_action('gravityview_log_error', 'GravityView_oEmbed[render_handler] $entry_slug not parsed by regex.', $matches );
175
+			do_action( 'gravityview_log_error', 'GravityView_oEmbed[render_handler] $entry_slug not parsed by regex.', $matches );
176 176
 
177 177
 			return '';
178 178
 		}
@@ -182,11 +182,11 @@  discard block
 block discarded – undo
182 182
 		// Setup the data used
183 183
 		$this->set_vars( $matches, $attr, $url, $rawattr );
184 184
 
185
-		if( is_admin() && !$this->is_full_oembed_preview ) {
185
+		if ( is_admin() && ! $this->is_full_oembed_preview ) {
186 186
 			$return = $this->render_admin( $matches, $attr, $url, $rawattr );
187 187
 		} else {
188 188
 
189
-			if( $this->is_full_oembed_preview ) {
189
+			if ( $this->is_full_oembed_preview ) {
190 190
 				$return .= $this->generate_preview_notice();
191 191
 			}
192 192
 
@@ -205,8 +205,8 @@  discard block
 block discarded – undo
205 205
 	private function generate_preview_notice() {
206 206
 		$floaty = GravityView_Admin::get_floaty();
207 207
 		$title = esc_html__( 'This will look better when it is embedded.', 'gravityview' );
208
-		$message = esc_html__('Styles don\'t get loaded when being previewed, so the content below will look strange. Don\'t be concerned!', 'gravityview');
209
-		return '<div class="updated notice">'. $floaty. '<h3>'.$title.'</h3><p>'.$message.'</p><br style="clear:both;" /></div>';
208
+		$message = esc_html__( 'Styles don\'t get loaded when being previewed, so the content below will look strange. Don\'t be concerned!', 'gravityview' );
209
+		return '<div class="updated notice">' . $floaty . '<h3>' . $title . '</h3><p>' . $message . '</p><br style="clear:both;" /></div>';
210 210
 	}
211 211
 
212 212
 	/**
@@ -219,20 +219,20 @@  discard block
 block discarded – undo
219 219
 	 */
220 220
 	private function set_vars( $matches, $attr, $url, $rawattr ) {
221 221
 
222
-		$this->entry_id = $matches['entry_slug'];
222
+		$this->entry_id = $matches[ 'entry_slug' ];
223 223
 
224
-		$post_id = $this->get_postid_from_url_and_slug( $url, $matches['slug'] );
224
+		$post_id = $this->get_postid_from_url_and_slug( $url, $matches[ 'slug' ] );
225 225
 
226 226
 		// The URL didn't have the View Custom Post Type structure.
227
-		if( empty( $matches['is_cpt'] ) || $matches['is_cpt'] !== 'gravityview' ) {
227
+		if ( empty( $matches[ 'is_cpt' ] ) || $matches[ 'is_cpt' ] !== 'gravityview' ) {
228 228
 
229
-			do_action('gravityview_log_debug', 'GravityView_oEmbed[render_handler] Embedding an entry inside a post or page', $matches );
229
+			do_action( 'gravityview_log_debug', 'GravityView_oEmbed[render_handler] Embedding an entry inside a post or page', $matches );
230 230
 
231 231
 			if ( function_exists( 'gravityview' ) && $post = get_post( $post_id ) ) {
232 232
 				$views = \GV\View_Collection::from_post( $post );
233 233
 				$views = $views->all();
234 234
 				if ( ! empty( $views ) )
235
-					$this->view_id = $views[0]->ID;
235
+					$this->view_id = $views[ 0 ]->ID;
236 236
 			} else {
237 237
 				/** Deprecated. */
238 238
 				$this->view_id = GravityView_View_Data::getInstance()->maybe_get_view_id( $post_id );
@@ -245,7 +245,7 @@  discard block
 block discarded – undo
245 245
 		}
246 246
 
247 247
 		// The inline content has $_POST['type'] set to "embed", while the "Add Media" modal doesn't set that.
248
-		$this->is_full_oembed_preview = ( isset( $_POST['action'] ) && $_POST['action'] === 'parse-embed' && !isset( $_POST['type'] ) );
248
+		$this->is_full_oembed_preview = ( isset( $_POST[ 'action' ] ) && $_POST[ 'action' ] === 'parse-embed' && ! isset( $_POST[ 'type' ] ) );
249 249
 	}
250 250
 
251 251
 	/**
@@ -263,15 +263,15 @@  discard block
 block discarded – undo
263 263
 		// Floaty the astronaut
264 264
 		$image = GravityView_Admin::get_floaty();
265 265
 
266
-		$embed_heading = sprintf( esc_html__('Embed Entry %d', 'gravityview'), $this->entry_id );
266
+		$embed_heading = sprintf( esc_html__( 'Embed Entry %d', 'gravityview' ), $this->entry_id );
267 267
 
268
-		$embed_text = sprintf( esc_html__('This entry will be displayed as it is configured in View %d', 'gravityview'), $this->view_id );
268
+		$embed_text = sprintf( esc_html__( 'This entry will be displayed as it is configured in View %d', 'gravityview' ), $this->view_id );
269 269
 
270 270
 		return '
271 271
 		<div class="loading-placeholder" style="background-color:#e6f0f5;">
272
-			<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>
272
+			<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>
273 273
 			<p style="margin:0; padding:0; font-family: -apple-system, BlinkMacSystemFont, \'Segoe UI\', Roboto, Oxygen-Sans, Ubuntu, Cantarell, \'Helvetica Neue\', sans-serif;">
274
-				'.$embed_text.'
274
+				'.$embed_text . '
275 275
 			</p>
276 276
 			<br style="clear: both;">
277 277
 		</div>';
@@ -326,14 +326,14 @@  discard block
 block discarded – undo
326 326
 	private function render_frontend( $matches, $attr, $url, $rawattr ) {
327 327
 
328 328
 		// If it's already been parsed, don't re-output it.
329
-		if( !empty( $this->output[ $this->entry_id ] ) ) {
329
+		if ( ! empty( $this->output[ $this->entry_id ] ) ) {
330 330
 			return $this->output[ $this->entry_id ];
331 331
 		}
332 332
 
333 333
 		$entry_output = $this->generate_entry_output();
334 334
 
335 335
 		// Wrap a container div around the output to allow for custom styling
336
-		$output = sprintf('<div class="gravityview-oembed gravityview-oembed-entry gravityview-oembed-entry-'.$this->entry_id.'">%s</div>', $entry_output );
336
+		$output = sprintf( '<div class="gravityview-oembed gravityview-oembed-entry gravityview-oembed-entry-' . $this->entry_id . '">%s</div>', $entry_output );
337 337
 
338 338
 		/**
339 339
 		 * @filter `gravityview/oembed/entry` Filter the output of the oEmbed entry embed
@@ -346,7 +346,7 @@  discard block
 block discarded – undo
346 346
 		 *  @var string $url The original URL that was matched by the regex. \n
347 347
 		 *  @var array $rawattr The original unmodified attributes.
348 348
 		 */
349
-		$output = apply_filters('gravityview/oembed/entry', $output, $this, compact( $entry_output, $matches, $attr, $url, $rawattr ) );
349
+		$output = apply_filters( 'gravityview/oembed/entry', $output, $this, compact( $entry_output, $matches, $attr, $url, $rawattr ) );
350 350
 
351 351
 		unset( $entry_output );
352 352
 
Please login to merge, or discard this patch.
Braces   +3 added lines, -2 removed lines patch added patch discarded remove patch
@@ -231,8 +231,9 @@
 block discarded – undo
231 231
 			if ( function_exists( 'gravityview' ) && $post = get_post( $post_id ) ) {
232 232
 				$views = \GV\View_Collection::from_post( $post );
233 233
 				$views = $views->all();
234
-				if ( ! empty( $views ) )
235
-					$this->view_id = $views[0]->ID;
234
+				if ( ! empty( $views ) ) {
235
+									$this->view_id = $views[0]->ID;
236
+				}
236 237
 			} else {
237 238
 				/** Deprecated. */
238 239
 				$this->view_id = GravityView_View_Data::getInstance()->maybe_get_view_id( $post_id );
Please login to merge, or discard this patch.