/**
  * @param ServerRequestInterface $request
  * @param ResponseInterface $response
  * @param callable $next
  *
  * @return ResponseInterface
  */
 public function __invoke(ServerRequestInterface $request, ResponseInterface $response, callable $next)
 {
     if ($staticFile = $this->getStaticFile($request->getUri())) {
         return $staticFile;
     }
     $outResponse = $next($request, $response);
     if (!$this->isHtmlAccepted($request)) {
         return $outResponse;
     }
     $debugBarHead = $this->debugBarRenderer->renderHead();
     $debugBarBody = $this->debugBarRenderer->render();
     if ($this->isHtmlResponse($outResponse)) {
         $body = $outResponse->getBody();
         if (!$body->eof() && $body->isSeekable()) {
             $body->seek(0, SEEK_END);
         }
         $body->write($debugBarHead . $debugBarBody);
         return $outResponse;
     }
     $outResponseBody = Serializer::toString($outResponse);
     $template = '<html><head>%s</head><body><h1>DebugBar</h1><p>Response:</p><pre>%s</pre>%s</body></html>';
     $escapedOutResponseBody = htmlspecialchars($outResponseBody);
     $result = sprintf($template, $debugBarHead, $escapedOutResponseBody, $debugBarBody);
     return new HtmlResponse($result);
 }
Exemplo n.º 2
0
 protected function renderBar($result)
 {
     if (strpos($result, '</head>') === false || strpos($result, '</body>') === false) {
         return $result;
     }
     $includes = $this->debugBarRenderer->renderHead();
     $this->debugBar->collect();
     $toolbar = $this->debugBarRenderer->render();
     $result = $this->insertAt($result, strpos($result, '</head>'), $includes);
     return $this->insertAt($result, strpos($result, '</body>'), $toolbar);
 }
Exemplo n.º 3
0
 /**
  * Displays the debug bar
  *
  * @return $this
  */
 public function render()
 {
     if ($this->enabled()) {
         echo $this->renderer->render();
     }
     return $this;
 }
 /**
  * @param ServerRequestInterface $request
  * @param ResponseInterface $response
  * @param callable $out
  *
  * @return ResponseInterface
  */
 public function __invoke(ServerRequestInterface $request, ResponseInterface $response, callable $out = null)
 {
     $outResponse = $out($request, $response);
     if (!$this->isHtmlAccepted($request)) {
         return $outResponse;
     }
     $debugBarHead = $this->debugBarRenderer->renderHead();
     $debugBarBody = $this->debugBarRenderer->render();
     if ($this->isHtmlResponse($outResponse)) {
         $outResponse->getBody()->write($debugBarHead . $debugBarBody);
         return $outResponse;
     }
     $outResponseBody = Serializer::toString($outResponse);
     $template = '<html><head>%s</head><body><h1>DebugBar</h1><p>Response:</p><pre>%s</pre>%s</body></html>';
     $escapedOutResponseBody = htmlspecialchars($outResponseBody);
     $result = sprintf($template, $debugBarHead, $escapedOutResponseBody, $debugBarBody);
     return new HtmlResponse($result);
 }
Exemplo n.º 5
0
 /**
  * @param JavascriptRenderer $renderer
  * @return string
  */
 public function wrapOutput(JavascriptRenderer $renderer)
 {
     ob_start();
     $renderer->dumpCssAssets();
     $css = '<style type="text/css">' . ob_get_contents() . '</style>';
     $css .= '<style type="text/css">' . $this->getCustomDebugBarStyle() . '</style>';
     ob_clean();
     $renderer->dumpJsAssets();
     $js = '<script type="text/javascript">' . ob_get_contents() . '</script>';
     ob_end_clean();
     return $css . $js . $renderer->render();
 }
Exemplo n.º 6
0
 /**
  * constructor, should be called by all derived views
  * will cause redirect if $loginrequired and not logged in
  * @param bool $loginrequired
  */
 public function __construct($loginrequired = false)
 {
     if (isset($_COOKIE['PHPSESSID'])) {
         session_start();
     }
     if ($loginrequired && !Auth::isLoggedIn()) {
         session_start();
         $this->redirect("/login");
     }
     parent::__construct();
     $reg = Registry::getInstance();
     $this->_context['images'] = $reg->imagePaths;
     $this->_context['baseHost'] = $reg->baseHost;
     $this->_context['disqus'] = $reg->disqus;
     // ownerID, if this is an owned board, this should be filled, for public boards this needs to be false
     $this->_context['ownerID'] = $reg->ownerID;
     // ownerType, if this is an owned board, this should be filled, for public boards this doesn't matter
     $this->_context['ownerType'] = $reg->ownerType;
     // when user is logged in we provide user object to all pages, false otherwise
     $this->_context['user'] = Auth::getUser();
     // make sure all views have the XSRF Token available
     $this->_context['XSRF'] = Form::getXSRFToken();
     // Global Kingboard information
     // pass version information
     $this->_context['Kingboard']['Version'] = Kingboard::VERSION;
     // ownerName, use Kingboard if not set
     if (!is_null($reg->ownerName) && $reg->ownerName) {
         $this->_context['Kingboard']['Name'] = $reg->ownerName;
     } else {
         $this->_context['Kingboard']['Name'] = Kingboard::NAME;
     }
     // release name
     $this->_context['Kingboard']['ReleaseName'] = Kingboard::RELEASE_NAME;
     // pick bootstrap theme path from public/css/themes folder
     $this->_context['theme'] = !is_null($reg->theme) ? $reg->theme : "default";
     // set header image, fall back to default if non configured
     $this->_context['header_image'] = !is_null($reg->headerImage) ? $reg->headerImage : "/images/banner/kingboard.png";
     $debugbar = $reg->debugbar;
     if (!is_null($debugbar)) {
         $jsrenderer = new JavascriptRenderer($debugbar, '/DebugBar');
         $this->_context['debugbar_header'] = $jsrenderer->renderhead();
         $this->_context['debugbar'] = $jsrenderer->render();
     }
     // ingame browser check
     $this->_context['igb'] = $this->isIGB();
 }
Exemplo n.º 7
0
 public function renderBody(IEvent $event)
 {
     $content = $event->getStr("content");
     $content .= $this->_debugRender->render();
     return $content;
 }
Exemplo n.º 8
0
 /**
  * Injects the js scripts into the given Response.
  *
  * @param Response $response A Response instance
  */
 protected function injectScripts(Response $response, JavascriptRenderer $renderer)
 {
     if (function_exists('mb_stripos')) {
         $posrFunction = 'mb_strripos';
         $substrFunction = 'mb_substr';
     } else {
         $posrFunction = 'strripos';
         $substrFunction = 'substr';
     }
     $content = $response->getContent();
     if (false !== ($pos = $posrFunction($content, '</body>'))) {
         $scripts = $renderer->renderHead() . $renderer->render();
         //            if ($this->debugbar->getStorage()) {
         //                $scripts .= sprintf('<script > phpdebugbar . setOpenHandler(new PhpDebugBar.OpenHandler({ url: "%s" }));</script
         //            > ', $this->router->generate('_debugbar'));
         //            }
         $content = $substrFunction($content, 0, $pos) . $scripts . $substrFunction($content, $pos);
         $response->setContent($content);
     }
 }
Exemplo n.º 9
0
 /**
  * @return string
  */
 public function render()
 {
     return $this->renderer->render();
 }