<?php
class FCKEditor {
private $areaname;
private $rooteditor;
private $areawidth = '100%';
private $areaheight = '400px';
private $bottontype = 'Default';
private $areavalue = '';
private $configure = [];
public function load($areaname) {
$this->initialize($areaname);
return $this->loadHtml();
}
private function initialize($areaname) {
global $urlconf;
$this->areaname = $areaname;
$this->rooteditor = $urlconf['domains'] . 'textarea/fck/';
$this->areavalue = $this->areavalue ?: '';
}
private function loadHtml() {
$value = htmlspecialchars($this->areavalue);
$html = '';
if ($this->browserSupported()) {
// 現代瀏覽器:載入 FCKeditor iframe
$file = (isset($_GET['fcksource']) && $_GET['fcksource'] === 'true')
? 'fckeditor.original.html'
: 'fckeditor.html';
$link = "{$this->rooteditor}editor/{$file}?InstanceName={$this->areaname}";
if ($this->bottontype) {
$link .= "&Toolbar={$this->bottontype}";
}
$html .= '';
$html .= '';
$html .= '';
} else {
// 降級:傳統 textarea
$w = strpos($this->areawidth, '%') === false ? $this->areawidth . 'px' : $this->areawidth;
$h = strpos($this->areaheight, '%') === false ? $this->areaheight . 'px' : $this->areaheight;
$html .= "";
}
$html .= '';
return $html;
}
private function browserSupported(): bool {
global $HTTP_USER_AGENT;
$ua = $HTTP_USER_AGENT ?? ($_SERVER['HTTP_USER_AGENT'] ?? '');
// IE (非 Mac、非 Opera)
if (stripos($ua, 'MSIE') !== false && stripos($ua, 'mac') === false && stripos($ua, 'Opera') === false) {
$ver = (float)substr($ua, stripos($ua, 'MSIE') + 5, 3);
return $ver >= 5.5;
}
// Gecko
if (stripos($ua, 'Gecko/') !== false) {
$build = (int)substr($ua, stripos($ua, 'Gecko/') + 6, 8);
return $build >= 20030210;
}
return false;
}
public function setData($data) {
$this->areavalue = stripslashes($data);
}
}
?>
<?php
require_once('FCKEditor.class.php');
$editor = new FCKEditor();
$editor->areawidth = '100%';
$editor->areaheight = '500px';
$editor->bottontype = 'Basic'; // 工具列模式
$editor->setData($articleContent); // 從資料庫載入內容
echo $editor->load('article_content');
?>
| 屬性 | 說明 | 預設值 |
|---|---|---|
rooteditor | FCKeditor 安裝根目錄 URL | 從 $urlconf 取得 |
areawidth/areaheight | 編輯區寬高 (支援 px/% ) | 100% / 400px |
bottontype | 工具列配置名稱 (對應 fckconfig.js) | Default |
fcksource | GET 參數,true 載入原始碼版 (除錯用) | false |
FCKeditor 已停止維護 (2010 年),後續專案請改用:
遷移重點:API 差異大、配置格式不同、輸出 HTML 標準化程度提高。