Пример #1
0
 /**
  * Log handler
  *
  * @param         $connector
  * @param  string $message   sprintf-ready error message string
  * @param  array  $args      sprintf (and extra) arguments to use
  * @param  int    $object_id Target object id
  * @param  array  $contexts  Contexts of the action
  * @param  int    $user_id   User responsible for the action
  *
  * @internal param string $action Action performed (stream_action)
  * @return int
  */
 public function log($connector, $message, $args, $object_id, $contexts, $user_id = null)
 {
     global $wpdb;
     if (is_null($user_id)) {
         $user_id = get_current_user_id();
     }
     require_once WP_STREAM_INC_DIR . 'class-wp-stream-author.php';
     $user = new WP_User($user_id);
     $roles = get_option($wpdb->get_blog_prefix() . 'user_roles');
     if (!isset($args['author_meta'])) {
         $args['author_meta'] = array('user_email' => $user->user_email, 'display_name' => defined('WP_CLI') && empty($user->display_name) ? 'WP-CLI' : $user->display_name, 'user_login' => $user->user_login, 'user_role_label' => !empty($user->roles) ? $roles[$user->roles[0]]['name'] : null, 'agent' => WP_Stream_Author::get_current_agent());
         if (defined('WP_CLI') && function_exists('posix_getuid')) {
             $uid = posix_getuid();
             $user_info = posix_getpwuid($uid);
             $args['author_meta']['system_user_id'] = $uid;
             $args['author_meta']['system_user_name'] = $user_info['name'];
         }
     }
     // Remove meta with null values from being logged
     $meta = array_filter($args, function ($var) {
         return !is_null($var);
     });
     $recordarr = array('object_id' => $object_id, 'site_id' => is_multisite() ? get_current_site()->id : 1, 'blog_id' => apply_filters('blog_id_logged', is_network_admin() ? 0 : get_current_blog_id()), 'author' => $user_id, 'author_role' => !empty($user->roles) ? $user->roles[0] : null, 'created' => current_time('mysql', 1), 'summary' => vsprintf($message, $args), 'parent' => self::$instance->prev_record, 'connector' => $connector, 'contexts' => $contexts, 'meta' => $meta, 'ip' => wp_stream_filter_input(INPUT_SERVER, 'REMOTE_ADDR', FILTER_VALIDATE_IP));
     $record_id = WP_Stream_DB::get_instance()->insert($recordarr);
     return $record_id;
 }
Пример #2
0
 public static function get_instance()
 {
     if (!self::$instance) {
         $class = __CLASS__;
         self::$instance = new $class();
     }
     return self::$instance;
 }
Пример #3
0
 /**
  * Verify that all needed databases are present and add an error message if not.
  *
  * @return void
  */
 public function verify_database_present()
 {
     /**
      * Filter will halt install() if set to true
      *
      * @param  bool
      * @return bool
      */
     if (apply_filters('wp_stream_no_tables', false)) {
         return;
     }
     if (!function_exists('is_plugin_active_for_network')) {
         require_once ABSPATH . '/wp-admin/includes/plugin.php';
     }
     global $wpdb;
     $database_message = '';
     $uninstall_message = '';
     // Check if all needed DB is present
     $missing_tables = array();
     foreach ($this->db->get_table_names() as $table_name) {
         if ($wpdb->get_var("SHOW TABLES LIKE '{$table_name}'") !== $table_name) {
             $missing_tables[] = $table_name;
         }
     }
     if ($missing_tables) {
         $database_message .= sprintf('%s <strong>%s</strong>', _n('The following table is not present in the WordPress database:', 'The following tables are not present in the WordPress database:', count($missing_tables), 'stream'), esc_html(implode(', ', $missing_tables)));
     }
     if (is_plugin_active_for_network(WP_STREAM_PLUGIN) && current_user_can('manage_network_plugins')) {
         $uninstall_message = sprintf(__('Please <a href="%s">uninstall</a> the Stream plugin and activate it again.', 'stream'), network_admin_url('plugins.php#stream'));
     } elseif (current_user_can('activate_plugins')) {
         $uninstall_message = sprintf(__('Please <a href="%s">uninstall</a> the Stream plugin and activate it again.', 'stream'), admin_url('plugins.php#stream'));
     }
     /**
      * Fires before admin notices are triggered for missing database tables.
      */
     do_action('wp_stream_before_db_notices');
     if (!empty($database_message)) {
         self::notice($database_message);
         if (!empty($uninstall_message)) {
             self::notice($uninstall_message);
         }
     }
 }
Пример #4
0
 /**
  * This function is used to uninstall all custom tables and uninstall the plugin
  * It will also uninstall custom actions
  */
 public static function uninstall_plugin()
 {
     global $wpdb;
     check_ajax_referer('stream_nonce', 'wp_stream_nonce');
     if (current_user_can(self::SETTINGS_CAP)) {
         // Prevent stream action from being fired on plugin
         remove_action('deactivate_plugin', array('WP_Stream_Connector_Installer', 'callback'), null);
         // Plugin is being uninstalled from only one of the multisite blogs
         if (is_multisite() && !is_plugin_active_for_network(WP_STREAM_PLUGIN)) {
             $blog_id = get_current_blog_id();
             $wpdb->query("DELETE FROM {$wpdb->base_prefix}stream WHERE blog_id = {$blog_id}");
             delete_option(plugin_basename(WP_STREAM_DIR) . '_db');
             delete_option(WP_Stream_Install::KEY);
             delete_option(WP_Stream_Settings::KEY);
         } else {
             // Delete all tables
             foreach (WP_Stream_DB::get_instance()->get_table_names() as $table) {
                 $wpdb->query("DROP TABLE {$table}");
             }
             // Delete database options
             if (is_multisite()) {
                 $blogs = wp_get_sites();
                 foreach ($blogs as $blog) {
                     switch_to_blog($blog['blog_id']);
                     delete_option(plugin_basename(WP_STREAM_DIR) . '_db');
                     delete_option(WP_Stream_Install::KEY);
                     delete_option(WP_Stream_Settings::KEY);
                 }
                 restore_current_blog();
             }
             // Delete database option
             delete_site_option(plugin_basename(WP_STREAM_DIR) . '_db');
             delete_site_option(WP_Stream_Install::KEY);
             delete_site_option(WP_Stream_Settings::KEY);
             delete_site_option(WP_Stream_Settings::DEFAULTS_KEY);
             delete_site_option(WP_Stream_Settings::NETWORK_KEY);
             delete_site_option('dashboard_stream_activity_options');
         }
         // Delete scheduled cron event hooks
         wp_clear_scheduled_hook('stream_auto_purge');
         // Deprecated hook
         wp_clear_scheduled_hook('wp_stream_auto_purge');
         // Deactivate the plugin
         deactivate_plugins(plugin_basename(WP_STREAM_DIR) . '/stream.php');
         // Redirect to plugin page
         wp_redirect(add_query_arg(array('deactivate' => true), self_admin_url('plugins.php')));
         exit;
     } else {
         wp_die("You don't have sufficient privileges to do this action.");
     }
 }