Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#61 2021-12-12 11:42:46

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 4,742
Website

Re: Two textpattern instances with one image folder

Kjeld wrote #332177:

The only thing that I have yet been unable to figure out is how to pull the images from the image folder on DOMAIN_1. Currently, the images are served from the image folder on DOMAIN_2.

The path to the Image directory of the Japanese installation should be changed to DOMAIN_1. How do I do that?

I have tried adding a path to the name of the images folder in the Image directory of the txp Admin Preferences in the Japanese installation, but this doesn’t work. I think you can only adjust the name of the folder here, not the path?

Bloke wrote #332179:

I expect the reason it’s using the old image path (ihu) is because the prefs aren’t being refreshed as I suggested above. Give me a little while to get near a laptop and I’ll see if I can test it out and see the best approach.

Some wild guesses here. If I understand Textpattern correctly, the image src is traditionally retrieved using the function imagesrcurl which uses ihu as Stef mentioned. As ihu is a php constant, it can’t be redeclared mid-application (pls correct me if I’m wrong).

Various options one could try out:

  • Set ihu on the second/Japanese site (or on both if using a separate installation just for the images) to use the actual src directory in config.php, as described here
define('ihu', 'https://static.example.com/');
  • Construct your image urls manually rather than using txp:image_url.
  • Unlikely: I’m guessing that setting the image directory to be ../english-site/images/ (where ../ means up a directory level) will either not work or will result in not very nice image urls.
  • Make the image folder on your Japanese server a symlink to the image folder on your English server. You may need SSH access to your server to do that because it doesn’t work over regular FTP. Sometimes the webhost’s webftp application has an option to set a symlink. This essentially makes any links to your regular /images/ folder invisibly draw in the images from the other folder. This method may allow you to make it look as if your image links are coming from your Japanese site url rather than from the English site url. (I usually add this along with any other custom settings to a notes file on the server so that I don’t forget it should the server need to change hosts).

This is assuming that your second/Japanese site doesn’t have its own images alongside the ones you’re pulling in from the other site. Perhaps someone else has another idea…


TXP Builders – finely-crafted code, design and txp

Offline

#62 2021-12-12 11:47:56

Kjeld
Member
From: Tokyo, Japan
Registered: 2005-02-05
Posts: 453
Website

Re: Two textpattern instances with one image folder

jakob wrote #332181:

Some wild guesses here. If I understand Textpattern correctly, the image src is traditionally retrieved using the function imagesrcurl which uses ihu as Stef mentioned. As ihu is a php constant, it can’t be redeclared mid-application (pls correct me if I’m wrong).

Various options one could try out:

  • Set ihu on the Japanese (or on both if using a separate installation just for the images) site to use the actual src directory in config.php, as described here

define('ihu', 'https://static.example.com/');...

  • Construct your image urls manually rather than using txp:image_url
  • I’m guessing setting the image directory to be ../english-site/images/ (where ../ means up a directory level) will either not work or will result in not very nice image urls.
  • Make the image folder on your Japanese server a symlink to the image folder on your English server. You may need SSH access to your server to do that because it doesn’t work over regular FTP. Sometimes the webhost’s webftp application has an option to set a symlink. This essentially makes any links to your regular /images/ folder invisibly draw in the images from the other folder. This method may allow you to make it look as if your image links are coming from your Japanese site url rather than from the English site url. (I usually add this along with any other custom settings to a notes file on the server so that I don’t forget it should the server need to change hosts).

This is assuming that your second/Japanese site doesn’t have its own images alongside the ones you’re pulling in from the other site.

Thanks, Julian. I remember the ihu suggestion from advice you previously gave me.

I am cooking dinner now, and am going to try these suggestions later tonight.


Old Photos of Japan – Japan in the 1850s~1960s (100% txp)
MeijiShowa – Stock photos of Japan in the 1850s~1960s (100% txp)
JapaneseStreets.com – Japanese street fashion (mostly txp)

Offline

#63 2021-12-12 11:48:07

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 4,742
Website

Re: Two textpattern instances with one image folder

colak wrote #332172:

I was just wondering how you are dealing with the alt attribute on this. Do you just use English or do you use another field for the Japanese site?

I am also wondering how search engines would interpret the hotlinking of images and the possible different alts.

An interesting question. I believe you could add a lang="ja" or lang="en" attribute to your image tag to specify the respective alt and title languages.


TXP Builders – finely-crafted code, design and txp

Offline

#64 2021-12-12 12:54:29

Kjeld
Member
From: Tokyo, Japan
Registered: 2005-02-05
Posts: 453
Website

Re: Two textpattern instances with one image folder

jakob wrote #332181:

  • Set ihu on the second/Japanese site (or on both if using a separate installation just for the images) to use the actual src directory in config.php, as described here

define('ihu', 'https://static.example.com/');...

This is the solution. So far it works perfectly and it is simple and straightforward.

This is my setup now:

  1. English installation on DOMAIN_1, with DATABASE_1
  2. Japanese installation on DOMAIN_2, with DATABASE_2
  3. jcr_image_custom to input both English and Japanese Alternate text and Caption in the English installation. The data is stored in txp_image on DATABASE_1
  4. rah_swap around txp:images tag in the Japanese installation to pull the Japanese Alternate text and Caption from txp_image in DATABASE_1
  5. define('ihu', 'https://static.example.com/'); in config.php of the Japanese installation. The url is the site serving the images in its images folder. In my case that is the English installation (DOMAIN_1).
  6. If needed, assign a custom field for connecting an article in language 1 to an article in language 2 and visa versa. You can store a complete link, part of the link, or just an id in the field.

It was hard getting to this point, but once it is clear what needs to be done, I think it is the simplest way to set up a multilingual configuration.

Just five basic steps really. If you don’t care about having Alternate text in your second language and don’t need captions, steps 3 and 4 could even be excluded.

Thank you very much to everybody in this thread and my thread about leaving MLP for all the input.

I hope other people find this as helpful and satisfying as I do.

EDIT

If I would start again from scratch, I would follow the following steps:

  1. Create a site for the main language. Add jcr_image_custom to allow Alternate text and Caption for images in another language. Wait with inputting images until the site for the secondary language has been completed
  2. Create a site for the secondary language. Install rah_swap. Add define('ihu', 'https://static.example.com/'); to config.php to define the main language site as the image server. Place rah_swap around image tags if an Alternate text and Caption is required
  3. Copy the database of the main language site to the database of the secondary site. Localize where necessary
  4. Start uploading images on the main language site and add the image id’s to the secondary language site

I still have to think about how to handle files.

Last edited by Kjeld (2021-12-12 14:07:27)


Old Photos of Japan – Japan in the 1850s~1960s (100% txp)
MeijiShowa – Stock photos of Japan in the 1850s~1960s (100% txp)
JapaneseStreets.com – Japanese street fashion (mostly txp)

Offline

#65 2021-12-12 16:01:08

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,468
Website GitHub

Re: Two textpattern instances with one image folder

Yeah, drat, forgot that ihu was a constant. So redefining it in your secondary Txp instance is the right approach. Nice workaround, Jools!


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

#66 2021-12-13 01:23:47

Kjeld
Member
From: Tokyo, Japan
Registered: 2005-02-05
Posts: 453
Website

Re: Two textpattern instances with one image folder

Bloke wrote #332185:

Yeah, drat, forgot that ihu was a constant. So redefining it in your secondary Txp instance is the right approach. Nice workaround, Jools!

Yes, great solution!

Until yesterday I didn’t understand what ihu stood for. It is actually clearly described in config-dist.php, but I am ashamed to confess that I never carefully read that file…

I am now wondering:

rah_swap stores alternative DB privileges in config.php. Textpattern already makes it possible to access an outside image folder through ihu.

Why not create something that, like rah_swap, also stores alternative DB privileges in config.php, and that makes it possible to access txp_image in another DB? Perhaps even as a potential set with ihu? It could perhaps even be an option in the setup installation process?

I don’t know how many users have a need for access to an image folder and txp_image in another installation, and how difficult it is to make this work. But it would make creating a multilingual installation with textpattern almost instant. It would become a cinch instead of a multi-month exploration and the need for assistance from the developers.

I assume there are also users with other reasons for sharing images amongst sites?

If the option is included in the installation setup, the process could perhaps even include the option of copying the database of the main installation to the new site? (With the express explanation that this is for creating a localized site — and this would also work in a subfolder, right? Doesn’t have to be a different domain.)

Just thinking out loud here…

Love to hear what you think.


Old Photos of Japan – Japan in the 1850s~1960s (100% txp)
MeijiShowa – Stock photos of Japan in the 1850s~1960s (100% txp)
JapaneseStreets.com – Japanese street fashion (mostly txp)

Offline

#67 2021-12-13 14:08:02

Kjeld
Member
From: Tokyo, Japan
Registered: 2005-02-05
Posts: 453
Website

Re: Two textpattern instances with one image folder

rah_swap : issues with srcset

In my two-textpattern-installations-using-one-image-folder setup I have encountered an issue with rah_swap (used on the Japanese installation) after I uploaded a new image on the English installation. It doesn’t seem to play well with srcset when an image does not exist on the Japanese installation.

I have the following shortcode (media_image) for images:

Sample 1

<rah::swap link="db6213_opj_en">

<txp:images id='<txp:yield name="id" />' wraptag="figure" class="my-4 breakout">
<img src="<txp:smd_thumbnail type='ls-1024' format='url' />"
srcset="<txp:smd_thumbnail type='ls-0640' format='url' /> 640w,
<txp:smd_thumbnail type='ls-0768' format='url' /> 768w,
<txp:smd_thumbnail type='ls-1024' format='url' /> 1024w"
class="d-block w-100" alt="<txp:jcr_image_custom name="ja_alt" />"
/>
<txp:jcr_image_custom name="ja_caption" wraptag="figcaption" class="figure-caption mx-3 mx-md-0" />
</txp:images>

</rah::swap>

It doesn’t put out any image url. The spaces where the ls-1024, ls-0640, ls-0768 image links ought to be remain empty. The weird thing is that the image alt and caption obtained through jcr_image_custom are shown.

This is the actual output on the page:

<figure class="my-4 breakout">
<img src=""
srcset=" 640w,
 768w,
 1024w"
class="d-block w-100" alt="swap test"
/>

<figcaption class="figure-caption mx-3 mx-md-0">swap test</figcaption>
</figure>

When I replace the above txp:images container with a regular txp:images container (such as the sample below) it works fine.

Sample 2

<txp:images id='<txp:yield name="id" />' wraptag="figure" class="my-4 breakout">
    <txp:image class="img-fluid" />
    <txp:jcr_image_custom name="ja_caption" wraptag="figcaption" class="figure-caption mx-3 mx-md-0" />
</txp:images>

I tried replacing smd_thumbnail with actual links like this:

Sample 3

<rah::swap link="db6213_opj_en">

<txp:images wraptag="figure" class="my-4 breakout">
<img src="https://www.domain.com/images/ls-1024/<txp:yield name="id" />.jpg"
srcset="https://www.domain.com/images/ls-640/<txp:yield name="id" />.jpg 640w,
https://www.domain.com/images/ls-768/<txp:yield name="id" />.jpg 768w,
https://www.domain.com/images/ls-1024/<txp:yield name="id" />.jpg 1024w"
class="d-block w-100" alt="<txp:jcr_image_custom name="ja_alt" />"
/>
<txp:jcr_image_custom name="ja_caption" wraptag="figcaption" class="figure-caption mx-3 mx-md-0" />
</txp:images>

</rah::swap>

This outputs the image repeatedly (maybe over 100 times…).

If the image exists in the Japanese installation there is no problem. Please note that rah_swap manages to find the image in the English installation and outputs it normally when srcset is not used (Sample 2).

Any suggestions for fixing this?

Let me know if you need additional information.

Last edited by Kjeld (2021-12-13 14:21:04)


Old Photos of Japan – Japan in the 1850s~1960s (100% txp)
MeijiShowa – Stock photos of Japan in the 1850s~1960s (100% txp)
JapaneseStreets.com – Japanese street fashion (mostly txp)

Offline

Board footer

Powered by FluxBB