예제 #1
0
 function flush_pope_cache()
 {
     if (is_user_logged_in() && current_user_can('manage_options') && isset($_REQUEST['ngg_flush_pope_cache'])) {
         C_Pope_Cache::get_instance()->flush();
         print "Flushed pope cache";
         exit;
     }
 }
 static function update($reset = FALSE)
 {
     $local_settings = C_NextGen_Settings::get_instance();
     $global_settings = C_NextGen_Global_Settings::get_instance();
     // This is a specific hack/work-around/fix and can probably be removed sometime after 2.0.20's release
     //
     // NextGen 2x was not multisite compatible until 2.0.18. Users that upgraded before this
     // will have nearly all of their settings stored globally (network wide) in wp_sitemeta. If
     // pope_module_list (which should always be a local setting) exists site-wide we wipe the current
     // global ngg_options and restore from defaults. This should only ever run once.
     if (is_multisite() && isset($global_settings->pope_module_list)) {
         // Setting this to TRUE will wipe current settings for display types, but also
         // allows the display type installer to run correctly
         $reset = TRUE;
         $settings_installer = new C_NextGen_Settings_Installer();
         $global_defaults = $settings_installer->get_global_defaults();
         // Preserve the network options we honor by restoring them after calling $global_settings->reset()
         $global_settings_to_keep = array();
         foreach ($global_defaults as $key => $val) {
             $global_settings_to_keep[$key] = $global_settings->{$key};
         }
         // Resets internal options to an empty array
         $global_settings->reset();
         // Restore the defaults, then our saved values. This must be done again later because
         // we've set $reset to TRUE.
         $settings_installer->install_global_settings();
         foreach ($global_settings_to_keep as $key => $val) {
             $global_settings->{$key} = $val;
         }
     }
     // Get last module list and current module list. Compare...
     $last_module_list = self::_get_last_module_list($reset);
     $current_module_list = self::_generate_module_info();
     $diff = array_diff($current_module_list, $last_module_list);
     $do_upgrade = count($diff) > 0 || count($last_module_list) != count($current_module_list);
     $can_upgrade = $do_upgrade ? self::can_do_upgrade() : FALSE;
     if ($can_upgrade && !$diff) {
         $diff = $current_module_list;
     }
     if ($can_upgrade) {
         // Clear APC cache
         if (function_exists('apc_clear_cache')) {
             @apc_clear_cache('opcode');
             apc_clear_cache();
         }
         // The cache should be flushed
         C_Photocrati_Cache::flush();
         C_Photocrati_Cache::flush('all');
         if (class_exists('C_Pope_Cache')) {
             C_Pope_Cache::get_instance()->flush();
         }
         // Remove all NGG created cron jobs
         self::refresh_cron();
         // Delete auto-update cache
         update_option('photocrati_auto_update_admin_update_list', null);
         update_option('photocrati_auto_update_admin_check_date', '');
         // Other Pope applications might be loaded, and therefore
         // all singletons should be destroyed, so that they can be
         // adapted as necessary. For now, we'll just assume that the factory
         // is the only singleton that will be used by other Pope applications
         C_Component_Factory::$_instances = array();
         foreach ($diff as $module_name) {
             if ($handler = self::get_handler_instance(array_shift(explode('|', $module_name)))) {
                 if (method_exists($handler, 'install')) {
                     $handler->install($reset);
                 }
             }
         }
         // NOTE & TODO: if the above section that declares $global_settings_to_keep is removed this should also
         // Since a hard-reset of the settings was forced we must again re-apply our previously saved values
         if (isset($global_settings_to_keep)) {
             foreach ($global_settings_to_keep as $key => $val) {
                 $global_settings->{$key} = $val;
             }
         }
         // Save any changes settings
         $global_settings->save();
         $local_settings->save();
     }
     // Another workaround to an issue caused by NextGen's lack of multisite compatibility. It's possible
     // the string substitation wasn't performed, so if a '%' symbol exists in gallerypath we reset it. It's
     // another db call, but again this should only ever run once.
     //
     // Remove this when removing the above reset-global-settings code
     if (strpos($local_settings->gallerypath, '%')) {
         $settings_installer = new C_NextGen_Settings_Installer();
         $local_settings->gallerypath = $settings_installer->gallerypath_replace($global_settings->gallerypath);
         $local_settings->save();
     }
     // Update the module list, and remove the update flag
     if ($can_upgrade) {
         update_option('pope_module_list', $current_module_list);
         self::done_upgrade();
     }
 }