Plugins and Products
One of the new features available in vBulletin 3.5 is plugins and products. Plugins and products are a new and easy way to add new features to a vBulletin installation.
There are some differences between a plugin and a product. A plugin allows new features to be added to a core vBuletin installation. In other words, it is a code snippet imported into vBulletin and executed by specific hooks. This is an easy way to extend functionality without making changes to the underlying PHP files of vBulletin.
A product is a downloadable package that contains notonly plugins but also templates, options, phrases, help files, and control panel entries. This means that these are a bigger, more integrated types of plugins.
Hooks are what drives plugins. These are locations within the PHP code of vBulletin that trigger events. These events can be used to run code contained in plugins. You can view these hooks from the AdminCP by clicking on Plugin Systemfollowed by Add New Plugin, and then clicking on the Hook Location drop-down box.
Getting Plugins and Products
Plenty of plugins and products that are designed to carry out a multitude of tasks are available for download. In fact, many hacks and board modifications have been converted to plugins and products because of the ease of installation.
The best place to begin your search for plugins is http://www.vbulletin.org.
Adding a Plugin
Adding a plugin to a vBulletin installation is much easier. From the AdminCP, click on Plugin System followed by Add New Plugin .
In this screen you can cut and paste the code from the instructions you have, and choose the necessary hook to execute the plugin.
After making all the changes, click on Save, and the plugin will be added to vBulletin and be ready to use.
What If Things Go Wrong?
Whenever you add any new code to a vBulletin installation, there is a chance that things may go wrong. The worst-case scenario is that you bring down the whole vBulletin board and make it totally inaccessible.
Fortunately, there's a global way to disable plugins, and it doesn't require access to the vBulleting interface, only FTP access to the server.
All you need to do is find the includes/config.php file and add the following code:
Define('DISABLE_HOOKS', true);
Save the file and upload it to the server. Now vBulletin will run without plugins, and this gives you a chance to remove the offending product or plugin using Manage Products or Manage Plugins from the AdminCP.
Once you have removed the offending plugin, you can reactivate the plugin system by removing that line of code from includes/config.php.
Summary
In this article we've looked at another code modification, but this time instead of concentrating on the hack itself we paid attention to the process of making a hack to the code of a vBulletin board. You are likely to want to carry out a number of hacks to your board, and with each one you will increase your knowledge and understanding of how the board works. With time you will get an understanding of how the different templates and PHP files interact, and this is when you are most likely to start to think about creating your own hacks.
Take your time when creating your own hacks don't rush it. Take advantage of the vBulletin licensing policy, and work on a test-bed installation of the discussion board that way, if things go badly wrong, you don't bring your whole forum down!
Here are the default usergroup settings for these usergroups.
Default Usergroup Settings
vBulletin comes pre-configured with seven default usergroups and one custom usergroup.
Programmer's Reference
This article has information that you may need if you are going to delve deeper into your vBulletin installation, and make changes, tweaks, and other hacks.
In this article we will look at:
- • The settings for the default usergroups
- • The default database tables created by a vBulletin installation
- • How to migrate to a new server
- • How graphics work in vBulletin
- • How to find and replace text in posts
- • Some tips on how to program for vBulletin
Default Usergroup Settings
vBulletin comes pre-configured with seven default usergroups and one custom usergroup.
Moving Servers in Six Easy Steps
If your discussion board grows beyond the capabilities offered by your current host, then you can migrate the whole vBulletin installation from one server to another with the minimum of fuss and effort. In this section we will look at how to do this.
We can break down the server move into six easy steps.
- • Cookie check
- • Back up database
- • Download the vBulletin installation
- • Transfer to new server
- • Restore database
- • Back online!
Cookie Check
The first thing to do is check on the current cookie settings. Setting a specific cookie domain and cookie paths can cause problems for you when moving servers or even changing the URL of the discussion board. To prevent these problems, reset your cookie path to / and remove any cookie domain value that might be present before carrying out the server move.
A warning about cookies!
An incorrectly set cookie domain or path can prevent you from accessing your control panel!
Back up Database
The next step is to back up the database. Refer to Article 5 for full details on how to do this. Make sure that you use an up-to-date backup and that you've locked the forum prior to carrying out the backup so that there can be no changes made to the data.
Download the vBulletin Files
Using an FTP program, download your current vBulletin installation to your PC. You could reinstall vBulletin onto the new server, but you will lose any changes you made.
Transfer to New Server
The quickest and easiest way to transfer the database to a new server is using SSH or Telnet.
New Host Tips
Make sure that your new host allows you to have such shell access. (They might not allow it as standard, but check to see if they will allow it temporarily to allow you to carry out the move.)
Follow this simple transfer process.
- 1. Telnet into your existing server.
- 2. Type the following: ftp NEWSERVER Where NEWSERVER is the hostname or IP address of your new server. You will be prompted for a username and password to login.
- 3. Next, type: bin cd /PATH/TO/NEW/DIRECTORY put /PATH/TO/DATABASE/DUMP.SQL replacing /PATH/TO/NEW/DIRECTORY by the path to the directory where you want to place the database backup and /PATH/TO/DATABASE/DUMP.SQL by the path to the database dump. If you omit this step, the backup will be put into the root of the server.
- 4. This process will now transfer the database.
- 5. When completed, type: close quit
- 6. Verify that the database has been transferred.
Database Restoration
- 1. On the new server, create the database in which your vBulletin data will be installed.
- 2. Telnet/SSH into the new server.
- 3. Type: mysql -USERNAME -p NEWDATABASENAME < PATH/TO/DUMP.SQL
replacing USERNAME by the username to access the database, NEWDATABASENAME by the name of the new database, and /PATH/TO/DUMP.SQL by the path to the database backup file.
Back Online
Upload your vBulletin files (the ones you downloaded earlier) remembering first to edit the includes/config.php file. Edit $servername, $dbusername, $dbpassword, and $dbname with the values that correspond with the new server.
Finally, log into the forum. Everything should be working as normal.
If, during the server change, you changed the URL used to access the community, then you'll also need to change BB URL value. Log in to the administrator control panel, go to the vBulletin Options section, and change you BB URL to correspond to the new URL.
Graphics
The graphics that you see in a standard vBulletin installation are not standard graphics. They started life as 3D objects and scenes created in an application called Lightwave 3D. The resulting rendered images were then post-processed using Adobe Photoshop.
3D graphics work differently from normal graphics the edges of the images do not end in a sharply defined pixel border. Instead they are matted to a specific background color. If you use the default background colors in vBulletin, then everything will be fine. However, if you change the background colors of the page, then you may need to do some work on the graphics. To make this easy the vBulletin developers have made available two versions of the Graphics Developer Kit. (You can download them from the vBulletin Members' Area.) The first kit contains fully prepared images, and all you need to do is choose the matte color and save the images. The second kit contains much larger layered images that allow you to make numerous changes to the look of the graphics before saving them.
Lightwave 3D and Adobe Photoshop
For more details on Lightwave 3D visit http://www.newtek.com/lightwave, and for more details on Adobe Photoshop visit http://www.adobe.com/products/photoshop.
Be aware, neither of these applications is cheap!
Global Post Text Find and Replace
This is something that many board administrators want to do but aren't sure how messing with the database directly seems dangerous to many. It is quite simple though, and you can do it all through the AdminCP.
Log into the AdminCP, and in the left-hand menu click on Import & Maintenance followed by Execute SQL Query. If you are greeted with a message that says: You are not authorized to execute SQL queries you will need to add your user ID number to the line: $canrunqueries = ''; in the includes/config.php file. For example, if your user ID is 1, this line will become: $canrunqueries = '1';
Now you can run queries. To carry out a find and replace on all the post data in your board, you will need to run an SQL query like this: UPDATE post SET pagetext = REPLACE (pagetext,'Vbulletin','vBulletin') WHERE pagetext LIKE '% Vbulletin%';
This SQL query looks through the posts for instances of Vbulletin and replaces them with vBulletin. The WHERE clause is used to optimize the find and replace as this allows MySQL to take advantages of indexes, which speeds things up.
If you get an error running this query then check to see if you are using a table prefix in the database for the tables (such as vb_) and add this to the query. This would change the query to the following: UPDATE vb_post SET pagetext = REPLACE (pagetext,'Vbulletin','vBulletin') WHERE pagetext LIKE '% Vbulletin%';
If you wanted to carry out a similar find and replace within PMs, you'd use the following query: UPDATE pmtext SET message = REPLACE (message,'Vbulletin','vBulletin') WHERE message LIKE '%Vbulletin%';
By using MySQL queries you are taking total control over the data held in the database. We don't have the time or scope here to cover MySQL queries in detail, so for more information visit http://dev.mysql.com. Alternatively, you can read Mastering phpMyAdmin for Effective MySQL Management by Marc Delisle, published by Packt Publishing (ISBN 1-904811-03-5).
Programming Standards
Good programming is clear, unambiguous programming. Let's run through a few tips to help make your code more readable, easier to debug, and easier to make changes to later on.
Braces
For clarity each brace should be placed on its own line in the code:
if ($condition)
{
// code goes here
}
Don't be tempted to condense code like this:
if ($condition)
{ // code goes here }
Indenting
Indent code between braces:
if ($condition)
{
// code goes here
}
Code between braces within braces should have deeper indenting:
if ($condition)
{
if ($condition2)
{
// code goes here
}
// some more code goes here
}
Give Operators Space
All operators (except -- and ++) should have a space either side.
$a = $b + $c;
String Quoting
All strings should be quoted with single quotes when they don't contain variables or control characters. Otherwise always use double quotes:
$a = 'Hello, World!';
$b = "Hello,\nWorld!";
$c = "$hello,\nWorld!";
Return Values
Use only lower-case true and false for return values. Upper-case should be reserved for custom constants.
if ($condition)
{
return true;
}
else
{
return false;
}
AND and OR
Always use AND rather than and or &&, and OR rather than or or || in your code.
if ($num1 AND $num2 OR $num3)
AS
Similarly, AS in foreach statements should be capitalized.
foreach ($array AS $num => $var)
{
// code goes here
}
SQL Queries
Under all circumstances, make sure that you double quote all SQL queries.
$DB_site->query("SELECT field FROM " . TABLE_PREFIX . "table ORDER BY field");
It may be better to write long queries on more than one line.
Summary
This article has been a rundown of information that will be of use to those who plan to do more with their vBulletin installation than just install it and leave it be. While really only scratching the surface of vBulletin, we're presented the information people request most often.
|