/[drupal]/contributions/modules/sidecontent/sidecontent.module
ViewVC logotype

Contents of /contributions/modules/sidecontent/sidecontent.module

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


Revision 1.15 - (show annotations) (download) (as text)
Sun May 24 14:36:12 2009 UTC (6 months ago) by MegaGrunt
Branch: MAIN
CVS Tags: DRUPAL-6--2-0-RC1, HEAD
Changes since 1.14: +8 -6 lines
File MIME type: text/x-php
- Fixed bug '"Print view include" option not displaying side content in printer-friendly page' #445668
1 <?php
2 // $Id: sidecontent.module,v 1.14 2009/04/05 01:03:13 MegaGrunt Exp $
3
4 /**
5 * Implementation of hook_perm().
6 */
7 function sidecontent_perm() {
8 return array('access side content', 'create side content');
9 }
10
11 /**
12 * Implementation of hook_block().
13 *
14 * Displays content in side bar
15 */
16 function sidecontent_block($op = 'list', $delta = 0, $edit = array()) {
17
18 switch ($op) {
19
20 case 'list':
21 $blocks[0]['info'] = t('Side content');
22 return $blocks;
23
24 case 'configure':
25 $form['sidecontent_print'] = array(
26 '#type' => 'checkbox',
27 '#title' => t('Print view include'),
28 '#default_value' => variable_get('sidecontent_print', false),
29 '#description' => t('Show content in print view (requires Print Friendly Pages module).'),
30 );
31
32 $form['sidecontent_options'] = array(
33 '#prefix' => '<strong>',
34 '#value' => t('Options for node form:'),
35 '#suffix' => '</strong>',
36 );
37
38 $form['sidecontent_show_input_format'] = array(
39 '#type' => 'checkbox',
40 '#title' => t('Show input format'),
41 '#default_value' => variable_get('sidecontent_show_input_format', true),
42 '#description' => t('If this box is not checked, the default input format will be used when formatting the block content.'),
43 );
44
45 $form['sidecontent_show_in_group'] = array(
46 '#type' => 'checkbox',
47 '#title' => t('Show in form group'),
48 '#default_value' => variable_get('sidecontent_show_in_group', true),
49 '#description' => t('Show textarea and form filters formatted as a form group.'),
50 );
51
52 $form['sidecontent_group_description'] = array(
53 '#type' => 'textfield',
54 '#title' => t('Group description'),
55 '#default_value' => check_plain(variable_get('sidecontent_group_description', 'Content to display in side block.')),
56 '#size' => 50,
57 '#maxlength' => 64,
58 '#description' => t('Short description that is displayed at the end of the form group.'),
59 );
60
61 return $form;
62
63 case 'save':
64
65 if (!user_access('create side content')) break;
66 variable_set('sidecontent_print', !empty($edit['sidecontent_print']));
67 variable_set('sidecontent_show_input_format', !empty($edit['sidecontent_show_input_format']));
68 variable_set('sidecontent_show_in_group', !empty($edit['sidecontent_show_in_group']));
69 variable_set('sidecontent_group_description', trim($edit['sidecontent_group_description']));
70 return;
71
72 case 'view': default:
73
74 // is this a node?
75 if (arg(0) != 'node') break;
76 if (!is_numeric(arg(1)) && arg(1) != 'add') break;
77
78 // does user have access to view node?
79 if (!user_access('access content')) break;
80
81 // does user have access to view sidecontent?
82 if (!user_access('access side content') && !user_access('create side content' )) break;
83
84 if (is_numeric(arg(1))) {
85
86 $node = node_load(arg(1));
87 $type = $node->type;
88 } else {
89 $type = arg(2);
90 }
91
92 // is sidecontent enabled for this node type?
93 if (!variable_get('sidecontent_' . $type, 1)) break;
94
95 // Preview
96 $node_form = $_POST['edit'];
97
98 if (!empty($node_form) && user_access('create side content' )) {
99
100 if (empty($node_form['sidecontent_format']) || !is_numeric($node_form['sidecontent_format'])) $node_form['sidecontent_format'] = FILTER_FORMAT_DEFAULT;
101 $sidecontent->sidetitle = $node_form['sidecontent_title'];
102 $sidecontent->sidecontent = $node_form['sidecontent'];
103 $sidecontent->format = $node_form['sidecontent_format'];
104
105 } else {
106
107 $sidecontent = db_fetch_object(db_query("SELECT s.format, s.sidetitle, s.sidecontent FROM {sidecontent} s WHERE nid = %d", $node->nid));
108 }
109
110 if ($sidecontent->sidecontent) {
111
112 if (!empty($sidecontent->sidetitle)) $block['subject'] = check_plain($sidecontent->sidetitle);
113 $block['content'] = check_markup($sidecontent->sidecontent, $sidecontent->format, FALSE);
114 }
115
116 return $block;
117 }
118
119 return;
120 }
121
122
123 /**
124 * Implementation of hook_form_alter.
125 */
126 function sidecontent_form_alter(&$form, &$form_state, $form_id) {
127
128 // Alter the settings form.
129 if ($form_id == 'node_type_form') {
130 $node_type = $form['old_type']['#value'];
131
132 $form['submission']['sidecontent'] = array(
133 '#type' => 'radios',
134 '#title' => t('Enable side content'),
135 '#default_value' => variable_get('sidecontent_' . $node_type, 0),
136 '#options' => array(t('Disabled'), t('Enabled')),
137 );
138 }
139
140 // Add stuff to the node submit form.
141 if (isset($form['type']) && $form['type']['#value'] . '_node_form' == $form_id) {
142
143 if (!user_access('create side content' )) return;
144
145 $node = $form['#node'];
146
147 $type = variable_get('sidecontent_' . $node->type, 1);
148
149 if (!empty($type)) {
150
151 if (variable_get('sidecontent_show_in_group', true)) {
152
153 $form['sidecontent'] = array(
154 '#type' => 'fieldset',
155 '#title' => t('Side Content'),
156 '#description' => check_plain(variable_get('sidecontent_group_description', '')),
157 '#collapsible' => TRUE,
158 '#collapsed' => empty($node->sidecontent),
159 );
160 }
161
162 $default_title = trim(variable_get('sidecontent_title', t('blank')));
163 $default_title = (empty($default_title)) ? t('blank') : check_plain($default_title);
164
165 $form['sidecontent']['sidecontent_title'] = array(
166 '#type' => 'textfield',
167 '#title' => t('Side Content Title'),
168 '#default_value' => $node->sidecontent_title,
169 '#description' => t("Leave blank to use default side content title: <em>%title</em>", array('%title' => $default_title)),
170 '#size' => 50,
171 '#maxlength' => 128
172 );
173
174 $form['sidecontent']['sidecontent'] = array(
175 '#type' => 'textarea',
176 '#title' => t('Side Content Text'),
177 '#default_value' => $node->sidecontent,
178 '#description' => t('Content to display in side block.'),
179 '#cols' => 60,
180 '#rows' => 20,
181 );
182
183 if (variable_get('sidecontent_show_input_format', true)) {
184 $form['sidecontent']['sidecontent_format'] = filter_form($node->sidecontent_format, NULL, array('sidecontent_format'));
185 }
186
187 }
188 }
189
190 }
191
192
193 /**
194 * Implementation of hook_nodeapi.
195 */
196 function sidecontent_nodeapi(&$node, $op, $teaser, $page) {
197
198 switch ($op) {
199
200 case 'load':
201
202 if (!user_access('access side content') && !user_access('create side content' )) break;
203
204 $results = db_fetch_object(db_query("SELECT * FROM {sidecontent} WHERE nid = %d", $node->nid));
205 if ($results) {
206 $node->sidecontent_title = $results->sidetitle;
207 $node->sidecontent = $results->sidecontent;
208 $node->sidecontent_format = $results->format;
209 }
210 break;
211
212 case 'validate':
213
214 if (!variable_get('sidecontent_'. $node->type, 1)) break;
215 if (!user_access('create side content' )) break;
216 $node->sidecontent = rtrim($node->sidecontent);
217 break;
218
219 case 'insert':
220
221 if (!variable_get('sidecontent_'. $node->type, 1)) break;
222 if (empty($node->sidecontent)) return;
223 if (!user_access('create side content' )) break;
224
225 if (!variable_get('sidecontent_show_input_format', true)) $node->sidecontent_format = FILTER_FORMAT_DEFAULT;
226
227 db_query("DELETE FROM {sidecontent} WHERE nid = %d", $node->nid);
228 db_query("INSERT INTO {sidecontent} (nid, format, sidetitle, sidecontent) VALUES (%d, %d, '%s', '%s')", $node->nid, $node->sidecontent_format, $node->sidecontent_title, $node->sidecontent);
229 break;
230
231 case 'update':
232
233 if (!variable_get('sidecontent_'. $node->type, 1)) break;
234 if (!user_access('create side content' )) break;
235 db_query("DELETE FROM {sidecontent} WHERE nid = %d", $node->nid);
236
237 if (empty($node->sidecontent)) return;
238
239 if (!variable_get('sidecontent_show_input_format', true)) $node->sidecontent_format = FILTER_FORMAT_DEFAULT;
240 db_query("INSERT INTO {sidecontent} (nid, format, sidetitle, sidecontent) VALUES (%d, %d, '%s', '%s')", $node->nid, $node->sidecontent_format, $node->sidecontent_title, $node->sidecontent);
241 break;
242
243 case 'view':
244
245 // add sidecontent into print view pages
246 if (arg(0) == 'print' && !empty($node->sidecontent)) {
247
248 $print = variable_get('sidecontent_print', false);
249 if (empty($print)) break;
250
251 // does user have access to view sidecontent?
252 if (!user_access('access side content') && !user_access('create side content' )) break;
253
254 // is the print module enabled
255 if (!module_exists('print')) break;
256
257 $sidecontent = check_markup($node->sidecontent, $node->format);
258
259 // note: print module disregards theme, so we have to include our markup here - yuuk!
260 $node->content['sidecontent'] = array('#value' => '<div class="sidecontent-print">' . $sidecontent . '</div>',
261 '#weight' => -10,
262 );
263 }
264
265 break;
266
267 case 'delete':
268
269 if (!variable_get('sidecontent_'. $node->type, 1)) break;
270 if (!user_access('create side content' )) break;
271 db_query("DELETE FROM {sidecontent} WHERE nid = %d", $node->nid);
272 break;
273
274 case 'update index':
275
276 if (!variable_get('sidecontent_'. $node->type, 1)) break;
277 if (!user_access('create side content' )) break;
278 if (!variable_get('sidecontent_show_input_format', true)) $node->sidecontent_format = FILTER_FORMAT_DEFAULT;
279 $text = check_markup($node->sidecontent, $node->sidecontent_format);
280 return $text;
281 }
282 }

  ViewVC Help
Powered by ViewVC 1.1.2