1. CKEditor 설치 및 적용

 

http://ckeditor.com/

 

CKEditor는 기본적으로 PHP에 설치하기 적합하도록 되어 있다

하지만 자바스크립트 기반의 소스이므로 .NET 환경과 JAVA환경에서도 설치할 수 있다.


* CKEditor 다운로드 및 서버 업로드

-http://ckeditor.com/download 에서 Full Package 선택. Download 클릭.

-ckeditor 폴더를 서버에 업로드.(당연히 필수)

 

* CKEditor 설치

-설치하고자 하는 페이지의 <head></head> 태그 사이에 다음 소스를 추가함. (필수)

<head>

...

<script type="text/javascript" src="/ckeditor/ckeditor.js"></script>

</head>

 

-class를 이용한 에디터 추가.

 단지 class="ckeditor"로 지정한다.

아래와 같이 <javascript>의 부가적인 추가 없이도 바로 적용이 된다.

<textarea rows="10" class="ckeditor" name="contents"></textarea>

 

-ID 를 이용한 에디터 추가 : 내가 사용한 방법

<textarea id="contents" name="contents" readonly="readonly"></textarea>

<script type="text/javascript">

CKEDITOR.replace( 'contents' );//textareaid명을 이용해서 ckeditor를 적용한다.

</script>

이 경우에는 class를 이용한 방법에 비해 다소 복잡하지만 각각의 Editor마다 다른 설정을 할 수 있다는 장점이 있다.


-<head>태그 사이에 script를 삽입할 경우.

 

<script type=”text/javascript”>

window.onload =function() //이게 더 붙는다.

CKEDITOR.replace('EDITOR가 삽입될 textareaID');

};

</script>

 

-Editor에 입력한 내용을 변수로 저장하기.

$변수명의 값을 POST 방식으로 넘긴다.

 

$변수명=CKEDITOR.instances.textarea의 ID.getData();

 

또는 <form>태그를 사용해서 그 값을 넘긴다.

 

<textarea>를 읽기모드만으로 하려면 readonly값을 준다.

ckeditor에서 입력한 텍스트가 DB에 저장할 때에는 내부에서 적용된 태그는 그대로 입력이 된다.

하지만 입력한 텍스트가 html 태그 형식이라면 문제가 생긴다.

그래서 DB입력 전에 htmlspecialchar()함수를 꼭 써야한다.

nl2br()함수와 addslashes()는 사용하지 않아도 ckeditor가 알아서 적용한다.

DB에서 읽어올 때는 ckeditor가 내부적으로 붙인 태그들은 ckeditor를 적용한 <textarea>에서는 자동으로 변환되어 출력된다.

 

주의

ckeditor가 적용되지 않은 글제목 등에는 반드시 addslashes(), stripslashes(), htmlspecialchars()함수를 사용하여야 한다.

ckeditor는 보안상의 이유로 4.5.10 이상의 버전을 사용할 것. (지금 사용하는 것은 4.6.2 full 버전 임.)

Posted by star story :

Snippet :: Code View :: "+location.href+'
'+b+"

");top.consoleRef.document.close()}$(".snippet-container").each(function(b){$(this).find("a.snippet-text").click(function(){var d=$(this).parents(".snippet-wrap").find(".snippet-formatted");var c=$(this).parents(".snippet-wrap").find(".snippet-textonly");d.toggle();c.toggle();if(c.is(":visible")){$(this).html("html")}else{$(this).html("text")}return false});$(this).find("a.snippet-window").click(function(){var c=$(this).parents(".snippet-wrap").find(".snippet-textonly").html();a(c);$(this).blur();return false})});$(".snippet-toggle").each(function(b){$(this).click(function(){$(this).parents(".snippet-container").find(".snippet-wrap").toggle()})})});