GravityView  2.17
The best, easiest way to display Gravity Forms entries on your website.
class-gravityview-lightbox-provider.php
Go to the documentation of this file.
1 <?php
2 
3 /**
4  * Registers a lightbox provider.
5  *
6  * @internal Currently internal; not ready for public usage.
7  */
9 
10  public static $slug;
11 
12  public static $script_slug;
13 
14  public static $style_slug;
15 
16  /**
17  * Adds actions and that modify GravityView to use this lightbox provider
18  */
19  public function add_hooks() {
20  add_filter( 'gravityview_lightbox_script', array( $this, 'filter_lightbox_script' ), 1000 );
21  add_filter( 'gravityview_lightbox_style', array( $this, 'filter_lightbox_style' ), 1000 );
22 
23  add_filter( 'gravityview/fields/fileupload/link_atts', array( $this, 'fileupload_link_atts' ), 10, 4 );
24  add_filter( 'gravityview/get_link/allowed_atts', array( $this, 'allowed_atts' ) );
25 
26  add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts') );
27  add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_styles') );
28 
29  add_action( 'gravityview/template/after', array( $this, 'print_scripts' ) );
30 
31  add_action( 'wp_footer', array( $this, 'output_footer' ) );
32  }
33 
34 
35  /**
36  * Prints scripts for lightbox after a View is rendered
37  *
38  * @since 2.10.1
39  *
40  * @param GV\Template_Context $gravityview
41  *
42  * @return void
43  */
44  public function print_scripts( $gravityview ) {
45 
46  if ( ! self::is_active( $gravityview ) ) {
47  return;
48  }
49 
50  wp_print_scripts( static::$script_slug );
51  wp_print_styles( static::$script_slug );
52  }
53 
54  /**
55  * Returns whether the provider is active for this View
56  *
57  * @since 2.10.1
58  *
59  * @param GV\Template_Context $gravityview
60  *
61  * @return bool true: yes! false: no!
62  */
63  protected static function is_active( $gravityview ) {
64 
65  $lightbox = $gravityview->view->settings->get( 'lightbox' );
66 
67  if ( ! $lightbox ) {
68  return false;
69  }
70 
71  $provider = gravityview()->plugin->settings->get( 'lightbox', GravityView_Lightbox::DEFAULT_PROVIDER );
72 
73  if ( static::$slug !== $provider ) {
74  return false;
75  }
76 
77  return true;
78  }
79 
80  /**
81  * Removes actions that were added by {@see GravityView_Lightbox_Provider::add_hooks}
82  * @internal Do not call directly. Instead, use:
83  *
84  * <code>
85  * do_action( 'gravityview/lightbox/provider', 'slug' );
86  * </code>
87  */
88  public function remove_hooks() {
89  remove_filter( 'gravityview_lightbox_script', array( $this, 'filter_lightbox_script' ), 1000 );
90  remove_filter( 'gravityview_lightbox_style', array( $this, 'filter_lightbox_style' ), 1000 );
91 
92  remove_filter( 'gravityview/fields/fileupload/link_atts', array( $this, 'fileupload_link_atts' ), 10 );
93  remove_filter( 'gravityview/get_link/allowed_atts', array( $this, 'allowed_atts' ) );
94 
95  remove_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts') );
96  remove_action( 'wp_enqueue_scripts', array( $this, 'enqueue_styles') );
97 
98  remove_action( 'wp_footer', array( $this, 'output_footer' ) );
99  }
100 
101  /**
102  * Modifies the name of the stylesheet to be enqueued when loading thickbox
103  *
104  * @param string $script
105  *
106  * @return string
107  */
108  public function filter_lightbox_script( $script = 'thickbox' ) {
109  return static::$script_slug;
110  }
111 
112  /**
113  * Modifies the name of the stylesheet to be enqueued when loading thickbox
114  *
115  * @param string $style
116  *
117  * @return string
118  */
119  public function filter_lightbox_style( $style = 'thickbox' ) {
120  return static::$style_slug;
121  }
122 
123  /**
124  * Get default settings for the script
125  *
126  * @return array
127  */
128  protected function default_settings() {
129  return array();
130  }
131 
132  /**
133  * Get the settings for the JavaScript, with filter applied
134  *
135  * @internal
136  *
137  * @return mixed|void
138  */
139  protected function get_settings() {
140  $settings = static::default_settings();
141 
142  return apply_filters( 'gravityview/lightbox/provider/' . static::$slug . '/settings', $settings );
143  }
144 
145  /**
146  * Output raw HTML in the wp_footer()
147  *
148  * @internal
149  */
150  public function output_footer() {}
151 
152  /**
153  * Enqueue scripts for the lightbox
154  *
155  * @internal
156  */
157  public function enqueue_scripts() {}
158 
159  /**
160  * Enqueue styles for the lightbox
161  *
162  * @internal
163  */
164  public function enqueue_styles() {}
165 
166  /**
167  * Modify the attributes allowed in an anchor tag generated by GravityView
168  *
169  * @internal
170  *
171  * @param array $atts Attributes allowed in an anchor <a> tag.
172  *
173  * @return array
174  */
175  public function allowed_atts( $atts = array() ) {
176  return $atts;
177  }
178 
179  /**
180  * Modified File Upload field links to use lightbox
181  *
182  * @since 2.10.1 Added $insecure_file_path
183  * @internal
184  *
185  * @param array|string $link_atts Array or attributes string.
186  * @param array $field_compat Current GravityView field.
187  * @param \GV\Template_Context|null $context The context.
188  * @param array $additional_details Array of additional details about the file. {
189  * @type string $file_path URL to file.
190  * @type string $insecure_file_path URL to insecure file.
191  * }
192  *
193  * @return mixed
194  */
195  public function fileupload_link_atts( $link_atts, $field_compat = array(), $context = null, $additional_details = null ) {
196  return $link_atts;
197  }
198 
199 }
print_scripts( $gravityview)
Prints scripts for lightbox after a View is rendered.
add_hooks()
Adds actions and that modify GravityView to use this lightbox provider.
allowed_atts( $atts=array())
Modify the attributes allowed in an anchor tag generated by GravityView.
output_footer()
Output raw HTML in the wp_footer()
get_settings()
Get the settings for the JavaScript, with filter applied.
remove_hooks()
Removes actions that were added by {.
default_settings()
Get default settings for the script.
filter_lightbox_style( $style='thickbox')
Modifies the name of the stylesheet to be enqueued when loading thickbox.
enqueue_styles()
Enqueue styles for the lightbox.
filter_lightbox_script( $script='thickbox')
Modifies the name of the stylesheet to be enqueued when loading thickbox.
fileupload_link_atts( $link_atts, $field_compat=array(), $context=null, $additional_details=null)
Modified File Upload field links to use lightbox.
gravityview()
The main GravityView wrapper function.
enqueue_scripts()
Enqueue scripts for the lightbox.
static is_active( $gravityview)
Returns whether the provider is active for this View.