Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
Re: Two textpattern instances with one image folder
demoncleaner wrote #302885:
in both cases newly uploaded images are only known by TXP instance itself and not by the other one, right?
Correct. Whichever Txp instance you use to upload will “know” about the image because it will have the metadata and image ID in the database. The other one will be blissfully unaware of anything and if you ask for <txp:image id="42" />
that you just uploaded in (say) master, the slave will shrug and return ‘no image’.
The problem is that Textpattern uses the database to determine if an image “exists” and then goes to the filesystem to check. I forgot about that fundamental behaviour when I posted earlier. Hence the only way to get it to work is to also switch the DB connection when you ask for something image-related. rah_swap is your best friend here, when you get it working.
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
Re: Two textpattern instances with one image folder
Hi
Maybe if you use same DB with different prefix, and create a clone table of image that serve as image table for one textpattern (txp_image cloned as prefix_txp_image) install, you should be able to use both textpattern install to access and modify images.
I tested it last year and it worked.
Cheers.
Offline
Re: Two textpattern instances with one image folder
Think I also had that in the past but can´t remember how I did it. Where would I have to tweak textpattern to tell that it takes this cloned txp_image table as master table for images?
I think that would be the perfect solution to make an excuse with the txp_image and both use it centraly.
Another approach – because unfortunately I can`t get rah_swap working – is this:
<txp:smd_query query='SELECT image FROM textpattern WHERE (id = <txp:article_id/>)'><img src="../images_txp/{image}.jpg" alt="" title=""></txp:smd_query>
I will fiddle around a bit with join to also get the extension. Image categories are not that important. for me. That will let me show an image even when its not in one instance. For this both instances have to be in the same DB. but that´s what I wanted to do anyway.
But your solution should be better I guess.
Last edited by demoncleaner (2016-11-15 15:49:17)
Offline
Re: Two textpattern instances with one image folder
Hi
You have nothing to change on textpattern, when you install textpattern you have a txp_image table DB created, if you have a second textpattern install with the same DB using a prefixe “prefix_” you will have a prefixe_txp_image created, go to phpmyadmin, delete that table and create a clone of txp_image and call it prefixe_txp_image and that s all.
Cheers.
Offline
Re: Two textpattern instances with one image folder
I don’t understand how either of those work, but I could be slow on the uptake ;-)
With dragondz’s suggestion, you can access and replace an image from both textpattern instances. That would work as long as nothing much changes, but how do you keep the two cloned txp_image tables in sync when actual details, e.g caption etc. are modified or new images are added? You’d have to re-clone, or have i missed something?
With smd_query, aren’t you essentially just getting at <txp:custom_field name="article_image" />
. You can plug that into the id
attribute of txp:images
or txp:image_url
to get the full image name/path. And, if you want to replace part of the path, you could wrap that with rah_replace or smd_wrap…
PS: @demoncleaner “because unfortunately I can’t get rah_swap working” … see your other post
TXP Builders – finely-crafted code, design and txp
Offline
Re: Two textpattern instances with one image folder
I also do not quite get what Dragonz tries to explain. If I do so I will just have a clone of all so far posted images but no track n sync for further uploads.
What I did with smd_query to get the image of the other instance is now this:
<txp:smd_query query='SELECT t.image, i.ext FROM textpattern t JOIN txp_image i ON t.image = i.id WHERE (t.id = <txp:article_id/>)'><img src="../images_txp/{image}{ext}" alt="" /></txp:smd_query>
Which works fine. Where as your jakob would have been easier =).
But like this you would still go with the Article Image input.
Offline
Re: Two textpattern instances with one image folder
I have forgotten that etc_query
can query any db (under current credentials):
<txp:etc_query url="master_base"
data='SELECT * FROM txp_image WHERE id IN(<txp:custom_field name="article_image" />)'
>
<img src="../images_txp/{name?}" alt="{alt?}" title="{caption?}" />
</txp:etc_query>
should retrieve image info from your “master” txp db.
Offline
Re: Two textpattern instances with one image folder
Even better. Thanks. But it would have to be {id?} instead of {name?}, right?
This solution works for me now. But would be cooler to still be able to work with images on the backend as usual.
Do you see any way to tell the textpattern backend it should forget about its prefix when it deals with txp_image table? So that the image handling on the backend side could also be concentrated on one and the same table? Assuming that all installs of TXP use the same DB of course.
There should be a point in the core where the prefix is set in front of txp_image. If I could avoid that and my en_textpattern is using my txp_image instead of en_txp_image that would be perfect. I won´t use image categories.
Offline
Re: Two textpattern instances with one image folder
demoncleaner wrote #302911:
But it would have to be {id?} instead of {name?}, right?
Not sure, look in txp_image
table.
There should be a point in the core where the prefix is set in front of txp_image. If I could avoid that and my en_textpattern is using my txp_image instead of en_txp_image that would be perfect. I won´t use image categories.
Sure, you could use image
callback and change global DB->table_prefix
(in 4.6), but image categories and authors would be looked for in wrong tables.
Offline
Re: Two textpattern instances with one image folder
I am not sure what the image callback is. Could you give me a hint?
Authors and Categories I would not need.
What would be important is, that I could also give a list of image IDs like 2,4,8 in custom_field and use it with the ect_query trick to generate a slider for example.
With one image I got it running already. What if I want to have several images on an article, use a custom_field + ect_query to get the job done?
Offline
Re: Two textpattern instances with one image folder
demoncleaner wrote #302917:
I am not sure what the image callback is. Could you give me a hint?
Authors and Categories I would not need.
Sorry, have no time to test right now, will do later
What would be important is, that I could also give a list of image IDs like 2,4,8 in custom_field and use it with the ect_query trick to generate a slider for example.
With one image I got it running already. What if I want to have several images on an article, use a custom_field + ect_query to get the job done?
The id IN(...)
query above should be fine if you store image ids in Article image field.
Offline
Re: Two textpattern instances with one image folder
Ah ok sure. Sorry. Should have tested myself before according to the IN…
For the callback I will try to see if I get any further and keep posting here in case.
Offline