Subscribe via
Welcome, Guest. Please login or register.
Did you miss your activation email?
 OMNINOGGIN ForumPlugin SupportWP MinifyBug report/patch for when run from WP installation in a subdir
Pages: [1]
Print
Author Topic: Bug report/patch for when run from WP installation in a subdir  (Read 1062 times)
michaeltyson
Newbie
*
Posts: 3


View Profile WWW Email
« on: January 20, 2010, 08:39:32 AM »

If WP Minify is used within a WP installation located in a sub-dir (not within the webroot), it incorrectly strips off the sub-dir name from the paths.

Fix below:

Code: [Select]
--- a/wp-minify.php 2010-01-20 16:23:01.000000000 +0100
+++ b/wp-minify.php 2010-01-20 16:29:05.000000000 +0100
@@ -247,7 +247,8 @@
   
       $wpm_options = get_option($this->name);
       $site_url    = get_option('siteurl');
-      $script_path = str_replace(trailingslashit($site_url), '', $src);
+      $parsed_url  = parse_url($site_url);
+      $script_path = str_replace(trailingslashit($site_url), trailingslashit($parsed_url['path']), $src);
       $script_path = preg_replace('/^\//', '', $script_path);
       $script_path = preg_replace('/\?.*/i', '', $script_path);
   
@@ -273,7 +274,8 @@
   
       $wpm_options = get_option($this->name);
       $site_url    = get_option('siteurl');
-      $css_path  = str_replace(trailingslashit($site_url), '', $src);
+      $parsed_url  = parse_url($site_url);
+      $css_path  = str_replace(trailingslashit($site_url), trailingslashit($parsed_url['path']), $src);
       $css_path  = preg_replace('/^\//', '', $css_path);
       $css_path  = preg_replace('/\?.*/i', '', $css_path);
   
Logged

michaeltyson
Newbie
*
Posts: 3


View Profile WWW Email
« Reply #1 on: January 20, 2010, 02:08:38 PM »

I noticed later that this is worked around by providing an option in Minify settings; Users may find it easier if the plugin works this out on its own, though.
Logged

Thaya
Administrator
Sr. Member
*****
Posts: 420



View Profile WWW Email
« Reply #2 on: January 24, 2010, 03:39:57 PM »

Thanks Michael, I will include this fix in the next release!
Logged

Luke
Newbie
*
Posts: 3


View Profile WWW Email
« Reply #3 on: February 05, 2010, 05:54:32 PM »

Hi
I experienced too that WP-Minify doesn't work on this scenario (my blog is on a subfolder..).
The option inside the settings page didn't work for me, so I tried to fix it by myself... I noticed this post only when all the work was done :)

Anyway I would like to share my solution since it is somehow similar, but takes on account the fact that resources on the same server are (in my opinion) to be considered "local" even if they are outside my WP subfolder...

Here is what I changed:
Code: [Select]
[wp-minify.php]
function get_js_location($src) {
[...]
      $site_url    = get_option('siteurl');
      $parsed_url  = parse_url($site_url);
-     $script_path = str_replace(trailingslashit($site_url), trailingslashit($parsed_url['path']), $src);
-     $script_path = preg_replace('/^\//', '', $script_path);
-     $script_path = preg_replace('/\?.*/i', '', $script_path);
+     $myhost = trailingslashit($site_url);
+     $myhost = preg_match('/^https?:\/\/.*?\//', $myhost, $matches);
+     $myhost = $myhost>0? $matches[0] : trailingslashit($site_url); // my host if found; the "slashed" site url otherwise
+     $script_path = str_replace($myhost, '', $src); // relative paths only for local urls..
+     $script_path = preg_replace('/\?.*/i', '', $script_path); // throws away parameters, if any..
[...]
-     return trailingslashit($wpm_options['wp_path']) . $location;
+     return $location;

[...] 
function get_css_location($src) {
[...]
      $site_url    = get_option('siteurl');
      $parsed_url  = parse_url($site_url);
-     $css_path  = str_replace(trailingslashit($site_url), trailingslashit($parsed_url['path']), $src);
-     $css_path  = preg_replace('/^\//', '', $css_path);
-     $css_path  = preg_replace('/\?.*/i', '', $css_path);
+     $myhost = trailingslashit($site_url);
+     $myhost = preg_match('/^https?:\/\/.*?\//', $myhost, $matches);
+     $myhost = $myhost>0? $matches[0] : trailingslashit($site_url); // my host if found; the "slashed" site url otherwise
+     $css_path  = str_replace($myhost, '', $src); // relative paths only for local urls..
+     $css_path  = preg_replace('/\?.*/i', '', $css_path); // throws away parameters, if any..
[...]
-     return trailingslashit($wpm_options['wp_path']) . $location;
+     return $location;

I didn't try this with a WP installed in the webserver root, but it should work.
What I can say is that it works when WP is installed in a subdir ;)

Just my 2 cents :)
« Last Edit: February 05, 2010, 06:00:54 PM by Luke » Logged

Thaya
Administrator
Sr. Member
*****
Posts: 420



View Profile WWW Email
« Reply #4 on: February 17, 2010, 12:10:59 AM »

Thank you so much Luke. I have included a modified version of your submission into the next release. I am very happy to see you guys helping out with the plugin as I don't have much time these days.
Logged

Luke
Newbie
*
Posts: 3


View Profile WWW Email
« Reply #5 on: February 17, 2010, 05:13:45 PM »

You're welcome :)
I'm happy for being able to help :)
I've just upgraded the plugin installed on my blog to the latest version you published, and all seem to work flawlessly :)
I'm still at WP 2.9.1, waiting for the localized version to be ready in order to upgrade it..

I sometimes happen to be (quite often to be honest) in the condition of having little to no spare time, but if something I do can be of help to many others, then I'm glad to share it!

Well, you know.. "all that is not given is lost" ;)
Thanks to you!
Logged

Pages: [1]
Print
Jump to: