-
Notifications
You must be signed in to change notification settings - Fork 0
/
ding_wiki.module
284 lines (240 loc) · 7.98 KB
/
ding_wiki.module
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
<?php
/**
* Implementation of hook_init().
*/
function ding_wiki_init() {
//Add our own stylesheet
drupal_add_css(drupal_get_path('module', 'ding_wiki') . '/css/ding_wiki.css');
//Add our javascript
drupal_add_js(drupal_get_path('module', 'ding_wiki') . '/js/jquery.gallerific.js');
drupal_add_js(drupal_get_path('module', 'ding_wiki') . '/js/ding_wiki.js');
global $custom_theme, $user;
if (variable_get('node_admin_theme', 0) && !ding_user_has_secure_role($user)) {
//Define the types should use the default theme instead of the admin one
$custom_form_types = array('wiki-page');
$use_custom_theme = false;
//Use default theme when adding types or edit
$use_custom_theme = (arg(0) == 'node' && arg(1) == 'add' && in_array(arg(2), $custom_form_types));
if (!$use_custom_theme && (arg(0) == 'node' && arg(2) == 'edit')) {
$node = node_load(arg(1));
$use_custom_theme = in_array($node->type, $custom_form_types);
}
//Set the theme
if ($use_custom_theme) {
$custom_theme = variable_get('theme_default', '0');
}
}
}
/**
* Implementation of hook_menu().
*/
function ding_wiki_menu() {
$items = array();
$items['node/%node/create-wiki-page'] = array(
'title' => 'Create new wiki page',
'page callback' => 'drupal_goto',
'page arguments' => array('node/add/wiki-page'),
'access callback' => '_ding_wiki_node_is_wiki',
'access arguments' => array(1),
'type' => MENU_LOCAL_TASK,
'weight' => -10, //We need to be before the view tab
);
return $items;
}
/**
* Implementation of hook_nodeapi().
*/
function ding_wiki_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) {
// Set default breadcrumb if
// - viewing a wiki page node
// - on a page by itself
// - without a menu item
if (($node->type == 'wiki_page') &&
($op == 'view') && !$a3 && $a4) {
if (!_ding_wiki_in_menu($node)) {
$trail = array(
l(t('Home'), '<front>'),
);
$trail[] = l(t('Wiki'), 'wiki');
$trail[] = l($node->title, 'node/' . $node->nid);
drupal_set_breadcrumb($trail);
}
}
}
/**
* Implementation of hook_theme().
*/
function ding_wiki_theme() {
$file = drupal_get_path('module', 'ding_wiki') . '/ding_wiki.theme.inc';
$theme = array(
'ding_wiki_formatter_text' => array(
'arguments' => array('element' => NULL),
'template' => 'templates/ting_reference_text',
'file' => $file,
),
'ding_wiki_formatter_mixed' => array(
'arguments' => array('element' => NULL),
'file' => $file,
),
'ding_wiki_formatter_thumbnail_description' => array(
'arguments' => array('element' => NULL),
'file' => $file,
),
'ding_wiki_formatter_thumbnail_link_description' => array(
'arguments' => array('element' => NULL),
'file' => $file,
),
);
return $theme;
}
/**
* Implementation of hook_theme_registry_alter.
*/
function ding_wiki_theme_registry_alter(&$theme_registry) {
//We provide our own node template for wiki pages so look here as well
$theme_path = drupal_get_path('module', 'ding_wiki') . '/templates';
$theme_hooks = array('node', 'content_field');
foreach ($theme_hooks as $hook) {
$theme_registry[$hook]['theme paths'][] = $theme_path;
}
}
function ding_wiki_preprocess_content_field(&$vars) {
$vars['node_type'] = $vars['node']->type;
$vars['node_type_css'] = str_replace('_', '-', $vars['node']->type);
// Pass along information whether this is a gallery subpage for a wiki node
if ($vars['node_type'] == 'wiki_page') {
$vars['wiki_gallery'] = (arg(2) == 'wiki_gallery') !== FALSE;
// Determine if we are on a wiki node page
// Ugly - is there a better way to achieve this?
$vars['wiki_page'] = FALSE;
if ((arg(0) == 'node') && is_int(arg(1)) && !arg(2)) {
$node = node_load(arg(1));
$vars['wiki_page'] = $node->type == 'wiki_page';
}
}
}
/**
* Implementation of hook_field_formatter_info().
*/
function ding_wiki_field_formatter_info() {
$formatters = array(
'text' => array(
'label' => t('Simple text'),
'field types' => array('ting_reference'),
'multiple values' => CONTENT_HANDLE_CORE,
),
'mixed' => array(
'label' => t('Combines image and text formatters for multiple values'),
'field types' => array('ting_reference'),
'multiple values' => CONTENT_HANDLE_CORE,
),
'thumbnail_description' => array(
'label' => t('Ding! wiki thumbnail with description'),
'field types' => array('image', 'filefield'),
'multiple values' => CONTENT_HANDLE_CORE,
),
'thumbnail_link_description' => array(
'label' => t('Ding! wiki thumbnail linked to full image with description'),
'field types' => array('image', 'filefield'),
'multiple values' => CONTENT_HANDLE_CORE,
),
);
return $formatters;
}
/**
* Implementation of hook_form_ID_alter().
*/
function ding_wiki_form_wiki_page_node_form_alter(&$form, &$form_state) {
global $user;
// Make sure buttons stay at the end
$form['buttons']['#weight'] = 9999;
if (!ding_user_has_secure_role($user)) {
// Remove revision information from the form. We do not wat to bother users
// with this
$form['revision_information']['#access'] = FALSE;
// Remove teaser split - this isn't something for users
unset($form['body_field']['teaser_js']);
unset($form['body_field']['teaser_include']);
$form['#after_build'][] = '_ding_wiki_remove_formats';
}
}
/**
* Remove body formatter elements from a form. Inspired by better_formats.
*
* @see better_formats_filter_form().
*/
function _ding_wiki_remove_formats($form, &$form_state) {
// Remove the formatting guidelines
$form['body_field']['format']['format']['guidelines']['#value'] = '';
// Remove the more formatting information link. It should be the last child
// in the format array.
$more_info_key = array_pop(element_children($form['body_field']['format']));
$form['body_field']['format'][$more_info_key]['#value'] = '';
return $form;
}
/**
* Implementation of hook_form_ID_alter().
*/
function ding_wiki_form_node_access_page_alter(&$form, &$form_state) {
// Make access control lists collapsed by default. They are seldom needed.
$form['nacl']['#collapsed'] = TRUE;
}
/**
* Implementation of hook_form_ID_alter().
*/
function ding_wiki_form_comment_form_alter(&$form, &$form_state) {
// Make the preview comment button disapear
$form['preview']['#access'] = FALSE;
}
/**
* Implementation of hook_elements().
*/
function ding_wiki_elements() {
$elements = array();
// Add another process function to imagefield widgets
$elements['imagefield_widget'] = array(
'#process' => array('ding_wiki_imagefield_widget_process'),
);
return $elements;
}
function ding_wiki_imagefield_widget_process($element, $edit, &$form_state, $form) {
// Images on wiki pages should show the title field first
// and no description.
if ($element['#type_name'] == 'wiki_page') {
$element['data']['title']['#weight'] = -1;
unset($element['data']['title']['#description']);
}
return $element;
}
/**
* Implementation of hook_ctools_plugin_directory().
*/
function ding_wiki_ctools_plugin_directory($owner, $plugin_type) {
return 'plugins/' . $plugin_type;
}
/**
* Returns whether a node is a wiki node.
*
* Used as access callback.
*/
function _ding_wiki_node_is_wiki($node) {
return $node->type == 'wiki_page';
}
/**
* Determine whether a node has a menu link.
*
* Used to determine pane visibility.
*/
function _ding_wiki_in_menu($node) {
return (bool) db_result(db_query("SELECT count(menu_name) as count FROM {menu_links} WHERE link_path = '%s'", 'node/' . $node->nid));
}
/**
* Determine the menu link id for the root wiki page.
*
* We do not know what menu link id the wiki root panel will obtain
* so we need to retrieve it for panel configuration at runtime.
*/
function _ding_wiki_root_mlid() {
return db_result(db_query('SELECT mlid FROM {menu_links} WHERE menu_name = "menu-organisation" AND link_path = "wiki"'));
}
include_once('ding_wiki.features.inc');