mirror of
https://github.com/silverstripe/silverstripe-cms
synced 2024-10-22 08:05:56 +02:00
MINOR Added php end tag to AssetAdmin, coding conventions
MINOR Fixed tabbing for various functions MINOR Removed commented out code that shouldn't be lying around git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/cms/branches/2.3@66612 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
parent
33c05c65f4
commit
43598d35e1
@ -14,7 +14,7 @@ class AssetAdmin extends LeftAndMain {
|
|||||||
|
|
||||||
static $menu_title = 'Files & Images';
|
static $menu_title = 'Files & Images';
|
||||||
|
|
||||||
public static $tree_class = "File";
|
public static $tree_class = 'File';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see Upload->allowedMaxFileSize
|
* @see Upload->allowedMaxFileSize
|
||||||
@ -150,7 +150,6 @@ class AssetAdmin extends LeftAndMain {
|
|||||||
$form->disableSecurityToken();
|
$form->disableSecurityToken();
|
||||||
|
|
||||||
return $form;
|
return $form;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -218,7 +217,6 @@ class AssetAdmin extends LeftAndMain {
|
|||||||
$status = "";
|
$status = "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
$fileIDs = array();
|
$fileIDs = array();
|
||||||
$fileNames = array();
|
$fileNames = array();
|
||||||
foreach($newFiles as $newFile) {
|
foreach($newFiles as $newFile) {
|
||||||
@ -244,11 +242,6 @@ class AssetAdmin extends LeftAndMain {
|
|||||||
HTML;
|
HTML;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Needs to be overridden to make sure an ID with value "0" is still valid (rootfolder)
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the form that displays the details of a folder, including a file list and fields for editing the folder name.
|
* Return the form that displays the details of a folder, including a file list and fields for editing the folder name.
|
||||||
*/
|
*/
|
||||||
@ -261,11 +254,10 @@ HTML;
|
|||||||
|
|
||||||
if($record) {
|
if($record) {
|
||||||
$fields = $record->getCMSFields();
|
$fields = $record->getCMSFields();
|
||||||
|
|
||||||
$actions = new FieldSet();
|
$actions = new FieldSet();
|
||||||
|
|
||||||
// Only show save button if not 'assets' folder
|
// Only show save button if not 'assets' folder
|
||||||
if( $record->canEdit() && $id != "root") {
|
if($record->canEdit() && $id != 'root') {
|
||||||
$actions = new FieldSet(
|
$actions = new FieldSet(
|
||||||
new FormAction('save',_t('AssetAdmin.SAVEFOLDERNAME','Save folder name'))
|
new FormAction('save',_t('AssetAdmin.SAVEFOLDERNAME','Save folder name'))
|
||||||
);
|
);
|
||||||
@ -281,11 +273,11 @@ HTML;
|
|||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
if( !$record->canEdit() )
|
if(!$record->canEdit()) {
|
||||||
$form->makeReadonly();
|
$form->makeReadonly();
|
||||||
|
}
|
||||||
|
|
||||||
return $form;
|
return $form;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -316,11 +308,13 @@ HTML;
|
|||||||
}
|
}
|
||||||
|
|
||||||
$message = sprintf(_t('AssetAdmin.MOVEDX','Moved %s files'),$numFiles);
|
$message = sprintf(_t('AssetAdmin.MOVEDX','Moved %s files'),$numFiles);
|
||||||
|
|
||||||
FormResponse::status_message($message, "good");
|
FormResponse::status_message($message, "good");
|
||||||
FormResponse::add("$('Form_EditForm').getPageFromServer($('Form_EditForm_ID').value)");
|
FormResponse::add("$('Form_EditForm').getPageFromServer($('Form_EditForm_ID').value)");
|
||||||
|
|
||||||
return FormResponse::respond();
|
return FormResponse::respond();
|
||||||
} else {
|
} else {
|
||||||
user_error("Bad data: $_REQUEST[DestFolderID]", E_USER_ERROR);
|
user_error('Bad data:' . $_REQUEST['DestFolderID'], E_USER_ERROR);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -336,25 +330,24 @@ HTML;
|
|||||||
$brokenPageList = '';
|
$brokenPageList = '';
|
||||||
|
|
||||||
if($fileList != "''") {
|
if($fileList != "''") {
|
||||||
$files = DataObject::get("File", "`File`.ID IN ($fileList)");
|
$files = DataObject::get('File', "`File`.ID IN ($fileList)");
|
||||||
if($files) {
|
if($files) {
|
||||||
foreach($files as $file) {
|
foreach($files as $file) {
|
||||||
if($file instanceof Image) {
|
if($file instanceof Image) {
|
||||||
$file->deleteFormattedImages();
|
$file->deleteFormattedImages();
|
||||||
}
|
}
|
||||||
if( !$folderID )
|
if(!$folderID) {
|
||||||
$folderID = $file->ParentID;
|
$folderID = $file->ParentID;
|
||||||
|
}
|
||||||
// $deleteList .= "\$('Form_EditForm_Files').removeById($file->ID);\n";
|
|
||||||
$file->delete();
|
$file->delete();
|
||||||
$numFiles++;
|
$numFiles++;
|
||||||
}
|
}
|
||||||
if($brokenPages = Notifications::getItems("BrokenLink")) {
|
if($brokenPages = Notifications::getItems('BrokenLink')) {
|
||||||
$brokenPageList = " ". _t('AssetAdmin.NOWBROKEN',"These pages now have broken links:")."</ul>";
|
$brokenPageList = " ". _t('AssetAdmin.NOWBROKEN', 'These pages now have broken links:') . '</ul>';
|
||||||
foreach($brokenPages as $brokenPage) {
|
foreach($brokenPages as $brokenPage) {
|
||||||
$brokenPageList .= "<li style="font-size: 65%">" . $brokenPage->Breadcrumbs(3, true) . "</li>";
|
$brokenPageList .= "<li style="font-size: 65%">" . $brokenPage->Breadcrumbs(3, true) . '</li>';
|
||||||
}
|
}
|
||||||
$brokenPageList .= "</ul>";
|
$brokenPageList .= '</ul>';
|
||||||
Notifications::notifyByEmail("BrokenLink", "Page_BrokenLinkEmail");
|
Notifications::notifyByEmail("BrokenLink", "Page_BrokenLinkEmail");
|
||||||
} else {
|
} else {
|
||||||
$brokenPageList = '';
|
$brokenPageList = '';
|
||||||
@ -363,19 +356,19 @@ HTML;
|
|||||||
$deleteList = '';
|
$deleteList = '';
|
||||||
if($folderID) {
|
if($folderID) {
|
||||||
$remaining = DB::query("SELECT COUNT(*) FROM `File` WHERE `ParentID`=$folderID")->value();
|
$remaining = DB::query("SELECT COUNT(*) FROM `File` WHERE `ParentID`=$folderID")->value();
|
||||||
|
if(!$remaining) $deleteList .= "Element.removeClassName(\$('sitetree').getTreeNodeByIdx('$folderID').getElementsByTagName('a')[0],'contents');";
|
||||||
if( !$remaining )
|
|
||||||
$deleteList .= "Element.removeClassName(\$('sitetree').getTreeNodeByIdx( '$folderID' ).getElementsByTagName('a')[0],'contents');";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
user_error("No files in $fileList could be found!", E_USER_ERROR);
|
user_error("No files in $fileList could be found!", E_USER_ERROR);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$message = sprintf(_t('AssetAdmin.DELETEDX',"Deleted %s files.%s"),$numFiles,$brokenPageList) ;
|
$message = sprintf(_t('AssetAdmin.DELETEDX',"Deleted %s files.%s"),$numFiles,$brokenPageList) ;
|
||||||
|
|
||||||
FormResponse::add($deleteList);
|
FormResponse::add($deleteList);
|
||||||
FormResponse::status_message($message, "good");
|
FormResponse::status_message($message, "good");
|
||||||
FormResponse::add("$('Form_EditForm').getPageFromServer($('Form_EditForm_ID').value)");
|
FormResponse::add("$('Form_EditForm').getPageFromServer($('Form_EditForm_ID').value)");
|
||||||
|
|
||||||
return FormResponse::respond();
|
return FormResponse::respond();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -521,18 +514,12 @@ JS;
|
|||||||
$parentID = (int) $p->ParentID;
|
$parentID = (int) $p->ParentID;
|
||||||
return <<<JS
|
return <<<JS
|
||||||
tree = $('sitetree');
|
tree = $('sitetree');
|
||||||
|
|
||||||
var newNode = tree.createTreeNode($p->ID, "$p->Title", "$p->class");
|
var newNode = tree.createTreeNode($p->ID, "$p->Title", "$p->class");
|
||||||
|
|
||||||
tree.getTreeNodeByIdx($parentID).appendTreeNode(newNode);
|
tree.getTreeNodeByIdx($parentID).appendTreeNode(newNode);
|
||||||
|
|
||||||
newNode.selectTreeNode();
|
newNode.selectTreeNode();
|
||||||
JS;
|
JS;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
Director::redirectBack();
|
Director::redirectBack();
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -546,83 +533,28 @@ JS;
|
|||||||
foreach($ids as $id) {
|
foreach($ids as $id) {
|
||||||
|
|
||||||
if(is_numeric($id)) {
|
if(is_numeric($id)) {
|
||||||
|
|
||||||
$record = DataObject::get_by_id($this->stat('tree_class'), $id);
|
$record = DataObject::get_by_id($this->stat('tree_class'), $id);
|
||||||
|
if(!$record) {
|
||||||
if(!$record)
|
|
||||||
|
|
||||||
Debug::message( "Record appears to be null" );
|
Debug::message( "Record appears to be null" );
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*if($record->hasMethod('BackLinkTracking')) {
|
|
||||||
$brokenPages = $record->BackLinkTracking();
|
|
||||||
|
|
||||||
foreach($brokenPages as $brokenPage) {
|
|
||||||
|
|
||||||
$brokenPageList .= "<li style=\"font-size: 65%\">" . $brokenPage->Breadcrumbs(3, true) . "</li>";
|
|
||||||
|
|
||||||
$brokenPage->HasBrokenLink = true;
|
|
||||||
|
|
||||||
$notifications[$brokenPage->OwnerID][] = $brokenPage;
|
|
||||||
|
|
||||||
$brokenPage->write();
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}*/
|
|
||||||
|
|
||||||
$record->delete();
|
$record->delete();
|
||||||
$record->destroy();
|
$record->destroy();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// DataObject::delete_by_id($this->stat('tree_class'), $id);
|
|
||||||
|
|
||||||
$script .= $this->deleteTreeNodeJS($record);
|
$script .= $this->deleteTreeNodeJS($record);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*if($notifications) foreach($notifications as $memberID => $pages) {
|
|
||||||
|
|
||||||
$email = new Page_BrokenLinkEmail();
|
|
||||||
|
|
||||||
$email->populateTemplate(new ArrayData(array(
|
|
||||||
|
|
||||||
"Recipient" => DataObject::get_by_id("Member", $memberID),
|
|
||||||
|
|
||||||
"BrokenPages" => new DataObjectSet($pages),
|
|
||||||
|
|
||||||
)));
|
|
||||||
|
|
||||||
$email->debug();
|
|
||||||
|
|
||||||
$email->send();
|
|
||||||
|
|
||||||
}*/
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
$s = (sizeof($ids) > 1) ? "s" :"";
|
|
||||||
|
|
||||||
$message = sizeof($ids) . " folder$s deleted.";
|
|
||||||
//
|
|
||||||
if(isset($brokenPageList)) $message .= " The following pages now have broken links:<ul>" . addslashes($brokenPageList) . "</ul>Their owners have been emailed and they will fix up those pages.";
|
|
||||||
*/
|
|
||||||
|
|
||||||
$size = sizeof($ids);
|
$size = sizeof($ids);
|
||||||
if($size > 1)
|
if($size > 1) {
|
||||||
$message = $size.' '._t('AssetAdmin.FOLDERSDELETED', 'folders deleted.');
|
$message = $size.' '._t('AssetAdmin.FOLDERSDELETED', 'folders deleted.');
|
||||||
else
|
} else {
|
||||||
$message = $size.' '._t('AssetAdmin.FOLDERDELETED', 'folder deleted.');
|
$message = $size.' '._t('AssetAdmin.FOLDERDELETED', 'folder deleted.');
|
||||||
|
}
|
||||||
|
|
||||||
if(isset($brokenPageList))
|
if(isset($brokenPageList)) {
|
||||||
$message .= ' '._t('AssetAdmin.NOWBROKEN', 'The following pages now have broken links:').'<ul>'.addslashes($brokenPageList).'</ul>'.
|
$message .= ' '._t('AssetAdmin.NOWBROKEN', 'The following pages now have broken links:').'<ul>'.addslashes($brokenPageList).'</ul>'.
|
||||||
_t('AssetAdmin.NOWBROKEN2', 'Their owners have been emailed and they will fix up those pages.');
|
_t('AssetAdmin.NOWBROKEN2', 'Their owners have been emailed and they will fix up those pages.');
|
||||||
|
}
|
||||||
|
|
||||||
$script .= "statusMessage('$message');";
|
$script .= "statusMessage('$message');";
|
||||||
echo $script;
|
echo $script;
|
||||||
@ -654,11 +586,10 @@ JS;
|
|||||||
public function save($urlParams, $form) {
|
public function save($urlParams, $form) {
|
||||||
// Don't save the root folder - there's no database record
|
// Don't save the root folder - there's no database record
|
||||||
if($_REQUEST['ID'] == 'root') {
|
if($_REQUEST['ID'] == 'root') {
|
||||||
FormResponse::status_message("Saved", "good");
|
FormResponse::status_message('Saved', 'good');
|
||||||
return FormResponse::respond();
|
return FormResponse::respond();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
$form->dataFieldByName('Title')->value = $form->dataFieldByName('Name')->value;
|
$form->dataFieldByName('Title')->value = $form->dataFieldByName('Name')->value;
|
||||||
|
|
||||||
return parent::save($urlParams, $form);
|
return parent::save($urlParams, $form);
|
||||||
@ -672,10 +603,7 @@ JS;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Removes all unused thumbnails, and echos status message to user.
|
* Removes all unused thumbnails, and echos status message to user.
|
||||||
*
|
|
||||||
* @returns null
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public function deleteUnusedThumbnails() {
|
public function deleteUnusedThumbnails() {
|
||||||
foreach($this->getUnusedThumbnailsArray() as $file) {
|
foreach($this->getUnusedThumbnailsArray() as $file) {
|
||||||
unlink(ASSETS_PATH . "/" . $file);
|
unlink(ASSETS_PATH . "/" . $file);
|
||||||
@ -685,17 +613,19 @@ JS;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates array containg all unused thumbnails.
|
* Creates array containg all unused thumbnails.
|
||||||
|
*
|
||||||
* Array is created in three steps:
|
* Array is created in three steps:
|
||||||
* 1.Scan assets folder and retrieve all thumbnails
|
* 1.Scan assets folder and retrieve all thumbnails
|
||||||
* 2.Scan all HTMLField in system and retrieve thumbnails from them.
|
* 2.Scan all HTMLField in system and retrieve thumbnails from them.
|
||||||
* 3.Count difference between two sets (array_diff)
|
* 3.Count difference between two sets (array_diff)
|
||||||
*
|
*
|
||||||
* @returns Array
|
* @return array
|
||||||
*/
|
*/
|
||||||
|
|
||||||
private function getUnusedThumbnailsArray() {
|
private function getUnusedThumbnailsArray() {
|
||||||
$allThumbnails = array();
|
$allThumbnails = array();
|
||||||
|
$usedThumbnails = array();
|
||||||
$dirIterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator(ASSETS_PATH));
|
$dirIterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator(ASSETS_PATH));
|
||||||
|
|
||||||
foreach($dirIterator as $file) {
|
foreach($dirIterator as $file) {
|
||||||
if($file->isFile()) {
|
if($file->isFile()) {
|
||||||
if(strpos($file->getPathname(),"_resampled") !== false) {
|
if(strpos($file->getPathname(),"_resampled") !== false) {
|
||||||
@ -707,8 +637,9 @@ JS;
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$classes = ClassInfo::subclassesFor('SiteTree');
|
$classes = ClassInfo::subclassesFor('SiteTree');
|
||||||
$usedThumbnails = array();
|
|
||||||
foreach($classes as $className) {
|
foreach($classes as $className) {
|
||||||
$sng = singleton($className);
|
$sng = singleton($className);
|
||||||
$objects = DataObject::get($className);
|
$objects = DataObject::get($className);
|
||||||
@ -728,6 +659,10 @@ JS;
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return array_diff($allThumbnails,$usedThumbnails);
|
return array_diff($allThumbnails,$usedThumbnails);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
?>
|
Loading…
Reference in New Issue
Block a user