Table of Contents

Integrate JavaScript-Editor

With Admidio 2.3 the CKEditor is included as the standard. This can now be installed with simple methods in a script.

Install editor in a form

The installation into a form has become very easy since version 3.0. Normally it should have been created with a form of class HtmlForm.

$form = new HtmlForm('edit_form', $g_root_path.'/adm_program/modules/announcements/announcements_function.php?ann_id='.$getAnnId, $page);

Now you can at call the method at the appropriate place just withaddEditor and the CKEditor is already contained in your form.

$form->addEditor('ann_description', $gL10n->get('SYS_TEXT'), $announcement->getValue('ann_description'), array('property' => FIELD_REQUIRED));

Storing the contents

If the contents of the editor shall be saved about an object or derived object of Table Access - class, it must be deposited an exception in the methods getValue and setValue for the editor field. This prevents the HTML content is removed from the editor again.

 public function getValue($field_name, $format = '')
    {
        if ($fieldName === 'ann_description')
        {
            $value = $this->dbColumns['ann_description'];
        }
        else
        {
            $value = parent::getValue($fieldName, $format);
        }
 
        return $value;
    }
 
    public function setValue($fieldName, $fieldValue, $checkValue = true)
    {
        if ($fieldName === 'ann_description')
        {
            return parent::setValue($fieldName, $fieldValue, false);
        }
        return parent::setValue($fieldName, $fieldValue);
    }

Validation of the HTML content

Because only HTML code is passed using the editor, this has yet to be validated before being stored in the database. For this purpose Admidio uses the script htmLawed. This must be integrated into the script that processes the inputs of the editor:

require_once ('../../libs/htmlawed/htmlawed.php');

In the next step the contents of the field is to be tested by the script:

$_POST['ann_description'] = htmLawed(stripslashes($_POST['ann_description']));

Enable image upload

If the editor instance shall allow the upload of images, so it must be specified in the upload script a folder name for a folder within adm_my_files. Proceed this by calling the script adm_program/system/ckeditor_upload_handler.php and supplement there the IF structure approximately 30 line with the new editor-ID

if ($_GET['CKEditor'] === 'ann_description ')
{
    $folderName = 'ANNOUNCEMENTS';
}

Skip the HTML code-Check

The final step in the integration of the editor, the system-wide check of all passed variables for Html code must be deactivated for the id of the editor-field. For this purpose, the function admStrStripTagsSpecial must be supplemented.

if ($key !== 'ann_description') // ckeditor-variable
{
    $srcArray[$key] = strStripTags($value);
}

Each new ID will be supplemented with && $key != 'editor_id_name'.

The integration of the CKEditor for another form is finished!