5 if ( ! defined(
'GRAVITYVIEW_DIR' ) ) {
13 public static $provider_url =
'';
23 public static function init() {
24 self::$provider_url = add_query_arg(
'gv_oembed_provider',
'1', site_url() );
26 wp_embed_register_handler(
'gravityview_entry', self::get_entry_regex(), array( __CLASS__,
'render' ), 20000 );
27 wp_oembed_add_provider( self::get_entry_regex(), self::$provider_url,
true );
29 if ( ! empty( $_GET[
'gv_oembed_provider'] ) && ! empty( $_GET[
'url'] ) ) {
30 add_action(
'template_redirect', array( __CLASS__,
'render_provider_request' ) );
33 add_action(
'pre_oembed_result', array( __CLASS__,
'pre_oembed_result' ), 11, 3 );
46 if ( ! empty( $_GET[
'url'] ) ) {
49 header(
'HTTP/1.0 404 Not Found' );
54 preg_match( self::get_entry_regex(),
$url, $matches );
55 $result = self::parse_matches( $matches,
$url );
56 if ( ! $result || count( $result ) != 2 ) {
57 header(
'HTTP/1.0 404 Not Found' );
61 list( $view,
$entry ) = $result;
63 echo json_encode( array(
65 'provider_name' =>
'gravityview',
66 'provider_url' => self::$provider_url,
67 'html' => self::render_preview_notice() . self::render_frontend( $view,
$entry ),
82 public static function render( $matches, $attr,
$url, $rawattr ) {
84 $result = self::parse_matches( $matches,
$url );
86 if ( ! $result || count( $result ) != 2 ) {
87 gravityview()->log->notice(
'View or entry could not be parsed in oEmbed url {url}', array(
'url' =>
$url,
'matches' => $matches ) );
88 return __(
'You are not allowed to view this content.',
'gk-gravityview' );
91 list( $view,
$entry ) = $result;
93 if ( Request::is_ajax() && ! Request::is_add_oembed_preview() ) {
95 return self::render_admin( $view,
$entry );
96 }
else if ( Request::is_add_oembed_preview() ) {
98 return self::render_preview_notice() . self::render_frontend( $view,
$entry );
101 return self::render_frontend( $view,
$entry );
114 if ( ! empty( $matches[
'entry_slug2'] ) ) {
115 $matches[
'is_cpt'] = $matches[
'is_cpt2'];
116 $matches[
'slug'] = $matches[
'slug2'];
117 $matches[
'entry_slug'] = $matches[
'entry_slug2'];
118 unset( $matches[
'is_cpt2'], $matches[
'slug2'], $matches[
'entry_slug2'] );
121 if ( empty( $matches[
'entry_slug'] ) ) {
122 gravityview()->log->error(
'Entry slug not parsed by regex.', array(
'data' => $matches ) );
125 $entry_id = $matches[
'entry_slug'];
128 if ( !
$entry = \
GV\GF_Entry::by_id( $entry_id ) ) {
129 gravityview()->log->error(
'Invalid entry ID {entry_id}', array(
'entry_id' => $entry_id ) );
143 if( is_numeric( $matches[
'slug'] ) ) {
148 $view =
\GV\View::from_post( get_page_by_path( $matches[
'slug'], OBJECT,
'gravityview' ) );
153 gravityview()->log->error(
'Could not detect View from URL {url}', array(
'url' =>
$url,
'data' => $matches ) );
157 return array( $view,
$entry );
173 $embed_heading = sprintf( esc_html__(
'Embed Entry %d',
'gk-gravityview' ),
$entry->ID );
175 $embed_text = sprintf( esc_html__(
'This entry will be displayed as it is configured in View %d',
'gk-gravityview' ), $view->ID );
178 <div class="loading-placeholder" style="background-color:#e6f0f5;"> 179 <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> 180 <p style="margin:0; padding:0; font-family: -apple-system, BlinkMacSystemFont, \'Segoe UI\', Roboto, Oxygen-Sans, Ubuntu, Cantarell, \'Helvetica Neue\', sans-serif;"> 183 <br style="clear: both;"> 194 $title = esc_html__(
'This will look better when it is embedded.',
'gk-gravityview' );
195 $message = esc_html__(
'Styles don\'t get loaded when being previewed, so the content below will look strange. Don\'t be concerned!',
'gk-gravityview');
196 return '<div class="updated notice">'.$floaty.
'<h3>'.
$title.
'</h3><p>'.$message.
'</p><br style="clear:both;" /></div>';
209 $public_states = get_post_stati( array(
'public' =>
true ) );
210 if ( ! in_array( $view->post_status, $public_states ) && ! \
GVCommon::has_cap(
'read_gravityview', $view->ID ) ) {
211 gravityview()->log->notice(
'The current user cannot access this View #{view_id}', array(
'view_id' => $view->ID ) );
212 return __(
'You are not allowed to view this content.',
'gk-gravityview' );
216 gravityview()->log->notice(
'Entry ID #{entry_id} is not active', array(
'entry_id' =>
$entry->ID ) );
217 return __(
'You are not allowed to view this content.',
'gk-gravityview' );
220 if ( $view->settings->get(
'show_only_approved' ) ) {
222 gravityview()->log->error(
'Entry ID #{entry_id} is not approved for viewing', array(
'entry_id' =>
$entry->ID ) );
223 return __(
'You are not allowed to view this content.',
'gk-gravityview' );
231 $is_reembedded =
false;
232 if ( in_array( get_class( $request ), array(
'GV\Frontend_Request',
'GV\Mock_Request' ) ) ) {
233 if ( ( $_view = $request->is_view() ) && $_view->ID !== $view->ID ) {
234 $is_reembedded =
true;
242 if ( $is_reembedded ||
$entry ) {
243 $view->widgets = new \GV\Widget_Collection();
246 if ( $request->is_edit_entry() ) {
252 $render = $loader->instances[
'render'];
263 'form_id' =>
$form[
'id'],
264 'view_id' => $view->ID,
265 'entries' => array(
$entry->as_entry() ),
269 ob_start() && $render->init( $data, \
GV\Entry::by_id(
$entry[
'id'] ), $view );
273 add_filter(
'gravityview/template/links/back/url',
'__return_false' );
275 $renderer = new \GV\Entry_Renderer();
277 $output = sprintf(
'<div class="gravityview-oembed gravityview-oembed-entry gravityview-oembed-entry-%d">%s</div>',
$entry->ID,
$output );
279 remove_filter(
'gravityview/template/links/back/url',
'__return_false' );
299 $rewrite_slug = apply_filters(
'gravityview_slug',
'view' );
302 $prefix = trailingslashit( home_url() );
305 $using_permalinks = $prefix .
"(?P<is_cpt>{$rewrite_slug})?/?(?P<slug>.+?)/{$entry_var_name}/(?P<entry_slug>.+?)/?\$";
308 $not_using_permalinks = $prefix .
"(?:index.php)?\?(?P<is_cpt2>[^=]+)=(?P<slug2>[^&]+)&entry=(?P<entry_slug2>[^&]+)\$";
311 $match_regex =
"(?:{$using_permalinks}|{$not_using_permalinks})";
313 return '#'.$match_regex.
'#i';
320 if ( ! preg_match( self::get_entry_regex(),
$url, $matches ) ) {
324 $view_entry = self::parse_matches( $matches,
$url );
325 if ( ! $view_entry || count( $view_entry ) != 2 ) {
329 list( $view,
$entry ) = $view_entry;
331 return self::render_frontend( $view,
$entry );
static render_preview_notice()
Generate a warning to users when previewing oEmbed in the Add Media modal.
static render( $matches, $attr, $url, $rawattr)
Output the embed HTML.
static getInstance( $passed_post=NULL)
static getInstance( $passed_post=NULL)
if(! isset( $gravityview)||empty( $gravityview->template)) $template
The entry loop for the list output.
static render_provider_request()
Output a response as a provider for an entry oEmbed URL.
if(gravityview() ->plugin->is_GF_25()) $form
static get_template_settings( $post_id)
Get all the settings for a View.
static render_admin( $view, $entry)
Display a nice placeholder in the admin for the entry.
static get_endpoint_name()
Return the endpoint name for a single Entry.
static render_frontend( $view, $entry)
Render the entry as an oEmbed.
static by_id( $post_id)
Construct a instance from a post ID.
static get_entry_regex()
Generate the Regular expression that matches embedded entries.
static pre_oembed_result( $result, $url, $args)
Internal oEmbed output, shortcircuit without proxying to the provider.
static parse_matches( $matches, $url)
Parse oEmbed regex matches and return View and Entry.
static get_floaty()
Get an image of our intrepid explorer friend.
gravityview()
The main GravityView wrapper function.
static is_approved( $status)
static has_cap( $caps='', $object_id=null, $user_id=null)
Alias of GravityView_Roles_Capabilities::has_cap()
If this file is called directly, abort.
static from_post( $post)
Construct a instance from a .