在多个应用程序之间共享TinyMCE插件

Sharing TinyMCE plugin across multiple applications

本文关键字:共享 TinyMCE 插件 之间 应用程序      更新时间:2023-09-26

我使用的是CakePHP 2.4.7和来自cakeedc的TinyMCE插件。

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

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

我现在得到这个错误时,试图加载编辑器:

Fatal Error (4): syntax Error, unexpected T_CONSTANT_ENCAPSED_STRING in [/xyz/Plugin/TinyMCE/webroot/js/tiny_mce/tiny_mce.js, line 1]

我应该如何开始调试这个?

解决方案尝试

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

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

<<p>看到strong> https://github.com/.../2.4.7/lib/Cake/Routing/Filter/AssetDispatcher.php L159-L160

一个非常烦人的,而且,如果你问我的话,因为它是未记录的和非可选的,危险的行为。

自定义资产调度程序

如果你想继续使用插件资产分派器,扩展内置的一个,并重新实现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

不要只禁用短打开标签

我在这里只是猜测,但它在其他服务器上工作的原因可能是短开放标记(即<?)被禁用。然而,即使这是你的新服务器上的问题,这不是你应该依赖的东西,资产仍然使用include()服务,你很可能不想检查所有第三方CSS/JS在每次更新时可能的PHP代码注入。