/[drupal]/contributions/modules/s5/s5_textfield.module
ViewVC logotype

Contents of /contributions/modules/s5/s5_textfield.module

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.1 - (show annotations) (download) (as text)
Sat Jan 12 17:37:52 2008 UTC (22 months, 2 weeks ago) by greggles
Branch: MAIN
CVS Tags: HEAD
Branch point for: DRUPAL-5, DRUPAL-6--1
File MIME type: text/x-php
feature #209076 by greggles, work on node bodies and text fields in addition to books (initial support)
1 <?php
2 // $Id: s5_textfield.module,v 1.2.2.1 2008/01/12 11:10:33 greggles Exp $
3
4 /**
5 * Implementation of hook_help()
6 */
7 function s5_textfield_help($section) {
8 switch ($section) {
9 case 'admin/modules#description':
10 return t('Play text fields broken by &lt;!--pagebreak--&gt; 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 */
19 function s5_textfield_link($type, $node = NULL, $teaser = FALSE) {
20 $links = array();
21 $node_type = in_array($node->type, variable_get('s5_textfield_node_types_enabled', array()), TRUE);
22 if ($type == 'node' && $node_type && !$teaser) {
23 $links['s5_textfield'] = array(
24 'title' => t('s5 slideshow'),
25 'href' => 'node/'. $node->nid .'/s5/',
26 'attributes' => array(
27 'title' => t('View a slideshow of this book page and subpages.')
28 )
29 );
30 }
31 return $links;
32 }
33
34 /**
35 * Implementation of hook_menu()
36 * // TODO add the field name /body | field_textname at end of node/NID/s5/whatevs
37 */
38 function s5_textfield_menu($may_cache) {
39 $items = array();
40 if ($may_cache) {
41 // plug into book module's book/export URL space
42
43 $items[] = array(
44 'path' => 'admin/settings/s5_textfield',
45 'title' => t('S5 Textfield Settings'),
46 'description' => t('Enables site settings for S5 Module.'),
47 'callback' => 'drupal_get_form',
48 'callback arguments' => 's5_textfield_settings_form',
49 'access' => user_access('administer site configuration'),
50 );
51 }
52 else {
53 if (arg(0) == 'node' && is_numeric(arg(1))) {
54 // We don't specify an access check here so that it is inherited by the parent path (i.e. the node)
55 $items[] = array(
56 'path' => 'node/'. arg(1) .'/s5',
57 'title' => t('S5 presentation'),
58 'type' => MENU_CALLBACK,
59 'callback' => 's5_textfield_export',
60 'callback arguments' => array(arg(1), arg(3)),
61 );
62 }
63 }
64 return $items;
65 }
66
67 /**
68 * Admin settings.
69 */
70 function s5_textfield_settings_form() {
71 // Allow admins to set the S5 theme to use
72 $path = drupal_get_path('module', 's5_textfield');
73 $files = file_scan_directory($path .'/ui', '^slides\.css$');
74 $themes = array();
75 foreach ($files as $filename => $file) {
76 $themes[] = str_replace('/', '', str_replace($path .'/ui', '', str_replace('slides.css', '', $filename)));
77 }
78 if (count($themes)) {
79 $form['s5_textfield_theme'] = array(
80 '#type' => 'select',
81 '#title' => t('Display of S5 Exported Books'),
82 '#default_value' => variable_get('s5_textfield_theme', 'default'),
83 '#options' => drupal_map_assoc($themes),
84 '#description' => t('Choose your theme from this list. You can also add more themes to S5.'),
85 );
86 $form['s5_textfield_slide_separator'] = array(
87 '#type' => 'textfield',
88 '#title' => t('Slide Separator'),
89 '#size' => 20,
90 '#maxlength' => 255,
91 '#default_value' => variable_get('s5_textfield_slide_separator', '<!--pagebreak-->'),
92 '#description' => t('S5 slide separator string. You should use an HTML tag that will render reasonably when paging is not enabled such as &lt;!--pagebreak--&gt;'),
93 );
94 $form['s5_textfield_title_separator'] = array(
95 '#type' => 'textfield',
96 '#title' => t('Slide/Title Separator'),
97 '#size' => 20,
98 '#maxlength' => 255,
99 '#default_value' => variable_get('s5_textfield_title_separator', '<!--titlebreak-->'),
100 '#description' => t('S5 slide/title separator string. You should use an HTML tag that will render reasonably when paging is not enabled such as &lt;!--titlebreak--&gt;'),
101 );
102 $form['s5_textfield_node_types_enabled'] = array(
103 '#type' => 'checkboxes',
104 '#title' => t('Node Types'),
105 '#description' => t('Set the node types you want to enable S5 Slideshows for.'),
106 '#default_value' => variable_get('s5_textfield_node_types_enabled', array()),
107 '#options' => node_get_types('names'),
108 );
109 //TODO mechanism to select types of fields
110 }
111 else {
112 $form['s5_error_message'] = array(
113 '#type' => 'markup',
114 '#title' => t('S5 Configuration Error'),
115 '#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.'),
116 );
117 }
118 return system_settings_form($form);
119 }
120
121 /**
122 * Export menu handler
123 */
124 function s5_textfield_export($nid = 0, $field = 'body') {
125 global $base_url;
126 watchdog('s5_textfield', $field);
127 $nid = (int) $nid;
128 $node = node_load($nid);
129
130 $node_type = in_array($node->type, variable_get('s5_textfield_node_types_enabled', array()), TRUE);
131 if (!$node_type) {
132 // This node isn't configured for s5, send them back to the regular version
133 drupal_goto('node/'. $nid);
134 }
135
136 // Adapted (simplified) version of node_view for Drupal 5.x
137 //Render the node content
138 $node = node_build_content($node, FALSE, TRUE);
139
140 // Disable fivestar widget output
141 unset($node->content["fivestar_widget"]);
142 // Disable service links module output
143 unset($node->content["service_links"]);
144 // TODO one or two more of these, probably
145
146 // Template variables to fill into the file
147 $variables = array(
148 'base_url' => "$base_url/",
149 'title' => check_plain($node->title),
150 'author' => check_plain($node->name),
151 'company' => '',
152 'location' => '',
153 'presdate' => '',
154 'slides' => $node->s5_slides,
155 );
156
157 // Try to match the node body for information on these details
158 $searchfor = array("author", "company", "location", "presdate");
159 foreach ($searchfor as $class) {
160 if (preg_match('!class="s5-'. $class .'">([^<]+)<!', $node->body, $found)) {
161 $variables[$class] = $found[1];
162 }
163 }
164
165 // Return template filled in with appropriate details
166 theme('s5_textfield_export', $variables);
167 }
168
169 function s5_textfield_nodeapi(&$node, $op, $teaser = NULL, $page = NULL) {
170 if ($op == 'view' || $op = 'load') {
171 if (isset($node->field_body[0]['view'])) { // support for CCK
172 _s5_textfield_nodeapi($node,
173 $node->field_body[0]['view'],
174 $node->field_teaser[0]['view'],
175 $op, $teaser, $page);
176 }
177 else if (isset($node->field_body[0]['value'])) { // support for CCK
178 _s5_textfield_nodeapi($node,
179 $node->field_body[0]['value'],
180 $node->field_teaser[0]['value'],
181 $op, $teaser, $page);
182 }
183 else {
184 _s5_textfield_nodeapi($node, $node->body, $node->teaser, $op, $teaser, $page);
185 }
186 }
187 }
188
189
190 /*
191 * Helper function for paging_nodeapi()
192 */
193 function _s5_textfield_nodeapi(&$node, &$nodebody, &$nodeteaser, $op, $teaser, $page) {
194 switch ($op) {
195 case 'load':
196 $node_type = in_array($node->type, variable_get('s5_textfield_node_types_enabled', array()), TRUE);
197 if ($node_type && arg(2) == 's5' && !$teaser) {
198 $node->s5_slides = explode(variable_get('s5_textfield_slide_separator', '<!--pagebreak-->'), $nodebody);
199 }
200 break;
201
202 case 'view':
203 $node_type = in_array($node->type, variable_get('s5_textfield_node_types_enabled', array()), TRUE);
204 if ($node_type && arg(2) == 's5' && !$teaser) {
205 if (count($node->s5_slides)) {
206 $slides = '';
207 foreach ($node->s5_slides as $key => $slide) {
208
209 $slide = explode(variable_get('s5_textfield_title_separator', '<!--titlebreak-->'), $slide);
210 if (count($slide) > 1) {
211 $slides .= '<div class="slide"><h1>'. check_plain($slide[0]) ."</h1>\n". check_markup($slide[1], $node->filter) .'</div>';
212 }
213 else if (count($slide) == 1) {
214 $slides .= '<div class="slide"><h1></h1>'."\n". check_markup($slide[0], $node->filter) .'</div>';
215 }
216 else {
217 $slides .= t('The empty slide. Weird - please <a href="!url">file a bug</a> explaining how you got here', array('!url' => url('http://drupal.org/node/add/project-issue/s5')));
218 }
219 }
220 }
221 $node->s5_slides = $slides;
222 }
223 break;
224 default:
225 break;
226 }
227 }
228
229
230
231 /**
232 * This is a very basic S5 template, using the default S5 theme,
233 * requiring S5 stlye files in <modules>/s5/ui
234 */
235 function theme_s5_textfield_export($variables) {
236 extract($variables);
237 $path = drupal_get_path('module', 's5_textfield');
238 $theme = variable_get('s5_textfield_theme', 'default');
239 echo <<<END_S5_PRESENTATION
240 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
241 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
242
243 <html xmlns="http://www.w3.org/1999/xhtml">
244
245 <head>
246 <title>{$title}</title>
247 <base href="{$base_url}" />
248 <meta name="generator" content="Drupal S5 Book Export" />
249 <meta name="version" content="S5 1.1" />
250 <meta name="presdate" content="{$presdate}" />
251 <meta name="author" content="{$author}" />
252 <meta name="company" content="{$company}" />
253 <meta name="defaultView" content="slideshow" />
254 <meta name="controlVis" content="hidden" />
255 <link rel="stylesheet" href="{$path}/ui/$theme/slides.css" type="text/css" media="projection" id="slideProj" />
256 <link rel="stylesheet" href="{$path}/ui/default/outline.css" type="text/css" media="screen" id="outlineStyle" />
257 <link rel="stylesheet" href="{$path}/ui/default/print.css" type="text/css" media="print" id="slidePrint" />
258 <link rel="stylesheet" href="{$path}/ui/default/opera.css" type="text/css" media="projection" id="operaFix" />
259 <script src="{$path}/ui/default/slides.js" type="text/javascript"></script>
260 </head>
261 <body>
262
263 <div class="layout">
264 <div id="controls"></div>
265 <div id="currentSlide"></div>
266 <div id="header"></div>
267 <div id="footer"><h1>{$location}</h1><h2>{$title}</h2></div>
268 </div>
269
270 <div class="presentation">
271 {$slides}
272 </div>
273
274 </body>
275 </html>
276 END_S5_PRESENTATION;
277
278 }

  ViewVC Help
Powered by ViewVC 1.1.2