2007-07-19 12:40:05 +02:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Provides a strip of thumbnails showing all of the images in the system.
|
|
|
|
* It will be tied to a 'parent field' that will provide it with a filter by which to reduce the number
|
|
|
|
* of thumbnails displayed.
|
2008-02-25 03:10:37 +01:00
|
|
|
* @package cms
|
|
|
|
* @subpackage assets
|
2007-07-19 12:40:05 +02:00
|
|
|
*/
|
|
|
|
class ThumbnailStripField extends FormField {
|
|
|
|
protected $parentField;
|
|
|
|
protected $updateMethod;
|
2010-10-15 04:36:33 +02:00
|
|
|
|
2010-10-15 04:36:40 +02:00
|
|
|
/**
|
|
|
|
* If this is enabled, then ommitting a folderID when calling getimages will search ALL folders.
|
|
|
|
* This is the legacy behaviour.
|
|
|
|
*
|
|
|
|
* The new behaviour is to only search the root folder if a folderID is ommitted.
|
|
|
|
*
|
|
|
|
* @var boolean
|
|
|
|
*/
|
2010-10-15 04:36:33 +02:00
|
|
|
protected static $use_legacy_image_search = false;
|
|
|
|
|
2010-10-15 04:36:40 +02:00
|
|
|
/**
|
|
|
|
* setter for ThumbnailStripField::use_legacy_image_search
|
|
|
|
* @param boolean $enable
|
|
|
|
*/
|
2010-10-15 04:36:33 +02:00
|
|
|
public static function set_use_legacy_image_search($enable) {
|
|
|
|
self::$use_legacy_image_search = $enable;
|
|
|
|
}
|
2010-10-15 04:36:40 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* getter for ThumbnailStripField::use_legacy_image_search
|
|
|
|
* @return boolean
|
|
|
|
*/
|
2010-10-15 04:36:33 +02:00
|
|
|
public static function get_use_legacy_image_search() {
|
|
|
|
return self::$use_legacy_image_search;
|
|
|
|
}
|
2007-07-19 12:40:05 +02:00
|
|
|
|
|
|
|
function __construct($name, $parentField, $updateMethod = "getimages") {
|
|
|
|
$this->parentField = $parentField;
|
|
|
|
$this->updateMethod = $updateMethod;
|
|
|
|
|
|
|
|
parent::__construct($name);
|
|
|
|
}
|
|
|
|
|
|
|
|
function ParentField() {
|
|
|
|
return $this->form->FormName() . '_' . $this->parentField;
|
|
|
|
}
|
|
|
|
|
|
|
|
function FieldHolder() {
|
2010-06-03 02:08:33 +02:00
|
|
|
Requirements::javascript(THIRDPARTY_DIR . '/prototype/prototype.js');
|
|
|
|
Requirements::javascript(THIRDPARTY_DIR . '/behaviour/behaviour.js');
|
|
|
|
Requirements::javascript(SAPPHIRE_DIR . '/javascript/prototype_improvements.js');
|
ENHANCEMENT Introduced constants for system paths like /sapphire in preparation for a more flexible directory reorganisation. Instead of hardcoding your path, please use the following constants: BASE_PATH, BASE_URL, SAPPHIRE_DIR, SAPPHIRE_PATH, CMS_DIR, CMS_PATH, THIRDPARTY_DIR, THIRDPARTY_PATH, ASSETS_DIR, ASSETS_PATH, THEMES_DIR, THEMES_PATH
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/cms/trunk@63175 467b73ca-7a2a-4603-9d3b-597d59a354a9
2008-09-28 15:12:20 +02:00
|
|
|
Requirements::javascript(CMS_DIR . '/javascript/ThumbnailStripField.js');
|
2007-07-19 12:40:05 +02:00
|
|
|
return $this->renderWith('ThumbnailStripField');
|
|
|
|
}
|
|
|
|
|
|
|
|
function UpdateMethod() {
|
|
|
|
return $this->updateMethod;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Populate the Thumbnail strip field, by looking for a folder,
|
|
|
|
* and the descendants of this folder.
|
2010-10-15 04:36:40 +02:00
|
|
|
*
|
|
|
|
* @see ThumbnailStripField::use_legacy_image_search
|
2007-07-19 12:40:05 +02:00
|
|
|
*/
|
|
|
|
function getimages() {
|
|
|
|
$result = '';
|
2008-11-13 05:55:23 +01:00
|
|
|
$images = null;
|
|
|
|
$whereSQL = '';
|
|
|
|
$folderID = isset($_GET['folderID']) ? (int) $_GET['folderID'] : 0;
|
|
|
|
$searchText = (isset($_GET['searchText']) && $_GET['searchText'] != 'undefined' && $_GET['searchText'] != 'null') ? Convert::raw2sql($_GET['searchText']) : '';
|
2008-11-07 04:05:43 +01:00
|
|
|
|
2008-11-13 05:55:23 +01:00
|
|
|
$folder = DataObject::get_by_id('Folder', (int) $_GET['folderID']);
|
2008-11-07 04:05:43 +01:00
|
|
|
|
2008-11-13 05:55:23 +01:00
|
|
|
if($folder) {
|
2010-05-28 04:37:58 +02:00
|
|
|
$folderList = $folder->getDescendantIDList();
|
2008-11-13 05:55:23 +01:00
|
|
|
array_unshift($folderList, $folder->ID);
|
|
|
|
|
2008-11-24 10:30:41 +01:00
|
|
|
$whereSQL = '"ParentID" IN (' . implode(', ', $folderList) . ')';
|
|
|
|
if($searchText) $whereSQL .= " AND \"Filename\" LIKE '%$searchText%'";
|
2008-11-13 05:55:23 +01:00
|
|
|
$images = DataObject::get('Image', $whereSQL, 'Title');
|
2007-07-19 12:40:05 +02:00
|
|
|
|
2008-11-13 05:55:23 +01:00
|
|
|
} else {
|
2010-10-15 04:36:33 +02:00
|
|
|
if (!self::$use_legacy_image_search) {
|
2010-10-15 04:36:47 +02:00
|
|
|
$whereSQL = "\"ParentID\" = 0";
|
2010-10-15 04:36:33 +02:00
|
|
|
} else {
|
|
|
|
$whereSQL = '';
|
2010-10-15 05:27:38 +02:00
|
|
|
|
|
|
|
// Prevent image search queries all images in the site initially when the page is loaded
|
|
|
|
if(empty($searchText)) $whereSQL = "\"ParentID\" = 0";
|
2010-10-15 04:36:33 +02:00
|
|
|
}
|
2010-10-15 04:36:47 +02:00
|
|
|
|
2008-11-13 05:55:23 +01:00
|
|
|
if($searchText) {
|
2010-10-15 04:36:47 +02:00
|
|
|
if (!empty($whereSQL)) $whereSQL .= " AND";
|
2010-10-15 04:36:33 +02:00
|
|
|
$whereSQL .= " \"Filename\" LIKE '%$searchText%'";
|
2008-11-13 05:55:23 +01:00
|
|
|
}
|
2010-04-14 00:20:10 +02:00
|
|
|
|
|
|
|
$images = DataObject::get('Image', $whereSQL, 'Title');
|
2008-11-13 05:55:23 +01:00
|
|
|
}
|
2007-07-19 12:40:05 +02:00
|
|
|
|
|
|
|
if($images) {
|
|
|
|
$result .= '<ul>';
|
|
|
|
foreach($images as $image) {
|
|
|
|
$thumbnail = $image->getFormattedImage('StripThumbnail');
|
|
|
|
|
2009-02-03 04:56:56 +01:00
|
|
|
if ($thumbnail instanceof Image_Cached) { //Hack here...
|
|
|
|
// Constrain the output image to a 600x600 square. This is passed to the destwidth/destheight in the class, which are then used to
|
|
|
|
// set width & height properties on the <img> tag inserted into the CMS. Resampling is done after save
|
|
|
|
$width = $image->Width;
|
|
|
|
$height = $image->Height;
|
|
|
|
if($width > 600) {
|
|
|
|
$height *= (600 / $width);
|
|
|
|
$width = 600;
|
|
|
|
}
|
|
|
|
if($height > 600) {
|
|
|
|
$width *= (600 / $height);
|
|
|
|
$height = 600;
|
|
|
|
}
|
|
|
|
|
|
|
|
$result .=
|
|
|
|
'<li>' .
|
|
|
|
'<a href="' . $image->Filename . '?r=' . rand(1,100000) . '" title="' . $image->Title . '">' .
|
|
|
|
'<img class="destwidth=' . round($width) . ',destheight=' . round($height) . '" src="'. $thumbnail->URL . '?r=' . rand(1,100000) . '" alt="' . $image->Title . '" />' .
|
|
|
|
'</a>' .
|
|
|
|
'</li>';
|
2007-07-19 12:40:05 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
$result .= '</ul>';
|
2010-10-15 05:27:38 +02:00
|
|
|
}
|
|
|
|
else {
|
2008-11-13 05:55:23 +01:00
|
|
|
if($folder) {
|
|
|
|
$result = '<h2>' . _t('ThumbnailStripField.NOFOLDERIMAGESFOUND', 'No images found in') . ' ' . $folder->Title . '</h2>';
|
|
|
|
} else {
|
|
|
|
$result = '<h2>' . _t('ThumbnailStripField.NOIMAGESFOUND', 'No images found') . '</h2>';
|
|
|
|
}
|
2007-07-19 12:40:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return $result;
|
|
|
|
}
|
|
|
|
|
|
|
|
function getflash() {
|
2008-11-13 05:55:23 +01:00
|
|
|
$flashObjects = null;
|
|
|
|
$result = '';
|
|
|
|
$whereSQL = '';
|
|
|
|
$folderID = isset($_GET['folderID']) ? (int) $_GET['folderID'] : 0;
|
|
|
|
$searchText = (isset($_GET['searchText']) && $_GET['searchText'] != 'undefined' && $_GET['searchText'] != 'null') ? Convert::raw2sql($_GET['searchText']) : '';
|
2007-07-19 12:40:05 +02:00
|
|
|
|
|
|
|
$width = Image::$strip_thumbnail_width - 10;
|
|
|
|
$height = Image::$strip_thumbnail_height - 10;
|
|
|
|
|
2008-11-13 05:55:23 +01:00
|
|
|
$folder = DataObject::get_by_id("Folder", (int) $_GET['folderID']);
|
|
|
|
|
|
|
|
if($folder) {
|
2010-05-28 04:38:05 +02:00
|
|
|
$folderList = $folder->getDescendantIDList();
|
2008-11-13 05:55:23 +01:00
|
|
|
array_unshift($folderList, $folder->ID);
|
|
|
|
|
2008-11-24 10:30:41 +01:00
|
|
|
$whereSQL = "\"ParentID\" IN (" . implode(', ', $folderList) . ") AND \"Filename\" LIKE '%.swf'";
|
|
|
|
if($searchText) $whereSQL .= " AND \"Filename\" LIKE '%$searchText%'";
|
2008-11-13 05:55:23 +01:00
|
|
|
|
|
|
|
$flashObjects = DataObject::get('File', $whereSQL);
|
|
|
|
} else {
|
|
|
|
if($searchText) {
|
2008-11-24 10:30:41 +01:00
|
|
|
$flashObjects = DataObject::get('File', "\"Filename\" LIKE '%$searchText%' AND \"Filename\" LIKE '%.swf'");
|
2008-11-13 05:55:23 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-07-19 12:40:05 +02:00
|
|
|
if($flashObjects) {
|
|
|
|
$result .= '<ul>';
|
|
|
|
foreach($flashObjects as $flashObject) {
|
|
|
|
$result .= <<<HTML
|
|
|
|
<li>
|
2008-11-16 22:41:02 +01:00
|
|
|
<a href="$flashObject->URL" title="$flashObject->Title">
|
2007-11-08 03:08:50 +01:00
|
|
|
<img src="cms/images/flash_small.jpg" alt="spacer" />
|
2007-07-19 12:40:05 +02:00
|
|
|
<br />
|
|
|
|
$flashObject->Name
|
|
|
|
</a>
|
|
|
|
</li>
|
|
|
|
HTML;
|
|
|
|
}
|
|
|
|
$result .= '</ul>';
|
2008-11-13 06:37:10 +01:00
|
|
|
} else {
|
|
|
|
if($folder) {
|
|
|
|
$result = '<h2>' . _t('ThumbnailStripField.NOFOLDERFLASHFOUND', 'No flash files found in') . ' ' . $folder->Title . '</h2>';
|
|
|
|
} else {
|
|
|
|
$result = '<h2>' . _t('ThumbnailStripField.NOFLASHFOUND', 'No flash files found') . '</h2>';
|
|
|
|
}
|
2007-07-19 12:40:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return $result;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|