Public feed #726309

Unnamed

public text v1 · immutable
Raw Edit
·published 2007-10-05 02:04 UTC
rendered paste body
<?php
// $Id: template.php 1629 2007-10-02 02:11:38Z stuf $

require_once(drupal_get_path('theme', 'nio') .'/inc/theme_overrides.inc');
require_once(drupal_get_path('theme', 'nio') .'/inc/node_process.inc');


require_once(drupal_get_path('theme', 'nio') .'/inc/views_lists.inc');


// NH: Not sure whether this is the best place to put this...
//variable_set('teaser_length', 300);

function nio_regions() {
  return array(
    'weather' => t('weather block'),
    'landing' => t('landing banner'),
    'content_top' => t('content top'),
    'content_bottom' => t('content bottom'),
    'foot_ad' => t('foot advertisement'),
    'sidebar' => t('content side'),
    'sidebar_ad' => t('sidebar ad'),
    'ponder_column' => t('pondering column')
  );
}

// CSS
drupal_add_css($path = path_to_theme().'/css/all.css', $type = 'theme', $media = 'all', $preprocess = TRUE);
drupal_add_css($path = path_to_theme().'/css/categories.css', $type = 'theme', $media = 'screen', $preprocess = TRUE);
drupal_add_css($path = path_to_theme().'/css/colours.css', $type = 'theme', $media = 'all', $preprocess = TRUE);
drupal_add_css($path = path_to_theme().'/css/blocks.css', $type = 'theme', $media = 'all', $preprocess = TRUE);
drupal_add_css($path = path_to_theme().'/css/image-links.css', $type = 'theme', $media = 'all', $preprocess = TRUE);
drupal_add_css($path = path_to_theme().'/css/photo_gallery.css', $type = 'theme', $media = 'all', $preprocess = TRUE);
drupal_add_css($path = path_to_theme().'/css/news.css', $type = 'theme', $media = 'all', $preprocess = TRUE);
drupal_add_css($path = path_to_theme().'/css/home.css', $type = 'theme', $media = 'all', TRUE);
drupal_add_css($path = path_to_theme().'/css/ob_jquery.tabs.css', $type = 'theme', $media = 'all', TRUE);
drupal_add_css($path = path_to_theme().'/css/forms.css', $type = 'theme', $media = 'all', TRUE);
drupal_add_css($path = path_to_theme().'/css/producer.css', $type = 'theme', $media = 'all', TRUE);
drupal_add_css($path = path_to_theme().'/css/paper.css', $type = 'theme', $media = 'print', $preprocess = TRUE);


drupal_add_js($path= path_to_theme().'/js/nio_ob_themes.js');
drupal_add_js($path= path_to_theme().'/js/jquery.hoverIntent.js');
//
function _phptemplate_variables($hook, $vars = array()) {
  // dpr($hook);
  switch ($hook) {
    // Send a new variable, $logged_in, to page.tpl.php to tell us if the current user is logged in or out.
    case 'page':

      // get the currently logged in user
      global $user;

      // An anonymous user has a user id of zero.
      if ($user->uid > 0) {
        // The user is logged in.
        $vars['logged_in'] = TRUE;
      }
      else {
        // The user has logged out.
        $vars['logged_in'] = FALSE;
      }

      // this doesn't seem quite right, but was the only way to keep
      // the events results
      if ($vars['event_results']) {
        $GLOBALS['ec_results'] = $vars['event_results'];
      }

      if ($GLOBALS['ec_results']) {
        $vars['content'] = $GLOBALS['ec_results'];
      }

      // See if we're looking at a page displaying a sponsored node
      if ($nid = $vars['node']->nid) {
        $vid = ob_help_get_taxonomy_id(VOCAB_SPONSOR);
        $terms = taxonomy_node_get_terms_by_vocabulary($nid, $vid, 'vid');
        $sponsor = $terms[$vid]->name;

        $vid = VOCAB_MENU_STRUCTURE_ID;
        $terms = taxonomy_node_get_terms_by_vocabulary($nid, $vid, 'vid');
        $tid = $terms[$vid]->tid;
        if ($parent = taxonomy_get_parents($tid, 'vid')) {
          $vars['body_class'] = ob_help_get_menu_string($terms[$vid]->name);
          $vars['body_id'] = ob_help_get_menu_string($parent[$vid]->name);
        } else {
          $vars['body_id'] = ob_help_get_menu_string($terms[$vid]->name);
        }
      } else if (arg(0) != 'admin') {
        // it's not a node, get the section from the menu path
        // but don't use admin pages
        $vars['body_id'] = arg(0);
        $vars['body_class'] = arg(1);
      }

      // get the banner file
      $vars['banner'] = ob_get_banner($vars['body_id'], $vars['body_class']);

      // get the sponsors files
      $vars['nrma_sponsor_logo'] = ob_get_nrma_sponsor($vars['nrma_sponsor']);
      $vars['pag_sponsor_logo'] = ob_get_pag_sponsor($vars['pag_sponsor']);

      $vars['minor_navigation'] = '<ul>'. menu_tree(222) .'</ul>';

      $vars['footer_menus'] = '
       <ul>'. menu_tree(247) .'</ul>
       <ul>'. menu_tree(252) .'</ul>
       <ul>'. menu_tree(257) .'</ul>';

      // if we use jsTools, get rid of the css
      if (module_exists('jstools')) {
        unset($vars['css']['all']['module']['sites/all/modules/jstools/tabs/drupal-tabs.css']);
        unset($vars['css']['all']['module']['sites/all/modules/jstools/tabs/tabs.css']);
      }

      // keep menu open on event search results
      // there's probably a better way to do this...
      if (arg(0) == 'whats-on' && arg(1) == 'events' && arg(2) == 'search') {
        $menu_path = array(array('path' => 'whats-on'), array('path' => 'events'));
        menu_set_location($menu_path);
      }

      // This section lets us modify whole page layouts depending on node type
      $node = $vars['node'];
      switch ($node->type) {
        case CONTENT_TYPE_BSO:
          $vars = process_bso_page($node, $vars);
          break;
      }


      break;

    case 'node':
      // get the currently logged in user
      global $user;

      // set a new $is_admin variable
      // this is determined by looking at the currently logged in user and seeing if they are in the role 'admin'
      $vars['is_admin'] = in_array('admin', $user->roles);

      $node_classes = array('node');
      if ($vars['sticky']) {
        $node_classes[] = 'sticky';
      }
      if (!$vars['node']->status) {
        $node_classes[] = 'node-unpublished';
      }
      $node_classes[] = 'ntype-'. nio_id_safe($vars['node']->type);
      // implode with spaces
      $vars['node_classes'] = implode(' ', $node_classes);

      // process variables for different node types
      $node = $vars['node'];
      switch ($node->type) {
        case CONTENT_TYPE_OB_PAGE:
          $vars = process_ob_std_page($node);
          break;

        case CONTENT_TYPE_BUSINESS:
          $vars = process_business_listing($node);
          break;

        case CONTENT_TYPE_EVENT:
          $vars = process_event($node, $vars);
          break;

        case CONTENT_TYPE_GALLERY_IMAGE:
          $vars = process_user_contrib_image($node, $vars);
          break;

        case CONTENT_TYPE_BSO:
          $vars = process_bso($node, $vars);
          break;
      }

      break;

    case 'comment':
      // we load the node object that the current comment is attached to
      $node = node_load($vars['comment']->nid);
      // if the author of this comment is equal to the author of the node, we set a variable
      // then in our theme we can theme this comment differently to stand out
      $vars['author_comment'] = $vars['comment']->uid == $node->uid ? TRUE : FALSE;
      break;

      break;
  }

  return $vars;
}

/*
 *  Finds a banner for the current section
 */
function ob_get_banner($body_id, $body_class) {
  // try the secondary first - look for a gif
  $banner = path_to_theme() .'/images/540_'. $body_id .'_'. $body_class .'_ban.gif';
  if (file_exists($banner)) {
    return $banner;
  }

  // if not a gif then a jpg
  $banner = path_to_theme() .'/images/540_'. $body_id .'_'. $body_class .'_ban.jpg';
  if (file_exists($banner)) {
    return $banner;
  }

  // otherwise the primary - first the gif
  $banner = path_to_theme() .'/images/540_'. $body_id .'_ban.gif';
  if (file_exists($banner)) {
    return $banner;
  }

  // then the jpg
  $banner = path_to_theme() .'/images/540_'. $body_id .'_ban.jpg';
  if (file_exists($banner)) {
    return $banner;
  }
}

// NRMA & Arts Qld sponsor logos - must be a better way to do this
function ob_get_nrma_sponsor($nrma_sponsor) {
	$nrma_sponsor_logo = path_to_theme() .'/images/sponsor_nrma.png';
  return $nrma_sponsor_logo;
  }

function ob_get_pag_sponsor($pag_sponsor) {	
	$pag_sponsor_logo = path_to_theme() .'/images/sponsor_artsqld.png';
 	return $pag_sponsor_logo;
 	}

function ob_get_teaser($node, $hp = FALSE, $txt = NULL, $length = 600) {
  if ($hp && $node->field_alt_teaser_homepage[0]['value']) {
    return $node->field_alt_teaser_homepage[0]['value'];
  }
  else if ($node->field_alt_default_teaser[0]['value']) {
    return $node->field_alt_default_teaser[0]['value'];
  }
  else if ($txt == NULL) {
    if ($length != 600) variable_set('teaser_length', $length);
    $txt = filter_xss(node_teaser($node->teaser), $allowed_tags = array('a', 'em', 'strong'));
    if ($length != 600) variable_set('teaser_length', 600);
    return $txt;
  }
  else {
    if ($length != 600) variable_set('teaser_length', $length);
    $txt = filter_xss(node_teaser($txt), $allowed_tags = array('a', 'em', 'strong'));
    if ($length != 600) variable_set('teaser_length', 600);
    return $txt;
  }
}

/*
 *  Returns how long ago from now a timestamp is
 */
function ob_ago($timestamp){
  $difference = time() - $timestamp;

  if($difference < 60) {
    return $difference." seconds ago";
  }
  else {
    $difference = round($difference / 60);
    if($difference < 60) {
      return $difference." minutes ago";
    }
    else {
      $difference = round($difference / 60);
      if($difference < 24) {
        $hoursnow = date('G');
        $diff = $hoursnow - $difference;
        if($diff < 0) return 'last night';
        $h = date('G', strtotime("-$difference hours"));
        if($h < 12) return 'this morning';
        if($h < 18) return 'this afternoon';
        if($h < 24) return 'this evening';
          return $difference." hours ago";
       }
       else {
          $difference = round($difference / 24);
          if($difference < 2) return 'yesterday';
          return $difference." days ago";
       }
     }
  }
}

function nio_id_safe($string) {
  if (is_numeric($string{0})) {
    // if the first character is numeric, add 'n' in front
    $string = 'n'. $string;
  }
  return strtolower(preg_replace('/[^a-zA-Z0-9-]+/', '-', $string));
}

function phptemplate_search_theme_form($form) {
  return _phptemplate_callback('ob-searchform', array('form' => $form));
}

function phptemplate_menu_tree($pid = 1) {
  if ($tree = phptemplate_menu_tree_improved($pid)) {
    return "\n<ul class=\"menu\">\n". $tree ."</ul>\n";
  }
}

function phptemplate_menu_tree_improved($pid = 1) {
  $menu = menu_get_menu();
  $output = '';

  if (isset($menu['visible'][$pid]) && $menu['visible'][$pid]['children']) {
    $num_children = count($menu['visible'][$pid]['children']);
    for ($i=0; $i < $num_children; ++$i) {
      $mid = $menu['visible'][$pid]['children'][$i];
      $type = isset($menu['visible'][$mid]['type']) ? $menu['visible'][$mid]['type'] : NULL;
      $children = isset($menu['visible'][$mid]['children']) ? $menu['visible'][$mid]['children'] : NULL;
      $extraclass = $i == 0 ? 'first' : ($i == $num_children-1 ? 'last' : '');
      $output .= theme('menu_item', $mid, menu_in_active_trail($mid) || ($type & MENU_EXPANDED) ? theme('menu_tree', $mid) : '', count($children) == 0, $extraclass);
    }
  }

  return $output;
}

function phptemplate_menu_item($mid, $children = '', $leaf = TRUE, $extraclass = '') {
  return '  <li class="'. ($leaf ? 'leaf' : ($children ? 'expanded' : 'collapsed')) . ($extraclass ? ' ' . $extraclass : '') . '">'. menu_item_link($mid, TRUE, $extraclass) . $children ."</li>\n";
}

function nio_menu_item($mid, $children = '', $leaf = TRUE) {
  $output = '<li';
  if ($children || $extraclass) {
    $output .= ' class="';
    if ($expanded) $output .= 'expanded ';
    if ($extraclass) $output .= $extraclass;
    $output .= '"';
  }
  $output .= '>';
  $output .= menu_item_link($mid) . $children ."</li>\n";
  return $output;
}

function phptemplate_comment_wrapper($content, $type = null) {
  static $node_type;
  if (isset($type)) $node_type = $type;

  if (!$content || $node_type == 'forum') {
    return "<div id=\"comments\">\n  ". $content . "\n</div>\n";
  }
  else {
    return "<div id=\"comments\">\n  <h2 class=\"comments\">". t('Comments') ."</h2>\n". $content ."\n</div> <!-- /#comments -->\n\n";
  }
}

function phptemplate_ob_nav_links($links, $attributes = array('class' => 'links')) {
  $output = '';

  if (count($links) > 0) {
    $output = '<ul'. drupal_attributes($attributes) .'>';

    $num_links = count($links);
    $i = 1;

    foreach ($links as $key => $link) {
      $class = '';

      // Automatically add a class to each link and also to each LI
      if (isset($link['attributes']) && isset($link['attributes']['class'])) {
        $link['attributes']['class'] .= ' ' . $key;
        $class = $key;
      }
      else {
        $link['attributes']['class'] = $key;
        $class = $key;
      }

      // Add first and last classes to the list of links to help out themers.
      $extra_class = '';
      if ($i == 1) {
        $extra_class .= 'first ';
      }
      if ($i == $num_links) {
        $extra_class .= 'last ';
      }
      $output .= '<li class="'. $extra_class . $class .'">';

      // Is the title HTML?
      $html = isset($link['html']) && $link['html'];

      // Initialize fragment and query variables.
      $link['query'] = isset($link['query']) ? $link['query'] : NULL;
      $link['fragment'] = isset($link['fragment']) ? $link['fragment'] : NULL;

      if (isset($link['href'])) {
        $output .= l('<span>'.$link['title'].'</span>', $link['href'], $link['attributes'], $link['query'], $link['fragment'], FALSE, TRUE);
      }
      else if ($link['title']) {
        //Some links are actually not links, but we wrap these in <span> for adding title and class attributes
        if (!$html) {
          $link['title'] = check_plain($link['title']);
        }
        $output .= '<span'. drupal_attributes($link['attributes']) .'>'. $link['title'] .'</span>';
      }

      $i++;
      $output .= "</li>\n";
    }

    $output .= '</ul>';
  }

  return $output;
}

switch($block->region) {
  case 'foot_ad' :
    include 'block-landing.tpl.php';
    break;
  default :
    //default theme
    break;
}

//function mysql_date_to_timestamp($mysql) {
//  $datear1 = explode('T', $mysql);
//  $datear2 = explode('-', $datear1[0]);
//  $datear3 = explode(':', $datear1[1]);
//  $stamp = mktime($datear3[0], $datear3[1], $datear3[2], $datear2[1], $datear2[2], $datear2[0]);
//  return $stamp;
//}

/*
 * A custom implementation of the nodequeue method
 */
function ob_nodequeue_nodes($qid, $backward = true, $teaser = true, $links = true, $from = 0, $count = 0, $use_theme = false) {
  $orderby = ($backward ? "DESC" : "ASC");
  $sql = db_rewrite_sql("SELECT n.nid FROM {node} n INNER JOIN {nodequeue_nodes} nn ON n.nid = nn.nid WHERE nn.qid = %d AND n.status = 1 ORDER BY nn.position $orderby");
  if ($count) {
    $result = db_query_range($sql, $qid, $from, $count);
  }
  else {
    $result = db_query($sql, $qid);
  }

  if ($use_theme) {
    while ($nid = db_fetch_object($result)) {
      $node = node_load($nid->nid);
      $output .= theme($use_theme, $node);
    }
  }
  else {
    while ($nid = db_fetch_object($result)) {
      $node = node_load($nid->nid);
      $output .= node_view($node, $teaser, false, $links);
    }
  }
  return $output;
}

/*
 * A custom implementation of the fetch random nodequeue method
 */
function ob_nodequeue_fetch_random($qid, $teaser = true, $links = true, $num = 1, $use_theme = false) {
  $count = db_result(db_query("SELECT count(*) FROM {nodequeue_nodes} WHERE qid = %d", $qid));
  $i = 0;
  $e = 0; // this is a threshold counter to not end up in an endless loop
  $m = 50;
  $output = '';
  $used = array();
  while ($i < $num) {
    $rand = rand(0, $count - 1);
    if (!in_array($rand, $used)) {
      $output .= ob_nodequeue_nodes($qid, true, $teaser, $links, $rand, 1, $use_theme);
      $used[] = $rand;
      $i++;
    }
    $e++;
    if ($e >= $m) break;
  }
  return $output;
}

function theme_homepage_feature($node) {
  $vars = array(
    'title_link' => l($node->title, 'node/'. $node->nid, array('class' => 'ob-title-link')),
    'title'      => $node->title,
    'href'       => 'node/'. $node->nid,
    'txt'        => ob_get_teaser($node, $hp = TRUE, NULL, $length = 200),
    'nid'        => $node->nid,
  );
  
  if ($node->type == CONTENT_TYPE_EVENT) $vars['date'] = format_date(mysql_date_to_timestamp($node->field_event_date[0]['value']), 'custom', 'j F Y');

  // get image
  switch ($node->type) {
    case CONTENT_TYPE_EVENT:
      $vars['img'] = $node->field_event_image[0]['filepath'];
      break;

    case CONTENT_TYPE_OB_PAGE:
      $vars['img'] = $node->field_main_picture[0]['filepath'];
      break;
  }
  return _phptemplate_callback('homepage_feature', $vars);
}

function theme_homepage_recommended($node) {
  $vars = array(
    'title_link' => l($node->title, 'node/'. $node->nid, array('class' => 'ob-title-link')),
    'title'      => $node->title,
    'href'       => 'node/'. $node->nid,
    'txt'        => ob_get_teaser($node, $hp = TRUE, NULL, $length = 100),
   // 'date'       => format_date(mysql_date_to_timestamp($node->field_event_date[0]['value']), 'custom', 'j F Y'),
    'nid'        => $node->nid,
  );
if ($node->type == CONTENT_TYPE_EVENT) $vars['date'] = format_date(mysql_date_to_timestamp($node->field_event_date[0]['value']), 'custom', 'j F Y');

  // get image
  switch ($node->type) {
    case CONTENT_TYPE_EVENT:
      $vars['img'] = $node->field_event_image[0]['filepath'];
      break;

    case CONTENT_TYPE_OB_PAGE:
      $vars['img'] = $node->field_main_picture[0]['filepath'];
      break;
  }
  return _phptemplate_callback('homepage_recommended', $vars);
}

function theme_homepage_yourimage($node) {
  $vars = array(
    // we'll need to make this more compatible for different node types
    'img'        => $node->field_user_contrib_image[0]['filepath'],
    'title_link' => l($node->title, 'node/'. $node->nid, array('class' => 'ob-title-link')),
    'title'      => $node->title,
    'href'       => 'node/'. $node->nid,
    'txt'        => $node->teaser,
    //'date'       => format_date(mysql_date_to_timestamp($node->field_event_date[0]['value']), 'custom', 'j F Y'),
  );
  return _phptemplate_callback('homepage_yourimage', $vars);
}

function theme_homepage_whatsnew($node) {
  $vars = array(
    'title_link' => l($node->title, 'node/'. $node->nid, array('class' => 'ob-title-link')),
    'txt'        => ob_get_teaser($node, $hp = TRUE),
    'date'       => ob_ago($node->changed),
	'node_id'    => $node->nid,
  );
  return _phptemplate_callback('homepage_whatsnew', $vars);
}


return $output;
//}

  $vars['ob_tvmovies_menu'] = menu_tree(get_menu_id('ob_tvmovies'));
  $node = $vars['node'];

  switch ($hook) {
	  case 'page': // For the main page
	    //dpr($vars['head']);
		if ((arg(1) == 'movies' || strpos($vars[node]->path, 'whats-on/movies') !== false)) {
	      $vars['ob_custom_header'] = '<div id="ob-heading-movies"><h1 class="hideThis">MOVIES</h1><img src="/sites/all/themes/ourbrisbane/nio/images/496x95_movies_hd.jpg" alt="Movie banner image" /></div>';
		  $vars['title_element']    = 'Movie session times, reviews, news and Hollywood gossip';
		  $vars['meta_keywords']    = 'Movies,cinema,theatre,session times,bcc,movie reviews,hollywood,gossip,interviews';
	      $vars['meta_description'] = 'Movie and session times for all Brisbane cinemas, movie reviews, interviews, news and celebrity gossip.';
			  
		  /**********************************************
		  * Movie list
		  **********************************************/
		  if ($node->path == 'whats-on/movies/titles/all') {
			$vars['title_element']    = 'Movie news and reviews - recent releases playing at Brisbane cinemas';
			$vars['meta_description'] = 'Information and reviews for all movies playing at cinemas across Brisbane right now.';
		  }
			  
		  /**********************************************
		  * Movie detail
		  **********************************************/
		  if ($node->type == 'movie') {
		    $vars = array_merge($vars, prepare_movie($node, 'page'));
		    $vars['content'] = _phptemplate_callback('detail_movie', $vars);
		  }
			
      /**********************************************
		  * News detail
      **********************************************/
		  elseif ($node->type == 'movietv_news') {
		    $vars['movie_image'] = ob_get_movie_image($node->field_media_filename[0]['value'], '', '300x100_movie_generic.jpg');
			  $vars['content'] = _phptemplate_callback('detail_news', $vars);
			  $vars['title_element']    = 'Movie news: ' . $node->title;
			  $vars['meta_keywords']    = 'Movies,news,gossip,movie industry,interviews,actors,directors,studios,coming soon';
	      $vars['meta_description'] = 'Movie news, interviews and gossip: ' . $node->title;
		  }  
		  /**********************************************
		  * All other
		  **********************************************/
		  else {
			  $vars['content'] = _phptemplate_callback('2_col_content', $vars);
		  }
			  
		  /**********************************************
			* Session times
		  **********************************************/
		  if (arg(2) == 'sessiontimes') {
			  $vars['title_element']    = 'Movie session times for all cinemas in Brisbane';
			  $vars['meta_keywords']    = 'Movies,session times,cinemas,bcc,palace,dendy,amc,megaplex,cineplex,gold class';
			  $vars['meta_description'] = 'Find up-to-date movie session times for any cinema in Brisbane.';
		  }
		}
	    
		if (arg(1) == 'tv' || strpos($node->path, 'whats-on/tv') !== false) {
				$vars['ob_custom_header'] = '<div id="ob-heading-tv"><h1 class="hideThis">TV</h1><img src="/sites/all/themes/ourbrisbane/nio/images/430x110_TV_hd.jpg" alt="TV Banner image" /></div>';
				$vars['title_element'] = 'TV guide - Television highlights and program schedules, news and gossip';
			    $vars['meta_keywords'] = 'TV,television,abc,sbs,seven,nine ,ten,bris31,guide,programs,programmes,shows,free-to-air,pay tv,cable,foxtel,austar,optus,digital,epg,program guide';
		        $vars['meta_description'] = 'Comprehensive guide to TV in Brisbane including full program guide for free-to-air and pay TV, highlights and industry news and gossip.';
	            
		        if (arg(2) == 'guide') $vars['title_element'] = 'TV guide - Television show times and information';
		        
			    if (arg(3) == 'results' || arg(2) == 'tonight' || arg(2) == 'now') {
					if (arg(3) == 'results') $vars['title'] = 'TV search results';
					ob_set_inline_css('div#ob-heading-tv { width:auto; margin-right:300px !important; }');
			        $vars['ob_custom_header'] = '<div id="tv-results-container"><div id="tv-results"><div id="top-right-content">' . $vars['content_misc'] . '</div><div id="ob-heading-tv"><h1 class="hideThis">TV</h1><img src="/sites/all/themes/ourbrisbane/nio/images/430x110_TV_hd.jpg" alt="TV Banner image" /></div><h2>' . $vars['title'] . '</h2><br /><div class="view-content-ob-movie-list" style="margin-right:300px;">&nbsp;</div>';
					$vars['sidebar_right'] = FALSE;
					$vars['title'] = NULL;
					$vars['content'] = _phptemplate_callback('2_col_header', $vars);
					
					if (arg(3) == 'results') $vars['title_element'] = 'TV guide search results';
					if (arg(2) == 'tonight') $vars['title_element'] = 'Tonight\'s TV';
					if (arg(2) == 'now') $vars['title_element'] = ' What\'s On TV right now';
				    $vars['meta_description'] = 'Comprehensive Brisbane TV Guide for all free-to-air and pay channels.';
				
				/**********************************************
				* News list
				**********************************************/
				} elseif (arg(2) == 'news' && arg(3) == '') {
				  $vars['title_element']    = 'TV news and celebrity gossip';
			      $vars['meta_keywords']    = 'TV,television,abc,sbs,seven,nine,ten,bris31,guide,programs,programmes,shows,gossip,hollywood,celebrity';
		          $vars['meta_description'] = 'A roundup of the best and worst in TV and entertainment news and gossip from Australia and around the world.';
				
				/**********************************************
				* News detail
				**********************************************/
				} elseif ($node->type == 'movietv_news') {
				  $vars['movie_image'] = ob_get_movie_image($node->field_media_filename[0]['value'], '', '300x100_tv_generic.jpg');
				  $vars['title_element']    = 'TV news and celebrity gossip: ' . $node->title;
				  $vars['content'] = _phptemplate_callback('detail_news', $vars);
		        
				/**********************************************
				* Highlight detail
				**********************************************/
				} elseif ($node->field_highlight[0]['value'] == 1) {
				  $vars['movie_image'] = ob_get_movie_image($node->field_media_filename[0]['value'], '', '300x100_tv_generic.jpg');
				  $vars['title_element']    = 'TV highlights: ' . $node->title;
				  $vars['content'] = _phptemplate_callback('detail_news', $vars);
				 
				/**********************************************
				* All other
				**********************************************/
				} else {
				  $vars['content'] = _phptemplate_callback('2_col_content', $vars);
				}
			}
		
       if ((arg(1) == 'events' || strpos($vars[node]->path, 'whats-on/events') !== false)) {
	      $vars['ob_custom_header'] = '<div id="ob-heading-movies"><h1 class="hideThis">EVENTS</h1><img src="/sites/all/themes/ourbrisbane/nio/images/496x95_movies_hd.jpg" alt="Movie banner image" /></div>';
		    $vars['title_element']    = 'Events date and information';
		    $vars['meta_keywords']    = 'Events';
	      $vars['meta_description'] = 'Dates and information for all Brisbane events.';
			  
		  /**********************************************
		  * Event list
		  **********************************************/
		  if ($node->path == 'whats-on/events/titles/all') {
			  $vars['title_element']    = 'Events - events happening around Brisbane';
			  $vars['meta_description'] = 'Information and dates for events happening across Brisbane right now.';
		  }
			  
		  /**********************************************
		  * Event detail
		  **********************************************/
		  if ($node->type == 'event') {
		    $vars = array_merge($vars, prepare_event($node, 'page'));
		    $vars['content'] = _phptemplate_callback('detail_event', $vars);
		  }
			  
		  /**********************************************
		  * All other
		  **********************************************/
		  else {
			$vars['content'] = _phptemplate_callback('2_col_content_events', $vars);
		  }
			  
		}
		
		// Page code has finished, last calls
		$vars['ob_inline_css'] = ob_prepare_inline_css(ob_set_inline_css());
		break;
		  
	  case 'node':
	    
	    switch ($node->type) {
	      case 'movietv_news':
        $vars = array(
	          'description' => $node->content['body']['#value']
	        );
	        break;
	        
	      case 'movie':
	        $vars = prepare_movie($node, 'node');
	        break;
	        
	      case 'tv':
	        $vars = prepare_tv($node, 'node');
	        break;
	      
	      case 'event':
	        $vars = prepare_event($node, 'node');
	        break;

	    }
	    break;

  }
  return $vars;
//}

function ob_get_movie_image($image, $size = '', $alt) {
  if ($image == '') {
    //if ($size == 'thumb') $image_path = path_to_theme() . '/images/' . $alt;
    //else $image_path = path_to_theme() . '/images/350x100_movie_generic.jpg';
  } elseif ($size == 'thumb') {
    $image_path = TVMOVIES_IMAGE_THUMB_DIRECTORY . $image;
  } else {
    $image_path = TVMOVIES_IMAGE_MEDIUM_DIRECTORY . $image;
  }
  if (!file_exists($image_path)) $image_path = path_to_theme() . '/images/' . $alt;

  return $image_path;
}

/**
 * Set inline CSS
 * 
 * Gathers inline CSS during page
 * creation in a static variable
 * 
 * @param $data
 *   A new snippet of CSS to be included in the
 *   individual page
 * @return 
 *   All gathered CSS or FALSE
 */
function ob_set_inline_css($data = NULL) {
  static $ob_stored_inline_css;
  
  if (!is_null($data)) {
    $ob_stored_inline_css .= $data ."\n";
  }
  return $ob_stored_inline_css; 
}

/**
 * Prepare inline CSS
 * 
 * Wraps the custom ob CSS into style sheet 
 * and CDATA tags for embedding in the page
 * 
 * @param $css
 *   The CSS gathered across the page cycle
 * @return 
 *   The complete style block or FALSE
 */
function ob_prepare_inline_css($css = FALSE) {
  $output = '';
  if ($css) {
    $output .= '<style type="text/css">/* <![CDATA[ */'."\n";
    $output .= $css;
    $output .= '/* ]]> */</style>'."\n";
    return $output;
  }
  else return false;
}

/**
 * Prepare movie detail data
 * 
 * @param $node
 *   The movie node object
 * @param $op
 *   The operation required (page or node)
 * @return 
 *   The template vars
 */
function prepare_movie($node, $op) {
  
  switch ($op) {
    case 'node':
	  $tax_terms = taxonomy_node_get_terms($node->nid);
	  $tax_list = '';
	  if (count($tax_terms) > 0) {
	    $tax_list .= "<ul>\n";
	    foreach($tax_terms as $v) $tax_list .= '<li>' . $v->name . '</li>';
	    $tax_list .= "</ul>\n";
	  }
	  
      $vars = array(
	    'description'   => $node->field_short_description[0]['value'],
	    'tax_terms'     => $tax_list,
	    'release_date'  => mysql_date_to_timestamp($node->field_movie_release_date[0]['value']),
	    'title_id'      => $node->field_title_id[0]['value'],
	  );
	  unset($tax_list);
	  break;
	  
    case 'page':
      $vars = array(
      'movie_image' => ob_get_movie_image($node->field_media_filename[0]['value'], '', '300x100_movie_generic.jpg'),
      'title_element' => 'Movie review: ' . $node->title,
      'meta_keywords' => 'Movies,cinema,theatre,' . $node->title . ',' . 
		  $node->field_main_cast[0]['value'] .
		  ',' . $node->field_director[0]['value'] . ',review,release',
      'meta_description' => 'Information and review of the movie \'' . $node->title . '\' playing at cinemas in Brisbane right now.',
	    'director'      => $node->field_director[0]['value'],
	    'main_cast'     => $node->field_main_cast[0]['value'],
	    'duration'      => $node->field_duration[0]['value'],
	    'imdb_id'       => $node->field_imdb_id[0]['value'],
	    'description'   => $node->field_short_description[0]['value'],
	    'tax_terms'     => $tax_list,
	    'release_date'  => mysql_date_to_timestamp($node->field_movie_release_date[0]['value']),
	    'title_id'      => $node->field_title_id[0]['value'],
	  );
	  $vars['official_site'] = ($node->field_url_0[0]['value']) ? l('Link', $node->field_url_0[0]['value']) : FALSE;
      break;
  }

  return $vars;
}

/**
 * Prepare TV detail data
 * 
 * @param $node
 *   The tv node object
 * @param $op
 *   The operation required (page or node)
 * @return 
 *   The template vars
 */
function prepare_tv($node, $op) {

  switch ($op) {
    case 'node':
	  $vars = array(
	    'channel' => $node->field_channel_abbrev[0]['value'],
	    'title' => $node->title,
	    'episode_name' => $node->field_episode_name[0]['value'],
	    'tax_terms' => taxonomy_node_get_terms($node->nid),
	    'tax_links' => taxonomy_link('taxonomy terms', $node),
	    'year_released' => $node->field_year_released[0]['value'],
	    'consumer_advice' => $node->field_consumer_advice[0]['value'],
	    'duration' => t("!time minutes", array('!time' => $node->field_duration[0]['value'])),
	    'director' => $node->field_director[0]['value'],
	     'description' => strip_tags($node->content['body']['#value']),
	     'cast' => $node->field_main_cast[0]['value'],
	  );
		
	  $vars['start_timestamp'] = mysql_date_to_timestamp($node->field_program_date[0]['value'] ."T". $node->field_program_time[0]['value'].":00");
	  // $vars['start_timestamp'] = $node->field_program_datetime[0]['value'];
	  // $vars['end_timestamp'] = (int) $node->field_duration[0]['value'] * 60 + $vars['start_timestamp'];
	  $vars['start_date'] = format_date($vars['start_timestamp'], 'large');
	  // $vars['start_time'] = date("g:i a", $vars['start_timestamp']);
	  // $vars['end_date'] = date("l, j F, Y", $vars['end_timestamp']);
	  // $vars['end_time'] = date("g:i a", $vars['end_timestamp']);
	  $tmp = array();
	  if ($node->field_country[0]['value']) {
	    $tmp[] = $node->field_country[0]['value'];
	   }
	   if ($node->field_language[0]['value']) {
	    $tmp[] = $node->field_language[0]['value'];
	  }
	  if (count($tmp > 0)) {
	    $vars['country'] = implode("/", $tmp);
	  }
	  unset($tmp);
	  foreach ($vars['tax_terms'] as $v) $tmp[] = $v->name;
	  $vars['tax_terms'] = implode(", ", $tmp);
	  unset($tmp);
	  foreach ($vars['tax_links'] as $v) $tmp[] = l($v['title'], $v['href']);
	  $vars['tax_links'] = implode(", ", $tmp);
	  unset($tmp);
	  // Set these vars if called using ajax (i.e. jTip)
	  if (stristr(arg(2), "xml")) {
	    $vars['xml'] = 1;
	    $vars['page'] = 1;
	    $vars['description'] = $node->body;
	  }
	  break;
	  
    case 'page':
      // Not implemented
      break;
  }
  
  return $vars;
}

/**
 * Prepare event detail data
 * 
 * @param $node
 *   The event node object
 * @param $op
 *   The operation required (page or node)
 * @return 
 *   The template vars
 */
function prepare_event($node, $op) {
  
  switch ($op) {
    case 'node':
	  $tax_terms = taxonomy_node_get_terms($node->nid);
	  $tax_list = '';
	  if (count($tax_terms) > 0) {
	    $tax_list .= "<ul>\n";
	    foreach($tax_terms as $v) $tax_list .= '<li>' . $v->name . '</li>';
	    $tax_list .= "</ul>\n";
	  }
	  
      $vars = array(
	    'tax_terms'     => $tax_list,
	    /*'release_date'  => $node->field_release_date[0]['value'],
	    'title_id'      => $node->field_title_id[0]['value'],*/
	  );
	  unset($tax_list);
	  break;
	  
    case 'page':
      $vars = array(
		/*'movie_image' => ob_get_movie_image($node->field_media_filename[0]['value'], '', '300x100_movie_generic.jpg'),
		'title_element' => 'Movie review: ' . $node->title,
		'meta_keywords' => 'Movies,cinema,theatre,' . $node->title . ',' . 
		  $node->field_main_cast[0]['value'] .
		  ',' . $node->field_director[0]['value'] . ',review,release',
		'meta_description' => 'Information and review of the movie \'' . $node->title . '\' playing at cinemas in Brisbane right now.',
	    'director'      => $node->field_director[0]['value'],
	    'main_cast'     => $node->field_main_cast[0]['value'],
	    'duration'      => $node->field_duration[0]['value'],
	    'imdb_id'       => $node->field_imdb_id[0]['value'],
	    'description'   => $node->field_short_description[0]['value'],*/
	    'tax_terms'     => $tax_list,
	    /*'release_date'  => $node->field_release_date[0]['value'],
	    'title_id'      => $node->field_title_id[0]['value'],*/
	  );
	  /*$vars['official_site'] = ($node->field_url_0[0]['value']) ? l('Link', $node->field_url_0[0]['value']) : FALSE;*/
      break;
  }

  return $vars;
}


/**
 * Gets the ID of a menu by supplying the name
 * @param menu name
 * @return menu id
 */
function get_menu_id($menu_name) {
	$menus = menu_get_root_menus();
	foreach ($menus as $id => $name) {
		if (strtolower($name) == strtolower($menu_name)): return $id; endif;
	}
}

/**
 *  Reset the css file array
 */
function ob_reset_css($css) {
  $new_css = array();
  $theme_css = $css['all']['theme'];
  $new_css['all']['theme'] = $theme_css;
  return $new_css;
}

function mysql_date_to_timestamp($mysql) {
  $datear1 = explode('T', $mysql);
  $datear2 = explode('-', $datear1[0]);
  $datear3 = explode(':', $datear1[1]);
  $stamp = mktime($datear3[0], $datear3[1], $datear3[2], $datear2[1], $datear2[2], $datear2[0]);
  return $stamp;
}

/**********************************************
* Override theme functions
**********************************************/

/**
 * Formats a list of standard OB teasers
 * @param teasers An array of teaser objects
 * @return output A XHTML definition list
 */
function theme_ob_teasers($teasers, $date_prefix = '') {
  $output = '<dl class="ob-teaser-list">';
  foreach ($teasers as $teaser) {
   

    $url = url('node/' . $teaser->nid);
    $output .= ' <dt><a href="' . $url . '">';
    if ($path = ob_get_movie_image($teaser->image, 'thumb', $teaser->image_alt)) {
      $output .= theme('image', $path, 'Thumbnail for '. $teaser->title);
    }
    $output .= '<span>'. $teaser->title .'</span></a></dt>';
    $output .= '<dd>';
    if ($teaser->program_datetime) {
      if (strrpos($teaser->program_datetime, "T") === FALSE || strrpos($teaser->program_datetime, "T00:00:00") == TRUE) {
        $output .= '<div class="ob-byline">'. $date_prefix . format_date(mysql_date_to_timestamp($teaser->program_datetime), 'custom', 'l, F j, Y') .'</div>';
      }
      else {
        $output .= '<div class="ob-byline">'. $date_prefix . format_date(mysql_date_to_timestamp($teaser->program_datetime), 'large') .'</div>';
      }
    }
    $output .= $teaser->description .'</dd>';
  }
  $output .= '</dl>';
  return $output;
}

function theme_ob_teaser_slider($teasers) {
  drupal_add_js(path_to_theme() . '/js/jquery.accessible-news-slider.js',1);
  drupal_add_js('$(function() {$(".top_stories").slideNews();});','inline');
  
  $output = '
	<div class="news_slider top_stories">
  		<div class="messaging"> Please Note: You may have disabled JavaScript and/or CSS. Although this news content will be accessible, certain functionality is unavailable. </div>
  		<a href="" class="skip" title="If you have JavaScript turned off, you will be unable to skip to the news content.">Skip to news content.</a>
  		<div class="prev"> <a href="#">Previous</a> </div>
  		<div class="next"> <a href="#">Next</a> </div>
  		<div class="news_items"> <a name=""></a>
		<div class="container fl">
	';
  
  foreach ($teasers as $teaser) {
    $url = url('node/' . $teaser->nid);
    $output .= '<div class="item fl"><a href="' . $url . '">';
    if ($path = ob_get_movie_image($teaser->image, 'thumb')) {
      $output .= theme('image', $path, 'Thumbnail for ' . $teaser->title);
    }
    $output .= '<span>' . $teaser->title . '</span></a>';
    $output .= ' <p>' . $teaser->description . '</p>';
    $output .= '</div>';
  }
  $output .= '</div></div></div>';
  return $output;
}