TinyMCE + IMCE

เจอปัญหาเวลาจะใช้ module IMCE ร่วมกับ TinyMCE
เพราะมันทำงานแยกกัน ไม่สามารถเอา IMCE มาใช้ใน Images Toold ของ TinyMCE
เคยแก้ไปทีนึงแล้ว ก็ลืม คราวนี้เลย blog ทิ้งไว้หน่อย

  • ลง TinyMCE และ IMCE ตามปกติ
  • เช็ค Profile กับ Permission ของทั้ง 2 module ให้เรียบร้อย
  • add code ด้านล่างลงในไฟล์ template.php ที่อยู่ใน theme (ถ้า theme ที่ใช้ไม่มีก็สร้างไฟล์ใหม่ได้เลย)
  1. <?php
  2. function phptemplate_tinymce_theme($init, $textarea_name, $theme_name, $is_running) {
  3. static $access, $integrated;
  4.  
  5. if (!isset($access)) {
  6. $access = function_exists('imce_access') && imce_access();
  7. }
  8.  
  9. $init = theme_tinymce_theme($init, $textarea_name, $theme_name, $is_running);
  10.  
  11. if ($init && $access) {
  12. $init['file_browser_callback'] = 'imceImageBrowser';
  13. if (!isset($integrated)) {
  14. $integrated = TRUE;
  15. drupal_add_js("
  16. function imceImageBrowser(field_name, url, type, win) {
  17. tinyOpenerWin = win, tinyTargetField = field_name;
  18. if (typeof tinyImceWin == 'undefined' || tinyImceWin.closed) {
  19. tinyImceWin = window.open(Drupal.settings.basePath +'?q=imce', '', 'width=760,height=560,resizable=1');
  20. tinyImceWin['imceOnLoad'] = function () {
  21. tinyImceWin.imce.highlight(url.substr(url.lastIndexOf('/')+1));
  22. tinyImceWin.imce.setSendTo(Drupal.t('Send to @app', {'@app': 'TinyMCE'}), function(file) {
  23. window.focus();
  24. tinyOpenerWin.focus();
  25. $('#width', tinyOpenerWin.document).val(file.width);
  26. $('#height', tinyOpenerWin.document).val(file.height);
  27. $('#'+ tinyTargetField, tinyOpenerWin.document).val(file.url).focus();
  28. });
  29. }
  30. }
  31. else {
  32. tinyImceWin.imce.highlight(url.substr(url.lastIndexOf('/')+1));
  33. }
  34. tinyImceWin.focus();
  35. }
  36. ", 'inline');
  37. }
  38. }
  39.  
  40. return $init;
  41. }
  42. ?>
  • clear cached date ที่ admin/settings/performance
  • เป็นอันเสร็จ