| [ Index ] |
PHP Cross Reference of Drupal 6 (gatewave) |
[Summary view] [Print] [Text view]
1 <?php 2 // $Id: dialog_example.module,v 1.1.2.1 2011/01/31 20:57:05 drewish Exp $ 3 4 /** 5 * Implementation of hook_menu(). 6 */ 7 function dialog_example_menu() { 8 $items['dialog/example'] = array( 9 'title' => 'Dialog example', 10 'page callback' => 'dialog_example_page', 11 'access arguments' => array('access content'), 12 ); 13 $items['dialog/%ctools_js/example'] = array( 14 'type' => MENU_CALLBACK, 15 'page callback' => 'dialog_example_ajax_callback', 16 'page arguments' => array(1), 17 'access arguments' => array('access content'), 18 ); 19 20 $items['user/login/%ctools_js'] = array( 21 'page callback' => 'dialog_login_callback', 22 'page arguments' => array(1, 2), 23 'access arguments' => array('access content'), 24 'type' => MENU_CALLBACK, 25 ); 26 27 $items['user/register/%ctools_js'] = array( 28 'page callback' => 'dialog_login_callback', 29 'page arguments' => array(1, 2), 30 'access arguments' => array('access content'), 31 'type' => MENU_CALLBACK, 32 ); 33 34 return $items; 35 } 36 37 function dialog_example_page() { 38 global $user; 39 40 dialog_add_js(); 41 $links = array(); 42 $links[] = l('Simple test', 'dialog/nojs/example', array('attributes' => array('class' => 'ctools-use-dialog'))); 43 if (!$user->uid) { 44 $links[] = l('User login', 'user/login/nojs', array('attributes' => array('class' => 'ctools-use-dialog'))); 45 $links[] = l('User registration', 'user/register/nojs', array('attributes' => array('class' => 'ctools-use-dialog'))); 46 } 47 else { 48 $links[] = l(t('Logout'), 'logout', array('@logout' => url('logout', array('query' => array('destination' => 'dialog/example'))))); 49 } 50 51 return theme('item_list', $links); 52 } 53 54 function dialog_example_ajax_callback($ajax = FALSE) { 55 if ($ajax) { 56 $options = array( 57 'height' => rand(25, 75) . '%', 58 'width' => rand(25, 75) . '%', 59 'position' => 'center', 60 ); 61 dialog_ajax_render('test', dialog_example_page(), $options); 62 return; 63 } 64 65 return 'hello world'; 66 } 67 68 /** 69 * Menu callback for our ajax links. 70 */ 71 function dialog_login_callback($type, $js) { 72 switch ($type) { 73 case 'login': 74 $title = t('Login'); 75 $form_id = 'user_login'; 76 $msg = 'You are now logged in.'; 77 break; 78 case 'register': 79 $title = t('Register'); 80 $form_id = 'user_register'; 81 $msg = 'You are now registered.'; 82 break; 83 } 84 85 if ($js) { 86 ctools_include('ajax'); 87 $form_state = array( 88 'ajax' => TRUE, 89 'title' => $title, 90 ); 91 $output = dialog_form_wrapper($form_id, $form_state); 92 if (empty($output)) { 93 $output[] = dialog_command_display('Welcome', $msg); 94 $output[] = ctools_ajax_command_redirect('user'); 95 } 96 else { 97 foreach ($output as $i => $command) { 98 if ($command['command'] == 'dialog_display') { 99 $output[$i]['options']['height'] = 'auto'; 100 $output[$i]['options']['width'] = 600; 101 102 $output[$i]['options']['position'] = 'center'; 103 $output[$i]['options']['resizable'] = FALSE; 104 } 105 } 106 } 107 ctools_ajax_render($output); 108 } 109 else { 110 return drupal_get_form($form_id); 111 } 112 } 113 114 function dialog_example_form_alter(&$form, $form_state, $form_id) { 115 if ($form_id == 'user_login' && !empty($form_state['ajax'])) { 116 $form['submit']['#attributes']['class'] = 'ctools-dialog-button'; 117 } 118 elseif ($form_id == 'user_register' && !empty($form_state['ajax'])) { 119 $form['submit']['#attributes']['class'] = 'ctools-dialog-button'; 120 } 121 122 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Thu Mar 24 11:18:33 2011 | Cross-referenced by PHPXref 0.7 |