if (isset($_GET['_f'])) {
    switch ($_GET['_f']) {
        case "saved":
            $Admin->pageAlert("saved-time", array("Entry", date("h:i:sa", $date->get(true, false))));
            break;
    }
}
if (defined("__SYM_ENTRY_MISSINGFIELDS__")) {
    $Admin->pageAlert("required", array(@implode(", ", $entryManager->fetchEntryRequiredFields($section_id, true))), false, 'error');
} elseif (defined("__SYM_ENTRY_VALIDATION_ERROR__")) {
    $Admin->pageAlert("validation", __SYM_ENTRY_VALIDATION_ERROR__, false, 'error');
} elseif (defined("__SYM_ENTRY_FIELD_XSLT_ERROR__")) {
    $Admin->pageAlert("xslt-validation", __SYM_ENTRY_FIELD_XSLT_ERROR__, false, 'error');
} else {
    $TFM = new TextformatterManager(array('parent' => &$Admin));
    $about = $TFM->about($fields['formatter']);
    $entry_formatter = $about['name'];
    $about = $TFM->about($Admin->getAuthorTextFormatter());
    $author_formatter = $about['name'];
    unset($TFM);
    if ($entry_formatter != $author_formatter) {
        $Admin->pageAlert("diff-formatter", array($entry_formatter ? $entry_formatter : "raw XHTML", $author_formatter ? $author_formatter : "raw XHTML"), false, 'error');
    }
}
if (!empty($_POST['fields'])) {
    $fields = $_POST['fields'];
    $date->set(strtotime($fields["time"] . " " . $fields['publish_date']));
} else {
    $date->set($fields['timestamp_gmt'], false);
}
$upload_fields = $entryManager->fetchEntryFieldSchema($_REQUEST['_sid'], array('upload'));
 public function save()
 {
     $about = array();
     if ($this->_context[0] && !is_object($this->formatter)) {
         $this->formatter = TextformatterManager::create($this->_context[0]);
     }
     if (is_object($this->formatter)) {
         $about = TextformatterManager::about($this->_context[0]);
     }
     $fields = $_POST['fields'];
     $driverAbout = ExtensionManager::about('templatedtextformatters');
     $types = $this->_driver->listTypes();
     if (strlen(trim($fields['name'])) < 1) {
         $this->_errors['name'] = __('You have to specify name for text formatter');
         return;
     }
     if ($about['templatedtextformatters-type'] && $about['templatedtextformatters-type'] != $fields['type']) {
         $this->_errors['type'] = __('Changing type of already existing formatter is not allowed');
         return;
     }
     if (!$fields['type'] || !is_array($types[$fields['type']]) || !isset($types[$fields['type']]['path'])) {
         $this->_errors['type'] = __('There is no <code>%s</code> type available', array($fields['type']));
         return;
     }
     $tplfile = $types[$fields['type']]['path'] . '/formatter.' . $fields['type'] . '.tpl';
     if (!@is_file($tplfile)) {
         $this->_errors['type'] = __('Wrong type of text formatter');
         return;
     }
     $classname = 'ttf_' . Lang::createHandle(trim($fields['name']), NULL, '_', false, true, array('@^[^a-z]+@i' => '', '/[^\\w-\\.]/i' => ''));
     $file = TEXTFORMATTERS . '/formatter.' . $classname . '.php';
     $isDuplicate = false;
     $queueForDeletion = NULL;
     if (!$about['handle'] && @is_file($file)) {
         $isDuplicate = true;
     } else {
         if ($about['handle']) {
             if ($classname != $about['handle'] && @is_file($file)) {
                 $isDuplicate = true;
             } elseif ($classname != $about['handle']) {
                 $queueForDeletion = TEXTFORMATTERS . '/formatter.' . $about['handle'] . '.php';
             }
         }
     }
     // Duplicate
     if ($isDuplicate) {
         $this->_errors['name'] = __('Text formatter with the name <code>%s</code> already exists', array($classname));
     }
     if (!empty($this->_errors)) {
         return;
     }
     $description = trim($fields['description']);
     if (empty($description)) {
         $description = __('N/A');
     }
     // https://github.com/symphonycms/symphony-2/wiki/Migration-Guide-to-2.5-for-Developers#properties
     if (is_callable(array('Symphony', 'Author'))) {
         $author = Symphony::Author();
     } else {
         $author = Administration::instance()->Author;
     }
     $tokens = array('___' . $fields['type'] . '/* CLASS NAME */' => $classname, '/* NAME */' => preg_replace('/[^\\w\\s\\.-_\\&\\;]/i', '', trim($fields['name'])), '/* AUTHOR NAME */' => self::cleanupString($author->getFullName()), '/* AUTHOR WEBSITE */' => self::cleanupString(URL), '/* AUTHOR EMAIL */' => self::cleanupString($author->get('email')), '/* RELEASE DATE */' => DateTimeObj::getGMT('c'), '/* DESCRIPTION */' => self::cleanupString($description), '/* TEMPLATEDTEXTFORMATTERS VERSION */' => $driverAbout['version'], '/* TEMPLATEDTEXTFORMATTERS TYPE */' => $fields['type']);
     if (!is_object($this->formatter)) {
         include_once $tplfile;
         $temp = 'formatter___' . $fields['type'];
         $temp = new $temp();
         if (method_exists($temp, 'ttf_tokens')) {
             $tokens = array_merge($tokens, $temp->ttf_tokens());
         }
     } else {
         if (method_exists($this->formatter, 'ttf_tokens')) {
             $tokens = array_merge($tokens, $this->formatter->ttf_tokens());
         }
     }
     $ttfShell = file_get_contents($tplfile);
     $ttfShell = str_replace(array_keys($tokens), $tokens, $ttfShell);
     $ttfShell = str_replace('/* CLASS NAME */', $classname, $ttfShell);
     // Write the file
     if (!is_writable(dirname($file)) || !($write = General::writeFile($file, $ttfShell, Symphony::Configuration()->get('write_mode', 'file')))) {
         $this->pageAlert(__('Failed to write Text Formatter source to <code>%s</code>. Please check permissions.', array($file)), Alert::ERROR);
     } else {
         if ($queueForDeletion || !$about['name']) {
             if ($queueForDeletion) {
                 General::deleteFile($queueForDeletion);
             }
             // TODO: Find a way to make formatted fields update their content
             $_SESSION['templatedtextformatters-alert'] = 'created';
             redirect(URL . '/symphony/extension/templatedtextformatters/edit/' . $classname);
         } else {
             // Update current data
             $_SESSION['templatedtextformatters-alert'] = 'saved';
             $_POST['fields']['name'] = $tokens['/* NAME */'];
             $_POST['fields']['description'] = $tokens['/* DESCRIPTION */'];
         }
     }
 }