Newer
Older
if ($unl_site_created_email_address) {
$recipients[] = $unl_site_created_email_address;
}
if ($unl_site_created_alert_admins) {
$role = user_role_load_by_name('Site Admin');
$select = db_select('users_roles', 'r');
$select->fields('r', array('uid'));
$select->condition('r.rid', $role->rid);
$uids = $select->execute()->fetchCol();
$users = user_load_multiple($uids);
foreach ($users as $user) {
if (!$user->mail) {
continue;
}
$recipients[] = $user->mail;
}
}
foreach ($recipients as $recipient) {
drupal_mail('unl', 'site_created', $recipient, language_default(), array('site' => $site), unl_shared_variable_get('site_mail'));
}
}
/**
* Custom function that outputs a simple "I'm still alive" page to check to see that drupal is working.
*/
function unl_still_alive() {
header('Content-type: text/plain');
echo '200 Still Alive';
}
/**
* Custom function to return the current admin theme for use with hook_menu_alter().
*/
function _unl_get_admin_theme(){
return variable_get('admin_theme', '0');
}
/**
* Custom function for imce access on content administration pages since imce_user_page_access()
* can't be used because only one file can be included in a hook_menu item ($items['admin/content/filebrowser'])
*/
function _unl_imce_file_browser_access() {
global $user;
$profile = imce_user_profile($user);
return $profile['usertab'];
}
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
/**
* Implements hook_block_view_alter()
* @param array $data
* @param stdClass $block
*/
function unl_block_view_alter(&$data, $block) {
if ($block->module == 'system' && $block->delta == 'main-menu') {
return unl_block_view_system_main_menu_alter($data, $block);
}
}
/**
* Tries to implement hook_block_view_MODULE_DELTA_alter, but since the delta contains a -,
* this is actually called from unl_block_view_alter() for now.
* Used to determin if a "sub-menu" should be used instead of the normal menu.
* @param array $data
* @param stdClass $block
*/
function unl_block_view_system_main_menu_alter(&$data, $block) {
$current_menu_link = _unl_get_current_menu_link();
$submenu = _unl_get_current_submenu($data['content'], $current_menu_link->mlid);
if ($submenu && $submenu['#original_link']['depth'] > 1) {
$data['content'] = $submenu['#below'];
}
$data['content'] = _unl_limit_menu_depth($data['content'], 2);
}
/**
* Return the mlid of the currently selected menu item.
* If the current page has no menu item, use return the mlid of its parent instead.
*/
function _unl_get_current_menu_link() {
$result = db_select('menu_links')
->fields('menu_links')
->condition('menu_name', 'main-menu')
->condition('link_path', current_path())
->execute()
->fetch();
if (!$result) {
return FALSE;
}
while (($result->hidden || $result->depth % 2 !== 0 || !$result->has_children) && $result->depth > 1) {
$result = db_select('menu_links')
->fields('menu_links')
->condition('menu_name', 'main-menu')
->condition('mlid', $result->plid)
->execute()
->fetch();
}
return $result;
}
/**
* Find the the submenu we are currently "drilled-down" to.
* @param array $menu_links
* @param int $current_mlid
*/
function _unl_get_current_submenu($menu_links, $current_mlid) {
foreach (element_children($menu_links) as $index) {
$menu_item = $menu_links[$index];
if ($menu_item['#original_link']['mlid'] == $current_mlid) {
return $menu_item;
}
$sub_menu = _unl_get_current_submenu($menu_item['#below'], $current_mlid);
if ($sub_menu) {
return $sub_menu;
}
}
return FALSE;
}
/**
* Remove any menu items that are more than $depth levels below the current root.
* @param array $menu_links
* @param int $depth
*/
function _unl_limit_menu_depth($menu_links, $depth) {
if ($depth == 0) {
return array();
}
foreach (element_children($menu_links) as $index) {
$menu_links[$index]['#below'] = _unl_limit_menu_depth($menu_links[$index]['#below'], $depth - 1);
}
return $menu_links;
}
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
/**
* Implements hook_block_info()
*/
function unl_block_info() {
$blocks = array();
$blocks['my_sites'] = array(
'info' => 'My Sites',
);
return $blocks;
}
/**
* Implements hook_block_view()
*/
function unl_block_view($delta = '') {
switch ($delta) {
case 'my_sites':
return unl_block_view_my_sites();
break;
default:
return array();
}
}
/**
* Implements hook_block_view('my_sites').
* Displays the list of sites/roles for the current user.
*/
function unl_block_view_my_sites()
{
require_once dirname(__FILE__) . DIRECTORY_SEPARATOR . 'unl_site_creation.php';
$block = array();
$block['content'] = _unl_get_user_audit_content($GLOBALS['user']->name);
return $block;
}