private function loadPHIDsByTypes($type) { $objects = id(new PhutilClassMapQuery())->setAncestorClass('PhabricatorFulltextInterface')->execute(); $normalized_type = phutil_utf8_strtolower($type); $matches = array(); foreach ($objects as $object) { $object_class = get_class($object); $normalized_class = phutil_utf8_strtolower($object_class); if (!strlen($type) || strpos($normalized_class, $normalized_type) !== false) { $matches[$object_class] = $object; } } if (!$matches) { $all_types = array(); foreach ($objects as $object) { $all_types[] = get_class($object); } sort($all_types); throw new PhutilArgumentUsageException(pht('Type "%s" matches no indexable objects. Supported types are: %s.', $type, implode(', ', $all_types))); } if (count($matches) > 1 && strlen($type)) { throw new PhutilArgumentUsageException(pht('Type "%s" matches multiple indexable objects. Use a more ' . 'specific string. Matching object types are: %s.', $type, implode(', ', array_keys($matches)))); } $phids = array(); foreach ($matches as $match) { $iterator = new LiskMigrationIterator($match); foreach ($iterator as $object) { $phids[] = $object->getPHID(); } } return $phids; }
public static function normalize($slug, $hashtag = false) { $slug = preg_replace('@/+@', '/', $slug); $slug = trim($slug, '/'); $slug = phutil_utf8_strtolower($slug); $ban = "\\x00-\\x19" . "#%&+=?" . " " . "\\\\" . "<>{}\\[\\]" . "'" . '"'; // In hashtag mode (used for Project hashtags), ban additional characters // which cause parsing problems. if ($hashtag) { $ban .= '`~!@$^*,:;(|)'; } $slug = preg_replace('([' . $ban . ']+)', '_', $slug); $slug = preg_replace('@_+@', '_', $slug); $parts = explode('/', $slug); // Remove leading and trailing underscores from each component, if the // component has not been reduced to a single underscore. For example, "a?" // converts to "a", but "??" converts to "_". foreach ($parts as $key => $part) { if ($part != '_') { $parts[$key] = trim($part, '_'); } } $slug = implode('/', $parts); // Specifically rewrite these slugs. It's OK to have a slug like "a..b", // but not a slug which is only "..". // NOTE: These are explicitly not pht()'d, because they should be stable // across languages. $replace = array('.' => 'dot', '..' => 'dotdot'); foreach ($replace as $pattern => $replacement) { $pattern = preg_quote($pattern, '@'); $slug = preg_replace('@(^|/)' . $pattern . '(\\z|/)@', '\\1' . $replacement . '\\2', $slug); } return $slug . '/'; }
private function processMailCommands(PhabricatorMetaMTAReceivedMail $mail, array $command_list) { $viewer = $this->getActor(); $object = $this->getMailReceiver(); $list = MetaMTAEmailTransactionCommand::getAllCommandsForObject($object); $map = MetaMTAEmailTransactionCommand::getCommandMap($list); $xactions = array(); foreach ($command_list as $command_argv) { $command = head($command_argv); $argv = array_slice($command_argv, 1); $handler = idx($map, phutil_utf8_strtolower($command)); if ($handler) { $results = $handler->buildTransactions($viewer, $object, $mail, $command, $argv); foreach ($results as $result) { $xactions[] = $result; } } else { $valid_commands = array(); foreach ($list as $valid_command) { $aliases = $valid_command->getCommandAliases(); if ($aliases) { foreach ($aliases as $key => $alias) { $aliases[$key] = '!' . $alias; } $aliases = implode(', ', $aliases); $valid_commands[] = pht('!%s (or %s)', $valid_command->getCommand(), $aliases); } else { $valid_commands[] = '!' . $valid_command->getCommand(); } } throw new Exception(pht('The command "!%s" is not a supported mail command. Valid ' . 'commands for this object are: %s.', $command, implode(', ', $valid_commands))); } } return $xactions; }
public static function normalize($slug) { $slug = preg_replace('@/+@', '/', $slug); $slug = trim($slug, '/'); $slug = phutil_utf8_strtolower($slug); $slug = preg_replace("@[\\x00-\\x19#%&+=\\\\?<> ]+@", '_', $slug); $slug = preg_replace('@_+@', '_', $slug); // Remove leading and trailing underscores from each component, if the // component has not been reduced to a single underscore. For example, "a?" // converts to "a", but "??" converts to "_". $parts = explode('/', $slug); foreach ($parts as $key => $part) { if ($part != '_') { $parts[$key] = trim($part, '_'); } } $slug = implode('/', $parts); // Specifically rewrite these slugs. It's OK to have a slug like "a..b", // but not a slug which is only "..". // NOTE: These are explicitly not pht()'d, because they should be stable // across languages. $replace = array('.' => 'dot', '..' => 'dotdot'); foreach ($replace as $pattern => $replacement) { $pattern = preg_quote($pattern, '@'); $slug = preg_replace('@(^|/)' . $pattern . '(\\z|/)@', '\\1' . $replacement . '\\2', $slug); } return $slug . '/'; }
protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) { $where = parent::buildWhereClauseParts($conn); if ($this->phids !== null) { $where[] = qsprintf($conn, 'p.phid IN (%Ls)', $this->phids); } if ($this->ids !== null) { $where[] = qsprintf($conn, 'p.id IN (%Ld)', $this->ids); } if ($this->repositoryPHIDs !== null) { $where[] = qsprintf($conn, 'rpath.repositoryPHID IN (%Ls)', $this->repositoryPHIDs); } if ($this->ownerPHIDs !== null) { $base_phids = $this->ownerPHIDs; $projects = id(new PhabricatorProjectQuery())->setViewer($this->getViewer())->withMemberPHIDs($base_phids)->execute(); $project_phids = mpull($projects, 'getPHID'); $all_phids = array_merge($base_phids, $project_phids); $where[] = qsprintf($conn, 'o.userPHID IN (%Ls)', $all_phids); } if (strlen($this->namePrefix)) { // NOTE: This is a hacky mess, but this column is currently case // sensitive and unique. $where[] = qsprintf($conn, 'LOWER(p.name) LIKE %>', phutil_utf8_strtolower($this->namePrefix)); } return $where; }
public function markupText($text, $children) { $matches = array(); preg_match($this->getRegEx(), $text, $matches); if (idx($matches, 'showword')) { $word = $matches['showword']; $show = true; } else { $word = $matches['hideword']; $show = false; } $class_suffix = phutil_utf8_strtolower($word); // This is the "(IMPORTANT)" or "NOTE:" part. $word_part = rtrim(substr($text, 0, strlen($matches[0]))); // This is the actual text. $text_part = substr($text, strlen($matches[0])); $text_part = $this->applyRules(rtrim($text_part)); $text_mode = $this->getEngine()->isTextMode(); if ($text_mode) { return $word_part . ' ' . $text_part; } if ($show) { $content = array(phutil_tag('span', array('class' => 'remarkup-note-word'), $word_part), ' ', $text_part); } else { $content = $text_part; } return phutil_tag('div', array('class' => 'remarkup-' . $class_suffix), $content); }
public final function getNgramsFromString($value, $mode) { $tokens = $this->tokenizeString($value); $ngrams = array(); foreach ($tokens as $token) { $token = phutil_utf8_strtolower($token); switch ($mode) { case 'query': break; case 'index': $token = ' ' . $token . ' '; break; case 'prefix': $token = ' ' . $token; break; } $len = strlen($token) - 2; for ($ii = 0; $ii < $len; $ii++) { $ngram = substr($token, $ii, 3); $ngrams[$ngram] = $ngram; } } ksort($ngrams); return array_keys($ngrams); }
public function process(XHPASTNode $root) { $aliases = $this->getFunctionAliases(); $functions = $this->getFunctionCalls($root, array_keys($aliases)); foreach ($functions as $function) { $function_name = $function->getChildByIndex(0); $this->raiseLintAtNode($function_name, pht('Alias functions should be avoided.'), $aliases[phutil_utf8_strtolower($function_name->getConcreteString())]); } }
private function normalizeSlug($slug) { // NOTE: We're using phutil_utf8_strtolower() (and not PhabricatorSlug's // normalize() method) because this normalization should be only somewhat // liberal. We want "#YOLO" to match against "#yolo", but "#\\yo!!lo" // should not. normalize() strips out most punctuation and leads to // excessively aggressive matches. return phutil_utf8_strtolower($slug); }
public static function tokenizeString($string) { $string = phutil_utf8_strtolower($string); $string = trim($string); if (!strlen($string)) { return array(); } $tokens = preg_split('/\\s+|-/', $string); return array_unique($tokens); }
public function markupKeystrokes(array $matches) { if (!$this->isFlatText($matches[0])) { return $matches[0]; } $keys = explode(' ', $matches[1]); foreach ($keys as $k => $v) { $v = trim($v, " \n"); $v = preg_replace('/\\\\(.)/', '\\1', $v); if (!strlen($v)) { unset($keys[$k]); continue; } $keys[$k] = $v; } $special = array(array('name' => pht('Command'), 'symbol' => "⌘", 'aliases' => array('cmd', 'command')), array('name' => pht('Option'), 'symbol' => "⌥", 'aliases' => array('opt', 'option')), array('name' => pht('Shift'), 'symbol' => "⇧", 'aliases' => array('shift')), array('name' => pht('Escape'), 'symbol' => "⎋", 'aliases' => array('esc', 'escape')), array('name' => pht('Up'), 'symbol' => "↑", 'heavy' => "⬆", 'aliases' => array('up', 'arrow-up', 'up-arrow', 'north')), array('name' => pht('Tab'), 'symbol' => "⇥", 'aliases' => array('tab')), array('name' => pht('Right'), 'symbol' => "→", 'heavy' => "➡", 'aliases' => array('right', 'right-arrow', 'arrow-right', 'east')), array('name' => pht('Left'), 'symbol' => "←", 'heavy' => "⬅", 'aliases' => array('left', 'left-arrow', 'arrow-left', 'west')), array('name' => pht('Down'), 'symbol' => "↓", 'heavy' => "⬇", 'aliases' => array('down', 'down-arrow', 'arrow-down', 'south')), array('name' => pht('Up Right'), 'symbol' => "↗", 'heavy' => "⬈", 'aliases' => array('up-right', 'upright', 'up-right-arrow', 'upright-arrow', 'arrow-up-right', 'arrow-upright', 'northeast', 'north-east')), array('name' => pht('Down Right'), 'symbol' => "↘", 'heavy' => "⬊", 'aliases' => array('down-right', 'downright', 'down-right-arrow', 'downright-arrow', 'arrow-down-right', 'arrow-downright', 'southeast', 'south-east')), array('name' => pht('Down Left'), 'symbol' => "↙", 'heavy' => "⬋", 'aliases' => array('down-left', 'downleft', 'down-left-arrow', 'downleft-arrow', 'arrow-down-left', 'arrow-downleft', 'southwest', 'south-west')), array('name' => pht('Up Left'), 'symbol' => "↖", 'heavy' => "⬉", 'aliases' => array('up-left', 'upleft', 'up-left-arrow', 'upleft-arrow', 'arrow-up-left', 'arrow-upleft', 'northwest', 'north-west'))); $map = array(); foreach ($special as $spec) { foreach ($spec['aliases'] as $alias) { $map[$alias] = $spec; } } $is_text = $this->getEngine()->isTextMode(); $is_html_mail = $this->getEngine()->isHTMLMailMode(); if ($is_html_mail) { $key_style = array('display: inline-block;', 'min-width: 1em;', 'padding: 4px 5px 5px;', 'font-weight: normal;', 'font-size: 0.8rem;', 'text-align: center;', 'text-decoration: none;', 'line-height: 0.6rem;', 'border-radius: 3px;', 'box-shadow: inset 0 -1px 0 rgba(71, 87, 120, 0.08);', 'user-select: none;', 'background: #f7f7f7;', 'border: 1px solid #C7CCD9;'); $key_style = implode(' ', $key_style); $join_style = array('padding: 0 4px;', 'color: #92969D;'); $join_style = implode(' ', $join_style); } else { $key_style = null; $join_style = null; } $parts = array(); foreach ($keys as $k => $v) { $normal = phutil_utf8_strtolower($v); if (isset($map[$normal])) { $spec = $map[$normal]; } else { $spec = array('name' => null, 'symbol' => $v); } if ($is_text) { $parts[] = '[' . $spec['symbol'] . ']'; } else { $parts[] = phutil_tag('kbd', array('title' => $spec['name'], 'style' => $key_style), $spec['symbol']); } } if ($is_text) { $parts = implode(' + ', $parts); } else { $glue = phutil_tag('span', array('class' => 'kbd-join', 'style' => $join_style), '+'); $parts = phutil_implode_html($glue, $parts); } return $this->getEngine()->storeText($parts); }
protected function getLintCodeFromLinterConfigurationKey($code) { switch (phutil_utf8_strtolower($code)) { case 'parse': return self::LINT_PARSE_ERROR; case 'fatal': return self::LINT_FATAL_ERROR; default: throw new Exception(pht('Unrecognized lint message code: "%s"', $code)); } }
public function getHeaderValue($key, $default = null) { $key = phutil_utf8_strtolower($key); foreach ($this->headers as $header) { list($hkey, $value) = $header; if (phutil_utf8_strtolower($hkey) === $key) { return $value; } } return $default; }
public function markupText($text, $children) { $matches = array(); preg_match($this->getRegEx(), $text, $matches); if (idx($matches, 'showword')) { $word = $matches['showword']; $show = true; } else { $word = $matches['hideword']; $show = false; } $class_suffix = phutil_utf8_strtolower($word); // This is the "(IMPORTANT)" or "NOTE:" part. $word_part = rtrim(substr($text, 0, strlen($matches[0]))); // This is the actual text. $text_part = substr($text, strlen($matches[0])); $text_part = $this->applyRules(rtrim($text_part)); $text_mode = $this->getEngine()->isTextMode(); $html_mail_mode = $this->getEngine()->isHTMLMailMode(); if ($text_mode) { return $word_part . ' ' . $text_part; } if ($show) { $content = array(phutil_tag('span', array('class' => 'remarkup-note-word'), $word_part), ' ', $text_part); } else { $content = $text_part; } if ($html_mail_mode) { if ($class_suffix == 'important') { $attributes = array('style' => 'margin: 16px 0; padding: 12px; border-left: 3px solid #c0392b; background: #f4dddb;'); } else { if ($class_suffix == 'note') { $attributes = array('style' => 'margin: 16px 0; padding: 12px; border-left: 3px solid #2980b9; background: #daeaf3;'); } else { if ($class_suffix == 'warning') { $attributes = array('style' => 'margin: 16px 0; padding: 12px; border-left: 3px solid #f1c40f; background: #fdf5d4;'); } } } } else { $attributes = array('class' => 'remarkup-' . $class_suffix); } return phutil_tag('div', $attributes, $content); }
private function filterMethods(array $methods) { foreach ($methods as $key => $method) { $application = $method->getApplication(); if (!$application) { continue; } if (!$application->isInstalled()) { unset($methods[$key]); } } $status = array(ConduitAPIMethod::METHOD_STATUS_STABLE => $this->isStable, ConduitAPIMethod::METHOD_STATUS_DEPRECATED => $this->isDeprecated, ConduitAPIMethod::METHOD_STATUS_UNSTABLE => $this->isUnstable); // Only apply status filters if any of them are set. if (array_filter($status)) { foreach ($methods as $key => $method) { $keep = idx($status, $method->getMethodStatus()); if (!$keep) { unset($methods[$key]); } } } if ($this->applicationNames) { $map = array_fuse($this->applicationNames); foreach ($methods as $key => $method) { $needle = $method->getApplicationName(); $needle = phutil_utf8_strtolower($needle); if (empty($map[$needle])) { unset($methods[$key]); } } } if ($this->nameContains) { $needle = phutil_utf8_strtolower($this->nameContains); foreach ($methods as $key => $method) { $haystack = $method->getAPIMethodName(); $haystack = phutil_utf8_strtolower($haystack); if (strpos($haystack, $needle) === false) { unset($methods[$key]); } } } if ($this->methods) { $map = array_fuse($this->methods); foreach ($methods as $key => $method) { $needle = $method->getAPIMethodName(); if (empty($map[$needle])) { unset($methods[$key]); } } } return $methods; }
public static function getGitHubPath($uri) { $uri_object = new PhutilURI($uri); $domain = $uri_object->getDomain(); $domain = phutil_utf8_strtolower($domain); switch ($domain) { case 'github.com': case 'www.github.com': return $uri_object->getPath(); default: return null; } }
private static function getFigletMap() { $root = dirname(phutil_get_library_root('phabricator')); $dirs = array($root . '/externals/figlet/fonts/', $root . '/externals/pear-figlet/fonts/', $root . '/resources/figlet/custom/'); $map = array(); foreach ($dirs as $dir) { foreach (Filesystem::listDirectory($dir, false) as $file) { if (preg_match('/\\.flf\\z/', $file)) { $name = phutil_utf8_strtolower($file); $name = preg_replace('/\\.flf\\z/', '', $name); $map[$name] = $dir . $file; } } } return $map; }
/** * Get the priorities and their command keywords. * * @return map Priorities to lists of command keywords. */ public static function getTaskPriorityKeywordsMap() { $map = self::getConfig(); foreach ($map as $key => $spec) { $words = idx($spec, 'keywords', array()); if (!is_array($words)) { $words = array($words); } foreach ($words as $word_key => $word) { $words[$word_key] = phutil_utf8_strtolower($word); } $words = array_unique($words); $map[$key] = $words; } return $map; }
public static function getDisableANSI() { if (self::$disableANSI === null) { $term = phutil_utf8_strtolower(getenv("TERM")); if (phutil_is_windows() && $term !== "cygwin" && $term !== "ansi") { self::$disableANSI = true; } else { if (function_exists('posix_isatty') && !posix_isatty(STDOUT)) { self::$disableANSI = true; } else { self::$disableANSI = false; } } } return self::$disableANSI; }
public function execute(PhutilArgumentParser $args) { $config_key = 'phabricator.developer-mode'; if (!PhabricatorEnv::getEnvConfig($config_key)) { throw new PhutilArgumentUsageException(pht('lipsum is a development and testing tool and may only be run ' . 'on installs in developer mode. Enable "%s" in your configuration ' . 'to enable lipsum.', $config_key)); } $all_generators = id(new PhutilClassMapQuery())->setAncestorClass('PhabricatorTestDataGenerator')->execute(); $argv = $args->getArg('args'); $all = 'all'; if (!$argv) { $names = mpull($all_generators, 'getGeneratorName'); sort($names); $list = id(new PhutilConsoleList())->setWrap(false)->addItems($names); id(new PhutilConsoleBlock())->addParagraph(pht('Choose which type or types of test data you want to generate, ' . 'or select "%s".', $all))->addList($list)->draw(); return 0; } $generators = array(); foreach ($argv as $arg_original) { $arg = phutil_utf8_strtolower($arg_original); $match = false; foreach ($all_generators as $generator) { $name = phutil_utf8_strtolower($generator->getGeneratorName()); if ($arg == $all) { $generators[] = $generator; $match = true; break; } if (strpos($name, $arg) !== false) { $generators[] = $generator; $match = true; break; } } if (!$match) { throw new PhutilArgumentUsageException(pht('Argument "%s" does not match the name of any generators.', $arg_original)); } } echo tsprintf("**<bg:blue> %s </bg>** %s\n", pht('GENERATORS'), pht('Selected generators: %s.', implode(', ', mpull($generators, 'getGeneratorName')))); echo tsprintf("**<bg:yellow> %s </bg>** %s\n", pht('WARNING'), pht('This command generates synthetic test data, including user ' . 'accounts. It is intended for use in development environments ' . 'so you can test features more easily. There is no easy way to ' . 'delete this data or undo the effects of this command. If you run ' . 'it in a production environment, it will pollute your data with ' . 'large amounts of meaningless garbage that you can not get rid of.')); $prompt = pht('Are you sure you want to generate piles of garbage?'); if (!phutil_console_confirm($prompt, true)) { return; } echo tsprintf("**<bg:green> %s </bg>** %s\n", pht('LIPSUM'), pht('Generating synthetic test objects forever. ' . 'Use ^C to stop when satisfied.')); $this->generate($generators); }
public function handleRequest(AphrontRequest $request) { $viewer = $request->getViewer(); $book_name = $request->getStr('book'); $query_text = $request->getStr('name'); $book = null; if ($book_name) { $book = id(new DivinerBookQuery())->setViewer($viewer)->withNames(array($book_name))->executeOne(); if (!$book) { return new Aphront404Response(); } } $query = id(new DivinerAtomQuery())->setViewer($viewer); if ($book) { $query->withBookPHIDs(array($book->getPHID())); } $context = $request->getStr('context'); if (strlen($context)) { $query->withContexts(array($context)); } $type = $request->getStr('type'); if (strlen($type)) { $query->withTypes(array($type)); } $query->withGhosts(false); $query->withIsDocumentable(true); $name_query = clone $query; $name_query->withNames(array($query_text, phutil_utf8_strtolower($query_text))); $atoms = $name_query->execute(); if (!$atoms) { $title_query = clone $query; $title_query->withTitles(array($query_text)); $atoms = $title_query->execute(); } $not_found_uri = $this->getApplicationURI(); if (!$atoms) { $dialog = id(new AphrontDialogView())->setUser($viewer)->setTitle(pht('Documentation Not Found'))->appendChild(pht('Unable to find the specified documentation. ' . 'You may have followed a bad or outdated link.'))->addCancelButton($not_found_uri, pht('Read More Documentation')); return id(new AphrontDialogResponse())->setDialog($dialog); } if (count($atoms) == 1 && $request->getBool('jump')) { $atom_uri = head($atoms)->getURI(); return id(new AphrontRedirectResponse())->setURI($atom_uri); } $list = $this->renderAtomList($atoms); return $this->newPage()->setTitle(array(pht('Find'), pht('"%s"', $query_text)))->appendChild(array($list)); }
public static function getCommandMap(array $commands) { assert_instances_of($commands, __CLASS__); $map = array(); foreach ($commands as $command) { $keywords = $command->getCommandAliases(); $keywords[] = $command->getCommand(); foreach ($keywords as $keyword) { $keyword = phutil_utf8_strtolower($keyword); if (empty($map[$keyword])) { $map[$keyword] = $command; } else { throw new Exception(pht('Mail commands "%s" and "%s" both respond to keyword "%s". ' . 'Keywords must be uniquely associated with commands.', get_class($command), get_class($map[$keyword]), $keyword)); } } } return $map; }
private static function getCowMap() { $root = dirname(phutil_get_library_root('phabricator')); $directories = array($root . '/externals/cowsay/cows/', $root . '/resources/cows/builtin/', $root . '/resources/cows/custom/'); $map = array(); foreach ($directories as $directory) { foreach (Filesystem::listDirectory($directory, false) as $cow_file) { $matches = null; if (!preg_match('/^(.*)\\.cow\\z/', $cow_file, $matches)) { continue; } $cow_name = $matches[1]; $cow_name = phutil_utf8_strtolower($cow_name); $map[$cow_name] = Filesystem::readFile($directory . $cow_file); } } return $map; }
/** * Get the markup language a README should be interpreted as. * * @param string Local README path, like "README.txt". * @return string Best markup interpreter (like "remarkup") for this file. */ private function getReadmeLanguage($path) { $path = phutil_utf8_strtolower($path); if ($path == 'readme') { return 'remarkup'; } $ext = last(explode('.', $path)); switch ($ext) { case 'remarkup': case 'md': return 'remarkup'; case 'rainbow': return 'rainbow'; case 'txt': default: return 'text'; } }
public function buildTransactions(PhabricatorUser $viewer, PhabricatorApplicationTransactionInterface $object, PhabricatorMetaMTAReceivedMail $mail, $command, array $argv) { $target = phutil_utf8_strtolower(implode(' ', $argv)); $yes_values = $this->getYesValues(); $no_values = $this->getNoValues(); if (in_array($target, $yes_values)) { $rsvp = PhabricatorCalendarEventAcceptTransaction::TRANSACTIONTYPE; } else { if (in_array($target, $no_values)) { $rsvp = PhabricatorCalendarEventDeclineTransaction::TRANSACTIONTYPE; } else { return array(); } } $xactions = array(); $xactions[] = $object->getApplicationTransactionTemplate()->setTransactionType($rsvp)->setNewValue(true); return $xactions; }
public static function normalize($slug) { $slug = preg_replace('@/+@', '/', $slug); $slug = trim($slug, '/'); $slug = phutil_utf8_strtolower($slug); $slug = preg_replace("@[\\x00-\\x19#%&+=\\\\?<> ]+@", '_', $slug); $slug = preg_replace('@_+@', '_', $slug); $slug = trim($slug, '_'); // Specifically rewrite these slugs. It's OK to have a slug like "a..b", // but not a slug which is only "..". // NOTE: These are explicitly not pht()'d, because they should be stable // across languages. $replace = array('.' => 'dot', '..' => 'dotdot'); foreach ($replace as $pattern => $replacement) { $pattern = preg_quote($pattern, '@'); $slug = preg_replace('@(^|/)' . $pattern . '(\\z|/)@', '\\1' . $replacement . '\\2', $slug); } return $slug . '/'; }
/** * Get the statuses and their command keywords. * * @return map Statuses to lists of command keywords. */ public static function getTaskStatusKeywordsMap() { $map = self::getEnabledStatusMap(); foreach ($map as $key => $spec) { $words = idx($spec, 'keywords', array()); if (!is_array($words)) { $words = array($words); } // For statuses, we include the status name because it's usually // at least somewhat meaningful. $words[] = $key; foreach ($words as $word_key => $word) { $words[$word_key] = phutil_utf8_strtolower($word); } $words = array_unique($words); $map[$key] = $words; } return $map; }
public function loadNamedObjects(PhabricatorObjectQuery $query, array $names) { $id_map = array(); foreach ($names as $name) { $id = substr($name, 1); $id = phutil_utf8_strtolower($id); $id_map[$id][] = $name; } $objects = id(new PhabricatorPeopleQuery())->setViewer($query->getViewer())->withUsernames(array_keys($id_map))->execute(); $results = array(); foreach ($objects as $id => $object) { $user_key = $object->getUsername(); $user_key = phutil_utf8_strtolower($user_key); foreach (idx($id_map, $user_key, array()) as $name) { $results[$name] = $object; } } return $results; }
private function readRequest() { // TODO: This is grossly inefficient for large requests. list($status, $body, $headers) = $this->future->resolve(); $this->httpCode = $status->getStatusCode(); // Strip "Transfer-Encoding" headers. Particularly, the server we proxied // may have chunked the response, but cURL will already have un-chunked it. // If we emit the header and unchunked data, the response becomes invalid. foreach ($headers as $key => $header) { list($header_head, $header_body) = $header; $header_head = phutil_utf8_strtolower($header_head); switch ($header_head) { case 'transfer-encoding': unset($headers[$key]); break; } } $this->headers = $headers; return $body; }
public static function getDisableANSI() { if (self::$disableANSI === null) { $term = phutil_utf8_strtolower(getenv('TERM')); // ansicon enables ANSI support on Windows if (!$term && getenv('ANSICON')) { $term = 'ansi'; } if (phutil_is_windows() && $term !== 'cygwin' && $term !== 'ansi') { self::$disableANSI = true; } else { if (function_exists('posix_isatty') && !posix_isatty(STDOUT)) { self::$disableANSI = true; } else { self::$disableANSI = false; } } } return self::$disableANSI; }