-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmultigraph.module
More file actions
executable file
·236 lines (212 loc) · 7.38 KB
/
multigraph.module
File metadata and controls
executable file
·236 lines (212 loc) · 7.38 KB
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
<?php
require_once DRUPAL_ROOT.'/'.drupal_get_path('module','multigraph')."/multigraph_functions.inc";
/**
* Implements hook_node_info() to provide our multigraph type.
*/
function multigraph_node_info() {
return array(
'multigraph' => array(
'name' => t('Multigraph'),
'base' => 'multigraph',
'description' => t('Use <i>multigraphs</i> to create interactive graph content with Multigraph.'),
'has_title' => TRUE,
'title_label' => t('Title'),
'help' => t('Enter a title, description, width, height, and the MUGL (xml) for a Multigraph.'),
),
);
}
function multigraph_menu() {
$items['multigraph/mugl/%'] = array(
'title' => 'MUGL SERVICE URI',
'type' => MENU_CALLBACK,
'page callback' => '_multigraph_muglservice_controller',
'page arguments' => array(2),
'access callback' => TRUE,
);
return $items;
}
function _multigraph_muglservice_controller($nid) {
$node = node_load($nid);
if (!$node || $node->type != 'multigraph') {
$mugl = 'What?';
} else {
$mugl = $node->field_multigraph_mugl['und']['0']['value'];
}
header('Content-type: text/xml');
print $mugl;
exit();
}
/*
function _multigraph_string_ends_with($string, $suffix) {
$suffix_len = strlen($suffix);
$string_len = strlen($string);
for ($i=1; $i<=$suffix_len; ++$i) {
if ($string[$string_len-$i] != $suffix[$suffix_len-$i]) {
return false;
}
}
return true;
}
*/
/**
* Implement hook_form() with the standard default form.
*/
function multigraph_form($node, $form_state) {
$form = node_content_form($node, $form_state);
return $form;
}
function multigraph_form_alter(&$form, $form_state, $form_id) {
if ($form_id == 'multigraph_node_form') {
if ((count($form['field_multigraph_swf']['und']['#default_value']) <= 0)
||
(!in_array($form['field_multigraph_swf']['und']['#default_value']['0'],
$form['field_multigraph_swf']['und']['#options']))) {
$swf_paths = _multigraph_available_swf_paths('multigraph');
if (count($swf_paths) <= 0) {
drupal_set_message("This site's multigraph package has not yet been set up with a copy of the Multigraph SWF file. See the README.txt file in the multigraph package directory for instructions.", 'warning');
} else {
$form['field_multigraph_swf']['und']['#default_value'] = $swf_paths[count($swf_paths)-1];
}
}
}
}
/**
* Implementation of hook_menu_alter().
*/
function multigraph_menu_alter(&$callbacks) {
// If the user does not have 'administer nodes' permission,
// disable the multigraph menu item by setting its access callback to FALSE.
/*
?????????
sometimes the following user_access() returns false, even for the admin user, even
when the admin user DOES still have 'administer nodes' perm. WHY WHY WHY???
?????????
if (!user_access('administer nodes')) {
$callbacks['node/add/multigraph']['access callback'] = FALSE;
// Must unset access arguments or Drupal will use user_access()
// as a default access callback.
unset($callbacks['node/add/multigraph']['access arguments']);
}
*/
}
/**
* Implementation of hook_permission().
*/
function multigraph_permission() {
return array(
'create multigraph' => array(
'title' => t('Create a multigraph'),
'description' => t('Create a multigraph'),
),
'edit own multigraph' => array(
'title' => t('Edit own multigraph'),
'description' => t('Edit your own multigraph'),
),
'edit any multigraph' => array(
'title' => t('Edit any multigraph'),
'description' => t('Edit any multigraph'),
),
'delete own multigraph' => array(
'title' => t('Delete own multigraph'),
'description' => t('Delete own multigraph'),
),
'delete any multigraph' => array(
'title' => t('Delete any multigraph'),
'description' => t('Delete any multigraph'),
),
);
}
/**
* Implementation of hook_validate().
*/
/*
function multigraph_validate($node) {
// Enforce a minimum character count of 2 on company names.
// if (isset($node->multigraph_company) && strlen($node->multigraph_company['und'][0]['value']) < 2) {
// form_set_error('multigraph_company', t('The company name line of your multigraph is too short. You need at least 2 characters.'), $limit_validation_errors = NULL);
// }
}
*/
/**
* Implementation of hook_insert().
*/
/*
function multigraph_insert($node) {
// log details of the multigraphing to watchdog
// watchdog('multigraph', 'A new multigraph titled: '.$node->title.' for company: '.$node->multigraph_company['und'][0]['value'].' was added by UID: '.$node->uid, $variables = array(), WATCHDOG_NOTICE, $link = 'node/'.$node->nid);
}
*/
/**
* Implementation of hook_update().
*/
/*
function multigraph_update($node) {
// log details of the multigraphing to watchdog
// watchdog('multigraph', 'A multigraph titled: '.$node->title.' for company: '.$node->multigraph_company['und'][0]['value'].' was updated by UID: '.$node->uid, $variables = array(), WATCHDOG_NOTICE, $link = 'node/'.$node->nid);
}
*/
/**
* Implementation of hook_delete().
*/
/*
function multigraph_delete($node) {
// log details of the multigraphing to watchdog
// watchdog('multigraph', 'A multigraph titled: '.$node->title.' for company: '.$node->multigraph_company['und'][0]['value'].' was deleted by UID: '.$node->uid, $variables = array(), WATCHDOG_NOTICE, $link = 'node/'.$node->nid);
}
*/
/**
* Implementation of hook_load().
*/
/*
function multigraph_load($nodes) {
// Add a new element to the node at load time for storing the multigraphing sponsor information
// foreach ($nodes as $node) {
// $node->sponsor = "ACME Career Services, Your Source for Drupal Jobs";
// }
// return $node;
}
*/
/**
* Implement hook_view().
*/
function multigraph_view($node, $view_mode) {
if ($view_mode == 'full') {
$width = $node->field_multigraph_width['und']['0']['value'];
$height = $node->field_multigraph_height['und']['0']['value'];
$swf = $node->field_multigraph_swf['und']['0']['value'];
$node->content['graph'] = array(
'#markup' => theme('graph',
array('nid' => $node->nid,
'mugl' => $node->field_multigraph_mugl['und']['0']['value'],
'width' => $node->field_multigraph_width['und']['0']['value'],
'height' => $node->field_multigraph_height['und']['0']['value'],
'swf' => $node->field_multigraph_swf['und']['0']['value'],
'flashcode' => _multigraph_object_embed_string($width,$height,
base_path()
. "multigraph/mugl/" . $node->nid,
base_path()
. drupal_get_path('module', 'multigraph')
. "/multigraph/"
. $swf))
),
'#weight' => 0,
);
unset($node->field_multigraph_mugl);
}
return $node;
}
/**
* Implementation of hook_theme().
*/
function multigraph_theme() {
return array(
'graph' => array('variables' => array('nid' => NULL,
'mugl' => NULL,
'width' => NULL,
'height' => NULL,
'swf' => NULL,
'flashcode' => NULL),
'template' => 'graph',
),
);
}