Permalink
Browse files

MINOR Fixed merge errors

  • Loading branch information...
1 parent a220d37 commit 495e15be9f44d1b2cbe25953156d3d5c0f930e1b @chillu chillu committed Mar 15, 2011
Showing with 99 additions and 352 deletions.
  1. +67 −253 code/AssetAdmin.php
  2. +4 −3 code/CMSMain.php
  3. +5 −2 code/LeftAndMain.php
  4. +23 −94 code/SecurityAdmin.php
View
@@ -24,8 +24,6 @@ class AssetAdmin extends LeftAndMain {
static $allowed_actions = array(
'addfolder',
- 'deletefolder',
- 'deletemarked',
'DeleteItemsForm',
'doUpload',
'getsubtree',
@@ -36,8 +34,7 @@ class AssetAdmin extends LeftAndMain {
'uploadiframe',
'UploadForm',
'deleteUnusedThumbnails' => 'ADMIN',
- 'batchactions',
- 'BatchActionsForm',
+ 'SyncForm',
);
/**
@@ -293,6 +290,71 @@ function doUpload($data, $form) {
</script>
HTML;
}
+
+ /**
+ * Add a new group and return its details suitable for ajax.
+ *
+ * @todo Move logic into Folder class, and use LeftAndMain->doAdd() default implementation.
+ */
+ public function doAdd($data, $form) {
+ $class = $this->stat('tree_class');
+
+ // check create permissions
+ if(!singleton($class)->canCreate()) return Security::permissionFailure($this);
+
+ // check addchildren permissions
+ if(
+ singleton($class)->hasDatabaseField('Hierarchy')
+ && isset($data['ParentID'])
+ && is_numeric($data['ParentID'])
+ ) {
+ $parentRecord = DataObject::get_by_id($class, $data['ParentID']);
+ if(
+ $parentRecord->hasMethod('canAddChildren')
+ && !$parentRecord->canAddChildren()
+ ) return Security::permissionFailure($this);
+ }
+
+ $parent = (isset($data['ParentID']) && is_numeric($data['ParentID'])) ? (int)$data['ParentID'] : 0;
+ $name = (isset($data['Name'])) ? basename($data['Name']) : _t('AssetAdmin.NEWFOLDER',"NewFolder");
+ if(!isset($parentRecord) || !$parentRecord->ID) $parent = 0;
+
+ // Get the folder to be created
+ if(isset($parentRecord->ID)) $filename = $parentRecord->FullPath . $name;
+ else $filename = ASSETS_PATH . '/' . $name;
+
+ // Actually create
+ if(!file_exists(ASSETS_PATH)) {
+ mkdir(ASSETS_PATH);
+ }
+
+ $record = new Folder();
+ $record->ParentID = $parent;
+
+ // Ensure uniqueness
+ $i = 2;
+ $baseFilename = substr($record->Filename, 0, -1) . '-';
+ while(file_exists($record->FullPath)) {
+ $record->Filename = $baseFilename . $i . '/';
+ $i++;
+ }
+
+ $record->Name = $record->Title = basename($record->Filename);
+ $record->write();
+
+ mkdir($record->FullPath);
+ chmod($record->FullPath, Filesystem::$file_create_mask);
+
+ // Used in TinyMCE inline folder creation
+ if(isset($data['returnID'])) {
+ return $record->ID;
+ } else if($this->isAjax()) {
+ $form = $this->getEditForm($record->ID);
+ return $form->formHtmlContent();
+ } else {
+ return $this->redirect(Controller::join_links($this->Link('show'), $record->ID));
+ }
+ }
/**
* Custom currentPage() method to handle opening the 'root' folder
@@ -306,200 +368,22 @@ public function currentPage() {
}
}
- /**
- * Return the form that displays the details of a folder, including a file list and fields for editing the folder name.
- */
- function getEditForm($id = null) {
- if($id && $id != "root") {
- $record = DataObject::get_by_id("File", $id);
- } else {
- $record = singleton("Folder");
- }
-
- if($record) {
- $fields = $record->getCMSFields();
- $actions = new FieldSet();
-
- // Only show save button if not 'assets' folder
- if($record->canEdit() && $id != 'root') {
- $actions = new FieldSet(
- new FormAction('save',_t('AssetAdmin.SAVEFOLDERNAME','Save folder name'))
- );
- }
-
- $form = new Form($this, "EditForm", $fields, $actions);
- if($record->ID) {
- $form->loadDataFrom($record);
- } else {
- $form->loadDataFrom(array(
- "ID" => "root",
- "URL" => Director::absoluteBaseURL() . 'assets/',
- ));
- }
-
- if(!$record->canEdit()) {
- $form->makeReadonly();
- }
-
- $this->extend('updateEditForm', $form);
-
- return $form;
- }
- }
-
function getSiteTreeFor($className, $rootID = null, $childrenMethod = null, $numChildrenMethod = null, $filterFunction = null, $minNodeCount = 30) {
if (!$childrenMethod) $childrenMethod = 'ChildFolders';
return parent::getSiteTreeFor($className, $rootID, $childrenMethod, $numChildrenMethod, $filterFunction, $minNodeCount);
}
-
- /**
- * Perform the "delete marked" action.
- * Called and returns in same way as 'save' function
- */
- public function deletemarked($urlParams, $form) {
- $fileList = "'" . ereg_replace(' *, *',"','",trim(addslashes($_REQUEST['FileIDs']))) . "'";
- $numFiles = 0;
- $folderID = 0;
- $deleteList = '';
- $brokenPageList = '';
-
- if($fileList != "''") {
- $files = DataObject::get("File", "\"File\".\"ID\" IN ($fileList)");
- if($files) {
- $brokenPages = array();
- foreach($files as $file) {
- $brokenPages = array_merge($brokenPages, $file->BackLinkTracking()->toArray());
- if($file instanceof Image) {
- $file->deleteFormattedImages();
- }
- if(!$folderID) {
- $folderID = $file->ParentID;
- }
- $file->delete();
- $numFiles++;
- }
- if($brokenPages) {
- $brokenPageList = " ". _t('AssetAdmin.NOWBROKEN', 'These pages now have broken links:') . '</ul>';
- foreach($brokenPages as $brokenPage) {
- $brokenPageList .= "<li style=&quot;font-size: 65%&quot;>" . $brokenPage->Breadcrumbs(3, true) . '</li>';
- }
- $brokenPageList .= '</ul>';
- } else {
- $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');";
- }
- } else {
- user_error("No files in $fileList could be found!", E_USER_ERROR);
- }
- }
-
- $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();
- }
public function getCMSTreeTitle() {
return Director::absoluteBaseURL() . "assets";
}
- /**
- * 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);
- $saved = sprintf(_t('AssetAdmin.SAVEDFILE','Saved file %s'),"#$data[ID]");
- echo <<<JS
- statusMessage('$saved');
- $('record-$data[ID]').getElementsByTagName('td')[1].innerHTML = "$title";
- $('record-$data[ID]').getElementsByTagName('td')[2].innerHTML = "$name";
-JS;
- }
-
- public function sync() {
- echo Filesystem::sync();
- }
-
- /**
- * Return the entire site tree as a nested UL.
- * @return string HTML for site tree
- */
public function SiteTreeAsUL() {
- $obj = singleton('Folder');
- $obj->setMarkingFilter('ClassName', ClassInfo::subclassesFor('Folder'));
- $obj->markPartialTree(30, null, "ChildFolders");
-
- if($p = $this->currentPage()) $obj->markToExpose($p);
-
- // getChildrenAsUL is a flexible and complex way of traversing the tree
- $siteTreeList = $obj->getChildrenAsUL(
- '',
- '"<li id=\"record-$child->ID\" class=\"$child->class" . $child->markingClasses() . ($extraArg->isCurrentPage($child) ? " current" : "") . "\">" . ' .
- '"<a href=\"" . Controller::join_links(substr($extraArg->Link(),0,-1), "show", $child->ID) . "\" class=\"" . ($child->hasChildFolders() ? " contents" : "") . "\" >" . $child->TreeTitle() . "</a>" ',
- $this,
- true,
- "ChildFolders"
- );
-
- // Wrap the root if needs be
- $rootLink = $this->Link() . 'show/root';
- $baseUrl = Director::absoluteBaseURL() . "assets";
- if(!isset($rootID)) {
- $siteTree = "<ul id=\"sitetree\" class=\"tree unformatted\"><li id=\"record-root\" class=\"Root\"><a href=\"$rootLink\"><strong>{$baseUrl}</strong></a>"
- . $siteTreeList . "</li></ul>";
- }
-
- return $siteTree;
+ return $this->getSiteTreeFor($this->stat('tree_class'), null, 'ChildFolders');
}
- /**
- * Returns a subtree of items underneat the given folder.
- */
- public function getsubtree() {
- $obj = DataObject::get_by_id('Folder', $_REQUEST['ID']);
- $obj->setMarkingFilter('ClassName', ClassInfo::subclassesFor('Folder'));
- $obj->markPartialTree();
-
- $results = $obj->getChildrenAsUL(
- '',
- '"<li id=\"record-$child->ID\" class=\"$child->class" . $child->markingClasses() . ($extraArg->isCurrentPage($child) ? " current" : "") . "\">" . ' .
- '"<a href=\"" . Controller::join_links(substr($extraArg->Link(),0,-1), "show", $child->ID) . "\" >" . $child->TreeTitle() . "</a>" ',
- $this,
- true
- );
-
- return substr(trim($results), 4, -5);
- }
-
-
//------------------------------------------------------------------------------------------//
// Data saving handlers
-
- /**
- * Add a new folder and return its details suitable for ajax.
- */
- public function addfolder($request) {
- // Protect against CSRF on destructive action
- if(!SecurityToken::inst()->checkRequest($request)) return $this->httpError(400);
-
- $parent = ($_REQUEST['ParentID'] && is_numeric($_REQUEST['ParentID'])) ? (int)$_REQUEST['ParentID'] : 0;
- $name = (isset($_REQUEST['Name'])) ? basename($_REQUEST['Name']) : _t('AssetAdmin.NEWFOLDER',"NewFolder");
- }
-
/**
* @return Form
*/
@@ -522,76 +406,6 @@ function SyncForm() {
}
/**
- * Delete a folder
- */
- public function deletefolder($data, $form) {
- $ids = split(' *, *', $_REQUEST['csvIDs']);
-
- if(!$ids) return false;
- $script = '';
-
- foreach($ids as $id) {
- if(is_numeric($id)) {
- $record = DataObject::get_by_id($this->stat('tree_class'), $id);
- if($record) {
- $script .= $this->deleteTreeNodeJS($record);
- $record->delete();
- $record->destroy();
- }
- }
- }
-
- $size = sizeof($ids);
- if($size > 1) {
- $message = $size.' '._t('AssetAdmin.FOLDERSDELETED', 'folders deleted.');
- } else {
- $message = $size.' '._t('AssetAdmin.FOLDERDELETED', 'folder deleted.');
- }
-
- $script .= "statusMessage('$message');";
-
- return $script;
- }
-
- public function removefile($request){
- // Protect against CSRF on destructive action
- if(!SecurityToken::inst()->checkRequest($request)) return $this->httpError(400);
-
- if($fileID = $this->urlParams['ID']) {
- $file = DataObject::get_by_id('File', $fileID);
- // Delete the temp verions of this file in assets/_resampled
- if($file instanceof Image) {
- $file->deleteFormattedImages();
- }
- $file->delete();
- $file->destroy();
-
- if(Director::is_ajax()) {
- echo <<<JS
- $('Form_EditForm_Files').removeFile($fileID);
- statusMessage('removed file', 'good');
-JS;
- } else {
- Director::redirectBack();
- }
- } else {
- 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') {
- FormResponse::status_message('Saved', 'good');
- return FormResponse::respond();
- }
-
- $form->dataFieldByName('Name')->Value = $form->dataFieldByName('Title')->Value();
-
- return parent::save($urlParams, $form);
- }
-
- /**
* #################################
* Garbage collection.
* #################################
View
@@ -45,6 +45,7 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr
'SideReportsForm',
'submit',
'versions',
+ 'VersionsForm',
'EditForm',
'AddForm',
'SearchTreeForm',
@@ -875,8 +876,8 @@ function ReportFormParameters() {
/**
* @return Form
*/
- function doShowSideReport() {
- $reportClass = $this->urlParams['ID'];
+ function doShowSideReport($data, $form) {
+ $reportClass = (isset($data['ReportClass'])) ? $data['ReportClass'] : $this->urlParams['ID'];
$reports = $this->SideReports();
if(isset($reports[$reportClass])) {
$report = $reports[$reportClass];
@@ -1091,7 +1092,7 @@ function getversion() {
SSViewer::setOption('rewriteHashlinks', false);
if(Director::is_ajax()) {
- $result = $templateData->renderWith($this->class . '_right');
+ $result = $templateData->renderWith(array($this->class . '_right', 'LeftAndMain_right'));
$parts = split('</?form[^>]*>', $result);
$content = $parts[sizeof($parts)-2];
if($this->ShowSwitchView()) {
Oops, something went wrong.

0 comments on commit 495e15b

Please sign in to comment.