Guest User

Untitled

a guest
Jul 18th, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 21.40 KB | None | 0 0
  1. <?php
  2. /**
  3. * GalleryPage.php: Sub-class of Page
  4. * @created 15/08/2007
  5. */
  6.  
  7. class GalleryPage extends Page {
  8.  
  9. static $db = array(
  10. 'ThumbnailType' => "Enum( array( 'CroppedResize', 'PaddedResize', 'FittedResize', 'Resize', 'ResizeByWidth', 'ResizeByHeight', 'ResizeRatio' ), 'Resize' )",
  11. 'ThumbnailWidth' => 'Int',
  12. 'ThumbnailHeight' => 'Int',
  13. 'NormalType' => "Enum( array( 'OriginalResize', 'CroppedResize', 'PaddedResize', 'FittedResize', 'Resize', 'ResizeByWidth', 'ResizeByHeight', 'ResizeRatio' ), 'Resize' )",
  14. 'NormalWidth' => 'Int',
  15. 'NormalHeight' => 'Int',
  16. 'MediaPerPageLimit' => 'Boolean',
  17. 'MediaPerPage' => 'Int',
  18. 'MediaPerLine' => 'Int',
  19. 'ShowTitle' => 'Boolean',
  20. 'ShowSize' => 'Boolean',
  21. 'ShowImageDimensions' => 'Boolean',
  22. 'SortBy' => "Enum( array( 'Title', 'UploadDateASC', 'UploadDateDESC' ), 'Title' )"
  23. );
  24.  
  25. static $has_one = array(
  26. 'Folder' => 'Folder',
  27. 'DefaultIcon' => 'Image'
  28. );
  29.  
  30. static $many_many = array(
  31. 'Extensions' => 'GalleryPage_Extension'
  32. );
  33.  
  34. static $defaults = array(
  35. 'ThumbnailType' => 'PaddedResize',
  36. 'ThumbnailWidth' => 90,
  37. 'ThumbnailHeight' => 70,
  38. 'NormalType' => 'Resize',
  39. 'NormalWidth' => 500,
  40. 'NormalHeight' => 500,
  41. 'MediaPerPageLimit' => true,
  42. 'MediaPerPage' => 30,
  43. 'MediaPerLine' => 8
  44. );
  45.  
  46. function onBeforeWrite() {
  47. if( $this->ID ) $this->checkFolder();
  48. parent::onBeforeWrite();
  49. }
  50.  
  51. /**
  52. * If this page doesn't have a folder, create one for us
  53. */
  54. function checkFolder() {
  55. if( ! $this->FolderID ) {
  56. $galleries = Folder::findOrMake('galleries');
  57. $galleries->Title = 'galleries';
  58. $galleries->write();
  59.  
  60. $folder = Folder::findOrMake('galleries/' . $this->URLSegment);
  61. $folder->Title = $this->Title;
  62. $folder->write();
  63.  
  64. $this->FolderID = $folder->ID;
  65. $this->write();
  66. FormResponse::add( "\$( 'Form_EditForm' ).getPageFromServer( $this->ID );" );
  67. }
  68. }
  69.  
  70. function onBeforeDelete() {
  71.  
  72. // Delete The ManyMany Relations
  73.  
  74. $this->Extensions()->removeAll();
  75.  
  76. parent::onBeforeDelete();
  77. }
  78.  
  79. function write() {
  80. if( ! $this->ID ) {
  81. parent::write();
  82. if( $imagesExtension = DataObject::get_one( 'GalleryPage_Extension', "`Title` = 'Images'" ) )
  83. $this->Extensions()->add( $imagesExtension );
  84. else if( $extension = DataObject::get_one( 'GalleryPage_Extension' ) )
  85. $this->Extensions()->add( $extension );
  86. }
  87. else
  88. parent::write();
  89. }
  90.  
  91. public function requireDefaultRecords() {
  92. parent::requireDefaultRecords();
  93.  
  94. $exist = DB::query( "SHOW TABLES LIKE 'FileRepository'" )->numRecords();
  95. if( $exist > 0 ) {
  96. if( DB::query( 'SELECT * FROM `FileRepository`' ) )
  97. DB::query( "UPDATE `GalleryPage`, `FileRepository` SET `GalleryPage`.`FolderID` = `FileRepository`.`FolderID` WHERE `GalleryPage`.`ID` = `FileRepository`.`ID`" );
  98. DB::query( 'RENAME TABLE `FileRepository` TO `_obsolete_FileRepository`' );
  99. echo( "<div style=\"padding:5px; color:white; background-color:blue;\">" . _t('GalleryPage.FILEREPOSITORYTRANSFERRED','The \'FileRepository\' table data content has been transferred successfully. Also, the table has been renamed to \'_obsolete_FileRepository\'.') . "</div>" );
  100. }
  101.  
  102. $exist = DB::query( "SHOW TABLES LIKE 'FileRepository_Live'" )->numRecords();
  103. if( $exist > 0 ) {
  104. if( DB::query( 'SELECT * FROM `FileRepository_Live`' ) )
  105. DB::query( "UPDATE `GalleryPage_Live`, `FileRepository_Live` SET `GalleryPage_Live`.`FolderID` = `FileRepository_Live`.`FolderID` WHERE `GalleryPage_Live`.`ID` = `FileRepository_Live`.`ID`" );
  106. DB::query( 'RENAME TABLE `FileRepository_Live` TO `_obsolete_FileRepository_Live`' );
  107. echo( "<div style=\"padding:5px; color:white; background-color:blue;\">" . _t('GalleryPage.FILEREPOSITORYLIVETRANSFERRED','The \'FileRepository_Live\' table data content has been transferred successfully. Also, the table has been renamed to \'_obsolete_FileRepository_Live\'.') . "</div>" );
  108. }
  109.  
  110. $exist = DB::query( "SHOW TABLES LIKE 'FileRepository_versions'" )->numRecords();
  111. if( $exist > 0 ) {
  112. DB::query( 'DROP TABLE `FileRepository_versions`' );
  113. echo( "<div style=\"padding:5px; color:white; background-color:blue;\">" . _t('GalleryPage.FILEREPOSITORYVERSIONREMOVED','The \'FileRepository_versions\' table has been removed successfully.') . "</div>" );
  114. }
  115. }
  116.  
  117. function getCMSFields( $cms = null) {
  118.  
  119. Requirements::javascript( 'gallery/javascript/GalleryPage_CMS.js' );
  120.  
  121. $fields = parent::getCMSFields( $cms );
  122. $fields->addFieldToTab( 'Root.Content.Gallery', new HeaderField( _t('GalleryPage.GALLERYLAYOUT','Gallery Layout') ) );
  123. $fields->addFieldsToTab( 'Root.Content.Gallery', array(
  124. new CheckboxField( 'MediaPerPageLimit', _t('GalleryPage.MEDIAPERPAGELIMIT','Limit The Number Of Media Files Per Page') ),
  125. new NumericField( 'MediaPerPage', _t('GalleryPage.MEDIAPERPAGE','Media Files Per Page') ),
  126. new NumericField( 'MediaPerLine', _t('GalleryPage.MEDIAPERLINE','Media Files Per Line') ),
  127. new CheckboxField( 'ShowTitle', _t('GalleryPage.SHOWTITLE','Show Media Title')),
  128. new CheckboxField( 'ShowSize', _t('GalleryPage.SHOWSIZE','Show Media Size') ),
  129. new CheckboxField( 'ShowImageDimensions', _t('GalleryPage.SHOWIMAGEDIMENSIONS','Show Media Dimensions') ),
  130. new HeaderField( _t('GalleryPage.IMAGEOPTIONS','Image Options') ),
  131. new DropdownField( 'ThumbnailType', _t('GalleryPage.RESIZINGMETHOD','Resizing Method'), array(
  132. 'CroppedResize' => _t('GalleryPage.CROPPEDRESIZE','Cropped Resize'),
  133. 'PaddedResize' => _t('GalleryPage.PADDEDRESIZE','Padded Resize'),
  134. 'FittedResize' => _t('GalleryPage.FITTEDRESIZE','Fitted Resize'),
  135. 'Resize' => _t('GalleryPage.RESIZE','Resize'),
  136. 'ResizeByWidth' => _t('GalleryPage.RESIZEBYWIDTH','Resize By Width'),
  137. 'ResizeByHeight' => _t('GalleryPage.RESIZEBYHEIGHT','Resize By Height'),
  138. 'ResizeRatio' => _t('GalleryPage.RESIZEBYRATIO','Resize By Ratio')
  139. )),
  140. new NumericField( 'ThumbnailWidth', _t('GalleryPage.IMAGEWIDTH','Image Width') ),
  141. new NumericField( 'ThumbnailHeight', _t('GalleryPage.IMAGEHEIGHT','Image Height') )
  142. ) );
  143. $fields->addFieldToTab( 'Root.Content.Gallery', new HeaderField( _t('GalleryPage.DEFAULTIMAGE','Default Image') ) );
  144. $fields->addFieldToTab( 'Root.Content.Gallery', new ImageField( 'DefaultIcon', '' ) );
  145. $fields->addFieldToTab( 'Root.Content.Popup', new HeaderField( _t('GalleryPage.IMAGEOPTIONS') ) );
  146. $fields->addFieldsToTab( 'Root.Content.Popup', array(
  147. new DropdownField( 'NormalType', _t('GalleryPage.RESIZINGMETHOD'), array(
  148. 'OriginalResize' => _t('GalleryPage.ORIGINALRESIZE','Original Resize'),
  149. 'CroppedResize' => _t('GalleryPage.CROPPEDRESIZE'),
  150. 'PaddedResize' => _t('GalleryPage.PADDEDRESIZE'),
  151. 'FittedResize' => _t('GalleryPage.FITTEDRESIZE'),
  152. 'Resize' => _t('GalleryPage.RESIZE'),
  153. 'ResizeByWidth' => _t('GalleryPage.RESIZEBYWIDTH'),
  154. 'ResizeByHeight' => _t('GalleryPage.RESIZEBYHEIGHT'),
  155. 'ResizeRatio' => _t('GalleryPage.RESIZEBYRATIO')
  156. )),
  157. new NumericField( 'NormalWidth', _t('GalleryPage.IMAGEWIDTH') ),
  158. new NumericField( 'NormalHeight', _t('GalleryPage.IMAGEHEIGHT') )
  159. ));
  160.  
  161. $folder = new TreeDropdownField( 'FolderID', _t('GalleryPage.SHOWFILESFROM','Show The Files From'), 'Folder' );
  162. $folder->setFilterFunction( create_function( '$obj', 'return $obj->class == "Folder";' ) );
  163. $fields->addFieldToTab( 'Root.Content.Files' , $folder );
  164. $fields->addFieldToTab( 'Root.Content.Files' , new OptionsetField(
  165. 'SortBy',
  166. _t('GalleryPage.SORTEDBY','Sorted By'),
  167. array(
  168. 'Title' => _t('GalleryPage.TITLE','Title'),
  169. 'UploadDateASC' => _t('GalleryPage.UPLOADDATEASC','Upload Date Ascending'),
  170. 'UploadDateDESC' => _t('GalleryPage.UPLOADDATEDESC','Upload Date Descending')
  171. )
  172. ) );
  173.  
  174. $extensionsTable = $this->getCMSExtensions();
  175. $fields->addFieldToTab( 'Root.Content.Extensions' , $extensionsTable );
  176.  
  177. return $fields;
  178. }
  179.  
  180. private function getCMSExtensions() {
  181. $tablefield = new ManyManyComplexTableField(
  182. $this,
  183. 'Extensions',
  184. 'GalleryPage_Extension',
  185. array(
  186. 'Title' => _t('GalleryPage.TITLE'),
  187. 'Extensions' => _t('GalleryPage.EXTENSIONS','Extensions')
  188. ),
  189. 'getCMSFields_forPopup'
  190. );
  191. $tablefield->setAddTitle( _t('GalleryPage.ANEXTENSION','An Extension') );
  192. return $tablefield;
  193. }
  194.  
  195. function Items( $limit = "" ) {
  196.  
  197. // TODO Implement this, searching through sub-directories if required to find appropriate files
  198.  
  199. /** Build the list of allowed file extensions **/
  200. if( $this->Extensions()->Count() > 0 ) {
  201. $extensions = '';
  202. foreach( $this->Extensions() as $ext )
  203. $extensions .= str_replace( ' ', '', $ext->Extensions ) . ',';
  204. $extensions = str_replace( ',', '|', substr( $extensions, 0, -1 ) );
  205. if( $this->SortBy == 'Title' )
  206. $sort = "`File`.`Title` ASC";
  207. else if( $this->SortBy == 'UploadDateASC' )
  208. $sort = "`File`.`Created` ASC";
  209. else if( $this->SortBy == 'UploadDateDESC' )
  210. $sort = "`File`.`Created` DESC";
  211. return DataObject::get("File", "`Filename` REGEXP '[.]({$extensions})\$' AND `ParentID` = '{$this->FolderID}'", $sort, "", $limit);
  212. }
  213. else
  214. return null;
  215. }
  216.  
  217. function GalleryItems( $limit ) {
  218.  
  219. /** Get the items from the database **/
  220. $items = $this->Items( $limit );
  221.  
  222. /** For every item that matches the filter... **/
  223. if( $items ) {
  224. $cpt = 0;
  225. foreach( $items as $item ) {
  226. $cpt++;
  227.  
  228. $ext = $item->getExtension();
  229.  
  230. $extensions = $this->Extensions();
  231. foreach( $extensions as $extension ) {
  232. if( ! is_bool( strpos( $extension->Extensions, $ext ) ) ) {
  233. $group = $extension;
  234. break;
  235. }
  236. }
  237.  
  238. if( ! is_bool( strpos( GalleryPage_Extension::$exts[ 'Images' ][ 'Extensions' ], $ext ) ) ) { // ...create/Get the formatted image...
  239. $imgForThumbnail = $item->newClassInstance( "GalleryPage_Image" );
  240.  
  241. $imgForNormal = $item->newClassInstance( 'GalleryPage_Image' );
  242.  
  243. if( $this->NormalType == 'OriginalResize' )
  244. $item->ViewLink = $item->URL;
  245. else {
  246. if( method_exists( $imgForNormal, "generate{$this->NormalType}" ) )
  247. $imgNormal = $imgForNormal->getFormattedImage( $this->NormalType, $this->NormalWidth, $this->NormalHeight );
  248. else // Fall back to the de facto image resize method
  249. $imgNormal = $imgForNormal->getFormattedImage( 'ResizedImage', $this->NormalWidth, $this->NormalHeight );
  250.  
  251. /** If the image was created/got succesfully... **/
  252. if( $imgNormal ) {
  253. /** Add the URL of the formatted image to our object **/
  254. $item->ViewLink = Director::baseURL().$imgNormal->Filename;
  255. }
  256. }
  257.  
  258. $item->HasDimensions = true;
  259. }
  260. else {
  261. $item->ViewLink = $item->URL;
  262.  
  263. if( $group->Type == 'ImagesSoundsVideos' || $group->LimitDimensions ) {
  264. if( $group->Type == 'ImagesSoundsVideos' )
  265. $item->HasDimensions = true;
  266. if( $ext != 'bmp' )
  267. $item->PopupDimensions = true;
  268. if( $item->PopupWidth > 0 && $item->PopupHeight > 0 ) {
  269. $item->Width = $item->PopupWidth;
  270. $item->Height = $item->PopupHeight;
  271. }
  272. else {
  273. $item->Width = $this->NormalWidth;
  274. $item->Height = $this->NormalHeight;
  275. }
  276. }
  277. if( $ext == 'swf' && $item->Embed ) {
  278. $item->PopupEmbed = true;
  279. if( ! $item->LimitDimensions ) {
  280. $item->HasDimensions = false;
  281. $item->PopupDimensions = false;
  282. }
  283. }
  284. $params = array();
  285. if( $item->PopupEmbed )
  286. array_push( $params, 'lightwindow_iframe_embed=true' );
  287. if( $group->Type == 'Documents' || $group->Type == 'WebPages' )
  288. array_push( $params, 'lightwindow_type=external' );
  289. if( $item->PopupDimensions ) {
  290. array_push( $params, 'lightwindow_width=' . $item->Width );
  291. array_push( $params, 'lightwindow_height=' . $item->Height );
  292. }
  293. $params = implode( ',', $params );
  294. foreach( $this->Extensions() as $extension ) {
  295. if( ! is_bool( strpos( $extension->Extensions, $ext ) ) && $extension->GalleryIconID > 0 && $extension->GalleryIcon()->exists() ) {
  296. $imgForThumbnail = $extension->GalleryIcon()->newClassInstance( "GalleryPage_Image" );
  297. break;
  298. }
  299. }
  300. if( ! isset( $imgForThumbnail ) ) {
  301. if( $this->DefaultIconID == 0 || ! $this->DefaultIcon()->exists() ) {
  302. $icon = new Image();
  303. $segment = 'gallery/images/Default.gif';
  304. $absolute = Director::baseFolder() . '/' . $segment;
  305. $icon->loadUploaded( array(
  306. 'name' => 'Default.gif',
  307. 'size' => filesize( $absolute ),
  308. 'tmp_name' => $absolute
  309. )
  310. );
  311. $this->DefaultIconID = $icon->ID;
  312. $this->writeToStage( 'Stage' );
  313. $this->publish( 'Stage', 'Live' );
  314. }
  315. $imgForThumbnail = $this->DefaultIcon()->newClassInstance( "GalleryPage_Image" );
  316. }
  317. }
  318.  
  319. if( method_exists( $imgForThumbnail, "generate{$this->ThumbnailType}" ) )
  320. $imgThumbnail = $imgForThumbnail->getFormattedImage( $this->ThumbnailType, $this->ThumbnailWidth, $this->ThumbnailHeight );
  321. else // Fall back to the de facto image resize method
  322. $imgThumbnail = $imgForThumbnail->getFormattedImage( 'ResizedImage', $this->ThumbnailWidth, $this->ThumbnailHeight );
  323. /** If the image can be created... **/
  324.  
  325. unset( $imgForThumbnail );
  326.  
  327. if( $imgThumbnail ) {
  328. /** ...add the URL of the formatted image to our item... **/
  329. $item->ThumbnailURL = Director::baseURL().$imgThumbnail->Filename;
  330. $item->JSLightWindow = 'lightwindow';
  331. if( ! $item->PopupEmbed && $group->Type != 'Documents' && $group->Type != 'WebPages' )
  332. $item->JSMedia = $this->Title . '[Media]';
  333. if(isset($params)) $item->PopupParams = $params;
  334. /** ..create a link to view the 'Normal' version of the image **/
  335. $item->FirstItemLine = $cpt % $this->MediaPerLine == 1;
  336. $item->LastItemLine = $cpt % $this->MediaPerLine == 0;
  337. $item->ShowTitle = $this->ShowTitle;
  338. $item->ShowSize = $this->ShowSize;
  339. $item->ShowImageDimensions = $this->ShowImageDimensions;
  340. }
  341.  
  342. unset($params);
  343. }
  344. }
  345. /** Return the DataObjectSet we've created above **/
  346. return $items;
  347. }
  348.  
  349. /**
  350. * Get a list of URLs to cache related to this page
  351. */
  352. function subPagesToCache() {
  353. $urls = parent::subPagesToCache();
  354. $urls[] = $this->Link() . 'rss';
  355.  
  356. $pages = $this->GalleryItems($this->MediaPerPage)->Pages();
  357. foreach($pages as $page) {
  358. $urls[] = $page->Link;
  359. }
  360. return $urls;
  361. }
  362. }
  363.  
  364. class GalleryPage_Controller extends Page_Controller {
  365.  
  366. function JSPrevPage() { return "previousPage"; }
  367.  
  368. function JSNextPage() { return "nextPage"; }
  369.  
  370. function init() {
  371. RSSFeed::linkToFeed($this->Link() . "rss", "RSS feed of this gallery");
  372.  
  373. // Javascript Requirements
  374.  
  375. Requirements::javascript( "gallery/javascript/prototype.js" );
  376. Requirements::javascript( "gallery/javascript/effects.js" );
  377. Requirements::javascript( "gallery/javascript/lightwindow.js" );
  378.  
  379. // CSS Requirements
  380.  
  381. Requirements::themedCSS('Gallery');
  382. Requirements::themedCSS('lightwindow');
  383.  
  384. if( $pos = strpos( $_SERVER[ 'HTTP_USER_AGENT' ], 'MSIE' ) ) {
  385. $version = substr( $_SERVER[ 'HTTP_USER_AGENT' ], $pos + 5, 3 );
  386. if( $version < 7 ) {
  387. Requirements::themedCSS('lightwindowIE6');
  388. }
  389. }
  390. parent::init();
  391. }
  392.  
  393. function PrevGalleryItems() {
  394. if( $this->MediaPerPageLimit ) {
  395. if(!$this->paginationStart()) return null;
  396. else {
  397. return $this->GalleryItems( "0, " . $this->paginationStart() );
  398. }
  399. }
  400. else
  401. return null;
  402. }
  403.  
  404. function NextGalleryItems() {
  405. if( $this->MediaPerPageLimit ) {
  406. /** Get the limit **/
  407. $limit = "";
  408. $start = $this->paginationStart() + $this->MediaPerPage;
  409. $fileNumberInFolder = DB::query( "SELECT COUNT(*) FROM File WHERE ParentID = $this->FolderID" )->value();
  410. $limit = $start . "," . $fileNumberInFolder;
  411. return $this->GalleryItems( $limit );
  412. }
  413. else
  414. return null;
  415. }
  416.  
  417. function paginationStart() {
  418. if($this->action == 'page' && is_numeric($this->urlParams['ID'])) return $this->urlParams['ID'];
  419. else return 0;
  420. }
  421.  
  422. function CurrentGalleryItems() {
  423. /** Get the limit **/
  424. $limit = "";
  425. if( $this->MediaPerPageLimit ) {
  426. $limit = $this->paginationStart() . "," . $this->MediaPerPage;
  427. }
  428. return $this->GalleryItems( $limit );
  429. }
  430.  
  431. function rss() {
  432. $rss = new GalleryRSSFeed($this->GalleryItems(""), $this->Link(), "Gallery items", "All items of the '" . $this->obj("Title")->XML() . "' gallery.", "Title", "RSSContent", "Owner");
  433. return $rss->outputToBrowser();
  434. }
  435. }
  436.  
  437. class GalleryPage_Image extends Image {
  438.  
  439. function generateCroppedResize( $gd, $width, $height ) { return $gd->croppedResize( $width, $height ); }
  440. function generatePaddedResize( $gd, $width, $height ) { return $gd->paddedResize( $width, $height ); }
  441. function generateFittedResize( $gd, $width, $height ) { return $gd->fittedResize( $width, $height ); }
  442. function generateResize( $gd, $width, $height ) { return $gd->resize( $width, $height ); }
  443. function generateResizeByWidth( $gd, $width, $height ) { return $gd->resizeByWidth( $width, $height ); }
  444. function generateResizeByHeight( $gd, $width, $height ) { return $gd->resizeByHeight( $width, $height ); }
  445. function generateResizeRatio( $gd, $width, $height ) { return $gd->resizeRatio( $width, $height ); }
  446.  
  447. }
  448.  
  449. class GalleryPage_Extension extends DataObject {
  450.  
  451. public static $exts = array(
  452. 'Images' => array( 'Extensions' => 'png, jpg, jpeg, gif', 'Type' => 'ImagesSoundsVideos'),
  453. 'Sounds' => array( 'Extensions' => 'wav, mp3, ram, m4a, mp4, wma', 'Type' => 'ImagesSoundsVideos'),
  454. 'Videos' => array( 'Extensions' => 'mpg, mpeg, avi, mov, qt, wmv, swf', 'Type' => 'ImagesSoundsVideos'),
  455. 'Pdf Documents' => array( 'Extensions' => 'pdf', 'Type' => 'Documents'),
  456. 'Web Pages' => array( 'Extensions' => 'html', 'Type' => 'WebPages'),
  457. );
  458.  
  459. static $db = array(
  460. 'Title' => 'Text',
  461. 'Extensions' => 'Text',
  462. 'Type' => "Enum( array( 'ImagesSoundsVideos', 'Documents', 'WebPages' ), 'ImagesSoundsVideos' )",
  463. 'LimitDimensions' => 'Boolean'
  464. );
  465.  
  466. static $has_one = array(
  467. 'GalleryIcon' => 'Image'
  468. );
  469.  
  470. static $belongs_many_many = array(
  471. 'Galleries' => 'GalleryPage'
  472. );
  473.  
  474. public function requireDefaultRecords() {
  475. parent::requireDefaultRecords();
  476.  
  477. if( ! $extension = DataObject::get_one( 'GalleryPage_Extension' ) ) {
  478.  
  479. $iconField = 'GalleryIconID';
  480.  
  481. foreach( self::$exts as $t => $e ) {
  482. $extension = new GalleryPage_Extension();
  483. $extension->Title = $t;
  484. $extension->Extensions = $e[ 'Extensions' ];
  485. $extension->Type = $e[ 'Type' ];
  486. $extension->write();
  487.  
  488. $fileName = str_replace( ' ', '_', $t ) . '.gif';
  489. if( Director::fileExists( $segment = 'gallery/images/' . $fileName ) ) {
  490. $icon = new Image();
  491. $absolute = Director::baseFolder() . '/' . $segment;
  492. $icon->loadUploaded( array(
  493. 'name' => $fileName,
  494. 'size' => filesize( $absolute ),
  495. 'tmp_name' => $absolute
  496. )
  497. );
  498. $extension->$iconField = $icon->ID;
  499. $extension->write();
  500. }
  501. }
  502. if( ! Database::$supressOutput ) {
  503. echo "<li style=\"color: orange\">" . _t('GalleryPage.IMAGESEXTENSIONCREATED','Images GalleryPage_Extension Created') . "</li>";
  504. echo "<li style=\"color: orange\">" . _t('GalleryPage.SOUNDSEXTENSIONCREATED','Sounds GalleryPage_Extension Created') . "</li>";
  505. echo "<li style=\"color: orange\">" . _t('GalleryPage.VIDEOSEXTENSIONCREATED','Videos GalleryPage_Extension Created') . "</li>";
  506. echo "<li style=\"color: orange\">" . _t('GalleryPage.PDFEXTENSIONCREATED','Pdf Documents GalleryPage_Extension Created') . "</li>";
  507. echo "<li style=\"color: orange\">" . _t('GalleryPage.WEBEXTENSIONCREATED','Web Pages GalleryPage_Extension Created') . "</li>";
  508. }
  509. }
  510. }
  511.  
  512. function getRequirementsForPopup() {
  513.  
  514. // Javascript Requirement
  515.  
  516. Requirements::javascript( 'gallery/javascript/GalleryPage_Extension_CMS.js' );
  517.  
  518. // CSS Requirement
  519.  
  520. Requirements::customCSS(<<<CSS
  521. .right form #LimitDimensions.checkbox input {
  522. margin: 0 1px;
  523. }
  524. /*.right form #LimitDimensions.checkbox label {
  525. margin-bottom: 4px;
  526. }*/
  527. CSS
  528. );
  529. }
  530.  
  531. function getCMSFields_forPopup() {
  532. $fields = new FieldSet();
  533. $fields->push( new HeaderField( _t('GalleryPage.TITLE') ) );
  534. $fields->push( new TextField( 'Title', '' ) );
  535. $fields->push( new HeaderField( _t('GalleryPage.EXTENSIONS') ) );
  536. $fields->push( new TextareaField( 'Extensions', '', 1 ) );
  537. $fields->push( new HeaderField( _t('GalleryPage.TYPE','Type') ) );
  538. $fields->push( new DropdownField( 'Type', '', array(
  539. 'ImagesSoundsVideos' => _t('GalleryPage.IMAGESSOUNDSVIDEOS','Images, Sounds Or Videos'),
  540. 'Documents' => _t('GalleryPage.DOCUMENTS','Documents'),
  541. 'WebPages' => _t('GalleryPage.WEBPAGES','Web Pages')
  542. )
  543. ) );
  544. $fields->push( new HeaderField( '' ) );
  545. $fields->push( new CheckboxField( 'LimitDimensions', _t('GalleryPage.LIMITDIMENSIONSINPOPUP','Limit The Dimensions In The Popup Window') ) );
  546. $fields->push( new HeaderField( _t('GalleryPage.ICON','Icon') ) );
  547. $fields->push( new ImageField( 'GalleryIcon', '' ) );
  548. return $fields;
  549. }
  550.  
  551. function onBeforeDelete() {
  552.  
  553. // Delete The ManyMany Relations
  554.  
  555. $this->Galleries()->removeAll();
  556.  
  557. parent::onBeforeDelete();
  558. }
  559. }
  560.  
  561. ?>
Add Comment
Please, Sign In to add comment