Paid CMSes can be useful or painful. I’ve ranted about vBulletin before, and have recently had a chance to work with ExpressionEngine v2 (built on CodeIgniter). The phraseology is strange at first, but I actually kind of like EE. Quick reference charts like this one or this one make most of the coding a breeze.
vBulletin, on the other hand, I thoroughly loath. The customer who had wanted it installed several months back now needs the install to be modified. Where the EE community is fairly open because the underlying framework is open source, vBulletin decided to silence complaining customers by locking them out of the forums. Their stranglehold also prevents people like me, who freelance but do not own our own vBulletin licenses, from accessing any useful community information on how to modify vBulletin.
So I hack. And I’m going to publish my hacks.
First up, my customer wants users to be redirected to the registration page instead of the login page when document permissions require them to sign up. I know, I prefer a login page as well, but this is what was requested.
You can read about how necessary search tools like grep are on my last vBulletin post. The login page for user permissions is coded into a template called STANDARD_ERROR. I was unable to find a way to make vBulletin perform a redirect (and including the “register” template was a fail), so I inserted a small JavaScript snippet inside of a logic block:
<vb:if condition="$show['permission_error']">
<script type="text/javascript">
var url = document.location.href;
url = escape(url.replace(/^.*?\.com/i, ''));
document.location.href = '/register.php?link='+url;
</script>
</vb:if>
This takes the current URL, strips off the domain name, and then passes it as a url-encoded string to register.php.
The second update requested was to give unregistered users a preview of a custom CMPS page. CMPS allows you to upload static HTML pages to the server and then serve them through vBulletin.
My first step was to change the page type from “HTML File” to “PHP File,” and to upload a simple PHP script (polls-process.php) for vBulletin to use instead of the HTML file (polls.html). The PHP script used file_get_contents() to read the original file (polls.html) and print it to STDOUT. That worked beautifully.
The second step was to learn how to detect logged-in users in the PHP file. As usual, grep was a very good friend because I am locked out of anything useful on the vBulletin forums. With a few searches and trials, I found that the $vbulletin global is available, which makes this the code to detect a signed-in user: $vbulletin->session->vars[’loggedin’].
I am going to keep some of the processing quiet because this is on a live website, but here is an example to help you perform the same hack on your site:
<?php
# Read the HTML file and strip it down for vBulletin.n$polls = file_get_contents('polls.html');n$polls = preg_replace('/^.*<body[^>]*>(.*)<\/body>.*$/si', '\1', $polls);
if (!$vbulletin->session->vars['loggedin']) {
# Additional processing here.
$polls .= <<<EOF
You must <a href="/register">Register</a> or log in to view the rest of this page.
EOF;
}
# Print the results for the user to see.necho $polls;
?>
Happy hacking.