privatemsg_limits.admin.inc

  1. 7-1 privatemsg_limits/privatemsg_limits.admin.inc
  2. 7-2 privatemsg_limits/privatemsg_limits.admin.inc
  3. 6-2 privatemsg_limits/privatemsg_limits.admin.inc

Admin menu callbacks for privatemsg_limits module.

File

privatemsg_limits/privatemsg_limits.admin.inc
View source
  1. <?php
  2. /**
  3. * @file
  4. * Admin menu callbacks for privatemsg_limits module.
  5. */
  6. /**
  7. * Menu callback for the admin configuration.
  8. */
  9. function privatemsg_limits_admin($form, &$form_state) {
  10. $default = array(
  11. '#type' => 'textfield',
  12. '#size' => '10',
  13. );
  14. $form['conversation'] = array(
  15. '#type' => 'fieldset',
  16. '#title' => t('Conversation settings'),
  17. );
  18. $form['conversation']['privatemsg_limits_messages_per_thread'] = array(
  19. '#type' => 'textfield',
  20. '#title' => t('Maximum number of messages in a conversation'),
  21. '#description' => t('The maximum number of messages that can be included in a conversation. If this maximum has already been reached and a user attempts to add an additional message, then the action specified below shall be taken. Leave this set to 0 if you want unlimited messages per conversation.'),
  22. '#default_value' => variable_get('privatemsg_limits_messages_per_thread', 0),
  23. '#size' => '3',
  24. );
  25. $form['conversation']['privatemsg_limits_messages_per_thread_action'] = array(
  26. '#type' => 'radios',
  27. '#title' => t('Maximum messages action'),
  28. '#description' => t('This action shall be taken once a thread has already reached its maximum number of messages.'),
  29. '#default_value' => variable_get('privatemsg_limits_messages_per_thread_action', 'create-new'),
  30. '#options' => array(
  31. 'create-new' => t('Create new conversation'),
  32. 'block-message' => t('Block message from being sent')
  33. ),
  34. );
  35. $form['receive'] = array(
  36. '#type' => 'fieldset',
  37. '#title' => t('Receive settings'),
  38. );
  39. $form['receive']['privatemsg_limits_receive_enabled'] = array(
  40. '#type' => 'checkbox',
  41. '#title' => t('Limit the total number of messages/conversations that a user may have.'),
  42. '#default_value' => variable_get('privatemsg_limits_receive_enabled', FALSE),
  43. );
  44. $form['receive']['privatemsg_limits_receive_object'] = array(
  45. '#type' => 'select',
  46. '#title' => t('What should be limited'),
  47. '#description' => t('Do you want to limit the number of individual messages a user can send, or limit the number of message conversations a user can initiate? An exceeded conversation limit will allow users to still write individual messages in existing conversations, but not start new ones.'),
  48. '#default_value' => variable_get('privatemsg_limits_receive_object', 'message'),
  49. '#options' => array('message' => t('Messages'), 'thread' => t('Conversations')),
  50. );
  51. $form['receive']['privatemsg_limits_receive_amount'] = array(
  52. '#type' => 'textfield',
  53. '#title' => t('Maximum number of messages/conversations per user'),
  54. '#description' => t('The total number of messages/conversations that a user may have before he has to delete old messages/conversations. When this limit is reached, users are not allowed to receive or send new messages.'),
  55. '#default_value' => variable_get('privatemsg_limits_receive_amount', 0),
  56. '#size' => '10',
  57. );
  58. $form['receive'] += _privatemsg_limits_role_override_form('receive_amount', $default);
  59. $form['send'] = array(
  60. '#type' => 'fieldset',
  61. '#title' => t('Send settings'),
  62. );
  63. $form['send']['privatemsg_limits_send_enabled'] = array(
  64. '#type' => 'checkbox',
  65. '#title' => t('Limit the total number of messages/conversations that a user can send in a given time period'),
  66. '#default_value' => variable_get('privatemsg_limits_send_enabled', FALSE),
  67. );
  68. $form['send']['privatemsg_limits_send_object'] = array(
  69. '#type' => 'select',
  70. '#title' => t('What should be limited'),
  71. '#description' => t('Do you want to limit the number of individual messages a user can send, or limit the number of message conversations a user can initiate? An exceeded conversation limit will allow users to still write individual messages in existing conversations, but not start new ones.'),
  72. '#default_value' => variable_get('privatemsg_limits_send_object', 'message'),
  73. '#options' => array('message' => t('Messages'), 'thread' => t('Conversations')),
  74. );
  75. $form['send']['privatemsg_limits_send_amount'] = array(
  76. '#type' => 'textfield',
  77. '#title' => t('Maximum number of messages/conversations per time period'),
  78. '#description' => t('The total number of messages/conversations that a user may send in a given time period.'),
  79. '#default_value' => variable_get('privatemsg_limits_send_amount', 0),
  80. '#size' => '10',
  81. );
  82. $form['send']['privatemsg_limits_send_timeframe'] = array(
  83. '#type' => 'select',
  84. '#title' => t('Set the time period to be used'),
  85. '#description' => t("Specify the time period to be used when limiting a user's sent messages/threads."),
  86. '#default_value' => variable_get('privatemsg_limits_send_timeframe', 3600),
  87. '#options' => drupal_map_assoc(array(60, 300, 1800, 3600, 86400, 604800, 604800 * 4), 'format_interval'),
  88. );
  89. $form['send'] += _privatemsg_limits_role_override_form('send_amount', $default);
  90. $form['recipients'] = array(
  91. '#type' => 'fieldset',
  92. '#title' => t('Recipient settings'),
  93. );
  94. $form['recipients']['privatemsg_limits_recipients_enabled'] = array(
  95. '#type' => 'checkbox',
  96. '#title' => t('Limit the total number of recipients that a user can include in a single message'),
  97. '#default_value' => variable_get('privatemsg_limits_recipients_enabled', FALSE),
  98. );
  99. $form['recipients']['privatemsg_limits_recipients_amount'] = array(
  100. '#type' => 'textfield',
  101. '#title' => t('Maximum number of recipients per message'),
  102. '#description' => t('Defines the total number of recipients a user may include in a single message. This setting only affects new messages (and not replies on existing message threads). A role (just like any other recipient type) is considered to be a single recipient regardless of the number of users with that role.'),
  103. '#default_value' => variable_get('privatemsg_limits_recipients_amount', 0),
  104. '#size' => '10',
  105. );
  106. $form['recipients'] += _privatemsg_limits_role_override_form('recipients_amount', $default);
  107. return system_settings_form($form);
  108. }
  109. /**
  110. * Provides a generic rules form to override the default values.
  111. *
  112. * @param string $name Unique name for the value
  113. * @param array $default default form configuration
  114. *
  115. * @return array Form fieldset
  116. */
  117. function _privatemsg_limits_role_override_form($name, $default) {
  118. $form['roles'] = array(
  119. '#type' => 'fieldset',
  120. '#description' => t('You may override the maximum limit specified above on a per-role basis. If a user has multiple roles, then the highest maximum value shall be used. Enter "unlimited" if a role may have unlimited messages/conversations. Enter "0" if you do not want to override the maximum limit setting.'),
  121. '#title' => t('Override maximum limit by role'),
  122. '#collapsible' => TRUE,
  123. '#collapsed' => TRUE,
  124. );
  125. foreach (user_roles(TRUE) as $id => $role) {
  126. $form['roles']["privatemsg_limits_{$name}_role_{$id}"] = $default + array(
  127. '#title' => $role,
  128. '#default_value' => variable_get("privatemsg_limits_{$name}_role_" . $id, 0),
  129. );
  130. }
  131. return $form;
  132. }

Functions

Namesort descending Description
privatemsg_limits_admin Menu callback for the admin configuration.
_privatemsg_limits_role_override_form Provides a generic rules form to override the default values.