function action()
 {
     if (@array_key_exists('save', $_POST['action'])) {
         $this->_errors = array();
         // Polish up some field content
         $fields = $_POST['fields'];
         if (isset($fields['pages'])) {
             $fields['pages'] = implode(',', $fields['pages']);
         }
         $fields['content_formatted'] = DocumentationForm::applyFormatting($fields['content'], true, $this->_errors);
         if ($fields['content_formatted'] === false) {
             $fields['content_formatted'] = General::sanitize(DocumentationForm::applyFormatting($fields['content']));
         }
         if (!isset($fields['title']) || trim($fields['title']) == '') {
             $this->_errors['title'] = __('Title is a required field');
         }
         if (!isset($fields['pages']) || trim($fields['pages']) == '') {
             $this->_errors['pages'] = __('Page is a required field');
         }
         if (!isset($fields['content']) || trim($fields['content']) == '') {
             $this->_errors['content'] = __('Content is a required field');
         }
         if (empty($this->_errors)) {
             if (!Symphony::Database()->insert($fields, 'tbl_documentation')) {
                 $this->pageAlert(__('Unknown errors occurred while attempting to save. Please check your <a href="%s">activity log</a>.', array(URL . '/symphony/system/log/')), Alert::ERROR);
             } else {
                 $doc_id = Symphony::Database()->getInsertID();
                 redirect(URL . "/symphony/extension/documenter/edit/{$doc_id}/created/");
             }
         }
     }
     if (is_array($this->_errors) && !empty($this->_errors)) {
         $this->pageAlert(__('An error occurred while processing this form. <a href="#error">See below for details.</a>'), Alert::ERROR);
     }
 }
 function applyFormatting($data, $validate = false, &$errors = NULL)
 {
     include_once TOOLKIT . '/class.textformattermanager.php';
     $text_formatter = Symphony::Configuration()->get('text-formatter', 'documentation');
     if ($text_formatter != 'none') {
         $formatter = TextformatterManager::create($text_formatter);
         $result = $formatter->run($data);
     } else {
         $result = $data;
     }
     if ($validate === true) {
         include_once TOOLKIT . '/class.xsltprocess.php';
         if ($text_formatter == 'none') {
             $result = DocumentationForm::__replaceAmpersands($result);
         } else {
             if (!General::validateXML($result, $errors, false, new XsltProcess())) {
                 $result = html_entity_decode($result, ENT_QUOTES, 'UTF-8');
                 $result = DocumentationForm::__replaceAmpersands($result);
                 if (!General::validateXML($result, $errors, false, new XsltProcess())) {
                     $result = $formatter->run(General::sanitize($data));
                     if (!General::validateXML($result, $errors, false, new XsltProcess())) {
                         return false;
                     }
                 }
             }
         }
     }
     return $result;
 }