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.
Options

different background new topic

jackmaessenjackmaessen ✭✭✭
edited March 2014 in Vanilla 2.0 - 2.8

using 2.0.18.10 with VanillaBootstrap theme

For a new topic or a new post , i changed the background in the class "New" so that people can easily see that this is a new post. And ofcourse in both cases the line "1 New" is being displayed.
But now i want to make difference between posting a comment in an existing topic or posting comment in a new topic (so actually starting new topic).
Both text are being parsed in the New class.
I found in helper_functions.php this piece of code:

function WriteDiscussion($Discussion, &$Sender, &$Session, $Alt2) {
   static $Alt = FALSE;
   $CssClass = 'Item';
   $CssClass .= $Discussion->Bookmarked == '1' ? ' Bookmarked' : '';
   $CssClass .= $Alt ? ' Alt ' : '';
   $Alt = !$Alt;
   $CssClass .= $Discussion->Announce == '1' ? ' Announcement' : '';
   $CssClass .= $Discussion->Dismissed == '1' ? ' Dismissed' : '';
   $CssClass .= $Discussion->InsertUserID == $Session->UserID ? ' Mine' : '';
   $CssClass .= ($Discussion->CountUnreadComments > 0 && $Session->IsValid()) ? ' New' : '';
   $DiscussionUrl = '/discussion/'.$Discussion->DiscussionID.'/'.Gdn_Format::Url($Discussion->Name).($Discussion->CountCommentWatch > 0 && C('Vanilla.Comments.AutoOffset') && $Session->UserID > 0 ? '/#Item_'.$Discussion->CountCommentWatch : '');
   $Sender->EventArguments['DiscussionUrl'] = &$DiscussionUrl;
   $Sender->EventArguments['Discussion'] = &$Discussion;
   $Sender->EventArguments['CssClass'] = &$CssClass;
   $First = UserBuilder($Discussion, 'First');
   $Last = UserBuilder($Discussion, 'Last');

   $Sender->FireEvent('BeforeDiscussionName');

My question: how can i give a new topic a different class in which the content is being parsed?
Because i want to give that class a different background-color.
I think i have to do something with this line:

$CssClass .= ($Discussion->CountUnreadComments > 0 && $Session->IsValid()) ? ' New' : '';

Can someone help me with that how i can make difference between a new topic and a new post in an existing topic?

Comments

  • Options
    hgtonighthgtonight ∞ · New Moderator

    Hiya!

    You can check the user discussion data and append a css class to discussions that haven't been viewed yet. I used the following as a quick test:

    public function DiscussionsController_BeforeDiscussionName_Handler($Sender) {
      if(Gdn::Session()->IsValid() && is_null($Sender->EventArguments['Discussion']->DateLastViewed)) {
        $Sender->EventArguments['CssClass'] .= ' UnreadDiscussion';
      }
    }
    

    This hooks into the discussions controller right before the name is displayed and adds the class UnreadDiscussion if appropriate. Putting this snippet in your theme hooks file will give you 'access' to style unread discussions differently.

    Search first

    Check out the Documentation! We are always looking for new content and pull requests.

    Click on insightful, awesome, and funny reactions to thank community volunteers for their valuable posts.

  • Options

    This works great @hgtonight. Thankyou. There is just one little thing: when clicking on All Viewed, the class UnreadDiscussion does not change to Item or Item Alt. But the "1 New" disappears. That's good! The background-color does disappear when you click on the topic itself. Is there any way i can make it work with the AllViewed to disappear?

  • Options
    hgtonighthgtonight ∞ · New Moderator

    That is a good question. The All Viewed plugin works by placing a datetime in the user table and hooking into the discussion model to change the comment counts reported.

    public function DiscussionsController_BeforeDiscussionName_Handler($Sender) {
      $Session = Gdn::Session();
      $Discussion = $Sender->EventArguments['Discussion'];
      $Class = 'UnreadDiscussion';
      $NewClass = '';
      if($Session->IsValid()) {
        if(is_null($Discussion->DateLastViewed)) {
          $NewClass = $Class;
        }
    
        // See if the date is before the all viewed date
        if(property_exists($Session->User, 'DateAllViewed') && $Discussion->DateInserted < $Session->User->DateAllViewed) {
          $NewClass = '';
        }
      }
      $Sender->EventArguments['CssClass'] .= " $NewClass";
    }
    

    This code should take the all viewed stamp into consideration and also not throw any errors in for installs not using the plugin.

    Search first

    Check out the Documentation! We are always looking for new content and pull requests.

    Click on insightful, awesome, and funny reactions to thank community volunteers for their valuable posts.

  • Options

    Awesome @hgtonight. This works great. And when hitting the AllViewed button, the bg colors disappear both!
    Thankyou very much for support.
    See attachment:

Sign In or Register to comment.