Sharing some tweaks to make work with 2.1

This discussion is related to the Post Count addon.
KezzBKezzB New
edited October 2012 in Feedback

Hiya,

I'm working with the 2.1 alpha at the moment and had to do some tweaks to get things working.

I thought I'd share so you don't have to figure them out when 2.1 comes out.

public function PostController_BeforeCommentRender_Handler(&$Sender)

changed to:

public function DiscussionController_BeforeCommentDisplay_Handler(&$Sender)

And

$Comments = $Sender->Data('CommentData');

changed to:

$Comments = $Sender->Data('Comments');

And

public function PostController_CommentInfo_Handler(&$Sender)

changed to:

public function DiscussionController_DiscussionInfo_Handler(&$Sender)

Hope that helps!

Kezz

aeryUnderDogLeeHbadnewsblairandrewpo

Comments

  • THANK YOU. PostCounts have been broken for me for weeks! Thanks for finally getting them working!!!

    mcdjmcdj
  • You might change the &$Sender to $Sender - everywhere. you will probably be happier in the long run.

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

    mirX
  • Looks like this has solved the issue for me. Thanks!

  • x00x00 MVP
    edited August 2014

    The whole thing can be simplified to just

    <br />class PostCountPlugin extends Gdn_Plugin {
    
       public function UserInfoModule_OnBasicInfo_Handler($Sender) {
          $PostCount = intval($Sender->User->CountDiscussions)+intval($Sender->User->CountComments);
          echo "<dt>".T(Plural($PostCount, 'Posts', 'Posts'))."</dt>\n";
          echo "<dd>".number_format($PostCount)."</dd>";
       }
    
       public function DiscussionController_CommentInfo_Handler($Sender) {
          $this->_AttachPostCount($Sender);
       }
    
       public function PostController_CommentInfo_Handler($Sender) {
          $this->_AttachPostCount($Sender);
       }
    
       protected function _AttachPostCount($Sender) {
          $Posts = intval($Sender->EventArguments['Author']->CountDiscussions)+intval($Sender->EventArguments['Author']->CountComments);
          echo '<span class="MItem">'.T(Plural(number_format($Posts),'Posts: %s','Posts: %s')).'</span>';
       }
    
       public function Setup() {
          // Nothing to do here!
       }
    
       public function Structure() {
          // Nothing to do here!
       }
    
    }
    

    No need to query the databases again, when he data is freely available with he the author.

    grep is your friend.

    hgtonightJoZ3_69cclubbmirX
  • Hey all, I just tried installing this plugin, running Vanilla 2.1.9 and made the changes suggested by @KezzB and @peregrine, but when I try to enable the plugin, vanilla tells me the addon was unable to be enabled because it generated a fatal error: "Whoops: there was an error."
    Am I doing something wrong?

  • R_JR_J Cheerleader & Troubleshooter Munich Moderator

    Use the code x00 has posted.


  • R_JR_J Cheerleader & Troubleshooter Munich Moderator

    ... but you would like to add

    public function DiscussionController_DiscussionInfo_Handler($Sender) {
        $this->_AttachPostCount($Sender);
    }
    


  • phreakphreak VanillaAPP - White label iOS and Android App MVP

    @linc: Wouldn't it be good to update the current PostCount plugin with this code.

    I would also add a postcount class, so it easier for designers to style it.

    echo ''.T(Plural(number_format($Posts),'Posts: %s','Posts: %s')).'';

  • LincLinc Director of Development Detroit Vanilla Staff

    @Bleistivt done

    hgtonightBleistivt
Sign In or Register to comment.