| 1 |
<?php
|
| 2 |
|
| 3 |
/*
|
| 4 |
* Declare the available regions implemented by this engine.
|
| 5 |
*
|
| 6 |
* @return
|
| 7 |
* An array of regions. The first array element will be used as the default region for themes.
|
| 8 |
* Each array element takes the format: variable_name => t('human readable name')
|
| 9 |
*/
|
| 10 |
function grid_inspired_regions() {
|
| 11 |
return array(
|
| 12 |
'left_region' => t('left sidebar'),
|
| 13 |
'right_region' => t('right sidebar'),
|
| 14 |
'above_content_region' => t('content top'),
|
| 15 |
'above_content_region' => t('content bottom'),
|
| 16 |
'footer_menu' => t('footer menu'),
|
| 17 |
'footer_left' => t('footer left'),
|
| 18 |
'footer_mid' => t('footer mid'),
|
| 19 |
'footer_right' => t('footer right')
|
| 20 |
);
|
| 21 |
}
|
| 22 |
|
| 23 |
/*
|
| 24 |
* CREATE OR MODIFY VARIABLES FOR YOUR THEME
|
| 25 |
*
|
| 26 |
* The most powerful function available to themers is the _phptemplate_variables() function. It allows you
|
| 27 |
* to pass newly created variables to different template (tpl.php) files in your theme. Or even unset ones you don't want
|
| 28 |
* to use.
|
| 29 |
*
|
| 30 |
* It works by switching on the hook, or name of the theme function, such as:
|
| 31 |
* - page
|
| 32 |
* - node
|
| 33 |
* - comment
|
| 34 |
* - block
|
| 35 |
*
|
| 36 |
* By switching on this hook you can send different variables to page.tpl.php file, node.tpl.php
|
| 37 |
* (and any other derivative node template file, like node-forum.tpl.php), comment.tpl.php, and block.tpl.php
|
| 38 |
*
|
| 39 |
*/
|
| 40 |
|
| 41 |
|
| 42 |
/**
|
| 43 |
* Intercept template variables
|
| 44 |
*
|
| 45 |
* @param $hook
|
| 46 |
* The name of the theme function being executed
|
| 47 |
* @param $vars
|
| 48 |
* A sequential array of variables passed to the theme function.
|
| 49 |
*/
|
| 50 |
|
| 51 |
function _phptemplate_variables($hook, $vars = array()) {
|
| 52 |
switch ($hook) {
|
| 53 |
// Send a new variable, $logged_in, to page.tpl.php to tell us if the current user is logged in or out.
|
| 54 |
case 'page':
|
| 55 |
// get the currently logged in user
|
| 56 |
global $user;
|
| 57 |
|
| 58 |
// An anonymous user has a user id of zero.
|
| 59 |
if ($user->uid > 0) {
|
| 60 |
// The user is logged in.
|
| 61 |
$vars['logged_in'] = TRUE;
|
| 62 |
}
|
| 63 |
else {
|
| 64 |
// The user has logged out.
|
| 65 |
$vars['logged_in'] = FALSE;
|
| 66 |
}
|
| 67 |
|
| 68 |
$body_classes = array();
|
| 69 |
// classes for body element
|
| 70 |
// allows advanced theming based on context (home page, node of certain type, etc.)
|
| 71 |
$body_classes[] = ($vars['is_front']) ? 'front' : 'not-front';
|
| 72 |
$body_classes[] = ($vars['logged_in']) ? 'logged-in' : 'not-logged-in';
|
| 73 |
if ($vars['node']->type) {
|
| 74 |
$body_classes[] = 'ntype-'. grid_inspired_id_safe($vars['node']->type);
|
| 75 |
}
|
| 76 |
switch (TRUE) {
|
| 77 |
case $vars['left_region'] && $vars['right_region'] :
|
| 78 |
$body_classes[] = 'both-sidebars';
|
| 79 |
break;
|
| 80 |
case $vars['left_region'] :
|
| 81 |
$body_classes[] = 'sidebar-left';
|
| 82 |
break;
|
| 83 |
case $vars['right_region'] :
|
| 84 |
$body_classes[] = 'sidebar-right';
|
| 85 |
break;
|
| 86 |
}
|
| 87 |
// implode with spaces
|
| 88 |
$vars['body_classes'] = implode(' ', $body_classes);
|
| 89 |
|
| 90 |
break;
|
| 91 |
|
| 92 |
case 'node':
|
| 93 |
// get the currently logged in user
|
| 94 |
global $user;
|
| 95 |
|
| 96 |
// set a new $is_admin variable
|
| 97 |
// this is determined by looking at the currently logged in user and seeing if they are in the role 'admin'
|
| 98 |
$vars['is_admin'] = in_array('admin', $user->roles);
|
| 99 |
|
| 100 |
$node_classes = array('node');
|
| 101 |
if ($vars['sticky']) {
|
| 102 |
$node_classes[] = 'sticky';
|
| 103 |
}
|
| 104 |
if (!$vars['node']->status) {
|
| 105 |
$node_classes[] = 'node-unpublished';
|
| 106 |
}
|
| 107 |
$node_classes[] = 'ntype-'. grid_inspired_id_safe($vars['node']->type);
|
| 108 |
// implode with spaces
|
| 109 |
$vars['node_classes'] = implode(' ', $node_classes);
|
| 110 |
|
| 111 |
if(count(taxonomy_node_get_terms($vars['node']->nid)))
|
| 112 |
$vars['has_terms'] = TRUE;
|
| 113 |
else
|
| 114 |
$vars['has_terms'] = FALSE;
|
| 115 |
|
| 116 |
break;
|
| 117 |
|
| 118 |
case 'comment':
|
| 119 |
// we load the node object that the current comment is attached to
|
| 120 |
$node = node_load($vars['comment']->nid);
|
| 121 |
// if the author of this comment is equal to the author of the node, we set a variable
|
| 122 |
// then in our theme we can theme this comment differently to stand out
|
| 123 |
$vars['author_comment'] = $vars['comment']->uid == $node->uid ? TRUE : FALSE;
|
| 124 |
break;
|
| 125 |
}
|
| 126 |
|
| 127 |
return $vars;
|
| 128 |
}
|
| 129 |
|
| 130 |
/**
|
| 131 |
* Converts a string to a suitable html ID attribute.
|
| 132 |
* - Preceeds initial numeric with 'n' character.
|
| 133 |
* - Replaces space and underscore with dash.
|
| 134 |
* - Converts entire string to lowercase.
|
| 135 |
* - Works for classes too!
|
| 136 |
*
|
| 137 |
* @param string $string
|
| 138 |
* the string
|
| 139 |
* @return
|
| 140 |
* the converted string
|
| 141 |
*/
|
| 142 |
function grid_inspired_id_safe($string) {
|
| 143 |
if (is_numeric($string{0})) {
|
| 144 |
// if the first character is numeric, add 'n' in front
|
| 145 |
$string = 'n'. $string;
|
| 146 |
}
|
| 147 |
return strtolower(preg_replace('/[^a-zA-Z0-9-]+/', '-', $string));
|
| 148 |
}
|