2011-10-26

CKEditor + KCFinder 筆記

CKEditor 的 config.js 中加入
config.filebrowserBrowseUrl = 'lib/kcfinder/browse.php?type=files';
config.filebrowserImageBrowseUrl = 'lib/kcfinder/browse.php?type=images';
config.filebrowserFlashBrowseUrl = 'lib/kcfinder/browse.php?type=flash';
config.filebrowserUploadUrl = 'lib/kcfinder/upload.php?type=files';
config.filebrowserImageUploadUrl = 'lib/kcfinder/upload.php?type=images';
config.filebrowserFlashUploadUrl = 'lib/kcfinder/upload.php?type=flash';
KCFinder 的 config.php 設定 session,user 登入後再設定 $_SESSION['mysite']['KCFINDER']['disabled'] = false;
'_sessionVar' => &$_SESSION['mysite']['KCFINDER'],
要放在 jQuery UI 的 dialog 中時忘記遇到什麼問題,後來改成在 dialog open 時才將 ckeditor 載入,dialog close 時再清掉。
$("#dialog-news").dialog({
  open: function () {
    $(this).find('textarea').ckeditor({height:360});
  },
  close: function () {
    $(this).find('textarea').val('').ckeditorGet().destroy();
  }
});
嵌入 KCFinder (例如按下某個 button 後跳出 KCFinder browser 的視窗,選擇檔案後返回)
$('#dialog-news button[name="attach"]').click(function(){
  window.KCFinder = {
    callBack: function(url) {
      window.KCFinder = null;
        $('#dialog-news input[name="link"]').val('.'+url);
      }
    };
  window.open('lib/kcfinder/browse.php?type=files&dir=files/attachment', 'kcfinder_textbox',
    'status=0, toolbar=0, location=0, menubar=0, directories=0, ' +
    'resizable=1, scrollbars=0, width=800, height=600'
  );
  return false;
});
KCFinder 上傳檔案改成 time stamp 加檔名,修改 core/uploader.php 中 public function upload()
$filename = date('YmdHis') . '-' . $this->normalizeFilename($file['name']);
  $target = file::getInexistantFilename($dir . $filename);

沒有留言:

張貼留言