API CHANGE Removed ImageEditor functionality, please use thirdparty modules, e.g. "silverstripe-pixlr" (http://github.com/nyeholt/silverstripe-pixlr) (from r104987)

git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/cms/trunk@112462 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
Ingo Schommer 2010-10-15 01:48:00 +00:00
parent 0ac0beca47
commit 2bdf183521
5 changed files with 0 additions and 479 deletions

View File

@ -9,7 +9,6 @@ Director::addRules(50, array(
'processes//$Action/$ID/$Batch' => 'BatchProcess_Controller',
'admin/help//$Action/$ID' => 'CMSHelp',
'admin/bulkload//$Action/$ID/$OtherID' => 'BulkLoaderAdmin',
'admin//ImageEditor/$Action' => 'ImageEditor',
'admin/cms//$Action/$ID/$OtherID' => 'CMSMain',
'PageComment//$Action/$ID' => 'PageComment_Controller',
'dev/buildcache/$Action' => 'RebuildStaticCacheTask',

View File

@ -72,7 +72,6 @@ class AssetTableField extends ComplexTableField {
$ret = parent::FieldHolder();
Requirements::javascript(CMS_DIR . '/javascript/AssetTableField.js');
Requirements::javascript('cms/javascript/ImageEditor/Activator.js');
return $ret;
}

View File

@ -1,264 +0,0 @@
<?php
/**
* This Controller handles all operation needed for ImageEditor to work(expect for GD operations).
* @package cms
* @subpackage assets
*/
class ImageEditor extends Controller {
static $allowed_actions = array(
'*' => 'CMS_ACCESS_CMSMain'
);
public $fileToEdit = "";
public $fileToEditOnlyName = "";
/**
* Includes all JS required for ImageEditor. This method requires setting
* a fileToEdit URL in POST.
*
* @return String
*/
public function index() {
Requirements::clear();
Requirements::javascript(SAPPHIRE_DIR . '/thirdparty/prototype/prototype.js');
Requirements::javascript(SAPPHIRE_DIR . '/thirdparty/scriptaculous/scriptaculous.js');
Requirements::javascript(CMS_DIR . '/javascript/ImageEditor/Utils.js');
//Requirements::javascript(CMS_DIR . '/javascript/ImageEditor/ImageHistory.js');
Requirements::javascript(CMS_DIR . '/javascript/ImageEditor/Image.js');
//Requirements::javascript(CMS_DIR . '/javascript/ImageEditor/ImageTransformation.js');
Requirements::javascript(CMS_DIR . '/javascript/ImageEditor/Resizeable.js');
Requirements::javascript(CMS_DIR . '/javascript/ImageEditor/Effects.js');
Requirements::javascript(CMS_DIR . '/javascript/ImageEditor/Environment.js');
Requirements::javascript(CMS_DIR . '/javascript/ImageEditor/Crop.js');
Requirements::javascript(CMS_DIR . '/javascript/ImageEditor/Resize.js');
Requirements::javascript(CMS_DIR . '/javascript/ImageEditor/ImageBox.js');
Requirements::javascript(CMS_DIR . '/javascript/ImageEditor/ImageEditor.js');
Requirements::javascript(CMS_DIR . '/javascript/ImageEditor/DocumentBody.js');
Requirements::javascript(SAPPHIRE_DIR . '/thirdparty/behaviour/behaviour.js');
Requirements::javascript(CMS_DIR . '/javascript/LeftAndMain.js');
Requirements::css(CMS_DIR . 'css/ImageEditor/ImageEditor.css');
if(!isset($this->requestParams['fileToEdit'])) $this->raiseError();
$fileWithPath = $this->requestParams['fileToEdit'];
$this->fileToEdit = $this->file2Origin($fileWithPath);
$this->fileToEditOnlyName = $this->urlToFilename($this->fileToEdit);
return $this->renderWith(__CLASS__);
}
/**
* Method is used for manipulating photos.
* Method requires two params set in POST
* file - file on which operation will be performed
* command - name of operation(crop|rotate|resize)
*
* Each operation requires additional parameters.
*
* @return String - JSON array with image properties (width,height,url).
*/
public function manipulate() {
$fileName = $this->requestParams['file'];
if(strpos($fileName,'?') !== false) $fileName = substr($fileName,0,strpos($fileName,'?'));
$command = $this->requestParams['command'];
$this->checkFileExists($fileName);
$fileInfo = pathinfo($fileName);
$gd = new GD($this->url2File($fileName));
switch($command) {
case 'rotate':
$gd = $gd->rotate(90);
break;
case 'resize':
$imageNewWidth = $_POST['newImageWidth'];
$imageNewHeight = $_POST['newImageHeight'];
$gd = $gd->resize($imageNewWidth,$imageNewHeight);
break;
case 'crop':
$top = $_POST['top'];
$left = $_POST['left'];
$width = $_POST['width'];
$height = $_POST['height'];
$gd = $gd->crop($top,$left,$width,$height);
break;
case 'greyscale':
$gd = $gd->greyscale();
break;
case 'sepia':
$gd = $gd->sepia();
break;
case 'blur':
$gd = $gd->blur();
break;
case 'adjust-contrast':
$value = intval($_POST['value']);
$gd = $gd->contrast($value);
break;
case 'adjust-brightness':
$value = intval($_POST['value']);
$gd = $gd->brightness($value);
break;
case 'adjust-gamma':
$value = floatval($_POST['value']);
$gd = $gd->gamma($value);
break;
}
$rand = md5(rand(1,100000));
$gd->writeTo(ASSETS_PATH . '/_tmp/' . $rand . '.' . $fileInfo['extension']);
return $this->getImageInfoInJSON($gd,ASSETS_PATH . '/_tmp/' . $rand . '.' . $fileInfo['extension']);
}
/**
* Method is used for saving photos.
* Method requires two params set in POST
* originalFile - this file will be replaced by second file
* editedFile - this file will replace first file.
*
* After replacing original file all thumbnails created from it are removed.
*
* @return String - Message that everything went ok.
*/
public function save() {
if(isset($this->requestParams['originalFile']) && isset($this->requestParams['editedFile'])) {
$originalFile = $this->requestParams['originalFile'];
$editedFile = $this->requestParams['editedFile'];
if(strpos($originalFile,'?') !== false) $originalFile = substr($originalFile,0,strpos($originalFile,'?'));
if($this->checkFileExists($originalFile) && $this->checkFileExists($editedFile)) {
if($editedFile != $originalFile && copy($this->url2File($editedFile),$this->url2File($originalFile))) {
$image = DataObject::get_one('File','"Filename" = \'' . substr($this->url2File($originalFile),3) . '\'');
$image->deleteFormattedImages();
$image->generateFormattedImage('AssetLibraryPreview');
} else {
$this->raiseError();
}
} else {
$this->raiseError();
}
} else {
$this->raiseError();
}
return 'parent.parent.parent.statusMessage(\'Image saved\',\'good\',false);';
}
/**
* Method is invoked when ImageEditor is closed whether image is saved or not.
*
* /assets/tmp is folder where we store temporary images created during editing so
* after closing they are no necessity to keep them.
*
* @return null
*/
public function close() {
$tmpDir = ASSETS_PATH . '/_tmp';
if(file_exists($tmpDir)) {
Filesystem::removeFolder($tmpDir);
mkdir($tmpDir, Filesystem::$folder_create_mask);
}
}
/**
* Method return JSON array containing info about image.
*
* @param gd - GD object used for retrieving info about image
* @param file
*
* @return string JSON array explained in manipulate method comment
*/
private function getImageInfoInJSON(GD $gd,$file) {
return '{"fileName":"' . $file . '","width":' . $gd->getWidth() . ',"height":' . $gd->getHeight() . '}';
}
/**
* Method converts thumbnail file name to file name of it's "parent"
*
* @param file - name of thumbnail file
*
* @return string name of parent file.
*/
private function file2Origin($file) {
$file = str_replace('_resampled/','',$file);
$file = str_replace('_resampled/','',$file);
$file = str_replace('AssetLibraryPreview-','',$file);
$this->checkFileExists($file);
return $file;
}
/**
* Method converts URL of file to file path in file system.
*
* @param url - url of file
*
* @return string path of file in file system
*/
private function url2File($url) {
return '..' . substr($url,strpos($url,'/assets'));
}
/**
* Method checks if file exists and have proper name and extension.
*
* If any of constraints aren't fulfilled method will generate error.
*
* @param url - url of file
*
* @return boolean
*/
private function checkFileExists($url) {
if(strpos($url,'?') !== false) $url = substr($url,0,strpos($url,'?'));
$pathInfo = pathinfo($url);
if(count($pathInfo) < 3) $this->raiseError();
if(!in_array($pathInfo['extension'],array('jpeg','jpg','jpe','png','gif','JPEG','JPG','JPE','PNG','GIF'))) $this->raiseError();
$path = explode('/',$pathInfo['dirname']);
if(count($path) > 1) {
$assetId = array_search('assets',$path);
if($assetId > 0) {
$realPath = '../' . implode('/',array_slice($path,$assetId,count($path) - $assetId));
if(strpos($pathInfo['basename'],'AssetLibraryPreview') !== false) {
$realPath .= '/' . substr($pathInfo['basename'],strpos($pathInfo['basename'],'-'));
} else {
$realPath .= '/' . $pathInfo['basename'];
}
} else {
$this->raiseError();
}
if(file_exists($realPath)) {
return true;
} else {
$this->raiseError();
}
} else {
$this->raiseError();
}
}
/**
* Method raiser error. Error is showed using statusMessage function.
*
* @param message - error message
*
*/
private function raiseError($message = "") {
echo "parent.parent.parent.statusMessage('Error: " . $message . "','bad',false);";
exit();
}
/**
* Method converts retrieves filename from url
*
* @param url
*
*/
private function urlToFilename($url) {
$path = pathinfo($url);
return $path['filename'] . "." . substr($path['extension'],0,strpos($path['extension'],'?'));
}
}
?>

View File

@ -258,28 +258,6 @@ $lang['en_US']['GroupImportForm']['Help2'] = '<div class="advanced">
$lang['en_US']['GroupImportForm']['ResultCreated'] = 'Created %d groups';
$lang['en_US']['GroupImportForm']['ResultDeleted'] = 'Deleted %d groups';
$lang['en_US']['GroupImportForm']['ResultUpdated'] = 'Updated %d groups';
$lang['en_US']['ImageEditor.ss']['ACTIONS'] = 'actions';
$lang['en_US']['ImageEditor.ss']['ADJUST'] = 'adjust';
$lang['en_US']['ImageEditor.ss']['APPLY'] = 'apply';
$lang['en_US']['ImageEditor.ss']['BLUR'] = 'blur';
$lang['en_US']['ImageEditor.ss']['BRIGHTNESS'] = 'brightness';
$lang['en_US']['ImageEditor.ss']['CANCEL'] = 'cancel';
$lang['en_US']['ImageEditor.ss']['CONTRAST'] = 'contrast';
$lang['en_US']['ImageEditor.ss']['CROP'] = 'crop';
$lang['en_US']['ImageEditor.ss']['CURRENTACTION'] = 'current&nbsp;action';
$lang['en_US']['ImageEditor.ss']['EDITFUNCTIONS'] = 'edit&nbsp;functions';
$lang['en_US']['ImageEditor.ss']['EFFECTS'] = 'effects';
$lang['en_US']['ImageEditor.ss']['EXIT'] = 'exit';
$lang['en_US']['ImageEditor.ss']['GAMMA'] = 'gamma';
$lang['en_US']['ImageEditor.ss']['GREYSCALE'] = 'greyscale';
$lang['en_US']['ImageEditor.ss']['HEIGHT'] = 'height';
$lang['en_US']['ImageEditor.ss']['REDO'] = 'redo';
$lang['en_US']['ImageEditor.ss']['ROT'] = 'rotate';
$lang['en_US']['ImageEditor.ss']['SAVE'] = 'save&nbsp;image';
$lang['en_US']['ImageEditor.ss']['SEPIA'] = 'sepia';
$lang['en_US']['ImageEditor.ss']['UNDO'] = 'undo';
$lang['en_US']['ImageEditor.ss']['UNTITLED'] = 'Untitled Document';
$lang['en_US']['ImageEditor.ss']['WIDTH'] = 'width';
$lang['en_US']['LeftAndMain']['CANT_REORGANISE'] = 'You do not have permission to rearange the site tree. Your change was not saved.';
$lang['en_US']['LeftAndMain']['HELP'] = array(
'Help',

View File

@ -1,191 +0,0 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" debug=true>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" />
<% base_tag %>
<title><% _t('UNTITLED','Untitled Document') %></title>
<meta http-equiv="imagetoolbar" content="no">
</head>
<body id="body" class="$CSSClasses" onload="ImageEditor.imageEditor = new ImageEditor.Main.initialize('$fileToEdit');">
<div id="Loading" style="background: #FFF url(cms/images/loading.gif) 50% 50% no-repeat; position: absolute;z-index: 100000;height: 100%;width: 100%;margin: 0;padding: 0;z-index: 100000;position: absolute;">Loading...</div>
<div id="Main">
<script type="text/javascript">
</script>
<div id="MenuBar">
<div id="TopLeft"></div>
<div id="TopRight"></div>
<div id="Filename">
<p>$fileToEditOnlyName</p>
</div>
<div id="Actions">
<a id="SaveButton" href="#a">
<div id="SaveIcon">
</div>
<p id="SaveText" class="menuText">
<% _t('SAVE','save&nbsp;image') %>
</p>
</a>
<a id="ExitButton" href="#a">
<div id="ExitIcon">
</div>
<p id="ExitText" class="menuText">
<% _t('EXIT', 'exit') %>
</p>
</a>
<a id="UndoButton" href="#a">
<div id="UndoIcon">
</div>
<p id="UndoText" class="menuText">
<% _t('UNDO','undo') %>
</p>
</a>
<a id="RedoButton" href="#a">
<div id="RedoIcon">
</div>
<p id="RedoText" class="menuText">
<% _t('REDO','redo') %>
</p>
</a>
<p id="ActionsDescription" class="menuText">
<% _t('ACTIONS', 'actions') %>
</p>
</div>
<div id="Effects">
<a id="GreyscaleButton" href="#a">
<div id="GreyscaleIcon"></div>
<p id="GreyscaleText" class="menuText">
<% _t('GREYSCALE','greyscale') %>
</p>
</a>
<a id="SepiaButton" href="#a">
<div id="SepiaIcon"></div>
<p id="SepiaText" class="menuText">
<% _t('SEPIA','sepia') %>
</p>
</a>
<a id="BlurButton" href="#a">
<div id="BlurIcon"></div>
<p id="BlurText" class="menuText">
<% _t('BLUR','blur') %>
</p>
</a>
<a id="AdjustButton" href="#a">
<div id="AdjustIcon"></div>
<p id="AdjustText" class="menuText">
<% _t('ADJUST','adjust') %>
</p>
</a>
<div id="AdjustMenu">
<div id="AdjustMenuContrastSlider">
<div id="AdjustMenuContrastSliderTrack" class="sliderTrack">
<div id="AdjustMenuContrastSliderTrackHandler" class="sliderTrackHandler">
</div>
</div>
</div>
<p id="AdjustMenuConstrastDescription" class="menuText effectDescription">
<% _t('CONTRAST','contrast') %>
</p>
<div id="AdjustMenuBrightnessSlider">
<div id="AdjustMenuBrightnessSliderTrack" class="sliderTrack">
<div id="AdjustMenuBrightnessSliderTrackHandler" class="sliderTrackHandler">
</div>
</div>
</div>
<p id="AdjustMenuBrightnessDescription" class="menuText effectDescription">
<% _t('BRIGHTNESS','brightness') %>
</p>
<div id="AdjustMenuGammaSlider">
<div id="AdjustMenuGammaSliderTrack" class="sliderTrack">
<div id="AdjustMenuGammaSliderTrackHandler" class="sliderTrackHandler">
</div>
</div>
</div>
<p id="AdjustMenuGammaDescription" class="menuText effectDescription">
<% _t('GAMMA','gamma') %>
</p>
<p id="AdjustMenuDescription" class="menuText">
<% _t('ADJUST','adjust') %>
</p>
</div>
<p id="EffectsDescription" class="menuText">
<% _t('EFFECTS','effects') %>
</p>
</div>
<div id="Functions">
<a id="RotateButton" href="#a">
<div id="RotateIcon">
</div>
<p id="RotateText" class="menuText">
<% _t('ROT','rotate') %>
</p>
</a>
<a id="CropButton" href="#a">
<div id="CropIcon"></div>
<p id="CropText" class="menuText">
<% _t('CROP','crop') %>
</p>
</a>
<div id="ImageSize">
<p id="ImageWidthLabel" class="menuText"><% _t('WIDTH','width') %></p>
<p id="ImageHeightLabel" class="menuText"><% _t('HEIGHT','height') %></p>
<p id="ImageWidth" class="menuText"></p>
<p id="ImageHeight" class="menuText"></p>
</div>
<p id="FunctionsDescription" class="menuText">
<% _t('EDITFUNCTIONS', 'edit&nbsp;functions') %>
</p>
</div>
<div id="CurrentAction">
<a id="CancelButton" href="#a">
<div id="CancelIcon">
</div>
<p id="CancelText" class="menuText">
<% _t('CANCEL','cancel') %>
</p>
</a>
<a id="ApplyButton" href="#a">
<div id="ApplyIcon">
</div>
<p id="ApplyText" class="menuText">
<% _t('APPLY', 'apply') %>
</p>
</a>
<p id="CurrentActionDescription" class="menuText">
<% _t('CURRENTACTION', 'current&nbsp;action') %>
</p>
</div>
</div>
<div id="TopRuler"></div>
<div id="LeftRuler"></div>
<div id="imageEditorContainer">
<div id="imageContainer">
<div id="leftGreyBox" class="greyBox"></div>
<div id="rightGreyBox" class="greyBox"></div>
<div id="upperGreyBox" class="greyBox"></div>
<div id="lowerGreyBox" class="greyBox"></div>
<img id="image" src="#" alt=""/>
<div id="cropBox"></div>
<div id="loadingIndicatorContainer">
<img id="loadingIndicator" alt="" src="cms/images/ImageEditor/indicator.gif">
</div>
</div>
</div>
</div>
<div id="fakeImgContainer">
<img id="fakeImg" src="#" alt=""/>
</div>
<div id="loadingIndicatorContainer2">
<img id="loadingIndicator2" alt="" src="cms/images/ImageEditor/indicator.gif">
</div>
<p id="statusMessage" style="visibility:hidden"></p>
<script type="text/javascript">
if(window.onload) old_onload = window.onload;
window.onload = function() {
Element.hide($('Loading'));
old_onload();
};
</script>
</body>
</html>