type == 'timeline' && $view_mode == 'full') { $node->content['timeline']['#markup'] = timelinejs($node->nid); } } /** * 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, ); 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'), ), ); } /** * 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(); } /** * Menu callback. */ function timelinejs_json($nid) { // 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); } foreach ($items as $event) { $output[] = theme('timelinejs_json_event', array('event' => $event)); $events = implode(',', $output); } $text = $media = NULL; $headline = $timeline->title; $date = $timeline->field_date['und']['0']['value']; print theme('timelinejs_json', array( 'headline' => $headline, 'date' => $date, 'text' => $text, 'media' => $media, 'events' => $events, )); # Avoid themable output. exit; } /** * Menu callback. * * @todo * Check for a timeline.css in the current theme instead of using a hardcoded value. * Dimensions should be configurable. */ function timelinejs($nid) { global $language; return theme('timelinejs', array( 'width' => '960px', 'height' => '500px', 'source' => '/timelinejs/json/'. (int) $nid, 'css' => '/sites/boletim/themes/boletimclean/timeline.css', 'lang' => '/sites/all/libraries/timelinejs/compiled/js/locale/'. $language->language .'.js', )); }