public static function get_instance() { if (!self::$instance) { self::$instance = new self(); } return self::$instance; }
public static function render_stream_page() { $page_title = __('Stream Records', 'stream'); self::$list_table->prepare_items(); echo '<div class="wrap">'; if (is_network_admin()) { $sites_connected = count(WP_Stream_Network::get_instance()->connected_sites); $site_count = ''; if ($sites_connected > 0) { $site_count = sprintf(_n(' (1 site)', ' (%d sites)', $sites_connected, 'stream'), $sites_connected); } printf('<h2>%s%s</h2>', __('Stream Records', 'stream'), $site_count); // xss ok } else { printf('<h2>%s</h2>', __('Stream Records', 'stream')); // xss ok } if (is_network_admin() && !$sites_connected && !WP_Stream::is_development_mode()) { wp_enqueue_style('wp-stream-connect', WP_STREAM_URL . 'ui/css/connect.css', array(), WP_Stream::VERSION); ?> <div id="stream-message" class="updated stream-network-connect stream-connect" style="display:block !important;"> <div class="stream-message-container"> <div class="stream-message-text"> <h4><?php _e('Get started with Stream for Multisite!', 'stream'); ?> </h4> <p><?php _e('Welcome to your Network Stream! Each site on your network must be connected individually by an admin on that site for it to show here.', 'stream'); ?> </p> </div> </div> </div> <?php } elseif (is_network_admin()) { // TO DO: Add support for a network wide API Key. Until then, show this notice. ?> <div id="stream-message" class="error stream-network-connect stream-connect" style="display:block !important;"> <div class="stream-message-container"> <div class="stream-message-text"> <h4><?php _e('Stream for Multisite is coming soon!', 'stream'); ?> </h4> <p><?php _e('Access to all the Stream feeds in your network is currently disabled.', 'stream'); ?> </p> </div> </div> </div> <?php } else { self::$list_table->display(); } echo '</div>'; }
public function multisite_labels($value, $grouping) { if ('blog_id' === $grouping && is_numeric($value)) { $blog = $value && is_multisite() ? get_blog_details($value) : WP_Stream_Network::get_network_blog(); $value = $blog->blogname; } return $value; }
/** * Class constructor */ private function __construct() { define('WP_STREAM_PLUGIN', plugin_basename(__FILE__)); define('WP_STREAM_DIR', plugin_dir_path(__FILE__)); define('WP_STREAM_URL', plugin_dir_url(__FILE__)); define('WP_STREAM_INC_DIR', WP_STREAM_DIR . 'includes/'); define('WP_STREAM_CLASS_DIR', WP_STREAM_DIR . 'classes/'); define('WP_STREAM_EXTENSIONS_DIR', WP_STREAM_DIR . 'extensions/'); spl_autoload_register(array($this, 'autoload')); // Load helper functions require_once WP_STREAM_INC_DIR . 'functions.php'; // Load DB helper interface/class $driver = 'WP_Stream_DB'; if (class_exists($driver)) { self::$db = new $driver(); } if (!self::$db) { wp_die(__('Stream: Could not load chosen DB driver.', 'stream'), 'Stream DB Error'); } // Load API helper interface/class self::$api = new WP_Stream_API(); // Install the plugin add_action('wp_stream_before_db_notices', array(__CLASS__, 'install')); // Load languages add_action('plugins_loaded', array(__CLASS__, 'i18n')); // Load settings, enabling extensions to hook in add_action('init', array('WP_Stream_Settings', 'load'), 9); // Load network class if (is_multisite()) { WP_Stream_Network::get_instance(); } // Load logger class add_action('plugins_loaded', array('WP_Stream_Log', 'load')); // Load connectors after widgets_init, but before the default of 10 add_action('init', array('WP_Stream_Connectors', 'load'), 9); // Load extensions foreach (glob(WP_STREAM_EXTENSIONS_DIR . '*') as $extension) { require_once sprintf('%s/class-wp-stream-%s.php', $extension, basename($extension)); } // Load support for feeds add_action('init', array('WP_Stream_Feeds', 'load')); // Add frontend indicator add_action('wp_head', array($this, 'frontend_indicator')); if (is_admin()) { add_action('plugins_loaded', array('WP_Stream_Admin', 'load')); add_action('plugins_loaded', array('WP_Stream_Dashboard_Widget', 'load')); add_action('plugins_loaded', array('WP_Stream_Live_Update', 'load')); add_action('plugins_loaded', array('WP_Stream_Pointers', 'load')); add_action('plugins_loaded', array('WP_Stream_Migrate', 'load')); } }
/** * Load our classes, actions/filters, only if our big brother is activated. * GO GO GO! * * @return void */ public function load() { if (!apply_filters('wp_stream_notifications_disallow_site_access', false) && (WP_Stream::is_connected() || WP_Stream::is_development_mode())) { add_action('admin_menu', array($this, 'register_menu'), 11); } // Load settings, enabling extensions to hook in require_once WP_STREAM_NOTIFICATIONS_INC_DIR . 'class-wp-stream-notifications-settings.php'; add_action('init', array('WP_Stream_Notifications_Settings', 'load'), 9); if (WP_Stream_API::is_restricted()) { add_action('in_admin_header', array(__CLASS__, 'in_admin_header')); return; } // Include all adapters include_once WP_STREAM_NOTIFICATIONS_INC_DIR . 'class-wp-stream-notifications-adapter.php'; $adapters = array('email', 'push', 'sms'); foreach ($adapters as $adapter) { include WP_STREAM_NOTIFICATIONS_INC_DIR . 'adapters/class-wp-stream-notifications-adapter-' . $adapter . '.php'; } // Load network class if (is_multisite()) { require_once WP_STREAM_NOTIFICATIONS_INC_DIR . 'class-wp-stream-notifications-network.php'; $this->network = new WP_Stream_Notifications_Network(); if (WP_Stream_Network::is_network_activated()) { add_action('network_admin_menu', array($this, 'register_menu'), 11); } // Allow Stream to override the admin_menu creation if on multisite add_filter('wp_stream_notifications_disallow_site_access', array('WP_Stream_Network', 'disable_admin_access')); } // Load Matcher include_once WP_STREAM_NOTIFICATIONS_INC_DIR . 'class-wp-stream-notifications-matcher.php'; $this->matcher = new WP_Stream_Notifications_Matcher(); }
function column_default($item, $column_name) { switch ($column_name) { case 'date': $created = date('Y-m-d H:i:s', strtotime($item->created)); $date_string = sprintf('<time datetime="%s" class="relative-time record-created">%s</time>', wp_stream_get_iso_8601_extended_date(strtotime($item->created)), get_date_from_gmt($created, 'Y/m/d')); $out = $this->column_link($date_string, 'date', get_date_from_gmt($created, 'Y/m/d')); $out .= '<br />'; $out .= get_date_from_gmt($created, 'h:i:s A'); break; case 'summary': $out = $item->summary; if ($item->object_id) { $out .= $this->column_link('<span class="dashicons dashicons-search stream-filter-object-id"></span>', array('object_id' => $item->object_id, 'context' => $item->context), null, __('View all records for this object', 'stream')); } $out .= $this->get_action_links($item); break; case 'author': $author = new WP_Stream_Author((int) $item->author, (array) $item->author_meta); $out = sprintf('<a href="%s">%s <span>%s</span></a>%s%s%s', $author->get_records_page_url(), $author->get_avatar_img(80), $author->get_display_name(), $author->is_deleted() ? sprintf('<br /><small class="deleted">%s</small>', esc_html__('Deleted User', 'stream')) : '', $author->get_role() ? sprintf('<br /><small>%s</small>', $author->get_role()) : '', $author->get_agent() ? sprintf('<br /><small>%s</small>', WP_Stream_Author::get_agent_label($author->get_agent())) : ''); break; case 'context': $connector_title = $this->get_term_title($item->{'connector'}, 'connector'); $context_title = $this->get_term_title($item->{'context'}, 'context'); $out = $this->column_link($connector_title, 'connector', $item->{'connector'}); $out .= '<br />↳ '; $out .= $this->column_link($context_title, array('connector' => $item->{'connector'}, 'context' => $item->{'context'})); break; case 'action': $out = $this->column_link($this->get_term_title($item->{$column_name}, $column_name), $column_name, $item->{$column_name}); break; case 'ip': $out = $this->column_link($item->{$column_name}, 'ip', $item->{$column_name}); break; case 'blog_id': $blog = $item->blog_id && is_multisite() ? get_blog_details($item->blog_id) : WP_Stream_Network::get_instance()->get_network_blog(); $out = sprintf('<a href="%s"><span>%s</span></a>', add_query_arg(array('blog_id' => $blog->blog_id), network_admin_url('admin.php?page=wp_stream')), esc_html($blog->blogname)); break; default: /** * Registers new Columns to be inserted into the table. The cell contents of this column is set * below with 'wp_stream_inster_column_default-' * * @param array $new_columns Array of new column titles to add */ $inserted_columns = apply_filters('wp_stream_register_column_defaults', $new_columns = array()); if (!empty($inserted_columns) && is_array($inserted_columns)) { foreach ($inserted_columns as $column_title) { /** * If column title inserted via wp_stream_register_column_defaults ($column_title) exists * among columns registered with get_columns ($column_name) and there is an action associated * with this column, do the action * * Also, note that the action name must include the $column_title registered * with wp_stream_register_column_defaults */ if ($column_title == $column_name && has_action("wp_stream_insert_column_default-{$column_title}")) { /** * Allows for the addition of content under a specified column. * * @since 1.0.0 * * @param object $item Contents of the row */ $out = do_action("wp_stream_insert_column_default-{$column_title}", $item); } else { $out = $column_name; } } } else { $out = $column_name; // xss ok } } echo $out; // xss ok }
/** * Search all records. * * @param array Elasticsearch's Query DSL query object. * @param array Returns specified fields only. * @param bool Allow API calls to be cached. * @param int Set transient expiration in seconds. * * @return mixed */ public function search($query = array(), $fields = array(), $sites = array(), $search_type = '', $allow_cache = false, $expiration = 120) { if (empty($sites)) { if (is_network_admin()) { $sites = array_keys(WP_Stream_Network::get_instance()->connected_sites); } elseif ($this->site_uuid) { $sites[] = $this->site_uuid; } } $url = $this->request_url('/search'); $body = array(); if (!empty($query)) { $body['query'] = $query; } if (!empty($fields)) { $body['fields'] = $fields; } if (!empty($sites)) { $body['sites'] = $sites; } if (!empty($search_type)) { $body['search_type'] = $search_type; } $args = array('method' => 'POST', 'body' => json_encode((object) $body)); return $this->remote_request($url, $args, $allow_cache, $expiration); }