123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218 |
- <?php
- /**
- * @file
- * Rules hooks for the Simplenews newsletter module.
- *
- * @addtogroup rules
- * @{
- */
- /**
- * Implements hook_rules_action_info().
- */
- function simplenews_rules_rules_action_info() {
- return array(
- 'simplenews_rules_action_send' => array(
- 'label' => t('Send newsletter'),
- 'group' => t('Simplenews'),
- 'parameter' => array(
- 'node' => array(
- 'type' => 'node',
- 'label' => t('The newsletter node to be sent.'),
- 'description' => t('The newsletter node that should be sent.'),
- )
- )
- ),
- 'simplenews_rules_action_subscribe' => array(
- 'label' => t('Subscribe an e-mail adress to a newsletter'),
- 'group' => t('Simplenews'),
- 'named parameter' => TRUE,
- 'parameter' => array(
- 'mail' => array(
- 'type' => 'text',
- 'label' => t('E-mail'),
- 'description' => t('The e-mail address that should be subscribed.'),
- ),
- 'tid' => array(
- 'type' => 'integer',
- 'label' => t('Simplenews category'),
- 'descrption' => t('For which newsletter category the subscription should happen.'),
- 'options list' => 'simplenews_category_list',
- ),
- 'confirmation' => array(
- 'type' => 'integer',
- 'label' => t('Confirmation required'),
- 'description' => t('Select if a confirmation is required. Default uses the default setting from the chosen newsletter category.'),
- 'options list' => 'simplenews_rules_confirmation_list',
- 'default value' => SIMPLENEWS_RULES_CONFIRMATION_DEFAULT,
- ),
- 'source' => array(
- 'type' => 'string',
- 'label' => t('Source'),
- 'description' => t('A string to identify the source of this subscription'),
- 'optional' => TRUE,
- ),
- 'source' => array(
- 'type' => 'text',
- 'label' => t('Source'),
- 'description' => t('A string to identify the source of this subscription'),
- 'optional' => TRUE,
- 'default value' => 'rules',
- ),
- 'language' => array(
- 'type' => 'token',
- 'label' => t('Language'),
- 'description' => t('If specified, the language to use for the subscription. Defaults to the default language.'),
- 'options list' => 'entity_metadata_language_list',
- 'optional' => TRUE,
- 'default value' => LANGUAGE_NONE,
- ),
- ),
- ),
- 'simplenews_rules_action_unsubscribe' => array(
- 'label' => t('Unsubscribe an e-mail adress from a newsletter'),
- 'group' => t('Simplenews'), 'named parameter' => TRUE,
- 'parameter' => array(
- 'mail' => array(
- 'type' => 'text',
- 'label' => t('E-mail'),
- 'description' => t('The e-mail address that should be unsubscribed.'),
- ),
- 'tid' => array(
- 'type' => 'integer',
- 'label' => t('Simplenews category'),
- 'descrption' => t('For which newsletter category the unsubscription should happen.'),
- 'options list' => 'simplenews_category_list',
- ),
- 'confirmation' => array(
- 'type' => 'integer',
- 'label' => t('Confirmation required'),
- 'description' => t('Select if a confirmation is required. Default uses the default setting from the chosen newsletter category.'),
- 'options list' => 'simplenews_rules_confirmation_list',
- 'default value' => SIMPLENEWS_RULES_CONFIRMATION_DEFAULT,
- ),
- 'source' => array(
- 'type' => 'text',
- 'label' => t('Source'),
- 'description' => t('A string to identify the source of this subscription'),
- 'optional' => TRUE,
- 'default value' => 'rules',
- ),
- 'language' => array(
- 'type' => 'token',
- 'label' => t('Language'),
- 'description' => t('If specified, the language to use for the subscription. Defaults to the default language.'),
- 'options list' => 'entity_metadata_language_list',
- 'optional' => TRUE,
- 'default value' => LANGUAGE_NONE,
- ),
- ),
- ),
- );
- }
- /**
- * Implements hook_event_info().
- */
- function simplenews_rules_rules_event_info() {
- return array(
- 'simplenews_rules_event_subscribe' => array(
- 'label' => t('A user has been subscribed'),
- 'group' => t('Simplenews'),
- 'variables' => array(
- 'mail' => array(
- 'type' => 'text',
- 'label' => t('E-Mail'),
- 'description' => t('The e-mail address that has been subscribed.'),
- ),
- 'tid' => array(
- 'type' => 'integer',
- 'label' => t('Simplenews category'),
- 'descrption' => t('The newsletter category of the subscription.'),
- 'options list' => 'simplenews_category_list',
- ),
- ),
- ),
- 'simplenews_rules_event_unsubscribe' => array(
- 'label' => t('A user has been unsubscribed'),
- 'group' => t('Simplenews'),
- 'variables' => array(
- 'mail' => array(
- 'type' => 'text',
- 'label' => t('E-mail'),
- 'description' => t('The e-mail address that has been subscribed.'),
- ),
- 'tid' => array(
- 'type' => 'integer',
- 'label' => t('Simplenews category'),
- 'descrption' => t('The newsletter category of the subscription.'),
- 'options list' => 'simplenews_category_list',
- ),
- ),
- ),
- );
- }
- /**
- * Action implementation, send a newsletter node.
- */
- function simplenews_rules_action_send($node) {
- $newsletter = simplenews_newsletter_load($node->nid);
- if ($newsletter && ($newsletter->status != SIMPLENEWS_STATUS_SEND_PENDING || $newsletter->status != SIMPLENEWS_STATUS_SEND_PENDING)) {
- module_load_include('inc', 'simplenews', 'includes/simplenews.mail');
- simplenews_add_node_to_spool($node);
- }
- }
- /**
- * Action Implementation: Subscribe an e-mail adress to a Simplenews newsletter.
- */
- function simplenews_rules_action_subscribe($args, $settings) {
- if ($args['language'] == LANGUAGE_NONE) {
- $args['language'] = NULL;
- }
- $confirmation = simplenews_rules_map_confirmation($args);
- // Pass the call forward.
- simplenews_subscribe_user($args['mail'], $args['tid'], $confirmation, $args['source'], $args['language']);
- }
- /**
- * Action Implementation: Unsubscribe an e-mail adress to a Simplenews newsletter.
- */
- function simplenews_rules_action_unsubscribe($args, $settings) {
- if ($args['language'] == LANGUAGE_NONE) {
- $args['language'] = NULL;
- }
- $confirmation = simplenews_rules_map_confirmation($args);
- // Pass the call forward.
- simplenews_unsubscribe_user($args['mail'], $args['tid'], $confirmation, $args['source'], $args['language']);
- }
- /**
- * Map args to the confrmation argument for subscribing/unsubscribing.
- */
- function simplenews_rules_map_confirmation($args) {
- switch ($args['confirmation']) {
- case SIMPLENEWS_RULES_CONFIRMATION_YES:
- $confirmation = TRUE;
- break;
- case SIMPLENEWS_RULES_CONFIRMATION_NO:
- $confirmation = FALSE;
- break;
- case SIMPLENEWS_RULES_CONFIRMATION_DEFAULT:
- $account = simplenews_load_user_by_mail($args['mail']);
- $confirmation = simplenews_require_double_opt_in($args['tid'], $account);
- break;
- }
- return $confirmation;
- }
- /**
- * @}
- */
|