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

A few general questions regarding XF best practices

Discussion in 'XenForo Development Discussions' started by SpecialK, Feb 15, 2014.

  1. SpecialK

    SpecialK Member

    Hi there. We need to limit our users to posting only once every week in a certain forum on our site. I wrote an addon to do this in vBulletin, but I was hoping something already existed for Xen. I found http://xenforo.com/community/resources/daily-post-limit-by-waindigo.1919/ which is pretty close to what we need, but doesn't let us define a time limit other than daily, which is a deal breaker unfortunately.

    Can anyone help?
  2. Brogan

    Brogan XenForo Moderator Staff Member

    You will need to have a custom add-on developed.
  3. SpecialK

    SpecialK Member

    Unfortunate. Guess it's time to dig into the Xenforo dev docs.
  4. SpecialK

    SpecialK Member

    I've started work on this addon but would like to know about some best practices (Apologies for the newbie questions - I am still fresh to XF):

    1. I've got my class/method set up and an event listener set up to fire that method on the controller_pre_dispatch event with a XenForo_ControllerPublic_Forum hint so that the method is only firing when absolutely necessary. Does this look correct for catching a new thread before it happens?

    2. So I've got my method firing on every new thread request (<?php if($action === 'CreateThread')..... ?>) but I only need to continue if the node ID is 7. What is the best way to go about this? I see that I can dig down into the controller variables to get to the node ID, but I wasn't sure if there was a proper API request to get this.

    3. OK, so now my method knows that a new thread is being posted to Node ID 7 and I need to see if the user has made any new threads in this node in the last 10 days. What is the proper way of querying the database for this information? The date calculation is easy, but I want to make sure we're going about all of this the right way in terms of API calls and whatnot.

    4. How do we show an error to the user and stop execution of the page? In VB it was just a standard_error() call but I haven't yet discovered the right way of doing this in XF.

    5. For future expansion on this, I see that I can create new option groups/options while in dev mode and assign these to my addon. Now, from my addon method, is there an options API that I would use to retrieve these settings?

    6. I stumbled on http://xenforo.com/community/threads/getting-the-forum-number-from-the-uri.68377/#post-717417 as well, which seems like a good idea (Hide the new thread button so the user can't even see it if he's not eligible to post right now) but I'm not sure what the implementation would look like since I don't know how XF wants classes extended.

    Overall, I absolutely love the flexibility here. This is leaps and bounds above VB development. I just need to get my bearings.

    Thanks in advance for anything you can help with.

    For what it's worth, I'm not completely helpless. I can figure out how to get things done, but I would rather learn the XF way. For example, I know I can do

    $db XenForo_Application::get('db');
    $addons $db->fetchRow('SELECT * FROM xf_addon');
    But I would like to know if there is a better way.
    Last edited: Feb 16, 2014

Share This Page