/** * Delete the file from the cloud (if it was ever there) */ public function onAfterDelete() { $bucket = CloudAssets::inst()->map($this->owner->getFilename()); if ($bucket && !Config::inst()->get('CloudAssets', 'uploads_disabled')) { if ($this->owner->hasMethod('onBeforeCloudDelete')) { $this->owner->onBeforeCloudDelete(); } try { CloudAssets::inst()->getLogger()->info("CloudAssets: deleting {$this->owner->getFilename()}"); $bucket->delete($this->owner); } catch (Exception $e) { CloudAssets::inst()->getLogger()->error("CloudAssets: Failed bucket delete: " . $e->getMessage() . " for " . $this->owner->getFullPath()); } if ($this->owner->hasMethod('onAfterCloudDelete')) { $this->owner->onAfterCloudDelete(); } } }
/** * @param File $f * @throws Exception */ public function put(File $f) { $fp = fopen($f->getFullPath(), 'r'); if (!$fp) { throw new Exception("Unable to open file: " . $f->getFilename()); } $headers = array(); if (!empty($this->config[self::FORCE_DL])) { $headers['Content-Disposition'] = 'attachment; filename=' . ($f->hasMethod('getFriendlyName') ? $f->getFriendlyName() : $f->Name); } $this->getContainer()->uploadObject($this->getRelativeLinkFor($f), $fp, $headers); }
/** * @param File $file * @return string */ protected function getThumbnailURLForFile(File $file) { if ($file->exists() && file_exists(Director::baseFolder() . '/' . $file->getFilename())) { $width = $this->getPreviewMaxWidth(); $height = $this->getPreviewMaxHeight(); if ($file->hasMethod('getThumbnail')) { return $file->getThumbnail($width, $height)->getURL(); } elseif ($file->hasMethod('getThumbnailURL')) { return $file->getThumbnailURL($width, $height); } elseif ($file->hasMethod('SetRatioSize')) { return $file->SetRatioSize($width, $height)->getURL(); } else { return $file->Icon(); } } return false; }
/** * @param File $file * @return string */ protected function getThumbnailURLForFile(File $file) { if ($file && $file->exists() && file_exists(Director::baseFolder() . '/' . $file->getFilename())) { if ($file->hasMethod('getThumbnail')) { return $file->getThumbnail($this->getConfig('previewMaxWidth'), $this->getConfig('previewMaxHeight'))->getURL(); } elseif ($file->hasMethod('getThumbnailURL')) { return $file->getThumbnailURL($this->getConfig('previewMaxWidth'), $this->getConfig('previewMaxHeight')); } elseif ($file->hasMethod('SetRatioSize')) { return $file->SetRatioSize($this->getConfig('previewMaxWidth'), $this->getConfig('previewMaxHeight'))->getURL(); } else { return $file->Icon(); } } return false; }
/** * Determines the validator to use for the edit form * @example 'getCMSValidator' * * @param File $file File context to generate validator from * @return Validator Validator object */ public function getDMSFileEditValidator($file) { // Empty validator if (empty($this->fileEditValidator)) { return null; } // Validator instance if ($this->fileEditValidator instanceof Validator) { return $this->fileEditValidator; } // Method to call on the given file if ($file->hasMethod($this->fileEditValidator)) { return $file->{$this->fileEditValidator}(); } user_error("Invalid value for UploadField::fileEditValidator", E_USER_ERROR); }