From d78dcdbf93ea69f7c8b2d5ea0627ffae45728dfc Mon Sep 17 00:00:00 2001 From: Zack Katz Date: Wed, 8 Mar 2023 11:07:28 -0500 Subject: [PATCH 01/10] Push working branch so @mrcasual can seeee --- .../rest/class-gv-rest-views-route.php | 2 +- .../class-gravityview-lightbox-provider.php | 12 ++++++++ .../lightbox/class-gravityview-lightbox.php | 18 +++++++++++ ...gravityview-lightbox-provider-fancybox.php | 30 ++++++++++++++++++- .../class-gravityview-field-entry-link.php | 5 ++-- .../class-gravityview-field-website.php | 1 + includes/fields/class-gravityview-field.php | 7 +++++ package.json | 5 ++-- templates/css/source/table-view-legacy.scss | 3 +- templates/fields/field-entry_link-html.php | 19 +++++++++--- 10 files changed, 91 insertions(+), 11 deletions(-) diff --git a/future/includes/rest/class-gv-rest-views-route.php b/future/includes/rest/class-gv-rest-views-route.php index ff8716d3c7..8022894027 100644 --- a/future/includes/rest/class-gv-rest-views-route.php +++ b/future/includes/rest/class-gv-rest-views-route.php @@ -140,7 +140,7 @@ public function prepare_entry_for_response( $view, $entry, \WP_REST_Request $req $return = array(); $renderer = new \GV\Field_Renderer(); - + $used_ids = array(); foreach ( $allowed as $field ) { diff --git a/includes/extensions/lightbox/class-gravityview-lightbox-provider.php b/includes/extensions/lightbox/class-gravityview-lightbox-provider.php index 825f1c3898..8193b6107b 100644 --- a/includes/extensions/lightbox/class-gravityview-lightbox-provider.php +++ b/includes/extensions/lightbox/class-gravityview-lightbox-provider.php @@ -21,6 +21,7 @@ public function add_hooks() { add_filter( 'gravityview_lightbox_style', array( $this, 'filter_lightbox_style' ), 1000 ); add_filter( 'gravityview/fields/fileupload/link_atts', array( $this, 'fileupload_link_atts' ), 10, 4 ); + add_filter( 'gravityview/entry_link/link_atts', array( $this, 'entry_link_link_atts' ), 10, 2 ); add_filter( 'gravityview/get_link/allowed_atts', array( $this, 'allowed_atts' ) ); add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts') ); @@ -176,6 +177,17 @@ public function allowed_atts( $atts = array() ) { return $atts; } + /** + * @filter `gravityview/entry_link/link_atts` Modify attributes before being passed to {@see gravityview_get_link} + * @since 2.14 + * + * @param array $link_atts + * @param \GV\Template_Context $context + */ + public function entry_link_link_atts( $link_atts, $context ) { + return static::fileupload_link_atts( $link_atts, array(), $context ); + } + /** * Modified File Upload field links to use lightbox * diff --git a/includes/extensions/lightbox/class-gravityview-lightbox.php b/includes/extensions/lightbox/class-gravityview-lightbox.php index 2f689b4411..9717506ce6 100644 --- a/includes/extensions/lightbox/class-gravityview-lightbox.php +++ b/includes/extensions/lightbox/class-gravityview-lightbox.php @@ -26,6 +26,24 @@ public function __construct() { add_action( 'plugins_loaded', array( $this, 'set_provider' ), 11 ); add_action( 'gravityview/lightbox/provider', array( $this, 'set_provider' ) ); + + /** + * `gravityview/field_output/context/{$tag}` Allow users to filter content on context + * @param string $value The content to be shown instead of the {{tag}} placeholder + * @param array $args Arguments passed to the function + * @param \GV\Template_Context $context The context. + */ + add_action( 'gravityview/field_output/context/class', function( $value, $args, $context ) { + + /** @var \GV\Field $field */ + $field = \GV\Utils::get( $context, 'field' ); + + if ( empty( $field ) ) { + return $value; + } + + return $value . ' ADSDASDSAD'; + }, 10, 3 ); } /** diff --git a/includes/extensions/lightbox/fancybox/class-gravityview-lightbox-provider-fancybox.php b/includes/extensions/lightbox/fancybox/class-gravityview-lightbox-provider-fancybox.php index 81ccb42713..312db70ef6 100644 --- a/includes/extensions/lightbox/fancybox/class-gravityview-lightbox-provider-fancybox.php +++ b/includes/extensions/lightbox/fancybox/class-gravityview-lightbox-provider-fancybox.php @@ -123,6 +123,34 @@ public function allowed_atts( $atts = array() ) { return $atts; } + // TODO: Disable `infinite` (endless loop) when using entry link 'gravityview/lightbox/provider/' . static::$slug . '/settings' + + public function entry_link_link_atts( $link_atts, $context ) { + + $field = \GV\Utils::get( $context, 'field' ); + + if ( ! $context || ! $field ) { + return $link_atts; + } + + if ( empty( $field->lightbox ) ) { + return $link_atts; + } + + $link_atts['class'] = \GV\Utils::get( $link_atts, 'class' ) . ' gravityview-fancybox'; + + $link_atts['class'] = gravityview_sanitize_html_class( $link_atts['class'] ); + + if ( $context && ! empty( $context->field ) ) { + $entry = $context->entry->as_entry(); + $link_atts['data-fancybox'] = 'gallery-' . sprintf( '%s-%s', $entry['form_id'], $context->field->ID ); + } + + $link_atts['data-type'] = 'iframe'; + + return $link_atts; + } + /** * @inheritDoc */ @@ -147,7 +175,7 @@ public function fileupload_link_atts( $link_atts, $field_compat = array(), $cont $link_atts['class'] = gravityview_sanitize_html_class( $link_atts['class'] ); if ( $context && ! empty( $context->field->field ) ) { - if ( $context->field->field->multipleFiles ) { + if ( ! empty( $context->field->field->multipleFiles ) ) { $entry = $context->entry->as_entry(); $link_atts['data-fancybox'] = 'gallery-' . sprintf( "%s-%s-%s", $entry['form_id'], $context->field->ID, $context->entry->get_slug() ); } diff --git a/includes/fields/class-gravityview-field-entry-link.php b/includes/fields/class-gravityview-field-entry-link.php index 847507fcec..45071ee8be 100644 --- a/includes/fields/class-gravityview-field-entry-link.php +++ b/includes/fields/class-gravityview-field-entry-link.php @@ -72,6 +72,9 @@ public function field_options( $field_options, $template_id, $field_id, $context return $field_options; } + $this->add_field_support( 'lightbox', $field_options ); + $this->add_field_support( 'new_window', $field_options ); + $add_options = array(); $add_options['entry_link_text'] = array( 'type' => 'text', @@ -81,8 +84,6 @@ public function field_options( $field_options, $template_id, $field_id, $context 'merge_tags' => true, ); - $this->add_field_support( 'new_window', $field_options ); - return $add_options + $field_options; } diff --git a/includes/fields/class-gravityview-field-website.php b/includes/fields/class-gravityview-field-website.php index 3f6ae84f93..154987311c 100644 --- a/includes/fields/class-gravityview-field-website.php +++ b/includes/fields/class-gravityview-field-website.php @@ -58,6 +58,7 @@ public function field_options( $field_options, $template_id, $field_id, $context 'priority' => 1500, ); + $this->add_field_support( 'lightbox', $field_options ); $this->add_field_support( 'new_window', $field_options ); /** diff --git a/includes/fields/class-gravityview-field.php b/includes/fields/class-gravityview-field.php index 3403743621..8d023c602d 100644 --- a/includes/fields/class-gravityview-field.php +++ b/includes/fields/class-gravityview-field.php @@ -451,6 +451,13 @@ private function field_support_options() { 'group' => 'display', 'priority' => 1300, ), + 'lightbox' => array( + 'type' => 'checkbox', + 'label' => __( 'Open in a lightbox?', 'gravityview' ), + 'value' => false, + 'group' => 'display', + 'priority' => 1300, + ), ); /** diff --git a/package.json b/package.json index 5455a4988e..2d6ecb8cd5 100644 --- a/package.json +++ b/package.json @@ -13,11 +13,12 @@ "grunt-newer": "^1.1.0", "grunt-postcss": "^0.9.0", "grunt-potomo": "^3.1.0", - "node-sass": "^5.0.0", "grunt-sass": "^3.1.0", "grunt-wp-i18n": "^0.5.1", "grunt-wp-readme-to-markdown": "^0.8.0", - "load-grunt-tasks": "^3.5.2" + "load-grunt-tasks": "^3.5.2", + "node-sass": "^5.0.0", + "vuepress": "^2.0.0-beta.27" }, "repository": { "type": "git", diff --git a/templates/css/source/table-view-legacy.scss b/templates/css/source/table-view-legacy.scss index 81b2d6929b..3b55220ccc 100644 --- a/templates/css/source/table-view-legacy.scss +++ b/templates/css/source/table-view-legacy.scss @@ -41,4 +41,5 @@ a.gv-sort.gv-icon-caret-up-down { &:hover { opacity: 1; } -} \ No newline at end of file +} + diff --git a/templates/fields/field-entry_link-html.php b/templates/fields/field-entry_link-html.php index 0c944eeb5f..472587ecfa 100644 --- a/templates/fields/field-entry_link-html.php +++ b/templates/fields/field-entry_link-html.php @@ -28,15 +28,17 @@ $output = apply_filters( 'gravityview_entry_link', GravityView_API::replace_variables( $link_text, $form, $entry ), $gravityview ); -$tag_atts = array(); +$link_atts = array(); if ( ! empty( $field_settings['new_window'] ) ) { - $tag_atts['target'] = '_blank'; + $link_atts['target'] = '_blank'; } global $post; -$href = $gravityview->entry->get_permalink( $gravityview->view, $gravityview->request, $tag_atts ); +$href = $gravityview->entry->get_permalink( $gravityview->view, $gravityview->request ); + +$href = 'https://gkdev.lndo.site/wp-json/gravityview/v1/views/872/entries/86.html'; /** * @filter `gravityview/entry_link/add_query_args` Modify whether to include passed $_GET parameters to the end of the url @@ -49,7 +51,16 @@ $href = add_query_arg( gv_get_query_args(), $href ); } -$link = gravityview_get_link( $href, $output, $tag_atts ); +/** + * @filter `gravityview/entry_link/link_atts` Modify attributes before being passed to {@see gravityview_get_link} + * @since 2.14 + * + * @param array $link_atts + * @param \GV\Template_Context $gravityview + */ +$link_atts = (array) apply_filters( 'gravityview/entry_link/link_atts', $link_atts, $gravityview ); + +$link = gravityview_get_link( $href, $output, $link_atts ); /** * @filter `gravityview_field_entry_link` Modify the link HTML (here for backward compatibility) From e5c6170ded0ac748815ec8a70851b376f25b64a2 Mon Sep 17 00:00:00 2001 From: Zack Katz Date: Mon, 5 Feb 2024 21:20:23 -0500 Subject: [PATCH 02/10] Add raw HTML output rendering --- .../rest/class-gv-rest-views-route.php | 37 ++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/future/includes/rest/class-gv-rest-views-route.php b/future/includes/rest/class-gv-rest-views-route.php index 8022894027..538eacdb03 100644 --- a/future/includes/rest/class-gv-rest-views-route.php +++ b/future/includes/rest/class-gv-rest-views-route.php @@ -351,7 +351,42 @@ public function get_sub_item( $request ) { if ( $format === 'html' ) { $renderer = new \GV\Entry_Renderer(); - return $renderer->render( $entry, $view, new Request( $request ) ); + + $rendered = $renderer->render( $entry, $view, new Request( $request ) ); + + /** + * Don't format the HTML as JSON, just return it. + */ + if ( 'raw' === $request->get_param( 'output' ) ) { + + $response = new \WP_REST_Response( '', 200 ); + $response->header( 'Content-Type', 'text/' . $format ); + + /** + * Filters whether the REST API request has already been served. + * + * Allow sending the request manually - by returning true, the API result + * will not be sent to the client. + * + * @since 4.4.0 + * + * @param bool $served Whether the request has already been served. + * Default false. + * @param \WP_HTTP_Response $result Result to send to the client. Usually a `WP_REST_Response`. + * @param \WP_REST_Request $request Request used to generate the response. + * @param \WP_REST_Server $server Server instance. + */ + add_filter( 'rest_pre_serve_request', function( $served, $result, $request, $server ) use ( $rendered ) { + + echo $rendered; + + return true; + }, 10, 4 ); + + return $response; + } + + return $rendered; } return $this->prepare_entry_for_response( $view, $entry, $request, 'single' ); From 3b30471448c8b423d16dd5d116c7aefde6c29df4 Mon Sep 17 00:00:00 2001 From: Zack Katz Date: Mon, 5 Feb 2024 21:49:57 -0500 Subject: [PATCH 03/10] Get single entry in lightbox working! Right now, it's very proof-of-concept, but I'm loving that this is finally working. --- .../rest/class-gv-rest-views-route.php | 2 + .../class-gravityview-lightbox-entry.php | 95 +++++++++++++++++++ .../lightbox/class-gravityview-lightbox.php | 1 + templates/fields/field-edit_link-html.php | 20 ++-- templates/fields/field-entry_link-html.php | 2 - 5 files changed, 112 insertions(+), 8 deletions(-) create mode 100644 includes/extensions/lightbox/class-gravityview-lightbox-entry.php diff --git a/future/includes/rest/class-gv-rest-views-route.php b/future/includes/rest/class-gv-rest-views-route.php index 538eacdb03..c6de55078a 100644 --- a/future/includes/rest/class-gv-rest-views-route.php +++ b/future/includes/rest/class-gv-rest-views-route.php @@ -378,6 +378,8 @@ public function get_sub_item( $request ) { */ add_filter( 'rest_pre_serve_request', function( $served, $result, $request, $server ) use ( $rendered ) { + $rendered = apply_filters( 'gk/gravityview/rest/entry/html', $rendered, $result, $request, $server ); + echo $rendered; return true; diff --git a/includes/extensions/lightbox/class-gravityview-lightbox-entry.php b/includes/extensions/lightbox/class-gravityview-lightbox-entry.php new file mode 100644 index 0000000000..b7523e028e --- /dev/null +++ b/includes/extensions/lightbox/class-gravityview-lightbox-entry.php @@ -0,0 +1,95 @@ + + + + Test + + + + + + + + +ID . '/entries/' . $entry['id'] . '.html' ); + + $args['lightbox'] = 1; + $args['output'] = 'raw'; + + return add_query_arg( $args, $href ); +}, 10, 3 ); + +/** + * @filter `gravityview/entry/permalink` The permalink of this entry. + * @since 2.0 + * @param string $permalink The permalink. + * @param \GV\Entry $entry The entry we're retrieving it for. + * @param \GV\View|null $view The view context. + * @param \GV\Request $request The request context. + */ +add_filter( 'gravityview/entry/permalink', function( $permalink, $gv_entry, $view, $request ) { + + $href = rest_url( 'gravityview/v1/views/' . $view->ID . '/entries/' . $gv_entry->ID . '.html' ); + + $args = [ + 'lightbox' => 1, + 'output' => 'raw' + ]; + + return add_query_arg( $args, $href ); +}, 10, 4 ); + +add_filter( 'gravityview/lightbox/provider/fancybox/settings', function ( $settings ) { + return $settings; +} ); + +/** + * + * + */ +add_filter( 'gk/gravityview/field/edit_link/atts', function ( $link_atts, $context ) { + $link_atts['data-fancybox'] = 'edit'; + $link_atts['data-type'] = 'iframe'; + + return $link_atts; +}, 10, 2 ); + +/** + * + * + */ +add_filter( 'gravityview/entry_link/link_atts', function ( $link_atts, $context ) { + $link_atts['data-fancybox'] = 'gallery'; + $link_atts['data-type'] = 'iframe'; + + return $link_atts; +}, 10, 2 ); + diff --git a/includes/extensions/lightbox/class-gravityview-lightbox.php b/includes/extensions/lightbox/class-gravityview-lightbox.php index 9717506ce6..330ad90b84 100644 --- a/includes/extensions/lightbox/class-gravityview-lightbox.php +++ b/includes/extensions/lightbox/class-gravityview-lightbox.php @@ -21,6 +21,7 @@ public function __construct() { require_once gravityview()->plugin->dir( 'includes/extensions/lightbox/class-gravityview-lightbox-provider.php' ); require_once gravityview()->plugin->dir( 'includes/extensions/lightbox/fancybox/class-gravityview-lightbox-provider-fancybox.php' ); + require_once gravityview()->plugin->dir( 'includes/extensions/lightbox/class-gravityview-lightbox-entry.php' ); // Using plugins_loaded instead of gravityview/loaded because Addon_Settings waits for all plugins to load. add_action( 'plugins_loaded', array( $this, 'set_provider' ), 11 ); diff --git a/templates/fields/field-edit_link-html.php b/templates/fields/field-edit_link-html.php index a43620f138..978b7bca08 100644 --- a/templates/fields/field-edit_link-html.php +++ b/templates/fields/field-edit_link-html.php @@ -37,13 +37,21 @@ $link_text = empty( $field_settings['edit_link'] ) ? __( 'Edit Entry', 'gravityview' ) : $field_settings['edit_link']; -$link_atts = array(); -if ( ! empty( $field_settings['new_window'] ) ) { - $link_atts['target'] = '_blank'; -} - $output = apply_filters( 'gravityview_entry_link', GravityView_API::replace_variables( $link_text, $form, $entry ), $gravityview ); $href = GravityView_Edit_Entry::get_edit_link( $entry, $gravityview->view->ID, $post ? $post->ID : null ); -echo gravityview_get_link( $href, $output, $link_atts ); +$tag_atts = []; +if ( ! empty( $field_settings['new_window'] ) ) { + $tag_atts['target'] = '_blank'; +} + +/** + * Modify the edit link HTML attributes before output. + * @since TODO + * @param array $tag_atts The link attributes. + * @param \GV\Template_Context $gravityview The context. + */ +$tag_atts = apply_filters( 'gk/gravityview/field/edit_link/atts', $tag_atts, $gravityview ); + +echo gravityview_get_link( $href, $output, $tag_atts ); diff --git a/templates/fields/field-entry_link-html.php b/templates/fields/field-entry_link-html.php index 472587ecfa..c8567c1243 100644 --- a/templates/fields/field-entry_link-html.php +++ b/templates/fields/field-entry_link-html.php @@ -38,8 +38,6 @@ $href = $gravityview->entry->get_permalink( $gravityview->view, $gravityview->request ); -$href = 'https://gkdev.lndo.site/wp-json/gravityview/v1/views/872/entries/86.html'; - /** * @filter `gravityview/entry_link/add_query_args` Modify whether to include passed $_GET parameters to the end of the url * @since 2.10 From 2bfc52d176428ed0b076f3e624ad5602974ccd2f Mon Sep 17 00:00:00 2001 From: Zack Katz Date: Tue, 6 Feb 2024 15:12:14 -0500 Subject: [PATCH 04/10] Move all required code into one file --- .../rest/class-gv-rest-views-route.php | 38 +---- .../class-gravityview-lightbox-entry.php | 131 +++++++++++++++++- 2 files changed, 127 insertions(+), 42 deletions(-) diff --git a/future/includes/rest/class-gv-rest-views-route.php b/future/includes/rest/class-gv-rest-views-route.php index c6de55078a..ca68b51807 100644 --- a/future/includes/rest/class-gv-rest-views-route.php +++ b/future/includes/rest/class-gv-rest-views-route.php @@ -352,43 +352,7 @@ public function get_sub_item( $request ) { if ( $format === 'html' ) { $renderer = new \GV\Entry_Renderer(); - $rendered = $renderer->render( $entry, $view, new Request( $request ) ); - - /** - * Don't format the HTML as JSON, just return it. - */ - if ( 'raw' === $request->get_param( 'output' ) ) { - - $response = new \WP_REST_Response( '', 200 ); - $response->header( 'Content-Type', 'text/' . $format ); - - /** - * Filters whether the REST API request has already been served. - * - * Allow sending the request manually - by returning true, the API result - * will not be sent to the client. - * - * @since 4.4.0 - * - * @param bool $served Whether the request has already been served. - * Default false. - * @param \WP_HTTP_Response $result Result to send to the client. Usually a `WP_REST_Response`. - * @param \WP_REST_Request $request Request used to generate the response. - * @param \WP_REST_Server $server Server instance. - */ - add_filter( 'rest_pre_serve_request', function( $served, $result, $request, $server ) use ( $rendered ) { - - $rendered = apply_filters( 'gk/gravityview/rest/entry/html', $rendered, $result, $request, $server ); - - echo $rendered; - - return true; - }, 10, 4 ); - - return $response; - } - - return $rendered; + return $renderer->render( $entry, $view, new Request( $request ) ); } return $this->prepare_entry_for_response( $view, $entry, $request, 'single' ); diff --git a/includes/extensions/lightbox/class-gravityview-lightbox-entry.php b/includes/extensions/lightbox/class-gravityview-lightbox-entry.php index b7523e028e..b6115f0dca 100644 --- a/includes/extensions/lightbox/class-gravityview-lightbox-entry.php +++ b/includes/extensions/lightbox/class-gravityview-lightbox-entry.php @@ -1,17 +1,132 @@ get_param( 'output' ) ) { + return false; + } + + if ( '1' !== $request->get_param( 'lightbox' ) ) { + return false; + } + + return true; +} + +add_filter( 'rest_post_dispatch', function ( $response, $server, $request ) { + + if ( ! $response instanceof \WP_REST_Response ) { + return $response; + } + + if ( false === strpos( $response->get_matched_route(), 'gravityview' ) ) { + return $response; + } + + if ( ! gravityview_is_request_lightbox( $request ) ) { + return $response; + } + + // Define the content type as being HTML instead of JSON. + $response->header( 'Content-Type', 'text/html' ); + + return $response; +}, 20, 3 ); + +/** + * Filters whether the REST API request has already been served. + * + * Allow sending the request manually - by returning true, the API result + * will not be sent to the client. + * + * @since 4.4.0 + * + * @param bool $served Whether the request has already been served. + * Default false. + * @param \WP_HTTP_Response $result Result to send to the client. Usually a `WP_REST_Response`. + * @param \WP_REST_Request $request Request used to generate the response. + * @param \WP_REST_Server $server Server instance. + */ +add_filter( 'rest_pre_serve_request', function( $served, $result, $request, $server ) { + + if ( ! gravityview_is_request_lightbox( $request ) ) { + return $served; + } + + $entry_id = $request->get_params()['s_id']; + $view_id = $request->get_params()['id']; + + $rendered = apply_filters( 'gk/gravityview/rest/entry/html', $result->get_data(), $result, $request, $entry_id, $view_id ); + + echo $rendered; + + return true; +}, 10, 4 ); + +/** + * Wrap the rendered HTML snippet inside a full HTML page. + * + * @internal + * @return void */ +add_filter( 'gk/gravityview/rest/entry/html', function( $rendered, $result, $request, $entry_id, $view_id ) { + + $view = \GV\View::by_id( $view_id ); + $entry = \GV\GF_Entry::by_id( $entry_id ); + + $title = $view->settings->get( 'single_title', '' ); + + $form = GVCommon::get_form( $entry['form_id'] ); + + // We are allowing HTML in the fields, so no escaping the output + $title = GravityView_API::replace_variables( $title, $form, $entry ); + + $title = do_shortcode( $title ); + + ob_start(); -add_filter( 'gk/gravityview/rest/entry/html', function( $rendered ) { ?> - Test + {{title}} - + + + + + + + + + - + {{content}} Date: Wed, 7 Feb 2024 15:21:37 -0500 Subject: [PATCH 05/10] Use theme styles instead of custom --- .../class-gravityview-lightbox-entry.php | 28 ++++--------------- 1 file changed, 5 insertions(+), 23 deletions(-) diff --git a/includes/extensions/lightbox/class-gravityview-lightbox-entry.php b/includes/extensions/lightbox/class-gravityview-lightbox-entry.php index b6115f0dca..fa52282678 100644 --- a/includes/extensions/lightbox/class-gravityview-lightbox-entry.php +++ b/includes/extensions/lightbox/class-gravityview-lightbox-entry.php @@ -107,33 +107,15 @@ function gravityview_is_request_lightbox( \WP_REST_Request $request ) { {{title}} - - - - - - + - + - {{content}} From d646e14b89af72aa049eda526988f529c08f320b Mon Sep 17 00:00:00 2001 From: Zack Katz Date: Wed, 7 Feb 2024 15:27:13 -0500 Subject: [PATCH 06/10] Allow filtering is_entry() and is_view() This allows us to override these values without modifying any other code. These are placeholders and should be reviewed. Also, should this be placed in GV\REST\Request() instead? --- future/includes/class-gv-request.php | 21 +++++++++++++++++-- .../includes/rest/class-gv-request-rest.php | 7 +++++++ 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/future/includes/class-gv-request.php b/future/includes/class-gv-request.php index c13d2fa3bd..383d41f35d 100644 --- a/future/includes/class-gv-request.php +++ b/future/includes/class-gv-request.php @@ -111,7 +111,17 @@ public function is_view( $return_view = true ) { if ( $post && 'gravityview' === get_post_type( $post ) ) { return ( $return_view ) ? \GV\View::from_post( $post ) : true; } - return false; + + /** + * Allow filtering the View object. + * @since TODO + * + * @param \GV\View|bool $view The View object returned or false. + */ + $is_view = apply_filters( 'gk/gravityview/request/is_view', false ); + + return $is_view instanceof \GV\View ? $is_view : false; + } } /** @@ -134,7 +144,14 @@ public function is_entry( $form_id = 0 ) { $id = get_query_var( Entry::get_endpoint_name() ); - if ( ! $id ) { + /** + * Allow filtering the entry ID. + * @since TODO + * @param int|string $id The entry ID integer or empty string. + */ + $id = apply_filters( 'gk/gravityview/request/is_entry/id', $id ); + + if ( ! $id || ! is_numeric( $id ) ) { return false; } diff --git a/future/includes/rest/class-gv-request-rest.php b/future/includes/rest/class-gv-request-rest.php index 7e3260dd78..a3ef61e908 100644 --- a/future/includes/rest/class-gv-request-rest.php +++ b/future/includes/rest/class-gv-request-rest.php @@ -19,6 +19,13 @@ public function __construct( \WP_REST_Request $request ) { $this->request = $request; } + public function is_view( $return_view = true ) { + } + + public function is_entry( $form_id = 0 ) { + die('asd'); + } + /** * Retrieve paging parameters if any. * From 5f5499e080e62d96babbd1ee052de39bf918a065 Mon Sep 17 00:00:00 2001 From: Zack Katz Date: Thu, 16 May 2024 12:14:57 -0400 Subject: [PATCH 07/10] Fix merge --- future/includes/class-gv-request.php | 1 - 1 file changed, 1 deletion(-) diff --git a/future/includes/class-gv-request.php b/future/includes/class-gv-request.php index 383d41f35d..8e06f2488f 100644 --- a/future/includes/class-gv-request.php +++ b/future/includes/class-gv-request.php @@ -122,7 +122,6 @@ public function is_view( $return_view = true ) { return $is_view instanceof \GV\View ? $is_view : false; } - } /** * Checks whether this is a single entry request From 935d1357d8cd2b95b61dae9c9587135f02c45153 Mon Sep 17 00:00:00 2001 From: Zack Katz Date: Thu, 16 May 2024 12:25:45 -0400 Subject: [PATCH 08/10] Remove debugging `die()` --- future/includes/rest/class-gv-request-rest.php | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/future/includes/rest/class-gv-request-rest.php b/future/includes/rest/class-gv-request-rest.php index a3ef61e908..282029276e 100644 --- a/future/includes/rest/class-gv-request-rest.php +++ b/future/includes/rest/class-gv-request-rest.php @@ -20,10 +20,21 @@ public function __construct( \WP_REST_Request $request ) { } public function is_view( $return_view = true ) { + return parent::is_view( $return_view ); } public function is_entry( $form_id = 0 ) { - die('asd'); + + // + // + // TODO: This is a temporary fix! + // + // + if ( isset( $_GET['lightbox'] ) ) { + return true; + } + + return parent::is_entry( $form_id ); } /** From c935772eaf63d1bd7d8740f2165c4579bf932db4 Mon Sep 17 00:00:00 2001 From: Vlad Date: Thu, 5 Sep 2024 13:06:37 -0400 Subject: [PATCH 09/10] Format code & use class imports --- .../class-gravityview-lightbox-entry.php | 99 ++++++++++--------- 1 file changed, 51 insertions(+), 48 deletions(-) diff --git a/includes/extensions/lightbox/class-gravityview-lightbox-entry.php b/includes/extensions/lightbox/class-gravityview-lightbox-entry.php index fa52282678..c64d8fa0f2 100644 --- a/includes/extensions/lightbox/class-gravityview-lightbox-entry.php +++ b/includes/extensions/lightbox/class-gravityview-lightbox-entry.php @@ -1,5 +1,10 @@ get_params()['s_id']; - $view_id = $request->get_params()['id']; + $view_id = $request->get_params()['id']; $rendered = apply_filters( 'gk/gravityview/rest/entry/html', $result->get_data(), $result, $request, $entry_id, $view_id ); @@ -85,12 +87,12 @@ function gravityview_is_request_lightbox( \WP_REST_Request $request ) { * Wrap the rendered HTML snippet inside a full HTML page. * * @internal + * * @return void */ -add_filter( 'gk/gravityview/rest/entry/html', function( $rendered, $result, $request, $entry_id, $view_id ) { - - $view = \GV\View::by_id( $view_id ); - $entry = \GV\GF_Entry::by_id( $entry_id ); +add_filter( 'gk/gravityview/rest/entry/html', function ( $rendered, $result, $request, $entry_id, $view_id ) { + $view = View::by_id( $view_id ); + $entry = GF_Entry::by_id( $entry_id ); $title = $view->settings->get( 'single_title', '' ); @@ -102,26 +104,27 @@ function gravityview_is_request_lightbox( \WP_REST_Request $request ) { $title = do_shortcode( $title ); ob_start(); - ?> - - - {{title}} - - - - - - - - {{content}} - - -"> + + {{title}} + + + + + + + + {{content}} + + + + ID . '/entries/' . $entry['id'] . '.html' ); $args['lightbox'] = 1; - $args['output'] = 'raw'; + $args['output'] = 'raw'; return add_query_arg( $args, $href ); }, 10, 3 ); /** * @filter `gravityview/entry/permalink` The permalink of this entry. - * @since 2.0 - * @param string $permalink The permalink. - * @param \GV\Entry $entry The entry we're retrieving it for. - * @param \GV\View|null $view The view context. - * @param \GV\Request $request The request context. + * @since 2.0 + * + * @param string $permalink The permalink. + * @param Entry $entry The entry we're retrieving it for. + * @param View|null $view The view context. + * @param Request $request The request context. */ -add_filter( 'gravityview/entry/permalink', function( $permalink, $gv_entry, $view, $request ) { - +add_filter( 'gravityview/entry/permalink', function ( $permalink, $gv_entry, $view, $request ) { $href = rest_url( 'gravityview/v1/views/' . $view->ID . '/entries/' . $gv_entry->ID . '.html' ); $args = [ 'lightbox' => 1, - 'output' => 'raw' + 'output' => 'raw', ]; return add_query_arg( $args, $href ); @@ -180,7 +183,7 @@ function gravityview_is_request_lightbox( \WP_REST_Request $request ) { */ add_filter( 'gk/gravityview/field/edit_link/atts', function ( $link_atts, $context ) { $link_atts['data-fancybox'] = 'edit'; - $link_atts['data-type'] = 'iframe'; + $link_atts['data-type'] = 'iframe'; return $link_atts; }, 10, 2 ); From 50fee7575df858c0a8fd35f1220ee3847b873d34 Mon Sep 17 00:00:00 2001 From: Vlad Date: Thu, 5 Sep 2024 13:07:00 -0400 Subject: [PATCH 10/10] Do not display back link in the single entry lightbox view --- .../class-gravityview-lightbox-entry.php | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/includes/extensions/lightbox/class-gravityview-lightbox-entry.php b/includes/extensions/lightbox/class-gravityview-lightbox-entry.php index c64d8fa0f2..8d9e094a51 100644 --- a/includes/extensions/lightbox/class-gravityview-lightbox-entry.php +++ b/includes/extensions/lightbox/class-gravityview-lightbox-entry.php @@ -194,8 +194,22 @@ function gravityview_is_request_lightbox( WP_REST_Request $request ) { */ add_filter( 'gravityview/entry_link/link_atts', function ( $link_atts, $context ) { $link_atts['data-fancybox'] = 'gallery'; - $link_atts['data-type'] = 'iframe'; + $link_atts['data-type'] = 'iframe'; return $link_atts; }, 10, 2 ); +/* + * Prevents the back link from being displayed in the single entry lightbox view. + * + * @since TBD + */ +add_filter( 'gravityview/template/links/back/url', function ( $url, $context ) { + $request = $context->request instanceof Request ? $context->request->get_request() : $context->request; + + if ( ! $request instanceof WP_REST_Request ) { + return $url; + } + + return gravityview_is_request_lightbox( $request ) ? null : $url; +}, 10, 3 );