Please upgrade here. These earlier versions are no longer being updated and have security issues.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.

Adsense in first post

RaizeRaize vancouver ✭✭
edited September 2010 in Vanilla 2.0 - 2.8
What's the best way to put some text ads in the first post of a discussion, where the users signature would usually be?

Comments

  • TimTim Operations Vanilla Staff
    Write a plugin that hooks into this event:

    public function DiscussionController_AfterCommentBody_Handler($Sender)

    Inside the method, check that you're in the first post by going like this:
    $Type = strtolower($RawType = $Controller->EventArguments['Type']); if ($Type == 'comment') return;

    Then insert whatever code you need to output your advertising.

    Vanilla Forums COO [GitHub, Twitter, About.me]

  • that will show up in every comment, if i'm not mistaken... i think @Raize just wants the ad to show up in the first comment in the thread (the one the thread author creates.)
  • TimTim Operations Vanilla Staff
    $Type = strtolower($RawType = $Controller->EventArguments['Type']);

    $Type = (comment|discussion)

    if ($Type == 'comment') return;

    Thus, "check the type. if it is a comment, get out and do nothing, else show ads".

    Vanilla Forums COO [GitHub, Twitter, About.me]

  • right... but that handler is called for every comment in the discussion.
  • TimTim Operations Vanilla Staff
    edited September 2010
    right... but that handler is called for every comment in the discussion.
    Yep. It is called after the discussion body, and then subsequently after every comment. That's why it has to check what the Type of the content it just rendered was, and if it was a comment, bail out and do nothing, otherwise (discussion) display ads.

    Have I missed something? I have this horrible feeling like you're going to point out a giant turd on my head... :p

    Vanilla Forums COO [GitHub, Twitter, About.me]

  • TimTim Operations Vanilla Staff
    applications/vanilla/views/discussion/index.php - line 38-40 <?php echo $this->FetchView('comments'); ?>

    applications/vanilla/views/discussion/comments.php -
    line 8-10if ($CurrentOffset == 0 && !$this->Data('NewComments', FALSE)) { echo WriteComment($this->Discussion, $this, $Session, $CurrentOffset); }
    line 14-18foreach ($CommentData as $Comment) { ++$CurrentOffset; $this->CurrentComment = $Comment; WriteComment($Comment, $this, $Session, $CurrentOffset); }

    applications/vanilla/views/discussion/helper_functions.php
    $Type = property_exists($Object, 'CommentID') ? 'Comment' : 'Discussion'; $Sender->EventArguments['Type'] = $Type;
    <?php $Sender->FireEvent('AfterCommentBody'); ?>

    Vanilla Forums COO [GitHub, Twitter, About.me]

  • The OP only wanted the code to show up in the first comment, not in every comment. In my addon i just used a counter to detect the first time the handler is fired.
Sign In or Register to comment.