1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Silly question about looking up a user's banned state

Discussion in 'XenForo Development Discussions' started by Ridemonkey, Apr 7, 2015.

  1. Ridemonkey

    Ridemonkey Well-Known Member

    I was trying to add some styling to one of my logs to indicate whether a user is banned while scrolling through the log.

    This log has $username and $user_id but I am unsure how to query a user's banned state using these. In normal templates I can just use $user.is_banned.

    I am quite obviously not a developer, just a guy trying to improve his admin workflow, so hopefully someone doesn't mind assisting in my newbie question :)
  2. Marcel

    Marcel Active Member

    Which log is it you want to add this information to?
  3. Ridemonkey

    Ridemonkey Well-Known Member

    I'm using the Stop Human Spam plugin and I use the log to identify spammers who are attempting to spam via profile posts. I'm trying to add an easy way to identify spammers that I have already banned so I don't waste time re-banning them.

    I have poked around the core logs (e.g. user change log) to see if any of them query the user's banned state but I can't find anything in there either.
  4. Marcel

    Marcel Active Member

    Ive just had a very quick cursory look at the SHS plugin via TAC Free
    (The actual SHS Plugin isn't free), and with my very limited experience and knowledge I think you would need to do the following :

    1: Add a new field to the database table sf_stophumanspam_log
    Name it something like 'userstate', and of type text.

    2: Add a new field to Datawriter/Log.php under function _getFields()
    'userstate' => array('type' => self::TYPE_STRING, 'default' => ''),

    3: Edit the code that writes to the log to actually add the user's state.
    That seems to be in Model/StopHumanSpam.php (lines 545 to 562) under function logEvent,

    just before $logWriter->save(); add the following line
    $logWriter->set('userstate', $visitor['user_state']);

    3: Edit the template shs_stophumanspam_log to add in the fields to display in the log.

    Please bear in mind this was a very cursory look and I have very limited knowledge so this could be completely wrong.
    Ridemonkey likes this.
  5. Ridemonkey

    Ridemonkey Well-Known Member

    Interesting... I figured I was overlooking something incredibly stupid but I guess not.

    So there's no way to query the state of the user from XenForo? The state of the user may change in between writing the log event and my actually browsing the log. In fact, it's actually very likely that the state of the user will change, since spammers are going to do a number of actions in rapid succession, they will usually get banned once someone notices their post in the moderation queue, and I will review the SHS logs much later. Thus, I only really care about displaying the active state of the user at the time I view the log.

    I appreciate your responses!
  6. Marcel

    Marcel Active Member

    Ah. TBH I'm not sure if you can. When you're viewing the log, you're just reading a nicely formatted output direct from the database of the SHS log, which as you know doesn't log the user state.

    So on a technical level you'll need some code to extract the username from the log and go and find out the user's banned state......per user.
    That code at the moment, just doesn't exist as part of SHS (if that makes sense).
    Ridemonkey likes this.
  7. Ridemonkey

    Ridemonkey Well-Known Member

    Thanks for looking into this for me - it's greatly appreciated.

    If anyone else has a suggestion for an easy way to do this, I'm all ears!
  8. Daniel Hood

    Daniel Hood Well-Known Member

    editing the query* to reflect something like:

    select log.*, user.user_state from sf_stophumanspam_log log left join xf_user user on user.user_id = log.user_id
    *I haven't seen any of the files or db schema relating to this add-on so I'm not giving specific instructions but this is the type of method you should probably use.
    Ridemonkey likes this.
  9. Marcel

    Marcel Active Member

    Thats much simpler! Told you someone else would know a better way :D
  10. Ridemonkey

    Ridemonkey Well-Known Member

    Great idea. I'll poke around with that tonight.

Share This Page