簡體   English   中英

在多個應用程序之間共享TinyMCE插件

[英]Sharing TinyMCE plugin across multiple applications

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

我在服務器上的共享位置中設置了CakePHP核心以及插件,以便多個應用程序可以訪問它。 這使我不必更新TinyMCE的多個副本。 一切正常,直到我遷移到新服務器和更新軟件。

新服務器正在運行Apache 2.4而不是2.2,並使用mod_ruid2代替suexec。

現在,當嘗試加載編輯器時出現此錯誤:

致命錯誤(4):語法錯誤,[/ xyz / Plugin / TinyMCE / webroot / js / tiny_mce / tiny_mce.js,第1行]中出現意外的T_CONSTANT_ENCAPSED_STRING

我應該如何開始調試呢?

解決方法嘗試

我嘗試將一個符號鏈接從應用程序的webroot添加到TinyMCE的插件webroot。 這樣做是因為它加載了js文件和編輯器,但是TinyMCE插件在錯誤的當前目錄上工作,並且文件管理不會分開。

問題是AssetDispatcher篩選器,它使用PHP的include()語句包含cssjs文件,從而導致文件通過PHP解析器發送,在其中發生<? 在TinyMCE腳本中。

參見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()include()資產,並且您很可能不想檢查所有第三方CSS / JS有關每次更新的可能的PHP代碼注入。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM