123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322 |
- <?php
- /**
- * @file
- * Page callbacks for the modal_forms module.
- */
- /*
- * A modal user login callback.
- */
- function modal_forms_login($js = NULL) {
- // Fall back if $js is not set.
- if (!$js) {
- return drupal_get_form('user_login');
- }
- ctools_include('modal');
- ctools_include('ajax');
- $form_state = array(
- // 'title' => t('Log in'),
- 'ajax' => TRUE,
- );
- $output = ctools_modal_form_wrapper('user_login', $form_state);
- if (!empty($form_state['executed'])) {
- // We'll just overwrite the form output if it was successful.
- $output = array();
- ctools_add_js('ajax-responder');
- $output[] = ctools_modal_command_dismiss(t('Login success'));
- if (isset($_GET['destination'])) {
- $output[] = ctools_ajax_command_redirect($_GET['destination']);
- }
- elseif(module_exists('login_destination')) {
- $destination = login_destination_get_destination('login');
- $output[] = ctools_ajax_command_redirect($destination['path']);
- }
- else {
- $output[] = ctools_ajax_command_reload();
- }
- }
- print ajax_render($output);
- }
- /**
- * A modal user register callback.
- */
- function modal_forms_register($js = NULL) {
- // Fall back if $js is not set.
- if (!$js) {
- return drupal_get_form('user_register_form');
- }
- ctools_include('modal');
- ctools_include('ajax');
- $form_state = array(
- // 'title' => t('Create new account'),
- 'ajax' => TRUE,
- );
- $output = ctools_modal_form_wrapper('user_register_form', $form_state);
- if (!empty($form_state['executed'])) {
- // We'll just overwrite the form output if it was successful.
- $output = array();
- ctools_add_js('ajax-responder');
- if (isset($_GET['destination'])) {
- $output[] = ctools_ajax_command_redirect($_GET['destination']);
- }
- elseif(module_exists('login_destination')) {
- $destination = login_destination_get_destination('login');
- $output[] = ctools_ajax_command_redirect($destination['path']);
- }
- else {
- $output[] = ctools_ajax_command_reload();
- }
- }
- print ajax_render($output);
- }
- /**
- * A modal user password callback.
- */
- function modal_forms_password($js = NULL) {
- module_load_include('inc', 'user', 'user.pages');
- // Fall back if $js is not set.
- if (!$js) {
- return drupal_get_form('user_pass');
- }
- ctools_include('modal');
- ctools_include('ajax');
- $form_state = array(
- // 'title' => t('Request new password'),
- 'ajax' => TRUE,
- );
- $output = ctools_modal_form_wrapper('user_pass', $form_state);
- if (!empty($form_state['executed'])) {
- // We'll just overwrite the form output if it was successful.
- $output = array();
- ctools_add_js('ajax-responder');
- if (isset($_GET['destination'])) {
- $output[] = ctools_ajax_command_redirect($_GET['destination']);
- }
- else {
- $output[] = ctools_ajax_command_reload();
- }
- }
- print ajax_render($output);
- }
- /**
- * A modal contact callback.
- */
- function modal_forms_contact($js = NULL) {
- module_load_include('inc', 'contact', 'contact.pages');
- // Fall back if $js is not set.
- if (!$js) {
- return drupal_get_form('contact_site_form');
- }
- ctools_include('modal');
- ctools_include('ajax');
- $form_state = array(
- // 'title' => t('Contact'),
- 'ajax' => TRUE,
- );
- $output = ctools_modal_form_wrapper('contact_site_form', $form_state);
- if (!empty($form_state['executed'])) {
- // We'll just overwrite the form output if it was successful.
- $output = array();
- ctools_add_js('ajax-responder');
- if (isset($_GET['destination'])) {
- $output[] = ctools_ajax_command_redirect($_GET['destination']);
- }
- else {
- $output[] = ctools_ajax_command_reload();
- }
- }
- print ajax_render($output);
- }
- /**
- * A modal personal contact form
- */
- function modal_forms_personal_contact($recipient, $js = NULL) {
- module_load_include('inc', 'contact', 'contact.pages');
- // Fall back if $js is not set.
- if (!$js) {
- return drupal_get_form('contact_personal_form', $recipient);
- }
- ctools_include('modal');
- ctools_include('ajax');
- $form_state = array(
- // 'title' => t('Contact'),
- 'build_info' => array(
- 'args' => array($recipient)
- ),
- 'ajax' => TRUE,
- );
- $output = ctools_modal_form_wrapper('contact_personal_form', $form_state);
- if (!empty($form_state['executed'])) {
- // We'll just overwrite the form output if it was successful.
- $output = array();
- ctools_add_js('ajax-responder');
- if (isset($_GET['destination'])) {
- $output[] = ctools_ajax_command_redirect($_GET['destination']);
- }
- else {
- $output[] = ctools_ajax_command_reload();
- }
- }
- print ajax_render($output);
- }
- /**
- * A modal comment callback.
- */
- function modal_forms_comment_reply($node, $js = NULL, $pid = NULL) {
- $output = array();
- $comment = array(
- 'pid' => $pid,
- 'nid' => $node->nid,
- );
- // Fall back if $js is not set.
- if (!$js) {
- return drupal_get_form('comment_node_' . $node->type . '_form', (object) $comment);
- }
- ctools_include('modal');
- ctools_include('ajax');
- $form_state = array(
- 'build_info' => array(
- 'args' => array(
- (object) $comment,
- ),
- ),
- // 'title' => t('Comment'),
- 'ajax' => TRUE,
- 're_render' => FALSE,
- 'no_redirect' => TRUE,
- );
- // Should we show the reply box?
- if ($node->comment != COMMENT_NODE_OPEN) {
- drupal_set_message(t('This discussion is closed: you can\'t post new comments.'), 'error');
- drupal_goto('node/' . $node->nid);
- }
- else {
- $output = drupal_build_form('comment_node_' . $node->type . '_form', $form_state);
- // Remove output bellow the comment.
- unset($output['comment_output_below']);
- }
- if (!$form_state['executed'] || $form_state['rebuild']) {
- $output = ctools_modal_form_render($form_state, $output);
- }
- else {
- // We'll just overwrite the form output if it was successful.
- $output = array();
- // @todo: Uncomment once http://drupal.org/node/1587916 is fixed.
- //if (is_array($form_state['redirect'])) {
- // list($path, $options) = $form_state['redirect'];
- // $output[] = ctools_ajax_command_redirect($path, 0, $options);
- //}
- if (isset($_GET['destination'])) {
- $output[] = ctools_ajax_command_redirect($_GET['destination']);
- }
- else {
- $output[] = ctools_ajax_command_reload();
- }
- }
- print ajax_render($output);
- }
- /**
- * Modal display of the node's webform.
- *
- * @param $node
- * A node object.
- */
- function modal_forms_view_webform($node, $js = NULL) {
- $output = array();
- // Fall back if $js is not set.
- if (!$js) {
- return drupal_get_form('webform_client_form_' . $node->nid, $node, FALSE);
- }
- ctools_include('modal');
- ctools_include('ajax');
- if (empty($node->webform['components'])) {
- // No webform or no components.
- $output[] = ctools_modal_command_display(t('Webform'), t('No webform found.'));
- print ajax_render($output);
- exit;
- }
- // Get webform title.
- $title = check_plain($node->title);
- $form_state = array(
- 'title' => $title,
- 'ajax' => TRUE,
- );
- // Prevent webform redirect.
- $GLOBALS['conf']['webform_blocks']['client-block-' . $node->nid]['pages_block'] = 1;
- $node->webform_block = TRUE;
- // Pass required parameters.
- $form_state['build_info']['args'] = array($node, FALSE);
- // Render the Webform.
- $output = ctools_modal_form_wrapper('webform_client_form_' . $node->nid, $form_state);
- if (!empty($form_state['executed'])) {
- if (!isset($form_state['storage'])) {
- ctools_add_js('ajax-responder');
- // Handle confirmation message or redirect.
- if ('<confirmation>' == $node->webform['redirect_url']) {
- // Use confirmation message if set, default text otherwise.
- // See webform/templates/webform-confirmation.tpl.php.
- $message = (empty($node->webform['confirmation'])) ? t('Thank you, your submission has been received.') : check_markup($node->webform['confirmation'], $node->webform['confirmation_format'], '', TRUE);
- $confirmation = '<div class="webform-confirmation">' . $message . '</div>';
- $confirmation .= ctools_ajax_text_button(t('Close'), 'modal_forms/nojs/dismiss', t('Close'));
- $output[] = ctools_modal_command_display($title, $confirmation);
- }
- elseif ('<none>' == $node->webform['redirect_url']) {
- // Reload webform node itself.
- $output[] = ctools_ajax_command_reload();
- }
- else {
- // Redirect to URL.
- // Note: Redirect code in webform_client_form_submit() is more complex.
- $url = trim(ltrim($node->webform['redirect_url'], '/'));
- $output[] = ctools_ajax_command_redirect($url);
- }
- }
- }
- print ajax_render($output);
- }
- /**
- * Closes modal windows.
- */
- function modal_forms_dismiss($js = NULL) {
- if (!$js) {
- // we should never be here out of ajax context
- return MENU_NOT_FOUND;
- }
- ctools_include('modal');
- ctools_include('ajax');
- $output = array(ctools_modal_command_dismiss());
- print ajax_render($output);
- }
|