How to embed the WysiwygPro html editor in a form

FIXME This howBold TextBold TextBold Text-to does not reflect Akelos best practices. The documentation bellow could be done in a cleaner way by using helpers. And better yet, wrapping the helper and the Editor into a plugin.

http://www.wysiwygpro.com/ is a decent editor, although it's not free ($64 a domain at time of writing). How to use it in your project?

For start: You cannot put the embed code in your _form partial, or any other view file. The example code provided by ViziMetrics is something like this:

// include the WysiwygPro script 
include_once('wysiwygPro/wysiwygPro.class.php'); 
 
// create a new WysiwygPro instance 
$editor = new wysiwygPro(); 
 
// give the editor a name 
$editor->name = 'demo';
 
// display the editor 
$editor->display(700, 400);

.. but the 'include' statement alone will throw an error when used in a view.

Solution: instantiate your editor in your controller:

// include the WysiwygPro script 
include_once($_SERVER['DOCUMENT_ROOT'].'/wysiwygPro/wysiwygPro.class.php');
 
// create a new WysiwygPro Instance
$this->editor = new wysiwygPro();
 
// give the editor a name
$this->editor->name = 'page[content]';
 
// set the html content
$this->editor->value = $this->page->content;

So you'll only have to display the editor in your view

<p>
   <label for="page_content">Pagecontent</label><br />        
   <?$editor->display('100%',400);?>
</p>

Here are some other settings that might be of use (all in your controller of course)

// set the HTML version and charset to the Akelos defaults
$this->editor->htmlVersion = 'XHTML 1.0 Transitional';
$this->editor->htmlCharset = 'UTF-8';
 
// load the stylesheet
$this->editor->addStylesheet('/stylesheets/scaffold.css');
 
// when having a multilingual site, you might as well use the provided translations
switch($this->language->getCurrentLocale()){
 case'fr'; $this->editor->lang='fr-fr'; break;
 case'de'; $this->editor->lang='de-de'; break;
 default ; $this->editor->lang='en-us'; break;
}

But that's not all you need to do. That would be to easy.
There's one more thing: Akelos uses a custom PHP session name.. and WysiwygPro puts the settings of the embedded editor in the session so the pop-up windows (used when adding an image, inserting a table,..) also have the right settings.

So, you'll have to let the WysiwygPro editor know of the custom session_name Akelos is using.

By default Akelos uses 'AK_' followed by 6 numbers generated using your hostname and application directory. You can easily read it out using

echo session_name();

But.. if you website is accessible under different domainnames (as most sites are, simply by omitting 'www.') you might have a problem.
It's probably better to set your own session_name. In config/config.php:

define('AK_SESSION_NAME','yoursessionname');

And then in wysiwygPro/conf/customSessHandlers.inc.php

session_name('yoursessionname');
session_start();

And now everything should work.