Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2009-08-04 04:18:59

jaredigital
Member
From: Texas
Registered: 2004-10-26
Posts: 26
Website

[textile] !imageurl! hard-codes URL in MySQL

This is an interesting one, and by “interesting” I mean “great, now I have to go back in and edit a bajillion articles.” :)

<txp:site_url /> was not working inside the Content > Write Body field on localhost, so I resorted to using Textile’s !imageurl! syntax, which did work. Unfortunately, TXP is hardcoding the image path that !imageurl! generates inside the MySQL > textpattern > Body_html table. This means that when the DB is exported, all the image paths are wrong (mine are hardcoded to localhost root — not really useful on my live site).

If I open each article to edit, change nothing, and just re-publish it, the path fixes itself to point back to the correct base URL.

Is this on the developers’ radar? Seems like it could be an easy fix. In the meantime, I guess I’ll be reading up on how to find & replace in MySQL. :(

Last edited by jaredigital (2009-08-04 04:19:21)

Offline

#2 2009-08-04 05:09:32

wet
Developer Emeritus
From: Schoerfling, Austria
Registered: 2005-06-06
Posts: 3,324
Website Mastodon

Re: [textile] !imageurl! hard-codes URL in MySQL

Textile uses the current site’s URL to build the img src attribute at the very moment it generates HTML from Textile if you use relative URLs for !imgurl!, i.e. URLs without a protocol and host part. This is done whenever an article is saved. If you move the site and resave articles later on, a new img src will result.

This is intended behaviour. There are other ways if you need more portability, e.g. <txp:image /> is a tag which renders the img element dynamically upon each request.

Offline

#3 2009-08-04 05:22:49

jaredigital
Member
From: Texas
Registered: 2004-10-26
Posts: 26
Website

Re: [textile] !imageurl! hard-codes URL in MySQL

Ah, I see. Any ideas on how to get <txp:site_url /> to work inside an article on localhost?

Offline

#4 2009-08-04 11:41:14

jsoo
Plugin Author
From: NC, USA
Registered: 2004-11-15
Posts: 1,793
Website

Re: [textile] !imageurl! hard-codes URL in MySQL

In what way is it not working? It works as expected for me.


Code is topiary

Offline

#5 2009-08-04 14:19:41

jaredigital
Member
From: Texas
Registered: 2004-10-26
Posts: 26
Website

Re: [textile] !imageurl! hard-codes URL in MySQL

When I use <txp:site_url /> in the Write > Body field, all it does is output the image path in text. But the tag works fine on my web host. It’s just localhost that does not do it right. I’ve tested on 2 different MAMP installations on 2 different computers with the same results. Maybe it’s a MAMP thing?

Offline

#6 2009-08-04 14:49:31

jsoo
Plugin Author
From: NC, USA
Registered: 2004-11-15
Posts: 1,793
Website

Re: [textile] !imageurl! hard-codes URL in MySQL

jaredigital wrote:

When I use <txp:site_url /> in the Write > Body field, all it does is output the image path in text. But the tag works fine on my web host. It’s just localhost that does not do it right. I’ve tested on 2 different MAMP installations on 2 different computers with the same results. Maybe it’s a MAMP thing?

Might be; I wouldn’t know as I don’t use MAMP. What output are you getting? At any rate, is there any reason not to use <txp:image /> as wet suggests?


Code is topiary

Offline

#7 2009-08-04 15:01:57

jaredigital
Member
From: Texas
Registered: 2004-10-26
Posts: 26
Website

Re: [textile] !imageurl! hard-codes URL in MySQL

On localhost, using <txp:site_url /> outputs text. So where there should be an image is instead a line of text, like http://localhost:8888/jaredigital/image.png. when I use the tag in the same exact context on my live site, online, the image displays as expected.

I can’t use <txp:image /> because these particular images have not been uploaded via the TXP image tab so there is no ID to reference.

It’s not a huge deal, as I was able to figure out how to search & replace the incorrect URL on all those images in MySQL. I just think it’s weird that within an environment like TXP, where pretty much everything can (and should) be relative to a moveable root, !imageurl! is not. Threw me for a loop. :o

Offline

#8 2009-08-04 15:12:14

jsoo
Plugin Author
From: NC, USA
Registered: 2004-11-15
Posts: 1,793
Website

Re: [textile] !imageurl! hard-codes URL in MySQL

jaredigital wrote:

On localhost, using <txp:site_url /> outputs text.

As it should — that’s all the tag does.

So where there should be an image is instead a line of text, like http://localhost:8888/jaredigital/image.png. when I use the tag in the same exact context on my live site, online, the image displays as expected.

What is the context? There’s no way that <txp:site_url /> can produce an image by itself. Surely you are using something like <img src="<txp:site_url />image.png" />?

I just think it’s weird that within an environment like TXP, where pretty much everything can (and should) be relative to a moveable root, !imageurl! is not.

I agree, it’s a bit weird, and not what I would have expected either.


Code is topiary

Offline

#9 2009-08-04 15:32:45

jaredigital
Member
From: Texas
Registered: 2004-10-26
Posts: 26
Website

Re: [textile] !imageurl! hard-codes URL in MySQL

What is the context? There’s no way that <txp:site_url /> can produce an image by itself. Surely you are using something like <img src=”<txp:site_url />image.png” />?

Sorry, I got a little mixed up there. :) Yes, I am trying to use <img src="<txp:site_url />image.png" /> in an article body on localhost. That outputs a broken image. When I view source, I see this: <p><img src="http://localhost:8888/jaredigital/image.png” /&gt;</p> Characters at the end are getting converted to unicode (it’s unicode, right?), which breaks the image. Very odd.

Last edited by jaredigital (2009-08-04 15:33:11)

Offline

#10 2009-08-04 15:42:47

els
Moderator
From: The Netherlands
Registered: 2004-06-06
Posts: 7,458

Re: [textile] !imageurl! hard-codes URL in MySQL

Could be Textile. Try

==<img src="<txp:site_url />image.png" />==

or

notextile. <img src="<txp:site_url />image.png" />

Offline

#11 2009-08-04 16:09:19

jaredigital
Member
From: Texas
Registered: 2004-10-26
Posts: 26
Website

Re: [textile] !imageurl! hard-codes URL in MySQL

Thanks, Els!

Both of those work, though notextile. also removes the <p> tags from around the image, which is great. Awesome! I have found my solution! :)

Offline

Board footer

Powered by FluxBB