GravityView  2.17
The best, easiest way to display Gravity Forms entries on your website.
class-gravityview-lightbox.php
Go to the documentation of this file.
1 <?php
2 
3 /**
4  * Manage lightbox scripts for GravityView
5  *
6  * TODO: Add a global setting for lightbox providers
7  * TODO: Add per-field settings
8  *
9  * @internal
10  */
12  const DEFAULT_PROVIDER = 'fancybox';
13 
14  private static $providers = array();
15 
16  private static $active_provider = null;
17 
18  /**
19  * GravityView_Lightbox_Provider constructor.
20  */
21  public function __construct() {
22  require_once gravityview()->plugin->dir( 'includes/extensions/lightbox/class-gravityview-lightbox-provider.php' );
23  require_once gravityview()->plugin->dir( 'includes/extensions/lightbox/fancybox/class-gravityview-lightbox-provider-fancybox.php' );
24 
25  add_action( 'plugins_loaded', array( $this, 'set_provider' ), 11 );
26 
27  add_action( 'gravityview/lightbox/provider', array( $this, 'set_provider' ) );
28  }
29 
30  /**
31  * Activate the lightbox provider chosen in settings
32  *
33  * @param string|null $provider GravityView_Lightbox_Provider::$slug of provider
34  *
35  * @internal
36  *
37  */
38  public function set_provider( $provider = null ) {
39 
40  if( gravityview()->request->is_admin() ) {
41  return;
42  }
43 
44  if ( empty( $provider ) ) {
45  $provider = gravityview()->plugin->settings->get( 'lightbox', self::DEFAULT_PROVIDER );
46  }
47 
48  if ( empty( self::$providers[ $provider ] ) || ! class_exists( self::$providers[ $provider ] ) ) {
49  gravityview()->log->error( 'Lightbox provider {provider} not registered.', array( 'provider' => $provider ) );
50  return;
51  }
52 
53  // Already set up.
54  if ( self::$active_provider && self::$active_provider instanceof self::$providers[ $provider ] ) {
55  return;
56  }
57 
58  // We're switching providers; remove the hooks that were added.
59  if( self::$active_provider ) {
60  self::$active_provider->remove_hooks();
61  }
62 
63  self::$active_provider = new self::$providers[ $provider ];
64 
65  self::$active_provider->add_hooks();
66  }
67 
68  /**
69  * Register lightbox providers
70  *
71  * @param $provider
72  */
73  public static function register( $provider ) {
74  self::$providers[ $provider::$slug ] = $provider;
75  }
76 
77 }
78 
set_provider( $provider=null)
Activate the lightbox provider chosen in settings.
__construct()
GravityView_Lightbox_Provider constructor.
Manage lightbox scripts for GravityView.
gravityview()
The main GravityView wrapper function.