{"id":648,"date":"2019-01-31T13:28:03","date_gmt":"2019-01-31T13:28:03","guid":{"rendered":"https:\/\/www.kolkataonweb.com\/code-bank\/?p=648"},"modified":"2019-01-31T13:31:59","modified_gmt":"2019-01-31T13:31:59","slug":"ckeditor-wysiwyg-editor-for-web","status":"publish","type":"post","link":"https:\/\/www.kolkataonweb.com\/code-bank\/php\/ckeditor-wysiwyg-editor-for-web\/","title":{"rendered":"CKEditor &#8211; WYSIWYG Editor for Web"},"content":{"rendered":"<p>This is a quick guide about integrating CKEditor<\/p>\n<p>Download CKEditor from here &#8211; <a href=\"https:\/\/ckeditor.com\/ckeditor-4\/download\/\">https:\/\/ckeditor.com\/ckeditor-4\/download\/<\/a> I downloaded the full version.<br \/>\nCall the scripts in your code<\/p>\n<pre class='wp-code-highlight prettyprint'>&lt;script src=\"ckeditor_full\/ckeditor.js\"&gt;&lt;\/script&gt;\r\n...\r\n...\r\n&lt;textarea required id=\"content\" name=\"content\"&gt;&lt;?php echo strlen($content) ? $content : \"\" ?&gt;&lt;\/textarea&gt;&lt;br\/&gt; \r\n&lt;script&gt;\r\n var editor = CKEDITOR.replace('content');\r\n \/\/CKEDITOR.instances['content'].setData(\"\");\r\n <span style=\"color: #008000;\">CKFinder.setupCKEditor(editor);<\/span> \/\/see below - this is for the CKFinder and can be omitted if file uploading is not needed\r\n&lt;\/script&gt;\r\n...\r\n...\r\n...\r\n&lt;script&gt; \r\n\/\/validation if needed\r\n if(document.getElementById(\"content\").value.length == 0)\r\n {\r\n   CKEDITOR.instances[0].updateElement(); \/\/Updates the <code>&lt;textarea&gt;<\/code> element that was replaced by the editor with the current data available in the editor. This is to ensure that it is updated before doing the check alert(\"Provide the mail body\"); return false; } &lt;\/script&gt;<\/pre>\n<p>The above will replace the plain textarea with the CKEditor.<\/p>\n<p>The number of toolbars and tools depends on the version of CKEditor (full or basic etc).<\/p>\n<p>For a customizing the toolbar<\/p>\n<pre class='wp-code-highlight prettyprint'><span style=\"color: #808080;\">CKEDITOR.editorConfig = function( config ) {<\/span>\r\n<span style=\"color: #808080;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \/\/ Define changes to default configuration here.<\/span>\r\n<span style=\"color: #808080;\">\u00a0\u00a0\u00a0\u00a0 \u00a0 \u00a0\u00a0 \/\/ For complete reference see:<\/span>\r\n<span style=\"color: #808080;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \/\/ http:\/\/docs.ckeditor.com\/#!\/api\/CKEDITOR.config<\/span>\r\n\r\n<span style=\"color: #808080;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \/\/ The toolbar groups arrangement, optimized for two toolbar\r\n<\/span><span style=\"color: #808080;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 rows.<\/span>config.toolbarGroups = [\r\n\r\n\r\n{ name: 'clipboard', groups: [ 'clipboard', 'undo' ] },\r\n{ name: 'editing', groups: [ 'find', 'selection', 'spellchecker' ] },\r\n{ name: 'links' },\r\n{ name: 'insert' },\r\n{ name: 'forms' },\r\n{ name: 'tools' },\r\n{ name: 'document', groups: [ 'mode', 'document', 'doctools' ] },\r\n{ name: 'others' },\r\n'\/',\r\n{ name: 'basicstyles', groups: [ 'basicstyles', 'cleanup' ] },\r\n{ name: 'paragraph', groups: [ 'list', 'indent', 'blocks', 'align', 'bidi' ] },\r\n{ name: 'styles' },\r\n{ name: 'colors' },\r\n{ name: 'about' }\r\n];<\/pre>\n<p>&nbsp;<\/p>\n<p>For making the file upload and drag drop uploads working with album view<\/p>\n<p>Download the CKFinder from here\u00a0 <a href=\"https:\/\/ckeditor.com\/ckfinder\/download\/\">https:\/\/ckeditor.com\/ckfinder\/download\/<\/a>\u00a0 I used the PHP version<br \/>\nCall the script in the code<\/p>\n<pre class='wp-code-highlight prettyprint'>&lt;script src=\"ckfinder\/ckfinder.js\"&gt;&lt;\/script&gt;<\/pre>\n<p>Open the <span style=\"color: #008000;\">config.php<\/span> file (under root of the ckfinder folder) and modify the following highlighted lines with suitable values<\/p>\n<pre class='wp-code-highlight prettyprint'>$config['backends'][] = array(\r\n\u00a0\u00a0 'name' =&gt; 'default',\r\n\u00a0\u00a0 'adapter' =&gt; 'local',\r\n\u00a0\u00a0\u00a0 <span style=\"color: #0000ff;\">'baseUrl' =&gt; 'https:\/\/xxxxxxxxxx.com\/projectname\/ckfinder\/userfiles\/', \/* note - I have used an URL but folder names and paths can be used also*\/<\/span>\r\n\u00a0\u00a0\u00a0 \/\/ 'root' =&gt; '', \/\/ Can be used to explicitly set the CKFinder user files directory.\r\n\u00a0\u00a0\u00a0 <span style=\"color: #0000ff;\">'chmodFiles' =&gt; 0644, \/\/this by default was 777 I changed that to 644<\/span>\r\n\u00a0\u00a0\u00a0 'chmodFolders' =&gt; 0755,\r\n\u00a0\u00a0 'filesystemEncoding' =&gt; 'UTF-8',\r\n);<\/pre>\n<p>Enable the PHP adapter (we used the default PHP adapter that comes with the CKFinder)<\/p>\n<pre class='wp-code-highlight prettyprint'>$config['authentication'] = function () {\r\n\u00a0\u00a0<span style=\"color: #0000ff;\"> return true;\u00a0 \/\/ by default this is false<\/span>\r\n};<\/pre>\n<p>Add the required plugins and enable them in the <span style=\"color: #008000;\">config.js<\/span> of the CKEditor<\/p>\n<pre class='wp-code-highlight prettyprint'>CKEDITOR.editorConfig = function( config ) {\r\n\u00a0\u00a0\u00a0\u00a0\u00a0 \/\/ Define changes to default configuration here. For example:\r\n\u00a0\u00a0\u00a0\u00a0 \/\/ config.language = 'fr';\r\n\u00a0\u00a0\u00a0 \/\/ config.uiColor = '#AADC6E';\r\n\r\n\u00a0\u00a0\u00a0 <span style=\"color: #0000ff;\">config.extraPlugins = 'notification';\u00a0 <span style=\"color: #333333;\">\/\/https:\/\/ckeditor.com\/cke4\/addon\/notification -- required by Notification Aggregator plugin<\/span><\/span>\r\n<span style=\"color: #0000ff;\">\u00a0\u00a0\u00a0 config.extraPlugins = 'notificationaggregator'; <span style=\"color: #333333;\">\/\/https:\/\/ckeditor.com\/cke4\/addon\/notificationaggregator\u00a0 -- -- required by Upload<\/span><\/span>\r\n\r\n\u00a0\u00a0\u00a0 <span style=\"color: #0000ff;\">config.extraPlugins = 'filetools';\u00a0\u00a0 <span style=\"color: #333333;\">\/\/https:\/\/ckeditor.com\/cke4\/addon\/filetools -- required by Upload<\/span><\/span>\r\n<span style=\"color: #0000ff;\">\u00a0\u00a0\u00a0 config.extraPlugins = 'uploadwidget'; <span style=\"color: #333333;\">\/\/https:\/\/ckeditor.com\/cke4\/addon\/uploadwidget -- required by uploadimage<\/span><\/span>\r\n<span style=\"color: #0000ff;\">\u00a0\u00a0\u00a0 config.extraPlugins = 'uploadimage'; \/\/<\/span>\r\n};<\/pre>\n<p>The PHP connector comes with the CKFinder<\/p>\n<p>Here are the files used above (latest versions as of time of writing)<\/p>\n<p><a href=\"https:\/\/www.kolkataonweb.com\/code-bank\/wp-content\/uploads\/2019\/01\/filetools_4.11.2.zip\">filetools_4.11.2<\/a><\/p>\n<p><a href=\"https:\/\/www.kolkataonweb.com\/code-bank\/wp-content\/uploads\/2019\/01\/notificationaggregator_4.11.2.zip\">notificationaggregator_4.11.2<\/a><\/p>\n<p><a href=\"https:\/\/www.kolkataonweb.com\/code-bank\/wp-content\/uploads\/2019\/01\/notification_4.11.2.zip\">notification_4.11.2<\/a><\/p>\n<p><a href=\"https:\/\/www.kolkataonweb.com\/code-bank\/wp-content\/uploads\/2019\/01\/ckfinder_php_3.4.5.zip\">ckfinder_php_3.4.5<\/a><\/p>\n<p><a href=\"https:\/\/www.kolkataonweb.com\/code-bank\/wp-content\/uploads\/2019\/01\/ckeditor_4.11.2_full.zip\">ckeditor_4.11.2_full<\/a><\/p>\n<p><a href=\"https:\/\/www.kolkataonweb.com\/code-bank\/wp-content\/uploads\/2019\/01\/uploadwidget_4.11.2.zip\">uploadwidget_4.11.2<\/a><\/p>\n<p><a href=\"https:\/\/www.kolkataonweb.com\/code-bank\/wp-content\/uploads\/2019\/01\/uploadimage_4.11.2.zip\">uploadimage_4.11.2<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>This is a quick guide about integrating CKEditor Download CKEditor from here &#8211; https:\/\/ckeditor.com\/ckeditor-4\/download\/ I downloaded the full version. Call the scripts in your code &lt;script src=&#8221;ckeditor_full\/ckeditor.js&#8221;&gt;&lt;\/script&gt; &#8230; &#8230; &lt;textarea required id=&#8221;content&#8221; name=&#8221;content&#8221;&gt;&lt;?php echo strlen($content) ? $content : &#8220;&#8221; ?&gt;&lt;\/textarea&gt;&lt;br\/&gt; &lt;script&gt; var editor = CKEDITOR.replace(&#8216;content&#8217;); \/\/CKEDITOR.instances[&#8216;content&#8217;].setData(&#8220;&#8221;); CKFinder.setupCKEditor(editor); \/\/see below &#8211; this is for the CKFinder&hellip; <a class=\"more-link\" href=\"https:\/\/www.kolkataonweb.com\/code-bank\/php\/ckeditor-wysiwyg-editor-for-web\/\">Continue reading <span class=\"screen-reader-text\">CKEditor &#8211; WYSIWYG Editor for Web<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[161,163,162,160],"class_list":["post-648","post","type-post","status-publish","format-standard","hentry","category-php","tag-ckeditor","tag-cms-edit-rich-text-editor","tag-rich-text-editor","tag-wysiwyg","entry"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.kolkataonweb.com\/code-bank\/wp-json\/wp\/v2\/posts\/648","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.kolkataonweb.com\/code-bank\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.kolkataonweb.com\/code-bank\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.kolkataonweb.com\/code-bank\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.kolkataonweb.com\/code-bank\/wp-json\/wp\/v2\/comments?post=648"}],"version-history":[{"count":4,"href":"https:\/\/www.kolkataonweb.com\/code-bank\/wp-json\/wp\/v2\/posts\/648\/revisions"}],"predecessor-version":[{"id":660,"href":"https:\/\/www.kolkataonweb.com\/code-bank\/wp-json\/wp\/v2\/posts\/648\/revisions\/660"}],"wp:attachment":[{"href":"https:\/\/www.kolkataonweb.com\/code-bank\/wp-json\/wp\/v2\/media?parent=648"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.kolkataonweb.com\/code-bank\/wp-json\/wp\/v2\/categories?post=648"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.kolkataonweb.com\/code-bank\/wp-json\/wp\/v2\/tags?post=648"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}