Jump to content

Textarea: Insert image path problem


Recommended Posts

Hope this is the right place for this.

Following scenario:

PW is running on my localhost:

http://localhost/mysite

when I insert an image into the textarea the path is like this: "/mysite/site/assets/files/1028/berlin.jpg"

Then I changed to a development host name, which point to the same directory:

http://mysite.dev

Then all the inserted images do no work anymore, because obviously "/mysite/site/assets/" does not exists, it then should be "/site/assets/"

Since the image path is written in this plain form into the db, this kind of inflexible.

Any solution to this?

Edit: It sure could be done easily with a .htacces rewrite:

RewriteRule ^mysite/(.*) $1

but I'd consider this hacky then.

Link to post
Share on other sites

I am not sure on the recommended way of avoiding this scenario in the first place, but you could run some SQL to change those links.

Something like:

UPDATE field_body SET data = REPLACE( data, '/mysite', '' )
 

This is untested and as with any manual DB manipulation, make sure you have a good backup first.

Link to post
Share on other sites

know this is kind of obvious, but the last time i did that i just ran a replacement on the content with the api..

<?php 
		$ps = $pages->find("template=basic-page");	
		foreach($ps as $p) {
			$p->setOutputFormatting(false);
			$new = str_replace('mysite/', '', $p->body);
			$p->body = $new;
			$p->save();
		}
?>
  • Like 2
Link to post
Share on other sites

Hey Macrura - good idea - for some reason I always resort to sql when it comes to these one off manipulations.

Off topic, but I wonder if a module that allowed you to run code snippets would be a good idea. It could perhaps even have a library of examples to deal with common issues like this, and the ability to store/share your own snippets. Kind if along the lines of Nik's excellent SelectorTest. Ideally it would report all the changes made etc.

Link to post
Share on other sites

well i picked up the idea from Soma to always have a 'tools.inc' file in my template folder.

Then in that file i paste in the code to run, load that page, and the commands execute. I'm keeping these various snippets in codebox snippets.

I agree that this method seems a little arcane, but it works well; makes it very easy to manipulate your data...just have to be careful since you're mass editing..

Back in my joomla days i used nonumber.nl DB replacer, which enabled you to do this kind of thing, and be able to preview the changes to the data, which was nice;

this PW api technique is more powerful though; i make a lot of backups to my sites when i'm working on them, so in the event something goes awry i can revert..

so to sum up - YES! it would be great to have this in the backend, and even be able to preview the changes.. if someone out there likes to write a module...i would support it in any way i could.

Link to post
Share on other sites

when I insert an image into the textarea the path is like this: "/mysite/site/assets/files/1028/berlin.jpg"

...

Then all the inserted images do no work anymore, because obviously "/mysite/site/assets/" does not exists, it then should be "/site/assets/"

Since the image path is written in this plain form into the db, this kind of inflexible.

Any solution to this?

Hi owzim, I'm a bit curious, but you have set up local and online-dev host yourself? If yes, you shouldn't setup them that different when using absolute image-pathes in textareas ;)

But to be serious again, - and besides the good solutions from the others on how to adjust it, - you may take a look to somas Images Manager for future projects:

...

Or you can enter the id directly:

{image=1033, width=100}
Once inserted into a textarea field it will get parsed when saved and loaded automaticly. It will store an abstract id tag in Database and convert it back to the image HTML tag. So after first save you'll see the image inserted in a Wysiwyg and be able to resize and place it as usual. ...
Link to post
Share on other sites

I develop all my sites of subdirectories on localhost, but when migrating them they usually aren't running off subdirs. I usually load the DB sql file into my text editor and do a search/replace "/mysite/" => "/", before migrating the DB to the live site. But it won't be long before we have this task taken care of internally without any need to do replacements. 

  • Like 2
Link to post
Share on other sites

...  

PW is running on my localhost:

http://localhost/mysite

...

Ooh, - now I've got it right: the problem are not the ImagePathes in Textareas but _all_ pathes because you setup different sites like http://localhost/mysite1/ , http://localhost/mysite2/ , ...

---

You may use Apache with vHosts and generic names like: http://pw1.machine.local/ , http://pw2.machine.local/ , http://pw3.machine.local/ , ...

---

Maybe one could use basic httpd.conf (without http-vhosts.conf) and edit two lines in it:

#DocumentRoot "C:/Apache2/htdocs"

DocumentRoot "C:/WEBSITES/pw1/htdocs"

#DocumentRoot "C:/WEBSITES/pw2/htdocs"

and

#<Directory "C:/Apache2/htdocs">

<Directory "C:/WEBSITES/pw1/htdocs">

#<Directory "C:/WEBSITES/pw2/htdocs">

to match the systempath of the site you are actually working on?

---

or you may have one Docroot and Directory in httpd.conf pointing to for example "C:/Apache2/website/htdocs" and in filesystem you have folders for your sites like

C:/Apache2/website.PW1/htdocs

C:/Apache2/website.PW2/htdocs

C:/Apache2/website.PW3/htdocs

 and you alter the path to C:/Apache2/website/htdocs for the site you work on. This only needs one edit and Apache restart isn't necessary.

--- I go with the vhosts :-) 

Link to post
Share on other sites
Ooh, - now I've got it right: the problem are not the ImagePathes in Textareas but _all_ pathes because you setup different sites like

I think that file/image/page URLs in textareas are the only place where the issue can occur. It happens just because editors like TinyMCE are storing ready-to-output HTML. Everywhere else in ProcessWire (except cache files), everything is stored as references, so it doesn't matter where the site is running. Our eventual built-in solution will just ensure that any local URLs in textareas are always saved as if the site were running from root (via the sleepValue function), and prepend any subdirs to root paths at runtime (via the wakeupValue function). 

  • Like 1
Link to post
Share on other sites

... Our eventual built-in solution will just ensure that any local URLs in textareas are always saved as if the site were running from root (via the sleepValue function), and prepend any subdirs to root paths at runtime (via the wakeupValue function).

Ryan, that's great!

It's that kind of great things one will find lots when starting to work with PW.  :wub:

In the past there were so much things that couldn't achvied or only with clumpsy workarounds. I just have to learn to think more positive and first try to find the most simplest solution, than look into PW to realise that it is almost in, or sometimes to get surprised that there even is a more comfortable and easier solution than that I could imagine.

Edited by horst
Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By prestoav
      Hi all and thanks for the great work on PW!

      One thing I find I have to do on any new site is add the Justify plugin to textarea fields as it is such a widely required feature for text headings in content.

      ANy chance this could be added to the core an automatically be installed on new textarea fields using CKEditor?

      Thank you!
    • By Guy Incognito
      Have read loads of similar threads but can't find the deifnitive answer. I'm bootstrapping ProcessWire into a Magento installation. Everything is working fine in terms of expected PW API functionality, however I cannot get the paths for images in the site work correctly.
      ProcessWire is installed in a subfolder called 'pw'.
      If I load the PW site directly e.g. visit mainsite.com/pw everything loads fine and all image paths are correct. If I load the parent site in the root folder with the PW bootstrapped page content rendered within it, the image paths don't contain the subfolder and so are broken. So I get
      https://mainsiteexample.com/site/templates/img/test.jpg instead of
      https://mainsiteexample.com/pw/site/templates/img/test.jpg I've tried updating the rewrite base in the .htaccess file but it doesn't seem to make any difference. Have also tried various settings in the config file to no avail. Wondering if rewrite base perhaps isn't working as intended because I'm behind a NGINX/Apache hybrid environment?
    • By Guy Incognito
      I'm trying to make an AJAX call from within a template to a php script within my templates folder, but I'm getting a 404 from all URLs. Is there a proper way to directly address scripts within PW templates? I've read it will work in the site root, but I'd rather keep all the code together if possible.
    • By louisstephens
      So, I am not even sure if this is possible, but I thought I would ask anyway. I was building a "system" that would make some modals (izimodal) using a few fields. A user would select the color combo they want, enter a title, fill out the body, and then I was going to pass this (in the template) to fill in the modal. I have this all working pretty flawlessly.
      <div id="example-modal" class="model" data-izimodal-autoopen data-izimodal-transitionin="fadeInDown" data-izimodal-iframeURL="<?php echo $page->example->url; ?>"></div> <script type="text/javascript"> $("#ca-entrance-modal").iziModal({ title: 'Custom Title Here', subtitle: '', headerColor: 'Custom Color Here', history: false, iframe : true, fullscreen: false, loop: false, width: 350, iframeHeight: 350, top: null, bottom: null, borderBottom: false, closeButton: true, }); </script> However, I have hit a road block. The modals are using iframes to pull in the corresponding modal page, but the javascript options are not being iframed (so the modal will actually launch etc). My thought was the user can just copy the page link to the modal, and insert it into the iframe and simply adding the js code, the modal would work (which it does).
      I guess here is my actually problem. Since the user is selecting several options to "customize" the modal, the javascript is custom and differs between each modal. Is there a way to "disable" a textarea, and output the "custom" javascript inside the textarea so they can copy it for inclusion on their actual pages?
       
      Or, is this something that I should just output in the frontend view for users.
    • By kalimati
      I am using sanitizer->textarea to sanitize and format the message inputted. I've tried various options including newlineReplacement but have been unable to convert newlines to <br> tags. Although the PHP nl2br function works as expected. Any suggestions?
      Thanks.
×
×
  • Create New...