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


PHP PhabricatorFile类代码示例

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


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

示例1: buildDefaultTransformation

 private function buildDefaultTransformation(PhabricatorFile $file)
 {
     static $regexps = array('@application/zip@' => 'zip', '@image/@' => 'image', '@application/pdf@' => 'pdf', '@.*@' => 'default');
     $type = $file->getMimeType();
     $prefix = 'default';
     foreach ($regexps as $regexp => $implied_prefix) {
         if (preg_match($regexp, $type)) {
             $prefix = $implied_prefix;
             break;
         }
     }
     switch ($this->transform) {
         case 'thumb-280x210':
             $suffix = '280x210';
             break;
         case 'thumb-160x120':
             $suffix = '160x120';
             break;
         case 'thumb-60x45':
             $suffix = '60x45';
             break;
         case 'preview-100':
             $suffix = '.p100';
             break;
         default:
             throw new Exception('Unsupported transformation type!');
     }
     $path = celerity_get_resource_uri("rsrc/image/icon/fatcow/thumbnails/{$prefix}{$suffix}.png");
     return id(new AphrontRedirectResponse())->setURI($path);
 }
开发者ID:denghp,项目名称:phabricator,代码行数:30,代码来源:PhabricatorFileTransformController.php

示例2: buildActionView

 private function buildActionView(PhabricatorUser $viewer, PhabricatorPaste $paste, PhabricatorFile $file)
 {
     $can_edit = PhabricatorPolicyFilter::hasCapability($viewer, $paste, PhabricatorPolicyCapability::CAN_EDIT);
     $can_fork = $viewer->isLoggedIn();
     $fork_uri = $this->getApplicationURI('/create/?parent=' . $paste->getID());
     return id(new PhabricatorActionListView())->setUser($viewer)->setObject($paste)->setObjectURI($this->getRequest()->getRequestURI())->addAction(id(new PhabricatorActionView())->setName(pht('Edit Paste'))->setIcon('fa-pencil')->setDisabled(!$can_edit)->setWorkflow(!$can_edit)->setHref($this->getApplicationURI('/edit/' . $paste->getID() . '/')))->addAction(id(new PhabricatorActionView())->setName(pht('Fork This Paste'))->setIcon('fa-code-fork')->setDisabled(!$can_fork)->setWorkflow(!$can_fork)->setHref($fork_uri))->addAction(id(new PhabricatorActionView())->setName(pht('View Raw File'))->setIcon('fa-file-text-o')->setHref($file->getBestURI()));
 }
开发者ID:fengshao0907,项目名称:phabricator,代码行数:7,代码来源:PhabricatorPasteViewController.php

示例3: calculatePatch

 /**
  * Calculate the DiffMatchPatch patch between two Phabricator files.
  *
  * @phutil-external-symbol class diff_match_patch
  */
 public static function calculatePatch(PhabricatorFile $old = null, PhabricatorFile $new = null)
 {
     $root = dirname(phutil_get_library_root('phabricator'));
     require_once $root . '/externals/diff_match_patch/diff_match_patch.php';
     $old_hash = self::EMPTY_HASH;
     $new_hash = self::EMPTY_HASH;
     if ($old !== null) {
         $old_hash = $old->getContentHash();
     }
     if ($new !== null) {
         $new_hash = $new->getContentHash();
     }
     $old_content = '';
     $new_content = '';
     if ($old_hash === $new_hash) {
         return null;
     }
     if ($old_hash !== self::EMPTY_HASH) {
         $old_content = $old->loadFileData();
     } else {
         $old_content = '';
     }
     if ($new_hash !== self::EMPTY_HASH) {
         $new_content = $new->loadFileData();
     } else {
         $new_content = '';
     }
     $dmp = new diff_match_patch();
     $dmp_patches = $dmp->patch_make($old_content, $new_content);
     return $dmp->patch_toText($dmp_patches);
 }
开发者ID:pugong,项目名称:phabricator,代码行数:36,代码来源:PhragmentPatchUtil.php

示例4: crudelyScaleTo

 /**
  * Very crudely scale an image up or down to an exact size.
  */
 private function crudelyScaleTo(PhabricatorFile $file, $dx, $dy)
 {
     $data = $file->loadFileData();
     $src = imagecreatefromstring($data);
     $dst = $this->applyScaleTo($src, $dx, $dy);
     return $this->saveImageDataInAnyFormat($dst, $file->getMimeType());
 }
开发者ID:neoxen,项目名称:phabricator,代码行数:10,代码来源:PhabricatorImageTransformer.php

示例5: newChunkQuery

 private function newChunkQuery(PhabricatorUser $viewer, PhabricatorFile $file)
 {
     $engine = $file->instantiateStorageEngine();
     if (!$engine->isChunkEngine()) {
         throw new Exception(pht('File "%s" does not have chunks!', $file->getPHID()));
     }
     return id(new PhabricatorFileChunkQuery())->setViewer($viewer)->withChunkHandles(array($file->getStorageHandle()));
 }
开发者ID:pugong,项目名称:phabricator,代码行数:8,代码来源:FileConduitAPIMethod.php

示例6: buildSourceCodeView

 private function buildSourceCodeView(PhabricatorPaste $paste, PhabricatorFile $file)
 {
     $language = $paste->getLanguage();
     $source = $file->loadFileData();
     if (empty($language)) {
         $source = PhabricatorSyntaxHighlighter::highlightWithFilename($paste->getTitle(), $source);
     } else {
         $source = PhabricatorSyntaxHighlighter::highlightWithLanguage($language, $source);
     }
     $lines = explode("\n", $source);
     return id(new PhabricatorSourceCodeView())->setLines($lines);
 }
开发者ID:neoxen,项目名称:phabricator,代码行数:12,代码来源:PhabricatorPasteViewController.php

示例7: renderCommentForm

 private function renderCommentForm(PhabricatorFile $file)
 {
     $viewer = $this->getViewer();
     if (!$viewer->isLoggedIn()) {
         $login_href = id(new PhutilURI('/auth/start/'))->setQueryParam('next', '/' . $file->getMonogram());
         return id(new PHUIFormLayoutView())->addClass('phui-comment-panel-empty')->appendChild(id(new PHUIButtonView())->setTag('a')->setText(pht('Login to Comment'))->setHref((string) $login_href));
     }
     $draft = PhabricatorDraft::newFromUserAndKey($viewer, $file->getPHID());
     $post_uri = $this->getApplicationURI('thread/' . $file->getPHID() . '/');
     $form = id(new AphrontFormView())->setUser($viewer)->setAction($post_uri)->addSigil('lightbox-comment-form')->addClass('lightbox-comment-form')->setWorkflow(true)->appendChild(id(new PhabricatorRemarkupControl())->setUser($viewer)->setName('comment')->setValue($draft->getDraft()))->appendChild(id(new AphrontFormSubmitControl())->setValue(pht('Comment')));
     $view = phutil_tag_div('phui-comment-panel', $form);
     return $view;
 }
开发者ID:NeoArmageddon,项目名称:phabricator,代码行数:13,代码来源:PhabricatorFileLightboxController.php

示例8: processRequest

 public function processRequest()
 {
     if (!PhabricatorEnv::getEnvConfig('files.enable-proxy')) {
         return new Aphront400Response();
     }
     $request = $this->getRequest();
     $uri = $request->getStr('uri');
     $proxy = id(new PhabricatorFileProxyImage())->loadOneWhere('uri = %s', $uri);
     if (!$proxy) {
         // This write is fine to skip CSRF checks for, we're just building a
         // cache of some remote image.
         $unguarded = AphrontWriteGuard::beginScopedUnguardedWrites();
         $file = PhabricatorFile::newFromFileDownload($uri, nonempty(basename($uri), 'proxied-file'));
         if ($file) {
             $proxy = new PhabricatorFileProxyImage();
             $proxy->setURI($uri);
             $proxy->setFilePHID($file->getPHID());
             $proxy->save();
         }
         unset($unguarded);
     }
     if ($proxy) {
         $file = id(new PhabricatorFile())->loadOneWhere('phid = %s', $proxy->getFilePHID());
         if ($file) {
             $view_uri = $file->getBestURI();
         } else {
             $bad_phid = $proxy->getFilePHID();
             throw new Exception("Unable to load file with phid {$bad_phid}.");
         }
         return id(new AphrontRedirectResponse())->setURI($view_uri);
     }
     return new Aphront400Response();
 }
开发者ID:nexeck,项目名称:phabricator,代码行数:33,代码来源:PhabricatorFileProxyController.php

示例9: render

 public function render()
 {
     $viewer = $this->getViewer();
     if (!$viewer->isLoggedIn()) {
         return null;
     }
     $instructions_id = 'phabricator-global-drag-and-drop-upload-instructions';
     require_celerity_resource('global-drag-and-drop-css');
     $hint_text = $this->getHintText();
     if (!strlen($hint_text)) {
         $hint_text = "⇪ " . pht('Drop Files to Upload');
     }
     // Use the configured default view policy. Drag and drop uploads use
     // a more restrictive view policy if we don't specify a policy explicitly,
     // as the more restrictive policy is correct for most drop targets (like
     // Pholio uploads and Remarkup text areas).
     $view_policy = $this->getViewPolicy();
     if ($view_policy === null) {
         $view_policy = PhabricatorFile::initializeNewFile()->getViewPolicy();
     }
     $submit_uri = $this->getSubmitURI();
     $done_uri = '/file/query/authored/';
     Javelin::initBehavior('global-drag-and-drop', array('ifSupported' => $this->showIfSupportedID, 'instructions' => $instructions_id, 'uploadURI' => '/file/dropupload/', 'submitURI' => $submit_uri, 'browseURI' => $done_uri, 'viewPolicy' => $view_policy, 'chunkThreshold' => PhabricatorFileStorageEngine::getChunkThreshold()));
     return phutil_tag('div', array('id' => $instructions_id, 'class' => 'phabricator-global-upload-instructions', 'style' => 'display: none;'), $hint_text);
 }
开发者ID:NeoArmageddon,项目名称:phabricator,代码行数:25,代码来源:PhabricatorGlobalUploadTargetView.php

示例10: readRequest

 public function readRequest(PhabricatorConfigOption $option, AphrontRequest $request)
 {
     $viewer = $request->getViewer();
     $view_policy = PhabricatorPolicies::POLICY_PUBLIC;
     if ($request->getBool('removeLogo')) {
         $logo_image_phid = null;
     } else {
         if ($request->getFileExists('logoImage')) {
             $logo_image = PhabricatorFile::newFromPHPUpload(idx($_FILES, 'logoImage'), array('name' => 'logo', 'authorPHID' => $viewer->getPHID(), 'viewPolicy' => $view_policy, 'canCDN' => true, 'isExplicitUpload' => true));
             $logo_image_phid = $logo_image->getPHID();
         } else {
             $logo_image_phid = self::getLogoImagePHID();
         }
     }
     $wordmark_text = $request->getStr('wordmarkText');
     $value = array('logoImagePHID' => $logo_image_phid, 'wordmarkText' => $wordmark_text);
     $errors = array();
     $e_value = null;
     try {
         $this->validateOption($option, $value);
     } catch (Exception $ex) {
         $e_value = pht('Invalid');
         $errors[] = $ex->getMessage();
         $value = array();
     }
     return array($e_value, $errors, $value, phutil_json_encode($value));
 }
开发者ID:endlessm,项目名称:phabricator,代码行数:27,代码来源:PhabricatorCustomLogoConfigType.php

示例11: execute

 protected function execute(ConduitAPIRequest $request)
 {
     $viewer = $request->getUser();
     $file_phid = $request->getValue('filePHID');
     $file = $this->loadFileByPHID($viewer, $file_phid);
     $start = $request->getValue('byteStart');
     $data = $request->getValue('data');
     $encoding = $request->getValue('dataEncoding');
     switch ($encoding) {
         case 'base64':
             $data = $this->decodeBase64($data);
             break;
         case null:
             break;
         default:
             throw new Exception(pht('Unsupported data encoding.'));
     }
     $length = strlen($data);
     $chunk = $this->loadFileChunkForUpload($viewer, $file, $start, $start + $length);
     // NOTE: These files have a view policy which prevents normal access. They
     // are only accessed through the storage engine.
     $chunk_data = PhabricatorFile::newFromFileData($data, array('name' => $file->getMonogram() . '.chunk-' . $chunk->getID(), 'viewPolicy' => PhabricatorPolicies::POLICY_NOONE));
     $chunk->setDataFilePHID($chunk_data->getPHID())->save();
     $missing = $this->loadAnyMissingChunk($viewer, $file);
     if (!$missing) {
         $file->setIsPartial(0)->save();
     }
     return null;
 }
开发者ID:pugong,项目名称:phabricator,代码行数:29,代码来源:FileUploadChunkConduitAPIMethod.php

示例12: processRequest

 public function processRequest()
 {
     if ($this->id) {
         $macro = id(new PhabricatorFileImageMacro())->load($this->id);
         if (!$macro) {
             return new Aphront404Response();
         }
     } else {
         $macro = new PhabricatorFileImageMacro();
     }
     $errors = array();
     $e_name = true;
     $request = $this->getRequest();
     $user = $request->getUser();
     if ($request->isFormPost()) {
         $macro->setName($request->getStr('name'));
         if (!strlen($macro->getName())) {
             $errors[] = 'Macro name is required.';
             $e_name = 'Required';
         } else {
             if (!preg_match('/^[a-z0-9_-]{3,}$/', $macro->getName())) {
                 $errors[] = 'Macro must be at least three characters long and contain ' . 'only lowercase letters, digits, hyphen and underscore.';
                 $e_name = 'Invalid';
             } else {
                 $e_name = null;
             }
         }
         if (!$errors) {
             $file = PhabricatorFile::newFromPHPUpload(idx($_FILES, 'file'), array('name' => $request->getStr('name'), 'authorPHID' => $user->getPHID()));
             $macro->setFilePHID($file->getPHID());
             try {
                 $macro->save();
                 return id(new AphrontRedirectResponse())->setURI('/file/macro/');
             } catch (AphrontQueryDuplicateKeyException $ex) {
                 $errors[] = 'Macro name is not unique!';
                 $e_name = 'Duplicate';
             }
         }
     }
     if ($errors) {
         $error_view = new AphrontErrorView();
         $error_view->setTitle('Form Errors');
         $error_view->setErrors($errors);
     } else {
         $error_view = null;
     }
     $form = new AphrontFormView();
     $form->setAction('/file/macro/edit/');
     $form->setUser($request->getUser());
     $form->setEncType('multipart/form-data')->appendChild(id(new AphrontFormTextControl())->setLabel('Name')->setName('name')->setValue($macro->getName())->setCaption('This word or phrase will be replaced with the image.')->setError($e_name))->appendChild(id(new AphrontFormFileControl())->setLabel('File')->setName('file')->setError(true))->appendChild(id(new AphrontFormSubmitControl())->setValue('Save Image Macro')->addCancelButton('/file/macro/'));
     $panel = new AphrontPanelView();
     if ($macro->getID()) {
         $panel->setHeader('Edit Image Macro');
     } else {
         $panel->setHeader('Create Image Macro');
     }
     $panel->appendChild($form);
     $panel->setWidth(AphrontPanelView::WIDTH_FORM);
     return $this->buildStandardPageResponse(array($error_view, $panel), array('title' => 'Edit Image Macro'));
 }
开发者ID:nguyennamtien,项目名称:phabricator,代码行数:60,代码来源:PhabricatorFileMacroEditController.php

示例13: processRequest

 public function processRequest()
 {
     // No CSRF for SendGrid.
     $unguarded = AphrontWriteGuard::beginScopedUnguardedWrites();
     $request = $this->getRequest();
     $user = $request->getUser();
     $raw_headers = $request->getStr('headers');
     $raw_headers = explode("\n", rtrim($raw_headers));
     $raw_dict = array();
     foreach (array_filter($raw_headers) as $header) {
         list($name, $value) = explode(':', $header, 2);
         $raw_dict[$name] = ltrim($value);
     }
     $headers = array('to' => $request->getStr('to'), 'from' => $request->getStr('from'), 'subject' => $request->getStr('subject')) + $raw_dict;
     $received = new PhabricatorMetaMTAReceivedMail();
     $received->setHeaders($headers);
     $received->setBodies(array('text' => $request->getStr('text'), 'html' => $request->getStr('from')));
     $file_phids = array();
     foreach ($_FILES as $file_raw) {
         try {
             $file = PhabricatorFile::newFromPHPUpload($file_raw, array('authorPHID' => $user->getPHID()));
             $file_phids[] = $file->getPHID();
         } catch (Exception $ex) {
             phlog($ex);
         }
     }
     $received->setAttachments($file_phids);
     $received->save();
     $received->processReceivedMail();
     $response = new AphrontWebpageResponse();
     $response->setContent("Got it! Thanks, SendGrid!\n");
     return $response;
 }
开发者ID:nexeck,项目名称:phabricator,代码行数:33,代码来源:PhabricatorMetaMTASendGridReceiveController.php

示例14: handleRequest

 public function handleRequest(AphrontRequest $request)
 {
     $viewer = $this->getViewer();
     $key = $this->newKeyForObjectPHID($request->getStr('objectPHID'));
     if (!$key) {
         return new Aphront404Response();
     }
     $cancel_uri = $key->getObject()->getSSHPublicKeyManagementURI($viewer);
     $token = id(new PhabricatorAuthSessionEngine())->requireHighSecuritySession($viewer, $request, $cancel_uri);
     if ($request->isFormPost()) {
         $default_name = $key->getObject()->getSSHKeyDefaultName();
         $keys = PhabricatorSSHKeyGenerator::generateKeypair();
         list($public_key, $private_key) = $keys;
         $file = PhabricatorFile::buildFromFileDataOrHash($private_key, array('name' => $default_name . '.key', 'ttl' => time() + 60 * 10, 'viewPolicy' => $viewer->getPHID()));
         $public_key = PhabricatorAuthSSHPublicKey::newFromRawKey($public_key);
         $type = $public_key->getType();
         $body = $public_key->getBody();
         $key->setName($default_name)->setKeyType($type)->setKeyBody($body)->setKeyComment(pht('Generated'))->save();
         // NOTE: We're disabling workflow on submit so the download works. We're
         // disabling workflow on cancel so the page reloads, showing the new
         // key.
         return $this->newDialog()->setTitle(pht('Download Private Key'))->setDisableWorkflowOnCancel(true)->setDisableWorkflowOnSubmit(true)->setSubmitURI($file->getDownloadURI())->appendParagraph(pht('A keypair has been generated, and the public key has been ' . 'added as a recognized key. Use the button below to download ' . 'the private key.'))->appendParagraph(pht('After you download the private key, it will be destroyed. ' . 'You will not be able to retrieve it if you lose your copy.'))->addSubmitButton(pht('Download Private Key'))->addCancelButton($cancel_uri, pht('Done'));
     }
     try {
         PhabricatorSSHKeyGenerator::assertCanGenerateKeypair();
         return $this->newDialog()->setTitle(pht('Generate New Keypair'))->addHiddenInput('objectPHID', $key->getObject()->getPHID())->appendParagraph(pht('This workflow will generate a new SSH keypair, add the public ' . 'key, and let you download the private key.'))->appendParagraph(pht('Phabricator will not retain a copy of the private key.'))->addSubmitButton(pht('Generate New Keypair'))->addCancelButton($cancel_uri);
     } catch (Exception $ex) {
         return $this->newDialog()->setTitle(pht('Unable to Generate Keys'))->appendParagraph($ex->getMessage())->addCancelButton($cancel_uri);
     }
 }
开发者ID:pugong,项目名称:phabricator,代码行数:30,代码来源:PhabricatorAuthSSHKeyGenerateController.php

示例15: handleRequest

 public function handleRequest(AphrontRequest $request)
 {
     $viewer = $request->getUser();
     $file = PhabricatorFile::initializeNewFile();
     $e_file = true;
     $errors = array();
     if ($request->isFormPost()) {
         $view_policy = $request->getStr('viewPolicy');
         if (!$request->getFileExists('file')) {
             $e_file = pht('Required');
             $errors[] = pht('You must select a file to upload.');
         } else {
             $file = PhabricatorFile::newFromPHPUpload(idx($_FILES, 'file'), array('name' => $request->getStr('name'), 'authorPHID' => $viewer->getPHID(), 'viewPolicy' => $view_policy, 'isExplicitUpload' => true));
         }
         if (!$errors) {
             return id(new AphrontRedirectResponse())->setURI($file->getInfoURI());
         }
         $file->setViewPolicy($view_policy);
     }
     $support_id = celerity_generate_unique_node_id();
     $instructions = id(new AphrontFormMarkupControl())->setControlID($support_id)->setControlStyle('display: none')->setValue(hsprintf('<br /><br /><strong>%s</strong> %s<br /><br />', pht('Drag and Drop:'), pht('You can also upload files by dragging and dropping them from your ' . 'desktop onto this page or the Phabricator home page.')));
     $policies = id(new PhabricatorPolicyQuery())->setViewer($viewer)->setObject($file)->execute();
     $form = id(new AphrontFormView())->setUser($viewer)->setEncType('multipart/form-data')->appendChild(id(new AphrontFormFileControl())->setLabel(pht('File'))->setName('file')->setError($e_file))->appendChild(id(new AphrontFormTextControl())->setLabel(pht('Name'))->setName('name')->setValue($request->getStr('name')))->appendChild(id(new AphrontFormPolicyControl())->setUser($viewer)->setCapability(PhabricatorPolicyCapability::CAN_VIEW)->setPolicyObject($file)->setPolicies($policies)->setName('viewPolicy'))->appendChild(id(new AphrontFormSubmitControl())->setValue(pht('Upload'))->addCancelButton('/file/'))->appendChild($instructions);
     $crumbs = $this->buildApplicationCrumbs();
     $crumbs->addTextCrumb(pht('Upload'), $request->getRequestURI());
     $crumbs->setBorder(true);
     $title = pht('Upload File');
     $global_upload = id(new PhabricatorGlobalUploadTargetView())->setUser($viewer)->setShowIfSupportedID($support_id);
     $form_box = id(new PHUIObjectBoxView())->setHeaderText(pht('File'))->setFormErrors($errors)->setBackground(PHUIObjectBoxView::BLUE_PROPERTY)->setForm($form);
     $header = id(new PHUIHeaderView())->setHeader($title)->setHeaderIcon('fa-upload');
     $view = id(new PHUITwoColumnView())->setHeader($header)->setFooter(array($form_box, $global_upload));
     return $this->newPage()->setTitle($title)->setCrumbs($crumbs)->appendChild($view);
 }
开发者ID:rchicoli,项目名称:phabricator,代码行数:33,代码来源:PhabricatorFileUploadController.php


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