public function view() { $this->setPageType('table'); $this->appendSubheading(__('Templated Text Formatters'), Widget::Anchor(__('Create New'), URL . '/symphony/extension/templatedtextformatters/edit/', __('Create a new hub'), 'create button')); $aTableHead = array(array(__('Title'), 'col'), array(__('Type'), 'col'), array(__('Description'), 'col')); $aTableBody = array(); $formatters = $this->_driver->listAll(); if (!is_array($formatters) || empty($formatters)) { $aTableBody = array(Widget::TableRow(array(Widget::TableData(__('None found.'), 'inactive', NULL, count($aTableHead))))); } else { $tfm = new TextformatterManager($this->_Parent); foreach ($formatters as $id => $data) { $formatter = $tfm->create($id); $about = $formatter->about(); $td1 = Widget::TableData(Widget::Anchor($about['name'], URL . "/symphony/extension/templatedtextformatters/edit/{$id}/", $about['name'])); $td2 = Widget::TableData($about['templatedtextformatters-type']); $td3 = Widget::TableData($about['description']); $td1->appendChild(Widget::Input('items[' . $id . ']', NULL, 'checkbox')); // Add a row to the body array, assigning each cell to the row $aTableBody[] = Widget::TableRow(array($td1, $td2, $td3)); } } $table = Widget::Table(Widget::TableHead($aTableHead), NULL, Widget::TableBody($aTableBody)); $this->Form->appendChild($table); $div = new XMLElement('div'); $div->setAttribute('class', 'actions'); $options = array(array(NULL, false, __('With Selected...')), array('delete', false, __('Delete'))); $div->appendChild(Widget::Select('with-selected', $options)); $div->appendChild(Widget::Input('action[apply]', __('Apply'), 'submit')); $this->Form->appendChild($div); }
protected function __applyFormatting($data, $validate = false, &$errors = NULL) { if ($this->get('formatter')) { $formatter = TextformatterManager::create($this->get('formatter')); $result = $formatter->run($data); } if ($validate === true) { include_once TOOLKIT . '/class.xsltprocess.php'; if (!General::validateXML($result, $errors, false, new XsltProcess())) { $result = html_entity_decode($result, ENT_QUOTES, 'UTF-8'); $result = $this->__replaceAmpersands($result); if (!General::validateXML($result, $errors, false, new XsltProcess())) { return false; } } } return $result; }
function view() { if (!$this->_context[0]) { echo __('Error: No formatter selected.'); exit; } $value = $_POST['data']; if (!$value) { exit; } $tm = new TextformatterManager($this->_Parent); $formatter = $tm->create($this->_context[0]); if (!$formatter) { echo __('Error: %s text formatter does not exist.', array($this->_context[0])); exit; } echo $formatter->run($value); exit; }
public function view() { // Determine which formatter to use // The textarea keeps this info in its class attribute, but sometimes there might be additional classes. // We'll grab one that matches the installed formatters. $fM = new TextformatterManager($this); $formatter_handle = array_pop(array_intersect(array_keys($fM->listAll()), explode(' ', $_POST['formatter']))); // We pass the full formatter name back for use in the preview display $format_name = new XMLElement('formatter'); $preview = new XMLElement('preview'); if (empty($formatter_handle)) { $format_name->setValue('None'); $preview->setValue($_POST['formatText']); } else { $formatter = $fM->create($formatter_handle); $formatter_about = $formatter->about(); $format_name->setValue($formatter_about['name']); $preview->setValue($formatter->run($_POST['formatText'])); } $this->_Result->appendChild($format_name); $this->_Result->appendChild($preview); }
public function run($string) { if (strlen(trim($string)) < 1) { return $string; } if (count($this->_formatters) < 1) { return stripslashes($string); } if (isset(self::$_recursion[__CLASS__]) && self::$_recursion[__CLASS__] > 0) { return "<!-- CHAIN RECURSION ERROR\n*\n*\t" . __("Detected text formatter recursion on %s", array("\n*\tMarkdown SmartyPants x No orphans (ttf_markdown_smartypants_x_no_orphans)")) . "\n*\t" . __("Formatter was run by %s", array("\n*\t" . end(FormatterChain::$stack))) . "\n*\n//-->" . stripslashes($string); } self::$_recursion[__CLASS__]++; FormatterChain::$stack[] = 'Markdown SmartyPants x No orphans (ttf_markdown_smartypants_x_no_orphans)'; $result = $string; foreach ($this->_formatters as $id => $name) { $formatter = TextformatterManager::create($id); $result = $formatter->run($result); } array_pop(FormatterChain::$stack); self::$_recursion[__CLASS__]--; return stripslashes($result); }
public function view() { $this->setPageType('table'); $this->setTitle(__('%1$s – %2$s', array(__('Templated Text Formatters'), __('Symphony')))); $this->appendSubheading(__('Templated Text Formatters'), Widget::Anchor(__('Create New'), URL . '/symphony/extension/templatedtextformatters/edit/', __('Create a new formatter'), 'create button', NULL, array('accesskey' => 'c'))); $aTableHead = array(array(__('Name'), 'col'), array(__('Type'), 'col'), array(__('Description'), 'col')); $aTableBody = array(); $formatters = $this->_driver->listAll(); if (!is_array($formatters) || empty($formatters)) { $aTableBody = array(Widget::TableRow(array(Widget::TableData(__('None found.'), 'inactive', NULL, count($aTableHead))), 'odd')); } else { foreach ($formatters as $id => $data) { $formatter = TextformatterManager::create($id); $about = $formatter->about(); $td1 = Widget::TableData(Widget::Anchor($about['name'], URL . "/symphony/extension/templatedtextformatters/edit/{$id}/", $about['name'])); $td2 = Widget::TableData($about['templatedtextformatters-type']); $td3 = Widget::TableData(General::sanitize($about['description'])); $td1->appendChild(Widget::Label(__('Select Text Formatter %s', array($about['name'])), null, 'accessible', null, array('for' => 'ttf-' . $id))); $td1->appendChild(Widget::Input('items[' . $id . ']', 'on', 'checkbox', array('id' => 'ttf-' . $id))); // Add a row to the body array, assigning each cell to the row $aTableBody[] = Widget::TableRow(array($td1, $td2, $td3)); } } $table = Widget::Table(Widget::TableHead($aTableHead), NULL, Widget::TableBody($aTableBody), 'selectable', null, array('role' => 'directory', 'aria-labelledby' => 'symphony-subheading', 'data-interactive' => 'data-interactive')); $this->Form->appendChild($table); $version = new XMLElement('p', 'Symphony ' . Symphony::Configuration()->get('version', 'symphony'), array('id' => 'version')); $this->Form->appendChild($version); $div = new XMLElement('div'); $div->setAttribute('class', 'actions'); $options = array(array(NULL, false, __('With Selected...')), array('delete', false, __('Delete'), 'confirm', null, array('data-message' => __('Are you sure you want to delete the selected text formatters?')))); Symphony::ExtensionManager()->notifyMembers('AddCustomActions', '/templatedtextformatters/', array('options' => &$options)); if (!empty($options)) { $div->appendChild(Widget::Apply($options)); $this->Form->appendChild($div); } }
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; }
public function applyFormatting($data) { if ($this->get('text_formatter') != 'none') { if (isset($this->_ParentCatalogue['entrymanager'])) { $tfm = $this->_ParentCatalogue['entrymanager']->formatterManager; } else { $tfm = new TextformatterManager($this->_engine); } $formatter = $tfm->create($this->get('text_formatter')); $formatted = $formatter->run($data); $formatted = preg_replace('/&(?![a-z]{0,4}\\w{2,3};|#[x0-9a-f]{2,6};)/i', '&', $formatted); return $formatted; } return General::sanitize($data); }
public function render_panel($context) { $config = $context['config']; switch ($context['type']) { case 'datasource_to_table': $ds = DatasourceManager::create($config['datasource'], NULL, false); if (!$ds) { $context['panel']->appendChild(new XMLElement('div', __('The Data Source with the name <code>%s</code> could not be found.', array($config['datasource'])))); return; } $param_pool = array(); $xml = $ds->grab($param_pool); if (!$xml) { return; } $xml = $xml->generate(); require_once TOOLKIT . '/class.xsltprocess.php'; $proc = new XsltProcess(); $data = $proc->process($xml, file_get_contents(EXTENSIONS . '/dashboard/lib/datasource-to-table.xsl')); $context['panel']->appendChild(new XMLElement('div', $data)); break; case 'rss_reader': require_once TOOLKIT . '/class.gateway.php'; require_once CORE . '/class.cacheable.php'; $cache_id = md5('rss_reader_cache' . $config['url']); $cache = new Cacheable(Administration::instance()->Database()); $data = $cache->check($cache_id); if (!$data) { $ch = new Gateway(); $ch->init(); $ch->setopt('URL', $config['url']); $ch->setopt('TIMEOUT', 6); $new_data = $ch->exec(); $writeToCache = true; if ((int) $config['cache'] > 0) { $cache->write($cache_id, $new_data, $config['cache']); } $xml = $new_data; if (empty($xml) && $data) { $xml = $data['data']; } } else { $xml = $data['data']; } if (!$xml) { $xml = '<error>' . __('Error: could not retrieve panel XML feed.') . '</error>'; } require_once TOOLKIT . '/class.xsltprocess.php'; $proc = new XsltProcess(); $data = $proc->process($xml, file_get_contents(EXTENSIONS . '/dashboard/lib/rss-reader.xsl'), array('show' => $config['show'])); $context['panel']->appendChild(new XMLElement('div', $data)); break; case 'html_block': require_once TOOLKIT . '/class.gateway.php'; require_once CORE . '/class.cacheable.php'; $cache_id = md5('html_block_' . $config['url']); $cache = new Cacheable(Administration::instance()->Database()); $data = $cache->check($cache_id); if (!$data) { $ch = new Gateway(); $ch->init(); $ch->setopt('URL', $config['url']); $ch->setopt('TIMEOUT', 6); $new_data = $ch->exec(); $writeToCache = true; if ((int) $config['cache'] > 0) { $cache->write($cache_id, $new_data, $config['cache']); } $html = $new_data; if (empty($html) && $data) { $html = $data['data']; } } else { $html = $data['data']; } if (!$html) { $html = '<p class="invalid">' . __('Error: could not retrieve panel HTML.') . '</p>'; } $context['panel']->appendChild(new XMLElement('div', $html)); break; case 'symphony_overview': $container = new XMLElement('div'); $dl = new XMLElement('dl'); $dl->appendChild(new XMLElement('dt', __('Website Name'))); $dl->appendChild(new XMLElement('dd', Symphony::Configuration()->get('sitename', 'general'))); $current_version = Symphony::Configuration()->get('version', 'symphony'); require_once TOOLKIT . '/class.gateway.php'; $ch = new Gateway(); $ch->init(); $ch->setopt('URL', 'https://api.github.com/repos/symphonycms/symphony-2/tags'); $ch->setopt('TIMEOUT', $timeout); $repo_tags = $ch->exec(); // tags request found if (is_array($repo_tags)) { $repo_tags = json_decode($repo_tags); $tags = array(); foreach ($repo_tags as $tag) { // remove tags that contain strings if (preg_match('/[a-zA]/i', $tag->name)) { continue; } $tags[] = $tag->name; } natsort($tags); rsort($tags); $latest_version = reset($tags); } else { $latest_version = $current_version; } $needs_update = version_compare($latest_version, $current_version, '>'); $dl->appendChild(new XMLElement('dt', __('Version'))); $dl->appendChild(new XMLElement('dd', $current_version . ($needs_update ? ' (<a href="http://getsymphony.com/download/releases/version/' . $latest_version . '/">' . __('Latest is %s', array($latest_version)) . "</a>)" : ''))); $container->appendChild(new XMLElement('h4', __('Configuration'))); $container->appendChild($dl); $entries = 0; foreach (SectionManager::fetch() as $section) { $entries += EntryManager::fetchCount($section->get('id')); } $dl = new XMLElement('dl'); $dl->appendChild(new XMLElement('dt', __('Sections'))); $dl->appendChild(new XMLElement('dd', (string) count(SectionManager::fetch()))); $dl->appendChild(new XMLElement('dt', __('Entries'))); $dl->appendChild(new XMLElement('dd', (string) $entries)); $dl->appendChild(new XMLElement('dt', __('Data Sources'))); $dl->appendChild(new XMLElement('dd', (string) count(DatasourceManager::listAll()))); $dl->appendChild(new XMLElement('dt', __('Events'))); $dl->appendChild(new XMLElement('dd', (string) count(EventManager::listAll()))); $dl->appendChild(new XMLElement('dt', __('Pages'))); $dl->appendChild(new XMLElement('dd', (string) count(PageManager::fetch()))); $container->appendChild(new XMLElement('h4', __('Statistics'))); $container->appendChild($dl); $context['panel']->appendChild($container); break; case 'markdown_text': $formatter = TextformatterManager::create($config['formatter']); $html = $formatter->run($config['text']); $context['panel']->appendChild(new XMLElement('div', $html)); break; } }
public function applyFormatting($data) { if ($this->get('formatter') != 'none') { $tfm = new TextformatterManager(Symphony::Engine()); $formatter = $tfm->create($this->get('formatter')); $formatted = $formatter->run($data); return preg_replace('/&(?![a-z]{0,4}\\w{2,3};|#[x0-9a-f]{2,6};)/i', '&', $formatted); } return null; }
function insertComment($comment, $isSpam = false) { $comment['author_id'] = NULL; $author_id = $this->_parent->isLoggedIn(); if ($author_id !== false) { $comment['author_id'] = $author_id; } $comment['author_ip'] = $_SERVER['REMOTE_ADDR']; #### # Delegate: CommentPreProcess # Description: Just before the comment is processed and saved. Good place to manipulate the data. $this->_parent->_CampfireManager->notifyMembers('CommentPreProcess', '/frontend/', array('isSpam' => &$isSpam, 'comment' => &$comment)); $this->isLastCommentSpam = $isSpam; unset($comment['remember']); $section = $this->_db->fetchRow(0, "SELECT * FROM tbl_sections WHERE `handle` = '" . $comment['section'] . "' LIMIT 1"); if (!is_array($section) || empty($section)) { $this->_notices[] = 'Invalid section specified.'; return false; } unset($comment['section']); if (isset($comment['entry_handle'])) { include_once TOOLKIT . "/class.entrymanager.php"; $entryManager = new EntryManager($this->_parent); $entry_id = $entryManager->fetchEntryIDFromPrimaryFieldHandle($section['id'], $comment['entry_handle']); $comment['entry_id'] = $entry_id[0]; unset($comment['entry_handle']); } if (!($entry = $entryManager->fetchEntriesByID($comment['entry_id'], false, true))) { $this->_notices[] = 'Invalid entry handle specified.'; return false; } if ($section['commenting'] == 'off') { return false; } $this->_notices = array(); $valid = $this->__validateComment($comment); if (!isset($this->_options['override-automatic-spam-detection']) || $this->_options['override-automatic-spam-detection'] == false) { $spam = $this->__isSpam($comment) || $this->__isBlackListed($comment['author_ip']); } else { $spam = $isSpam || $this->__isBlackListed($comment['author_ip']) ? true : false; } $comment = array_map(array($this, "__doBanWords"), $comment); $options = $this->_options; require_once LIBRARY . "/core/class.textformattermanager.php"; $TFM = new TextformatterManager(array('parent' => &$this->_parent)); if ($options['formatting-type'] != NULL && ($formatter = $TFM->create($options['formatting-type']))) { $comment['body'] = $formatter->run($comment['body']); } else { $comment['body'] = strip_tags($comment['body']); } $comment['author_url'] = General::validateUrl($comment['author_url']); $comment['spam'] = $spam ? "yes" : "no"; ##Check the comment body for well-formedness $xml_errors = array(); General::validateXML($comment['body'], $xml_errors, false); if (!empty($xml_errors)) { $xml_errors = array(); $comment['body'] = str_replace(array('<', '>', '&'), array('<', '>', '&'), $comment['body']); General::validateXML($comment['body'], $xml_errors, false, new XsltProcess()); if (!empty($xml_errors)) { $this->_notices[] = "Comment contains invalid text or markup."; return false; } } ## ##Check the comment name field for well-formedness $xml_errors = array(); General::validateXML($comment['author_name'], $xml_errors, false); if (!empty($xml_errors)) { $this->_notices[] = "Author name contains invalid text or markup."; } ## $dupe = $options['allow-duplicates'] == "on" ? false : $this->__isDuplicateComment($comment); $nuke_comment = !empty($xml_errors) || $spam && $options['nuke-spam'] == 'on'; #### # Delegate: CommentPreSave # Description: Just before the comment is inserted into the database. Also, final checks # of its validity have been performed. Good place to manipulate the data and check values $this->_parent->_CampfireManager->notifyMembers('CommentPreSave', '/frontend/', array('nuke' => &$nuke_comment, 'dupe' => &$dupe, 'comment' => &$comment)); if (!$nuke_comment && $valid && !$dupe) { if ($spam) { $this->isLastCommentSpam = true; } unset($comment['author_ip']); if ($this->_db->insert($comment, "tbl_comments")) { $comment_id = $this->_db->getInsertID(); $this->_parent->updateMetadata("comment", $comment_id); #### # Delegate: CommentPostSave # Description: After inserting comment into database. Comment ID is provided $this->_parent->_CampfireManager->notifyMembers('CommentPostSave', '/frontend/', array('id' => $comment_id)); if ($options['email-notify'] == 'on' && !$spam) { $this->__emailEntryAuthor($comment, $entry); } return true; } else { $this->_notices[] = 'Comment not successfully saved. An unknown error has occurred.'; } } else { if (!$valid || $nuke_comment) { $this->_notices[] = 'Comment flagged as spam and has not been saved.'; $this->isLastCommentSpam = true; } else { if ($dupe) { $this->_notices[] = 'Duplicate post detected.'; } } } #### # Delegate: CommentFailedInsert # Description: After a failed insert. Notices are provided $this->_parent->_CampfireManager->notifyMembers('CommentFailedInsert', '/frontend/', array('notices' => $this->_notices)); return false; }
public function getFormatter($name) { $tfm = new TextformatterManager($this->_Parent); $formatter = $tfm->create($name); return array('about' => $formatter->about(), 'options' => $formatter->options()); }
function applyFormatting($data) { if ($this->get('formatter')) { if (isset($this->_ParentCatalogue['entrymanager'])) { $tfm = $this->_ParentCatalogue['entrymanager']->formatterManager; } else { $tfm = new TextformatterManager($this->_engine); } $formatter = $tfm->create($this->get('formatter')); return $formatter->run($data); } return NULL; }
##Entries if (!defined("__SYM_MIGRATION_ERRORS__")) { $Admin->log->pushToLog("Migrating Entries Table", SYM_LOG_NOTICE, true, true); //--------------------- $TFM = new TextformatterManager(array('parent' => &$Admin)); $sql = "SELECT `id`, `title`, `body_raw`, `formatter` FROM `tbl_entries`"; if (!($entries = $DB->fetch($sql))) { $error = true; $Admin->log->pushToLog("Could not get entry records from database", SYM_LOG_ERROR, true, true); } if (!$error && is_array($entries) && !empty($entries)) { foreach ($entries as $e) { $error = false; $Admin->log->pushToLog("Converting '" . $e['title'] . "' ... ", SYM_LOG_NOTICE, true, false); $fields = array(); if ($e['formatter'] && !($formatter = $TFM->create($e['formatter'], array(), true))) { $error = true; $Admin->log->pushToLog("Failed (Could not create formatter '" . $e['formatter'] . "')", SYM_LOG_NOTICE, true, true, true); } else { if ($e['formatter'] != NULL) { $fields['body'] = $formatter->run(General::reverse_sanitize($e['body_raw'])); } else { $fields['body'] = General::reverse_sanitize($e['body_raw']); } $fields['excerpt'] = General::limitWords($fields['body']); $fields['excerpt'] = preg_replace('/[\\s]+/', ' ', $fields['excerpt']); ##Update the entry if (!$DB->update($fields, "tbl_entries", "WHERE `id` = '" . $e['id'] . "' LIMIT 1")) { $error = true; $Admin->log->pushToLog("Failed (Problem updating fields)", SYM_LOG_NOTICE, true, true, true); } else {
protected function __applyFormatting($data, $validate = false, &$errors = NULL) { if ($this->get('formatter')) { if (isset($this->_ParentCatalogue['entrymanager'])) { $tfm = $this->_ParentCatalogue['entrymanager']->formatterManager; } else { $tfm = new TextformatterManager($this->_engine); } $formatter = $tfm->create($this->get('formatter')); $result = $formatter->run($data); } if ($validate === true) { include_once TOOLKIT . '/class.xsltprocess.php'; if (!General::validateXML($result, $errors, false, new XsltProcess())) { $result = html_entity_decode($result, ENT_QUOTES, 'UTF-8'); $result = $this->__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; }
public function applyFormatting($data) { if ($this->get('text_formatter') != 'none') { $formatter = TextformatterManager::create($this->get('text_formatter')); $formatted = $formatter->run($data); $formatted = preg_replace('/&(?![a-z]{0,4}\\w{2,3};|#[x0-9a-f]{2,6};)/i', '&', $formatted); return trim($formatted); } return General::sanitize(trim($data)); }
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 */']; } } }