| 1 |  |  | <?php | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  |  * GravityView oEmbed handling | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  |  * @package   GravityView | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  |  * @license   GPL2+ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  |  * @author    Katz Web Services, Inc. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  |  * @link      http://gravityview.co | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  |  * @copyright Copyright 2014, Katz Web Services, Inc. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |  * @since 1.6 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  | if ( ! defined( 'ABSPATH' ) ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  | 	die; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  | } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |  * Register oEmbed handlers for embedding GravityView data and render that data | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |  * @since 1.6 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  | class GravityView_oEmbed { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  | 	protected $output = array(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  | 	protected $entry_id = NULL; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  | 	protected $view_id = NULL; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  | 	protected $is_full_oembed_preview = false; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  | 	static $instance = NULL; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                            
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  | 	private function __construct() {} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  | 	private function initialize() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  | 		add_action( 'init', array( $this, 'register_handler' ) ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  | 	 * @return GravityView_oEmbed | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  | 	 * @since 1.6 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  | 	static function getInstance() { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                            
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  | 		if( empty( self::$instance ) ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  | 			self::$instance = new self; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  | 			self::$instance->initialize(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  | 		return self::$instance; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  | 	 * Register the oEmbed handler | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  | 	 * @since 1.6 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  | 	 * @uses get_handler_regex | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  | 	function register_handler() { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  | 		wp_embed_register_handler( 'gravityview_entry', $this->get_handler_regex(), array( $this, 'render_handler' ), 20000 ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  | 	 * Generate the Regular expression that matches embedded entries. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  | 	 * Generates different regex if using permalinks and if not using permalinks | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  | 	 * @since 1.6 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  | 	 * @return string Regex code | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  | 	private function get_handler_regex() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  | 		if ( defined( 'GRAVITYVIEW_FUTURE_CORE_LOADED' ) ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  | 			$entry_var_name = \GV\Entry::get_endpoint_name(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  | 		} else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  | 			/** Deprecated. Use \GV\Entry::get_endpoint_name instead. */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  | 			$entry_var_name = GravityView_Post_Types::get_entry_var_name(); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  | 		/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  | 		 * @filter `gravityview_slug` Modify the url part for a View. [Read the doc](http://docs.gravityview.co/article/62-changing-the-view-slug) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  | 		 * @param string $rewrite_slug The slug shown in the URL | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  | 		 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  | 		$rewrite_slug = apply_filters( 'gravityview_slug', 'view' ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  | 		// Only support embeds for current site | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 |  |  | 		$prefix = trailingslashit( home_url() ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 |  |  | 		// Using permalinks | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 |  |  | 		$using_permalinks = $prefix . "(?P<is_cpt>{$rewrite_slug})?/?(?P<slug>.+?)/{$entry_var_name}/(?P<entry_slug>.+?)/?\$"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 95 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 96 |  |  | 		// Not using permalinks | 
            
                                                                                                            
                            
            
                                    
            
            
                | 97 |  |  | 		$not_using_permalinks = $prefix . "(?:index.php)?\?(?P<is_cpt2>[^=]+)=(?P<slug2>[^&]+)&entry=(?P<entry_slug2>[^&]+)\$"; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 98 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 99 |  |  | 		// Catch either | 
            
                                                                                                            
                            
            
                                    
            
            
                | 100 |  |  | 		$match_regex = "(?:{$using_permalinks}|{$not_using_permalinks})"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 101 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 102 |  |  | 		return '#'.$match_regex.'#i'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 103 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 104 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 105 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 106 |  |  | 	 * Get the post ID from an URL | 
            
                                                                                                            
                            
            
                                    
            
            
                | 107 |  |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 108 |  |  | 	 * This is necessary because url_to_postid() doesn't work with permalinks off for custom post types | 
            
                                                                                                            
                            
            
                                    
            
            
                | 109 |  |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 110 |  |  | 	 * @uses url_to_postid() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 111 |  |  | 	 * @since 1.6 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 112 |  |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 113 |  |  | 	 * @param string $url URL to get the post ID from | 
            
                                                                                                            
                            
            
                                    
            
            
                | 114 |  |  | 	 * @param string $slug The name of a post, used as backup way of checking for post ID | 
            
                                                                                                            
                            
            
                                    
            
            
                | 115 |  |  | 	 * @return int 0 if not found; int of URL post ID otherwise | 
            
                                                                                                            
                            
            
                                    
            
            
                | 116 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 117 |  |  | 	private function get_postid_from_url_and_slug( $url = '', $slug = '' ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 118 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 119 |  |  | 		$post_id = url_to_postid( $url ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 120 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 121 |  |  | 		if( empty( $post_id ) ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 122 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 123 |  |  | 			$args = array( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 124 |  |  | 				'post_status' => 'publish', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 125 |  |  | 				'name' => $slug, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 126 |  |  | 				'post_type' => array('any', 'gravityview'), | 
                            
                    |  |  |  | 
                                                                                        
                                                                                            
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 127 |  |  | 			); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 128 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 129 |  |  | 			$posts = get_posts( $args ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 130 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 131 |  |  | 			if( !empty( $posts ) ) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 132 |  |  | 				$post_id = $posts[0]->ID; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 133 |  |  | 			} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 134 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 135 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 136 |  |  | 		return $post_id; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 137 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 138 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 139 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 140 |  |  | 	 * Get the entry id for the current oEmbedded entry | 
            
                                                                                                            
                            
            
                                    
            
            
                | 141 |  |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 142 |  |  | 	 * @since 1.6 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 143 |  |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 144 |  |  | 	 * @return int|null | 
            
                                                                                                            
                            
            
                                    
            
            
                | 145 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 146 |  |  | 	public function get_entry_id() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 147 |  |  | 		return $this->entry_id; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 148 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 149 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 150 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 151 |  |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 152 |  |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 153 |  |  | 	 * @since 1.6 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 154 |  |  | 	 * @see GravityView_oEmbed::add_providers() for the regex | 
            
                                                                                                            
                            
            
                                    
            
            
                | 155 |  |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 156 |  |  | 	 * @param array $matches The regex matches from the provided regex when calling wp_embed_register_handler() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 157 |  |  | 	 * @param array $attr Embed attributes. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 158 |  |  | 	 * @param string $url The original URL that was matched by the regex. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 159 |  |  | 	 * @param array $rawattr The original unmodified attributes. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 160 |  |  | 	 * @return string The embed HTML. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 161 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 162 |  |  | 	public function render_handler( $matches, $attr, $url, $rawattr ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 163 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 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'] ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 170 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 171 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 172 |  |  | 		// No Entry was found | 
            
                                                                                                            
                            
            
                                    
            
            
                | 173 |  |  | 		if( empty( $matches['entry_slug'] ) ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 174 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 175 |  |  | 			do_action('gravityview_log_error', 'GravityView_oEmbed[render_handler] $entry_slug not parsed by regex.', $matches ); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 176 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 177 |  |  | 			return ''; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 178 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 179 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 180 |  |  | 		$return = ''; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 181 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 182 |  |  | 		// Setup the data used | 
            
                                                                                                            
                            
            
                                    
            
            
                | 183 |  |  | 		$this->set_vars( $matches, $attr, $url, $rawattr ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 184 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 185 |  |  | 		if( is_admin() && !$this->is_full_oembed_preview ) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 186 |  |  | 			$return = $this->render_admin( $matches, $attr, $url, $rawattr ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 187 |  |  | 		} else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 188 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 189 |  |  | 			if( $this->is_full_oembed_preview ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 190 |  |  | 				$return .= $this->generate_preview_notice(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 191 |  |  | 			} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 192 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 193 |  |  | 			$return .= $this->render_frontend( $matches, $attr, $url, $rawattr ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 194 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 195 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 196 |  |  | 		return $return; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 197 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 198 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 199 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 200 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 201 |  |  | 	 * Generate a warning to users when previewing oEmbed in the Add Media modal | 
            
                                                                                                            
                            
            
                                    
            
            
                | 202 |  |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 203 |  |  | 	 * @return string HTML notice | 
            
                                                                                                            
                            
            
                                    
            
            
                | 204 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 205 |  |  | 	private function generate_preview_notice() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 206 |  |  | 		$floaty = GravityView_Admin::get_floaty(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 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>'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 210 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 211 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 212 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 213 |  |  | 	 * Set entry_id and view_id from the data sent to render_handler | 
            
                                                                                                            
                            
            
                                    
            
            
                | 214 |  |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 215 |  |  | 	 * @var $entry_id | 
            
                                                                                                            
                            
            
                                    
            
            
                | 216 |  |  | 	 * @var $view_id | 
            
                                                                                                            
                            
            
                                    
            
            
                | 217 |  |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 218 |  |  | 	 * @see render_handler | 
            
                                                                                                            
                            
            
                                    
            
            
                | 219 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 220 | 1 |  | 	private function set_vars( $matches, $attr, $url, $rawattr ) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                            
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 221 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 222 | 1 |  | 		$this->entry_id = $matches['entry_slug']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 223 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 224 | 1 |  | 		$post_id = $this->get_postid_from_url_and_slug( $url, $matches['slug'] ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 225 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 226 |  |  | 		// The URL didn't have the View Custom Post Type structure. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 227 | 1 |  | 		if( empty( $matches['is_cpt'] ) || $matches['is_cpt'] !== 'gravityview' ) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 228 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 229 | 1 |  | 			do_action('gravityview_log_debug', 'GravityView_oEmbed[render_handler] Embedding an entry inside a post or page', $matches ); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 230 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 231 | 1 |  | 			if ( defined( 'GRAVITYVIEW_FUTURE_CORE_LOADED' ) && $post = get_post( $post_id ) ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 232 | 1 |  | 				$views = \GV\View_Collection::from_post( $post ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 233 | 1 |  | 				$views = $views->all(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 234 | 1 |  | 				if ( ! empty( $views ) ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 235 |  |  | 					/** maybe_get_view_id has a side-effect that adds retrieved views to the global scope */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 236 | 1 |  | 					foreach ( $views as $view ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 237 | 1 |  | 						if ( \GV\View::exists( $view->ID ) && ! gravityview()->views->contains( $view->ID ) ) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 238 | 1 |  | 							gravityview()->views->add( $view ); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 239 |  |  | 						} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 240 |  |  | 					} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 241 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 242 | 1 |  | 					$this->view_id = $views[0]->ID; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 243 |  |  | 				} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 244 |  |  | 			} else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 245 |  |  | 				/** Deprecated. */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 246 | 1 |  | 				$this->view_id = GravityView_View_Data::getInstance()->maybe_get_view_id( $post_id ); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 247 |  |  | 			} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 248 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 249 |  |  | 		} else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 250 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 251 |  |  | 			$this->view_id = $post_id; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 252 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 253 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 254 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 255 |  |  | 		// The inline content has $_POST['type'] set to "embed", while the "Add Media" modal doesn't set that. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 256 | 1 |  | 		$this->is_full_oembed_preview = ( isset( $_POST['action'] ) && $_POST['action'] === 'parse-embed' && !isset( $_POST['type'] ) ); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                            
                                                                                            
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 257 | 1 |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 258 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 259 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 260 |  |  | 	 * Display a nice placeholder in the admin for the entry | 
            
                                                                                                            
                            
            
                                    
            
            
                | 261 |  |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 262 |  |  | 	 * @param array $matches The regex matches from the provided regex when calling wp_embed_register_handler() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 263 |  |  | 	 * @param array $attr Embed attributes. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 264 |  |  | 	 * @param string $url The original URL that was matched by the regex. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 265 |  |  | 	 * @param array $rawattr The original unmodified attributes. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 266 |  |  | 	 * @return string The embed HTML. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 267 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 268 |  |  | 	private function render_admin( $matches, $attr, $url, $rawattr ) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                            
                                                                                            
                                                                                            
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 269 |  |  | 		global $wp_version; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 270 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 271 |  |  | 		// Floaty the astronaut | 
            
                                                                                                            
                            
            
                                    
            
            
                | 272 |  |  | 		$image = GravityView_Admin::get_floaty(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 273 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 274 |  |  | 		$embed_heading = sprintf( esc_html__('Embed Entry %d', 'gravityview'), $this->entry_id ); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                            
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 275 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 276 |  |  | 		$embed_text = sprintf( esc_html__('This entry will be displayed as it is configured in View %d', 'gravityview'), $this->view_id ); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                            
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 277 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 278 |  |  | 		return ' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 279 |  |  | 		<div class="loading-placeholder" style="background-color:#e6f0f5;"> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 280 |  |  | 			<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> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 281 |  |  | 			<p style="margin:0; padding:0; font-family: -apple-system, BlinkMacSystemFont, \'Segoe UI\', Roboto, Oxygen-Sans, Ubuntu, Cantarell, \'Helvetica Neue\', sans-serif;"> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 282 |  |  | 				'.$embed_text.' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 283 |  |  | 			</p> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 284 |  |  | 			<br style="clear: both;"> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 285 |  |  | 		</div>'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 286 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 287 |  |  | 	} | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 288 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 289 |  |  | 	private function generate_entry_output() { | 
            
                                                                        
                            
            
                                    
            
            
                | 290 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 291 |  |  | 		// Tell get_gravityview() to display a single entry | 
            
                                                                        
                            
            
                                    
            
            
                | 292 |  |  | 		add_filter( 'gravityview/is_single_entry', array( $this, 'set_single_entry_id' ) ); | 
            
                                                                        
                            
            
                                    
            
            
                | 293 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 294 |  |  | 		ob_start(); | 
            
                                                                        
                            
            
                                    
            
            
                | 295 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 296 |  |  | 		// Print the entry as configured in View | 
            
                                                                        
                            
            
                                    
            
            
                | 297 |  |  | 		the_gravityview( $this->view_id ); | 
            
                                                                        
                            
            
                                    
            
            
                | 298 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 299 |  |  | 		$view_html = ob_get_clean(); | 
            
                                                                        
                            
            
                                    
            
            
                | 300 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 301 |  |  | 		// Clean up the filter | 
            
                                                                        
                            
            
                                    
            
            
                | 302 |  |  | 		remove_filter( 'gravityview/is_single_entry', array( $this, 'set_single_entry_id' ) ); | 
            
                                                                        
                            
            
                                    
            
            
                | 303 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 304 |  |  | 		// Strip the new lines that are generated--when editing an entry in particular, scripts are printed that | 
            
                                                                        
                            
            
                                    
            
            
                | 305 |  |  | 		// then are passed through wpautop() and everything looks terrible. | 
            
                                                                        
                            
            
                                    
            
            
                | 306 |  |  | 		$view_html = str_replace( "\n", ' ', $view_html ); | 
            
                                                                        
                            
            
                                    
            
            
                | 307 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 308 |  |  | 		return $view_html; | 
            
                                                                        
                            
            
                                    
            
            
                | 309 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 310 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 311 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 312 |  |  | 	 * Tell get_gravityview() to display a single entry | 
            
                                                                                                            
                            
            
                                    
            
            
                | 313 |  |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 314 |  |  | 	 * REQUIRED FOR THE VIEW TO OUTPUT A SINGLE ENTRY | 
            
                                                                                                            
                            
            
                                    
            
            
                | 315 |  |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 316 |  |  | 	 * @param bool|int $is_single_entry Existing single entry. False, because GV thinks we're in a post or page. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 317 |  |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 318 |  |  | 	 * @return int The current entry ID | 
            
                                                                                                            
                            
            
                                    
            
            
                | 319 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 320 |  |  | 	public function set_single_entry_id( $is_single_entry = false ) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 321 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 322 |  |  | 		return $this->entry_id; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 323 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 324 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 325 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 326 |  |  | 	 * GravityView embed entry handler | 
            
                                                                                                            
                            
            
                                    
            
            
                | 327 |  |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 328 |  |  | 	 * @param array $matches The regex matches from the provided regex when calling {@link wp_embed_register_handler()}. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 329 |  |  | 	 * @param array $attr Embed attributes. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 330 |  |  | 	 * @param string $url The original URL that was matched by the regex. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 331 |  |  | 	 * @param array $rawattr The original unmodified attributes. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 332 |  |  | 	 * @return string The embed HTML. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 333 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 334 |  |  | 	private function render_frontend( $matches, $attr, $url, $rawattr ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 335 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 336 |  |  | 		// If it's already been parsed, don't re-output it. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 337 |  |  | 		if( !empty( $this->output[ $this->entry_id ] ) ) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 338 |  |  | 			return $this->output[ $this->entry_id ]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 339 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 340 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 341 |  |  | 		$entry_output = $this->generate_entry_output(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 342 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 343 |  |  | 		// Wrap a container div around the output to allow for custom styling | 
            
                                                                                                            
                            
            
                                    
            
            
                | 344 |  |  | 		$output = sprintf('<div class="gravityview-oembed gravityview-oembed-entry gravityview-oembed-entry-'.$this->entry_id.'">%s</div>', $entry_output ); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 345 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 346 |  |  | 		/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 347 |  |  | 		 * @filter `gravityview/oembed/entry` Filter the output of the oEmbed entry embed | 
            
                                                                                                            
                            
            
                                    
            
            
                | 348 |  |  | 		 * @param string $output HTML of the embedded entry, with wrapper div | 
            
                                                                                                            
                            
            
                                    
            
            
                | 349 |  |  | 		 * @param GravityView_oEmbed $object The current GravityView_oEmbed instance | 
            
                                                                                                            
                            
            
                                    
            
            
                | 350 |  |  | 		 * @param array $atts Other passed parameters and info. \n | 
            
                                                                                                            
                            
            
                                    
            
            
                | 351 |  |  | 		 *  @var string $entry_output HTML of just the View output, without the wrapper \n | 
            
                                                                                                            
                            
            
                                    
            
            
                | 352 |  |  | 		 *  @var array  $matches Capture group matches from the regex \n | 
            
                                                                                                            
                            
            
                                    
            
            
                | 353 |  |  | 		 *  @var array $attr Embed attributes. \n | 
            
                                                                                                            
                            
            
                                    
            
            
                | 354 |  |  | 		 *  @var string $url The original URL that was matched by the regex. \n | 
            
                                                                                                            
                            
            
                                    
            
            
                | 355 |  |  | 		 *  @var array $rawattr The original unmodified attributes. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 356 |  |  | 		 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 357 |  |  | 		$output = apply_filters('gravityview/oembed/entry', $output, $this, compact( $entry_output, $matches, $attr, $url, $rawattr ) ); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 358 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 359 |  |  | 		unset( $entry_output ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 360 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 361 |  |  | 		$this->output[ $this->entry_id ] = $output; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 362 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 363 |  |  | 		return $this->output[ $this->entry_id ]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 364 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 365 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 366 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 367 |  |  | } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 368 |  |  |  | 
            
                                                        
            
                                    
            
            
                | 369 |  |  | GravityView_oEmbed::getInstance(); | 
            
                        
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.