2007-07-19 12:40:28 +02:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Represents an image attached to a page.
|
2008-02-25 03:10:37 +01:00
|
|
|
* @package sapphire
|
|
|
|
* @subpackage filesystem
|
2007-07-19 12:40:28 +02:00
|
|
|
*/
|
|
|
|
class Image extends File {
|
2008-05-10 04:21:26 +02:00
|
|
|
|
2009-01-08 23:33:56 +01:00
|
|
|
const ORIENTATION_SQUARE = 0;
|
|
|
|
const ORIENTATION_PORTRAIT = 1;
|
|
|
|
const ORIENTATION_LANDSCAPE = 2;
|
|
|
|
|
2008-05-10 04:21:26 +02:00
|
|
|
static $casting = array(
|
|
|
|
'Tag' => 'HTMLText',
|
|
|
|
);
|
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
/**
|
|
|
|
* The width of an image thumbnail in a strip.
|
|
|
|
* @var int
|
|
|
|
*/
|
|
|
|
public static $strip_thumbnail_width = 50;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The height of an image thumbnail in a strip.
|
|
|
|
* @var int
|
|
|
|
*/
|
|
|
|
public static $strip_thumbnail_height = 50;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The width of an image thumbnail in the CMS.
|
|
|
|
* @var int
|
|
|
|
*/
|
|
|
|
public static $cms_thumbnail_width = 100;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The height of an image thumbnail in the CMS.
|
|
|
|
*/
|
|
|
|
public static $cms_thumbnail_height = 100;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The width of an image thumbnail in the Asset section.
|
|
|
|
*/
|
|
|
|
public static $asset_thumbnail_width = 100;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The height of an image thumbnail in the Asset section.
|
|
|
|
*/
|
|
|
|
public static $asset_thumbnail_height = 100;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The width of an image preview in the Asset section.
|
|
|
|
*/
|
|
|
|
public static $asset_preview_width = 400;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The height of an image preview in the Asset section.
|
|
|
|
*/
|
|
|
|
public static $asset_preview_height = 200;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set up template methods to access the transformations generated by 'generate' methods.
|
|
|
|
*/
|
|
|
|
public function defineMethods() {
|
|
|
|
$methodNames = $this->allMethodNames();
|
|
|
|
foreach($methodNames as $methodName) {
|
|
|
|
if(substr($methodName,0,8) == 'generate') {
|
|
|
|
$this->addWrapperMethod(substr($methodName,8), 'getFormattedImage');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
parent::defineMethods();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* An image exists if it has a filename.
|
|
|
|
* @return boolean
|
|
|
|
*/
|
|
|
|
public function exists() {
|
|
|
|
if(isset($this->record["Filename"])) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2008-03-18 00:50:18 +01:00
|
|
|
* Get the relative URL for this Image.
|
|
|
|
* Overwrites File->URL() which returns an absolute URL.
|
|
|
|
*
|
|
|
|
* @todo Refactor to return absolute URL like {@link File}
|
|
|
|
* @uses Director::baseURL()
|
|
|
|
* @return string
|
2007-07-19 12:40:28 +02:00
|
|
|
*/
|
2008-03-18 00:50:18 +01:00
|
|
|
function getURL() {
|
2007-07-19 12:40:28 +02:00
|
|
|
return Director::baseURL() . $this->Filename;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return an XHTML img tag for this Image.
|
|
|
|
* @return string
|
|
|
|
*/
|
2008-05-10 04:21:26 +02:00
|
|
|
function getTag() {
|
2009-10-08 00:03:53 +02:00
|
|
|
if(file_exists($this->FullPath)) {
|
2007-07-19 12:40:28 +02:00
|
|
|
$url = $this->URL();
|
2009-04-06 05:23:44 +02:00
|
|
|
$title = ($this->Title) ? $this->Title : $this->Filename;
|
2009-05-12 06:00:32 +02:00
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
return "<img src=\"$url\" alt=\"$title\" />";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return an XHTML img tag for this Image.
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
function forTemplate() {
|
|
|
|
return $this->Tag();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Load a recently uploaded image into this image field.
|
|
|
|
* @param array $tmpFile The array entry from $_FILES
|
|
|
|
* @return boolean Returns true if successful
|
|
|
|
*/
|
|
|
|
function loadUploaded($tmpFile) {
|
2008-04-06 06:09:02 +02:00
|
|
|
if(parent::loadUploaded($tmpFile) === true) {
|
2007-07-19 12:40:28 +02:00
|
|
|
$this->deleteFormattedImages();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function loadUploadedImage($tmpFile) {
|
|
|
|
if(!is_array($tmpFile)) {
|
|
|
|
user_error("Image::loadUploadedImage() Not passed an array. Most likely, the form hasn't got the right enctype", E_USER_ERROR);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!$tmpFile['size']) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
$class = $this->class;
|
|
|
|
|
|
|
|
// Create a folder
|
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/sapphire/trunk@63154 467b73ca-7a2a-4603-9d3b-597d59a354a9
2008-09-27 18:02:38 +02:00
|
|
|
if(!file_exists(ASSETS_PATH)) {
|
|
|
|
mkdir(ASSETS_PATH, Filesystem::$folder_create_mask);
|
2007-07-19 12:40:28 +02:00
|
|
|
}
|
|
|
|
|
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/sapphire/trunk@63154 467b73ca-7a2a-4603-9d3b-597d59a354a9
2008-09-27 18:02:38 +02:00
|
|
|
if(!file_exists(ASSETS_PATH . "/$class")) {
|
|
|
|
mkdir(ASSETS_PATH . "/$class", Filesystem::$folder_create_mask);
|
2007-07-19 12:40:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Generate default filename
|
|
|
|
$file = str_replace(' ', '-',$tmpFile['name']);
|
|
|
|
$file = ereg_replace('[^A-Za-z0-9+.-]+','',$file);
|
|
|
|
$file = ereg_replace('-+', '-',$file);
|
|
|
|
if(!$file) {
|
|
|
|
$file = "file.jpg";
|
|
|
|
}
|
|
|
|
|
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/sapphire/trunk@63154 467b73ca-7a2a-4603-9d3b-597d59a354a9
2008-09-27 18:02:38 +02:00
|
|
|
$file = ASSETS_PATH . "/$class/$file";
|
2007-07-19 12:40:28 +02:00
|
|
|
|
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/sapphire/trunk@63154 467b73ca-7a2a-4603-9d3b-597d59a354a9
2008-09-27 18:02:38 +02:00
|
|
|
while(file_exists(BASE_PATH . "/$file")) {
|
2007-07-19 12:40:28 +02:00
|
|
|
$i = $i ? ($i+1) : 2;
|
|
|
|
$oldFile = $file;
|
|
|
|
$file = ereg_replace('[0-9]*(\.[^.]+$)',$i . '\\1', $file);
|
|
|
|
if($oldFile == $file && $i > 2) user_error("Couldn't fix $file with $i", E_USER_ERROR);
|
|
|
|
}
|
|
|
|
|
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/sapphire/trunk@63154 467b73ca-7a2a-4603-9d3b-597d59a354a9
2008-09-27 18:02:38 +02:00
|
|
|
if(file_exists($tmpFile['tmp_name']) && copy($tmpFile['tmp_name'], BASE_PATH . "/$file")) {
|
2007-07-19 12:40:28 +02:00
|
|
|
// Remove the old images
|
|
|
|
|
|
|
|
$this->deleteFormattedImages();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function SetWidth($width) {
|
|
|
|
return $this->getFormattedImage('SetWidth', $width);
|
|
|
|
}
|
|
|
|
|
2008-08-22 05:03:57 +02:00
|
|
|
public function SetHeight($height) {
|
2008-08-22 05:05:28 +02:00
|
|
|
return $this->getFormattedImage('SetHeight', $height);
|
2008-08-22 05:03:57 +02:00
|
|
|
}
|
|
|
|
|
2008-08-22 05:03:20 +02:00
|
|
|
public function SetSize($width, $height) {
|
|
|
|
return $this->getFormattedImage('SetSize', $width, $height);
|
|
|
|
}
|
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
/**
|
|
|
|
* Resize this Image by width, keeping aspect ratio. Use in templates with $SetWidth.
|
|
|
|
* @return GD
|
|
|
|
*/
|
|
|
|
public function generateSetWidth(GD $gd, $width) {
|
|
|
|
return $gd->resizeByWidth($width);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Resize this Image by height, keeping aspect ratio. Use in templates with $SetHeight.
|
|
|
|
* @return GD
|
|
|
|
*/
|
|
|
|
public function generateSetHeight(GD $gd, $height){
|
|
|
|
return $gd->resizeByHeight($height);
|
|
|
|
}
|
|
|
|
|
2008-08-22 05:03:20 +02:00
|
|
|
/**
|
|
|
|
* Resize this Image by both width and height, using padded resize. Use in templates with $SetSize.
|
|
|
|
* @return GD
|
|
|
|
*/
|
|
|
|
public function generateSetSize(GD $gd, $width, $height) {
|
|
|
|
return $gd->paddedResize($width, $height);
|
|
|
|
}
|
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
public function CMSThumbnail() {
|
|
|
|
return $this->getFormattedImage('CMSThumbnail');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Resize this image for the CMS. Use in templates with $CMSThumbnail.
|
|
|
|
* @return GD
|
|
|
|
*/
|
|
|
|
function generateCMSThumbnail(GD $gd) {
|
|
|
|
return $gd->paddedResize($this->stat('cms_thumbnail_width'),$this->stat('cms_thumbnail_height'));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Resize this image for preview in the Asset section. Use in templates with $AssetLibraryPreview.
|
|
|
|
* @return GD
|
|
|
|
*/
|
|
|
|
function generateAssetLibraryPreview(GD $gd) {
|
|
|
|
return $gd->paddedResize($this->stat('asset_preview_width'),$this->stat('asset_preview_height'));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Resize this image for thumbnail in the Asset section. Use in templates with $AssetLibraryThumbnail.
|
|
|
|
* @return GD
|
|
|
|
*/
|
|
|
|
function generateAssetLibraryThumbnail(GD $gd) {
|
|
|
|
return $gd->paddedResize($this->stat('asset_thumbnail_width'),$this->stat('asset_thumbnail_height'));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Resize this image for use as a thumbnail in a strip. Use in templates with $StripThumbnail.
|
|
|
|
* @return GD
|
|
|
|
*/
|
|
|
|
function generateStripThumbnail(GD $gd) {
|
|
|
|
return $gd->croppedResize($this->stat('strip_thumbnail_width'),$this->stat('strip_thumbnail_height'));
|
|
|
|
}
|
2007-08-24 05:53:37 +02:00
|
|
|
|
2007-08-28 03:26:52 +02:00
|
|
|
function generatePaddedImage(GD $gd, $width, $height) {
|
2007-08-24 05:53:37 +02:00
|
|
|
return $gd->paddedResize($width, $height);
|
|
|
|
}
|
2007-07-19 12:40:28 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Return an image object representing the image in the given format.
|
|
|
|
* This image will be generated using generateFormattedImage().
|
|
|
|
* The generated image is cached, to flush the cache append ?flush=1 to your URL.
|
|
|
|
* @param string $format The name of the format.
|
|
|
|
* @param string $arg1 An argument to pass to the generate function.
|
|
|
|
* @param string $arg2 A second argument to pass to the generate function.
|
|
|
|
* @return Image_Cached
|
|
|
|
*/
|
|
|
|
function getFormattedImage($format, $arg1 = null, $arg2 = null) {
|
|
|
|
if($this->ID && $this->Filename && Director::fileExists($this->Filename)) {
|
|
|
|
$cacheFile = $this->cacheFilename($format, $arg1, $arg2);
|
|
|
|
|
|
|
|
if(!file_exists("../".$cacheFile) || isset($_GET['flush'])) {
|
|
|
|
$this->generateFormattedImage($format, $arg1, $arg2);
|
|
|
|
}
|
|
|
|
|
|
|
|
return new Image_Cached($cacheFile);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return the filename for the cached image, given it's format name and arguments.
|
|
|
|
* @param string $format The format name.
|
|
|
|
* @param string $arg1 The first argument passed to the generate function.
|
|
|
|
* @param string $arg2 The second argument passed to the generate function.
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
function cacheFilename($format, $arg1 = null, $arg2 = null) {
|
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/sapphire/trunk@63154 467b73ca-7a2a-4603-9d3b-597d59a354a9
2008-09-27 18:02:38 +02:00
|
|
|
$folder = $this->ParentID ? $this->Parent()->Filename : ASSETS_DIR . "/";
|
2007-07-19 12:40:28 +02:00
|
|
|
|
|
|
|
$format = $format.$arg1.$arg2;
|
|
|
|
|
|
|
|
return $folder . "_resampled/$format-" . $this->Name;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Generate an image on the specified format. It will save the image
|
|
|
|
* at the location specified by cacheFilename(). The image will be generated
|
|
|
|
* using the specific 'generate' method for the specified format.
|
2008-02-25 03:10:37 +01:00
|
|
|
* @param string $format Name of the format to generate.
|
|
|
|
* @param string $arg1 Argument to pass to the generate method.
|
|
|
|
* @param string $arg2 A second argument to pass to the generate method.
|
2007-07-19 12:40:28 +02:00
|
|
|
*/
|
|
|
|
function generateFormattedImage($format, $arg1 = null, $arg2 = null) {
|
|
|
|
$cacheFile = $this->cacheFilename($format, $arg1, $arg2);
|
|
|
|
|
|
|
|
$gd = new GD("../" . $this->Filename);
|
|
|
|
|
|
|
|
|
|
|
|
if($gd->hasGD()){
|
|
|
|
$generateFunc = "generate$format";
|
|
|
|
if($this->hasMethod($generateFunc)){
|
|
|
|
$gd = $this->$generateFunc($gd, $arg1, $arg2);
|
|
|
|
if($gd){
|
|
|
|
$gd->writeTo("../" . $cacheFile);
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
USER_ERROR("Image::generateFormattedImage - Image $format function not found.",E_USER_WARNING);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Generate a resized copy of this image with the given width & height.
|
|
|
|
* Use in templates with $ResizedImage.
|
|
|
|
*/
|
|
|
|
function generateResizedImage($gd, $width, $height) {
|
|
|
|
if(is_numeric($gd) || !$gd){
|
|
|
|
USER_ERROR("Image::generateFormattedImage - generateResizedImage is being called by legacy code or gd is not set.",E_USER_WARNING);
|
|
|
|
}else{
|
|
|
|
return $gd->resize($width, $height);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Generate a resized copy of this image with the given width & height, cropping to maintain aspect ratio.
|
|
|
|
* Use in templates with $CroppedImage
|
|
|
|
*/
|
|
|
|
function generateCroppedImage($gd, $width, $height) {
|
|
|
|
return $gd->croppedResize($width, $height);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Remove all of the formatted cached images.
|
|
|
|
* Should be called by any method that updates the current image.
|
|
|
|
*/
|
|
|
|
public function deleteFormattedImages() {
|
|
|
|
if($this->Filename) {
|
|
|
|
$numDeleted = 0;
|
|
|
|
$methodNames = $this->allMethodNames();
|
|
|
|
$numDeleted = 0;
|
|
|
|
foreach($methodNames as $methodName) {
|
|
|
|
if(substr($methodName,0,8) == 'generate') {
|
|
|
|
$format = substr($methodName,8);
|
|
|
|
$cacheFile = $this->cacheFilename($format);
|
|
|
|
if(Director::fileExists($cacheFile)) {
|
|
|
|
unlink(Director::getAbsFile($cacheFile));
|
|
|
|
$numDeleted++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $numDeleted;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the dimensions of this Image.
|
|
|
|
* @param string $dim If this is equal to "string", return the dimensions in string form,
|
|
|
|
* if it is 0 return the height, if it is 1 return the width.
|
|
|
|
* @return string|int
|
|
|
|
*/
|
|
|
|
function getDimensions($dim = "string") {
|
|
|
|
if($this->getField('Filename')) {
|
|
|
|
$imagefile = Director::baseFolder() . '/' . $this->getField('Filename');
|
|
|
|
if(file_exists($imagefile)) {
|
|
|
|
$size = getimagesize($imagefile);
|
|
|
|
return ($dim === "string") ? "$size[0]x$size[1]" : $size[$dim];
|
|
|
|
} else {
|
|
|
|
return ($dim === "string") ? "file '$imagefile' not found" : null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the width of this image.
|
|
|
|
* @return int
|
|
|
|
*/
|
|
|
|
function getWidth() {
|
|
|
|
return $this->getDimensions(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the height of this image.
|
|
|
|
* @return int
|
|
|
|
*/
|
|
|
|
function getHeight() {
|
|
|
|
return $this->getDimensions(1);
|
|
|
|
}
|
2008-03-18 00:50:18 +01:00
|
|
|
|
2009-01-08 23:33:56 +01:00
|
|
|
/**
|
|
|
|
* Get the orientation of this image.
|
2009-04-22 11:10:58 +02:00
|
|
|
* @return ORIENTATION_SQUARE | ORIENTATION_PORTRAIT | ORIENTATION_LANDSCAPE
|
2009-01-08 23:33:56 +01:00
|
|
|
*/
|
2009-04-22 11:10:58 +02:00
|
|
|
function getOrientation() {
|
2009-01-08 23:33:56 +01:00
|
|
|
$width = $this->getWidth();
|
|
|
|
$height = $this->getHeight();
|
|
|
|
if($width > $height) {
|
|
|
|
return self::ORIENTATION_LANDSCAPE;
|
|
|
|
} elseif($height > $width) {
|
|
|
|
return self::ORIENTATION_PORTRAIT;
|
|
|
|
} else {
|
|
|
|
return self::ORIENTATION_SQUARE;
|
|
|
|
}
|
|
|
|
}
|
2008-03-18 00:50:18 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// ###################
|
|
|
|
// DEPRECATED
|
|
|
|
// ###################
|
|
|
|
|
2008-05-10 04:21:26 +02:00
|
|
|
/**
|
2008-10-16 13:03:01 +02:00
|
|
|
* @deprecated Use getTag() instead
|
2008-05-10 04:21:26 +02:00
|
|
|
*/
|
|
|
|
function Tag() {
|
|
|
|
return $this->getTag();
|
|
|
|
}
|
|
|
|
|
2008-03-18 00:50:18 +01:00
|
|
|
/**
|
2008-10-16 13:03:01 +02:00
|
|
|
* @deprecated Use getURL() instead
|
2008-03-18 00:50:18 +01:00
|
|
|
*/
|
|
|
|
function URL() {
|
2008-03-19 21:51:49 +01:00
|
|
|
return $this->getURL();
|
2008-03-18 00:50:18 +01:00
|
|
|
}
|
2007-07-19 12:40:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2008-02-25 03:10:37 +01:00
|
|
|
* A resized / processed {@link Image} object.
|
|
|
|
* When Image object are processed or resized, a suitable Image_Cached object is returned, pointing to the
|
|
|
|
* cached copy of the processed image.
|
|
|
|
* @package sapphire
|
|
|
|
* @subpackage filesystem
|
2007-07-19 12:40:28 +02:00
|
|
|
*/
|
|
|
|
class Image_Cached extends Image {
|
|
|
|
/**
|
|
|
|
* Create a new cached image.
|
|
|
|
* @param string $filename The filename of the image.
|
|
|
|
* @param boolean $isSingleton This this to true if this is a singleton() object, a stub for calling methods. Singletons
|
|
|
|
* don't have their defaults set.
|
|
|
|
*/
|
|
|
|
public function __construct($filename = null, $isSingleton = false) {
|
|
|
|
parent::__construct(array(), $isSingleton);
|
|
|
|
$this->Filename = $filename;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getRelativePath() {
|
|
|
|
return $this->getField('Filename');
|
|
|
|
}
|
|
|
|
|
|
|
|
// Prevent this from doing anything
|
|
|
|
public function requireTable() {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
public function debug() {
|
|
|
|
return "Image_Cached object for $this->Filename";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2008-02-25 03:10:37 +01:00
|
|
|
* Uploader support for the uploading anything which is a File or subclass of File, eg Image.
|
2008-09-28 15:08:56 +02:00
|
|
|
* Is connected to the URL routing "/image" through sapphire/_config.php,
|
|
|
|
* and used by all iframe-based upload-fields in the CMS.
|
|
|
|
*
|
Merging in refactored Translatable architecture from trunk, including related/required changesets like enhancements to Object static handling (see details below)
------------------------------------------------------------------------
r68900 | sminnee | 2008-12-15 14:30:41 +1300 (Mon, 15 Dec 2008) | 1 line
Static caching merges from dnc branch
------------------------------------------------------------------------
r68917 | sminnee | 2008-12-15 14:49:06 +1300 (Mon, 15 Dec 2008) | 1 line
Merged Requirements fix from nestedurls branch
------------------------------------------------------------------------
r70033 | aoneil | 2009-01-13 14:03:41 +1300 (Tue, 13 Jan 2009) | 2 lines
Add translation migration task
------------------------------------------------------------------------
r70072 | ischommer | 2009-01-13 17:34:27 +1300 (Tue, 13 Jan 2009) | 5 lines
API CHANGE Removed obsolete internal Translatable methods: hasOwnTranslatableFields(), allFieldsInTable()
ENHANCEMENT Removed $create flag in Translatable::getTranslation() and replaced with explit action createTranslation()
ENHANCEMENT Sorting return array of Translatable::getTranslatedLangs()
ENHANCEMENT Added a note about saving a page before creating a translation
MINOR Added phpdoc to Translatable
------------------------------------------------------------------------
r70073 | ischommer | 2009-01-13 17:34:45 +1300 (Tue, 13 Jan 2009) | 1 line
ENHANCEMENT Added basic unit tests to new Translatable API
------------------------------------------------------------------------
r70080 | aoneil | 2009-01-13 18:04:21 +1300 (Tue, 13 Jan 2009) | 3 lines
BUGFIX: Fix translatable migration regenerating URLSegments when it shouldn't
BUGFIX: Fix translatable migration not writing records to Live properly
------------------------------------------------------------------------
r70118 | ischommer | 2009-01-14 11:28:24 +1300 (Wed, 14 Jan 2009) | 3 lines
API CHANGE Removed obsolete Translatable::table_exists()
ENHANCEMENT Made Translatable constructor arguments optional, as by default all database fields are marked translatable
MINOR More unit tests for Translatable
------------------------------------------------------------------------
r70138 | ischommer | 2009-01-14 17:00:30 +1300 (Wed, 14 Jan 2009) | 1 line
BUGFIX Disabled assumption that SQLQuery->filtersOnID() should only kick in when exactly one WHERE clause is given - this is very fragile and hard to test. It would return TRUE on $where = "SiteTree.ID = 5", but not on $where = array("Lang = 'de'", "SiteTree.ID = 5")
------------------------------------------------------------------------
r70214 | ischommer | 2009-01-15 18:56:25 +1300 (Thu, 15 Jan 2009) | 3 lines
BUGFIX Falling back to Translatable::current_lang() if no $context object is given, in augmentAllChildrenIncludingDeleted() and AllChildrenIncludingDeleted()
MINOR phpdoc for Translatable
MINOR Added more Translatable unit tests
------------------------------------------------------------------------
r70306 | ischommer | 2009-01-16 17:14:34 +1300 (Fri, 16 Jan 2009) | 9 lines
ENHANCEMENT Recursively creating translations for parent pages to ensure that a translated page is still accessible by traversing the tree, e.g. in "cms translation mode" (in Translatable->onBeforeWrite())
ENHANCEMENT Simplified AllChildrenIncludingDeleted() to not require a special augmentAllChildrenIncludingDeleted() implementation: We don't combine untranslated/translated children any longer (which was used in CMS tree view), but rather just show translated records
ENHANCEMENT Ensuring uniqueness of URL segments by appending "-<langcode>" to new translations (in Translatable->onBeforeWrite())
ENHANCEMENT Added Translatable->alternateGetByUrl() as a hook into SiteTree::get_by_url()
ENHANCEMENT Adding link back to original page in CMS editform for translations
BUGFIX Excluding HiddenField instances from Translatable->updateCMSFields()
BUGFIX Don't require a record to be written (through exists()) when checking Translatable->isTranslation() or Translatable->hasTranslation()
MINOR Don't use createMethod() shortcut for Translatable->AllChildrenIncludingDeleted()
MINOR Added Translatable unit tests
------------------------------------------------------------------------
r70318 | ischommer | 2009-01-19 11:46:16 +1300 (Mon, 19 Jan 2009) | 1 line
BUGFIX Reverted special cases for Translatable in Versioned->canBeVersioned() (originally committed in r42119) - was checking for existence of underscores in table names as an indication of the "_lang" suffix, which is no longer needed. It was also a flawed assumption which tripped over classes like TranslatableTest_TestPage
------------------------------------------------------------------------
r70319 | ischommer | 2009-01-19 11:47:02 +1300 (Mon, 19 Jan 2009) | 1 line
ENHANCEMENT Disabled Translatab-e>augmentWrite() - was only needed for the blacklist fields implementation which is inactive for the moment
------------------------------------------------------------------------
r70326 | ischommer | 2009-01-19 14:25:23 +1300 (Mon, 19 Jan 2009) | 2 lines
ENHANCEMENT Making ErrorPage static HTML files translatable (#2233)
ENHANCEMENT Added ErrorPage::$static_filepath to flexibly set location of static error pages (defaults to /assets)
------------------------------------------------------------------------
r70327 | ischommer | 2009-01-19 15:18:41 +1300 (Mon, 19 Jan 2009) | 1 line
FEATURE Enabled specifying a language through a hidden field in SearchForm which limits the search to pages in this language (incl. unit tests)
------------------------------------------------------------------------
r71258 | sharvey | 2009-02-03 15:49:34 +1300 (Tue, 03 Feb 2009) | 2 lines
BUGFIX: Fix translatable being enabled when it shouldn't be
------------------------------------------------------------------------
r71340 | ischommer | 2009-02-04 14:36:12 +1300 (Wed, 04 Feb 2009) | 1 line
BUGFIX Including Hierarchy->children in flushCache() and renamed to _cache_children. This caused problems in TranslatableTest when re-using the same SiteTree->Children() method with different languages on the same object (even with calling flushCache() inbetween the calls)
------------------------------------------------------------------------
r71567 | gmunn | 2009-02-10 13:49:16 +1300 (Tue, 10 Feb 2009) | 1 line
'URLSegment' on line 484 and 494 now escaped
------------------------------------------------------------------------
r72054 | ischommer | 2009-02-23 10:30:41 +1300 (Mon, 23 Feb 2009) | 3 lines
BUGFIX Fixed finding a translated homepage without an explicit URLSegment (e.g. http://mysite.com/?lang=de) - see #3540
ENHANCEMENT Added Translatable::get_homepage_urlsegment_by_language()
ENHANCEMENT Added RootURLController::get_default_homepage_urlsegment()
------------------------------------------------------------------------
r72367 | ischommer | 2009-03-03 11:13:30 +1300 (Tue, 03 Mar 2009) | 2 lines
ENHANCEMENT Added i18n::get_lang_from_locale() and i18n::convert_rfc1766()
ENHANCEMENT Using IETF/HTTP compatible "long" language code in SiteTree->MetaTags(). This means the default <meta type="content-language..."> value will be "en-US" instead of "en". The locale can be either set through the Translatable content language, or through i18n::set_locale()
------------------------------------------------------------------------
r73036 | sminnee | 2009-03-14 13:16:32 +1300 (Sat, 14 Mar 2009) | 1 line
ENHANCEMENT #3032 ajshort: Use static methods for accessing static data
------------------------------------------------------------------------
r73059 | sminnee | 2009-03-15 14:09:59 +1300 (Sun, 15 Mar 2009) | 2 lines
ENHANCEMENT: Added Object::clearCache() to clear a cache
BUGFIX: Make object cache testing more robust
------------------------------------------------------------------------
r73338 | ischommer | 2009-03-19 05:13:40 +1300 (Thu, 19 Mar 2009) | 9 lines
API CHANGE Added concept of "translation groups" to Translatable- every page can belong to a group of related translations, rather than having an explicit "original", meaning you can have pages in "non-default" languages which have no representation in other language trees. This group is recorded in a new table "<classname>_translationgroups". Translatable->createTranslation() and Translatable->onBeforeWrite() will automatically associate records in this groups. Added Translatable->addTranslationGroup(), Translatable->removeTranslationGroup(), Translatable->getTranslationGroup()
API CHANGE Removed Translatable->isTranslation() - after the new "translation group" model, every page is potentially a translation
API CHANGE Translatable->findOriginalIDs(), Translatable->setOriginalPage(), Translatable->getOriginalPage()
ENHANCEMENT Translatable->getCMSFields() will now always show the "create translation" option, not only on default languages - meaning you can create translations based on other translations
ENHANCEMENT Translatable language dropdown in CMS will always show all available languages, rather than filtering by already existing translations
ENHANCEMENT Added check for an existing record in Translatable->createTranslation()
BUGFIX Removed Translatable->getLang() which overloaded the $db property - it was causing side effects during creation of SiteTree default records.
BUGFIX Added check in Translatable->augmentSQL() to avoid reapplying "Lang = ..." filter twice
BUGFIX Removed bypass in Translatable->AllChildrenIncludingDeleted()
------------------------------------------------------------------------
r73339 | ischommer | 2009-03-19 05:15:46 +1300 (Thu, 19 Mar 2009) | 1 line
BUGFIX Disabled "untranslated" CSS class for SiteTree elements - doesn't apply any longer with the new "translation groups" concept
------------------------------------------------------------------------
r73341 | ischommer | 2009-03-19 06:01:51 +1300 (Thu, 19 Mar 2009) | 1 line
BUGFIX Disabled auto-excluding of default language from the "available languages" array in LanguageDropdownField - due to the new "translation groups" its possible to have a translation from another language into the default language
------------------------------------------------------------------------
r73342 | ischommer | 2009-03-19 06:13:23 +1300 (Thu, 19 Mar 2009) | 4 lines
BUGFIX Setting ParentID of translated record if recursively creating parents in Translatable::onBeforeWrite()
BUGFIX Fixing inline form action for "create translation"
BUGFIX Removed link to "original page" for a translation - no longer valid
MINOR documentation for Translatable
------------------------------------------------------------------------
r73464 | ischommer | 2009-03-20 20:51:00 +1300 (Fri, 20 Mar 2009) | 1 line
MINOR documentation
------------------------------------------------------------------------
r73465 | ischommer | 2009-03-20 20:58:52 +1300 (Fri, 20 Mar 2009) | 1 line
BUGFIX Fixed Hierarchy->Children() testing in TranslatableTest - with the new datamodel you can't call Children() in a different language regardless of Translatable::set_reading_lang(), the Children() call has to be made from a parent in the same language
------------------------------------------------------------------------
r73466 | ischommer | 2009-03-20 21:36:40 +1300 (Fri, 20 Mar 2009) | 2 lines
ENHANCEMENT Added Translatable::get_locale_from_lang(), Translatable::get_common_locales(), $common_locales and $likely_subtags in preparation to switch Translatable from using short "lang" codes to proper long locales
API CHANGE Deprecated Translatable::set_default_lang(), Translatable::default_lang()
------------------------------------------------------------------------
r73467 | ischommer | 2009-03-20 21:38:57 +1300 (Fri, 20 Mar 2009) | 1 line
ENHANCEMENT Supporting "Locale-English" and "Locale-Native" as listing arguments in LanguageDropdownField
------------------------------------------------------------------------
r73468 | ischommer | 2009-03-20 21:47:06 +1300 (Fri, 20 Mar 2009) | 7 lines
ENHANCEMENT Adjusted SearchForm, Debug, ErrorPage, SiteTree to using locales instead of lang codes
API CHANGE Changed Translatable datamodel to use locales ("en_US") instead of lang values ("en).
API CHANGE Changed Translatable::$default_lang to $default_locale, Translatable::$reading_lang to $reading_locale
API CHANGE Using "locale" instead of "lang" in Translatable::choose_site_lang() to auto-detect language from cookies or GET parameters
API CHANGE Deprecated Translatable::is_default_lang(), set_default_lang(), get_default_lang(), current_lang(), set_reading_lang(), get_reading_lang(), get_by_lang(), get_one_by_lang()
API CHANGE Removed Translatable::get_original() - with the new "translation groups" concept there no longer is an original for a translation
BUGFIX Updated MigrateTranslatableTask to new Locale based datamodel
------------------------------------------------------------------------
r73470 | ischommer | 2009-03-20 21:56:57 +1300 (Fri, 20 Mar 2009) | 1 line
MINOR fixed typo
------------------------------------------------------------------------
r73472 | sminnee | 2009-03-21 17:30:04 +1300 (Sat, 21 Mar 2009) | 1 line
BUGFIX: Fixed translatable test execution by making protected methods public
------------------------------------------------------------------------
r73473 | sminnee | 2009-03-21 18:10:05 +1300 (Sat, 21 Mar 2009) | 1 line
ENHANCEMENT: Added Object::combined_static(), which gets all values of a static property from each class in the hierarchy
------------------------------------------------------------------------
r73883 | ischommer | 2009-04-01 08:32:19 +1300 (Wed, 01 Apr 2009) | 1 line
BUGFIX Making $_SINGLETONS a global instead of a static in Core.php so it can be re-used in other places
------------------------------------------------------------------------
r73951 | ischommer | 2009-04-02 05:35:32 +1300 (Thu, 02 Apr 2009) | 3 lines
API CHANGE Deprecated Translatable::enable() and i18n::enable()- use Object::add_extension('SiteTree','Translatable'), Deprecated Translatable::disable() and i18n::disable() - use Object::remove_extension('SiteTree','Translatable'), Deprecated Translatable::enabled() - use $myPage->hasExtension('Translatable')
API CHANGE Removed Translatable::creating_from() - doesn't apply any longer
ENHANCEMENT Translatable extension is no longer hooked up to SiteTree by default, which should improve performance and memory usage for sites not using Translatable. Please use Object::add_extension('SiteTree','Translatable') in your _config.php instead. Adjusted several classes (Image, ErrorPage, RootURLController) to the new behaviour.
------------------------------------------------------------------------
r73882 | ischommer | 2009-04-01 08:31:21 +1300 (Wed, 01 Apr 2009) | 1 line
ENHANCEMENT Added DataObjectDecorator->setOwner()
------------------------------------------------------------------------
r73884 | ischommer | 2009-04-01 08:32:51 +1300 (Wed, 01 Apr 2009) | 1 line
ENHANCEMENT Added Extension::get_classname_without_arguments()
------------------------------------------------------------------------
r73900 | ischommer | 2009-04-01 11:27:53 +1300 (Wed, 01 Apr 2009) | 7 lines
API CHANGE Deprecated Object->extInstance(), use getExtensionInstance() instead
ENHANCEMENT Added Object->getExtensionInstances()
ENHANCEMENT Added Object::get_extensions()
ENHANCEMENT Unsetting class caches when using Object::add_extension() to avoid problems with defineMethods etc.
BUGFIX Fixed extension comparison with case sensitivity and stripping arguments in Object::has_extension()
BUGFIX Unsetting all cached singletons in Object::remove_extension() to avoid outdated extension_instances
MINOR Documentation in Object
------------------------------------------------------------------------
r74017 | ischommer | 2009-04-03 10:49:40 +1300 (Fri, 03 Apr 2009) | 1 line
ENHANCEMENT Improved deprecated fallbacks in Translatable by auto-converting short language codes to long locales and vice versa through i18n::get_lang_from_locale()/i18n::get_locale_from_lang()
------------------------------------------------------------------------
r74030 | ischommer | 2009-04-03 11:41:26 +1300 (Fri, 03 Apr 2009) | 1 line
MINOR Re-added Translatable::default_lang() for more graceful fallback to Translatable::default_locale()
------------------------------------------------------------------------
r74065 | ischommer | 2009-04-04 05:38:51 +1300 (Sat, 04 Apr 2009) | 1 line
BUGFIX Re-added Translatable->isTranslation() for more friendly deprecation (originally removed in r73338)
------------------------------------------------------------------------
r74069 | ischommer | 2009-04-04 09:43:01 +1300 (Sat, 04 Apr 2009) | 1 line
BUGFIX Fixed legacy handling of Translatable::enable(),Translatable::disable() and Translatable::is_enabled() - applying extension to SiteTree instead of Page to avoid datamodel clashes
------------------------------------------------------------------------
r74070 | ischommer | 2009-04-04 10:23:51 +1300 (Sat, 04 Apr 2009) | 1 line
API CHANGE Deprecated Translatable::choose_site_lang(), use choose_site_locale()
------------------------------------------------------------------------
r74941 | ischommer | 2009-04-22 15:22:09 +1200 (Wed, 22 Apr 2009) | 2 lines
ENHANCEMENT Adding SapphireTest::set_up_once() and SapphireTest::tear_down_once() for better test performance with state that just needs to be initialized once per test case (not per test method). Added new SapphireTestSuite to support this through PHPUnit.
ENHANCEMENT Using set_up_once() in TranslatableTest and TranslatableSearchFormTest for better test run performance
------------------------------------------------------------------------
r74942 | ischommer | 2009-04-22 15:24:50 +1200 (Wed, 22 Apr 2009) | 1 line
BUGFIX Fixed TranslatableSearchFormTest->setUp() method
------------------------------------------------------------------------
r73509 | ischommer | 2009-03-23 11:59:14 +1300 (Mon, 23 Mar 2009) | 1 line
MINOR phpdoc documentation
------------------------------------------------------------------------
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/branches/2.3@74986 467b73ca-7a2a-4603-9d3b-597d59a354a9
2009-04-23 03:45:10 +02:00
|
|
|
* Used by {@link FileIFrameField}, {@link ImageField}.
|
|
|
|
*
|
2008-10-31 03:09:04 +01:00
|
|
|
* @todo Refactor to using FileIFrameField and ImageField as a controller for the upload,
|
2008-09-28 15:08:56 +02:00
|
|
|
* rather than something totally disconnected from the original Form and FormField
|
|
|
|
* context. Without the original context its impossible to control permissions etc.
|
|
|
|
*
|
2008-02-25 03:10:37 +01:00
|
|
|
* @package sapphire
|
|
|
|
* @subpackage filesystem
|
2007-07-19 12:40:28 +02:00
|
|
|
*/
|
|
|
|
class Image_Uploader extends Controller {
|
2008-08-15 00:20:32 +02:00
|
|
|
static $url_handlers = array(
|
|
|
|
'$Action!/$Class!/$ID!/$Field!/$FormName!' => '$FormName',
|
|
|
|
'$Action/$Class/$ID/$Field' => 'handleAction',
|
|
|
|
);
|
|
|
|
|
2009-03-18 04:01:36 +01:00
|
|
|
static $allowed_actions = array(
|
2009-03-18 04:53:39 +01:00
|
|
|
'iframe' => 'CMS_ACCESS_CMSMain',
|
|
|
|
'flush' => 'CMS_ACCESS_CMSMain',
|
|
|
|
'save' => 'CMS_ACCESS_CMSMain',
|
2009-03-18 05:04:05 +01:00
|
|
|
'delete' => 'CMS_ACCESS_CMSMain',
|
2009-03-18 06:42:02 +01:00
|
|
|
'EditImageForm' => 'CMS_ACCESS_CMSMain',
|
|
|
|
'DeleteImageForm' => 'CMS_ACCESS_CMSMain'
|
2009-03-18 04:01:36 +01:00
|
|
|
);
|
|
|
|
|
2008-11-10 20:54:30 +01:00
|
|
|
function init() {
|
|
|
|
// set language
|
|
|
|
$member = Member::currentUser();
|
|
|
|
if(!empty($member->Locale)) {
|
|
|
|
i18n::set_locale($member->Locale);
|
|
|
|
}
|
|
|
|
|
|
|
|
// set reading lang
|
Merging in refactored Translatable architecture from trunk, including related/required changesets like enhancements to Object static handling (see details below)
------------------------------------------------------------------------
r68900 | sminnee | 2008-12-15 14:30:41 +1300 (Mon, 15 Dec 2008) | 1 line
Static caching merges from dnc branch
------------------------------------------------------------------------
r68917 | sminnee | 2008-12-15 14:49:06 +1300 (Mon, 15 Dec 2008) | 1 line
Merged Requirements fix from nestedurls branch
------------------------------------------------------------------------
r70033 | aoneil | 2009-01-13 14:03:41 +1300 (Tue, 13 Jan 2009) | 2 lines
Add translation migration task
------------------------------------------------------------------------
r70072 | ischommer | 2009-01-13 17:34:27 +1300 (Tue, 13 Jan 2009) | 5 lines
API CHANGE Removed obsolete internal Translatable methods: hasOwnTranslatableFields(), allFieldsInTable()
ENHANCEMENT Removed $create flag in Translatable::getTranslation() and replaced with explit action createTranslation()
ENHANCEMENT Sorting return array of Translatable::getTranslatedLangs()
ENHANCEMENT Added a note about saving a page before creating a translation
MINOR Added phpdoc to Translatable
------------------------------------------------------------------------
r70073 | ischommer | 2009-01-13 17:34:45 +1300 (Tue, 13 Jan 2009) | 1 line
ENHANCEMENT Added basic unit tests to new Translatable API
------------------------------------------------------------------------
r70080 | aoneil | 2009-01-13 18:04:21 +1300 (Tue, 13 Jan 2009) | 3 lines
BUGFIX: Fix translatable migration regenerating URLSegments when it shouldn't
BUGFIX: Fix translatable migration not writing records to Live properly
------------------------------------------------------------------------
r70118 | ischommer | 2009-01-14 11:28:24 +1300 (Wed, 14 Jan 2009) | 3 lines
API CHANGE Removed obsolete Translatable::table_exists()
ENHANCEMENT Made Translatable constructor arguments optional, as by default all database fields are marked translatable
MINOR More unit tests for Translatable
------------------------------------------------------------------------
r70138 | ischommer | 2009-01-14 17:00:30 +1300 (Wed, 14 Jan 2009) | 1 line
BUGFIX Disabled assumption that SQLQuery->filtersOnID() should only kick in when exactly one WHERE clause is given - this is very fragile and hard to test. It would return TRUE on $where = "SiteTree.ID = 5", but not on $where = array("Lang = 'de'", "SiteTree.ID = 5")
------------------------------------------------------------------------
r70214 | ischommer | 2009-01-15 18:56:25 +1300 (Thu, 15 Jan 2009) | 3 lines
BUGFIX Falling back to Translatable::current_lang() if no $context object is given, in augmentAllChildrenIncludingDeleted() and AllChildrenIncludingDeleted()
MINOR phpdoc for Translatable
MINOR Added more Translatable unit tests
------------------------------------------------------------------------
r70306 | ischommer | 2009-01-16 17:14:34 +1300 (Fri, 16 Jan 2009) | 9 lines
ENHANCEMENT Recursively creating translations for parent pages to ensure that a translated page is still accessible by traversing the tree, e.g. in "cms translation mode" (in Translatable->onBeforeWrite())
ENHANCEMENT Simplified AllChildrenIncludingDeleted() to not require a special augmentAllChildrenIncludingDeleted() implementation: We don't combine untranslated/translated children any longer (which was used in CMS tree view), but rather just show translated records
ENHANCEMENT Ensuring uniqueness of URL segments by appending "-<langcode>" to new translations (in Translatable->onBeforeWrite())
ENHANCEMENT Added Translatable->alternateGetByUrl() as a hook into SiteTree::get_by_url()
ENHANCEMENT Adding link back to original page in CMS editform for translations
BUGFIX Excluding HiddenField instances from Translatable->updateCMSFields()
BUGFIX Don't require a record to be written (through exists()) when checking Translatable->isTranslation() or Translatable->hasTranslation()
MINOR Don't use createMethod() shortcut for Translatable->AllChildrenIncludingDeleted()
MINOR Added Translatable unit tests
------------------------------------------------------------------------
r70318 | ischommer | 2009-01-19 11:46:16 +1300 (Mon, 19 Jan 2009) | 1 line
BUGFIX Reverted special cases for Translatable in Versioned->canBeVersioned() (originally committed in r42119) - was checking for existence of underscores in table names as an indication of the "_lang" suffix, which is no longer needed. It was also a flawed assumption which tripped over classes like TranslatableTest_TestPage
------------------------------------------------------------------------
r70319 | ischommer | 2009-01-19 11:47:02 +1300 (Mon, 19 Jan 2009) | 1 line
ENHANCEMENT Disabled Translatab-e>augmentWrite() - was only needed for the blacklist fields implementation which is inactive for the moment
------------------------------------------------------------------------
r70326 | ischommer | 2009-01-19 14:25:23 +1300 (Mon, 19 Jan 2009) | 2 lines
ENHANCEMENT Making ErrorPage static HTML files translatable (#2233)
ENHANCEMENT Added ErrorPage::$static_filepath to flexibly set location of static error pages (defaults to /assets)
------------------------------------------------------------------------
r70327 | ischommer | 2009-01-19 15:18:41 +1300 (Mon, 19 Jan 2009) | 1 line
FEATURE Enabled specifying a language through a hidden field in SearchForm which limits the search to pages in this language (incl. unit tests)
------------------------------------------------------------------------
r71258 | sharvey | 2009-02-03 15:49:34 +1300 (Tue, 03 Feb 2009) | 2 lines
BUGFIX: Fix translatable being enabled when it shouldn't be
------------------------------------------------------------------------
r71340 | ischommer | 2009-02-04 14:36:12 +1300 (Wed, 04 Feb 2009) | 1 line
BUGFIX Including Hierarchy->children in flushCache() and renamed to _cache_children. This caused problems in TranslatableTest when re-using the same SiteTree->Children() method with different languages on the same object (even with calling flushCache() inbetween the calls)
------------------------------------------------------------------------
r71567 | gmunn | 2009-02-10 13:49:16 +1300 (Tue, 10 Feb 2009) | 1 line
'URLSegment' on line 484 and 494 now escaped
------------------------------------------------------------------------
r72054 | ischommer | 2009-02-23 10:30:41 +1300 (Mon, 23 Feb 2009) | 3 lines
BUGFIX Fixed finding a translated homepage without an explicit URLSegment (e.g. http://mysite.com/?lang=de) - see #3540
ENHANCEMENT Added Translatable::get_homepage_urlsegment_by_language()
ENHANCEMENT Added RootURLController::get_default_homepage_urlsegment()
------------------------------------------------------------------------
r72367 | ischommer | 2009-03-03 11:13:30 +1300 (Tue, 03 Mar 2009) | 2 lines
ENHANCEMENT Added i18n::get_lang_from_locale() and i18n::convert_rfc1766()
ENHANCEMENT Using IETF/HTTP compatible "long" language code in SiteTree->MetaTags(). This means the default <meta type="content-language..."> value will be "en-US" instead of "en". The locale can be either set through the Translatable content language, or through i18n::set_locale()
------------------------------------------------------------------------
r73036 | sminnee | 2009-03-14 13:16:32 +1300 (Sat, 14 Mar 2009) | 1 line
ENHANCEMENT #3032 ajshort: Use static methods for accessing static data
------------------------------------------------------------------------
r73059 | sminnee | 2009-03-15 14:09:59 +1300 (Sun, 15 Mar 2009) | 2 lines
ENHANCEMENT: Added Object::clearCache() to clear a cache
BUGFIX: Make object cache testing more robust
------------------------------------------------------------------------
r73338 | ischommer | 2009-03-19 05:13:40 +1300 (Thu, 19 Mar 2009) | 9 lines
API CHANGE Added concept of "translation groups" to Translatable- every page can belong to a group of related translations, rather than having an explicit "original", meaning you can have pages in "non-default" languages which have no representation in other language trees. This group is recorded in a new table "<classname>_translationgroups". Translatable->createTranslation() and Translatable->onBeforeWrite() will automatically associate records in this groups. Added Translatable->addTranslationGroup(), Translatable->removeTranslationGroup(), Translatable->getTranslationGroup()
API CHANGE Removed Translatable->isTranslation() - after the new "translation group" model, every page is potentially a translation
API CHANGE Translatable->findOriginalIDs(), Translatable->setOriginalPage(), Translatable->getOriginalPage()
ENHANCEMENT Translatable->getCMSFields() will now always show the "create translation" option, not only on default languages - meaning you can create translations based on other translations
ENHANCEMENT Translatable language dropdown in CMS will always show all available languages, rather than filtering by already existing translations
ENHANCEMENT Added check for an existing record in Translatable->createTranslation()
BUGFIX Removed Translatable->getLang() which overloaded the $db property - it was causing side effects during creation of SiteTree default records.
BUGFIX Added check in Translatable->augmentSQL() to avoid reapplying "Lang = ..." filter twice
BUGFIX Removed bypass in Translatable->AllChildrenIncludingDeleted()
------------------------------------------------------------------------
r73339 | ischommer | 2009-03-19 05:15:46 +1300 (Thu, 19 Mar 2009) | 1 line
BUGFIX Disabled "untranslated" CSS class for SiteTree elements - doesn't apply any longer with the new "translation groups" concept
------------------------------------------------------------------------
r73341 | ischommer | 2009-03-19 06:01:51 +1300 (Thu, 19 Mar 2009) | 1 line
BUGFIX Disabled auto-excluding of default language from the "available languages" array in LanguageDropdownField - due to the new "translation groups" its possible to have a translation from another language into the default language
------------------------------------------------------------------------
r73342 | ischommer | 2009-03-19 06:13:23 +1300 (Thu, 19 Mar 2009) | 4 lines
BUGFIX Setting ParentID of translated record if recursively creating parents in Translatable::onBeforeWrite()
BUGFIX Fixing inline form action for "create translation"
BUGFIX Removed link to "original page" for a translation - no longer valid
MINOR documentation for Translatable
------------------------------------------------------------------------
r73464 | ischommer | 2009-03-20 20:51:00 +1300 (Fri, 20 Mar 2009) | 1 line
MINOR documentation
------------------------------------------------------------------------
r73465 | ischommer | 2009-03-20 20:58:52 +1300 (Fri, 20 Mar 2009) | 1 line
BUGFIX Fixed Hierarchy->Children() testing in TranslatableTest - with the new datamodel you can't call Children() in a different language regardless of Translatable::set_reading_lang(), the Children() call has to be made from a parent in the same language
------------------------------------------------------------------------
r73466 | ischommer | 2009-03-20 21:36:40 +1300 (Fri, 20 Mar 2009) | 2 lines
ENHANCEMENT Added Translatable::get_locale_from_lang(), Translatable::get_common_locales(), $common_locales and $likely_subtags in preparation to switch Translatable from using short "lang" codes to proper long locales
API CHANGE Deprecated Translatable::set_default_lang(), Translatable::default_lang()
------------------------------------------------------------------------
r73467 | ischommer | 2009-03-20 21:38:57 +1300 (Fri, 20 Mar 2009) | 1 line
ENHANCEMENT Supporting "Locale-English" and "Locale-Native" as listing arguments in LanguageDropdownField
------------------------------------------------------------------------
r73468 | ischommer | 2009-03-20 21:47:06 +1300 (Fri, 20 Mar 2009) | 7 lines
ENHANCEMENT Adjusted SearchForm, Debug, ErrorPage, SiteTree to using locales instead of lang codes
API CHANGE Changed Translatable datamodel to use locales ("en_US") instead of lang values ("en).
API CHANGE Changed Translatable::$default_lang to $default_locale, Translatable::$reading_lang to $reading_locale
API CHANGE Using "locale" instead of "lang" in Translatable::choose_site_lang() to auto-detect language from cookies or GET parameters
API CHANGE Deprecated Translatable::is_default_lang(), set_default_lang(), get_default_lang(), current_lang(), set_reading_lang(), get_reading_lang(), get_by_lang(), get_one_by_lang()
API CHANGE Removed Translatable::get_original() - with the new "translation groups" concept there no longer is an original for a translation
BUGFIX Updated MigrateTranslatableTask to new Locale based datamodel
------------------------------------------------------------------------
r73470 | ischommer | 2009-03-20 21:56:57 +1300 (Fri, 20 Mar 2009) | 1 line
MINOR fixed typo
------------------------------------------------------------------------
r73472 | sminnee | 2009-03-21 17:30:04 +1300 (Sat, 21 Mar 2009) | 1 line
BUGFIX: Fixed translatable test execution by making protected methods public
------------------------------------------------------------------------
r73473 | sminnee | 2009-03-21 18:10:05 +1300 (Sat, 21 Mar 2009) | 1 line
ENHANCEMENT: Added Object::combined_static(), which gets all values of a static property from each class in the hierarchy
------------------------------------------------------------------------
r73883 | ischommer | 2009-04-01 08:32:19 +1300 (Wed, 01 Apr 2009) | 1 line
BUGFIX Making $_SINGLETONS a global instead of a static in Core.php so it can be re-used in other places
------------------------------------------------------------------------
r73951 | ischommer | 2009-04-02 05:35:32 +1300 (Thu, 02 Apr 2009) | 3 lines
API CHANGE Deprecated Translatable::enable() and i18n::enable()- use Object::add_extension('SiteTree','Translatable'), Deprecated Translatable::disable() and i18n::disable() - use Object::remove_extension('SiteTree','Translatable'), Deprecated Translatable::enabled() - use $myPage->hasExtension('Translatable')
API CHANGE Removed Translatable::creating_from() - doesn't apply any longer
ENHANCEMENT Translatable extension is no longer hooked up to SiteTree by default, which should improve performance and memory usage for sites not using Translatable. Please use Object::add_extension('SiteTree','Translatable') in your _config.php instead. Adjusted several classes (Image, ErrorPage, RootURLController) to the new behaviour.
------------------------------------------------------------------------
r73882 | ischommer | 2009-04-01 08:31:21 +1300 (Wed, 01 Apr 2009) | 1 line
ENHANCEMENT Added DataObjectDecorator->setOwner()
------------------------------------------------------------------------
r73884 | ischommer | 2009-04-01 08:32:51 +1300 (Wed, 01 Apr 2009) | 1 line
ENHANCEMENT Added Extension::get_classname_without_arguments()
------------------------------------------------------------------------
r73900 | ischommer | 2009-04-01 11:27:53 +1300 (Wed, 01 Apr 2009) | 7 lines
API CHANGE Deprecated Object->extInstance(), use getExtensionInstance() instead
ENHANCEMENT Added Object->getExtensionInstances()
ENHANCEMENT Added Object::get_extensions()
ENHANCEMENT Unsetting class caches when using Object::add_extension() to avoid problems with defineMethods etc.
BUGFIX Fixed extension comparison with case sensitivity and stripping arguments in Object::has_extension()
BUGFIX Unsetting all cached singletons in Object::remove_extension() to avoid outdated extension_instances
MINOR Documentation in Object
------------------------------------------------------------------------
r74017 | ischommer | 2009-04-03 10:49:40 +1300 (Fri, 03 Apr 2009) | 1 line
ENHANCEMENT Improved deprecated fallbacks in Translatable by auto-converting short language codes to long locales and vice versa through i18n::get_lang_from_locale()/i18n::get_locale_from_lang()
------------------------------------------------------------------------
r74030 | ischommer | 2009-04-03 11:41:26 +1300 (Fri, 03 Apr 2009) | 1 line
MINOR Re-added Translatable::default_lang() for more graceful fallback to Translatable::default_locale()
------------------------------------------------------------------------
r74065 | ischommer | 2009-04-04 05:38:51 +1300 (Sat, 04 Apr 2009) | 1 line
BUGFIX Re-added Translatable->isTranslation() for more friendly deprecation (originally removed in r73338)
------------------------------------------------------------------------
r74069 | ischommer | 2009-04-04 09:43:01 +1300 (Sat, 04 Apr 2009) | 1 line
BUGFIX Fixed legacy handling of Translatable::enable(),Translatable::disable() and Translatable::is_enabled() - applying extension to SiteTree instead of Page to avoid datamodel clashes
------------------------------------------------------------------------
r74070 | ischommer | 2009-04-04 10:23:51 +1300 (Sat, 04 Apr 2009) | 1 line
API CHANGE Deprecated Translatable::choose_site_lang(), use choose_site_locale()
------------------------------------------------------------------------
r74941 | ischommer | 2009-04-22 15:22:09 +1200 (Wed, 22 Apr 2009) | 2 lines
ENHANCEMENT Adding SapphireTest::set_up_once() and SapphireTest::tear_down_once() for better test performance with state that just needs to be initialized once per test case (not per test method). Added new SapphireTestSuite to support this through PHPUnit.
ENHANCEMENT Using set_up_once() in TranslatableTest and TranslatableSearchFormTest for better test run performance
------------------------------------------------------------------------
r74942 | ischommer | 2009-04-22 15:24:50 +1200 (Wed, 22 Apr 2009) | 1 line
BUGFIX Fixed TranslatableSearchFormTest->setUp() method
------------------------------------------------------------------------
r73509 | ischommer | 2009-03-23 11:59:14 +1300 (Mon, 23 Mar 2009) | 1 line
MINOR phpdoc documentation
------------------------------------------------------------------------
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/branches/2.3@74986 467b73ca-7a2a-4603-9d3b-597d59a354a9
2009-04-23 03:45:10 +02:00
|
|
|
if(singleton('SiteTree')->hasExtension('Translatable') && !Director::is_ajax()) {
|
|
|
|
Translatable::choose_site_locale(array_keys(Translatable::get_existing_content_languages('SiteTree')));
|
2008-11-10 20:54:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
parent::init();
|
|
|
|
}
|
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
/**
|
|
|
|
* Ensures the css is loaded for the iframe.
|
|
|
|
*/
|
|
|
|
function iframe() {
|
2008-04-26 08:36:23 +02:00
|
|
|
if(!Permission::check('CMS_ACCESS_CMSMain')) Security::permissionFailure($this);
|
2008-02-25 03:10:37 +01:00
|
|
|
|
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/sapphire/trunk@63154 467b73ca-7a2a-4603-9d3b-597d59a354a9
2008-09-27 18:02:38 +02:00
|
|
|
Requirements::css(CMS_DIR . "/css/Image_iframe.css");
|
2007-07-19 12:40:28 +02:00
|
|
|
return array();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Image object attached to this class.
|
|
|
|
* @var Image
|
|
|
|
*/
|
|
|
|
protected $imageObj;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Associated parent object.
|
|
|
|
* @var DataObject
|
|
|
|
*/
|
|
|
|
protected $linkedObj;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Finds the associated parent object from the urlParams.
|
|
|
|
* @return DataObject
|
|
|
|
*/
|
|
|
|
function linkedObj() {
|
|
|
|
if(!$this->linkedObj) {
|
|
|
|
$this->linkedObj = DataObject::get_by_id($this->urlParams['Class'], $this->urlParams['ID']);
|
|
|
|
if(!$this->linkedObj) {
|
|
|
|
user_error("Data object '{$this->urlParams['Class']}.{$this->urlParams['ID']}' couldn't be found", E_USER_ERROR);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $this->linkedObj;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the Image object attached to this class.
|
|
|
|
* @return Image
|
|
|
|
*/
|
|
|
|
function Image() {
|
|
|
|
if(!$this->imageObj) {
|
|
|
|
$funcName = $this->urlParams['Field'];
|
|
|
|
$linked = $this->linkedObj();
|
|
|
|
$this->imageObj = $linked->obj($funcName);
|
|
|
|
if(!$this->imageObj) {$this->imageObj = new Image(null);}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $this->imageObj;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns true if the file attachment is an image.
|
|
|
|
* Otherwise, it's a file.
|
|
|
|
* @return boolean
|
|
|
|
*/
|
|
|
|
function IsImage() {
|
|
|
|
$className = $this->Image()->class;
|
|
|
|
return $className == "Image" || is_subclass_of($className, "Image");
|
|
|
|
}
|
|
|
|
|
|
|
|
function UseSimpleForm() {
|
|
|
|
if(!$this->useSimpleForm) {
|
|
|
|
$this->useSimpleForm = false;
|
|
|
|
}
|
|
|
|
return $this->useSimpleForm;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return a link to this uploader.
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
function Link($action = null) {
|
|
|
|
return $this->RelativeLink($action);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return the relative link to this uploader.
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
function RelativeLink($action = null) {
|
|
|
|
if(!$action) {
|
|
|
|
$action = "index";
|
|
|
|
}
|
|
|
|
return "images/$action/{$this->urlParams['Class']}/{$this->urlParams['ID']}/{$this->urlParams['Field']}";
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Form to show the current image and allow you to upload another one.
|
|
|
|
* @return Form
|
|
|
|
*/
|
|
|
|
function EditImageForm() {
|
|
|
|
$isImage = $this->IsImage();
|
2007-10-25 04:47:45 +02:00
|
|
|
$type = $isImage ? _t('Controller.IMAGE', "Image") : _t('Controller.FILE', "File");
|
2007-07-19 12:40:28 +02:00
|
|
|
if($this->Image()->ID) {
|
2007-10-25 04:47:45 +02:00
|
|
|
$title = sprintf(
|
|
|
|
_t('ImageUploader.REPLACE', "Replace %s", PR_MEDIUM, 'Replace file/image'),
|
|
|
|
$type
|
|
|
|
);
|
|
|
|
$fromYourPC = _t('ImageUploader.ONEFROMCOMPUTER', "With one from your computer");
|
|
|
|
$fromTheDB = _t('ImageUplaoder.ONEFROMFILESTORE', "With one from the file store");
|
2007-07-19 12:40:28 +02:00
|
|
|
} else {
|
2007-10-25 04:47:45 +02:00
|
|
|
$title = sprintf(
|
|
|
|
_t('ImageUploader.ATTACH', "Attach %s", PR_MEDIUM, 'Attach image/file'),
|
|
|
|
$type
|
|
|
|
);
|
|
|
|
$fromYourPC = _t('ImageUploader.FROMCOMPUTER', "From your computer");
|
|
|
|
$fromTheDB = _t('ImageUploader.FROMFILESTORE', "From the file store");
|
2007-07-19 12:40:28 +02:00
|
|
|
}
|
2007-10-25 04:47:45 +02:00
|
|
|
return new Form(
|
|
|
|
$this,
|
|
|
|
'EditImageForm',
|
|
|
|
new FieldSet(
|
|
|
|
new HiddenField("Class", null, $this->urlParams['Class']),
|
|
|
|
new HiddenField("ID", null, $this->urlParams['ID']),
|
|
|
|
new HiddenField("Field", null, $this->urlParams['Field']),
|
2008-10-16 15:26:50 +02:00
|
|
|
new HeaderField('EditImageHeader',$title),
|
2007-10-25 04:47:45 +02:00
|
|
|
new SelectionGroup("ImageSource", array(
|
|
|
|
"new//$fromYourPC" => new FieldGroup("",
|
|
|
|
new FileField("Upload","")
|
|
|
|
),
|
|
|
|
"existing//$fromTheDB" => new FieldGroup("",
|
|
|
|
new TreeDropdownField("ExistingFile", "","File")
|
|
|
|
)
|
|
|
|
))
|
|
|
|
),
|
|
|
|
new FieldSet(
|
|
|
|
new FormAction("save",$title)
|
|
|
|
)
|
|
|
|
);
|
2007-07-19 12:40:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A simple version of the upload form.
|
|
|
|
* @returns string
|
|
|
|
*/
|
|
|
|
function EditImageSimpleForm() {
|
|
|
|
$isImage = $this->IsImage();
|
2007-10-25 04:47:45 +02:00
|
|
|
$type = $isImage ? _t('Controller.IMAGE') : _t('Controller.FILE');
|
2007-07-19 12:40:28 +02:00
|
|
|
if($this->Image()->ID) {
|
2007-10-25 04:47:45 +02:00
|
|
|
$title = sprintf(
|
|
|
|
_t('ImageUploader.REPLACE'),
|
|
|
|
$type
|
|
|
|
);
|
|
|
|
$fromYourPC = _t('ImageUploader.ONEFROMCOMPUTER');
|
2007-07-19 12:40:28 +02:00
|
|
|
} else {
|
2007-10-25 04:47:45 +02:00
|
|
|
$title = sprintf(
|
|
|
|
_t('ImageUploader.ATTACH'),
|
|
|
|
$type
|
|
|
|
);
|
|
|
|
$fromTheDB = _t('ImageUploader.ONEFROMFILESTORE');
|
2007-07-19 12:40:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return new Form($this, 'EditImageSimpleForm', new FieldSet(
|
|
|
|
new HiddenField("Class", null, $this->urlParams['Class']),
|
|
|
|
new HiddenField("ID", null, $this->urlParams['ID']),
|
|
|
|
new HiddenField("Field", null, $this->urlParams['Field']),
|
|
|
|
new FileField("Upload","")
|
|
|
|
),
|
|
|
|
new FieldSet(
|
|
|
|
new FormAction("save",$title)
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A form to delete this image.
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
function DeleteImageForm() {
|
|
|
|
if($this->Image()->ID) {
|
|
|
|
$isImage = $this->IsImage();
|
2007-10-25 04:47:45 +02:00
|
|
|
$type = $isImage ? _t('Controller.IMAGE') : _t('Controller.FILE');
|
|
|
|
$title = sprintf(
|
|
|
|
_t('ImageUploader.DELETE', 'Delete %s', PR_MEDIUM, 'Delete file/image'),
|
|
|
|
$type
|
|
|
|
);
|
2008-02-25 03:10:37 +01:00
|
|
|
$form = new Form(
|
2007-10-25 04:47:45 +02:00
|
|
|
$this,
|
|
|
|
'DeleteImageForm',
|
|
|
|
new FieldSet(
|
2007-11-01 06:31:58 +01:00
|
|
|
new HiddenField("Class", null, $this->urlParams['Class']),
|
2007-10-25 04:47:45 +02:00
|
|
|
new HiddenField("ID", null, $this->urlParams['ID']),
|
2008-02-25 03:10:37 +01:00
|
|
|
new HiddenField("Field", null, $this->urlParams['Field'])
|
2007-07-19 12:40:28 +02:00
|
|
|
),
|
|
|
|
new FieldSet(
|
2008-02-25 03:10:37 +01:00
|
|
|
$deleteAction = new ConfirmedFormAction(
|
2007-10-25 04:47:45 +02:00
|
|
|
"delete",
|
|
|
|
$title,
|
|
|
|
sprintf(_t('ImageUploader.REALLYDELETE', "Do you really want to remove this %s?"), $type)
|
|
|
|
)
|
2007-07-19 12:40:28 +02:00
|
|
|
)
|
|
|
|
);
|
2008-02-25 03:10:37 +01:00
|
|
|
$deleteAction->addExtraClass('delete');
|
|
|
|
|
|
|
|
return $form;
|
2007-07-19 12:40:28 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Save the data in this form.
|
|
|
|
*/
|
|
|
|
function save($data, $form) {
|
2007-12-02 22:35:17 +01:00
|
|
|
if($data['ImageSource'] != 'existing' && $data['Upload']['size'] == 0) {
|
2007-10-29 02:35:33 +01:00
|
|
|
// No image has been uploaded
|
|
|
|
Director::redirectBack();
|
|
|
|
return;
|
|
|
|
}
|
2007-07-19 12:40:28 +02:00
|
|
|
$owner = DataObject::get_by_id($data['Class'], $data['ID']);
|
|
|
|
$fieldName = $data['Field'] . 'ID';
|
2008-02-25 03:10:37 +01:00
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
if($data['ImageSource'] == 'existing') {
|
2007-10-29 02:35:33 +01:00
|
|
|
if(!$data['ExistingFile']) {
|
|
|
|
// No image has been selected
|
|
|
|
Director::redirectBack();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
$owner->$fieldName = $data['ExistingFile'];
|
|
|
|
|
|
|
|
// Edit the class name, if applicable
|
|
|
|
$existingFile = DataObject::get_by_id("File", $data['ExistingFile']);
|
|
|
|
$desiredClass = $owner->has_one($data['Field']);
|
2008-02-25 03:10:37 +01:00
|
|
|
|
|
|
|
// Unless specifically asked, we don't want the user to be able
|
|
|
|
// to select a folder
|
|
|
|
if(is_a($existingFile, 'Folder') && $desiredClass != 'Folder') {
|
|
|
|
Director::redirectBack();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
if(!is_a($existingFile, $desiredClass)) {
|
|
|
|
$existingFile->ClassName = $desiredClass;
|
|
|
|
$existingFile->write();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// TODO We need to replace this with a way to get the type of a field
|
|
|
|
$imageClass = $owner->has_one($data['Field']);
|
|
|
|
|
|
|
|
// If we can't find the relationship, assume its an Image.
|
2008-09-23 04:18:02 +02:00
|
|
|
if( !$imageClass) $imageClass = 'Image';
|
2007-07-19 12:40:28 +02:00
|
|
|
|
|
|
|
// Assuming its a decendant of File
|
|
|
|
$image = new $imageClass();
|
|
|
|
$image->loadUploaded($data['Upload']);
|
|
|
|
$owner->$fieldName = $image->ID;
|
|
|
|
|
|
|
|
// store the owner id with the uploaded image
|
|
|
|
$member = Member::currentUser();
|
|
|
|
$image->OwnerID = $member->ID;
|
|
|
|
$image->write();
|
|
|
|
}
|
|
|
|
|
|
|
|
$owner->write();
|
|
|
|
Director::redirectBack();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Delete the image referenced by this form.
|
|
|
|
*/
|
|
|
|
function delete($data, $form) {
|
2007-11-01 06:31:58 +01:00
|
|
|
$owner = DataObject::get_by_id( $data[ 'Class' ], $data[ 'ID' ] );
|
|
|
|
$fieldName = $data[ 'Field' ] . 'ID';
|
|
|
|
$owner->$fieldName = 0;
|
|
|
|
$owner->write();
|
2007-07-19 12:40:28 +02:00
|
|
|
Director::redirect($this->Link('iframe'));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Flush all of the generated images.
|
|
|
|
*/
|
|
|
|
function flush() {
|
2008-02-25 03:10:37 +01:00
|
|
|
if(!Permission::check('ADMIN')) Security::permissionFailure($this);
|
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
$images = DataObject::get("Image","");
|
|
|
|
$numItems = 0;
|
|
|
|
$num = 0;
|
|
|
|
|
|
|
|
foreach($images as $image) {
|
|
|
|
$numDeleted = $image->deleteFormattedImages();
|
|
|
|
if($numDeleted) {
|
|
|
|
$numItems++;
|
|
|
|
}
|
|
|
|
$num += $numDeleted;
|
|
|
|
}
|
|
|
|
echo $num . ' formatted images from ' . $numItems . ' items flushed';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-10-08 00:03:53 +02:00
|
|
|
?>
|