Vanilla In the Cloud
A nice forum application with a single-sign-on plugin that's easy to use with MODx.
A nice forum application with a single-sign-on plugin that's easy to use with MODx.
This Vanilla installation is for testing, experimenting and demo purposes only! It is not going to be used as a discussion forum; use the MODx forums instead.
Installing a Vanilla forum on the cloud is easy. Get it here and make sure to read the installation documentation here. Upload its directory to the web root and run its installer at yourcloud.com/vanilla/. You'll need to know the information for your database; unless you have a really busy site Vanilla can use the same database as MODx with no problems.
The Vanilla site has plenty of information on how to set up, configure and theme a Vanilla site. Once the site is looking the way I like, I'll get into setting up a single-sign-on. I might even embed Vanilla in a MODx page.
Adding a Home link to the MODx home page is a good beginning to understanding how Vanilla is put together. I asked this same question on the Vanilla forums two years ago, and the answer is still good today. Follow the instructions exactly, and you'll have a Home page that links to your main MODx site - at least if you use the default theme.
I decided to try out a different theme from the Vanilla add-ons, and I kind of like this Nebula theme. Of course, it uses a totally different structure in its default.master.tpl file than the default Vanilla theme does, so instead of adding a "Home" link to the menu I changed the URL the logo uses. When I find out how to manipulate the menu building method used in this theme, I'll post the information.
Since this installation of Vanilla is for testing, experimenting, and demo purposes only I don't want people trying to register. I found the module that adds the login/registration block that is usually found in the upper right content area in the vanilla/applications/dashboard/views/modules directory. All of the blocks used in the default Vanilla theme are in this folder. You can modify them by copying them to the same folder structure in your custom theme: vanilla/themes/nebula/views/modules. In this case, I wanted to modify the guest.php module, so I copied it from the dashboard/views/modules folder into my themes/nebula/views/module folder. It's mostly just an HTML structure, so I simply removed the content in the div structure and put in what I wanted to display there.
Vanilla uses the Smarty template engine, so in some cases editing the default main menu items also involves dealing with Smarty. For example, earlier I mentioned wanting a "Home" link to link back to my MODx site. Well, there is a Smarty module {home_link}. In vanilla/library/vendors/SmartyPlugins is a file function.home_link.php. Here you get a structure defining the home_link. One of the fields is the URL. It's full of %-prefixed Vanilla setting values, so I just replaced the href part with the URL to my MODx home page. Works, but I'm hoping to find out that there is some way to override these function in my own theme folder, as is done with the default Vanilla modules.
Some themes, and the default.master.tpl that is taken from the vanilla/dashboard/views folder, use embedded PHP code with an AddLink()function. But the Nebula theme and other newer themes use a template with Smarty template tags, like {home_link} instead.
Uploaded the jsconnect plugin to my Vanilla's plugins folder, then in my Vanilla dashboard I enabled it and began to configure it. I uploaded their php library to my assets/libraries folder.
At the bottom of the jsconnect plugin configuration page, there is a button to generate your id and secret. You'll need these later for your snippet. You'll also need three MODx URLs for it, one for login, one for registration, and one for passing the jsonp data for a logged-in MODx user, so I created these pages, using basic Login and Register snippets on those pages.
For the user info page, I created a resource with no template, an alias of 'vanilla-sso', and put an uncached snippet call in its content. Doesn't matter what you name it; I named it VanillaSSO. Publish and save the resource.
Now, create a new snippet and put this code in the snippet:
************************************************************
require_once('assets/libraries/functions.jsconnect.php');
$clientID = 'xyzabc'; // put your client ID here
$secret = 'xyzabcghietcetc'; // put your secret code here
$user = array();
if ($modx->user->isAuthenticated('web')) {
$profile = $modx->user->getOne('Profile');
$email = $profile ? $profile->get('email') : '';
$user['uniqueid'] = $modx->user->get('id');
$user['name'] = $modx->user->get('username');
$user['email'] = $email;
}
$secure = true; // false for test only mode - will skip the ID and secret tests
WriteJsConnect($user, $_GET, $clientID, $secret, $secure);
*************************************************************
That's all there is to it.
When a MODx user goes to the forum and clicks the forum's login button, he'll get the option of using his MODx login. There is another plugin to force an automatic login, but I'll leave that for another day.
Try it... log in to this site as "testing", password "testing123", then go to the forum and log in there.
For a "real" forum, I would put my clientID and secret in a file outside of the web root and include that file in the snippet code, just to secure them a bit better.