public function processRequest() { $request = $this->getRequest(); $user = $request->getUser(); $cache = new PhabricatorKeyValueDatabaseCache(); $cache = new PhutilKeyValueCacheProfiler($cache); $cache->setProfiler(PhutilServiceProfiler::getInstance()); $result = $cache->getKey('darkconsole:' . $this->key); if (!$result) { return new Aphront400Response(); } try { $result = phutil_json_decode($result); } catch (PhutilJSONParserException $ex) { return new Aphront400Response(); } if ($result['vers'] != DarkConsoleCore::STORAGE_VERSION) { return new Aphront400Response(); } if ($result['user'] != $user->getPHID()) { return new Aphront400Response(); } $output = array(); $output['tabs'] = $result['tabs']; $output['panel'] = array(); foreach ($result['data'] as $class => $data) { try { $obj = newv($class, array()); $obj->setData($data); $obj->setRequest($request); $panel = $obj->renderPanel(); // Because cookie names can now be prefixed, wipe out any cookie value // with the session cookie name anywhere in its name. $pattern = '(' . preg_quote(PhabricatorCookies::COOKIE_SESSION) . ')'; foreach ($_COOKIE as $cookie_name => $cookie_value) { if (preg_match($pattern, $cookie_name)) { $panel = PhutilSafeHTML::applyFunction('str_replace', $cookie_value, '(session-key)', $panel); } } $output['panel'][$class] = $panel; } catch (Exception $ex) { $output['panel'][$class] = 'error'; } } return id(new AphrontAjaxResponse())->setContent($output); }
protected function willSendResponse($response) { $request = $this->getRequest(); $response = parent::willSendResponse($response); $console = $request->getApplicationConfiguration()->getConsole(); if ($console) { $response = PhutilSafeHTML::applyFunction('str_replace', hsprintf('<darkconsole />'), $console->render($request), $response); } return $response; }
private function highlightSource($text, array $options) { if ($options['counterexample']) { $aux_class = ' remarkup-counterexample'; } else { $aux_class = null; } $aux_style = null; if ($this->getEngine()->isHTMLMailMode()) { if ($options['counterexample']) { $aux_style = 'border: 1px solid #c0392b; background: #f4dddb; font-size: 10x; padding: 8px;'; } else { $aux_style = 'border: 1px solid #f1c40f; background: #fdf5d4; font-size: 10x; padding: 8px;'; } } if ($options['lines']) { // Put a minimum size on this because the scrollbar is otherwise // unusable. $height = max(6, (int) $options['lines']); $aux_style = $aux_style . ' ' . 'max-height: ' . 2 * $height . 'em; overflow: auto;'; } $engine = $this->getEngine()->getConfig('syntax-highlighter.engine'); if (!$engine) { $engine = 'PhutilDefaultSyntaxHighlighterEngine'; } $engine = newv($engine, array()); $engine->setConfig('pygments.enabled', $this->getEngine()->getConfig('pygments.enabled')); return phutil_tag('pre', array('class' => 'remarkup-code' . $aux_class, 'style' => $aux_style), PhutilSafeHTML::applyFunction('rtrim', $engine->highlightSource($options['lang'], $text))); }
private function highlightSource($text, array $options) { if ($options['counterexample']) { $aux_class = ' remarkup-counterexample'; } else { $aux_class = null; } $aux_style = null; if ($options['lines']) { // Put a minimum size on this because the scrollbar is otherwise // unusable. $height = max(6, (int) $options['lines']); $aux_style = 'max-height: ' . 2 * $height . 'em;'; } $engine = $this->getEngine()->getConfig('syntax-highlighter.engine'); if (!$engine) { $engine = 'PhutilDefaultSyntaxHighlighterEngine'; } $engine = newv($engine, array()); $engine->setConfig('pygments.enabled', $this->getEngine()->getConfig('pygments.enabled')); return phutil_tag('pre', array('class' => 'remarkup-code' . $aux_class, 'style' => $aux_style), PhutilSafeHTML::applyFunction('rtrim', $engine->highlightSource($options['lang'], $text))); }
function phutil_escape_html_newlines($string) { return PhutilSafeHTML::applyFunction('nl2br', $string); }
private function highlightSource($text, array $options) { if ($options['counterexample']) { $aux_class = ' remarkup-counterexample'; } else { $aux_class = null; } $aux_style = null; if ($this->getEngine()->isHTMLMailMode()) { $aux_style = array('font: 11px/15px "Menlo", "Consolas", "Monaco", monospace;', 'padding: 12px;', 'margin: 0;'); if ($options['counterexample']) { $aux_style[] = 'background: #f7e6e6;'; } else { $aux_style[] = 'background: rgba(71, 87, 120, 0.08);'; } $aux_style = implode(' ', $aux_style); } if ($options['lines']) { // Put a minimum size on this because the scrollbar is otherwise // unusable. $height = max(6, (int) $options['lines']); $aux_style = $aux_style . ' ' . 'max-height: ' . 2 * $height . 'em; overflow: auto;'; } $engine = $this->getEngine()->getConfig('syntax-highlighter.engine'); if (!$engine) { $engine = 'PhutilDefaultSyntaxHighlighterEngine'; } $engine = newv($engine, array()); $engine->setConfig('pygments.enabled', $this->getEngine()->getConfig('pygments.enabled')); return phutil_tag('pre', array('class' => 'remarkup-code' . $aux_class, 'style' => $aux_style), PhutilSafeHTML::applyFunction('rtrim', $engine->highlightSource($options['lang'], $text))); }