| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  |  * Black Studio TinyMCE Widget - Compatibility with NextGEN Gallery plugin | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  |  * @package Black_Studio_TinyMCE_Widget | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  | namespace Black_Studio_TinyMCE_Widget\Compatibility\Plugin; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  | // Exit if accessed directly. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  | if ( ! defined( 'ABSPATH' ) ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  | 	exit; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  | } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  | if ( ! class_exists( 'Black_Studio_TinyMCE_Widget\\Compatibility\\Plugin\\Nextgen_Gallery', false ) ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  | 	 * Class that provides compatibility code for NextGEN Gallery plugin | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  | 	 * @package Black_Studio_TinyMCE_Widget | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  | 	 * @since 3.0.0 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  | 	*/ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  | 	final class Nextgen_Gallery { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  | 		/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  | 		 * The single instance of the class | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  | 		 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  | 		 * @var object | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  | 		 * @since 3.0.0 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  | 		 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  | 		protected static $_instance = null; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  | 		/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  | 		 * Return the single class instance | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  | 		 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  | 		 * @return object | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  | 		 * @since 3.0.0 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  | 		 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  | 		public static function instance() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  | 			if ( is_null( self::$_instance ) ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  | 				self::$_instance = new self(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  | 			} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  | 			return self::$_instance; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  | 		/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  | 		 * Class constructor | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  | 		 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  | 		 * @uses is_admin() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  | 		 * @uses add_filter() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  | 		 * @uses add_action() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  | 		 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  | 		 * @since 3.0.0 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  | 		 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  | 		protected function __construct() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  | 			if ( is_admin() ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  | 				add_action( 'admin_init', array( $this, 'admin_init' ) ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  | 			} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  | 			add_action( 'init', array( $this, 'customizer_init' ), 20 ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  | 			add_filter( 'widget_text', array( $this, 'widget_text' ) ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  | 			if ( ! function_exists( 'is_plugin_active' ) ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  | 				include_once ABSPATH . 'wp-admin/includes/plugin.php'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  | 			} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  | 		/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  | 		 * Prevent the class from being cloned | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  | 		 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  | 		 * @return void | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  | 		 * @since 3.0.0 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  | 		 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  | 		protected function __clone() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  | 			_doing_it_wrong( __FUNCTION__, esc_html__( 'Cheatin’ uh?' ), '3.0' ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  | 		/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  | 		 * Initialize compatibility code for NextGEN Gallery plugin | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  | 		 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  | 		 * @uses add_action() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  | 		 * @uses is_plugin_active() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  | 		 * @uses M_Attach_To_Post class (part of NextGEN Gallery) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  | 		 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  | 		 * @return void | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  | 		 * @since 3.0.0 | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 85 |  |  | 		 */ | 
            
                                                                        
                            
            
                                    
            
            
                | 86 |  |  | 		public function admin_init() { | 
            
                                                                        
                            
            
                                    
            
            
                | 87 |  |  | 			if ( is_plugin_active( 'nextgen-gallery/nggallery.php' ) ) { | 
            
                                                                        
                            
            
                                    
            
            
                | 88 |  |  | 				if ( isset( $_SERVER['SCRIPT_NAME'] ) && ! preg_match( '/\/wp-admin\/(post|post-new)\.php$/', sanitize_text_field( wp_unslash( $_SERVER['SCRIPT_NAME'] ) ) ) && bstw()->admin()->enabled() ) { // Input var ok. | 
            
                                                                        
                            
            
                                    
            
            
                | 89 |  |  | 					if ( class_exists( 'M_Attach_To_Post' ) ) { | 
            
                                                                        
                            
            
                                    
            
            
                | 90 |  |  | 						$ngg_module_attach_to_post = new M_Attach_To_Post(); | 
            
                                                                        
                            
            
                                    
            
            
                | 91 |  |  | 						add_action( 'admin_enqueue_scripts', array( $ngg_module_attach_to_post, '_enqueue_tinymce_resources' ) ); | 
            
                                                                        
                            
            
                                    
            
            
                | 92 |  |  | 						add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_style' ) ); | 
            
                                                                        
                            
            
                                    
            
            
                | 93 |  |  | 					} | 
            
                                                                        
                            
            
                                    
            
            
                | 94 |  |  | 				} | 
            
                                                                        
                            
            
                                    
            
            
                | 95 |  |  | 			} | 
            
                                                                        
                            
            
                                    
            
            
                | 96 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 97 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 98 |  |  | 		/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 99 |  |  | 		 * Enqueue admin style for NextGEN Gallery plugin | 
            
                                                                                                            
                            
            
                                    
            
            
                | 100 |  |  | 		 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 101 |  |  | 		 * @uses wp_enqueue_style() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 102 |  |  | 		 * @uses C_Router class (part of NextGEN Gallery) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 103 |  |  | 		 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 104 |  |  | 		 * @return void | 
            
                                                                                                            
                            
            
                                    
            
            
                | 105 |  |  | 		 * @since 3.0.0 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 106 |  |  | 		 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 107 |  |  | 		public function admin_enqueue_style() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 108 |  |  | 			if ( class_exists( 'C_Router' ) ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 109 |  |  | 				$router = C_Router::get_instance(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 110 |  |  | 				wp_enqueue_style( 'ngg_attach_to_post_dialog', $router->get_static_url( 'photocrati-attach_to_post#attach_to_post_dialog.css' ) ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 111 |  |  | 			} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 112 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 113 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 114 |  |  | 		/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 115 |  |  | 		 * Enqueue NextGEN Gallery frame communication script in Customizer | 
            
                                                                                                            
                            
            
                                    
            
            
                | 116 |  |  | 		 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 117 |  |  | 		 * @uses is_plugin_active() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 118 |  |  | 		 * @uses add_action() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 119 |  |  | 		 * @uses M_Frame_Communication class (part of NextGEN Gallery) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 120 |  |  | 		 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 121 |  |  | 		 * @return void | 
            
                                                                                                            
                            
            
                                    
            
            
                | 122 |  |  | 		 * @since 3.0.0 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 123 |  |  | 		 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 124 |  |  | 		public function customizer_init() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 125 |  |  | 			if ( is_plugin_active( 'nextgen-gallery/nggallery.php' ) ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 126 |  |  | 				if ( class_exists( 'M_Frame_Communication' ) ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 127 |  |  | 					$ngg_module_frame_communication = new M_Frame_Communication(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 128 |  |  | 					add_action( 'customize_controls_enqueue_scripts', array( $ngg_module_frame_communication, 'enqueue_admin_scripts' ) ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 129 |  |  | 				} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 130 |  |  | 			} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 131 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 132 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 133 |  |  | 		/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 134 |  |  | 		 * Widget text filter code for NextGEN Gallery plugin | 
            
                                                                                                            
                            
            
                                    
            
            
                | 135 |  |  | 		 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 136 |  |  | 		 * @uses is_plugin_active() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 137 |  |  | 		 * @uses M_Attach_To_Post class (part of NextGEN Gallery) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 138 |  |  | 		 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 139 |  |  | 		 * @param string $content Widget content. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 140 |  |  | 		 * @return string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 141 |  |  | 		 * @since 2.4.0 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 142 |  |  | 		 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 143 |  |  | 		public function widget_text( $content ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 144 |  |  | 			if ( is_plugin_active( 'nextgen-gallery/nggallery.php' ) ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 145 |  |  | 				if ( class_exists( 'M_Attach_To_Post' ) ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 146 |  |  | 					$ngg_module_attach_to_post = new M_Attach_To_Post(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 147 |  |  | 					$content                   = $ngg_module_attach_to_post->substitute_placeholder_imgs( $content ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 148 |  |  | 				} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 149 |  |  | 			} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 150 |  |  | 			return $content; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 151 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 152 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 153 |  |  | 	} // END class | 
            
                                                                                                            
                            
            
                                    
            
            
                | 154 |  |  |  | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 155 |  |  | } // END class_exists | 
            
                                                        
            
                                    
            
            
                | 156 |  |  |  |