repo
stringlengths
7
63
file_url
stringlengths
81
284
file_path
stringlengths
5
200
content
stringlengths
0
32.8k
language
stringclasses
1 value
license
stringclasses
7 values
commit_sha
stringlengths
40
40
retrieved_at
stringdate
2026-01-04 15:02:33
2026-01-05 05:24:06
truncated
bool
2 classes
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/macro/controller/PhabricatorMacroController.php
src/applications/macro/controller/PhabricatorMacroController.php
<?php abstract class PhabricatorMacroController extends PhabricatorController { protected function buildSideNavView($for_app = false) { $nav = new AphrontSideNavFilterView(); $nav->setBaseURI(new PhutilURI($this->getApplicationURI())); if ($for_app) { $nav->addLabel(pht('Create')); $nav->addFilter('', pht('Create Macro'), $this->getApplicationURI('/create/')); } id(new PhabricatorMacroSearchEngine()) ->setViewer($this->getRequest()->getUser()) ->addNavigationItems($nav->getMenu()); return $nav; } public function buildApplicationMenu() { return $this->buildSideNavView($for_app = true)->getMenu(); } protected function buildApplicationCrumbs() { $crumbs = parent::buildApplicationCrumbs(); $can_manage = $this->hasApplicationCapability( PhabricatorMacroManageCapability::CAPABILITY); $crumbs->addAction( id(new PHUIListItemView()) ->setName(pht('Create Macro')) ->setHref($this->getApplicationURI('/create/')) ->setIcon('fa-plus-square') ->setDisabled(!$can_manage) ->setWorkflow(!$can_manage)); return $crumbs; } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/macro/controller/PhabricatorMacroListController.php
src/applications/macro/controller/PhabricatorMacroListController.php
<?php final class PhabricatorMacroListController extends PhabricatorMacroController { public function shouldAllowPublic() { return true; } public function handleRequest(AphrontRequest $request) { $key = $request->getURIData('key'); $controller = id(new PhabricatorApplicationSearchController()) ->setQueryKey($key) ->setSearchEngine(new PhabricatorMacroSearchEngine()) ->setNavigation($this->buildSideNavView()); return $this->delegateToController($controller); } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/macro/controller/PhabricatorMacroMemeController.php
src/applications/macro/controller/PhabricatorMacroMemeController.php
<?php final class PhabricatorMacroMemeController extends PhabricatorMacroController { public function shouldAllowPublic() { return true; } public function handleRequest(AphrontRequest $request) { $macro_name = $request->getStr('macro'); $upper_text = $request->getStr('uppertext'); $lower_text = $request->getStr('lowertext'); $viewer = $request->getViewer(); $file = id(new PhabricatorMemeEngine()) ->setViewer($viewer) ->setTemplate($macro_name) ->setAboveText($request->getStr('above')) ->setBelowText($request->getStr('below')) ->newAsset(); $content = array( 'imageURI' => $file->getViewURI(), ); return id(new AphrontAjaxResponse())->setContent($content); } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/macro/controller/PhabricatorMacroEditController.php
src/applications/macro/controller/PhabricatorMacroEditController.php
<?php final class PhabricatorMacroEditController extends PhameBlogController { public function handleRequest(AphrontRequest $request) { return id(new PhabricatorMacroEditEngine()) ->setController($this) ->buildResponse(); } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/macro/controller/PhabricatorMacroAudioController.php
src/applications/macro/controller/PhabricatorMacroAudioController.php
<?php final class PhabricatorMacroAudioController extends PhabricatorMacroController { public function handleRequest(AphrontRequest $request) { $viewer = $request->getViewer(); $id = $request->getURIData('id'); $this->requireApplicationCapability( PhabricatorMacroManageCapability::CAPABILITY); $macro = id(new PhabricatorMacroQuery()) ->setViewer($viewer) ->requireCapabilities( array( PhabricatorPolicyCapability::CAN_VIEW, )) ->withIDs(array($id)) ->executeOne(); if (!$macro) { return new Aphront404Response(); } $errors = array(); $view_uri = $this->getApplicationURI('/view/'.$macro->getID().'/'); $e_file = null; $file = null; if ($request->isFormPost()) { $xactions = array(); if ($request->getBool('behaviorForm')) { $xactions[] = id(new PhabricatorMacroTransaction()) ->setTransactionType( PhabricatorMacroAudioBehaviorTransaction::TRANSACTIONTYPE) ->setNewValue($request->getStr('audioBehavior')); } else { $file = null; if ($request->getFileExists('file')) { $file = PhabricatorFile::newFromPHPUpload( $_FILES['file'], array( 'name' => $request->getStr('name'), 'authorPHID' => $viewer->getPHID(), 'isExplicitUpload' => true, )); } if ($file) { if (!$file->isAudio()) { $errors[] = pht( 'The file you uploaded is invalid: it is not recognizable as '. 'a valid audio file.'); $e_file = pht('Invalid'); } else { $xactions[] = id(new PhabricatorMacroTransaction()) ->setTransactionType( PhabricatorMacroAudioTransaction::TRANSACTIONTYPE) ->setNewValue($file->getPHID()); } } else { $errors[] = pht( 'To change the audio for a macro, you must upload an audio '. 'file.'); $e_file = pht('Required'); } } if (!$errors) { id(new PhabricatorMacroEditor()) ->setActor($viewer) ->setContinueOnNoEffect(true) ->setContentSourceFromRequest($request) ->applyTransactions($macro, $xactions); return id(new AphrontRedirectResponse())->setURI($view_uri); } } $form = id(new AphrontFormView()) ->addHiddenInput('behaviorForm', 1) ->setUser($viewer); $options = id(new AphrontFormRadioButtonControl()) ->setLabel(pht('Audio Behavior')) ->setName('audioBehavior') ->setValue( nonempty( $macro->getAudioBehavior(), PhabricatorFileImageMacro::AUDIO_BEHAVIOR_NONE)); $options->addButton( PhabricatorFileImageMacro::AUDIO_BEHAVIOR_NONE, pht('Do Not Play'), pht('Do not play audio.')); $options->addButton( PhabricatorFileImageMacro::AUDIO_BEHAVIOR_ONCE, pht('Play Once'), pht('Play audio once, when the viewer looks at the macro.')); $options->addButton( PhabricatorFileImageMacro::AUDIO_BEHAVIOR_LOOP, pht('Play Continuously'), pht( 'Play audio continuously, treating the macro as an audio source. '. 'Best for ambient sounds.')); $form->appendChild($options); $form->appendChild( id(new AphrontFormSubmitControl()) ->setValue(pht('Save Audio Behavior')) ->addCancelButton($view_uri)); $crumbs = $this->buildApplicationCrumbs(); $title = pht('Edit Audio: %s', $macro->getName()); $crumb = pht('Edit Audio'); $crumbs->addTextCrumb(pht('Macro "%s"', $macro->getName()), $view_uri); $crumbs->addTextCrumb($crumb, $request->getRequestURI()); $crumbs->setBorder(true); $upload_form = id(new AphrontFormView()) ->setEncType('multipart/form-data') ->setUser($viewer) ->appendChild( id(new AphrontFormFileControl()) ->setLabel(pht('Audio File')) ->setName('file')) ->appendChild( id(new AphrontFormSubmitControl()) ->setValue(pht('Upload File'))); $upload = id(new PHUIObjectBoxView()) ->setHeaderText(pht('Upload New Audio')) ->setBackground(PHUIObjectBoxView::BLUE_PROPERTY) ->setForm($upload_form); $form_box = id(new PHUIObjectBoxView()) ->setHeaderText(pht('Behavior')) ->setFormErrors($errors) ->setBackground(PHUIObjectBoxView::BLUE_PROPERTY) ->setForm($form); $header = id(new PHUIHeaderView()) ->setHeader($title) ->setHeaderIcon('fa-pencil'); $view = id(new PHUITwoColumnView()) ->setHeader($header) ->setFooter(array( $form_box, $upload, )); return $this->newPage() ->setTitle($title) ->setCrumbs($crumbs) ->appendChild($view); } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/macro/controller/PhabricatorMacroMemeDialogController.php
src/applications/macro/controller/PhabricatorMacroMemeDialogController.php
<?php final class PhabricatorMacroMemeDialogController extends PhabricatorMacroController { public function handleRequest(AphrontRequest $request) { $viewer = $request->getViewer(); $phid = head($request->getArr('macro')); $above = $request->getStr('above'); $below = $request->getStr('below'); $e_macro = true; $errors = array(); if ($request->isDialogFormPost()) { if (!$phid) { $e_macro = pht('Required'); $errors[] = pht('Macro name is required.'); } else { $macro = id(new PhabricatorMacroQuery()) ->setViewer($viewer) ->withPHIDs(array($phid)) ->executeOne(); if (!$macro) { $e_macro = pht('Invalid'); $errors[] = pht('No such macro.'); } } if (!$errors) { $options = new PhutilSimpleOptions(); $data = array( 'src' => $macro->getName(), 'above' => $above, 'below' => $below, ); $string = $options->unparse($data, $escape = '}'); $result = array( 'text' => "{meme, {$string}}", ); return id(new AphrontAjaxResponse())->setContent($result); } } $view = id(new AphrontFormView()) ->setUser($viewer) ->appendControl( id(new AphrontFormTokenizerControl()) ->setLabel(pht('Macro')) ->setName('macro') ->setLimit(1) ->setDatasource(new PhabricatorMacroDatasource()) ->setError($e_macro)) ->appendChild( id(new AphrontFormTextControl()) ->setLabel(pht('Above')) ->setName('above') ->setValue($above)) ->appendChild( id(new AphrontFormTextControl()) ->setLabel(pht('Below')) ->setName('below') ->setValue($below)); $dialog = id(new AphrontDialogView()) ->setUser($viewer) ->setTitle(pht('Create Meme')) ->appendForm($view) ->addCancelButton('/') ->addSubmitButton(pht('Llama Diorama')); return id(new AphrontDialogResponse())->setDialog($dialog); } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/macro/storage/PhabricatorMacroTransaction.php
src/applications/macro/storage/PhabricatorMacroTransaction.php
<?php final class PhabricatorMacroTransaction extends PhabricatorModularTransaction { public function getApplicationName() { return 'file'; } public function getTableName() { return 'macro_transaction'; } public function getApplicationTransactionType() { return PhabricatorMacroMacroPHIDType::TYPECONST; } public function getApplicationTransactionCommentObject() { return new PhabricatorMacroTransactionComment(); } public function getBaseTransactionClass() { return 'PhabricatorMacroTransactionType'; } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/macro/storage/PhabricatorMacroTransactionComment.php
src/applications/macro/storage/PhabricatorMacroTransactionComment.php
<?php final class PhabricatorMacroTransactionComment extends PhabricatorApplicationTransactionComment { public function getApplicationTransactionObject() { return new PhabricatorMacroTransaction(); } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/macro/storage/PhabricatorFileImageMacro.php
src/applications/macro/storage/PhabricatorFileImageMacro.php
<?php final class PhabricatorFileImageMacro extends PhabricatorFileDAO implements PhabricatorSubscribableInterface, PhabricatorApplicationTransactionInterface, PhabricatorFlaggableInterface, PhabricatorTokenReceiverInterface, PhabricatorPolicyInterface { protected $authorPHID; protected $filePHID; protected $name; protected $isDisabled = 0; protected $audioPHID; protected $audioBehavior = self::AUDIO_BEHAVIOR_NONE; protected $mailKey; private $file = self::ATTACHABLE; private $audio = self::ATTACHABLE; const AUDIO_BEHAVIOR_NONE = 'audio:none'; const AUDIO_BEHAVIOR_ONCE = 'audio:once'; const AUDIO_BEHAVIOR_LOOP = 'audio:loop'; public function attachFile(PhabricatorFile $file) { $this->file = $file; return $this; } public function getFile() { return $this->assertAttached($this->file); } public function attachAudio(PhabricatorFile $audio = null) { $this->audio = $audio; return $this; } public function getAudio() { return $this->assertAttached($this->audio); } public static function initializeNewFileImageMacro(PhabricatorUser $actor) { $macro = id(new self()) ->setAuthorPHID($actor->getPHID()); return $macro; } protected function getConfiguration() { return array( self::CONFIG_AUX_PHID => true, self::CONFIG_COLUMN_SCHEMA => array( 'name' => 'text128', 'authorPHID' => 'phid?', 'isDisabled' => 'bool', 'audioPHID' => 'phid?', 'audioBehavior' => 'text64', 'mailKey' => 'bytes20', ), self::CONFIG_KEY_SCHEMA => array( 'name' => array( 'columns' => array('name'), 'unique' => true, ), 'key_disabled' => array( 'columns' => array('isDisabled'), ), 'key_dateCreated' => array( 'columns' => array('dateCreated'), ), ), ) + parent::getConfiguration(); } public function generatePHID() { return PhabricatorPHID::generateNewPHID( PhabricatorMacroMacroPHIDType::TYPECONST); } public function save() { if (!$this->getMailKey()) { $this->setMailKey(Filesystem::readRandomCharacters(20)); } return parent::save(); } public function getViewURI() { return '/macro/view/'.$this->getID().'/'; } /* -( PhabricatorApplicationTransactionInterface )------------------------- */ public function getApplicationTransactionEditor() { return new PhabricatorMacroEditor(); } public function getApplicationTransactionTemplate() { return new PhabricatorMacroTransaction(); } /* -( PhabricatorSubscribableInterface )----------------------------------- */ public function isAutomaticallySubscribed($phid) { return false; } /* -( PhabricatorTokenRecevierInterface )---------------------------------- */ public function getUsersToNotifyOfTokenGiven() { return array( $this->getAuthorPHID(), ); } /* -( PhabricatorPolicyInterface )----------------------------------------- */ public function getCapabilities() { return array( PhabricatorPolicyCapability::CAN_VIEW, PhabricatorPolicyCapability::CAN_EDIT, ); } public function getPolicy($capability) { switch ($capability) { case PhabricatorPolicyCapability::CAN_VIEW: return PhabricatorPolicies::getMostOpenPolicy(); case PhabricatorPolicyCapability::CAN_EDIT: $app = PhabricatorApplication::getByClass( 'PhabricatorMacroApplication'); return $app->getPolicy(PhabricatorMacroManageCapability::CAPABILITY); } } public function hasAutomaticCapability($capability, PhabricatorUser $viewer) { return false; } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/macro/query/PhabricatorMacroTransactionQuery.php
src/applications/macro/query/PhabricatorMacroTransactionQuery.php
<?php final class PhabricatorMacroTransactionQuery extends PhabricatorApplicationTransactionQuery { public function getTemplateApplicationTransaction() { return new PhabricatorMacroTransaction(); } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/macro/query/PhabricatorMacroQuery.php
src/applications/macro/query/PhabricatorMacroQuery.php
<?php final class PhabricatorMacroQuery extends PhabricatorCursorPagedPolicyAwareQuery { private $ids; private $phids; private $authorPHIDs; private $names; private $nameLike; private $namePrefix; private $dateCreatedAfter; private $dateCreatedBefore; private $flagColor; private $needFiles; private $status = 'status-any'; const STATUS_ANY = 'status-any'; const STATUS_ACTIVE = 'status-active'; const STATUS_DISABLED = 'status-disabled'; public static function getStatusOptions() { return array( self::STATUS_ACTIVE => pht('Active Macros'), self::STATUS_DISABLED => pht('Disabled Macros'), self::STATUS_ANY => pht('Active and Disabled Macros'), ); } public static function getFlagColorsOptions() { $options = array( '-1' => pht('(No Filtering)'), '-2' => pht('(Marked With Any Flag)'), ); foreach (PhabricatorFlagColor::getColorNameMap() as $color => $name) { $options[$color] = $name; } return $options; } public function withIDs(array $ids) { $this->ids = $ids; return $this; } public function withPHIDs(array $phids) { $this->phids = $phids; return $this; } public function withAuthorPHIDs(array $author_phids) { $this->authorPHIDs = $author_phids; return $this; } public function withNameLike($name) { $this->nameLike = $name; return $this; } public function withNames(array $names) { $this->names = $names; return $this; } public function withNamePrefix($prefix) { $this->namePrefix = $prefix; return $this; } public function withStatus($status) { $this->status = $status; return $this; } public function withDateCreatedBefore($date_created_before) { $this->dateCreatedBefore = $date_created_before; return $this; } public function withDateCreatedAfter($date_created_after) { $this->dateCreatedAfter = $date_created_after; return $this; } public function withFlagColor($flag_color) { $this->flagColor = $flag_color; return $this; } public function needFiles($need_files) { $this->needFiles = $need_files; return $this; } public function newResultObject() { return new PhabricatorFileImageMacro(); } protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) { $where = parent::buildWhereClauseParts($conn); if ($this->ids !== null) { $where[] = qsprintf( $conn, 'm.id IN (%Ld)', $this->ids); } if ($this->phids !== null) { $where[] = qsprintf( $conn, 'm.phid IN (%Ls)', $this->phids); } if ($this->authorPHIDs !== null) { $where[] = qsprintf( $conn, 'm.authorPHID IN (%Ls)', $this->authorPHIDs); } if (($this->nameLike !== null) && strlen($this->nameLike)) { $where[] = qsprintf( $conn, 'm.name LIKE %~', $this->nameLike); } if ($this->names !== null) { $where[] = qsprintf( $conn, 'm.name IN (%Ls)', $this->names); } if (($this->namePrefix !== null) && strlen($this->namePrefix)) { $where[] = qsprintf( $conn, 'm.name LIKE %>', $this->namePrefix); } switch ($this->status) { case self::STATUS_ACTIVE: $where[] = qsprintf( $conn, 'm.isDisabled = 0'); break; case self::STATUS_DISABLED: $where[] = qsprintf( $conn, 'm.isDisabled = 1'); break; case self::STATUS_ANY: break; default: throw new Exception(pht("Unknown status '%s'!", $this->status)); } if ($this->dateCreatedAfter) { $where[] = qsprintf( $conn, 'm.dateCreated >= %d', $this->dateCreatedAfter); } if ($this->dateCreatedBefore) { $where[] = qsprintf( $conn, 'm.dateCreated <= %d', $this->dateCreatedBefore); } if ($this->flagColor != '-1' && $this->flagColor !== null) { if ($this->flagColor == '-2') { $flag_colors = array_keys(PhabricatorFlagColor::getColorNameMap()); } else { $flag_colors = array($this->flagColor); } $flags = id(new PhabricatorFlagQuery()) ->withOwnerPHIDs(array($this->getViewer()->getPHID())) ->withTypes(array(PhabricatorMacroMacroPHIDType::TYPECONST)) ->withColors($flag_colors) ->setViewer($this->getViewer()) ->execute(); if (empty($flags)) { throw new PhabricatorEmptyQueryException(pht('No matching flags.')); } else { $where[] = qsprintf( $conn, 'm.phid IN (%Ls)', mpull($flags, 'getObjectPHID')); } } return $where; } protected function didFilterPage(array $macros) { if ($this->needFiles) { $file_phids = mpull($macros, 'getFilePHID'); $files = id(new PhabricatorFileQuery()) ->setViewer($this->getViewer()) ->setParentQuery($this) ->withPHIDs($file_phids) ->execute(); $files = mpull($files, null, 'getPHID'); foreach ($macros as $key => $macro) { $file = idx($files, $macro->getFilePHID()); if (!$file) { unset($macros[$key]); continue; } $macro->attachFile($file); } } return $macros; } protected function getPrimaryTableAlias() { return 'm'; } public function getQueryApplicationClass() { return 'PhabricatorMacroApplication'; } public function getOrderableColumns() { return parent::getOrderableColumns() + array( 'name' => array( 'table' => 'm', 'column' => 'name', 'type' => 'string', 'reverse' => true, 'unique' => true, ), ); } protected function newPagingMapFromPartialObject($object) { return array( 'id' => (int)$object->getID(), 'name' => $object->getName(), ); } public function getBuiltinOrders() { return array( 'name' => array( 'vector' => array('name'), 'name' => pht('Name'), ), ) + parent::getBuiltinOrders(); } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/macro/query/PhabricatorMacroSearchEngine.php
src/applications/macro/query/PhabricatorMacroSearchEngine.php
<?php final class PhabricatorMacroSearchEngine extends PhabricatorApplicationSearchEngine { public function getResultTypeDescription() { return pht('Macros'); } public function getApplicationClassName() { return 'PhabricatorMacroApplication'; } public function newQuery() { return id(new PhabricatorMacroQuery()) ->needFiles(true); } protected function buildCustomSearchFields() { return array( id(new PhabricatorSearchSelectField()) ->setLabel(pht('Status')) ->setKey('status') ->setOptions(PhabricatorMacroQuery::getStatusOptions()), id(new PhabricatorUsersSearchField()) ->setLabel(pht('Authors')) ->setKey('authorPHIDs') ->setAliases(array('author', 'authors')), id(new PhabricatorSearchTextField()) ->setLabel(pht('Name Contains')) ->setKey('nameLike'), id(new PhabricatorSearchStringListField()) ->setLabel(pht('Exact Names')) ->setKey('names'), id(new PhabricatorSearchSelectField()) ->setLabel(pht('Marked with Flag')) ->setKey('flagColor') ->setDefault('-1') ->setOptions(PhabricatorMacroQuery::getFlagColorsOptions()), id(new PhabricatorSearchDateField()) ->setLabel(pht('Created After')) ->setKey('createdStart'), id(new PhabricatorSearchDateField()) ->setLabel(pht('Created Before')) ->setKey('createdEnd'), ); } protected function getDefaultFieldOrder() { return array( '...', 'createdStart', 'createdEnd', ); } protected function buildQueryFromParameters(array $map) { $query = $this->newQuery(); if ($map['authorPHIDs']) { $query->withAuthorPHIDs($map['authorPHIDs']); } if ($map['status']) { $query->withStatus($map['status']); } if ($map['names']) { $query->withNames($map['names']); } if (strlen($map['nameLike'])) { $query->withNameLike($map['nameLike']); } if ($map['createdStart']) { $query->withDateCreatedAfter($map['createdStart']); } if ($map['createdEnd']) { $query->withDateCreatedBefore($map['createdEnd']); } if ($map['flagColor'] !== null) { $query->withFlagColor($map['flagColor']); } return $query; } protected function getURI($path) { return '/macro/'.$path; } protected function getBuiltinQueryNames() { $names = array( 'active' => pht('Active'), 'all' => pht('All'), ); if ($this->requireViewer()->isLoggedIn()) { $names['authored'] = pht('Authored'); } return $names; } public function buildSavedQueryFromBuiltin($query_key) { $query = $this->newSavedQuery(); $query->setQueryKey($query_key); switch ($query_key) { case 'active': return $query->setParameter( 'status', PhabricatorMacroQuery::STATUS_ACTIVE); case 'all': return $query->setParameter( 'status', PhabricatorMacroQuery::STATUS_ANY); case 'authored': return $query->setParameter( 'authorPHIDs', array($this->requireViewer()->getPHID())); } return parent::buildSavedQueryFromBuiltin($query_key); } protected function renderResultList( array $macros, PhabricatorSavedQuery $query, array $handles) { assert_instances_of($macros, 'PhabricatorFileImageMacro'); $viewer = $this->requireViewer(); $handles = $viewer->loadHandles(mpull($macros, 'getAuthorPHID')); $xform = PhabricatorFileTransform::getTransformByKey( PhabricatorFileThumbnailTransform::TRANSFORM_PINBOARD); $pinboard = new PHUIPinboardView(); foreach ($macros as $macro) { $file = $macro->getFile(); $item = id(new PHUIPinboardItemView()) ->setUser($viewer) ->setObject($macro); if ($file) { $item->setImageURI($file->getURIForTransform($xform)); list($x, $y) = $xform->getTransformedDimensions($file); $item->setImageSize($x, $y); } if ($macro->getDateCreated()) { $datetime = phabricator_date($macro->getDateCreated(), $viewer); $item->appendChild( phutil_tag( 'div', array(), pht('Created on %s', $datetime))); } else { // Very old macros don't have a creation date. Rendering something // keeps all the pins at the same height and avoids flow issues. $item->appendChild( phutil_tag( 'div', array(), pht('Created in ages long past'))); } if ($macro->getAuthorPHID()) { $author_handle = $handles[$macro->getAuthorPHID()]; $item->appendChild( pht('Created by %s', $author_handle->renderLink())); } $item->setURI($this->getApplicationURI('/view/'.$macro->getID().'/')); $item->setDisabled($macro->getisDisabled()); $item->setHeader($macro->getName()); $pinboard->addItem($item); } $result = new PhabricatorApplicationSearchResultView(); $result->setContent($pinboard); return $result; } protected function getNewUserBody() { $create_button = id(new PHUIButtonView()) ->setTag('a') ->setText(pht('Create a Macro')) ->setHref('/macro/create/') ->setColor(PHUIButtonView::GREEN); $icon = $this->getApplication()->getIcon(); $app_name = $this->getApplication()->getName(); $view = id(new PHUIBigInfoView()) ->setIcon($icon) ->setTitle(pht('Welcome to %s', $app_name)) ->setDescription( pht('Create easy to remember shortcuts to images and memes.')) ->addAction($create_button); return $view; } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/macro/mail/PhabricatorMacroMailReceiver.php
src/applications/macro/mail/PhabricatorMacroMailReceiver.php
<?php final class PhabricatorMacroMailReceiver extends PhabricatorObjectMailReceiver { public function isEnabled() { return PhabricatorApplication::isClassInstalled( 'PhabricatorManiphestApplication'); } protected function getObjectPattern() { return 'MCRO[1-9]\d*'; } protected function loadObject($pattern, PhabricatorUser $viewer) { $id = (int)substr($pattern, 4); return id(new PhabricatorMacroQuery()) ->setViewer($viewer) ->withIDs(array($id)) ->executeOne(); } protected function getTransactionReplyHandler() { return new PhabricatorMacroReplyHandler(); } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/macro/mail/PhabricatorMacroReplyHandler.php
src/applications/macro/mail/PhabricatorMacroReplyHandler.php
<?php final class PhabricatorMacroReplyHandler extends PhabricatorApplicationTransactionReplyHandler { public function validateMailReceiver($mail_receiver) { if (!($mail_receiver instanceof PhabricatorFileImageMacro)) { throw new Exception( pht('Mail receiver is not a %s!', 'PhabricatorFileImageMacro')); } } public function getObjectPrefix() { return 'MCRO'; } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/macro/editor/PhabricatorMacroEditor.php
src/applications/macro/editor/PhabricatorMacroEditor.php
<?php final class PhabricatorMacroEditor extends PhabricatorApplicationTransactionEditor { public function getEditorApplicationClass() { return 'PhabricatorMacroApplication'; } public function getEditorObjectsDescription() { return pht('Macros'); } public function getCreateObjectTitle($author, $object) { return pht('%s created this macro.', $author); } public function getCreateObjectTitleForFeed($author, $object) { return pht('%s created %s.', $author, $object); } protected function shouldSendMail( PhabricatorLiskDAO $object, array $xactions) { return true; } protected function buildReplyHandler(PhabricatorLiskDAO $object) { return id(new PhabricatorMacroReplyHandler()) ->setMailReceiver($object); } protected function buildMailTemplate(PhabricatorLiskDAO $object) { $name = $object->getName(); $name = 'Image Macro "'.$name.'"'; return id(new PhabricatorMetaMTAMail()) ->setSubject($name); } protected function getMailTo(PhabricatorLiskDAO $object) { return array( $this->requireActor()->getPHID(), ); } protected function buildMailBody( PhabricatorLiskDAO $object, array $xactions) { $body = parent::buildMailBody($object, $xactions); $body->addLinkSection( pht('MACRO DETAIL'), PhabricatorEnv::getProductionURI('/macro/view/'.$object->getID().'/')); return $body; } protected function getMailSubjectPrefix() { return pht('[Macro]'); } protected function shouldPublishFeedStory( PhabricatorLiskDAO $object, array $xactions) { return true; } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/macro/editor/PhabricatorMacroEditEngine.php
src/applications/macro/editor/PhabricatorMacroEditEngine.php
<?php final class PhabricatorMacroEditEngine extends PhabricatorEditEngine { const ENGINECONST = 'macro.image'; public function getEngineName() { return pht('Macro Image'); } public function getSummaryHeader() { return pht('Configure Macro Image Forms'); } public function getSummaryText() { return pht('Configure creation and editing of Macro images.'); } public function getEngineApplicationClass() { return 'PhabricatorMacroApplication'; } public function isEngineConfigurable() { return false; } protected function newEditableObject() { $viewer = $this->getViewer(); return PhabricatorFileImageMacro::initializeNewFileImageMacro($viewer); } protected function newObjectQuery() { return new PhabricatorMacroQuery(); } protected function getObjectCreateTitleText($object) { return pht('Create New Macro'); } protected function getObjectEditTitleText($object) { return pht('Edit Macro %s', $object->getName()); } protected function getObjectEditShortText($object) { return $object->getName(); } protected function getObjectCreateShortText() { return pht('Create Macro'); } protected function getObjectName() { return pht('Macro'); } protected function getObjectViewURI($object) { return $object->getViewURI(); } protected function getEditorURI() { return $this->getApplication()->getApplicationURI('edit/'); } protected function getCreateNewObjectPolicy() { return $this->getApplication()->getPolicy( PhabricatorMacroManageCapability::CAPABILITY); } protected function willConfigureFields($object, array $fields) { if ($this->getIsCreate()) { $subscribers_field = idx($fields, PhabricatorSubscriptionsEditEngineExtension::FIELDKEY); if ($subscribers_field) { // By default, hide the subscribers field when creating a macro // because it makes the workflow SO HARD and wastes SO MUCH TIME. $subscribers_field->setIsHidden(true); } } return $fields; } protected function buildCustomEditFields($object) { return array( id(new PhabricatorTextEditField()) ->setKey('name') ->setLabel(pht('Name')) ->setDescription(pht('Macro name.')) ->setConduitDescription(pht('Name of the macro.')) ->setConduitTypeDescription(pht('New macro name.')) ->setTransactionType(PhabricatorMacroNameTransaction::TRANSACTIONTYPE) ->setIsRequired(true) ->setValue($object->getName()), id(new PhabricatorFileEditField()) ->setKey('filePHID') ->setLabel(pht('Image File')) ->setDescription(pht('Image file to import.')) ->setTransactionType(PhabricatorMacroFileTransaction::TRANSACTIONTYPE) ->setConduitDescription(pht('File PHID to import.')) ->setConduitTypeDescription(pht('File PHID.')) ->setValue($object->getFilePHID()), ); } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/macro/xaction/PhabricatorMacroTransactionType.php
src/applications/macro/xaction/PhabricatorMacroTransactionType.php
<?php abstract class PhabricatorMacroTransactionType extends PhabricatorModularTransactionType {}
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/macro/xaction/PhabricatorMacroAudioTransaction.php
src/applications/macro/xaction/PhabricatorMacroAudioTransaction.php
<?php final class PhabricatorMacroAudioTransaction extends PhabricatorMacroTransactionType { const TRANSACTIONTYPE = 'macro:audio'; public function generateOldValue($object) { return $object->getAudioPHID(); } public function applyInternalEffects($object, $value) { $object->setAudioPHID($value); } public function extractFilePHIDs($object, $value) { $file_phids = array(); if ($value) { $file_phids[] = $value; } return $file_phids; } public function getTitle() { $new = $this->getNewValue(); $old = $this->getOldValue(); if (!$old) { return pht( '%s attached audio: %s.', $this->renderAuthor(), $this->renderHandle($new)); } else { return pht( '%s changed the audio for this macro from %s to %s.', $this->renderAuthor(), $this->renderHandle($old), $this->renderHandle($new)); } } public function getTitleForFeed() { $new = $this->getNewValue(); $old = $this->getOldValue(); if (!$old) { return pht( '%s attached audio to %s: %s.', $this->renderAuthor(), $this->renderObject(), $this->renderHandle($new)); } else { return pht( '%s changed the audio for %s from %s to %s.', $this->renderAuthor(), $this->renderObject(), $this->renderHandle($old), $this->renderHandle($new)); } } public function getIcon() { return 'fa-music'; } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/macro/xaction/PhabricatorMacroAudioBehaviorTransaction.php
src/applications/macro/xaction/PhabricatorMacroAudioBehaviorTransaction.php
<?php final class PhabricatorMacroAudioBehaviorTransaction extends PhabricatorMacroTransactionType { const TRANSACTIONTYPE = 'macro:audiobehavior'; public function generateOldValue($object) { return $object->getAudioBehavior(); } public function applyInternalEffects($object, $value) { $object->setAudioBehavior($value); } public function getTitle() { $new = $this->getNewValue(); $old = $this->getOldValue(); switch ($new) { case PhabricatorFileImageMacro::AUDIO_BEHAVIOR_ONCE: return pht( '%s set the audio to play once.', $this->renderAuthor()); case PhabricatorFileImageMacro::AUDIO_BEHAVIOR_LOOP: return pht( '%s set the audio to loop.', $this->renderAuthor()); default: return pht( '%s disabled the audio for this macro.', $this->renderAuthor()); } } public function getTitleForFeed() { $new = $this->getNewValue(); $old = $this->getOldValue(); switch ($new) { case PhabricatorFileImageMacro::AUDIO_BEHAVIOR_ONCE: return pht( '%s set the audio for %s to play once.', $this->renderAuthor(), $this->renderObject()); case PhabricatorFileImageMacro::AUDIO_BEHAVIOR_LOOP: return pht( '%s set the audio for %s to loop.', $this->renderAuthor(), $this->renderObject()); default: return pht( '%s disabled the audio for %s.', $this->renderAuthor(), $this->renderObject()); } } public function getIcon() { $new = $this->getNewValue(); switch ($new) { case PhabricatorFileImageMacro::AUDIO_BEHAVIOR_ONCE: return 'fa-play-circle'; case PhabricatorFileImageMacro::AUDIO_BEHAVIOR_LOOP: return 'fa-repeat'; default: return 'fa-pause-circle'; } } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/macro/xaction/PhabricatorMacroDisabledTransaction.php
src/applications/macro/xaction/PhabricatorMacroDisabledTransaction.php
<?php final class PhabricatorMacroDisabledTransaction extends PhabricatorMacroTransactionType { const TRANSACTIONTYPE = 'macro:disabled'; public function generateOldValue($object) { return $object->getIsDisabled(); } public function applyInternalEffects($object, $value) { $object->setIsDisabled($value); } public function getTitle() { if ($this->getNewValue()) { return pht( '%s disabled this macro.', $this->renderAuthor()); } else { return pht( '%s restored this macro.', $this->renderAuthor()); } } public function getTitleForFeed() { if ($this->getNewValue()) { return pht( '%s disabled %s.', $this->renderAuthor(), $this->renderObject()); } else { return pht( '%s restored %s.', $this->renderAuthor(), $this->renderObject()); } } public function getIcon() { if ($this->getNewValue()) { return 'fa-ban'; } else { return 'fa-check'; } } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/macro/xaction/PhabricatorMacroNameTransaction.php
src/applications/macro/xaction/PhabricatorMacroNameTransaction.php
<?php final class PhabricatorMacroNameTransaction extends PhabricatorMacroTransactionType { const TRANSACTIONTYPE = 'macro:name'; public function generateOldValue($object) { return $object->getName(); } public function applyInternalEffects($object, $value) { $object->setName($value); } public function getTitle() { return pht( '%s renamed this macro from %s to %s.', $this->renderAuthor(), $this->renderOldValue(), $this->renderNewValue()); } public function getTitleForFeed() { return pht( '%s renamed %s from %s to %s.', $this->renderAuthor(), $this->renderObject(), $this->renderOldValue(), $this->renderNewValue()); } public function validateTransactions($object, array $xactions) { $errors = array(); $viewer = $this->getActor(); if ($this->isEmptyTextTransaction($object->getName(), $xactions)) { $errors[] = $this->newRequiredError( pht('Macros must have a name.')); return $errors; } $max_length = $object->getColumnMaximumByteLength('name'); foreach ($xactions as $xaction) { $old_value = $this->generateOldValue($object); $new_value = $xaction->getNewValue(); $new_length = strlen($new_value); if ($new_length > $max_length) { $errors[] = $this->newInvalidError( pht('The name can be no longer than %s characters.', new PhutilNumber($max_length))); } if (!self::isValidMacroName($new_value)) { // This says "emoji", but the actual rule we implement is "all other // unicode characters are also fine". $errors[] = $this->newInvalidError( pht( 'Macro name "%s" be: at least three characters long; and contain '. 'only lowercase letters, digits, hyphens, colons, underscores, '. 'and emoji; and not be composed entirely of latin symbols.', $new_value), $xaction); } // Check name is unique when updating / creating if ($old_value != $new_value) { $macro = id(new PhabricatorMacroQuery()) ->setViewer($viewer) ->withNames(array($new_value)) ->executeOne(); if ($macro) { $errors[] = $this->newInvalidError( pht('Macro "%s" already exists.', $new_value)); } } } return $errors; } public static function isValidMacroName($name) { if (preg_match('/^[:_-]+\z/', $name)) { return false; } // Accept trivial macro names. if (preg_match('/^[a-z0-9:_-]{3,}\z/', $name)) { return true; } // Reject names with fewer than 3 glyphs. $length = phutil_utf8v_combined($name); if (count($length) < 3) { return false; } // Check character-by-character for any symbols that we don't want. $characters = phutil_utf8v($name); foreach ($characters as $character) { if (ord($character[0]) > 0x7F) { continue; } if (preg_match('/^[^a-z0-9:_-]/', $character)) { return false; } } return true; } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/macro/xaction/PhabricatorMacroFileTransaction.php
src/applications/macro/xaction/PhabricatorMacroFileTransaction.php
<?php final class PhabricatorMacroFileTransaction extends PhabricatorMacroTransactionType { const TRANSACTIONTYPE = 'macro:file'; public function generateOldValue($object) { return $object->getFilePHID(); } public function applyInternalEffects($object, $value) { $object->setFilePHID($value); } public function extractFilePHIDs($object, $value) { return array($value); } public function getTitle() { return pht( '%s changed the image for this macro.', $this->renderAuthor()); } public function getTitleForFeed() { return pht( '%s changed the image for %s.', $this->renderAuthor(), $this->renderObject()); } public function validateTransactions($object, array $xactions) { $errors = array(); $viewer = $this->getActor(); $old_phid = $object->getFilePHID(); foreach ($xactions as $xaction) { $file_phid = $xaction->getNewValue(); if (!$old_phid) { if ($this->isEmptyTextTransaction($file_phid, $xactions)) { $errors[] = $this->newRequiredError( pht('Image macros must have a file.')); return $errors; } } // Only validate if file was uploaded if ($file_phid) { $file = id(new PhabricatorFileQuery()) ->setViewer($viewer) ->withPHIDs(array($file_phid)) ->executeOne(); if (!$file) { $errors[] = $this->newInvalidError( pht('"%s" is not a valid file PHID.', $file_phid)); } else { if (!$file->isViewableImage()) { $mime_type = $file->getMimeType(); $errors[] = $this->newInvalidError( pht('File mime type of "%s" is not a valid viewable image.', $mime_type)); } } } } return $errors; } public function getIcon() { return 'fa-file-image-o'; } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/macro/xaction/__tests__/PhabricatorMacroTestCase.php
src/applications/macro/xaction/__tests__/PhabricatorMacroTestCase.php
<?php final class PhabricatorMacroTestCase extends PhabricatorTestCase { public function testMacroNames() { $lit = "\xF0\x9F\x94\xA5"; $combining_diaeresis = "\xCC\x88"; $cases = array( // Only 2 glyphs long. "u{$combining_diaeresis}n" => false, "{$lit}{$lit}" => false, // Too short. 'a' => false, '' => false, // Bad characters. 'yes!' => false, "{$lit} {$lit} {$lit}" => false, "aaa\nbbb" => false, 'aaa~' => false, 'aaa`' => false, // Special rejections for only latin symbols. '---' => false, '___' => false, '-_-' => false, ':::' => false, '-_:' => false, "{$lit}{$lit}{$lit}" => true, 'bwahahaha' => true, "u{$combining_diaeresis}nt" => true, 'a-a-a-a' => true, ); foreach ($cases as $input => $expect) { $this->assertEqual( $expect, PhabricatorMacroNameTransaction::isValidMacroName($input), pht('Validity of macro "%s"', $input)); } } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/macro/application/PhabricatorMacroApplication.php
src/applications/macro/application/PhabricatorMacroApplication.php
<?php final class PhabricatorMacroApplication extends PhabricatorApplication { public function getBaseURI() { return '/macro/'; } public function getName() { return pht('Macro'); } public function getShortDescription() { return pht('Image Macros and Memes'); } public function getIcon() { return 'fa-file-image-o'; } public function getTitleGlyph() { return "\xE2\x9A\x98"; } public function getApplicationGroup() { return self::GROUP_UTILITIES; } public function getRoutes() { return array( '/macro/' => array( '(query/(?P<key>[^/]+)/)?' => 'PhabricatorMacroListController', 'create/' => 'PhabricatorMacroEditController', 'view/(?P<id>[1-9]\d*)/' => 'PhabricatorMacroViewController', $this->getEditRoutePattern('edit/') => 'PhabricatorMacroEditController', 'audio/(?P<id>[1-9]\d*)/' => 'PhabricatorMacroAudioController', 'disable/(?P<id>[1-9]\d*)/' => 'PhabricatorMacroDisableController', 'meme/' => 'PhabricatorMacroMemeController', 'meme/create/' => 'PhabricatorMacroMemeDialogController', ), ); } protected function getCustomCapabilities() { return array( PhabricatorMacroManageCapability::CAPABILITY => array( 'caption' => pht('Allows creating and editing macros.'), ), ); } public function getMailCommandObjects() { return array( 'macro' => array( 'name' => pht('Email Commands: Macros'), 'header' => pht('Interacting with Macros'), 'object' => new PhabricatorFileImageMacro(), 'summary' => pht( 'This page documents the commands you can use to interact with '. 'image macros.'), ), ); } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/macro/phid/PhabricatorMacroMacroPHIDType.php
src/applications/macro/phid/PhabricatorMacroMacroPHIDType.php
<?php final class PhabricatorMacroMacroPHIDType extends PhabricatorPHIDType { const TYPECONST = 'MCRO'; public function getTypeName() { return pht('Image Macro'); } public function getPHIDTypeApplicationClass() { return 'PhabricatorMacroApplication'; } public function getTypeIcon() { return 'fa-meh-o'; } public function newObject() { return new PhabricatorFileImageMacro(); } protected function buildQueryForObjects( PhabricatorObjectQuery $query, array $phids) { return id(new PhabricatorMacroQuery()) ->withPHIDs($phids); } public function loadHandles( PhabricatorHandleQuery $query, array $handles, array $objects) { foreach ($handles as $phid => $handle) { $macro = $objects[$phid]; $id = $macro->getID(); $name = $macro->getName(); $handle->setName($name); $handle->setFullName(pht('Image Macro "%s"', $name)); $handle->setURI("/macro/view/{$id}/"); } } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/macro/conduit/MacroConduitAPIMethod.php
src/applications/macro/conduit/MacroConduitAPIMethod.php
<?php abstract class MacroConduitAPIMethod extends ConduitAPIMethod { final public function getApplication() { return PhabricatorApplication::getByClass('PhabricatorMacroApplication'); } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/macro/conduit/MacroEditConduitAPIMethod.php
src/applications/macro/conduit/MacroEditConduitAPIMethod.php
<?php final class MacroEditConduitAPIMethod extends PhabricatorEditEngineAPIMethod { public function getAPIMethodName() { return 'macro.edit'; } public function newEditEngine() { return new PhabricatorMacroEditEngine(); } public function getMethodSummary() { return pht( 'Apply transactions to create a new macro or edit an existing one.'); } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/macro/conduit/MacroCreateMemeConduitAPIMethod.php
src/applications/macro/conduit/MacroCreateMemeConduitAPIMethod.php
<?php final class MacroCreateMemeConduitAPIMethod extends MacroConduitAPIMethod { public function getAPIMethodName() { return 'macro.creatememe'; } public function getMethodStatus() { return self::METHOD_STATUS_UNSTABLE; } public function getMethodDescription() { return pht('Generate a meme.'); } protected function defineParamTypes() { return array( 'macroName' => 'string', 'upperText' => 'optional string', 'lowerText' => 'optional string', ); } protected function defineReturnType() { return 'string'; } protected function defineErrorTypes() { return array( 'ERR-NOT-FOUND' => pht('Macro was not found.'), ); } protected function execute(ConduitAPIRequest $request) { $user = $request->getUser(); $file = id(new PhabricatorMemeEngine()) ->setViewer($user) ->setTemplate($request->getValue('macroName')) ->setAboveText($request->getValue('upperText')) ->setBelowText($request->getValue('lowerText')) ->newAsset(); return array( 'uri' => $file->getViewURI(), ); } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/macro/conduit/MacroQueryConduitAPIMethod.php
src/applications/macro/conduit/MacroQueryConduitAPIMethod.php
<?php final class MacroQueryConduitAPIMethod extends MacroConduitAPIMethod { public function getAPIMethodName() { return 'macro.query'; } public function getMethodDescription() { return pht('Retrieve image macro information.'); } protected function defineParamTypes() { return array( 'authorPHIDs' => 'optional list<phid>', 'phids' => 'optional list<phid>', 'ids' => 'optional list<id>', 'names' => 'optional list<string>', 'nameLike' => 'optional string', ); } protected function defineReturnType() { return 'list<dict>'; } protected function execute(ConduitAPIRequest $request) { $query = id(new PhabricatorMacroQuery()) ->setViewer($request->getUser()) ->needFiles(true); $author_phids = $request->getValue('authorPHIDs'); $phids = $request->getValue('phids'); $ids = $request->getValue('ids'); $name_like = $request->getValue('nameLike'); $names = $request->getValue('names'); if ($author_phids) { $query->withAuthorPHIDs($author_phids); } if ($phids) { $query->withPHIDs($phids); } if ($ids) { $query->withIDs($ids); } if ($name_like) { $query->withNameLike($name_like); } if ($names) { $query->withNames($names); } $macros = $query->execute(); if (!$macros) { return array(); } $results = array(); foreach ($macros as $macro) { $file = $macro->getFile(); $results[$macro->getName()] = array( 'uri' => $file->getBestURI(), 'phid' => $macro->getPHID(), 'authorPHID' => $file->getAuthorPHID(), 'dateCreated' => $file->getDateCreated(), 'filePHID' => $file->getPHID(), ); } return $results; } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/macro/engine/PhabricatorMemeEngine.php
src/applications/macro/engine/PhabricatorMemeEngine.php
<?php final class PhabricatorMemeEngine extends Phobject { private $viewer; private $template; private $aboveText; private $belowText; private $templateFile; private $metrics; public function setViewer(PhabricatorUser $viewer) { $this->viewer = $viewer; return $this; } public function getViewer() { return $this->viewer; } public function setTemplate($template) { $this->template = $template; return $this; } public function getTemplate() { return $this->template; } public function setAboveText($above_text) { $this->aboveText = $above_text; return $this; } public function getAboveText() { return $this->aboveText; } public function setBelowText($below_text) { $this->belowText = $below_text; return $this; } public function getBelowText() { return $this->belowText; } public function getGenerateURI() { $params = array( 'macro' => $this->getTemplate(), 'above' => $this->getAboveText(), 'below' => $this->getBelowText(), ); return new PhutilURI('/macro/meme/', $params); } public function newAsset() { $cache = $this->loadCachedFile(); if ($cache) { return $cache; } $template = $this->loadTemplateFile(); if (!$template) { throw new Exception( pht( 'Template "%s" is not a valid template.', $template)); } $hash = $this->newTransformHash(); $asset = $this->newAssetFile($template); $xfile = id(new PhabricatorTransformedFile()) ->setOriginalPHID($template->getPHID()) ->setTransformedPHID($asset->getPHID()) ->setTransform($hash); try { $caught = null; $unguarded = AphrontWriteGuard::beginScopedUnguardedWrites(); try { $xfile->save(); } catch (Exception $ex) { $caught = $ex; } unset($unguarded); if ($caught) { throw $caught; } return $asset; } catch (AphrontDuplicateKeyQueryException $ex) { $xfile = $this->loadCachedFile(); if (!$xfile) { throw $ex; } return $xfile; } } private function newTransformHash() { $properties = array( 'kind' => 'meme', 'above' => $this->getAboveText(), 'below' => $this->getBelowText(), ); $properties = phutil_json_encode($properties); return PhabricatorHash::digestForIndex($properties); } public function loadCachedFile() { $viewer = $this->getViewer(); $template_file = $this->loadTemplateFile(); if (!$template_file) { return null; } $hash = $this->newTransformHash(); $xform = id(new PhabricatorTransformedFile())->loadOneWhere( 'originalPHID = %s AND transform = %s', $template_file->getPHID(), $hash); if (!$xform) { return null; } return id(new PhabricatorFileQuery()) ->setViewer($viewer) ->withPHIDs(array($xform->getTransformedPHID())) ->executeOne(); } private function loadTemplateFile() { if ($this->templateFile === null) { $viewer = $this->getViewer(); $template = $this->getTemplate(); $macro = id(new PhabricatorMacroQuery()) ->setViewer($viewer) ->withNames(array($template)) ->needFiles(true) ->executeOne(); if (!$macro) { return null; } $this->templateFile = $macro->getFile(); } return $this->templateFile; } private function newAssetFile(PhabricatorFile $template) { $data = $this->newAssetData($template); return PhabricatorFile::newFromFileData( $data, array( 'name' => 'meme-'.$template->getName(), 'canCDN' => true, // In modern code these can end up linked directly in email, so let // them stick around for a while. 'ttl.relative' => phutil_units('30 days in seconds'), )); } private function newAssetData(PhabricatorFile $template) { $template_data = $template->loadFileData(); // When we aren't adding text, just return the data unmodified. This saves // us from doing expensive stitching when we aren't actually making any // changes to the image. $above_text = coalesce($this->getAboveText(), ''); $below_text = coalesce($this->getBelowText(), ''); if (!strlen(trim($above_text)) && !strlen(trim($below_text))) { return $template_data; } $result = $this->newImagemagickAsset($template, $template_data); if ($result) { return $result; } return $this->newGDAsset($template, $template_data); } private function newImagemagickAsset( PhabricatorFile $template, $template_data) { // We're only going to use Imagemagick on GIFs. $mime_type = $template->getMimeType(); if ($mime_type != 'image/gif') { return null; } // We're only going to use Imagemagick if it is actually available. $available = PhabricatorEnv::getEnvConfig('files.enable-imagemagick'); if (!$available) { return null; } // Test of the GIF is an animated GIF. If it's a flat GIF, we'll fall // back to GD. $input = new TempFile(); Filesystem::writeFile($input, $template_data); list($err, $out) = exec_manual('convert %s info:', $input); if ($err) { return null; } $split = phutil_split_lines($out); $frames = count($split); if ($frames <= 1) { return null; } // Split the frames apart, transform each frame, then merge them back // together. $output = new TempFile(); $future = new ExecFuture( 'convert %s -coalesce +adjoin %s_%s', $input, $input, '%09d'); $future->setTimeout(10)->resolvex(); $output_files = array(); for ($ii = 0; $ii < $frames; $ii++) { $frame_name = sprintf('%s_%09d', $input, $ii); $output_name = sprintf('%s_%09d', $output, $ii); $output_files[] = $output_name; $frame_data = Filesystem::readFile($frame_name); $memed_frame_data = $this->newGDAsset($template, $frame_data); Filesystem::writeFile($output_name, $memed_frame_data); } $future = new ExecFuture( 'convert -dispose background -loop 0 %Ls %s', $output_files, $output); $future->setTimeout(10)->resolvex(); return Filesystem::readFile($output); } private function newGDAsset(PhabricatorFile $template, $data) { $img = imagecreatefromstring($data); if (!$img) { throw new Exception( pht('Failed to imagecreatefromstring() image template data.')); } $dx = imagesx($img); $dy = imagesy($img); $metrics = $this->getMetrics($dx, $dy); $font = $this->getFont(); $size = $metrics['size']; $above = coalesce($this->getAboveText(), ''); if (strlen($above)) { $x = (int)floor(($dx - $metrics['text']['above']['width']) / 2); $y = $metrics['text']['above']['height'] + 12; $this->drawText($img, $font, $metrics['size'], $x, $y, $above); } $below = coalesce($this->getBelowText(), ''); if (strlen($below)) { $x = (int)floor(($dx - $metrics['text']['below']['width']) / 2); $y = $dy - 12 - $metrics['text']['below']['descend']; $this->drawText($img, $font, $metrics['size'], $x, $y, $below); } return PhabricatorImageTransformer::saveImageDataInAnyFormat( $img, $template->getMimeType()); } private function getFont() { $phabricator_root = dirname(phutil_get_library_root('phabricator')); $font_root = $phabricator_root.'/resources/font/'; if (Filesystem::pathExists($font_root.'impact.ttf')) { $font_path = $font_root.'impact.ttf'; } else { $font_path = $font_root.'tuffy.ttf'; } return $font_path; } private function getMetrics($dim_x, $dim_y) { if ($this->metrics === null) { $font = $this->getFont(); $font_max = 72; $font_min = 5; $margin_x = 16; $margin_y = 16; $last = null; $cursor = floor(($font_max + $font_min) / 2); $min = $font_min; $max = $font_max; $texts = array( 'above' => $this->getAboveText(), 'below' => $this->getBelowText(), ); $metrics = null; $best = null; while (true) { $all_fit = true; $text_metrics = array(); foreach ($texts as $key => $text) { $text = coalesce($text, ''); $box = imagettfbbox($cursor, 0, $font, $text); $height = abs($box[3] - $box[5]); $width = abs($box[0] - $box[2]); // This is the number of pixels below the baseline that the // text extends, for example if it has a "y". $descend = $box[3]; if (($height + $margin_y) > $dim_y) { $all_fit = false; break; } if (($width + $margin_x) > $dim_x) { $all_fit = false; break; } $text_metrics[$key]['width'] = $width; $text_metrics[$key]['height'] = $height; $text_metrics[$key]['descend'] = $descend; } if ($all_fit || $best === null) { $best = $cursor; $metrics = $text_metrics; } if ($all_fit) { $min = $cursor; } else { $max = $cursor; } $last = $cursor; $cursor = floor(($max + $min) / 2); if ($cursor === $last) { break; } } $this->metrics = array( 'size' => $best, 'text' => $metrics, ); } return $this->metrics; } private function drawText($img, $font, $size, $x, $y, $text) { $text_color = imagecolorallocate($img, 255, 255, 255); $border_color = imagecolorallocate($img, 0, 0, 0); $border = 2; for ($xx = ($x - $border); $xx <= ($x + $border); $xx += $border) { for ($yy = ($y - $border); $yy <= ($y + $border); $yy += $border) { if (($xx === $x) && ($yy === $y)) { continue; } imagettftext($img, $size, 0, $xx, $yy, $border_color, $font, $text); } } imagettftext($img, $size, 0, $x, $y, $text_color, $font, $text); } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/macro/typeahead/PhabricatorEmojiDatasource.php
src/applications/macro/typeahead/PhabricatorEmojiDatasource.php
<?php final class PhabricatorEmojiDatasource extends PhabricatorTypeaheadDatasource { public function getPlaceholderText() { return pht('Type an emoji name...'); } public function getBrowseTitle() { return pht('Browse Emojis'); } public function getDatasourceApplicationClass() { return 'PhabricatorMacroApplication'; } public function loadResults() { $results = $this->buildResults(); return $this->filterResultsAgainstTokens($results); } protected function renderSpecialTokens(array $values) { return $this->renderTokensFromResults($this->buildResults(), $values); } private function buildResults() { $raw_query = $this->getRawQuery(); $data = id(new PhabricatorEmojiRemarkupRule())->markupEmojiJSON(); $emojis = phutil_json_decode($data); $results = array(); foreach ($emojis as $shortname => $emoji) { $display_name = $emoji.' '.$shortname; $name = str_replace('_', ' ', $shortname); $result = id(new PhabricatorTypeaheadResult()) ->setPHID($shortname) ->setName($name) ->setDisplayname($display_name) ->setAutocomplete($emoji); $results[$shortname] = $result; } return $results; } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/macro/typeahead/PhabricatorMacroDatasource.php
src/applications/macro/typeahead/PhabricatorMacroDatasource.php
<?php final class PhabricatorMacroDatasource extends PhabricatorTypeaheadDatasource { public function getPlaceholderText() { return pht('Type a macro name...'); } public function getBrowseTitle() { return pht('Browse Macros'); } public function getDatasourceApplicationClass() { return 'PhabricatorMacroApplication'; } public function loadResults() { $raw_query = $this->getRawQuery(); $query = id(new PhabricatorMacroQuery()) ->setOrder('name') ->withNamePrefix($raw_query); $macros = $this->executeQuery($query); $results = array(); foreach ($macros as $macro) { $closed = null; if ($macro->getIsDisabled()) { $closed = pht('Disabled'); } $results[] = id(new PhabricatorTypeaheadResult()) ->setPHID($macro->getPHID()) ->setClosed($closed) ->setName($macro->getName()); } return $results; } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/macro/capability/PhabricatorMacroManageCapability.php
src/applications/macro/capability/PhabricatorMacroManageCapability.php
<?php final class PhabricatorMacroManageCapability extends PhabricatorPolicyCapability { const CAPABILITY = 'macro.manage'; public function getCapabilityName() { return pht('Can Manage Macros'); } public function describeCapabilityRejection() { return pht('You do not have permission to manage image macros.'); } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/macro/markup/PhabricatorMemeRemarkupRule.php
src/applications/macro/markup/PhabricatorMemeRemarkupRule.php
<?php final class PhabricatorMemeRemarkupRule extends PhutilRemarkupRule { private $images; public function getPriority() { return 200.0; } public function apply($text) { return preg_replace_callback( '@{meme,((?:[^}\\\\]+|\\\\.)+)}@m', array($this, 'markupMeme'), $text); } public function markupMeme(array $matches) { if (!$this->isFlatText($matches[0])) { return $matches[0]; } $options = array( 'src' => null, 'above' => null, 'below' => null, ); $parser = new PhutilSimpleOptions(); $options = $parser->parse($matches[1]) + $options; $engine = id(new PhabricatorMemeEngine()) ->setViewer(PhabricatorUser::getOmnipotentUser()) ->setTemplate($options['src']) ->setAboveText($options['above']) ->setBelowText($options['below']); $asset = $engine->loadCachedFile(); $is_html_mail = $this->getEngine()->isHTMLMailMode(); $is_text = $this->getEngine()->isTextMode(); $must_inline = ($is_html_mail || $is_text); if ($must_inline) { if (!$asset) { try { $asset = $engine->newAsset(); } catch (Exception $ex) { return $matches[0]; } } } if ($asset) { $uri = $asset->getViewURI(); } else { $uri = $engine->getGenerateURI(); } if ($is_text) { $parts = array(); $above = $options['above']; if (strlen($above)) { $parts[] = pht('"%s"', $above); } $parts[] = $options['src'].' <'.$uri.'>'; $below = $options['below']; if (strlen($below)) { $parts[] = pht('"%s"', $below); } $parts = implode("\n", $parts); return $this->getEngine()->storeText($parts); } $alt_text = pht( 'Macro %s: %s %s', $options['src'], $options['above'], $options['below']); if ($asset) { $img = $this->newTag( 'img', array( 'src' => $uri, 'class' => 'phabricator-remarkup-macro', 'alt' => $alt_text, )); } else { $img = id(new PHUIRemarkupImageView()) ->setURI($uri) ->addClass('phabricator-remarkup-macro') ->setAlt($alt_text); } return $this->getEngine()->storeText($img); } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/macro/markup/PhabricatorEmojiRemarkupRule.php
src/applications/macro/markup/PhabricatorEmojiRemarkupRule.php
<?php final class PhabricatorEmojiRemarkupRule extends PhutilRemarkupRule { public function getPriority() { return 200.0; } public function apply($text) { return preg_replace_callback( '(\B:(\S+):\B)', array($this, 'markupEmoji'), $text); } public function markupEmojiJSON() { $root = dirname(phutil_get_library_root('phabricator')); $json = Filesystem::readFile( $root.'/resources/emoji/manifest.json'); return $json; } public function markupEmoji(array $matches) { if (!$this->isFlatText($matches[0])) { return $matches[0]; } static $map = array( 'watch' => "\xE2\x8C\x9A", 'hourglass' => "\xE2\x8C\x9B", 'fast_forward' => "\xE2\x8F\xA9", 'rewind' => "\xE2\x8F\xAA", 'arrow_double_up' => "\xE2\x8F\xAB", 'arrow_double_down' => "\xE2\x8F\xAC", 'alarm_clock' => "\xE2\x8F\xB0", 'hourglass_flowing_sand' => "\xE2\x8F\xB3", 'white_medium_small_square' => "\xE2\x97\xBD", 'black_medium_small_square' => "\xE2\x97\xBE", 'umbrella' => "\xE2\x98\x94", 'coffee' => "\xE2\x98\x95", 'aries' => "\xE2\x99\x88", 'taurus' => "\xE2\x99\x89", 'gemini' => "\xE2\x99\x8A", 'cancer' => "\xE2\x99\x8B", 'leo' => "\xE2\x99\x8C", 'virgo' => "\xE2\x99\x8D", 'libra' => "\xE2\x99\x8E", 'scorpius' => "\xE2\x99\x8F", 'sagittarius' => "\xE2\x99\x90", 'capricorn' => "\xE2\x99\x91", 'aquarius' => "\xE2\x99\x92", 'pisces' => "\xE2\x99\x93", 'wheelchair' => "\xE2\x99\xBF", 'anchor' => "\xE2\x9A\x93", 'zap' => "\xE2\x9A\xA1", 'white_circle' => "\xE2\x9A\xAA", 'black_circle' => "\xE2\x9A\xAB", 'soccer' => "\xE2\x9A\xBD", 'snowman' => "\xE2\x9B\x84", 'partly_sunny' => "\xE2\x9B\x85", 'ophiuchus' => "\xE2\x9B\x8E", 'no_entry' => "\xE2\x9B\x94", 'church' => "\xE2\x9B\xAA", 'fountain' => "\xE2\x9B\xB2", 'golf' => "\xE2\x9B\xB3", 'sailboat' => "\xE2\x9B\xB5", 'boat' => "\xE2\x9B\xB5", 'tent' => "\xE2\x9B\xBA", 'fuelpump' => "\xE2\x9B\xBD", 'white_check_mark' => "\xE2\x9C\x85", 'fist' => "\xE2\x9C\x8A", 'hand' => "\xE2\x9C\x8B", 'raised_hand' => "\xE2\x9C\x8B", 'sparkles' => "\xE2\x9C\xA8", 'x' => "\xE2\x9D\x8C", 'negative_squared_cross_mark' => "\xE2\x9D\x8E", 'question' => "\xE2\x9D\x93", 'grey_question' => "\xE2\x9D\x94", 'grey_exclamation' => "\xE2\x9D\x95", 'exclamation' => "\xE2\x9D\x97", 'heavy_exclamation_mark' => "\xE2\x9D\x97", 'heavy_plus_sign' => "\xE2\x9E\x95", 'heavy_minus_sign' => "\xE2\x9E\x96", 'heavy_division_sign' => "\xE2\x9E\x97", 'curly_loop' => "\xE2\x9E\xB0", 'loop' => "\xE2\x9E\xBF", 'black_large_square' => "\xE2\xAC\x9B", 'white_large_square' => "\xE2\xAC\x9C", 'star' => "\xE2\xAD\x90", 'o' => "\xE2\xAD\x95", 'mahjong' => "\xF0\x9F\x80\x84", 'black_joker' => "\xF0\x9F\x83\x8F", 'ab' => "\xF0\x9F\x86\x8E", 'cl' => "\xF0\x9F\x86\x91", 'cool' => "\xF0\x9F\x86\x92", 'free' => "\xF0\x9F\x86\x93", 'id' => "\xF0\x9F\x86\x94", 'new' => "\xF0\x9F\x86\x95", 'ng' => "\xF0\x9F\x86\x96", 'ok' => "\xF0\x9F\x86\x97", 'sos' => "\xF0\x9F\x86\x98", 'up' => "\xF0\x9F\x86\x99", 'vs' => "\xF0\x9F\x86\x9A", 'koko' => "\xF0\x9F\x88\x81", 'u7121' => "\xF0\x9F\x88\x9A", 'u6307' => "\xF0\x9F\x88\xAF", 'u7981' => "\xF0\x9F\x88\xB2", 'u7a7a' => "\xF0\x9F\x88\xB3", 'u5408' => "\xF0\x9F\x88\xB4", 'u6e80' => "\xF0\x9F\x88\xB5", 'u6709' => "\xF0\x9F\x88\xB6", 'u7533' => "\xF0\x9F\x88\xB8", 'u5272' => "\xF0\x9F\x88\xB9", 'u55b6' => "\xF0\x9F\x88\xBA", 'ideograph_advantage' => "\xF0\x9F\x89\x90", 'accept' => "\xF0\x9F\x89\x91", 'cyclone' => "\xF0\x9F\x8C\x80", 'foggy' => "\xF0\x9F\x8C\x81", 'closed_umbrella' => "\xF0\x9F\x8C\x82", 'night_with_stars' => "\xF0\x9F\x8C\x83", 'sunrise_over_mountains' => "\xF0\x9F\x8C\x84", 'sunrise' => "\xF0\x9F\x8C\x85", 'city_sunset' => "\xF0\x9F\x8C\x86", 'city_sunrise' => "\xF0\x9F\x8C\x87", 'rainbow' => "\xF0\x9F\x8C\x88", 'bridge_at_night' => "\xF0\x9F\x8C\x89", 'ocean' => "\xF0\x9F\x8C\x8A", 'volcano' => "\xF0\x9F\x8C\x8B", 'milky_way' => "\xF0\x9F\x8C\x8C", 'earth_africa' => "\xF0\x9F\x8C\x8D", 'earth_americas' => "\xF0\x9F\x8C\x8E", 'earth_asia' => "\xF0\x9F\x8C\x8F", 'globe_with_meridians' => "\xF0\x9F\x8C\x90", 'new_moon' => "\xF0\x9F\x8C\x91", 'waxing_crescent_moon' => "\xF0\x9F\x8C\x92", 'first_quarter_moon' => "\xF0\x9F\x8C\x93", 'waxing_gibbous_moon' => "\xF0\x9F\x8C\x94", 'moon' => "\xF0\x9F\x8C\x94", 'full_moon' => "\xF0\x9F\x8C\x95", 'waning_gibbous_moon' => "\xF0\x9F\x8C\x96", 'last_quarter_moon' => "\xF0\x9F\x8C\x97", 'waning_crescent_moon' => "\xF0\x9F\x8C\x98", 'crescent_moon' => "\xF0\x9F\x8C\x99", 'new_moon_with_face' => "\xF0\x9F\x8C\x9A", 'first_quarter_moon_with_face' => "\xF0\x9F\x8C\x9B", 'last_quarter_moon_with_face' => "\xF0\x9F\x8C\x9C", 'full_moon_with_face' => "\xF0\x9F\x8C\x9D", 'sun_with_face' => "\xF0\x9F\x8C\x9E", 'star2' => "\xF0\x9F\x8C\x9F", 'stars' => "\xF0\x9F\x8C\xA0", 'chestnut' => "\xF0\x9F\x8C\xB0", 'seedling' => "\xF0\x9F\x8C\xB1", 'evergreen_tree' => "\xF0\x9F\x8C\xB2", 'deciduous_tree' => "\xF0\x9F\x8C\xB3", 'palm_tree' => "\xF0\x9F\x8C\xB4", 'cactus' => "\xF0\x9F\x8C\xB5", 'tulip' => "\xF0\x9F\x8C\xB7", 'cherry_blossom' => "\xF0\x9F\x8C\xB8", 'rose' => "\xF0\x9F\x8C\xB9", 'hibiscus' => "\xF0\x9F\x8C\xBA", 'sunflower' => "\xF0\x9F\x8C\xBB", 'blossom' => "\xF0\x9F\x8C\xBC", 'corn' => "\xF0\x9F\x8C\xBD", 'ear_of_rice' => "\xF0\x9F\x8C\xBE", 'herb' => "\xF0\x9F\x8C\xBF", 'four_leaf_clover' => "\xF0\x9F\x8D\x80", 'maple_leaf' => "\xF0\x9F\x8D\x81", 'fallen_leaf' => "\xF0\x9F\x8D\x82", 'leaves' => "\xF0\x9F\x8D\x83", 'mushroom' => "\xF0\x9F\x8D\x84", 'tomato' => "\xF0\x9F\x8D\x85", 'eggplant' => "\xF0\x9F\x8D\x86", 'grapes' => "\xF0\x9F\x8D\x87", 'melon' => "\xF0\x9F\x8D\x88", 'watermelon' => "\xF0\x9F\x8D\x89", 'tangerine' => "\xF0\x9F\x8D\x8A", 'lemon' => "\xF0\x9F\x8D\x8B", 'banana' => "\xF0\x9F\x8D\x8C", 'pineapple' => "\xF0\x9F\x8D\x8D", 'apple' => "\xF0\x9F\x8D\x8E", 'green_apple' => "\xF0\x9F\x8D\x8F", 'pear' => "\xF0\x9F\x8D\x90", 'peach' => "\xF0\x9F\x8D\x91", 'cherries' => "\xF0\x9F\x8D\x92", 'strawberry' => "\xF0\x9F\x8D\x93", 'hamburger' => "\xF0\x9F\x8D\x94", 'pizza' => "\xF0\x9F\x8D\x95", 'meat_on_bone' => "\xF0\x9F\x8D\x96", 'poultry_leg' => "\xF0\x9F\x8D\x97", 'rice_cracker' => "\xF0\x9F\x8D\x98", 'rice_ball' => "\xF0\x9F\x8D\x99", 'rice' => "\xF0\x9F\x8D\x9A", 'curry' => "\xF0\x9F\x8D\x9B", 'ramen' => "\xF0\x9F\x8D\x9C", 'spaghetti' => "\xF0\x9F\x8D\x9D", 'bread' => "\xF0\x9F\x8D\x9E", 'fries' => "\xF0\x9F\x8D\x9F", 'sweet_potato' => "\xF0\x9F\x8D\xA0", 'dango' => "\xF0\x9F\x8D\xA1", 'oden' => "\xF0\x9F\x8D\xA2", 'sushi' => "\xF0\x9F\x8D\xA3", 'fried_shrimp' => "\xF0\x9F\x8D\xA4", 'fish_cake' => "\xF0\x9F\x8D\xA5", 'icecream' => "\xF0\x9F\x8D\xA6", 'shaved_ice' => "\xF0\x9F\x8D\xA7", 'ice_cream' => "\xF0\x9F\x8D\xA8", 'doughnut' => "\xF0\x9F\x8D\xA9", 'cookie' => "\xF0\x9F\x8D\xAA", 'chocolate_bar' => "\xF0\x9F\x8D\xAB", 'candy' => "\xF0\x9F\x8D\xAC", 'lollipop' => "\xF0\x9F\x8D\xAD", 'custard' => "\xF0\x9F\x8D\xAE", 'honey_pot' => "\xF0\x9F\x8D\xAF", 'cake' => "\xF0\x9F\x8D\xB0", 'bento' => "\xF0\x9F\x8D\xB1", 'stew' => "\xF0\x9F\x8D\xB2", 'egg' => "\xF0\x9F\x8D\xB3", 'fork_and_knife' => "\xF0\x9F\x8D\xB4", 'tea' => "\xF0\x9F\x8D\xB5", 'sake' => "\xF0\x9F\x8D\xB6", 'wine_glass' => "\xF0\x9F\x8D\xB7", 'cocktail' => "\xF0\x9F\x8D\xB8", 'tropical_drink' => "\xF0\x9F\x8D\xB9", 'beer' => "\xF0\x9F\x8D\xBA", 'beers' => "\xF0\x9F\x8D\xBB", 'baby_bottle' => "\xF0\x9F\x8D\xBC", 'ribbon' => "\xF0\x9F\x8E\x80", 'gift' => "\xF0\x9F\x8E\x81", 'birthday' => "\xF0\x9F\x8E\x82", 'jack_o_lantern' => "\xF0\x9F\x8E\x83", 'christmas_tree' => "\xF0\x9F\x8E\x84", 'santa' => "\xF0\x9F\x8E\x85", 'fireworks' => "\xF0\x9F\x8E\x86", 'sparkler' => "\xF0\x9F\x8E\x87", 'balloon' => "\xF0\x9F\x8E\x88", 'tada' => "\xF0\x9F\x8E\x89", 'confetti_ball' => "\xF0\x9F\x8E\x8A", 'tanabata_tree' => "\xF0\x9F\x8E\x8B", 'crossed_flags' => "\xF0\x9F\x8E\x8C", 'bamboo' => "\xF0\x9F\x8E\x8D", 'dolls' => "\xF0\x9F\x8E\x8E", 'flags' => "\xF0\x9F\x8E\x8F", 'wind_chime' => "\xF0\x9F\x8E\x90", 'rice_scene' => "\xF0\x9F\x8E\x91", 'school_satchel' => "\xF0\x9F\x8E\x92", 'mortar_board' => "\xF0\x9F\x8E\x93", 'carousel_horse' => "\xF0\x9F\x8E\xA0", 'ferris_wheel' => "\xF0\x9F\x8E\xA1", 'roller_coaster' => "\xF0\x9F\x8E\xA2", 'fishing_pole_and_fish' => "\xF0\x9F\x8E\xA3", 'microphone' => "\xF0\x9F\x8E\xA4", 'movie_camera' => "\xF0\x9F\x8E\xA5", 'cinema' => "\xF0\x9F\x8E\xA6", 'headphones' => "\xF0\x9F\x8E\xA7", 'art' => "\xF0\x9F\x8E\xA8", 'tophat' => "\xF0\x9F\x8E\xA9", 'circus_tent' => "\xF0\x9F\x8E\xAA", 'ticket' => "\xF0\x9F\x8E\xAB", 'clapper' => "\xF0\x9F\x8E\xAC", 'performing_arts' => "\xF0\x9F\x8E\xAD", 'video_game' => "\xF0\x9F\x8E\xAE", 'dart' => "\xF0\x9F\x8E\xAF", 'slot_machine' => "\xF0\x9F\x8E\xB0", '8ball' => "\xF0\x9F\x8E\xB1", 'game_die' => "\xF0\x9F\x8E\xB2", 'bowling' => "\xF0\x9F\x8E\xB3", 'flower_playing_cards' => "\xF0\x9F\x8E\xB4", 'musical_note' => "\xF0\x9F\x8E\xB5", 'notes' => "\xF0\x9F\x8E\xB6", 'saxophone' => "\xF0\x9F\x8E\xB7", 'guitar' => "\xF0\x9F\x8E\xB8", 'musical_keyboard' => "\xF0\x9F\x8E\xB9", 'trumpet' => "\xF0\x9F\x8E\xBA", 'violin' => "\xF0\x9F\x8E\xBB", 'musical_score' => "\xF0\x9F\x8E\xBC", 'running_shirt_with_sash' => "\xF0\x9F\x8E\xBD", 'tennis' => "\xF0\x9F\x8E\xBE", 'ski' => "\xF0\x9F\x8E\xBF", 'basketball' => "\xF0\x9F\x8F\x80", 'checkered_flag' => "\xF0\x9F\x8F\x81", 'snowboarder' => "\xF0\x9F\x8F\x82", 'runner' => "\xF0\x9F\x8F\x83", 'running' => "\xF0\x9F\x8F\x83", 'surfer' => "\xF0\x9F\x8F\x84", 'trophy' => "\xF0\x9F\x8F\x86", 'horse_racing' => "\xF0\x9F\x8F\x87", 'football' => "\xF0\x9F\x8F\x88", 'rugby_football' => "\xF0\x9F\x8F\x89", 'swimmer' => "\xF0\x9F\x8F\x8A", 'house' => "\xF0\x9F\x8F\xA0", 'house_with_garden' => "\xF0\x9F\x8F\xA1", 'office' => "\xF0\x9F\x8F\xA2", 'post_office' => "\xF0\x9F\x8F\xA3", 'european_post_office' => "\xF0\x9F\x8F\xA4", 'hospital' => "\xF0\x9F\x8F\xA5", 'bank' => "\xF0\x9F\x8F\xA6", 'atm' => "\xF0\x9F\x8F\xA7", 'hotel' => "\xF0\x9F\x8F\xA8", 'love_hotel' => "\xF0\x9F\x8F\xA9", 'convenience_store' => "\xF0\x9F\x8F\xAA", 'school' => "\xF0\x9F\x8F\xAB", 'department_store' => "\xF0\x9F\x8F\xAC", 'factory' => "\xF0\x9F\x8F\xAD", 'lantern' => "\xF0\x9F\x8F\xAE", 'izakaya_lantern' => "\xF0\x9F\x8F\xAE", 'japanese_castle' => "\xF0\x9F\x8F\xAF", 'european_castle' => "\xF0\x9F\x8F\xB0", 'rat' => "\xF0\x9F\x90\x80", 'mouse2' => "\xF0\x9F\x90\x81", 'ox' => "\xF0\x9F\x90\x82", 'water_buffalo' => "\xF0\x9F\x90\x83", 'cow2' => "\xF0\x9F\x90\x84", 'tiger2' => "\xF0\x9F\x90\x85", 'leopard' => "\xF0\x9F\x90\x86", 'rabbit2' => "\xF0\x9F\x90\x87", 'cat2' => "\xF0\x9F\x90\x88", 'dragon' => "\xF0\x9F\x90\x89", 'crocodile' => "\xF0\x9F\x90\x8A", 'whale2' => "\xF0\x9F\x90\x8B", 'snail' => "\xF0\x9F\x90\x8C", 'snake' => "\xF0\x9F\x90\x8D", 'racehorse' => "\xF0\x9F\x90\x8E", 'ram' => "\xF0\x9F\x90\x8F", 'goat' => "\xF0\x9F\x90\x90", 'sheep' => "\xF0\x9F\x90\x91", 'monkey' => "\xF0\x9F\x90\x92", 'rooster' => "\xF0\x9F\x90\x93", 'chicken' => "\xF0\x9F\x90\x94", 'dog2' => "\xF0\x9F\x90\x95", 'pig2' => "\xF0\x9F\x90\x96", 'boar' => "\xF0\x9F\x90\x97", 'elephant' => "\xF0\x9F\x90\x98", 'octopus' => "\xF0\x9F\x90\x99", 'shell' => "\xF0\x9F\x90\x9A", 'bug' => "\xF0\x9F\x90\x9B", 'ant' => "\xF0\x9F\x90\x9C", 'bee' => "\xF0\x9F\x90\x9D", 'honeybee' => "\xF0\x9F\x90\x9D", 'beetle' => "\xF0\x9F\x90\x9E", 'fish' => "\xF0\x9F\x90\x9F", 'tropical_fish' => "\xF0\x9F\x90\xA0", 'blowfish' => "\xF0\x9F\x90\xA1", 'turtle' => "\xF0\x9F\x90\xA2", 'hatching_chick' => "\xF0\x9F\x90\xA3", 'baby_chick' => "\xF0\x9F\x90\xA4", 'hatched_chick' => "\xF0\x9F\x90\xA5", 'bird' => "\xF0\x9F\x90\xA6", 'penguin' => "\xF0\x9F\x90\xA7", 'koala' => "\xF0\x9F\x90\xA8", 'poodle' => "\xF0\x9F\x90\xA9", 'dromedary_camel' => "\xF0\x9F\x90\xAA", 'camel' => "\xF0\x9F\x90\xAB", 'dolphin' => "\xF0\x9F\x90\xAC", 'flipper' => "\xF0\x9F\x90\xAC", 'mouse' => "\xF0\x9F\x90\xAD", 'cow' => "\xF0\x9F\x90\xAE", 'tiger' => "\xF0\x9F\x90\xAF", 'rabbit' => "\xF0\x9F\x90\xB0", 'cat' => "\xF0\x9F\x90\xB1", 'dragon_face' => "\xF0\x9F\x90\xB2", 'whale' => "\xF0\x9F\x90\xB3", 'horse' => "\xF0\x9F\x90\xB4", 'monkey_face' => "\xF0\x9F\x90\xB5", 'dog' => "\xF0\x9F\x90\xB6", 'pig' => "\xF0\x9F\x90\xB7", 'frog' => "\xF0\x9F\x90\xB8", 'hamster' => "\xF0\x9F\x90\xB9", 'wolf' => "\xF0\x9F\x90\xBA", 'bear' => "\xF0\x9F\x90\xBB", 'panda_face' => "\xF0\x9F\x90\xBC", 'pig_nose' => "\xF0\x9F\x90\xBD", 'paw_prints' => "\xF0\x9F\x90\xBE", 'feet' => "\xF0\x9F\x90\xBE", 'eyes' => "\xF0\x9F\x91\x80", 'ear' => "\xF0\x9F\x91\x82", 'nose' => "\xF0\x9F\x91\x83", 'lips' => "\xF0\x9F\x91\x84", 'tongue' => "\xF0\x9F\x91\x85", 'point_up_2' => "\xF0\x9F\x91\x86", 'point_down' => "\xF0\x9F\x91\x87", 'point_left' => "\xF0\x9F\x91\x88", 'point_right' => "\xF0\x9F\x91\x89", 'punch' => "\xF0\x9F\x91\x8A", 'facepunch' => "\xF0\x9F\x91\x8A", 'wave' => "\xF0\x9F\x91\x8B", 'ok_hand' => "\xF0\x9F\x91\x8C", '+1' => "\xF0\x9F\x91\x8D", 'thumbsup' => "\xF0\x9F\x91\x8D", '_1' => "\xF0\x9F\x91\x8E", 'thumbsdown' => "\xF0\x9F\x91\x8E", 'clap' => "\xF0\x9F\x91\x8F", 'open_hands' => "\xF0\x9F\x91\x90", 'crown' => "\xF0\x9F\x91\x91", 'womans_hat' => "\xF0\x9F\x91\x92", 'eyeglasses' => "\xF0\x9F\x91\x93", 'necktie' => "\xF0\x9F\x91\x94", 'tshirt' => "\xF0\x9F\x91\x95", 'shirt' => "\xF0\x9F\x91\x95", 'jeans' => "\xF0\x9F\x91\x96", 'dress' => "\xF0\x9F\x91\x97", 'kimono' => "\xF0\x9F\x91\x98", 'bikini' => "\xF0\x9F\x91\x99", 'womans_clothes' => "\xF0\x9F\x91\x9A", 'purse' => "\xF0\x9F\x91\x9B", 'handbag' => "\xF0\x9F\x91\x9C", 'pouch' => "\xF0\x9F\x91\x9D", 'mans_shoe' => "\xF0\x9F\x91\x9E", 'shoe' => "\xF0\x9F\x91\x9E", 'athletic_shoe' => "\xF0\x9F\x91\x9F", 'high_heel' => "\xF0\x9F\x91\xA0", 'sandal' => "\xF0\x9F\x91\xA1", 'boot' => "\xF0\x9F\x91\xA2", 'footprints' => "\xF0\x9F\x91\xA3", 'bust_in_silhouette' => "\xF0\x9F\x91\xA4", 'busts_in_silhouette' => "\xF0\x9F\x91\xA5", 'boy' => "\xF0\x9F\x91\xA6", 'girl' => "\xF0\x9F\x91\xA7", 'man' => "\xF0\x9F\x91\xA8", 'woman' => "\xF0\x9F\x91\xA9", 'family' => "\xF0\x9F\x91\xAA", 'couple' => "\xF0\x9F\x91\xAB", 'two_men_holding_hands' => "\xF0\x9F\x91\xAC", 'two_women_holding_hands' => "\xF0\x9F\x91\xAD", 'cop' => "\xF0\x9F\x91\xAE", 'dancers' => "\xF0\x9F\x91\xAF", 'bride_with_veil' => "\xF0\x9F\x91\xB0", 'person_with_blond_hair' => "\xF0\x9F\x91\xB1", 'man_with_gua_pi_mao' => "\xF0\x9F\x91\xB2", 'man_with_turban' => "\xF0\x9F\x91\xB3", 'older_man' => "\xF0\x9F\x91\xB4", 'older_woman' => "\xF0\x9F\x91\xB5", 'baby' => "\xF0\x9F\x91\xB6", 'construction_worker' => "\xF0\x9F\x91\xB7", 'princess' => "\xF0\x9F\x91\xB8", 'japanese_ogre' => "\xF0\x9F\x91\xB9", 'japanese_goblin' => "\xF0\x9F\x91\xBA", 'ghost' => "\xF0\x9F\x91\xBB", 'angel' => "\xF0\x9F\x91\xBC", 'alien' => "\xF0\x9F\x91\xBD", 'space_invader' => "\xF0\x9F\x91\xBE", 'imp' => "\xF0\x9F\x91\xBF", 'skull' => "\xF0\x9F\x92\x80", 'information_desk_person' => "\xF0\x9F\x92\x81", 'guardsman' => "\xF0\x9F\x92\x82", 'dancer' => "\xF0\x9F\x92\x83", 'lipstick' => "\xF0\x9F\x92\x84", 'nail_care' => "\xF0\x9F\x92\x85", 'massage' => "\xF0\x9F\x92\x86", 'haircut' => "\xF0\x9F\x92\x87", 'barber' => "\xF0\x9F\x92\x88", 'syringe' => "\xF0\x9F\x92\x89", 'pill' => "\xF0\x9F\x92\x8A", 'kiss' => "\xF0\x9F\x92\x8B", 'love_letter' => "\xF0\x9F\x92\x8C", 'ring' => "\xF0\x9F\x92\x8D", 'gem' => "\xF0\x9F\x92\x8E", 'couplekiss' => "\xF0\x9F\x92\x8F", 'bouquet' => "\xF0\x9F\x92\x90", 'couple_with_heart' => "\xF0\x9F\x92\x91", 'wedding' => "\xF0\x9F\x92\x92", 'heartbeat' => "\xF0\x9F\x92\x93", 'broken_heart' => "\xF0\x9F\x92\x94", 'two_hearts' => "\xF0\x9F\x92\x95", 'sparkling_heart' => "\xF0\x9F\x92\x96", 'heartpulse' => "\xF0\x9F\x92\x97", 'cupid' => "\xF0\x9F\x92\x98", 'blue_heart' => "\xF0\x9F\x92\x99", 'green_heart' => "\xF0\x9F\x92\x9A", 'yellow_heart' => "\xF0\x9F\x92\x9B", 'purple_heart' => "\xF0\x9F\x92\x9C", 'gift_heart' => "\xF0\x9F\x92\x9D", 'revolving_hearts' => "\xF0\x9F\x92\x9E", 'heart_decoration' => "\xF0\x9F\x92\x9F", 'diamond_shape_with_a_dot_inside' => "\xF0\x9F\x92\xA0", 'bulb' => "\xF0\x9F\x92\xA1", 'anger' => "\xF0\x9F\x92\xA2", 'bomb' => "\xF0\x9F\x92\xA3", 'zzz' => "\xF0\x9F\x92\xA4", 'boom' => "\xF0\x9F\x92\xA5", 'collision' => "\xF0\x9F\x92\xA5", 'sweat_drops' => "\xF0\x9F\x92\xA6", 'droplet' => "\xF0\x9F\x92\xA7", 'dash' => "\xF0\x9F\x92\xA8", 'poop' => "\xF0\x9F\x92\xA9", 'shit' => "\xF0\x9F\x92\xA9", 'hankey' => "\xF0\x9F\x92\xA9", 'muscle' => "\xF0\x9F\x92\xAA", 'dizzy' => "\xF0\x9F\x92\xAB", 'speech_balloon' => "\xF0\x9F\x92\xAC", 'thought_balloon' => "\xF0\x9F\x92\xAD", 'white_flower' => "\xF0\x9F\x92\xAE", '100' => "\xF0\x9F\x92\xAF", 'moneybag' => "\xF0\x9F\x92\xB0", 'currency_exchange' => "\xF0\x9F\x92\xB1", 'heavy_dollar_sign' => "\xF0\x9F\x92\xB2", 'credit_card' => "\xF0\x9F\x92\xB3", 'yen' => "\xF0\x9F\x92\xB4", 'dollar' => "\xF0\x9F\x92\xB5", 'euro' => "\xF0\x9F\x92\xB6", 'pound' => "\xF0\x9F\x92\xB7", 'money_with_wings' => "\xF0\x9F\x92\xB8", 'chart' => "\xF0\x9F\x92\xB9", 'seat' => "\xF0\x9F\x92\xBA", 'computer' => "\xF0\x9F\x92\xBB", 'briefcase' => "\xF0\x9F\x92\xBC", 'minidisc' => "\xF0\x9F\x92\xBD", 'floppy_disk' => "\xF0\x9F\x92\xBE", 'cd' => "\xF0\x9F\x92\xBF", 'dvd' => "\xF0\x9F\x93\x80", 'file_folder' => "\xF0\x9F\x93\x81", 'open_file_folder' => "\xF0\x9F\x93\x82", 'page_with_curl' => "\xF0\x9F\x93\x83", 'page_facing_up' => "\xF0\x9F\x93\x84", 'date' => "\xF0\x9F\x93\x85", 'calendar' => "\xF0\x9F\x93\x86", 'card_index' => "\xF0\x9F\x93\x87", 'chart_with_upwards_trend' => "\xF0\x9F\x93\x88", 'chart_with_downwards_trend' => "\xF0\x9F\x93\x89", 'bar_chart' => "\xF0\x9F\x93\x8A", 'clipboard' => "\xF0\x9F\x93\x8B", 'pushpin' => "\xF0\x9F\x93\x8C", 'round_pushpin' => "\xF0\x9F\x93\x8D", 'paperclip' => "\xF0\x9F\x93\x8E", 'straight_ruler' => "\xF0\x9F\x93\x8F", 'triangular_ruler' => "\xF0\x9F\x93\x90", 'bookmark_tabs' => "\xF0\x9F\x93\x91", 'ledger' => "\xF0\x9F\x93\x92", 'notebook' => "\xF0\x9F\x93\x93", 'notebook_with_decorative_cover' => "\xF0\x9F\x93\x94", 'closed_book' => "\xF0\x9F\x93\x95", 'book' => "\xF0\x9F\x93\x96", 'open_book' => "\xF0\x9F\x93\x96", 'green_book' => "\xF0\x9F\x93\x97", 'blue_book' => "\xF0\x9F\x93\x98", 'orange_book' => "\xF0\x9F\x93\x99", 'books' => "\xF0\x9F\x93\x9A", 'name_badge' => "\xF0\x9F\x93\x9B", 'scroll' => "\xF0\x9F\x93\x9C", 'pencil' => "\xF0\x9F\x93\x9D", 'memo' => "\xF0\x9F\x93\x9D", 'telephone_receiver' => "\xF0\x9F\x93\x9E", 'pager' => "\xF0\x9F\x93\x9F", 'fax' => "\xF0\x9F\x93\xA0", 'satellite' => "\xF0\x9F\x93\xA1", 'loudspeaker' => "\xF0\x9F\x93\xA2", 'mega' => "\xF0\x9F\x93\xA3", 'outbox_tray' => "\xF0\x9F\x93\xA4", 'inbox_tray' => "\xF0\x9F\x93\xA5", 'package' => "\xF0\x9F\x93\xA6", 'e_mail' => "\xF0\x9F\x93\xA7", 'incoming_envelope' => "\xF0\x9F\x93\xA8", 'envelope_with_arrow' => "\xF0\x9F\x93\xA9", 'mailbox_closed' => "\xF0\x9F\x93\xAA", 'mailbox' => "\xF0\x9F\x93\xAB", 'mailbox_with_mail' => "\xF0\x9F\x93\xAC", 'mailbox_with_no_mail' => "\xF0\x9F\x93\xAD", 'postbox' => "\xF0\x9F\x93\xAE", 'postal_horn' => "\xF0\x9F\x93\xAF", 'newspaper' => "\xF0\x9F\x93\xB0", 'iphone' => "\xF0\x9F\x93\xB1", 'calling' => "\xF0\x9F\x93\xB2", 'vibration_mode' => "\xF0\x9F\x93\xB3", 'mobile_phone_off' => "\xF0\x9F\x93\xB4", 'no_mobile_phones' => "\xF0\x9F\x93\xB5", 'signal_strength' => "\xF0\x9F\x93\xB6", 'camera' => "\xF0\x9F\x93\xB7", 'video_camera' => "\xF0\x9F\x93\xB9", 'tv' => "\xF0\x9F\x93\xBA", 'radio' => "\xF0\x9F\x93\xBB", 'vhs' => "\xF0\x9F\x93\xBC", 'twisted_rightwards_arrows' => "\xF0\x9F\x94\x80", 'repeat' => "\xF0\x9F\x94\x81", 'repeat_one' => "\xF0\x9F\x94\x82", 'arrows_clockwise' => "\xF0\x9F\x94\x83", 'arrows_counterclockwise' => "\xF0\x9F\x94\x84", 'low_brightness' => "\xF0\x9F\x94\x85", 'high_brightness' => "\xF0\x9F\x94\x86", 'mute' => "\xF0\x9F\x94\x87", 'speaker' => "\xF0\x9F\x94\x88", 'sound' => "\xF0\x9F\x94\x89", 'loud_sound' => "\xF0\x9F\x94\x8A", 'battery' => "\xF0\x9F\x94\x8B", 'electric_plug' => "\xF0\x9F\x94\x8C", 'mag' => "\xF0\x9F\x94\x8D", 'mag_right' => "\xF0\x9F\x94\x8E", 'lock_with_ink_pen' => "\xF0\x9F\x94\x8F", 'closed_lock_with_key' => "\xF0\x9F\x94\x90", 'key' => "\xF0\x9F\x94\x91", 'lock' => "\xF0\x9F\x94\x92", 'unlock' => "\xF0\x9F\x94\x93", 'bell' => "\xF0\x9F\x94\x94", 'no_bell' => "\xF0\x9F\x94\x95", 'bookmark' => "\xF0\x9F\x94\x96", 'link' => "\xF0\x9F\x94\x97", 'radio_button' => "\xF0\x9F\x94\x98", 'back' => "\xF0\x9F\x94\x99", 'end' => "\xF0\x9F\x94\x9A", 'on' => "\xF0\x9F\x94\x9B", 'soon' => "\xF0\x9F\x94\x9C", 'top' => "\xF0\x9F\x94\x9D", 'underage' => "\xF0\x9F\x94\x9E", 'keycap_ten' => "\xF0\x9F\x94\x9F", 'capital_abcd' => "\xF0\x9F\x94\xA0", 'abcd' => "\xF0\x9F\x94\xA1", '1234' => "\xF0\x9F\x94\xA2", 'symbols' => "\xF0\x9F\x94\xA3", 'abc' => "\xF0\x9F\x94\xA4", 'fire' => "\xF0\x9F\x94\xA5", 'flashlight' => "\xF0\x9F\x94\xA6", 'wrench' => "\xF0\x9F\x94\xA7", 'hammer' => "\xF0\x9F\x94\xA8", 'nut_and_bolt' => "\xF0\x9F\x94\xA9", 'knife' => "\xF0\x9F\x94\xAA", 'hocho' => "\xF0\x9F\x94\xAA", 'gun' => "\xF0\x9F\x94\xAB", 'microscope' => "\xF0\x9F\x94\xAC", 'telescope' => "\xF0\x9F\x94\xAD", 'crystal_ball' => "\xF0\x9F\x94\xAE", 'six_pointed_star' => "\xF0\x9F\x94\xAF", 'beginner' => "\xF0\x9F\x94\xB0", 'trident' => "\xF0\x9F\x94\xB1", 'black_square_button' => "\xF0\x9F\x94\xB2", 'white_square_button' => "\xF0\x9F\x94\xB3", 'red_circle' => "\xF0\x9F\x94\xB4", 'large_blue_circle' => "\xF0\x9F\x94\xB5", 'large_orange_diamond' => "\xF0\x9F\x94\xB6", 'large_blue_diamond' => "\xF0\x9F\x94\xB7", 'small_orange_diamond' => "\xF0\x9F\x94\xB8", 'small_blue_diamond' => "\xF0\x9F\x94\xB9", 'small_red_triangle' => "\xF0\x9F\x94\xBA", 'small_red_triangle_down' => "\xF0\x9F\x94\xBB", 'arrow_up_small' => "\xF0\x9F\x94\xBC", 'arrow_down_small' => "\xF0\x9F\x94\xBD", 'clock1' => "\xF0\x9F\x95\x90", 'clock2' => "\xF0\x9F\x95\x91", 'clock3' => "\xF0\x9F\x95\x92", 'clock4' => "\xF0\x9F\x95\x93", 'clock5' => "\xF0\x9F\x95\x94", 'clock6' => "\xF0\x9F\x95\x95", 'clock7' => "\xF0\x9F\x95\x96", 'clock8' => "\xF0\x9F\x95\x97", 'clock9' => "\xF0\x9F\x95\x98", 'clock10' => "\xF0\x9F\x95\x99", 'clock11' => "\xF0\x9F\x95\x9A", 'clock12' => "\xF0\x9F\x95\x9B", 'clock130' => "\xF0\x9F\x95\x9C", 'clock230' => "\xF0\x9F\x95\x9D", 'clock330' => "\xF0\x9F\x95\x9E", 'clock430' => "\xF0\x9F\x95\x9F", 'clock530' => "\xF0\x9F\x95\xA0", 'clock630' => "\xF0\x9F\x95\xA1", 'clock730' => "\xF0\x9F\x95\xA2", 'clock830' => "\xF0\x9F\x95\xA3", 'clock930' => "\xF0\x9F\x95\xA4", 'clock1030' => "\xF0\x9F\x95\xA5", 'clock1130' => "\xF0\x9F\x95\xA6", 'clock1230' => "\xF0\x9F\x95\xA7", 'mount_fuji' => "\xF0\x9F\x97\xBB", 'tokyo_tower' => "\xF0\x9F\x97\xBC", 'statue_of_liberty' => "\xF0\x9F\x97\xBD", 'japan' => "\xF0\x9F\x97\xBE", 'moyai' => "\xF0\x9F\x97\xBF", 'grinning' => "\xF0\x9F\x98\x80", 'grin' => "\xF0\x9F\x98\x81", 'joy' => "\xF0\x9F\x98\x82", 'smiley' => "\xF0\x9F\x98\x83", 'smile' => "\xF0\x9F\x98\x84", 'sweat_smile' => "\xF0\x9F\x98\x85", 'satisfied' => "\xF0\x9F\x98\x86", 'laughing' => "\xF0\x9F\x98\x86", 'innocent' => "\xF0\x9F\x98\x87", 'smiling_imp' => "\xF0\x9F\x98\x88", 'wink' => "\xF0\x9F\x98\x89", 'blush' => "\xF0\x9F\x98\x8A", 'yum' => "\xF0\x9F\x98\x8B", 'relieved' => "\xF0\x9F\x98\x8C", 'heart_eyes' => "\xF0\x9F\x98\x8D", 'sunglasses' => "\xF0\x9F\x98\x8E", 'smirk' => "\xF0\x9F\x98\x8F", 'neutral_face' => "\xF0\x9F\x98\x90", 'expressionless' => "\xF0\x9F\x98\x91", 'unamused' => "\xF0\x9F\x98\x92", 'sweat' => "\xF0\x9F\x98\x93", 'pensive' => "\xF0\x9F\x98\x94", 'confused' => "\xF0\x9F\x98\x95", 'confounded' => "\xF0\x9F\x98\x96", 'kissing' => "\xF0\x9F\x98\x97", 'kissing_heart' => "\xF0\x9F\x98\x98", 'kissing_smiling_eyes' => "\xF0\x9F\x98\x99", 'kissing_closed_eyes' => "\xF0\x9F\x98\x9A", 'stuck_out_tongue' => "\xF0\x9F\x98\x9B", 'stuck_out_tongue_winking_eye' => "\xF0\x9F\x98\x9C", 'stuck_out_tongue_closed_eyes' => "\xF0\x9F\x98\x9D", 'disappointed' => "\xF0\x9F\x98\x9E", 'worried' => "\xF0\x9F\x98\x9F", 'angry' => "\xF0\x9F\x98\xA0", 'rage' => "\xF0\x9F\x98\xA1", 'cry' => "\xF0\x9F\x98\xA2", 'persevere' => "\xF0\x9F\x98\xA3", 'triumph' => "\xF0\x9F\x98\xA4", 'disappointed_relieved' => "\xF0\x9F\x98\xA5", 'frowning' => "\xF0\x9F\x98\xA6", 'anguished' => "\xF0\x9F\x98\xA7", 'fearful' => "\xF0\x9F\x98\xA8", 'weary' => "\xF0\x9F\x98\xA9", 'sleepy' => "\xF0\x9F\x98\xAA", 'tired_face' => "\xF0\x9F\x98\xAB", 'grimacing' => "\xF0\x9F\x98\xAC", 'sob' => "\xF0\x9F\x98\xAD", 'open_mouth' => "\xF0\x9F\x98\xAE", 'hushed' => "\xF0\x9F\x98\xAF", 'cold_sweat' => "\xF0\x9F\x98\xB0", 'scream' => "\xF0\x9F\x98\xB1", 'astonished' => "\xF0\x9F\x98\xB2", 'flushed' => "\xF0\x9F\x98\xB3", 'sleeping' => "\xF0\x9F\x98\xB4", 'dizzy_face' => "\xF0\x9F\x98\xB5", 'no_mouth' => "\xF0\x9F\x98\xB6", 'mask' => "\xF0\x9F\x98\xB7", 'smile_cat' => "\xF0\x9F\x98\xB8", 'joy_cat' => "\xF0\x9F\x98\xB9", 'smiley_cat' => "\xF0\x9F\x98\xBA", 'heart_eyes_cat' => "\xF0\x9F\x98\xBB", 'smirk_cat' => "\xF0\x9F\x98\xBC", 'kissing_cat' => "\xF0\x9F\x98\xBD", 'pouting_cat' => "\xF0\x9F\x98\xBE", 'crying_cat_face' => "\xF0\x9F\x98\xBF", 'scream_cat' => "\xF0\x9F\x99\x80", 'no_good' => "\xF0\x9F\x99\x85", 'ok_woman' => "\xF0\x9F\x99\x86", 'bow' => "\xF0\x9F\x99\x87", 'see_no_evil' => "\xF0\x9F\x99\x88", 'hear_no_evil' => "\xF0\x9F\x99\x89", 'speak_no_evil' => "\xF0\x9F\x99\x8A", 'raising_hand' => "\xF0\x9F\x99\x8B", 'raised_hands' => "\xF0\x9F\x99\x8C", 'person_frowning' => "\xF0\x9F\x99\x8D", 'person_with_pouting_face' => "\xF0\x9F\x99\x8E", 'pray' => "\xF0\x9F\x99\x8F", 'rocket' => "\xF0\x9F\x9A\x80", 'helicopter' => "\xF0\x9F\x9A\x81", 'steam_locomotive' => "\xF0\x9F\x9A\x82", 'railway_car' => "\xF0\x9F\x9A\x83", 'bullettrain_side' => "\xF0\x9F\x9A\x84", 'bullettrain_front' => "\xF0\x9F\x9A\x85", 'train2' => "\xF0\x9F\x9A\x86", 'metro' => "\xF0\x9F\x9A\x87", 'light_rail' => "\xF0\x9F\x9A\x88", 'station' => "\xF0\x9F\x9A\x89", 'tram' => "\xF0\x9F\x9A\x8A", 'train' => "\xF0\x9F\x9A\x8B", 'bus' => "\xF0\x9F\x9A\x8C", 'oncoming_bus' => "\xF0\x9F\x9A\x8D", 'trolleybus' => "\xF0\x9F\x9A\x8E", 'busstop' => "\xF0\x9F\x9A\x8F", 'minibus' => "\xF0\x9F\x9A\x90", 'ambulance' => "\xF0\x9F\x9A\x91", 'fire_engine' => "\xF0\x9F\x9A\x92", 'police_car' => "\xF0\x9F\x9A\x93", 'oncoming_police_car' => "\xF0\x9F\x9A\x94", 'taxi' => "\xF0\x9F\x9A\x95", 'oncoming_taxi' => "\xF0\x9F\x9A\x96", 'red_car' => "\xF0\x9F\x9A\x97", 'car' => "\xF0\x9F\x9A\x97", 'oncoming_automobile' => "\xF0\x9F\x9A\x98", 'blue_car' => "\xF0\x9F\x9A\x99", 'truck' => "\xF0\x9F\x9A\x9A", 'articulated_lorry' => "\xF0\x9F\x9A\x9B", 'tractor' => "\xF0\x9F\x9A\x9C", 'monorail' => "\xF0\x9F\x9A\x9D", 'mountain_railway' => "\xF0\x9F\x9A\x9E", 'suspension_railway' => "\xF0\x9F\x9A\x9F", 'mountain_cableway' => "\xF0\x9F\x9A\xA0", 'aerial_tramway' => "\xF0\x9F\x9A\xA1", 'ship' => "\xF0\x9F\x9A\xA2", 'rowboat' => "\xF0\x9F\x9A\xA3", 'speedboat' => "\xF0\x9F\x9A\xA4", 'traffic_light' => "\xF0\x9F\x9A\xA5", 'vertical_traffic_light' => "\xF0\x9F\x9A\xA6", 'construction' => "\xF0\x9F\x9A\xA7", 'rotating_light' => "\xF0\x9F\x9A\xA8", 'triangular_flag_on_post' => "\xF0\x9F\x9A\xA9", 'door' => "\xF0\x9F\x9A\xAA", 'no_entry_sign' => "\xF0\x9F\x9A\xAB", 'smoking' => "\xF0\x9F\x9A\xAC", 'no_smoking' => "\xF0\x9F\x9A\xAD", 'put_litter_in_its_place' => "\xF0\x9F\x9A\xAE", 'do_not_litter' => "\xF0\x9F\x9A\xAF", 'potable_water' => "\xF0\x9F\x9A\xB0", 'non_potable_water' => "\xF0\x9F\x9A\xB1", 'bike' => "\xF0\x9F\x9A\xB2", 'no_bicycles' => "\xF0\x9F\x9A\xB3", 'bicyclist' => "\xF0\x9F\x9A\xB4", 'mountain_bicyclist' => "\xF0\x9F\x9A\xB5", 'walking' => "\xF0\x9F\x9A\xB6", 'no_pedestrians' => "\xF0\x9F\x9A\xB7", 'children_crossing' => "\xF0\x9F\x9A\xB8", 'mens' => "\xF0\x9F\x9A\xB9", 'womens' => "\xF0\x9F\x9A\xBA", 'restroom' => "\xF0\x9F\x9A\xBB", 'baby_symbol' => "\xF0\x9F\x9A\xBC", 'toilet' => "\xF0\x9F\x9A\xBD", 'wc' => "\xF0\x9F\x9A\xBE", 'shower' => "\xF0\x9F\x9A\xBF", 'bath' => "\xF0\x9F\x9B\x80", 'bathtub' => "\xF0\x9F\x9B\x81", 'passport_control' => "\xF0\x9F\x9B\x82", 'customs' => "\xF0\x9F\x9B\x83", 'baggage_claim' => "\xF0\x9F\x9B\x84", 'left_luggage' => "\xF0\x9F\x9B\x85", 'copyright' => "\xC2\xA9\xEF\xB8\x8F", 'registered' => "\xC2\xAE\xEF\xB8\x8F", 'bangbang' => "\xE2\x80\xBC\xEF\xB8\x8F", 'interrobang' => "\xE2\x81\x89\xEF\xB8\x8F",
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
true
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/macro/markup/PhabricatorImageMacroRemarkupRule.php
src/applications/macro/markup/PhabricatorImageMacroRemarkupRule.php
<?php final class PhabricatorImageMacroRemarkupRule extends PhutilRemarkupRule { private $macros; const KEY_RULE_MACRO = 'rule.macro'; public function apply($text) { return preg_replace_callback( '@^\s*([a-zA-Z0-9:_\x7f-\xff-]+)$@m', array($this, 'markupImageMacro'), $text); } public function markupImageMacro(array $matches) { if ($this->macros === null) { $this->macros = array(); $viewer = $this->getEngine()->getConfig('viewer'); $rows = id(new PhabricatorMacroQuery()) ->setViewer($viewer) ->withStatus(PhabricatorMacroQuery::STATUS_ACTIVE) ->execute(); $this->macros = mpull($rows, 'getPHID', 'getName'); } $name = (string)$matches[1]; if (empty($this->macros[$name])) { return $matches[1]; } $engine = $this->getEngine(); $metadata_key = self::KEY_RULE_MACRO; $metadata = $engine->getTextMetadata($metadata_key, array()); $token = $engine->storeText('<macro>'); $metadata[] = array( 'token' => $token, 'phid' => $this->macros[$name], 'original' => $name, ); $engine->setTextMetadata($metadata_key, $metadata); return $token; } public function didMarkupText() { $engine = $this->getEngine(); $metadata_key = self::KEY_RULE_MACRO; $metadata = $engine->getTextMetadata($metadata_key, array()); if (!$metadata) { return; } $phids = ipull($metadata, 'phid'); $viewer = $this->getEngine()->getConfig('viewer'); // Load all the macros. $macros = id(new PhabricatorMacroQuery()) ->setViewer($viewer) ->withStatus(PhabricatorMacroQuery::STATUS_ACTIVE) ->withPHIDs($phids) ->execute(); $macros = mpull($macros, null, 'getPHID'); // Load all the images and audio. $file_phids = array_merge( array_values(mpull($macros, 'getFilePHID')), array_values(mpull($macros, 'getAudioPHID'))); $file_phids = array_filter($file_phids); $files = array(); if ($file_phids) { $files = id(new PhabricatorFileQuery()) ->setViewer($viewer) ->withPHIDs($file_phids) ->execute(); $files = mpull($files, null, 'getPHID'); } // Replace any macros that we couldn't load the macro or image for with // the original text. foreach ($metadata as $key => $spec) { $macro = idx($macros, $spec['phid']); if ($macro) { $file = idx($files, $macro->getFilePHID()); if ($file) { continue; } } $engine->overwriteStoredText($spec['token'], $spec['original']); unset($metadata[$key]); } foreach ($metadata as $spec) { $macro = $macros[$spec['phid']]; $file = $files[$macro->getFilePHID()]; $src_uri = $file->getBestURI(); if ($this->getEngine()->isTextMode()) { $result = $spec['original'].' <'.$src_uri.'>'; $engine->overwriteStoredText($spec['token'], $result); continue; } else if ($this->getEngine()->isHTMLMailMode()) { $src_uri = PhabricatorEnv::getProductionURI($src_uri); } $id = null; $audio = idx($files, $macro->getAudioPHID()); $should_play = ($audio && $macro->getAudioBehavior() != PhabricatorFileImageMacro::AUDIO_BEHAVIOR_NONE); if ($should_play) { $id = celerity_generate_unique_node_id(); $loop = null; switch ($macro->getAudioBehavior()) { case PhabricatorFileImageMacro::AUDIO_BEHAVIOR_LOOP: $loop = true; break; } Javelin::initBehavior( 'audio-source', array( 'sourceID' => $id, 'audioURI' => $audio->getBestURI(), 'loop' => $loop, )); } $result = $this->newTag( 'img', array( 'id' => $id, 'src' => $src_uri, 'alt' => $spec['original'], 'title' => $spec['original'], 'height' => $file->getImageHeight(), 'width' => $file->getImageWidth(), 'class' => 'phabricator-remarkup-macro', )); $engine->overwriteStoredText($spec['token'], $result); } $engine->setTextMetadata($metadata_key, array()); } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/macro/markup/PhabricatorIconRemarkupRule.php
src/applications/macro/markup/PhabricatorIconRemarkupRule.php
<?php final class PhabricatorIconRemarkupRule extends PhutilRemarkupRule { public function getPriority() { return 200.0; } public function apply($text) { return preg_replace_callback( '@{icon\b((?:[^}\\\\]+|\\\\.)*)}@m', array($this, 'markupIcon'), $text); } public function markupIcon(array $matches) { $engine = $this->getEngine(); $text_mode = $engine->isTextMode(); $mail_mode = $engine->isHTMLMailMode(); if (!$this->isFlatText($matches[0]) || $text_mode || $mail_mode) { return $matches[0]; } $extra = idx($matches, 1); // We allow various forms, like these: // // {icon} // {icon camera} // {icon,camera} // {icon camera color=red} // {icon, camera, color=red} $extra = ltrim($extra, ", \n"); $extra = preg_split('/[\s,]+/', $extra, 2); // Choose some arbitrary default icon so that previews render in a mostly // reasonable way as you're typing the syntax. $icon = idx($extra, 0, 'paw'); $defaults = array( 'color' => null, 'spin' => false, ); $options = idx($extra, 1, ''); $parser = new PhutilSimpleOptions(); $options = $parser->parse($options) + $defaults; // NOTE: We're validating icon and color names to prevent users from // adding arbitrary CSS classes to the document. Although this probably // isn't dangerous, it's safer to validate. static $icon_names; if (!$icon_names) { $icon_names = array_fuse(PHUIIconView::getIcons()); } static $color_names; if (!$color_names) { $color_names = array_fuse(PHUIIconView::getIconColors()); } if (empty($icon_names['fa-'.$icon])) { $icon = 'paw'; } $color = $options['color']; if (empty($color_names[$color])) { $color = null; } $classes = array(); $classes[] = $color; $spin = $options['spin']; if ($spin) { $classes[] = 'ph-spin'; } $icon_view = id(new PHUIIconView()) ->setIcon('fa-'.$icon, implode(' ', $classes)); return $this->getEngine()->storeText($icon_view); } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/feed/PhabricatorFeedStoryPublisher.php
src/applications/feed/PhabricatorFeedStoryPublisher.php
<?php final class PhabricatorFeedStoryPublisher extends Phobject { private $relatedPHIDs; private $storyType; private $storyData; private $storyTime; private $storyAuthorPHID; private $primaryObjectPHID; private $subscribedPHIDs = array(); private $mailRecipientPHIDs = array(); private $notifyAuthor; private $mailTags = array(); private $unexpandablePHIDs = array(); public function setMailTags(array $mail_tags) { $this->mailTags = $mail_tags; return $this; } public function getMailTags() { return $this->mailTags; } public function setNotifyAuthor($notify_author) { $this->notifyAuthor = $notify_author; return $this; } public function getNotifyAuthor() { return $this->notifyAuthor; } public function setRelatedPHIDs(array $phids) { $this->relatedPHIDs = $phids; return $this; } public function setSubscribedPHIDs(array $phids) { $this->subscribedPHIDs = $phids; return $this; } public function setPrimaryObjectPHID($phid) { $this->primaryObjectPHID = $phid; return $this; } public function setUnexpandablePHIDs(array $unexpandable_phids) { $this->unexpandablePHIDs = $unexpandable_phids; return $this; } public function getUnexpandablePHIDs() { return $this->unexpandablePHIDs; } public function setStoryType($story_type) { $this->storyType = $story_type; return $this; } public function setStoryData(array $data) { $this->storyData = $data; return $this; } public function setStoryTime($time) { $this->storyTime = $time; return $this; } public function setStoryAuthorPHID($phid) { $this->storyAuthorPHID = $phid; return $this; } public function setMailRecipientPHIDs(array $phids) { $this->mailRecipientPHIDs = $phids; return $this; } public function publish() { $class = $this->storyType; if (!$class) { throw new Exception( pht( 'Call %s before publishing!', 'setStoryType()')); } if (!class_exists($class)) { throw new Exception( pht( "Story type must be a valid class name and must subclass %s. ". "'%s' is not a loadable class.", 'PhabricatorFeedStory', $class)); } if (!is_subclass_of($class, 'PhabricatorFeedStory')) { throw new Exception( pht( "Story type must be a valid class name and must subclass %s. ". "'%s' is not a subclass of %s.", 'PhabricatorFeedStory', $class, 'PhabricatorFeedStory')); } $chrono_key = $this->generateChronologicalKey(); $story = new PhabricatorFeedStoryData(); $story->setStoryType($this->storyType); $story->setStoryData($this->storyData); $story->setAuthorPHID((string)$this->storyAuthorPHID); $story->setChronologicalKey($chrono_key); $story->save(); if ($this->relatedPHIDs) { $ref = new PhabricatorFeedStoryReference(); $sql = array(); $conn = $ref->establishConnection('w'); foreach (array_unique($this->relatedPHIDs) as $phid) { $sql[] = qsprintf( $conn, '(%s, %s)', $phid, $chrono_key); } queryfx( $conn, 'INSERT INTO %T (objectPHID, chronologicalKey) VALUES %LQ', $ref->getTableName(), $sql); } $subscribed_phids = $this->subscribedPHIDs; if ($subscribed_phids) { $subscribed_phids = $this->filterSubscribedPHIDs($subscribed_phids); $this->insertNotifications($chrono_key, $subscribed_phids); $this->sendNotification($chrono_key, $subscribed_phids); } PhabricatorWorker::scheduleTask( 'FeedPublisherWorker', array( 'key' => $chrono_key, )); return $story; } private function insertNotifications($chrono_key, array $subscribed_phids) { if (!$this->primaryObjectPHID) { throw new Exception( pht( 'You must call %s if you %s!', 'setPrimaryObjectPHID()', 'setSubscribedPHIDs()')); } $notif = new PhabricatorFeedStoryNotification(); $sql = array(); $conn = $notif->establishConnection('w'); $will_receive_mail = array_fill_keys($this->mailRecipientPHIDs, true); $user_phids = array_unique($subscribed_phids); foreach ($user_phids as $user_phid) { if (isset($will_receive_mail[$user_phid])) { $mark_read = 1; } else { $mark_read = 0; } $sql[] = qsprintf( $conn, '(%s, %s, %s, %d)', $this->primaryObjectPHID, $user_phid, $chrono_key, $mark_read); } if ($sql) { queryfx( $conn, 'INSERT INTO %T '. '(primaryObjectPHID, userPHID, chronologicalKey, hasViewed) '. 'VALUES %LQ', $notif->getTableName(), $sql); } PhabricatorUserCache::clearCaches( PhabricatorUserNotificationCountCacheType::KEY_COUNT, $user_phids); } private function sendNotification($chrono_key, array $subscribed_phids) { $data = array( 'key' => (string)$chrono_key, 'type' => 'notification', 'subscribers' => $subscribed_phids, ); PhabricatorNotificationClient::tryToPostMessage($data); } /** * Remove PHIDs who should not receive notifications from a subscriber list. * * @param list<phid> List of potential subscribers. * @return list<phid> List of actual subscribers. */ private function filterSubscribedPHIDs(array $phids) { $phids = $this->expandRecipients($phids); $tags = $this->getMailTags(); if ($tags) { $all_prefs = id(new PhabricatorUserPreferencesQuery()) ->setViewer(PhabricatorUser::getOmnipotentUser()) ->withUserPHIDs($phids) ->needSyntheticPreferences(true) ->execute(); $all_prefs = mpull($all_prefs, null, 'getUserPHID'); } $pref_default = PhabricatorEmailTagsSetting::VALUE_EMAIL; $pref_ignore = PhabricatorEmailTagsSetting::VALUE_IGNORE; $keep = array(); foreach ($phids as $phid) { if (($phid == $this->storyAuthorPHID) && !$this->getNotifyAuthor()) { continue; } if ($tags && isset($all_prefs[$phid])) { $mailtags = $all_prefs[$phid]->getSettingValue( PhabricatorEmailTagsSetting::SETTINGKEY); $notify = false; foreach ($tags as $tag) { // If this is set to "email" or "notify", notify the user. if ((int)idx($mailtags, $tag, $pref_default) != $pref_ignore) { $notify = true; break; } } if (!$notify) { continue; } } $keep[] = $phid; } return array_values(array_unique($keep)); } private function expandRecipients(array $phids) { $expanded_phids = id(new PhabricatorMetaMTAMemberQuery()) ->setViewer(PhabricatorUser::getOmnipotentUser()) ->withPHIDs($phids) ->executeExpansion(); // Filter out unexpandable PHIDs from the results. The typical case for // this is that resigned reviewers should not be notified just because // they are a member of some project or package reviewer. $original_map = array_fuse($phids); $unexpandable_map = array_fuse($this->unexpandablePHIDs); foreach ($expanded_phids as $key => $phid) { // We can keep this expanded PHID if it was present originally. if (isset($original_map[$phid])) { continue; } // We can also keep it if it isn't marked as unexpandable. if (!isset($unexpandable_map[$phid])) { continue; } // If it's unexpandable and we produced it by expanding recipients, // throw it away. unset($expanded_phids[$key]); } $expanded_phids = array_values($expanded_phids); return $expanded_phids; } /** * We generate a unique chronological key for each story type because we want * to be able to page through the stream with a cursor (i.e., select stories * after ID = X) so we can efficiently perform filtering after selecting data, * and multiple stories with the same ID make this cumbersome without putting * a bunch of logic in the client. We could use the primary key, but that * would prevent publishing stories which happened in the past. Since it's * potentially useful to do that (e.g., if you're importing another data * source) build a unique key for each story which has chronological ordering. * * @return string A unique, time-ordered key which identifies the story. */ private function generateChronologicalKey() { // Use the epoch timestamp for the upper 32 bits of the key. Default to // the current time if the story doesn't have an explicit timestamp. $time = nonempty($this->storyTime, time()); // Generate a random number for the lower 32 bits of the key. $rand = head(unpack('L', Filesystem::readRandomBytes(4))); // On 32-bit machines, we have to get creative. if (PHP_INT_SIZE < 8) { // We're on a 32-bit machine. if (function_exists('bcadd')) { // Try to use the 'bc' extension. return bcadd(bcmul($time, bcpow(2, 32)), $rand); } else { // Do the math in MySQL. TODO: If we formalize a bc dependency, get // rid of this. $conn_r = id(new PhabricatorFeedStoryData())->establishConnection('r'); $result = queryfx_one( $conn_r, 'SELECT (%d << 32) + %d as N', $time, $rand); return $result['N']; } } else { // This is a 64 bit machine, so we can just do the math. return ($time << 32) + $rand; } } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/feed/controller/PhabricatorFeedDetailController.php
src/applications/feed/controller/PhabricatorFeedDetailController.php
<?php final class PhabricatorFeedDetailController extends PhabricatorFeedController { public function handleRequest(AphrontRequest $request) { $viewer = $request->getViewer(); $id = $request->getURIData('id'); $story = id(new PhabricatorFeedQuery()) ->setViewer($viewer) ->withChronologicalKeys(array($id)) ->executeOne(); if (!$story) { return new Aphront404Response(); } if ($request->getStr('text')) { $text = $story->renderText(); return id(new AphrontPlainTextResponse())->setContent($text); } $feed = array($story); $builder = new PhabricatorFeedBuilder($feed); $builder->setUser($viewer); $feed_view = $builder->buildView(); $title = pht('Story'); $crumbs = $this->buildApplicationCrumbs(); $crumbs->addTextCrumb($title); return $this->newPage() ->setTitle($title) ->setCrumbs($crumbs) ->appendChild($feed_view); } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/feed/controller/PhabricatorFeedController.php
src/applications/feed/controller/PhabricatorFeedController.php
<?php abstract class PhabricatorFeedController extends PhabricatorController {}
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/feed/controller/PhabricatorFeedTransactionListController.php
src/applications/feed/controller/PhabricatorFeedTransactionListController.php
<?php final class PhabricatorFeedTransactionListController extends PhabricatorFeedController { public function shouldAllowPublic() { return true; } public function handleRequest(AphrontRequest $request) { return id(new PhabricatorFeedTransactionSearchEngine()) ->setController($this) ->buildResponse(); } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/feed/controller/PhabricatorFeedListController.php
src/applications/feed/controller/PhabricatorFeedListController.php
<?php final class PhabricatorFeedListController extends PhabricatorFeedController { public function shouldAllowPublic() { return true; } public function handleRequest(AphrontRequest $request) { $navigation = array(); $navigation[] = id(new PHUIListItemView()) ->setType(PHUIListItemView::TYPE_LABEL) ->setName(pht('Transactions')); $navigation[] = id(new PHUIListItemView()) ->setName(pht('Transaction Logs')) ->setHref($this->getApplicationURI('transactions/')); return id(new PhabricatorFeedSearchEngine()) ->setController($this) ->setNavigationItems($navigation) ->buildResponse(); } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/feed/storage/PhabricatorFeedStoryData.php
src/applications/feed/storage/PhabricatorFeedStoryData.php
<?php final class PhabricatorFeedStoryData extends PhabricatorFeedDAO implements PhabricatorDestructibleInterface { protected $phid; protected $storyType; protected $storyData; protected $authorPHID; protected $chronologicalKey; protected function getConfiguration() { return array( self::CONFIG_AUX_PHID => true, self::CONFIG_SERIALIZATION => array( 'storyData' => self::SERIALIZATION_JSON, ), self::CONFIG_COLUMN_SCHEMA => array( 'chronologicalKey' => 'uint64', 'storyType' => 'text64', ), self::CONFIG_KEY_SCHEMA => array( 'key_phid' => null, 'phid' => array( 'columns' => array('phid'), 'unique' => true, ), 'chronologicalKey' => array( 'columns' => array('chronologicalKey'), 'unique' => true, ), ), ) + parent::getConfiguration(); } public function generatePHID() { return PhabricatorPHID::generateNewPHID( PhabricatorPHIDConstants::PHID_TYPE_STRY); } public function getEpoch() { if (PHP_INT_SIZE < 8) { // We're on a 32-bit machine. if (function_exists('bcadd')) { // Try to use the 'bc' extension. return bcdiv($this->chronologicalKey, bcpow(2, 32)); } else { // Do the math in MySQL. TODO: If we formalize a bc dependency, get // rid of this. // See: PhabricatorFeedStoryPublisher::generateChronologicalKey() $conn_r = id($this->establishConnection('r')); $result = queryfx_one( $conn_r, // Insert the chronologicalKey as a string since longs don't seem to // be supported by qsprintf and ints get maxed on 32 bit machines. 'SELECT (%s >> 32) as N', $this->chronologicalKey); return $result['N']; } } else { return $this->chronologicalKey >> 32; } } public function getValue($key, $default = null) { return idx($this->storyData, $key, $default); } /* -( PhabricatorDestructibleInterface )----------------------------------- */ public function destroyObjectPermanently( PhabricatorDestructionEngine $engine) { $this->openTransaction(); $conn = $this->establishConnection('w'); queryfx( $conn, 'DELETE FROM %T WHERE chronologicalKey = %s', id(new PhabricatorFeedStoryNotification())->getTableName(), $this->getChronologicalKey()); queryfx( $conn, 'DELETE FROM %T WHERE chronologicalKey = %s', id(new PhabricatorFeedStoryReference())->getTableName(), $this->getChronologicalKey()); $this->delete(); $this->saveTransaction(); } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/feed/storage/PhabricatorFeedStoryReference.php
src/applications/feed/storage/PhabricatorFeedStoryReference.php
<?php final class PhabricatorFeedStoryReference extends PhabricatorFeedDAO { protected $objectPHID; protected $chronologicalKey; protected function getConfiguration() { return array( self::CONFIG_IDS => self::IDS_MANUAL, self::CONFIG_TIMESTAMPS => false, self::CONFIG_COLUMN_SCHEMA => array( 'chronologicalKey' => 'uint64', 'id' => null, ), self::CONFIG_KEY_SCHEMA => array( 'PRIMARY' => null, 'objectPHID' => array( 'columns' => array('objectPHID', 'chronologicalKey'), 'unique' => true, ), 'chronologicalKey' => array( 'columns' => array('chronologicalKey'), ), ), ) + parent::getConfiguration(); } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/feed/storage/PhabricatorFeedDAO.php
src/applications/feed/storage/PhabricatorFeedDAO.php
<?php abstract class PhabricatorFeedDAO extends PhabricatorLiskDAO { public function getApplicationName() { return 'feed'; } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/feed/management/PhabricatorFeedManagementWorkflow.php
src/applications/feed/management/PhabricatorFeedManagementWorkflow.php
<?php abstract class PhabricatorFeedManagementWorkflow extends PhabricatorManagementWorkflow {}
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/feed/management/PhabricatorFeedManagementRepublishWorkflow.php
src/applications/feed/management/PhabricatorFeedManagementRepublishWorkflow.php
<?php final class PhabricatorFeedManagementRepublishWorkflow extends PhabricatorFeedManagementWorkflow { protected function didConstruct() { $this ->setName('republish') ->setExamples('**republish** __story_key__') ->setSynopsis( pht( 'Republish a feed event to all consumers.')) ->setArguments( array( array( 'name' => 'key', 'wildcard' => true, ), )); } public function execute(PhutilArgumentParser $args) { $console = PhutilConsole::getConsole(); $viewer = $this->getViewer(); $key = $args->getArg('key'); if (count($key) < 1) { throw new PhutilArgumentUsageException( pht('Specify a story key to republish.')); } else if (count($key) > 1) { throw new PhutilArgumentUsageException( pht('Specify exactly one story key to republish.')); } $key = head($key); $story = id(new PhabricatorFeedQuery()) ->setViewer($viewer) ->withChronologicalKeys(array($key)) ->executeOne(); if (!$story) { throw new PhutilArgumentUsageException( pht('No story exists with key "%s"!', $key)); } $console->writeOut("%s\n", pht('Republishing story...')); PhabricatorWorker::setRunAllTasksInProcess(true); PhabricatorWorker::scheduleTask( 'FeedPublisherWorker', array( 'key' => $key, )); $console->writeOut("%s\n", pht('Done.')); return 0; } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/feed/worker/FeedPushWorker.php
src/applications/feed/worker/FeedPushWorker.php
<?php abstract class FeedPushWorker extends PhabricatorWorker { protected function loadFeedStory() { $task_data = $this->getTaskData(); $key = $task_data['key']; $story = id(new PhabricatorFeedQuery()) ->setViewer(PhabricatorUser::getOmnipotentUser()) ->withChronologicalKeys(array($key)) ->executeOne(); if (!$story) { throw new PhabricatorWorkerPermanentFailureException( pht( 'Feed story (with key "%s") does not exist or could not be loaded.', $key)); } return $story; } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/feed/worker/FeedPublisherHTTPWorker.php
src/applications/feed/worker/FeedPublisherHTTPWorker.php
<?php final class FeedPublisherHTTPWorker extends FeedPushWorker { protected function doWork() { if (PhabricatorEnv::getEnvConfig('phabricator.silent')) { // Don't invoke hooks in silent mode. return; } $story = $this->loadFeedStory(); $data = $story->getStoryData(); $uri = idx($this->getTaskData(), 'uri'); $valid_uris = PhabricatorEnv::getEnvConfig('feed.http-hooks'); if (!in_array($uri, $valid_uris)) { throw new PhabricatorWorkerPermanentFailureException(); } $post_data = array( 'storyID' => $data->getID(), 'storyType' => $data->getStoryType(), 'storyData' => $data->getStoryData(), 'storyAuthorPHID' => $data->getAuthorPHID(), 'storyText' => $story->renderText(), 'epoch' => $data->getEpoch(), ); // NOTE: We're explicitly using "http_build_query()" here because the // "storyData" parameter may be a nested object with arbitrary nested // sub-objects. $post_data = http_build_query($post_data, '', '&'); id(new HTTPSFuture($uri, $post_data)) ->setMethod('POST') ->setTimeout(30) ->resolvex(); } public function getWaitBeforeRetry(PhabricatorWorkerTask $task) { return max($task->getFailureCount(), 1) * 60; } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/feed/worker/FeedPublisherWorker.php
src/applications/feed/worker/FeedPublisherWorker.php
<?php final class FeedPublisherWorker extends FeedPushWorker { protected function doWork() { $story = $this->loadFeedStory(); $uris = PhabricatorEnv::getEnvConfig('feed.http-hooks'); if ($uris) { foreach ($uris as $uri) { $this->queueTask( 'FeedPublisherHTTPWorker', array( 'key' => $story->getChronologicalKey(), 'uri' => $uri, )); } } $argv = array( array(), ); // Find and schedule all the enabled Doorkeeper publishers. // TODO: Use PhutilClassMapQuery? $doorkeeper_workers = id(new PhutilSymbolLoader()) ->setAncestorClass('DoorkeeperFeedWorker') ->loadObjects($argv); foreach ($doorkeeper_workers as $worker) { if (!$worker->isEnabled()) { continue; } $this->queueTask( get_class($worker), array( 'key' => $story->getChronologicalKey(), )); } } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/feed/query/PhabricatorFeedSearchEngine.php
src/applications/feed/query/PhabricatorFeedSearchEngine.php
<?php final class PhabricatorFeedSearchEngine extends PhabricatorApplicationSearchEngine { public function getResultTypeDescription() { return pht('Feed Stories'); } public function getApplicationClassName() { return 'PhabricatorFeedApplication'; } public function newQuery() { return new PhabricatorFeedQuery(); } protected function shouldShowOrderField() { return false; } protected function buildCustomSearchFields() { return array( id(new PhabricatorUsersSearchField()) ->setLabel(pht('Include Users')) ->setKey('userPHIDs'), // NOTE: This query is not executed with EdgeLogic, so we can't use // a fancy logical datasource. id(new PhabricatorSearchDatasourceField()) ->setDatasource(new PhabricatorProjectDatasource()) ->setLabel(pht('Include Projects')) ->setKey('projectPHIDs'), id(new PhabricatorSearchDateControlField()) ->setLabel(pht('Occurs After')) ->setKey('rangeStart'), id(new PhabricatorSearchDateControlField()) ->setLabel(pht('Occurs Before')) ->setKey('rangeEnd'), // NOTE: This is a legacy field retained only for backward // compatibility. If the projects field used EdgeLogic, we could use // `viewerprojects()` to execute an equivalent query. id(new PhabricatorSearchCheckboxesField()) ->setKey('viewerProjects') ->setOptions( array( 'self' => pht('Include stories about projects I am a member of.'), )), ); } protected function buildQueryFromParameters(array $map) { $query = $this->newQuery(); $phids = array(); if ($map['userPHIDs']) { $phids += array_fuse($map['userPHIDs']); } if ($map['projectPHIDs']) { $phids += array_fuse($map['projectPHIDs']); } // NOTE: This value may be `true` for older saved queries, or // `array('self')` for newer ones. $viewer_projects = $map['viewerProjects']; if ($viewer_projects) { $viewer = $this->requireViewer(); $projects = id(new PhabricatorProjectQuery()) ->setViewer($viewer) ->withMemberPHIDs(array($viewer->getPHID())) ->execute(); $phids += array_fuse(mpull($projects, 'getPHID')); } if ($phids) { $query->withFilterPHIDs($phids); } $range_min = $map['rangeStart']; if ($range_min) { $range_min = $range_min->getEpoch(); } $range_max = $map['rangeEnd']; if ($range_max) { $range_max = $range_max->getEpoch(); } if ($range_min && $range_max) { if ($range_min > $range_max) { throw new PhabricatorSearchConstraintException( pht( 'The specified "Occurs Before" date is earlier in time than the '. 'specified "Occurs After" date, so this query can never match '. 'any results.')); } } if ($range_min || $range_max) { $query->withEpochInRange($range_min, $range_max); } return $query; } protected function getURI($path) { return '/feed/'.$path; } protected function getBuiltinQueryNames() { $names = array( 'all' => pht('All Stories'), ); if ($this->requireViewer()->isLoggedIn()) { $names['projects'] = pht('Tags'); } return $names; } public function buildSavedQueryFromBuiltin($query_key) { $query = $this->newSavedQuery(); $query->setQueryKey($query_key); switch ($query_key) { case 'all': return $query; case 'projects': return $query->setParameter('viewerProjects', array('self')); } return parent::buildSavedQueryFromBuiltin($query_key); } protected function renderResultList( array $objects, PhabricatorSavedQuery $query, array $handles) { $builder = new PhabricatorFeedBuilder($objects); if ($this->isPanelContext()) { $builder->setShowHovercards(false); } else { $builder->setShowHovercards(true); } $builder->setUser($this->requireViewer()); $view = $builder->buildView(); $list = phutil_tag_div('phabricator-feed-frame', $view); $result = new PhabricatorApplicationSearchResultView(); $result->setContent($list); return $result; } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/feed/query/PhabricatorFeedTransactionQuery.php
src/applications/feed/query/PhabricatorFeedTransactionQuery.php
<?php final class PhabricatorFeedTransactionQuery extends PhabricatorCursorPagedPolicyAwareQuery { private $phids; private $authorPHIDs; private $objectTypes; private $createdMin; private $createdMax; public function withPHIDs(array $phids) { $this->phids = $phids; return $this; } public function withAuthorPHIDs(array $phids) { $this->authorPHIDs = $phids; return $this; } public function withObjectTypes(array $types) { $this->objectTypes = $types; return $this; } public function withDateCreatedBetween($min, $max) { $this->createdMin = $min; $this->createdMax = $max; return $this; } public function newResultObject() { // Return an arbitrary valid transaction object. The actual query may // return objects of any subclass of "ApplicationTransaction" when it is // executed, but we need to pick something concrete here to make some // integrations work (like automatic handling of PHIDs in data export). return new PhabricatorUserTransaction(); } protected function loadPage() { $queries = $this->newTransactionQueries(); $xactions = array(); if ($this->shouldLimitResults()) { $limit = $this->getRawResultLimit(); if (!$limit) { $limit = null; } } else { $limit = null; } // We're doing a bit of manual work to get paging working, because this // query aggregates the results of a large number of subqueries. // Overall, we're ordering transactions by "<dateCreated, phid>". Ordering // by PHID is not very meaningful, but we don't need the ordering to be // especially meaningful, just consistent. Using PHIDs is easy and does // everything we need it to technically. // To actually configure paging, if we have an external cursor, we load // the internal cursor first. Then we pass it to each subquery and the // subqueries pretend they just loaded a page where it was the last object. // This configures their queries properly and we can aggregate a cohesive // set of results by combining all the queries. $cursor = $this->getExternalCursorString(); if ($cursor !== null) { $cursor_object = $this->newInternalCursorFromExternalCursor($cursor); } else { $cursor_object = null; } $is_reversed = $this->getIsQueryOrderReversed(); $created_min = $this->createdMin; $created_max = $this->createdMax; $xaction_phids = $this->phids; $author_phids = $this->authorPHIDs; foreach ($queries as $query) { $query->withDateCreatedBetween($created_min, $created_max); if ($xaction_phids !== null) { $query->withPHIDs($xaction_phids); } if ($author_phids !== null) { $query->withAuthorPHIDs($author_phids); } if ($limit !== null) { $query->setLimit($limit); } if ($cursor_object !== null) { $query ->setAggregatePagingCursor($cursor_object) ->setIsQueryOrderReversed($is_reversed); } $query->setOrder('global'); $query_xactions = $query->execute(); foreach ($query_xactions as $query_xaction) { $xactions[] = $query_xaction; } $xactions = msortv($xactions, 'newGlobalSortVector'); if ($is_reversed) { $xactions = array_reverse($xactions); } if ($limit !== null) { $xactions = array_slice($xactions, 0, $limit); // If we've found enough transactions to fill up the entire requested // page size, we can narrow the search window: transactions after the // last transaction we've found so far can't possibly be part of the // result set. if (count($xactions) === $limit) { $last_date = last($xactions)->getDateCreated(); if ($is_reversed) { if ($created_max === null) { $created_max = $last_date; } else { $created_max = min($created_max, $last_date); } } else { if ($created_min === null) { $created_min = $last_date; } else { $created_min = max($created_min, $last_date); } } } } } return $xactions; } public function getQueryApplicationClass() { return 'PhabricatorFeedApplication'; } private function newTransactionQueries() { $viewer = $this->getViewer(); $queries = id(new PhutilClassMapQuery()) ->setAncestorClass('PhabricatorApplicationTransactionQuery') ->execute(); $type_map = array(); // If we're querying for specific transaction PHIDs, we only need to // consider queries which may load transactions with subtypes present // in the list. // For example, if we're loading Maniphest Task transaction PHIDs, we know // we only have to look at Maniphest Task transactions, since other types // of objects will never have the right transaction PHIDs. $xaction_phids = $this->phids; if ($xaction_phids) { foreach ($xaction_phids as $xaction_phid) { $type_map[phid_get_subtype($xaction_phid)] = true; } } $object_types = $this->objectTypes; if ($object_types) { $object_types = array_fuse($object_types); } $results = array(); foreach ($queries as $query) { $query_type = $query->getTemplateApplicationTransaction() ->getApplicationTransactionType(); if ($type_map) { if (!isset($type_map[$query_type])) { continue; } } if ($object_types) { if (!isset($object_types[$query_type])) { continue; } } $results[] = id(clone $query) ->setViewer($viewer) ->setParentQuery($this); } return $results; } protected function newExternalCursorStringForResult($object) { return (string)$object->getPHID(); } protected function applyExternalCursorConstraintsToQuery( PhabricatorCursorPagedPolicyAwareQuery $subquery, $cursor) { $subquery->withPHIDs(array($cursor)); } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/feed/query/PhabricatorFeedQuery.php
src/applications/feed/query/PhabricatorFeedQuery.php
<?php final class PhabricatorFeedQuery extends PhabricatorCursorPagedPolicyAwareQuery { private $filterPHIDs; private $chronologicalKeys; private $rangeMin; private $rangeMax; public function withFilterPHIDs(array $phids) { $this->filterPHIDs = $phids; return $this; } public function withChronologicalKeys(array $keys) { $this->chronologicalKeys = $keys; return $this; } public function withEpochInRange($range_min, $range_max) { $this->rangeMin = $range_min; $this->rangeMax = $range_max; return $this; } public function newResultObject() { return new PhabricatorFeedStoryData(); } protected function loadPage() { // NOTE: We return raw rows from this method, which is a little unusual. return $this->loadStandardPageRows($this->newResultObject()); } protected function willFilterPage(array $data) { $stories = PhabricatorFeedStory::loadAllFromRows($data, $this->getViewer()); foreach ($stories as $key => $story) { if (!$story->isVisibleInFeed()) { unset($stories[$key]); } } return $stories; } protected function buildJoinClauseParts(AphrontDatabaseConnection $conn) { $joins = parent::buildJoinClauseParts($conn); // NOTE: We perform this join unconditionally (even if we have no filter // PHIDs) to omit rows which have no story references. These story data // rows are notifications or realtime alerts. $ref_table = new PhabricatorFeedStoryReference(); $joins[] = qsprintf( $conn, 'JOIN %T ref ON ref.chronologicalKey = story.chronologicalKey', $ref_table->getTableName()); return $joins; } protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) { $where = parent::buildWhereClauseParts($conn); if ($this->filterPHIDs !== null) { $where[] = qsprintf( $conn, 'ref.objectPHID IN (%Ls)', $this->filterPHIDs); } if ($this->chronologicalKeys !== null) { // NOTE: We can't use "%d" to format these large integers on 32-bit // systems. Historically, we formatted these into integers in an // awkward way because MySQL could sometimes (?) fail to use the proper // keys if the values were formatted as strings instead of integers. // After the "qsprintf()" update to use PhutilQueryString, we can no // longer do this in a sneaky way. However, the MySQL key issue also // no longer appears to reproduce across several systems. So: just use // strings until problems turn up? $where[] = qsprintf( $conn, 'ref.chronologicalKey IN (%Ls)', $this->chronologicalKeys); } // NOTE: We may not have 64-bit PHP, so do the shifts in MySQL instead. // From EXPLAIN, it appears like MySQL is smart enough to compute the // result and make use of keys to execute the query. if ($this->rangeMin !== null) { $where[] = qsprintf( $conn, 'ref.chronologicalKey >= (%d << 32)', $this->rangeMin); } if ($this->rangeMax !== null) { $where[] = qsprintf( $conn, 'ref.chronologicalKey < (%d << 32)', $this->rangeMax); } return $where; } protected function buildGroupClause(AphrontDatabaseConnection $conn) { if ($this->filterPHIDs !== null) { return qsprintf($conn, 'GROUP BY ref.chronologicalKey'); } else { return qsprintf($conn, 'GROUP BY story.chronologicalKey'); } } protected function getDefaultOrderVector() { return array('key'); } public function getBuiltinOrders() { return array( 'newest' => array( 'vector' => array('key'), 'name' => pht('Creation (Newest First)'), 'aliases' => array('created'), ), 'oldest' => array( 'vector' => array('-key'), 'name' => pht('Creation (Oldest First)'), ), ); } public function getOrderableColumns() { $table = ($this->filterPHIDs ? 'ref' : 'story'); return array( 'key' => array( 'table' => $table, 'column' => 'chronologicalKey', 'type' => 'string', 'unique' => true, ), ); } protected function applyExternalCursorConstraintsToQuery( PhabricatorCursorPagedPolicyAwareQuery $subquery, $cursor) { $subquery->withChronologicalKeys(array($cursor)); } protected function newExternalCursorStringForResult($object) { return $object->getChronologicalKey(); } protected function newPagingMapFromPartialObject($object) { // This query is unusual, and the "object" is a raw result row. return array( 'key' => $object['chronologicalKey'], ); } protected function getPrimaryTableAlias() { return 'story'; } public function getQueryApplicationClass() { return 'PhabricatorFeedApplication'; } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/feed/query/PhabricatorFeedTransactionSearchEngine.php
src/applications/feed/query/PhabricatorFeedTransactionSearchEngine.php
<?php final class PhabricatorFeedTransactionSearchEngine extends PhabricatorApplicationSearchEngine { public function getResultTypeDescription() { return pht('Transactions'); } public function getApplicationClassName() { return 'PhabricatorFeedApplication'; } public function newQuery() { return new PhabricatorFeedTransactionQuery(); } protected function buildCustomSearchFields() { return array( id(new PhabricatorUsersSearchField()) ->setLabel(pht('Authors')) ->setKey('authorPHIDs') ->setAliases(array('author', 'authors')), id(new PhabricatorSearchDatasourceField()) ->setLabel(pht('Object Types')) ->setKey('objectTypes') ->setAliases(array('objectType')) ->setDatasource(new PhabricatorTransactionsObjectTypeDatasource()), id(new PhabricatorSearchDateField()) ->setLabel(pht('Created After')) ->setKey('createdStart'), id(new PhabricatorSearchDateField()) ->setLabel(pht('Created Before')) ->setKey('createdEnd'), ); } protected function buildQueryFromParameters(array $map) { $query = $this->newQuery(); if ($map['authorPHIDs']) { $query->withAuthorPHIDs($map['authorPHIDs']); } if ($map['objectTypes']) { $query->withObjectTypes($map['objectTypes']); } $created_min = $map['createdStart']; $created_max = $map['createdEnd']; if ($created_min && $created_max) { if ($created_min > $created_max) { throw new PhabricatorSearchConstraintException( pht( 'The specified "Created Before" date is earlier in time than the '. 'specified "Created After" date, so this query can never match '. 'any results.')); } } if ($created_min || $created_max) { $query->withDateCreatedBetween($created_min, $created_max); } return $query; } protected function getURI($path) { return '/feed/transactions/'.$path; } protected function getBuiltinQueryNames() { $names = array( 'all' => pht('All Transactions'), ); return $names; } public function buildSavedQueryFromBuiltin($query_key) { $query = $this->newSavedQuery() ->setQueryKey($query_key); switch ($query_key) { case 'all': return $query; } return parent::buildSavedQueryFromBuiltin($query_key); } protected function renderResultList( array $objects, PhabricatorSavedQuery $query, array $handles) { assert_instances_of($objects, 'PhabricatorApplicationTransaction'); $viewer = $this->requireViewer(); $handle_phids = array(); foreach ($objects as $object) { $author_phid = $object->getAuthorPHID(); if ($author_phid !== null) { $handle_phids[] = $author_phid; } $object_phid = $object->getObjectPHID(); if ($object_phid !== null) { $handle_phids[] = $object_phid; } } $handles = $viewer->loadHandles($handle_phids); $rows = array(); foreach ($objects as $object) { $author_phid = $object->getAuthorPHID(); $object_phid = $object->getObjectPHID(); try { $title = $object->getTitle(); } catch (Exception $ex) { $title = null; } $rows[] = array( $handles[$author_phid]->renderLink(), $handles[$object_phid]->renderLink(), AphrontTableView::renderSingleDisplayLine($title), phabricator_datetime($object->getDateCreated(), $viewer), ); } $table = id(new AphrontTableView($rows)) ->setHeaders( array( pht('Author'), pht('Object'), pht('Transaction'), pht('Date'), )) ->setColumnClasses( array( null, null, 'wide', 'right', )); return id(new PhabricatorApplicationSearchResultView()) ->setTable($table); } protected function newExportFields() { $fields = array( id(new PhabricatorPHIDExportField()) ->setKey('authorPHID') ->setLabel(pht('Author PHID')), id(new PhabricatorStringExportField()) ->setKey('author') ->setLabel(pht('Author')), id(new PhabricatorStringExportField()) ->setKey('objectType') ->setLabel(pht('Object Type')), id(new PhabricatorPHIDExportField()) ->setKey('objectPHID') ->setLabel(pht('Object PHID')), id(new PhabricatorStringExportField()) ->setKey('objectName') ->setLabel(pht('Object Name')), id(new PhabricatorStringExportField()) ->setKey('description') ->setLabel(pht('Description')), ); return $fields; } protected function newExportData(array $xactions) { $viewer = $this->requireViewer(); $phids = array(); foreach ($xactions as $xaction) { $phids[] = $xaction->getAuthorPHID(); $phids[] = $xaction->getObjectPHID(); } $handles = $viewer->loadHandles($phids); $export = array(); foreach ($xactions as $xaction) { $xaction_phid = $xaction->getPHID(); $author_phid = $xaction->getAuthorPHID(); if ($author_phid) { $author_name = $handles[$author_phid]->getName(); } else { $author_name = null; } $object_phid = $xaction->getObjectPHID(); if ($object_phid) { $object_name = $handles[$object_phid]->getName(); } else { $object_name = null; } $old_target = $xaction->getRenderingTarget(); try { $description = $xaction ->setRenderingTarget(PhabricatorApplicationTransaction::TARGET_TEXT) ->getTitle(); } catch (Exception $ex) { $description = null; } $xaction->setRenderingTarget($old_target); $export[] = array( 'authorPHID' => $author_phid, 'author' => $author_name, 'objectType' => phid_get_subtype($xaction_phid), 'objectPHID' => $object_phid, 'objectName' => $object_name, 'description' => $description, ); } return $export; } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/feed/builder/PhabricatorFeedBuilder.php
src/applications/feed/builder/PhabricatorFeedBuilder.php
<?php final class PhabricatorFeedBuilder extends Phobject { private $user; private $stories; private $hovercards = false; private $noDataString; public function __construct(array $stories) { assert_instances_of($stories, 'PhabricatorFeedStory'); $this->stories = $stories; } public function setUser(PhabricatorUser $user) { $this->user = $user; return $this; } public function setShowHovercards($hover) { $this->hovercards = $hover; return $this; } public function setNoDataString($string) { $this->noDataString = $string; return $this; } public function buildView() { if (!$this->user) { throw new PhutilInvalidStateException('setUser'); } $user = $this->user; $stories = $this->stories; $null_view = new AphrontNullView(); require_celerity_resource('phabricator-feed-css'); $last_date = null; foreach ($stories as $story) { $story->setHovercard($this->hovercards); $date = ucfirst(phabricator_relative_date($story->getEpoch(), $user)); if ($date !== $last_date) { if ($last_date !== null) { $null_view->appendChild( phutil_tag_div('phabricator-feed-story-date-separator')); } $last_date = $date; $header = new PHUIHeaderView(); $header->setHeader($date); $header->setHeaderIcon('fa-calendar msr'); $null_view->appendChild($header); } try { $view = $story->renderView(); $view->setUser($user); $view = $view->render(); } catch (Exception $ex) { // If rendering failed for any reason, don't fail the entire feed, // just this one story. $view = id(new PHUIFeedStoryView()) ->setUser($user) ->setChronologicalKey($story->getChronologicalKey()) ->setEpoch($story->getEpoch()) ->setTitle( pht('Feed Story Failed to Render (%s)', get_class($story))) ->appendChild(pht('%s: %s', get_class($ex), $ex->getMessage())); } $null_view->appendChild($view); } $box = id(new PHUIObjectBoxView()) ->appendChild($null_view); if (empty($stories)) { $nodatastring = pht('No Stories.'); if ($this->noDataString) { $nodatastring = $this->noDataString; } $view = id(new PHUIBoxView()) ->addClass('mlt mlb msr msl') ->appendChild($nodatastring); $box->appendChild($view); } return $box; } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/feed/application/PhabricatorFeedApplication.php
src/applications/feed/application/PhabricatorFeedApplication.php
<?php final class PhabricatorFeedApplication extends PhabricatorApplication { public function getBaseURI() { return '/feed/'; } public function getName() { return pht('Feed'); } public function getShortDescription() { return pht('Review Recent Activity'); } public function getIcon() { return 'fa-newspaper-o'; } public function getApplicationGroup() { return self::GROUP_UTILITIES; } public function canUninstall() { return false; } public function getRoutes() { return array( '/feed/' => array( '(?P<id>\d+)/' => 'PhabricatorFeedDetailController', '(?:query/(?P<queryKey>[^/]+)/)?' => 'PhabricatorFeedListController', 'transactions/' => array( $this->getQueryRoutePattern() => 'PhabricatorFeedTransactionListController', ), ), ); } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/feed/story/PhabricatorFeedStory.php
src/applications/feed/story/PhabricatorFeedStory.php
<?php /** * Manages rendering and aggregation of a story. A story is an event (like a * user adding a comment) which may be represented in different forms on * different channels (like feed, notifications and realtime alerts). * * @task load Loading Stories * @task policy Policy Implementation */ abstract class PhabricatorFeedStory extends Phobject implements PhabricatorPolicyInterface, PhabricatorMarkupInterface { private $data; private $hasViewed; private $hovercard = false; private $renderingTarget = PhabricatorApplicationTransaction::TARGET_HTML; private $handles = array(); private $objects = array(); private $projectPHIDs = array(); private $markupFieldOutput = array(); /* -( Loading Stories )---------------------------------------------------- */ /** * Given @{class:PhabricatorFeedStoryData} rows, load them into objects and * construct appropriate @{class:PhabricatorFeedStory} wrappers for each * data row. * * @param list<dict> List of @{class:PhabricatorFeedStoryData} rows from the * database. * @return list<PhabricatorFeedStory> List of @{class:PhabricatorFeedStory} * objects. * @task load */ public static function loadAllFromRows(array $rows, PhabricatorUser $viewer) { $stories = array(); $data = id(new PhabricatorFeedStoryData())->loadAllFromArray($rows); foreach ($data as $story_data) { $class = $story_data->getStoryType(); try { $ok = class_exists($class) && is_subclass_of($class, __CLASS__); } catch (PhutilMissingSymbolException $ex) { $ok = false; } // If the story type isn't a valid class or isn't a subclass of // PhabricatorFeedStory, decline to load it. if (!$ok) { continue; } $key = $story_data->getChronologicalKey(); $stories[$key] = newv($class, array($story_data)); } $object_phids = array(); $key_phids = array(); foreach ($stories as $key => $story) { $phids = array(); foreach ($story->getRequiredObjectPHIDs() as $phid) { $phids[$phid] = true; } if ($story->getPrimaryObjectPHID()) { $phids[$story->getPrimaryObjectPHID()] = true; } $key_phids[$key] = $phids; $object_phids += $phids; } $object_query = id(new PhabricatorObjectQuery()) ->setViewer($viewer) ->withPHIDs(array_keys($object_phids)); $objects = $object_query->execute(); foreach ($key_phids as $key => $phids) { if (!$phids) { continue; } $story_objects = array_select_keys($objects, array_keys($phids)); if (count($story_objects) != count($phids)) { // An object this story requires either does not exist or is not visible // to the user. Decline to render the story. unset($stories[$key]); unset($key_phids[$key]); continue; } $stories[$key]->setObjects($story_objects); } // If stories are about PhabricatorProjectInterface objects, load the // projects the objects are a part of so we can render project tags // on the stories. $project_phids = array(); foreach ($objects as $object) { if ($object instanceof PhabricatorProjectInterface) { $project_phids[$object->getPHID()] = array(); } } if ($project_phids) { $edge_query = id(new PhabricatorEdgeQuery()) ->withSourcePHIDs(array_keys($project_phids)) ->withEdgeTypes( array( PhabricatorProjectObjectHasProjectEdgeType::EDGECONST, )); $edge_query->execute(); foreach ($project_phids as $phid => $ignored) { $project_phids[$phid] = $edge_query->getDestinationPHIDs(array($phid)); } } $handle_phids = array(); foreach ($stories as $key => $story) { foreach ($story->getRequiredHandlePHIDs() as $phid) { $key_phids[$key][$phid] = true; } if ($story->getAuthorPHID()) { $key_phids[$key][$story->getAuthorPHID()] = true; } $object_phid = $story->getPrimaryObjectPHID(); $object_project_phids = idx($project_phids, $object_phid, array()); $story->setProjectPHIDs($object_project_phids); foreach ($object_project_phids as $dst) { $key_phids[$key][$dst] = true; } $handle_phids += $key_phids[$key]; } // NOTE: This setParentQuery() is a little sketchy. Ideally, this whole // method should be inside FeedQuery and it should be the parent query of // both subqueries. We're just trying to share the workspace cache. $handles = id(new PhabricatorHandleQuery()) ->setViewer($viewer) ->setParentQuery($object_query) ->withPHIDs(array_keys($handle_phids)) ->execute(); foreach ($key_phids as $key => $phids) { if (!$phids) { continue; } $story_handles = array_select_keys($handles, array_keys($phids)); $stories[$key]->setHandles($story_handles); } // Load and process story markup blocks. $engine = new PhabricatorMarkupEngine(); $engine->setViewer($viewer); foreach ($stories as $story) { foreach ($story->getFieldStoryMarkupFields() as $field) { $engine->addObject($story, $field); } } $engine->process(); foreach ($stories as $story) { foreach ($story->getFieldStoryMarkupFields() as $field) { $story->setMarkupFieldOutput( $field, $engine->getOutput($story, $field)); } } return $stories; } public function setMarkupFieldOutput($field, $output) { $this->markupFieldOutput[$field] = $output; return $this; } public function getMarkupFieldOutput($field) { if (!array_key_exists($field, $this->markupFieldOutput)) { throw new Exception( pht( 'Trying to retrieve markup field key "%s", but this feed story '. 'did not request it be rendered.', $field)); } return $this->markupFieldOutput[$field]; } public function setHovercard($hover) { $this->hovercard = $hover; return $this; } public function setRenderingTarget($target) { $this->validateRenderingTarget($target); $this->renderingTarget = $target; return $this; } public function getRenderingTarget() { return $this->renderingTarget; } private function validateRenderingTarget($target) { switch ($target) { case PhabricatorApplicationTransaction::TARGET_HTML: case PhabricatorApplicationTransaction::TARGET_TEXT: break; default: throw new Exception(pht('Unknown rendering target: %s', $target)); break; } } public function setObjects(array $objects) { $this->objects = $objects; return $this; } public function getObject($phid) { $object = idx($this->objects, $phid); if (!$object) { throw new Exception( pht( "Story is asking for an object it did not request ('%s')!", $phid)); } return $object; } public function getPrimaryObject() { $phid = $this->getPrimaryObjectPHID(); if (!$phid) { throw new Exception(pht('Story has no primary object!')); } return $this->getObject($phid); } public function getPrimaryObjectPHID() { return null; } final public function __construct(PhabricatorFeedStoryData $data) { $this->data = $data; } abstract public function renderView(); public function renderAsTextForDoorkeeper( DoorkeeperFeedStoryPublisher $publisher) { // TODO: This (and text rendering) should be properly abstract and // universal. However, this is far less bad than it used to be, and we // need to clean up more old feed code to really make this reasonable. return pht( '(Unable to render story of class %s for Doorkeeper.)', get_class($this)); } public function getRequiredHandlePHIDs() { return array(); } public function getRequiredObjectPHIDs() { return array(); } public function setHasViewed($has_viewed) { $this->hasViewed = $has_viewed; return $this; } public function getHasViewed() { return $this->hasViewed; } final public function setHandles(array $handles) { assert_instances_of($handles, 'PhabricatorObjectHandle'); $this->handles = $handles; return $this; } final protected function getObjects() { return $this->objects; } final protected function getHandles() { return $this->handles; } final protected function getHandle($phid) { if (isset($this->handles[$phid])) { if ($this->handles[$phid] instanceof PhabricatorObjectHandle) { return $this->handles[$phid]; } } $handle = new PhabricatorObjectHandle(); $handle->setPHID($phid); $handle->setName(pht("Unloaded Object '%s'", $phid)); return $handle; } final public function getStoryData() { return $this->data; } final public function getEpoch() { return $this->getStoryData()->getEpoch(); } final public function getChronologicalKey() { return $this->getStoryData()->getChronologicalKey(); } final public function getValue($key, $default = null) { return $this->getStoryData()->getValue($key, $default); } final public function getAuthorPHID() { return $this->getStoryData()->getAuthorPHID(); } final protected function renderHandleList(array $phids) { $items = array(); foreach ($phids as $phid) { $items[] = $this->linkTo($phid); } $list = null; switch ($this->getRenderingTarget()) { case PhabricatorApplicationTransaction::TARGET_TEXT: $list = implode(', ', $items); break; case PhabricatorApplicationTransaction::TARGET_HTML: $list = phutil_implode_html(', ', $items); break; } return $list; } final protected function linkTo($phid) { $handle = $this->getHandle($phid); switch ($this->getRenderingTarget()) { case PhabricatorApplicationTransaction::TARGET_TEXT: return $handle->getLinkName(); } return $handle->renderLink(); } final protected function renderString($str) { switch ($this->getRenderingTarget()) { case PhabricatorApplicationTransaction::TARGET_TEXT: return $str; case PhabricatorApplicationTransaction::TARGET_HTML: return phutil_tag('strong', array(), $str); } } final public function renderSummary($text, $len = 128) { if ($len) { $text = id(new PhutilUTF8StringTruncator()) ->setMaximumGlyphs($len) ->truncateString($text); } switch ($this->getRenderingTarget()) { case PhabricatorApplicationTransaction::TARGET_HTML: $text = phutil_escape_html_newlines($text); break; } return $text; } public function getNotificationAggregations() { return array(); } protected function newStoryView() { $view = id(new PHUIFeedStoryView()) ->setChronologicalKey($this->getChronologicalKey()) ->setEpoch($this->getEpoch()) ->setViewed($this->getHasViewed()); $project_phids = $this->getProjectPHIDs(); if ($project_phids) { $view->setTags($this->renderHandleList($project_phids)); } return $view; } public function setProjectPHIDs(array $phids) { $this->projectPHIDs = $phids; return $this; } public function getProjectPHIDs() { return $this->projectPHIDs; } public function getFieldStoryMarkupFields() { return array(); } public function isVisibleInFeed() { return true; } public function isVisibleInNotifications() { return true; } /* -( PhabricatorPolicyInterface Implementation )-------------------------- */ public function getPHID() { return null; } /** * @task policy */ public function getCapabilities() { return array( PhabricatorPolicyCapability::CAN_VIEW, ); } /** * @task policy */ public function getPolicy($capability) { // NOTE: We enforce that a user can see all the objects a story is about // when loading it, so we don't need to perform a equivalent secondary // policy check later. return PhabricatorPolicies::getMostOpenPolicy(); } /** * @task policy */ public function hasAutomaticCapability($capability, PhabricatorUser $viewer) { return false; } /* -( PhabricatorMarkupInterface Implementation )--------------------------- */ public function getMarkupFieldKey($field) { return 'feed:'.$this->getChronologicalKey().':'.$field; } public function newMarkupEngine($field) { return PhabricatorMarkupEngine::getEngine('feed'); } public function getMarkupText($field) { throw new PhutilMethodNotImplementedException(); } public function didMarkupText( $field, $output, PhutilMarkupEngine $engine) { return $output; } public function shouldUseMarkupCache($field) { return true; } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/feed/config/PhabricatorFeedConfigOptions.php
src/applications/feed/config/PhabricatorFeedConfigOptions.php
<?php final class PhabricatorFeedConfigOptions extends PhabricatorApplicationConfigOptions { public function getName() { return pht('Feed'); } public function getDescription() { return pht('Feed options.'); } public function getIcon() { return 'fa-newspaper-o'; } public function getGroup() { return 'apps'; } public function getOptions() { $hooks_help = $this->deformat(pht(<<<EODOC IMPORTANT: Feed hooks are deprecated and have been replaced by Webhooks. You can configure Webhooks in Herald. This configuration option will be removed in a future version of the software. (This legacy option may be configured with a list of URIs; feed stories will send to these URIs.) EODOC )); return array( $this->newOption('feed.http-hooks', 'list<string>', array()) ->setLocked(true) ->setSummary(pht('Deprecated.')) ->setDescription($hooks_help), ); } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/feed/conduit/FeedQueryConduitAPIMethod.php
src/applications/feed/conduit/FeedQueryConduitAPIMethod.php
<?php final class FeedQueryConduitAPIMethod extends FeedConduitAPIMethod { public function getAPIMethodName() { return 'feed.query'; } public function getMethodStatus() { return self::METHOD_STATUS_UNSTABLE; } public function getMethodDescription() { return pht('Query the feed for stories'); } private function getDefaultLimit() { return 100; } protected function defineParamTypes() { return array( 'filterPHIDs' => 'optional list <phid>', 'limit' => 'optional int (default '.$this->getDefaultLimit().')', 'after' => 'optional int', 'before' => 'optional int', 'view' => 'optional string (data, html, html-summary, text)', ); } private function getSupportedViewTypes() { return array( 'html' => pht('Full HTML presentation of story'), 'data' => pht('Dictionary with various data of the story'), 'html-summary' => pht('Story contains only the title of the story'), 'text' => pht('Simple one-line plain text representation of story'), ); } protected function defineErrorTypes() { $view_types = array_keys($this->getSupportedViewTypes()); $view_types = implode(', ', $view_types); return array( 'ERR-UNKNOWN-TYPE' => pht( 'Unsupported view type, possibles are: %s', $view_types), ); } protected function defineReturnType() { return 'nonempty dict'; } protected function execute(ConduitAPIRequest $request) { $results = array(); $user = $request->getUser(); $view_type = $request->getValue('view'); if (!$view_type) { $view_type = 'data'; } $query = id(new PhabricatorFeedQuery()) ->setViewer($user); $filter_phids = $request->getValue('filterPHIDs'); if ($filter_phids) { $query->withFilterPHIDs($filter_phids); } $limit = $request->getValue('limit'); if (!$limit) { $limit = $this->getDefaultLimit(); } $pager = id(new AphrontCursorPagerView()) ->setPageSize($limit); $after = $request->getValue('after'); if (strlen($after)) { $pager->setAfterID($after); } $before = $request->getValue('before'); if (strlen($before)) { $pager->setBeforeID($before); } $stories = $query->executeWithCursorPager($pager); if ($stories) { foreach ($stories as $story) { $story_data = $story->getStoryData(); $data = null; try { $view = $story->renderView(); } catch (Exception $ex) { // When stories fail to render, just fail that story. phlog($ex); continue; } $view->setEpoch($story->getEpoch()); $view->setUser($user); switch ($view_type) { case 'html': $data = $view->render(); break; case 'html-summary': $data = $view->render(); break; case 'data': $data = array( 'class' => $story_data->getStoryType(), 'epoch' => $story_data->getEpoch(), 'authorPHID' => $story_data->getAuthorPHID(), 'chronologicalKey' => $story_data->getChronologicalKey(), 'data' => $story_data->getStoryData(), ); break; case 'text': $data = array( 'class' => $story_data->getStoryType(), 'epoch' => $story_data->getEpoch(), 'authorPHID' => $story_data->getAuthorPHID(), 'chronologicalKey' => $story_data->getChronologicalKey(), 'objectPHID' => $story->getPrimaryObjectPHID(), 'text' => $story->renderText(), ); break; default: throw new ConduitException('ERR-UNKNOWN-TYPE'); } $results[$story_data->getPHID()] = $data; } } return $results; } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/feed/conduit/FeedConduitAPIMethod.php
src/applications/feed/conduit/FeedConduitAPIMethod.php
<?php abstract class FeedConduitAPIMethod extends ConduitAPIMethod { final public function getApplication() { return PhabricatorApplication::getByClass('PhabricatorFeedApplication'); } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/fact/controller/PhabricatorFactObjectController.php
src/applications/fact/controller/PhabricatorFactObjectController.php
<?php final class PhabricatorFactObjectController extends PhabricatorFactController { public function handleRequest(AphrontRequest $request) { $viewer = $request->getViewer(); $phid = $request->getURIData('phid'); $object = id(new PhabricatorObjectQuery()) ->setViewer($viewer) ->withNames(array($phid)) ->executeOne(); if (!$object) { return new Aphront404Response(); } $engines = PhabricatorFactEngine::loadAllEngines(); foreach ($engines as $key => $engine) { $engine = id(clone $engine) ->setViewer($viewer); $engines[$key] = $engine; if (!$engine->supportsDatapointsForObject($object)) { unset($engines[$key]); } } if (!$engines) { return $this->newDialog() ->setTitle(pht('No Engines')) ->appendParagraph( pht( 'No fact engines support generating facts for this object.')) ->addCancelButton($this->getApplicationURI()); } $key_dimension = new PhabricatorFactKeyDimension(); $object_phid = $object->getPHID(); $facts = array(); $generated_datapoints = array(); $timings = array(); foreach ($engines as $key => $engine) { $engine_facts = $engine->newFacts(); $engine_facts = mpull($engine_facts, null, 'getKey'); $facts[$key] = $engine_facts; $t_start = microtime(true); $generated_datapoints[$key] = $engine->newDatapointsForObject($object); $t_end = microtime(true); $timings[$key] = ($t_end - $t_start); } $object_id = id(new PhabricatorFactObjectDimension()) ->newDimensionID($object_phid, true); $stored_datapoints = id(new PhabricatorFactDatapointQuery()) ->withFacts(array_mergev($facts)) ->withObjectPHIDs(array($object_phid)) ->needVectors(true) ->execute(); $stored_groups = array(); foreach ($stored_datapoints as $stored_datapoint) { $stored_groups[$stored_datapoint['key']][] = $stored_datapoint; } $stored_map = array(); foreach ($engines as $key => $engine) { $stored_map[$key] = array(); foreach ($facts[$key] as $fact) { $fact_datapoints = idx($stored_groups, $fact->getKey(), array()); $fact_datapoints = igroup($fact_datapoints, 'vector'); $stored_map[$key] += $fact_datapoints; } } $handle_phids = array(); $handle_phids[] = $object->getPHID(); foreach ($generated_datapoints as $key => $datapoint_set) { foreach ($datapoint_set as $datapoint) { $dimension_phid = $datapoint->getDimensionPHID(); if ($dimension_phid !== null) { $handle_phids[$dimension_phid] = $dimension_phid; } } } foreach ($stored_map as $key => $stored_datapoints) { foreach ($stored_datapoints as $vector_key => $datapoints) { foreach ($datapoints as $datapoint) { $dimension_phid = $datapoint['dimensionPHID']; if ($dimension_phid !== null) { $handle_phids[$dimension_phid] = $dimension_phid; } } } } $handles = $viewer->loadHandles($handle_phids); $dimension_map = id(new PhabricatorFactObjectDimension()) ->newDimensionMap($handle_phids, true); $content = array(); $object_list = id(new PHUIPropertyListView()) ->setViewer($viewer) ->addProperty( pht('Object'), $handles[$object->getPHID()]->renderLink()); $total_cost = array_sum($timings); $total_cost = pht('%sms', new PhutilNumber((int)(1000 * $total_cost))); $object_list->addProperty(pht('Total Cost'), $total_cost); $object_box = id(new PHUIObjectBoxView()) ->setHeaderText(pht('Fact Extraction Report')) ->addPropertyList($object_list); $content[] = $object_box; $icon_fact = id(new PHUIIconView()) ->setIcon('fa-line-chart green') ->setTooltip(pht('Consistent Fact')); $icon_nodata = id(new PHUIIconView()) ->setIcon('fa-question-circle-o violet') ->setTooltip(pht('No Stored Datapoints')); $icon_new = id(new PHUIIconView()) ->setIcon('fa-plus red') ->setTooltip(pht('Not Stored')); $icon_surplus = id(new PHUIIconView()) ->setIcon('fa-minus red') ->setTooltip(pht('Not Generated')); foreach ($engines as $key => $engine) { $rows = array(); foreach ($generated_datapoints[$key] as $datapoint) { $dimension_phid = $datapoint->getDimensionPHID(); if ($dimension_phid !== null) { $dimension = $handles[$datapoint->getDimensionPHID()]->renderLink(); } else { $dimension = null; } $fact_key = $datapoint->getKey(); $fact = idx($facts[$key], $fact_key, null); if ($fact) { $fact_label = $fact->getName(); } else { $fact_label = $fact_key; } $vector_key = $datapoint->newDatapointVector(); if (isset($stored_map[$key][$vector_key])) { unset($stored_map[$key][$vector_key]); $icon = $icon_fact; } else { $icon = $icon_new; } $rows[] = array( $icon, $fact_label, $dimension, $datapoint->getValue(), phabricator_datetime($datapoint->getEpoch(), $viewer), ); } foreach ($stored_map[$key] as $vector_key => $datapoints) { foreach ($datapoints as $datapoint) { $dimension_phid = $datapoint['dimensionPHID']; if ($dimension_phid !== null) { $dimension = $handles[$dimension_phid]->renderLink(); } else { $dimension = null; } $fact_key = $datapoint['key']; $fact = idx($facts[$key], $fact_key, null); if ($fact) { $fact_label = $fact->getName(); } else { $fact_label = $fact_key; } $rows[] = array( $icon_surplus, $fact_label, $dimension, $datapoint['value'], phabricator_datetime($datapoint['epoch'], $viewer), ); } } foreach ($facts[$key] as $fact) { $has_any = id(new PhabricatorFactDatapointQuery()) ->withFacts(array($fact)) ->setLimit(1) ->execute(); if ($has_any) { continue; } if (!$has_any) { $rows[] = array( $icon_nodata, $fact->getName(), null, null, null, ); } } $table = id(new AphrontTableView($rows)) ->setHeaders( array( null, pht('Fact'), pht('Dimension'), pht('Value'), pht('Date'), )) ->setColumnClasses( array( '', '', '', 'n wide right', 'right', )); $extraction_cost = $timings[$key]; $extraction_cost = pht( '%sms', new PhutilNumber((int)(1000 * $extraction_cost))); $header = pht( '%s (%s)', get_class($engine), $extraction_cost); $box = id(new PHUIObjectBoxView()) ->setHeaderText($header) ->setTable($table); $content[] = $box; if ($engine instanceof PhabricatorTransactionFactEngine) { $groups = $engine->newTransactionGroupsForObject($object); $groups = array_values($groups); $xaction_phids = array(); foreach ($groups as $group_key => $xactions) { foreach ($xactions as $xaction) { $xaction_phids[] = $xaction->getAuthorPHID(); } } $xaction_handles = $viewer->loadHandles($xaction_phids); $rows = array(); foreach ($groups as $group_key => $xactions) { foreach ($xactions as $xaction) { $rows[] = array( $group_key, $xaction->getTransactionType(), $xaction_handles[$xaction->getAuthorPHID()]->renderLink(), phabricator_datetime($xaction->getDateCreated(), $viewer), ); } } $table = id(new AphrontTableView($rows)) ->setHeaders( array( pht('Group'), pht('Type'), pht('Author'), pht('Date'), )) ->setColumnClasses( array( null, 'pri', 'wide', 'right', )); $header = pht( '%s (Transactions)', get_class($engine)); $xaction_box = id(new PHUIObjectBoxView()) ->setHeaderText($header) ->setTable($table); $content[] = $xaction_box; } } $crumbs = $this->buildApplicationCrumbs() ->addTextCrumb(pht('Chart')); $title = pht('Chart'); return $this->newPage() ->setTitle($title) ->setCrumbs($crumbs) ->appendChild($content); } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/fact/controller/PhabricatorFactChartController.php
src/applications/fact/controller/PhabricatorFactChartController.php
<?php final class PhabricatorFactChartController extends PhabricatorFactController { public function handleRequest(AphrontRequest $request) { $viewer = $request->getViewer(); $chart_key = $request->getURIData('chartKey'); if (!$chart_key) { return new Aphront404Response(); } $engine = id(new PhabricatorChartRenderingEngine()) ->setViewer($viewer); $chart = $engine->loadChart($chart_key); if (!$chart) { return new Aphront404Response(); } // When drawing a chart, we send down a placeholder piece of HTML first, // then fetch the data via async request. Determine if we're drawing // the structure or actually pulling the data. $mode = $request->getURIData('mode'); $is_draw_mode = ($mode === 'draw'); $want_data = $is_draw_mode; // In developer mode, always pull the data in the main request. We'll // throw it away if we're just drawing the chart frame, but this currently // makes errors quite a bit easier to debug. if (PhabricatorEnv::getEnvConfig('phabricator.developer-mode')) { $want_data = true; } if ($want_data) { $chart_data = $engine->newChartData(); if ($is_draw_mode) { return id(new AphrontAjaxResponse())->setContent($chart_data); } } $chart_view = $engine->newChartView(); return $this->newChartResponse($chart_view); } private function newChartResponse($chart_view) { $box = id(new PHUIObjectBoxView()) ->setHeaderText(pht('Chart')) ->appendChild($chart_view); $crumbs = $this->buildApplicationCrumbs() ->addTextCrumb(pht('Chart')) ->setBorder(true); $title = pht('Chart'); return $this->newPage() ->setTitle($title) ->setCrumbs($crumbs) ->appendChild( array( $box, )); } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/fact/controller/PhabricatorFactController.php
src/applications/fact/controller/PhabricatorFactController.php
<?php abstract class PhabricatorFactController extends PhabricatorController {}
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/fact/controller/PhabricatorFactHomeController.php
src/applications/fact/controller/PhabricatorFactHomeController.php
<?php final class PhabricatorFactHomeController extends PhabricatorFactController { public function shouldAllowPublic() { return true; } public function handleRequest(AphrontRequest $request) { $viewer = $this->getViewer(); $chart = id(new PhabricatorDemoChartEngine()) ->setViewer($viewer) ->newStoredChart(); return id(new AphrontRedirectResponse())->setURI($chart->getURI()); } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/fact/storage/PhabricatorFactAggregate.php
src/applications/fact/storage/PhabricatorFactAggregate.php
<?php final class PhabricatorFactAggregate extends PhabricatorFactDAO { protected $factType; protected $objectPHID; protected $valueX; protected function getConfiguration() { return array( self::CONFIG_COLUMN_SCHEMA => array( 'id' => 'auto64', 'factType' => 'text32', 'valueX' => 'uint64', ), self::CONFIG_KEY_SCHEMA => array( 'factType' => array( 'columns' => array('factType', 'objectPHID'), 'unique' => true, ), ), ) + parent::getConfiguration(); } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/fact/storage/PhabricatorFactChart.php
src/applications/fact/storage/PhabricatorFactChart.php
<?php final class PhabricatorFactChart extends PhabricatorFactDAO implements PhabricatorPolicyInterface { protected $chartKey; protected $chartParameters = array(); private $datasets = self::ATTACHABLE; protected function getConfiguration() { return array( self::CONFIG_SERIALIZATION => array( 'chartParameters' => self::SERIALIZATION_JSON, ), self::CONFIG_COLUMN_SCHEMA => array( 'chartKey' => 'bytes12', ), self::CONFIG_KEY_SCHEMA => array( 'key_chart' => array( 'columns' => array('chartKey'), 'unique' => true, ), ), ) + parent::getConfiguration(); } public function setChartParameter($key, $value) { $this->chartParameters[$key] = $value; return $this; } public function getChartParameter($key, $default = null) { return idx($this->chartParameters, $key, $default); } public function newChartKey() { $digest = serialize($this->chartParameters); $digest = PhabricatorHash::digestForIndex($digest); return $digest; } public function save() { if ($this->getID()) { throw new Exception( pht( 'Chart configurations are not mutable. You can not update or '. 'overwrite an existing chart configuration.')); } $this->chartKey = $this->newChartKey(); return parent::save(); } public function attachDatasets(array $datasets) { assert_instances_of($datasets, 'PhabricatorChartDataset'); $this->datasets = $datasets; return $this; } public function getDatasets() { return $this->assertAttached($this->datasets); } public function getURI() { return urisprintf('/fact/chart/%s/', $this->getChartKey()); } /* -( PhabricatorPolicyInterface )----------------------------------------- */ public function getCapabilities() { return array( PhabricatorPolicyCapability::CAN_VIEW, ); } public function getPolicy($capability) { return PhabricatorPolicies::getMostOpenPolicy(); } public function hasAutomaticCapability($capability, PhabricatorUser $viewer) { return false; } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/fact/storage/PhabricatorFactDimension.php
src/applications/fact/storage/PhabricatorFactDimension.php
<?php abstract class PhabricatorFactDimension extends PhabricatorFactDAO { abstract protected function getDimensionColumnName(); final public function newDimensionID($key, $create = false) { $map = $this->newDimensionMap(array($key), $create); return idx($map, $key); } final public function newDimensionUnmap(array $ids) { if (!$ids) { return array(); } $conn = $this->establishConnection('r'); $column = $this->getDimensionColumnName(); $rows = queryfx_all( $conn, 'SELECT id, %C FROM %T WHERE id IN (%Ld)', $column, $this->getTableName(), $ids); $rows = ipull($rows, $column, 'id'); return $rows; } final public function newDimensionMap(array $keys, $create = false) { if (!$keys) { return array(); } $conn = $this->establishConnection('r'); $column = $this->getDimensionColumnName(); $rows = queryfx_all( $conn, 'SELECT id, %C FROM %T WHERE %C IN (%Ls)', $column, $this->getTableName(), $column, $keys); $rows = ipull($rows, 'id', $column); $map = array(); $need = array(); foreach ($keys as $key) { if (isset($rows[$key])) { $map[$key] = (int)$rows[$key]; } else { $need[] = $key; } } if (!$need) { return $map; } if (!$create) { return $map; } $sql = array(); foreach ($need as $key) { $sql[] = qsprintf( $conn, '(%s)', $key); } $unguarded = AphrontWriteGuard::beginScopedUnguardedWrites(); foreach (PhabricatorLiskDAO::chunkSQL($sql) as $chunk) { queryfx( $conn, 'INSERT IGNORE INTO %T (%C) VALUES %LQ', $this->getTableName(), $column, $chunk); } unset($unguarded); $rows = queryfx_all( $conn, 'SELECT id, %C FROM %T WHERE %C IN (%Ls)', $column, $this->getTableName(), $column, $need); $rows = ipull($rows, 'id', $column); foreach ($need as $key) { if (isset($rows[$key])) { $map[$key] = (int)$rows[$key]; } else { throw new Exception( pht( 'Failed to load or generate dimension ID ("%s") for dimension '. 'key "%s".', get_class($this), $key)); } } return $map; } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/fact/storage/PhabricatorFactIntDatapoint.php
src/applications/fact/storage/PhabricatorFactIntDatapoint.php
<?php final class PhabricatorFactIntDatapoint extends PhabricatorFactDAO { protected $keyID; protected $objectID; protected $dimensionID; protected $value; protected $epoch; private $key; private $objectPHID; private $dimensionPHID; protected function getConfiguration() { return array( self::CONFIG_TIMESTAMPS => false, self::CONFIG_COLUMN_SCHEMA => array( 'id' => 'auto64', 'dimensionID' => 'id?', 'value' => 'sint64', ), self::CONFIG_KEY_SCHEMA => array( 'key_dimension' => array( 'columns' => array('keyID', 'dimensionID'), ), 'key_object' => array( 'columns' => array('objectID'), ), ), ) + parent::getConfiguration(); } public function setKey($key) { $this->key = $key; return $this; } public function getKey() { return $this->key; } public function setObjectPHID($object_phid) { $this->objectPHID = $object_phid; return $this; } public function getObjectPHID() { return $this->objectPHID; } public function setDimensionPHID($dimension_phid) { $this->dimensionPHID = $dimension_phid; return $this; } public function getDimensionPHID() { return $this->dimensionPHID; } public function newDatapointVector() { return $this->formatVector( array( $this->key, $this->objectPHID, $this->dimensionPHID, $this->value, $this->epoch, )); } public function newRawVector(array $spec) { return $this->formatVector( array( $spec['key'], $spec['objectPHID'], $spec['dimensionPHID'], $spec['value'], $spec['epoch'], )); } private function formatVector(array $vector) { return implode(':', $vector); } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/fact/storage/PhabricatorFactCursor.php
src/applications/fact/storage/PhabricatorFactCursor.php
<?php final class PhabricatorFactCursor extends PhabricatorFactDAO { protected $name; protected $position; protected function getConfiguration() { return array( self::CONFIG_COLUMN_SCHEMA => array( 'name' => 'text64', 'position' => 'text64', ), self::CONFIG_KEY_SCHEMA => array( 'name' => array( 'columns' => array('name'), 'unique' => true, ), ), ) + parent::getConfiguration(); } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/fact/storage/PhabricatorFactRaw.php
src/applications/fact/storage/PhabricatorFactRaw.php
<?php /** * Raw fact about an object. */ final class PhabricatorFactRaw extends PhabricatorFactDAO { protected $factType; protected $objectPHID; protected $objectA; protected $valueX; protected $valueY; protected $epoch; protected function getConfiguration() { return array( self::CONFIG_COLUMN_SCHEMA => array( 'id' => 'auto64', 'factType' => 'text32', 'objectA' => 'phid', 'valueX' => 'sint64', 'valueY' => 'sint64', ), self::CONFIG_KEY_SCHEMA => array( 'objectPHID' => array( 'columns' => array('objectPHID'), ), 'factType' => array( 'columns' => array('factType', 'epoch'), ), 'factType_2' => array( 'columns' => array('factType', 'objectA'), ), ), ) + parent::getConfiguration(); } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/fact/storage/PhabricatorFactKeyDimension.php
src/applications/fact/storage/PhabricatorFactKeyDimension.php
<?php final class PhabricatorFactKeyDimension extends PhabricatorFactDimension { protected $factKey; protected function getConfiguration() { return array( self::CONFIG_TIMESTAMPS => false, self::CONFIG_COLUMN_SCHEMA => array( 'factKey' => 'text64', ), self::CONFIG_KEY_SCHEMA => array( 'key_factkey' => array( 'columns' => array('factKey'), 'unique' => true, ), ), ) + parent::getConfiguration(); } protected function getDimensionColumnName() { return 'factKey'; } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/fact/storage/PhabricatorFactObjectDimension.php
src/applications/fact/storage/PhabricatorFactObjectDimension.php
<?php final class PhabricatorFactObjectDimension extends PhabricatorFactDimension { protected $objectPHID; protected function getConfiguration() { return array( self::CONFIG_TIMESTAMPS => false, self::CONFIG_COLUMN_SCHEMA => array(), self::CONFIG_KEY_SCHEMA => array( 'key_object' => array( 'columns' => array('objectPHID'), 'unique' => true, ), ), ) + parent::getConfiguration(); } protected function getDimensionColumnName() { return 'objectPHID'; } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/fact/storage/PhabricatorFactDAO.php
src/applications/fact/storage/PhabricatorFactDAO.php
<?php abstract class PhabricatorFactDAO extends PhabricatorLiskDAO { public function getApplicationName() { return 'fact'; } protected function getConfiguration() { return array( self::CONFIG_TIMESTAMPS => false, ) + parent::getConfiguration(); } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/fact/management/PhabricatorFactManagementAnalyzeWorkflow.php
src/applications/fact/management/PhabricatorFactManagementAnalyzeWorkflow.php
<?php final class PhabricatorFactManagementAnalyzeWorkflow extends PhabricatorFactManagementWorkflow { protected function didConstruct() { $this ->setName('analyze') ->setSynopsis(pht('Manually invoke fact analyzers.')) ->setArguments( array( array( 'name' => 'iterator', 'param' => 'name', 'repeat' => true, 'help' => pht('Process only iterator __name__.'), ), array( 'name' => 'all', 'help' => pht('Analyze from the beginning, ignoring cursors.'), ), array( 'name' => 'skip-aggregates', 'help' => pht('Skip analysis of aggregate facts.'), ), )); } public function execute(PhutilArgumentParser $args) { $console = PhutilConsole::getConsole(); $daemon = new PhabricatorFactDaemon(array()); $daemon->setVerbose(true); $daemon->setEngines(PhabricatorFactEngine::loadAllEngines()); $iterators = PhabricatorFactDaemon::getAllApplicationIterators(); $selected = $args->getArg('iterator'); if ($selected) { $use = array(); foreach ($selected as $iterator_name) { if (isset($iterators[$iterator_name])) { $use[$iterator_name] = $iterators[$iterator_name]; } else { $console->writeErr( "%s\n", pht("Iterator '%s' does not exist.", $iterator_name)); } } $iterators = $use; } foreach ($iterators as $iterator_name => $iterator) { if ($args->getArg('all')) { $daemon->processIterator($iterator); } else { $daemon->processIteratorWithCursor($iterator_name, $iterator); } } return 0; } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/fact/management/PhabricatorFactManagementCursorsWorkflow.php
src/applications/fact/management/PhabricatorFactManagementCursorsWorkflow.php
<?php final class PhabricatorFactManagementCursorsWorkflow extends PhabricatorFactManagementWorkflow { protected function didConstruct() { $this ->setName('cursors') ->setSynopsis(pht('Show a list of fact iterators and cursors.')) ->setExamples( "**cursors**\n". "**cursors** --reset __cursor__") ->setArguments( array( array( 'name' => 'reset', 'param' => 'cursor', 'repeat' => true, 'help' => pht('Reset cursor __cursor__.'), ), )); } public function execute(PhutilArgumentParser $args) { $console = PhutilConsole::getConsole(); $reset = $args->getArg('reset'); if ($reset) { foreach ($reset as $name) { $cursor = id(new PhabricatorFactCursor())->loadOneWhere( 'name = %s', $name); if ($cursor) { $console->writeOut("%s\n", pht('Resetting cursor %s...', $name)); $cursor->delete(); } else { $console->writeErr( "%s\n", pht('Cursor %s does not exist or is already reset.', $name)); } } return 0; } $iterator_map = PhabricatorFactDaemon::getAllApplicationIterators(); if (!$iterator_map) { $console->writeErr("%s\n", pht('No cursors.')); return 0; } $cursors = id(new PhabricatorFactCursor())->loadAllWhere( 'name IN (%Ls)', array_keys($iterator_map)); $cursors = mpull($cursors, 'getPosition', 'getName'); foreach ($iterator_map as $iterator_name => $iterator) { $console->writeOut( "%s (%s)\n", $iterator_name, idx($cursors, $iterator_name, 'start')); } return 0; } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/fact/management/PhabricatorFactManagementWorkflow.php
src/applications/fact/management/PhabricatorFactManagementWorkflow.php
<?php abstract class PhabricatorFactManagementWorkflow extends PhabricatorManagementWorkflow {}
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/fact/management/PhabricatorFactManagementListWorkflow.php
src/applications/fact/management/PhabricatorFactManagementListWorkflow.php
<?php final class PhabricatorFactManagementListWorkflow extends PhabricatorFactManagementWorkflow { protected function didConstruct() { $this ->setName('list') ->setSynopsis(pht('Show a list of fact engines.')) ->setArguments(array()); } public function execute(PhutilArgumentParser $args) { $console = PhutilConsole::getConsole(); $engines = PhabricatorFactEngine::loadAllEngines(); foreach ($engines as $engine) { $console->writeOut("%s\n", get_class($engine)); } return 0; } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/fact/management/PhabricatorFactManagementDestroyWorkflow.php
src/applications/fact/management/PhabricatorFactManagementDestroyWorkflow.php
<?php final class PhabricatorFactManagementDestroyWorkflow extends PhabricatorFactManagementWorkflow { protected function didConstruct() { $this ->setName('destroy') ->setSynopsis(pht('Destroy all facts.')) ->setArguments(array()); } public function execute(PhutilArgumentParser $args) { $console = PhutilConsole::getConsole(); $question = pht( 'Really destroy all facts? They will need to be rebuilt through '. 'analysis, which may take some time.'); $ok = $console->confirm($question, $default = false); if (!$ok) { return 1; } $tables = array(); $tables[] = new PhabricatorFactCursor(); $tables[] = new PhabricatorFactIntDatapoint(); $tables[] = new PhabricatorFactObjectDimension(); $tables[] = new PhabricatorFactKeyDimension(); foreach ($tables as $table) { $conn = $table->establishConnection('w'); $name = $table->getTableName(); $console->writeOut("%s\n", pht("Destroying table '%s'...", $name)); queryfx( $conn, 'TRUNCATE TABLE %T', $name); } $console->writeOut("%s\n", pht('Done.')); } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/fact/extract/PhabricatorFactUpdateIterator.php
src/applications/fact/extract/PhabricatorFactUpdateIterator.php
<?php /** * Iterate over objects by update time in a stable way. This iterator only works * for "normal" Lisk objects: objects with an auto-increment ID and a * dateModified column. */ final class PhabricatorFactUpdateIterator extends PhutilBufferedIterator { private $cursor; private $object; private $position; private $ignoreUpdatesDuration = 15; public function __construct(LiskDAO $object) { $this->object = $object; } public function setPosition($position) { $this->position = $position; return $this; } protected function didRewind() { $this->cursor = $this->position; } protected function getCursorFromObject($object) { if ($object->hasProperty('dateModified')) { return $object->getDateModified().':'.$object->getID(); } else { return $object->getID(); } } public function key() { return $this->getCursorFromObject($this->current()); } protected function loadPage() { if ($this->object->hasProperty('dateModified')) { if ($this->cursor) { list($after_epoch, $after_id) = explode(':', $this->cursor); } else { $after_epoch = 0; $after_id = 0; } // NOTE: We ignore recent updates because once we process an update we'll // never process rows behind it again. We need to read only rows which // we're sure no new rows will be inserted behind. If we read a row that // was updated on the current second, another update later on in this // second could affect an object with a lower ID, and we'd skip that // update. To avoid this, just ignore any rows which have been updated in // the last few seconds. This also reduces the amount of work we need to // do if an object is repeatedly updated; we will just look at the end // state without processing the intermediate states. Finally, this gives // us reasonable protections against clock skew between the machine the // daemon is running on and any machines performing writes. $page = $this->object->loadAllWhere( '((dateModified > %d) OR (dateModified = %d AND id > %d)) AND (dateModified < %d - %d) ORDER BY dateModified ASC, id ASC LIMIT %d', $after_epoch, $after_epoch, $after_id, time(), $this->ignoreUpdatesDuration, $this->getPageSize()); } else { if ($this->cursor) { $after_id = $this->cursor; } else { $after_id = 0; } $page = $this->object->loadAllWhere( 'id > %d ORDER BY id ASC LIMIT %d', $after_id, $this->getPageSize()); } if ($page) { $this->cursor = $this->getCursorFromObject(end($page)); } return $page; } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/fact/query/PhabricatorFactDatapointQuery.php
src/applications/fact/query/PhabricatorFactDatapointQuery.php
<?php final class PhabricatorFactDatapointQuery extends Phobject { private $facts; private $objectPHIDs; private $limit; private $needVectors; private $keyMap = array(); private $dimensionMap = array(); public function withFacts(array $facts) { $this->facts = $facts; return $this; } public function withObjectPHIDs(array $object_phids) { $this->objectPHIDs = $object_phids; return $this; } public function setLimit($limit) { $this->limit = $limit; return $this; } public function needVectors($need) { $this->needVectors = $need; return $this; } public function execute() { $facts = mpull($this->facts, null, 'getKey'); if (!$facts) { throw new Exception(pht('Executing a fact query requires facts.')); } $table_map = array(); foreach ($facts as $fact) { $datapoint = $fact->newDatapoint(); $table = $datapoint->getTableName(); if (!isset($table_map[$table])) { $table_map[$table] = array( 'table' => $datapoint, 'facts' => array(), ); } $table_map[$table]['facts'][] = $fact; } $rows = array(); foreach ($table_map as $spec) { $rows[] = $this->executeWithTable($spec); } $rows = array_mergev($rows); $key_unmap = array_flip($this->keyMap); $dimension_unmap = array_flip($this->dimensionMap); $groups = array(); $need_phids = array(); foreach ($rows as $row) { $groups[$row['keyID']][] = $row; $object_id = $row['objectID']; if (!isset($dimension_unmap[$object_id])) { $need_phids[$object_id] = $object_id; } $dimension_id = $row['dimensionID']; if ($dimension_id && !isset($dimension_unmap[$dimension_id])) { $need_phids[$dimension_id] = $dimension_id; } } $dimension_unmap += id(new PhabricatorFactObjectDimension()) ->newDimensionUnmap($need_phids); $results = array(); foreach ($groups as $key_id => $rows) { $key = $key_unmap[$key_id]; $fact = $facts[$key]; $datapoint = $fact->newDatapoint(); foreach ($rows as $row) { $dimension_id = $row['dimensionID']; if ($dimension_id) { if (!isset($dimension_unmap[$dimension_id])) { continue; } else { $dimension_phid = $dimension_unmap[$dimension_id]; } } else { $dimension_phid = null; } $object_id = $row['objectID']; if (!isset($dimension_unmap[$object_id])) { continue; } else { $object_phid = $dimension_unmap[$object_id]; } $result = array( 'key' => $key, 'objectPHID' => $object_phid, 'dimensionPHID' => $dimension_phid, 'value' => (int)$row['value'], 'epoch' => $row['epoch'], ); if ($this->needVectors) { $result['vector'] = $datapoint->newRawVector($result); } $results[] = $result; } } return $results; } private function executeWithTable(array $spec) { $table = $spec['table']; $facts = $spec['facts']; $conn = $table->establishConnection('r'); $fact_keys = mpull($facts, 'getKey'); $this->keyMap = id(new PhabricatorFactKeyDimension()) ->newDimensionMap($fact_keys); if (!$this->keyMap) { return array(); } $where = array(); $where[] = qsprintf( $conn, 'keyID IN (%Ld)', $this->keyMap); if ($this->objectPHIDs) { $object_map = id(new PhabricatorFactObjectDimension()) ->newDimensionMap($this->objectPHIDs); if (!$object_map) { return array(); } $this->dimensionMap = $object_map; $where[] = qsprintf( $conn, 'objectID IN (%Ld)', $this->dimensionMap); } $where = qsprintf($conn, '%LA', $where); if ($this->limit) { $limit = qsprintf( $conn, 'LIMIT %d', $this->limit); } else { $limit = qsprintf($conn, ''); } return queryfx_all( $conn, 'SELECT keyID, objectID, dimensionID, value, epoch FROM %T WHERE %Q %Q', $table->getTableName(), $where, $limit); } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/fact/application/PhabricatorFactApplication.php
src/applications/fact/application/PhabricatorFactApplication.php
<?php final class PhabricatorFactApplication extends PhabricatorApplication { public function getShortDescription() { return pht('Chart and Analyze Data'); } public function getName() { return pht('Facts'); } public function getBaseURI() { return '/fact/'; } public function getIcon() { return 'fa-line-chart'; } public function getApplicationGroup() { return self::GROUP_UTILITIES; } public function getRoutes() { return array( '/fact/' => array( '' => 'PhabricatorFactHomeController', 'chart/(?P<chartKey>[^/]+)/(?:(?P<mode>draw)/)?' => 'PhabricatorFactChartController', 'object/(?<phid>[^/]+)/' => 'PhabricatorFactObjectController', ), ); } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/fact/fact/PhabricatorPointsFact.php
src/applications/fact/fact/PhabricatorPointsFact.php
<?php final class PhabricatorPointsFact extends PhabricatorFact { protected function newTemplateDatapoint() { return new PhabricatorFactIntDatapoint(); } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/fact/fact/PhabricatorFact.php
src/applications/fact/fact/PhabricatorFact.php
<?php abstract class PhabricatorFact extends Phobject { private $key; public static function getAllFacts() { $engines = PhabricatorFactEngine::loadAllEngines(); $map = array(); foreach ($engines as $engine) { $facts = $engine->newFacts(); $facts = mpull($facts, null, 'getKey'); $map += $facts; } return $map; } final public function setKey($key) { $this->key = $key; return $this; } final public function getKey() { return $this->key; } final public function getName() { return pht('Fact "%s"', $this->getKey()); } final public function newDatapoint() { return $this->newTemplateDatapoint() ->setKey($this->getKey()); } abstract protected function newTemplateDatapoint(); final public function getFunctionArguments() { $key = $this->getKey(); $argv = array(); if (preg_match('/\.project\z/', $key)) { $argv[] = id(new PhabricatorChartFunctionArgument()) ->setName('phid') ->setType('phid'); } if (preg_match('/\.owner\z/', $key)) { $argv[] = id(new PhabricatorChartFunctionArgument()) ->setName('phid') ->setType('phid'); } return $argv; } final public function buildWhereClauseParts( AphrontDatabaseConnection $conn, PhabricatorChartFunctionArgumentParser $arguments) { $where = array(); $has_phid = $this->getFunctionArguments(); if ($has_phid) { $phid = $arguments->getArgumentValue('phid'); $dimension_id = id(new PhabricatorFactObjectDimension()) ->newDimensionID($phid); $where[] = qsprintf( $conn, 'dimensionID = %d', $dimension_id); } return $where; } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/fact/fact/PhabricatorCountFact.php
src/applications/fact/fact/PhabricatorCountFact.php
<?php final class PhabricatorCountFact extends PhabricatorFact { protected function newTemplateDatapoint() { return new PhabricatorFactIntDatapoint(); } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/fact/chart/PhabricatorFactChartFunction.php
src/applications/fact/chart/PhabricatorFactChartFunction.php
<?php final class PhabricatorFactChartFunction extends PhabricatorChartFunction { const FUNCTIONKEY = 'fact'; private $fact; private $map; private $refs; protected function newArguments() { $key_argument = $this->newArgument() ->setName('fact-key') ->setType('fact-key'); $parser = $this->getArgumentParser(); $parser->parseArgument($key_argument); $fact = $this->getArgument('fact-key'); $this->fact = $fact; return $fact->getFunctionArguments(); } public function loadData() { $fact = $this->fact; $key_id = id(new PhabricatorFactKeyDimension()) ->newDimensionID($fact->getKey()); if (!$key_id) { $this->map = array(); return; } $table = $fact->newDatapoint(); $conn = $table->establishConnection('r'); $table_name = $table->getTableName(); $where = array(); $where[] = qsprintf( $conn, 'keyID = %d', $key_id); $parser = $this->getArgumentParser(); $parts = $fact->buildWhereClauseParts($conn, $parser); foreach ($parts as $part) { $where[] = $part; } $data = queryfx_all( $conn, 'SELECT id, value, epoch FROM %T WHERE %LA ORDER BY epoch ASC', $table_name, $where); $map = array(); $refs = array(); if ($data) { foreach ($data as $row) { $ref = (string)$row['id']; $value = (int)$row['value']; $epoch = (int)$row['epoch']; if (!isset($map[$epoch])) { $map[$epoch] = 0; } $map[$epoch] += $value; if (!isset($refs[$epoch])) { $refs[$epoch] = array(); } $refs[$epoch][] = $ref; } } $this->map = $map; $this->refs = $refs; } public function getDomain() { $min = head_key($this->map); $max = last_key($this->map); return new PhabricatorChartInterval($min, $max); } public function newInputValues(PhabricatorChartDataQuery $query) { return array_keys($this->map); } public function evaluateFunction(array $xv) { $map = $this->map; $yv = array(); foreach ($xv as $x) { if (isset($map[$x])) { $yv[] = $map[$x]; } else { $yv[] = null; } } return $yv; } public function getDataRefs(array $xv) { return array_select_keys($this->refs, $xv); } public function loadRefs(array $refs) { $fact = $this->fact; $datapoint_table = $fact->newDatapoint(); $conn = $datapoint_table->establishConnection('r'); $dimension_table = new PhabricatorFactObjectDimension(); $where = array(); $where[] = qsprintf( $conn, 'p.id IN (%Ld)', $refs); $rows = queryfx_all( $conn, 'SELECT p.id id, p.value, od.objectPHID objectPHID, dd.objectPHID dimensionPHID FROM %R p LEFT JOIN %R od ON od.id = p.objectID LEFT JOIN %R dd ON dd.id = p.dimensionID WHERE %LA', $datapoint_table, $dimension_table, $dimension_table, $where); $rows = ipull($rows, null, 'id'); $results = array(); foreach ($refs as $ref) { if (!isset($rows[$ref])) { continue; } $row = $rows[$ref]; $results[$ref] = array( 'objectPHID' => $row['objectPHID'], 'dimensionPHID' => $row['dimensionPHID'], 'value' => (float)$row['value'], ); } return $results; } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/fact/chart/PhabricatorSinChartFunction.php
src/applications/fact/chart/PhabricatorSinChartFunction.php
<?php final class PhabricatorSinChartFunction extends PhabricatorPureChartFunction { const FUNCTIONKEY = 'sin'; protected function newArguments() { return array(); } public function evaluateFunction(array $xv) { $yv = array(); foreach ($xv as $x) { $yv[] = sin(deg2rad($x)); } return $yv; } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/fact/chart/PhabricatorChartDataset.php
src/applications/fact/chart/PhabricatorChartDataset.php
<?php abstract class PhabricatorChartDataset extends Phobject { private $functions; final public function getDatasetTypeKey() { return $this->getPhobjectClassConstant('DATASETKEY', 32); } final public function getFunctions() { return $this->functions; } final public function setFunctions(array $functions) { assert_instances_of($functions, 'PhabricatorComposeChartFunction'); $this->functions = $functions; return $this; } final public static function getAllDatasetTypes() { return id(new PhutilClassMapQuery()) ->setAncestorClass(__CLASS__) ->setUniqueMethod('getDatasetTypeKey') ->execute(); } final public static function newFromDictionary(array $map) { PhutilTypeSpec::checkMap( $map, array( 'type' => 'string', 'functions' => 'list<wild>', )); $types = self::getAllDatasetTypes(); $dataset_type = $map['type']; if (!isset($types[$dataset_type])) { throw new Exception( pht( 'Trying to construct a dataset of type "%s", but this type is '. 'unknown. Supported types are: %s.', $dataset_type, implode(', ', array_keys($types)))); } $dataset = id(clone $types[$dataset_type]); $functions = array(); foreach ($map['functions'] as $map) { $functions[] = PhabricatorChartFunction::newFromDictionary($map); } $dataset->setFunctions($functions); return $dataset; } final public function getChartDisplayData( PhabricatorChartDataQuery $data_query) { return $this->newChartDisplayData($data_query); } abstract protected function newChartDisplayData( PhabricatorChartDataQuery $data_query); final public function getTabularDisplayData( PhabricatorChartDataQuery $data_query) { $results = array(); $functions = $this->getFunctions(); foreach ($functions as $function) { $datapoints = $function->newDatapoints($data_query); $refs = $function->getDataRefs(ipull($datapoints, 'x')); foreach ($datapoints as $key => $point) { $x = $point['x']; if (isset($refs[$x])) { $xrefs = $refs[$x]; } else { $xrefs = array(); } $datapoints[$key]['refs'] = $xrefs; } $results[] = array( 'data' => $datapoints, ); } return id(new PhabricatorChartDisplayData()) ->setWireData($results); } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/fact/chart/PhabricatorComposeChartFunction.php
src/applications/fact/chart/PhabricatorComposeChartFunction.php
<?php final class PhabricatorComposeChartFunction extends PhabricatorHigherOrderChartFunction { const FUNCTIONKEY = 'compose'; protected function newArguments() { return array( $this->newArgument() ->setName('f') ->setType('function') ->setRepeatable(true), ); } public function evaluateFunction(array $xv) { $original_positions = array_keys($xv); $remaining_positions = $original_positions; foreach ($this->getFunctionArguments() as $function) { $xv = $function->evaluateFunction($xv); // If a function evaluates to "null" at some positions, we want to return // "null" at those positions and stop evaluating the function. // We also want to pass "evaluateFunction()" a natural list containing // only values it should evaluate: keys should not be important and we // should not pass "null". This simplifies implementation of functions. // To do this, first create a map from original input positions to // function return values. $xv = array_combine($remaining_positions, $xv); // If a function evaluated to "null" at any position where we evaluated // it, the result will be "null". We remove the position from the // vector so we stop evaluating it. foreach ($xv as $x => $y) { if ($y !== null) { continue; } unset($xv[$x]); } // Store the remaining original input positions for the next round, then // throw away the array keys so we're passing the next function a natural // list with only non-"null" values. $remaining_positions = array_keys($xv); $xv = array_values($xv); // If we have no more inputs to evaluate, we can bail out early rather // than passing empty vectors to functions for evaluation. if (!$xv) { break; } } $yv = array(); $xv = array_combine($remaining_positions, $xv); foreach ($original_positions as $position) { if (isset($xv[$position])) { $y = $xv[$position]; } else { $y = null; } $yv[$position] = $y; } return $yv; } public function getDataRefs(array $xv) { // TODO: This is not entirely correct. The correct implementation would // map "x -> y" at each stage of composition and pull and aggregate all // the datapoint refs. In practice, we currently never compose functions // with a data function somewhere in the middle, so just grabbing the first // result is close enough. // In the future, we may: notably, "x -> shift(-1 month) -> ..." to // generate a month-over-month overlay is a sensible operation which will // source data from the middle of a function composition. foreach ($this->getFunctionArguments() as $function) { return $function->getDataRefs($xv); } return array(); } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/fact/chart/PhabricatorSumChartFunction.php
src/applications/fact/chart/PhabricatorSumChartFunction.php
<?php final class PhabricatorSumChartFunction extends PhabricatorHigherOrderChartFunction { const FUNCTIONKEY = 'sum'; protected function newArguments() { return array( $this->newArgument() ->setName('f') ->setType('function') ->setRepeatable(true), ); } public function evaluateFunction(array $xv) { $fv = array(); foreach ($this->getFunctionArguments() as $function) { $fv[] = $function->evaluateFunction($xv); } $n = count($xv); $yv = array_fill(0, $n, null); foreach ($fv as $f) { for ($ii = 0; $ii < $n; $ii++) { if ($f[$ii] !== null) { if (!isset($yv[$ii])) { $yv[$ii] = 0; } $yv[$ii] += $f[$ii]; } } } return $yv; } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/fact/chart/PhabricatorChartAxis.php
src/applications/fact/chart/PhabricatorChartAxis.php
<?php final class PhabricatorChartAxis extends Phobject { private $minimumValue; private $maximumValue; public function setMinimumValue($minimum_value) { $this->minimumValue = $minimum_value; return $this; } public function getMinimumValue() { return $this->minimumValue; } public function setMaximumValue($maximum_value) { $this->maximumValue = $maximum_value; return $this; } public function getMaximumValue() { return $this->maximumValue; } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/fact/chart/PhabricatorChartFunctionArgument.php
src/applications/fact/chart/PhabricatorChartFunctionArgument.php
<?php final class PhabricatorChartFunctionArgument extends Phobject { private $name; private $type; private $repeatable; public function setName($name) { $this->name = $name; return $this; } public function getName() { return $this->name; } public function setRepeatable($repeatable) { $this->repeatable = $repeatable; return $this; } public function getRepeatable() { return $this->repeatable; } public function setType($type) { $types = array( 'fact-key' => true, 'function' => true, 'number' => true, 'phid' => true, ); if (!isset($types[$type])) { throw new Exception( pht( 'Chart function argument type "%s" is unknown. Valid types '. 'are: %s.', $type, implode(', ', array_keys($types)))); } $this->type = $type; return $this; } public function getType() { return $this->type; } public function newValue($value) { switch ($this->getType()) { case 'phid': // TODO: This could be validated better, but probably should not be // a primitive type. return $value; case 'fact-key': if (!is_string($value)) { throw new Exception( pht( 'Value for "fact-key" argument must be a string, got %s.', phutil_describe_type($value))); } $facts = PhabricatorFact::getAllFacts(); $fact = idx($facts, $value); if (!$fact) { throw new Exception( pht( 'Fact key "%s" is not a known fact key.', $value)); } return $fact; case 'function': // If this is already a function object, just return it. if ($value instanceof PhabricatorChartFunction) { return $value; } if (!is_array($value)) { throw new Exception( pht( 'Value for "function" argument must be a function definition, '. 'formatted as a list, like: [fn, arg1, arg, ...]. Actual value '. 'is %s.', phutil_describe_type($value))); } if (!phutil_is_natural_list($value)) { throw new Exception( pht( 'Value for "function" argument must be a natural list, not '. 'a dictionary. Actual value is "%s".', phutil_describe_type($value))); } if (!$value) { throw new Exception( pht( 'Value for "function" argument must be a list with a function '. 'name; got an empty list.')); } $function_name = array_shift($value); if (!is_string($function_name)) { throw new Exception( pht( 'Value for "function" argument must be a natural list '. 'beginning with a function name as a string. The first list '. 'item has the wrong type, %s.', phutil_describe_type($function_name))); } $functions = PhabricatorChartFunction::getAllFunctions(); if (!isset($functions[$function_name])) { throw new Exception( pht( 'Function "%s" is unknown. Valid functions are: %s', $function_name, implode(', ', array_keys($functions)))); } return id(clone $functions[$function_name]) ->setArguments($value); case 'number': if (!is_float($value) && !is_int($value)) { throw new Exception( pht( 'Value for "number" argument must be an integer or double, '. 'got %s.', phutil_describe_type($value))); } return $value; } throw new PhutilMethodNotImplementedException(); } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/fact/chart/PhabricatorChartFunctionLabel.php
src/applications/fact/chart/PhabricatorChartFunctionLabel.php
<?php final class PhabricatorChartFunctionLabel extends Phobject { private $key; private $name; private $color; private $icon; private $fillColor; public function setKey($key) { $this->key = $key; return $this; } public function getKey() { return $this->key; } public function setName($name) { $this->name = $name; return $this; } public function getName() { return $this->name; } public function setColor($color) { $this->color = $color; return $this; } public function getColor() { return $this->color; } public function setIcon($icon) { $this->icon = $icon; return $this; } public function getIcon() { return $this->icon; } public function setFillColor($fill_color) { $this->fillColor = $fill_color; return $this; } public function getFillColor() { return $this->fillColor; } public function toWireFormat() { return array( 'key' => $this->getKey(), 'name' => $this->getName(), 'color' => $this->getColor(), 'icon' => $this->getIcon(), 'fillColor' => $this->getFillColor(), ); } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/fact/chart/PhabricatorMaxChartFunction.php
src/applications/fact/chart/PhabricatorMaxChartFunction.php
<?php final class PhabricatorMaxChartFunction extends PhabricatorPureChartFunction { const FUNCTIONKEY = 'max'; protected function newArguments() { return array( $this->newArgument() ->setName('max') ->setType('number'), ); } public function evaluateFunction(array $xv) { $max = $this->getArgument('max'); $yv = array(); foreach ($xv as $x) { if ($x > $max) { $yv[] = null; } else { $yv[] = $x; } } return $yv; } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/fact/chart/PhabricatorChartStackedAreaDataset.php
src/applications/fact/chart/PhabricatorChartStackedAreaDataset.php
<?php final class PhabricatorChartStackedAreaDataset extends PhabricatorChartDataset { const DATASETKEY = 'stacked-area'; private $stacks; public function setStacks(array $stacks) { $this->stacks = $stacks; return $this; } public function getStacks() { return $this->stacks; } protected function newChartDisplayData( PhabricatorChartDataQuery $data_query) { $functions = $this->getFunctions(); $functions = mpull($functions, null, 'getKey'); $stacks = $this->getStacks(); if (!$stacks) { $stacks = array( array_reverse(array_keys($functions), true), ); } $series = array(); $raw_points = array(); foreach ($stacks as $stack) { $stack_functions = array_select_keys($functions, $stack); $function_points = $this->getFunctionDatapoints( $data_query, $stack_functions); $stack_points = $function_points; $function_points = $this->getGeometry( $data_query, $function_points); $baseline = array(); foreach ($function_points as $function_idx => $points) { $bounds = array(); foreach ($points as $x => $point) { if (!isset($baseline[$x])) { $baseline[$x] = 0; } $y0 = $baseline[$x]; $baseline[$x] += $point['y']; $y1 = $baseline[$x]; $bounds[] = array( 'x' => $x, 'y0' => $y0, 'y1' => $y1, ); if (isset($stack_points[$function_idx][$x])) { $stack_points[$function_idx][$x]['y1'] = $y1; } } $series[$function_idx] = $bounds; } $raw_points += $stack_points; } $series = array_select_keys($series, array_keys($functions)); $series = array_values($series); $raw_points = array_select_keys($raw_points, array_keys($functions)); $raw_points = array_values($raw_points); $range_min = null; $range_max = null; foreach ($series as $geometry_list) { foreach ($geometry_list as $geometry_item) { $y0 = $geometry_item['y0']; $y1 = $geometry_item['y1']; if ($range_min === null) { $range_min = $y0; } $range_min = min($range_min, $y0, $y1); if ($range_max === null) { $range_max = $y1; } $range_max = max($range_max, $y0, $y1); } } // We're going to group multiple events into a single point if they have // X values that are very close to one another. // // If the Y values are also close to one another (these points are near // one another in a horizontal line), it can be hard to select any // individual point with the mouse. // // Even if the Y values are not close together (the points are on a // fairly steep slope up or down), it's usually better to be able to // mouse over a single point at the top or bottom of the slope and get // a summary of what's going on. $domain_max = $data_query->getMaximumValue(); $domain_min = $data_query->getMinimumValue(); $resolution = ($domain_max - $domain_min) / 100; $events = array(); foreach ($raw_points as $function_idx => $points) { $event_list = array(); $event_group = array(); $head_event = null; foreach ($points as $point) { $x = $point['x']; if ($head_event === null) { // We don't have any points yet, so start a new group. $head_event = $x; $event_group[] = $point; } else if (($x - $head_event) <= $resolution) { // This point is close to the first point in this group, so // add it to the existing group. $event_group[] = $point; } else { // This point is not close to the first point in the group, // so create a new group. $event_list[] = $event_group; $head_event = $x; $event_group = array($point); } } if ($event_group) { $event_list[] = $event_group; } $event_spec = array(); foreach ($event_list as $key => $event_points) { // NOTE: We're using the last point as the representative point so // that you can learn about a section of a chart by hovering over // the point to right of the section, which is more intuitive than // other points. $event = last($event_points); $event = $event + array( 'n' => count($event_points), ); $event_list[$key] = $event; } $events[] = $event_list; } $wire_labels = array(); foreach ($functions as $function_key => $function) { $label = $function->getFunctionLabel(); $wire_labels[] = $label->toWireFormat(); } $result = array( 'type' => $this->getDatasetTypeKey(), 'data' => $series, 'events' => $events, 'labels' => $wire_labels, ); return id(new PhabricatorChartDisplayData()) ->setWireData($result) ->setRange(new PhabricatorChartInterval($range_min, $range_max)); } private function getAllXValuesAsMap( PhabricatorChartDataQuery $data_query, array $point_lists) { // We need to define every function we're drawing at every point where // any of the functions we're drawing are defined. If we don't, we'll // end up with weird gaps or overlaps between adjacent areas, and won't // know how much we need to lift each point above the baseline when // stacking the functions on top of one another. $must_define = array(); $min = $data_query->getMinimumValue(); $max = $data_query->getMaximumValue(); $must_define[$max] = $max; $must_define[$min] = $min; foreach ($point_lists as $point_list) { foreach ($point_list as $x => $point) { $must_define[$x] = $x; } } ksort($must_define); return $must_define; } private function getFunctionDatapoints( PhabricatorChartDataQuery $data_query, array $functions) { assert_instances_of($functions, 'PhabricatorChartFunction'); $points = array(); foreach ($functions as $idx => $function) { $points[$idx] = array(); $datapoints = $function->newDatapoints($data_query); foreach ($datapoints as $point) { $x_value = $point['x']; $points[$idx][$x_value] = $point; } } return $points; } private function getGeometry( PhabricatorChartDataQuery $data_query, array $point_lists) { $must_define = $this->getAllXValuesAsMap($data_query, $point_lists); foreach ($point_lists as $idx => $points) { $missing = array(); foreach ($must_define as $x) { if (!isset($points[$x])) { $missing[$x] = true; } } if (!$missing) { continue; } $values = array_keys($points); $cursor = -1; $length = count($values); foreach ($missing as $x => $ignored) { // Move the cursor forward until we find the last point before "x" // which is defined. while ($cursor + 1 < $length && $values[$cursor + 1] < $x) { $cursor++; } // If this new point is to the left of all defined points, we'll // assume the value is 0. If the point is to the right of all defined // points, we assume the value is the same as the last known value. // If it's between two defined points, we average them. if ($cursor < 0) { $y = 0; } else if ($cursor + 1 < $length) { $xmin = $values[$cursor]; $xmax = $values[$cursor + 1]; $ymin = $points[$xmin]['y']; $ymax = $points[$xmax]['y']; // Fill in the missing point by creating a linear interpolation // between the two adjacent points. $distance = ($x - $xmin) / ($xmax - $xmin); $y = $ymin + (($ymax - $ymin) * $distance); } else { $xmin = $values[$cursor]; $y = $points[$xmin]['y']; } $point_lists[$idx][$x] = array( 'x' => $x, 'y' => $y, ); } ksort($point_lists[$idx]); } return $point_lists; } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/fact/chart/PhabricatorPureChartFunction.php
src/applications/fact/chart/PhabricatorPureChartFunction.php
<?php abstract class PhabricatorPureChartFunction extends PhabricatorChartFunction { public function getDataRefs(array $xv) { return array(); } public function loadRefs(array $refs) { return array(); } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/fact/chart/PhabricatorMinChartFunction.php
src/applications/fact/chart/PhabricatorMinChartFunction.php
<?php final class PhabricatorMinChartFunction extends PhabricatorPureChartFunction { const FUNCTIONKEY = 'min'; protected function newArguments() { return array( $this->newArgument() ->setName('min') ->setType('number'), ); } public function evaluateFunction(array $xv) { $min = $this->getArgument('min'); $yv = array(); foreach ($xv as $x) { if ($x < $min) { $yv[] = null; } else { $yv[] = $x; } } return $yv; } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/fact/chart/PhabricatorScaleChartFunction.php
src/applications/fact/chart/PhabricatorScaleChartFunction.php
<?php final class PhabricatorScaleChartFunction extends PhabricatorPureChartFunction { const FUNCTIONKEY = 'scale'; protected function newArguments() { return array( $this->newArgument() ->setName('scale') ->setType('number'), ); } public function evaluateFunction(array $xv) { $scale = $this->getArgument('scale'); $yv = array(); foreach ($xv as $x) { $yv[] = $x * $scale; } return $yv; } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/fact/chart/PhabricatorChartInterval.php
src/applications/fact/chart/PhabricatorChartInterval.php
<?php final class PhabricatorChartInterval extends Phobject { private $min; private $max; public function __construct($min, $max) { $this->min = $min; $this->max = $max; } public static function newFromIntervalList(array $intervals) { $min = null; $max = null; foreach ($intervals as $interval) { if ($interval === null) { continue; } $interval_min = $interval->getMin(); if ($interval_min !== null) { if ($min === null) { $min = $interval_min; } else { $min = min($min, $interval_min); } } $interval_max = $interval->getMax(); if ($interval_max !== null) { if ($max === null) { $max = $interval_max; } else { $max = max($max, $interval_max); } } } return new self($min, $max); } public function setMin($min) { $this->min = $min; return $this; } public function getMin() { return $this->min; } public function setMax($max) { $this->max = $max; return $this; } public function getMax() { return $this->max; } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/fact/chart/PhabricatorChartDataQuery.php
src/applications/fact/chart/PhabricatorChartDataQuery.php
<?php final class PhabricatorChartDataQuery extends Phobject { private $limit; private $minimumValue; private $maximumValue; public function setMinimumValue($minimum_value) { $this->minimumValue = $minimum_value; return $this; } public function getMinimumValue() { return $this->minimumValue; } public function setMaximumValue($maximum_value) { $this->maximumValue = $maximum_value; return $this; } public function getMaximumValue() { return $this->maximumValue; } public function setLimit($limit) { $this->limit = $limit; return $this; } public function getLimit() { return $this->limit; } public function selectInputValues(array $xv) { $result = array(); $x_min = $this->getMinimumValue(); $x_max = $this->getMaximumValue(); $limit = $this->getLimit(); if ($x_min !== null) { foreach ($xv as $key => $x) { if ($x < $x_min) { unset($xv[$key]); } } } if ($x_max !== null) { foreach ($xv as $key => $x) { if ($x > $x_max) { unset($xv[$key]); } } } // If we have too many data points, throw away some of the data. // TODO: This doesn't work especially well right now. if ($limit !== null) { $count = count($xv); if ($count > $limit) { $ii = 0; $every = ceil($count / $limit); foreach ($xv as $key => $x) { $ii++; if (($ii % $every) && ($ii != $count)) { unset($xv[$key]); } } } } return array_values($xv); } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false
phacility/phabricator
https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/fact/chart/PhabricatorChartFunctionArgumentParser.php
src/applications/fact/chart/PhabricatorChartFunctionArgumentParser.php
<?php final class PhabricatorChartFunctionArgumentParser extends Phobject { private $function; private $rawArguments; private $unconsumedArguments; private $haveAllArguments = false; private $unparsedArguments; private $argumentMap = array(); private $argumentPosition = 0; private $argumentValues = array(); private $repeatableArgument = null; public function setFunction(PhabricatorChartFunction $function) { $this->function = $function; return $this; } public function getFunction() { return $this->function; } public function setRawArguments(array $arguments) { $this->rawArguments = $arguments; $this->unconsumedArguments = $arguments; } public function addArgument(PhabricatorChartFunctionArgument $spec) { $name = $spec->getName(); if (!strlen($name)) { throw new Exception( pht( 'Chart function "%s" emitted an argument specification with no '. 'argument name. Argument specifications must have unique names.', $this->getFunctionArgumentSignature())); } $type = $spec->getType(); if (!strlen($type)) { throw new Exception( pht( 'Chart function "%s" emitted an argument specification ("%s") with '. 'no type. Each argument specification must have a valid type.', $this->getFunctionArgumentSignature(), $name)); } if (isset($this->argumentMap[$name])) { throw new Exception( pht( 'Chart function "%s" emitted multiple argument specifications '. 'with the same name ("%s"). Each argument specification must have '. 'a unique name.', $this->getFunctionArgumentSignature(), $name)); } if ($this->repeatableArgument) { if ($spec->getRepeatable()) { throw new Exception( pht( 'Chart function "%s" emitted multiple repeatable argument '. 'specifications ("%s" and "%s"). Only one argument may be '. 'repeatable and it must be the last argument.', $this->getFunctionArgumentSignature(), $name, $this->repeatableArgument->getName())); } else { throw new Exception( pht( 'Chart function "%s" emitted a repeatable argument ("%s"), then '. 'another argument ("%s"). No arguments are permitted after a '. 'repeatable argument.', $this->getFunctionArgumentSignature(), $this->repeatableArgument->getName(), $name)); } } if ($spec->getRepeatable()) { $this->repeatableArgument = $spec; } $this->argumentMap[$name] = $spec; $this->unparsedArguments[] = $spec; return $this; } public function parseArgument( PhabricatorChartFunctionArgument $spec) { $this->addArgument($spec); return $this->parseArguments(); } public function setHaveAllArguments($have_all) { $this->haveAllArguments = $have_all; return $this; } public function getAllArguments() { return array_values($this->argumentMap); } public function getRawArguments() { return $this->rawArguments; } public function parseArguments() { $have_count = count($this->rawArguments); $want_count = count($this->argumentMap); if ($this->haveAllArguments) { if ($this->repeatableArgument) { if ($want_count > $have_count) { throw new Exception( pht( 'Function "%s" expects %s or more argument(s), but only %s '. 'argument(s) were provided.', $this->getFunctionArgumentSignature(), $want_count, $have_count)); } } else if ($want_count !== $have_count) { throw new Exception( pht( 'Function "%s" expects %s argument(s), but %s argument(s) were '. 'provided.', $this->getFunctionArgumentSignature(), $want_count, $have_count)); } } while ($this->unparsedArguments) { $argument = array_shift($this->unparsedArguments); $name = $argument->getName(); if (!$this->unconsumedArguments) { throw new Exception( pht( 'Function "%s" expects at least %s argument(s), but only %s '. 'argument(s) were provided.', $this->getFunctionArgumentSignature(), $want_count, $have_count)); } $raw_argument = array_shift($this->unconsumedArguments); $this->argumentPosition++; $is_repeatable = $argument->getRepeatable(); // If this argument is repeatable and we have more arguments, add it // back to the end of the list so we can continue parsing. if ($is_repeatable && $this->unconsumedArguments) { $this->unparsedArguments[] = $argument; } try { $value = $argument->newValue($raw_argument); } catch (Exception $ex) { throw new Exception( pht( 'Argument "%s" (in position "%s") to function "%s" is '. 'invalid: %s', $name, $this->argumentPosition, $this->getFunctionArgumentSignature(), $ex->getMessage())); } if ($is_repeatable) { if (!isset($this->argumentValues[$name])) { $this->argumentValues[$name] = array(); } $this->argumentValues[$name][] = $value; } else { $this->argumentValues[$name] = $value; } } } public function getArgumentValue($key) { if (!array_key_exists($key, $this->argumentValues)) { throw new Exception( pht( 'Function "%s" is requesting an argument ("%s") that it did '. 'not define.', $this->getFunctionArgumentSignature(), $key)); } return $this->argumentValues[$key]; } private function getFunctionArgumentSignature() { $argument_list = array(); foreach ($this->argumentMap as $key => $spec) { $argument_list[] = $key; } if (!$this->haveAllArguments || $this->repeatableArgument) { $argument_list[] = '...'; } return sprintf( '%s(%s)', $this->getFunction()->getFunctionKey(), implode(', ', $argument_list)); } }
php
Apache-2.0
5720a38cfe95b00ca4be5016dd0d2f3195f4fa04
2026-01-04T15:03:23.651835Z
false