当前位置: 首页>>代码示例>>PHP>>正文


PHP phutil_utf8_convert函数代码示例

本文整理汇总了PHP中phutil_utf8_convert函数的典型用法代码示例。如果您正苦于以下问题:PHP phutil_utf8_convert函数的具体用法?PHP phutil_utf8_convert怎么用?PHP phutil_utf8_convert使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了phutil_utf8_convert函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: loadGitCommitRef

 private function loadGitCommitRef()
 {
     $repository = $this->getRepository();
     // NOTE: %B was introduced somewhat recently in git's history, so pull
     // commit message information with %s and %b instead.
     // Even though we pass --encoding here, git doesn't always succeed, so
     // we try a little harder, since git *does* tell us what the actual encoding
     // is correctly (unless it doesn't; encoding is sometimes empty).
     list($info) = $repository->execxLocalCommand('log -n 1 --encoding=%s --format=%s %s --', 'UTF-8', implode('%x00', array('%e', '%cn', '%ce', '%an', '%ae', '%T', '%at', '%s%n%n%b')), $this->identifier);
     $parts = explode("", $info);
     $encoding = array_shift($parts);
     foreach ($parts as $key => $part) {
         if ($encoding) {
             $part = phutil_utf8_convert($part, 'UTF-8', $encoding);
         }
         $parts[$key] = phutil_utf8ize($part);
         if (!strlen($parts[$key])) {
             $parts[$key] = null;
         }
     }
     $hashes = array(id(new DiffusionCommitHash())->setHashType(ArcanistDifferentialRevisionHash::HASH_GIT_COMMIT)->setHashValue($this->identifier), id(new DiffusionCommitHash())->setHashType(ArcanistDifferentialRevisionHash::HASH_GIT_TREE)->setHashValue($parts[4]));
     $author_epoch = (int) $parts[5];
     if (!$author_epoch) {
         $author_epoch = null;
     }
     return id(new DiffusionCommitRef())->setCommitterName($parts[0])->setCommitterEmail($parts[1])->setAuthorName($parts[2])->setAuthorEmail($parts[3])->setHashes($hashes)->setAuthorEpoch($author_epoch)->setMessage($parts[6]);
 }
开发者ID:truSense,项目名称:phabricator,代码行数:27,代码来源:DiffusionLowLevelCommitQuery.php

示例2: loadFileContentFromFuture

 public final function loadFileContentFromFuture(Future $future)
 {
     if ($this->timeout) {
         $future->setTimeout($this->timeout);
     }
     if ($this->getByteLimit()) {
         $future->setStdoutSizeLimit($this->getByteLimit());
     }
     try {
         $file_content = $this->executeQueryFromFuture($future);
     } catch (CommandException $ex) {
         if (!$future->getWasKilledByTimeout()) {
             throw $ex;
         }
         $message = pht('<Attempt to load this file was terminated after %s second(s).>', $this->timeout);
         $file_content = new DiffusionFileContent();
         $file_content->setCorpus($message);
     }
     $this->fileContent = $file_content;
     $repository = $this->getRequest()->getRepository();
     $try_encoding = $repository->getDetail('encoding');
     if ($try_encoding) {
         $this->fileContent->setCorpus(phutil_utf8_convert($this->fileContent->getCorpus(), 'UTF-8', $try_encoding));
     }
     return $this->fileContent;
 }
开发者ID:moizsajid,项目名称:phabricator,代码行数:26,代码来源:DiffusionFileContentQuery.php

示例3: loadFileContent

 public final function loadFileContent()
 {
     $this->fileContent = $this->executeQuery();
     $repository = $this->getRequest()->getRepository();
     $try_encoding = $repository->getDetail('encoding');
     if ($try_encoding) {
         $this->fileContent->setCorpus(phutil_utf8_convert($this->fileContent->getCorpus(), "UTF-8", $try_encoding));
     }
     return $this->fileContent;
 }
开发者ID:rudimk,项目名称:phabricator,代码行数:10,代码来源:DiffusionFileContentQuery.php

示例4: parseCommit

 public function parseCommit(PhabricatorRepository $repository, PhabricatorRepositoryCommit $commit)
 {
     // NOTE: %B was introduced somewhat recently in git's history, so pull
     // commit message information with %s and %b instead.
     // Even though we pass --encoding here, git doesn't always succeed, so
     // we try a little harder, since git *does* tell us what the actual encoding
     // is correctly (unless it doesn't; encoding is sometimes empty).
     list($info) = $repository->execxLocalCommand('log -n 1 --encoding=%s --format=%s %s --', 'UTF-8', implode('%x00', array('%e', '%cn', '%ce', '%an', '%ae', '%s%n%n%b')), $commit->getCommitIdentifier());
     $parts = explode("", $info);
     $encoding = array_shift($parts);
     foreach ($parts as $key => $part) {
         if ($encoding) {
             $part = phutil_utf8_convert($part, 'UTF-8', $encoding);
         }
         $parts[$key] = phutil_utf8ize($part);
     }
     $committer_name = $parts[0];
     $committer_email = $parts[1];
     $author_name = $parts[2];
     $author_email = $parts[3];
     $message = $parts[4];
     if (strlen($author_email)) {
         $author = "{$author_name} <{$author_email}>";
     } else {
         $author = "{$author_name}";
     }
     if (strlen($committer_email)) {
         $committer = "{$committer_name} <{$committer_email}>";
     } else {
         $committer = "{$committer_name}";
     }
     if ($committer == $author) {
         $committer = null;
     }
     $this->updateCommitData($author, $message, $committer);
     if ($this->shouldQueueFollowupTasks()) {
         $task = new PhabricatorWorkerTask();
         $task->setTaskClass('PhabricatorRepositoryGitCommitChangeParserWorker');
         $task->setData(array('commitID' => $commit->getID()));
         $task->save();
     }
 }
开发者ID:neoxen,项目名称:phabricator,代码行数:42,代码来源:PhabricatorRepositoryGitCommitMessageParserWorker.php

示例5: __construct

 public function __construct($status_code, $body, array $headers, $expect = null)
 {
     // NOTE: Avoiding PhutilUTF8StringTruncator here because this isn't lazy
     // and responses may be large.
     if (strlen($body) > 512) {
         $excerpt = substr($body, 0, 512) . '...';
     } else {
         $excerpt = $body;
     }
     $content_type = BaseHTTPFuture::getHeader($headers, 'Content-Type');
     $match = null;
     if (preg_match('/;\\s*charset=([^;]+)/', $content_type, $match)) {
         $encoding = trim($match[1], "\"'");
         try {
             $excerpt = phutil_utf8_convert($excerpt, 'UTF-8', $encoding);
         } catch (Exception $ex) {
         }
     }
     $this->excerpt = phutil_utf8ize($excerpt);
     $this->expect = $expect;
     parent::__construct($status_code);
 }
开发者ID:lsubra,项目名称:libphutil,代码行数:22,代码来源:HTTPFutureHTTPResponseStatus.php

示例6: dirname

 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
if ($argc > 1) {
    $_SERVER['PHABRICATOR_ENV'] = $argv[1];
}
$root = dirname(dirname(dirname(__FILE__)));
require_once $root . '/scripts/__init_script__.php';
require_once $root . '/externals/mimemailparser/MimeMailParser.class.php';
$parser = new MimeMailParser();
$parser->setText(file_get_contents('php://stdin'));
$text_body = $parser->getMessageBody('text');
$text_body_headers = $parser->getMessageBodyHeaders('text');
$content_type = idx($text_body_headers, 'content-type');
if (!phutil_is_utf8($text_body) && (preg_match('/charset="(.*?)"/', $content_type, $matches) || preg_match('/charset=(\\S+)/', $content_type, $matches))) {
    $text_body = phutil_utf8_convert($text_body, "UTF-8", $matches[1]);
}
$headers = $parser->getHeaders();
$headers['subject'] = iconv_mime_decode($headers['subject'], 0, "UTF-8");
$headers['from'] = iconv_mime_decode($headers['from'], 0, "UTF-8");
$received = new PhabricatorMetaMTAReceivedMail();
$received->setHeaders($headers);
$received->setBodies(array('text' => $text_body, 'html' => $parser->getMessageBody('html')));
$attachments = array();
foreach ($parser->getAttachments() as $attachment) {
    if (preg_match('@text/(plain|html)@', $attachment->getContentType()) && $attachment->getContentDisposition() == 'inline') {
        // If this is an "inline" attachment with some sort of text content-type,
        // do not treat it as a file for attachment. MimeMailParser already picked
        // it up in the getMessageBody() call above. We still want to treat 'inline'
        // attachments with other content types (e.g., images) as attachments.
        continue;
开发者ID:neoxen,项目名称:phabricator,代码行数:31,代码来源:mail_handler.php

示例7: generateChanges


//.........这里部分代码省略.........
         } else {
             if ($repository_api instanceof ArcanistMercurialAPI) {
                 $diff = $repository_api->getFullMercurialDiff();
                 if (!strlen($diff)) {
                     throw new ArcanistUsageException(pht('No changes found. (Did you specify the wrong commit range?)'));
                 }
                 $changes = $parser->parseDiff($diff);
             } else {
                 throw new Exception(pht('Repository API is not supported.'));
             }
         }
     }
     if (count($changes) > 250) {
         $message = pht('This diff has a very large number of changes (%s). Differential ' . 'works best for changes which will receive detailed human review, ' . 'and not as well for large automated changes or bulk checkins. ' . 'See %s for information about reviewing big checkins. Continue anyway?', phutil_count($changes), 'https://secure.phabricator.com/book/phabricator/article/' . 'differential_large_changes/');
         if (!phutil_console_confirm($message)) {
             throw new ArcanistUsageException(pht('Aborted generation of gigantic diff.'));
         }
     }
     $limit = 1024 * 1024 * 4;
     foreach ($changes as $change) {
         $size = 0;
         foreach ($change->getHunks() as $hunk) {
             $size += strlen($hunk->getCorpus());
         }
         if ($size > $limit) {
             $byte_warning = pht("Diff for '%s' with context is %s bytes in length. " . "Generally, source changes should not be this large.", $change->getCurrentPath(), new PhutilNumber($size));
             if (!$this->getArgument('less-context')) {
                 $byte_warning .= ' ' . pht("If this file is a huge text file, try using the '%s' flag.", '--less-context');
             }
             if ($repository_api instanceof ArcanistSubversionAPI) {
                 throw new ArcanistUsageException($byte_warning . ' ' . pht("If the file is not a text file, mark it as binary with:" . "\n\n  \$ %s\n", 'svn propset svn:mime-type application/octet-stream <filename>'));
             } else {
                 $confirm = $byte_warning . ' ' . pht("If the file is not a text file, you can mark it 'binary'. " . "Mark this file as 'binary' and continue?");
                 if (phutil_console_confirm($confirm)) {
                     $change->convertToBinaryChange($repository_api);
                 } else {
                     throw new ArcanistUsageException(pht('Aborted generation of gigantic diff.'));
                 }
             }
         }
     }
     $try_encoding = nonempty($this->getArgument('encoding'), null);
     $utf8_problems = array();
     foreach ($changes as $change) {
         foreach ($change->getHunks() as $hunk) {
             $corpus = $hunk->getCorpus();
             if (!phutil_is_utf8($corpus)) {
                 // If this corpus is heuristically binary, don't try to convert it.
                 // mb_check_encoding() and mb_convert_encoding() are both very very
                 // liberal about what they're willing to process.
                 $is_binary = ArcanistDiffUtils::isHeuristicBinaryFile($corpus);
                 if (!$is_binary) {
                     if (!$try_encoding) {
                         try {
                             $try_encoding = $this->getRepositoryEncoding();
                         } catch (ConduitClientException $e) {
                             if ($e->getErrorCode() == 'ERR-BAD-ARCANIST-PROJECT') {
                                 echo phutil_console_wrap(pht('Lookup of encoding in arcanist project failed: %s', $e->getMessage()) . "\n");
                             } else {
                                 throw $e;
                             }
                         }
                     }
                     if ($try_encoding) {
                         $corpus = phutil_utf8_convert($corpus, 'UTF-8', $try_encoding);
                         $name = $change->getCurrentPath();
                         if (phutil_is_utf8($corpus)) {
                             $this->writeStatusMessage(pht("Converted a '%s' hunk from '%s' to UTF-8.\n", $name, $try_encoding));
                             $hunk->setCorpus($corpus);
                             continue;
                         }
                     }
                 }
                 $utf8_problems[] = $change;
                 break;
             }
         }
     }
     // If there are non-binary files which aren't valid UTF-8, warn the user
     // and treat them as binary changes. See D327 for discussion of why Arcanist
     // has this behavior.
     if ($utf8_problems) {
         $utf8_warning = sprintf("%s\n\n%s\n\n    %s\n", pht('This diff includes %s file(s) which are not valid UTF-8 (they ' . 'contain invalid byte sequences). You can either stop this ' . 'workflow and fix these files, or continue. If you continue, ' . 'these files will be marked as binary.', phutil_count($utf8_problems)), pht("You can learn more about how Phabricator handles character " . "encodings (and how to configure encoding settings and detect and " . "correct encoding problems) by reading 'User Guide: UTF-8 and " . "Character Encoding' in the Phabricator documentation."), pht('%s AFFECTED FILE(S)', phutil_count($utf8_problems)));
         $confirm = pht('Do you want to mark these %s file(s) as binary and continue?', phutil_count($utf8_problems));
         echo phutil_console_format("**%s**\n", pht('Invalid Content Encoding (Non-UTF8)'));
         echo phutil_console_wrap($utf8_warning);
         $file_list = mpull($utf8_problems, 'getCurrentPath');
         $file_list = '    ' . implode("\n    ", $file_list);
         echo $file_list;
         if (!phutil_console_confirm($confirm, $default_no = false)) {
             throw new ArcanistUsageException(pht('Aborted workflow to fix UTF-8.'));
         } else {
             foreach ($utf8_problems as $change) {
                 $change->convertToBinaryChange($repository_api);
             }
         }
     }
     $this->uploadFilesForChanges($changes);
     return $changes;
 }
开发者ID:rmaz,项目名称:arcanist,代码行数:101,代码来源:ArcanistDiffWorkflow.php

示例8: testUTF8Convert

 public function testUTF8Convert()
 {
     if (!function_exists('mb_convert_encoding')) {
         $this->assertSkipped("Requires mbstring extension.");
     }
     // "[ae]gis se[n]or [(c)] 1970 [+/-] 1 [degree]"
     $input = "�gis SE�OR � 1970 �1�";
     $expect = "ægis SEÑOR © 1970 ±1°";
     $output = phutil_utf8_convert($input, 'UTF-8', 'ISO-8859-1');
     $this->assertEqual($expect, $output, 'Conversion from ISO-8859-1.');
     $caught = null;
     try {
         phutil_utf8_convert('xyz', 'moon language', 'UTF-8');
     } catch (Exception $ex) {
         $caught = $ex;
     }
     $this->assertEqual(true, (bool) $caught, 'Conversion with bogus encoding.');
 }
开发者ID:relrod,项目名称:libphutil,代码行数:18,代码来源:PhutilUTF8TestCase.php

示例9: applyCustomInternalTransaction

 protected function applyCustomInternalTransaction(PhabricatorLiskDAO $object, PhabricatorApplicationTransaction $xaction)
 {
     switch ($xaction->getTransactionType()) {
         case PhabricatorRepositoryTransaction::TYPE_VCS:
             $object->setVersionControlSystem($xaction->getNewValue());
             break;
         case PhabricatorRepositoryTransaction::TYPE_ACTIVATE:
             $object->setDetail('tracking-enabled', $xaction->getNewValue());
             break;
         case PhabricatorRepositoryTransaction::TYPE_NAME:
             $object->setName($xaction->getNewValue());
             break;
         case PhabricatorRepositoryTransaction::TYPE_DESCRIPTION:
             $object->setDetail('description', $xaction->getNewValue());
             break;
         case PhabricatorRepositoryTransaction::TYPE_DEFAULT_BRANCH:
             $object->setDetail('default-branch', $xaction->getNewValue());
             break;
         case PhabricatorRepositoryTransaction::TYPE_TRACK_ONLY:
             $object->setDetail('branch-filter', array_fill_keys($xaction->getNewValue(), true));
             break;
         case PhabricatorRepositoryTransaction::TYPE_AUTOCLOSE_ONLY:
             $object->setDetail('close-commits-filter', array_fill_keys($xaction->getNewValue(), true));
             break;
         case PhabricatorRepositoryTransaction::TYPE_UUID:
             $object->setUUID($xaction->getNewValue());
             break;
         case PhabricatorRepositoryTransaction::TYPE_SVN_SUBPATH:
             $object->setDetail('svn-subpath', $xaction->getNewValue());
             break;
         case PhabricatorRepositoryTransaction::TYPE_NOTIFY:
             $object->setDetail('herald-disabled', (int) (!$xaction->getNewValue()));
             break;
         case PhabricatorRepositoryTransaction::TYPE_AUTOCLOSE:
             $object->setDetail('disable-autoclose', (int) (!$xaction->getNewValue()));
             break;
         case PhabricatorRepositoryTransaction::TYPE_REMOTE_URI:
             $object->setDetail('remote-uri', $xaction->getNewValue());
             break;
         case PhabricatorRepositoryTransaction::TYPE_LOCAL_PATH:
             $object->setDetail('local-path', $xaction->getNewValue());
             break;
         case PhabricatorRepositoryTransaction::TYPE_HOSTING:
             return $object->setHosted($xaction->getNewValue());
         case PhabricatorRepositoryTransaction::TYPE_PROTOCOL_HTTP:
             return $object->setServeOverHTTP($xaction->getNewValue());
         case PhabricatorRepositoryTransaction::TYPE_PROTOCOL_SSH:
             return $object->setServeOverSSH($xaction->getNewValue());
         case PhabricatorRepositoryTransaction::TYPE_PUSH_POLICY:
             return $object->setPushPolicy($xaction->getNewValue());
         case PhabricatorRepositoryTransaction::TYPE_CREDENTIAL:
             return $object->setCredentialPHID($xaction->getNewValue());
         case PhabricatorRepositoryTransaction::TYPE_DANGEROUS:
             $object->setDetail('allow-dangerous-changes', $xaction->getNewValue());
             return;
         case PhabricatorRepositoryTransaction::TYPE_SLUG:
             $object->setRepositorySlug($xaction->getNewValue());
             return;
         case PhabricatorRepositoryTransaction::TYPE_SERVICE:
             $object->setAlmanacServicePHID($xaction->getNewValue());
             return;
         case PhabricatorRepositoryTransaction::TYPE_SYMBOLS_LANGUAGE:
             $object->setDetail('symbol-languages', $xaction->getNewValue());
             return;
         case PhabricatorRepositoryTransaction::TYPE_SYMBOLS_SOURCES:
             $object->setDetail('symbol-sources', $xaction->getNewValue());
             return;
         case PhabricatorRepositoryTransaction::TYPE_STAGING_URI:
             $object->setDetail('staging-uri', $xaction->getNewValue());
             return;
         case PhabricatorRepositoryTransaction::TYPE_AUTOMATION_BLUEPRINTS:
             $object->setDetail('automation.blueprintPHIDs', $xaction->getNewValue());
             return;
         case PhabricatorRepositoryTransaction::TYPE_ENCODING:
             // Make sure the encoding is valid by converting to UTF-8. This tests
             // that the user has mbstring installed, and also that they didn't type
             // a garbage encoding name. Note that we're converting from UTF-8 to
             // the target encoding, because mbstring is fine with converting from
             // a nonsense encoding.
             $encoding = $xaction->getNewValue();
             if (strlen($encoding)) {
                 try {
                     phutil_utf8_convert('.', $encoding, 'UTF-8');
                 } catch (Exception $ex) {
                     throw new PhutilProxyException(pht("Error setting repository encoding '%s': %s'", $encoding, $ex->getMessage()), $ex);
                 }
             }
             $object->setDetail('encoding', $encoding);
             break;
     }
 }
开发者ID:nanamiwang,项目名称:phabricator,代码行数:91,代码来源:PhabricatorRepositoryEditor.php

示例10: parseChangeset


//.........这里部分代码省略.........
         }
         $hunk->setOldLength($old_len);
         $hunk->setNewLength($new_len);
         $add = 0;
         $del = 0;
         $hit_next_hunk = false;
         while (($line = $this->nextLine()) !== null) {
             if (strlen(rtrim($line, "\r\n"))) {
                 $char = $line[0];
             } else {
                 // Normally, we do not encouter empty lines in diffs, because
                 // unchanged lines have an initial space. However, in Git, with
                 // the option `diff.suppress-blank-empty` set, unchanged blank lines
                 // emit as completely empty. If we encounter a completely empty line,
                 // treat it as a ' ' (i.e., unchanged empty line) line.
                 $char = ' ';
             }
             switch ($char) {
                 case '\\':
                     if (!preg_match('@\\ No newline at end of file@', $line)) {
                         $this->didFailParse(pht("Expected '\\ No newline at end of file'."));
                     }
                     if ($new_len) {
                         $real[] = $line;
                         $hunk->setIsMissingOldNewline(true);
                     } else {
                         $real[] = $line;
                         $hunk->setIsMissingNewNewline(true);
                     }
                     if (!$new_len) {
                         break 2;
                     }
                     break;
                 case '+':
                     ++$add;
                     --$new_len;
                     $real[] = $line;
                     break;
                 case '-':
                     if (!$old_len) {
                         // In this case, we've hit "---" from a new file. So don't
                         // advance the line cursor.
                         $hit_next_hunk = true;
                         break 2;
                     }
                     ++$del;
                     --$old_len;
                     $real[] = $line;
                     break;
                 case ' ':
                     if (!$old_len && !$new_len) {
                         break 2;
                     }
                     --$old_len;
                     --$new_len;
                     $real[] = $line;
                     break;
                 default:
                     // We hit something, likely another hunk.
                     $hit_next_hunk = true;
                     break 2;
             }
         }
         if ($old_len || $new_len) {
             $this->didFailParse(pht('Found the wrong number of hunk lines.'));
         }
         $corpus = implode('', $real);
         $is_binary = false;
         if ($this->detectBinaryFiles) {
             $is_binary = !phutil_is_utf8($corpus);
             $try_encoding = $this->tryEncoding;
             if ($is_binary && $try_encoding) {
                 $is_binary = ArcanistDiffUtils::isHeuristicBinaryFile($corpus);
                 if (!$is_binary) {
                     $corpus = phutil_utf8_convert($corpus, 'UTF-8', $try_encoding);
                     if (!phutil_is_utf8($corpus)) {
                         throw new Exception(pht("Failed to convert a hunk from '%s' to UTF-8. " . "Check that the specified encoding is correct.", $try_encoding));
                     }
                 }
             }
         }
         if ($is_binary) {
             // SVN happily treats binary files which aren't marked with the right
             // mime type as text files. Detect that junk here and mark the file
             // binary. We'll catch stuff with unicode too, but that's verboten
             // anyway. If there are too many false positives with this we might
             // need to make it threshold-triggered instead of triggering on any
             // unprintable byte.
             $change->setFileType(ArcanistDiffChangeType::FILE_BINARY);
         } else {
             $hunk->setCorpus($corpus);
             $hunk->setAddLines($add);
             $hunk->setDelLines($del);
             $change->addHunk($hunk);
         }
         if (!$hit_next_hunk) {
             $line = $this->nextNonemptyLine();
         }
     } while (preg_match('/^@@ /', $line));
 }
开发者ID:benchling,项目名称:arcanist,代码行数:101,代码来源:ArcanistDiffParser.php

示例11: convertNonUTF8Diff

 private function convertNonUTF8Diff($diff)
 {
     if ($this->encoding) {
         $diff = phutil_utf8_convert($diff, $this->encoding, 'UTF-8');
     }
     return $diff;
 }
开发者ID:chaozhang80,项目名称:tool-package,代码行数:7,代码来源:ArcanistBundle.php

示例12: buildPatch

 private function buildPatch(PhabricatorMetaMTAMail $template, PhabricatorRepository $repository, PhabricatorRepositoryCommit $commit)
 {
     $attach_key = 'metamta.diffusion.attach-patches';
     $inline_key = 'metamta.diffusion.inline-patches';
     $attach_patches = PhabricatorEnv::getEnvConfig($attach_key);
     $inline_patches = PhabricatorEnv::getEnvConfig($inline_key);
     if (!$attach_patches && !$inline_patches) {
         return;
     }
     $encoding = $repository->getDetail('encoding', 'UTF-8');
     $result = null;
     $patch_error = null;
     try {
         $raw_patch = $this->loadRawPatchText($repository, $commit);
         if ($attach_patches) {
             $commit_name = $repository->formatCommitName($commit->getCommitIdentifier());
             $template->addAttachment(new PhabricatorMetaMTAAttachment($raw_patch, $commit_name . '.patch', 'text/x-patch; charset=' . $encoding));
         }
     } catch (Exception $ex) {
         phlog($ex);
         $patch_error = 'Unable to generate: ' . $ex->getMessage();
     }
     if ($patch_error) {
         $result = $patch_error;
     } else {
         if ($inline_patches) {
             $len = substr_count($raw_patch, "\n");
             if ($len <= $inline_patches) {
                 // We send email as utf8, so we need to convert the text to utf8 if
                 // we can.
                 if ($encoding) {
                     $raw_patch = phutil_utf8_convert($raw_patch, 'UTF-8', $encoding);
                 }
                 $result = phutil_utf8ize($raw_patch);
             }
         }
     }
     if ($result) {
         $result = "PATCH\n\n{$result}\n";
     }
     return $result;
 }
开发者ID:denghp,项目名称:phabricator,代码行数:42,代码来源:PhabricatorRepositoryCommitHeraldWorker.php

示例13: dirname

        }
    }
}
$root = dirname(dirname(dirname(__FILE__)));
require_once $root . '/scripts/__init_script__.php';
require_once $root . '/externals/mimemailparser/MimeMailParser.class.php';
$args = new PhutilArgumentParser($argv);
$args->parseStandardArguments();
$args->parse(array(array('name' => 'process-duplicates', 'help' => pht("Process this message, even if it's a duplicate of another message. " . "This is mostly useful when debugging issues with mail routing.")), array('name' => 'env', 'wildcard' => true)));
$parser = new MimeMailParser();
$parser->setText(file_get_contents('php://stdin'));
$text_body = $parser->getMessageBody('text');
$text_body_headers = $parser->getMessageBodyHeaders('text');
$content_type = idx($text_body_headers, 'content-type');
if (!phutil_is_utf8($text_body) && (preg_match('/charset="(.*?)"/', $content_type, $matches) || preg_match('/charset=(\\S+)/', $content_type, $matches))) {
    $text_body = phutil_utf8_convert($text_body, 'UTF-8', $matches[1]);
}
$headers = $parser->getHeaders();
$headers['subject'] = iconv_mime_decode($headers['subject'], 0, 'UTF-8');
$headers['from'] = iconv_mime_decode($headers['from'], 0, 'UTF-8');
if ($args->getArg('process-duplicates')) {
    $headers['message-id'] = Filesystem::readRandomCharacters(64);
}
$received = new PhabricatorMetaMTAReceivedMail();
$received->setHeaders($headers);
$received->setBodies(array('text' => $text_body, 'html' => $parser->getMessageBody('html')));
$attachments = array();
foreach ($parser->getAttachments() as $attachment) {
    if (preg_match('@text/(plain|html)@', $attachment->getContentType()) && $attachment->getContentDisposition() == 'inline') {
        // If this is an "inline" attachment with some sort of text content-type,
        // do not treat it as a file for attachment. MimeMailParser already picked
开发者ID:pugong,项目名称:phabricator,代码行数:31,代码来源:mail_handler.php

示例14: inlinePatch

 private function inlinePatch(PhabricatorMetaMTAMailBody $body, PhabricatorRepositoryCommit $commit)
 {
     if (!$this->getRawPatch()) {
         return;
     }
     $inline_key = 'metamta.diffusion.inline-patches';
     $inline_patches = PhabricatorEnv::getEnvConfig($inline_key);
     if (!$inline_patches) {
         return;
     }
     $repository = $commit->getRepository();
     $raw_patch = $this->getRawPatch();
     $result = null;
     $len = substr_count($raw_patch, "\n");
     if ($len <= $inline_patches) {
         // We send email as utf8, so we need to convert the text to utf8 if
         // we can.
         $encoding = $repository->getDetail('encoding', 'UTF-8');
         if ($encoding) {
             $raw_patch = phutil_utf8_convert($raw_patch, 'UTF-8', $encoding);
         }
         $result = phutil_utf8ize($raw_patch);
     }
     if ($result) {
         $result = "PATCH\n\n{$result}\n";
     }
     $body->addRawSection($result);
 }
开发者ID:shrimpma,项目名称:phabricator,代码行数:28,代码来源:PhabricatorAuditEditor.php

示例15: validateTransaction

 protected function validateTransaction(PhabricatorLiskDAO $object, $type, array $xactions)
 {
     $errors = parent::validateTransaction($object, $type, $xactions);
     switch ($type) {
         case PhabricatorRepositoryTransaction::TYPE_AUTOCLOSE_ONLY:
         case PhabricatorRepositoryTransaction::TYPE_TRACK_ONLY:
             foreach ($xactions as $xaction) {
                 foreach ($xaction->getNewValue() as $pattern) {
                     // Check for invalid regular expressions.
                     $regexp = PhabricatorRepository::extractBranchRegexp($pattern);
                     if ($regexp !== null) {
                         $ok = @preg_match($regexp, '');
                         if ($ok === false) {
                             $error = new PhabricatorApplicationTransactionValidationError($type, pht('Invalid'), pht('Expression "%s" is not a valid regular expression. Note ' . 'that you must include delimiters.', $regexp), $xaction);
                             $errors[] = $error;
                             continue;
                         }
                     }
                     // Check for formatting mistakes like `regex(...)` instead of
                     // `regexp(...)`.
                     $matches = null;
                     if (preg_match('/^([^(]+)\\(.*\\)\\z/', $pattern, $matches)) {
                         switch ($matches[1]) {
                             case 'regexp':
                                 break;
                             default:
                                 $error = new PhabricatorApplicationTransactionValidationError($type, pht('Invalid'), pht('Matching function "%s(...)" is not recognized. Valid ' . 'functions are: regexp(...).', $matches[1]), $xaction);
                                 $errors[] = $error;
                                 break;
                         }
                     }
                 }
             }
             break;
         case PhabricatorRepositoryTransaction::TYPE_AUTOMATION_BLUEPRINTS:
             foreach ($xactions as $xaction) {
                 $old = nonempty($xaction->getOldValue(), array());
                 $new = nonempty($xaction->getNewValue(), array());
                 $add = array_diff($new, $old);
                 $invalid = PhabricatorObjectQuery::loadInvalidPHIDsForViewer($this->getActor(), $add);
                 if ($invalid) {
                     $errors[] = new PhabricatorApplicationTransactionValidationError($type, pht('Invalid'), pht('Some of the selected automation blueprints are invalid ' . 'or restricted: %s.', implode(', ', $invalid)), $xaction);
                 }
             }
             break;
         case PhabricatorRepositoryTransaction::TYPE_VCS:
             $vcs_map = PhabricatorRepositoryType::getAllRepositoryTypes();
             $current_vcs = $object->getVersionControlSystem();
             if (!$this->getIsNewObject()) {
                 foreach ($xactions as $xaction) {
                     if ($xaction->getNewValue() == $current_vcs) {
                         continue;
                     }
                     $errors[] = new PhabricatorApplicationTransactionValidationError($type, pht('Immutable'), pht('You can not change the version control system an existing ' . 'repository uses. It can only be set when a repository is ' . 'first created.'), $xaction);
                 }
             } else {
                 $value = $object->getVersionControlSystem();
                 foreach ($xactions as $xaction) {
                     $value = $xaction->getNewValue();
                     if (empty($vcs_map[$value])) {
                         $errors[] = new PhabricatorApplicationTransactionValidationError($type, pht('Invalid'), pht('Specified version control system must be a VCS ' . 'recognized by Phabricator: %s.', implode(', ', array_keys($vcs_map))), $xaction);
                     }
                 }
                 if (!strlen($value)) {
                     $error = new PhabricatorApplicationTransactionValidationError($type, pht('Required'), pht('When creating a repository, you must specify a valid ' . 'underlying version control system: %s.', implode(', ', array_keys($vcs_map))), nonempty(last($xactions), null));
                     $error->setIsMissingFieldError(true);
                     $errors[] = $error;
                 }
             }
             break;
         case PhabricatorRepositoryTransaction::TYPE_NAME:
             $missing = $this->validateIsEmptyTextField($object->getName(), $xactions);
             if ($missing) {
                 $error = new PhabricatorApplicationTransactionValidationError($type, pht('Required'), pht('Repository name is required.'), nonempty(last($xactions), null));
                 $error->setIsMissingFieldError(true);
                 $errors[] = $error;
             }
             break;
         case PhabricatorRepositoryTransaction::TYPE_ACTIVATE:
             $status_map = PhabricatorRepository::getStatusMap();
             foreach ($xactions as $xaction) {
                 $status = $xaction->getNewValue();
                 if (empty($status_map[$status])) {
                     $errors[] = new PhabricatorApplicationTransactionValidationError($type, pht('Invalid'), pht('Repository status "%s" is not valid.', $status), $xaction);
                 }
             }
             break;
         case PhabricatorRepositoryTransaction::TYPE_ENCODING:
             foreach ($xactions as $xaction) {
                 // Make sure the encoding is valid by converting to UTF-8. This tests
                 // that the user has mbstring installed, and also that they didn't
                 // type a garbage encoding name. Note that we're converting from
                 // UTF-8 to the target encoding, because mbstring is fine with
                 // converting from a nonsense encoding.
                 $encoding = $xaction->getNewValue();
                 if (!strlen($encoding)) {
                     continue;
                 }
                 try {
                     phutil_utf8_convert('.', $encoding, 'UTF-8');
//.........这里部分代码省略.........
开发者ID:rchicoli,项目名称:phabricator,代码行数:101,代码来源:PhabricatorRepositoryEditor.php


注:本文中的phutil_utf8_convert函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。