diff --git a/class-404-template.php b/class-404-template.php index add91ef..ddfff55 100644 --- a/class-404-template.php +++ b/class-404-template.php @@ -44,8 +44,9 @@ public function download() { $u = wp_upload_dir(); - $basedir = str_replace( $this->uploads_basedir(), '', $u['basedir'] ); - $abspath = $basedir . $this->get_local_path(); + $remove = str_replace( get_option( 'siteurl' ), '', $u['baseurl'] ); + $basedir = str_replace( $remove, '', $u['basedir'] ); + $abspath = $basedir . $this->get_dated_path(); $dir = dirname( $abspath ); if ( !is_dir( $dir ) && !wp_mkdir_p( $dir ) ) { @@ -55,7 +56,9 @@ public function download() { $saved_image = $wp_filesystem->put_contents( $abspath, $this->response['body'], FS_CHMOD_FILE ); // predefined mode settings for WP files if ( $saved_image ) { - wp_redirect( get_site_url( get_current_blog_id(), $this->get_local_path() ) ); + $path = $this->get_ms_adjusted_path(); + $redirect = get_site_url( get_current_blog_id(), $path ); + wp_redirect( $redirect ); exit; }else { $this->display_and_exit( "Please check permissions. Could not write image $dir" ); @@ -84,6 +87,7 @@ public function display_and_exit( $message=false ) { */ public function allow_path() { $path = $this->get_remote_path(); + if ( empty( $path ) ) { return false; } $allowed_paths = array( @@ -120,12 +124,31 @@ public function get_siteurl() { $url = str_replace( array( 'http://', 'https://' ), '', UBP_LIVE_DOMAIN ); $url = 'http://' . $url; - }else if ( defined( 'UBP_SITEURL' ) && false !== UBP_SITEURL ) { - + }else if ( is_multisite() && ( $siteurl = get_option( '_ubp_site_url' ) ) ) { + + $url = parse_url( $siteurl ); + $url = 'http://' . $url['host'] . @$url['path']; + + }else if ( is_multisite() && defined( 'UBP_SITEURL' ) && false !== UBP_SITEURL ) { + + + $details = get_blog_details(); + $url = parse_url( UBP_SITEURL ); + $ms_url = ''; + if ( SUBDOMAIN_INSTALL ) { + $parts = explode( '.', $details->domain ); + $ms_url = $parts[0] . '.' . $url['host']; + } else { + $ms_url = $url['host'] . $details->path; + } + $url = 'http://' . $ms_url . @$url['path']; + + } else if ( defined( 'UBP_SITEURL' ) && false !== UBP_SITEURL ) { + $url = parse_url( UBP_SITEURL ); $url = 'http://' . $url['host'] . @$url['path']; - }else if ( !is_multisite() ) { + } else { // Nothing set... Get original siteurl from database remove_filter( 'option_siteurl', '_config_wp_siteurl' ); @@ -147,6 +170,27 @@ public function get_domain() { return $this->domain; } + public function get_dated_path() { + $path = $this->get_local_path(); + + if ( function_exists( 'is_multisite' ) && is_multisite() && strpos( $path, '/files/' ) === 0 ) { + $path = str_replace( '/files', '', $path ); + } + + return $path; + } + + public function get_ms_adjusted_path() { + $path = $this->get_local_path(); + + //switch to the "new" multisite files location + if ( function_exists( 'is_multisite' ) && is_multisite() && strpos( $path, '/files/' ) === 0 ) { + $path = 'wp-content/uploads/sites/' . get_current_blog_id() . str_replace( '/files', '', $path ); + } + + return $path; + } + public function get_auth() { if ( !isset( $this->auth ) ) { $user = parse_url( $this->get_siteurl(), PHP_URL_USER ); @@ -170,8 +214,10 @@ public function get_local_path() { // If local install is in a subdirectory, modify path to request from WordPress root $local_wordpress_path = parse_url( get_site_url(), PHP_URL_PATH ) . '/'; $requested_path = parse_url( $_SERVER['REQUEST_URI'], PHP_URL_PATH ); + if (substr($requested_path, 0, strlen($local_wordpress_path)) == $local_wordpress_path) { - $requested_path = substr($requested_path, strlen($local_wordpress_path)-1, strlen($requested_path)); + //$requested_path = substr($requested_path, strlen($local_wordpress_path), strlen($requested_path)); + $requested_path = substr($requested_path, strlen($local_wordpress_path)-1, strlen($requested_path)); } $this->local_path = $requested_path; @@ -186,6 +232,7 @@ public function get_remote_path() { // If remote install is in a subdirectory, prepend the remote path $remote_path = parse_url( $this->get_siteurl(), PHP_URL_PATH ); + if ( !empty( $remote_path ) ) { $this->remote_path = $remote_path . $this->get_local_path(); }else { diff --git a/class-get-public-ip.php b/class-get-public-ip.php index 47f3f0d..e035817 100644 --- a/class-get-public-ip.php +++ b/class-get-public-ip.php @@ -44,7 +44,7 @@ function __toString() { public function get_ip( $url, $args=array() ) { $defaults = array( 'method' => 'GET', - 'referer'=> $domain, + 'referer'=> $this->domain, 'body' => '', 'index' => 0, ); @@ -58,7 +58,7 @@ public function get_ip( $url, $args=array() ) { ); $response = wp_remote_get( $url, $query_args ); - + if ( ! is_wp_error( $response ) ) { $body = strip_tags($response['body']); diff --git a/class-helpers.php b/class-helpers.php index e546bd3..a95a7a9 100644 --- a/class-helpers.php +++ b/class-helpers.php @@ -13,7 +13,7 @@ static public function init_404_template( $template ) { } static public function requirements_check() { - add_action( 'admin_init', 'UBP_Helpers::require_no_multisite', 11 ); + //add_action( 'admin_init', 'UBP_Helpers::require_no_multisite', 11 ); add_action( 'admin_notices', 'UBP_Helpers::request_uploads_writable' ); add_action( 'admin_footer', 'UBP_Helpers::request_permalinks_enabled' ); } @@ -21,7 +21,7 @@ static public function requirements_check() { /** * Require single-site install before activating. */ - static public function require_no_multisite() { + static public function require_no_multisite() { if ( function_exists( 'is_multisite' ) && !is_multisite() ) { return true; } if ( is_admin() && (!defined('DOING_AJAX') || !DOING_AJAX) ) { @@ -64,4 +64,31 @@ static public function request_uploads_writable() { return false; } + static public function print_multisite_setting( $id ) { + switch_to_blog( $id ); + $ubp_site_url = get_option( '_ubp_site_url' ); + restore_current_blog(); + ?> + + UBP Site URL + + + path . 'files/'; + $allowed_paths[] = $details->path . 'wp-content/uploads/'; + return $allowed_paths; + } + + static function stop_ms_files_rewriting() { + $path = ABSPATH . 'wp-content/uploads/sites/' . get_current_blog_id(); + define( 'BLOGUPLOADDIR', $path ); + } + + static function pre_site_option_ms_files_rewriting( $option ) { + return 0; //return 0, not FALSE + } } \ No newline at end of file diff --git a/readme.txt b/readme.txt index f330612..c9e9b0c 100644 --- a/readme.txt +++ b/readme.txt @@ -1,5 +1,5 @@ === Uploads by Proxy === -Contributors: pdclark +Contributors: pdclark, jrfoell Author URI: http://pdclark.com Tags: localhost, local, development, staging, uploads, media library, xampp, mamp, wamp, git, svn, subversion Requires at least: 3.1 @@ -22,6 +22,28 @@ In most cases, you should be able to activate the plugin and go. If the plugin d If you are on a staging server (not a local development environment) you may need to force the plugin to run with `define( 'UBP_IS_LOCAL', true );` in `wp-config.php`. Do not set this on a live site! += Multi-Site = + +Multi-site support is available in WordPress 3.6+ but it requires additional configuration. + +In wp-config.php, in addition to the 'UBP_SITEURL' define, also add this: + + define('UPLOADBLOGSDIR', 'wp-content/uploads/sites'); + +In your .htaccess, comment out the "ms-files" line if present. It will look something like one of these two lines: + + #RewriteRule ^([_0-9a-zA-Z-]+/)?files/(.+) wp-includes/ms-files.php?file=$2 [L] + #RewriteRule ^files/(.+) wp-includes/ms-files.php?file=$1 [L] + +Also in your .htaccess, replace the following 'Normal' rewrite rules with the UBP Multisite rule below: + +# Normal +#RewriteRule ^([_0-9a-zA-Z-]+/)?(wp-(content|admin|includes).*) $2 [L] +# UBP Multisite +RewriteRule ^[_0-9a-zA-Z-]+/(wp-(content|admin|includes).*) $1 [L] + +This last .htaccess change is needed due to a bug that either manifests itself in Apache or in the default distributed WordPress Multi-Site .htaccess (https://core.trac.wordpress.org/ticket/20746) + == Installation == @@ -82,6 +104,10 @@ function ubp_ip_url( $url, $domain ) { == Changelog == += 1.1.3 = + +Multi-Site support (requires extra manual configuration) + = 1.1.2 = * Fix: Resolve a warning output in debug environments. (Static function not declared as static.) diff --git a/uploads-by-proxy.php b/uploads-by-proxy.php index a648e4c..2f77103 100644 --- a/uploads-by-proxy.php +++ b/uploads-by-proxy.php @@ -5,7 +5,7 @@ Author: Paul Clark Author URI: http://pdclark.com Description: Load images from production site if missing in development environment. Activate by using either define('WP_SITEURL', 'http://development-domain.com'); or define('UBP_SITEURL', 'http://live-domain.com/wordpress'); in wp-config.php. -Version: 1.1.2 +Version: 1.1.3ms */ /** @@ -54,3 +54,10 @@ add_action( 'admin_init', 'UBP_Helpers::requirements_check' ); add_filter( '404_template', 'UBP_Helpers::init_404_template' ); } + +if ( function_exists( 'is_multisite' ) && is_multisite() ) { + add_action( 'wpmueditblogaction', 'UBP_Helpers::print_multisite_setting' ); + add_filter( 'ubp_allowed_paths', 'UBP_Helpers::ubp_extra_paths' ); + add_action( 'init','UBP_Helpers::stop_ms_files_rewriting' ); + add_filter( 'pre_site_option_ms_files_rewriting', 'UBP_Helpers::pre_site_option_ms_files_rewriting' ); +}