[Solved] Help, modifying the moderations.controller.php to fix comment and discussion deletion*
I tried to change a permission to allow for multiple deletions of old posts. I made changes to class.moderationcontroller.php
Now It sends an error message: Parse error: syntax error, unexpected T_VARIABLE in /hermes/bosoraweb069/b284/sl.lionslair/public_html/Forum/applications/vanilla/controllers/class.moderationcontroller.php on line 325
So I use the "find" feature in Firefox and it shows 3 instances of vanilla.comment in this php file. Obviously I fubbed up, so I have copied the content of the file. Can we get this back to normal?
Text of class.moderationcontroller.php:
<?php if (!defined('APPLICATION')) exit();
/*
Copyright 2008, 2009 Vanilla Forums Inc.
This file is part of Garden.
*
* @since 2.0.18
* @package Vanilla
*/
class ModerationController extends VanillaController {
/**
* Looks at the user's attributes and form postback to see if any comments
* have been checked for administration, and if so, puts an inform message on
* the screen to take action.
*/
public function CheckedComments() {
$this->DeliveryType(DELIVERY_TYPE_BOOL);
$this->DeliveryMethod(DELIVERY_METHOD_JSON);
ModerationController::InformCheckedComments($this);
$this->Render();
}
/**
* Looks at the user's attributes and form postback to see if any discussions
* have been checked for administration, and if so, puts an inform message on
* the screen to take action.
*/
public function CheckedDiscussions() {
$this->DeliveryType(DELIVERY_TYPE_BOOL);
$this->DeliveryMethod(DELIVERY_METHOD_JSON);
ModerationController::InformCheckedDiscussions($this);
$this->Render();
}
/**
* Looks at the user's attributes and form postback to see if any comments
* have been checked for administration, and if so, adds an inform message to
* $Sender to take action.
*/
public static function InformCheckedComments($Sender) {
$Session = Gdn::Session();
$HadCheckedComments = FALSE;
$TransientKey = GetValue('TransientKey', $_POST);
if ($Session->IsValid() && $Session->ValidateTransientKey($TransientKey)) {
// Form was posted, so accept changes to checked items.
$DiscussionID = GetValue('DiscussionID', $_POST, 0);
$CheckIDs = GetValue('CheckIDs', $_POST);
if (empty($CheckIDs))
$CheckIDs = array();
$CheckIDs = (array)$CheckIDs;
$CheckedComments = Gdn::UserModel()->GetAttribute($Session->User->UserID, 'CheckedComments', array()); if (!is_array($CheckedComments)) $CheckedComments = array(); if (!array_key_exists($DiscussionID, $CheckedComments)) { $CheckedComments[$DiscussionID] = array(); } else { // Were there checked comments in this discussion before the form was posted? $HadCheckedComments = count($CheckedComments[$DiscussionID]) > 0; } foreach ($CheckIDs as $Check) { if (GetValue('checked', $Check)) { if (!ArrayHasValue($CheckedComments, $Check['checkId'])) $CheckedComments[$DiscussionID][] = $Check['checkId']; } else { RemoveValueFromArray($CheckedComments[$DiscussionID], $Check['checkId']); } } if (count($CheckedComments[$DiscussionID]) == 0) unset($CheckedComments[$DiscussionID]); Gdn::UserModel()->SaveAttribute($Session->User->UserID, 'CheckedComments', $CheckedComments); } else if ($Session->IsValid()) { // No form posted, just retrieve checked items for display $DiscussionID = property_exists($Sender, 'DiscussionID') ? $Sender->DiscussionID : 0; $CheckedComments = Gdn::UserModel()->GetAttribute($Session->User->UserID, 'CheckedComments', array()); if (!is_array($CheckedComments)) $CheckedComments = array(); } // Retrieve some information about the checked items $CountDiscussions = count($CheckedComments); $CountComments = 0; foreach ($CheckedComments as $DiscID => $Comments) { if ($DiscID == $DiscussionID) $CountComments += count($Comments); // Sum of comments in this discussion } if ($CountComments > 0) { $SelectionMessage = Wrap(sprintf( 'You have selected %1$s in this discussion.', Plural($CountComments, '%s comment', '%s comments') ), 'div'); $ActionMessage = T('Take Action:'); // Can the user delete the comment? $DiscussionModel = new DiscussionModel(); $Discussion = $DiscussionModel->GetID($DiscussionID); if ($Session->CheckPermission('Vanilla.Comment.Delete', TRUE, 'Category', $Discussion->CategoryID)) $ActionMessage .= ' '.Anchor(T('Delete'), 'vanilla/moderation/confirmcommentdeletes/'.$DiscussionID, 'Delete Popup'); $Sender->EventArguments['SelectionMessage'] = &$SelectionMessage; $Sender->EventArguments['ActionMessage'] = &$ActionMessage; $Sender->EventArguments['Discussion'] = $Discussion; $Sender->FireEvent('BeforeCheckComments'); $ActionMessage .= ' '.Anchor(T('Cancel'), 'vanilla/moderation/clearcommentselections/'.$DiscussionID.'/{TransientKey}/?Target={SelfUrl}', 'CancelAction'); $Sender->InformMessage( $SelectionMessage .Wrap($ActionMessage, 'div', array('class' => 'Actions')), array( 'CssClass' => 'NoDismiss', 'id' => 'CheckSummary' ) ); } else if ($HadCheckedComments) { // Remove the message completely if there were previously checked comments in this discussion, but none now $Sender->InformMessage('', array('id' => 'CheckSummary')); }
}
Comments
/**
* Looks at the user's attributes and form postback to see if any discussions
* have been checked for administration, and if so, adds an inform message to
* $Sender to take action.
*/
public static function InformCheckedDiscussions($Sender) {
$Session = Gdn::Session();
$HadCheckedDiscussions = FALSE;
$TransientKey = GetValue('TransientKey', $_POST);
if ($Session->IsValid() && $Session->ValidateTransientKey($TransientKey)) {
// Form was posted, so accept changes to checked items.
$CheckIDs = GetValue('CheckIDs', $_POST);
if (empty($CheckIDs))
$CheckIDs = array();
$CheckIDs = (array)$CheckIDs;
}
/**
* Remove all comments checked for administration from the user's attributes.
*/
public function ClearCommentSelections($DiscussionID = '', $TransientKey = '') {
$Session = Gdn::Session();
if ($Session->ValidateTransientKey($TransientKey)) {
$CheckedComments = Gdn::UserModel()->GetAttribute($Session->User->UserID, 'CheckedComments', array());
unset($CheckedComments[$DiscussionID]);
Gdn::UserModel()->SaveAttribute($Session->UserID, 'CheckedComments', $CheckedComments);
}
}
/**
* Remove all discussions checked for administration from the user's attributes.
*/
public function ClearDiscussionSelections($TransientKey = '') {
$Session = Gdn::Session();
if ($Session->ValidateTransientKey($TransientKey))
Gdn::UserModel()->SaveAttribute($Session->UserID, 'CheckedDiscussions', FALSE);
}
/**
* Form to confirm that the administrator wants to delete the selected
* comments (and has permission to do so).
*/
public function ConfirmCommentDeletes($DiscussionID = '') {
$Session = Gdn::Session();
$this->Form = new Gdn_Form();
$DiscussionModel = new DiscussionModel();
$Discussion = $DiscussionModel->GetID($DiscussionID);
if (!$Discussion)
return;
}
/**
* Form to confirm that the administrator wants to delete the selected
* discussions (and has permission to do so).
*/
public function ConfirmDiscussionDeletes() {
$Session = Gdn::Session();
$this->Form = new Gdn_Form();
$DiscussionModel = new DiscussionModel();
// Clear selections
Gdn::UserModel()->SaveAttribute($Session->UserID, 'CheckedDiscussions', FALSE);
ModerationController::InformCheckedDiscussions($this);
$this->RedirectUrl = 'discussions';
}_____
}
}
attaching the file ... thanks for helping with fat fingered faux pas
do you have a question? If so you should have posted it in the title instead of help.
in any event what do you want? somebody to fix your changes. or a way to restore your files to normal?
or are you providing an answer of some kind?
you might post your changes in a zip format and upload them. since your formatting has gone awry.
I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.
@motahcity
Is there a reason you don't want to download another copy of Vanilla, and overwrite your 'fubbed' file with the 'unfubbed' version?
Only, I would guess that would be the quickest fix.
No, I absolutely need help. I made some changes that probably shouldn't have been made. In the class.moderationcontroller.php file.
Pretty limited as to the change(s) ... changed Vanilla.Comment.Delete(s) attribute. Some were plural, some not. I changed them all to plural, and now I get this error: Parse error: syntax error, unexpected T_VARIABLE in /hermes/bosoraweb069/b284/sl.lionslair/public_html/Forum/applications/vanilla/controllers/class.moderationcontroller.php on line 325
If you can assist I'd be most grateful. Site is inoperative.
that was my question does he want a fix to his own modifications. and the reason whay he has a syntax error. He probably has a missing ; or missing bracket some common syntax error
or does he want to restore to original.
this is a good reference for php error message tokens
http://php.net/manual/en/tokens.php
I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.
You shouldn't do that, but you've learned it the hard way right now, I assume...
If you've made changes, than go back to the original version. If you are using 2.0.18.8, than this will be what you are looking for: https://raw.github.com/vanillaforums/Garden/2.0/applications/vanilla/controllers/class.moderationcontroller.php
Well, as long as I am getting attention in the Dunce Cap Corner I'll try again. Just want corrections made to the original. After I get the site working again I'll go to the server and do a backup, then upgrade Vanilla.
Why was this done? Another member received an e-mail advising how to make a change. That went over like a turd in the party punch bowl.
I'm an analogue dinosaur .. your help is appreciated.
you've got dashes here
should be
I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.
That fixed it. I'd shout YOU ROCK!!!! but it wouldn't convey enough praise.
Next bowl has your name on it, and if you're in the neighborhood you should stop in and enjoy it!
Thanks.
what fixed it. did you do? restore or change the code to remove ___
try clicking on insightful or awesome once in a while too!
I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.
Hopefully, without the floater...
Removed the dashes, saved and reloaded the page. No error and the forum is running fine again.
No floaters ... but this is what was advised to an associate. Naturally, I fubbed it up.
@whu606 said:
(...) This (...) may well work (...)
(...)
$this->Permission('Vanilla.Comments.Delete', TRUE, 'Category', 'any');
Making that change should do the trick.
Note my careful use of the 'may well'!
The only change suggested was to try changing
Vanilla.Comment
to
Vanilla.Comments
Yea, that was too easy. I need to take the difficult road, and when all is lost ... beg for help. : )
you are referring to this maybe.
http://vanillaforums.org/discussion/comment/177120/#Comment_177120
since there is no permission regarding the field 'Vanilla.Comment.Delete' in the permission table.
however in the permission table this field "Vanilla.Comments.Delete" exists.
checking for a permission that doesn't exist in the permission table would be futile.
so all you did or needed to do was correct the this-> permission field to march the correct permissions table column.
just a bug in vanilla.
so essentially any reference anywhere in the vanilla software that references a check permission setting for Vanilla.Comment.Delete needs to be change to Vanilla.Comments.Delete
I noticed the problem in one of 422's premium themes also.
I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.
Thank you, 'that' logic doesn't elude me. Happy you shared Peregrine.
Messing with unfamiliar code is a no no, and I know better .... but that looked pretty simple. Line 291 ... gave me a map too.
Maybe my trail marking bread crumbs had garlic on them?
maybe a moderator can change the title of the thread.
to something "Help, modifying the moderations.controller.php to fix comment and discussion deletion in 2.0.1.18"
I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.