Modify the response to add link to the email preview.

@param $response
@param $previewPath
4643
private function addLinkToResponse($response, $previewPath)
    {
        if (app()->runningInConsole()) {
            return;
        }

        $content = $response->getContent();

        $linkHTML = "<div id='MailPreviewDriverBox' style='
            position:absolute;
            top:0;
            z-index:99999;
            background:#fff;
            border:solid 1px #ccc;
            padding: 15px;
            '>
        An email was just sent: <a href='".url('/themsaid/mail-preview?path='.$previewPath)."'>Preview Sent Email</a>
        </div>";

        $timeout = intval(config('mailpreview.popup_timeout', 8000));

        if ($timeout > 0) {
            $linkHTML .= "<script type=\"text/javascript\">";

            $linkHTML .= "setTimeout(function(){
            document.body.removeChild(document.getElementById('MailPreviewDriverBox'));
            }, " . $timeout . ");";

            $linkHTML .= "</script>";
        }


        $bodyPosition = strripos($content, '</body>');

        if (false !== $bodyPosition) {
            $content = substr($content, 0, $bodyPosition).$linkHTML.substr($content, $bodyPosition);
        }

        $response->setContent($content);
    }
784391
public function renderWithExtraParams($view, array $parameters = [], Response $response = null)
    {
        if (!$this->isXmlHttpRequest()) {
            $parameters['breadcrumbs_builder'] = $this->get('sonata.admin.breadcrumbs_builder');
        }
        $parameters['admin'] = $parameters['admin'] ??
            $this->admin;

        $parameters['base_template'] = $parameters['base_template'] ??
            $this->getBaseTemplate();

        $parameters['admin_pool'] = $this->get('sonata.admin.pool');

        //NEXT_MAJOR: Remove method alias and use $this->render() directly.
        return $this->originalRender($view, $parameters, $response);
    }
1096231
public function updateRecords(array $apidata, $preview = false)
    {
        if (is_array($apidata)) {
            $this->setSource(new ArrayBulkLoaderSource($apidata));
        }
        $this->addNewRecords = false;
        $this->preprocessChecks();
        return $this->load(null, $preview);
    }
1193656
private function addLinkHeader(Response $response, $link)
    {
        if ($response->headers->get('Link')) {
            $link = $response->headers->get('Link') . ',' . $link;
        }

        $response->header('Link', $link);
    }
352874
protected function addNextSearchLinks( $request, $response ) {

		$max_pages = (int) ceil( $this->totalBooks / (int) $request['per_page'] );

		$response->header( 'X-WP-Total', (int) $this->totalBooks );
		$response->header( 'X-WP-TotalPages', $max_pages );

		if ( $this->lastKnownBookId ) {
			unset( $request['page'] );
			$request_params = $request->get_query_params();
			$base = add_query_arg( $request_params, rest_url( sprintf( '%s/%s', $this->namespace, $this->rest_base ) ) );
			$next_link = add_query_arg( 'next', $this->lastKnownBookId, $base );
			$response->link_header( 'next', $next_link );
		}
	}
815585
def show_body
      prevent_browser_caching
      cms_edit_links!
      with_email_locale do
        _, body = mail_and_body
        render inline: body, layout: 'rails_email_preview/email'
      end
    end
666586
public function preview() {
    if ($this->uuid) {
      $this->_save(Recurly_Client::POST, $this->uri() . '/preview');
    } else {
      $this->_save(Recurly_Client::POST, Recurly_Client::PATH_SUBSCRIPTIONS . '/preview');
    }
  }
1371603
public function previewTemplateWithEmail($template, $send_email) {
        $data = [ ];
        $data['template'] = $template;
        $data['send_email'] = $send_email;

        $result = $this->apiPost('preview', $data);
        return $result;
    }
128340
def ajax_preview(request, **kwargs):
    
    data = {
        "html": render_to_string("pinax/blog/_preview.html", {
            "content": parse(request.POST.get("markup"))
        })
    }
    return JsonResponse(data)
38076
function displayResponse(response){
  
  // Gather and display HTTP response data
  var lines = [
    response.statusCode + ' ' + response.statusText,
    headersToString(response.headers)
  ];
  if(response.data){
    lines.push('');
    lines.push(prettyPrint(response.data));
  }
  output(lines.join('\n'));
  
  // Attach listeners to links so that clicking a link will auto-populate
  // the url field
  Array.from($output.querySelectorAll('.link')).forEach(function(link){
    link.addEventListener('click', function(){
      // Remove leading and trailing "
      $url.value = link.innerHTML.slice(1,-1);
      window.scrollTo(0, 0);
    });
  });
}
676848
public function injectDebugBar(ResponseInterface $response)
    {
        $content = $response->getContent();

        $renderer = $this->getJavascriptRenderer();
        $renderedContent = $this->generateAssetsContent().$renderer->render();

        $pos = strripos($content, '</body>');
        if (false !== $pos) {
            $content = substr($content, 0, $pos).$renderedContent.substr($content, $pos);
        } else {
            $content = '<body>'.$content.'</body>'.$renderedContent;
        }
        // Update the new content and reset the content length
        $response->setContent($content);
        $response->headers->remove('Content-Length');
    }
1237039
protected function handleResponseCreateFilelink($response)
    {
        $status_code = $response->getStatusCode();

        if ($status_code !== 200) {
            throw new FilestackException($response->getBody(), $status_code);
        }

        $json_response = json_decode($response->getBody(), true);
        $url = $json_response['url'];
        $file_handle = substr($url, strrpos($url, '/') + 1);

        $filelink = new Filelink($file_handle, $this->api_key, $this->security);
        $filelink->metadata['filename'] = $json_response['filename'];
        $filelink->metadata['size'] = $json_response['size'];
        $filelink->metadata['mimetype'] = 'unknown';

        if (isset($json_response['type'])) {
            $filelink->metadata['mimetype'] = $json_response['type'];
        } elseif (isset($json_response['mimetype'])) {
            $filelink->metadata['mimetype'] = $json_response['mimetype'];
        }

        return $filelink;
    }
545451
public function htmlAction(Request $request, $teaserId)
    {
        $requestStack = $this->get('request_stack');
        $masterRequest = $requestStack->getMasterRequest();

        if ($request->get('preview') || $request->get('_preview')) {
            $request->attributes->set('_preview', true);
        } elseif ($masterRequest !== $request && $masterRequest->attributes->get('_preview')) {
            $request->attributes->set('_preview', true);
        }

        $teaser = $this->get('phlexible_teaser.teaser_service')->find($teaserId);

        $request->attributes->set('contentDocument', $teaser);

        $renderConfigurator = $this->get('phlexible_element_renderer.configurator');
        $renderConfig = $renderConfigurator->configure($request);

        if ($renderConfig->getResponse()) {
            return $renderConfig->getResponse();
        }

        if ($request->get('template')) {
            $renderConfig->set('template', $request->get('template', 'teaser'));
        }

        $data = $renderConfig->getVariables();

        return $this->render($data['template'], (array) $data);
    }
567446
protected function buildSelfLink(array &$response)
    {
        $link = [];

        if (!empty($type = $response[Serializer::CLASS_IDENTIFIER_KEY])) {
            list($idValues, $idProperties) = RecursiveFormatterHelper::getIdPropertyAndValues(
                $this->mappings,
                $response,
                $type
            );

            $href = self::buildUrl(
                $this->mappings,
                $idProperties,
                $idValues,
                $this->mappings[$type]->getResourceUrl(),
                $type
            );

            if ($href != $this->mappings[$type]->getResourceUrl()) {
                $link[self::SELF_LINK] = $href;
            }
        }

        return $link;
    }
25541
def preview(self):
        """"""

        if hasattr(self, '_url'):
            url = self._url + '/preview'
            return self.post(url)
        else:
            url = urljoin(recurly.base_uri(), self.collection_path + '/preview')
            return self.post(url)
117534
public function upsertManyRecords(array $apidata, $preview = false)
    {
        if (is_array($apidata)) {
            $this->setSource(new ArrayBulkLoaderSource($apidata));
        }
        $this->preprocessChecks();
        return $this->load(null, $preview);
    }
211352
public function injectDebugbar(Response $response)
    {
        $content = $response->getContent();

        $renderer = $this->getJavascriptRenderer();

        $openHandlerUrl = $this->di['url']->getStatic( array('for'=>'debugbar.openhandler') );
        $renderer->setOpenHandlerUrl($openHandlerUrl);


        $renderedContent = $renderer->renderHead() . $renderer->render();

        $pos = strripos($content, '</body>');
        if (false !== $pos) {
            $content = substr($content, 0, $pos) . $renderedContent . substr($content, $pos);
        } else {
            $content = $content . $renderedContent;
        }

        $response->setContent($content);
    }