Webylon 3.1 API Docs
  • Package
  • Class
  • Tree
  • Deprecated
  • Download
Version: current
  • 3.2
  • 3.1

Packages

  • auth
  • Booking
  • cart
    • shipping
    • steppedcheckout
  • Catalog
  • cms
    • assets
    • batchaction
    • batchactions
    • bulkloading
    • comments
    • content
    • core
    • export
    • newsletter
    • publishers
    • reports
    • security
    • tasks
  • Dashboard
  • DataObjectManager
  • event
  • faq
  • forms
    • actions
    • core
    • fields-basic
    • fields-dataless
    • fields-datetime
    • fields-files
    • fields-formatted
    • fields-formattedinput
    • fields-relational
    • fields-structural
    • transformations
    • validators
  • googlesitemaps
  • guestbook
  • installer
  • newsletter
  • None
  • photo
    • gallery
  • PHP
  • polls
  • recaptcha
  • sapphire
    • api
    • bulkloading
    • control
    • core
    • cron
    • dev
    • email
    • fields-formattedinput
    • filesystem
    • formatters
    • forms
    • i18n
    • integration
    • misc
    • model
    • parsers
    • search
    • security
    • tasks
    • testing
    • tools
    • validation
    • view
    • widgets
  • seo
    • open
      • graph
  • sfDateTimePlugin
  • spamprotection
  • stealth
    • captha
  • subsites
  • userform
    • pagetypes
  • userforms
  • webylon
  • widgets

Classes

  • AssetAdmin
  • AssetTableField
  • FileComplexTableField
  • FileList
  • FilesystemSyncTask
  • ImageEditor
  • ThumbnailStripField
  1 <?php
  2 /**
  3  * Provides a strip of thumbnails showing all of the images in the system.
  4  * It will be tied to a 'parent field' that will provide it with a filter by which to reduce the number
  5  * of thumbnails displayed.
  6  * @package cms
  7  * @subpackage assets
  8  */
  9 class ThumbnailStripField extends FormField {
 10     protected $parentField;
 11     protected $updateMethod;
 12     
 13     function __construct($name, $parentField, $updateMethod = "getimages") {
 14         $this->parentField = $parentField;
 15         $this->updateMethod = $updateMethod;
 16         
 17         parent::__construct($name);
 18     }
 19     
 20     function ParentField() {
 21         return $this->form->FormName() . '_' . $this->parentField;
 22     }
 23     
 24     function FieldHolder() {
 25         Requirements::javascript(CMS_DIR . '/javascript/ThumbnailStripField.js');
 26         return $this->renderWith('ThumbnailStripField');
 27     }
 28     
 29     function UpdateMethod() {
 30         return $this->updateMethod;
 31     }
 32     
 33     /**
 34      * Populate the Thumbnail strip field, by looking for a folder, 
 35      * and the descendants of this folder.
 36      */
 37     function getimages() {
 38         $result = '';
 39         $images = null;
 40         $whereSQL = '';
 41         $folderID = isset($_GET['folderID']) ? (int) $_GET['folderID'] : 0;
 42         $searchText = (isset($_GET['searchText']) && $_GET['searchText'] != 'undefined' && $_GET['searchText'] != 'null') ? Convert::raw2sql($_GET['searchText']) : '';
 43 
 44         $folder = DataObject::get_by_id('Folder', (int) $_GET['folderID']);
 45         
 46         if($folder) {
 47             $folderList = $folder->getDescendantIDList();
 48             array_unshift($folderList, $folder->ID);
 49             $whereSQL .= '"ParentID" IN (' . implode(', ', $folderList) . ') AND "Filename" LIKE \'' . ASSETS_DIR . '%\'';          
 50         } else {
 51             $whereSQL .= '"ParentID" = 0 AND "Filename" LIKE \'' . ASSETS_DIR . '%\'';
 52         }
 53         
 54         if($searchText) {
 55             $whereSQL .= " AND \"Filename\" LIKE '%$searchText%'";
 56         }       
 57         // check for hidden from CMS files
 58         if (singleton('File')->hasDatabaseField('Hidden')) {
 59             $whereSQL .= ' AND "Hidden" = 0';
 60         }
 61         
 62         $images = DataObject::get('Image', $whereSQL, 'Title');
 63         if($images) {
 64             $result .= '<ul>';
 65             foreach($images as $image) {
 66                 $thumbnail = $image->getFormattedImage('StripThumbnail');
 67                 
 68                 if ($thumbnail instanceof Image_Cached) {       //Hack here...
 69                     // Constrain the output image to a 600x600 square.  This is passed to the destwidth/destheight in the class, which are then used to
 70                     // set width & height properties on the <img> tag inserted into the CMS.  Resampling is done after save
 71                     $width = $image->Width;
 72                     $height = $image->Height;
 73                     if($width > 600) {
 74                         $height *= (600 / $width);
 75                         $width = 600;
 76                     }
 77                     if($height > 600) {
 78                         $width *= (600 / $height);
 79                         $height = 600;
 80                     }
 81                     
 82                     $result .= 
 83                         '<li>' .
 84                             '<a href="' . $image->Filename . '?r=' . rand(1,100000) . '" title="' . $image->Title .   '">' .
 85                                 '<img class="destwidth=' . round($width) . ',destheight=' . round($height) . '" src="'. $thumbnail->URL . '?r=' . rand(1,100000) . '" alt="' . $image->Title . '" />' .
 86                             '</a>' .
 87                         '</li>';
 88                 }
 89             }
 90             $result .= '</ul>';
 91         } else {
 92             if($folder) {
 93                 $result = '<h2>' . _t('ThumbnailStripField.NOFOLDERIMAGESFOUND', 'No images found in') . ' ' . $folder->Title . '</h2>';
 94             } else {
 95                 $result = '<h2>' . _t('ThumbnailStripField.NOIMAGESFOUND', 'No images found') . '</h2>';
 96             }
 97         }
 98         
 99         return $result;
100     }
101 
102     function getflash() {
103         $flashObjects = null;
104         $result = '';
105         $whereSQL = '';
106         $folderID = isset($_GET['folderID']) ? (int) $_GET['folderID'] : 0;
107         $searchText = (isset($_GET['searchText']) && $_GET['searchText'] != 'undefined' && $_GET['searchText'] != 'null') ? Convert::raw2sql($_GET['searchText']) : '';
108 
109         $width = Image::$strip_thumbnail_width - 10;
110         $height = Image::$strip_thumbnail_height - 10;
111         
112         $folder = DataObject::get_by_id("Folder", (int) $_GET['folderID']);
113         
114         if($folder) {
115             $folderList = $folder->getDescendantIDList();
116             array_unshift($folderList, $folder->ID);
117             
118             $whereSQL = "\"ParentID\" IN (" . implode(', ', $folderList) . ") AND \"Filename\" LIKE '%.swf'";
119             if($searchText) $whereSQL .= " AND \"Filename\" LIKE '%$searchText%'";
120             
121             $flashObjects = DataObject::get('File', $whereSQL);
122         } else {
123             if($searchText) {
124                 $flashObjects = DataObject::get('File', "\"Filename\" LIKE '%$searchText%' AND \"Filename\" LIKE '%.swf'");
125             }
126         }
127         
128         if($flashObjects) {
129             $result .= '<ul>';
130             foreach($flashObjects as $flashObject) {
131                 $result .= <<<HTML
132 <li>
133 <a href="$flashObject->URL" title="$flashObject->Title">
134     <img src="cms/images/flash_small.jpg" alt="spacer" />
135     <br />
136     $flashObject->Name
137 </a>
138 </li>
139 HTML;
140             }
141             $result .= '</ul>';         
142         } else {
143             if($folder) {
144                 $result = '<h2>' . _t('ThumbnailStripField.NOFOLDERFLASHFOUND', 'No flash files found in') . ' ' . $folder->Title . '</h2>';
145             } else {
146                 $result = '<h2>' . _t('ThumbnailStripField.NOFLASHFOUND', 'No flash files found') . '</h2>';
147             }
148         }
149         
150         return $result;
151     }
152 }
153 
154 ?>
[Raise a SilverStripe Framework issue/bug](https://github.com/silverstripe/silverstripe-framework/issues/new)
- [Raise a SilverStripe CMS issue/bug](https://github.com/silverstripe/silverstripe-cms/issues/new)
- Please use the Silverstripe Forums to ask development related questions. -
Webylon 3.1 API Docs API documentation generated by ApiGen 2.8.0