Advertisement
Guest User

Untitled

a guest
Feb 28th, 2014
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.87 KB | None | 0 0
  1. public function handleRequest(SS_HTTPRequest $request, DataModel $model = null) {
  2. $response = parent::handleRequest($request, $model);
  3. if ($body = $response->getBody()) {
  4. $body = self::replaceCDN($body);
  5. $response->setBody($body);
  6. }
  7. return $response;
  8. }
  9.  
  10.  
  11. static function replaceCDN($body) {
  12. if (!$body) {
  13. return;
  14. }
  15. $cdn = "//" . S3_BUCKET . ".s3.amazonaws.com/assets"; // or a working cname record
  16. $myDomain = Director::absoluteBaseURL();
  17. $body = str_replace('src="assets/', 'src="'.$cdn.'/', $body);
  18. $body = str_replace('href="assets/', 'href="'.$cdn.'/', $body);
  19. $body = str_replace($myDomain . 'assets/', $cdn.'/', $body); //absolute links
  20.  
  21. return $body;
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement