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. if (!isset($query->alterTags)) { // Check if we have a search_node alter tag. if (!isset($query->alterTags['search_node'])) { // 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. $biblio_year_sort = $space->controllers->variable->get('biblio_order', 'space'); $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']; } // Rebuild the array to our defaults only when the user is NOT searching. When the user is searching, use their selections. 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; } } } } /** * Implements hook_field_widget_form_alter(). * * 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) { 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.') { $element[$key]['#process'][] = 'uw_virtual_site_homepage_image_field_widget_process'; } } } } /** * Implements hook_image_field_widget_process(). * * 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. $element['title']['#description'] = 'The title is display with the picture.'; // Return the altered element. return $element; } /** * Implements hook_page_alter(). * * Placing homepage banners on the virtual site homepage. */ function uw_virtual_site_homepage_page_alter(&$page) { global $base_path; // Setting the variables to be used in homepage banners. $index = 0; $continue = TRUE; if (isset($page['uw-virtual-site-homepage']['field_uw_faculty_list_logo'][0]['#markup'])) { $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']])) { $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; } } // If there are banners, process them. if (isset($page['uw-virtual-site-homepage']['field_uw_homepage_banners'][$index])) { // HTML divs in homepage banners. $html = '
'; $html .= '
'; $pagenumber = 0; $boxes = ''; $num_of_images = 0; // Get the number of images in the homepage banners. foreach ($page['uw-virtual-site-homepage']['field_uw_homepage_banners'] as $key => $value) { if (is_int($key)) { $num_of_images++; } } // While there is a continue, process the homepage banners. while ($continue) { foreach ($page['uw-virtual-site-homepage']['field_uw_homepage_banners'][$index]['entity']['field_collection_item'] as $key => $value) { $fc_id = $key; break; } // Set theme paths, alt text and all banner sizes. $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']; $banner_alt = 'Test ALT'; $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); $pagenumber++; // Set the image. if ($pagenumber == 1) { $html .= '
'; } else { $html .= '
'; } 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 .= ''; } // Set the picture using the picture tag. $html .= ' '; $html .= '' . $banner_alt . ''; $html .= ''; // If there is a title, double check, and then set the caption. 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'])) { // If there is a title, set the caption. // If there is not title, check that there is a title for the link and use that. 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'] !== "") { $html .= ''; } 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 .= ''; } } 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 .= ''; } // Increment the index. $index++; // If there are not any more homepage banners, stop processing the homepage banners. if (!(isset($page['uw-virtual-site-homepage']['field_uw_homepage_banners'][$index]))) { $continue = FALSE; } // If there is more than one image add the paginator blocks. if ($num_of_images > 1) { // More html. $html .= ''; $html .= '
'; if ($pagenumber == 1) { $boxes .= '
  • Display banner #' . $pagenumber . '
  • '; } else { $boxes .= '
  • Display banner #' . $pagenumber . '
  • '; } } else { $html .= '
    '; } } // If there is more than one image, add the Play/Pause button. if ($num_of_images > 1) { // Final closing html and play/pause button. $html .= '
    '; $html .= ''; $html .= ''; $html .= '
    '; } else { // Close the opening HTML divs in homepage banners. if single image in banner. $html .= ''; $html .= ''; } // 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. 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('/

    (.*)/s', '

    ' . $page['uw-virtual-site-homepage']['field_uw_credentials'][0]['#markup'] . '

    ', $page['header_second']['boxes_site_info']['content']['#markup']); } elseif (isset($page['header_second']['boxes_site_info']['#markup']) && $page['header_second']['boxes_site_info']['#markup']) { $page['header_second']['boxes_site_info']['#markup'] = preg_replace('/

    (.*)/s', '

    ' . $page['uw-virtual-site-homepage']['field_uw_credentials'][0]['#markup'] . '

    ', $page['header_second']['boxes_site_info']['#markup']); } } } /** * Implements hook_form_alter(). * * Form ID: _os_link_external_form * Hide target option field. */ function uw_virtual_site_homepage_form_alter(&$form, &$form_state, $form_id) { if ($form_id == "biblio_search_form") { $form['search_form']['#collapsed'] = FALSE; $form['search_form']['#collapsible'] = FALSE; 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; } } } if ($form_id == '_os_link_external_form' && isset($form['target_option'])) { unset($form['target_option']); } } /** * Implements hook_FORMID_form_alter(). * * Removing options and placing data on the form for setting the virtual homepage. */ 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(); // Ensure that we don't replace all the slashes if just at top root. if ($base_path !== '/') { // Ensure that we are at the very base. $url = str_replace($base_path, '', $url); } // Break URL into its parts. $url_parts = explode('/', $url); // The username should be the first element in the url_parts array, set it to username. // If the first element is blank use the second element. if ($url_parts[0] == '') { $username = $url_parts[1]; } else { $username = $url_parts[0]; } // Set title to watiam id and disable title. $form['title']['#value'] = $username; $form['title']['#disabled'] = TRUE; $form['title']['#access'] = FALSE; // Removing elements from the page that we do not want set. $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; // 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', '#title' => t('Name'), '#default_value' => $node->title, '#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).'), '#size' => 60, '#required' => TRUE, ); // Ensuring that we are getting a default value. if (isset($node->field_site_description[LANGUAGE_NONE][0]['value'])) { $default_value = $node->field_site_description[LANGUAGE_NONE][0]['value']; } else { $default_value = ''; } // 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'] = ''; } // 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', '#title' => t('Title'), '#default_value' => $default_value, '#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).'), '#size' => 60, ); $form['site_info']['field_uw_credentials'] = $form['field_uw_credentials']; unset($form['field_uw_credentials']); // 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. $form['actions']['submit']['#submit'][] = 'uw_virtual_site_homepage_node_form_redirect'; // Adding the validate for twitter. $form['#validate'][] = '_uw_virtual_site_homepage_twitter_validate'; } /** * The validate for twitter. */ function _uw_virtual_site_homepage_twitter_validate(&$form, &$form_state) { // If there is a twitter username. if (isset($form_state['values']['field_uw_twitter_username'][LANGUAGE_NONE][0]['value'])) { // If the twitter username has a value. if ($form_state['values']['field_uw_twitter_username'][LANGUAGE_NONE][0]['value'] !== "") { // If there is a twitter type. if (isset($form_state['values']['field_uw_twitter_type'][LANGUAGE_NONE][0])) { // If the twitter type has no value, set a form error. if ($form_state['values']['field_uw_twitter_type'][LANGUAGE_NONE][0]['value'] == NULL) { // Set the form error. form_set_error('field-uw-twitter-username', 'You must select a place to display the twitter feed.'); } } } } } /** * 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, ); 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, ); } // 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); } } } /** * Submit callback. */ function uw_virtual_site_homepage_node_form_redirect($form, &$form_state) { // 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); // Unset destination first. unset($_GET['destination']); unset($_REQUEST['edit']['destination']); // Redirecting to home page after a save. $form_state['redirect'] = 'home'; } /** * */ function _uw_virtual_site_homepage_get_site_links() { // 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; }