PDA

View Full Version : add custom attribute to forums


curriertech
01-25-2013, 08:14 PM
First off let me be clear, I'm not a programmer so I don't know what I'm talking about, and I'm probably going to break my forum trying to do this.

So today I was trying to figure out how to make a basic plugin to define an array of forumids to generate a value that I could use in a template conditional. After several iterations of trial and error it functions well, suprisingly. However, I thought it would be better if instead of having to edit the array with forumids, I could add a checkbox in the forum settings for "don't show ads" and store that attribute in the database, using that data to generate the array. That way if I add a new forum and check that box, no ads are displayed and I didn't have to touch the plugin.

Any advice on how I could accomplish this? Conceptually it doesn't sound like it could be that difficult but as I said, I'm no programmer.

kh99
01-25-2013, 08:32 PM
There's an article on doing just that here: www.vbulletin.org/forum/showthread.php?t=93445 It was written for vb3 but I believe it should still work with vb4.

curriertech
01-25-2013, 08:41 PM
Thank you! I searched my face off and didn't find that on my own. :)

--------------- Added 1359164686 at 1359164686 ---------------

Well I've made some progress, I've got the option in place and it sets the value in the database, but I'm having trouble getting the conditional to work. Here's what I've done so far, maybe someone can point out what I missed.

# Create new column in forum table called 'hideads'
ALTER TABLE `forum`
ADD COLUMN `hideads` smallint(3) unsigned NOT NULL DEFAULT '0',

# Create a plugin at hook forumdata_start
$this->validfields['hideads'] = array(TYPE_STR, REQ_NO);

# Create a plugin at hook forumadmin_edit_form
print_yes_no_row($vbphrase['hide_ads'], 'forum[hideads]', $forum['hideads']);

# Add phrase hide_ads
Hide ads in this forum?

At this point I tested setting the admincp option to 'yes' and verified that the hideads column was set to 1 for the selected forum. It was.

# Set conditional in template
<vb:if condition="$bbuserinfo[userid] == 0 AND $foruminfo['hideads'] == 0">
ad code here </vb:if>

--------------- Added 1359210128 at 1359210128 ---------------

I feel like I need to preregister the variable for the ad templates, but I'm not sure how to define it in this instance. Hideads? $hideads? $foruminfo['hideads']?

--------------- Added 1359213886 at 1359213886 ---------------

I did some more testing and if I use this conditional in FORUMDISPLAY it works as expected...

<vb:if condition="$foruminfo['hideads'] == 0">test</vb:if>

So, it seems that the variable just isn't working in the ad location templates. I'm getting closer. I wish these updates bumped this thread. :(

curriertech
01-27-2013, 01:10 PM
Thanks to Kevin for this. All that needed to change was the syntax of the conditional.
<vb:if condition="$GLOBALS['foruminfo']['hideads']">

Now the whole thing works with just two plugins, a new column in the forum table, and a conditional in the appropriate ad location templates.