Guest User

Untitled

a guest
Jun 19th, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.55 KB | None | 0 0
  1. Index: image_gallery/code/ImageGalleryManager.php
  2. ===================================================================
  3. --- image_gallery/code/ImageGalleryManager.php (revision 511)
  4. +++ image_gallery/code/ImageGalleryManager.php (working copy)
  5. @@ -238,4 +238,4 @@
  6. }
  7.  
  8.  
  9. -?>
  10. \ No newline at end of file
  11. +?>
  12. Index: image_gallery/code/ImageGalleryPage.php
  13. ===================================================================
  14. --- image_gallery/code/ImageGalleryPage.php (revision 511)
  15. +++ image_gallery/code/ImageGalleryPage.php (working copy)
  16. @@ -53,10 +53,10 @@
  17. }
  18.  
  19. function onBeforeWrite() {
  20. - parent::onBeforeWrite();
  21. - if( $this->ID )
  22. - $this->RootFolder()->Title = $this->Title;
  23. - }
  24. + parent::onBeforeWrite();
  25. + if( $this->ID )
  26. + $this->RootFolder()->Title = $this->Title;
  27. + }
  28.  
  29. function onAfterWrite()
  30. {
  31. @@ -70,14 +70,23 @@
  32. $this->RootFolder()->delete();
  33. }
  34. */
  35. +
  36. + function generateRootFolderName() {
  37. + $prefix = Object::has_extension('SiteTree', 'Translatable')?
  38. + str_replace('_', '-', $this->Locale) . '-': '';
  39. + // Combining $this->Link() with the Locale will make name collisions almost
  40. + // impossible, the result is then hashed to ensure that it fits in File->Filename.
  41. + return md5("{$prefix}{$this->Link()}");
  42. + }
  43. +
  44. function checkFolder() {
  45. if( ! $this->RootFolderID ) {
  46. $galleries = Folder::findOrMake('image-gallery');
  47. $galleries->Title = 'Image Gallery';
  48. $galleries->write();
  49. - $folder = Folder::findOrMake('image-gallery/' . $this->URLSegment);
  50. + $folder = Folder::findOrMake("image-gallery/{$this->generateRootFolderName()}");
  51. $folder->Title = $this->Title;
  52. - $folder->setName($this->Title);
  53. + $folder->setName($this->generateRootFolderName());
  54. $folder->write();
  55.  
  56. $this->RootFolderID = $folder->ID;
  57. @@ -87,7 +96,7 @@
  58. FormResponse::add( "\$( 'Form_EditForm' ).getPageFromServer( $this->ID );" );
  59. }
  60. else {
  61. - $this->RootFolder()->setName($this->Title);
  62. + $this->RootFolder()->setName($this->generateRootFolderName());
  63. $this->RootFolder()->write();
  64. }
  65.  
  66. @@ -219,11 +228,11 @@
  67.  
  68. private static function get_default_ui()
  69. {
  70. - $classes = ClassInfo::subclassesFor("ImageGalleryUI");
  71. - foreach($classes as $class) {
  72. - if($class != "ImageGalleryUI") return $class;
  73. - }
  74. - return false;
  75. + $classes = ClassInfo::subclassesFor("ImageGalleryUI");
  76. + foreach($classes as $class) {
  77. + if($class != "ImageGalleryUI") return $class;
  78. + }
  79. + return false;
  80. }
  81.  
  82. public function GalleryUI()
  83. @@ -266,7 +275,7 @@
  84.  
  85. if($items === null)
  86. $items = $this->Items($limit);
  87. - $this->includeUI();
  88. + $this->includeUI();
  89. if( $items ) {
  90. foreach( $items as $item ) {
  91. if($this->Square)
  92. @@ -287,7 +296,7 @@
  93. $item->setUI($this->UI);
  94. }
  95. }
  96. - return $this->UI->updateItems($items);
  97. + return $this->UI->updateItems($items);
  98. }
  99. return false;
  100. }
  101. @@ -333,43 +342,42 @@
  102.  
  103. public function init()
  104. {
  105. -
  106. parent::init();
  107. Requirements::themedCSS('ImageGallery');
  108. }
  109.  
  110. public function index()
  111. {
  112. - if($this->SingleAlbumView())
  113. - return $this->renderWith(array($this->getModelClass().'_album','Page'));
  114. - return $this->renderWith(array('ImageGalleryPage','Page'));
  115. + if($this->SingleAlbumView())
  116. + return $this->renderWith(array($this->getModelClass().'_album','Page'));
  117. + return $this->renderWith(array('ImageGalleryPage','Page'));
  118. }
  119.  
  120. private function getModelClass()
  121. {
  122. - return str_replace("_Controller","",$this->class);
  123. + return str_replace("_Controller","",$this->class);
  124. }
  125.  
  126. private function getModel()
  127. {
  128. - return DataObject::get_by_id($this->getModelClass(),$this->ID);
  129. + return DataObject::get_by_id($this->getModelClass(),$this->ID);
  130. }
  131.  
  132.  
  133. protected function adjacentAlbum($dir)
  134. - {
  135. - $t = $dir == "next" ? ">" : "<";
  136. - $sort = $dir == "next" ? "ASC" : "DESC";
  137. - return DataObject::get_one(
  138. - $this->albumClass,
  139. - "ImageGalleryPageID = {$this->ID} AND SortOrder $t {$this->CurrentAlbum()->SortOrder}",
  140. - false,
  141. - "SortOrder $sort"
  142. - );
  143. - }
  144. -
  145. - public function NextAlbum()
  146. {
  147. + $t = $dir == "next" ? ">" : "<";
  148. + $sort = $dir == "next" ? "ASC" : "DESC";
  149. + return DataObject::get_one(
  150. + $this->albumClass,
  151. + "ImageGalleryPageID = {$this->ID} AND SortOrder $t {$this->CurrentAlbum()->SortOrder}",
  152. + false,
  153. + "SortOrder $sort"
  154. + );
  155. + }
  156. +
  157. + public function NextAlbum()
  158. + {
  159. return $this->adjacentAlbum("next");
  160. }
  161.  
  162. @@ -391,4 +399,4 @@
  163.  
  164. }
  165.  
  166. -?>
  167. \ No newline at end of file
  168. +?>
  169. Index: image_gallery/code/ImageGalleryItem.php
  170. ===================================================================
  171. --- image_gallery/code/ImageGalleryItem.php (revision 511)
  172. +++ image_gallery/code/ImageGalleryItem.php (working copy)
  173. @@ -38,11 +38,19 @@
  174. {
  175. parent::onBeforeWrite();
  176.  
  177. - if($image = $this->Image()) {
  178. + $image = $this->Image();
  179. + if($image->ID) {
  180. if(isset($_POST['AlbumID']) && $album = DataObject::get_by_id("ImageGalleryAlbum", $_POST['AlbumID'])) {
  181. $image->setField("ParentID",$album->FolderID);
  182. $image->write();
  183. }
  184. + } else if(!$image->ID && $this->ImageID) {
  185. + // Image is not a valid ImageGalleryImage, but we have an ImageID, if that
  186. + // ImageID references a real image we should change it into an ImageGalleryImage.
  187. + if ($image = DataObject::get_by_id('Image', $this->ImageID)) {
  188. + $image = $image->newClassInstance('ImageGalleryImage');
  189. + $image->write();
  190. + }
  191. }
  192. }
  193.  
  194. @@ -88,4 +96,4 @@
  195. {
  196. return Permission::check(self::$delete_permission);
  197. }
  198. -}
  199. \ No newline at end of file
  200. +}
Add Comment
Please, Sign In to add comment