Problems with TinyMCE / MCImageManager

I have all kinds of weird path problems in tinyMCE. I'm not sure if this is due to MCImageManaI will try to summarize my setup:

I have a .NET site. At the moment, the root of the application is at http: // localhost / APP /

tiny_mce is located in ~ / tiny_mce, the imagemanager plugin is, of course, located in ~ / tiny_mce / plugins / imagemanager

~ / uploads is where I want the images to be uploaded / managed

~ / tiny_mce / plugins / imagemanager / web.config contains this key: <add key="filesystem.rootpath" value="../../../upload" />

It also contains <add key="preview.urlprefix" value="{proto}://{host}/APP/" /> to take into account that the root of the application does not belong to the root of the host name (unfortunately, I do not need to specify hard this .... but this is another problem)

So far so good - when I look at the image dialog in tinyMCE, I get the image browser and look at the correct folder

Oddities begin when I select an image. Here, what is placed in the "Image URL" field in the "Insert / edit image" form:

../APPot/downloads/Image.jpg

APPot? What the heck? Shouldn't it be "upload / Image.JPG"?

It was with

 tinyMCE.init({ //..... relative_urls: true, remove_script_host: true, document_base_url: 'http://localhost/APP/' }); 

and

 mcImageManager.init({ relative_urls: true, remove_script_host: true, document_base_url: 'http://localhost/APP/' }); 

I can’t say whether this second one is needed or even something to do.

where is "from"? I suppose its existence is explained by why it cannot understand how to use document_base_url.

If I reset the url prefix to the original parameter: <add key="preview.urlprefix" value="{proto}://{host}/" /> , I get:

../downloads/DSCF0546.JPG

which actually seems a little closer. There is no "ot", but it is a directory.

Does anyone know what is going on?

+4
source share
2 answers

TL DR

Configuration example

  • Your network www.example.com has DocumentRoot /var/www-data/
  • you upload images to /var/www/uploads/images
  • you serve your images from vhost static.example.com with DocumentRoot /var/www

Related settings

  • set preview.wwwroot to /var/www
  • set filesystem.rootpath to /var/www/uploads/images
  • set preview.urlprefix to http://static.example.com (or //static.example.com )

Extended explanation

It is joyfully encoded when wild 'ds appears!

The problem is related to Moxiecode_ManagerEngine::convertPathToURI , which uses the code fragment $uri = substr($abs_path, strlen($root)); where $abs_path is the "server" path ( /var/www/uploads/images/image.png ) and $root - $root = $this->getSiteRoot(); . By default, MCIE tries to "guess" the siteroot URL (it considers incorrect /var/www-data/ ). In my case, I saved the downloaded files to another server, where siteurl was a little different. So substr removed the completely unrelated part of $abs_path

 substr('/var/www/uploads/images/image.png', strlen('/var/www-data/')) == 'ds/images/image.png' 

To fix this, you need to set the preview.wwwroot config directive. If installed, it returns from getSiteRoot and is partitioned accordingly.

 substr('/var/www/uploads/images/image.png', strlen('/var/www/')) == 'uploads/images/image.png' 

The code Moxiecode_ManagerEngine::convertPathToURI is dumb and needs to be fixed, but this solution is pretty good.

+1
source

Since relative_urls: true, document_based_url used to generate the path. Try setting relative_urls: to false. Here is some documentation that explains the options:

0
source

Source: https://habr.com/ru/post/1286713/


All Articles