Projet

Général

Profil

Révision 01f36513

Ajouté par Assos Assos il y a environ 6 ans

Weekly update of contrib modules

Voir les différences:

drupal7/sites/all/modules/webform/webform.module
454 454
}
455 455

  
456 456
/**
457
 * Menu LOADERNAME_to_arg callback. Determines the arguments used to generate a
458
 * menu link.
457
 * Menu LOADERNAME_to_arg callback.
458
 *
459
 * Determines the arguments used to generate a menu link.
459 460
 *
460 461
 * This is implemented only to give the webform_localization modules an
461 462
 * opportunity to link to the orignial webform from the localized one. See
......
472 473
 * @return string
473 474
 *   The $arg, modified as desired.
474 475
 */
475
function webform_menu_to_arg($arg, $map, $index) {
476
function webform_menu_to_arg($arg, array $map, $index) {
476 477
  return function_exists('webform_localization_webform_menu_to_arg')
477 478
          ? webform_localization_webform_menu_to_arg($arg, $map, $index)
478 479
          : $arg;
......
617 618
 *   The webform submission object.
618 619
 * @param object $op
619 620
 *   The operation to perform. Must be one of view, edit, delete, list.
620
 * @param array $account
621
 * @param object $account
621 622
 *   Optional. A user object or NULL to use the currently logged-in user.
622 623
 *
623 624
 * @return bool
......
654 655
      return $module_access || $general_access;
655 656

  
656 657
    case 'edit':
657
      return $module_access || ($general_access && (user_access('edit all webform submissions', $account) || (user_access('edit own webform submissions', $account) && $account->uid == $submission->uid)));
658

  
659 658
    case 'delete':
660
      return $module_access || ($general_access && (user_access('delete all webform submissions', $account) || (user_access('delete own webform submissions', $account) && $account->uid == $submission->uid)));
659
      return $module_access || (
660
        $general_access && (
661
          user_access($op . ' all webform submissions', $account) || (
662
            user_access($op . ' own webform submissions', $account) &&
663
            $account->uid == $submission->uid
664
          )
665
        )
666
      );
661 667

  
662 668
    case 'list':
663
      return $module_access || user_access('access all webform results', $account) || (user_access('access own webform submissions', $account) && ($account->uid || isset($_SESSION['webform_submission']))) || (user_access('access own webform results', $account) && $account->uid == $node->uid);
669
      return $module_access ||
670
        user_access('access all webform results', $account) || (
671
          user_access('access own webform submissions', $account) && (
672
            $account->uid ||
673
            isset($_SESSION['webform_submission'])
674
          )
675
        ) || (
676
          user_access('access own webform results', $account) &&
677
          $account->uid == $node->uid
678
        );
664 679
  }
665 680
}
666 681

  
......
677 692
}
678 693

  
679 694
/**
680
 * Menu access callback. Ensure a user has both results access and permission
681
 * to clear submissions.
695
 * Menu access callback.
696
 *
697
 * Ensure a user has both results access and permission to clear submissions.
682 698
 */
683 699
function webform_results_clear_access($node, $account = NULL) {
684 700
  global $user;
......
693 709
 * Menu access callback. Ensure a sure has access to update a webform node.
694 710
 *
695 711
 * Unlike webform_results_access and webform_results_clear_access, access is
696
 * completely overridden by the any implementation of hook_webform_update_access.
712
 * completely overridden by the any implementation of
713
 * hook_webform_update_access.
697 714
 *
698 715
 * If hook_webform_update_access is implemented by one or more other modules,
699 716
 * the results must be unanimously TRUE for access to be granted; otherwise it
......
1787 1804
  }
1788 1805

  
1789 1806
  // Load the components, emails, and defaults for all webform-enabled nodes.
1790
  // TODO: Increase efficiency here by pulling in all information all at once
1807
  // @todo: Increase efficiency here by pulling in all information all at once
1791 1808
  // instead of individual queries.
1792 1809
  foreach ($nodes as $nid => $node) {
1793 1810
    if (!in_array($node->type, $webform_types)) {
......
2018 2035
    // This prevents one anonymous user from generated a disabled webform page
2019 2036
    // for the cache, which would be shown to other anonymous users who have not
2020 2037
    // exceeded the limit.
2021
    if (($user_limit_exceeded = webform_submission_user_limit_check($node)) && !$cached) {
2038
    // Cached should be checked first to avoid the expensive limit check on
2039
    // cached requests.
2040
    if (!$cached && ($user_limit_exceeded = webform_submission_user_limit_check($node))) {
2022 2041
      $enabled = FALSE;
2023 2042
    }
2024 2043
  }
......
2132 2151
/**
2133 2152
 * Output the Webform into the node content.
2134 2153
 *
2135
 * @param object $node
2136
 *   The webform node object.
2137
 * @param object $page
2138
 *   If this webform node is being viewed as the main content of the page.
2139
 * @param array $form
2140
 *   The rendered form.
2141
 * @param $enabled
2142
 *   If the form allowed to be completed by the current user.
2154
 * @param array $variables
2155
 *   The variables array.
2143 2156
 *
2144 2157
 * @return string
2158
 *   The rendered Webform.
2145 2159
 */
2146
function theme_webform_view($variables) {
2160
function theme_webform_view(array $variables) {
2147 2161
  // Only show the form if this user is allowed access.
2148 2162
  if ($variables['webform']['#enabled']) {
2149 2163
    return drupal_render($variables['webform']['#form']);
......
2153 2167
/**
2154 2168
 * Display a message to a user if they are not allowed to fill out a form.
2155 2169
 *
2156
 * @param object $node
2157
 *   The webform node object.
2158
 * @param $page
2159
 *   If this webform node is being viewed as the main content of the page.
2160
 * @param $submission_count
2161
 *   The number of submissions this user has already submitted. Not calculated
2162
 *   for anonymous users.
2163
 * @param $user_limit_exceeded
2164
 *   Boolean value if the submission limit for this user has been exceeded.
2165
 * @param $total_limit_exceeded
2166
 *   Boolean value if the total submission limit has been exceeded.
2167
 * @param $allowed_roles
2168
 *   A list of user roles that are allowed to submit this webform.
2169
 * @param $closed
2170
 *   Boolean value if submissions are closed.
2171
 */
2172
function theme_webform_view_messages($variables) {
2170
 * @param array $variables
2171
 *   The variables array.
2172
 */
2173
function theme_webform_view_messages(array $variables) {
2173 2174
  global $user;
2174 2175

  
2175 2176
  $node = $variables['node'];
......
2466 2467
}
2467 2468

  
2468 2469
/**
2469
 * Client form generation function. If this is displaying an existing
2470
 * submission, pass in the $submission variable with the contents of the
2471
 * submission to be displayed.
2470
 * Client form generation function.
2471
 *
2472
 * If this is displaying an existing submission, pass in the $submission
2473
 * variable with the contents of the submission to be displayed.
2472 2474
 *
2473 2475
 * @param $form
2474 2476
 *   The current form array (always empty).
......
2614 2616
    // validated page.
2615 2617
    if (!isset($form_state['storage']['page_num']) && $submission && $submission->is_draft && $submission->highest_valid_page) {
2616 2618
      // Find the
2617
      //    1) previous/next non-empty page, or
2618
      //    2) the preview page, or
2619
      //    3) the preview page, forcing its display if the form would unexpectedly submit, or
2620
      //    4) page 1 even if empty, if no other previous page would be shown.
2619
      //   1) previous/next non-empty page, or
2620
      //   2) the preview page, or
2621
      //   3) the preview page, forcing its display if the form would
2622
      //      unexpectedly submit, or
2623
      //   4) page 1 even if empty, if no other previous page would be shown.
2621 2624
      $form_state['webform']['page_num'] = $submission->highest_valid_page;
2622 2625
      do {
2623 2626
        $form_state['webform']['page_num']++;
......
2627 2630
        $form_state['webform']['preview'] = TRUE;
2628 2631
        $form_state['webform']['page_count']++;
2629 2632
      }
2630
      // The form hasn't been submitted (ever) and the preview code will
2631
      // expect $form_state['values']['submitted'] to be set from a previous
2633
      // The form hasn't been submitted (ever) and the preview code will expect
2634
      // $form_state['values']['submitted'] to be set from a previous
2632 2635
      // submission, so provide these values here.
2633 2636
      $form_state['values']['submitted'] = $input_values;
2634 2637
      $form_state['storage']['submitted'] = $input_values;
......
2652 2655
      );
2653 2656
    }
2654 2657

  
2655
    // Check whether a previous submission was truncated. The length of the client form is not
2656
    // estimated before submission because a) the determination may not be accurate for some
2657
    // webform components and b) the error will be apparent upon submission.
2658
    // Check whether a previous submission was truncated. The length of the
2659
    // client form is not estimated before submission because a) the
2660
    // determination may not be accurate for some webform components and b) the
2661
    // error will be apparent upon submission.
2658 2662
    webform_input_vars_check($form, $form_state, 'submitted');
2659 2663

  
2660 2664
    // Recursively add components to the form. The unfiltered version of the
......
2947 2951
 * upon form submission.
2948 2952
 */
2949 2953
function webform_client_form_prevalidate($form, &$form_state) {
2950
  // Refresh the node in case it changed since the form was build and retrieved from cache.
2954
  // Refresh the node in case it changed since the form was build and retrieved
2955
  // from cache.
2951 2956
  $node = $form['#node'] = node_load($form['#node']->nid);
2952 2957
  $finished = $form_state['values']['details']['finished'];
2953 2958

  
......
2977 2982
  // is no submission yet (hence isn't being edited) or the user isn't an admin.
2978 2983
  // Another way to consider this is that the form is open when its status is
2979 2984
  // open OR there is a submission and the user is an admin.
2980
  $closed = empty($node->webform['status']) && (empty($form['#submission']) || !user_access('edit all webform submissions'));
2985
  $closed = empty($node->webform['status']) && (
2986
    empty($form['#submission']) ||
2987
    !user_access('edit all webform submissions')
2988
  );
2981 2989

  
2982 2990
  // Prevent submission by throwing an error.
2983 2991
  if ((!$allowed_role || $total_limit_exceeded || $user_limit_exceeded || $closed)) {
......
3194 3202
  $nid = $form_state['values']['details']['nid'];
3195 3203
  $node = node_load($nid);
3196 3204
  if (user_is_logged_in() &&
3197
      $errors && !key_exists('', $errors) &&
3205
      $errors && !array_key_exists('', $errors) &&
3198 3206
      $node->webform['auto_save'] &&
3199 3207
      !$form_state['values']['details']['finished'] &&
3200 3208
      !empty($form_state['values']['op'])) {
......
3290 3298

  
3291 3299
    if (isset($forward)) {
3292 3300
      // Find the
3293
      //    1) previous/next non-empty page, or
3294
      //    2) the preview page, or
3295
      //    3) the preview page, forcing its display if the form would unexpectedly submit, or
3296
      //    4) page 1 even if empty, if no other previous page would be shown.
3301
      //   1) previous/next non-empty page, or
3302
      //   2) the preview page, or
3303
      //   3) the preview page, forcing its display if the form would
3304
      //      unexpectedly submit, or
3305
      //   4) page 1 even if empty, if no other previous page would be shown.
3297 3306
      $preview_page_num = $form_state['storage']['page_count'] + (int) !$form_state['webform']['preview'];
3298 3307
      $page_num = $current_page;
3299 3308
      do {
......
3914 3923
/**
3915 3924
 * Theme the headers when sending an email from webform.
3916 3925
 *
3917
 * @param object $node
3918
 *   The complete node object for the webform.
3919
 * @param $submission
3920
 *   The webform submission of the user.
3921
 * @param $email
3922
 *   If you desire to make different e-mail headers depending on the recipient,
3923
 *   you can check the $email['email'] property to output different content.
3924
 *   This will be the ID of the component that is a conditional e-mail
3925
 *   recipient. For the normal e-mails, it will have the value of 'default'.
3926
 * @param array $variables
3927
 *   The variables array.
3926 3928
 *
3927
 * @return
3929
 * @return array
3928 3930
 *   An array of headers to be used when sending a webform email. If headers
3929 3931
 *   for "From", "To", or "Subject" are set, they will take precedence over
3930 3932
 *   the values set in the webform configuration.
3931 3933
 */
3932
function theme_webform_mail_headers($variables) {
3934
function theme_webform_mail_headers(array $variables) {
3933 3935
  $headers = array(
3934
    'X-Mailer' => 'Drupal Webform (PHP/' . phpversion() . ')',
3936
    'X-Mailer' => 'Drupal Webform' . (ini_get('expose_php') ? ' (PHP/' . phpversion() . ')' : ''),
3935 3937
  );
3936 3938
  return $headers;
3937 3939
}
......
4160 4162
 * @param object $node
4161 4163
 *   The node object to check if a database entry exists.
4162 4164
 *
4163
 * @return
4165
 * @return bool
4164 4166
 *   This function should always return TRUE if no errors were encountered,
4165 4167
 *   ensuring that a webform table row has been created. Will return FALSE if
4166 4168
 *   a record does not exist and a new one could not be created.
......
4186 4188
 * @param object $node
4187 4189
 *   The node object to check if a database entry is still required.
4188 4190
 *
4189
 * @return
4191
 * @return bool
4190 4192
 *   Returns TRUE if the webform still has a record in the database. Returns
4191 4193
 *   FALSE if the webform does not have a record or if the previously existing
4192 4194
 *   record was just deleted.
......
4220 4222
 * @return int|int[]
4221 4223
 *   The cid of the component or an array of component ids.
4222 4224
 */
4223
function webform_get_cid(&$node, $form_key, $pid = NULL) {
4225
function webform_get_cid($node, $form_key, $pid = NULL) {
4224 4226
  if ($pid === NULL) {
4225 4227
    $cids = array();
4226 4228
    foreach ($node->webform['components'] as $cid => $component) {
......
4416 4418
    return '';
4417 4419
  }
4418 4420
  $groups = $variables['groups'];
4419
  module_load_include('inc', 'token', 'token.pages');
4420 4421

  
4421 4422
  // Assume dialogs are not supported, show as a fieldset.
4422 4423
  $help = array(
......
4439 4440
    $help['help']['#markup'] .= '<p>' . t('A full listing of tokens may be listed here by installing the <a href="http://drupal.org/project/token">Token module</a>.') . '</p>';
4440 4441
    unset($help['token_tree']);
4441 4442
  }
4442
  elseif (function_exists('token_page_output_tree')) {
4443
    // Token supports dialogs: display simply as a link.
4444
    $help = $help['token_tree'];
4445
    $help['#dialog'] = TRUE;
4443
  else {
4444
    module_load_include('inc', 'token', 'token.pages');
4445
    if (function_exists('token_page_output_tree')) {
4446
      // Token supports dialogs: display simply as a link.
4447
      $help = $help['token_tree'];
4448
      $help['#dialog'] = TRUE;
4449
    }
4446 4450
  }
4447 4451

  
4448 4452
  return render($help);
4449 4453
}
4450 4454

  
4451 4455
/**
4452
 * Convert a name into an identifier that is safe for machine names, classes,
4453
 * and other ASCII uses.
4456
 * Convert a name into an identifier.
4457
 *
4458
 * The identifier is safe for machine names, classes, and other ASCII uses.
4454 4459
 */
4455 4460
function _webform_safe_name($name) {
4456 4461
  $new = trim($name);
......
4887 4892
 *   The callback to check.
4888 4893
 *
4889 4894
 * @return bool
4895
 *   Whether or not the hook is implemented.
4890 4896
 */
4891 4897
function webform_component_implements($type, $callback) {
4892 4898
  $function = '_webform_' . $callback . '_' . $type;
......
5091 5097
 * @return string
5092 5098
 *   A date/time format string.
5093 5099
 */
5094
function webform_date_format($type = NULL, $exclude = array()) {
5100
function webform_date_format($type = NULL, array $exclude = array()) {
5095 5101
  static $formats = array();
5096 5102
  $id = $type . ':' . implode('', $exclude);
5097 5103
  if (!isset($formats[$id])) {
......
5262 5268
  return $extra;
5263 5269
}
5264 5270

  
5265
/**
5266
 * Implements hook_mollom_form_list().
5267
 */
5268
function webform_mollom_form_list() {
5269
  $forms = array();
5270
  $webform_types = webform_node_types();
5271
  if (empty($webform_types)) {
5272
    return $forms;
5273
  }
5274

  
5275
  $query = db_select('webform', 'w');
5276
  $query->innerJoin('node', 'n', 'n.nid = w.nid');
5277
  $query->fields('n', array('nid', 'title'));
5278
  $query->condition('n.type', $webform_types, 'IN');
5279
  $result = $query->execute();
5280

  
5281
  foreach ($result as $node) {
5282
    $form_id = 'webform_client_form_' . $node->nid;
5283
    $forms[$form_id] = array(
5284
      'title' => t('@name form', array('@name' => $node->title)),
5285
      'entity' => 'webform',
5286
      'delete form' => 'webform_submission_delete_form',
5287
    );
5288
  }
5289
  return $forms;
5290
}
5291

  
5292
/**
5293
 * Implements hook_mollom_form_info().
5294
 */
5295
function webform_mollom_form_info($form_id) {
5296
  module_load_include('inc', 'webform', 'includes/webform.components');
5297

  
5298
  $nid = drupal_substr($form_id, 20);
5299
  $node = node_load($nid);
5300
  $form_info = array(
5301
    'title' => t('@name form', array('@name' => $node->title)),
5302
    'mode' => MOLLOM_MODE_ANALYSIS,
5303
    'bypass access' => array('edit all webform submissions', 'edit any webform content'),
5304
    'entity' => 'webform',
5305
    'elements' => array(),
5306
    'mapping' => array(
5307
      'post_id' => 'details][sid',
5308
      'author_id' => 'details][uid',
5309
    ),
5310
  );
5311
  // Add components as elements.
5312
  // These components can be enabled for textual analysis (when not using a
5313
  // CAPTCHA-only protection) in Mollom's form configuration.
5314
  foreach ($node->webform['components'] as $cid => $component) {
5315
    if (webform_component_feature($component['type'], 'spam_analysis')) {
5316
      $parents = implode('][', webform_component_parent_keys($node, $component));
5317
      $form_info['elements']['submitted][' . $parents] = check_plain(t($component['name']));
5318
    }
5319
  }
5320
  // Assign field mappings based on webform configuration.
5321
  // Since multiple emails can be configured, we iterate over all and take
5322
  // over the assigned component for the field mapping in any email, unless
5323
  // we already assigned one. We are not interested in administratively
5324
  // configured static strings, only user-submitted values.
5325
  foreach ($node->webform['emails'] as $email) {
5326
    // Subject (post_title).
5327
    if (!isset($form_info['mapping']['post_title'])) {
5328
      $cid = $email['subject'];
5329
      if (is_numeric($cid)) {
5330
        $parents = implode('][', webform_component_parent_keys($node, $node->webform['components'][$cid]));
5331
        $form_info['mapping']['post_title'] = 'submitted][' . $parents;
5332
      }
5333
    }
5334
    // From name (author_name).
5335
    if (!isset($form_info['mapping']['author_name'])) {
5336
      $cid = $email['from_name'];
5337
      if (is_numeric($cid)) {
5338
        $parents = implode('][', webform_component_parent_keys($node, $node->webform['components'][$cid]));
5339
        $form_info['mapping']['author_name'] = 'submitted][' . $parents;
5340
      }
5341
    }
5342
    // From address (author_mail).
5343
    if (!isset($form_info['mapping']['author_mail'])) {
5344
      $cid = $email['from_address'];
5345
      if (is_numeric($cid)) {
5346
        $parents = implode('][', webform_component_parent_keys($node, $node->webform['components'][$cid]));
5347
        $form_info['mapping']['author_mail'] = 'submitted][' . $parents;
5348
      }
5349
    }
5350
  }
5351

  
5352
  return $form_info;
5353
}
5354

  
5355 5271
/**
5356 5272
 * Implements hook_date_views_extra_tables().
5357 5273
 */
......
5360 5276
}
5361 5277

  
5362 5278
/**
5363
 * Returns the next serial number for a given node and increments the serial
5364
 * number.
5279
 * Returns the next serial number for a given node and increments it.
5365 5280
 *
5366 5281
 * @param int $nid
5367 5282
 *   The nid of the node.
......
5400 5315
}
5401 5316

  
5402 5317
/**
5403
 * Returns the next submission serial number to be used, based on the
5404
 * submissions in the database.
5318
 * Returns the next submission serial number to be used.
5319
 *
5320
 * This is based on the submissions in the database.
5405 5321
 *
5406 5322
 * @param int $nid
5407 5323
 *   The Node ID of the Webform.
......
5435 5351
 * @see clone_node_save()
5436 5352
 * @see drupal_alter()
5437 5353
 */
5438
function webform_clone_node_alter(&$node, $context) {
5354
function webform_clone_node_alter(&$node, array $context) {
5439 5355
  if (isset($node->webform)) {
5440 5356
    $defaults = webform_node_defaults();
5441 5357
    $node->webform['next_serial'] = $defaults['next_serial'];
......
5443 5359
}
5444 5360

  
5445 5361
/**
5446
 * Check if the last form submission exceeded the servers max_input_vars
5447
 * limit and optionally preflight the current form to be returned in this
5448
 * request.
5362
 * Check if the last form submission exceeded the servers max_input_vars limit.
5363
 *
5364
 * Optionally preflight the current form to be returned in this request.
5449 5365
 *
5450 5366
 * @param array $form
5451 5367
 *   Reference to the form, which will be changed if $parent_key is set.
......
5458 5374
 *   Omit to not preflight the form, or the array key for the parent of where
5459 5375
 *   the preflight warning should be inserted into the form.
5460 5376
 */
5461
function webform_input_vars_check(&$form, $form_state, $detect_key, $parent_key = NULL) {
5377
function webform_input_vars_check(array &$form, array $form_state, $detect_key, $parent_key = NULL) {
5462 5378
  if (isset($parent_key)) {
5463 5379
    $form['#pre_render'] = array('webform_pre_render_input_vars');
5464 5380
    $form['#input_var_waring_parent'] = $parent_key;
5465 5381
  }
5466
  if (!empty($form_state['input']) && key_exists($detect_key, $form_state['input']) && !key_exists('form_id', $form_state['input'])) {
5382
  if (!empty($form_state['input']) && array_key_exists($detect_key, $form_state['input']) && !array_key_exists('form_id', $form_state['input'])) {
5467 5383
    // A form was submitted with POST, but the form_id was missing. The most likely cause of this
5468 5384
    // is that the POST was truncated because PHP exceeded its max_input_vars limit.
5469 5385
    $subs = array(
......
5482 5398
}
5483 5399

  
5484 5400
/**
5485
 * Checks the number of input form elements on this page to ensure that the
5486
 * PHP max_input_vars limit is not exceeded.
5401
 * Checks the number of input form elements on this page.
5402
 *
5403
 * This ensures that the PHP max_input_vars limit is not exceeded.
5487 5404
 *
5488 5405
 * Install this function as a #pre_render function.
5489 5406
 */
......
5541 5458
 * @return int
5542 5459
 *   The number of elements in the form that will result in $_POST entries.
5543 5460
 */
5544
function webform_count_input_vars($element) {
5461
function webform_count_input_vars(array $element) {
5545 5462
  static $input_types = array(
5546 5463
    'checkbox' => 1,
5547 5464
    'date' => 1,
......
5569 5486
}
5570 5487

  
5571 5488
/**
5572
 * Counts terminals in an array. Useful for counting how many input_vars were
5573
 * returned in $_POST.
5489
 * Counts terminals in an array.
5490
 *
5491
 * Useful for counting how many input_vars were returned in $_POST.
5574 5492
 *
5575 5493
 * @param $a
5576 5494
 *   Array or array element to be counted

Formats disponibles : Unified diff