HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.
Anyone know of an addon to ban users from a discussion?
On a different forum software there was an addon that allowed moderators to ban people from a thread (discussion)...
Anyone know of such an addon?
No, but it would be realtively easy, I guess. Are you ready to write your first plugin? I would guide you!
Copy the example plugin folder to a new folder and call it "discussionBan"
Rename the new plugin file to class.discussionban.plugin.php (lower case)
Look inside that plugin file for the beginning PluginInfo array. The array key must match the folder "discussionBan"
The class name must be DiscussionBanPlugin.
Start by changing the PluginInfo array how you need it and wiping everything inside the plugin class. We will start at zero.
In the following steps you would have to
1. add an entry to the discussion option menu (plugin Q&A has code which we could look up)
2. provide a user search field - we can look that up in the conversations application
3. I would assume that feature would be used sparsely so the information could be directly saved to the Discussion tables Attributes column, no need for database structure changes
4. there must be a hook on the BeforeSaveDiscussion event: check if session user is banned, if yes add validation result - simple!
Basically, that's it!
There should be a module (that's how "widgets" are called in Vanilla) which shows all banned users in a discussion so that mods can unban users. That would be one additional step, but nothing too complex, either.
oh I am definitely going to get to work on this.
Ok R_J here is what I have so far in my class.dicsussionban.plugin.php file:
@R_J I also think I have the discussionoptions.php figured out somewhat.
ummm I did the code format but it didn't.
Enclose your code in three
~signs. I've changed your comments that way.
First learn something general about plugins: http://docs.vanillaforums.com/developer/plugins/
If you want to add your own option to discussions, you would have to find out how other plugins do so. The Q&A plugin has the following method:
Changed to what should be done in your case it should be similar to this:
If you want to understaand why that has any effect, you need to look at the following:
First, this function decides which options to show. At the end of the function, there is a possibility for you to add elemenets
When the page is rendered, the writeDiscussionOptions is called, which fetches the options with the function above.
By adding the above given method to your class, you tell Vanilla that there is one additional option to show in a discussion.
That option would try to open yourforum.com/plugin/bandiscussion/somediscussionid Before that doesn't exist, there will not much happen. Creating that is simple, though. Add
to your plugin and you would see some sample output
The view that you have given above is a very good start! Save it to /plugins/banDiscussion/views/bandiscussion.php
Instead of giving that debug output, we now want to render your view.
Change the lines above to
Check if using the discussion option now shows your view!
I get syntax error with the above when I add this into my class.
Ok so I think I was right. The option no shows:
Of course when I click on it a pop up comes up and then I get thrown to a blank screen. This shows and then after a second I get a black screen of nothing. Probably because we still need to tell it what it is supposed to do.
Here is what I have so far.
Scratch that there was some errors in the paths. This is what I have now.
Somewhere along the line we switched from it being discussionBan to banDiscussion os I switched things around.
Just a tip here, a class Popup will only popup content from a pre-existing page or module. I suggest you first create a page where the settings appear, before you pop anything up. The reason why it does not show, is because the js to pop up requires the content to exist somewhere, either as a file or a page rendered. it will create the popup box but will eternally try to load the content.
You should be trying this out in the stand alone forum and not the embedded forum.
❌ ✊ ♥. ¸. ••. ¸♥¸. ••. ¸♥ ✊ ❌
I don't have a standalone forum to work with it on. I only have an embedded forum. Ok so with the popup I thought it looked to the view file no?
If your PHP doesn't support the brackets as array definitions, you should update your PHP version.
By the way: we inserted a link into the menu and links can be opened in their own window. If you want to debug your popup, most of the time you get more information if you open the link in a separate tab.
And after I did this, I thought it might be better to extend the VanillaController.
In order to be able to show you in more detail what is needed and what I've done, I've created a github repo. You don't need to understand git itself to look at it. It should simply enable you to track the steps I've made: https://github.com/R-J/discussionBan/commits/master
I fixed some formattings and a little bit of the view. Here are some of the changes I made explained in more detail:
The PluginInfo array holds meta information of your plugin, but it also contains magic: if you give a link to a settings page here, there will be an option to open that settings in the plugins overview in the dashboard.
I cannot think of any permission needed and so I have removed it.
You can use an array key "Name" which you can fill with any value you like. I have chosen "Discussion Ban"
There have been a typo in the second method and that's why the link you have created in the menu hasn't found the target. In order to show the view, that view has to be found... $sender->render('viewnamewithoutextension', '', 'plugins/subfolder')
You have used "discussionBan" in there, but your view was named discussionoptions.php.
The view uses a form, but that form doesn't exist, so we have to attach it to the class.
This might be a good point to talk about that
$senderthat you see everywhere... Vanilla gets extended by hooking into events which are fired throughout Vanillas program flow. If we end our plugins method with ..._create, we create something new. If we use pluginController_discussionBan_create, we create something that is reachable on your domain under plugin/discussionban - quite simple, isn't it?
And this $sender is an instance of the PluginController that you can find in class.plugincontroller.php. This extends the DashboardController which extends - like any controller in Vanilla - the Gdn_Controller. You can do with $sender whatever you can do with PluginController, DashboardController and Gdn_Controller.
And what we need to do if we want to use a form, is to create an instance of the form class and attach it to our class
$sender = new Gdn_Form();
You have to work with the result of what is entered. Look at the UserModel: it provides a method to get a User object by the name. You would have to loop through all names that have been entered and get the user ids. Use that decho function to see the results. Its ugly, but a quick way to "debug". Look at class.model.php "saveToSerializedColumn" method in order to find out how to save that userIDs to the discussion table.
I've provided an if/else construct where you can add code for the time when the form has been submitted and when it has been read first. In the else clause, you might want to find out how to get a list of all already saved usernames and display them there.
@R_J thanks for this! I am looking at it now, at first look when I enable what you've given me to start with the first post in the discussion disappears for me. I will try and figure out what's going on with that but wondering if anything jumps out at you as to why this may be.
disregard the above about the starting topic not displaying.