/[drupal]/contributions/modules/token/token_actions.module
ViewVC logotype

Contents of /contributions/modules/token/token_actions.module

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.5 - (show annotations) (download) (as text)
Sat Jul 11 18:33:46 2009 UTC (4 months, 2 weeks ago) by eaton
Branch: MAIN
CVS Tags: HEAD
Changes since 1.4: +11 -22 lines
File MIME type: text/x-php
Migrating changes from #113614 - numerous minor token fixes, coding standards tweaks, and more. Also added token.dev.inc, which provides a simple testbed for token replacement at admin/settings/token. Updated token_actions for HEAD as well.
1 <?php
2 // $Id: token_actions.module,v 1.4 2007/08/01 02:13:16 eaton Exp $
3
4 /**
5 * Implementation of hook_action_info().
6 */
7 function token_actions_action_info() {
8 return array(
9 'token_actions_message_action' => array(
10 'type' => 'system',
11 'description' => t('Display a tokenized message to the user'),
12 'configurable' => TRUE,
13 'hooks' => array(
14 'nodeapi' => array('view', 'insert', 'update', 'delete'),
15 'comment' => array('view', 'insert', 'update', 'delete'),
16 'user' => array('view', 'insert', 'update', 'delete', 'login'),
17 'taxonomy' => array('insert', 'update', 'delete'),
18 ),
19 ),
20 'token_actions_send_email_action' => array(
21 'description' => t('Send tokenized e-mail'),
22 'type' => 'system',
23 'configurable' => TRUE,
24 'hooks' => array(
25 'nodeapi' => array('view', 'insert', 'update', 'delete'),
26 'comment' => array('view', 'insert', 'update', 'delete'),
27 'user' => array('view', 'insert', 'update', 'delete', 'login'),
28 'taxonomy' => array('insert', 'update', 'delete'),
29 )
30 ),
31 'token_actions_goto_action' => array(
32 'description' => t('Redirect to a tokenized URL'),
33 'type' => 'system',
34 'configurable' => TRUE,
35 'hooks' => array(
36 'nodeapi' => array('view', 'insert', 'update', 'delete'),
37 'comment' => array('view', 'insert', 'update', 'delete'),
38 'user' => array('view', 'insert', 'update', 'delete', 'login'),
39 )
40 )
41 );
42 }
43
44 /**
45 * Return a form definition so the Send email action can be configured.
46 *
47 * @param $context
48 * Default values (if we are editing an existing action instance).
49 * @return
50 * Form definition.
51 */
52 function token_actions_send_email_action_form($context) {
53 // Set default values for form.
54 if (!isset($context['recipient'])) {
55 $context['recipient'] = '';
56 }
57 if (!isset($context['subject'])) {
58 $context['subject'] = '';
59 }
60 if (!isset($context['message'])) {
61 $context['message'] = '';
62 }
63
64 $form['recipient'] = array(
65 '#type' => 'textfield',
66 '#title' => t('Recipient'),
67 '#default_value' => $context['recipient'],
68 '#size' => '20',
69 '#maxlength' => '254',
70 '#description' => t('The email address to which the message should be sent.'),
71 );
72 $form['subject'] = array(
73 '#type' => 'textfield',
74 '#title' => t('Subject'),
75 '#default_value' => $context['subject'],
76 '#size' => '20',
77 '#maxlength' => '254',
78 '#description' => t('The subject of the message.'),
79 );
80 $form['message'] = array(
81 '#type' => 'textarea',
82 '#title' => t('Message'),
83 '#default_value' => $context['message'],
84 '#cols' => '80',
85 '#rows' => '20',
86 '#description' => t('The message that should be sent.'),
87 );
88
89 $form['help'] = array(
90 '#type' => 'fieldset',
91 '#collapsible' => TRUE,
92 '#collapsed' => TRUE,
93 '#title' => t('Placeholder tokens'),
94 '#description' => t("The following placeholder tokens can be used in to generate the URL path. Some tokens may not be available, depending on the context in which the action is triggered."),
95 );
96
97 $form['help']['tokens'] = array(
98 '#markup' => '<strong>' . t('Token help is not yet available.') . '</strong>',
99 );
100
101 return $form;
102 }
103
104 function token_actions_send_email_action_submit($form, $form_state) {
105 $form_values = $form_state['input'];
106 // Process the HTML form to store configuration. The keyed array that
107 // we return will be serialized to the database.
108 $params = array(
109 'recipient' => $form_values['recipient'],
110 'subject' => $form_values['subject'],
111 'message' => $form_values['message'],
112 );
113 return $params;
114 }
115
116 /**
117 * Implementation of a configurable Drupal action.
118 * Sends an email.
119 */
120 function token_actions_send_email_action($object, $context) {
121 $from = variable_get('site_mail', ini_get('sendmail_from'));
122 $recipient = token_replace_all($context['recipient'], $context);
123
124 $subject = token_replace($context['subject'], $context);
125 $subject = str_replace(array("\r", "\n"), '', $subject);
126 $message = token_replace($context['message'], $context);
127
128 $body = drupal_html_to_text($message);
129
130 if (drupal_mail('action_send_email', $recipient, $subject, $body, $from)) {
131 watchdog('action', 'Sent email to %recipient', array('%recipient' => $recipient));
132 }
133 else {
134 watchdog('error', 'Unable to send email to %recipient', array('%recipient' => $recipient));
135 }
136 }
137
138 function token_actions_message_action_form($context) {
139 $form['message'] = array(
140 '#type' => 'textarea',
141 '#title' => t('Message'),
142 '#default_value' => isset($context['message']) ? $context['message'] : '',
143 '#required' => TRUE,
144 '#rows' => '8',
145 '#description' => t('The message to be displayed to the current user.'),
146 );
147
148 $form['help'] = array(
149 '#type' => 'fieldset',
150 '#collapsible' => TRUE,
151 '#collapsed' => TRUE,
152 '#title' => t('Placeholder tokens'),
153 '#description' => t("The following placeholder tokens can be used in the custom message text. Some tokens may not be available, depending on the context in which the action is triggered."),
154 );
155
156 $form['help']['tokens'] = array(
157 '#markup' => '<strong>' . t('Token help is not yet available.') . '</strong>',
158 );
159
160 return $form;
161 }
162
163 function token_actions_message_action_submit($form, $form_state) {
164 return array('message' => $form_state['input']['message']);
165 }
166
167 /**
168 * Implementation of a configurable Drupal action.
169 * Sends a configurable message to the current user's screen.
170 */
171 function token_actions_message_action(&$object, $context = array()) {
172 $context['message'] = token_replace($context['message'], $context);
173 drupal_set_message($context['message']);
174 }
175
176 /**
177 * Implementation of a configurable Drupal action.
178 * Redirect user to a URL.
179 */
180 function token_actions_goto_action_form($context) {
181 $form['url'] = array(
182 '#type' => 'textfield',
183 '#title' => t('URL'),
184 '#description' => t('The URL to which the user should be redirected. This can be an internal URL like node/1234 or an external URL like http://drupal.org.'),
185 '#default_value' => isset($context['url']) ? $context['url'] : '',
186 '#required' => TRUE,
187 );
188 $form['help'] = array(
189 '#type' => 'fieldset',
190 '#collapsible' => TRUE,
191 '#collapsed' => TRUE,
192 '#title' => t('Placeholder tokens'),
193 '#description' => t("The following placeholder tokens can be used in the URL path. Some tokens may not be available, depending on the context in which the action is triggered."),
194 );
195
196 $form['help']['tokens'] = array(
197 '#markup' => '<strong>' . t('Token help is not yet available.') . '</strong>',
198 );
199
200 return $form;
201 }
202
203 function token_actions_goto_action_submit($form, $form_state) {
204 return array(
205 'url' => $form_state['values']['url']
206 );
207 }
208
209 function token_actions_goto_action($object, $context) {
210 drupal_goto(token_replace_multiple($context['url'], $context));
211 }

  ViewVC Help
Powered by ViewVC 1.1.2