コード例 #1
0
 public function postRequest(\SS_HTTPRequest $request, \SS_HTTPResponse $response, \DataModel $model)
 {
     if ($this->convertUrls && $response && $response->getStatusCode() == 200) {
         // only convert if we have an HTML content type response
         $body = $response->getBody();
         // find urls inserted in content
         if (strpos($body, 'cdnfileid') > 0 && preg_match_all('/data-cdnfileid="(\\d+)"/', $body, $matches)) {
             $files = CdnImage::get()->filter('ID', $matches[1]);
             $fileIds = array();
             foreach ($files as $file) {
                 $url = $file->getUrl();
                 $filename = $file->Filename;
                 $body = str_replace("src=\"{$filename}\"", "src=\"{$url}\"", $body);
                 $fileIds[] = $file->ID;
             }
             $assets = ContentServiceAsset::get()->filter('SourceID', $matches[1]);
             foreach ($assets as $asset) {
                 $url = $asset->getUrl();
                 $filename = $asset->Filename;
                 // note the extra forward slash here, image_cached inserts it
                 $body = str_replace("src=\"/{$filename}\"", "src=\"{$url}\"", $body);
             }
             $response->setBody($body);
         }
     }
 }
コード例 #2
0
 /**
  * Create a new cached image.
  * @param string $filename The filename of the image.
  * @param boolean $isSingleton This this to true if this is a singleton() object, a stub for calling methods.
  *                             Singletons don't have their defaults set.
  */
 public function __construct($filename = null, $isSingleton = false)
 {
     parent::__construct(array(), $isSingleton);
     $this->ID = -1;
     $this->Filename = $filename;
 }