/[drupal]/contributions/modules/subscriptions/subscriptions_mail.admin.inc
ViewVC logotype

Contents of /contributions/modules/subscriptions/subscriptions_mail.admin.inc

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


Revision 1.3 - (show annotations) (download) (as text)
Tue Nov 3 22:35:11 2009 UTC (3 weeks, 2 days ago) by salvis
Branch: MAIN
CVS Tags: HEAD
Changes since 1.2: +2 -2 lines
File MIME type: text/x-php
Fix some strings.
1 <?php
2 // $Id: subscriptions_mail.admin.inc,v 1.2 2009/10/04 15:51:07 salvis Exp $
3
4 /**
5 * @file
6 * Subscriptions module mail gateway (admin functions).
7 */
8
9 /**
10 * Implementation of hook_form_alter().
11 *
12 * Adds to the General Settings part at admin/settings/subscriptions.
13 */
14 function _subscriptions_mail_form_subscriptions_settings_form_alter(&$form, &$form_state) {
15 global $user;
16 $tr = 't';
17
18 // check the $base_url (#199039, #226335)
19 $url = url('', array('absolute' => TRUE));
20 if (empty($_POST) && preg_match('!//($|/|localhost/|([0-9]{1,3}\.){3}[0-9]{1,3}/)!', $url)) {
21 drupal_set_message(t('Your installation returns %url as the base URL of the site. This is probably not what you want, and it can usually be fixed by setting the %variable variable in your %file file.', array('%url' => $url, '%variable' => '$base_url', '%file' => 'settings.php')), 'error');
22 }
23
24 $variables = array('!Module' => 'Subscriptions');
25 $form['mail_settings'] = array(
26 '#type' => 'fieldset',
27 '#title' => t('Mail settings'),
28 '#weight' => -3,
29 );
30 $form['mail_settings']['subscriptions_site_mail'] = array(
31 '#type' => 'textfield',
32 '#title' => t('E-mail address'),
33 '#default_value' => _subscriptions_mail_site_mail(TRUE),
34 '#description' => t('A valid e-mail address to be used as the %From and %Reply_To address by the auto-mailer for !Module notifications. To lessen the likelihood of e-mail being marked as spam, this e-mail address should use the same domain as the website.', $variables + array('%From' => 'From', '%Reply_To' => 'Reply-To')) .'<br />'. t('Clear this field to use the default site e-mail address.'),
35 );
36 $form['mail_settings']['subscriptions_site_mail_name'] = array(
37 '#type' => 'textfield',
38 '#title' => t('E-mail name'),
39 '#default_value' => variable_get('subscriptions_site_mail_name', ''),
40 '#description' => t('An optional name to go with the e-mail address above, no "double-quotes".') .'<br />'. t('Clear this field to use the e-mail address only &mdash; some e-mail clients will display only the portion of the address to the left of the @ sign.'),
41 );
42 $form['mail_settings']['subscriptions_number_of_mails'] = array(
43 '#type' => 'textfield',
44 '#title' => t('Maximum number of notifications to send per cron run'),
45 '#default_value' => variable_get('subscriptions_number_of_mails', 0),
46 '#description' => t('If you need to limit the number of outgoing e-mails for some reason, then set that number here. The default is 0, which means unlimited.'),
47 );
48 $cron_percentage = subscriptions_mail_get_cron_percentage();
49 $form['mail_settings']['subscriptions_cron_percent'] = array(
50 '#type' => 'textfield',
51 '#title' => t('Maximum percent of cron job time to use'),
52 '#default_value' => $cron_percentage,
53 '#description' => t('Limit the percentage of cron job time that !Module may use. If you have modules with cron jobs that run after !Module, then be sure to leave enough time for them! The default is !value.<br />You can temporarily set this to 0 to suspend processing of the notifications queue.', $variables + array('!value' => 50)),
54 );
55 if (empty($_POST) && $cron_percentage <= 0) {
56 $message = t('!Module cannot send any notifications because its <a href="@link">cron job time</a> is 0!', $variables + array('@link' => '#edit-subscriptions-cron-percent'));
57 drupal_set_message(t('Warning: !message', array('!message' => $message)), 'error');
58 $form['mail_settings']['subscriptions_cron_percent']['#attributes'] = array('class' => 'error');
59 }
60 $form['mail_settings']['queue_length'] = array(
61 '#type' => 'item',
62 '#title' => t('Queue'),
63 '#value' => t('There are %count items in the queue.', array('%count' => db_result(db_query("SELECT COUNT(sqid) FROM {subscriptions_queue}")))) .' &nbsp; ',
64 '#description' => t('Note: The number of generated e-mails is typically much lower than the number of queue items.'),
65 );
66 $form['mail_settings']['queue_length']['purge_queue'] = array(
67 '#type' => 'submit',
68 '#name' => 'op',
69 '#value' => t('Purge the queue'),
70 );
71 $form['mail_settings']['subscriptions_watchgood'] = array(
72 '#type' => 'checkbox',
73 '#title' => t('Display watchdog entries for successful mailings'),
74 '#default_value' => variable_get('subscriptions_watchgood', 1),
75 '#description' => t('Logs successful mailings to the watchdog log. Default is ON, but with many subscribers this will generate a huge number of log entries.'),
76 );
77 $form['mail_settings']['subscriptions_watchstats'] = array(
78 '#type' => 'checkbox',
79 '#title' => t('Display summary watchdog entries per cron job'),
80 '#default_value' => variable_get('subscriptions_watchstats', 1),
81 '#description' => t('Logs the mailing counts, time spent, and size of the remaining queue to the watchdog log. This is valuable information for estimating the load on the cron job and on your mail server. Default is ON.'),
82 );
83 $form['mail_settings']['subscriptions_showmailkeys'] = array(
84 '#type' => 'checkbox',
85 '#title' => t('Append the mailkey to every notification'),
86 '#default_value' => variable_get('subscriptions_showmailkeys', 0),
87 '#description' => t('Appends the key of the !Mail_Editor_template that was used to create each e-mail, to assist with configuration and testing. Default is OFF.', array('!Mail_Editor_template' => l('Mail Editor template', (module_exists('mail_edit') ? 'admin/build/mail-edit' : 'http://drupal.org/project/mail_edit')))),
88 );
89 $handlers = array_reverse($form['#submit']);
90 $handlers[] = '_subscriptions_mail_submit_subscriptions_settings_form';
91 $form['#submit'] = array_reverse($handlers); // put our handler in front
92 }
93
94 /**
95 * Submit handler for the Purge-the-queue button on the Subscriptions settings form.
96 */
97 function _subscriptions_mail_submit_subscriptions_settings_form($form, &$form_state) {
98 if ($form_state['values']['op'] == $form_state['values']['purge_queue']) {
99 drupal_goto('admin/settings/subscriptions/purge-queue', drupal_get_destination());
100 }
101 }
102
103 /**
104 * Implementation of hook_form_alter().
105 *
106 * Add the digest parts to the subscriptions_mail_digest mail_edit page.
107 *
108 * @ingroup hooks
109 * @ingroup form
110 */
111 function _subscriptions_mail_form_mail_edit_trans_alter(&$form, &$form_state) {
112 $mailkey = 'subscriptions_mail_digest';
113 if ($form['id']['#value'] == $mailkey) {
114 $tr = 't';
115 $langcode = $form['language']['#value'];
116
117 $form['mail']['subject']['#title'] = t('Digest subject');
118 $form['mail']['body']['#title'] = t('Digest body');
119 $form['mail']['body']['#rows'] = 8;
120
121 $digest_item = subscriptions_mail_template_load(SUBSCRIPTIONS_DIGEST_MAILKEY .'+item', $langcode, 'body', 'DITEM');
122 $digest_item_separator = subscriptions_mail_template_load(SUBSCRIPTIONS_DIGEST_MAILKEY .'+item', $langcode, 'subject', 'SEP');
123 $digest_item_comment = subscriptions_mail_template_load(SUBSCRIPTIONS_DIGEST_MAILKEY .'+comment', $langcode, 'body', 'DITEMCMT');
124
125 $form['mail']['digest_item'] = array(
126 '#title' => t('Digest item'),
127 '#type' => 'textarea',
128 '#default_value' => $digest_item,
129 '#rows' => 15,
130 );
131 if ($placeholders = module_invoke('subscriptions_content', 'mail_edit_tokens_list', 'digest')) {
132 $doc = "<dl>\n";
133 foreach ($placeholders as $name => $description) {
134 $doc .= '<dt>'. $name .'</dt>';
135 $doc .= '<dd>'. $description .'</dd>';
136 }
137 $doc .= "</dl>\n";
138 $form['mail']['digest_item_help'] = array(
139 '#title' => $tr('Replacement patterns'),
140 '#type' => 'fieldset',
141 '#collapsible' => TRUE,
142 '#collapsed' => TRUE,
143 );
144 $form['mail']['digest_item_help']['help'] = array(
145 '#value' => $doc,
146 );
147 }
148 $form['mail']['digest_item_comment'] = array(
149 '#title' => t('Digest item comment'),
150 '#type' => 'textarea',
151 '#default_value' => $digest_item_comment,
152 '#rows' => 4,
153 '#description' => t('The comments inside a digest item body.'),
154 );
155 if ($placeholders = module_invoke('subscriptions_content', 'mail_edit_tokens_list', 'comments')) {
156 $doc = "<dl>\n";
157 foreach ($placeholders as $name => $description) {
158 $doc .= '<dt>'. $name .'</dt>';
159 $doc .= '<dd>'. $description .'</dd>';
160 }
161 $doc .= "</dl>\n";
162 $form['mail']['comment_token_help'] = array(
163 '#title' => t('Replacement patterns'),
164 '#type' => 'fieldset',
165 '#collapsible' => TRUE,
166 '#collapsed' => TRUE,
167 );
168 $form['mail']['comment_token_help']['help'] = array(
169 '#value' => $doc,
170 );
171 }
172 $form['mail']['digest_item_separator'] = array(
173 '#title' => t('Digest item separator'),
174 '#type' => 'textarea',
175 '#default_value' => $digest_item_separator,
176 '#rows' => 2,
177 '#description' => t('The separator between digest items (if needed).'),
178 );
179
180 $form['op']['#submit'][] = 'subscriptions_mail_form_mail_edit_trans_save';
181 if (isset($form['delete'])) {
182 $form['delete']['#submit'][] = 'subscriptions_mail_form_mail_edit_trans_delete';
183 }
184 }
185 }
186
187 /**
188 * Save handler for enhanced mail_edit page.
189 */
190 function subscriptions_mail_form_mail_edit_trans_save($form, &$form_state) {
191 $id = $form_state['values']['id'];
192 $form_state['values']['description'] = '';
193 $form_state['values']['subject'] = $form_state['values']['digest_item_separator'];
194 $form_state['values']['body'] = $form_state['values']['digest_item'];
195 $form_state['values']['id'] = $id .'+item';
196 mail_edit_trans_save($form, $form_state);
197 $form_state['values']['subject'] = '';
198 $form_state['values']['body'] = $form_state['values']['digest_item_comment'];
199 $form_state['values']['id'] = $id .'+comment';
200 mail_edit_trans_save($form, $form_state);
201 }
202
203 /**
204 * Delete handler for enhanced mail_edit page.
205 */
206 function subscriptions_mail_form_mail_edit_trans_delete($form, &$form_state) {
207 foreach (array('item', 'comment') as $key) {
208 db_query("DELETE FROM {mail_edit} WHERE id = '%s' AND language = '%s'", $form_state['values']['id'] ."+$key", $form_state['values']['language']);
209 }
210 }
211

  ViewVC Help
Powered by ViewVC 1.1.2