Bootstrap

bootstrap-block.jpg

The module enables custom bootstrap based on admin-defined bootstrap script.

The bootstrap module uses some simple script to make some actions on bootstrap matching some conditions.
All conditions and actions are defined in 'plugins' - php .inc files placed in 'plugins' folder under bootstrap.module file.

Conditions

So if a plugin wants to expose conditions it must implement 2 hooks like usual drupal ones:

hook_bootstrap_condition_info()
hook_bootstrap_condition($type,$cmd)

condition_info() hook must return associative array with
condition 'keywords' as keys, and another associative array with keys
'name', 'help' - for descriptive purposes.
example:
function path_bootstrap_condition_info(){
$items['path']=array(
'name'=>t('Path')
);
return $items;
}

condition($type,$cmd) hook must return true or false, indicating the match's result:

function role_bootstrap_condition($type,$cmd){
global $user;
$roles=$user->roles;
if($user->uid==1) $roles[-1]='root';
$regexp =preg_replace('/,\s*/','|',$cmd);
$regexp =preg_replace('/\*/','.*',$regexp);
foreach($roles as $r){
if(preg_match('/^'.$regexp.'$/',$r)){
return 1;
}
}
return 0;
}

Actions

Actions use the similar hooks:

hook_bootstrap_action_info()
hook_bootstrap_action($type,$cmd,$match)

action_info() hook can return extra key 'negative match', indicating that an action should be called on negative match also. so the third argument in action() hook indicates match status.

Script

The script's structure is very simple.
Every line should begin with condition or action name, returned by info() hooks.
After [space] the rest of the line is treated like the condition/action's command and sent to the according hook in the according plugin.
So script collects condition matches. As soon as an action is encountered it begins execute or skip the following actions based on conditions - if all conditions before actions match execution takes order. Actions are executed before a new condition encountered and the process repeats.

Subscripts

It's possible to make subscripts. Subscripts act like action and can contain its own set of conditions and actions.
Subscripts are open with 'begin' keyword and closed with 'end' keyword.

Script example:

role anonymous*
begin
path <front> user*
access restrict
end

user-agent *MSIE*
error You are using a wrong browser !

path user/register *captcha*
load captcha

path *facet* *node* admin/content* user/\d+*
load content

path node.+add admin/content/taxonomy*
load taxonomy_defaults

path node/\d+ admin/content* *lightbox*
load lightbox2

path <front> user/(register|password|login)
skip imagecache, nodefamily, translation

role root, translator
load translation

path <front> *facet*
skip email link
load faceted_search

path admin*
load taxonomy_manager

after installing go admin/build/bootstrap to write the script.

Downloads



 
 

Drupal is a registered trademark of Dries Buytaert.