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

标签 javascript cakephp tinymce assets

我正在使用 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 调度程序

如果您想继续使用插件资源调度程序,请扩展内置资源调度程序,并重新实现 AssetDispatcher::_deliverAsset()删除了包含功能的方法。当然,从维护 Angular 来看,这有点烦人,但这是一个非常快速的解决方案。

类似于:

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

相关文章:

TinyMCE 没有在菜单中提供 Bullist 或 numlist 图标

javascript - 使用 d3 的 chrome 扩展

JavaScript,计算器中的输出

php - 使用 PHP 和 JavaScript 验证表单?

php - 从Web管理界面提取数据

mysql - CakePhp根据经纬度从数据库获取结果

php - 如何从 CakePHP 2.9 中的 ownTo 模型获取数据

javascript - 使用ajax抓取表单数据

css - TinyMCE 默认字体未通过表单提交

php - 每个用户在 TinyMCE 的 iBrowser 中都有自己的图像文件夹