From df46043a67edd9176d62a53a8af5cc06e44797c5 Mon Sep 17 00:00:00 2001 From: Sean Harvey Date: Thu, 4 Mar 2010 03:40:29 +0000 Subject: [PATCH] MINOR Replaced locations of Director::is_ajax() and Director::redirectBack() with instance method calls - the latter static function is deprecated git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/cms/branches/2.4@100484 467b73ca-7a2a-4603-9d3b-597d59a354a9 --- code/AssetAdmin.php | 4 ++-- code/CMSBatchActionHandler.php | 4 ++-- code/CMSMain.php | 8 ++++---- code/GroupImportForm.php | 2 +- code/LeftAndMain.php | 11 +++++------ code/MemberImportForm.php | 2 +- code/MemberTableField.php | 2 +- code/ModelAdmin.php | 15 ++++++++------- code/ReportAdmin.php | 2 +- code/sitefeatures/PageComment.php | 20 ++++++++++---------- code/sitefeatures/PageCommentInterface.php | 10 +++++----- 11 files changed, 40 insertions(+), 40 deletions(-) diff --git a/code/AssetAdmin.php b/code/AssetAdmin.php index 6ccbef59..42ba389f 100755 --- a/code/AssetAdmin.php +++ b/code/AssetAdmin.php @@ -657,13 +657,13 @@ JS; $file->delete(); $file->destroy(); - if(Director::is_ajax()) { + if($this->isAjax()) { echo <<redirectBack(); } } else { user_error("AssetAdmin::removefile: Bad parameters: File=$fileID", E_USER_ERROR); diff --git a/code/CMSBatchActionHandler.php b/code/CMSBatchActionHandler.php index ff53a0c5..a5f4229b 100644 --- a/code/CMSBatchActionHandler.php +++ b/code/CMSBatchActionHandler.php @@ -49,8 +49,8 @@ class CMSBatchActionHandler extends RequestHandler { function handleAction($request) { // This method can't be called without ajax. - if(!Director::is_ajax()) { - Director::redirectBack(); + if(!$this->parentController->isAjax()) { + $this->parentController->redirectBack(); return; } diff --git a/code/CMSMain.php b/code/CMSMain.php index e459429f..d52b1f0e 100755 --- a/code/CMSMain.php +++ b/code/CMSMain.php @@ -668,7 +668,7 @@ JS; $recordID = $record->ID; $record->delete(); - if(Director::is_ajax()) { + if($this->isAjax()) { // need a valid ID value even if the record doesn't have one in the database // (its still present in the live tables) $liveRecord = Versioned::get_one_by_stage('SiteTree', 'Live', "\"SiteTree_Live\".\"ID\" = $recordID"); @@ -683,7 +683,7 @@ JS; return FormResponse::respond(); } } else { - Director::redirectBack(); + $this->redirectBack(); } } @@ -913,7 +913,7 @@ JS; SSViewer::setOption('rewriteHashlinks', false); - if(Director::is_ajax()) { + if($this->isAjax()) { $result = $templateData->renderWith($this->class . '_right'); $parts = split(']*>', $result); return $parts[sizeof($parts)-2]; @@ -997,7 +997,7 @@ JS; } function sendFormToBrowser($templateData) { - if(Director::is_ajax()) { + if($this->isAjax()) { SSViewer::setOption('rewriteHashlinks', false); $result = $this->customise($templateData)->renderWith($this->class . '_right'); $parts = split(']*>', $result); diff --git a/code/GroupImportForm.php b/code/GroupImportForm.php index a514247d..43233db9 100644 --- a/code/GroupImportForm.php +++ b/code/GroupImportForm.php @@ -83,7 +83,7 @@ class GroupImportForm extends Form { $this->sessionMessage($msg, 'good'); - Director::redirectBack(); + $this->redirectBack(); } } diff --git a/code/LeftAndMain.php b/code/LeftAndMain.php index 025a4e2b..e2df7c12 100644 --- a/code/LeftAndMain.php +++ b/code/LeftAndMain.php @@ -113,7 +113,7 @@ class LeftAndMain extends Controller { ); // set reading lang - if(Object::has_extension('SiteTree', 'Translatable') && !Director::is_ajax()) { + if(Object::has_extension('SiteTree', 'Translatable') && !$this->isAjax()) { Translatable::choose_site_locale(array_keys(Translatable::get_existing_content_languages('SiteTree'))); } @@ -151,7 +151,7 @@ class LeftAndMain extends Controller { if(Director::redirected_to()) return; // Audit logging hook - if(empty($_REQUEST['executeForm']) && !Director::is_ajax()) $this->extend('accessedCMS'); + if(empty($_REQUEST['executeForm']) && !$this->isAjax()) $this->extend('accessedCMS'); // Set the members html editor config HtmlEditorConfig::set_active(Member::currentUser()->getHtmlEditorConfigForCMS()); @@ -352,10 +352,9 @@ class LeftAndMain extends Controller { Session::set('currentMember', $params['OtherID']); } - if(Director::is_ajax()) { + if($this->isAjax()) { SSViewer::setOption('rewriteHashlinks', false); return $this->EditForm()->formHtmlContent(); - } else { return array(); } @@ -576,7 +575,7 @@ class LeftAndMain extends Controller { * and updates the tree via javascript. */ public function returnItemToUser($p) { - if(Director::is_ajax()) { + if($this->isAjax()) { // Prepare the object for insertion. $parentID = (int) $p->ParentID; $id = $p->ID ? $p->ID : "new-$p->class-$p->ParentID"; @@ -670,7 +669,7 @@ JS; $record->Status = ($record->Status == "New page" || $record->Status == "Saved (new)") ? "Saved (new)" : "Saved (update)"; } - if(Director::is_ajax()) { + if($this->isAjax()) { if($SQL_id != $record->ID) { FormResponse::add("$('sitetree').setNodeIdx(\"{$SQL_id}\", \"$record->ID\");"); FormResponse::add("$('Form_EditForm').elements.ID.value = \"$record->ID\";"); diff --git a/code/MemberImportForm.php b/code/MemberImportForm.php index d3df83c5..d126693e 100644 --- a/code/MemberImportForm.php +++ b/code/MemberImportForm.php @@ -87,7 +87,7 @@ class MemberImportForm extends Form { $this->sessionMessage($msg, 'good'); - Director::redirectBack(); + $this->controller->redirectBack(); } /** diff --git a/code/MemberTableField.php b/code/MemberTableField.php index 32bc5cec..aca76634 100755 --- a/code/MemberTableField.php +++ b/code/MemberTableField.php @@ -347,7 +347,7 @@ class MemberTableField extends ComplexTableField { ); $form->sessionMessage($message, 'good'); - Director::redirectBack(); + $this->controller->redirectBack(); } /** diff --git a/code/ModelAdmin.php b/code/ModelAdmin.php index a451f42d..8382f1f6 100755 --- a/code/ModelAdmin.php +++ b/code/ModelAdmin.php @@ -515,7 +515,7 @@ class ModelAdmin_CollectionController extends Controller { // File wasn't properly uploaded, show a reminder to the user if(empty($_FILES['_CsvFile']['tmp_name'])) { $form->sessionMessage(_t('ModelAdmin.NOCSVFILE', 'Please browse for a CSV file to import'), 'good'); - Director::redirectBack(); + $this->redirectBack(); return false; } @@ -542,7 +542,7 @@ class ModelAdmin_CollectionController extends Controller { if(!$results->CreatedCount() && !$results->UpdatedCount()) $message .= _t('ModelAdmin.NOIMPORT', "Nothing to import"); $form->sessionMessage($message, 'good'); - Director::redirectBack(); + $this->redirectBack(); } /** @@ -837,7 +837,7 @@ class ModelAdmin_CollectionController extends Controller { $form->saveInto($model); $model->write(); - if(Director::is_ajax()) { + if($this->isAjax()) { $class = $this->parentController->getRecordControllerClass($this->getModelClass()); $recordController = new $class($this, $request, $model->ID); return new SS_HTTPResponse( @@ -890,7 +890,7 @@ class ModelAdmin_RecordController extends Controller { */ function edit($request) { if ($this->currentRecord) { - if(Director::is_ajax()) { + if($this->isAjax()) { return new SS_HTTPResponse( $this->EditForm()->forAjaxTemplate(), 200, @@ -962,10 +962,10 @@ class ModelAdmin_RecordController extends Controller { // Behaviour switched on ajax. - if(Director::is_ajax()) { + if($this->parentController->isAjax()) { return $this->edit($request); } else { - Director::redirectBack(); + $this->parentController->redirectBack(); } } @@ -976,8 +976,9 @@ class ModelAdmin_RecordController extends Controller { if($this->currentRecord->canDelete(Member::currentUser())) { $this->currentRecord->delete(); Director::redirect($this->parentController->Link('SearchForm?action=search')); + } else { + $this->parentController->redirectBack(); } - else Director::redirectBack(); return; } diff --git a/code/ReportAdmin.php b/code/ReportAdmin.php index dd3619f9..6507e36a 100755 --- a/code/ReportAdmin.php +++ b/code/ReportAdmin.php @@ -95,7 +95,7 @@ class ReportAdmin extends LeftAndMain { if(isset($params['ID'])) Session::set('currentReport', $params['ID']); if(isset($params['OtherID'])) Session::set('currentOtherID', $params['OtherID']); - if(Director::is_ajax()) { + if($this->isAjax()) { SSViewer::setOption('rewriteHashlinks', false); $result = $this->customise(array( diff --git a/code/sitefeatures/PageComment.php b/code/sitefeatures/PageComment.php index 9067d0f7..4684cd2e 100755 --- a/code/sitefeatures/PageComment.php +++ b/code/sitefeatures/PageComment.php @@ -185,10 +185,10 @@ class PageComment_Controller extends Controller { } } - if(Director::is_ajax()) { + if($this->isAjax()) { echo ""; } else { - Director::redirectBack(); + $this->redirectBack(); } } @@ -200,10 +200,10 @@ class PageComment_Controller extends Controller { } } - if(Director::is_ajax()) { + if($this->isAjax()) { echo ""; } else { - Director::redirectBack(); + $this->redirectBack(); } } @@ -217,10 +217,10 @@ class PageComment_Controller extends Controller { // @todo Report to spamprotecter this is true - if(Director::is_ajax()) { + if($this->isAjax()) { echo $comment->renderWith('PageCommentInterface_singlecomment'); } else { - Director::redirectBack(); + $this->redirectBack(); } } } @@ -254,14 +254,14 @@ class PageComment_Controller extends Controller { $comment->write(); } } - if(Director::is_ajax()) { + if($this->isAjax()) { if(SSAkismet::isEnabled() && SSAkismet::getSaveSpam()) { echo $comment->renderWith('PageCommentInterface_singlecomment'); } else { echo ''; } } else { - Director::redirectBack(); + $this->redirectBack(); } } /** @@ -291,10 +291,10 @@ class PageComment_Controller extends Controller { $comment->write(); } } - if(Director::is_ajax()) { + if($this->isAjax()) { echo $comment->renderWith('PageCommentInterface_singlecomment'); } else { - Director::redirectBack(); + $this->redirectBack(); } } diff --git a/code/sitefeatures/PageCommentInterface.php b/code/sitefeatures/PageCommentInterface.php index b3dae5e0..274da5db 100755 --- a/code/sitefeatures/PageCommentInterface.php +++ b/code/sitefeatures/PageCommentInterface.php @@ -301,8 +301,8 @@ class PageCommentInterface_Form extends Form { //check if spam question was right. if(MathSpamProtection::isEnabled()){ if(!MathSpamProtection::correctAnswer($data['Math'])){ - if(!Director::is_ajax()) { - Director::redirectBack(); + if(!$this->controller->isAjax()) { + $this->controller->redirectBack(); } return "spamprotectionfailed"; //used by javascript for checking if the spam question was wrong } @@ -330,7 +330,7 @@ class PageCommentInterface_Form extends Form { $comment->write(); Cookie::set("PageCommentInterface_Comment", ''); - if(Director::is_ajax()) { + if($this->controller->isAjax()) { if($comment->NeedsModeration){ echo _t('PageCommentInterface_Form.AWAITINGMODERATION', "Your comment has been submitted and is now awaiting moderation."); } else{ @@ -347,7 +347,7 @@ class PageCommentInterface_Form extends Form { } } - return Director::redirectBack(); // worst case, just go back to the page + return $this->controller->redirectBack(); // worst case, just go back to the page } } } @@ -362,7 +362,7 @@ class PageCommentInterface_Controller extends ContentController { } function newspamquestion() { - if(Director::is_ajax()) { + if($this->isAjax()) { echo Convert::raw2xml(sprintf(_t('PageCommentInterface_Controller.SPAMQUESTION', "Spam protection question: %s"),MathSpamProtection::getMathQuestion())); } }