Go Back   vb.org Archive > vBulletin 4 Discussion > vB4 Programming Discussions
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 01-25-2013, 08:14 PM
curriertech curriertech is offline
 
Join Date: Aug 2005
Location: NH
Posts: 121
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default add custom attribute to forums

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.
Reply With Quote
  #2  
Old 01-25-2013, 08:32 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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.
Reply With Quote
  #3  
Old 01-25-2013, 08:41 PM
curriertech curriertech is offline
 
Join Date: Aug 2005
Location: NH
Posts: 121
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Thank you! I searched my face off and didn't find that on my own.

--------------- Added [DATE]1359164686[/DATE] at [TIME]1359164686[/TIME] ---------------

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.

Code:
# Create new column in forum table called 'hideads'
ALTER TABLE `forum`
ADD COLUMN `hideads` smallint(3) unsigned NOT NULL DEFAULT '0',
Code:
# 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']);
Code:
# 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.

Code:
# Set conditional in template
<vb:if condition="$bbuserinfo[userid] == 0 AND $foruminfo['hideads'] == 0">
ad code here </vb:if>
--------------- Added [DATE]1359210128[/DATE] at [TIME]1359210128[/TIME] ---------------

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 [DATE]1359213886[/DATE] at [TIME]1359213886[/TIME] ---------------

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

Code:
<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.
Reply With Quote
  #4  
Old 01-27-2013, 01:10 PM
curriertech curriertech is offline
 
Join Date: Aug 2005
Location: NH
Posts: 121
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Thanks to Kevin for this. All that needed to change was the syntax of the conditional.
Code:
<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.
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 03:45 PM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.03645 seconds
  • Memory Usage 2,193KB
  • Queries Executed 13 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (6)bbcode_code
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (4)post_thanks_box
  • (4)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (4)post_thanks_postbit_info
  • (4)postbit
  • (4)postbit_onlinestatus
  • (4)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_postinfo_query
  • fetch_postinfo
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete