1 <?php
2 3 4 5 6 7 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 35 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
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) {
68
69
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.
-