2006/7/11 火曜日

FCKeditorをPHPから使って見た

Filed under: WEB2.0, リッチクライアント — y2sunlight @ 13:45:00

前回の記事の続きです。

FCKeditor をPHPから使ってみました。wiki.fckeditor.net に従って設定してみます:

ここでは、PHP Integration Module(FCKeditor/fckeditor.php)を使います。前回に書いた「あきら×ひろこ=ゆう 」ではJavaScript Integration Module(FCKeditor/fckeditor.js)を使った方法を紹介しています。

fckeditor.phpを使った FCKeditor の設置

 fckeditor

設置環境:

  • /samples/ajax/editor/editor.php — サンプルコード(エディタ)
  • /samples/ajax/editor/savedata.php— サンプルコード(データ保存)
  • /samples/ajax/editor/FCKeditor/ — FCKeditor設置ディレクトリ
  • /samples/ajax/editor/Resource/ — リソースディレクトリ
  • /samples/ajax/editor/Upload/ — アップロードディレクトリ

editor.php(エディタ):

<?php
include(”FCKeditor/fckeditor.php”) ;
?>
<html>
<head><title>FCKeditor</title>
<meta http-equiv=”Content-Type” content=”text/html; charset=utf-8″>
</head>
<body>
<form action=”savedata.php” method=”post”>
<?php
$oFCKeditor = new FCKeditor(’FCKeditor1′) ;
$oFCKeditor->BasePath =  ‘/samples/ajax/editor/FCKeditor/’;
$oFCKeditor->Width = ‘100%’;
$oFCKeditor->Height = ‘200′;
$oFCKeditor->ToolbarSet = ‘Default’;
$oFCKeditor->Value = ‘Default text in editor’;
$oFCKeditor->Create() ;
?>
</form>
</body>
</html>

  • FCKeditorクラスのコンストラクタの引数(FCKeditor1)はエディタの要素名です。POST変数として使われます。
  • FCKeditor->BasePath は仮想パスで指定します。
  • Width と Height はエディタの幅と高さです。エディタは iframe の中に入っており、Width と Height はiframe のサイズを指定します。
  • Value はエディタで編集するテキストの内容です。

 savedata.php(データ保存): ちょっと手抜きです;

<?php
$postedValue = htmlspecialchars( stripslashes( $_POST[’FCKeditor1′] ) ) ;
?>
<html>
<head><title>Posted Data</title>
<meta http-equiv=”Content-Type” content=”text/html; charset=utf-8″>
</head>
<body>
<?=$postedValue?>
</body>
</html>

  • $_POST[’FCKeditor1′]  と new FCKeditor(’FCKeditor1′) が関係している点に注意して下さい。

リソースブラウザとアップローダの設置

FCKeditor/fckconfig.js:

var _FileBrowserLanguage = ‘php’ ; // 初期値は’asp’です
var _QuickUploadLanguage = ‘php’ ; // 初期値は’asp’です

FCKeditor/editor/filemanager/browser/
   default/connectors/php/config.php:

// SECURITY: You must explicitelly enable this “connector”. (Set it to “true”).
$Config[’Enabled’] = true ;

// Path to user files relative to the document root.
$Config[’UserFilesPath’] = ‘/samples/ajax/editor/Resource/’;

FCKeditor/editor/filemanager/upload/php/config.php:

// SECURITY: You must explicitelly enable this “uploader”.
$Config[’Enabled’] = true ;

// Path to uploaded files relative to the document root.
$Config[’UserFilesPath’] = ‘/samples/ajax/editor/Upload/’;

リソースブラウザの概観

リソースブラウザ

リソースブラウザはファイルのアップロードにも使用でき、かなり便利です。

コメント (1) »

  1. 現在、net2ftp_v0.95を使用しているのですが、エディタ編集機能の「fckeditor」「tinymce」より、イメージとflashのアップロードが出来ません。エラーダイヤログが表示されます。
    何か設定が必要なのでしょうか?

    もし何かおわかりでしたら、ご教示をお願い致します

    コメント by yo-1 — 2007/5/15 火曜日 @ 17:43:18

コメント RSS トラックバック URI

コメントをどうぞ

HTML convert time: 0.968 sec. Powered by WordPress ME