Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Index: image_gallery/code/ImageGalleryManager.php
- ===================================================================
- --- image_gallery/code/ImageGalleryManager.php (revision 511)
- +++ image_gallery/code/ImageGalleryManager.php (working copy)
- @@ -238,4 +238,4 @@
- }
- -?>
- \ No newline at end of file
- +?>
- Index: image_gallery/code/ImageGalleryPage.php
- ===================================================================
- --- image_gallery/code/ImageGalleryPage.php (revision 511)
- +++ image_gallery/code/ImageGalleryPage.php (working copy)
- @@ -53,10 +53,10 @@
- }
- function onBeforeWrite() {
- - parent::onBeforeWrite();
- - if( $this->ID )
- - $this->RootFolder()->Title = $this->Title;
- - }
- + parent::onBeforeWrite();
- + if( $this->ID )
- + $this->RootFolder()->Title = $this->Title;
- + }
- function onAfterWrite()
- {
- @@ -70,14 +70,23 @@
- $this->RootFolder()->delete();
- }
- */
- +
- + function generateRootFolderName() {
- + $prefix = Object::has_extension('SiteTree', 'Translatable')?
- + str_replace('_', '-', $this->Locale) . '-': '';
- + // Combining $this->Link() with the Locale will make name collisions almost
- + // impossible, the result is then hashed to ensure that it fits in File->Filename.
- + return md5("{$prefix}{$this->Link()}");
- + }
- +
- function checkFolder() {
- if( ! $this->RootFolderID ) {
- $galleries = Folder::findOrMake('image-gallery');
- $galleries->Title = 'Image Gallery';
- $galleries->write();
- - $folder = Folder::findOrMake('image-gallery/' . $this->URLSegment);
- + $folder = Folder::findOrMake("image-gallery/{$this->generateRootFolderName()}");
- $folder->Title = $this->Title;
- - $folder->setName($this->Title);
- + $folder->setName($this->generateRootFolderName());
- $folder->write();
- $this->RootFolderID = $folder->ID;
- @@ -87,7 +96,7 @@
- FormResponse::add( "\$( 'Form_EditForm' ).getPageFromServer( $this->ID );" );
- }
- else {
- - $this->RootFolder()->setName($this->Title);
- + $this->RootFolder()->setName($this->generateRootFolderName());
- $this->RootFolder()->write();
- }
- @@ -219,11 +228,11 @@
- private static function get_default_ui()
- {
- - $classes = ClassInfo::subclassesFor("ImageGalleryUI");
- - foreach($classes as $class) {
- - if($class != "ImageGalleryUI") return $class;
- - }
- - return false;
- + $classes = ClassInfo::subclassesFor("ImageGalleryUI");
- + foreach($classes as $class) {
- + if($class != "ImageGalleryUI") return $class;
- + }
- + return false;
- }
- public function GalleryUI()
- @@ -266,7 +275,7 @@
- if($items === null)
- $items = $this->Items($limit);
- - $this->includeUI();
- + $this->includeUI();
- if( $items ) {
- foreach( $items as $item ) {
- if($this->Square)
- @@ -287,7 +296,7 @@
- $item->setUI($this->UI);
- }
- }
- - return $this->UI->updateItems($items);
- + return $this->UI->updateItems($items);
- }
- return false;
- }
- @@ -333,43 +342,42 @@
- public function init()
- {
- -
- parent::init();
- Requirements::themedCSS('ImageGallery');
- }
- public function index()
- {
- - if($this->SingleAlbumView())
- - return $this->renderWith(array($this->getModelClass().'_album','Page'));
- - return $this->renderWith(array('ImageGalleryPage','Page'));
- + if($this->SingleAlbumView())
- + return $this->renderWith(array($this->getModelClass().'_album','Page'));
- + return $this->renderWith(array('ImageGalleryPage','Page'));
- }
- private function getModelClass()
- {
- - return str_replace("_Controller","",$this->class);
- + return str_replace("_Controller","",$this->class);
- }
- private function getModel()
- {
- - return DataObject::get_by_id($this->getModelClass(),$this->ID);
- + return DataObject::get_by_id($this->getModelClass(),$this->ID);
- }
- protected function adjacentAlbum($dir)
- - {
- - $t = $dir == "next" ? ">" : "<";
- - $sort = $dir == "next" ? "ASC" : "DESC";
- - return DataObject::get_one(
- - $this->albumClass,
- - "ImageGalleryPageID = {$this->ID} AND SortOrder $t {$this->CurrentAlbum()->SortOrder}",
- - false,
- - "SortOrder $sort"
- - );
- - }
- -
- - public function NextAlbum()
- {
- + $t = $dir == "next" ? ">" : "<";
- + $sort = $dir == "next" ? "ASC" : "DESC";
- + return DataObject::get_one(
- + $this->albumClass,
- + "ImageGalleryPageID = {$this->ID} AND SortOrder $t {$this->CurrentAlbum()->SortOrder}",
- + false,
- + "SortOrder $sort"
- + );
- + }
- +
- + public function NextAlbum()
- + {
- return $this->adjacentAlbum("next");
- }
- @@ -391,4 +399,4 @@
- }
- -?>
- \ No newline at end of file
- +?>
- Index: image_gallery/code/ImageGalleryItem.php
- ===================================================================
- --- image_gallery/code/ImageGalleryItem.php (revision 511)
- +++ image_gallery/code/ImageGalleryItem.php (working copy)
- @@ -38,11 +38,19 @@
- {
- parent::onBeforeWrite();
- - if($image = $this->Image()) {
- + $image = $this->Image();
- + if($image->ID) {
- if(isset($_POST['AlbumID']) && $album = DataObject::get_by_id("ImageGalleryAlbum", $_POST['AlbumID'])) {
- $image->setField("ParentID",$album->FolderID);
- $image->write();
- }
- + } else if(!$image->ID && $this->ImageID) {
- + // Image is not a valid ImageGalleryImage, but we have an ImageID, if that
- + // ImageID references a real image we should change it into an ImageGalleryImage.
- + if ($image = DataObject::get_by_id('Image', $this->ImageID)) {
- + $image = $image->newClassInstance('ImageGalleryImage');
- + $image->write();
- + }
- }
- }
- @@ -88,4 +96,4 @@
- {
- return Permission::check(self::$delete_permission);
- }
- -}
- \ No newline at end of file
- +}
Add Comment
Please, Sign In to add comment