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:
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.
$polls = file_get_contents(‘polls.html’);
$polls = preg_replace(’/^.*
]*>(.*)<\/body>.*$/si’, ‘\1’, $polls);
if (!$vbulletin->session->vars[‘loggedin’]) {
# Additional processing here.
$polls .= <<Register or log in to view the rest of this page.
EOF;
}
# Print the results for the user to see.
echo $polls;
?>
Happy hacking.
Comments
Submitted by Carrie on
...and immediately began to wonder what on earth you had against church bulletins. ^_^
Submitted by Chris on
Hah, no.
Submitted by garrettw on
I’m thinking that preg_replace() call might not scale well. It might be more efficient to somehow cache the resulting HTML and just serve that instead (which you could do with a simple include statement), unless polls.html changes quite frequently. But I don’t know the situation; you might not really need that level of efficiency.
when you could just echo $polls (or include the cached file) and then echo ‘your registration text’ when necessary. (Yeah, I used single quotes there—heredoc seems a bit bulky for something so short.)
Also, the concatenation to $polls followed by echoing $polls probably wastes an infinitesimal about of processing power
Submitted by Chris on
It turns out that I have to expand this script to serve multiple files, but caching may be a good idea if the site were slashdotted (yeah, right
). The polls page probably changes once a month (as a guess).
The concatenation and then later echo is supposed to improve code readability. I cut out the processing that happened inside the if block.
For my comments in PHP, I use hashes to comment code and // or /* */ to comment out code… It just helps me see what a comment is doing without reading it.
Submitted by garrettw on
I see. I just don’t comment my code, even though I should.
Submitted by Chris on
That’s why it’s called “code,” right?
Submitted by garrettw on
Exxxactly.