/[drupal]/contributions/modules/actionapps/aaview.module
ViewVC logotype

Contents of /contributions/modules/actionapps/aaview.module

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


Revision 1.1 - (show annotations) (download) (as text)
Thu Apr 12 16:29:34 2007 UTC (2 years, 7 months ago) by miiimooo
Branch: MAIN
CVS Tags: HEAD
File MIME type: text/x-php
belated initial commit of the two actionapps modules. they are prototype modules demonstrating integration of ActionApps and Drupal
1 <?php
2 // $Id$
3 /**
4 *
5 * aaview drupal module
6 * basic actionapps view level integration
7 * developed for the actionkit project
8 *
9 * (C)2006 Michael Moritz mimo/at/gn.apc.org
10 * version 0.1 2006/08
11 *
12 */
13
14 define(AAVIEW_VERSION,'0.1');
15 define(DEFAULT_AA_PATH,$_SERVER["DOCUMENT_ROOT"] . "/apc-aa");
16 define(AA_CONFIG_FILE,"/include/config.php3");
17 define(AAVIEW_DEBUG,TRUE);
18 /**
19 * Display debug info
20 * @param section which section of the site we're displaying help
21 * @return help text for section
22 */
23 function _d() {
24 if(defined('AAVIEW_DEBUG')) {
25 foreach(func_get_args() as $arg)
26 drupal_set_message(var_export($arg,TRUE));
27 }
28 }
29 function aaview_menu($maycache) {
30 $items = array();
31
32 if ($maycache) {
33 $items[] = array('path' => 'admin/aaview',
34 'title' => t('aaview'),
35 'callback' => 'aaview_admin',
36 'access' => user_access('administer aaview'),
37 'type' => MENU_DYNAMIC_ITEM);
38
39
40 $items[] = array(
41 'path' => 'aaview/selects/slice',
42 'title' => t('configure aaview block'),
43 'access' => user_access('access content'),
44 'callback' => '_aaview_selects_slice',
45 'type' => MENU_CALLBACK,
46 );
47 $items[] = array(
48 'path' => 'aaview/selects/view',
49 'title' => t('configure aaview block'),
50 'access' => user_access('access content'),
51 'callback' => '_aaview_selects_view',
52 'type' => MENU_CALLBACK,
53 );
54
55 /* $items[] = array(
56 'path' => 'aaview/select',
57 'title' => t('Drop down menus'),
58 'access' => user_access('access content'),
59 'type' => MENU_DEFAULT_LOCAL_TASK,
60 );
61 */
62 /* $items[] = array(
63 'path' => 'aaview/texts',
64 'title' => t('Text fields'),
65 'access' => user_access('access content'),
66 'callback' => 'aaview_page',
67 'type' => MENU_LOCAL_TASK,
68 'weight' => 1,
69 ); */
70 }
71 return $items;
72 }
73
74 /**
75 * Callback handler for select changes
76 * @return form output
77 */
78 function _aaview_selects_slice() {
79 // Globals provided by the activeforms module
80 global $activeforms_is_ajax, $activeforms_values, $activeforms_element;
81
82 /** get the form array **/
83 $form = _aaview_configure();
84 /// when slice changes reset view
85 $form['mms']['view']['#default_value'] = -1;
86 return drupal_get_form('aaview_block_admin_configure', $form);
87 }
88 /**
89 * Callback handler for select changes
90 * @return form output
91 */
92 function _aaview_selects_view() {
93 // Globals provided by the activeforms module
94 global $activeforms_is_ajax, $activeforms_values, $activeforms_element;
95
96 /** get the form array **/
97 $form = _aaview_configure();
98 return drupal_get_form('aaview_block_admin_configure', $form);
99 }
100
101 /**
102 * Display help and module information
103 * @param section which section of the site we're displaying help
104 * @return help text for section
105 */
106 function aaview_help($section='') {
107
108 $output = '';
109 switch ($section) {
110 case "admin/modules#description":
111 $output = t("Displays ActionApps View");
112 break;
113 }
114
115 return $output;
116 }
117
118 /**
119 * Valid permissions for this module
120 * @return array An array of valid permissions for the aaview module
121 */
122 function aaview_perm() {
123 // return array('access content');
124 return array('administer aaview');
125 }
126 /**
127 * Build the aaview_block slice and view selection form
128 * @param delta some wierd drupal thing
129 * @returns a form array
130 */
131 function _aaview_save($delta,$edit=array()) {
132 // drupal_set_message(var_export($edit,TRUE));
133 $var_path = "aaview_block_".$delta."_";
134 variable_set($var_path.'slice', $edit['slice']);
135 variable_set($var_path.'view', $edit['view']);
136 variable_set($var_path.'params', $edit['params']);
137 }
138 /**
139 * Build the aaview_block slice and view selection form
140 * @param delta some wierd drupal thing
141 * @returns a form array
142 */
143
144 function _aaview_configure($delta=0,$edit=array()) {
145
146 // Globals provided by the activeforms module
147 global $activeforms_is_ajax, $activeforms_values, $activeforms_element;
148
149 $have_activeforms = module_exist('activeforms');
150 if(!$have_activeforms) {
151 form_set_error('', t("aaview requires the activeforms module"));
152 return;
153 }
154
155 // drupal_set_message(var_export($edit,TRUE));
156 $var_path = "aaview_block_".$delta."_";
157 $aapath = variable_get('aaview_installation_path','');
158 $valid = _aaview_validate_aa_path($aapath);
159 if( $valid !== true ) {
160 form_set_error('', $valid);
161 return;
162 }
163 $slices = _aa_get_slices_list();
164 $selected_slice = ($activeforms_is_ajax && isset($activeforms_values['slice']['value'])) ? $activeforms_values['slice']['value'] : -1;
165 // if($selected_slice != variable_get($var_path.'slice','-1'))
166 // variable_set($var_path.'view', '-1');
167 $selected_slice = ($selected_slice == -1) ? variable_get($var_path.'slice','-1') : $selected_slice;
168 if($selected_slice == -1)
169 $slices = array_merge(array('-1' => t("Select an ActionApps slice")),$slices);
170
171
172 $form['mms']['slice'] = array(
173 '#type' => 'select',
174 '#title' => t('Slice'),
175 '#default_value' => $selected_slice,
176 '#options' => $slices,
177 '#multiple' => FALSE,
178 '#required' => FALSE,
179 '#prefix' => '<span id="slice-wrapper">',
180 '#suffix' => '</span>',
181 // '#DANGEROUS_SKIP_CHECK' => TRUE,
182 );
183
184 $status[] = $slices[$selected_slice];
185
186 // if($selected_slice == -1)
187 // $form['mms']['slice']['#options'][-1] = t("select a slice");
188
189 $views = ($selected_slice == -1) ? array('-1'=>t("Select a slice first")) :_aa_get_views_list($selected_slice);
190
191 $form['mms']['view'] = array(
192 '#type' => 'select',
193 '#title' => t('View'),
194 '#default_value' => -1,
195 '#options' => $views,
196 '#multiple' => FALSE,
197 '#required' => FALSE,
198 '#prefix' => '<span id="view-wrapper">',
199 '#suffix' => '</span>',
200 /** necessary - otherwise drupal form validation is not happy **/
201 '#DANGEROUS_SKIP_CHECK' => TRUE,
202 );
203
204 $selected_view = $activeforms_is_ajax && isset($activeforms_values['view']['value']) ? $activeforms_values['view']['value'] : -1;
205 $selected_view = ($selected_view == -1) ? variable_get($var_path.'view','-1') : $selected_view;
206
207 $status[] = $views[$selected_view];
208
209 /* if($selected_view == -1)
210 $form['mms']['view']['#options'][-1] = t("select a view");*/
211
212 if($selected_slice == -1) {
213 $slices = array_merge(array('-1' => t("Select an ActionApps slice")),$slices);
214 $form['mms']['view']['#prefix'] .= '<span style="display: none">';
215 $form['mms']['view']['#suffix'] .= '</span>';
216 }
217 $form['mms']['view']['#default_value'] = $selected_view;
218
219 ksort($form['mms']['view']['#options']);
220
221 if(($selected_view == -1) || (count($form['mms']['view']['#options']) == 0))
222 $form['mms']['view']['#options'] = array_merge(array('-1' => t("Select an ActionApps view")),$form['mms']['view']['#options']);
223
224 $form['mms']['status'] = array(
225 '#type' => 'markup',
226 '#value' => theme('breadcrumb', $status),
227 '#prefix' => '<span id="status-wrapper">',
228 '#suffix' => '</span>',
229 );
230 $form['mms']['params'] = array(
231 '#type' => 'textfield',
232 '#title' => t('View Parameters'),
233 '#default_value' => variable_get($var_path.'params',''),
234 '#size' => 60,
235 '#maxlength' => 64,
236 '#description' => t('Parameters to pass onto the ActionApps view'),
237 '#prefix' => '<span id="params-wrapper">',
238 '#suffix' => '</span>',
239 );
240
241 if( ($selected_view == -1) || ($selected_slice == -1)) {
242 $form['mms']['params']['#prefix'] .= '<span style="display: none">';
243 $form['mms']['params']['#suffix'] .= '</span>';
244 }
245 $form['activeforms_definitions'] = array(
246 '#type' => 'activeforms',
247 '#listeners' => array(
248 'edit-slice' => array(
249 'onchange' => array(
250 /** Note the #uri - it define which drupal handler
251 will be called via POST when the value of the
252 select box changes */
253 '#uri' => url('aaview/selects/slice'),
254 '#targets' => array(
255 array(
256 'id' => 'view-wrapper',
257 'property' => 'innerHTML',
258 'render-path' => array('mms','view'),
259 ),
260 /* array(
261 'id' => 'series-wrapper',
262 'property' => 'innerHTML',
263 'render-path' => array('mms','series'),
264 ),*/
265 array(
266 'id' => 'status-wrapper',
267 'property' => 'innerHTML',
268 'value' => $form['mms']['status']['#value'],
269 ),
270 ),
271 '#passbacks' => array(
272 'edit-slice' => 'value',
273 ),
274 ),
275 ),
276 'edit-view' => array(
277 'onchange' => array(
278 '#uri' => url('aaview/selects/view'),
279 '#targets' => array(
280 array(
281 'id' => 'params-wrapper',
282 'property' => 'innerHTML',
283 'render-path' => array('mms', 'params'),
284 ),
285 array(
286 'id' => 'status-wrapper',
287 'property' => 'innerHTML',
288 'value' => $form['mms']['status']['#value'],
289 ),
290 ),
291 '#passbacks' => array(
292 'edit-slice' => 'value',
293 'edit-view' => 'value',
294 ),
295 ),
296 ),
297 ),
298 );
299
300 return $form;
301 }
302 /**
303 * aaview block handler
304 * @param op the operation from the URL
305 * @param delta offset
306 * @returns block HTML
307 */
308 function _view_error($msg)
309 {
310 $block['subject'] = 'aaview error';
311 $block['content'] = $mgs;
312 return $block;
313 }
314 /**
315 * aaview block handler
316 * @param op the operation from the URL
317 * @param delta offset
318 * @returns block HTML
319 */
320 function _aaview_view($delta,$edit) {
321 // subject,content
322 $var_path = "aaview_block_".$delta."_";
323
324 $aapath = variable_get('aaview_installation_path','');
325 $valid = _aaview_validate_aa_path($aapath);
326 if( $valid !== true )
327 return _view_error($valid);
328
329 $slice = variable_get($var_path.'slice',false);
330 if(!$slice)
331 return _view_error(t("no slice selected"));
332 $view = variable_get($var_path.'view',false);
333 if(!$view)
334 return _view_error(t("no view selected"));
335 $params = variable_get($var_path.'params',false);
336
337 $block['subject'] = "aaview";
338 $block['content'] = _aa_get_view($slice,$view,$params);
339 return $block;
340 }
341
342
343 /**
344 * aaview block handler
345 * @param op the operation from the URL
346 * @param delta offset
347 * @returns block HTML
348 */
349 function aaview_block($op='list',$delta=0,$edit = array()) {
350
351 // drupal_set_message(var_export(func_get_args(),TRUE));
352 switch($op) {
353 case "list":
354 $block[0]["info"] = t('ActionApps View');
355 return $block;
356 case 'configure':
357 return _aaview_configure($delta,$edit);
358 case 'view':
359 return _aaview_view($delta,$edit);
360 case 'save':
361 return _aaview_save($delta,$edit);
362 drupal_set_message(t('Your form has been saved.'));
363 break;
364
365 }
366 }
367 function aaview_activeselect($source, $targets, $string, $extra = NULL) {
368 if (empty($source) || empty($targets) || empty($string)) {
369 exit();
370 }
371 $targets = explode(',', $targets);
372 $output = array();
373
374 $array = activeselect_explode_values($string);
375
376 foreach ($targets as $target) {
377 $options = array();
378
379 $first_element = TRUE;
380 foreach ($array as $key => $value) {
381 $options[$key. '-'. $target]['value'] = $value. ' ('. $target. ')';
382
383 if ($first_element) {
384 $options[$key. '-'. $target]['selected'] = TRUE;
385 $first_element = FALSE;
386 }
387 else {
388 $options[$key. '-'. $target]['selected'] = FALSE;
389 }
390 }
391 $multiple = TRUE;
392
393 $output[$target] = array('options' => $options, 'multiple' => $multiple);
394 }
395
396 activeselect_set_header_nocache();
397
398 print drupal_to_js($output);
399 exit();
400 }
401
402
403 function aaview_admin() {
404
405 $edit = $_POST['edit'];
406 $op = $_POST['op'];
407 if (!$op) {
408 $op = arg(2);
409 }
410
411 switch ($op) {
412 default:
413 drupal_set_title(t('Drupal AA View Admin Panel'));
414 $output = aaview_admin_overview();
415 }
416
417 drupal_set_title($title);
418 return $output;
419 }
420
421 /**
422 * Default view of the admin Drupal AA View link.
423 *
424 */
425 function aaview_admin_overview() {
426 //Include the definitions and functions for drupalvb
427 //require_once('drupalvb.inc');
428
429 //Initialize drupalvb; set up $vbulletin and connects to the database
430 // $vblink = drupalvb_vb_init();
431
432 // global $vbulletin;
433
434 $style = array('style' => 'width:auto;');
435 $forversion = "4.7.0 RC 2";
436 $aaviewversion = AAVIEW_VERSION;
437 // $forum_name = variable_get('drupalvb_forum_name', '');
438
439 //Info table
440 $header = array(array("data" => t('Information'), 'colspan' => 2));
441 $row[] = array(array("data" => t("AA View version: "), 'align' => 'right', 'title' => t('version')), $aaviewversion);
442 $row[] = array(array("data" => t("For Drupal version: "), 'align' => 'right', 'title' => t('drupal')), $forversion);
443 $row[] = array(array("data" => t("ActionApps installation path: "), 'align' => 'right', 'title' => t('ActionApps path')), variable_get('aaview_installation_path', ''));
444
445 $output = "<p>" . theme("table", $header, $row, $style) . '<br />';
446 $row = null;
447
448 //Quick Links
449 $items = null;
450 // $items[] = l(t("View the View"), variable_get('drupalvb_forum_address', ''), array('target' => '_blank'));
451 $items[] = l(t("AA View Settings"), "admin/settings/aaview");
452 // $items[] = l(t("ActionApps Login"), variable_get('drupalvb_forum_address', '') . '/' . $vbulletin->config['Misc']['admincpdir'], array('target' => '_blank'));
453 // $items[] = l(t("Forum Moderator Control Panel"), variable_get('drupalvb_forum_address', '') . '/' . $vbulletin->config['Misc']['modcpdir'], array('target' => '_blank'));
454 $output .= theme_item_list($items, "Quick Links");
455
456 //Block configuration links
457 $items = null;
458 // $items[] = l(t("Forum Activity (recent posts)"), "admin/block/configure/drupalvb/0");
459 // $items[] = l(t("Forum Info (users online, new posts/PMs)"), "admin/block/configure/drupalvb/1");
460 // $items[] = l(t("Forum Admin (total posts/threads/members, active members)"), "admin/block/configure/drupalvb/2");
461 // $output .= theme_item_list($items, "Block Configuration");
462
463 //Features
464 $items = null;
465 // $items[] = "User creation/deletion in Drupal makes appropriate entries in vBulletin.";
466 // $items[] = "User login/logout cookie and session handling for vBulletin.";
467 // $items[] = "Account updates in Drupal make appropriate changes in vBulletin.";
468 // $items[] = "Three customizeable blocks for related vBulletin information";
469 // $items[] = "Configuration handled in Drupal is a snap.";
470 // $items[] = "Keep track of private messages from within Drupal.";
471 // $output .= theme_item_list($items, "Features");
472
473 // drupalvb_close($vblink);
474
475 return $output;
476 }
477 /**
478 * Implementation of hook_settings().
479 * - This data is compiled and outputted by the function below
480 */
481 function aaview_settings() {
482 //Include the definitions and functions for drupalvb
483 // require_once('drupalvb.inc');
484
485 $form['aaview_installation_path'] = array(
486 '#type' => 'textfield',
487 '#title' => t('ActionApps installation path'),
488 '#default_value' => variable_get('aaview_installation_path', DEFAULT_AA_PATH),
489 '#size' => 50,
490 '#maxlength' => 10000,
491 '#description' => t('The path to your ActionApps installation (AA_BASE_PATH)'),
492 );
493 return $form;
494 }
495 /**
496 * Validate settings input
497 *
498 * check if the AA config file exists
499 * use form_set_error if this is not a valid AA_BASE_DIR
500 *
501 */
502 function aaview_settings_form_validate($form_id, $form_values) {
503 if($form_id == 'aaview_settings_form') {
504 $valid = _aaview_validate_aa_path($form_values['aaview_installation_path']);
505 if($valid !== true ) {
506 form_set_error('aaview_installation_path', $valid);
507 }
508 }
509 }
510 /**
511 * Validate ActionApps installation path
512 * check whether the file include/config.php3 exists
513 */
514 function _aaview_validate_aa_path($path) {
515 if(!$path)
516 return t("ActionApps installation path not set.<br />Go to "). l(t("AA View Settings"), "admin/settings/aaview") . t(" to set this");
517 if(! file_exists($path.AA_CONFIG_FILE) ) {
518 // the var_dump(stat()) forces output of SAFE MODE retsrictions / OPEN BASEDIR etc.
519 return $path.AA_CONFIG_FILE." "
520 . t('does not point to an ActionApps installation.') .
521 var_dump(stat($path));
522 }
523 return true;
524 }
525 /**
526 * Return list of slices from ActionApps
527 * @return array of slice names/ids
528 */
529 function _aa_get_slices_list() {
530 require_once("actionapps.inc");
531 $aaInst = new AAInstall(variable_get('aaview_installation_path', '').AA_CONFIG_FILE);
532 return $aaInst->getArrayFromArray($aaInst->listSlices());
533 }
534 /**
535 * Return list of views in one ActionApps slice
536 * @param slice_id id of AA slice
537 * @return array of views/ids
538 */
539 function _aa_get_views_list($slice_id = -1) {
540 if($slice_id == -1)
541 return array();
542 $aaInst = new AAInstall(variable_get('aaview_installation_path', '').AA_CONFIG_FILE);
543 $views_in_slice = $aaInst->listViews($slice_id);
544 return $aaInst->getArrayFromArray($views_in_slice);
545 }
546 /**
547 * Return content of AA view (the HTML output)
548 * @param slice_id id of AA slice
549 * @param view_id id of AA view
550 * @param params view parameters
551 * @return array of views/ids
552 */
553 function _aa_get_view($slice_id,$view_id,$params) {
554 require_once("actionapps.inc");
555 $aaInst = new AAInstall(variable_get('aaview_installation_path', '').AA_CONFIG_FILE);
556 $view_content = $aaInst->getView($slice_id,$view_id,$params);
557 return $view_content;
558 }
559 ?>

  ViewVC Help
Powered by ViewVC 1.1.2