'./top_hat_dynamic/data', 'cache' => false, 'secure' => false, 'central_url' => 'http://oregonstate.edu/osuhomepage', 'central_path' => '/www/virtual/oregonstate.edu/osuhomepage', 'version' => '1.2', 'search_url' => 'http://search.oregonstate.edu', 'site_name' => '', 'site_domain' => 'oregonstate.edu', 'top_hat_border_color' => '#dbd6d0', 'top_hat_wrapper' => 'wrapper4', 'top_hat_search_box'=>true, 'top_hat_campaign_id' => '', 'top_hat_menu_links' => true, 'top_hat_disable_drupal_search' => false ); // Include the library file. We are using the default path for this, not the // central path from custom settings - we can't get settings until we load the library. // So, ALWAYS make sure that the default central path points to the location where // the osu_homepage library that was developed to go with this version of top-hat // lives. /* replaced with local library file include_once(substr(__FILE__, 0, strrpos(__FILE__, "/")) . '/../../../lib/' . $top_hat_default_settings['version'] . '/functions.php'); */ $new_data_path = dirname(__FILE__) . '/data'; $top_hat_default_settings['data_path'] = $new_data_path; $top_hat_default_settings['cache'] = 0; include_once(substr(__FILE__, 0, strrpos(__FILE__, "/")) . '/lib/' . $top_hat_default_settings['version'] . '/functions.php'); // get the settings $top_hat_settings = get_settings($top_hat_default_settings, $osu_home_settings); // set the cache filename $top_hat_cache_filename = 'top-hat-'.md5(serialize($top_hat_settings)); $osu_top_hat_html = ''; // if we are using cache, fetch it if($top_hat_settings['cache']) { $osu_top_hat_html = get_cache($top_hat_settings['data_path'], $top_hat_cache_filename); } // if we didn't get a cache file, render the top hat string if (empty($osu_top_hat_html)) { try { $osu_top_hat_html = generate_top_hat($top_hat_settings); if($top_hat_settings['cache']) { save_cache($top_hat_settings['data_path'], $top_hat_cache_filename, $osu_top_hat_html); } } catch (Exception $e) { // todo: add proper exception handling } } //echo the top hat string echo $osu_top_hat_html; /** * Displays the top hat region * * @param array $top_hat_settings - array of all current settings * @return string - fully rendered top hat html string * */ function generate_top_hat($top_hat_settings) { $border_color = $top_hat_settings['top_hat_border_color']; $wrapper = $top_hat_settings['top_hat_wrapper']; $site_name = $top_hat_settings['site_name']; $site_domain = $top_hat_settings['site_domain']; $drupal_search = !$top_hat_settings['top_hat_disable_drupal_search']; $url = $top_hat_settings['central_url']; $version = $top_hat_settings['version']; $tag_image_src = $url . '/regions/top-hat/' . $version . '/images/osu-tag.gif'; $top_hat_data = $top_hat_settings['data_path'] . '/top-hat-1.xml'; $top_hat_html = ''; // If a drupal site is including this file, ask Drupal for the site path. // and set some drupal specific items if ($drupal_search && is_drupal()) { global $base_url; $top_hat_html .= sprintf('', $base_url ); if (empty($site_domain)) { $site_domain = str_replace('http://', '', $base_url); $top_hat_settings['site_domain'] = $site_domain; } if (empty($top_hat_settings['site_name'])) { $site_name = variable_get('site_name', ''); $top_hat_settings['site_name'] = $site_name; } $search_this_site = true; } $top_hat_html .= sprintf('
', $border_color ); $top_hat_html .= sprintf('
', $wrapper); $top_hat_html .= ''; $top_hat_html .= render_img_tag($tag_image_src, "Oregon State University", "tag"); $top_hat_html .= ''; if ($top_hat_settings['top_hat_menu_links']) { $top_hat_html .= render_menu_links($top_hat_settings); $top_hat_html .= render_foundation_link($top_hat_settings); } if ($top_hat_settings['top_hat_search_box']) { $top_hat_html .= render_search_box($top_hat_settings, $search_this_site); } $top_hat_html .= '
'; return $top_hat_html; } /** * Renders the menu links list from the top hat data file * * @param array $top_hat_settings - array of all current settings * @return string - fully rendered html list of menu links * */ function render_menu_links($top_hat_settings) { // Menu links // this is where we actually open the top hat data file, which // contains the links $data_file = $top_hat_settings['data_path'] . '/top-hat-1.xml'; $data_handle = fopen($data_file, 'r'); $data_xml = fread($data_handle, filesize($data_file)); fclose($data_handle); $top_hat_data = xmlrpc_decode($data_xml); $menu_string = ''; $menu_string .= ''; return $menu_string; } /** * renders the foundation (make a gift) link, which will point to the * appropriate fund as indicated by a setting * * @param array $top_hat_settings - array of all current settings * @return string - fully rendered foundation link html string * */ function render_foundation_link($top_hat_settings) { $campaign_img_src = $top_hat_settings['central_url'] . '/regions/top-hat/' . $top_hat_settings['version'] . '/images/campaign.png'; // TODO: take this URL out and put it in settings $campaign_link = 'https://osufoundation.org/giving/online_gift.shtml?first_designation=' . $top_hat_settings['top_hat_campaign_id']; // campaign link - this will be replaced in v1.2 $link_string .= sprintf( ''; return $link_string; } /** * Renders the top hat search box * * TODO: Simplify search box * * @param array $top_hat_settings - array of all current settings * @return string - fully rendered search box html string * */ function render_search_box($top_hat_settings, $search_this_site=null) { $search_image = $top_hat_settings['central_url'] . '/regions/top-hat/' . $top_hat_settings['version'] . '/images/menu.jpg'; $sumbit_image = $top_hat_settings['central_url'] . '/regions/top-hat/' . $top_hat_settings['version'] . '/images/submit.jpg'; $checked_image = $top_hat_settings['central_url'] . '/regions/top-hat/' . $top_hat_settings['version'] . '/images/check.gif'; $checked = '' . render_img_tag($checked_image, "selected") . ''; $search_box_string = ''; $search_box_string .= sprintf( ''; return $search_box_string; }