TinyMCE:如何在上传图像时保持相对 URL,但在使用 "insert link" 选项时使用绝对 URL?
TinyMCE: How do you keep relative URLs when uploading images BUT use absolute URL when using "insert link" option?
TinyMCE 版本:4.3.10
图片上传插件:jbimages
我需要存储两个图像的绝对路径以及添加到表单中的任何 link,以便可以通过电子邮件发送消息。但是,切换 "relative_urls" 会弄乱其中之一。
例如:
relative_urls: 真
此设置会产生正确的 links。但是,通过 jbimages 上传的任何图像都会导致相对 links,这对电子邮件不利。图像存储为 "images/21312.png"。这不会在电子邮件中打开,因为它缺少域前缀。
relative_urls: 假
当通过 jbimages 上传时,此设置会生成正确的图像 URLs。但是,所有其他 link 都以文档根 URL 为前缀。换句话说,link 添加为 "example.org" 变成 "www.example.com/example.org",其中 example.com 是我的域根。
理想的结果是将 link 保存为绝对的而不是前缀,而上传的图像以域的 URL.
为前缀
如果没有设置适应上述情况,是否有其他插件允许将图片上传到正文中?我尝试了拖放操作,但这会将图像转换为 base64,但并不总是能正常工作。
谢谢
我会看看这个附加参数:
https://www.tinymce.com/docs/configure/url-handling/#remove_script_host
根据文档:
If this option is enabled the protocol and host part of the URLs
returned will be removed. This option is only used if the relative_urls option is set to false
If disabled, URLs will be returned in this format:
http://www.example.com/somedir/somefile.htm
instead of the default
format: /somedir/somefile.htm
.
URL 操纵的整个主题在此处回顾:https://www.tinymce.com/docs/configure/url-handling/
如果除 JBImages 插件外一切正常,我会询问插件创建者是否有任何可以更改的设置来解决此问题。
在@Michael Fromin 的帮助下,我结合他的 answer/comment:
解决了这个问题
我需要设置以下内容:
relative_urls: true
remove_script_host: false
urlconverter_callback : 'customURLConverter'
对于 customURLConverter 函数,我使用了这个:
function customURLConverter(url, node, on_save, name)
{
var checkURL;
var urlPrefix;
// Get the first 7 characters of the string
checkURL = url.substring(0, 7);
// Determine if those characters are coming from the image uploader
if(checkURL === "/system")
{
// prefix the incoming URL with my domain
urlPrefix = 'https://www.example.com';
url = urlPrefix.concat(url);
}
// Return URL
return url;
}
在我的用例中,我使用 jbimages 上传的图像中的 URL 是可预测的,因此我可以检查其中的前 X 个字符。没有任何人(在我的站点中)会链接到以“/system”开头的 URL,因此我始终可以安全地假设来自 TinyMCE 的任何以“/system”开头的 URL " 是上传的图片。
尝试在配置中添加 tinyMCE :
convert_urls : 0
TinyMCE 版本:4.3.10
图片上传插件:jbimages
我需要存储两个图像的绝对路径以及添加到表单中的任何 link,以便可以通过电子邮件发送消息。但是,切换 "relative_urls" 会弄乱其中之一。
例如:
relative_urls: 真
此设置会产生正确的 links。但是,通过 jbimages 上传的任何图像都会导致相对 links,这对电子邮件不利。图像存储为 "images/21312.png"。这不会在电子邮件中打开,因为它缺少域前缀。
relative_urls: 假
当通过 jbimages 上传时,此设置会生成正确的图像 URLs。但是,所有其他 link 都以文档根 URL 为前缀。换句话说,link 添加为 "example.org" 变成 "www.example.com/example.org",其中 example.com 是我的域根。
理想的结果是将 link 保存为绝对的而不是前缀,而上传的图像以域的 URL.
为前缀如果没有设置适应上述情况,是否有其他插件允许将图片上传到正文中?我尝试了拖放操作,但这会将图像转换为 base64,但并不总是能正常工作。
谢谢
我会看看这个附加参数:
https://www.tinymce.com/docs/configure/url-handling/#remove_script_host
根据文档:
If this option is enabled the protocol and host part of the URLs returned will be removed. This option is only used if the relative_urls option is set to false
If disabled, URLs will be returned in this format:
http://www.example.com/somedir/somefile.htm
instead of the default format:/somedir/somefile.htm
.
URL 操纵的整个主题在此处回顾:https://www.tinymce.com/docs/configure/url-handling/
如果除 JBImages 插件外一切正常,我会询问插件创建者是否有任何可以更改的设置来解决此问题。
在@Michael Fromin 的帮助下,我结合他的 answer/comment:
解决了这个问题我需要设置以下内容:
relative_urls: true
remove_script_host: false
urlconverter_callback : 'customURLConverter'
对于 customURLConverter 函数,我使用了这个:
function customURLConverter(url, node, on_save, name)
{
var checkURL;
var urlPrefix;
// Get the first 7 characters of the string
checkURL = url.substring(0, 7);
// Determine if those characters are coming from the image uploader
if(checkURL === "/system")
{
// prefix the incoming URL with my domain
urlPrefix = 'https://www.example.com';
url = urlPrefix.concat(url);
}
// Return URL
return url;
}
在我的用例中,我使用 jbimages 上传的图像中的 URL 是可预测的,因此我可以检查其中的前 X 个字符。没有任何人(在我的站点中)会链接到以“/system”开头的 URL,因此我始终可以安全地假设来自 TinyMCE 的任何以“/system”开头的 URL " 是上传的图片。
尝试在配置中添加 tinyMCE :
convert_urls : 0