Newer
Older
require_once dirname(__FILE__) . '/includes/common.php';
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/**
* Implements hook_field_attach_view_alter().
*/
function unl_field_attach_view_alter(&$output, $context) {
// Replace the field named field_hrorgunit containing an org unit number with that unit's listing from the UNL directory
foreach (element_children($output) as $field_name) {
$element = &$output[$field_name];
switch ($element['#field_name']) {
case 'field_hrorgunit':
$result = file_get_contents('http://directory.unl.edu/departments/?view=deptlistings&org_unit='.$element['#items'][0]['value'].'&format=partial');
if (!empty($result) && $result != '<div id="all_employees"></div>') {
drupal_add_css('http://directory.unl.edu/css/peoplefinder_default.css', 'external');
drupal_add_js('http://directory.unl.edu/scripts/peoplefinder.js', 'external');
drupal_add_js('var PF_URL = "http://directory.unl.edu/", ANNOTATE_URL = "http://annotate.unl.edu/";', 'inline');
// Need to check to see if directory.unl.edu only returned a partial result. If so, result will have a message in between the closing ul and div tags like so: </ul><p>Try refining your search.</p></div></div>
if (!preg_match('/<\/ul>\s*\n*\s*<\/div><\/div>/', $result)) {
// Extra message at the bottom indicating not all results returned - hide it
drupal_add_css('#all_employees > * > p {display:none;}', 'inline');
// Alert the user to visit the directory site
drupal_add_js('jQuery(document).ready(function(){jQuery("#all_employees .result_head").css("font-size","13px").html("We\'re a big department! Partial listing shown below, please visit <a href=\"http://directory.unl.edu/departments/'.$element['#items'][0]['value'].'#all_employees\">our department lisiting on the UNL Directory</a> to see everyone.");});', 'inline');
}
}
else {
$result = '<p>Please visit the <a href="http://directory.unl.edu/">UNL Directory</a> for listings.</p>';
}
foreach ($element['#items'] as $delta => $item) {
$element[$delta]['#markup'] = $result;
}
break;
default:
}
}
}
/**
* Implementation of hook_node_access().
*/
function unl_node_access($node, $op, $account) {
// When content types are created they have blank permissions so base access on the 'Basic page' type. This is done because with shared permissions subsites can't edit permissions.
//@TODO Make this configureable i.e. make it possible to opt-out certain types from this.
switch($op) {
case 'view':
break;
case 'create':
return user_access('create page content', $account) ? NODE_ACCESS_ALLOW : NODE_ACCESS_IGNORE;
case 'update':
if (isset($node->uid) && $node->uid == $account->uid) {
return user_access('edit own page content', $account) ? NODE_ACCESS_ALLOW : NODE_ACCESS_IGNORE;
}
return user_access('edit any page content', $account) ? NODE_ACCESS_ALLOW : NODE_ACCESS_IGNORE;
case 'delete':
if (isset($node->uid) && $node->uid == $account->uid) {
return user_access('delete own page content', $account) ? NODE_ACCESS_ALLOW : NODE_ACCESS_IGNORE;
}
return user_access('delete any page content', $account) ? NODE_ACCESS_ALLOW : NODE_ACCESS_IGNORE;
}
}
function unl_node_prepare($node) {
Eric Rasmussen
committed
$node->menu['expanded'] = 1;
Eric Rasmussen
committed
/**
* Implementation of hook_wywiwyg_plugin() found in wysiwyg.api.php
*/
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
function unl_wysiwyg_plugin($editor) {
switch ($editor) {
case 'tinymce':
return array(
'unl' => array(
// A URL to the plugin's homepage.
'url' => 'http://gforge.unl.edu/gf/project/wdn_tinymce/',
// The full path to the native editor plugin.
'path' => $editor['library path'] . '/plugins/unl',
// A list of editor extensions provided by this native plugin.
// Extensions are not displayed as buttons and touch the editor's
// internals, so you should know what you are doing.
'extensions' => array(
'unl' => 'UNL Extension'
),
// Boolean whether this plugin is a native plugin, i.e. shipped with
// the editor. Definition must be ommitted for plugins provided by
// other modules.
'internal' => TRUE,
// Boolean whether the editor needs to load this plugin. When TRUE,
// the editor will automatically load the plugin based on the 'path'
// variable provided. If FALSE, the plugin either does not need to
// be loaded or is already loaded by something else on the page.
// Most plugins should define TRUE here.
'load' => TRUE,
// A list of buttons provided by this native plugin. The key has to
// match the corresponding JavaScript implementation. The value is
// is displayed on the editor configuration form only.
'buttons' => array(
'unlZenBox' => 'UNL Zen Box',
'unlZenTable' => 'UNL Zen Table',
'unlLayout' => 'UNL Layout',
'unlTooltip' => 'UNL Tooltip',
),
// A list of global, native editor configuration settings to
// override. To be used rarely and only when required.
'options' => array(
'skin' => 'unl',
'table_styles' => 'ZenTable Bright (yellow)=zentable bright;ZenTable Cool (blue)=zentable cool;ZenTable Energetic (orange)=zentable energetic;ZenTable Soothing (green)=zentable soothing;ZenTable Primary (red)=zentable primary;ZenTable Neutral (gray)=zentable neutral;', 'doctype' => '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">',
'valid_elements' => '*[*],script[src|type=text/javascript]',
),
)
// Wysiwyg wrapper plugin AJAX callback.
// 'callback' => url('myplugin/browse'),
// 'icon' => drupal_get_path('module', 'mymodule') . '/myplugin/myplugin.png',
// Might need to be set later on; after retrieving customized editor
// layout.
//'theme_advanced_buttons1' => array(t('Button title (optional)') => 'myplugin'),
);
}
function unl_permission() {
return array(
'unl migration' => array(
'title' => t('Migration'),
'description' => t('Migrate UNL Template based sites to drupal'),
'unl site creation' => array(
'title' => t('Site Creation'),
'description' => t('Create new drupal sites using the UNL profile'),
Tim Steiner
committed
'restrict access' => TRUE,
),
'unl grant all permissions' => array(
'title' => t('Grant All Permissions'),
'description' => t('If this is not checked, a user can only grant permissions that they themselves have. Requires the "Administer permissions" permission.'),
Tim Steiner
committed
'restrict access' => TRUE,
),
Tim Steiner
committed
'unl administer administrator permissions' => array(
'title' => t('Administer Administrator\'s Permissions'),
'description' => t('If this is not checked, a user can not change the permissions of the administrator role. Requires the "Administer permissions" permission.'),
'restrict access' => TRUE,
),
'title' => t('Change Theme Settings'),
'description' => t('Allow this role to change the current theme settings.'),
),
'unl imce javascript upload' => array(
'title' => t('Upload Javascript Files Through IMCE'),
),
Eric Rasmussen
committed
/**
* Adds UNL Migration Tool to the Content menu for admin
*/
function unl_menu() {
$access = array();
// Returns confirmation 'user_loggedin' if user is logged into the system
$items['user/unl/whoami'] = array(
'title' => 'UNL Whoami Tool',
'access callback' => TRUE,
'page callback' => 'unl_whoami',
'file' => 'unl_whoami.php',
);
// Returns html technical feedback form
$items['user/unl/technical_feedback'] = array(
'title' => 'Technical Feedback',
'description' => 'Returns a form to fill out to give technical feedback',
'access callback' => TRUE,
'page callback' => 'technical_feedback',
'file' => 'technical_feedback.php'
);
$items['admin/content/unl/migration'] = array(
'title' => 'UNL Migration Tool',
'description' => 'Migrate a static UNL template page into drupal',
'access arguments' => array('unl migration'),
'page callback' => 'drupal_get_form',
'page arguments' => array('unl_migration'),
'type' => MENU_LOCAL_TASK,
'file' => 'unl_migration.php',
);
$items['admin/themes'] = array(
'title' => 'Appearance',
'description' => 'Configure your theme.',
'access callback' => 'unl_user_access',
'access arguments' => array(array('!administer themes', 'unl theme settings')),
'page callback' => 'drupal_get_form',
'position' => 'left',
'weight' => -6,
);
$items['_status'] = array(
'title' => 'Still Alive',
'page callback' => 'unl_still_alive',
'access callback' => TRUE,
);
if (conf_path() == 'sites/default') {
$items['admin/sites/unl'] = array(
'title' => 'UNL Site Creation Tool',
Tim Steiner
committed
'description' => 'Create and manage UNL Drupal sites and aliases.',
'access arguments' => array('unl site creation'),
Tim Steiner
committed
'page callback' => 'unl_sites_page',
'type' => MENU_LOCAL_TASK,
'file' => 'unl_site_creation.php',
);
Tim Steiner
committed
$items['admin/sites/unl/sites'] = array(
'title' => 'Sites',
'description' => 'Create and manage UNL Drupal sites.',
'type' => MENU_DEFAULT_LOCAL_TASK,
'weight' => -8,
);
$items['admin/sites/unl/%/delete'] = array(
'title' => 'Delete site',
'page callback' => 'drupal_get_form',
'page arguments' => array('unl_site_delete_confirm', 3),
'access arguments' => array('unl site creation'),
'file' => 'unl_site_creation.php',
);
Tim Steiner
committed
$items['admin/sites/unl/aliases'] = array(
'title' => 'Aliases',
'description' => 'Manage aliases of UNL Drupal sites.',
'access arguments' => array('unl site creation'),
Tim Steiner
committed
'page callback' => 'unl_aliases_page',
'type' => MENU_LOCAL_TASK,
'file' => 'unl_site_creation.php',
);
$items['admin/sites/unl/wdn_registry'] = array(
'title' => 'WDN Registry',
'description' => 'Settings for the connection to the WDN Registry.',
'access arguments' => array('unl site creation'),
'page callback' => 'drupal_get_form',
'page arguments' => array('unl_wdn_registry'),
'type' => MENU_LOCAL_TASK,
'file' => 'unl_site_creation.php',
);
function unl_menu_alter(&$items) {
foreach (array('module', 'file', 'page arguments') as $key) {
$items['admin/themes'][$key] = $items['admin/appearance/settings/' . variable_get('theme_default')][$key];
}
return $items;
}
* Implementation of hook_file_validate().
* Fires when files are uploaded after Drupal Core sanitization but before saving to file system or db
*/
function unl_file_validate($file) {
// For IMCE uploads only, check if Drupal core just altered a *.js upload to *.js.txt and correct if permitted
if ($file->source == 'imce' && substr($file->filename, -7) == '.js.txt' && user_access('unl imce javascript upload')) {
// Chop off the .txt extesnsion that's been added
$file->destination = substr($file->destination, 0, -4);
$file->filename = substr($file->filename, 0, -4);
}
return;
}
function unl_form_alter(&$form, $form_state, $form_id) {
// Make new menu items expanded by default.
if ($form_id == 'menu_edit_item' && $form['mlid']['#value'] == 0) {
$form['expanded']['#default_value'] = TRUE;
}
Tim Steiner
committed
if ($form_id == 'system_site_information_settings') {
$form['site_information']['https'] = array(
'#type' => 'checkbox',
'#title' => 'SSL Enabled',
'#default_value' => variable_get('https', FALSE),
);
if (conf_path() != 'sites/default') {
$alternate_uris = unl_get_alternate_base_uris();
$base_urls = array('_null' => '--Select One--');
foreach ($alternate_uris as $alternate_uri) {
$base_urls[$alternate_uri] = $alternate_uri;
};
$form['site_information']['unl_primary_base_url'] = array(
'#title' => 'Primary Base URL',
'#type' => 'select',
'#options' => $base_urls,
'#default_value' => variable_get('unl_primary_base_url'),
);
$form['#submit'][] = 'unl_system_settings_form_submit';
}
Tim Steiner
committed
}
/**
* Modify the Permissions and Roles forms for non-administrators
*/
$admin_role_id = unl_shared_variable_get('user_admin_role', -1);
if (!in_array($admin_role_id, array_keys($GLOBALS['user']->roles))) {
switch ($form_id) {
// Add additional validation on admin/people/permissions/roles/edit/%
case 'user_admin_role' :
$form['#validate'][] = 'unl_user_admin_role_validate';
break;
// Hide administrator role on admin/people/permissions/roles
case 'user_admin_roles' :
foreach ($form['roles'] as $key => $role) {
if (isset($role['#role']->rid) && $role['#role']->rid == $admin_role_id) {
unset($form['roles'][$key]);
}
Tim Steiner
committed
}
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
break;
// Hide administrator column on admin/people/permissions
case 'user_admin_permissions' :
if (!user_access('unl grant all permissions')) {
// Remove permissions this user doesn't have from the headings list.
foreach ($form['permission'] as $permission => $sub_form) {
if (is_int($permission)) {
continue;
}
if (!user_access($permission)) {
unset($form['permission'][$permission]);
}
}
// Remove any empty permission section headings.
$permission_sections = array_keys($form['permission']);
foreach ($permission_sections as $index => $permission_section) {
if (!is_int($permission_section)) {
continue;
}
if (!isset($permission_sections[$index + 1]) || is_int($permission_sections[$index + 1])) {
unset($form['permission'][$permission_section]);
}
}
// Remove the permissions this user doesn't have from the checkboxes list.
foreach ($form['checkboxes'] as $role_id => $sub_form) {
foreach ($sub_form['#options'] as $permission => $value) {
if (!user_access($permission)) {
unset($form['checkboxes'][$role_id]['#options'][$permission]);
}
}
Tim Steiner
committed
}
}
// Unset the administrator checkbox column if user can't administer administrator permissions
if (!user_access('unl administer administrator permissions')) {
unset($form['role_names'][$admin_role_id]);
unset($form['role_names']['#value'][$admin_role_id]);
unset($form['checkboxes'][$admin_role_id]);
}
// Make these settings unavailable even if they are enabled for the user
$administrator_permissions = array(
'unl administer administrator permissions',
'unl site creation',
'administer modules',
'administer themes',
'administer software updates',
'administer imce',
'administer filters',
);
foreach ($form['permission'] as $permission => $sub_form) {
if (in_array($permission, $administrator_permissions)) {
unset($form['permission'][$permission]);
}
}
foreach ($form['checkboxes'] as $admin_role_id => $sub_form) {
foreach ($sub_form['#options'] as $permission => $value) {
if (in_array($permission, $administrator_permissions)) {
unset($form['checkboxes'][$admin_role_id]['#options'][$permission]);
}
}
}
break;
default :
break;
}
}
Tim Steiner
committed
/**
* On the node edit form, hide the "Provide a menu link" checkbox since we'll
* be using the menu to build a site hierarchy. Instead, add a button that will
* determine whether or not the menu link is visible or not.
Tim Steiner
committed
if (substr($form_id, -10) == '_node_form') {
Tim Steiner
committed
$form['menu']['#title'] = 'Site hierachy';
Tim Steiner
committed
$form['menu']['enabled']['#default_value'] = TRUE;
$form['menu']['enabled']['#prefix'] = '<div style="display: none;">';
$form['menu']['enabled']['#suffix'] = '</div>';
Tim Steiner
committed
$form['menu']['link']['link_title']['#required'] = TRUE;
Tim Steiner
committed
$mlid = $form['menu']['link']['mlid']['#value'];
if ($mlid) {
$menu_link = menu_link_load($mlid);
$default_visible = ($menu_link['hidden'] ? 0 : 1);
}
else {
$default_visible = 0;
}
$form['menu']['visible'] = array(
'#type' => 'checkbox',
'#title' => 'Display in menu',
'#default_value' => $default_visible,
'#weight' => 0,
);
Tim Steiner
committed
$form['actions']['submit']['#submit'][] = 'unl_node_form_submit';
// Also turn on revisioning by default
$form['revision_information']['revision']['#default_value'] = TRUE;
unset($form['revision_information']['revision']['#states']);
Tim Steiner
committed
// Also hide the "Promoted to front page" option
$form['options']['promote']['#prefix'] = '<div style="display:none;">';
$form['options']['promote']['#suffix'] = '</div>';
Tim Steiner
committed
// Also hide the "Sticky at top of lists" option
$form['options']['sticky']['#prefix'] = '<div style="display:none;">';
$form['options']['sticky']['#suffix'] = '</div>';
Tim Steiner
committed
}
// Add the Roles checkboxes to the user edit form for users with ability to 'Administer users' but not 'Administer permissions'
if (in_array($form_id, array('user_register_form', 'user_profile_form')) && user_access('administer users') && !user_access('administer permissions')) {
$roles = array_map('check_plain', user_roles(TRUE));
// Unset the adminsitrator checkbox, validation code that prevents a user who is not an administrator from granting the administrator role is in the unl_cas module
$form['account']['roles']['#options'] = $roles;
$form['account']['roles']['#access'] = !empty($roles);
Tim Steiner
committed
}
/**
* When a node is modified, update its menu link to be hidden or not based on the user input.
*/
function unl_node_form_submit($form, &$form_state) {
$menu_data = $form_state['values']['menu'];
if ($menu_data['mlid']) {
$menu_link = menu_link_load($menu_data['mlid']);
}
else {
list($parent_menu_name, $parent_mlid) = explode(':', $menu_data['parent']);
$menu_links = menu_load_links($parent_menu_name);
foreach ($menu_links as $menu_link) {
if ($menu_link['plid'] != $parent_mlid) {
continue;
}
if ($menu_link['link_path'] != 'node/' . $form_state['values']['nid']) {
continue;
}
break;
}
}
Tim Steiner
committed
$menu_link['hidden'] = $menu_data['visible'] ? 0 : 1;
menu_link_save($menu_link);
Tim Steiner
committed
}
function unl_system_settings_form_submit($form, &$form_state) {
variable_set('https', (bool) $form_state['values']['https']);
if ($form_state['values']['unl_primary_base_url'] != '_null') {
variable_set('unl_primary_base_url', $form_state['values']['unl_primary_base_url']);
}
else {
variable_del('unl_primary_base_url');
}
Tim Steiner
committed
function unl_theme() {
return array(
Tim Steiner
committed
'render element' => 'form',
Tim Steiner
committed
),
Tim Steiner
committed
}
Tim Steiner
committed
function unl_url_outbound_alter(&$path, &$options, $original_path) {
$path_parts = parse_url($path);
if (isset($path_parts['scheme']) || $path == 'user/cas') {
return;
}
Tim Steiner
committed
$user = $GLOBALS['user'];
$user_roles = array_keys($user->roles);
$generic_user = TRUE;
foreach ($user_roles as $user_role) {
if (in_array($user_role, array(DRUPAL_ANONYMOUS_RID, DRUPAL_AUTHENTICATED_RID))) {
continue;
}
$generic_user = FALSE;
}
if (isset($options['https'])) {
return;
}
Tim Steiner
committed
$options['https'] = (bool) (variable_get('https', 0) && !$generic_user);
}
Tim Steiner
committed
function unl_user_access($permissions, $account = NULL) {
foreach ($permissions as $permission) {
if (substr($permission, 0, 1) == '!') {
$permission = substr($permission, 1);
$result = !user_access($permission, $account);
}
else {
$result = user_access($permission, $account);
}
if (!$result) {
return FALSE;
}
}
/**
* Additional validation on the user_admin_role form (admin/people/permissions/roles/edit/%)
* to prevent a user from deleting the administrator role. (This is not needed if permissions are shared and only administrators can edit roles.)
*/
function unl_user_admin_role_validate($form, &$form_state) {
$admin_role_id = unl_shared_variable_get('user_admin_role', -1);
if ($form_state['values']['op'] == t('Delete role')) {
$role = user_role_load_by_name($form_state['values']['name']);
if ($role && $role->rid == $admin_role_id) {
form_set_error('name', t('The role name %name can not be deleted. Seriously dude. Seriously.', array('%name' => $form_state['values']['name'])));
}
}
}
function unl_cron() {
if (PHP_SAPI == 'cli') {
return;
}
$queue = DrupalQueue::get('unl_migration');
if ($queue->numberOfItems() > 0) {
require_once dirname(__FILE__) . DIRECTORY_SEPARATOR . 'unl_migration.php';
$item = $queue->claimItem(120);
$queue->deleteItem($item);
if (unl_migration_queue_step($item->data)) {
unl_send_site_created_email();
}
if (conf_path() == 'sites/default') {
$wdn_registry_info = array(
'database' => variable_get('unl_wdn_registry_database'),
'username' => variable_get('unl_wdn_registry_username'),
'password' => variable_get('unl_wdn_registry_password'),
'host' => variable_get('unl_wdn_registry_host'),
'driver' => 'mysql',
);
if (!$wdn_registry_info['database']) {
return;
}
Database::addConnectionInfo('wdn_registry', 'default', $wdn_registry_info);
$data = db_select('site_request', 'r')
->fields('r')
->where('`url` IS NULL')
->execute()
->fetchAll();
}
catch (Exception $e) {
db_set_active();
return;
}
$sites_to_create = array();
foreach ($data as $site) {
$full_department = $site->department;
$department = $full_department;
$department = strtr($department, array(' ' => ''));
$department = strtolower($department);
$department = preg_replace('/[^[a-z0-9]/', '', $department);
$site_name = $site->site_name;
$site_name = strtr($site_name, array(' ' => ''));
$site_name = strtolower($site_name);
$site_name = preg_replace('/[^[a-z0-9]/', '', $site_name);
$path = $department . '/' . $site_name;
$db_prefix = unl_create_db_prefix($site);
$sites_to_create[] = array(
'site_path' => $path,
'uri' => url($path),
'clean_url' => TRUE,
'db_prefix' => $db_prefix,
'site_admin' => $site->site_admin ? $site->site_admin : '',
'migration_url' => $site->migration_url ? $site->migration_url : '',
'migration_path' => $site->migration_path ? $site->migration_path : '',
'department' => $full_department,
if (variable_get('unl_wdn_registry_production')) {
db_update('site_request')
->fields(array('url' => url($path)))
->condition('id', $site->id)
->execute();
}
foreach ($sites_to_create as $site_to_create) {
try {
db_insert('unl_sites')->fields($site_to_create)->execute();
}
catch (PDOException $e) {
// Ignore duplicate records.
if ($e->getCode() != 23000) {
throw $e;
}
}
}
// Creates a db_prefix short enough to not go over MySQL's max table name length
function unl_create_db_prefix($site) {
$parent_prefix = '_' . $GLOBALS['databases']['default']['default']['prefix'];
$site_name = strtolower($site->site_name);
$site_name = preg_replace('/[^[a-z0-9]/', '', $site_name);
$site_name = explode(' ', $site_name);
foreach ($site_name as $site_word) {
$site_words[$site_word] = strlen($site_word);
}
do {
$db_prefix = '';
$found = FALSE;
foreach ($site_words as $site_word => $length) {
$db_prefix .= substr($site_word, 0, $length);
if (max($site_words) == $length && !$found) {
$found = TRUE;
$site_words[$site_word] = $length-1;
}
}
} while (strlen($db_prefix . $parent_prefix) > 32);
function unl_get_alternate_base_uris() {
$shared_prefix = unl_get_shared_db_prefix();
if (is_array($GLOBALS['databases']['default']['default']['prefix'])) {
$db_prefix = $GLOBALS['databases']['default']['default']['prefix']['default'];
$db_prefix = substr($db_prefix, 0, 0 - strlen($shared_prefix) - 1);
}
else {
return array();
}
$rows = db_query(
"SELECT s.uri, a.base_uri, a.path "
. "FROM {$shared_prefix}unl_sites AS s "
. "LEFT JOIN {$shared_prefix}unl_sites_aliases AS a "
. " ON s.site_id = a.site_id "
. "WHERE db_prefix=:db_prefix",
array(':db_prefix' => $db_prefix)
)->fetchAll();
if (count($rows) < 1) {
return array();
}
$uris = array($rows[0]->uri);
foreach ($rows as $row) {
if ($row->base_uri . $row->path) {
$uris[] = $row->base_uri . $row->path;
return $uris;
}
function unl_init() {
$primary_base_url = variable_get('unl_primary_base_url');
if ($primary_base_url) {
if (substr($primary_base_url, -1) != '/') {
$primary_base_url .= '/';
}
$current_url_schema = parse_url(url(), PHP_URL_SCHEME);
$primary_base_url_schema = parse_url($primary_base_url, PHP_URL_SCHEME);
$primary_base_url = $current_url_schema . substr($primary_base_url, strlen($primary_base_url_schema));
if (conf_path() != 'sites/default' && $primary_base_url != url()) {
drupal_goto($primary_base_url . current_path());
}
function unl_mail($key, &$message, $params) {
if ($key == 'site_created') {
$site = $params['site'];
$uri = $site->uri;
$site_admin = $site->site_admin;
$department = $site->department;
$message['subject'] = 'New UNLcms site for ' . $department;
$message['body'][] = <<<EOF
To $site_admin,
Thank you for registering your site at UNLcms. You may now log in using your myUNL information by clicking the link below or copying and pasting it to your browser:
$uri
You must log in in order manage your web site and edit the content. The "Login" link is at the top of the page and you log in using your myUNL information.
For information on how to manage your site & content, please view the online how-to videos found in the menu at the top of the following page, within the category of "Get Help":
http://unlcms.unl.edu
When this new site was created, an attempt was made to copy the content from your current site to this new site. You will want to review all of the content to verify that it is complete and that it is presented correctly. This import process is dependent on the current's site using and adherence to UNL Templates.
Once your content has been finalized and your are ready to go public with your new site, please contact us to activate the proper public URL (cleaner and shorter). This current URL you've been given will not be indexed or found in search engines until the proper public URL has been established.
Please let us know if you have suggestions or questions.
Thank you,
EOF;
}
}
function unl_send_site_created_email($site = NULL) {
$shared_prefix = unl_get_shared_db_prefix();
// If no site was specified, get the current site.
if (!$site) {
if (!is_array($GLOBALS['databases']['default']['default']['prefix'])) {
return;
}
$db_prefix = $GLOBALS['databases']['default']['default']['prefix']['default'];
$db_prefix = substr($db_prefix, 0, 0 - strlen($shared_prefix) - 1);
$data = db_query(
"SELECT * "
. "FROM {$shared_prefix}unl_sites "
. "WHERE db_prefix = :prefix ",
array(':prefix' => $db_prefix)
)->fetchAll();
if (count($data) == 0) {
return;
}
$site = $data[0];
}
$unl_site_created_email_address = unl_shared_variable_get('unl_site_created_email_address');
$unl_site_created_alert_admins = unl_shared_variable_get('unl_site_created_alert_admins');
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'));
}
}
// 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';
}