From 563f9f6ff1f294055b2fee95e5aee69905b2ff90 Mon Sep 17 00:00:00 2001 From: Silvio Date: Tue, 14 Aug 2012 13:37:43 -0300 Subject: Adding print templates --- timelinejs.module | 39 +++++++++++++++++++++++++++++++++------ 1 file changed, 33 insertions(+), 6 deletions(-) (limited to 'timelinejs.module') diff --git a/timelinejs.module b/timelinejs.module index 731d459..9ca1985 100644 --- a/timelinejs.module +++ b/timelinejs.module @@ -60,6 +60,14 @@ function timelinejs_theme($existing, $type, $theme, $path) { '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'), + ), ); } @@ -81,9 +89,9 @@ function timelinejs_load_events($nid) { } /** - * Menu callback. + * Load all events from a timeline. */ -function timelinejs_json($nid) { +function timelinejs_fetch_items($nid, $format = 'json') { // Sanitization and basic data. $nid = (int) $nid; $timeline = node_load($nid); @@ -101,21 +109,33 @@ function timelinejs_json($nid) { } foreach ($items as $event) { - $output[] = theme('timelinejs_json_event', array('event' => $event)); - $events = implode(',', $output); + $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; - print theme('timelinejs_json', array( + 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; @@ -139,3 +159,10 @@ function timelinejs($nid, $width = '960px', $height = '500px') { 'lang' => '/sites/all/libraries/timelinejs/compiled/js/locale/'. $language->language .'.js', )); } + +/** + * Menu callback. + */ +function timelinejs_print($nid) { + return theme('timelinejs_print', timelinejs_fetch_items($nid, 'print')); +} -- cgit v1.2.3