2012-01-09 17:32:27 +01:00
|
|
|
<?php
|
2012-03-08 21:08:12 +01:00
|
|
|
class CMSFileAddController extends LeftAndMain {
|
2012-01-09 17:32:27 +01:00
|
|
|
|
2013-03-18 11:47:15 +01:00
|
|
|
private static $url_segment = 'assets/add';
|
|
|
|
private static $url_priority = 60;
|
|
|
|
private static $required_permission_codes = 'CMS_ACCESS_AssetAdmin';
|
|
|
|
private static $menu_title = 'Files';
|
|
|
|
private static $tree_class = 'Folder';
|
2016-07-28 20:50:21 +02:00
|
|
|
|
2012-02-03 00:11:11 +01:00
|
|
|
// public function upload($request) {
|
|
|
|
// $formHtml = $this->renderWith(array('AssetAdmin_UploadContent'));
|
2012-04-05 14:45:26 +02:00
|
|
|
// if($request->isAjax()) {
|
2012-02-03 00:11:11 +01:00
|
|
|
// return $formHtml;
|
|
|
|
// } else {
|
|
|
|
// return $this->customise(array(
|
|
|
|
// 'Content' => $formHtml
|
|
|
|
// ))->renderWith(array('AssetAdmin', 'LeftAndMain'));
|
|
|
|
// }
|
|
|
|
// }
|
2012-03-08 21:08:12 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Custom currentPage() method to handle opening the 'root' folder
|
|
|
|
*/
|
|
|
|
public function currentPage() {
|
|
|
|
$id = $this->currentPageID();
|
2012-03-08 22:18:07 +01:00
|
|
|
if($id && is_numeric($id) && $id > 0) {
|
2012-09-21 05:35:53 +02:00
|
|
|
$folder = DataObject::get_by_id('Folder', $id);
|
|
|
|
if($folder && $folder->exists()) {
|
|
|
|
return $folder;
|
|
|
|
}
|
2012-03-08 21:08:12 +01:00
|
|
|
}
|
2012-09-21 05:35:53 +02:00
|
|
|
return new Folder();
|
2012-03-08 21:08:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return fake-ID "root" if no ID is found (needed to upload files into the root-folder)
|
|
|
|
*/
|
|
|
|
public function currentPageID() {
|
2016-07-28 20:50:21 +02:00
|
|
|
$request = $this->getRequest();
|
|
|
|
if (is_numeric($request->requestVar('ID'))) {
|
|
|
|
return $request->requestVar('ID');
|
|
|
|
} elseif (is_numeric($request->param('ID'))) {
|
|
|
|
return $request->param('ID');
|
2012-03-08 21:08:12 +01:00
|
|
|
} else {
|
2012-03-08 22:18:07 +01:00
|
|
|
return 0;
|
2012-03-08 21:08:12 +01:00
|
|
|
}
|
2012-03-07 17:02:08 +01:00
|
|
|
}
|
|
|
|
|
2012-02-03 00:11:11 +01:00
|
|
|
/**
|
2014-02-10 21:35:13 +01:00
|
|
|
* @param null $id Not used.
|
|
|
|
* @param null $fields Not used.
|
2012-02-03 00:11:11 +01:00
|
|
|
* @return Form
|
|
|
|
* @todo what template is used here? AssetAdmin_UploadContent.ss doesn't seem to be used anymore
|
|
|
|
*/
|
2012-02-10 23:15:41 +01:00
|
|
|
public function getEditForm($id = null, $fields = null) {
|
2012-04-12 10:36:25 +02:00
|
|
|
Requirements::javascript(FRAMEWORK_DIR . '/javascript/AssetUploadField.js');
|
|
|
|
Requirements::css(FRAMEWORK_DIR . '/css/AssetUploadField.css');
|
2012-02-03 00:11:11 +01:00
|
|
|
|
2012-02-21 21:17:56 +01:00
|
|
|
$folder = $this->currentPage();
|
|
|
|
|
2012-04-04 16:59:22 +02:00
|
|
|
$uploadField = UploadField::create('AssetUploadField', '');
|
2012-02-03 00:11:11 +01:00
|
|
|
$uploadField->setConfig('previewMaxWidth', 40);
|
|
|
|
$uploadField->setConfig('previewMaxHeight', 30);
|
2013-11-06 10:08:15 +01:00
|
|
|
$uploadField->setConfig('changeDetection', false);
|
2012-02-03 00:11:11 +01:00
|
|
|
$uploadField->addExtraClass('ss-assetuploadfield');
|
|
|
|
$uploadField->removeExtraClass('ss-uploadfield');
|
|
|
|
$uploadField->setTemplate('AssetUploadField');
|
2012-03-08 22:18:07 +01:00
|
|
|
|
2012-09-21 05:35:53 +02:00
|
|
|
if($folder->exists() && $folder->getFilename()) {
|
2012-03-02 15:43:22 +01:00
|
|
|
// The Upload class expects a folder relative *within* assets/
|
|
|
|
$path = preg_replace('/^' . ASSETS_DIR . '\//', '', $folder->getFilename());
|
|
|
|
$uploadField->setFolderName($path);
|
2012-03-08 22:17:05 +01:00
|
|
|
} else {
|
2012-09-21 05:35:53 +02:00
|
|
|
$uploadField->setFolderName('/'); // root of the assets
|
2012-02-03 00:11:11 +01:00
|
|
|
}
|
|
|
|
|
2012-03-27 02:40:23 +02:00
|
|
|
$exts = $uploadField->getValidator()->getAllowedExtensions();
|
|
|
|
asort($exts);
|
2012-10-16 07:43:10 +02:00
|
|
|
$uploadField->Extensions = implode(', ', $exts);
|
2012-03-27 02:40:23 +02:00
|
|
|
|
2016-01-06 00:42:07 +01:00
|
|
|
$form = CMSForm::create(
|
2012-03-26 23:18:05 +02:00
|
|
|
$this,
|
2013-07-02 09:33:38 +02:00
|
|
|
'EditForm',
|
2012-03-26 23:18:05 +02:00
|
|
|
new FieldList(
|
2016-07-28 20:50:21 +02:00
|
|
|
$uploadField,
|
2012-03-26 23:18:05 +02:00
|
|
|
new HiddenField('ID')
|
|
|
|
),
|
2012-03-02 15:43:22 +01:00
|
|
|
new FieldList()
|
2013-07-02 09:33:38 +02:00
|
|
|
)->setHTMLID('Form_EditForm');
|
2013-05-10 15:00:57 +02:00
|
|
|
$form->setResponseNegotiator($this->getResponseNegotiator());
|
2012-02-15 19:35:11 +01:00
|
|
|
$form->addExtraClass('center cms-edit-form ' . $this->BaseCSSClasses());
|
2012-03-07 17:02:08 +01:00
|
|
|
// Don't use AssetAdmin_EditForm, as it assumes a different panel structure
|
2012-03-08 21:08:12 +01:00
|
|
|
$form->setTemplate($this->getTemplatesWithSuffix('_EditForm'));
|
2012-02-21 21:17:56 +01:00
|
|
|
$form->Fields()->push(
|
|
|
|
new LiteralField(
|
|
|
|
'BackLink',
|
|
|
|
sprintf(
|
|
|
|
'<a href="%s" class="backlink ss-ui-button cms-panel-link" data-icon="back">%s</a>',
|
|
|
|
Controller::join_links(singleton('AssetAdmin')->Link('show'), $folder ? $folder->ID : 0),
|
|
|
|
_t('AssetAdmin.BackToFolder', 'Back to folder')
|
|
|
|
)
|
|
|
|
)
|
|
|
|
);
|
2012-03-02 15:43:22 +01:00
|
|
|
$form->loadDataFrom($folder);
|
2012-02-21 21:17:56 +01:00
|
|
|
|
2014-08-01 00:37:11 +02:00
|
|
|
$this->extend('updateEditForm', $form);
|
|
|
|
|
2012-01-09 17:32:27 +01:00
|
|
|
return $form;
|
|
|
|
}
|
|
|
|
|
2012-03-07 17:02:08 +01:00
|
|
|
/**
|
2014-02-10 21:35:13 +01:00
|
|
|
* @param bool $unlinked
|
2012-03-08 21:08:12 +01:00
|
|
|
* @return ArrayList
|
2012-03-07 17:02:08 +01:00
|
|
|
*/
|
2012-03-08 21:08:12 +01:00
|
|
|
public function Breadcrumbs($unlinked = false) {
|
|
|
|
$items = parent::Breadcrumbs($unlinked);
|
|
|
|
|
|
|
|
// The root element should explicitly point to the root node.
|
2012-03-08 22:18:07 +01:00
|
|
|
$items[0]->Link = Controller::join_links(singleton('AssetAdmin')->Link('show'), 0);
|
|
|
|
|
|
|
|
// Enforce linkage of hierarchy to AssetAdmin
|
|
|
|
foreach($items as $item) {
|
|
|
|
$baselink = $this->Link('show');
|
|
|
|
if(strpos($item->Link, $baselink) !== false) {
|
|
|
|
$item->Link = str_replace($baselink, singleton('AssetAdmin')->Link('show'), $item->Link);
|
|
|
|
}
|
|
|
|
}
|
2012-03-08 21:08:12 +01:00
|
|
|
|
|
|
|
$items->push(new ArrayData(array(
|
|
|
|
'Title' => _t('AssetAdmin.Upload', 'Upload'),
|
|
|
|
'Link' => $this->Link()
|
|
|
|
)));
|
2016-07-28 20:50:21 +02:00
|
|
|
|
2012-03-08 21:08:12 +01:00
|
|
|
return $items;
|
2012-02-15 19:35:11 +01:00
|
|
|
}
|
2012-01-09 17:32:27 +01:00
|
|
|
|
2012-03-26 23:18:05 +02:00
|
|
|
}
|