Madhouse Utils – Documentation

Madhouse Utils provides some tools to help you deal with common tasks. Here’s a quickstart about the most of those tools, they are more but you don’t especially need to know how it works behind the stage. If you do, dig into the source code which is well-commented.

We’re working on documenting all the tools that are available in Madhouse Utils. Here’s a quickstart :

  1. Read our tutorial which uses a lot of Madhouse Utils tools : How to develop plugins for Osclass
  2. Check the helpers that are all contained in helpers/ directory. These helpers are documented and you should be able to get it quickly.


Madhouse Utils simplifies e-mails in Osclass.

Defining e-mails.

To define an e-mail, create a class that extends Madhouse_AbstractEmail. Here’s an example :

class Madhouse_Messenger_Emails_Reminder extends Madhouse_AbstractEmail {

	function __construct() {
		$this->withWords(array("{INBOX_URL}", "{NB_UNREAD_MESSAGES}"));

	public static function getName()
        return "email_alert_mmessenger_messages";

        public static function getDefaultTitle()
	    return "You have unread messages !";

	public static function getDefaultContent()
	    return "You have {NB_UNREAD_MESSAGES} unread messages in you inbox : {INBOX_URL}";

	public function send($sender, $recipients, $nbUnread) {

What’s been done here :

  1. An e-mail is defined with the slug ’email_alert_mmessenger_messages’
  2. There’s two words available ‘{INBOX_URL}’ and ‘{NB_UNREAD}’
  3. We gave a default title and content.
  4. A ‘send’ method has been defined to set who’s sending it, who’s receiving it and the value that will replace our words. Here again, Madhouse Utils is making our lives easier, we just have to give him a sender ($sender), an array of recipients ($recipients) and the values (mdh_messenger_inbox_url() for INBOX_URL and $nbUnread for {NB_UNREAD_MESSAGES}). We’ll see later an example.

2. Install & Uninstall

You need to install this e-mail. There’s two helpers for that :

  • mdh_install_email($className);
  • mdh_uninstall_email($className);

Use those helpers in the install and uninstall function of your plugin giving the class name of the e-mail.

// In the osc_register_hook of your plugin :
// In the _uninstall of your plugin :

That’s it. Madhouse Utils handles everything for you.

3. Sending an e-mail.

What about sending this e-mail. Wherever you want this to be sent, do something like this :

$email = new Madhouse_Messenger_Emails_Reminder();

// send() asks for Madhouse_User instance. Here's how :
$sender = Madhouse_Utils_Models::findUserByPrimaryKey(osc_logged_user_id());
$recipients = array(Madhouse_Utils_Models::findUserByPrimaryKey(42));

// Just a dummy variable
$nbUnread = 3;

// Send it!
$email->send($sender, $recipients, $nbUnread);

The current user (logged in user) will send an e-mail to the user id=42 with {NB_UNREAD} replaced by ‘3’.

Mustache.php / Mustache.js

Madhouse Utils adds support for Mustache, a templating engine. This works like registring / enqueing scripts but with template files.

There’s three helpers :

  • madhouse_register_mustache($key, $file) // registers a template, $key is a unique identifier;
  • madhouse_enqueue_mustache($key) // enqueue the template $key;
  • madhouse_render_mustache($key, $values) // renders the mustache $key with $values (associative array);


I know it’s harsh documentation. Working on that.

Madhouse Utils can give you many many services as a themes / plugins developer for Osclass… You got some tools explained in our tutorial and some here. For now, just dig into the code for the rest :(.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s