Пример #1
0
 public function SetImageSize($width, $height, $crop = 'fill', $gravity = 'faces')
 {
     CloudinaryFile::get_api();
     $options = array('width' => $width, 'height' => $height, 'crop' => $crop, 'quality' => 70, 'gravity' => $gravity, 'secure_distribution' => true, 'secure' => true);
     $cloudinaryID = CloudinaryFile::get_public_id($this->CloudinaryURL);
     return Cloudinary::cloudinary_url($cloudinaryID . '.' . $this->Format, $options);
 }
Пример #2
0
 public function Link()
 {
     CloudinaryFile::get_api();
     $options = array('secure_distribution' => true, 'secure' => true);
     $cloudinaryID = CloudinaryFile::get_public_id($this->CloudinaryURL);
     return Cloudinary::cloudinary_url($cloudinaryID . '.' . $this->Format, $options);
 }
 /**
  * Scrape the content of a field to detect anly links to local SiteTree pages or files
  *
  * @param string $field The name of the field on {@link @owner} to scrape
  */
 public function trackLinksInField($field)
 {
     $record = $this->owner;
     $linkedCloudinary = array();
     preg_match_all('/\\[cloudinary,id=\\"\\d*\\"/i', $record->{$field}, $matches);
     if ($matches && isset($matches[0])) {
         foreach ($matches[0] as $match) {
             $id = str_replace('"', '', str_replace('[cloudinary,id=', '', $match));
             if ($file = CloudinaryFile::get()->byID((int) $id)) {
                 $linkedCloudinary[] = (int) $id;
             } else {
                 $record->HasBrokenFile = true;
             }
         }
     }
     // Update the "CloudinaryTracking" many_many
     if ($record->ID && $record->many_many('CloudinaryTracking') && ($tracker = $record->CloudinaryTracking())) {
         $tracker->removeByFilter(sprintf('"FieldName" = \'%s\' AND "%s" = %d', $field, $tracker->getForeignKey(), $record->ID));
         if ($linkedCloudinary) {
             foreach ($linkedCloudinary as $item) {
                 $tracker->add($item, array('FieldName' => $field));
             }
         }
     }
     parent::trackLinksInField($field);
 }
 public function upload(SS_HTTPRequest $request)
 {
     $name = $this->getName();
     $postVars = $request->postVar($name);
     $tmpFileName = null;
     if (isset($postVars['tmp_name']) && isset($postVars['tmp_name']['file']) && !empty($postVars['tmp_name']['file'])) {
         $tmpFileName = $postVars['tmp_name']['file'];
     }
     if ($tmpFileName && is_uploaded_file($tmpFileName)) {
         CloudinaryFile::get_api();
         $arrRet = Uploader::upload($tmpFileName);
         Session::set('public_id', $arrRet['secure_url']);
         Session::save();
     }
 }
 /**
  * @param $arguments
  * @param null $content
  * @param null $parser
  * @return string
  *
  * Parse short codes for the cloudinary tags
  */
 public static function cloudinary_markdown($arguments, $content = null, $parser = null)
 {
     if (!isset($arguments['id']) || !is_numeric($arguments['id'])) {
         return;
     }
     $file = CloudinaryFile::get()->byID($arguments['id']);
     if ($file) {
         if ($file->ClassName == 'CloudinaryImage') {
             $alt = "";
             if (isset($arguments['alt'])) {
                 $alt = $arguments['alt'];
             }
             if (isset($arguments['width']) && isset($arguments['height'])) {
                 return $file->customise(array('width' => $arguments['width'], 'height' => $arguments['height'], 'alt' => $alt))->renderWith('MarkDownShortCode');
             } else {
                 return $file->customise(array('alt' => $alt))->renderWith('MarkDownShortCode');
             }
         }
     }
 }
 /**
  * @return mixed
  */
 public function ColorSelectThumbnail()
 {
     if ($video = CloudinaryFile::get()->byID($this->value)) {
         return $video->GetFileImage(200, 112, 90);
     }
 }
 public function onBeforeInit()
 {
     CloudinaryFile::SetCloudinaryConfigs();
 }
 /**
  * @return DataObject|File
  */
 public function getItem()
 {
     return CloudinaryFile::get()->byId($this->itemID);
 }