uw_virtual_site_homepage.module 25.7 KB
Newer Older
1
<?php
Liam Morland's avatar
Liam Morland committed
2

3 4 5 6 7 8
/**
 * @file
 * Code for the UW Virtual Site Homepage feature.
 */

include_once 'uw_virtual_site_homepage.features.inc';
9

10 11
/**
 * Implements hook_module_implements_alter().
Liam Morland's avatar
Liam Morland committed
12
 *
13 14 15 16
 * Remove the os_publications query_biblio_alter.
 */
function uw_virtual_site_homepage_module_implements_alter(&$implementations, $hook) {
  // If we are on the query_biblio_alter hook, unset os_publications and place uw_virtual_site_homepage last.
Liam Morland's avatar
Liam Morland committed
17
  if ($hook == "query_biblio_alter") {
18 19 20 21 22 23 24 25 26 27 28 29
    // Move uw_virtual_site_homepage's query_biblio_alter to be done last.
    $group = $implementations['uw_virtual_site_homepage'];
    unset($implementations['uw_virtual_site_homepage']);
    $implementations['uw_virtual_site_homepage'] = $group;

    // Remove os_publicatons' query_biblio_alter.
    unset($implementations['os_publications']);
  }
}

/**
 * Implements hook query_TAG_alter().
Liam Morland's avatar
Liam Morland committed
30
 *
31 32 33 34 35 36 37 38 39 40 41 42
 * TAG: biblio.
 * Set the searching and sorting options for the biblio query and add the space.
 */
function uw_virtual_site_homepage_query_biblio_alter(QueryAlterableInterface $query) {

  // Ensure that we have vsite turned on.
  if (!module_exists('vsite') || !$space = spaces_get_space()) {
    return;
  }

  _os_publications_filter_by_term($query);

Liam Morland's avatar
Liam Morland committed
43
  // This has to be separate because of scoping.
44 45 46 47 48 49 50 51 52 53
  if ($space->type == 'og') {
    $query->innerJoin('og_membership', 'ogm', 'n.nid = ogm.etid');
    $query->condition('ogm.entity_type', 'node');
    $query->condition('ogm.group_type', 'node');
    $query->condition('ogm.gid', $space->id);
  }

  $item = menu_get_item();

  // Checking for search_node alter tag.
Liam Morland's avatar
Liam Morland committed
54
  if (!isset($query->alterTags)) {
55 56

    // Check if we have a search_node alter tag.
Liam Morland's avatar
Liam Morland committed
57
    if (!isset($query->alterTags['search_node'])) {
58 59 60 61 62 63

      // Check the sort order for biblio.
      // If we're sorting by year, we want to sort by date as well to replicate D6
      // sorting.
      if (variable_get('biblio_sort', 'year') == 'year') {
        // Get their sort order.
Liam Morland's avatar
Liam Morland committed
64
        $biblio_year_sort = $space->controllers->variable->get('biblio_order', 'space');
65 66 67 68 69 70 71
        $order = &$query->getOrderBy();

        // Don't wipe the non-default sort order, this will let users still toggle asc/desc sorting by year.
        if (array_key_exists('biblio_year', $order) && $order['biblio_year'] != $biblio_year_sort) {
          $biblio_year_sort = $order['biblio_year'];
        }

Liam Morland's avatar
Liam Morland committed
72
        // Rebuild the array to our defaults only when the user is NOT searching.  When the user is searching, use their selections.
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 109 110 111 112 113
        if (isset($_GET['s']) && in_array($_GET['s'], array('author', 'title', 'type'))) {
          $s = current(array_keys($order));
          $o = current($order);

          if ($s = 'biblio_sort_title') {
            $biblio_sort_title = $o;
          }
        }
        else {
          $order = array();
        }

        // Sort by year, and after that create another sorting by the node's
        // "sticky" property, the creation date of the node, the Biblio date, and
        // the Biblio title.
        $order['biblio_year'] = isset($biblio_year_sort) ? $biblio_year_sort : 'DESC';
        $order['n.sticky'] = 'DESC';
        $order['n.created'] = 'DESC';
        $order['biblio_sort_title'] = (isset($biblio_sort_title)) ? $biblio_sort_title : 'ASC';
      }
      elseif (variable_get('biblio_sort', 'year') == 'type') {
        // Sort by type, and after that create another sorting by creation date of
        // the node.
        $order = &$query->getOrderBy();
        $new_order = array();

        foreach ($order as $key => $value) {
          $new_order[$key] = $value;
          if ($key == 'biblio_type_name') {
            $new_order['n.sticky'] = 'DESC';
            $new_order['biblio_year'] = 'DESC';
            $new_order['n.created'] = 'DESC';
          }
        }

        $order = $new_order;
      }
    }
  }
}

Liam Morland's avatar
Liam Morland committed
114
/**
115
 * Implements hook_field_widget_form_alter().
Liam Morland's avatar
Liam Morland committed
116
 *
117 118 119
 * Adding process to image types to change title to caption for homepage banners.
 */
function uw_virtual_site_homepage_field_widget_form_alter(&$element, &$form_state, $context) {
120

Liam Morland's avatar
Liam Morland committed
121 122 123
  if ($context['field']['type'] == 'image') {
    foreach (element_children($element) as $key => $child) {
      if ($element[$key]['#description'] == 'Provide banner images for virtual site homepages on Scholar at Waterloo sites.') {
124 125 126 127 128 129 130 131
        $element[$key]['#process'][] = 'uw_virtual_site_homepage_image_field_widget_process';
      }
    }
  }
}

/**
 * Implements hook_image_field_widget_process().
Liam Morland's avatar
Liam Morland committed
132
 *
133 134 135 136
 * Processing images to change title to caption for homepage banners.
 */
function uw_virtual_site_homepage_image_field_widget_process($element, &$form_state, $form) {
  // Set the title to be the caption and the description.
137
  $element['title']['#description'] = 'The title is display with the picture.';
138

Liam Morland's avatar
Liam Morland committed
139
  // Return the altered element.
140 141 142
  return $element;
}

143
/**
144
 * Implements hook_page_alter().
Liam Morland's avatar
Liam Morland committed
145
 *
146 147 148
 * Placing homepage banners on the virtual site homepage.
 */
function uw_virtual_site_homepage_page_alter(&$page) {
149
  global $base_path;
150

151
  // Setting the variables to be used in homepage banners.
152
  $index = 0;
Liam Morland's avatar
Liam Morland committed
153
  $continue = TRUE;
154

Liam Morland's avatar
Liam Morland committed
155
  if (isset($page['uw-virtual-site-homepage']['field_uw_faculty_list_logo'][0]['#markup'])) {
156 157
    $site_links = _uw_virtual_site_homepage_get_site_links();
    if (isset($site_links[$page['uw-virtual-site-homepage']['field_uw_faculty_list_logo'][0]['#markup']])) {
158 159
      $site_link = $site_links[$page['uw-virtual-site-homepage']['field_uw_faculty_list_logo'][0]['#markup']];
      $page['uw-virtual-site-homepage']['uw_scholar_row']['site_link'] = $site_link;
160
    }
161 162
  }

163
  // If there are banners, process them.
Liam Morland's avatar
Liam Morland committed
164
  if (isset($page['uw-virtual-site-homepage']['field_uw_homepage_banners'][$index])) {
165

Liam Morland's avatar
Liam Morland committed
166
    // HTML divs in homepage banners.
167 168
    $html = '<div class="field-name-field-uw-home-page-banners">';
    $html .= '<div class="field-items">';
169

170 171
    $pagenumber = 0;
    $boxes = '';
172 173 174
    $num_of_images = 0;

    // Get the number of images in the homepage banners.
Liam Morland's avatar
Liam Morland committed
175 176
    foreach ($page['uw-virtual-site-homepage']['field_uw_homepage_banners'] as $key => $value) {
      if (is_int($key)) {
177 178 179
        $num_of_images++;
      }
    }
180

181
    // While there is a continue, process the homepage banners.
Liam Morland's avatar
Liam Morland committed
182 183 184 185
    while ($continue) {
      foreach ($page['uw-virtual-site-homepage']['field_uw_homepage_banners'][$index]['entity']['field_collection_item'] as $key => $value) {
        $fc_id = $key;
        break;
186 187
      }

188
      // Set theme paths, alt text and all banner sizes.
189
      $file = $page['uw-virtual-site-homepage']['field_uw_homepage_banners'][$index]['entity']['field_collection_item'][$fc_id]['field_uw_homepage_banners_image'][0]['#item']['uri'];
190

191
      $banner_alt = 'Test ALT';
192 193 194 195 196
      $banner_small = image_style_url('uw_homepage_banners', $file);
      $banner_square = image_style_url('uw_homepage_banners_small', $file);
      $banner_med = image_style_url('uw_homepage_banners_medium', $file);
      $banner_large = image_style_url('uw_homepage_banners_large', $file);
      $banner_xl = image_style_url('uw_homepage_banners_xl', $file);
197

198
      $pagenumber++;
199 200

      // Set the image.
Liam Morland's avatar
Liam Morland committed
201 202
      if ($pagenumber == 1) {
        $html .= '<figure class="field-item uw-homepage-banners-figure element-selected">';
203 204
      }
      else {
Liam Morland's avatar
Liam Morland committed
205
        $html .= '<figure class="field-item uw-homepage-banners-figure element-invisible">';
206
      }
207

Liam Morland's avatar
Liam Morland committed
208 209
      if (isset($page['uw-virtual-site-homepage']['field_uw_homepage_banners'][$index]['entity']['field_collection_item'][$fc_id]['field_uw_homepage_banners_link']['#items'][0]['url'])) {
        $html .= '<a href="' . $page['uw-virtual-site-homepage']['field_uw_homepage_banners'][$index]['entity']['field_collection_item'][$fc_id]['field_uw_homepage_banners_link']['#items'][0]['url'] . '">';
210 211
      }

212 213
      // Set the picture using the picture tag.
      $html .= '<picture>
Liam Morland's avatar
Liam Morland committed
214
                <source srcset="' . $banner_xl . '" media="(min-width: 1280px)">
215 216
                <source srcset="' . $banner_large . '" media="(min-width: 1024px)">
                <source srcset="' . $banner_med . '" media="(min-width: 769px)">
217
                <source srcset="' . $banner_square . '" media="(min-width: 480px)">
218
                <source srcset="' . $banner_small . '" media="(min-width: 320px)">
219
                <source srcset="' . $banner_large . '">';
220
      $html .= '<img src="' . $banner_xl . '" alt="' . $banner_alt . '">';
221
      $html .= '</picture>';
222 223

      // If there is a title, double check, and then set the caption.
Liam Morland's avatar
Liam Morland committed
224
      if (isset($page['uw-virtual-site-homepage']['field_uw_homepage_banners'][$index]['entity']['field_collection_item'][$fc_id]['field_uw_homepage_banners_image'][0]['#item']['title'])) {
225 226

        // If there is a title, set the caption.
227
        //  If there is not title, check that there is a title for the link and use that.
Liam Morland's avatar
Liam Morland committed
228
        if ($page['uw-virtual-site-homepage']['field_uw_homepage_banners'][$index]['entity']['field_collection_item'][$fc_id]['field_uw_homepage_banners_image'][0]['#item']['title'] !== "") {
229
          $html .= '<div class="banner-caption-wrapper">';
230 231
          $html .= '<div class="banner-caption">';
          $html .= '<h2>' . $page['uw-virtual-site-homepage']['field_uw_homepage_banners'][$index]['entity']['field_collection_item'][$fc_id]['field_uw_homepage_banners_image'][0]['#item']['title'] . '</h2>';
Liam Morland's avatar
Liam Morland committed
232 233
          if ($page['uw-virtual-site-homepage']['field_uw_homepage_banners'][$index]['entity']['field_collection_item'][$fc_id]['field_uw_homepage_banners_image'][0]['#item']['image_field_caption']['value']) {
            $html .= '<span>' . $page['uw-virtual-site-homepage']['field_uw_homepage_banners'][$index]['entity']['field_collection_item'][$fc_id]['field_uw_homepage_banners_image'][0]['#item']['image_field_caption']['value'] . '</span>';
234
          }
235 236
          $html .= '</div>';
          $html .= '</div>';
237
        }
238 239 240 241 242 243 244
        elseif (isset($page['uw-virtual-site-homepage']['field_uw_homepage_banners'][$index]['entity']['field_collection_item'][$fc_id]['field_uw_homepage_banners_link']['#items'][0]['title'])) {
          $html .= '<div class="banner-caption-wrapper">';
          $html .= '<div class="banner-caption">';
          $html .= '<h2>' . $page['uw-virtual-site-homepage']['field_uw_homepage_banners'][$index]['entity']['field_collection_item'][$fc_id]['field_uw_homepage_banners_link']['#items'][0]['title'] . '</h2>';
          $html .= '</div>';
          $html .= '</div>';
        }
245
      }
246

Liam Morland's avatar
Liam Morland committed
247 248 249
      if (isset($page['uw-virtual-site-homepage']['field_uw_homepage_banners'][$index]['entity']['field_collection_item'][$fc_id]['field_uw_homepage_banners_link']['#items'][0]['url'])) {
        $html .= '</a>';
      }
250

251
      // Increment the index.
252
      $index++;
253 254

      // If there are not any more homepage banners, stop processing the homepage banners.
Liam Morland's avatar
Liam Morland committed
255 256
      if (!(isset($page['uw-virtual-site-homepage']['field_uw_homepage_banners'][$index]))) {
        $continue = FALSE;
257
      }
258 259

      // If there is more than one image add the paginator blocks.
Liam Morland's avatar
Liam Morland committed
260
      if ($num_of_images > 1) {
261 262
        // More html.
        $html .= '<div class="banner-controls">';
Liam Morland's avatar
Liam Morland committed
263

264 265 266
        // Set previous and next buttons.
        $html .= '<button id="previous_banner" class="tabs-previous"><</button>';
        $html .= '<button id="next_banner" class="tabs-next">></button>';
Liam Morland's avatar
Liam Morland committed
267

268 269 270
        // More html to close the homepage banners.
        $html .= '</div>';
        $html .= '</figure>';
Liam Morland's avatar
Liam Morland committed
271 272 273

        if ($pagenumber == 1) {
          $boxes .= '<li><a href="" title="display banner #' . $pagenumber . '" class="hpb_selected" data-pagenumber="' . $pagenumber . '"><span class="element-invisible">Display banner #</span>' . $pagenumber . '</a></li>';
274 275
        }
        else {
Liam Morland's avatar
Liam Morland committed
276
          $boxes .= '<li><a href="" title="display banner #' . $pagenumber . '" data-pagenumber="' . $pagenumber . '"><span class="element-invisible">Display banner #</span>' . $pagenumber . '</a></li>';
277 278
        }
      }
Liam Morland's avatar
Liam Morland committed
279
      else {
280 281
        $html .= '</figure>';
      }
282
    }
283

284
    // If there is more than one image, add the Play/Pause button.
Liam Morland's avatar
Liam Morland committed
285
    if ($num_of_images > 1) {
286 287 288 289 290 291 292 293 294 295 296
      // Final closing html and play/pause button.
      $html .= '</div>';
      $html .= '<button class="slideshow-control pause" title="Pause">';
      $html .= '<span class="element-invisible">Pause banner slideshow</span>';
      $html .= '<span class="icon-pause"></span>';
      $html .= '</button>';
      $html .= '<ul class="homepage_banners_paginator">';
      $html .= $boxes;
      $html .= '</ul>';
      $html .= '</div>';
    }
Liam Morland's avatar
Liam Morland committed
297 298 299 300
    else {
      // Close the opening HTML divs in homepage banners. if single image in banner.
      $html .= '</div>';
      $html .= '</div>';
301
    }
302 303 304 305 306 307

    // Set the html to the page variable.
    $page['uw_virtual_page_homepage_banners_html'] = $html;
  }

  // If there is credentials in the virutal site homepage settings, add it to the header.
Liam Morland's avatar
Liam Morland committed
308 309 310 311
  if (isset($page['uw-virtual-site-homepage']['field_uw_credentials'])) {
    if (isset($page['header_second']['boxes_site_info']['content']['#markup'])) {
      $page['header_second']['boxes_site_info']['content']['#markup'] = preg_replace('/<p>(.*)<a(.*)<\/a>/s', '<h2>' . $page['uw-virtual-site-homepage']['field_uw_credentials'][0]['#markup'] . '</h2>', $page['header_second']['boxes_site_info']['content']['#markup']);
    }
312
    elseif (isset($page['header_second']['boxes_site_info']['#markup']) && $page['header_second']['boxes_site_info']['#markup']) {
Liam Morland's avatar
Liam Morland committed
313 314
      $page['header_second']['boxes_site_info']['#markup'] = preg_replace('/<p>(.*)<a(.*)<\/a>/s', '<h2>' . $page['uw-virtual-site-homepage']['field_uw_credentials'][0]['#markup'] . '</h2>', $page['header_second']['boxes_site_info']['#markup']);
    }
315 316 317
  }
}

318
/**
Liam Morland's avatar
Liam Morland committed
319
 * Implements hook_form_alter().
Liam Morland's avatar
Liam Morland committed
320
 *
321 322 323 324
 * Form ID: _os_link_external_form
 * Hide target option field.
 */
function uw_virtual_site_homepage_form_alter(&$form, &$form_state, $form_id) {
325

Liam Morland's avatar
Liam Morland committed
326 327 328
  if ($form_id == "biblio_search_form") {
    $form['search_form']['#collapsed'] = FALSE;
    $form['search_form']['#collapsible'] = FALSE;
329

Liam Morland's avatar
Liam Morland committed
330 331 332 333
    if (isset($form['search_form']['filterform']['filters']['current'][0]['#markup'])) {
      if ($form['search_form']['filterform']['filters']['current'][0]['#markup'] !== "") {
        $form['search_form']['filterform']['filters']['#collapsed'] = FALSE;
      }
334
    }
Liam Morland's avatar
Liam Morland committed
335
  }
336 337 338 339 340
  if ($form_id == '_os_link_external_form' && isset($form['target_option'])) {
    unset($form['target_option']);
  }
}

341
/**
342
 * Implements hook_FORMID_form_alter().
Liam Morland's avatar
Liam Morland committed
343
 *
344
 * Removing options and placing data on the form for setting the virtual homepage.
345
 */
346 347 348 349 350 351
function uw_virtual_site_homepage_form_uw_virtual_site_homepage_node_form_alter(&$form, &$form_state, $form_id) {
  global $base_path;

  // Get current link.
  $url = request_uri();

352
  // Ensure that we don't replace all the slashes if just at top root.
Liam Morland's avatar
Liam Morland committed
353
  if ($base_path !== '/') {
354 355 356
    // Ensure that we are at the very base.
    $url = str_replace($base_path, '', $url);
  }
357

Liam Morland's avatar
Liam Morland committed
358
  // Break URL into its parts.
359 360 361
  $url_parts = explode('/', $url);

  // The username should be the first element in the url_parts array, set it to username.
362
  // If the first element is blank use the second element.
Liam Morland's avatar
Liam Morland committed
363 364
  if ($url_parts[0] == '') {
    $username = $url_parts[1];
365 366 367 368
  }
  else {
    $username = $url_parts[0];
  }
369 370 371 372

  // Set title to watiam id and disable title.
  $form['title']['#value'] = $username;
  $form['title']['#disabled'] = TRUE;
373
  $form['title']['#access'] = FALSE;
374

375
  // Removing elements from the page that we do not want set.
376 377 378 379 380 381 382 383
  $form['author']['#access'] = FALSE;
  $form['menu']['#access'] = FALSE;
  $form['path']['#access'] = FALSE;
  $form['options']['#access'] = FALSE;
  $form['og_group_ref']['#access'] = FALSE;
  $form['og_vocabulary']['#access'] = FALSE;
  $form['book']['#access'] = FALSE;
  $form['comment_settings']['#access'] = FALSE;
384

385 386 387 388 389 390 391 392 393 394 395 396 397 398 399
  // Getting the current space and loading that node.
  // This is the users vsite node.
  $space = spaces_get_space();
  $node = $space->group;

  // Adding the site information group to the form.
  $form['site_info'] = array(
    '#type' => 'fieldset',
    '#title' => t('Site Information'),
    '#weight' => -999,
  );

  // Adding the site title to the form.  This is at the top of every page.
  $form['site_info']['site_title'] = array(
    '#type' => 'textfield',
400
    '#title' => t('Name'),
401
    '#default_value' => $node->title,
402
    '#description' => t('Enter your name as the title of your site. This will appear at the top of every page (for example: Dr John Doe).'),
403
    '#size' => 60,
Liam Morland's avatar
Liam Morland committed
404
    '#required' => TRUE,
405 406
  );

407
  // Ensuring that we are getting a default value.
Liam Morland's avatar
Liam Morland committed
408
  if (isset($node->field_site_description[LANGUAGE_NONE][0]['value'])) {
409 410 411 412 413 414
    $default_value = $node->field_site_description[LANGUAGE_NONE][0]['value'];
  }
  else {
    $default_value = '';
  }

415 416 417 418 419 420
  // Move help text of site description from the bottom to the top of field_uw_site_description.
  if (isset($form['field_uw_site_description'][LANGUAGE_NONE][0]['#description'])) {
    $form['field_uw_site_description'][LANGUAGE_NONE][0]['#field_prefix'] = $form['field_uw_site_description'][LANGUAGE_NONE][0]['#description'];
    $form['field_uw_site_description'][LANGUAGE_NONE][0]['#description'] = '';
  }

421 422 423
  // Adding the site description to the page.  This is just below the site title and on every page.
  $form['site_info']['descrip'] = array(
    '#type' => 'textfield',
424
    '#title' => t('Title'),
425
    '#default_value' => $default_value,
426
    '#description' => t('Enter your academic role, position or title. This will appear under the site title at the top of every page (for example: Professor of Economics).'),
427 428 429
    '#size' => 60,
  );

430 431 432
  $form['site_info']['field_uw_credentials'] = $form['field_uw_credentials'];
  unset($form['field_uw_credentials']);

433 434 435 436
  // Adding the site information submit callback.
  $form['actions']['submit']['#submit'][] = 'uw_vitual_site_homepage_site_information_form_submit';

  // Adding the redirect back to the homepage after the save of the uw_virtual_site_homepage.
437
  $form['actions']['submit']['#submit'][] = 'uw_virtual_site_homepage_node_form_redirect';
438

439 440
  // Adding the validate for twitter.
  $form['#validate'][] = '_uw_virtual_site_homepage_twitter_validate';
441 442 443
}

/**
444
 * The validate for twitter.
445
 */
446
function _uw_virtual_site_homepage_twitter_validate(&$form, &$form_state) {
447

Liam Morland's avatar
Liam Morland committed
448 449
  // If there is a twitter username.
  if (isset($form_state['values']['field_uw_twitter_username'][LANGUAGE_NONE][0]['value'])) {
450

Liam Morland's avatar
Liam Morland committed
451 452
    // If the twitter username has a value.
    if ($form_state['values']['field_uw_twitter_username'][LANGUAGE_NONE][0]['value'] !== "") {
453

Liam Morland's avatar
Liam Morland committed
454 455
      // If there is a twitter type.
      if (isset($form_state['values']['field_uw_twitter_type'][LANGUAGE_NONE][0])) {
456

Liam Morland's avatar
Liam Morland committed
457 458
        // If the twitter type has no value, set a form error.
        if ($form_state['values']['field_uw_twitter_type'][LANGUAGE_NONE][0]['value'] == NULL) {
459

Liam Morland's avatar
Liam Morland committed
460 461
          // Set the form error.
          form_set_error('field-uw-twitter-username', 'You must select a place to display the twitter feed.');
462
        }
Liam Morland's avatar
Liam Morland committed
463
      }
464
    }
Liam Morland's avatar
Liam Morland committed
465
  }
466 467
}

468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486
/**
 * Submit callback.
 * Saves site title and site description.
 */
function uw_vitual_site_homepage_site_information_form_submit($form, &$form_state) {
  if (module_exists('vsite') && $space = spaces_get_space()) {
    // Getting the current space and loading that node.
    // This is the users vsite node.
    $node = $space->group;

    // Setting the title from the form.  This can not be blank and is validate because it is a required element on the form.
    $node->title = $form_state['values']['site_title'];

    // Setting the site description from the form.
    $node->field_site_description[LANGUAGE_NONE][0] = array(
      'value' => $form_state['values']['descrip'],
      'format' => NULL,
    );

Liam Morland's avatar
Liam Morland committed
487 488 489 490 491
    if (isset($form_state['value']['field_uw_credentials'])) {
      $node->field_uw_credentials[LANGUAGE_NONE][0] = array(
        'value' => $form_state['value']['field_uw_credentials'],
        'format' => NULL,
      );
492
    }
493

494 495 496 497 498 499 500 501 502 503 504
    // Ensuring that we get a save of the node which is the users vsite.
    try {
      node_save($node);
    }
    catch (Exception $e) {
      drupal_set_message(t('Error saving site information. Contact your site administrator.'), 'error');
      error_log($e);
    }
  }
}

505 506 507 508
/**
 * Submit callback.
 */
function uw_virtual_site_homepage_node_form_redirect($form, &$form_state) {
509 510 511
  // Clear the caches of the landing page info, in case the site title has changed.
  cache_clear_all('ctools_export:views_view:uw_os_number_of_sites', 'cache_views', TRUE);
  cache_clear_all('uw_os_number_of_sites', 'cache_views_data', TRUE);
512 513 514 515 516

  // Unset destination first.
  unset($_GET['destination']);
  unset($_REQUEST['edit']['destination']);

517
  // Redirecting to home page after a save.
518
  $form_state['redirect'] = 'home';
519
}
520

Liam Morland's avatar
Liam Morland committed
521 522 523
/**
 *
 */
524
function _uw_virtual_site_homepage_get_site_links() {
Liam Morland's avatar
Liam Morland committed
525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587
  // Array that stores all of links.
  $site_links['University of Waterloo'] = 'https://uwaterloo.ca';
  $site_links['Applied Health Sciences'] = 'https://uwaterloo.ca/applied-health-sciences/';
  $site_links['Applied Health Sciences - Recreation and Leisure Studies'] = 'https://uwaterloo.ca/recreation-and-leisure-studies/';
  $site_links['Applied Health Sciences - Kinesiology'] = 'https://uwaterloo.ca/kinesiology/';
  $site_links['Applied Health Sciences - Public Health'] = 'https://uwaterloo.ca/public-health-and-health-systems/';
  $site_links['Arts'] = 'https://uwaterloo.ca/arts/';
  $site_links['Arts - Anthropology'] = 'https://uwaterloo.ca/anthropology/';
  $site_links['Arts - Classical Studies'] = 'https://uwaterloo.ca/classical-studies/';
  $site_links['Arts - Drama Speech Communication'] = 'https://uwaterloo.ca/drama-speech-communication/';
  $site_links['Arts - Economics'] = 'https://uwaterloo.ca/economics/';
  $site_links['Arts - English Language Literature'] = 'https://uwaterloo.ca/english/';
  $site_links['Arts - Fine Arts'] = 'https://uwaterloo.ca/fine-arts/';
  $site_links['Arts - French'] = 'https://uwaterloo.ca/french-studies/';
  $site_links['Arts - Germanic Slavic Studies'] = 'https://uwaterloo.ca/germanic-slavic-studies/';
  $site_links['Arts - History'] = 'https://uwaterloo.ca/history/';
  $site_links['Arts - Philosophy'] = 'https://uwaterloo.ca/philosophy/';
  $site_links['Arts - Political Science'] = 'https://uwaterloo.ca/political-science/';
  $site_links['Arts - Psychology'] = 'https://uwaterloo.ca/psychology/';
  $site_links['Arts - Religious Studies'] = 'https://uwaterloo.ca/religious-studies/';
  $site_links['Arts - School of Accounting and Finance'] = 'https://uwaterloo.ca/school-of-accounting-and-finance/';
  $site_links['Arts - Sociology and Legal Studies'] = 'https://uwaterloo.ca/sociology-and-legal-studies/';
  $site_links['Arts - Spanish and Latin American Studies'] = 'https://uwaterloo.ca/spanish/';
  $site_links['Engineering'] = 'https://uwaterloo.ca/engineering/';
  $site_links['Engineering wordmark'] = 'https://uwaterloo.ca/engineering/';
  $site_links['Engineering - Architecture'] = 'https://uwaterloo.ca/architecture/';
  $site_links['Engineering - Chemical Engineering'] = 'https://uwaterloo.ca/chemical-engineering/';
  $site_links['Engineering - Civil Environmental Engineering'] = 'https://uwaterloo.ca/civil-environmental-engineering/';
  $site_links['Engineering - Electrical Computer Engineering'] = 'https://uwaterloo.ca/electrical-computer-engineering/';
  $site_links['Engineering - Management Sciences'] = 'https://uwaterloo.ca/management-sciences/';
  $site_links['Engineering - Mechanical Engineering'] = 'https://uwaterloo.ca/mechanical-mechatronics-engineering/';
  $site_links['Engineering - Systems Design Engineering'] = 'https://uwaterloo.ca/systems-design-engineering/';
  $site_links['Environment'] = 'https://uwaterloo.ca/environment/';
  $site_links['Environment - Environment Enterprise Development'] = 'https://uwaterloo.ca/school-environment-enterprise-development/';
  $site_links['Environment - Enviromental Resources and Sustainability'] = 'https://uwaterloo.ca/environment-resources-and-sustainability/';
  $site_links['Environment - Geography Environmental and Management'] = 'https://uwaterloo.ca/geography-environmental-management/';
  $site_links['Environment - Knowledge Intergration'] = 'https://uwaterloo.ca/knowledge-integration/';
  $site_links['Environment - Planning'] = 'https://uwaterloo.ca/planning/';
  $site_links['Mathematics'] = 'https://uwaterloo.ca/math/';
  $site_links['Mathematics - Applied Math'] = 'https://uwaterloo.ca/applied-mathematics/';
  $site_links['Mathematics - Combinatorics and Optimization'] = 'https://uwaterloo.ca/combinatorics-and-optimization/';
  $site_links['Mathematics - Computer Science'] = 'https://cs.uwaterloo.ca/';
  $site_links['Mathematics - Pure Math'] = 'https://uwaterloo.ca/pure-mathematics/';
  $site_links['Mathematics - Statistics Actuarial Science'] = 'https://uwaterloo.ca/statistics-and-actuarial-science/';
  $site_links['Science'] = 'https://uwaterloo.ca/science/';
  $site_links['Sciecne - Pharmacy'] = 'https://uwaterloo.ca/pharmacy/';
  $site_links['Science - Biology'] = 'https://uwaterloo.ca/biology/';
  $site_links['Science - Chemistry'] = 'https://uwaterloo.ca/chemistry/';
  $site_links['Science- Earth and Environmental Science'] = 'https://uwaterloo.ca/earth-environmental-sciences/';
  $site_links['Science - Optometry and Vision Science'] = 'https://uwaterloo.ca/optometry-vision-science/';
  $site_links['Science - Physics and Astronomy'] = 'https://uwaterloo.ca/physics-astronomy/';
  $site_links['Conrad Grebel'] = 'https://uwaterloo.ca/grebel/';
  $site_links['Renison University College'] = 'https://uwaterloo.ca/renison/';
  $site_links['St. Jerome\'s University'] = 'https://www.sju.ca/';
  $site_links['St. Jerome\'s University'] = 'https://www.sju.ca/';
  $site_links['St. Paul\'s University College'] = 'https://uwaterloo.ca/stpauls/';
  $site_links['McMaster University'] = 'http://www.mcmaster.ca/';
  $site_links['University of Guelph'] = 'http://www.uoguelph.ca/';
  $site_links['Water Institute'] = 'https://uwaterloo.ca/water-institute/';
  $site_links['Western University'] = 'http://www.uwo.ca/';
  $site_links['Wilfrid Laurier University'] = 'https://www.wlu.ca/';

  return $site_links;
588
}