Newer
Older
$uris = array($rows[0]->uri);
foreach ($rows as $row) {
if ($row->base_uri . $row->path) {
$uris[] = $row->base_uri . $row->path;
/**
* Implementation of hook_init().
*/
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() && PHP_SAPI != 'cli') {
drupal_goto($primary_base_url . current_path());
}
if (variable_get('unl_use_base_tag', TRUE)) {
$base_tag = array(
'#type' => 'html_tag',
'#tag' => 'base',
'#attributes' => array(
'href' => url('<front>', array('absoule' => TRUE)),
),
);
drupal_add_html_head($base_tag, 'base');
}
drupal_add_js(array('unl' => array('use_base_tag' => variable_get('unl_use_base_tag', TRUE))), 'setting');
_unl_handle_directory_index();
}
/**
* Custom function called by unl_init() to redirect users from
* a non-existant some/path/index.html to an existing some/path.
*/
function _unl_handle_directory_index() {
$path = current_path();
if (!in_array(basename($path), array('index.html', 'index.htm', 'index.shtml'))) {
return;
}
if (drupal_lookup_path('source', $path)) {
return;
}
if (drupal_lookup_path('source', dirname($path))) {
drupal_goto(dirname($path));
return;
}
if (dirname($path) == '.') {
drupal_goto('<front>');
return;
}
/**
* Implementation of hook_mail().
*/
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;
/**
* Custom function.
*/
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'));
}
}
/**
* 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'];
}
/**
* 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 determine 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();
if (!$current_menu_link) {
return;
}
$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();
}
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
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;
}
/**
* Implements hook_block_info()
*/
function unl_block_info() {
$blocks = array();
$blocks['my_sites'] = array(
'info' => 'My Sites',
'cache' => DRUPAL_CACHE_PER_USER,
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
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()
{
if (user_is_anonymous()) {
return array();
}
require_once dirname(__FILE__) . DIRECTORY_SEPARATOR . 'unl_site_creation.php';
$block = array();
$block['content'] = _unl_get_user_audit_content($GLOBALS['user']->name);
/**
* Implements hook_stream_wrappers_alter().
*/
function unl_stream_wrappers_alter(&$wrappers) {
if (variable_get('unl_clean_file_url')) {
$wrappers['public']['class'] = 'UnlPublicStreamWrapper';
}
}
class UnlPublicStreamWrapper extends DrupalPublicStreamWrapper {
function getExternalUrl() {
$url = $GLOBALS['base_url'];
if (!variable_get('unl_clean_file_url')) {
$url .= '/' . self::getDirectoryPath();
}
$path = str_replace('\\', '/', $this->getTarget());
$url .= '/' . drupal_encode_path($path);
return $url;
}
}
/**
* Implements hook_query_alter()
* Currently used to filter out users with no roles at "admin/people".
*/
function unl_query_alter(QueryAlterableInterface $query)
{
// If this query is coming from the "People" admin page
if (current_path() == 'admin/people') {
// Find the prefix for the "users" table
$usersTableAlias = NULL;
foreach ($query->getTables() as $alias => $table) {
if ($table['table'] == 'users') {
}
}
// If we actually find a users table
if ($usersTableAlias) {
// Join it with the users_roles tables so that only users with roles are seleceted.
$query->join('users_roles', 'unl_distinct_prefix_r', $usersTableAlias . '.uid = unl_distinct_prefix_r.uid');
}
}
}