/** * Class initialization. * * Get and set required properties, and add our action hooks, function * calls and file includes to initialize this class. * * @wp-hook void * @uses add_action() * @since 2.0.0 * @return void */ public function init() { // Retrieve required properties from our main plugin class. $this->plugin = NextGEN_Gallery_Optimizer_Basic::get_instance(); $vars = $this->plugin->get_vars(); $this->settings_slug = $vars['settings_slug']; $this->plugin_dir_url = $vars['plugin_dir_url']; $this->prefix = $vars['prefix']; $this->version = $vars['version']; // Retrieve required properties from our main admin class. $this->admin = NGGOBASIC_Admin::get_instance(); $vars = $this->admin->get_vars(); $this->plugin_dir_file = $vars['plugin_dir_file']; // Get our settings instance. $this->settings = NGGOBASIC_Settings::get_instance(); // Reset our class/rel code if accidentally changed. add_action('admin_init', array($this, 'update_modified_fancybox_code')); // Register and enqueue Optimizer's JavaScript file for NextGEN's lightbox settings. add_action('admin_enqueue_scripts', array($this, 'enqueue_nextgen_options_page_js')); // Install our lightbox on initial activation add_action('admin_footer', array($this, 'install_controller')); // Uninstall Fancybox if Optimizer is deactivated. register_deactivation_hook($this->plugin_dir_file, array($this, 'uninstall_controller')); }
/** * Class initialization. * * Get and set required properties, and add our action hooks, function * calls and file includes to initialize this class. * * @wp-hook void * @uses add_action() * @since 2.0.0 * @return void */ public function init() { // Retrieve required properties from our main plugin class. $this->plugin = NextGEN_Gallery_Optimizer_Basic::get_instance(); $vars = $this->plugin->get_vars(); $this->db_name = $vars['db_name']; $this->prefix = $vars['prefix']; $this->version = $vars['version']; $this->plugin_dir_url = $vars['plugin_dir_url']; $this->plugin_dir_path = $vars['plugin_dir_path']; // Retrieve required properties from our main admin class. $this->admin = NGGOBASIC_Admin::get_instance(); $vars = $this->admin->get_vars(); $this->fancybox_interface_slug = $vars['fancybox_interface_slug']; // Get our settings instance. $this->settings = NGGOBASIC_Settings::get_instance(); // Add our action hooks. add_action('admin_menu', array($this, 'add_options_page')); add_action('admin_enqueue_scripts', array($this, 'enqueue_scripts_and_styles')); /** * Remove all admin toolbars, notifications and navigation elements from * the Fancybox settings interface. * * We need to detect the page the PHP way here as get_current_screen() * isn't available in time to access the admin_bar_init hook. */ if (isset($_GET['page']) && $_GET['page'] == $this->fancybox_interface_slug) { // Remove top admin bar. add_filter('init', array($this, 'remove_top_admin_bar')); // Doesn't seem to work on admin_init. // Remove the update nag. add_action('admin_notices', array($this, 'remove_update_nag'), 1); // Priority 1 is important here. // Remove NextGEN's "Gallery" menu item. add_action('admin_init', array($this, 'remove_nextgen_menu_item')); // Doesn't seem to work on admin_menu. // Remove all WordPress menu items. add_action('admin_menu', array($this, 'remove_admin_menu_items')); // Remove the WordPress colophon and version number. add_action('admin_init', array($this, 'remove_footer')); } }
/** * Fix for Fancybox images on IE6 & IE8. * * Microsoft.AlphaImageLoader CSS requires absolute file paths, * so we'll run a regex on first activation, after an update and on change * of URL to write in the correct image URLs. * * @wp-hook void * @uses plugins_url(), update_option() * @since 2.0.0 moved inside class and removed function name prefix * @since 2.0.0 added plugin_dir_url() check for devs moving from development servers to production * @return void|boolean */ function fancybox_stylesheet_regex() { // Run on first activation and update. if (!isset($this->settings->version) || isset($this->settings->version) && $this->settings->version != $this->version || !isset($this->settings->plugin_dir_url) || isset($this->settings->plugin_dir_url) && $this->settings->plugin_dir_url != $this->plugin_dir_url) { // The file and rewrite paths. $new_image_path = $this->plugin_dir_url . "fancybox/"; $file = file_get_contents($this->fancybox_css_path); // The regex. $pattern = '/\\(src=\'(.*?)fancybox\\//'; $replacement = '(src=\'' . $new_image_path; $update_css = preg_replace($pattern, $replacement, $file); // Run our regex rewrite operation. if ($this->fancybox_regex_rewrite_operation($update_css, $this->fancybox_css_path)) { /** * We only want to run this regex on first activation, after * auto-update or on change of url, so we'll update the "version" * and "plugin_dir_url" options we check against. */ $settings = NGGOBASIC_Settings::get_instance(); $settings->version = $this->version; $settings->plugin_dir_url = $this->plugin_dir_url; $settings->save(); return true; } else { /** * Nullify our "version" and "plugin_dir_url" properties until * the regex has run successfully. */ $settings = NGGOBASIC_Settings::get_instance(); $settings->version = 'not_set'; $settings->plugin_dir_url = 'not_set'; $settings->save(); return false; } } }
/** * Load our dependencies as required. * * @wp-hook void * @since 2.0.0 * @uses void * @see admin_setup() * @return void */ function load_dependencies() { // Include our NGGOBASIC_Settings class for installation and settings updates. require_once $this->plugin_dir_path . 'admin/assets/class-' . $this->prefix . '-settings.php'; $this->settings = NGGOBASIC_Settings::get_instance(); $this->settings->init(); if ($this->nextgen_v1) { // Load appropriate Fancybox installation if we're using NextGEN v1.9.13 and below. require_once $this->plugin_dir_path . 'admin/assets/install/class-' . $this->prefix . '-fancybox-installer-nextgen-v1.php'; $this->fancybox_installer_nextgen_v1 = NGGOBASIC_Fancybox_Installer_NextGEN_V1::get_instance(); $this->fancybox_installer_nextgen_v1->init(); } if ($this->nextgen_v2) { // Load appropriate Fancybox installation if we're using NextGEN v2.0 and above. require_once $this->plugin_dir_path . 'admin/assets/install/class-' . $this->prefix . '-fancybox-installer-nextgen-v2.php'; $this->fancybox_installer_nextgen_v2 = NGGOBASIC_Fancybox_Installer_NextGEN_V2::get_instance(); $this->fancybox_installer_nextgen_v2->init(); if ($this->settings->optimize_admin && !$this->is_nextgen_admin()) { // Remove all NextGEN 2.0 scripts and styles from the admin (except where required) to speed up page loads. require_once $this->plugin_dir_path . 'admin/assets/class-' . $this->prefix . '-admin-cleanup.php'; $this->admin_cleanup = NGGOBASIC_Admin_Cleanup::get_instance(); $this->admin_cleanup->init(); } } // Include our settings page class. require_once $this->plugin_dir_path . 'admin/assets/class-' . $this->prefix . '-settings-page.php'; $this->settings_page = NGGOBASIC_Settings_Page::get_instance(); $this->settings_page->init(); // Include our Dynamic Fancybox Settings Interface demo class. require_once $this->plugin_dir_path . 'admin/assets/class-' . $this->prefix . '-dfsi-demo.php'; $this->DFSI = NGGOBASIC_DFSI_Demo::get_instance(); $this->DFSI->init(); // Include our regex operations. require_once $this->plugin_dir_path . 'admin/assets/class-' . $this->prefix . '-regex.php'; $this->regex = NGGOBASIC_Regex::get_instance(); $this->regex->init(); }
/** * Class initialization. * * Get and set required properties, and add our action hooks, function * calls and file includes to initialize this class. * * @wp-hook void * @uses add_action() * @since 2.0.0 * @return void */ public function init() { // Retrieve required properties from our main plugin class. $this->plugin = NextGEN_Gallery_Optimizer_Basic::get_instance(); $vars = $this->plugin->get_vars(); $this->db_name = $vars['db_name']; $this->prefix = $vars['prefix']; $this->version = $vars['version']; $this->display_name = $vars['display_name']; $this->settings_slug = $vars['settings_slug']; $this->plugin_dir_url = $vars['plugin_dir_url']; $this->plugin_dir_path = $vars['plugin_dir_path']; $this->fancybox_version = $vars['fancybox_version']; $this->nextgen_v1 = $vars['nextgen_v1']; $this->nextgen_v2 = $vars['nextgen_v2']; // Retrieve required properties from our main admin class. $this->admin = NGGOBASIC_Admin::get_instance(); $vars = $this->admin->get_vars(); $this->fancybox_interface_slug = $vars['fancybox_interface_slug']; // Get our settings instance. $this->settings = NGGOBASIC_Settings::get_instance(); // Add our action hooks. add_action('admin_menu', array($this, 'add_options_page')); add_action('admin_enqueue_scripts', array($this, 'enqueue_scripts_and_styles')); }
/** * Controller method for Fancybox installation. * * Install our menu option at Gallery --> Other Options --> Lightbox Effects * upon Optimizer's activation. * * Additionally, as NextGEN 2.0 persists full, hard-coded filepaths for * lightbox scripts and styles to the database, we'll reinstall Fancybox if * a user's domain ever changes (useful for devs moving a client's site * from development to production). * * Also, as the "custom" lightbox effect is no longer an option in NextGEN * 2.0, we'll make our Fancybox lightbox the current selection upon upgrade * from NextGEN v1 if "custom" is selected. * * We're using the admin_footer hook here, so we can capture the current * selection on the same page load as the lightbox form submission (for * when a new selection is being made). * * @wp-hook admin_footer * @uses void * @since 2.0.0 * @return void */ function install_controller() { $this->reset_installation(); $this->capture_previous_lightbox_settings(); // Run our initial installation upon activation or reactivation. if (!$this->settings->fancybox_installed) { /** * Install our lightbox after ensuring there are no duplicate db * entries for users switching back and forth between NextGEN * codebases. */ $this->uninstall(); $this->install(); // Set our install flag as true so we only run on activation. $this->settings->fancybox_installed = true; $this->settings->save(); } // Reinstall if Fancybox is selected and the site has been moved to a new URL. if ($this->settings->fancybox && $this->settings->lightbox_plugin_dir_url != $this->plugin_dir_url) { $this->uninstall_controller(); $this->install(); // Reset our URL flag so we only run again on the next domain/directory change. $settings = NGGOBASIC_Settings::get_instance(); $settings->lightbox_plugin_dir_url = $this->plugin_dir_url; $settings->save(); } // Make sure "ngg_settings" is indeed an object first, as it's only set if the "C_NextGen_Settings" class is loaded (which as of NextGEN v2.0.7x, doesn't occur during activation of other plugins). if (is_object($this->ngg_settings) && 'custom' == $this->ngg_settings->thumbEffect) { $this->save_fancybox_selection(); } $this->set_fancybox_checkbox(); }