gpt4 book ai didi

javascript - 跨多个应用程序共享 TinyMCE 插件

转载 作者:行者123 更新时间:2023-11-29 19:38:46 27 4
gpt4 key购买 nike

我正在使用 CakePHP 2.4.7 和 CakeDC 的 TinyMCE 插件。

我在服务器上的一个共享位置设置了我的 CakePHP 核心和插件,以便多个应用程序可以访问它。这使我不必更新 TinyMCE 的多个副本。在我迁移到新服务器并更新软件之前,一切都运行良好。

新服务器运行 Apache 2.4 而不是 2.2,并使用 mod_ruid2 而不是 suexec。

我现在在尝试加载编辑器时遇到此错误:

fatal error (4):语法错误,[/xyz/Plugin/TinyMCE/webroot/js/tiny_mce/tiny_mce.js,第 1 行] 中的意外 T_CONSTANT_ENCAPSED_STRING

我应该如何开始调试它?

解决方法尝试

我尝试添加一个从应用程序的 webroot 到 TinyMCE 的插件 webroot 的符号链接(symbolic link)。这是因为它加载了 js 文件和编辑器,但是 TinyMCE 插件在错误的当前目录上工作,文件管理不会分开。

最佳答案

问题是 AssetDispatcher过滤器,它包括 cssjs使用 PHP 的文件 include()语句,导致文件通过 PHP 解析器发送,在那里它会偶然发现 <? 的出现在 TinyMCE 脚本中。

参见 https://github.com/.../2.4.7/lib/Cake/Routing/Filter/AssetDispatcher.php#L159-L160

如果你问我,这是一种非常烦人的行为,而且,因为它是无证且非可选的,所以是危险的行为。

自定义 Assets 调度器

如果您想继续使用插件 Assets 分配器,请扩展内置的分配器,并重新实现 AssetDispatcher::_deliverAsset()删除了包含功能的方法。当然,这在维护方面有点烦人,但这是一个非常快速的修复。

类似于:

// 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

不要只禁用短的开放标签

我只是猜测,但它在您的其他服务器上运行的原因可能是 short open tags (即 <? )禁用的地方。然而,即使这是您的新服务器上的问题,这也不是您应该依赖的东西, Assets 仍在使用 include() 提供服务。 ,并且您很可能不想在每次更新时都检查所有第三方 CSS/JS 是否存在可能的 PHP 代码注入(inject)。

关于javascript - 跨多个应用程序共享 TinyMCE 插件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24266294/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com