vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vBulletin 3 Articles (https://vborg.vbsupport.ru/forumdisplay.php?f=187)
-   -   Add options per forum (https://vborg.vbsupport.ru/showthread.php?t=93445)

Logikos 08-01-2005 10:00 PM

Add options per forum
 
What this is
This guide will teach you to use the hooks system to add options to your admincp/forum.php page. One finished, you will be able to add new options to your forum with just a few lines of code.

Don't understand?
Ever wanted to turn something on, but only in one of your forums? For example, lets say you want to execute code, but only in forum I.D. 2, 16, and 45.

Lets begin!
In this tutorial we will assume that you want a yes or no option; in order to enable/disable some code. In order to do that we first need to create a new row in the database. This will hold the information of which forums will be enabled/disabled. Always remember that '1' is considered as on, or enabled. And that '0' is considered off, or disabled.

Please make sure this is all done on a test forum!

We have to store the data!
Run this SQL Query:
[sql]
ALTER TABLE forum ADD (
var smallint(3) unsigned not null default ''
)
[/sql]

Var = The name of the row in the database. This should be a name that will describe your system in one word. For example. In my vB Category Icons hack. This row is named 'forumhomeicon'

Now that we have added our new row named 'var'. We now have to add the on/off option in the forums manager area of the admin control panel.

Add the option in the ACP
To add this new option in the ACP we need to create a new hook and add some code to that hook.

The hook name should be: forumadmin_edit_form
And the code should be:
PHP Code:

print_input_row($vbphrase['your_phrase'], 'forum[var]'$forum['var']); 

Notice the 'var'? Remember, that's the row name!
That will actually add the yes/no row to all your forums in the admincp. So when you click on the save button, it will add your selection to the database.

But how does it know which row to add it to? Glad you asked.

You have to create one more hook!
The hook name should be: forumdata_start
And the code to add there is the following
PHP Code:

$this->validfields['var'] = array(TYPE_STRREQ_NO); 

Notice the var again? That's telling it which row to add it to.

I want to add more then just one option!
Then you will need to repeat this tutorial for each option you would like to have.

Now that you have saved both hooks. You can now use the following code in any of your hooks.

PHP Code:

if ($foruminfo['var'] == 1)
{
     
// your code here


In templates you would use

HTML Code:

<if condition="$foruminfo['var'] == 1">
    <!-- Your Code Here -->
</if>

Big Tip:
If you have 2 or more options being added to the forums, you can place all the code in each hook. For example:

Hookname: forumadmin_edit_form
Code:
PHP Code:

print_input_row($vbphrase['your_phrase'], 'forum[var1]'$forum['var1']);
print_input_row($vbphrase['your_phrase'], 'forum[var2]'$forum['var2']); 

Hook Name: forumdata_start
Code:
PHP Code:

$this->validfields['var1'] = array(TYPE_STRREQ_NO);
$this->validfields['var2'] = array(TYPE_STRREQ_NO); 

You don't have to keep creating new hooks for more options for the same hack. Is better to only create hooks for separate hacks.



Custom Fields
The following fields can also be used.
PHP Code:

// This will print an input form. Good for titles, and such.
print_input_row($vbphrase['your_phrase'], 'forum[var]'$forum['var']); 

PHP Code:

//This will print a yes or no row
print_yes_no_row($vbphrase['your_phrase'], 'forum[var]'$forum['var']); 

PHP Code:

//This will print a text area. Good for descriptions
print_textarea_row($vbphrase['your_phrase'], 'forum[var]'$forum['var']); 

There are more that can be used. When I have some more time I will add them all here. :)

This tutorial was created for a member who needed to know how to do this exact thing, so I figured I would teach everyone. :p

akanevsky 08-02-2005 01:19 PM

There is actually an easier way:
Just add a new bit to the $_FORUMOPTIONS array and you are there. Why alter the database?

Logikos 08-02-2005 01:24 PM

Quote:

Originally Posted by Dark Visor
There is actually an easier way:
Just add a new bit to the $_FORUMOPTIONS array and you are there. Why alter the database?

Care to share?

Andreas 08-02-2005 01:29 PM

Using existing Bitfields is bad coding style ;)
This will cause problems sooner or later when Jelsoft starts to use further Bits.

Furthermore, $_FORUMOPTIONS doesn't even exist in vBulletin 3.5

And as it is possible not to use forumoptions here, it should be encouraged to do so (eg. use custom fields).
This is official Jelsoft stance regarding Bitfields.

Logikos 08-02-2005 01:32 PM

Thanks for clearing that up Andreas. I thought the way I was doing it was incorrect for a min.

Andreas 08-02-2005 01:35 PM

Nope, it's absolutely correct - but you might want to point out that if you are adding a bunch of Yes/No type settings, it could be a good idea to introduce a custom bitfield :)

Logikos 08-02-2005 01:39 PM

Quote:

Originally Posted by KirbyDE
but you might want to point out that if you are adding a bunch of Yes/No type settings, it could be a good idea to introduce a custom bitfield

Thanks, I'll edit my first post with all of them in a few mins. After I type them all. :)

akanevsky 08-02-2005 02:01 PM

Quote:

Using existing Bitfields is bad coding style
Umm... Why? Did you just make this up?

Quote:

This will cause problems sooner or later when Jelsoft starts to use further Bits.
That would be a release of a new version. And the hack would have to be recoded anyways.

Quote:

Furthermore, $_FORUMOPTIONS doesn't even exist in vBulletin 3.5
You're right. I thought it was there because it was in 3.0.7. I am sure there is another variable of that kind, I'ma go and take a look at the code.. By the way, I used custom bitfields in one of my hacks for 3.0.7.. It was fine.

Quote:

And as it is possible not to use forumoptions here, it should be encouraged to do so (eg. use custom fields).
This is official Jelsoft stance regarding Bitfields.
Then they should make "custom fields" for forums just like there are some for users.

Quote:

Thanks for clearing that up Andreas. I thought the way I was doing it was incorrect for a min.
Didn't say "incorrect". Just wanted to suggest a way that does not involve changing DB.. ;)

Logikos 08-02-2005 02:07 PM

When i said incorrect, I meant not to your coding standards. ;)

Andreas 08-02-2005 02:09 PM

Quote:

Originally Posted by Dark Visor
Umm... Why? Did you just make this up?

No. As said, this is official Jelsoft stance.
It is bad, as (in contrary to custom tables/colums/variables) using default vBulletin Bitfields for custom settings will cause Problems.

Wort Case scenario: Your Hack uses the next available Bit in forumoptions for "Show Quick Stats for this Forum".
Now the next vBulletin Version comes and redifines this Bit to "Prune this Forum every 24 hours".
Now all users of this Hack have the Bit set ...


Quote:

Then they should make "custom fields" for forums just like there are some for users.
Well, what does adding a custom field do?
It adds a record to Table profilefield and alters table userfield to have a new MEDIUMTEXT columd fieldxx.
This is just an easy-to-use frontend to alter the Database, so where is the difference?

Keeping the Product Manager in mind, such DB alterations can be done easily, without the User having to know anything about running queries.

akanevsky 08-02-2005 02:20 PM

Quote:

When i said incorrect, I meant not to your coding standards.
Jeez. Not mine... Jelsoft's.

Quote:

Wort Case scenario: Your Hack uses the next available Bit in forumoptions for "Show Quick Stats for this Forum".
Now the next vBulletin Version comes and redifines this Bit to "Prune this Forum every 24 hours".
Now all users of this Hack have the Bit set ...
The hack was not tested on the new version therefore it should not be installed.

Quote:

Well, what does adding a custom field do?
It adds a record to Table profilefield and alters table userfield to have a new MEDIUMTEXT columd fieldxx.
This is just an easy-to-use frontend to alter the Database, so where is the difference?
Difference is the errors on the user side.

Quote:

Keeping the Product Manager in mind, such DB alterations can be done easily, without the User having to know anything about running queries.
That's true. :) I still have to get used to the existence of that manager.

Oh, there is an array called $vbulletin->bf_misc_forumoptions, but I cannot find out how is it populated. :(

Andreas 08-02-2005 02:32 PM

Quote:

Originally Posted by Dark Visor
The hack was not tested on the new version therefore it should not be installed.

You don't seem to see the Problem:
The Hack was installed on the previous Version, which means the Bit is currently set.
No matter if the Users reinstalls it on the new Version (without verified compatiablilty or not), the Bit is still set.[/QUOTE]

Quote:

Oh, there is an array called $vbulletin->bf_misc_forumoptions, but I cannot find out how is it populated.
Refer to my Usergroup Permissions How-To ;)

akanevsky 08-02-2005 02:45 PM

Quote:

The Hack was installed on the previous Version, which means the Bit is currently set.
No matter if the Users reinstalls it on the new Version (without verified compatiablilty or not), the Bit is still set.
[/QUOTE]

Ahhh... Crap. Yes, you are right. Solution:
Upon upgrade, let upgrade.php remove all the new bits from the data storage.

Andreas 08-02-2005 02:57 PM

That would mean Jelsoft taking responsiblity for custom Code - this won't happen :)
It's our responsibility to avoid such things.

akanevsky 08-02-2005 03:01 PM

Quote:

That would mean Jelsoft taking responsiblity for custom Code - this won't happen
It's our responsibility to avoid such things.
No, it would mean Jelsoft taking the measures to avoid the possible negative outside influence of any previously installed hackware. :P

Would you please change the thread's title and prefix it with [How-To]? That way all the how to threads stand out :) Thx.

Revan 08-02-2005 05:15 PM

[sql]var smallint(3) not null default ''[/sql]shouldnt it be[sql]var smallint(3) unsigned not null default ''[/sql]?

Marco van Herwaarden 08-02-2005 07:29 PM

Unsigned woul be better, since you will be able to store more options.

Chris M 08-02-2005 10:54 PM

Quote:

Originally Posted by Dark Visor
No, it would mean Jelsoft taking the measures to avoid the possible negative outside influence of any previously installed hackware. :P

Would you please change the thread's title and prefix it with [How-To]? That way all the how to threads stand out :) Thx.

Jelsoft do not support modified boards - This would come under such a heading, therefore since you do not need to alter the bitfields with a standard installation of vBulletin, unless they alter their own bitfields in an upgrade they should not have to cater for such an scenario :)

Satan

Logikos 08-02-2005 11:18 PM

Quote:

Originally Posted by Dark Visor
Would you please change the thread's title and prefix it with [How-To]? That way all the how to threads stand out Thx.

Read the first 2 words in the thread title. How to add options per forum. :rolleyes:

Thanks Revan, fixed first post.

akanevsky 08-03-2005 12:06 AM

How-To without braces tho :(

Code Monkey 10-02-2005 05:07 PM

Quote:

Add the option in the ACP
To add this new option in the ACP we need to create a new hook and add some code to that hook.
How and where do I do that?

Rebecca217 10-11-2005 11:02 PM

Thank you so much for this tutorial. I found it very helpful! :)

Rebecca

JimNY 10-12-2005 02:05 AM

Hi everyone,

i am new to this but i like know how to add the following pages to my site.

home --><--forum---><--Link Page--> <--Resources--><--etc-->

How do I go about doing just that? Any help would be appreciated.

JimNY 10-13-2005 11:13 AM

Hi Everyone,

Can some help me please?

Evil X 10-20-2005 01:25 AM

I want to make make it so when users post in my graphic forum, it has a drop down below the title were it will say Experience: and they can choose from noobie or pro or basic and then it will add it to the title... (ie they put pro as thier graphic experience) so it would say something like this in the title- Check out this new design!!![PRO]

akanevsky 10-28-2005 11:21 PM

Dude, this is vBulletin 3.5, and the stuff in this tutorial could be done via XML...
HINT: <group name="misc"><group name="forumoptions">...</group></group>

badnans 11-17-2005 08:53 AM

How do I allow end users to ADD A NEW FORUM? By end users, I mean, registered users who are neither administrators, nor moderators. I am trying to look for a complete example using vB_DataManager_Forum.

Marco van Herwaarden 11-17-2005 06:44 PM

Could you please try to explain what you want to achieve. This sounds like it is getting very close to the borders of the license agreement.

badnans 11-18-2005 10:33 AM

Quote:

Originally Posted by MarcoH64
Could you please try to explain what you want to achieve. This sounds like it is getting very close to the borders of the license agreement.

Was that message for my query? If a registered user has to create a Forum Topic, is it violation of vBulletin Agreement??? :surprised:

By the way, I figured it out:
Code:

$forum = array(
        'title' => 'My Forum Topic,
        'description' => '',
        'link' => '',
        'displayorder' => 1,
        'daysprune' => -1,
        'parentid' => 1,
        'newthreademail' => '',
        'newpostemail' => '',
        'options' => array(
                'moderatenewpost' => 0,
                'moderatenewthread' => 0,
                'moderateattach' => 0,
                'warnall' => 0,
                'styleoverride' => 0,
                'canhavepassword' => 1,
                'cancontainthreads' => 0,
                'active' => 1,
                'allowposting' => 0,
                'indexposts' => 0,
                'allowhtml' => 0,
                'allowbbcode' => 1,
                'allowimages' => 1,
                'allowsmilies' => 1,
                'allowicons' => 1,
                'allowratings' => 0,
                'countposts' => 0,
                'showonforumjump' => 1),
        'styleid' => -1,
        'password' => '',
);
$forumdata =& datamanager_init('Forum', $vbulletin, ERRTYPE_CP);
        foreach ($forum AS $varname => $value)
        {
                if ($varname == 'options')
                {
                        foreach ($value AS $key => $val)
                        {
                                $forumdata->set_bitfield('options', $key, $val);
                        }
                }
                else
                {
                        $forumdata->set($varname, $value);
                }
        }

$forumid = $forumdata->save();


Marco van Herwaarden 11-18-2005 03:54 PM

Yes that question was for you, but since you didn't answer what you want to achieve, i can also not anwer if it is a violation of the user agreement.

badnans 11-18-2005 04:26 PM

Quote:

Originally Posted by MarcoH64
but since you didn't answer what you want to achieve

Its a very simple thing I wanted and I thought the question was straightforward. I did answer your query when I asked "If a registered user has to create a Forum Topic"

Here are the details:

I was trying to figure out how I can allow a registered user to add a new "Forum Topic" in my implementation of vBulletin.

What I saw was one can add Forums through the Admin Control Panel and mark them either as Categories or Forums.

My requirement was, under special situations, I would like registered users to add a Forum Topic, and the admin will then approve the forum to be active.

After some study of the documentation and admin code, i was able to figure out how to achieve that using "Datamanager". The code I have posted earlier does what I wanted.

Is this the correct approach? This is similar to adding a User using "Datamanager" as given in one of the examples. I was worried when you mentioned
Quote:

Originally Posted by MarcoH64
This sounds like it is getting very close to the borders of the license agreement.


Marco van Herwaarden 11-18-2005 04:30 PM

As long as it will not allow members to create their own forums and make them look/access them like a standalone board, you will not be breaking the license agreement. Otherwise yes.

badnans 11-18-2005 04:43 PM

Thanks your reply...

Do you mean "standalone forum" as in a separate implementation of vBulletin software?... that isn't the intention.

These will be part of one single implementation and each of the forum topics will have to be approved by the Admin. The Admin might choose to appoint the user who created the forum as its Moderator.

I hope thats in line with the agreement.

Frozen Dreams 12-05-2005 02:45 PM

Just wanted to say thanks, Live Wire. Your tut was just what I needed and really helped cutting down on time I probably would have needed without it. Very helpful indeed!

joefitz 02-07-2006 01:27 AM

FYI, if anyone is interested in a hack that makes it easy to add custom forum permissions (which match up with a set of custom usergroup permissions), check out my hack at:Custom Usergroup Forum Permissions

Livewire, this thread was very useful to me. I'm hoping to incorporate custom forum options into my hack as well, which will provide the ultimate in permissioning...

custom forum permissions-> custom usergroup permissions -> custom forum permissions.

Logikos 02-07-2006 02:23 AM

Glad you found this turorial useful :)

zagman76 03-01-2006 07:55 AM

I am having some trouble with this.

I have done everything to-the-letter, but the custom option (which is the [you] hack) is still being allowed across the board. Is this a function of the [you] hack, or is there something I am missing in these instructions?

I seem to only be able to turn the [you] hack on/off by changing the php code here (from 1 to 0) (this is how I have the [you] hack configured on my site after following the instructions)
PHP Code:

if ($foruminfo['perforumhack'] == 1)
{
     
// your code here

$this->post['message'] = str_replace('[you]'$this->registry->userinfo['username'], $this->post['message']);



the adminCP forum option always defaults to "No" as well - even when I save and re-enter the forum manager.

here is what I used in the forumadmin_edit_forum hook:
PHP Code:

print_yes_no_row($vbphrase['Allow_Hack'], 'vb3_forum[perforumhack]'$vb3_forum['perforumhack']); 

thanks!!

zagman76 03-10-2006 05:31 AM

-bump-


....any help? :)

Logikos 03-10-2006 08:25 AM

This:
PHP Code:

print_yes_no_row($vbphrase['Allow_Hack'], 'vb3_forum[perforumhack]'$vb3_forum['perforumhack']); 

Should Be:
PHP Code:

print_yes_no_row($vbphrase['Allow_Hack'], 'forum[perforumhack]'$forum['perforumhack']); 


Marco van Herwaarden 03-10-2006 08:58 AM

Why you want to use a input_row for a yes/no value?


All times are GMT. The time now is 02:40 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.01770 seconds
  • Memory Usage 1,886KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)bbcode_code_printable
  • (1)bbcode_html_printable
  • (12)bbcode_php_printable
  • (23)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (1)pagenav_pagelink
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (40)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.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/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • pagenav_page
  • pagenav_complete
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete