跨多个应用程序共享 TinyMCE 插件 [英] Sharing TinyMCE plugin across multiple applications
问题描述
我使用的是 CakePHP 2.4.7 和 CakeDC 的 TinyMCE 插件.
I'm using CakePHP 2.4.7 and the TinyMCE plugin from CakeDC.
我在服务器上的共享位置设置了我的 CakePHP 核心和插件,以便多个应用程序可以访问它.这使我不必更新 TinyMCE 的多个副本.在我迁移到新服务器并更新软件之前,一切都运行良好.
I set up my CakePHP core along with the plugin in a shared location on my server so that multiple applications can access it. This keeps me from having to update multiple copies of TinyMCE. Everything was working well until I migrated to a new server and updated software.
新服务器运行的是 Apache 2.4 而不是 2.2,并且使用 mod_ruid2 而不是 suexec.
The new server is running Apache 2.4 instead of 2.2 and using mod_ruid2 instead of suexec.
我现在在尝试加载编辑器时收到此错误:
I now get this error when trying to load the editor:
致命错误 (4):语法错误,意外的 T_CONSTANT_ENCAPSED_STRING 在 [/xyz/Plugin/TinyMCE/webroot/js/tiny_mce/tiny_mce.js, line 1]
我应该如何开始调试?
我尝试将符号链接从应用程序的 webroot 添加到 TinyMCE 的插件 webroot.这是因为它加载了 js 文件和编辑器,但是 TinyMCE 插件在错误的当前目录上工作,文件管理不会分开.
I tried adding a symlink from an application's webroot to TinyMCE's plugin webroot. This works in that it loads the js file and the editor, but then TinyMCE plugins are working on the wrong current directory and file management would not be separated.
推荐答案
问题在于AssetDispatcher
过滤器,它包括css
和js
文件使用 PHPs include()
语句,导致文件通过 PHP 解析器发送,在那里它会偶然发现 TinyMCE 脚本中 的出现.
The problem is the AssetDispatcher
filter, it includes css
and js
files using PHPs include()
statement, causing the files to be sent through the PHP parser, where it will stumble over the occurrences of <?
in the TinyMCE script.
参见<强>https://github.com/.../2.4.7/lib/Cake/Routing/Filter/AssetDispatcher.php#L159-L160
如果你问我,这是一个非常烦人的,而且,因为它是无证和非可选的,危险的行为.
A very annoying, and, since it's undocumented and non-optional, dangerous behavior if you ask me.
如果您想继续使用插件资产调度程序,请扩展内置的调度程序,并重新实现 AssetDispatcher::_deliverAsset()
方法并删除包含功能.当然,这有点烦人,维护明智,但这是一个非常快速的解决方案.
In case you want to continue to use a plugin asset dispatcher, extend the built in one, and reimplement the AssetDispatcher::_deliverAsset()
method with the include functionality removed. Of course this is kinda annoying, maintenance wise, but it's a pretty quick fix.
类似于:
// app/Routing/Filter/MyAssetDispatcher.php
App::uses('AssetDispatcher', 'Routing/Filter');
class MyAssetDispatcher extends AssetDispatcher {
protected function _deliverAsset(CakeResponse $response, $assetFile, $ext) {
// see the source of your CakePHP core for the
// actual code that you'd need to reimpelment
ob_start();
$compressionEnabled = Configure::read('Asset.compress') && $response->compress();
if ($response->type($ext) == $ext) {
$contentType = 'application/octet-stream';
$agent = env('HTTP_USER_AGENT');
if (preg_match('%Opera(/| )([0-9].[0-9]{1,2})%', $agent) || preg_match('/MSIE ([0-9].[0-9]{1,2})/', $agent)) {
$contentType = 'application/octetstream';
}
$response->type($contentType);
}
if (!$compressionEnabled) {
$response->header('Content-Length', filesize($assetFile));
}
$response->cache(filemtime($assetFile));
$response->send();
ob_clean();
// instead of the possible `include()` in the original
// methods source, use `readfile()` only
readfile($assetFile);
if ($compressionEnabled) {
ob_end_flush();
}
}
}
// app/Config/bootstrap.php
Configure::write('Dispatcher.filters', array(
'MyAssetDispatcher', // instead of AssetDispatcher
// ...
));
另见http://book.cakephp.org/2.0/en/development/dispatch-filters.html
See also http://book.cakephp.org/2.0/en/development/dispatch-filters.html
我只是在这里猜测,但它在您的其他服务器上运行的原因可能是 短开放标签(即<?
)被禁用.但是,即使这是您的新服务器上的问题,这也不是您应该依赖的东西,资产仍在使用 include()
提供服务,您很可能不想检查您所有的第三方 CSS/JS,以便在每次更新时注入可能的 PHP 代码.
I'm just guessig here, but the reason why it was working on your other server probably is that short open tags (ie <?
) where disabled. However even if that is the problem on your new server, this isn't something you should rely on, the assets are still being served using include()
, and you most probably don't want to check all your third party CSS/JS for possible PHP code injections on every update.
这篇关于跨多个应用程序共享 TinyMCE 插件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!