Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2017-01-14 11:12:43

kirito
Member
From: Italy
Registered: 2017-01-10
Posts: 34

IMPATH, img_dir for a sub-folder installation

Hello everybody, I’m new in the forum, but I’m using textpattern for my own website for a long time. I’m developing a plugin about images (will post everything when it will work) and I’m wondering if there’s a way to change IMPATH to an arbitrary one.

The situation is I want to install the actual site in /blog (in which I have /index.php, /textpattern etc), and store images and files in a sub-folder of the root, in /images and /files. Then I redirect via .htaccess all requests to /blog:

RewriteEngine On
RewriteCond %{REQUEST_URI} !^/(files|images|video|fonts) [NC]
RewriteCond %{REQUEST_URI} !^/blog [NC]
RewriteRule ^(.*)$ blog/$1 [L]

Do this way because my provider doesn’t support symlinks, even if it is a linux host. Sad but true…
Anyway, if I leave $prefs['img_dir'] as images the IMPATH constant will become /path/to/home/blog/images and it doesn’t work. If i set at ../images then IMPATH is “kind of” correct, but http requests would become www.example.com/../images.

This seems to work for my “production” site, but doesn’t work for my local copy which is in a sub-folder /path/to/html/txp-dev/blog/, to which I connect as http://example.com/txp-dev/ (remember .htaccess rewrite). In this case, if img_dir is set to ../images then browser try to access to http://example.com/images/, so obviusly it doesn’t find images at all.

So what?

I would like to have this situation:

  • site installed in: /path/to/html/txp-dev/blog/
  • images in: /path/to/html/txp-dev/images/

Site is accessible at http://example.com/txp-dev, so browser should point to http://example.com/txp-dev/images/ for images, but IMPATH should be /path/to/html/txp-dev/images/.

Is it possible without hacking core files?

Last edited by kirito (2017-01-14 11:15:38)

Offline

#2 2017-01-14 11:51:39

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 10,090
Website

Re: IMPATH, img_dir for a sub-folder installation

Is the ihu variable of any use? You can set it in your config.php to point to docroot. The idea behind the variable was to allow you to serve images from another domain (e.g. a cookieless domain) but for your case it should be able to serve images from the folder above your Textpattern installation.


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

#3 2017-01-14 12:44:03

kirito
Member
From: Italy
Registered: 2017-01-10
Posts: 34

Re: IMPATH, img_dir for a sub-folder installation

Thank you for the hint. I managed it to work, but it’s a bit “tricky”.

define('ihu', '/txp-dev/fakedir/');

Then img_dir is set to ../images in the preferences tab. If I do not this (aka let it images) the diagnostic complains that /path/to/html/txp-dev/blog/images is not writable. Of course, it is a “wrong” path.

With your “hack” url to images become example.com/txp-dev/fakedir/../images/ and it works, because at the end it points to example.com/txp-dev/images and then Apache Rewrite can do its work.

Isn’t it possible to force the local path not depending on $prefs['img_dir']?

Last edited by kirito (2017-01-14 12:44:53)

Offline

#4 2017-01-14 12:47:06

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 10,090
Website

Re: IMPATH, img_dir for a sub-folder installation

I’ve never tried it, but can you just empty the path-to-images pref? And then just use ihu as a complete URL to the desired images folder? Not sure if it’ll work.


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

#5 2017-01-14 12:48:30

kirito
Member
From: Italy
Registered: 2017-01-10
Posts: 34

Re: IMPATH, img_dir for a sub-folder installation

I mean, for my case it should be better to let .htaccess do the correct rewrite at url level (so do not modify ihu and img_dir), and simply let know textpattern what the real local path to images is. Am I wrong?

Last edited by kirito (2017-01-14 15:32:03)

Offline

#6 2017-01-14 12:51:50

kirito
Member
From: Italy
Registered: 2017-01-10
Posts: 34

Re: IMPATH, img_dir for a sub-folder installation

Bloke wrote #303568:

I’ve never tried it, but can you just empty the path-to-images pref? And then just use ihu as a complete URL to the desired images folder? Not sure if it’ll work.

It doesn’t work, because it seems that all the part that refer to the image panel do effectively use the img_dir variable to build the local path. If path-to-images is empty, then it search in /path/to/html/txp-dev/

Last edited by kirito (2017-01-14 12:52:10)

Offline

#7 2017-01-14 13:09:56

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 10,090
Website

Re: IMPATH, img_dir for a sub-folder installation

kirito wrote #303570:

If path-to-images is empty, then it search in /path/to/html/txp-dev/

Darn, that’s a shame.

I wonder if it’s something we could improve in the next version of Textpattern? Do you have any suggestions (or a Pull Request) on how we could make the path-to-image and ihu more flexible? Not just for your specific case here, but generally.

Most of the code to do with image path handling is done in a function called imagesrcurl() in lib/txplib_misc.php. It seems to just concatenate ihu and $img_dir so maybe $img_dir is tinkered with elsewhere in the code if it’s empty.


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

#8 2017-01-14 16:31:49

kirito
Member
From: Italy
Registered: 2017-01-10
Posts: 34

Re: IMPATH, img_dir for a sub-folder installation

Well, I’m not a programmer at all so I don’t know if I can suggest anything. :) As for $img_dir, if it’s empty then IMPATH become just $path_to_site. IMPATH is defined like this:

define('IMPATH', $path_to_site.DS.$img_dir.DS);

Here is the problem: $path_to_site always expand to the full local path /path/to/html/txp-dev/blog/. So if my image dir is in /path/to/html/txp-dev/images (a sibling dir) then $img_dir must be ../images.

IMPATH is not affected by ihu. I tried to define ihu at /foo/bar/ in config.php and the situation is: diagnostic doesn’t complain and I can also upload new pictures, but images ar not rendered because <img /> tags become <img src="/foo/bar/../images/1.jpg">..., where $img_dir = "../images".

As for what I see, it would be good to let the user optionally set IMPATH as a full absolute path, not depending on other costant nor variables. ihu should not be involved.

Offline

Board footer

Powered by FluxBB