-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoutline_designer.module
332 lines (317 loc) · 11.5 KB
/
outline_designer.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
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
<?php
// ELMS: Outline Designer API - Usability improvements for outline creation
// Copyright (C) 2008-2012 The Pennsylvania State University
//
// Bryan Ollendyke
//
// Keith D. Bailey
//
// 12 Borland
// University Park, PA 16802
/**
* @file
* API for implementation of the Outline Designer usability improvements.
*/
/**
* Implements hook_permission().
*/
function outline_designer_permission() {
return array(
'use outline designer' => array(
'title' => t('use outline designer'),
'description' => t('Grant basic access to use the outline designer'),
),
);
}
/**
* Implements hook_menu().
*/
function outline_designer_menu() {
$items = array();
$items['outline_designer/ajax'] = array(
'access arguments' => array('use outline designer'),
'page callback' => '_outline_designer_ajax',
'page arguments' => array(2, 3, 4, 5, 6, 7),
'type' => MENU_CALLBACK,
);
$items['admin/config/content/outline_designer'] = array(
'title' => 'Outline Designer',
'description' => 'The Outline Designer settings allow you to associate icons to content types for use in structuring book content.',
'page callback' => 'drupal_get_form',
'page arguments' => array('outline_designer_settings'),
'type' => MENU_NORMAL_ITEM,
'access arguments' => array('administer site configuration'),
);
return $items;
}
/**
* Helper function to generate scripts for a page.
*/
function _outline_designer_setup($ajax_path, $nid) {
drupal_add_css(drupal_get_path('module', 'outline_designer') . '/css/outline_designer.css');
drupal_add_js(drupal_get_path('module', 'outline_designer') . '/js/jquery.contextmenu.js');
drupal_add_js(drupal_get_path('module', 'outline_designer') . '/js/outline_designer.js', array('scope' => 'footer'));
// invoke implementation of ops javascript
module_invoke_all('outline_designer_ops_js', $ajax_path, $nid);
}
/**
* Implements hook_outline_designer_ops_js().
*/
function outline_designer_outline_designer_ops_js($ajax_path, $nid = NULL) {
$purl = '';
if (module_exists('purl')) {
$options = array();
// need to look for a group if it exists otherwise it should work fine
if (arg(0) == 'admin') {
$node = node_load($nid);
purl_url_outbound_alter($purl, $options, '');
$ajax_base_path = base_path() . $purl . $ajax_path;
$node = node_load($nid);
if (count($node->og_groups)) {
$group = node_load(array_pop($node->og_groups));
$ajax_base_path = base_path() . $group->purl . '/' . $ajax_path;
}
else {
$ajax_base_path = base_path() . $ajax_path;
}
}
else {
purl_url_outbound_alter($purl, $options, '');
$ajax_base_path = base_path() . $purl . $ajax_path;
}
}
else {
$ajax_base_path = base_path() . $ajax_path;
}
// pass variables to js
$js_variables = array(
'outline_designer' => array(
'path' => base_path() . drupal_get_path('module', 'outline_designer') . '/',
'theme' => variable_get('outline_designer_theme', 'vista'),
'collapseToggle' => variable_get('outline_designer_collapse_toggle', 1),
'collapseList' => array(),
'token' => drupal_get_token(),
'factor' => 1,
'ajaxPath' => $ajax_base_path,
),
);
drupal_add_js($js_variables, "setting");
}
/**
* Theme Callback: render the top buttons for outline designer ui.
*/
function theme_outline_designer_ui_prefix($variables) {
$nid = $variables['nid'];
$icon_path = $variables['icon_path'];
$can_add = $variables['can_add'];
$output = '<fieldset class="collapsible"><div>';
// only append the add form if it is allowed
if ($can_add) {
$output .= '<div style="width:120px; float:left; height:30px; margin-right:6px;" class="context-menu context-menu-theme-' . variable_get('outline_designer_theme', 'vista') . '"><div title="Add Content" alt="Add Content" class="context-menu-item">
<div style="background-image: url(' . $icon_path . 'add_content.png);" class="context-menu-item-inner" onclick="Drupal.settings.outline_designer.activeNid=' . $nid . ';Drupal.outline_designer.form_render(' . "'add_content'" . ');">
' . t('Add content') . '
</div>
</div>
</div>';
}
$output .= '<div style="height:30px; float:left;">
<a href="#" onclick="Drupal.outline_designer.scale(-1);" class="od-operation-icons">
<img alt="' . t('Decrease interface') . '" title="' . t('Decrease interface') . '" src="' . $icon_path . 'text-decrease.png" />
</a>
<a href="#" onclick="Drupal.outline_designer.scale(1);" class="od-operation-icons">
<img alt="' . t('Increase interface') . '" title="' . t('Increase interface') . '" src="' . $icon_path . 'text-increase.png" />
</a>
<a href="#" onclick="Drupal.outline_designer.scale(0);" class="od-operation-icons">
<img alt="' . t('Reset interface') . '" title="' . t('Reset interface') . '" src="' . $icon_path . 'text-reset.png" />
</a>
<a href="#" onclick="Drupal.outline_designer.openAll();" class="od-operation-icons">
<img alt="' . t('Open all branches') . '" title="' . t('Open all branches') . '" src="' . $icon_path . 'open-all.png" />
</a>
<a href="#" onclick="Drupal.outline_designer.collapseAll();" class="od-operation-icons">
<img alt="' . t('Close all branches') . '" title="' . t('Close all branches') . '" src="' . $icon_path . 'close-all.png" />
</a>
</div>
</div>
</fieldset>';
return $output;
}
/**
* Helper function to make outline designer settings more obvious.
*/
function outline_designer_settings($form, &$form_state) {
// collapse default state
$form["ui"] = array(
'#type' => 'fieldset',
'#title' => t('User interface'),
'#collapsed' => FALSE,
'#collapsible' => TRUE,
);
$form["ui"]["outline_designer_theme"] = array(
'#type' => 'select',
'#title' => t('Menu theme'),
'#default_value' => variable_get('outline_designer_theme', 'vista'),
'#options' => array(
'vista' => 'Vista',
'xp' => 'XP',
'human' => 'Human',
'osx' => 'OS X',
),
'#description' => 'Theme for the outline designer menu system',
'#required' => TRUE,
);
// collapse default state
$form["ui"]["outline_designer_collapse_toggle"] = array(
'#type' => 'checkbox',
'#title' => t('Collapse nested content by default?'),
'#default_value' => variable_get('outline_designer_collapse_toggle', 1),
'#description' => 'This is helpful when working with large book structures.',
'#required' => FALSE,
);
return system_settings_form($form);
}
/**
* Implementation of the ajax menu hook
*
* @args
* $token = user token to block CSF attack
* $type = type of outline action
* $action = action that's being performed
* $var1 = typically nid being acted on
* $var2 = additional data like title, ect.
* $var3 = even more data like type
*/
function _outline_designer_ajax($token, $type, $action, $var1, $var2, $var3) {
global $user;
$token = check_plain($token);
$type = check_plain($type);
$action = check_plain($action);
$var1 = check_plain($var1);
$var2 = check_plain($var2);
$var3 = check_plain($var3);
if (drupal_valid_token($token)) {
$ops = _outline_designer_get_operations($type, TRUE);
foreach ($ops as $key => $op) {
if ($action == $key && isset($op['callback'])) {
print call_user_func_array($op['callback'], array($var1, $var2, $var3));
}
}
}
exit();
}
/**
* Suffix adds the info to tack on the end of the form
*/
function theme_outline_designer_overlay_suffix($variables) {
$render = $variables['render'];
return '
<div id="od_popup_overlay"></div>
<div id="od_popup" class="context-menu context-menu-theme-' . variable_get('outline_designer_theme', 'vista') . '">
<div class="popup-statusbar"></div>
<div class="popup-content"></div>
<div class="popup-buttons">
<input type="button" name="Save" value="Save" class="od_submit_button" />
</div>
<img src="' . base_path() . drupal_get_path('module', 'outline_designer') . '/images/close.png" class="od_cancel_button" />
</div>
<div id="od_popup_toolbox">' . $render . '</div>';
}
/**
* Implements hook_theme().
*/
function outline_designer_theme() {
$theme = array(
'outline_designer_context_menu_items_matrix' => array(
'render element' => 'form',
),
'outline_designer_suffix' => array(
'variables' => array(
'nid' => NULL,
'icon_path' => NULL,
),
),
'outline_designer_prefix' => array(
'variables' => array(
'type' => NULL,
'nid' => NULL,
'icon_path' => NULL,
),
),
'outline_designer_overlay_suffix' => array(
'variables' => array('render' => NULL),
),
'outline_designer_ui_prefix' => array(
'variables' => array(
'nid' => NULL,
'icon_path' => NULL,
'can_add' => NULL,
),
),
);
return $theme;
}
/**
* Theme Callback: Outline Designer page prefix
*/
function theme_outline_designer_prefix($variables) {
$type = $variables['type'];
$nid = $variables['nid'];
$icon_path = $variables['icon_path'];
return '<img alt="' . $type . '" id="node-' . $nid . '-icon" src="' . base_path() . variable_get("outline_designer_" . $type . "_icon", drupal_get_path('module', 'outline_designer') . "/images/page.png") . '" alt="Nid: ' . $nid . '" title="Nid: ' . $nid . '" style="float:left; margin:2px;" /><img src="' . $icon_path . 'settings.png" alt="' . t('Content operations') . '" title="' . t('Content operations') . '" id="node-' . $nid . '" class="outline_designer_edit_button" />';
}
/**
* Theme Callback: Outline Designer page suffix
*/
function theme_outline_designer_suffix($variables) {
$nid = $variables['nid'];
$icon_path = $variables['icon_path'];
return '<img src="' . $icon_path . 'open.png" alt="open" class="od-toggle-open" id="collapse-' . $nid . '" />';
}
/**
* Theme Callback: Display the Context menu items as a matrix
*/
function theme_outline_designer_context_menu_items_matrix($variables) {
$form = $variables['form'];
$roles = user_roles(TRUE);
foreach (element_children($form["checkboxes"]) as $item_name) {
$trow = array();
foreach ($roles as $rid => $role) {
$trow[] = drupal_render($form["checkboxes"][$item_name]["outline_designer_context_menu_" . $item_name . "_" . $rid]);
}
$rows[] = $trow;
}
$output = theme('table', array('header' => array_values($roles), 'rows' => $rows));
return $output;
}
/**
* Implements hook_outline_designer_operations().
*/
function outline_designer_outline_designer_operations($type) {
// stub to ensure that value list is an array
return array();
}
/**
* Helper function to invoke hook calls and build a list of operations.
*/
function _outline_designer_get_operations($type, $keep_callbacks = FALSE) {
// allow other modules to define the list of operations
$ops = module_invoke_all('outline_designer_operations', $type);
// allow for altering of this list
drupal_alter('outline_designer_operations', $ops, $type);
// hide callbacks unless told to keep them, this helps unclutter js side
if (!$keep_callbacks) {
foreach ($ops as $key => $op) {
// make sure its set so we dont throw an error
if (isset($op['callback'])) {
unset($ops[$key]['callback']);
}
// remove calls stating they are API only
// callback removal is for all UI based calls
if ($op['title'] == '<<OUTLINE_DESIGNER_API_ONLY>>') {
unset($ops[$key]);
}
}
}
return $ops;
}