GravityView  2.17
The best, easiest way to display Gravity Forms entries on your website.
class-gravityview-lightbox-provider-fancybox.php
Go to the documentation of this file.
1 <?php
2 /**
3  * Integrate with the FancyBox lightbox and gallery scripts
4  * @see https://fancyapps.com/fancybox/3/docs/#options
5  * @since 2.10
6  */
7 
8 /**
9  * Register the FancyBox lightbox
10  *
11  * @internal
12  */
14 
15  public static $slug = 'fancybox';
16 
17  public static $script_slug = 'gravityview-fancybox';
18 
19  public static $style_slug = 'gravityview-fancybox';
20 
21  /**
22  * @inheritDoc
23  */
24  public function print_scripts( $gravityview ) {
25 
26  parent::print_scripts( $gravityview );
27 
28  if ( ! self::is_active( $gravityview ) ) {
29  return;
30  }
31 
32  $settings = self::get_settings();
33 
34  $settings = json_encode( $settings );
35  ?>
36  <style>
37  .fancybox-container {
38  z-index: 100000; /** Divi is 99999 */
39  }
40 
41  .admin-bar .fancybox-container {
42  margin-top: 32px;
43  }
44  </style>
45  <script>
46  if ( window.Fancybox ){
47  Fancybox.bind(".gravityview-fancybox", <?php echo $settings; ?>);
48  }
49  </script>
50  <?php
51 
52  }
53 
54  /**
55  * Options to pass to Fancybox
56  *
57  * @see https://fancyapps.com/fancybox/3/docs/#options
58  *
59  * @return array
60  */
61  protected function default_settings() {
62 
63  $defaults = array(
64  'animationEffect' => 'fade',
65  'toolbar' => true,
66  'closeExisting' => true,
67  'arrows' => true,
68  'buttons' => array(
69  'thumbs',
70  'close',
71  ),
72  'i18n' => array(
73  'en' => array(
74  'CLOSE' => __( 'Close', 'gk-gravityview' ),
75  'NEXT' => __( 'Next', 'gk-gravityview' ),
76  'PREV' => __( 'Previous', 'gk-gravityview' ),
77  'ERROR' => __( 'The requested content cannot be loaded. Please try again later.', 'gk-gravityview' ),
78  'PLAY_START' => __( 'Start slideshow', 'gk-gravityview' ),
79  'PLAY_STOP' => __( 'Pause slideshow', 'gk-gravityview' ),
80  'FULL_SCREEN' => __( 'Full screen', 'gk-gravityview' ),
81  'THUMBS' => __( 'Thumbnails', 'gk-gravityview' ),
82  'DOWNLOAD' => __( 'Download', 'gk-gravityview' ),
83  'SHARE' => __( 'Share', 'gk-gravityview' ),
84  'ZOOM' => __( 'Zoom', 'gk-gravityview' ),
85  ),
86  )
87  );
88 
89  return $defaults;
90  }
91 
92  /**
93  * @inheritDoc
94  */
95  public function enqueue_scripts() {
96  wp_register_script( self::$script_slug, plugins_url( 'assets/lib/fancybox/dist/fancybox.umd.js', GRAVITYVIEW_FILE ), array(), GV_PLUGIN_VERSION );
97  }
98 
99  /**
100  * @inheritDoc
101  */
102  public function enqueue_styles() {
103  wp_register_style( self::$style_slug, plugins_url( 'assets/lib/fancybox/dist/fancybox.css', GRAVITYVIEW_FILE ), array(), GV_PLUGIN_VERSION );
104  }
105 
106  /**
107  * @inheritDoc
108  */
109  public function allowed_atts( $atts = array() ) {
110 
111  $atts['data-fancybox'] = null;
112  $atts['data-fancybox-trigger'] = null;
113  $atts['data-fancybox-index'] = null;
114  $atts['data-src'] = null;
115  $atts['data-type'] = null;
116  $atts['data-width'] = null;
117  $atts['data-height'] = null;
118  $atts['data-srcset'] = null;
119  $atts['data-caption'] = null;
120  $atts['data-options'] = null;
121  $atts['data-filter'] = null;
122 
123  return $atts;
124  }
125 
126  /**
127  * @inheritDoc
128  */
129  public function fileupload_link_atts( $link_atts, $field_compat = array(), $context = null, $additional_details = null ) {
130 
131  if ( $context && ! $context->view->settings->get( 'lightbox', false ) ) {
132  return $link_atts;
133  }
134 
135  // Prevent empty content from getting added to the lightbox gallery
136  if ( is_array( $additional_details ) && empty( $additional_details['file_path'] ) ) {
137  return $link_atts;
138  }
139 
140  // Prevent empty content from getting added to the lightbox gallery
141  if ( is_array( $additional_details ) && ! empty( $additional_details['disable_lightbox'] ) ) {
142  return $link_atts;
143  }
144 
145  $link_atts['class'] = \GV\Utils::get( $link_atts, 'class' ) . ' gravityview-fancybox';
146 
147  $link_atts['class'] = gravityview_sanitize_html_class( $link_atts['class'] );
148 
149  if ( $context && ! empty( $context->field->field ) ) {
150  if ( $context->field->field->multipleFiles ) {
151  $entry = $context->entry->as_entry();
152  $link_atts['data-fancybox'] = 'gallery-' . sprintf( "%s-%s-%s", $entry['form_id'], $context->field->ID, $context->entry->get_slug() );
153  }
154  }
155 
156  $file_path = \GV\Utils::get( $additional_details, 'file_path' );
157 
158  /**
159  * For file types that require IFRAME, declare `pdf` media type.
160  * @see https://fancyapps.com/docs/ui/fancybox#media-types
161  */
162  if ( false !== strpos( $file_path, 'gv-iframe' ) ) {
163  $link_atts['data-type'] = 'pdf';
164  }
165 
166  return $link_atts;
167  }
168 
169 }
170 
171 GravityView_Lightbox::register( 'GravityView_Lightbox_Provider_FancyBox' );
const GV_PLUGIN_VERSION(! GravityKit\GravityView\Foundation\meets_min_php_version_requirement(__FILE__, '7.2.0'))
Constants.
Definition: gravityview.php:34
const GRAVITYVIEW_FILE
Full path to the GravityView file "GRAVITYVIEW_FILE" "./gravityview.php".
Definition: gravityview.php:40
Integrate with the FancyBox lightbox and gallery scripts.
static get( $array, $key, $default=null)
Grab a value from an array or an object or default.
static register( $provider)
Register lightbox providers.
$entry
Definition: notes.php:27
fileupload_link_atts( $link_atts, $field_compat=array(), $context=null, $additional_details=null)