system.rules.inc 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307
  1. <?php
  2. /**
  3. * @file
  4. * Rules integration for the system module.
  5. *
  6. * @addtogroup rules
  7. *
  8. * @{
  9. */
  10. /**
  11. * Implements hook_rules_file_info() on behalf of the system module.
  12. */
  13. function rules_system_file_info() {
  14. return array('modules/system.eval');
  15. }
  16. /**
  17. * Implements hook_rules_event_info() on behalf of the system module.
  18. */
  19. function rules_system_event_info() {
  20. return array(
  21. 'init' => array(
  22. 'label' => t('Drupal is initializing'),
  23. 'group' => t('System'),
  24. 'help' => t("Be aware that some actions might initialize the theme system. After that, it's impossible for any module to change the used theme."),
  25. 'access callback' => 'rules_system_integration_access',
  26. ),
  27. 'cron' => array(
  28. 'label' => t('Cron maintenance tasks are performed'),
  29. 'group' => t('System'),
  30. 'access callback' => 'rules_system_integration_access',
  31. ),
  32. 'watchdog' => array(
  33. 'label' => t('System log entry is created'),
  34. 'variables' => array(
  35. 'log_entry' => array(
  36. 'type' => 'log_entry',
  37. 'label' => t('Log entry'),
  38. ),
  39. ),
  40. 'group' => t('System'),
  41. 'access callback' => 'rules_system_integration_access',
  42. ),
  43. );
  44. }
  45. /**
  46. * Implements hook_rules_data_info() on behalf of the system module.
  47. *
  48. * @see rules_core_modules()
  49. */
  50. function rules_system_data_info() {
  51. return array(
  52. 'log_entry' => array(
  53. 'label' => t('watchdog log entry'),
  54. 'wrap' => TRUE,
  55. 'property info' => _rules_system_watchdog_log_entry_info(),
  56. ),
  57. );
  58. }
  59. /**
  60. * Defines property info for watchdog log entries.
  61. *
  62. * Used by the log entry data type to provide a useful metadata wrapper.
  63. */
  64. function _rules_system_watchdog_log_entry_info() {
  65. return array(
  66. 'type' => array(
  67. 'type' => 'text',
  68. 'label' => t('The category to which this message belongs'),
  69. ),
  70. 'message' => array(
  71. 'type' => 'text',
  72. 'label' => ('Log message'),
  73. 'getter callback' => 'rules_system_log_get_message',
  74. 'sanitized' => TRUE,
  75. ),
  76. 'severity' => array(
  77. 'type' => 'integer',
  78. 'label' => t('Severity'),
  79. 'options list' => 'watchdog_severity_levels',
  80. ),
  81. 'request_uri' => array(
  82. 'type' => 'uri',
  83. 'label' => t('Request uri'),
  84. ),
  85. 'link' => array(
  86. 'type' => 'text',
  87. 'label' => t('An associated, HTML formatted link'),
  88. ),
  89. );
  90. }
  91. /**
  92. * Implements hook_rules_action_info() on behalf of the system module.
  93. */
  94. function rules_system_action_info() {
  95. return array(
  96. 'drupal_message' => array(
  97. 'label' => t('Show a message on the site'),
  98. 'group' => t('System'),
  99. 'parameter' => array(
  100. 'message' => array(
  101. 'type' => 'text',
  102. 'label' => t('Message'),
  103. 'sanitize' => TRUE,
  104. 'translatable' => TRUE,
  105. ),
  106. 'type' => array(
  107. 'type' => 'token',
  108. 'label' => t('Message type'),
  109. 'options list' => 'rules_action_drupal_message_types',
  110. 'default value' => 'status',
  111. 'optional' => TRUE,
  112. ),
  113. 'repeat' => array(
  114. 'type' => 'boolean',
  115. 'label' => t('Repeat message'),
  116. 'description' => t("If disabled and the message has been already shown, then the message won't be repeated."),
  117. 'default value' => TRUE,
  118. 'optional' => TRUE,
  119. 'restriction' => 'input',
  120. ),
  121. ),
  122. 'base' => 'rules_action_drupal_message',
  123. 'access callback' => 'rules_system_integration_access',
  124. ),
  125. 'redirect' => array(
  126. 'label' => t('Page redirect'),
  127. 'group' => t('System'),
  128. 'parameter' => array(
  129. 'url' => array(
  130. 'type' => 'uri',
  131. 'label' => t('URL'),
  132. 'description' => t('A Drupal path, path alias, or external URL to redirect to. Enter (optional) queries after "?" and (optional) anchor after "#".'),
  133. ),
  134. 'force' => array(
  135. 'type' => 'boolean',
  136. 'label' => t('Force redirect'),
  137. 'restriction' => 'input',
  138. 'description' => t("Force the redirect even if another destination parameter is present. Per default Drupal would redirect to the path given as destination parameter, in case it is set. Usually the destination parameter is set by appending it to the URL, e.g. !example_url", array('!example_url' => 'http://example.com/user/login?destination=node/2')),
  139. 'optional' => TRUE,
  140. 'default value' => TRUE,
  141. ),
  142. 'destination' => array(
  143. 'type' => 'boolean',
  144. 'label' => t('Append destination parameter'),
  145. 'restriction' => 'input',
  146. 'description' => t('Whether to append a destination parameter to the URL, so another redirect issued later on would lead back to the origin page.'),
  147. 'optional' => TRUE,
  148. 'default value' => FALSE,
  149. ),
  150. ),
  151. 'base' => 'rules_action_drupal_goto',
  152. 'access callback' => 'rules_system_integration_access',
  153. ),
  154. 'breadcrumb_set' => array(
  155. 'label' => t('Set breadcrumb'),
  156. 'group' => t('System'),
  157. 'parameter' => array(
  158. 'titles' => array(
  159. 'type' => 'list<text>',
  160. 'label' => t('Titles'),
  161. 'description' => t('A list of titles for the breadcrumb links.'),
  162. 'translatable' => TRUE,
  163. ),
  164. 'paths' => array(
  165. 'type' => 'list<text>',
  166. 'label' => t('Paths'),
  167. 'description' => t('A list of Drupal paths for the breadcrumb links, matching the order of the titles.'),
  168. ),
  169. ),
  170. 'base' => 'rules_action_breadcrumb_set',
  171. 'access callback' => 'rules_system_integration_access',
  172. ),
  173. 'mail' => array(
  174. 'label' => t('Send mail'),
  175. 'group' => t('System'),
  176. 'parameter' => array(
  177. 'to' => array(
  178. 'type' => 'text',
  179. 'label' => t('To'),
  180. 'description' => t('The e-mail address or addresses where the message will be sent to. The formatting of this string must comply with RFC 2822.'),
  181. ),
  182. 'subject' => array(
  183. 'type' => 'text',
  184. 'label' => t('Subject'),
  185. 'description' => t("The mail's subject."),
  186. 'translatable' => TRUE,
  187. ),
  188. 'message' => array(
  189. 'type' => 'text',
  190. 'label' => t('Message'),
  191. 'description' => t("The mail's message body."),
  192. 'translatable' => TRUE,
  193. ),
  194. 'from' => array(
  195. 'type' => 'text',
  196. 'label' => t('From'),
  197. 'description' => t("The mail's from address. Leave it empty to use the site-wide configured address."),
  198. 'optional' => TRUE,
  199. ),
  200. 'language' => array(
  201. 'type' => 'token',
  202. 'label' => t('Language'),
  203. 'description' => t('If specified, the language used for getting the mail message and subject.'),
  204. 'options list' => 'entity_metadata_language_list',
  205. 'optional' => TRUE,
  206. 'default value' => LANGUAGE_NONE,
  207. 'default mode' => 'selector',
  208. ),
  209. ),
  210. 'base' => 'rules_action_mail',
  211. 'access callback' => 'rules_system_integration_access',
  212. ),
  213. 'mail_to_users_of_role' => array(
  214. 'label' => t('Send mail to all users of a role'),
  215. 'group' => t('System'),
  216. 'parameter' => array(
  217. 'roles' => array(
  218. 'type' => 'list<integer>',
  219. 'label' => t('Roles'),
  220. 'options list' => 'entity_metadata_user_roles',
  221. 'description' => t('Select the roles whose users should receive the mail.'),
  222. ),
  223. 'subject' => array(
  224. 'type' => 'text',
  225. 'label' => t('Subject'),
  226. 'description' => t("The mail's subject."),
  227. ),
  228. 'message' => array(
  229. 'type' => 'text',
  230. 'label' => t('Message'),
  231. 'description' => t("The mail's message body."),
  232. ),
  233. 'from' => array(
  234. 'type' => 'text',
  235. 'label' => t('From'),
  236. 'description' => t("The mail's from address. Leave it empty to use the site-wide configured address."),
  237. 'optional' => TRUE,
  238. ),
  239. ),
  240. 'base' => 'rules_action_mail_to_users_of_role',
  241. 'access callback' => 'rules_system_integration_access',
  242. ),
  243. 'block_ip' => array(
  244. 'label' => t('Block IP address'),
  245. 'group' => t('System'),
  246. 'parameter' => array(
  247. 'ip_address' => array(
  248. 'type' => 'ip_address',
  249. 'label' => t('IP address'),
  250. 'description' => t('If not provided, the IP address of the current user will be used.'),
  251. 'optional' => TRUE,
  252. 'default value' => NULL,
  253. ),
  254. ),
  255. 'base' => 'rules_action_block_ip',
  256. 'access callback' => 'rules_system_integration_access',
  257. ),
  258. );
  259. }
  260. /**
  261. * Help callback for the "Send mail to users of a role" action.
  262. */
  263. function rules_action_mail_to_users_of_role_help() {
  264. return t('WARNING: This may cause problems if there are too many users of these roles on your site, as your server may not be able to handle all the mail requests all at once.');
  265. }
  266. /**
  267. * System integration access callback.
  268. */
  269. function rules_system_integration_access($type, $name) {
  270. return user_access('administer site configuration');
  271. }
  272. /**
  273. * Options list callback defining drupal_message types.
  274. */
  275. function rules_action_drupal_message_types() {
  276. return array(
  277. 'status' => t('Status'),
  278. 'warning' => t('Warning'),
  279. 'error' => t('Error'),
  280. );
  281. }
  282. /**
  283. * Implements hook_rules_evaluator_info() on behalf of the system module.
  284. */
  285. function rules_system_evaluator_info() {
  286. return array(
  287. 'token' => array(
  288. 'class' => 'RulesTokenEvaluator',
  289. 'type' => array('text', 'uri', 'list<text>', 'list<uri>'),
  290. 'weight' => 0,
  291. ),
  292. );
  293. }
  294. /**
  295. * @}
  296. */