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.

Hooks in the middle of discussion list

Is there a hook available that will allow me to add something in the middle of the discussion list. like something after the 5th Discussion or 5th Comment.

Comments

  • edited March 2007
    I would have to look to see about the discussion grid, but to put something after the 5th post, you could do something like this:
    if ('comments.php' == $Context->SelfUrl) { Function TweenPost(&$CommentGrid) $RowNumber = &$CommentGrid->DelegateParameters['RowNumber']; $Comment = &$CommentGrid->DelegateParameters['Comment']; if ( 5 == $RowNumber ) { // close the existing CommentBody div, and open a new one that gets closed by the old div: $Comment->Body .= '</div><div class="TweenPost">' . $data; } $Context->AddToDelegate('CommentGrid', 'PreCommentOptionsRender', 'TweenPost'); }
    Edit: Changed TweenPost($$CommentGrid) to TweenPost(&$CommentGrid)
  • perfect. thanks Wallphone
  • WallPhone / MySchizoBuddy can you please explain a little bit more.where to place this code.

    Actually i want to display an ad after first comment ;-)

    Thanks for your help guys
  • edited March 2007
    You have to use for an extension: look at the document, and start by: http://lussumo.com/docs/doku.php?id=vanilla:development:gettingstarted
  • edited April 2007
    How do u pass the $data variable to TweenPost what will the AddDelegate thingy look like when u have to pass a variable to the function
  • all you do is make the variable at the start of your extension, then in the function, use this...

    global $data;
  • thats how i have done so far
    but i have to do that for every single delegate I'm using. I was hoping to call the function with the data, which will make my code lot smaller than it is right now
  • then use call_user_func() or call_user_method()
  • edited April 2007
    here are two functions that do 99% the same thing
    function DisplayMenuNugget(&$Menu) { global $NuggetObj; for ($i=0; $i < count($NuggetObj->Nugget); $i++) { if ($NuggetObj->Nugget[$i]['status']//check status && in_array($Menu->Context->Session->User->RoleID, $NuggetObj->Nugget[$i]['roles']) // check roles && in_array($Menu->Context->SelfUrl, $NuggetObj->Nugget[$i]['pages']) //check pages && $NuggetObj->Nugget[$i]['position'] == 'MENU') { $NuggetObj->Nugget[$i]['html'] = AllowPHP($NuggetObj->Nugget[$i]['html']); if(!$NuggetObj->Nugget[$i]['hideName']) $DisplayNuggetString = '<h2>'.$NuggetObj->Nugget[$i]['name'].'</h2>'; $DisplayNuggetString = '<div class="Nugget '.$NuggetObj->Nugget[$i]['position'].'">'.$DisplayNuggetString. $NuggetObj->Nugget[$i]['html'].'</div>'; echo $DisplayNuggetString; } } } $Context->AddToDelegate('Menu', 'PreBodyRender', 'DisplayMenuNugget'); function DisplayBelowPanelNugget(&$Panel) { global $NuggetObj; for ($i=0; $i < count($NuggetObj->Nugget); $i++) { if ($NuggetObj->Nugget[$i]['status']//check status && in_array($Panel->Context->Session->User->RoleID, $NuggetObj->Nugget[$i]['roles']) // check roles && in_array($Panel->Context->SelfUrl, $NuggetObj->Nugget[$i]['pages']) //check pages && $NuggetObj->Nugget[$i]['position'] == 'BELOW_PANEL') { $NuggetObj->Nugget[$i]['html'] = AllowPHP($NuggetObj->Nugget[$i]['html']); if(!$NuggetObj->Nugget[$i]['hideName']) $DisplayNuggetString = '<h2>'.$NuggetObj->Nugget[$i]['name'].'</h2>'; $DisplayNuggetString = '<div class="Nugget '.$NuggetObj->Nugget[$i]['position'].'">'.$DisplayNuggetString. $NuggetObj->Nugget[$i]['html'].'</div>'; echo $DisplayNuggetString; } } } $Context->AddToDelegate('Panel', 'PostElementsRender', 'DisplayBelowPanelNugget');

    I would like to just use one function, by passing appropriate parameters
  • What you have is completely fine. No excessive variables are made to go with each function so it doesn't run slower than it should. If your really desperate, you can add the '$NuggetObj' Object into the Context Object and have the render() function empty.
This discussion has been closed.