/**
  * Load our classes, actions/filters, only if our big brother is activated.
  * GO GO GO!
  *
  * @return void
  */
 public function load()
 {
     add_action('all_admin_notices', array($this, 'admin_notices'));
     // Load settings
     require_once WP_STREAM_REPORTS_INC_DIR . 'class-wp-stream-reports-settings.php';
     add_action('init', array('WP_Stream_Reports_Settings', 'load'), 9);
     // Load date interval
     require_once WP_STREAM_CLASS_DIR . 'class-wp-stream-date-interval.php';
     require_once WP_STREAM_REPORTS_INC_DIR . 'class-wp-stream-reports-date-interval.php';
     add_action('init', array('WP_Stream_Reports_Date_Interval', 'get_instance'));
     // Load metaboxes and charts
     require_once WP_STREAM_REPORTS_INC_DIR . 'class-wp-stream-reports-meta-boxes.php';
     require_once WP_STREAM_REPORTS_INC_DIR . 'class-wp-stream-reports-charts.php';
     add_action('init', array('WP_Stream_Reports_Metaboxes', 'get_instance'), 12);
     // Load template tags
     require_once WP_STREAM_REPORTS_INC_DIR . 'template-tags.php';
     // Register new submenu
     add_action('network_admin_menu', array($this, 'register_menu'), 11);
     if (WP_Stream::is_connected() || WP_Stream::is_development_mode()) {
         add_action('admin_menu', array($this, 'register_menu'), 11);
     }
     self::$disallow_access = apply_filters('wp_stream_reports_disallow_site_access', false);
     // Register and enqueue the administration scripts
     add_action('admin_enqueue_scripts', array($this, 'register_ui_assets'), 20);
     add_action('admin_print_scripts', array($this, 'dequeue_media_conflicts'), 9999);
 }
Example #2
0
 /**
  * Check is menu is present in menu array
  */
 public function test_register_menu()
 {
     do_action('admin_menu');
     global $menu, $submenu;
     //Check main menu
     $this->assertTrue(in_array('wp_stream', reset($menu)));
     if (WP_Stream::is_connected() || WP_Stream::is_development_mode()) {
         //Check submenu
         $this->assertTrue(in_array('wp_stream_settings', $submenu['wp_stream'][1]));
     }
 }
 /**
  * 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 Matcher
     include_once WP_STREAM_NOTIFICATIONS_INC_DIR . 'class-wp-stream-notifications-matcher.php';
     $this->matcher = new WP_Stream_Notifications_Matcher();
 }
 /**
  * Implements WP_Stream_Wrapper_Interface::get_web_accessible_url()
  *
  * Returns a URL that can be accessed from a browser. For example,
  * the web URL of the internal URI "local://example.txt" might be
  * "http://www.example.com/wp-content/example.txt".
  *
  * @return string
  *   the web accessible URL for the resource.
  *
  * @see     WP_Local_Stream_Wrapper_Interface::get_web_accessible_url()
  * @since   1.0.0
  */
 public function get_web_accessible_url()
 {
     $path = str_replace('\\', '/', WP_Stream::target($this->uri));
     return content_url('stream_tests/' . $path);
 }
    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>';
    }
 /**
  * Helper function to query the marketplace API via wp_remote_request.
  *
  * @param string The url to access.
  * @param string The method of the request.
  * @param array  The headers sent during the request.
  * @param bool   Allow API calls to be cached.
  * @param int    Set transient expiration in seconds.
  *
  * @return object The results of the wp_remote_request request.
  */
 protected function remote_request($url = '', $args = array(), $allow_cache = true, $expiration = 300)
 {
     if (empty($url)) {
         return false;
     }
     $defaults = array('headers' => array(), 'method' => 'GET', 'body' => '', 'sslverify' => true);
     $this->count++;
     $args = wp_parse_args($args, $defaults);
     $args['headers']['Stream-Site-API-Key'] = $this->api_key;
     $args['headers']['Accept-Version'] = $this->api_version;
     $args['headers']['Content-Type'] = 'application/json';
     if (WP_Stream::is_development_mode()) {
         $args['blocking'] = true;
     }
     add_filter('http_api_transports', array(__CLASS__, 'http_api_transport_priority'), 10, 3);
     $transient = 'wp_stream_' . md5($url);
     if ('GET' === $args['method'] && $allow_cache) {
         if (false === ($request = get_transient($transient))) {
             $request = wp_remote_request($url, $args);
             set_transient($transient, $request, $expiration);
         }
     } else {
         $request = wp_remote_request($url, $args);
     }
     remove_filter('http_api_transports', array(__CLASS__, 'http_api_transport_priority'), 10);
     // Return early if the request is non blocking
     if (isset($args['blocking']) && false === $args['blocking']) {
         return true;
     }
     if (!is_wp_error($request)) {
         $data = apply_filters('wp_stream_api_request_data', json_decode($request['body']), $url, $args);
         // Loose comparison needed
         if (200 == $request['response']['code'] || 201 == $request['response']['code']) {
             return $data;
         } else {
             // Disconnect if unauthorized or no longer exists, loose comparison needed
             if (403 == $request['response']['code'] || 410 == $request['response']['code']) {
                 WP_Stream_Admin::remove_api_authentication();
             }
             $this->errors['errors']['http_code'] = $request['response']['code'];
         }
         if (isset($data->error)) {
             $this->errors['errors']['api_error'] = $data->error;
         }
     } else {
         $this->errors['errors']['remote_request_error'] = $request->get_error_message();
         WP_Stream::notice(sprintf('<strong>%s</strong> %s.', __('Stream API Error.', 'stream'), $this->errors['errors']['remote_request_error']));
     }
     if (!empty($this->errors)) {
         delete_transient($transient);
     }
     return false;
 }
 /**
  * Tests normalizing a stream
  *
  * Tests WP_Stream::normalize()
  */
 public function test_normalize()
 {
     /**
      * Test malformed URI at the scheme/target junction
      */
     $malformed_uri = 'test:///example/path1/path2/hello_world.txt';
     $expected = 'test://example/path1/path2/hello_world.txt';
     $this->assertEquals($expected, WP_Stream::normalize($malformed_uri));
     /**
      * Test malformed URI with multiple separators in target
      */
     $malformed_uri = 'test://example/path1//path2/hello_world.txt';
     $expected = 'test://example/path1/path2/hello_world.txt';
     $this->assertEquals($expected, WP_Stream::normalize($malformed_uri));
     /**
      * Test malformed URI with mutliple problems
      */
     $malformed_uri = 'test:////example/path1//path2//hello_world.txt';
     $expected = 'test://example/path1/path2/hello_world.txt';
     $this->assertEquals($expected, WP_Stream::normalize($malformed_uri));
     /**
      * Test method call when there is no target
      */
     $malformed_uri = 'test://';
     $expected = 'test://';
     $this->assertEquals($expected, WP_Stream::normalize($malformed_uri));
     /**
      * Test method call when there is no target but the URI is malformed
      */
     $malformed_uri = 'test:///';
     $expected = 'test://';
     $this->assertEquals($expected, WP_Stream::normalize($malformed_uri));
 }
Example #8
0
 /**
  * Return active instance of WP_Stream, create one if it doesn't exist
  *
  * @return WP_Stream
  */
 public static function get_instance()
 {
     if (empty(self::$instance)) {
         $class = __CLASS__;
         self::$instance = new $class();
     }
     return self::$instance;
 }
 /**
  * Setup this test case
  */
 function setUp()
 {
     // Register test stream wrapper
     wp_test_stream_wrapper_register();
     /**
      * Initialize instance variables
      */
     $wrapper = WP_Stream::new_wrapper_instance('test://');
     $this->test_dir = $wrapper->get_wrapper_path();
     $this->filename = 'testfile.txt';
     $this->uri = 'test://' . $this->filename;
     $this->path = $this->test_dir . '/' . $this->filename;
     $this->expected_contents = 'The miracle is this - the more we share, the more we have. -- Leonard Nimoy';
     /**
      * Setup and assert starting evironment
      */
     if (file_exists($this->uri)) {
         unlink($this->uri);
     }
     $this->assertFileNotExists($this->uri);
     $this->assertFileNotExists($this->path);
     // Open and write to the file
     $fh = fopen($this->uri, 'w');
     fwrite($fh, $this->expected_contents);
     fclose($fh);
     $this->assertFileExists($this->path);
     $this->assertEquals(filesize($this->uri), filesize($this->path));
 }
 /**
  * Tests setting and getting URI
  *
  * Tests the $uri attribute of
  */
 public function test_uri_attribute()
 {
     $uri = 'test://testfile.txt';
     $scheme = WP_Stream::scheme($uri);
     $class_name = WP_Stream::wrapper_class_name($scheme);
     $instance = WP_Stream::new_wrapper_instance($uri);
     $this->assertEquals($uri, $instance->get_uri());
     $new_uri = 'test://testfile2.txt';
     $instance->set_uri($new_uri);
     $this->assertEquals($new_uri, $instance->get_uri());
 }
 /**
  * Implements WP_Stream_Wrapper_Interface::dirname()
  *
  * This function is typically invoked through wp_dirname().
  *
  * @param string $uri
  *   the URI or path.
  *
  * @return mixed
  *   the new temporary filename, or false on failure.
  *
  * @see     WP_Stream_Wrapper_Interface::dirname()
  * @see     wp_dirname()
  * @since   1.0.0
  */
 public function dirname($uri)
 {
     list($scheme, $target) = explode('://', $uri, 2);
     $target = WP_Stream::target($uri);
     $dirname = dirname($target);
     if ($dirname == '.') {
         $dirname = '';
     }
     return $scheme . '://' . $dirname;
 }
Example #12
0
<?php

/**
 * Tests bootstrapper
 *
 * @author X-Team <x-team.com>
 * @author Jonathan Bardo <*****@*****.**>
 */
// Use in code to trigger custom actions
define('STREAM_TESTS', true);
$_tests_dir = getenv('WP_TESTS_DIR');
if (!$_tests_dir) {
    $_tests_dir = '/tmp/wordpress-tests-lib';
}
require_once $_tests_dir . '/includes/functions.php';
tests_add_filter('muplugins_loaded', function () {
    // Manually load plugin
    require dirname(dirname(__FILE__)) . '/stream.php';
    // Call Activate plugin function
    WP_Stream::install();
});
// Removes all sql tables on shutdown
// Do this action last
tests_add_filter('shutdown', function () {
    // Empty all tables so we don't deal with leftovers
    drop_tables();
}, 999999);
require $_tests_dir . '/includes/bootstrap.php';
require dirname(__FILE__) . '/testcase.php';
Example #13
0
 /**
  * Check if get instance function return a valid instance of the strem class
  *
  * @return void
  */
 public function test_get_instance()
 {
     $instance = WP_Stream::get_instance();
     $this->assertInstanceOf('WP_Stream', $instance);
 }
 /**
  * Give the user options for how to handle their legacy Stream records
  *
  * @action admin_notices
  * @return void
  */
 public static function migrate_notice()
 {
     if (!self::show_migrate_notice()) {
         return;
     }
     $notice = sprintf('<strong id="stream-migrate-title">%s</strong></p><p id="stream-migrate-message">%s</p><div id="stream-migrate-progress"><progress value="0" max="100"></progress> <strong>0&#37;</strong> <em></em> <button id="stream-migrate-actions-close" class="button button-secondary">%s</button><div class="clear"></div></div><p id="stream-migrate-actions"><button id="stream-start-migrate" class="button button-primary">%s</button> <button id="stream-migrate-reminder" class="button button-secondary">%s</button> <a href="#" id="stream-delete-records" class="delete">%s</a>', __('Migrate Stream Records', 'stream'), sprintf(__('We found %s existing Stream records that need to be migrated to your Stream account.', 'stream'), number_format(self::$record_count)), __('Close', 'stream'), __('Start Migration Now', 'stream'), __('Remind Me Later', 'stream'), __('Delete Existing Records', 'stream'));
     WP_Stream::notice($notice, false);
 }
 /**
  * Normalizes a stream URI by making it syntactically correct
  *
  * The following actions are performed on the stream URI that is
  * returned.
  *
  * - Removing leading slashes from target.
  * - Removing duplicate path separators from target.
  *
  * @param string $uri
  *   the stream URI to normalize.
  * @return string
  *   the normalized stream URI after the modifications listed in the
  *   function description have been performed.
  *
  * @access  public
  * @static
  * @since   1.0.0
  */
 public static function normalize($uri)
 {
     $scheme = WP_Stream::scheme($uri);
     if ($scheme && WP_Stream::scheme_valid($scheme)) {
         $target = WP_Stream::target($uri);
         if ($target !== false) {
             $target = self::_clean_path_components($target);
             $uri = $scheme . '://' . $target;
         }
     }
     return $uri;
 }
 /**
  * Add a specific body class to all Stream admin screens
  *
  * @filter admin_body_class
  *
  * @param  string $classes
  *
  * @return string $classes
  */
 public static function admin_body_class($classes)
 {
     if (self::is_stream_screen()) {
         $classes .= sprintf(' %s ', self::ADMIN_BODY_CLASS);
         if (WP_Stream::is_connected() || WP_Stream::is_development_mode()) {
             $classes .= ' wp_stream_connected ';
         } else {
             $classes .= ' wp_stream_disconnected ';
         }
         if (WP_Stream_API::is_restricted()) {
             $classes .= ' wp_stream_restricted ';
         }
     }
     $settings_pages = array(self::SETTINGS_PAGE_SLUG);
     if (isset($_GET['page']) && in_array($_GET['page'], $settings_pages)) {
         $classes .= sprintf(' %s ', self::SETTINGS_PAGE_SLUG);
     }
     return $classes;
 }
/**
 * Sets access and modification time of file
 *
 * PHP's touch() does not work well with stream wrappers. This helper function
 * adds this missing support.
 *
 * This function is fully compatible with PHP's touch() function and may be
 * called in the same way. For example, both a URI and a normal filepath
 * can be provided for the $uri parameter.
 *
 * @param string $uri
 *   the URI or path to file being touched.
 * @param   int $time
 *   The touch time. If $time is not provided, the current system time is
 *   used.
 * @param int $atime
 *   If present, the access time of the given filename is set to the value
 *   of $atime. Otherwise, it is set to $time.
 *
 * @return bool
 *   true on success or false on failure.
 *
 * @link    http://php.net/manual/en/function.touch.php
 * @see     touch()
 * @since   1.0.0
 */
function wp_touch($uri, $time = null, $atime = null)
{
    if (is_null($time)) {
        $time = time();
    }
    $scheme = WP_Stream::scheme($uri);
    if ($scheme && WP_Stream::scheme_valid($scheme)) {
        $dirname = wp_dirname($uri);
        $filename = basename($uri);
        $path = wp_realpath($dirname);
        if ($path !== false) {
            $uri = $path . '/' . $filename;
        } else {
            // The directory path does not exist
            return false;
        }
    }
    return touch($uri, $time, $atime);
}