Пример #1
0
 public function getCmsFields()
 {
     $fields = parent::getCmsFields();
     $fields->addFieldsToTab('Root.VideoInformation', array(new TextField('VideoID', 'Video ID', $this->VideoID), new TextField('VideoWidth', 'Video Width', $this->VideoWidth), new TextField('VideoHeight', 'Video Height', $this->VideoHeight), new CheckboxField('UseImageInstead', 'Use the uploaded image in place of this video', $this->UseImageInstead == 1), new CheckboxField('PrivacyEnhancedMode', 'Show video in privacy enhanced mode', $this->PrivacyEnhancedMode == 1), new CheckboxField('AutoPlay', 'Autoplay video (not recommended)', $this->AutoPlay == 1), new CheckboxField('ShowSuggestedVideos', 'Show suggested videos at end of video', $this->ShowSuggestedVideos == 1)));
     if (empty($this->VideoID)) {
         $preview = new LiteralField('YouTubePreviewField', '<p>To preview the video, please save this record with a VideoID (e.g http://youtube.com/<strong>VideoID</strong>) <a href="http://www.google.com/support/youtube/bin/answer.py?answer=171780">example</a></p>');
     } else {
         if ($this->PrivacyEnhancedMode == 1) {
             $host = "www.youtube-nocookie.com";
         } else {
             $host = "www.youtube.com";
         }
         $preview = new LiteralField('YouTubePreviewField', "<div style=\"width:{$this->VideoWidth}px;margin:8px auto;\">" . $this->FlashCode() . "</div>");
     }
     $fields->addFieldToTab('Root.VideoPreview', $preview);
     return $fields;
 }
 protected function MigrateImageGalleryAlbum($id, $gallery)
 {
     try {
         //grab this album
         $album = $this->ImageGalleryAlbum($id);
         if (empty($album['ID'])) {
             throw new Exception("The target album does not exist");
         }
         //grab its items
         $items = $this->ImageGalleryAlbumItems($album['ID']);
         if (empty($gallery->ID)) {
             throw new Exception("I can't migrate an album {$album->AlbumName} into an empty gallery");
         }
         if (empty($gallery->Title)) {
             $gallery->Title = $album['AlbumName'];
         }
         if (empty($gallery->Description)) {
             $gallery->Description = $album['Description'];
         }
         $gallery->Migrated = 1;
         $gallery->write();
         if (!empty($items)) {
             foreach ($items as $item) {
                 //get the source image for this item
                 $image = DataObject::get_by_id('File', $item['ImageID']);
                 if (!empty($image->ID)) {
                     //does the image exist ?
                     $source_filename_path = BASE_PATH . "/" . $image->Filename;
                     $target_filename = $target_filename_path = FALSE;
                     $path_info = pathinfo($source_filename_path);
                     if (!empty($path_info['dirname']) && !empty($path_info['basename'])) {
                         $target_filename = "DA_copy_of_" . $path_info['basename'];
                         $target_filename_path = $path_info['dirname'] . "/" . $target_filename;
                     }
                     //print $source_filename_path . "\n";print $target_filename . "\n";print $target_filename_path . "\n";
                     //we'll make a copy of it so that the old images can be deleted without touching the new files
                     //if the target image exists, assume it's already been migrated and just update the record
                     $migrated_file = FALSE;
                     if (file_exists($target_filename_path)) {
                         $copy = TRUE;
                         //grab the file_id. this is an update
                         $pattern = preg_quote(addslashes(BASE_PATH . "/"));
                         $target_replaced = preg_replace("|^{$pattern}|", "", $target_filename_path);
                         $migrated_file = DataObject::get_one("File", "Filename='" . convert::raw2sql(ltrim($target_replaced, "/")) . "'");
                     } else {
                         if (is_readable($source_filename_path) && is_readable(dirname($target_filename_path)) && !file_exists($target_filename_path) && is_writable(dirname($target_filename_path))) {
                             $copy = copy($source_filename_path, $target_filename_path);
                         }
                     }
                     if ($copy) {
                         $file = new DisplayAnythingFile();
                         $file->Visible = 1;
                         $file->Caption = $item['Caption'];
                         $file->GalleryID = $gallery->ID;
                         $file->Filename = $target_filename_path;
                         $file->ParentID = $image->ParentID;
                         $file->OwnerID = $image->OwnerID;
                         $file->Sort = $image->Sort;
                         $file->Title = $image->Title;
                         if (!empty($migrated_file->ID)) {
                             /**
                              * an update
                              * note if the file already exists on the file system
                              * but not in the DB, a new file will be created
                              */
                             $file->ID = $migrated_file->ID;
                         }
                         //don't set ->Name, crazy crap happens thanks to File::setName(0
                         $file_id = $file->write();
                     }
                 }
             }
         }
     } catch (Exception $e) {
         //failed
     }
 }