WYSIWYGPro Helper and tutorial
2 : config/wysiwygpro.php
I couldn't find any resources on setting up WYSIWYGPro with Cake so I developed this helper along with instructions for total integration with your system. If you've never used WYSIWYGPro, you should check out the demos. I've tried every WYSIWYG editor out there and none of the other ones even come close as far as I'm concerned.
The helper actually has 2 files, a configuration file and the helper itself. Both can be found at my public GitHub account here:
Source Code on GitHub
You'll want to drop the config file into your app/config folder. It's setup as a standard Configure::load() file. All of your application defaults can be set here to be used by the helper. You can also change any settings you wish every time that you call the helper.
Let's look at the part of the configuration file:
The settings prefixed with _ are special settings for the helper itself. Others are all references to either functions or properties used by WYSIWYGPro itself. The settings are iterated through, detecting either method or property within WYSIWYGPro and setting them appropriately. If you notice, the disableFeatures setting is using array(array( syntax. That's because the functions are called using php's call_user_func_array and if we want to pass an array as the first argument of a function, that array must be the first value of the passed array.
This structure allows you to call any WYSIWYGPro setting even if I haven't included it in the config file, just reference the developer documentation to expand on everything.
Other settings such as directory defaults are fairly self-explanatory. There are 3 types, images, documents, and media. Images and Media can be directly embedded, document (including images and media) can be linked to.
The 'directories' setting is where you specify which directories you actually want to be available.
Here we've include 4 directories, an image, document, and media directory using the default settings and an image directory using some custom settings. The full example is available in the config file. Directories that are missing will be created using the '_directory_permissions' setting.
You can also provide a list of styles for end users to use. I find this is preferable to giving full font/color control to most people so you can limit the available options to only your chosen styles.
You can also have the editor use a specified CSS file to format the contents. It's not included in the config file by default, but you could easily do something like this seeing that the function is available here.
WYSIWYGPro Developer Docs - addStylesheet
Source Code on GitHub
You'll want to drop the config file into your app/config folder. It's setup as a standard Configure::load() file. All of your application defaults can be set here to be used by the helper. You can also change any settings you wish every time that you call the helper.
Let's look at the part of the configuration file:
<?php
$config['Wysiwygpro']['htmlCharset'] = 'UTF-8';
$config['Wysiwygpro']['operaSupport'] = true;
//Disabled but likely requested features: fontcolor, highlight
$config['Wysiwygpro']['disableFeatures'] = array(array('print','outdent','indent','full','fontcolor','spacer','emoticon','snippets','highlight','dirltr','dirrtl','bookmark'));
//Add buttons not included by default
$config['Wysiwygpro']['addRegisteredButton'] = array('document','after:link');
?>
The settings prefixed with _ are special settings for the helper itself. Others are all references to either functions or properties used by WYSIWYGPro itself. The settings are iterated through, detecting either method or property within WYSIWYGPro and setting them appropriately. If you notice, the disableFeatures setting is using array(array( syntax. That's because the functions are called using php's call_user_func_array and if we want to pass an array as the first argument of a function, that array must be the first value of the passed array.
This structure allows you to call any WYSIWYGPro setting even if I haven't included it in the config file, just reference the developer documentation to expand on everything.
Other settings such as directory defaults are fairly self-explanatory. There are 3 types, images, documents, and media. Images and Media can be directly embedded, document (including images and media) can be linked to.
<?php
$config['Wysiwygpro']['_directory_settings'] = array(
//images
'image' => array(
'type' => 'image',
'dir' => WWW_ROOT . 'img',
'URL' => '/img',
'name' => 'All Images',
'editImages' => false,
'renameFiles' => false,
'renameFolders' => false,
'deleteFiles' => false,
'deleteFolders' => false,
'copyFiles' => true,
'copyFolders' => true,
'moveFiles' => false,
'moveFolders' => false,
'upload' => true,
'overwrite' => false,
'createFolders' => true,
'filters' => array('Thumbnails')
),
...
?>
The 'directories' setting is where you specify which directories you actually want to be available.
<?php
$config['Wysiwygpro']['directories'] = array(
array('type' => 'image'),
array('type' => 'document'),
array('type' => 'media'),
array( //Example of including a custom directory
'type' => 'image',
'dir' => WWW_ROOT . 'img/mine',
'URL' => '/img/mine',
'name' => 'My Images',
'editImages' => true,
'renameFiles' => true,
...
?>
Here we've include 4 directories, an image, document, and media directory using the default settings and an image directory using some custom settings. The full example is available in the config file. Directories that are missing will be created using the '_directory_permissions' setting.
You can also provide a list of styles for end users to use. I find this is preferable to giving full font/color control to most people so you can limit the available options to only your chosen styles.
<?php
//Provide a list of styles that users can choose from
$config['Wysiwygpro']['stylesMenu'] = array(
'p' => 'Paragraph',
'div' => 'Div',
'h2' => 'Heading 2',
'h3' => 'Heading 3',
'h4' => 'Heading 4',
'h5' => 'Heading 5',
'blockquote' => 'Blockquote',
'p class="warning"' => 'Warning Box' //Example of a style with a class
);
?>
You can also have the editor use a specified CSS file to format the contents. It's not included in the config file by default, but you could easily do something like this seeing that the function is available here.
WYSIWYGPro Developer Docs - addStylesheet
<?php
$config['Wysiwygpro']['addStylesheet'] = '/css/wysiwygpro.css';
?>
Comments
Comment
1 yeah
Comment
2 Yeah, not sure what happened with Drupal either
Comment
3 WPro
WPro seem to be my solutions when I take a look on it. However, after spent my plenty money (64USD is not a 'small' amount in my country, it can feed some family for weeks) for the developer version, what I really get is an incomplete documentation and some emotional reply message to my service request. So, I decide to ask for the refund.
Anyway, your article still give me some idea for my current project.
Thanks!
Comment
4 WYSIWYGPro Helper and tutorial