/** * \static Formats text using the given formatter. This method is useful if * you don't want to instantiate a TextFormatter object. If you want to * reuse the textformatter instance, don't use this method. * * \param $text * String with text to format * * \param $formatter * The name of the formatter to use (optional) * * \return * String containing the formatted text */ function format($text, $formatter = null) { // {{{ assert('is_string($text)'); assert('is_string($formatter) || is_null($formatter)'); $f = new TextFormatter($text, $formatter); return $f->render(); }
<?php error_reporting(E_ALL); require_once '../anewt.lib.php'; anewt_include('textformatting'); /* Simple text */ $input = 'This is a test.'; var_dump(TextFormatter::format($input)); var_dump(TextFormatter::format($input, 'raw')); var_dump(TextFormatter::format($input, 'specialchars')); var_dump(TextFormatter::format($input, 'entities')); var_dump(TextFormatter::format($input, 'textile')); /* HTML text (with leading whitespace!) */ $input = ' <p>This is a <strong>test</strong>.</p>'; var_dump(TextFormatter::format($input)); var_dump(TextFormatter::format($input, 'raw')); var_dump(TextFormatter::format($input, 'specialchars')); var_dump(TextFormatter::format($input, 'entities')); var_dump(TextFormatter::format($input, 'textile'));
$reopened = $db->Query('SELECT COUNT(*) FROM {history} WHERE task_id = ? AND event_type = 13', array($task_id)); // Check for cached version $cached = $db->Query("SELECT content, last_updated\n FROM {cache}\n WHERE topic = ? AND type = 'task'", array($task_details['task_id'])); $cached = $db->FetchRow($cached); // List of votes $get_votes = $db->Query('SELECT u.user_id, u.user_name, u.real_name, v.date_time FROM {votes} v LEFT JOIN {users} u ON v.user_id = u.user_id WHERE v.task_id = ? ORDER BY v.date_time DESC', array($task_id)); if ($task_details['last_edited_time'] > $cached['last_updated'] || !defined('FLYSPRAY_USE_CACHE')) { $task_text = TextFormatter::render($task_details['detailed_desc'], 'task', $task_details['task_id']); } else { $task_text = TextFormatter::render($task_details['detailed_desc'], 'task', $task_details['task_id'], $cached['content']); } $page->assign('prev_id', $prev_id); $page->assign('next_id', $next_id); $page->assign('task_text', $task_text); $page->assign('subtasks', $subtasks_cleaned); $page->assign('deps', $check_deps_cleaned); $page->assign('parent', $db->fetchAllArray($parent)); $page->assign('blocks', $check_blocks_cleaned); $page->assign('votes', $db->fetchAllArray($get_votes)); $page->assign('penreqs', $db->fetchAllArray($get_pending)); $page->assign('d_open', $db->fetchOne($open_deps)); $page->assign('watched', $db->fetchOne($watching)); $page->assign('reopened', $db->fetchOne($reopened)); $page->pushTpl('details.view.tpl'); ///////////////
public function appendFormatterSelect(SymphonyDOMElement $wrapper, $selected = NULL, $name = 'fields[format]', $label_value = null) { require_once LIB . '/class.textformatter.php'; if (!$label_value) { $label_value = __('Text Formatter'); } $label = Widget::Label($label_value); $document = $wrapper->ownerDocument; $options = array(); $options[] = array(NULL, false, __('None')); $iterator = new TextFormatterIterator(); if ($iterator->length() > 0) { foreach ($iterator as $pathname) { $handle = TextFormatter::getHandleFromFilename(basename($pathname)); $tf = TextFormatter::load($pathname); $options[] = array($handle, $selected == $handle, constant(sprintf('%s::NAME', get_class($tf)))); } } $label->appendChild(Widget::Select($name, $options)); $wrapper->appendChild($label); }
} if (str_has_prefix($arg, '--')) { continue; } $fd = fopen($arg, 'r'); $title = $arg; break; } /* Input */ $input_chunks = array(); while (!feof($fd)) { $input_chunks[] = fread($fd, 16384); } $input = join('', $input_chunks); fclose($fd); /* Output */ $output = TextFormatter::format($input, 'textile'); $output = trim($output); if ($use_page) { anewt_include('page'); $page = new AnewtPage(); $page->enable_dublin_core = false; $page->content_type = 'application/xhtml+xml'; $page->charset = 'UTF-8'; $page->title = $title; $page->add_stylesheet_href_media('style.css', 'screen'); $page->append(ax_raw($output)); echo to_string($page), NL; } else { echo $output, NL; }
public static function loadFromHandle($handle) { if (!is_array(self::$formatters)) { self::$formatters = array(); } if (!self::$iterator instanceof TextFormatterIterator) { self::$iterator = new TextFormatterIterator(); } self::$iterator->rewind(); if (in_array($handle, array_values(self::$formatters))) { $tmp = array_flip(self::$formatters); return new $tmp[$handle](); } foreach (self::$iterator as $tf) { if (basename($tf) == "{$handle}.php") { return self::load($tf); } } throw new TextFormatterException("No such Formatter '{$handle}'"); }
public function applyFormatting($value) { if (isset($this->{'text-formatter'}) and $this->{'text-formatter'} != TextFormatter::NONE) { try { $formatter = TextFormatter::loadFromHandle($this->{'text-formatter'}); $result = $formatter->run($value); $result = preg_replace('/&(?![a-z]{0,4}\\w{2,3};|#[x0-9a-f]{2,6};)/i', '&', $result); return $result; } catch (Exception $e) { // Problem loading the formatter // TODO: Decide is we should be handling this better. } } return General::sanitize($value); }
/** * XXX: A mess,remove my in 1.0. No time for that, sorry. */ function event_description($history) { $return = ''; global $fs, $baseurl, $details, $proj; $translate = array('item_summary' => 'summary', 'project_id' => 'attachedtoproject', 'task_type' => 'tasktype', 'product_category' => 'category', 'item_status' => 'status', 'task_priority' => 'priority', 'operating_system' => 'operatingsystem', 'task_severity' => 'severity', 'product_version' => 'reportedversion', 'mark_private' => 'visibility', 'estimated_effort' => 'estimatedeffort'); // if somehing gets double escaped, add it here. $noescape = array('new_value', 'old_value'); foreach ($history as $key => $value) { if (!in_array($key, $noescape)) { $history[$key] = Filters::noXSS($value); } } $new_value = $history['new_value']; $old_value = $history['old_value']; switch ($history['event_type']) { case '3': //Field changed if (!$new_value && !$old_value) { $return .= eL('taskedited'); break; } $field = $history['field_changed']; switch ($field) { case 'item_summary': case 'project_id': case 'task_type': case 'product_category': case 'item_status': case 'task_priority': case 'operating_system': case 'task_severity': case 'product_version': if ($field == 'task_priority') { $old_value = $fs->priorities[$old_value]; $new_value = $fs->priorities[$new_value]; } elseif ($field == 'task_severity') { $old_value = $fs->severities[$old_value]; $new_value = $fs->severities[$new_value]; } elseif ($field == 'item_summary') { $old_value = Filters::noXSS($old_value); $new_value = Filters::noXSS($new_value); } else { $old_value = $history[$field . '1']; $new_value = $history[$field . '2']; } $field = eL($translate[$field]); break; case 'closedby_version': $field = eL('dueinversion'); $old_value = $old_value == '0' ? eL('undecided') : $history['product_version1']; $new_value = $new_value == '0' ? eL('undecided') : $history['product_version2']; break; case 'due_date': $field = eL('duedate'); $old_value = formatDate($old_value, false, eL('undecided')); $new_value = formatDate($new_value, false, eL('undecided')); break; case 'percent_complete': $field = eL('percentcomplete'); $old_value .= '%'; $new_value .= '%'; break; case 'mark_private': $field = eL($translate[$field]); if ($old_value == 1) { $old_value = eL('private'); } else { $old_value = eL('public'); } if ($new_value == 1) { $new_value = eL('private'); } else { $new_value = eL('public'); } break; case 'detailed_desc': $field = "<a href=\"javascript:getHistory('{$history['task_id']}', '{$baseurl}', 'history', '{$history['history_id']}');showTabById('history', true);\">" . eL('details') . '</a>'; if (!empty($details)) { $details_previous = TextFormatter::render($old_value); $details_new = TextFormatter::render($new_value); } $old_value = ''; $new_value = ''; break; case 'estimated_effort': $field = eL($translate[$field]); $old_value = effort::SecondsToString($old_value, $proj->prefs['hours_per_manday'], $proj->prefs['estimated_effort_format']); $new_value = effort::SecondsToString($new_value, $proj->prefs['hours_per_manday'], $proj->prefs['estimated_effort_format']); break; } $return .= eL('fieldchanged') . ": {$field}"; if ($old_value || $new_value) { $return .= " ({$old_value} → {$new_value})"; } break; case '1': //Task opened $return .= eL('taskopened'); break; case '2': //Task closed $return .= eL('taskclosed'); $return .= " ({$history['resolution_name']}"; if (!empty($old_value)) { $return .= ': ' . TextFormatter::render($old_value, true); } $return .= ')'; break; case '4': //Comment added $return .= '<a href="#comments">' . eL('commentadded') . '</a>'; break; case '5': //Comment edited $return .= "<a href=\"javascript:getHistory('{$history['task_id']}', '{$baseurl}', 'history', '{$history['history_id']}');\">" . eL('commentedited') . "</a>"; if ($history['c_date_added']) { $return .= " (" . eL('commentby') . ' ' . tpl_userlink($history['c_user_id']) . " - " . formatDate($history['c_date_added'], true) . ")"; } if ($details) { $details_previous = TextFormatter::render($old_value); $details_new = TextFormatter::render($new_value); } break; case '6': //Comment deleted $return .= "<a href=\"javascript:getHistory('{$history['task_id']}', '{$baseurl}', 'history', '{$history['history_id']}');\">" . eL('commentdeleted') . "</a>"; if ($new_value != '' && $history['field_changed'] != '') { $return .= " (" . eL('commentby') . ' ' . tpl_userlink($new_value) . " - " . formatDate($history['field_changed'], true) . ")"; } if (!empty($details)) { $details_previous = TextFormatter::render($old_value); $details_new = ''; } break; case '7': //Attachment added $return .= eL('attachmentadded'); if ($history['orig_name']) { $return .= ": <a href=\"{$baseurl}?getfile=" . intval($new_value) . '">' . "{$history['orig_name']}</a>"; } else { if ($history['old_value']) { $return .= ': ' . $history['old_value']; } } break; case '8': //Attachment deleted $return .= eL('attachmentdeleted') . ': ' . Filters::noXSS($new_value); break; case '9': //Notification added $return .= eL('notificationadded') . ': ' . tpl_userlink($new_value); break; case '10': //Notification deleted $return .= eL('notificationdeleted') . ': ' . tpl_userlink($new_value); break; case '11': //Related task added $return .= eL('relatedadded') . ': ' . tpl_tasklink($new_value); break; case '12': //Related task deleted $return .= eL('relateddeleted') . ': ' . tpl_tasklink($new_value); break; case '13': //Task reopened $return .= eL('taskreopened'); break; case '14': //Task assigned if (empty($old_value)) { $users = explode(' ', trim($new_value)); $users = array_map('tpl_userlink', $users); $return .= eL('taskassigned') . ' '; $return .= implode(', ', $users); } elseif (empty($new_value)) { $return .= eL('assignmentremoved'); } else { $users = explode(' ', trim($new_value)); $users = array_map('tpl_userlink', $users); $return .= eL('taskreassigned') . ' '; $return .= implode(', ', $users); } break; // Mentioned in docs, not used anywhere. Will implement if suitable // translations already exist, otherwise leave to 1.1. (Found translations) // Mentioned in docs, not used anywhere. Will implement if suitable // translations already exist, otherwise leave to 1.1. (Found translations) case '15': // This task was added to another task's related list $return .= eL('addedasrelated') . ': ' . tpl_tasklink($new_value); break; case '16': // This task was removed from another task's related list $return .= eL('deletedasrelated') . ': ' . tpl_tasklink($new_value); break; case '17': //Reminder added $return .= eL('reminderadded') . ': ' . tpl_userlink($new_value); break; case '18': //Reminder deleted $return .= eL('reminderdeleted') . ': ' . tpl_userlink($new_value); break; case '19': //User took ownership $return .= eL('ownershiptaken') . ': ' . tpl_userlink($new_value); break; case '20': //User requested task closure $return .= eL('closerequestmade') . ' - ' . $new_value; break; case '21': //User requested task $return .= eL('reopenrequestmade') . ' - ' . $new_value; break; case '22': // Dependency added $return .= eL('depadded') . ' ' . tpl_tasklink($new_value); break; case '23': // Dependency added to other task $return .= eL('depaddedother') . ' ' . tpl_tasklink($new_value); break; case '24': // Dependency removed $return .= eL('depremoved') . ' ' . tpl_tasklink($new_value); break; case '25': // Dependency removed from other task $return .= eL('depremovedother') . ' ' . tpl_tasklink($new_value); break; // 26 and 27 replaced by 0 (mark_private) // 26 and 27 replaced by 0 (mark_private) case '28': // PM request denied $return .= eL('pmreqdenied') . ' - ' . $new_value; break; case '29': // User added to assignees list $return .= eL('addedtoassignees'); break; case '30': // user created $return .= eL('usercreated'); break; case '31': // user deleted $return .= eL('userdeleted'); break; case '32': // Subtask added $return .= eL('subtaskadded') . ' ' . tpl_tasklink($new_value); break; case '33': // Subtask removed $return .= eL('subtaskremoved') . ' ' . tpl_tasklink($new_value); break; case '34': // supertask added $return .= eL('supertaskadded') . ' ' . tpl_tasklink($new_value); break; case '35': // supertask removed $return .= eL('supertaskremoved') . ' ' . tpl_tasklink($new_value); break; } if (isset($details_previous)) { $GLOBALS['details_previous'] = $details_previous; } if (isset($details_new)) { $GLOBALS['details_new'] = $details_new; } return $return; }
<?php define('IN_FS', true); header('Content-type: text/html; charset=utf-8'); $webdir = dirname(dirname(dirname(htmlspecialchars($_SERVER['PHP_SELF'], ENT_QUOTES, 'utf-8')))); require_once '../../header.php'; if (Cookie::has('flyspray_userid') && Cookie::has('flyspray_passhash')) { $user = new User(Cookie::val('flyspray_userid')); $user->check_account_ok(); } else { $user = new User(0, $proj); } # TODO csrftoken checking echo TextFormatter::render(Post::val('text'));
/** * @return null */ public function testArrayData() { $data = array(array('foo', 'bar', 'baz'), array('biz', 'wiz', 'kiz')); $expected = "foo,bar,baz" . PHP_EOL . "biz,wiz,kiz" . PHP_EOL; $this->assertEquals($expected, $this->compositor->compose($data)); }
function __construct($args = array()) { parent::__construct($args); }
<?php require_once dirname(__FILE__) . '/../anewt.lib.php'; define('ANEWT_TEXTILE_DEVELOPMENT', 1); anewt_include('page'); $p = new AnewtPage(); $p->set('title', 'Textile formatting test'); if (AnewtRequest::get_bool('debug')) { header('Content-type: text/plain'); $p->set('content_type', 'text/plain'); } else { list($base_url, $params) = AnewtUrl::parse(AnewtRequest::url()); $params['debug'] = '1'; $debug_url = AnewtUrl::build(array($base_url), $params); $p->append(ax_p(ax_a_href('(Page source for debugging)', $debug_url))); } anewt_include('textformatting'); anewt_include('textile'); $text = file_get_contents(dirname(__FILE__) . '/sample-text.txt'); $formatted_text = TextFormatter::format($text, 'textile'); $p->append(ax_raw($formatted_text)); $p->flush();
public function setDescription($description) { $this->description = TextFormatter::linkify($description); }