本文整理汇总了PHP中phutil_utf8_shorten函数的典型用法代码示例。如果您正苦于以下问题:PHP phutil_utf8_shorten函数的具体用法?PHP phutil_utf8_shorten怎么用?PHP phutil_utf8_shorten使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了phutil_utf8_shorten函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: renderValueForRevisionView
public function renderValueForRevisionView()
{
$diff = $this->getDiff();
$ustar = DifferentialRevisionUpdateHistoryView::renderDiffUnitStar($diff);
$umsg = DifferentialRevisionUpdateHistoryView::getDiffUnitMessage($diff);
$postponed_count = 0;
$udata = $this->getDiffProperty('arc:unit');
$utail = null;
if ($udata) {
$unit_messages = array();
foreach ($udata as $test) {
$name = idx($test, 'name');
$result = idx($test, 'result');
if ($result != DifferentialUnitTestResult::RESULT_POSTPONED && $result != DifferentialUnitTestResult::RESULT_PASS) {
$engine = PhabricatorMarkupEngine::newDifferentialMarkupEngine();
$userdata = phutil_utf8_shorten(idx($test, 'userdata'), 512);
$userdata = $engine->markupText($userdata);
$unit_messages[] = '<li>' . '<span class="unit-result-' . phutil_escape_html($result) . '">' . phutil_escape_html(ucwords($result)) . '</span>' . ' ' . phutil_escape_html($name) . '<p>' . $userdata . '</p>' . '</li>';
} else {
if ($result == DifferentialUnitTestResult::RESULT_POSTPONED) {
$postponed_count++;
}
}
}
$uexcuse = $this->getUnitExcuse();
if ($unit_messages) {
$utail = '<div class="differential-unit-block">' . $uexcuse . '<ul>' . implode("\n", $unit_messages) . '</ul>' . '</div>';
}
}
if ($postponed_count > 0 && $diff->getUnitStatus() == DifferentialUnitStatus::UNIT_POSTPONED) {
$umsg = $postponed_count . ' ' . $umsg;
}
return $ustar . ' ' . $umsg . $utail;
}
示例2: fail
private function fail($near, $message)
{
$message = sprintf('%s near: %s', $message, phutil_utf8_shorten($near, 32000));
if ($this->getEngine()->isTextMode()) {
return '(' . $message . ')';
}
return hsprintf('<div style="color: red;">%s</div>', $message);
}
示例3: getSummary
public function getSummary()
{
$message = $this->getCommitMessage();
$lines = explode("\n", $message);
$summary = head($lines);
$summary = phutil_utf8_shorten($summary, self::SUMMARY_MAX_LENGTH);
return $summary;
}
示例4: testUTF8shorten
public function testUTF8shorten()
{
$inputs = array(array("1erp derp derp", 9, "", "1erp derp"), array("2erp derp derp", 12, "...", "2erp derp..."), array("derpxderpxderp", 12, "...", "derpxderp..."), array("derp♃derpderp", 12, "...", "derp♃derp..."), array("", 12, "...", ""), array("derp", 12, "...", "derp"), array("11111", 5, "2222", "11111"), array("111111", 5, "2222", "12222"), array("D1rp. Derp derp.", 7, "...", "D1rp."), array("D2rp. Derp derp.", 5, "...", "D2rp."), array("D3rp. Derp derp.", 4, "...", "D..."), array("D4rp. Derp derp.", 14, "...", "D4rp. Derp..."), array("D5rpderp, derp derp", 16, "...", "D5rpderp..."), array("D6rpderp, derp derp", 17, "...", "D6rpderp, derp..."), array("Gr͠mpyCatSmiles", 8, "...", "Gr͠mpy..."), array("X͠͠͠Y", 1, "", "X͠͠͠"), array("Derp, supercalafragalisticexpialadoshus", 30, "...", "Derp..."), array("((((((((((", 8, '...', '(((((...'), array('derp', 3, 'quack', 'quack'));
foreach ($inputs as $input) {
list($string, $length, $terminal, $expect) = $input;
$result = phutil_utf8_shorten($string, $length, $terminal);
$this->assertEqual($expect, $result, 'Shortening of ' . $string);
}
}
示例5: writeAndRead
private function writeAndRead($write, $read)
{
$future = new ExecFuture('cat');
$future->write($write);
$lines = array();
foreach (new LinesOfALargeExecFuture($future) as $line) {
$lines[] = $line;
}
$this->assertEqual($read, $lines, "Write: " . phutil_utf8_shorten($write, 32));
}
示例6: writeAndRead
private function writeAndRead($write, $read, $delimiter = "\n")
{
$tmp = new TempFile();
Filesystem::writeFile($tmp, $write);
$lines = array();
$iterator = id(new LinesOfALargeFile($tmp))->setDelimiter($delimiter);
foreach ($iterator as $n => $line) {
$lines[$n - 1] = $line;
}
$this->assertEqual($read, $lines, "Write: " . phutil_utf8_shorten($write, 32));
}
示例7: flagWasEdited
private static function flagWasEdited($flag, $verb)
{
$color = idx(self::$colorMap, $flag['color'], 'cyan');
$note = $flag['note'];
if ($note) {
// Make sure notes that are long or have line breaks in them or
// whatever don't mess up the formatting.
$note = implode(' ', preg_split('/\\s+/', $note));
$note = ' (' . phutil_utf8_shorten($note, 40, '...') . ')';
}
echo phutil_console_format("<fg:{$color}>%s</fg> flag%s {$verb}!\n", $flag['colorName'], $note);
}
示例8: renderView
public function renderView()
{
$data = $this->getStoryData();
$author_phid = $data->getAuthorPHID();
$owner_phid = $data->getValue('ownerPHID');
$task_phid = $data->getValue('taskPHID');
$objects = $this->getObjects();
$action = $data->getValue('action');
$view = new PhabricatorFeedStoryView();
$verb = ManiphestAction::getActionPastTenseVerb($action);
$extra = null;
switch ($action) {
case ManiphestAction::ACTION_ASSIGN:
if ($owner_phid) {
$extra = ' to ' . '<strong>' . $this->getHandle($owner_phid)->renderLink() . '</strong>';
} else {
$verb = 'placed';
$extra = ' up for grabs';
}
break;
}
$title = '<strong>' . $this->getHandle($author_phid)->renderLink() . '</strong>' . " {$verb} task " . '<strong>' . $this->getHandle($task_phid)->renderLink() . '</strong>';
$title .= $extra;
$title .= '.';
$view->setTitle($title);
switch ($action) {
case ManiphestAction::ACTION_CREATE:
$full_size = true;
break;
default:
$full_size = false;
break;
}
$view->setEpoch($data->getEpoch());
if ($full_size) {
if (!empty($objects[$author_phid])) {
$image_phid = $objects[$author_phid]->getProfileImagePHID();
$image_uri = PhabricatorFileURI::getViewURIForPHID($image_phid);
$view->setImage($image_uri);
}
$content = phutil_escape_html(phutil_utf8_shorten($data->getValue('description'), 128));
$content = str_replace("\n", '<br />', $content);
$view->appendChild($content);
} else {
$view->setOneLineStory(true);
}
return $view;
}
示例9: testUTF8shorten
public function testUTF8shorten()
{
$inputs = array(array("1erp derp derp", 9, "", "1erp derp"), array("2erp derp derp", 12, "...", "2erp derp..."), array("derpxderpxderp", 12, "...", "derpxderp..."), array("derp♃derpderp", 12, "...", "derp♃derp..."), array("", 12, "...", ""), array("derp", 12, "...", "derp"), array("11111", 5, "2222", "11111"), array("111111", 5, "2222", "12222"), array("D1rp. Derp derp.", 7, "...", "D1rp."), array("D2rp. Derp derp.", 5, "...", "D2rp."), array("D3rp. Derp derp.", 4, "...", "D..."), array("D4rp. Derp derp.", 14, "...", "D4rp. Derp..."), array("D5rpderp, derp derp", 16, "...", "D5rpderp..."), array("D6rpderp, derp derp", 17, "...", "D6rpderp, derp..."), array("Derp, supercalafragalisticexpialadoshus", 30, "...", "Derp..."), array("((((((((((", 8, '...', '(((((...'));
foreach ($inputs as $input) {
list($string, $length, $terminal, $expect) = $input;
$result = phutil_utf8_shorten($string, $length, $terminal);
$this->assertEqual($expect, $result, 'Shortening of ' . $string);
}
try {
phutil_utf8_shorten('derp', 3, 'quack');
$caught = false;
} catch (Exception $ex) {
$caught = true;
}
$this->assertEqual(true, $caught, 'Expect exception for terminal.');
}
示例10: processRequest
public function processRequest()
{
$projects = id(new PhabricatorProject())->loadAllWhere('1 = 1 ORDER BY id DESC limit 100');
$project_phids = mpull($projects, 'getPHID');
$profiles = array();
if ($projects) {
$profiles = id(new PhabricatorProjectProfile())->loadAllWhere('projectPHID in (%Ls)', $project_phids);
$profiles = mpull($profiles, null, 'getProjectPHID');
}
$affil_groups = array();
if ($projects) {
$affil_groups = PhabricatorProjectAffiliation::loadAllForProjectPHIDs($project_phids);
}
$author_phids = mpull($projects, 'getAuthorPHID');
$handles = id(new PhabricatorObjectHandleData($author_phids))->loadHandles();
$query = id(new ManiphestTaskQuery())->withProjects($project_phids)->withAnyProject(true)->withStatus(ManiphestTaskQuery::STATUS_OPEN)->setLimit(PHP_INT_MAX);
$tasks = $query->execute();
$groups = array();
foreach ($tasks as $task) {
foreach ($task->getProjectPHIDs() as $phid) {
$groups[$phid][] = $task;
}
}
$rows = array();
foreach ($projects as $project) {
$phid = $project->getPHID();
$profile = $profiles[$phid];
$affiliations = $affil_groups[$phid];
$group = idx($groups, $phid, array());
$task_count = count($group);
$population = count($affiliations);
$status = PhabricatorProjectStatus::getNameForStatus($project->getStatus());
$blurb = $profile->getBlurb();
$blurb = phutil_utf8_shorten($blurb, $columns = 100);
$rows[] = array(phutil_escape_html($project->getName()), phutil_escape_html($blurb), $handles[$project->getAuthorPHID()]->renderLink(), phutil_escape_html($population), phutil_escape_html($status), phutil_render_tag('a', array('href' => '/maniphest/view/all/?projects=' . $phid), phutil_escape_html($task_count)), phutil_render_tag('a', array('class' => 'small grey button', 'href' => '/project/view/' . $project->getID() . '/'), 'View Project Profile'));
}
$table = new AphrontTableView($rows);
$table->setHeaders(array('Project', 'Description', 'Mastermind', 'Population', 'Status', 'Open Tasks', ''));
$table->setColumnClasses(array('pri', 'wide', '', 'right', '', 'right', 'action'));
$panel = new AphrontPanelView();
$panel->appendChild($table);
$panel->setHeader('Project');
$panel->setCreateButton('Create New Project', '/project/create/');
return $this->buildStandardPageResponse($panel, array('title' => 'Projects'));
}
示例11: render
public function render()
{
require_celerity_resource('phabricator-project-tag-css');
$show = array_slice($this->handles, 0, 2);
$tags = array();
foreach ($show as $handle) {
$tags[] = phutil_render_tag('a', array('href' => $handle->getURI(), 'class' => 'phabricator-project-tag'), phutil_escape_html(phutil_utf8_shorten($handle->getName(), 24)));
}
if (count($this->handles) > 2) {
require_celerity_resource('aphront-tooltip-css');
Javelin::initBehavior('phabricator-tooltips');
$all = array();
foreach ($this->handles as $handle) {
$all[] = $handle->getName();
}
$tags[] = javelin_render_tag('span', array('class' => 'phabricator-project-tag', 'sigil' => 'has-tooltip', 'meta' => array('tip' => implode(', ', $all), 'size' => 200)), "…");
}
return implode("\n", $tags);
}
示例12: processRequest
public function processRequest()
{
$request = $this->getRequest();
$user = $request->getUser();
$offset = $request->getInt('offset', 0);
$page_size = 1000;
$pager = new AphrontPagerView();
$request_uri = $request->getRequestURI();
$pager->setURI($request_uri, 'offset');
$pager->setPageSize($page_size);
$pager->setOffset($offset);
$query = new PhabricatorChatLogQuery();
$query->withChannels(array($this->channel));
$logs = $query->executeWithPager($pager);
require_celerity_resource('phabricator-chatlog-css');
$last_author = null;
$last_epoch = null;
$row_idx = 0;
$row_colors = array('normal', 'alternate');
$out = array();
$out[] = '<table class="phabricator-chat-log">';
foreach ($logs as $log) {
$this_author = $log->getAuthor();
$this_epoch = $log->getEpoch();
if ($this_author !== $last_author || $this_epoch - 60 * 5 > $last_epoch) {
++$row_idx;
$out[] = '<tr class="initial ' . $row_colors[$row_idx % 2] . '">';
$out[] = '<td class="timestamp">' . phabricator_datetime($log->getEpoch(), $user) . '</td>';
$author = $log->getAuthor();
$author = phutil_utf8_shorten($author, 18);
$out[] = '<td class="author">' . phutil_escape_html($author) . '</td>';
} else {
$out[] = '<tr class="' . $row_colors[$row_idx % 2] . '">';
$out[] = '<td class="similar" colspan="2"></td>';
}
$out[] = '<td class="message">' . phutil_escape_html($log->getMessage()) . '</td>';
$out[] = '</tr>';
$last_author = $this_author;
$last_epoch = $this_epoch;
}
$out[] = '</table>';
return $this->buildStandardPageResponse(array(implode("\n", $out), $pager), array('title' => 'Channel Log'));
}
示例13: buildQuestionListView
private function buildQuestionListView(array $questions)
{
assert_instances_of($questions, 'PonderQuestion');
$user = $this->getRequest()->getUser();
$view = new PhabricatorObjectItemListView();
$view->setNoDataString(pht('No matching questions.'));
foreach ($questions as $question) {
$item = new PhabricatorObjectItemView();
$item->setHeader('Q' . $question->getID() . ' ' . $question->getTitle());
$item->setHref('/Q' . $question->getID());
$desc = $question->getContent();
if ($desc) {
$item->addDetail(pht('Description'), phutil_escape_html(phutil_utf8_shorten($desc, 128)));
}
$item->addDetail(pht('Author'), $this->getHandle($question->getAuthorPHID())->renderLink());
$item->addDetail(pht('Votes'), $question->getVoteCount());
$item->addDetail(pht('Answers'), $question->getAnswerCount());
$created = pht('Created %s', phabricator_date($question->getDateCreated(), $user));
$item->addAttribute($created);
$view->addItem($item);
}
return $view;
}
示例14: buildDisplayRows
//.........这里部分代码省略.........
$color = '#ffd';
// Render as warning.
} else {
$color_ratio = ($blame['epoch'] - $epoch_min) / $epoch_range;
$color_value = 0xf6 * (1.0 - $color_ratio);
$color = sprintf('#%02x%02x%02x', $color_value, 0xf6, $color_value);
}
$display_line['epoch'] = idx($blame, 'epoch');
$display_line['color'] = $color;
$display_line['commit'] = $rev;
if (isset($blame['handle'])) {
$author_link = $blame['handle']->renderLink();
} else {
$author_link = phutil_render_tag('span', array(), phutil_escape_html($blame['author']));
}
$display_line['author'] = $author_link;
$last_rev = $rev;
}
}
if ($line_arr) {
if ($line_number == $line_arr[0]['min']) {
$display_line['target'] = true;
}
foreach ($line_arr as $range) {
if ($line_number >= $range['min'] && $line_number <= $range['max']) {
$display_line['highlighted'] = true;
}
}
}
$display[] = $display_line;
++$line_number;
}
$commits = array_filter(ipull($display, 'commit'));
if ($commits) {
$commits = id(new PhabricatorAuditCommitQuery())->withIdentifiers($drequest->getRepository()->getID(), $commits)->needCommitData(true)->execute();
$commits = mpull($commits, null, 'getCommitIdentifier');
}
$revision_ids = id(new DifferentialRevision())->loadIDsByCommitPHIDs(mpull($commits, 'getPHID'));
$revisions = array();
if ($revision_ids) {
$revisions = id(new DifferentialRevision())->loadAllWhere('id IN (%Ld)', $revision_ids);
}
$request = $this->getRequest();
$user = $request->getUser();
Javelin::initBehavior('phabricator-oncopy', array());
$rows = array();
foreach ($display as $line) {
$line_href = $drequest->generateURI(array('action' => 'browse', 'line' => $line['line'], 'stable' => true));
$blame = array();
if ($line['color']) {
$color = $line['color'];
$before_link = null;
$commit_link = null;
$revision_link = null;
if (idx($line, 'commit')) {
$commit = $line['commit'];
$summary = 'Unknown';
if (idx($commits, $commit)) {
$summary = $commits[$commit]->getCommitData()->getSummary();
}
$tooltip = phabricator_date($line['epoch'], $user) . " · " . $summary;
Javelin::initBehavior('phabricator-tooltips', array());
require_celerity_resource('aphront-tooltip-css');
$commit_link = javelin_render_tag('a', array('href' => $drequest->generateURI(array('action' => 'commit', 'commit' => $line['commit'])), 'sigil' => 'has-tooltip', 'meta' => array('tip' => $tooltip, 'align' => 'E', 'size' => 600)), phutil_escape_html(phutil_utf8_shorten($line['commit'], 9, '')));
$revision_id = null;
if (idx($commits, $commit)) {
$revision_id = idx($revision_ids, $commits[$commit]->getPHID());
}
if ($revision_id) {
$revision = idx($revisions, $revision_id);
if (!$revision) {
$tooltip = '(Invalid revision)';
} else {
$tooltip = phabricator_date($revision->getDateModified(), $user) . " · " . $revision->getTitle();
}
$revision_link = javelin_render_tag('a', array('href' => '/D' . $revision_id, 'sigil' => 'has-tooltip', 'meta' => array('tip' => $tooltip, 'align' => 'E', 'size' => 600)), 'D' . $revision_id);
}
$uri = $line_href->alter('before', $commit);
$before_link = javelin_render_tag('a', array('href' => $uri->setQueryParam('view', 'blame'), 'sigil' => 'has-tooltip', 'meta' => array('tip' => 'Skip Past This Commit', 'align' => 'E', 'size' => 300)), "«");
}
$blame[] = phutil_render_tag('th', array('class' => 'diffusion-blame-link', 'style' => 'background: ' . $color), $before_link);
$blame[] = phutil_render_tag('th', array('class' => 'diffusion-rev-link', 'style' => 'background: ' . $color), $commit_link);
$blame[] = phutil_render_tag('th', array('class' => 'diffusion-rev-link', 'style' => 'background: ' . $color), $revision_link);
$blame[] = phutil_render_tag('th', array('class' => 'diffusion-author-link', 'style' => 'background: ' . $color), idx($line, 'author'));
}
$line_link = phutil_render_tag('a', array('href' => $line_href), phutil_escape_html($line['line']));
$blame[] = javelin_render_tag('th', array('class' => 'diffusion-line-link', 'sigil' => 'diffusion-line-link', 'style' => isset($color) ? 'background: ' . $color : null), $line_link);
Javelin::initBehavior('diffusion-line-linker');
$blame = implode('', $blame);
if ($line['target']) {
Javelin::initBehavior('diffusion-jump-to', array('target' => 'scroll_target'));
$anchor_text = '<a id="scroll_target"></a>';
} else {
$anchor_text = null;
}
$line_text = phutil_render_tag('td', array(), $anchor_text . "" . $line['data']);
$rows[] = phutil_render_tag('tr', array('class' => $line['highlighted'] ? 'highlighted' : null), $blame . $line_text);
}
return $rows;
}
示例15: loadHandles
//.........这里部分代码省略.........
$handle = new PhabricatorObjectHandle();
$handle->setPHID($phid);
$handle->setType($type);
if (empty($projects[$phid])) {
$handle->setName('Unknown Arcanist Project');
} else {
$project = $projects[$phid];
$handle->setName($project->getName());
$handle->setComplete(true);
}
$handles[$phid] = $handle;
}
break;
case PhabricatorPHIDConstants::PHID_TYPE_WIKI:
$document_dao = new PhrictionDocument();
$content_dao = new PhrictionContent();
$conn = $document_dao->establishConnection('r');
$documents = queryfx_all($conn, 'SELECT * FROM %T document JOIN %T content
ON document.contentID = content.id
WHERE document.phid IN (%Ls)', $document_dao->getTableName(), $content_dao->getTableName(), $phids);
$documents = ipull($documents, null, 'phid');
foreach ($phids as $phid) {
$handle = new PhabricatorObjectHandle();
$handle->setPHID($phid);
$handle->setType($type);
if (empty($documents[$phid])) {
$handle->setName('Unknown Document');
} else {
$info = $documents[$phid];
$handle->setName($info['title']);
$handle->setURI(PhrictionDocument::getSlugURI($info['slug']));
$handle->setComplete(true);
}
$handles[$phid] = $handle;
}
break;
case PhabricatorPHIDConstants::PHID_TYPE_QUES:
$questions = id(new PonderQuestionQuery())->withPHIDs($phids)->execute();
$questions = mpull($questions, null, 'getPHID');
foreach ($phids as $phid) {
$handle = new PhabricatorObjectHandle();
$handle->setPHID($phid);
$handle->setType($type);
if (empty($questions[$phid])) {
$handle->setName('Unknown Ponder Question');
} else {
$question = $questions[$phid];
$handle->setName(phutil_utf8_shorten($question->getTitle(), 60));
$handle->setURI(new PhutilURI('Q' . $question->getID()));
$handle->setComplete(true);
}
$handles[$phid] = $handle;
}
break;
case PhabricatorPHIDConstants::PHID_TYPE_PSTE:
$pastes = id(new PhabricatorPasteQuery())->withPHIDs($phids)->setViewer($this->viewer)->execute();
$pastes = mpull($pastes, null, 'getPHID');
foreach ($phids as $phid) {
$handle = new PhabricatorObjectHandle();
$handle->setPHID($phid);
$handle->setType($type);
if (empty($pastes[$phid])) {
$handle->setName('Unknown Paste');
} else {
$paste = $pastes[$phid];
$handle->setName($paste->getTitle());
$handle->setFullName('P' . $paste->getID() . ': ' . $paste->getTitle());
$handle->setURI('/P' . $paste->getID());
$handle->setComplete(true);
}
$handles[$phid] = $handle;
}
break;
default:
$loader = null;
if (isset($external_loaders[$type])) {
$loader = $external_loaders[$type];
} else {
if (isset($external_loaders['*'])) {
$loader = $external_loaders['*'];
}
}
if ($loader) {
$object = newv($loader, array());
$handles += $object->loadHandles($phids);
break;
}
foreach ($phids as $phid) {
$handle = new PhabricatorObjectHandle();
$handle->setType($type);
$handle->setPHID($phid);
$handle->setName('Unknown Object');
$handle->setFullName('An Unknown Object');
$handles[$phid] = $handle;
}
break;
}
}
return $handles;
}