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
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) {
69
70
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.
-