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

Packages

  • 1c
    • exchange
      • catalog
  • auth
  • Booking
  • building
    • company
  • cart
    • shipping
    • steppedcheckout
  • Catalog
    • monument
  • 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         $images = DataObject::get('Image', $whereSQL, 'Title');
 62         if($images) {
 63             $result .= '<ul>';
 64             foreach($images as $image) {
 65                 $thumbnail = $image->getFormattedImage('StripThumbnail');
 66                 
 67                 if ($thumbnail instanceof Image_Cached) {       //Hack here...
 68                     // Constrain the output image to a 600x600 square.  This is passed to the destwidth/destheight in the class, which are then used to
 69                     // set width & height properties on the <img> tag inserted into the CMS.  Resampling is done after save
 70                     $width = $image->Width;
 71                     $height = $image->Height;
 72                     if($width > 600) {
 73                         $height *= (600 / $width);
 74                         $width = 600;
 75                     }
 76                     if($height > 600) {
 77                         $width *= (600 / $height);
 78                         $height = 600;
 79                     }
 80                     
 81                     $result .= 
 82                         '<li>' .
 83                             '<a href="' . $image->Filename . '?r=' . rand(1,100000) . '" title="' . $image->Title .   '">' .
 84                                 '<img class="destwidth=' . round($width) . ',destheight=' . round($height) . '" src="'. $thumbnail->URL . '?r=' . rand(1,100000) . '" alt="' . $image->Title . '" />' .
 85                             '</a>' .
 86                         '</li>';
 87                 }
 88             }
 89             $result .= '</ul>';
 90         } else {
 91             if($folder) {
 92                 $result = '<h2>' . _t('ThumbnailStripField.NOFOLDERIMAGESFOUND', 'No images found in') . ' ' . $folder->Title . '</h2>';
 93             } else {
 94                 $result = '<h2>' . _t('ThumbnailStripField.NOIMAGESFOUND', 'No images found') . '</h2>';
 95             }
 96         }
 97         
 98         return $result;
 99     }
100 
101     function getflash() {
102         $flashObjects = null;
103         $result = '';
104         $whereSQL = '';
105         $folderID = isset($_GET['folderID']) ? (int) $_GET['folderID'] : 0;
106         $searchText = (isset($_GET['searchText']) && $_GET['searchText'] != 'undefined' && $_GET['searchText'] != 'null') ? Convert::raw2sql($_GET['searchText']) : '';
107 
108         $width = Image::$strip_thumbnail_width - 10;
109         $height = Image::$strip_thumbnail_height - 10;
110         
111         $folder = DataObject::get_by_id("Folder", (int) $_GET['folderID']);
112         
113         if($folder) {
114             $folderList = $folder->getDescendantIDList();
115             array_unshift($folderList, $folder->ID);
116             
117             $whereSQL = "\"ParentID\" IN (" . implode(', ', $folderList) . ") AND \"Filename\" LIKE '%.swf'";
118             if($searchText) $whereSQL .= " AND \"Filename\" LIKE '%$searchText%'";
119             
120             $flashObjects = DataObject::get('File', $whereSQL);
121         } else {
122             if($searchText) {
123                 $flashObjects = DataObject::get('File', "\"Filename\" LIKE '%$searchText%' AND \"Filename\" LIKE '%.swf'");
124             }
125         }
126         
127         if($flashObjects) {
128             $result .= '<ul>';
129             foreach($flashObjects as $flashObject) {
130                 $result .= <<<HTML
131 <li>
132 <a href="$flashObject->URL" title="$flashObject->Title">
133     <img src="cms/images/flash_small.jpg" alt="spacer" />
134     <br />
135     $flashObject->Name
136 </a>
137 </li>
138 HTML;
139             }
140             $result .= '</ul>';         
141         } else {
142             if($folder) {
143                 $result = '<h2>' . _t('ThumbnailStripField.NOFOLDERFLASHFOUND', 'No flash files found in') . ' ' . $folder->Title . '</h2>';
144             } else {
145                 $result = '<h2>' . _t('ThumbnailStripField.NOFLASHFOUND', 'No flash files found') . '</h2>';
146             }
147         }
148         
149         return $result;
150     }
151 }
152 
153 ?>
[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.2 API Docs API documentation generated by ApiGen 2.8.0