2007-07-19 12:40:05 +02:00
|
|
|
|
<?php
|
|
|
|
|
/**
|
|
|
|
|
* AssetAdmin is the 'file store' section of the CMS.
|
|
|
|
|
* It provides an interface for maniupating the File and Folder objects in the system.
|
2008-04-06 10:20:13 +02:00
|
|
|
|
*
|
2008-02-25 03:10:37 +01:00
|
|
|
|
* @package cms
|
|
|
|
|
* @subpackage assets
|
2007-07-19 12:40:05 +02:00
|
|
|
|
*/
|
|
|
|
|
class AssetAdmin extends LeftAndMain {
|
2008-04-06 10:20:13 +02:00
|
|
|
|
|
2008-11-02 22:27:55 +01:00
|
|
|
|
static $url_segment = 'assets';
|
|
|
|
|
|
|
|
|
|
static $url_rule = '/$Action/$ID';
|
|
|
|
|
|
|
|
|
|
static $menu_title = 'Files & Images';
|
|
|
|
|
|
2008-12-04 23:38:58 +01:00
|
|
|
|
public static $tree_class = 'File';
|
2008-04-06 10:20:13 +02:00
|
|
|
|
|
|
|
|
|
/**
|
2008-10-02 02:34:41 +02:00
|
|
|
|
* @see Upload->allowedMaxFileSize
|
2008-04-06 10:20:13 +02:00
|
|
|
|
* @var int
|
|
|
|
|
*/
|
|
|
|
|
public static $allowed_max_file_size;
|
|
|
|
|
|
2008-02-25 03:10:37 +01:00
|
|
|
|
static $allowed_actions = array(
|
|
|
|
|
'addfolder',
|
|
|
|
|
'deletefolder',
|
|
|
|
|
'deletemarked',
|
2009-01-06 03:18:33 +01:00
|
|
|
|
'DeleteItemsForm',
|
2008-02-25 03:10:37 +01:00
|
|
|
|
'doUpload',
|
|
|
|
|
'getfile',
|
|
|
|
|
'getsubtree',
|
|
|
|
|
'movemarked',
|
|
|
|
|
'removefile',
|
|
|
|
|
'savefile',
|
2010-03-02 03:35:55 +01:00
|
|
|
|
'sync',
|
2008-02-25 03:10:37 +01:00
|
|
|
|
'uploadiframe',
|
2008-08-09 07:57:44 +02:00
|
|
|
|
'UploadForm',
|
2010-11-17 06:21:03 +01:00
|
|
|
|
'deleteUnusedThumbnails' => 'ADMIN',
|
|
|
|
|
'SitetreeAsUL'
|
2008-02-25 03:10:37 +01:00
|
|
|
|
);
|
2007-07-19 12:40:05 +02:00
|
|
|
|
|
2010-03-16 03:28:29 +01:00
|
|
|
|
/**
|
|
|
|
|
* @var boolean Enables upload of additional textual information
|
|
|
|
|
* alongside each file (through multifile.js), which makes
|
|
|
|
|
* batch changes easier.
|
|
|
|
|
*
|
|
|
|
|
* CAUTION: This is an unstable API which might change.
|
|
|
|
|
*/
|
2010-03-16 03:32:49 +01:00
|
|
|
|
public static $metadata_upload_enabled = false;
|
2010-03-16 03:28:29 +01:00
|
|
|
|
|
2007-07-19 12:40:05 +02:00
|
|
|
|
/**
|
|
|
|
|
* Return fake-ID "root" if no ID is found (needed to upload files into the root-folder)
|
|
|
|
|
*/
|
|
|
|
|
public function currentPageID() {
|
|
|
|
|
if(isset($_REQUEST['ID']) && is_numeric($_REQUEST['ID'])) {
|
|
|
|
|
return $_REQUEST['ID'];
|
|
|
|
|
} elseif (is_numeric($this->urlParams['ID'])) {
|
|
|
|
|
return $this->urlParams['ID'];
|
|
|
|
|
} elseif(is_numeric(Session::get("{$this->class}.currentPage"))) {
|
|
|
|
|
return Session::get("{$this->class}.currentPage");
|
|
|
|
|
} else {
|
|
|
|
|
return "root";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Set up the controller, in particular, re-sync the File database with the assets folder./
|
|
|
|
|
*/
|
|
|
|
|
function init() {
|
|
|
|
|
parent::init();
|
2007-10-29 03:10:59 +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/cms/trunk@63154 467b73ca-7a2a-4603-9d3b-597d59a354a9
2008-09-27 18:02:38 +02:00
|
|
|
|
if(!file_exists(ASSETS_PATH)) {
|
|
|
|
|
mkdir(ASSETS_PATH);
|
2007-10-29 03:10:59 +01:00
|
|
|
|
}
|
2007-07-19 12:40:05 +02:00
|
|
|
|
|
|
|
|
|
// needed for MemberTableField (Requirements not determined before Ajax-Call)
|
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@63154 467b73ca-7a2a-4603-9d3b-597d59a354a9
2008-09-27 18:02:38 +02:00
|
|
|
|
Requirements::css(THIRDPARTY_DIR . "/greybox/greybox.css");
|
|
|
|
|
Requirements::css(SAPPHIRE_DIR . "/css/ComplexTableField.css");
|
|
|
|
|
|
|
|
|
|
Requirements::javascript(CMS_DIR . "/javascript/AssetAdmin.js");
|
2007-07-19 12:40:05 +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/cms/trunk@63154 467b73ca-7a2a-4603-9d3b-597d59a354a9
2008-09-27 18:02:38 +02:00
|
|
|
|
Requirements::javascript(THIRDPARTY_DIR . "/greybox/AmiJS.js");
|
|
|
|
|
Requirements::javascript(THIRDPARTY_DIR . "/greybox/greybox.js");
|
|
|
|
|
Requirements::css(THIRDPARTY_DIR . "/greybox/greybox.css");
|
2007-09-27 22:56:55 +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/cms/trunk@63154 467b73ca-7a2a-4603-9d3b-597d59a354a9
2008-09-27 18:02:38 +02:00
|
|
|
|
Requirements::css(CMS_DIR . "/css/AssetAdmin.css");
|
2008-11-22 04:47:56 +01:00
|
|
|
|
|
|
|
|
|
Requirements::customScript(<<<JS
|
|
|
|
|
_TREE_ICONS = {};
|
|
|
|
|
_TREE_ICONS['Folder'] = {
|
2009-11-26 06:08:34 +01:00
|
|
|
|
fileIcon: 'sapphire/javascript/tree/images/page-closedfolder.gif',
|
|
|
|
|
openFolderIcon: 'sapphire/javascript/tree/images/page-openfolder.gif',
|
|
|
|
|
closedFolderIcon: 'sapphire/javascript/tree/images/page-closedfolder.gif'
|
2008-11-22 04:47:56 +01:00
|
|
|
|
};
|
|
|
|
|
JS
|
|
|
|
|
);
|
2007-07-19 12:40:05 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Show the content of the upload iframe. The form is specified by a template.
|
|
|
|
|
*/
|
|
|
|
|
function uploadiframe() {
|
|
|
|
|
Requirements::clear();
|
|
|
|
|
|
2009-11-26 06:08:34 +01:00
|
|
|
|
Requirements::javascript(SAPPHIRE_DIR . "/thirdparty/prototype/prototype.js");
|
|
|
|
|
Requirements::javascript(SAPPHIRE_DIR . '/javascript/loader.js');
|
|
|
|
|
Requirements::javascript(SAPPHIRE_DIR . "/thirdparty/behaviour/behaviour.js");
|
|
|
|
|
Requirements::javascript(SAPPHIRE_DIR . "/javascript/prototype_improvements.js");
|
|
|
|
|
Requirements::javascript(SAPPHIRE_DIR . "/javascript/layout_helpers.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@63154 467b73ca-7a2a-4603-9d3b-597d59a354a9
2008-09-27 18:02:38 +02:00
|
|
|
|
Requirements::javascript(CMS_DIR . "/javascript/LeftAndMain.js");
|
2009-11-26 06:08:34 +01:00
|
|
|
|
Requirements::javascript(CMS_DIR . "/thirdparty/multifile/multifile.js");
|
|
|
|
|
Requirements::css(CMS_DIR . "/thirdparty/multifile/multifile.css");
|
2010-02-16 05:00:59 +01:00
|
|
|
|
Requirements::javascript(SAPPHIRE_DIR . "/thirdparty/jquery/jquery.js");
|
|
|
|
|
Requirements::javascript(SAPPHIRE_DIR . "/javascript/jquery_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@63154 467b73ca-7a2a-4603-9d3b-597d59a354a9
2008-09-27 18:02:38 +02:00
|
|
|
|
Requirements::css(CMS_DIR . "/css/typography.css");
|
|
|
|
|
Requirements::css(CMS_DIR . "/css/layout.css");
|
|
|
|
|
Requirements::css(CMS_DIR . "/css/cms_left.css");
|
|
|
|
|
Requirements::css(CMS_DIR . "/css/cms_right.css");
|
2007-07-19 12:40:05 +02:00
|
|
|
|
|
|
|
|
|
if(isset($data['ID']) && $data['ID'] != 'root') $folder = DataObject::get_by_id("Folder", $data['ID']);
|
|
|
|
|
else $folder = singleton('Folder');
|
|
|
|
|
|
2008-11-07 13:21:41 +01:00
|
|
|
|
return array( 'CanUpload' => $folder->canEdit());
|
2007-07-19 12:40:05 +02:00
|
|
|
|
}
|
|
|
|
|
|
2010-02-16 05:00:59 +01:00
|
|
|
|
/**
|
2010-03-16 03:28:29 +01:00
|
|
|
|
* Needs to be enabled through {@link AssetAdmin::$metadata_upload_enabled}
|
|
|
|
|
*
|
2010-02-16 05:00:59 +01:00
|
|
|
|
* @return String
|
|
|
|
|
*/
|
|
|
|
|
function UploadMetadataHtml() {
|
2010-03-16 03:28:29 +01:00
|
|
|
|
if(!self::$metadata_upload_enabled) return;
|
|
|
|
|
|
2010-02-16 05:00:59 +01:00
|
|
|
|
$fields = singleton('File')->uploadMetadataFields();
|
|
|
|
|
|
|
|
|
|
// Return HTML with markers for easy replacement
|
|
|
|
|
$fieldHtml = '';
|
|
|
|
|
foreach($fields as $field) $fieldHtml = $fieldHtml . $field->FieldHolder();
|
|
|
|
|
$fieldHtml = preg_replace('/(name|for|id)="(.+?)"/', '$1="$2[__X__]"', $fieldHtml);
|
|
|
|
|
|
|
|
|
|
// Icky hax to fix certain elements with fixed ids
|
|
|
|
|
$fieldHtml = preg_replace('/-([a-zA-Z0-9]+?)\[__X__\]/', '[__X__]-$1', $fieldHtml);
|
|
|
|
|
|
|
|
|
|
return $fieldHtml;
|
|
|
|
|
}
|
|
|
|
|
|
2007-07-19 12:40:05 +02:00
|
|
|
|
/**
|
|
|
|
|
* Return the form object shown in the uploadiframe.
|
|
|
|
|
*/
|
|
|
|
|
function UploadForm() {
|
2008-04-26 08:39:23 +02:00
|
|
|
|
$form = new Form($this,'UploadForm', new FieldSet(
|
2007-07-19 12:40:05 +02:00
|
|
|
|
new HiddenField("ID", "", $this->currentPageID()),
|
2009-11-17 21:30:27 +01:00
|
|
|
|
new HiddenField("FolderID", "", $this->currentPageID()),
|
2007-07-19 12:40:05 +02:00
|
|
|
|
// needed because the button-action is triggered outside the iframe
|
|
|
|
|
new HiddenField("action_doUpload", "", "1"),
|
2009-02-03 04:46:15 +01:00
|
|
|
|
new FileField("Files[0]" , _t('AssetAdmin.CHOOSEFILE','Choose file: ')),
|
2007-07-19 12:40:05 +02:00
|
|
|
|
new LiteralField('UploadButton',"
|
2009-07-02 09:23:29 +02:00
|
|
|
|
<input type=\"submit\" value=\"". _t('AssetAdmin.UPLOAD', 'Upload Files Listed Below'). "\" name=\"action_upload\" id=\"Form_UploadForm_action_upload\" class=\"action\" />
|
2007-07-19 12:40:05 +02:00
|
|
|
|
"),
|
|
|
|
|
new LiteralField('MultifileCode',"
|
2007-09-16 18:33:05 +02:00
|
|
|
|
<p>" . _t('AssetAdmin.FILESREADY','Files ready to upload:') ."</p>
|
2009-07-02 09:23:29 +02:00
|
|
|
|
<div id=\"Form_UploadForm_FilesList\"></div>
|
2007-07-19 12:40:05 +02:00
|
|
|
|
")
|
|
|
|
|
), new FieldSet(
|
|
|
|
|
));
|
2008-04-26 08:39:23 +02:00
|
|
|
|
|
|
|
|
|
// Makes ajax easier
|
|
|
|
|
$form->disableSecurityToken();
|
|
|
|
|
|
|
|
|
|
return $form;
|
2007-07-19 12:40:05 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* This method processes the results of the UploadForm.
|
|
|
|
|
* It will save the uploaded files to /assets/ and create new File objects as required.
|
|
|
|
|
*/
|
|
|
|
|
function doUpload($data, $form) {
|
2009-12-23 02:53:03 +01:00
|
|
|
|
$newFiles = array();
|
|
|
|
|
$fileIDs = array();
|
|
|
|
|
$fileNames = array();
|
|
|
|
|
$fileSizeWarnings = '';
|
|
|
|
|
$uploadErrors = '';
|
|
|
|
|
$jsErrors = '';
|
|
|
|
|
$status = '';
|
|
|
|
|
$statusMessage = '';
|
2010-02-16 05:00:59 +01:00
|
|
|
|
$processedFiles = array();
|
|
|
|
|
|
|
|
|
|
foreach($data['Files'] as $param => $files) {
|
|
|
|
|
if(!is_array($files)) $files = array($files);
|
|
|
|
|
foreach($files as $key => $value) {
|
|
|
|
|
$processedFiles[$key][$param] = $value;
|
2007-07-19 12:40:05 +02:00
|
|
|
|
}
|
2009-11-13 01:19:55 +01:00
|
|
|
|
}
|
|
|
|
|
|
2010-02-16 05:00:59 +01:00
|
|
|
|
// Load POST data from arrays in to the correct dohickey.
|
|
|
|
|
$processedData = array();
|
|
|
|
|
foreach($data as $dataKey => $value) {
|
|
|
|
|
if ($dataKey == 'Files') continue;
|
|
|
|
|
if (is_array($value)) {
|
|
|
|
|
$i = 0;
|
|
|
|
|
foreach($value as $fileId => $dataValue) {
|
|
|
|
|
if (!isset($processedData[$i])) $processedData[$i] = array();
|
|
|
|
|
$processedData[$i][$dataKey] = $dataValue;
|
|
|
|
|
$i++;
|
|
|
|
|
}
|
|
|
|
|
}
|
2009-11-13 01:19:55 +01:00
|
|
|
|
}
|
2010-02-16 05:00:59 +01:00
|
|
|
|
$processedData = array_reverse($processedData);
|
|
|
|
|
|
2010-03-11 03:43:47 +01:00
|
|
|
|
if($data['FolderID'] && $data['FolderID'] != '') $folder = DataObject::get_by_id("Folder", $data['FolderID']);
|
2010-02-16 05:00:59 +01:00
|
|
|
|
else $folder = singleton('Folder');
|
|
|
|
|
|
|
|
|
|
foreach($processedFiles as $filePostId => $tmpFile) {
|
2008-04-06 10:20:13 +02:00
|
|
|
|
if($tmpFile['error'] == UPLOAD_ERR_NO_TMP_DIR) {
|
2007-08-21 04:32:20 +02:00
|
|
|
|
$status = 'bad';
|
2008-02-25 03:10:37 +01:00
|
|
|
|
$statusMessage = _t('AssetAdmin.NOTEMP', 'There is no temporary folder for uploads. Please set upload_tmp_dir in php.ini.');
|
2007-08-21 04:32:20 +02:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2008-04-06 10:20:13 +02:00
|
|
|
|
if($tmpFile['tmp_name']) {
|
2007-08-21 04:32:20 +02:00
|
|
|
|
// Workaround open_basedir problems
|
|
|
|
|
if(ini_get("open_basedir")) {
|
2008-04-06 10:20:13 +02:00
|
|
|
|
$newtmp = TEMP_FOLDER . '/' . $tmpFile['name'];
|
|
|
|
|
move_uploaded_file($tmpFile['tmp_name'], $newtmp);
|
|
|
|
|
$tmpFile['tmp_name'] = $newtmp;
|
2007-08-21 04:32:20 +02:00
|
|
|
|
}
|
2007-07-19 12:40:05 +02:00
|
|
|
|
|
2008-04-06 10:20:13 +02:00
|
|
|
|
// validate files (only if not logged in as admin)
|
2010-01-13 01:08:01 +01:00
|
|
|
|
if(!File::$apply_restrictions_to_admin && Permission::check('ADMIN')) {
|
2008-04-06 10:20:13 +02:00
|
|
|
|
$valid = true;
|
2007-07-19 12:40:05 +02:00
|
|
|
|
} else {
|
2010-03-01 02:18:01 +01:00
|
|
|
|
|
|
|
|
|
// Set up the validator instance with rules
|
|
|
|
|
$validator = new Upload_Validator();
|
|
|
|
|
$validator->setAllowedExtensions(File::$allowed_extensions);
|
|
|
|
|
$validator->setAllowedMaxFileSize(self::$allowed_max_file_size);
|
|
|
|
|
|
|
|
|
|
// Do the upload validation with the rules
|
2008-04-06 10:20:13 +02:00
|
|
|
|
$upload = new Upload();
|
2010-03-01 02:18:01 +01:00
|
|
|
|
$upload->setValidator($validator);
|
2008-04-06 10:20:13 +02:00
|
|
|
|
$valid = $upload->validate($tmpFile);
|
|
|
|
|
if(!$valid) {
|
|
|
|
|
$errors = $upload->getErrors();
|
|
|
|
|
if($errors) foreach($errors as $error) {
|
|
|
|
|
$jsErrors .= "alert('" . Convert::raw2js($error) . "');";
|
|
|
|
|
}
|
|
|
|
|
}
|
2007-07-19 12:40:05 +02:00
|
|
|
|
}
|
2008-04-06 10:20:13 +02:00
|
|
|
|
|
|
|
|
|
// move file to given folder
|
2010-02-16 05:00:59 +01:00
|
|
|
|
if($valid) {
|
|
|
|
|
$newFile = $folder->addUploadToFolder($tmpFile);
|
|
|
|
|
|
2010-03-16 03:28:29 +01:00
|
|
|
|
if(self::$metadata_upload_enabled && isset($processedData[$filePostId])) {
|
2010-02-16 05:00:59 +01:00
|
|
|
|
$fileObject = DataObject::get_by_id('File', $newFile);
|
|
|
|
|
$metadataForm = new Form($this, 'MetadataForm', $fileObject->uploadMetadataFields(), new FieldSet());
|
|
|
|
|
$metadataForm->loadDataFrom($processedData[$filePostId]);
|
|
|
|
|
$metadataForm->saveInto($fileObject);
|
|
|
|
|
$fileObject->write();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$newFiles[] = $newFile;
|
|
|
|
|
}
|
2007-07-19 12:40:05 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if($newFiles) {
|
|
|
|
|
$numFiles = sizeof($newFiles);
|
2009-12-23 02:53:03 +01:00
|
|
|
|
$statusMessage = sprintf(_t('AssetAdmin.UPLOADEDX',"Uploaded %s files"),$numFiles);
|
2007-07-19 12:40:05 +02:00
|
|
|
|
$status = "good";
|
2007-08-21 04:32:20 +02:00
|
|
|
|
} else if($status != 'bad') {
|
2007-09-16 18:33:05 +02:00
|
|
|
|
$statusMessage = _t('AssetAdmin.NOTHINGTOUPLOAD','There was nothing to upload');
|
2007-07-19 12:40:05 +02:00
|
|
|
|
$status = "";
|
|
|
|
|
}
|
2009-11-13 01:19:55 +01:00
|
|
|
|
|
2010-01-28 22:56:38 +01:00
|
|
|
|
$fileObj = false;
|
2008-02-25 03:10:37 +01:00
|
|
|
|
foreach($newFiles as $newFile) {
|
|
|
|
|
$fileIDs[] = $newFile;
|
2008-11-24 10:30:41 +01:00
|
|
|
|
$fileObj = DataObject::get_one('File', "\"File\".\"ID\"=$newFile");
|
2009-04-29 03:44:28 +02:00
|
|
|
|
// notify file object after uploading
|
|
|
|
|
if (method_exists($fileObj, 'onAfterUpload')) $fileObj->onAfterUpload();
|
2008-02-25 03:10:37 +01:00
|
|
|
|
$fileNames[] = $fileObj->Name;
|
|
|
|
|
}
|
|
|
|
|
|
2010-01-28 22:56:38 +01:00
|
|
|
|
// workaround for content editors image upload.Passing an extra hidden field
|
|
|
|
|
// in the content editors view of 'UploadMode' @see HtmlEditorField
|
|
|
|
|
// this will be refactored for 2.5
|
|
|
|
|
if(isset($data['UploadMode']) && $data['UploadMode'] == "CMSEditor" && $fileObj) {
|
|
|
|
|
// we can use $fileObj considering that the uploader in the cmseditor can only upload
|
|
|
|
|
// one file at a time. Once refactored to multiple files this is going to have to be changed
|
|
|
|
|
$width = (is_a($fileObj, 'Image')) ? $fileObj->getWidth() : '100';
|
|
|
|
|
$height = (is_a($fileObj, 'Image')) ? $fileObj->getHeight() : '100';
|
|
|
|
|
|
|
|
|
|
$values = array(
|
|
|
|
|
'Filename' => $fileObj->Filename,
|
|
|
|
|
'Width' => $width,
|
|
|
|
|
'Height' => $height
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
return Convert::raw2json($values);
|
|
|
|
|
}
|
|
|
|
|
|
2008-02-25 03:10:37 +01:00
|
|
|
|
$sFileIDs = implode(',', $fileIDs);
|
|
|
|
|
$sFileNames = implode(',', $fileNames);
|
2008-04-26 08:39:23 +02:00
|
|
|
|
|
2007-07-19 12:40:05 +02:00
|
|
|
|
echo <<<HTML
|
|
|
|
|
<script type="text/javascript">
|
2008-02-25 03:10:37 +01:00
|
|
|
|
/* IDs: $sFileIDs */
|
|
|
|
|
/* Names: $sFileNames */
|
|
|
|
|
|
2007-07-19 12:40:05 +02:00
|
|
|
|
var form = parent.document.getElementById('Form_EditForm');
|
|
|
|
|
parent.statusMessage("{$statusMessage}","{$status}");
|
2008-04-06 10:20:13 +02:00
|
|
|
|
$jsErrors
|
2007-07-19 12:40:05 +02:00
|
|
|
|
parent.document.getElementById('sitetree').getTreeNodeByIdx( "{$folder->ID}" ).getElementsByTagName('a')[0].className += ' contents';
|
2010-07-19 04:16:21 +02:00
|
|
|
|
form.getPageFromServer(form.elements.ID.value);
|
2007-07-19 12:40:05 +02:00
|
|
|
|
</script>
|
|
|
|
|
HTML;
|
|
|
|
|
}
|
2009-04-29 03:44:28 +02:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Custom currentPage() method to handle opening the 'root' folder
|
|
|
|
|
*/
|
|
|
|
|
public function currentPage() {
|
|
|
|
|
$id = $this->currentPageID();
|
|
|
|
|
if($id && is_numeric($id)) {
|
|
|
|
|
return DataObject::get_by_id($this->stat('tree_class'), $id);
|
|
|
|
|
} else if($id == 'root') {
|
|
|
|
|
return singleton($this->stat('tree_class'));
|
|
|
|
|
}
|
|
|
|
|
}
|
2007-07-19 12:40:05 +02:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Return the form that displays the details of a folder, including a file list and fields for editing the folder name.
|
|
|
|
|
*/
|
|
|
|
|
function getEditForm($id) {
|
|
|
|
|
if($id && $id != "root") {
|
|
|
|
|
$record = DataObject::get_by_id("File", $id);
|
|
|
|
|
} else {
|
|
|
|
|
$record = singleton("Folder");
|
|
|
|
|
}
|
2009-07-02 00:28:06 +02:00
|
|
|
|
|
2008-02-25 03:10:37 +01:00
|
|
|
|
if($record) {
|
|
|
|
|
$fields = $record->getCMSFields();
|
2007-07-19 12:40:05 +02:00
|
|
|
|
$actions = new FieldSet();
|
|
|
|
|
|
2007-09-15 22:47:35 +02:00
|
|
|
|
// Only show save button if not 'assets' folder
|
2008-12-04 23:38:58 +01:00
|
|
|
|
if($record->canEdit() && $id != 'root') {
|
2007-07-19 12:40:05 +02:00
|
|
|
|
$actions = new FieldSet(
|
2007-09-16 18:33:05 +02:00
|
|
|
|
new FormAction('save',_t('AssetAdmin.SAVEFOLDERNAME','Save folder name'))
|
2007-07-19 12:40:05 +02:00
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$form = new Form($this, "EditForm", $fields, $actions);
|
|
|
|
|
if($record->ID) {
|
|
|
|
|
$form->loadDataFrom($record);
|
|
|
|
|
} else {
|
|
|
|
|
$form->loadDataFrom(array(
|
|
|
|
|
"ID" => "root",
|
|
|
|
|
"URL" => Director::absoluteBaseURL() . 'assets/',
|
|
|
|
|
));
|
|
|
|
|
}
|
|
|
|
|
|
2008-12-04 23:38:58 +01:00
|
|
|
|
if(!$record->canEdit()) {
|
2007-07-19 12:40:05 +02:00
|
|
|
|
$form->makeReadonly();
|
2008-12-04 23:38:58 +01:00
|
|
|
|
}
|
2007-07-19 12:40:05 +02:00
|
|
|
|
|
2010-02-11 02:20:20 +01:00
|
|
|
|
$this->extend('updateEditForm', $form);
|
|
|
|
|
|
2007-07-19 12:40:05 +02:00
|
|
|
|
return $form;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Perform the "move marked" action.
|
2007-09-15 22:47:35 +02:00
|
|
|
|
* Called and returns in same way as 'save' function
|
2007-07-19 12:40:05 +02:00
|
|
|
|
*/
|
2007-09-15 22:47:35 +02:00
|
|
|
|
public function movemarked($urlParams, $form) {
|
2009-02-03 03:50:25 +01:00
|
|
|
|
if($_REQUEST['DestFolderID'] && (is_numeric($_REQUEST['DestFolderID']) || ($_REQUEST['DestFolderID']) == 'root')) {
|
|
|
|
|
$destFolderID = ($_REQUEST['DestFolderID'] == 'root') ? 0 : $_REQUEST['DestFolderID'];
|
2011-09-15 14:36:47 +02:00
|
|
|
|
$fileList = "'" . ereg_replace(' *, *',"','",trim(Convert::raw2sql($_REQUEST['FileIDs']))) . "'";
|
2007-07-19 12:40:05 +02:00
|
|
|
|
$numFiles = 0;
|
|
|
|
|
|
|
|
|
|
if($fileList != "''") {
|
2008-11-24 10:30:41 +01:00
|
|
|
|
$files = DataObject::get("File", "\"File\".\"ID\" IN ($fileList)");
|
2007-07-19 12:40:05 +02:00
|
|
|
|
if($files) {
|
|
|
|
|
foreach($files as $file) {
|
2007-09-15 22:30:54 +02:00
|
|
|
|
if($file instanceof Image) {
|
2008-12-04 23:38:58 +01:00
|
|
|
|
$file->deleteFormattedImages();
|
|
|
|
|
}
|
2007-07-19 12:40:05 +02:00
|
|
|
|
$file->ParentID = $destFolderID;
|
|
|
|
|
$file->write();
|
|
|
|
|
$numFiles++;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
user_error("No files in $fileList could be found!", E_USER_ERROR);
|
|
|
|
|
}
|
|
|
|
|
}
|
2007-09-15 22:47:35 +02:00
|
|
|
|
|
2007-09-16 18:33:05 +02:00
|
|
|
|
$message = sprintf(_t('AssetAdmin.MOVEDX','Moved %s files'),$numFiles);
|
2008-12-04 23:38:58 +01:00
|
|
|
|
|
2007-09-15 22:47:35 +02:00
|
|
|
|
FormResponse::status_message($message, "good");
|
2009-10-21 06:39:50 +02:00
|
|
|
|
FormResponse::add("$('Form_EditForm_Files').refresh();");
|
2008-12-04 23:38:58 +01:00
|
|
|
|
|
2009-10-21 06:35:25 +02:00
|
|
|
|
return FormResponse::respond();
|
2007-07-19 12:40:05 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Perform the "delete marked" action.
|
2007-09-15 22:47:35 +02:00
|
|
|
|
* Called and returns in same way as 'save' function
|
2007-07-19 12:40:05 +02:00
|
|
|
|
*/
|
2007-09-15 22:47:35 +02:00
|
|
|
|
public function deletemarked($urlParams, $form) {
|
2011-09-15 14:36:47 +02:00
|
|
|
|
$fileList = "'" . ereg_replace(' *, *',"','",trim(Convert::raw2sql($_REQUEST['FileIDs']))) . "'";
|
2008-12-04 23:38:58 +01:00
|
|
|
|
$numFiles = 0;
|
|
|
|
|
$folderID = 0;
|
|
|
|
|
$deleteList = '';
|
|
|
|
|
$brokenPageList = '';
|
|
|
|
|
|
|
|
|
|
if($fileList != "''") {
|
|
|
|
|
$files = DataObject::get("File", "\"File\".\"ID\" IN ($fileList)");
|
|
|
|
|
if($files) {
|
2010-06-11 00:04:22 +02:00
|
|
|
|
$brokenPages = array();
|
2008-12-04 23:38:58 +01:00
|
|
|
|
foreach($files as $file) {
|
2010-06-11 00:04:22 +02:00
|
|
|
|
$brokenPages = array_merge($brokenPages, $file->BackLinkTracking()->toArray());
|
2008-12-04 23:38:58 +01:00
|
|
|
|
if($file instanceof Image) {
|
|
|
|
|
$file->deleteFormattedImages();
|
2007-07-19 12:40:05 +02:00
|
|
|
|
}
|
2008-12-04 23:38:58 +01:00
|
|
|
|
if(!$folderID) {
|
|
|
|
|
$folderID = $file->ParentID;
|
2007-07-19 12:40:05 +02:00
|
|
|
|
}
|
2008-12-04 23:38:58 +01:00
|
|
|
|
$file->delete();
|
|
|
|
|
$numFiles++;
|
|
|
|
|
}
|
2010-06-11 00:04:22 +02:00
|
|
|
|
if($brokenPages) {
|
2008-12-04 23:38:58 +01:00
|
|
|
|
$brokenPageList = " ". _t('AssetAdmin.NOWBROKEN', 'These pages now have broken links:') . '</ul>';
|
|
|
|
|
foreach($brokenPages as $brokenPage) {
|
|
|
|
|
$brokenPageList .= "<li style="font-size: 65%">" . $brokenPage->Breadcrumbs(3, true) . '</li>';
|
2007-07-19 12:40:05 +02:00
|
|
|
|
}
|
2008-12-04 23:38:58 +01:00
|
|
|
|
$brokenPageList .= '</ul>';
|
2007-07-19 12:40:05 +02:00
|
|
|
|
} else {
|
2008-12-04 23:38:58 +01:00
|
|
|
|
$brokenPageList = '';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$deleteList = '';
|
|
|
|
|
if($folderID) {
|
|
|
|
|
$remaining = DB::query("SELECT COUNT(*) FROM \"File\" WHERE \"ParentID\" = $folderID")->value();
|
|
|
|
|
if(!$remaining) $deleteList .= "Element.removeClassName(\$('sitetree').getTreeNodeByIdx('$folderID').getElementsByTagName('a')[0],'contents');";
|
2007-07-19 12:40:05 +02:00
|
|
|
|
}
|
2008-12-04 23:38:58 +01:00
|
|
|
|
} else {
|
|
|
|
|
user_error("No files in $fileList could be found!", E_USER_ERROR);
|
2007-07-19 12:40:05 +02:00
|
|
|
|
}
|
2008-12-04 23:38:58 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$message = sprintf(_t('AssetAdmin.DELETEDX',"Deleted %s files.%s"),$numFiles,$brokenPageList) ;
|
|
|
|
|
|
|
|
|
|
FormResponse::add($deleteList);
|
|
|
|
|
FormResponse::status_message($message, "good");
|
|
|
|
|
FormResponse::add("$('Form_EditForm').getPageFromServer($('Form_EditForm_ID').value)");
|
|
|
|
|
|
|
|
|
|
return FormResponse::respond();
|
2007-07-19 12:40:05 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns the content to be placed in Form_SubForm when editing a file.
|
|
|
|
|
* Called using ajax.
|
|
|
|
|
*/
|
|
|
|
|
public function getfile() {
|
|
|
|
|
SSViewer::setOption('rewriteHashlinks', false);
|
|
|
|
|
|
|
|
|
|
// bdc: only try to return something if user clicked on an object
|
|
|
|
|
if (is_object($this->getSubForm($this->urlParams['ID']))) {
|
|
|
|
|
return $this->getSubForm($this->urlParams['ID'])->formHtmlContent();
|
|
|
|
|
}
|
|
|
|
|
else return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Action handler for the save button on the file subform.
|
|
|
|
|
* Saves the file
|
|
|
|
|
*/
|
|
|
|
|
public function savefile($data, $form) {
|
|
|
|
|
$record = DataObject::get_by_id("File", $data['ID']);
|
|
|
|
|
$form->saveInto($record);
|
|
|
|
|
$record->write();
|
|
|
|
|
$title = Convert::raw2js($record->Title);
|
|
|
|
|
$name = Convert::raw2js($record->Name);
|
2007-09-16 18:33:05 +02:00
|
|
|
|
$saved = sprintf(_t('AssetAdmin.SAVEDFILE','Saved file %s'),"#$data[ID]");
|
2007-07-19 12:40:05 +02:00
|
|
|
|
echo <<<JS
|
2007-09-16 18:33:05 +02:00
|
|
|
|
statusMessage('$saved');
|
2007-07-19 12:40:05 +02:00
|
|
|
|
$('record-$data[ID]').getElementsByTagName('td')[1].innerHTML = "$title";
|
|
|
|
|
$('record-$data[ID]').getElementsByTagName('td')[2].innerHTML = "$name";
|
|
|
|
|
JS;
|
|
|
|
|
}
|
|
|
|
|
|
2010-03-02 03:35:55 +01:00
|
|
|
|
public function sync() {
|
|
|
|
|
echo Filesystem::sync();
|
|
|
|
|
}
|
|
|
|
|
|
2007-07-19 12:40:05 +02:00
|
|
|
|
/**
|
2008-11-06 23:56:24 +01:00
|
|
|
|
* Return the entire site tree as a nested UL.
|
|
|
|
|
* @return string HTML for site tree
|
2008-02-25 03:10:37 +01:00
|
|
|
|
*/
|
2007-07-19 12:40:05 +02:00
|
|
|
|
public function SiteTreeAsUL() {
|
|
|
|
|
$obj = singleton('Folder');
|
2009-03-10 22:59:19 +01:00
|
|
|
|
$obj->setMarkingFilter('ClassName', ClassInfo::subclassesFor('Folder'));
|
2009-07-02 00:28:06 +02:00
|
|
|
|
$obj->markPartialTree(30, null, "ChildFolders");
|
2007-07-19 12:40:05 +02:00
|
|
|
|
|
|
|
|
|
if($p = $this->currentPage()) $obj->markToExpose($p);
|
|
|
|
|
|
|
|
|
|
// getChildrenAsUL is a flexible and complex way of traversing the tree
|
2008-11-06 23:56:24 +01:00
|
|
|
|
$siteTreeList = $obj->getChildrenAsUL(
|
|
|
|
|
'',
|
|
|
|
|
'"<li id=\"record-$child->ID\" class=\"$child->class" . $child->markingClasses() . ($extraArg->isCurrentPage($child) ? " current" : "") . "\">" . ' .
|
2009-11-27 03:11:34 +01:00
|
|
|
|
'"<a href=\"" . Controller::join_links(substr($extraArg->Link(),0,-1), "show", $child->ID) . "\" class=\"" . ($child->hasChildFolders() ? " contents" : "") . "\" >" . $child->TreeTitle() . "</a>" ',
|
2008-11-06 23:56:24 +01:00
|
|
|
|
$this,
|
2009-07-02 00:28:06 +02:00
|
|
|
|
true,
|
|
|
|
|
"ChildFolders"
|
2008-11-06 23:56:24 +01:00
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
// Wrap the root if needs be
|
2007-07-19 12:40:05 +02:00
|
|
|
|
$rootLink = $this->Link() . 'show/root';
|
2009-01-05 07:17:59 +01:00
|
|
|
|
$baseUrl = Director::absoluteBaseURL() . "assets";
|
2008-11-06 23:56:24 +01:00
|
|
|
|
if(!isset($rootID)) {
|
2009-01-05 07:17:59 +01:00
|
|
|
|
$siteTree = "<ul id=\"sitetree\" class=\"tree unformatted\"><li id=\"record-root\" class=\"Root\"><a href=\"$rootLink\"><strong>{$baseUrl}</strong></a>"
|
2008-11-06 23:56:24 +01:00
|
|
|
|
. $siteTreeList . "</li></ul>";
|
|
|
|
|
}
|
2007-07-19 12:40:05 +02:00
|
|
|
|
|
|
|
|
|
return $siteTree;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns a subtree of items underneat the given folder.
|
|
|
|
|
*/
|
|
|
|
|
public function getsubtree() {
|
2008-11-07 00:47:28 +01:00
|
|
|
|
$obj = DataObject::get_by_id('Folder', $_REQUEST['ID']);
|
2009-03-10 22:59:19 +01:00
|
|
|
|
$obj->setMarkingFilter('ClassName', ClassInfo::subclassesFor('Folder'));
|
2007-07-19 12:40:05 +02:00
|
|
|
|
$obj->markPartialTree();
|
|
|
|
|
|
2008-11-07 00:47:28 +01:00
|
|
|
|
$results = $obj->getChildrenAsUL(
|
|
|
|
|
'',
|
|
|
|
|
'"<li id=\"record-$child->ID\" class=\"$child->class" . $child->markingClasses() . ($extraArg->isCurrentPage($child) ? " current" : "") . "\">" . ' .
|
2009-11-27 03:11:34 +01:00
|
|
|
|
'"<a href=\"" . Controller::join_links(substr($extraArg->Link(),0,-1), "show", $child->ID) . "\" >" . $child->TreeTitle() . "</a>" ',
|
2008-11-07 00:47:28 +01:00
|
|
|
|
$this,
|
|
|
|
|
true
|
|
|
|
|
);
|
2007-07-19 12:40:05 +02:00
|
|
|
|
|
2008-11-07 00:47:28 +01:00
|
|
|
|
return substr(trim($results), 4, -5);
|
2007-07-19 12:40:05 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------------------//
|
|
|
|
|
|
|
|
|
|
// Data saving handlers
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Add a new folder and return its details suitable for ajax.
|
|
|
|
|
*/
|
2010-11-01 02:29:02 +01:00
|
|
|
|
public function addfolder($request) {
|
|
|
|
|
// Protect against CSRF on destructive action
|
|
|
|
|
if(!SecurityToken::inst()->checkRequest($request)) return $this->httpError(400);
|
|
|
|
|
|
2009-02-03 04:46:15 +01:00
|
|
|
|
$parent = ($_REQUEST['ParentID'] && is_numeric($_REQUEST['ParentID'])) ? (int)$_REQUEST['ParentID'] : 0;
|
|
|
|
|
$name = (isset($_REQUEST['Name'])) ? basename($_REQUEST['Name']) : _t('AssetAdmin.NEWFOLDER',"NewFolder");
|
2007-07-19 12:40:05 +02:00
|
|
|
|
|
|
|
|
|
if($parent) {
|
2008-10-24 03:23:52 +02:00
|
|
|
|
$parentObj = DataObject::get_by_id('File', $parent);
|
2007-07-19 12:40:05 +02:00
|
|
|
|
if(!$parentObj || !$parentObj->ID) $parent = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Get the folder to be created
|
2009-04-29 03:44:28 +02:00
|
|
|
|
if(isset($parentObj->ID)) $filename = $parentObj->FullPath . $name;
|
|
|
|
|
else $filename = ASSETS_PATH . '/' . $name;
|
|
|
|
|
|
2007-07-19 12:40:05 +02:00
|
|
|
|
// Actually create
|
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@63154 467b73ca-7a2a-4603-9d3b-597d59a354a9
2008-09-27 18:02:38 +02:00
|
|
|
|
if(!file_exists(ASSETS_PATH)) {
|
|
|
|
|
mkdir(ASSETS_PATH);
|
2007-10-29 03:10:59 +01:00
|
|
|
|
}
|
2009-10-31 02:25:32 +01:00
|
|
|
|
|
2009-04-29 03:44:28 +02:00
|
|
|
|
$p = new Folder();
|
|
|
|
|
$p->ParentID = $parent;
|
2009-10-31 02:25:32 +01:00
|
|
|
|
$p->Name = $p->Title = basename($filename);
|
|
|
|
|
|
|
|
|
|
// Ensure uniqueness
|
|
|
|
|
$i = 2;
|
|
|
|
|
$baseFilename = substr($p->Filename, 0, -1) . '-';
|
|
|
|
|
while(file_exists($p->FullPath)) {
|
|
|
|
|
$p->Filename = $baseFilename . $i . '/';
|
|
|
|
|
$i++;
|
|
|
|
|
}
|
|
|
|
|
|
2007-07-19 12:40:05 +02:00
|
|
|
|
$p->write();
|
2009-10-31 02:25:32 +01:00
|
|
|
|
|
|
|
|
|
mkdir($p->FullPath);
|
|
|
|
|
chmod($p->FullPath, Filesystem::$file_create_mask);
|
|
|
|
|
|
2007-11-12 22:47:45 +01:00
|
|
|
|
if(isset($_REQUEST['returnID'])) {
|
|
|
|
|
return $p->ID;
|
|
|
|
|
} else {
|
|
|
|
|
return $this->returnItemToUser($p);
|
|
|
|
|
}
|
2009-10-31 02:25:32 +01:00
|
|
|
|
|
2007-07-19 12:40:05 +02:00
|
|
|
|
}
|
|
|
|
|
|
2009-01-06 03:18:33 +01:00
|
|
|
|
/**
|
|
|
|
|
* @return Form
|
|
|
|
|
*/
|
|
|
|
|
function DeleteItemsForm() {
|
|
|
|
|
$form = new Form(
|
|
|
|
|
$this,
|
|
|
|
|
'DeleteItemsForm',
|
|
|
|
|
new FieldSet(
|
|
|
|
|
new LiteralField('SelectedPagesNote',
|
|
|
|
|
sprintf('<p>%s</p>', _t('AssetAdmin_left.ss.SELECTTODEL','Select the folders that you want to delete and then click the button below'))
|
|
|
|
|
),
|
|
|
|
|
new HiddenField('csvIDs')
|
|
|
|
|
),
|
|
|
|
|
new FieldSet(
|
|
|
|
|
new FormAction('deletefolder', _t('AssetAdmin_left.ss.DELFOLDERS','Delete the selected folders'))
|
|
|
|
|
)
|
|
|
|
|
);
|
|
|
|
|
$form->addExtraClass('actionparams');
|
|
|
|
|
|
|
|
|
|
return $form;
|
|
|
|
|
}
|
|
|
|
|
|
2007-07-19 12:40:05 +02:00
|
|
|
|
/**
|
|
|
|
|
* Delete a folder
|
|
|
|
|
*/
|
2010-11-14 20:39:03 +01:00
|
|
|
|
public function deletefolder($data, $form) {
|
2007-07-19 12:40:05 +02:00
|
|
|
|
$ids = split(' *, *', $_REQUEST['csvIDs']);
|
2008-11-14 01:45:32 +01:00
|
|
|
|
|
|
|
|
|
if(!$ids) return false;
|
2010-03-30 22:57:48 +02:00
|
|
|
|
$script = '';
|
2008-11-14 01:45:32 +01:00
|
|
|
|
|
2007-07-19 12:40:05 +02:00
|
|
|
|
foreach($ids as $id) {
|
2008-12-04 23:38:58 +01:00
|
|
|
|
if(is_numeric($id)) {
|
|
|
|
|
$record = DataObject::get_by_id($this->stat('tree_class'), $id);
|
2009-04-29 03:44:28 +02:00
|
|
|
|
if($record) {
|
|
|
|
|
$script .= $this->deleteTreeNodeJS($record);
|
|
|
|
|
$record->delete();
|
|
|
|
|
$record->destroy();
|
2008-12-04 23:38:58 +01:00
|
|
|
|
}
|
2007-07-19 12:40:05 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
2008-02-25 03:10:37 +01:00
|
|
|
|
|
|
|
|
|
$size = sizeof($ids);
|
2008-12-04 23:38:58 +01:00
|
|
|
|
if($size > 1) {
|
|
|
|
|
$message = $size.' '._t('AssetAdmin.FOLDERSDELETED', 'folders deleted.');
|
|
|
|
|
} else {
|
|
|
|
|
$message = $size.' '._t('AssetAdmin.FOLDERDELETED', 'folder deleted.');
|
|
|
|
|
}
|
2010-03-30 22:57:48 +02:00
|
|
|
|
|
2007-07-19 12:40:05 +02:00
|
|
|
|
$script .= "statusMessage('$message');";
|
2010-03-31 07:00:02 +02:00
|
|
|
|
|
|
|
|
|
return $script;
|
2007-07-19 12:40:05 +02:00
|
|
|
|
}
|
|
|
|
|
|
2010-11-01 02:29:02 +01:00
|
|
|
|
public function removefile($request){
|
|
|
|
|
// Protect against CSRF on destructive action
|
|
|
|
|
if(!SecurityToken::inst()->checkRequest($request)) return $this->httpError(400);
|
|
|
|
|
|
2008-12-04 23:38:58 +01:00
|
|
|
|
if($fileID = $this->urlParams['ID']) {
|
2007-07-19 12:40:05 +02:00
|
|
|
|
$file = DataObject::get_by_id('File', $fileID);
|
2007-09-15 23:57:11 +02:00
|
|
|
|
// Delete the temp verions of this file in assets/_resampled
|
|
|
|
|
if($file instanceof Image) {
|
|
|
|
|
$file->deleteFormattedImages();
|
|
|
|
|
}
|
2007-07-19 12:40:05 +02:00
|
|
|
|
$file->delete();
|
|
|
|
|
$file->destroy();
|
2010-03-31 07:00:02 +02:00
|
|
|
|
|
2010-03-04 05:09:18 +01:00
|
|
|
|
if(Director::is_ajax()) {
|
2007-07-19 12:40:05 +02:00
|
|
|
|
echo <<<JS
|
|
|
|
|
$('Form_EditForm_Files').removeFile($fileID);
|
|
|
|
|
statusMessage('removed file', 'good');
|
|
|
|
|
JS;
|
2008-12-04 23:38:58 +01:00
|
|
|
|
} else {
|
2010-03-04 05:09:18 +01:00
|
|
|
|
Director::redirectBack();
|
2007-07-19 12:40:05 +02:00
|
|
|
|
}
|
2008-12-04 23:38:58 +01:00
|
|
|
|
} else {
|
2007-07-19 12:40:05 +02:00
|
|
|
|
user_error("AssetAdmin::removefile: Bad parameters: File=$fileID", E_USER_ERROR);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function save($urlParams, $form) {
|
|
|
|
|
// Don't save the root folder - there's no database record
|
|
|
|
|
if($_REQUEST['ID'] == 'root') {
|
2008-12-04 23:38:58 +01:00
|
|
|
|
FormResponse::status_message('Saved', 'good');
|
2007-07-19 12:40:05 +02:00
|
|
|
|
return FormResponse::respond();
|
|
|
|
|
}
|
|
|
|
|
|
2010-01-27 23:23:55 +01:00
|
|
|
|
$form->dataFieldByName('Name')->Value = $form->dataFieldByName('Title')->Value();
|
2007-07-19 12:40:05 +02:00
|
|
|
|
|
|
|
|
|
return parent::save($urlParams, $form);
|
|
|
|
|
}
|
2007-10-02 23:34:57 +02:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* #################################
|
|
|
|
|
* Garbage collection.
|
|
|
|
|
* #################################
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/**
|
2009-02-03 04:46:15 +01:00
|
|
|
|
* Removes all unused thumbnails from the file store
|
|
|
|
|
* and returns the status of the process to the user.
|
2008-12-04 23:38:58 +01:00
|
|
|
|
*/
|
2010-11-01 02:29:02 +01:00
|
|
|
|
public function deleteunusedthumbnails($request) {
|
|
|
|
|
// Protect against CSRF on destructive action
|
|
|
|
|
if(!SecurityToken::inst()->checkRequest($request)) return $this->httpError(400);
|
|
|
|
|
|
2009-02-03 04:46:15 +01:00
|
|
|
|
$count = 0;
|
|
|
|
|
$thumbnails = $this->getUnusedThumbnails();
|
|
|
|
|
|
|
|
|
|
if($thumbnails) {
|
|
|
|
|
foreach($thumbnails as $thumbnail) {
|
|
|
|
|
unlink(ASSETS_PATH . "/" . $thumbnail);
|
|
|
|
|
$count++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$message = sprintf(_t('AssetAdmin.THUMBSDELETED', '%s unused thumbnails have been deleted'), $count);
|
|
|
|
|
FormResponse::status_message($message, 'good');
|
|
|
|
|
echo FormResponse::respond();
|
2007-10-02 23:34:57 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2008-12-04 23:38:58 +01:00
|
|
|
|
* Creates array containg all unused thumbnails.
|
|
|
|
|
*
|
|
|
|
|
* Array is created in three steps:
|
2009-02-03 04:46:15 +01:00
|
|
|
|
* 1. Scan assets folder and retrieve all thumbnails
|
|
|
|
|
* 2. Scan all HTMLField in system and retrieve thumbnails from them.
|
|
|
|
|
* 3. Count difference between two sets (array_diff)
|
2008-12-04 23:38:58 +01:00
|
|
|
|
*
|
|
|
|
|
* @return array
|
|
|
|
|
*/
|
2009-02-03 04:46:15 +01:00
|
|
|
|
private function getUnusedThumbnails() {
|
2008-12-04 23:38:58 +01:00
|
|
|
|
$allThumbnails = array();
|
|
|
|
|
$usedThumbnails = array();
|
|
|
|
|
$dirIterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator(ASSETS_PATH));
|
2009-02-03 04:46:15 +01:00
|
|
|
|
$classes = ClassInfo::subclassesFor('SiteTree');
|
2008-12-04 23:38:58 +01:00
|
|
|
|
|
2009-02-03 04:46:15 +01:00
|
|
|
|
if($dirIterator) {
|
|
|
|
|
foreach($dirIterator as $file) {
|
|
|
|
|
if($file->isFile()) {
|
|
|
|
|
if(strpos($file->getPathname(), '_resampled') !== false) {
|
|
|
|
|
$pathInfo = pathinfo($file->getPathname());
|
|
|
|
|
if(in_array(strtolower($pathInfo['extension']), array('jpeg', 'jpg', 'jpe', 'png', 'gif'))) {
|
|
|
|
|
$path = str_replace('\\','/', $file->getPathname());
|
|
|
|
|
$allThumbnails[] = substr($path, strpos($path, '/assets/') + 8);
|
|
|
|
|
}
|
2008-12-04 23:38:58 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2009-02-03 04:46:15 +01:00
|
|
|
|
if($classes) {
|
|
|
|
|
foreach($classes as $className) {
|
|
|
|
|
$SNG_class = singleton($className);
|
|
|
|
|
$objects = DataObject::get($className);
|
|
|
|
|
|
|
|
|
|
if($objects !== NULL) {
|
|
|
|
|
foreach($objects as $object) {
|
|
|
|
|
foreach($SNG_class->db() as $fieldName => $fieldType) {
|
|
|
|
|
if($fieldType == 'HTMLText') {
|
|
|
|
|
$url1 = HTTP::findByTagAndAttribute($object->$fieldName,array('img' => 'src'));
|
|
|
|
|
|
|
|
|
|
if($url1 != NULL) {
|
|
|
|
|
$usedThumbnails[] = substr($url1[0], strpos($url1[0], '/assets/') + 8);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if($object->latestPublished > 0) {
|
|
|
|
|
$object = Versioned::get_latest_version($className, $object->ID);
|
|
|
|
|
$url2 = HTTP::findByTagAndAttribute($object->$fieldName, array('img' => 'src'));
|
|
|
|
|
|
|
|
|
|
if($url2 != NULL) {
|
|
|
|
|
$usedThumbnails[] = substr($url2[0], strpos($url2[0], '/assets/') + 8);
|
|
|
|
|
}
|
|
|
|
|
}
|
2008-12-04 23:38:58 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2009-02-03 04:46:15 +01:00
|
|
|
|
return array_diff($allThumbnails, $usedThumbnails);
|
2008-12-04 23:38:58 +01:00
|
|
|
|
}
|
2009-02-03 04:46:15 +01:00
|
|
|
|
|
2007-11-01 21:58:28 +01:00
|
|
|
|
}
|
2009-04-29 03:44:28 +02:00
|
|
|
|
?>
|