I created a function in one of the files I include on each PHP page in a CMS I work on. Here is most of it:
// CKEditor code for text editor
function text_editor($field_name, $value, $toolbar = "User", $cols = "80%", $rows = 10)
{
include('includes/ckeditor/ckeditor.php');
$CKEditor = new CKEditor();
$CKEditor->basePath = 'includes/ckeditor/';
// Do not print the code directly to the browser, return it instead
$CKEditor->returnOutput = true;
// set the graphical look of CKEditor
//$config['skin'] = 'office2003'; // default skin is -> kama --> available skins: kama, office2003, v2 --- uncomment line to use
// User Interface Color, works only on default skin: kama
$config['uiColor'] = '#AABBCC'; // User Interface Color ... sets CKEditor's toolbar gradient color
// set up Width and Height of CKEditor
$config['width'] = $cols; // width can be set to pixels or percentage... For Example: $config['width'] = 600; -OR- $config['width'] = '90%';
$config['height'] = $rows * 17;
if($toolbar == "Basic") {
$config['toolbar'] = array(
array( 'Source','-','Cut', 'Copy', 'PasteText', 'PasteFromWord', '-', 'Undo','Redo','-','BidiLtr', 'BidiRtl'),
'/',
array( 'Bold', 'Italic', '-', 'HorizontalRule', '-', 'NumberedList','BulletedList','-','OrderedList','UnorderedList','-','Link','Unlink','Anchor','-','About')
);
}
// Create editor instance.
echo $CKEditor->editor($field_name, $value, $config);
}
I also have 2 other toolbars I use in this, but I left out their code.
Of course you may change any of the 5 variables listed, for example:
text_editor("content", "", "User", "100%", "15");
...which means you have a textarea field named "content" ...where the initial value is empty "" ...where the toolbar to use is named "User" ...where the width of the editor instance is "100%" AND ...where the height of the editor instance is "15" rows
If you wish, you can replace the width from a percentage to number of pixels. For example, replace "100%" with 600.
I have CKEditor installed in a directory named "includes" in a folder named "ckeditor" as you can see by the "include" line of code. You can upload/create a different location, but you would need to change the "include" line AND the basePath line to match where you have uploaded CKEditor.
I do not have CKFinder installed, as I found a way to use the old FCKeditor filemanager. There is code listed in the CKEditor docs/pages to show you what lines of code to use for CKFinder.
The function I listed should be put in a file that is called or "included" in the file where you will want to display an editor instance. For my system, I have a file called "mainfile.php" which is "included" in nearly all my other files to pull in info and functions that can be used.
Once you have this function in a file as described above, you can use this code to display CKEditor:
...where yourfieldname is the database fieldname, ...where "" is the initial value that is displayed in the textbox area ...where "Basic" is the toolbar name ...where "80%" is the width of the editor and ...where "10" is the number of rows or actually the height of the editor textbox area
Of course you should put in the values you will need for that specific instance.
If you are using CKEditor to edit the text field from above, you will need to change what is displayed in the "value"/"initial value" listing. For example:
Re: CK EDITOR HOW TO EMBED IN PHP CODE
// CKEditor code for text editor function text_editor($field_name, $value, $toolbar = "User", $cols = "80%", $rows = 10) { include('includes/ckeditor/ckeditor.php'); $CKEditor = new CKEditor(); $CKEditor->basePath = 'includes/ckeditor/'; // Do not print the code directly to the browser, return it instead $CKEditor->returnOutput = true; // set the graphical look of CKEditor //$config['skin'] = 'office2003'; // default skin is -> kama --> available skins: kama, office2003, v2 --- uncomment line to use // User Interface Color, works only on default skin: kama $config['uiColor'] = '#AABBCC'; // User Interface Color ... sets CKEditor's toolbar gradient color // set up Width and Height of CKEditor $config['width'] = $cols; // width can be set to pixels or percentage... For Example: $config['width'] = 600; -OR- $config['width'] = '90%'; $config['height'] = $rows * 17; if($toolbar == "Basic") { $config['toolbar'] = array( array( 'Source','-','Cut', 'Copy', 'PasteText', 'PasteFromWord', '-', 'Undo','Redo','-','BidiLtr', 'BidiRtl'), '/', array( 'Bold', 'Italic', '-', 'HorizontalRule', '-', 'NumberedList','BulletedList','-','OrderedList','UnorderedList','-','Link','Unlink','Anchor','-','About') ); } // Create editor instance. echo $CKEditor->editor($field_name, $value, $config); }I also have 2 other toolbars I use in this, but I left out their code.
Here is how to call it for use in other files:
text_editor("yourfieldname", "", "Basic", "80%", "10");Of course you may change any of the 5 variables listed, for example:
text_editor("content", "", "User", "100%", "15");...which means you have a textarea field named "content"
...where the initial value is empty ""
...where the toolbar to use is named "User"
...where the width of the editor instance is "100%"
AND
...where the height of the editor instance is "15" rows
If you wish, you can replace the width from a percentage to number of pixels. For example, replace "100%" with 600.
Re: CK EDITOR HOW TO EMBED IN PHP CODE
What else I need to do--
There are 2 things:
CKEDITOR AND CKFINDER--
How to integrate them with your code?
and where these 2 things are to be installed(WAMP?)
Re: CK EDITOR HOW TO EMBED IN PHP CODE
I do not have CKFinder installed, as I found a way to use the old FCKeditor filemanager. There is code listed in the CKEditor docs/pages to show you what lines of code to use for CKFinder.
The function I listed should be put in a file that is called or "included" in the file where you will want to display an editor instance. For my system, I have a file called "mainfile.php" which is "included" in nearly all my other files to pull in info and functions that can be used.
Once you have this function in a file as described above, you can use this code to display CKEditor:
text_editor("yourfieldname", "", "Basic", "80%", "10");...where yourfieldname is the database fieldname,
...where "" is the initial value that is displayed in the textbox area
...where "Basic" is the toolbar name
...where "80%" is the width of the editor
and
...where "10" is the number of rows or actually the height of the editor textbox area
Of course you should put in the values you will need for that specific instance.
If you are using CKEditor to edit the text field from above, you will need to change what is displayed in the "value"/"initial value" listing. For example:
text_editor("yourfieldname", "$yourfieldname", "Basic", "80%", "10");...where $yourfieldname = the variable that contains the text field you are wanting to edit.