Path: blob/master/src/view/form/control/PhabricatorRemarkupControl.php
12256 views
<?php12final class PhabricatorRemarkupControl3extends AphrontFormTextAreaControl {45private $disableFullScreen = false;6private $canPin;7private $sendOnEnter = false;8private $remarkupMetadata = array();910public function setDisableFullScreen($disable) {11$this->disableFullScreen = $disable;12return $this;13}1415public function setCanPin($can_pin) {16$this->canPin = $can_pin;17return $this;18}1920public function getCanPin() {21return $this->canPin;22}2324public function setSendOnEnter($soe) {25$this->sendOnEnter = $soe;26return $this;27}2829public function getSendOnEnter() {30return $this->sendOnEnter;31}3233public function setRemarkupMetadata(array $value) {34$this->remarkupMetadata = $value;35return $this;36}3738public function getRemarkupMetadata() {39return $this->remarkupMetadata;40}4142public function setValue($value) {43if ($value instanceof RemarkupValue) {44$this->setRemarkupMetadata($value->getMetadata());45$value = $value->getCorpus();46}4748return parent::setValue($value);49}5051protected function renderInput() {52$id = $this->getID();53if (!$id) {54$id = celerity_generate_unique_node_id();55$this->setID($id);56}5758$viewer = $this->getUser();59if (!$viewer) {60throw new PhutilInvalidStateException('setUser');61}6263// NOTE: Metadata is passed to Javascript in a structured way, and also64// dumped directly into the form as an encoded string. This makes it less65// likely that we'll lose server-provided metadata (for example, from a66// saved draft) if there is a client-side error.6768$metadata_name = $this->getName().'_metadata';69$metadata_value = (object)$this->getRemarkupMetadata();70$metadata_string = phutil_json_encode($metadata_value);7172$metadata_id = celerity_generate_unique_node_id();73$metadata_input = phutil_tag(74'input',75array(76'type' => 'hidden',77'id' => $metadata_id,78'name' => $metadata_name,79'value' => $metadata_string,80));8182// We need to have this if previews render images, since Ajax can not83// currently ship JS or CSS.84require_celerity_resource('phui-lightbox-css');8586if (!$this->getDisabled()) {87Javelin::initBehavior(88'aphront-drag-and-drop-textarea',89array(90'target' => $id,91'remarkupMetadataID' => $metadata_id,92'remarkupMetadataValue' => $metadata_value,93'activatedClass' => 'aphront-textarea-drag-and-drop',94'uri' => '/file/dropupload/',95'chunkThreshold' => PhabricatorFileStorageEngine::getChunkThreshold(),96));97}9899$root_id = celerity_generate_unique_node_id();100101$user_datasource = new PhabricatorPeopleDatasource();102$emoji_datasource = new PhabricatorEmojiDatasource();103$proj_datasource = id(new PhabricatorProjectDatasource())104->setParameters(105array(106'autocomplete' => 1,107));108109$phriction_datasource = new PhrictionDocumentDatasource();110$phurl_datasource = new PhabricatorPhurlURLDatasource();111112Javelin::initBehavior(113'phabricator-remarkup-assist',114array(115'pht' => array(116'bold text' => pht('bold text'),117'italic text' => pht('italic text'),118'monospaced text' => pht('monospaced text'),119'List Item' => pht('List Item'),120'Quoted Text' => pht('Quoted Text'),121'data' => pht('data'),122'name' => pht('name'),123'URL' => pht('URL'),124'key-help' => pht('Pin or unpin the comment form.'),125),126'canPin' => $this->getCanPin(),127'disabled' => $this->getDisabled(),128'sendOnEnter' => $this->getSendOnEnter(),129'rootID' => $root_id,130'autocompleteMap' => (object)array(13164 => array( // "@"132'datasourceURI' => $user_datasource->getDatasourceURI(),133'headerIcon' => 'fa-user',134'headerText' => pht('Find User:'),135'hintText' => $user_datasource->getPlaceholderText(),136),13735 => array( // "#"138'datasourceURI' => $proj_datasource->getDatasourceURI(),139'headerIcon' => 'fa-briefcase',140'headerText' => pht('Find Project:'),141'hintText' => $proj_datasource->getPlaceholderText(),142),14358 => array( // ":"144'datasourceURI' => $emoji_datasource->getDatasourceURI(),145'headerIcon' => 'fa-smile-o',146'headerText' => pht('Find Emoji:'),147'hintText' => $emoji_datasource->getPlaceholderText(),148149// Cancel on emoticons like ":3".150'ignore' => array(151'3',152')',153'(',154'-',155'/',156),157),15891 => array( // "["159'datasourceURI' => $phriction_datasource->getDatasourceURI(),160'headerIcon' => 'fa-book',161'headerText' => pht('Find Document:'),162'hintText' => $phriction_datasource->getPlaceholderText(),163'cancel' => array(164':', // Cancel on "http:" and similar.165'|',166']',167),168'prefix' => '^\\[',169),17040 => array( // "("171'datasourceURI' => $phurl_datasource->getDatasourceURI(),172'headerIcon' => 'fa-compress',173'headerText' => pht('Find Phurl:'),174'hintText' => $phurl_datasource->getPlaceholderText(),175'cancel' => array(176')',177),178'prefix' => '^\\(',179),180),181));182Javelin::initBehavior('phabricator-tooltips', array());183184$actions = array(185'fa-bold' => array(186'tip' => pht('Bold'),187'nodevice' => true,188),189'fa-italic' => array(190'tip' => pht('Italics'),191'nodevice' => true,192),193'fa-text-width' => array(194'tip' => pht('Monospaced'),195'nodevice' => true,196),197'fa-link' => array(198'tip' => pht('Link'),199'nodevice' => true,200),201array(202'spacer' => true,203'nodevice' => true,204),205'fa-list-ul' => array(206'tip' => pht('Bulleted List'),207'nodevice' => true,208),209'fa-list-ol' => array(210'tip' => pht('Numbered List'),211'nodevice' => true,212),213'fa-code' => array(214'tip' => pht('Code Block'),215'nodevice' => true,216),217'fa-quote-right' => array(218'tip' => pht('Quote'),219'nodevice' => true,220),221'fa-table' => array(222'tip' => pht('Table'),223'nodevice' => true,224),225'fa-cloud-upload' => array(226'tip' => pht('Upload File'),227),228);229230$can_use_macros = function_exists('imagettftext');231232if ($can_use_macros) {233$can_use_macros = PhabricatorApplication::isClassInstalledForViewer(234'PhabricatorMacroApplication',235$viewer);236}237238if ($can_use_macros) {239$actions[] = array(240'spacer' => true,241);242$actions['fa-meh-o'] = array(243'tip' => pht('Meme'),244);245}246247$actions['fa-eye'] = array(248'tip' => pht('Preview'),249'align' => 'right',250);251252$actions['fa-book'] = array(253'tip' => pht('Help'),254'align' => 'right',255'href' => PhabricatorEnv::getDoclink('Remarkup Reference'),256);257258$mode_actions = array();259260if (!$this->disableFullScreen) {261$mode_actions['fa-arrows-alt'] = array(262'tip' => pht('Fullscreen Mode'),263'align' => 'right',264);265}266267if ($this->getCanPin()) {268$mode_actions['fa-thumb-tack'] = array(269'tip' => pht('Pin Form On Screen'),270'align' => 'right',271);272}273274if ($mode_actions) {275$actions += $mode_actions;276}277278$buttons = array();279foreach ($actions as $action => $spec) {280281$classes = array();282283if (idx($spec, 'align') == 'right') {284$classes[] = 'remarkup-assist-right';285}286287if (idx($spec, 'nodevice')) {288$classes[] = 'remarkup-assist-nodevice';289}290291if (idx($spec, 'spacer')) {292$classes[] = 'remarkup-assist-separator';293$buttons[] = phutil_tag(294'span',295array(296'class' => implode(' ', $classes),297),298'');299continue;300} else {301$classes[] = 'remarkup-assist-button';302}303304if ($action == 'fa-cloud-upload') {305$classes[] = 'remarkup-assist-upload';306}307308$href = idx($spec, 'href', '#');309if ($href == '#') {310$meta = array('action' => $action);311$mustcapture = true;312$target = null;313} else {314$meta = array();315$mustcapture = null;316$target = '_blank';317}318319$content = null;320321$tip = idx($spec, 'tip');322if ($tip) {323$meta['tip'] = $tip;324$content = javelin_tag(325'span',326array(327'aural' => true,328),329$tip);330}331332$sigils = array();333$sigils[] = 'remarkup-assist';334if (!$this->getDisabled()) {335$sigils[] = 'has-tooltip';336}337338$buttons[] = javelin_tag(339'a',340array(341'class' => implode(' ', $classes),342'href' => $href,343'sigil' => implode(' ', $sigils),344'meta' => $meta,345'mustcapture' => $mustcapture,346'target' => $target,347'tabindex' => -1,348),349phutil_tag(350'div',351array(352'class' =>353'remarkup-assist phui-icon-view phui-font-fa bluegrey '.$action,354),355$content));356}357358$buttons = phutil_tag(359'div',360array(361'class' => 'remarkup-assist-bar',362),363$buttons);364365$use_monospaced = $viewer->compareUserSetting(366PhabricatorMonospacedTextareasSetting::SETTINGKEY,367PhabricatorMonospacedTextareasSetting::VALUE_TEXT_MONOSPACED);368369if ($use_monospaced) {370$monospaced_textareas_class = 'PhabricatorMonospaced';371} else {372$monospaced_textareas_class = null;373}374375$this->setCustomClass(376'remarkup-assist-textarea '.$monospaced_textareas_class);377378return javelin_tag(379'div',380array(381'sigil' => 'remarkup-assist-control',382'class' => $this->getDisabled() ? 'disabled-control' : null,383'id' => $root_id,384),385array(386$buttons,387parent::renderInput(),388$metadata_input,389));390}391392}393394395