Developing a hack for a vBulletin installation

an article added by: Linda Gould at 05312007


In: Root » Internet and online » Forums » Developing a hack for a vBulletin installation

French Spanish Portuguese Italian German Japanese Chinese Korean Russian Arabic

Developing a Hack
In this article we'll be looking at how you go about developing a hack for a vBulletin installation. Being based on the PHP language and on MySQL database infrastructure makes vBulletin very versatile, so we're going to have to limit our scope. Almost anything that you would want to do with vBulletin is possible if you know how to leverage PHP and MySQL!
In particular we will look at:
• How to hack a discussion board by changing one of the template files
• How to distribute a hack by giving other programmers clear instructions about the code changes
Hacking vBulletin
Let's take a look at how to create a vBulletin hack. The hack we're going to be developing here is one that allows you to control how vBulletin handles private message receipts. As we saw in Article 3, private messages, known as PMs, are messages that one member can send to another member of the board.

The member types a message into the private message window and then clicks on the SubmitMessagebutton.
The recipient can collect the message the next time they log in (or, if they are already logged in, the next time they request a new page from the board).
But there's one feature that seems to annoy some members (especially if it's a popular board where the members make a lot of use of the PM facility). This is the read receipt feature. When a PM is submitted, a message box is displayed asking the sender whether they want to request a read receipt.

Read receipts are a useful feature, but the problem is the message box displayed people find it gets in the way and often they won't want to send a read receipt with every message. You as the administrator can do something about this you can hack your vBulletin installation to give your members greater control over how read receipts are handled.
You have the power …
… to disable private messaging read receipts altogether. In the left-hand menu in the AdminCP, click on Usergroupsfollowed by Usergroup Manager. Then for each usergroup you don't want to have this feature, click on EditUsergroup and set CanUse Message Trackingand CanDeny Private MessageReadReceipt Requestto No. Doing this, however, will remove the ability for members to request a read receipt. It would be much better to simply change how the request works.

Making the Changes
Let's now work through how to make this hack possible. There are a few code changes you need to make to a vBulletin template. If things go wrong, you already know how to revert templates back to their original state. As long as you take care and follow the code here carefully, everything will work out fine. But always keep a backup just in case!
Locating the Template
In the left-hand menu of the AdminCP, click on Styles& Templates to expand it, and then click on Style Manager .

This brings up the Style Managerpage in the right-hand side screen. Click on the button marked << >> to expand the template window.

You now need to click on the new button marked << >> lower down on the page to expand all the templates so as to find the one you are looking for.

In the scrolling window, work your way down until you get to a template called pm_newpm. Double-click on the link to open the template.

Hacking the pm_newpm Template
You can now make a few changes to this template. These changes involve removing the existing code that causes the prompt to appear and adding new code that provides a checkbox so that the sender can request a read receipt if they want one.
The first thing you need to do is locate the following segment of JavaScript code in the template:
else if (formname.dopreview != true)
{
<if condition="$show['trackpm']">
if (confirm("$vbphrase[request_receipt_for_message]"))
{
formname.receipt.value = 1;
}
</if>
}
You need to remove this section of code. Rather than delete it outright it's much better to just comment out the code by adding // and a space to the beginning of each line of the script:
// else if (formname.dopreview != true)
// {
and so on.
While you're doing this, it's a good idea to add a note so that later you will be reminded later why you commented it out!
// Begin PM read receipt hack
// else if (formname.dopreview != true)
// {

// }
// End PM read receipt hack

Next, within the same template, find this segment of code:
<input type="hidden" name="receipt" value="0" />
(This will be on one long line, so it may be rather hard to find.) Comment this out too. Since this is HTML, we comment it out by placing <!-- and --> around the line. Again, it's wise to add comments to the code to remind you why you removed the line:
<!-- Begin PM read receipt hack -->
<!-- line removed -->
<!-- <input type="hidden" name="receipt" value="0" /> -->
<!-- End PM read receipt hack -->
Next, look for the following segment of code:
<div>
<label for="cb_parseurl">
<input type="checkbox" name="parseurl" value="1" id="cb_parseurl"
tabindex="1" $checked[parseurl] />
$vbphrase[automatically_parse_links_in_text]
</label>
</div>
When you locate it, you need to add below it as follows (again remembering to add the comments):
<!-- Begin PM read receipt hack -->
<!-- line added -->
<div>
<label for="cb_receipt">
<input type="checkbox" name="receipt" id="cb_receipt" value="1" />
Request Read Receipt?
</label>
</div>
<!-- End PM read receipt hack -->
Now that you've made the modifications to the code, you can save it by clicking on the Save button.
Testing the Hack
Testing is simple try sending a PM! When you are in the private message window, you will see the new checkbox enabling you to specify that you want a read receipt for the message you send. Try a couple of tests, one with a read receipt request and another one without, just to make sure it all works.

Next, within the same template, find this segment of code:
<input type="hidden" name="receipt" value="0" />
(This will be on one long line, so it may be rather hard to find.) Comment this out too. Since this is HTML, we comment it out by placing <!-- and --> around the line. Again, it's wise to add comments to the code to remind you why you removed the line:
<!-- Begin PM read receipt hack -->
<!-- line removed -->
<!-- <input type="hidden" name="receipt" value="0" /> -->
<!-- End PM read receipt hack -->
Next, look for the following segment of code:
<div>
<label for="cb_parseurl">
<input type="checkbox" name="parseurl" value="1" id="cb_parseurl"
tabindex="1" $checked[parseurl] />
$vbphrase[automatically_parse_links_in_text]
</label>
</div>
When you locate it, you need to add below it as follows (again remembering to add the comments):
<!-- Begin PM read receipt hack -->
<!-- line added -->
<div>
<label for="cb_receipt">
<input type="checkbox" name="receipt" id="cb_receipt" value="1" />
Request Read Receipt?
</label>
</div>
<!-- End PM read receipt hack -->
Now that you've made the modifications to the code, you can save it by clicking on the Save button.
Testing the Hack
Testing is simple try sending a PM! When you are in the private message window, you will see the new checkbox enabling you to specify that you want a read receipt for the message you send. Try a couple of tests, one with a read receipt request and another one without, just to make sure it all works.

Hack Distribution
So now you have a hack and you want to make it available to other people. The question is, how do you do this? The license agreement prevents you from distributing whole templates, and anyway, you're only making small changes to the template so it's silly to get people to replace code that is unchanged.
The best way to distribute hacks is in the form of clear instructions that others can easily follow. There are many ways to do this but the following is an example of one way that is clear and straightforward.
MODIFICATION – PM READ RECEIPT CHECKBOX Version 1.0.2
-----------------------------------------------------
Open TEMPLATE pm_newpm
Find and DELETE/COMMENT OUT:
else if (formname.dopreview != true)
{
<if condition="$show['trackpm']">
if (confirm("$vbphrase[request_receipt_for_message]"))
{
formname.receipt.value = 1;
}
</if>
}
Find and DELETE/COMMENT OUT:
<input type="hidden" name="receipt" value="0" />
Find:
<div>
<label for="cb_parseurl">
<input type="checkbox" name="parseurl" value="1"
id="cb_parseurl" tabindex="1" $checked[parseurl] />
$vbphrase[automatically_parse_links_in_text]
</label>
</div>
Below code ADD:
<div>
<label for="cb_receipt">
<input type="checkbox" name="receipt" id="cb_receipt" value="1" />
Request Read Receipt?
</label>
</div>
SAVE pm_newpm and CLOSE.
Test modification.
END OF MODIFICATION

With this hack we needed only to modify templates, but there are times when you need to document edits to settings or even to actual PHP files. Settings changes can be documented by specifying the menu navigation and the final setting change.

Admin CP -> Usergroups -> Usergroup Manager -> Edit Usergroup
Set "Can Use Message Tracking"
and "Can Deny Private Message Read Receipt Request" to "No".
The PHP file modification that we saw in Article 4 can also be documented in this way:
PAYPAL MODIFICATION Version 1.0.2
---------------------------------
Open includes\functions_subscriptions.php
Find:
<input type=\"hidden\" name=\"no_shipping\" value=\"1\" />
Replace with:
<input type=\"hidden\" name=\"no_shipping\" value=\"0\" />
SAVE and UPLOAD
Test modification.
END OF MODIFICATION
-------------------
Tips for Hack Distribution
Here are a few tips that make code distribution easier for both you and the person following the instructions:
1. Test hacks thoroughly. If possible, try them out on a test installation of vBulletin before making changes to your active board.
2. Be specific as to which file or template requires modification.
3. Replace whole lines of code don't mess about trying to explain which bit of the line needs changing.
4. Feel free to add comments to the code you include. This will make life easier for the person using the instructions but will also bulk out your code.
5. Be clear as to what code you want the user to find and what they should then do with it (e.g. replace it with different code or add something above or below it). Be careful to check that the code you want the user to search for isn't duplicated elsewhere in the file. If this is the case, then be more specific and display more than one line of code.
6. Don't use line numbers these can change with updates to the software. Also, any code changes (or other hacks) above the line will cause the line numbers to be wrong.
7. Make sure that you give the proper name for the template or PHP file you want editing. In the case of PHP files, include the path within the vBulletin installation.

8. Keep version numbers updated. If you make a small change to the code (to fix a typo say or make a small modification), then change the minor version number (say from 1.0.2 to 1.0.3). For big changes or alterations that allow the code to work for a new version of vBulletin, change the major version number (say from 1.0.4 to 2.0.0).

legal disclaimer

Our website is not responsible for the information contained by this article. Web-articles is a free articles resource.
Suggestion: If you need fresh, daily updated content for your website, feel free to use our service. Click here for more information.

related articles

1. Introduction to the vBulletin Board
Before we see how to install vBulletin, and how to customize and hack the board, let's take a little time to look at the board, the company behind it, and a little of its history. We will also show you what other people have accomplished with this most versatile and powerful board. What is vBulletin? This is a good place to start! vBulletin is software that is loaded onto a web server to allow you to create and manage online forums or discussion boards. It is des...

2. The vBulletin Advantage
The vBulletin Advantage What are the key benefits from choosing and running vBulletin? Here are the top reasons to base your community on vBulletin. Versatile vBulletin is designed to be versatile and can be run on a variety of platforms. • vBulletin is written in PHP, making it fast, efficient, and capable of running on a broad range of hosting platforms. Shared hosting provides the cheapest option, while semi-dedicated hosting solutions offer more power...

3. vBulletin Licensing Options
vBulletin Licensing Options vBulletin is a commercial product, and you must therefore buy a license before you can use it. To offer site owners the greatest possible flexibility there are two licensing options to choose from: • Leased license • Owned license Leased License Purchasing a leased license will allow you to run vBulletin on your server for one year. During this period you will be entitled to technical support and softwa...

4. The requirements of vBulletin
In the next article we're going to be shifting our focus to the installation and configuration of vBulletin. In this article we begin at the point where most people begin with vBulletin with a copy of the software and somewhere to upload it to. If you have both of those, then you are probably eager to get going with the installation! We will look at: • The requirements of vBulletin • How to install the files • How to create the database • How ...

5. The vBulletin Control Panel
The vBulletin Control Panel Now that you have come this far, you are probably eager to access the Control Panel and get started. Click on the link on the Step 13 page to access the Control Panel. (You will need to have deleted the install/install.php file before being able to continue.) After clicking on the link you will then need to enter the username and password you assigned to the administrator during the installation of vBulletin. Once you log into the Control P...

6. Importing Data into vBulletin
If you are moving to vBulletin from another type of discussion board, then there is a good chance that you won't want to lose all the posts that you already have and start again with nothing. And it's not just the posts that are important what about all your member information usernames, passwords, profile data? You don't want to lose all that and start with aIn the right-hand pane you get information about the version notice how we are being told that there is a newer version of vBulletin available. That's a really handy feature, and...

7. The vBulletin User Experience
A Tour of vBulletin In the previous article we looked at the vBulletin installation process. This process involved downloading the installation files, making edits to the configuration files, creating or preparing a database for vBulletin, uploading the installation files, and finally going through the vBulletin installation wizard. We also looked at how to import posts and settings from another discussion board into vBulletin. Now that you have a working vBulletin board, the next thing that you need to do is famili...

8. Customizing Your vBulletin Board
  Customizing Your vBulletin Board Most of the best discussion boards on the Web have been customized in one way or another. Some have only basic customizations to give the place a specific look and feel, while others have been heavily modified and customized to look, feel, and work exactly how the owners want them to. At this stage you probably want something in the middle you want a certain level of customization but don't want to take on too much too soon, right? That's fine the g...

9. vBulletin templates
Template Modifications So far we've looked at how to modify CSS stylesheet information, which controls how vBulletin looks, and the phrases, which control the text. Both of these modifications allow you to radically change how your vBulletin board looks and feels. Template modifications allow you to do a lot more and to make much more radical changes to your vBulletin installation. In fact, templates control nearly every aspect of a vBulletin board. Each page that the end user sees is the result of one or mo...

10. Hacking a vBulletin Board
Hacks So far we've talked about making modifications to a vBulletin installation, and we've looked at four different ways to modify the installation. So far we've called the changes 'modifications', but the term that you are more likely to see used on the web is 'hacks'. Whenever a board is modified, it is said to be hacked (not to be confused with 'hacked' as in the security being compromised by a hacker), and modifications are known as hacks as in "hacks to a board"...