system.rules.inc 9.0 KB

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