/** * @param MediaInfoStorageItem $mediaItem * @param string $cdnType * @param array $operations * * @return string */ protected function createRequestParameterValue(MediaInfoStorageItem $mediaItem, $cdnType, array $operations = array()) { $params = array('id' => $mediaItem->getId(), 'websiteid' => $mediaItem->getWebsiteId(), 'type' => $cdnType, 'date' => $mediaItem->getLastModified()); if (!empty($operations)) { $params['chain'] = $this->convertOperationsToChainString($operations); } return urlencode(\json_encode($params)); }
/** * @param MediaInfoStorageItem $mediaItem * @param array $operations * * @return string */ public function getPreviewUrl(MediaInfoStorageItem $mediaItem, array $operations = array()) { $ops = array(); foreach ($operations as $op) { $ops[] = join('_', $op); } $operationSting = join('/', $ops); $return = $this->prefix . "/" . $mediaItem->getId() . '/' . $mediaItem->getName() . '/' . $operationSting; $this->calls[] = array('method' => 'getPreviewUrl', 'params' => array($mediaItem->getId(), $operations), 'return' => $return); return $return; }
/** * @return array */ protected function createTestDataForMovedResponse() { $websiteId = $this->websiteId; $mediaId = 'MEDIA-00000000-0000-0000-0000-000000000001-MEDIA'; $uploadData = time() - 3600; $mediaItem = new MediaInfoStorageItem($mediaId, FS::joinPath($this->getMediaFileDirectory($websiteId), 'logo.jpg'), 'logo.jpg', time(), 10, time(), FS::joinPath($this->getMediaFileDirectory($websiteId), '/icon_jpg.png'), $websiteId); $infoStorageMock = $this->createMediaItemInfoStorageMock(array($mediaItem->getId() => $mediaItem)); $mediaContext = $this->createMediaContext($infoStorageMock); $httpRequestMock = $this->createHttpRequestMock(); $mediaRequest = new MediaRequest($mediaId, MediaRequest::TYPE_STREAM, $uploadData - 1); return array($mediaContext, $httpRequestMock, $mediaRequest, '\\Render\\MediaCDNHelper\\MediaResponse\\MovedResponse'); }
protected function validateMediaInfoStorageItem(array $itemArray, MediaInfoStorageItem $infoStorageItem) { $this->assertEquals($itemArray['id'], $infoStorageItem->getId()); $this->assertEquals($itemArray['name'], $infoStorageItem->getName()); $this->assertEquals($itemArray['size'], $infoStorageItem->getSize()); $this->assertEquals($itemArray['filePath'], $infoStorageItem->getFilePath()); $this->assertEquals($itemArray['lastModified'], $infoStorageItem->getLastModified()); }
/** * @param MediaInfoStorageItem $mediaItem * @param MediaRequest $mediaRequest * * @return string */ private function uniqueKey(MediaInfoStorageItem $mediaItem, MediaRequest $mediaRequest) { return md5(json_encode(array('id' => $mediaItem->getId(), 'type' => $mediaRequest->getCdnType(), 'operations' => $mediaRequest->getOperations()))); }
/** * @param MediaInfoStorageItem $mediaItem * @param string $filePath * @param string $cmsCacheFilePath * * @return bool */ protected function isCmsCacheFileValid(MediaInfoStorageItem $mediaItem, $filePath, $cmsCacheFilePath) { $orgFileTime = @\filemtime($filePath); $cacheFileTime = @\filemtime($cmsCacheFilePath); $cacheFileSize = @\filesize($cmsCacheFilePath); if (empty($orgFileTime) || empty($cacheFileTime) || empty($cacheFileSize)) { return false; } if ($orgFileTime >= $cacheFileTime) { return false; } if ($mediaItem->getLastModified() >= $cacheFileTime) { return false; } return true; }
/** * @param MediaInfoStorageItem $mediaItem * @param $useIcon * * @return string */ private function getBaseFilenameForCache(MediaInfoStorageItem $mediaItem, $useIcon) { if ($useIcon) { return basename($mediaItem->getIconFilePath()); } else { $extension = $this->getExtensionFromFilename(basename($mediaItem->getFilePath())); return $mediaItem->getId() . '.' . $extension; } }
/** * @param MediaInfoStorageItem $mediaItem * * @return bool */ protected function isTypeOfSvg(MediaInfoStorageItem $mediaItem) { $filePath = $mediaItem->getFilePath(); return substr($filePath, -3) == 'svg'; }
/** * @param MediaInfoStorageItem $mediaItem * @param $filename * @param array $operations * * @param string $cdnType * * @return string */ protected function createImageUrl(MediaInfoStorageItem $mediaItem, $filename, array $operations, $cdnType) { $call = array('id' => $mediaItem->getId(), 'type' => $cdnType, 'operations' => $operations); $this->addMediaCall($call); return parent::createImageUrl($mediaItem, $filename, $operations, $cdnType); }