| 1 |
<?php
|
| 2 |
// $Id: s5_book.module,v 1.3 2008/01/12 11:04:57 greggles Exp $
|
| 3 |
|
| 4 |
/**
|
| 5 |
* Implementation of hook_help()
|
| 6 |
*/
|
| 7 |
function s5_book_help($section) {
|
| 8 |
switch ($section) {
|
| 9 |
case 'admin/modules#description':
|
| 10 |
return t('Play book pages as S5 presentations.');
|
| 11 |
}
|
| 12 |
}
|
| 13 |
|
| 14 |
/**
|
| 15 |
* Implementation of hook_link()
|
| 16 |
* Adds an s5 link to a fully displayed book page
|
| 17 |
*/
|
| 18 |
function s5_book_link($type, $node = NULL, $teaser = FALSE) {
|
| 19 |
$links = array();
|
| 20 |
if ($type == 'node' && $node->type == 'book' && !$teaser) {
|
| 21 |
$links['s5_book'] = array(
|
| 22 |
'title' => t('s5 slideshow'),
|
| 23 |
'href' => 'book/export/s5/'. $node->nid,
|
| 24 |
'attributes' => array(
|
| 25 |
'title' => t('View a slideshow of this book page and subpages.')
|
| 26 |
)
|
| 27 |
);
|
| 28 |
}
|
| 29 |
return $links;
|
| 30 |
}
|
| 31 |
|
| 32 |
/**
|
| 33 |
* Implementation of hook_menu()
|
| 34 |
*/
|
| 35 |
function s5_book_menu($may_cache) {
|
| 36 |
$items = array();
|
| 37 |
if ($may_cache) {
|
| 38 |
// plug into book module's book/export URL space
|
| 39 |
$items[] = array(
|
| 40 |
'path' => 'book/export/s5',
|
| 41 |
'title' => t('S5 presentation'),
|
| 42 |
'access' => user_access('access content'),
|
| 43 |
'type' => MENU_CALLBACK,
|
| 44 |
'callback' => 's5_book_export'
|
| 45 |
);
|
| 46 |
// add a tab to the outline editor to ease slide addition
|
| 47 |
$items[] = array(
|
| 48 |
'path' => 'admin/node/book/add',
|
| 49 |
'title' => t('add book page'),
|
| 50 |
'access' => user_access('create book pages'),
|
| 51 |
'type' => MENU_LOCAL_TASK,
|
| 52 |
'callback' => 's5_book_page_add',
|
| 53 |
'weight' => 200
|
| 54 |
);
|
| 55 |
$items[] = array(
|
| 56 |
'path' => 'admin/settings/s5_book',
|
| 57 |
'title' => t('S5 Book Settings'),
|
| 58 |
'description' => t('Enables site settings for S5 Module.'),
|
| 59 |
'callback' => 'drupal_get_form',
|
| 60 |
'callback arguments' => 's5_book_settings_form',
|
| 61 |
'access' => user_access('administer site configuration'),
|
| 62 |
);
|
| 63 |
}
|
| 64 |
return $items;
|
| 65 |
}
|
| 66 |
|
| 67 |
/**
|
| 68 |
* Admin settings.
|
| 69 |
*/
|
| 70 |
function s5_book_settings_form() {
|
| 71 |
// Allow admins to set the S5 theme to use
|
| 72 |
|
| 73 |
$path = drupal_get_path('module', 's5_book');
|
| 74 |
$files = file_scan_directory($path .'/ui', '^slides\.css$');
|
| 75 |
$themes = array();
|
| 76 |
foreach ($files as $filename => $file) {
|
| 77 |
$themes[] = str_replace('/', '', str_replace($path .'/ui', '', str_replace('slides.css', '', $filename)));
|
| 78 |
}
|
| 79 |
if (count($themes)) {
|
| 80 |
$form['s5_book_theme'] = array(
|
| 81 |
'#type' => 'select',
|
| 82 |
'#title' => t('Display of S5 Exported Books'),
|
| 83 |
'#default_value' => variable_get('s5_book_theme','default'),
|
| 84 |
'#options' => drupal_map_assoc($themes),
|
| 85 |
'#description' => t('Choose your theme from this list. You can also add more themes to S5.'),
|
| 86 |
);
|
| 87 |
|
| 88 |
}
|
| 89 |
else {
|
| 90 |
$form['s5_error_message'] = array(
|
| 91 |
'#type' => 'markup',
|
| 92 |
'#title' => t('S5 Configuration Error'),
|
| 93 |
'#value' => t('It appears that you have no S5 themes. Please make sure the module is installed correctly and that you have at least one theme.'),
|
| 94 |
);
|
| 95 |
}
|
| 96 |
return system_settings_form($form);
|
| 97 |
}
|
| 98 |
|
| 99 |
|
| 100 |
/**
|
| 101 |
* Redirector menu handler to have an easier to use UI
|
| 102 |
*/
|
| 103 |
function s5_book_page_add() {
|
| 104 |
drupal_goto('node/add/book');
|
| 105 |
}
|
| 106 |
|
| 107 |
/**
|
| 108 |
* Export menu handler
|
| 109 |
*/
|
| 110 |
function s5_book_export($nid = 0) {
|
| 111 |
global $base_url;
|
| 112 |
|
| 113 |
$nid = (int) $nid;
|
| 114 |
$depth = count(book_location($nid)) + 1;
|
| 115 |
$node = node_load($nid);
|
| 116 |
|
| 117 |
// Template variables to fill into the file
|
| 118 |
$variables = array(
|
| 119 |
'base_url' => "$base_url/",
|
| 120 |
'title' => check_plain($node->title),
|
| 121 |
'author' => check_plain($node->name),
|
| 122 |
'company' => '',
|
| 123 |
'location' => '',
|
| 124 |
'presdate' => '',
|
| 125 |
'slides' => book_recurse($nid, $depth, 's5_book_node_display', 's5_book_node_dumb'),
|
| 126 |
);
|
| 127 |
|
| 128 |
// Try to match the node body for information on these details
|
| 129 |
$searchfor = array("author", "company", "location", "presdate");
|
| 130 |
foreach ($searchfor as $class) {
|
| 131 |
if (preg_match('!class="s5-' . $class . '">([^<]+)<!', $node->body, $found)) {
|
| 132 |
$variables[$class] = $found[1];
|
| 133 |
}
|
| 134 |
}
|
| 135 |
|
| 136 |
// Return template filled in with appropriate details
|
| 137 |
theme('s5_book_export', $variables);
|
| 138 |
}
|
| 139 |
|
| 140 |
/**
|
| 141 |
* Book recursion function
|
| 142 |
* Flattens the book structure, immediately closing slides for every node
|
| 143 |
*/
|
| 144 |
function s5_book_node_display($node, $depth, $nid) {
|
| 145 |
|
| 146 |
// Let the content hook take action (taken from book.module)
|
| 147 |
if (node_hook($node, 'content')) {
|
| 148 |
$node = node_invoke($node, 'content');
|
| 149 |
}
|
| 150 |
|
| 151 |
// Enclose slide in wrapper (you can have handout info on slide)
|
| 152 |
if ($node->body) {
|
| 153 |
return '<div class="slide"><h1>'. check_plain($node->title) ."</h1>\n".
|
| 154 |
$node->body .'</div>';
|
| 155 |
}
|
| 156 |
}
|
| 157 |
|
| 158 |
/**
|
| 159 |
* Just avoid running into the default node addendum
|
| 160 |
*/
|
| 161 |
function s5_book_node_dumb($node, $depth) { }
|
| 162 |
|
| 163 |
/**
|
| 164 |
* This is a very basic S5 template, using the default S5 theme,
|
| 165 |
* requiring S5 stlye files in modules/s5/ui
|
| 166 |
*/
|
| 167 |
function theme_s5_book_export($variables) {
|
| 168 |
extract($variables);
|
| 169 |
$path = drupal_get_path('module', 's5_book');
|
| 170 |
$theme = variable_get('s5_book_theme','default');
|
| 171 |
echo <<<END_S5_PRESENTATION
|
| 172 |
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
|
| 173 |
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
| 174 |
|
| 175 |
<html xmlns="http://www.w3.org/1999/xhtml">
|
| 176 |
|
| 177 |
<head>
|
| 178 |
<title>{$title}</title>
|
| 179 |
<base href="{$base_url}" />
|
| 180 |
<meta name="generator" content="Drupal S5 Book Export" />
|
| 181 |
<meta name="version" content="S5 1.1" />
|
| 182 |
<meta name="presdate" content="{$presdate}" />
|
| 183 |
<meta name="author" content="{$author}" />
|
| 184 |
<meta name="company" content="{$company}" />
|
| 185 |
<meta name="defaultView" content="slideshow" />
|
| 186 |
<meta name="controlVis" content="hidden" />
|
| 187 |
<link rel="stylesheet" href="{$path}/ui/$theme/slides.css" type="text/css" media="projection" id="slideProj" />
|
| 188 |
<link rel="stylesheet" href="{$path}/ui/default/outline.css" type="text/css" media="screen" id="outlineStyle" />
|
| 189 |
<link rel="stylesheet" href="{$path}/ui/default/print.css" type="text/css" media="print" id="slidePrint" />
|
| 190 |
<link rel="stylesheet" href="{$path}/ui/default/opera.css" type="text/css" media="projection" id="operaFix" />
|
| 191 |
<script src="{$path}/ui/default/slides.js" type="text/javascript"></script>
|
| 192 |
</head>
|
| 193 |
<body>
|
| 194 |
|
| 195 |
<div class="layout">
|
| 196 |
<div id="controls"></div>
|
| 197 |
<div id="currentSlide"></div>
|
| 198 |
<div id="header"></div>
|
| 199 |
<div id="footer"><h1>{$location}</h1><h2>{$title}</h2></div>
|
| 200 |
</div>
|
| 201 |
|
| 202 |
<div class="presentation">
|
| 203 |
{$slides}
|
| 204 |
</div>
|
| 205 |
|
| 206 |
</body>
|
| 207 |
</html>
|
| 208 |
END_S5_PRESENTATION;
|
| 209 |
|
| 210 |
}
|