| 1 |
<?php
|
| 2 |
// $Id: subscriptions.admin.inc,v 1.20 2009/04/13 21:50:29 salvis Exp $
|
| 3 |
|
| 4 |
/**
|
| 5 |
* @file
|
| 6 |
* Subscriptions module (load-on-demand admin functions).
|
| 7 |
*/
|
| 8 |
|
| 9 |
/**
|
| 10 |
* Site Settings form at admin/settings/subscriptions.
|
| 11 |
* Other submodules contribute additional parts to this form.
|
| 12 |
*/
|
| 13 |
function subscriptions_settings_form(&$form_state) {
|
| 14 |
global $user;
|
| 15 |
$form = array();
|
| 16 |
$tr = 't';
|
| 17 |
|
| 18 |
$form['links'] = array(
|
| 19 |
'#type' => 'fieldset',
|
| 20 |
'#title' => t('Links'),
|
| 21 |
'#collapsible' => TRUE,
|
| 22 |
'#collapsed' => TRUE,
|
| 23 |
'#weight' => -100,
|
| 24 |
);
|
| 25 |
$form['links'][] = array(
|
| 26 |
'#value' => '<div>'. l($tr('Permissions'), 'admin/user/permissions', array('fragment' => 'module-subscriptions')) .'</div>',
|
| 27 |
'#weight' => -20,
|
| 28 |
);
|
| 29 |
if (module_exists('subscriptions_mail')) {
|
| 30 |
if (module_exists('mail_edit')) {
|
| 31 |
$form['links'][] = array(
|
| 32 |
'#value' => '<div>'. l($tr('Mail templates'), 'admin/build/mail-edit') .'</div>',
|
| 33 |
'#weight' => -10,
|
| 34 |
);
|
| 35 |
}
|
| 36 |
else {
|
| 37 |
$form['links'][] = array(
|
| 38 |
'#value' => '<div>'. l('Mail Editor', 'http://drupal.org/project/mail_edit') .'</div>',
|
| 39 |
'#weight' => -10,
|
| 40 |
);
|
| 41 |
}
|
| 42 |
}
|
| 43 |
$form['links'][] = array(
|
| 44 |
'#value' => '<div>'. l(t('Run cron manually!'), 'admin/reports/status/run-cron') .'</div>',
|
| 45 |
'#weight' => 0,
|
| 46 |
);
|
| 47 |
$form['links'][] = array(
|
| 48 |
'#value' => '<div>'. l(t('My subscriptions'), 'user/'. $user->uid .'/subscriptions') .'</div>',
|
| 49 |
'#weight' => 10,
|
| 50 |
);
|
| 51 |
|
| 52 |
|
| 53 |
//$form['sub_settings'] = array(
|
| 54 |
// '#type' => 'fieldset',
|
| 55 |
// '#title' => t('General settings'),
|
| 56 |
// '#weight' => -3,
|
| 57 |
//);
|
| 58 |
//$form['sub_settings']['subscriptions_testpost'] = array(
|
| 59 |
// '#type' => 'checkbox',
|
| 60 |
// '#title' => t('Test held posts prior to sending'),
|
| 61 |
// '#default_value' => variable_get('subscriptions_testpost', 0),
|
| 62 |
// '#description' => t('Tests to see if a post about to be sent by cron is still active. Adds a small amount of overhead. Default is OFF.'),
|
| 63 |
//);
|
| 64 |
//$form['sub_settings']['subscriptions_link_teaser'] = array(
|
| 65 |
// '#type' => 'checkbox',
|
| 66 |
// '#title' => t('Show subscribe link with teaser'),
|
| 67 |
// '#default_value' => variable_get('subscriptions_link_teaser', 1),
|
| 68 |
// '#description' => t('Uncheck to show link only in node view.'),
|
| 69 |
//);
|
| 70 |
|
| 71 |
if (variable_get('subscriptions_show_install_info', 1) && (
|
| 72 |
!module_exists('subscriptions_ui') ||
|
| 73 |
!module_exists('subscriptions_mail') ||
|
| 74 |
!module_exists('subscriptions_content') ||
|
| 75 |
!module_exists('subscriptions_taxonomy'))) {
|
| 76 |
if (empty($_POST)) {
|
| 77 |
include_once drupal_get_path('module', 'subscriptions') .'/subscriptions.install.inc';
|
| 78 |
_subscriptions_install_information();
|
| 79 |
}
|
| 80 |
$form['subscriptions_show_install_info'] = array(
|
| 81 |
'#type' => 'checkbox',
|
| 82 |
'#title' => t('Keep showing the installation reminder above.'),
|
| 83 |
'#default_value' => variable_get('subscriptions_show_install_info', 1),
|
| 84 |
'#description' => t('Uncheck this box to permanently remove the reminder, if you have a reason for not enabling the standard selection of Subscriptions modules.'),
|
| 85 |
'#weight' => -101,
|
| 86 |
);
|
| 87 |
}
|
| 88 |
|
| 89 |
return system_settings_form($form);
|
| 90 |
}
|
| 91 |
|
| 92 |
/* ******************************************************* */
|
| 93 |
/* user screens: display, edit functions */
|
| 94 |
/* ******************************************************* */
|
| 95 |
|
| 96 |
/**
|
| 97 |
* Theme subscriptions page controls table.
|
| 98 |
*
|
| 99 |
* @ingroup themeable
|
| 100 |
*/
|
| 101 |
function theme_subscriptions_form_table($element) {
|
| 102 |
$output = '';
|
| 103 |
$rows = array();
|
| 104 |
drupal_add_js(drupal_get_path('module', 'subscriptions') .'/subscriptions_tableselect.js', 'module', 'header', FALSE, TRUE, FALSE);
|
| 105 |
$columns['checkboxes'] = array('data' => '', 'width' => '1%', 'class' => 'subscriptions-table select-all');
|
| 106 |
$columns['labels'] = array('data' => t('Subscription'), 'width' => '18%');
|
| 107 |
if (isset($element['send_interval']) && $element['send_interval']['#access']) {
|
| 108 |
$columns['send_interval'] = array('data' => t('Send interval'), 'width' => '20%');
|
| 109 |
}
|
| 110 |
if (isset($element['send_updates']) && $element['send_updates']['#access']) {
|
| 111 |
$columns['send_updates'] = array('data' => t('On updates'), 'width' => '10%');
|
| 112 |
}
|
| 113 |
if (isset($element['send_comments']) && $element['send_comments']['#access'] && module_exists('comment')) {
|
| 114 |
$columns['send_comments'] = array('data' => t('On comments'), 'width' => '10%');
|
| 115 |
}
|
| 116 |
|
| 117 |
// check whether we have an Author column
|
| 118 |
if (isset($element['author'])) {
|
| 119 |
foreach (element_children($element['checkboxes']) as $key) {
|
| 120 |
foreach (element_children($element['checkboxes'][$key]) as $key1) {
|
| 121 |
if ($key1 != -1) {
|
| 122 |
$tr = 't';
|
| 123 |
$columns['author'] = array('data' => $tr('Author'), 'width' => '20%');
|
| 124 |
}
|
| 125 |
}
|
| 126 |
}
|
| 127 |
}
|
| 128 |
if (isset($element['extra_info'])) {
|
| 129 |
$columns['extra_info']['data'] = $element['extra_info']['#title'];
|
| 130 |
}
|
| 131 |
$column_keys = array_keys($columns);
|
| 132 |
unset($columns[end($column_keys)]['width']); // let the last column grow
|
| 133 |
|
| 134 |
if (isset($element['checkboxes'])) {
|
| 135 |
foreach (element_children($element['checkboxes']) as $key) {
|
| 136 |
foreach (element_children($element['checkboxes'][$key]) as $key1) {
|
| 137 |
if (empty($element['checkboxes'][$key][$key1]['#disabled'])) {
|
| 138 |
$element['checkboxes'][$key][$key1]['#attributes']['class'] = 'select-row';
|
| 139 |
}
|
| 140 |
$row = array();
|
| 141 |
foreach (array_keys($columns) as $colkey) {
|
| 142 |
$row[] = drupal_render($element[$colkey][$key][$key1]);
|
| 143 |
}
|
| 144 |
$rows[] = $row;
|
| 145 |
}
|
| 146 |
}
|
| 147 |
}
|
| 148 |
if ($rows) {
|
| 149 |
$output .= theme('table', array_values($columns), $rows);
|
| 150 |
//$output .= drupal_render($element);
|
| 151 |
}
|
| 152 |
return $output;
|
| 153 |
}
|
| 154 |
|
| 155 |
|
| 156 |
/**
|
| 157 |
* Subscriptions page submit handler.
|
| 158 |
*
|
| 159 |
* @ingroup form
|
| 160 |
*/
|
| 161 |
function subscriptions_page_form_submit($form, &$form_state) {
|
| 162 |
global $user;
|
| 163 |
if (isset($form_state['values']['header']['role']['roles'])) {
|
| 164 |
$rid0 = current($form_state['values']['header']['role']['roles']);
|
| 165 |
}
|
| 166 |
if ($form_state['values']['op'] == $form_state['values']['submit']) {
|
| 167 |
if (empty($rid0)) {
|
| 168 |
$form_state['values']['header']['role']['roles'][] = -$form_state['values']['uid']; // will be negated again below
|
| 169 |
}
|
| 170 |
$module = $form_state['values']['module'];
|
| 171 |
$field = $form_state['values']['field'];
|
| 172 |
$access_key = (isset($form_state['values']['access_key']) ? $form_state['values']['access_key'] : $module);
|
| 173 |
foreach ($form_state['values'] as $element_values) {
|
| 174 |
if (isset($element_values[0])) {
|
| 175 |
$element_values = $element_values[0];
|
| 176 |
}
|
| 177 |
if (isset($element_values['defaults']['send_interval'])) {
|
| 178 |
$defaults = $element_values['defaults'];
|
| 179 |
foreach ($element_values['checkboxes'] as $value => $bundle) {
|
| 180 |
foreach ($bundle as $author_uid => $set_to_enabled) {
|
| 181 |
if ($set_to_enabled && (
|
| 182 |
!isset($defaults['checkboxes'][$value][$author_uid]) ||
|
| 183 |
$element_values['send_interval'][$value][$author_uid] != $defaults['send_interval'][$value][$author_uid] ||
|
| 184 |
empty($element_values['send_updates'][$value][$author_uid]) != empty($defaults['send_updates'][$value][$author_uid]) ||
|
| 185 |
empty($element_values['send_comments'][$value][$author_uid]) != empty($defaults['send_comments'][$value][$author_uid]))) {
|
| 186 |
$send_updates = (empty($element_values['send_updates'][$value][$author_uid]) ? 0 : 1);
|
| 187 |
$send_comments = (empty($element_values['send_comments'][$value][$author_uid]) ? 0 : 1);
|
| 188 |
foreach ($form_state['values']['header']['role']['roles'] as $uid) {
|
| 189 |
subscriptions_write($access_key, $module, $field, $value, $author_uid, -$uid, $element_values['send_interval'][$value][$author_uid], $send_updates, $send_comments);
|
| 190 |
}
|
| 191 |
$changed = TRUE;
|
| 192 |
}
|
| 193 |
elseif (!$set_to_enabled && isset($defaults['checkboxes'][$value][$author_uid])) {
|
| 194 |
// It was enabled but now it is not. Delete.
|
| 195 |
foreach ($form_state['values']['header']['role']['roles'] as $uid) {
|
| 196 |
db_query("DELETE FROM {subscriptions} WHERE module = '%s' AND field = '%s' AND value = '%s' AND author_uid = %d AND recipient_uid = %d", $module, $field, $value, $author_uid, -$uid);
|
| 197 |
}
|
| 198 |
$changed = TRUE;
|
| 199 |
}
|
| 200 |
}
|
| 201 |
}
|
| 202 |
}
|
| 203 |
}
|
| 204 |
if (!empty($changed)) {
|
| 205 |
drupal_set_message(t('Your subscriptions were updated.'));
|
| 206 |
}
|
| 207 |
}
|
| 208 |
if (!empty($rid0)) {
|
| 209 |
$form_state['redirect'] = 'admin/settings/subscriptions/userdefaults/'. arg(4);
|
| 210 |
if ($rid0 != DRUPAL_AUTHENTICATED_RID) {
|
| 211 |
$form_state['redirect'] .= '/'. $rid0;
|
| 212 |
}
|
| 213 |
}
|
| 214 |
}
|
| 215 |
|
| 216 |
/**
|
| 217 |
* Display subscribed content data on the user and site subscriptions pages.
|
| 218 |
* @ TODO clean up all of these parts
|
| 219 |
*
|
| 220 |
* @ingroup form
|
| 221 |
*/
|
| 222 |
function subscriptions_page($account, $stype) {
|
| 223 |
$stypes = subscriptions_types();
|
| 224 |
if (!isset($stypes[$stype])) {
|
| 225 |
drupal_not_found();
|
| 226 |
return;
|
| 227 |
}
|
| 228 |
|
| 229 |
if (arg(0) == 'admin') {
|
| 230 |
$form['header'] = array(
|
| 231 |
'#type' => 'fieldset',
|
| 232 |
'#title' => t('Admin Information'),
|
| 233 |
'#attributes' => array('class' => 'error'),
|
| 234 |
'#collapsible' => TRUE,
|
| 235 |
'#collapsed' => FALSE,
|
| 236 |
'#weight' => -2,
|
| 237 |
);
|
| 238 |
$form['header'][] = array(
|
| 239 |
'#type' => 'item',
|
| 240 |
'#value' => t('The selected subscriptions will be given to <b>newly created</b> users.'),
|
| 241 |
);
|
| 242 |
|
| 243 |
$tr = 't';
|
| 244 |
$form['header']['role'] = array(
|
| 245 |
'#type' => 'fieldset',
|
| 246 |
'#title' => $tr('Roles'),
|
| 247 |
'#collapsible' => TRUE,
|
| 248 |
'#collapsed' => !is_numeric(arg(5)),
|
| 249 |
);
|
| 250 |
$form['header']['role']['header'] = array(
|
| 251 |
'#type' => 'markup',
|
| 252 |
'#value' => '<div>'. t('If a user has one or more roles assigned at creation time, then she will receive the additional subscriptions defined for these roles.') .'</div>',
|
| 253 |
'#weight' => -5,
|
| 254 |
);
|
| 255 |
$form['header']['role']['roles'] = array(
|
| 256 |
'#type' => 'select',
|
| 257 |
'#title' => t('Role(s)'),
|
| 258 |
'#default_value' => (is_numeric(arg(5))? arg(5) : DRUPAL_AUTHENTICATED_RID),
|
| 259 |
'#options' => user_roles(TRUE),
|
| 260 |
'#description' => t('Select the role to load or role(s) to save.'),
|
| 261 |
'#multiple' => TRUE,
|
| 262 |
);
|
| 263 |
$form['header']['role']['load'] = array(
|
| 264 |
'#type' => 'submit',
|
| 265 |
'#value' => t('Load'),
|
| 266 |
);
|
| 267 |
}
|
| 268 |
else {
|
| 269 |
$form['header'][] = array(
|
| 270 |
'#value' => t('Current subscriptions:'),
|
| 271 |
'#weight' => -2,
|
| 272 |
);
|
| 273 |
}
|
| 274 |
|
| 275 |
$form['footer'] = array(
|
| 276 |
'#type' => 'item',
|
| 277 |
'#description' => t('The master checkboxes on the left turn the given subscription on or off. Click and Shift-click to turn a range of subscriptions on or off.') .'<br />'. t('Depending on the setup of the site, you may have additional options for active subscriptions.'),
|
| 278 |
'#weight' => 10,
|
| 279 |
);
|
| 280 |
|
| 281 |
$callback = $stypes[$stype]['page'];
|
| 282 |
$output = function_exists($callback) ? $callback($account, $form) : '';
|
| 283 |
//drupal_add_link(array(
|
| 284 |
// 'rel' => 'alternate',
|
| 285 |
// 'type' => 'application/rss+xml',
|
| 286 |
// 'title' => t('!name Subscriptions', array('!name' => $user->name)),
|
| 287 |
// 'href' => url('subscriptions/feed'),
|
| 288 |
//));
|
| 289 |
drupal_set_title(isset($account) ? check_plain($account->name) : t('Subscriptions'));
|
| 290 |
return theme('box', '', $output); // . theme('xml_icon', url('subscriptions/feed'));
|
| 291 |
}
|
| 292 |
|
| 293 |
/**
|
| 294 |
* Construct the overview page, which displays a summary of subscriptions per
|
| 295 |
* type as well as the user settings at user/UID/subscriptions.
|
| 296 |
* This form is also used for admin/settings/subscriptions/userdefaults.
|
| 297 |
*
|
| 298 |
* @params $account
|
| 299 |
* Must be a valid user account from user_load() or NULL (for the admin form).
|
| 300 |
*/
|
| 301 |
function subscriptions_page_user_overview($account) {
|
| 302 |
// Build summary
|
| 303 |
$uid = (isset($account) ? $account->uid : -DRUPAL_AUTHENTICATED_RID);
|
| 304 |
$counts = array();
|
| 305 |
$result = db_query("SELECT module, field, count(1) as number FROM {subscriptions} WHERE recipient_uid = %d GROUP BY module, field", $uid);
|
| 306 |
while ($subs = db_fetch_object($result)) {
|
| 307 |
if (!empty($subs->module)) {
|
| 308 |
$counts[$subs->module][$subs->field] = $subs->number;
|
| 309 |
}
|
| 310 |
}
|
| 311 |
// give other modules a chance to add their count(s)
|
| 312 |
$more_counts = module_invoke_all('count_user_subscriptions', $counts, $uid);
|
| 313 |
$counts = array_merge($counts, $more_counts);
|
| 314 |
|
| 315 |
$tr = 't';
|
| 316 |
$header = array(array('data' => $tr('Type'), 'width' => '20%'), t('Number'));
|
| 317 |
$types = subscriptions_types();
|
| 318 |
if ($uid < 0) {
|
| 319 |
unset($types['node']);
|
| 320 |
}
|
| 321 |
uasort($types, '_subscriptions_cmp_by_weight');
|
| 322 |
foreach ($types as $stype => $type) {
|
| 323 |
$has_access = ($uid < 0 && user_access('administer site configuration')) || user_access($type['access'], $account);
|
| 324 |
if ($has_access || user_access('administer user subscriptions')) {
|
| 325 |
$rows[] = array(
|
| 326 |
($has_access ? l($tr($type['title']), ($uid < 0 ? "admin/settings/subscriptions/userdefaults/$stype" : "user/$account->uid/subscriptions/$stype")) : $type['title']),
|
| 327 |
isset($counts[$type['fields'][0]][$type['fields'][1]]) ? $counts[$type['fields'][0]][$type['fields'][1]] : 0,
|
| 328 |
);
|
| 329 |
}
|
| 330 |
}
|
| 331 |
$output = theme('table', $header, $rows);
|
| 332 |
$output .= theme('item', array('#value' => '', '#description' => t('Note: The counts on this page may differ from the ones on the detail pages for various technical reasons.')));
|
| 333 |
$output .= '<br />';
|
| 334 |
|
| 335 |
$output .= drupal_get_form('subscriptions_user_settings_form', $account);
|
| 336 |
drupal_set_title($uid < 0 ? t('Subscriptions') : check_plain($account->name));
|
| 337 |
return $output;
|
| 338 |
}
|
| 339 |
|
| 340 |
/**
|
| 341 |
* Returns the form definition for the settings part of the overview page.
|
| 342 |
* This subform is also used for admin/settings/subscriptions/userdefaults.
|
| 343 |
*
|
| 344 |
* @params $account
|
| 345 |
* Must be a valid user account from user_load() or NULL (for the admin form).
|
| 346 |
*
|
| 347 |
* @ingroup form
|
| 348 |
*/
|
| 349 |
function subscriptions_user_settings_form(&$form_state, $account) {
|
| 350 |
global $user;
|
| 351 |
|
| 352 |
$uid = (isset($account) ? $account->uid : -DRUPAL_AUTHENTICATED_RID);
|
| 353 |
$tr = 't';
|
| 354 |
$form['settings'] = array(
|
| 355 |
'#type' => 'fieldset',
|
| 356 |
'#title' => $tr('Settings'),
|
| 357 |
'#weight' => 5,
|
| 358 |
'#collapsible' => isset($account),
|
| 359 |
'#collapsed' => isset($account),
|
| 360 |
);
|
| 361 |
if ($uid < 0) {
|
| 362 |
$form['settings']['info'] = array(
|
| 363 |
'#type' => 'fieldset',
|
| 364 |
'#title' => $tr('Admin Information'),
|
| 365 |
'#attributes' => array('class' => 'error'),
|
| 366 |
'#collapsible' => TRUE,
|
| 367 |
'#collapsed' => FALSE,
|
| 368 |
);
|
| 369 |
$form['settings']['info'][] = array(
|
| 370 |
'#type' => 'item',
|
| 371 |
'#value' => '<div>'. t("The subtabs here under %User_defaults mirror those found at !My_account_Subscriptions, except that the fieldsets here come up already expanded. Please go there now and familiarize yourself with what's there!",
|
| 372 |
array(
|
| 373 |
'%User_defaults' => $tr('User defaults'),
|
| 374 |
'!My_account_Subscriptions' => l($tr('My account') .'|'. $tr('Subscriptions'), 'user/'. $user->uid .'/subscriptions'),
|
| 375 |
'%Settings' => $tr('Settings'),
|
| 376 |
)
|
| 377 |
) .'</div>',
|
| 378 |
);
|
| 379 |
$form['settings']['info'][] = array(
|
| 380 |
'#type' => 'item',
|
| 381 |
'#value' => '<div>'. t("The default settings that you define here are used for those users that haven't (yet) saved their own settings.",
|
| 382 |
array(
|
| 383 |
'%User_defaults' => $tr('User defaults'),
|
| 384 |
'!My_account_Subscriptions' => l($tr('My account') .'|'. $tr('Subscriptions'), 'user/'. $user->uid .'/subscriptions'),
|
| 385 |
'%Settings' => $tr('Settings'),
|
| 386 |
)
|
| 387 |
) .'</div>',
|
| 388 |
);
|
| 389 |
$form['settings']['info']['hide_overview_page'] = array(
|
| 390 |
'#type' => 'checkbox',
|
| 391 |
'#title' => t('Hide the %Overview page from your users', array('%Overview' => t('Overview'))),
|
| 392 |
'#default_value' => variable_get('subscriptions_hide_overview_page', 0),
|
| 393 |
'#description' => t("If you hide this page, your users won't be able to change any of these settings. The default is OFF."),
|
| 394 |
);
|
| 395 |
}
|
| 396 |
$form['settings']['autosub'] = array(
|
| 397 |
'#type' => 'fieldset',
|
| 398 |
'#title' => t('Auto-subscribe'),
|
| 399 |
'#access' => !isset($account) || user_access('subscribe to content', $account),
|
| 400 |
);
|
| 401 |
$form['settings']['autosub']['autosub_post'] = array(
|
| 402 |
'#type' => 'checkbox',
|
| 403 |
'#title' => t('Auto-subscribe to new content'),
|
| 404 |
'#default_value' => _subscriptions_get_setting('autosub_on_post', $account),
|
| 405 |
'#description' => t('Automatically subscribes you to items that you create.'),
|
| 406 |
);
|
| 407 |
$form['settings']['autosub']['autosub_update'] = array(
|
| 408 |
'#type' => 'checkbox',
|
| 409 |
'#title' => t('Auto-subscribe to updated content'),
|
| 410 |
'#default_value' => _subscriptions_get_setting('autosub_on_update', $account),
|
| 411 |
'#description' => t('Automatically subscribes you to items that you update (if you have that permission).'),
|
| 412 |
);
|
| 413 |
$form['settings']['autosub']['autosub_comment'] = array(
|
| 414 |
'#type' => 'checkbox',
|
| 415 |
'#title' => t('Auto-subscribe to comments'),
|
| 416 |
'#default_value' => _subscriptions_get_setting('autosub_on_comment', $account),
|
| 417 |
'#description' => t('Automatically subscribes you to items that you comment on (or where you update a comment, if you have that permission).'),
|
| 418 |
'#access' => module_exists('comment') && (!isset($account) || user_access('post comments', $account) || user_access('post comments without approval', $account)),
|
| 419 |
);
|
| 420 |
$form['settings']['sendself'] = array(
|
| 421 |
'#type' => 'checkbox',
|
| 422 |
'#title' => t('Notify poster of own posts'),
|
| 423 |
'#default_value' => _subscriptions_get_setting('send_self', $account),
|
| 424 |
'#description' => t("Sends you notifications about your own posts (if you're subscribed)."),
|
| 425 |
);
|
| 426 |
$form['settings']['digest'] = array(
|
| 427 |
'#type' => 'checkbox',
|
| 428 |
'#title' => t('Digest mode'),
|
| 429 |
'#default_value' => _subscriptions_get_setting('digest', $account),
|
| 430 |
'#description' => t("Merges your notifications into a single email, sent at the interval you specify."),
|
| 431 |
);
|
| 432 |
$form['settings']['preferences'] = array(
|
| 433 |
'#type' => 'fieldset',
|
| 434 |
'#title' => t('Preferences'),
|
| 435 |
'#access' => FALSE,
|
| 436 |
);
|
| 437 |
$form['settings']['preferences']['send_interval'] = array(
|
| 438 |
'#title' => t('Send interval'),
|
| 439 |
'#type' => 'select',
|
| 440 |
'#options' => _subscriptions_send_intervals(),
|
| 441 |
'#default_value' => _subscriptions_get_setting('send_interval', $account),
|
| 442 |
'#description' => t('The frequency of notifications; it may take longer, but notifications will not be sent more frequently than indicated.'),
|
| 443 |
);
|
| 444 |
$form['settings']['preferences']['send_updates'] = array(
|
| 445 |
'#title' => t('On updates'),
|
| 446 |
'#type' => 'checkbox',
|
| 447 |
'#default_value' => _subscriptions_get_setting('send_updates', $account),
|
| 448 |
'#description' => t('Sends a notification when an item is updated.'),
|
| 449 |
);
|
| 450 |
$form['settings']['preferences']['send_comments'] = array(
|
| 451 |
'#title' => t('On comments'),
|
| 452 |
'#type' => 'checkbox',
|
| 453 |
'#default_value' => _subscriptions_get_setting('send_comments', $account),
|
| 454 |
'#description' => t('Sends a notification when an item receives a comment or reply.'),
|
| 455 |
);
|
| 456 |
$form['settings']['preferences']['description'] = array(
|
| 457 |
'#value' => t('Any changes you make here will only apply to newly created subscriptions.'),
|
| 458 |
);
|
| 459 |
$form['settings']['visibility'] = array(
|
| 460 |
'#type' => 'fieldset',
|
| 461 |
'#title' => t('Visibility of controls'),
|
| 462 |
'#collapsible' => isset($account),
|
| 463 |
'#collapsed' => isset($account),
|
| 464 |
'#access' => FALSE,
|
| 465 |
);
|
| 466 |
$form['settings']['visibility'][] = array(
|
| 467 |
'#type' => 'item',
|
| 468 |
'#description' => t('The control(s) mentioned below appear(s) as one or more columns<br /> a) in the %Subscribe subform of node pages and<br /> b) on the sibling subtabs of this %Overview page.<br /> After you have set your %Preferences right above, you may want to hide the corresponding column(s), if you never change those values anyway.', array('%Subscribe' => $tr('Subscribe'), '%Overview' => $tr('Overview'), '%Preferences' => $tr('Preferences'))),
|
| 469 |
);
|
| 470 |
$visibility_options = array(t('Visible'), t('Hidden'));
|
| 471 |
if (!isset($account)) {
|
| 472 |
$visibility_options[] = t('Permanently hidden, except for the %preferences', array('%preferences' => 'Preferences'));
|
| 473 |
$visibility_options[] = t('Completely inaccessible to the user');
|
| 474 |
$form['settings']['visibility']['info'] = array(
|
| 475 |
'#type' => 'fieldset',
|
| 476 |
'#title' => $tr('Admin Information'),
|
| 477 |
'#attributes' => array('class' => 'error'),
|
| 478 |
'#collapsible' => TRUE,
|
| 479 |
'#collapsed' => FALSE,
|
| 480 |
);
|
| 481 |
$form['settings']['visibility']['info'][] = array(
|
| 482 |
'#type' => 'item',
|
| 483 |
'#value' =>
|
| 484 |
t("Beyond defining the %Visible/%Hidden defaults for your users, you can",
|
| 485 |
array(
|
| 486 |
'%Visible' => $tr('Visible'),
|
| 487 |
'%Hidden' => $tr('Hidden'),
|
| 488 |
)) .
|
| 489 |
'<ul><li>'. t("permanently hide the columns (and the corresponding visibility controls), so that the users cannot make them visible anymore (they can still change their %Preferences though), or",
|
| 490 |
array(
|
| 491 |
'%Preferences' => $tr('Preferences'),
|
| 492 |
)) .'</li>'.
|
| 493 |
'<li>'. t("you can even hide the %Preferences, so that what you've set right above is cast in stone.",
|
| 494 |
array(
|
| 495 |
'%Preferences' => $tr('Preferences'),
|
| 496 |
)) .'</li></ul>',
|
| 497 |
);
|
| 498 |
}
|
| 499 |
foreach (array('interval', 'updates', 'comments') as $parm ) {
|
| 500 |
$site_setting = _subscriptions_get_setting('send_'. $parm .'_visible', 0);
|
| 501 |
$pref_access = !isset($account) || $site_setting >= -1;
|
| 502 |
$control_access = !isset($account) || $site_setting >= 0;
|
| 503 |
$form['settings']['visibility']['send_'. $parm .'_visible'] = array(
|
| 504 |
'#title' => ($parm == 'interval' ? t('Send interval') :
|
| 505 |
($parm == 'updates' ? t('On updates') : t('On comments'))),
|
| 506 |
'#type' => 'radios',
|
| 507 |
'#options' => $visibility_options,
|
| 508 |
'#default_value' => 1-_subscriptions_get_setting('send_'. $parm .'_visible', $account),
|
| 509 |
'#access' => $control_access,
|
| 510 |
);
|
| 511 |
if ($control_access) {
|
| 512 |
$form['settings']['visibility']['#access'] = TRUE;
|
| 513 |
}
|
| 514 |
$form['settings']['preferences']['send_'. $parm]['#access'] = $pref_access;
|
| 515 |
if ($pref_access) {
|
| 516 |
$form['settings']['preferences']['#access'] = TRUE;
|
| 517 |
}
|
| 518 |
}
|
| 519 |
$form['settings']['save'] = array(
|
| 520 |
'#type' => 'submit',
|
| 521 |
'#value' => t('Save'),
|
| 522 |
);
|
| 523 |
if ($uid > 0 && !_subscriptions_get_setting('uses_defaults', $account)) {
|
| 524 |
$form['settings']['reset'] = array(
|
| 525 |
'#type' => 'submit',
|
| 526 |
'#value' => t('Reset to site defaults'),
|
| 527 |
);
|
| 528 |
}
|
| 529 |
$form['settings']['#submit'][] = 'subscriptions_user_options_submit';
|
| 530 |
return $form;
|
| 531 |
}
|
| 532 |
|
| 533 |
/**
|
| 534 |
* User settings subform submit handler.
|
| 535 |
*
|
| 536 |
* @ingroup form
|
| 537 |
*/
|
| 538 |
function subscriptions_user_settings_form_submit($form, &$form_state) {
|
| 539 |
if (isset($form_state['values']['reset']) && $form_state['values']['op'] == $form_state['values']['reset']) {
|
| 540 |
if (($uid = arg(1))> 0) {
|
| 541 |
db_query("UPDATE {subscriptions_user} SET digest = -1, send_interval = -1, send_updates = -1, send_comments = -1, send_interval_visible = -1, send_updates_visible = -1, send_comments_visible = -1, autosub_on_post = -1, autosub_on_update = -1, autosub_on_comment = -1, send_self = -1 WHERE uid = %d", $uid);
|
| 542 |
drupal_set_message(t('The site defaults were restored.'));
|
| 543 |
}
|
| 544 |
}
|
| 545 |
elseif ($form_state['values']['op'] == $form_state['values']['save']) {
|
| 546 |
if (arg(0) == 'user') {
|
| 547 |
$uid = arg(1);
|
| 548 |
}
|
| 549 |
else {
|
| 550 |
$uid = -DRUPAL_AUTHENTICATED_RID;
|
| 551 |
if (variable_get('subscriptions_hide_overview_page', 0) != $form_state['values']['hide_overview_page']) {
|
| 552 |
variable_set('subscriptions_hide_overview_page', $form_state['values']['hide_overview_page']);
|
| 553 |
menu_rebuild();
|
| 554 |
}
|
| 555 |
}
|
| 556 |
$send_interval_visible = 1-$form_state['values']['send_interval_visible'];
|
| 557 |
$send_updates_visible = 1-$form_state['values']['send_updates_visible'];
|
| 558 |
$send_comments_visible = 1-$form_state['values']['send_comments_visible'];
|
| 559 |
db_query("
|
| 560 |
UPDATE {subscriptions_user}
|
| 561 |
SET digest = %d, send_interval = %d, send_updates = %d, send_comments = %d,
|
| 562 |
send_interval_visible = %d, send_updates_visible = %d, send_comments_visible = %d,
|
| 563 |
autosub_on_post = %d, autosub_on_update = %d, autosub_on_comment = %d,
|
| 564 |
send_self = %d
|
| 565 |
WHERE uid = %d",
|
| 566 |
$form_state['values']['digest'],
|
| 567 |
($uid > 0 && $send_interval_visible == -2 ? -1 : $form_state['values']['send_interval']),
|
| 568 |
($uid > 0 && $send_updates_visible == -2 ? -1 : $form_state['values']['send_updates']),
|
| 569 |
($uid > 0 && $send_comments_visible == -2 ? -1 : $form_state['values']['send_comments']),
|
| 570 |
$send_interval_visible, $send_updates_visible, $send_comments_visible,
|
| 571 |
$form_state['values']['autosub_post'],
|
| 572 |
$form_state['values']['autosub_update'],
|
| 573 |
$form_state['values']['autosub_comment'],
|
| 574 |
$form_state['values']['sendself'],
|
| 575 |
$uid);
|
| 576 |
drupal_set_message(t('The changes have been saved.'));
|
| 577 |
}
|
| 578 |
}
|
| 579 |
|
| 580 |
/**
|
| 581 |
* Provide the form definition for admin/settings/subscriptions/intervals.
|
| 582 |
*
|
| 583 |
* Called by _subscriptions_menu() in subscriptions.module.
|
| 584 |
*
|
| 585 |
* @ingroup form
|
| 586 |
*
|
| 587 |
* @see _subscriptions_menu()
|
| 588 |
*/
|
| 589 |
function subscriptions_intervals(&$form_state) {
|
| 590 |
$default = '';
|
| 591 |
foreach (_subscriptions_send_intervals() as $interval => $text) {
|
| 592 |
$default .= "$interval|$text\n";
|
| 593 |
}
|
| 594 |
$form['intervals'] = array(
|
| 595 |
'#type' => 'textarea',
|
| 596 |
'#cols' => 40,
|
| 597 |
'#default_value' => $default,
|
| 598 |
'#description' => t('Every line has the format of seconds|human readable text'),
|
| 599 |
);
|
| 600 |
$form['submit'] = array(
|
| 601 |
'#type' => 'submit',
|
| 602 |
'#value' => t('Save'),
|
| 603 |
);
|
| 604 |
return $form;
|
| 605 |
}
|
| 606 |
|
| 607 |
/**
|
| 608 |
* Sending intervals settings form submit handler.
|
| 609 |
*
|
| 610 |
* @ingroup form
|
| 611 |
*/
|
| 612 |
function subscriptions_intervals_submit($form, &$form_state) {
|
| 613 |
$intervals = array();
|
| 614 |
foreach (explode("\n", $form_state['values']['intervals']) as $line) {
|
| 615 |
if ($line) {
|
| 616 |
$v = explode('|', $line);
|
| 617 |
$intervals[$v[0]] = $v[1];
|
| 618 |
}
|
| 619 |
}
|
| 620 |
variable_set('subscriptions_send_intervals', $intervals);
|
| 621 |
}
|
| 622 |
|
| 623 |
/**
|
| 624 |
* Provide the form definition for adding subscriptions via
|
| 625 |
* subscriptions/add/... link.
|
| 626 |
*
|
| 627 |
* Callback of _subscriptions_menu() in subscriptions.module.
|
| 628 |
*
|
| 629 |
* @param $stype
|
| 630 |
* Subscription type.
|
| 631 |
* @param $sid
|
| 632 |
* Subscription parameter (depends on type).
|
| 633 |
* @param $author_uid
|
| 634 |
* User ID for author-specific subscriptions or NULL/-1 for all authors.
|
| 635 |
*
|
| 636 |
* @ingroup forms
|
| 637 |
* @see _subscriptions_menu()
|
| 638 |
*/
|
| 639 |
function subscriptions_add_form(&$form_state, $stype, $sid, $author_uid = NULL) {
|
| 640 |
global $user;
|
| 641 |
$form['sid'] = array('#type' => 'value', '#value' => $sid);
|
| 642 |
$form['uid'] = array('#type' => 'value', '#value' => $user->uid);
|
| 643 |
$form['stype'] = array('#type' => 'value', '#value' => $stype);
|
| 644 |
$form['author_uid'] = array('#type' => 'value', '#value' => $author_uid);
|
| 645 |
$form['send_interval'] = array(
|
| 646 |
'#title' => t('Send interval'),
|
| 647 |
'#type' => 'select',
|
| 648 |
'#options' => _subscriptions_send_intervals(),
|
| 649 |
'#default_value' => _subscriptions_get_setting('send_interval', $user),
|
| 650 |
'#access' => _subscriptions_get_setting('send_interval_visible', $user),
|
| 651 |
);
|
| 652 |
$form['updates'] = array(
|
| 653 |
'#type' => 'checkbox',
|
| 654 |
'#title' => 'On updates',
|
| 655 |
'#default_value' => _subscriptions_get_setting('send_updates', $user),
|
| 656 |
'#access' => _subscriptions_get_setting('send_updates_visible', $user),
|
| 657 |
);
|
| 658 |
$form['comments'] = array(
|
| 659 |
'#type' => 'checkbox',
|
| 660 |
'#title' => 'On comments',
|
| 661 |
'#default_value' => _subscriptions_get_setting('send_comments', $user),
|
| 662 |
'#access' => _subscriptions_get_setting('send_comments_visible', $user),
|
| 663 |
);
|
| 664 |
$form['submit'] = array(
|
| 665 |
'#type' => 'submit',
|
| 666 |
'#value' => t('Subscribe'),
|
| 667 |
);
|
| 668 |
return $form;
|
| 669 |
}
|
| 670 |
|
| 671 |
/**
|
| 672 |
* Add Subscription form submit handler.
|
| 673 |
*
|
| 674 |
* @ingroup form
|
| 675 |
*/
|
| 676 |
function subscriptions_add_form_submit($form, &$form_state) {
|
| 677 |
if ($a = module_invoke_all('subscriptions', 'stype', $form_state['values']['stype'], $form_state['values']['sid'], (isset($form_state['values']['author_uid']) ? $form_state['values']['author_uid'] : -1))) {
|
| 678 |
list($module, $field, $value, $author_uid) = $a;
|
| 679 |
$uid = $form_state['values']['uid'];
|
| 680 |
subscriptions_write_subscription($module, $field, $value, $author_uid, $uid, $form_state['values']['send_interval'], $form_state['values']['updates'], $form_state['values']['comments']);
|
| 681 |
drupal_set_message(t('Your subscription was activated.'));
|
| 682 |
$form_state['redirect'] = '<front>';
|
| 683 |
}
|
| 684 |
else {
|
| 685 |
drupal_set_message(t('Your subscription could not be activated.'));
|
| 686 |
}
|
| 687 |
}
|
| 688 |
|
| 689 |
/**
|
| 690 |
* Provide the form definition for deleting subscriptions via
|
| 691 |
* subscriptions/del/... link.
|
| 692 |
*
|
| 693 |
* Callback of _subscriptions_menu() in subscriptions.module.
|
| 694 |
*
|
| 695 |
* @param $form_state
|
| 696 |
* FAPI form state.
|
| 697 |
* @param $stype
|
| 698 |
* Subscription type.
|
| 699 |
* @param $sid
|
| 700 |
* Subscription parameter (depends on type).
|
| 701 |
* @param $author_uid
|
| 702 |
* User ID for author-specific subscriptions or -1/NULL for all authors.
|
| 703 |
*
|
| 704 |
* @ingroup forms
|
| 705 |
* @see _subscriptions_menu()
|
| 706 |
*/
|
| 707 |
function subscriptions_del_form(&$form_state, $stype, $sid, $author_uid = NULL) {
|
| 708 |
global $user;
|
| 709 |
|
| 710 |
if ($a = module_invoke_all('subscriptions', 'stype', $stype, $sid, (isset($author_uid) ? $author_uid : -1))) {
|
| 711 |
list($module, $field, $value, $author_uid) = $a;
|
| 712 |
return subscriptions_delete_form($form_state, $module, $field, $value, $author_uid, $user->uid);
|
| 713 |
}
|
| 714 |
drupal_set_message(t('Your subscription could not be deactivated.'));
|
| 715 |
}
|
| 716 |
|
| 717 |
/**
|
| 718 |
* Returns a list of send intervals.
|
| 719 |
*/
|
| 720 |
function _subscriptions_send_intervals() {
|
| 721 |
return variable_get('subscriptions_send_intervals',
|
| 722 |
array(
|
| 723 |
1 => t('As soon as possible'),
|
| 724 |
900 => t('Every 15 minutes'),
|
| 725 |
3600 => t('Hourly'),
|
| 726 |
10800 => t('Every three hours'),
|
| 727 |
86400 => t('Daily'),
|
| 728 |
)
|
| 729 |
);
|
| 730 |
}
|
| 731 |
|
| 732 |
/**
|
| 733 |
* Helper function for the submodules to build the table(s) on their
|
| 734 |
* user/UID/subscriptions/... pages.
|
| 735 |
*
|
| 736 |
* @ingroup form
|
| 737 |
*/
|
| 738 |
function subscriptions_form_helper(&$form, &$defaults, $author_uid, $key, $title, $subscription) {
|
| 739 |
static $intervals;
|
| 740 |
if (!isset($intervals)) {
|
| 741 |
$intervals = _subscriptions_send_intervals();
|
| 742 |
}
|
| 743 |
if (isset($subscription['author_uid']) && ($author_uid == $subscription['author_uid'])) {
|
| 744 |
$defaults['checkboxes'][$key][$author_uid] = 1;
|
| 745 |
}
|
| 746 |
$defaults['send_interval'][$key][$author_uid] = $subscription['send_interval'];
|
| 747 |
if ($subscription['send_comments']) {
|
| 748 |
$defaults['send_comments'][$key][$author_uid] = 1;
|
| 749 |
}
|
| 750 |
if ($subscription['send_updates']) {
|
| 751 |
$defaults['send_updates'][$key][$author_uid] = 1;
|
| 752 |
}
|
| 753 |
if (isset($subscription['author_uid']) && $subscription['author_uid'] > 0) {
|
| 754 |
$author_value = check_plain(db_result(db_query('SELECT name FROM {users} WHERE uid = %d', $subscription['author_uid'])));
|
| 755 |
}
|
| 756 |
elseif ($author_uid == 0) {
|
| 757 |
$author_value = variable_get('anonymous', '???');
|
| 758 |
}
|
| 759 |
else {
|
| 760 |
$author_value = '';
|
| 761 |
}
|
| 762 |
|
| 763 |
$form['labels'][$key][$author_uid] = array(
|
| 764 |
'#type' => 'item',
|
| 765 |
'#value' => $title,
|
| 766 |
);
|
| 767 |
$form['author'][$key][$author_uid] = array(
|
| 768 |
'#value' => $author_value,
|
| 769 |
);
|
| 770 |
$form['send_interval'][$key][$author_uid] = array(
|
| 771 |
'#type' => 'select',
|
| 772 |
'#options' => $intervals,
|
| 773 |
'#default_value' => $defaults['send_interval'][$key][$author_uid],
|
| 774 |
);
|
| 775 |
foreach (array('checkboxes', 'send_comments', 'send_updates') as $col_name) {
|
| 776 |
$form[$col_name][$key][$author_uid] = array(
|
| 777 |
'#type' => 'checkbox',
|
| 778 |
'#default_value' => !empty($defaults[$col_name][$key][$author_uid]),
|
| 779 |
);
|
| 780 |
}
|
| 781 |
if (isset($subscription['extra_info'])) {
|
| 782 |
$form['extra_info'][$key][$author_uid] = array(
|
| 783 |
'#type' => 'item',
|
| 784 |
'#value' => $subscription['extra_info'],
|
| 785 |
);
|
| 786 |
}
|
| 787 |
}
|
| 788 |
|
| 789 |
/**
|
| 790 |
* Helper function for the submodules to hide invisible or empty columns from
|
| 791 |
* their page form table(s).
|
| 792 |
*
|
| 793 |
* @ingroup form
|
| 794 |
*/
|
| 795 |
function subscriptions_form_column_filter(&$form_table, $uid) {
|
| 796 |
foreach (array('send_interval', 'send_comments', 'send_updates', 'author') as $key) {
|
| 797 |
if (isset($form_table[$key])) {
|
| 798 |
$form_table[$key]['#access'] = ($uid <= 0 || $key == 'author' || _subscriptions_get_setting($key .'_visible', $uid) > 0);
|
| 799 |
}
|
| 800 |
}
|
| 801 |
}
|