code
stringlengths 15
9.96M
| docstring
stringlengths 1
10.1k
| func_name
stringlengths 1
124
| language
stringclasses 1
value | repo
stringlengths 7
63
| path
stringlengths 6
186
| url
stringlengths 50
236
| license
stringclasses 4
values |
---|---|---|---|---|---|---|---|
public static function getTaskPriorityName($priority) {
return idx(self::getTaskPriorityMap(), $priority, $priority);
} | Retrieve the full name of the priority level provided.
@param int $priority A priority level.
@return string The priority name if the level is a valid one. | getTaskPriorityName | php | phorgeit/phorge | src/applications/maniphest/constants/ManiphestTaskPriority.php | https://github.com/phorgeit/phorge/blob/master/src/applications/maniphest/constants/ManiphestTaskPriority.php | Apache-2.0 |
public static function getTaskPriorityColor($priority) {
return idx(self::getColorMap(), $priority, 'black');
} | Retrieve the color of the priority level given
@param int $priority A priority level.
@return string The color of the priority if the level is valid,
or black if it is not. | getTaskPriorityColor | php | phorgeit/phorge | src/applications/maniphest/constants/ManiphestTaskPriority.php | https://github.com/phorgeit/phorge/blob/master/src/applications/maniphest/constants/ManiphestTaskPriority.php | Apache-2.0 |
private function validatePHIDList(array $phid_list, $phid_type, $field) {
$phid_groups = phid_group_by_type($phid_list);
unset($phid_groups[$phid_type]);
if (!empty($phid_groups)) {
throw id(new ConduitException('ERR-INVALID-PARAMETER'))
->setErrorDescription(
pht(
'One or more PHIDs were invalid for %s.',
$field));
}
return true;
} | NOTE: This is a temporary stop gap since its easy to make malformed tasks.
Long-term, the values set in @{method:defineParamTypes} will be used to
validate data implicitly within the larger Conduit application.
TODO: Remove this in favor of generalized Conduit hotness. | validatePHIDList | php | phorgeit/phorge | src/applications/maniphest/conduit/ManiphestConduitAPIMethod.php | https://github.com/phorgeit/phorge/blob/master/src/applications/maniphest/conduit/ManiphestConduitAPIMethod.php | Apache-2.0 |
private function getValueForPoints($value) {
// The Point can be various types also thanks to Conduit API
// like integers, floats, null, and strings of course.
// Everything meaningful must be printable as a string.
$is_empty = phutil_string_cast($value) === '';
if ($is_empty) {
$value = null;
}
if ($value !== null) {
$value = (double)$value;
}
return $value;
} | Normalize your Story Points from generic stuff to double or null.
@param mixed $value Your raw Story Points
@return double|null | getValueForPoints | php | phorgeit/phorge | src/applications/maniphest/xaction/ManiphestTaskPointsTransaction.php | https://github.com/phorgeit/phorge/blob/master/src/applications/maniphest/xaction/ManiphestTaskPointsTransaction.php | Apache-2.0 |
private function renderReportFilters(array $tokens, $has_window) {
$request = $this->getRequest();
$viewer = $request->getUser();
$form = id(new AphrontFormView())
->setUser($viewer)
->appendControl(
id(new AphrontFormTokenizerControl())
->setDatasource(new PhabricatorProjectDatasource())
->setLabel(pht('Project'))
->setLimit(1)
->setName('set_project')
// TODO: This is silly, but this is Maniphest reports.
->setValue(mpull($tokens, 'getPHID')));
if ($has_window) {
list($window_str, $ignored, $window_error) = $this->getWindow();
$form
->appendChild(
id(new AphrontFormTextControl())
->setLabel(pht('Recently Means'))
->setName('set_window')
->setCaption(
pht('Configure the cutoff for the "Recently Closed" column.'))
->setValue($window_str)
->setError($window_error));
}
$form
->appendChild(
id(new AphrontFormSubmitControl())
->setValue(pht('Filter By Project')));
$filter = new AphrontListFilterView();
$filter->appendChild($form);
return $filter;
} | @param array $tokens
@param bool $has_window
@return AphrontListFilterView | renderReportFilters | php | phorgeit/phorge | src/applications/maniphest/controller/ManiphestReportController.php | https://github.com/phorgeit/phorge/blob/master/src/applications/maniphest/controller/ManiphestReportController.php | Apache-2.0 |
private function getAveragePriority() {
// TODO: This is sort of a hard-code for the default "normal" status.
// When reports are more powerful, this should be made more general.
return 50;
} | @return int 50 | getAveragePriority | php | phorgeit/phorge | src/applications/maniphest/controller/ManiphestReportController.php | https://github.com/phorgeit/phorge/blob/master/src/applications/maniphest/controller/ManiphestReportController.php | Apache-2.0 |
private function renderOldest(array $tasks) {
assert_instances_of($tasks, 'ManiphestTask');
$oldest = null;
foreach ($tasks as $id => $task) {
if (($oldest === null) ||
($task->getDateCreated() < $tasks[$oldest]->getDateCreated())) {
$oldest = $id;
}
}
if ($oldest === null) {
return array('-', 0);
}
$oldest = $tasks[$oldest];
$raw_age = (time() - $oldest->getDateCreated());
$age = number_format($raw_age / (24 * 60 * 60)).' d';
$link = javelin_tag(
'a',
array(
'href' => '/T'.$oldest->getID(),
'sigil' => 'has-tooltip',
'meta' => array(
'tip' => 'T'.$oldest->getID().': '.$oldest->getTitle(),
),
'target' => '_blank',
),
$age);
return array($link, $raw_age);
} | Render date of oldest open task per user or per project with a link.
Used on /maniphest/report/user/ and /maniphest/report/project/ URIs.
@return array<PhutilSafeHTML,int> HTML link markup and the timespan
(as epoch) since task creation | renderOldest | php | phorgeit/phorge | src/applications/maniphest/controller/ManiphestReportController.php | https://github.com/phorgeit/phorge/blob/master/src/applications/maniphest/controller/ManiphestReportController.php | Apache-2.0 |
private function getIncludeOpenGraphMetadata(PhabricatorUser $viewer,
$object) {
// Don't waste time adding OpenGraph metadata for logged-in users
if ($viewer->getIsStandardUser()) {
return false;
}
// Include OpenGraph tags only for public objects
return $object->getViewPolicy() === PhabricatorPolicies::POLICY_PUBLIC;
} | Whether the page should include Open Graph metadata tags
@param PhabricatorUser $viewer Viewer of the object
@param object $object
@return bool True if the page should serve Open Graph metadata tags | getIncludeOpenGraphMetadata | php | phorgeit/phorge | src/applications/maniphest/controller/ManiphestTaskDetailController.php | https://github.com/phorgeit/phorge/blob/master/src/applications/maniphest/controller/ManiphestTaskDetailController.php | Apache-2.0 |
private function getOpenGraphProtocolMetadataValues($task) {
$viewer = $this->getViewer();
$v = [];
$v['og:site_name'] = PlatformSymbols::getPlatformServerName();
$v['og:type'] = 'object';
$v['og:url'] = PhabricatorEnv::getProductionURI($task->getURI());
$v['og:title'] = $task->getMonogram().' '.$task->getTitle();
$desc = $task->getDescription();
if (phutil_nonempty_string($desc)) {
$v['og:description'] =
PhabricatorMarkupEngine::summarizeSentence($desc);
}
$v['og:image'] =
PhabricatorCustomLogoConfigType::getLogoURI($viewer);
$v['og:image:height'] = 64;
$v['og:image:width'] = 64;
return $v;
} | Get Open Graph Protocol metadata values
@param ManiphestTask $task
@return array Map of Open Graph property => value | getOpenGraphProtocolMetadataValues | php | phorgeit/phorge | src/applications/maniphest/controller/ManiphestTaskDetailController.php | https://github.com/phorgeit/phorge/blob/master/src/applications/maniphest/controller/ManiphestTaskDetailController.php | Apache-2.0 |
private function getIgnoreGroupedProjectPHIDs() {
// Maybe we should also exclude the "OPERATOR_NOT" PHIDs? It won't
// impact the results, but we might end up with a better query plan.
// Investigate this on real data? This is likely very rare.
$edge_types = array(
PhabricatorProjectObjectHasProjectEdgeType::EDGECONST,
);
$phids = array();
$phids[] = $this->getEdgeLogicValues(
$edge_types,
array(
PhabricatorQueryConstraint::OPERATOR_AND,
));
$any = $this->getEdgeLogicValues(
$edge_types,
array(
PhabricatorQueryConstraint::OPERATOR_OR,
));
if (count($any) == 1) {
$phids[] = $any;
}
return array_mergev($phids);
} | Return project PHIDs which we should ignore when grouping tasks by
project. For example, if a user issues a query like:
Tasks tagged with all projects: Frontend, Bugs
...then we don't show "Frontend" or "Bugs" groups in the result set, since
they're meaningless as all results are in both groups.
Similarly, for queries like:
Tasks tagged with any projects: Public Relations
...we ignore the single project, as every result is in that project. (In
the case that there are several "any" projects, we do not ignore them.)
@return list<string> Project PHIDs which should be ignored in query
construction. | getIgnoreGroupedProjectPHIDs | php | phorgeit/phorge | src/applications/maniphest/query/ManiphestTaskQuery.php | https://github.com/phorgeit/phorge/blob/master/src/applications/maniphest/query/ManiphestTaskQuery.php | Apache-2.0 |
public function setMailTags(array $tags) {
$this->setParam('mailtags', array_unique($tags));
return $this;
} | These tags are used to allow users to opt out of receiving certain types
of mail, like updates when a task's projects change.
@param list<string> $tags Tag constants.
@return $this | setMailTags | php | phorgeit/phorge | src/applications/metamta/storage/PhabricatorMetaMTAMail.php | https://github.com/phorgeit/phorge/blob/master/src/applications/metamta/storage/PhabricatorMetaMTAMail.php | Apache-2.0 |
public function setParentMessageID($id) {
$this->setParam('parent-message-id', $id);
return $this;
} | In Gmail, conversations will be broken if you reply to a thread and the
server sends back a response without referencing your Message-ID, even if
it references a Message-ID earlier in the thread. To avoid this, use the
parent email's message ID explicitly if it's available. This overwrites the
"In-Reply-To" and "References" headers we would otherwise generate. This
needs to be set whenever an action is triggered by an email message. See
T251 for more details.
@param string $id The "Message-ID" of the email which precedes this one.
@return $this | setParentMessageID | php | phorgeit/phorge | src/applications/metamta/storage/PhabricatorMetaMTAMail.php | https://github.com/phorgeit/phorge/blob/master/src/applications/metamta/storage/PhabricatorMetaMTAMail.php | Apache-2.0 |
public function setForceDelivery($force) {
$this->setParam('force', $force);
return $this;
} | Force delivery of a message, even if recipients have preferences which
would otherwise drop the message.
This is primarily intended to let users who don't want any email still
receive things like password resets.
@param bool $force True to force delivery despite user preferences.
@return $this | setForceDelivery | php | phorgeit/phorge | src/applications/metamta/storage/PhabricatorMetaMTAMail.php | https://github.com/phorgeit/phorge/blob/master/src/applications/metamta/storage/PhabricatorMetaMTAMail.php | Apache-2.0 |
public function setIsBulk($is_bulk) {
$this->setParam('is-bulk', $is_bulk);
return $this;
} | Flag that this is an auto-generated bulk message and should have bulk
headers added to it if appropriate. Broadly, this means some flavor of
"Precedence: bulk" or similar, but is implementation and configuration
dependent.
@param bool $is_bulk True if the mail is automated bulk mail.
@return $this | setIsBulk | php | phorgeit/phorge | src/applications/metamta/storage/PhabricatorMetaMTAMail.php | https://github.com/phorgeit/phorge/blob/master/src/applications/metamta/storage/PhabricatorMetaMTAMail.php | Apache-2.0 |
public function setThreadID($thread_id, $is_first_message = false) {
$this->setParam('thread-id', $thread_id);
$this->setParam('is-first-message', $is_first_message);
return $this;
} | Use this method to set an ID used for message threading. MetaMTA will
set appropriate headers (Message-ID, In-Reply-To, References and
Thread-Index) based on the capabilities of the underlying mailer.
@param string $thread_id Unique identifier, appropriate for use in a
Message-ID, In-Reply-To or References headers.
@param bool $is_first_message (optional) If true, indicates this is the
first message in the thread.
@return $this | setThreadID | php | phorgeit/phorge | src/applications/metamta/storage/PhabricatorMetaMTAMail.php | https://github.com/phorgeit/phorge/blob/master/src/applications/metamta/storage/PhabricatorMetaMTAMail.php | Apache-2.0 |
public function saveAndSend() {
return $this->save();
} | Save a newly created mail to the database. The mail will eventually be
delivered by the MetaMTA daemon.
@return $this | saveAndSend | php | phorgeit/phorge | src/applications/metamta/storage/PhabricatorMetaMTAMail.php | https://github.com/phorgeit/phorge/blob/master/src/applications/metamta/storage/PhabricatorMetaMTAMail.php | Apache-2.0 |
public function sendNow() {
if ($this->getStatus() != PhabricatorMailOutboundStatus::STATUS_QUEUE) {
throw new Exception(pht('Trying to send an already-sent mail!'));
}
$mailers = self::newMailers(
array(
'outbound' => true,
'media' => array(
$this->getMessageType(),
),
));
$try_mailers = $this->getParam('mailers.try');
if ($try_mailers) {
$mailers = mpull($mailers, null, 'getKey');
$mailers = array_select_keys($mailers, $try_mailers);
}
return $this->sendWithMailers($mailers);
} | Attempt to deliver an email immediately, in this process.
@return void | sendNow | php | phorgeit/phorge | src/applications/metamta/storage/PhabricatorMetaMTAMail.php | https://github.com/phorgeit/phorge/blob/master/src/applications/metamta/storage/PhabricatorMetaMTAMail.php | Apache-2.0 |
public function buildRecipientList() {
$actors = $this->loadAllActors();
$actors = $this->filterDeliverableActors($actors);
return mpull($actors, 'getPHID');
} | Get all of the recipients for this mail, after preference filters are
applied. This list has all objects to whom delivery will be attempted.
Note that this expands recipients into their members, because delivery
is never directly attempted to aggregate actors like projects.
@return list<string> A list of all recipients to whom delivery will be
attempted.
@task recipients | buildRecipientList | php | phorgeit/phorge | src/applications/metamta/storage/PhabricatorMetaMTAMail.php | https://github.com/phorgeit/phorge/blob/master/src/applications/metamta/storage/PhabricatorMetaMTAMail.php | Apache-2.0 |
public function expandRecipients(array $phids) {
if ($this->recipientExpansionMap === null) {
$all_phids = $this->getAllActorPHIDs();
$this->recipientExpansionMap = id(new PhabricatorMetaMTAMemberQuery())
->setViewer(PhabricatorUser::getOmnipotentUser())
->withPHIDs($all_phids)
->execute();
}
$results = array();
foreach ($phids as $phid) {
foreach ($this->recipientExpansionMap[$phid] as $recipient_phid) {
$results[$recipient_phid] = $recipient_phid;
}
}
return array_keys($results);
} | Expand a list of recipient PHIDs (possibly including aggregate recipients
like projects) into a deaggregated list of individual recipient PHIDs.
For example, this will expand project PHIDs into a list of the project's
members.
@param list<string> $phids List of recipient PHIDs, possibly including
aggregate recipients.
@return list<string> Deaggregated list pf PHIDs of mailable recipients. | expandRecipients | php | phorgeit/phorge | src/applications/metamta/storage/PhabricatorMetaMTAMail.php | https://github.com/phorgeit/phorge/blob/master/src/applications/metamta/storage/PhabricatorMetaMTAMail.php | Apache-2.0 |
private function getRawEmailAddress($address) {
$matches = null;
$ok = preg_match('/<(.*)>/', $address, $matches);
if ($ok) {
$address = $matches[1];
}
return $address;
} | Strip an email address down to the actual [email protected] part if
necessary, since sometimes it will have formatting like
'"Abraham Lincoln" <[email protected]>'. | getRawEmailAddress | php | phorgeit/phorge | src/applications/metamta/storage/PhabricatorMetaMTAReceivedMail.php | https://github.com/phorgeit/phorge/blob/master/src/applications/metamta/storage/PhabricatorMetaMTAReceivedMail.php | Apache-2.0 |
private function dropMailFromPhabricator() {
if (!$this->getHeader('x-phabricator-sent-this-message')) {
return;
}
throw new PhabricatorMetaMTAReceivedMailProcessingException(
MetaMTAReceivedMailStatus::STATUS_FROM_PHABRICATOR,
pht(
"Ignoring email with '%s' header to avoid loops.",
'X-Phabricator-Sent-This-Message'));
} | If Phabricator sent the mail, always drop it immediately. This prevents
loops where, e.g., the public bug address is also a user email address
and creating a bug sends them an email, which loops. | dropMailFromPhabricator | php | phorgeit/phorge | src/applications/metamta/storage/PhabricatorMetaMTAReceivedMail.php | https://github.com/phorgeit/phorge/blob/master/src/applications/metamta/storage/PhabricatorMetaMTAReceivedMail.php | Apache-2.0 |
private function dropMailAlreadyReceived() {
$message_id_hash = $this->getMessageIDHash();
if (!$message_id_hash) {
// No message ID hash, so we can't detect duplicates. This should only
// happen with very old messages.
return;
}
$messages = $this->loadAllWhere(
'messageIDHash = %s ORDER BY id ASC LIMIT 2',
$message_id_hash);
$messages_count = count($messages);
if ($messages_count <= 1) {
// If we only have one copy of this message, we're good to process it.
return;
}
$first_message = reset($messages);
if ($first_message->getID() == $this->getID()) {
// If this is the first copy of the message, it is okay to process it.
// We may not have been able to to process it immediately when we received
// it, and could may have received several copies without processing any
// yet.
return;
}
$message = pht(
'Ignoring email with "Message-ID" hash "%s" that has been seen %d '.
'times, including this message.',
$message_id_hash,
$messages_count);
throw new PhabricatorMetaMTAReceivedMailProcessingException(
MetaMTAReceivedMailStatus::STATUS_DUPLICATE,
$message);
} | If this mail has the same message ID as some other mail, and isn't the
first mail we we received with that message ID, we drop it as a duplicate. | dropMailAlreadyReceived | php | phorgeit/phorge | src/applications/metamta/storage/PhabricatorMetaMTAReceivedMail.php | https://github.com/phorgeit/phorge/blob/master/src/applications/metamta/storage/PhabricatorMetaMTAReceivedMail.php | Apache-2.0 |
private function loadSender() {
$viewer = $this->getViewer();
// Try to identify the user based on their "From" address.
$from_address = $this->newFromAddress();
if ($from_address) {
$user = id(new PhabricatorPeopleQuery())
->setViewer($viewer)
->withEmails(array($from_address->getAddress()))
->executeOne();
if ($user) {
return $user;
}
}
return null;
} | Identify the sender's user account for a piece of received mail.
Note that this method does not validate that the sender is who they say
they are, just that they've presented some credential which corresponds
to a recognizable user. | loadSender | php | phorgeit/phorge | src/applications/metamta/storage/PhabricatorMetaMTAReceivedMail.php | https://github.com/phorgeit/phorge/blob/master/src/applications/metamta/storage/PhabricatorMetaMTAReceivedMail.php | Apache-2.0 |
public function supportsMessageIDHeader() {
return false;
} | Return true if this adapter supports setting a "Message-ID" when sending
email.
This is an ugly implementation detail because mail threading is a horrible
mess, implemented differently by every client in existence. | supportsMessageIDHeader | php | phorgeit/phorge | src/applications/metamta/adapter/PhabricatorMailAdapter.php | https://github.com/phorgeit/phorge/blob/master/src/applications/metamta/adapter/PhabricatorMailAdapter.php | Apache-2.0 |
public function sendMessage(PhabricatorMailExternalMessage $message) {
$root = phutil_get_library_root('phabricator');
$root = dirname($root);
require_once $root.'/externals/phpmailer/class.phpmailer-lite.php';
$mailer = PHPMailerLite::newFromMessage($message);
$mailer->Send();
} | @phutil-external-symbol class PHPMailerLite | sendMessage | php | phorgeit/phorge | src/applications/metamta/adapter/PhabricatorMailSendmailAdapter.php | https://github.com/phorgeit/phorge/blob/master/src/applications/metamta/adapter/PhabricatorMailSendmailAdapter.php | Apache-2.0 |
public function sendMessage(PhabricatorMailExternalMessage $message) {
$root = phutil_get_library_root('phabricator');
$root = dirname($root);
require_once $root.'/externals/phpmailer/class.phpmailer-lite.php';
$mailer = PHPMailerLite::newFromMessage($message);
$mailer->Mailer = 'amazon-ses';
$mailer->customMailer = $this;
$mailer->Send();
} | @phutil-external-symbol class PHPMailerLite | sendMessage | php | phorgeit/phorge | src/applications/metamta/adapter/PhabricatorMailAmazonSESAdapter.php | https://github.com/phorgeit/phorge/blob/master/src/applications/metamta/adapter/PhabricatorMailAmazonSESAdapter.php | Apache-2.0 |
public function getCommandSyntax() {
return '**!'.$this->getCommand().'**';
} | Return a one-line Remarkup description of command syntax for documentation.
@return string Brief human-readable remarkup.
@task docs | getCommandSyntax | php | phorgeit/phorge | src/applications/metamta/command/MetaMTAEmailTransactionCommand.php | https://github.com/phorgeit/phorge/blob/master/src/applications/metamta/command/MetaMTAEmailTransactionCommand.php | Apache-2.0 |
public function getCommandDescription() {
return null;
} | Return a longer human-readable description of the command effect.
This can be as long as necessary to explain the command.
@return string|null Human-readable remarkup of whatever length is desired.
@task docs | getCommandDescription | php | phorgeit/phorge | src/applications/metamta/command/MetaMTAEmailTransactionCommand.php | https://github.com/phorgeit/phorge/blob/master/src/applications/metamta/command/MetaMTAEmailTransactionCommand.php | Apache-2.0 |
private function initMimemailparser() {
// Not having this extension is probably a frequent error locally.
if (!function_exists('mailparse_msg_create')) {
$this->assertSkipped(pht('PHP mailparse extension is not installed'));
}
// Root of Phorge installation
$root = dirname(dirname(dirname(dirname(dirname(__DIR__)))));
// This is safe to be called multiple times.
require_once $root.'/externals/mimemailparser/__init.php';
} | Be sure to have mimemailparser classes. | initMimemailparser | php | phorgeit/phorge | src/applications/metamta/externals/__tests__/PhabricatorExternalMimeMailParserTestCase.php | https://github.com/phorgeit/phorge/blob/master/src/applications/metamta/externals/__tests__/PhabricatorExternalMimeMailParserTestCase.php | Apache-2.0 |
public static function normalizeAddress(PhutilEmailAddress $address) {
$raw_address = $address->getAddress();
$raw_address = phutil_utf8_strtolower($raw_address);
$raw_address = trim($raw_address);
// If a mailbox prefix is configured and present, strip it off.
$prefix_key = 'metamta.single-reply-handler-prefix';
$prefix = PhabricatorEnv::getEnvConfig($prefix_key);
if (phutil_nonempty_string($prefix)) {
$prefix = $prefix.'+';
$len = strlen($prefix);
if (!strncasecmp($raw_address, $prefix, $len)) {
$raw_address = substr($raw_address, $len);
}
}
return id(clone $address)
->setAddress($raw_address);
} | Normalize an email address for comparison or lookup.
Phabricator can be configured to prepend a prefix to all reply addresses,
which can make forwarding rules easier to write. This method strips the
prefix if it is present, and normalizes casing and whitespace.
@param PhutilEmailAddress $address Email address.
@return PhutilEmailAddress Normalized address. | normalizeAddress | php | phorgeit/phorge | src/applications/metamta/util/PhabricatorMailUtil.php | https://github.com/phorgeit/phorge/blob/master/src/applications/metamta/util/PhabricatorMailUtil.php | Apache-2.0 |
public static function matchAddresses(
PhutilEmailAddress $u,
PhutilEmailAddress $v) {
$u = self::normalizeAddress($u);
$v = self::normalizeAddress($v);
return ($u->getAddress() === $v->getAddress());
} | Determine if two inbound email addresses are effectively identical.
This method strips and normalizes addresses so that equivalent variations
are correctly detected as identical. For example, these addresses are all
considered to match one another:
"Abraham Lincoln" <[email protected]>
[email protected]
<[email protected]>
"Abraham" <[email protected]> # With configured prefix.
@param PhutilEmailAddress $u Email address.
@param PhutilEmailAddress $v Another email address.
@return bool True if addresses are effectively the same address. | matchAddresses | php | phorgeit/phorge | src/applications/metamta/util/PhabricatorMailUtil.php | https://github.com/phorgeit/phorge/blob/master/src/applications/metamta/util/PhabricatorMailUtil.php | Apache-2.0 |
public function addRawSection($text) {
if (strlen($text)) {
$text = rtrim($text);
$this->sections[] = $text;
$this->htmlSections[] = phutil_escape_html_newlines(
phutil_tag('div', array(), $text));
}
return $this;
} | Add a raw block of text to the email. This will be rendered as-is.
@param string $text Block of text.
@return $this
@task compose | addRawSection | php | phorgeit/phorge | src/applications/metamta/view/PhabricatorMetaMTAMailBody.php | https://github.com/phorgeit/phorge/blob/master/src/applications/metamta/view/PhabricatorMetaMTAMailBody.php | Apache-2.0 |
public function addTextSection($header, $section) {
if ($section instanceof PhabricatorMetaMTAMailSection) {
$plaintext = $section->getPlaintext();
$html = $section->getHTML();
} else {
$plaintext = $section;
$html = phutil_escape_html_newlines(phutil_tag('div', array(), $section));
}
$this->addPlaintextSection($header, $plaintext);
$this->addHTMLSection($header, $html);
return $this;
} | Add a block of text with a section header. This is rendered like this:
HEADER
Text is indented.
@param string $header Header text.
@param string $section Section text.
@return $this
@task compose | addTextSection | php | phorgeit/phorge | src/applications/metamta/view/PhabricatorMetaMTAMailBody.php | https://github.com/phorgeit/phorge/blob/master/src/applications/metamta/view/PhabricatorMetaMTAMailBody.php | Apache-2.0 |
public function addAttachment(PhabricatorMailAttachment $attachment) {
$this->attachments[] = $attachment;
return $this;
} | Add an attachment.
@param PhabricatorMailAttachment $attachment Attachment.
@return $this
@task compose | addAttachment | php | phorgeit/phorge | src/applications/metamta/view/PhabricatorMetaMTAMailBody.php | https://github.com/phorgeit/phorge/blob/master/src/applications/metamta/view/PhabricatorMetaMTAMailBody.php | Apache-2.0 |
public function render() {
return implode("\n\n", $this->sections)."\n";
} | Render the email body.
@return string Rendered body.
@task render | render | php | phorgeit/phorge | src/applications/metamta/view/PhabricatorMetaMTAMailBody.php | https://github.com/phorgeit/phorge/blob/master/src/applications/metamta/view/PhabricatorMetaMTAMailBody.php | Apache-2.0 |
public function getAttachments() {
return $this->attachments;
} | Retrieve attachments.
@return list<PhabricatorMailAttachment> Attachments.
@task render | getAttachments | php | phorgeit/phorge | src/applications/metamta/view/PhabricatorMetaMTAMailBody.php | https://github.com/phorgeit/phorge/blob/master/src/applications/metamta/view/PhabricatorMetaMTAMailBody.php | Apache-2.0 |
private function indent($text) {
return rtrim(" ".str_replace("\n", "\n ", $text));
} | Indent a block of text for rendering under a section heading.
@param string $text Text to indent.
@return string Indented text.
@task render | indent | php | phorgeit/phorge | src/applications/metamta/view/PhabricatorMetaMTAMailBody.php | https://github.com/phorgeit/phorge/blob/master/src/applications/metamta/view/PhabricatorMetaMTAMailBody.php | Apache-2.0 |
private function getUserName(PhabricatorUser $user) {
$format = PhabricatorEnv::getEnvConfig('metamta.user-address-format');
switch ($format) {
case 'short':
$name = $user->getUserName();
break;
case 'real':
$name = strlen($user->getRealName()) ?
$user->getRealName() : $user->getUserName();
break;
case 'full':
default:
$name = $user->getFullName();
break;
}
return $name;
} | Small helper function to make sure we format the username properly as
specified by the `metamta.user-address-format` configuration value. | getUserName | php | phorgeit/phorge | src/applications/metamta/query/PhabricatorMetaMTAActorQuery.php | https://github.com/phorgeit/phorge/blob/master/src/applications/metamta/query/PhabricatorMetaMTAActorQuery.php | Apache-2.0 |
public function executeExpansion() {
return array_unique(array_mergev($this->execute()));
} | Execute the query, merging results into a single list of unique member
PHIDs. | executeExpansion | php | phorgeit/phorge | src/applications/metamta/query/PhabricatorMetaMTAMemberQuery.php | https://github.com/phorgeit/phorge/blob/master/src/applications/metamta/query/PhabricatorMetaMTAMemberQuery.php | Apache-2.0 |
private function expandRecipientPHIDs(array $to, array $cc) {
$to_result = array();
$cc_result = array();
// "Unexpandable" users have disengaged from an object (for example,
// by resigning from a revision).
// If such a user is still a direct recipient (for example, they're still
// on the Subscribers list) they're fair game, but group targets (like
// projects) will no longer include them when expanded.
$unexpandable = $this->getUnexpandablePHIDs();
$unexpandable = array_fuse($unexpandable);
$all_phids = array_merge($to, $cc);
if ($all_phids) {
$map = id(new PhabricatorMetaMTAMemberQuery())
->setViewer(PhabricatorUser::getOmnipotentUser())
->withPHIDs($all_phids)
->execute();
foreach ($to as $phid) {
foreach ($map[$phid] as $expanded) {
if ($expanded !== $phid) {
if (isset($unexpandable[$expanded])) {
continue;
}
}
$to_result[$expanded] = $expanded;
}
}
foreach ($cc as $phid) {
foreach ($map[$phid] as $expanded) {
if ($expanded !== $phid) {
if (isset($unexpandable[$expanded])) {
continue;
}
}
$cc_result[$expanded] = $expanded;
}
}
}
// Remove recipients from "CC" if they're also present in "To".
$cc_result = array_diff_key($cc_result, $to_result);
return array(array_values($to_result), array_values($cc_result));
} | Expand lists of recipient PHIDs.
This takes any compound recipients (like projects) and looks up all their
members.
@param list<string> $to List of To PHIDs.
@param list<string> $cc List of CC PHIDs.
@return pair<list<string>, list<string>> Expanded PHID lists. | expandRecipientPHIDs | php | phorgeit/phorge | src/applications/metamta/replyhandler/PhabricatorMailReplyHandler.php | https://github.com/phorgeit/phorge/blob/master/src/applications/metamta/replyhandler/PhabricatorMailReplyHandler.php | Apache-2.0 |
private function loadRecipientUsers(array $to, array $cc) {
$to_result = array();
$cc_result = array();
$all_phids = array_merge($to, $cc);
if ($all_phids) {
// We need user settings here because we'll check translations later
// when generating mail.
$users = id(new PhabricatorPeopleQuery())
->setViewer(PhabricatorUser::getOmnipotentUser())
->withPHIDs($all_phids)
->needUserSettings(true)
->execute();
$users = mpull($users, null, 'getPHID');
foreach ($to as $phid) {
if (isset($users[$phid])) {
$to_result[$phid] = $users[$phid];
}
}
foreach ($cc as $phid) {
if (isset($users[$phid])) {
$cc_result[$phid] = $users[$phid];
}
}
}
return array($to_result, $cc_result);
} | Load @{class:PhabricatorUser} objects for each recipient.
Invalid recipients are dropped from the results.
@param list<string> $to List of To PHIDs.
@param list<string> $cc List of CC PHIDs.
@return pair<wild, wild> Maps from PHIDs to users. | loadRecipientUsers | php | phorgeit/phorge | src/applications/metamta/replyhandler/PhabricatorMailReplyHandler.php | https://github.com/phorgeit/phorge/blob/master/src/applications/metamta/replyhandler/PhabricatorMailReplyHandler.php | Apache-2.0 |
public function parseBody($body) {
$body = $this->stripTextBody($body);
$commands = array();
$lines = phutil_split_lines($body, $retain_endings = true);
// We'll match commands at the beginning and end of the mail, but not
// in the middle of the mail body.
list($top_commands, $lines) = $this->stripCommands($lines);
list($end_commands, $lines) = $this->stripCommands(array_reverse($lines));
$lines = array_reverse($lines);
$commands = array_merge($top_commands, array_reverse($end_commands));
$lines = rtrim(implode('', $lines));
return array(
'body' => $lines,
'commands' => $commands,
);
} | Mails can have bodies such as
!claim
taking this task
Or
!assign alincoln
please, take this task I took; its hard
This function parses such an email body and returns a dictionary
containing a clean body text (e.g. "taking this task"), and a list of
commands. For example, this body above might parse as:
array(
'body' => 'please, take this task I took; it's hard',
'commands' => array(
array('assign', 'alincoln'),
),
)
@param string $body Raw mail text body.
@return dict Parsed body. | parseBody | php | phorgeit/phorge | src/applications/metamta/parser/PhabricatorMetaMTAEmailBodyParser.php | https://github.com/phorgeit/phorge/blob/master/src/applications/metamta/parser/PhabricatorMetaMTAEmailBodyParser.php | Apache-2.0 |
public static function loadUserPreferences(PhabricatorUser $user) {
return id(new PhabricatorUserPreferencesQuery())
->setViewer($user)
->withUsers(array($user))
->needSyntheticPreferences(true)
->executeOne();
} | Load or create a preferences object for the given user.
@param PhabricatorUser $user User to load or create preferences for. | loadUserPreferences | php | phorgeit/phorge | src/applications/settings/storage/PhabricatorUserPreferences.php | https://github.com/phorgeit/phorge/blob/master/src/applications/settings/storage/PhabricatorUserPreferences.php | Apache-2.0 |
public static function loadGlobalPreferences(PhabricatorUser $viewer) {
$global = id(new PhabricatorUserPreferencesQuery())
->setViewer($viewer)
->withBuiltinKeys(
array(
self::BUILTIN_GLOBAL_DEFAULT,
))
->executeOne();
if (!$global) {
$global = id(new self())
->attachUser(new PhabricatorUser());
}
return $global;
} | Load or create a global preferences object.
If no global preferences exist, an empty preferences object is returned.
@param PhabricatorUser $viewer Viewing user. | loadGlobalPreferences | php | phorgeit/phorge | src/applications/settings/storage/PhabricatorUserPreferences.php | https://github.com/phorgeit/phorge/blob/master/src/applications/settings/storage/PhabricatorUserPreferences.php | Apache-2.0 |
public function getPanelKey() {
return $this->getPhobjectClassConstant('PANELKEY');
} | Return a unique string used in the URI to identify this panel, like
"example".
@return string Unique panel identifier (used in URIs).
@task config | getPanelKey | php | phorgeit/phorge | src/applications/settings/panel/PhabricatorSettingsPanel.php | https://github.com/phorgeit/phorge/blob/master/src/applications/settings/panel/PhabricatorSettingsPanel.php | Apache-2.0 |
public function getPanelMenuIcon() {
return 'fa-wrench';
} | Return an icon for the panel in the menu.
@return string Icon identifier.
@task config | getPanelMenuIcon | php | phorgeit/phorge | src/applications/settings/panel/PhabricatorSettingsPanel.php | https://github.com/phorgeit/phorge/blob/master/src/applications/settings/panel/PhabricatorSettingsPanel.php | Apache-2.0 |
public function isEnabled() {
return true;
} | Return false to prevent this panel from being displayed or used. You can
do, e.g., configuration checks here, to determine if the feature your
panel controls is unavailable in this install. By default, all panels are
enabled.
@return bool True if the panel should be shown.
@task config | isEnabled | php | phorgeit/phorge | src/applications/settings/panel/PhabricatorSettingsPanel.php | https://github.com/phorgeit/phorge/blob/master/src/applications/settings/panel/PhabricatorSettingsPanel.php | Apache-2.0 |
public function isUserPanel() {
return true;
} | Return true if this panel is available to users while editing their own
settings.
@return bool True to enable management on behalf of a user.
@task config | isUserPanel | php | phorgeit/phorge | src/applications/settings/panel/PhabricatorSettingsPanel.php | https://github.com/phorgeit/phorge/blob/master/src/applications/settings/panel/PhabricatorSettingsPanel.php | Apache-2.0 |
public function isManagementPanel() {
return false;
} | Return true if this panel is available to administrators while managing
bot and mailing list accounts.
@return bool True to enable management on behalf of accounts.
@task config | isManagementPanel | php | phorgeit/phorge | src/applications/settings/panel/PhabricatorSettingsPanel.php | https://github.com/phorgeit/phorge/blob/master/src/applications/settings/panel/PhabricatorSettingsPanel.php | Apache-2.0 |
public function isTemplatePanel() {
return false;
} | Return true if this panel is available while editing settings templates.
@return bool True to allow editing in templates.
@task config | isTemplatePanel | php | phorgeit/phorge | src/applications/settings/panel/PhabricatorSettingsPanel.php | https://github.com/phorgeit/phorge/blob/master/src/applications/settings/panel/PhabricatorSettingsPanel.php | Apache-2.0 |
public function isMultiFactorEnrollmentPanel() {
return false;
} | Return true if this panel should be available when enrolling in MFA on
a new account with MFA requiredd.
@return bool True to allow configuration during MFA enrollment.
@task config | isMultiFactorEnrollmentPanel | php | phorgeit/phorge | src/applications/settings/panel/PhabricatorSettingsPanel.php | https://github.com/phorgeit/phorge/blob/master/src/applications/settings/panel/PhabricatorSettingsPanel.php | Apache-2.0 |
final public function getPanelURI($path = '') {
$path = ltrim($path, '/');
if ($this->overrideURI) {
return rtrim($this->overrideURI, '/').'/'.$path;
}
$key = $this->getPanelKey();
$key = phutil_escape_uri($key);
$user = $this->getUser();
if ($user) {
if ($user->isLoggedIn()) {
$username = $user->getUsername();
return "/settings/user/{$username}/page/{$key}/{$path}";
} else {
// For logged-out users, we can't put their username in the URI. This
// page will prompt them to login, then redirect them to the correct
// location.
return "/settings/panel/{$key}/";
}
} else {
$builtin = $this->getPreferences()->getBuiltinKey();
return "/settings/builtin/{$builtin}/page/{$key}/{$path}";
}
} | Get the URI for this panel.
@param string $path (optional) Path to append.
@return string Relative URI for the panel.
@task panel | getPanelURI | php | phorgeit/phorge | src/applications/settings/panel/PhabricatorSettingsPanel.php | https://github.com/phorgeit/phorge/blob/master/src/applications/settings/panel/PhabricatorSettingsPanel.php | Apache-2.0 |
final public function getPanelOrderVector() {
return id(new PhutilSortVector())
->addString($this->getPanelName());
} | Generates a key to sort the list of panels.
@return string Sortable key.
@task internal | getPanelOrderVector | php | phorgeit/phorge | src/applications/settings/panel/PhabricatorSettingsPanel.php | https://github.com/phorgeit/phorge/blob/master/src/applications/settings/panel/PhabricatorSettingsPanel.php | Apache-2.0 |
public function isUserPanel() {
$sms_auth_factor = new PhabricatorSMSAuthFactor();
if ($sms_auth_factor->isSMSMailerConfigured()) {
return true;
}
return false;
} | Whether to display "Contact Numbers" panel in users' Personal
Settings by checking if global SMS support is configured | isUserPanel | php | phorgeit/phorge | src/applications/settings/panel/PhabricatorContactNumbersSettingsPanel.php | https://github.com/phorgeit/phorge/blob/master/src/applications/settings/panel/PhabricatorContactNumbersSettingsPanel.php | Apache-2.0 |
public function needSyntheticPreferences($synthetic) {
$this->synthetic = $synthetic;
return $this;
} | Always return preferences for every queried user.
If no settings exist for a user, a new empty settings object with
appropriate defaults is returned.
@param bool $synthetic True to generate synthetic preferences for missing
users. | needSyntheticPreferences | php | phorgeit/phorge | src/applications/settings/query/PhabricatorUserPreferencesQuery.php | https://github.com/phorgeit/phorge/blob/master/src/applications/settings/query/PhabricatorUserPreferencesQuery.php | Apache-2.0 |
public static function sortTimeline(array $u, array $v) {
// If these events occur at different times, ordering is obvious.
if ($u['at'] != $v['at']) {
return ($u['at'] < $v['at']) ? -1 : 1;
}
$u_end = ($u['type'] == 'end' || $u['type'] == 'pop');
$v_end = ($v['type'] == 'end' || $v['type'] == 'pop');
$u_id = $u['event']->getID();
$v_id = $v['event']->getID();
if ($u_end == $v_end) {
// These are both start events or both end events. Sort them by ID.
if (!$u_end) {
return ($u_id < $v_id) ? -1 : 1;
} else {
return ($u_id < $v_id) ? 1 : -1;
}
} else {
// Sort them (start, end) if they're the same event, and (end, start)
// otherwise.
if ($u_id == $v_id) {
return $v_end ? -1 : 1;
} else {
return $v_end ? 1 : -1;
}
}
} | Sort events in timeline order. Notably, for events which occur on the same
second, we want to process end events after start events. | sortTimeline | php | phorgeit/phorge | src/applications/phrequent/storage/PhrequentTimeBlock.php | https://github.com/phorgeit/phorge/blob/master/src/applications/phrequent/storage/PhrequentTimeBlock.php | Apache-2.0 |
public function newStorageObject() {
return id(new PhorgeFlagFlaggedObjectFieldStorage())
->setViewer($this->getViewer());
} | The parent function is defined to return a PhabricatorCustomFieldStorage,
but that assumes a DTO with a particular form; That doesn't apply here.
Maybe the function needs to be re-defined with a suitable interface.
For now, PhorgeFlagFlaggedObjectFieldStorage just duck-types into the
right shape. | newStorageObject | php | phorgeit/phorge | src/applications/flag/customfield/PhorgeFlagFlaggedObjectCustomField.php | https://github.com/phorgeit/phorge/blob/master/src/applications/flag/customfield/PhorgeFlagFlaggedObjectCustomField.php | Apache-2.0 |
public function setGroupBy($group) {
$this->groupBy = $group;
return $this;
} | NOTE: this is done in PHP and not in MySQL, which means its inappropriate
for large datasets. Pragmatically, this is fine for user flags which are
typically well under 100 flags per user. | setGroupBy | php | phorgeit/phorge | src/applications/flag/query/PhabricatorFlagQuery.php | https://github.com/phorgeit/phorge/blob/master/src/applications/flag/query/PhabricatorFlagQuery.php | Apache-2.0 |
public function setSubmitURI($uri) {
$this->submitURI = $uri;
return $this;
} | Set the URI associated to the Submit Button
If you want a normal link and not any form submission,
see also: setDisableWorkflowOnSubmit(false).
@param string $uri
@return self | setSubmitURI | php | phorgeit/phorge | src/view/AphrontDialogView.php | https://github.com/phorgeit/phorge/blob/master/src/view/AphrontDialogView.php | Apache-2.0 |
public function addSubmitButton($text = null) {
if (!$text) {
$text = pht('Okay');
}
$this->submitButton = $text;
return $this;
} | Add a Submit Button and specify its text
If you want to associate an URI for this Button,
see also: setSubmitURI().
@param string $text Text shown for that button
@return self | addSubmitButton | php | phorgeit/phorge | src/view/AphrontDialogView.php | https://github.com/phorgeit/phorge/blob/master/src/view/AphrontDialogView.php | Apache-2.0 |
public function setDisableWorkflowOnSubmit($disable_workflow_on_submit) {
$this->disableWorkflowOnSubmit = $disable_workflow_on_submit;
return $this;
} | Enable or Disable a Workflow on Submit
For example, if your Submit Button should be a normal link,
without activating any Workflow, you can set false.
@param bool $disable_workflow_on_submit
@return self | setDisableWorkflowOnSubmit | php | phorgeit/phorge | src/view/AphrontDialogView.php | https://github.com/phorgeit/phorge/blob/master/src/view/AphrontDialogView.php | Apache-2.0 |
function phabricator_format_local_time($epoch, $user, $format) {
if (!$epoch) {
// If we're missing date information for something, the DateTime class will
// throw an exception when we try to construct an object. Since this is a
// display function, just return an empty string.
return '';
}
$user_zone = $user->getTimezoneIdentifier();
static $zones = array();
if (empty($zones[$user_zone])) {
$zones[$user_zone] = new DateTimeZone($user_zone);
}
$zone = $zones[$user_zone];
// NOTE: Although DateTime takes a second DateTimeZone parameter to its
// constructor, it ignores it if the date string includes timezone
// information. Further, it treats epoch timestamps ("@946684800") as having
// a UTC timezone. Set the timezone explicitly after constructing the object.
try {
$date = new DateTime('@'.$epoch);
} catch (Exception $ex) {
// NOTE: DateTime throws an empty exception if the format is invalid,
// just replace it with a useful one.
throw new Exception(
pht("Construction of a DateTime() with epoch '%s' ".
"raised an exception.", $epoch));
}
$date->setTimezone($zone);
return PhutilTranslator::getInstance()->translateDate($format, $date);
} | This function does not usually need to be called directly. Instead, call
@{function:phabricator_date}, @{function:phabricator_time}, or
@{function:phabricator_datetime}.
@param int $epoch Unix epoch timestamp.
@param PhabricatorUser $user User viewing the timestamp.
@param string $format Date format, as per DateTime class.
@return string Formatted, local date/time. | phabricator_format_local_time | php | phorgeit/phorge | src/view/viewutils.php | https://github.com/phorgeit/phorge/blob/master/src/view/viewutils.php | Apache-2.0 |
public function setViewer(PhabricatorUser $viewer) {
$this->viewer = $viewer;
return $this;
} | Set the user viewing this element.
@param PhabricatorUser $viewer Viewing user.
@return $this | setViewer | php | phorgeit/phorge | src/view/AphrontView.php | https://github.com/phorgeit/phorge/blob/master/src/view/AphrontView.php | Apache-2.0 |
public function getViewer() {
if (!$this->viewer) {
throw new PhutilInvalidStateException('setViewer');
}
return $this->viewer;
} | Get the user viewing this element.
Throws an exception if no viewer has been set.
@return PhabricatorUser Viewing user. | getViewer | php | phorgeit/phorge | src/view/AphrontView.php | https://github.com/phorgeit/phorge/blob/master/src/view/AphrontView.php | Apache-2.0 |
public function hasViewer() {
return (bool)$this->viewer;
} | Test if a viewer has been set on this element.
@return bool True if a viewer is available. | hasViewer | php | phorgeit/phorge | src/view/AphrontView.php | https://github.com/phorgeit/phorge/blob/master/src/view/AphrontView.php | Apache-2.0 |
public function setUser(PhabricatorUser $user) {
return $this->setViewer($user);
} | Deprecated, use @{method:setViewer}.
@task config
@deprecated | setUser | php | phorgeit/phorge | src/view/AphrontView.php | https://github.com/phorgeit/phorge/blob/master/src/view/AphrontView.php | Apache-2.0 |
protected function getUser() {
if (!$this->hasViewer()) {
return null;
}
return $this->getViewer();
} | Deprecated, use @{method:getViewer}.
@task config
@deprecated | getUser | php | phorgeit/phorge | src/view/AphrontView.php | https://github.com/phorgeit/phorge/blob/master/src/view/AphrontView.php | Apache-2.0 |
protected function canAppendChild() {
return true;
} | Test if this View accepts children.
By default, views accept children, but subclases may override this method
to prevent children from being appended. Doing so will cause
@{method:appendChild} to throw exceptions instead of appending children.
@return bool True if the View should accept children.
@task children | canAppendChild | php | phorgeit/phorge | src/view/AphrontView.php | https://github.com/phorgeit/phorge/blob/master/src/view/AphrontView.php | Apache-2.0 |
final public function appendChild($child) {
if (!$this->canAppendChild()) {
$class = get_class($this);
throw new Exception(
pht("View '%s' does not support children.", $class));
}
$this->children[] = $child;
return $this;
} | Append a child to the list of children.
This method will only work if the view supports children, which is
determined by @{method:canAppendChild}.
@param wild $child Something renderable.
@return $this | appendChild | php | phorgeit/phorge | src/view/AphrontView.php | https://github.com/phorgeit/phorge/blob/master/src/view/AphrontView.php | Apache-2.0 |
final protected function renderChildren() {
return $this->children;
} | Produce children for rendering.
Historically, this method reduced children to a string representation,
but it no longer does.
@return wild Renderable children.
@task | renderChildren | php | phorgeit/phorge | src/view/AphrontView.php | https://github.com/phorgeit/phorge/blob/master/src/view/AphrontView.php | Apache-2.0 |
final public function hasChildren() {
if ($this->children) {
$this->children = $this->reduceChildren($this->children);
}
return (bool)$this->children;
} | Test if an element has no children.
@return bool True if this element has children.
@task children | hasChildren | php | phorgeit/phorge | src/view/AphrontView.php | https://github.com/phorgeit/phorge/blob/master/src/view/AphrontView.php | Apache-2.0 |
private function reduceChildren(array $children) {
foreach ($children as $key => $child) {
if ($child === null) {
unset($children[$key]);
} else if ($child === '') {
unset($children[$key]);
} else if (is_array($child)) {
$child = $this->reduceChildren($child);
if ($child) {
$children[$key] = $child;
} else {
unset($children[$key]);
}
}
}
return $children;
} | Reduce effectively-empty lists of children to be actually empty. This
recursively removes `null`, `''`, and `array()` from the list of children
so that @{method:hasChildren} can more effectively align with expectations.
NOTE: Because View children are not rendered, a View which renders down
to nothing will not be reduced by this method.
@param list<wild> $children Renderable children.
@return list<wild> Reduced list of children.
@task children | reduceChildren | php | phorgeit/phorge | src/view/AphrontView.php | https://github.com/phorgeit/phorge/blob/master/src/view/AphrontView.php | Apache-2.0 |
public function willRender() {
return;
} | Inconsistent, unreliable pre-rendering hook.
This hook //may// fire before views render. It is not fired reliably, and
may fire multiple times.
If it does fire, views might use it to register data for later loads, but
almost no datasources support this now; this is currently only useful for
tokenizers. This mechanism might eventually see wider support or might be
removed. | willRender | php | phorgeit/phorge | src/view/AphrontView.php | https://github.com/phorgeit/phorge/blob/master/src/view/AphrontView.php | Apache-2.0 |
public function appendControl(AphrontFormControl $control) {
$this->controls[] = $control;
return $this->appendChild($control);
} | Append a control to the form.
This method behaves like @{method:appendChild}, but it only takes
controls. It will propagate some information from the form to the
control to simplify rendering.
@param AphrontFormControl $control Control to append.
@return $this | appendControl | php | phorgeit/phorge | src/view/form/AphrontFormView.php | https://github.com/phorgeit/phorge/blob/master/src/view/form/AphrontFormView.php | Apache-2.0 |
public function setCaption($caption) {
$this->caption = $caption;
return $this;
} | Set the Caption
The Caption shows a tip usually nearby the related input field.
@param string|PhutilSafeHTML|null $caption
@return self | setCaption | php | phorgeit/phorge | src/view/form/control/AphrontFormControl.php | https://github.com/phorgeit/phorge/blob/master/src/view/form/control/AphrontFormControl.php | Apache-2.0 |
public function getCaption() {
return $this->caption;
} | Get the Caption
The Caption shows a tip usually nearby the related input field.
@return string|PhutilSafeHTML|null | getCaption | php | phorgeit/phorge | src/view/form/control/AphrontFormControl.php | https://github.com/phorgeit/phorge/blob/master/src/view/form/control/AphrontFormControl.php | Apache-2.0 |
private function newDateTime($date, $time) {
$date = $this->getStandardDateFormat($date);
$time = $this->getStandardTimeFormat($time);
try {
// We need to provide the timezone in the constructor, and also set it
// explicitly. If the date is an epoch timestamp, the timezone in the
// constructor is ignored. If the date is not an epoch timestamp, it is
// used to parse the date.
$zone = $this->getTimezone();
$datetime = new DateTime("{$date} {$time}", $zone);
$datetime->setTimezone($zone);
} catch (Exception $ex) {
return null;
}
return $datetime;
} | Create a DateTime object including timezone
@param string $date Date, like "2024-08-20" or "2024-07-1" or such
@param string|null $time Time, like "12:00 AM" or such
@return DateTime|null | newDateTime | php | phorgeit/phorge | src/view/form/control/AphrontFormDateControlValue.php | https://github.com/phorgeit/phorge/blob/master/src/view/form/control/AphrontFormDateControlValue.php | Apache-2.0 |
public function getDateTime() {
return $this->newDateTime($this->valueDate, $this->valueTime);
} | @return DateTime|null | getDateTime | php | phorgeit/phorge | src/view/form/control/AphrontFormDateControlValue.php | https://github.com/phorgeit/phorge/blob/master/src/view/form/control/AphrontFormDateControlValue.php | Apache-2.0 |
private function getTimezone() {
if ($this->zone) {
return $this->zone;
}
$viewer_zone = $this->viewer->getTimezoneIdentifier();
$this->zone = new DateTimeZone($viewer_zone);
return $this->zone;
} | @return DateTimeZone | getTimezone | php | phorgeit/phorge | src/view/form/control/AphrontFormDateControlValue.php | https://github.com/phorgeit/phorge/blob/master/src/view/form/control/AphrontFormDateControlValue.php | Apache-2.0 |
public function setCollapsible($collapsible) {
$this->collapsible = $collapsible;
return $this;
} | Render PHUIHeaderView as a <summary> instead of a <div> HTML tag.
To be used for collapse/expand in combination with PHUIBoxView.
@param bool $collapsible True to wrap in <summary> instead of <div> HTML
tag. | setCollapsible | php | phorgeit/phorge | src/view/phui/PHUIHeaderView.php | https://github.com/phorgeit/phorge/blob/master/src/view/phui/PHUIHeaderView.php | Apache-2.0 |
public function setHref($href) {
PhutilURI::checkHrefType($href);
$this->href = $href;
return $this;
} | Set the href attribute
@param string|PhutilURI|null $href
@return self | setHref | php | phorgeit/phorge | src/view/phui/PHUIObjectItemView.php | https://github.com/phorgeit/phorge/blob/master/src/view/phui/PHUIObjectItemView.php | Apache-2.0 |
public function getHref() {
return $this->href;
} | Get the href attribute
@see PHUIObjectItemView::setHref()
@return string|PhutilURI|null | getHref | php | phorgeit/phorge | src/view/phui/PHUIObjectItemView.php | https://github.com/phorgeit/phorge/blob/master/src/view/phui/PHUIObjectItemView.php | Apache-2.0 |
public function setImageHref($image_href) {
PhutilURI::checkHrefType($image_href);
$this->imageHref = $image_href;
return $this;
} | Set the image href attribute
@param string|PhutilURI|null $image_href
@return self | setImageHref | php | phorgeit/phorge | src/view/phui/PHUIObjectItemView.php | https://github.com/phorgeit/phorge/blob/master/src/view/phui/PHUIObjectItemView.php | Apache-2.0 |
public function setIcon($icon) {
phlog(
pht('Deprecated call to setIcon(), use setImageIcon() instead.'));
return $this->setImageIcon($icon);
} | This method has been deprecated, use @{method:setImageIcon} instead.
@deprecated | setIcon | php | phorgeit/phorge | src/view/phui/PHUIObjectItemView.php | https://github.com/phorgeit/phorge/blob/master/src/view/phui/PHUIObjectItemView.php | Apache-2.0 |
public function setTooltip($tooltip) {
$this->tooltip = $tooltip;
return $this;
} | Set a Tooltip.
@param string|null $tooltip
@return self | setTooltip | php | phorgeit/phorge | src/view/phui/PHUISegmentBarSegmentView.php | https://github.com/phorgeit/phorge/blob/master/src/view/phui/PHUISegmentBarSegmentView.php | Apache-2.0 |
public function setTitle($title) {
$this->title = $title;
return $this;
} | Set a title
@param string|null $title
@return self | setTitle | php | phorgeit/phorge | src/view/phui/PHUIInfoView.php | https://github.com/phorgeit/phorge/blob/master/src/view/phui/PHUIInfoView.php | Apache-2.0 |
public function addTextCrumb($text, $href = null, $strikethrough = false) {
return $this->addCrumb(
id(new PHUICrumbView())
->setName($text)
->setHref($href)
->setStrikethrough($strikethrough));
} | Convenience method for adding a simple crumb with just text, or text and
a link.
@param string $text Text of the crumb.
@param string $href (optional) href for the crumb.
@param bool $strikethrough (optional) Strikethrough (=inactive/disabled)
for the crumb.
@return $this | addTextCrumb | php | phorgeit/phorge | src/view/phui/PHUICrumbsView.php | https://github.com/phorgeit/phorge/blob/master/src/view/phui/PHUICrumbsView.php | Apache-2.0 |
public function setAlwaysVisible($always_visible) {
$this->alwaysVisible = $always_visible;
return $this;
} | Make this crumb always visible, even on devices where it would normally
be hidden.
@param bool $always_visible True to make the crumb always visible.
@return $this | setAlwaysVisible | php | phorgeit/phorge | src/view/phui/PHUICrumbView.php | https://github.com/phorgeit/phorge/blob/master/src/view/phui/PHUICrumbView.php | Apache-2.0 |
public function setStrikethrough(bool $strikethrough) {
$this->strikethrough = $strikethrough;
return $this;
} | Render this crumb as strike-through.
@param bool $strikethrough True to render the crumb strike-through.
@return $this | setStrikethrough | php | phorgeit/phorge | src/view/phui/PHUICrumbView.php | https://github.com/phorgeit/phorge/blob/master/src/view/phui/PHUICrumbView.php | Apache-2.0 |
public function setShade($shade) {
phlog(
pht('Deprecated call to setShade(), use setColor() instead.'));
$this->color = $shade;
return $this;
} | This method has been deprecated, use @{method:setColor} instead.
@deprecated | setShade | php | phorgeit/phorge | src/view/phui/PHUITagView.php | https://github.com/phorgeit/phorge/blob/master/src/view/phui/PHUITagView.php | Apache-2.0 |
public function setHref($href) {
PhutilURI::checkHrefType($href);
$this->href = $href;
return $this;
} | Set the href attribute
@param string|PhutilURI|null $href
@return self | setHref | php | phorgeit/phorge | src/view/phui/PHUITagView.php | https://github.com/phorgeit/phorge/blob/master/src/view/phui/PHUITagView.php | Apache-2.0 |
public function setCollapsible($collapsible) {
$this->collapsible = $collapsible;
return $this;
} | Render PHUIBoxView as a <details> instead of a <div> HTML tag.
To be used for collapse/expand in combination with PHUIHeaderView.
@param bool $collapsible True to wrap in <summary> instead of <div> HTML
tag. | setCollapsible | php | phorgeit/phorge | src/view/phui/PHUIBoxView.php | https://github.com/phorgeit/phorge/blob/master/src/view/phui/PHUIBoxView.php | Apache-2.0 |
private function getHoursOfDay() {
$included_datetimes = array();
$day_datetime = $this->getDateTime();
$day_epoch = $day_datetime->format('U');
$day_datetime->modify('+1 day');
$next_day_epoch = $day_datetime->format('U');
$included_time = $day_epoch;
$included_datetime = $this->getDateTime();
while ($included_time < $next_day_epoch) {
$included_datetimes[] = clone $included_datetime;
$included_datetime->modify('+1 hour');
$included_time = $included_datetime->format('U');
}
return $included_datetimes;
} | returns DateTime of each hour in the day | getHoursOfDay | php | phorgeit/phorge | src/view/phui/calendar/PHUICalendarDayView.php | https://github.com/phorgeit/phorge/blob/master/src/view/phui/calendar/PHUICalendarDayView.php | Apache-2.0 |
private function getDatesInMonth() {
$viewer = $this->getViewer();
$timezone = new DateTimeZone($viewer->getTimezoneIdentifier());
$month = $this->month;
$year = $this->year;
list($next_year, $next_month) = $this->getNextYearAndMonth();
$end_date = new DateTime("{$next_year}-{$next_month}-01", $timezone);
list($start_of_week, $end_of_week) = $this->getWeekStartAndEnd();
$days_in_month = id(clone $end_date)->modify('-1 day')->format('d');
$first_month_day_date = new DateTime("{$year}-{$month}-01", $timezone);
$last_month_day_date = id(clone $end_date)->modify('-1 day');
$first_weekday_of_month = $first_month_day_date->format('w');
$last_weekday_of_month = $last_month_day_date->format('w');
$day_date = id(clone $first_month_day_date);
$num_days_display = $days_in_month;
if ($start_of_week !== $first_weekday_of_month) {
$interim_start_num = ($first_weekday_of_month + 7 - $start_of_week) % 7;
$num_days_display += $interim_start_num;
$day_date->modify('-'.$interim_start_num.' days');
}
if ($end_of_week !== $last_weekday_of_month) {
$interim_end_day_num = ($end_of_week - $last_weekday_of_month + 7) % 7;
$num_days_display += $interim_end_day_num;
$end_date->modify('+'.$interim_end_day_num.' days');
}
$days = array();
for ($day = 1; $day <= $num_days_display; $day++) {
$day_epoch = $day_date->format('U');
$end_epoch = $end_date->format('U');
if ($day_epoch >= $end_epoch) {
break;
} else {
$days[] = clone $day_date;
}
$day_date->modify('+1 day');
}
return $days;
} | Return a DateTime object representing the first moment in each day in the
month, according to the user's locale.
@return list List of DateTimes, one for each day. | getDatesInMonth | php | phorgeit/phorge | src/view/phui/calendar/PHUICalendarMonthView.php | https://github.com/phorgeit/phorge/blob/master/src/view/phui/calendar/PHUICalendarMonthView.php | Apache-2.0 |
public function addHeadItem($html) {
if ($html instanceof PhutilSafeHTML) {
$this->headItems[] = $html;
}
} | Insert a HTML element into <head> of the page to render.
@param PhutilSafeHTML $html HTML header to add | addHeadItem | php | phorgeit/phorge | src/view/page/PhabricatorStandardPageView.php | https://github.com/phorgeit/phorge/blob/master/src/view/page/PhabricatorStandardPageView.php | Apache-2.0 |
private function addThing($key, $name, $uri, $type, $icon = null) {
$item = id(new PHUIListItemView())
->setName($name)
->setType($type);
if (phutil_nonempty_string($icon)) {
$item->setIcon($icon);
}
if (strlen($key)) {
$item->setKey($key);
}
if ($uri) {
$item->setHref($uri);
} else {
$href = clone $this->baseURI;
$href->setPath(rtrim($href->getPath().$key, '/').'/');
$href = (string)$href;
$item->setHref($href);
}
return $this->addMenuItem($item);
} | Add a thing in the menu
@param string $key Internal name
@param string $name Human name
@param mixed $uri Destination URI. For example as string or as PhutilURI.
@param string $type Item type. For example see PHUIListItemView constants.
@param string $icon Icon name | addThing | php | phorgeit/phorge | src/view/layout/AphrontSideNavFilterView.php | https://github.com/phorgeit/phorge/blob/master/src/view/layout/AphrontSideNavFilterView.php | Apache-2.0 |
public function getURILineRange($key, $limit) {
$range = $this->getURIData($key);
return self::parseURILineRange($range, $limit);
} | Read line range parameter data from the request.
Applications like Paste, Diffusion, and Harbormaster use "$12-14" in the
URI to allow users to link to particular lines.
@param string $key URI data key to pull line range information from.
@param int|null $limit Maximum length of the range.
@return null|pair<int, int> Null, or beginning and end of the range. | getURILineRange | php | phorgeit/phorge | src/aphront/AphrontRequest.php | https://github.com/phorgeit/phorge/blob/master/src/aphront/AphrontRequest.php | Apache-2.0 |
public function setRequestData(array $request_data) {
$this->requestData = $request_data;
return $this;
} | @task data | setRequestData | php | phorgeit/phorge | src/aphront/AphrontRequest.php | https://github.com/phorgeit/phorge/blob/master/src/aphront/AphrontRequest.php | Apache-2.0 |
public function getRequestData() {
return $this->requestData;
} | @task data | getRequestData | php | phorgeit/phorge | src/aphront/AphrontRequest.php | https://github.com/phorgeit/phorge/blob/master/src/aphront/AphrontRequest.php | Apache-2.0 |
public function getInt($name, $default = null) {
if (isset($this->requestData[$name])) {
// Converting from array to int is "undefined". Don't rely on whatever
// PHP decides to do.
if (is_array($this->requestData[$name])) {
return $default;
}
return (int)$this->requestData[$name];
} else {
return $default;
}
} | @task data | getInt | php | phorgeit/phorge | src/aphront/AphrontRequest.php | https://github.com/phorgeit/phorge/blob/master/src/aphront/AphrontRequest.php | Apache-2.0 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.