Vanilla 1 is no longer supported or maintained. If you need a copy, you can get it here.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.

Fatal Error on comments.php... Can't see any more disccussions!

edited November 2008 in Vanilla 1.0 Help
Opps, looks like I've buggered something up again. I'd greatly appreciate any help on this.

I was only slightly tweaking with the comments.php file (in attempt to modify the whisper back function), and upon uploading my modified file, I broke my forum..kinda.

Clicking on any discussion, or after posting, I get this error:
Fatal error: Using $this when not in object context in ...pathtomyforum.../forum/comments.php on line 5

Here's the thing though... I've replaced the file with the correct, unmodified, vanilla-default comments.php file but I'm still getting the same error! So what's up?

Line 5 reads:
if ($this->Context->WarningCollector->Count() > 0) {


  • Options
    edited November 2008
    it should be:
    if ($Context->WarningCollector->Count() > 0) {

    the code is in the global scope. $this is a pseudo-variable accessible in an instance method scope; it is a reference to the instance (object) itself.

    You can use $this->Context inside a method if its object has a Context property:
    class A { var $Context; function A(&$Context) { // constructor // Get Context when an object is created // and set the Context property with it $this->Context =& $Context; } [...] function CountWarning() { return $this->Context->WarningCollector->Count(); } } [...] $a = new A($Context); $a->CountWarning();

    Some objects in vanilla don't have this property.
  • Options
    edited November 2008
    Thanks for the input Dinoboff, some of that is a bit over my head though...sorry!

    Changing that in the comments.php file (should it be changed in both the root vanilla folder as well as the themes folder?) gives this error then:
    Fatal error: Call to a member function Count() on a non-object in ...pathtomyforum.../forum/comments.php on line 5


    I guess I'm just failing to understand why reverting back to the original line of code isn't resolving these errors?
  • Options
    edited November 2008
    It doesn't make sense. As long as you put it after:
    include("appg/settings.php"); $Configuration['SELF_URL'] = 'comments.php'; include("appg/init_vanilla.php");
    ...It should work.

    For the theme files, it depends of the context. As long as they are included from a Controller method, you can get $Context with $this->Context.
  • Options
    edited November 2008
    I guess I'm not following entirely... The three lines of code you mentioned are not even in my comments.php file. Should they be? Am I looking in the wrong place?

    Here's my root level comments.php file:
    <?php // Note: This file is included from the library/Vanilla/Vanilla.Control.CommentGrid.php class. $CommentList = ''; if ($Context->WarningCollector->Count() > 0) { $CommentList .= '<div class="ErrorContainer"> <div class="ErrorTitle">'.$this->Context->GetDefinition('ErrorTitle').'</div>' .$this->Context->WarningCollector->GetMessages() .'</div>'; } else { $PageDetails = $this->pl->GetPageDetails($this->Context); $PageList = $this->pl->GetNumericList(); $SessionPostBackKey = $this->Context->Session->GetCsrfValidationKey(); $CommentList .= '<div class="ContentInfo Top"> <h1>'; if ($this->Context->Configuration['USE_CATEGORIES']) $CommentList .= '<a href="'.GetUrl($this->Context->Configuration, 'index.php', '', 'CategoryID', $this->Discussion->CategoryID).'">'.$this->Discussion->Category.'</a>: '; $CommentList .= DiscussionPrefix($this->Context, $this->Discussion).' '; if ($this->Discussion->WhisperUserID > 0) { $CommentList .= $this->Discussion->WhisperUsername.': '; } $CommentList .= $this->Discussion->Name .'</h1> <a href="#pgbottom">'.$this->Context->GetDefinition('BottomOfPage').'</a> <div class="PageInfo"> <p>'.$PageDetails.'</p> '.$PageList.' </div> </div> <div id="ContentBody"> <ol id="Comments">'; $Comment = $this->Context->ObjectFactory->NewContextObject($this->Context, 'Comment'); $RowNumber = 0; $CommentID = 0; $Alternate = 0; // Define the current user's permissions and preferences // (small optimization so they don't have to be checked every loop): $PERMISSION_EDIT_COMMENTS = $this->Context->Session->User->Permission('PERMISSION_EDIT_COMMENTS'); $PERMISSION_HIDE_COMMENTS = $this->Context->Session->User->Permission('PERMISSION_HIDE_COMMENTS'); $PERMISSION_EDIT_DISCUSSIONS = $this->Context->Session->User->Permission('PERMISSION_EDIT_DISCUSSIONS'); while ($Row = $this->Context->Database->GetRow($this->CommentData)) { if ($RowNumber > 0) $PERMISSION_EDIT_DISCUSSIONS = 0; $RowNumber++; $Comment->Clear(); $Comment->GetPropertiesFromDataSet($Row, $this->Context->Session->UserID); $CommentAuthUsername = $Comment->AuthUsername; // Get an unencoded version of the author's username $ShowHtml = $Comment->FormatPropertiesForDisplay(); $ShowIcon = $Comment->AuthIcon != '' ? 1 : 0; $this->DelegateParameters['ShowHtml'] = &$ShowHtml; $this->DelegateParameters['ShowIcon'] = &$ShowIcon; $this->DelegateParameters['RowNumber'] = &$RowNumber; $CommentClass = ''; if ($Comment->WhisperUserID > 0) { if ( ($Comment->WhisperUserID == $this->Context->Session->UserID && $Comment->AuthUserID == $this->Context->Session->UserID) or $Comment->WhisperUserID == $this->Context->Session->UserID ) { $CommentClass = 'WhisperTo'; } else { $CommentClass = 'WhisperFrom'; } } else if ($this->Discussion->WhisperUserID > 0) { $CommentClass = ($Comment->AuthUserID == $this->Context->Session->UserID) ? 'WhisperFrom' : 'WhisperTo'; } if ($Comment->Deleted) $CommentClass .= ' Hidden'; if ($Alternate) $CommentClass .= ' Alternate'; $CommentClass = trim($CommentClass); $CommentList .= '<li id="Comment_'.$Comment->CommentID.'"'.($CommentClass == ''?'':' class="'.$CommentClass.'"').'> <a name="Item_'.$RowNumber.'"></a> <div class="CommentHeader"> <ul> <li> '.($ShowIcon?'<div class="CommentIcon" style="'."background-image:url('".$Comment->AuthIcon."');".'">&nbsp;</div>':'').' <span>'.$this->Context->GetDefinition('CommentAuthor').'</span><a href="'.GetUrl($this->Context->Configuration, 'account.php', '', 'u', $Comment->AuthUserID).'">'.$Comment->AuthUsername.'</a>'; // Point out who it was whispered to if necessary if ($Comment->WhisperUserID > 0) { if ($Comment->WhisperUserID == $this->Context->Session->UserID && $Comment->AuthUserID == $this->Context->Session->UserID) { $CommentList .= $this->Context->GetDefinition('ToYourself'); } elseif ($Comment->WhisperUserID == $this->Context->Session->UserID) { $CommentList .= $this->Context->GetDefinition('ToYou'); } else { $CommentList .= str_replace('//1', $Comment->WhisperUsername, $this->Context->GetDefinition('ToX')); } } $CommentList .= '</li> <li> <span>'.$this->Context->GetDefinition('CommentTime').'</span>'.TimeDiff($this->Context, $Comment->DateCreated); if ($Comment->DateEdited != '') $CommentList .= ' <em>'.$this->Context->GetDefinition('Edited').'</em>'; if ($Comment->Deleted) $CommentList .= ' <i>'.str_replace(array('//1', '//2'), array(TimeDiff($this->Context, $Comment->DateDeleted), $Comment->DeleteUsername), $this->Context->GetDefinition('CommentHiddenOnXByY')).'</i>'; // Whisper back button if (!$this->Discussion->Closed && $Comment->WhisperUserID > 0 && $Comment->WhisperUserID == $this->Context->Session->UserID) $CommentList .= '<a class="WhisperBack" onclick="' ."WhisperBack('".$Comment->DiscussionID."', '".str_replace("'", "\\'", $CommentAuthUsername)."', '".$this->Context->Configuration['BASE_URL']."');" .'">'.$this->Context->GetDefinition('WhisperBack').'</a>'; $CommentList .= '</li> </ul> <span> &nbsp;'; // Set up comment options $this->DelegateParameters['Comment'] = &$Comment; $this->DelegateParameters['CommentList'] = &$CommentList; $this->DelegateParameters['RowNumber'] = &$RowNumber; $CommentList .= $this->CallDelegate('PreCommentOptionsRender'); if ($this->Context->Session->UserID > 0) { if ($Comment->AuthUserID == $this->Context->Session->UserID || $PERMISSION_EDIT_COMMENTS || $PERMISSION_EDIT_DISCUSSIONS) { if ((!$this->Discussion->Closed && $this->Discussion->Active) || $PERMISSION_EDIT_COMMENTS || $PERMISSION_EDIT_DISCUSSIONS) $CommentList .= '<a href="'.GetUrl($this->Context->Configuration, 'post.php', '', 'CommentID', $Comment->CommentID).'">'.$this->Context->GetDefinition('edit').'</a> '; } if ($PERMISSION_HIDE_COMMENTS) $CommentList .= '<a id="HideComment'.$Comment->CommentID.'" href="./" onclick="' ."HideComment('".$this->Context->Configuration['WEB_ROOT']."ajax/switch.php', '".($Comment->Deleted?"0":"1")."', '".$this->Discussion->DiscussionID."', '".$Comment->CommentID."', '".$this->Context->GetDefinition("ShowConfirm")."', '".$this->Context->GetDefinition("HideConfirm")."', 'HideComment".$Comment->CommentID."', '".$SessionPostBackKey."');" .' return false;">'.$this->Context->GetDefinition($Comment->Deleted?'Show':'Hide').'</a> '; } $this->DelegateParameters['CommentList'] = &$CommentList; $this->CallDelegate('PostCommentOptionsRender'); $CommentList .= ' </span> </div>'; if ($Comment->AuthRoleDesc != '') $CommentList .= '<div class="CommentNotice">'.$Comment->AuthRoleDesc.'</div>'; $CommentList .= '<div class="CommentBody" id="CommentBody_'.$Comment->CommentID.'">'; $CommentList .= $Comment->Body.' </div> </li>'; $Alternate = FlipBool($Alternate); } $CommentList .= '</ol> </div>'; if (@$PageList && @$PageDetails) { $CommentList .= '<div class="ContentInfo Middle"> <div class="PageInfo"> <p>'.$PageDetails.'</p> '.$PageList.' </div> </div>'; } } echo $CommentList; ?>

    What's weird is that this wasn't even the one I was messing with...??? I was initially trying to modify the comments.php file in the themes folder, but again even undoing the little modification I made caused errors...
  • Options
    You meant themes/comments.php...

    It should be if ($this->Context->WarningCollector->Count() > 0) {
  • Options
    Oh man do I get the idiot award here... I pieced together based on your last two comments that I probably overwrote the root level comments.php with the themes one. Yup...I did. Put the proper php back in it's proper location and all is good. Sorry to waste your time Dinoboff, but I do appreciate the help. Cheers.
This discussion has been closed.