本文整理汇总了PHP中head_key函数的典型用法代码示例。如果您正苦于以下问题:PHP head_key函数的具体用法?PHP head_key怎么用?PHP head_key使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了head_key函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: processRequest
public function processRequest()
{
$request = $this->getRequest();
$repository = id(new PhabricatorRepository())->load($this->id);
if (!$repository) {
return new Aphront404Response();
}
$views = array('basic' => 'Basics', 'tracking' => 'Tracking');
$this->repository = $repository;
if (!isset($views[$this->view])) {
$this->view = head_key($views);
}
$nav = new AphrontSideNavView();
foreach ($views as $view => $name) {
$nav->addNavItem(phutil_render_tag('a', array('class' => $view == $this->view ? 'aphront-side-nav-selected' : null, 'href' => '/repository/edit/' . $repository->getID() . '/' . $view . '/'), phutil_escape_html($name)));
}
$nav->appendChild($this->renderDaemonNotice());
$this->sideNav = $nav;
switch ($this->view) {
case 'basic':
return $this->processBasicRequest();
case 'tracking':
return $this->processTrackingRequest();
default:
throw new Exception("Unknown view.");
}
}
示例2: buildQueryFromSavedQuery
public function buildQueryFromSavedQuery(PhabricatorSavedQuery $saved)
{
$query = id(new PhabricatorMacroQuery())->needFiles(true)->withIDs($saved->getParameter('ids', array()))->withPHIDs($saved->getParameter('phids', array()))->withAuthorPHIDs($saved->getParameter('authorPHIDs', array()));
$status = $saved->getParameter('status');
$options = PhabricatorMacroQuery::getStatusOptions();
if (empty($options[$status])) {
$status = head_key($options);
}
$query->withStatus($status);
$names = $saved->getParameter('names', array());
if ($names) {
$query->withNames($names);
}
$like = $saved->getParameter('nameLike');
if (strlen($like)) {
$query->withNameLike($like);
}
$start = $this->parseDateTime($saved->getParameter('createdStart'));
$end = $this->parseDateTime($saved->getParameter('createdEnd'));
if ($start) {
$query->withDateCreatedAfter($start);
}
if ($end) {
$query->withDateCreatedBefore($end);
}
$color = $saved->getParameter('flagColor');
if (strlen($color)) {
$query->withFlagColor($color);
}
return $query;
}
示例3: buildBareRepository
protected function buildBareRepository($callsign)
{
$existing_repository = id(new PhabricatorRepositoryQuery())->withCallsigns(array($callsign))->setViewer(PhabricatorUser::getOmnipotentUser())->executeOne();
if ($existing_repository) {
$existing_repository->delete();
}
$data_dir = dirname(__FILE__) . '/data/';
$types = array('svn' => PhabricatorRepositoryType::REPOSITORY_TYPE_SVN, 'hg' => PhabricatorRepositoryType::REPOSITORY_TYPE_MERCURIAL, 'git' => PhabricatorRepositoryType::REPOSITORY_TYPE_GIT);
$hits = array();
foreach ($types as $type => $const) {
$path = $data_dir . $callsign . '.' . $type . '.tgz';
if (Filesystem::pathExists($path)) {
$hits[$const] = $path;
}
}
if (!$hits) {
throw new Exception("No test data for callsign '{$callsign}'. Expected an archive " . "like '{$callsign}.git.tgz' in '{$data_dir}'.");
}
if (count($hits) > 1) {
throw new Exception("Expected exactly one archive matching callsign '{$callsign}', " . "found too many: " . implode(', ', $hits));
}
$path = head($hits);
$vcs_type = head_key($hits);
$dir = PhutilDirectoryFixture::newFromArchive($path);
$local = new TempFile('.ignore');
$user = $this->generateNewTestUser();
$repo = PhabricatorRepository::initializeNewRepository($user)->setCallsign($callsign)->setName(pht('Test Repo "%s"', $callsign))->setVersionControlSystem($vcs_type)->setDetail('local-path', dirname($local) . '/' . $callsign)->setDetail('remote-uri', 'file://' . $dir->getPath() . '/');
$this->didConstructRepository($repo);
$repo->save();
$repo->makeEphemeral();
// Keep the disk resources around until we exit.
$this->dirs[] = $dir;
$this->dirs[] = $local;
return $repo;
}
示例4: run
public function run()
{
$ids = $this->getArgument('task_id');
$message = $this->getArgument('message');
$status = strtolower($this->getArgument('status'));
if (!isset($status) || $status == '') {
$status = head_key($this->statusOptions);
}
if (isset($this->statusOptions[$status])) {
$status = $this->statusOptions[$status];
} else {
$options = array_keys($this->statusOptions);
$last = array_pop($options);
echo "Invalid status {$status}, valid options are " . implode(', ', $options) . ", or {$last}.\n";
return;
}
foreach ($ids as $id) {
if (!preg_match("/^T?\\d+\$/", $id)) {
echo "Invalid Task ID: {$id}.\n";
return 1;
}
$id = ltrim($id, 'T');
$result = $this->closeTask($id, $status, $message);
$status_options = array_flip($this->statusOptions);
$current_status = $status_options[$status];
if ($result) {
echo "T{$id}'s status is now set to {$current_status}.\n";
} else {
echo "T{$id} is already set to {$current_status}.\n";
}
}
return 0;
}
示例5: processRequest
public function processRequest()
{
$request = $this->getRequest();
$user = $request->getUser();
$content_type_map = HeraldContentTypeConfig::getContentTypeMap();
if (empty($content_type_map[$this->contentType])) {
$this->contentType = head_key($content_type_map);
}
$rule_type_map = HeraldRuleTypeConfig::getRuleTypeMap();
if (empty($rule_type_map[$this->ruleType])) {
$this->ruleType = HeraldRuleTypeConfig::RULE_TYPE_PERSONAL;
}
// Reorder array to put "personal" first.
$rule_type_map = array_select_keys($rule_type_map, array(HeraldRuleTypeConfig::RULE_TYPE_PERSONAL)) + $rule_type_map;
$captions = array(HeraldRuleTypeConfig::RULE_TYPE_PERSONAL => 'Personal rules notify you about events. You own them, but they can ' . 'only affect you.', HeraldRuleTypeConfig::RULE_TYPE_GLOBAL => 'Global rules notify anyone about events. No one owns them, and ' . 'anyone can edit them. Usually, Global rules are used to notify ' . 'mailing lists.');
$radio = id(new AphrontFormRadioButtonControl())->setLabel('Type')->setName('rule_type')->setValue($this->ruleType);
foreach ($rule_type_map as $value => $name) {
$radio->addButton($value, $name, idx($captions, $value));
}
$form = id(new AphrontFormView())->setUser($user)->setAction('/herald/rule/')->appendChild(id(new AphrontFormSelectControl())->setLabel('New rule for')->setName('content_type')->setValue($this->contentType)->setOptions($content_type_map))->appendChild($radio)->appendChild(id(new AphrontFormSubmitControl())->setValue('Create Rule')->addCancelButton('/herald/view/' . $this->contentType . '/'));
$panel = new AphrontPanelView();
$panel->setHeader('Create New Herald Rule');
$panel->setWidth(AphrontPanelView::WIDTH_FULL);
$panel->appendChild($form);
$nav = $this->renderNav();
$nav->selectFilter('new');
$nav->appendChild($panel);
return $this->buildStandardPageResponse($nav, array('title' => 'Create Herald Rule'));
}
示例6: handleRequest
public function handleRequest(AphrontRequest $request)
{
$id = $request->getURIData('class');
$classes = id(new PhutilSymbolLoader())->setAncestorClass('PhabricatorUIExample')->loadObjects();
$classes = msort($classes, 'getName');
$nav = new AphrontSideNavFilterView();
$nav->setBaseURI(new PhutilURI($this->getApplicationURI('view/')));
foreach ($classes as $class => $obj) {
$name = $obj->getName();
$nav->addFilter($class, $name);
}
$selected = $nav->selectFilter($id, head_key($classes));
$example = $classes[$selected];
$example->setRequest($this->getRequest());
$result = $example->renderExample();
if ($result instanceof AphrontResponse) {
// This allows examples to generate dialogs, etc., for demonstration.
return $result;
}
require_celerity_resource('phabricator-ui-example-css');
$crumbs = $this->buildApplicationCrumbs();
$crumbs->addTextCrumb($example->getName());
$note = id(new PHUIInfoView())->setTitle(pht('%s (%s)', $example->getName(), get_class($example)))->appendChild($example->getDescription())->setSeverity(PHUIInfoView::SEVERITY_NODATA);
$nav->appendChild(array($crumbs, $note, $result));
return $this->buildApplicationPage($nav, array('title' => $example->getName()));
}
示例7: processRequest
public function processRequest()
{
$classes = id(new PhutilSymbolLoader())->setAncestorClass('PhabricatorUIExample')->loadObjects();
$classes = msort($classes, 'getName');
$nav = new AphrontSideNavFilterView();
$nav->setBaseURI(new PhutilURI($this->getApplicationURI('view/')));
foreach ($classes as $class => $obj) {
$name = $obj->getName();
$nav->addFilter($class, $name);
}
$selected = $nav->selectFilter($this->class, head_key($classes));
$example = $classes[$selected];
$example->setRequest($this->getRequest());
$result = $example->renderExample();
if ($result instanceof AphrontResponse) {
// This allows examples to generate dialogs, etc., for demonstration.
return $result;
}
require_celerity_resource('phabricator-ui-example-css');
$crumbs = $this->buildApplicationCrumbs();
$crumbs->addTextCrumb($example->getName());
$header = id(new PHUIHeaderView())->setHeader(pht('%s (%s)', $example->getName(), get_class($example)))->setSubheader($example->getDescription())->setNoBackground(true);
$nav->appendChild(array($crumbs, $header, phutil_tag('br'), $result));
return $this->buildApplicationPage($nav, array('title' => $example->getName()));
}
示例8: processRequest
public function processRequest()
{
$classes = id(new PhutilSymbolLoader())->setAncestorClass('PhabricatorUIExample')->selectAndLoadSymbols();
$classes = ipull($classes, 'name', 'name');
$selected = null;
foreach ($classes as $class => $ignored) {
$classes[$class] = newv($class, array());
if ($this->class == $classes[$class]->getName()) {
$selected = $class;
}
}
if (!$selected) {
$selected = head_key($classes);
}
$nav = new AphrontSideNavView();
foreach ($classes as $class => $obj) {
$name = $obj->getName();
$nav->addNavItem(phutil_render_tag('a', array('href' => '/uiexample/view/' . $name . '/', 'class' => $selected == $class ? 'aphront-side-nav-selected' : null), phutil_escape_html($obj->getName())));
}
require_celerity_resource('phabricator-ui-example-css');
$example = $classes[$selected];
$example->setRequest($this->getRequest());
$nav->appendChild('<div class="phabricator-ui-example-header">' . '<h1 class="phabricator-ui-example-name">' . phutil_escape_html($example->getName()) . ' (' . get_class($example) . ')' . '</h1>' . '<p class="phabricator-ui-example-description">' . $example->getDescription() . '</p>' . '</div>');
$nav->appendChild($example->renderExample());
return $this->buildStandardPageResponse($nav, array('title' => 'UI Example'));
}
示例9: processRequest
public function processRequest()
{
$classes = id(new PhutilSymbolLoader())->setAncestorClass('PhabricatorUIExample')->setConcreteOnly(true)->selectAndLoadSymbols();
$classes = ipull($classes, 'name', 'name');
foreach ($classes as $class => $ignored) {
$classes[$class] = newv($class, array());
}
$classes = msort($classes, 'getName');
$nav = new AphrontSideNavFilterView();
$nav->setBaseURI(new PhutilURI($this->getApplicationURI('view/')));
foreach ($classes as $class => $obj) {
$name = $obj->getName();
$nav->addFilter($class, $name);
}
$selected = $nav->selectFilter($this->class, head_key($classes));
require_celerity_resource('phabricator-ui-example-css');
$example = $classes[$selected];
$example->setRequest($this->getRequest());
$result = $example->renderExample();
if ($result instanceof AphrontResponse) {
// This allows examples to generate dialogs, etc., for demonstration.
return $result;
}
$nav->appendChild('<div class="phabricator-ui-example-header">' . '<h1 class="phabricator-ui-example-name">' . phutil_escape_html($example->getName()) . ' (' . get_class($example) . ')' . '</h1>' . '<p class="phabricator-ui-example-description">' . $example->getDescription() . '</p>' . '</div>');
$nav->appendChild($result);
return $this->buildApplicationPage($nav, array('title' => 'UI Example', 'device' => true));
}
示例10: render
public function render(AphrontRequest $request)
{
$user = $request->getUser();
$plugins = $this->getEnabledPlugins();
foreach ($plugins as $plugin) {
$plugin->setRequest($request);
$plugin->willShutdown();
}
foreach ($plugins as $plugin) {
$plugin->didShutdown();
}
foreach ($plugins as $plugin) {
$plugin->setData($plugin->generateData());
}
$selected = $user->getConsoleTab();
$visible = $user->getConsoleVisible();
if (!isset($plugins[$selected])) {
$selected = head_key($plugins);
}
$tabs = array();
foreach ($plugins as $key => $plugin) {
$tabs[$key] = array('name' => $plugin->getName(), 'panel' => $plugin->render());
}
$tabs_markup = array();
$panel_markup = array();
foreach ($tabs as $key => $data) {
$is_selected = $key == $selected;
if ($is_selected) {
$style = null;
$tabclass = 'dark-console-tab-selected';
} else {
$style = 'display: none;';
$tabclass = null;
}
$tabs_markup[] = javelin_render_tag('a', array('class' => "dark-console-tab {$tabclass}", 'sigil' => 'dark-console-tab', 'id' => 'dark-console-tab-' . $key), (string) $data['name']);
$panel_markup[] = javelin_render_tag('div', array('class' => 'dark-console-panel dark-console-panel-' . $key, 'style' => $style, 'sigil' => 'dark-console-panel'), (string) $data['panel']);
}
$console = javelin_render_tag('table', array('class' => 'dark-console', 'sigil' => 'dark-console', 'style' => $visible ? '' : 'display: none;'), '<tr>' . '<th class="dark-console-tabs">' . implode("\n", $tabs_markup) . '</th>' . '<td>' . implode("\n", $panel_markup) . '</td>' . '</tr>');
if (!empty($_COOKIE['phsid'])) {
$console = str_replace($_COOKIE['phsid'], phutil_escape_html('<session-key>'), $console);
}
if ($request->isAjax()) {
// for ajax this HTML gets updated on the client
$request_history = null;
} else {
$request_table_header = '<div class="dark-console-panel-request-log-separator"></div>';
$rows = array();
$table = new AphrontTableView($rows);
$table->setHeaders(array('Sequence', 'Type', 'URI'));
$table->setColumnClasses(array('', '', 'wide'));
$request_table = $request_table_header . $table->render();
$request_history = javelin_render_tag('table', array('class' => 'dark-console dark-console-request-log', 'sigil' => 'dark-console-request-log', 'style' => $visible ? '' : 'display: none;'), '<tr>' . '<th class="dark-console-tabs">' . javelin_render_tag('a', array('class' => 'dark-console-tab dark-console-tab-selected'), 'Request Log') . '</th>' . '<td>' . javelin_render_tag('div', array('class' => 'dark-console-panel dark-console-panel-RequestLog'), $request_table) . '</td>' . '</tr>');
}
return "\n\n\n\n" . $console . $request_history . "\n\n\n\n";
}
示例11: handleRequest
public function handleRequest(AphrontRequest $request)
{
$viewer = $request->getViewer();
$color_map = PhabricatorFilesComposeIconBuiltinFile::getAllColors();
$icon_map = $this->getIconMap();
if ($request->isFormPost()) {
$project_phid = $request->getStr('projectPHID');
if ($project_phid) {
$project = id(new PhabricatorProjectQuery())->setViewer($viewer)->withPHIDs(array($project_phid))->requireCapabilities(array(PhabricatorPolicyCapability::CAN_VIEW, PhabricatorPolicyCapability::CAN_EDIT))->executeOne();
if (!$project) {
return new Aphront404Response();
}
}
$icon = $request->getStr('icon');
$color = $request->getStr('color');
$composer = id(new PhabricatorFilesComposeIconBuiltinFile())->setIcon($icon)->setColor($color);
$data = $composer->loadBuiltinFileData();
$file = PhabricatorFile::buildFromFileDataOrHash($data, array('name' => $composer->getBuiltinDisplayName(), 'profile' => true, 'canCDN' => true));
if ($project_phid) {
$edit_uri = '/project/history/' . $project->getID() . '/';
$xactions = array();
$xactions[] = id(new PhabricatorProjectTransaction())->setTransactionType(PhabricatorProjectTransaction::TYPE_IMAGE)->setNewValue($file->getPHID());
$editor = id(new PhabricatorProjectTransactionEditor())->setActor($viewer)->setContentSourceFromRequest($request)->setContinueOnMissingFields(true)->setContinueOnNoEffect(true);
$editor->applyTransactions($project, $xactions);
return id(new AphrontRedirectResponse())->setURI($edit_uri);
} else {
$content = array('phid' => $file->getPHID());
return id(new AphrontAjaxResponse())->setContent($content);
}
}
$value_color = head_key($color_map);
$value_icon = head_key($icon_map);
require_celerity_resource('people-profile-css');
$buttons = array();
foreach ($color_map as $color => $info) {
$quip = idx($info, 'quip');
$buttons[] = javelin_tag('button', array('class' => 'grey profile-image-button', 'sigil' => 'has-tooltip compose-select-color', 'style' => 'margin: 0 8px 8px 0', 'meta' => array('color' => $color, 'tip' => $quip)), id(new PHUIIconView())->addClass('compose-background-' . $color));
}
$icons = array();
foreach ($icon_map as $icon => $spec) {
$quip = idx($spec, 'quip');
$icons[] = javelin_tag('button', array('class' => 'grey profile-image-button', 'sigil' => 'has-tooltip compose-select-icon', 'style' => 'margin: 0 8px 8px 0', 'meta' => array('icon' => $icon, 'tip' => $quip)), id(new PHUIIconView())->setIconFont($icon)->addClass('compose-icon-bg'));
}
$dialog_id = celerity_generate_unique_node_id();
$color_input_id = celerity_generate_unique_node_id();
$icon_input_id = celerity_generate_unique_node_id();
$preview_id = celerity_generate_unique_node_id();
$preview = id(new PHUIIconView())->setID($preview_id)->addClass('compose-background-' . $value_color)->setIconFont($value_icon)->addClass('compose-icon-bg');
$color_input = javelin_tag('input', array('type' => 'hidden', 'name' => 'color', 'value' => $value_color, 'id' => $color_input_id));
$icon_input = javelin_tag('input', array('type' => 'hidden', 'name' => 'icon', 'value' => $value_icon, 'id' => $icon_input_id));
Javelin::initBehavior('phabricator-tooltips');
Javelin::initBehavior('icon-composer', array('dialogID' => $dialog_id, 'colorInputID' => $color_input_id, 'iconInputID' => $icon_input_id, 'previewID' => $preview_id, 'defaultColor' => $value_color, 'defaultIcon' => $value_icon));
$dialog = id(new AphrontDialogView())->setUser($viewer)->setFormID($dialog_id)->setClass('compose-dialog')->setTitle(pht('Compose Image'))->appendChild(phutil_tag('div', array('class' => 'compose-header'), pht('Choose Background Color')))->appendChild($buttons)->appendChild(phutil_tag('div', array('class' => 'compose-header'), pht('Choose Icon')))->appendChild($icons)->appendChild(phutil_tag('div', array('class' => 'compose-header'), pht('Preview')))->appendChild($preview)->appendChild($color_input)->appendChild($icon_input)->addCancelButton('/')->addSubmitButton(pht('Save Image'));
return id(new AphrontDialogResponse())->setDialog($dialog);
}
示例12: render
public function render()
{
if (!$this->mock) {
throw new Exception('Call setMock() before render()!');
}
$mock = $this->mock;
require_celerity_resource('javelin-behavior-pholio-mock-view');
$images = array();
$panel_id = celerity_generate_unique_node_id();
$viewport_id = celerity_generate_unique_node_id();
$ids = mpull($mock->getImages(), 'getID');
if ($this->imageID && isset($ids[$this->imageID])) {
$selected_id = $this->imageID;
} else {
$selected_id = head_key($ids);
}
// TODO: We could maybe do a better job with tailoring this, which is the
// image shown on the review stage.
$nonimage_uri = celerity_get_resource_uri('rsrc/image/icon/fatcow/thumbnails/default.p100.png');
$engine = id(new PhabricatorMarkupEngine())->setViewer($this->getUser());
foreach ($mock->getAllImages() as $image) {
$engine->addObject($image, 'default');
}
$engine->process();
$current_set = 0;
foreach ($mock->getAllImages() as $image) {
$file = $image->getFile();
$metadata = $file->getMetadata();
$x = idx($metadata, PhabricatorFile::METADATA_IMAGE_WIDTH);
$y = idx($metadata, PhabricatorFile::METADATA_IMAGE_HEIGHT);
$is_obs = (bool) $image->getIsObsolete();
if (!$is_obs) {
$current_set++;
}
$history_uri = '/pholio/image/history/' . $image->getID() . '/';
$images[] = array('id' => $image->getID(), 'fullURI' => $file->getBestURI(), 'stageURI' => $file->isViewableImage() ? $file->getBestURI() : $nonimage_uri, 'pageURI' => $this->getImagePageURI($image, $mock), 'downloadURI' => $file->getDownloadURI(), 'historyURI' => $history_uri, 'width' => $x, 'height' => $y, 'title' => $image->getName(), 'descriptionMarkup' => $engine->getOutput($image, 'default'), 'isObsolete' => (bool) $image->getIsObsolete(), 'isImage' => $file->isViewableImage(), 'isViewable' => $file->isViewableInBrowser());
}
$navsequence = array();
foreach ($mock->getImages() as $image) {
$navsequence[] = $image->getID();
}
$full_icon = array(javelin_tag('span', array('aural' => true), pht('View Raw File')), id(new PHUIIconView())->setIconFont('fa-file-image-o'));
$download_icon = array(javelin_tag('span', array('aural' => true), pht('Download File')), id(new PHUIIconView())->setIconFont('fa-download'));
$login_uri = id(new PhutilURI('/login/'))->setQueryParam('next', (string) $this->getRequestURI());
$config = array('mockID' => $mock->getID(), 'panelID' => $panel_id, 'viewportID' => $viewport_id, 'commentFormID' => $this->getCommentFormID(), 'images' => $images, 'selectedID' => $selected_id, 'loggedIn' => $this->getUser()->isLoggedIn(), 'logInLink' => (string) $login_uri, 'navsequence' => $navsequence, 'fullIcon' => hsprintf('%s', $full_icon), 'downloadIcon' => hsprintf('%s', $download_icon), 'currentSetSize' => $current_set);
Javelin::initBehavior('pholio-mock-view', $config);
$mockview = '';
$mock_wrapper = javelin_tag('div', array('id' => $viewport_id, 'sigil' => 'mock-viewport', 'class' => 'pholio-mock-image-viewport'), '');
$image_header = javelin_tag('div', array('id' => 'mock-image-header', 'class' => 'pholio-mock-image-header'), '');
$mock_wrapper = javelin_tag('div', array('id' => $panel_id, 'sigil' => 'mock-panel touchable', 'class' => 'pholio-mock-image-panel'), array($image_header, $mock_wrapper));
$inline_comments_holder = javelin_tag('div', array('id' => 'mock-image-description', 'sigil' => 'mock-image-description', 'class' => 'mock-image-description'), '');
$mockview[] = phutil_tag('div', array('class' => 'pholio-mock-image-container', 'id' => 'pholio-mock-image-container'), array($mock_wrapper, $inline_comments_holder));
return $mockview;
}
示例13: applyAssign
protected function applyAssign(array $phids)
{
$adapter = $this->getAdapter();
$object = $adapter->getObject();
$current = array($object->getOwnerPHID());
$allowed_types = array(PhabricatorPeopleUserPHIDType::TYPECONST);
$targets = $this->loadStandardTargets($phids, $allowed_types, $current);
if (!$targets) {
return;
}
$phid = head_key($targets);
$xaction = $adapter->newTransaction()->setTransactionType(ManiphestTransaction::TYPE_OWNER)->setNewValue($phid);
$adapter->queueTransaction($xaction);
$this->logEffect(self::DO_ASSIGN, array($phid));
}
示例14: handleRequest
public function handleRequest(AphrontRequest $request)
{
$response = $this->loadDiffusionContext();
if ($response) {
return $response;
}
$viewer = $this->getViewer();
$drequest = $this->getDiffusionRequest();
$repository = $drequest->getRepository();
$panels = DiffusionRepositoryManagementPanel::getAllPanels();
foreach ($panels as $key => $panel) {
$panel->setViewer($viewer)->setRepository($repository)->setController($this);
if (!$panel->shouldEnableForRepository($repository)) {
unset($panels[$key]);
continue;
}
}
$selected = $request->getURIData('panel');
if (!strlen($selected)) {
$selected = head_key($panels);
}
if (empty($panels[$selected])) {
return new Aphront404Response();
}
$nav = $this->renderSideNav($repository, $panels, $selected);
$this->navigation = $nav;
$panel = $panels[$selected];
$content = $panel->buildManagementPanelContent();
$title = array($panel->getManagementPanelLabel(), $repository->getDisplayName());
$crumbs = $this->buildApplicationCrumbs();
$crumbs->addTextCrumb($panel->getManagementPanelLabel());
$crumbs->setBorder(true);
$header_text = pht('%s: %s', $repository->getDisplayName(), $panel->getManagementPanelLabel());
$header = id(new PHUIHeaderView())->setHeader($header_text)->setHeaderIcon('fa-pencil');
if ($repository->isTracked()) {
$header->setStatus('fa-check', 'bluegrey', pht('Active'));
} else {
$header->setStatus('fa-ban', 'dark', pht('Inactive'));
}
$header->addActionLink(id(new PHUIButtonView())->setTag('a')->setText(pht('View Repository'))->setHref($repository->getURI())->setIcon('fa-code'));
$view = id(new PHUITwoColumnView())->setHeader($header)->setNavigation($nav)->setMainColumn($content);
$curtain = $panel->buildManagementPanelCurtain();
if ($curtain) {
$view->setCurtain($curtain);
}
return $this->newPage()->setTitle($title)->setCrumbs($crumbs)->appendChild($view);
}
示例15: processRequest
public function processRequest()
{
$request = $this->getRequest();
$viewer = $request->getUser();
$colors = array('red' => pht('Verbillion'), 'orange' => pht('Navel Orange'), 'yellow' => pht('Prim Goldenrod'), 'green' => pht('Lustrous Verdant'), 'blue' => pht('Tropical Deep'), 'sky' => pht('Wide Open Sky'), 'indigo' => pht('Pleated Khaki'), 'violet' => pht('Aged Merlot'), 'charcoal' => pht('Gemstone'), 'backdrop' => pht('Driven Snow'));
$manifest = PHUIIconView::getSheetManifest(PHUIIconView::SPRITE_PROJECTS);
if ($request->isFormPost()) {
$icon = $request->getStr('icon');
$color = $request->getStr('color');
if (isset($colors[$color]) && isset($manifest['projects-' . $icon])) {
$root = dirname(phutil_get_library_root('phabricator'));
$icon_file = $root . '/resources/sprite/projects_1x/' . $icon . '.png';
$icon_data = Filesystem::readFile($icon_file);
$data = $this->composeImage($color, $icon_data);
$file = PhabricatorFile::buildFromFileDataOrHash($data, array('name' => 'project.png', 'canCDN' => true));
$content = array('phid' => $file->getPHID());
return id(new AphrontAjaxResponse())->setContent($content);
}
}
$value_color = head_key($colors);
$value_icon = head_key($manifest);
$value_icon = substr($value_icon, strlen('projects-'));
require_celerity_resource('people-profile-css');
$buttons = array();
foreach ($colors as $color => $name) {
$buttons[] = javelin_tag('button', array('class' => 'grey profile-image-button', 'sigil' => 'has-tooltip compose-select-color', 'style' => 'margin: 0 8px 8px 0', 'meta' => array('color' => $color, 'tip' => $name)), id(new PHUIIconView())->addClass('compose-background-' . $color));
}
$icons = array();
$icon_quips = array('8ball' => pht('Take a Risk'), 'alien' => pht('Foreign Interface'), 'announce' => pht('Louder is Better'), 'art' => pht('Unique Snowflake'), 'award' => pht('Shooting Star'), 'bacon' => pht('Healthy Vegetables'), 'bandaid' => pht('Durable Infrastructure'), 'beer' => pht('Healthy Vegetable Juice'), 'bomb' => pht('Imminent Success'), 'briefcase' => pht('Adventure Pack'), 'bug' => pht('Costumed Egg'), 'calendar' => pht('Everyone Loves Meetings'), 'cloud' => pht('Water Cycle'), 'coffee' => pht('Half-Whip Nonfat Soy Latte'), 'creditcard' => pht('Expense It'), 'death' => pht('Calcium Promotes Bone Health'), 'desktop' => pht('Magical Portal'), 'dropbox' => pht('Cardboard Box'), 'education' => pht('Debt'), 'experimental' => pht('CAUTION: Dangerous Chemicals'), 'facebook' => pht('Popular Social Network'), 'facility' => pht('Pollution Solves Problems'), 'film' => pht('Actual Physical Film'), 'forked' => pht('You Can\'t Eat Soup'), 'games' => pht('Serious Business'), 'ghost' => pht('Haunted'), 'gift' => pht('Surprise!'), 'globe' => pht('Scanner Sweep'), 'golf' => pht('Business Meeting'), 'heart' => pht('Undergoing a Major Surgery'), 'intergalactic' => pht('Jupiter'), 'lock' => pht('Extremely Secret'), 'mail' => pht('Oragami'), 'martini' => pht('Healthy Olive Drink'), 'medical' => pht('Medic!'), 'mobile' => pht('Cellular Telephone'), 'music' => pht("♫"), 'news' => pht('Actual Physical Newspaper'), 'orgchart' => pht('It\'s Good to be King'), 'peoples' => pht('Angel and Devil'), 'piechart' => pht('Actual Physical Pie'), 'poison' => pht('Healthy Bone Juice'), 'putabirdonit' => pht('Put a Bird On It'), 'radiate' => pht('Radiant Beauty'), 'savings' => pht('Oink Oink'), 'search' => pht('Sleuthing'), 'shield' => pht('Royal Crest'), 'speed' => pht('Slow and Steady'), 'sprint' => pht('Fire Exit'), 'star' => pht('The More You Know'), 'storage' => pht('Stack of Pancakes'), 'tablet' => pht('Cellular Telephone For Giants'), 'travel' => pht('Pretty Clearly an Airplane'), 'twitter' => pht('Bird Stencil'), 'warning' => pht('No Caution Required, Everything Looks Safe'), 'whale' => pht('Friendly Walrus'));
foreach ($manifest as $icon => $spec) {
$icon = substr($icon, strlen('projects-'));
$icons[] = javelin_tag('button', array('class' => 'grey profile-image-button', 'sigil' => 'has-tooltip compose-select-icon', 'style' => 'margin: 0 8px 8px 0', 'meta' => array('icon' => $icon, 'tip' => idx($icon_quips, $icon, $icon))), id(new PHUIIconView())->setSpriteIcon($icon)->setSpriteSheet(PHUIIconView::SPRITE_PROJECTS));
}
$dialog_id = celerity_generate_unique_node_id();
$color_input_id = celerity_generate_unique_node_id();
$icon_input_id = celerity_generate_unique_node_id();
$preview_id = celerity_generate_unique_node_id();
$preview = id(new PHUIIconView())->setID($preview_id)->addClass('compose-background-' . $value_color)->setSpriteIcon($value_icon)->setSpriteSheet(PHUIIconView::SPRITE_PROJECTS);
$color_input = javelin_tag('input', array('type' => 'hidden', 'name' => 'color', 'value' => $value_color, 'id' => $color_input_id));
$icon_input = javelin_tag('input', array('type' => 'hidden', 'name' => 'icon', 'value' => $value_icon, 'id' => $icon_input_id));
Javelin::initBehavior('phabricator-tooltips');
Javelin::initBehavior('icon-composer', array('dialogID' => $dialog_id, 'colorInputID' => $color_input_id, 'iconInputID' => $icon_input_id, 'previewID' => $preview_id, 'defaultColor' => $value_color, 'defaultIcon' => $value_icon));
$dialog = id(new AphrontDialogView())->setUser($viewer)->setFormID($dialog_id)->setClass('compose-dialog')->setTitle(pht('Compose Image'))->appendChild(phutil_tag('div', array('class' => 'compose-header'), pht('Choose Background Color')))->appendChild($buttons)->appendChild(phutil_tag('div', array('class' => 'compose-header'), pht('Choose Icon')))->appendChild($icons)->appendChild(phutil_tag('div', array('class' => 'compose-header'), pht('Preview')))->appendChild($preview)->appendChild($color_input)->appendChild($icon_input)->addCancelButton('/')->addSubmitButton(pht('Save Image'));
return id(new AphrontDialogResponse())->setDialog($dialog);
}