type == 'timeline' && $view_mode == 'full') { $node->content['timeline']['#markup'] = timelinejs($node->nid); $node->content['timeline']['#weight'] = -1; } } /** * Implements hook_menu() */ function timelinejs_menu() { $items['timelinejs/json'] = array( 'page callback' => 'timelinejs_json', 'access arguments' => array('access content'), 'type' => MENU_CALLBACK, ); $items['timeline'] = array( 'page callback' => 'timelinejs', 'access arguments' => array('access content'), 'type' => MENU_CALLBACK, ); $items['widgets/timeline'] = array( 'page callback' => 'timelinejs_widget', 'access arguments' => array('access content'), 'type' => MENU_CALLBACK, ); return $items; } /** * Implements hook_theme() */ function timelinejs_theme($existing, $type, $theme, $path) { return array( 'timelinejs' => array( 'template' => 'timelinejs', 'variables' => array( 'width' => NULL, 'height' => NULL, 'source' => NULL, 'start_at_end' => 'false', 'hash_bookmark' => 'true', 'css' => NULL, 'js' => '/sites/all/libraries/timelinejs/compiled/js/timeline.js', 'lang' => NULL, ), ), 'timelinejs_json' => array( 'template' => 'timelinejs_json', 'variables' => array('headline', 'date', 'text', 'media', 'events'), ), 'timelinejs_json_event' => array( 'template' => 'timelinejs_json_event', 'variables' => array('event'), ), 'timelinejs_print' => array( 'template' => 'timelinejs_print', 'variables' => array('headline', 'date', 'text', 'media', 'events'), ), 'timelinejs_print_event' => array( 'template' => 'timelinejs_print_event', 'variables' => array('event'), ), ); } /** * Get a score nid from a timeline nid. */ function timelinejs_load_events($nid) { $query = db_select('field_data_field_timeline', 't'); // Basic query. $query ->fields('t', array('entity_id')) ->condition('t.bundle', 'event') ->condition('t.field_timeline_target_id', $nid, '='); $result = $query->execute(); return $result->fetchAll(); } /** * Load all events from a timeline. */ function timelinejs_fetch_items($nid, $format = 'json') { // Sanitization and basic data. $nid = (int) $nid; $timeline = node_load($nid); $nodes = timelinejs_load_events($nid); foreach ($nodes as $node) { $items[] = node_load($node->entity_id); } if (empty($items)) { $items[0] = new stdClass(); $items[0]->field_date['und'][0]['value'] = NULL; $items[0]->title = t('No items'); $items[0]->body['und'][0]['value'] = t('Currently there are no items in this timeline.'); } foreach ($items as $event) { if (!isset($event->body['und'])) { $event->body['und'] = NULL; } $output[] = theme('timelinejs_'. $format .'_event', array('event' => $event)); if ($format == 'json') { $events = implode(',', $output); } else { $events = implode($output); } } $text = $media = NULL; $headline = $timeline->title; $date = NULL; return array( 'headline' => $headline, 'date' => $date, 'text' => $text, 'media' => $media, 'events' => $events, ); } /** * Menu callback. */ function timelinejs_json($nid) { print theme('timelinejs_json', timelinejs_fetch_items($nid)); # Avoid themable output. exit; } /** * Menu callback. */ function timelinejs_widget($nid = NULL, $width = '960px', $height = '500px') { // Check parameters. if ($nid == NULL) { print t('Page not found'); exit; } else { $node = node_load($nid); if ($node == FALSE) { print t('Page not found'); exit; } } // Format output and include timeline. $output = ''; $output .= ''; $output .= '
'; $output .= '