| 1 |
<?php |
<?php |
| 2 |
// $Id: ezmlm.module,v 1.18.4.3 2008/05/31 19:33:59 hutch Exp $ |
// $Id: ezmlm.module,v 1.18.4.4 2008/09/03 10:38:19 hutch Exp $ |
| 3 |
// $Name: $ |
// $Name: $ |
| 4 |
// for drupal 5.x |
// for drupal 5.x |
| 5 |
|
|
| 11 |
*/ |
*/ |
| 12 |
|
|
| 13 |
/** |
/** |
| 14 |
|
* Implementation of hook_user(). |
| 15 |
|
* by mjs2020 |
| 16 |
|
* this adds the ability to subscribe to mailing lists |
| 17 |
|
* during the registration process. |
| 18 |
|
*/ |
| 19 |
|
function ezmlm_user($op, &$edit, &$account, $category = NULL) { |
| 20 |
|
switch ($op) { |
| 21 |
|
case 'register': |
| 22 |
|
if ( variable_get('ezmlm_register', 0) && variable_get('ezmlm_register_list', 0) ) { |
| 23 |
|
$listsform = _ezmlm_subscribe_form('REG', variable_get('ezmlm_reg_display', 'email')); |
| 24 |
|
unset($listsform['ezmlm_email'], $listsform['submit'], $listsform['subscribe'] ); |
| 25 |
|
|
| 26 |
|
$form['ezmlm'] = array( |
| 27 |
|
"#type" => "fieldset", |
| 28 |
|
"#title" => t("Mailing lists"), |
| 29 |
|
"#description" => t("Please select the mailing lists you would like to subscribe to."), |
| 30 |
|
'#collapsible' => FALSE, |
| 31 |
|
"#tree" => FALSE, |
| 32 |
|
"#parents" => array("ezmlm"), |
| 33 |
|
); |
| 34 |
|
$form['ezmlm']['ezmlm_subscribe'] = array(); |
| 35 |
|
foreach ($listsform['ezmlm_subscribe'] as $key => $ezmlm_list) { |
| 36 |
|
$ezmlm_list['#parents'][0] = $key; |
| 37 |
|
$ezmlm_list['#name'] = $key; |
| 38 |
|
$form['ezmlm']['ezmlm_subscribe'][$key] = $ezmlm_list; |
| 39 |
|
} |
| 40 |
|
return $form; |
| 41 |
|
} |
| 42 |
|
break; |
| 43 |
|
case 'insert': |
| 44 |
|
if ( variable_get('ezmlm_register', 0) && variable_get('ezmlm_register_list', 0) ) { |
| 45 |
|
$lists = _ezmlm_get_lists('REG'); |
| 46 |
|
$listct = _ezmlm_get_count('REG'); |
| 47 |
|
$arr = array(); |
| 48 |
|
// get the selected mailing list addresses |
| 49 |
|
for ($ct=1; $ct <= $listct; $ct++) { |
| 50 |
|
if (isset($edit["ezmlm_list_$ct"])) { |
| 51 |
|
$address = $edit["ezmlm_list_$ct"]; |
| 52 |
|
if ($address && in_array($address, $lists)) { |
| 53 |
|
$arr[] = $address; |
| 54 |
|
} |
| 55 |
|
} |
| 56 |
|
} |
| 57 |
|
$email = trim($edit['mail']); |
| 58 |
|
$ret = _ezmlm_subscribe_process($arr, $email); |
| 59 |
|
if (is_array($ret)) { |
| 60 |
|
$output = (t('Please check your mail at %mail to confirm registration of:', array('%mail' => $email))); |
| 61 |
|
drupal_set_message($output ."<br />". implode('<br />', $ret)); |
| 62 |
|
} |
| 63 |
|
else { |
| 64 |
|
drupal_set_message($ret, 'error'); |
| 65 |
|
} |
| 66 |
|
} |
| 67 |
|
break; |
| 68 |
|
} |
| 69 |
|
} |
| 70 |
|
|
| 71 |
|
/** |
| 72 |
* Implementation of hook_help(). |
* Implementation of hook_help(). |
| 73 |
*/ |
*/ |
| 74 |
function ezmlm_help($section) { |
function ezmlm_help($section) { |
| 122 |
'description' => t('Ezmlm mailing lists management.'), |
'description' => t('Ezmlm mailing lists management.'), |
| 123 |
'access' => user_access('administer ezmlm'), |
'access' => user_access('administer ezmlm'), |
| 124 |
'callback' => 'drupal_get_form', |
'callback' => 'drupal_get_form', |
| 125 |
'callback arguments' => 'ezmlm_settings', |
'callback arguments' => array('ezmlm_settings'), |
| 126 |
'type' => MENU_NORMAL_ITEM, |
'type' => MENU_NORMAL_ITEM, |
| 127 |
); |
); |
| 128 |
} |
} |
| 144 |
switch ($delta) { |
switch ($delta) { |
| 145 |
case 0: |
case 0: |
| 146 |
$block = ""; |
$block = ""; |
| 147 |
if (strlen(trim(variable_get('ezmlmmailinglists', '')))) { |
if (drupal_strlen(trim(variable_get('ezmlmmailinglists', '')))) { |
| 148 |
$block['subject'] = variable_get('ezmlm_block_title', t('Subscriptions')); |
$block['subject'] = variable_get('ezmlm_block_title', t('Subscriptions')); |
| 149 |
$block['content'] .= ezmlm_page(); |
$block['content'] .= ezmlm_page(variable_get('ezmlm_block_display', 'email')); |
| 150 |
} |
} |
| 151 |
return $block; |
return $block; |
| 152 |
} |
} |
| 162 |
* Menu callback; presents the subscription form on a page, or processes |
* Menu callback; presents the subscription form on a page, or processes |
| 163 |
* that form's input, whether from block or page. |
* that form's input, whether from block or page. |
| 164 |
*/ |
*/ |
| 165 |
function ezmlm_page() { |
function ezmlm_page($display='') { |
| 166 |
$output = drupal_get_form('_ezmlm_subscribe_form'); |
if (! $display) { |
| 167 |
|
$display = variable_get('ezmlm_display', 'email'); |
| 168 |
|
} |
| 169 |
|
$output = drupal_get_form('_ezmlm_subscribe_form', 'DEFAULT', $display); |
| 170 |
return $output; |
return $output; |
| 171 |
} |
} |
| 172 |
|
|
| 209 |
$lists = variable_get('ezmlmmailinglists', ''); |
$lists = variable_get('ezmlmmailinglists', ''); |
| 210 |
if (is_array($lists)) { |
if (is_array($lists)) { |
| 211 |
foreach ($lists as $list_text => $list_email) { |
foreach ($lists as $list_text => $list_email) { |
| 212 |
$form['ezmlm_delete'][$list_text] = array( |
$list_text2 = preg_replace('/\s/', '~', $list_text); |
| 213 |
|
$form['ezmlm_delete'][$list_text2] = array( |
| 214 |
'#type' => 'checkbox', |
'#type' => 'checkbox', |
| 215 |
'#title' => "$list_text ($list_email)" , |
'#title' => "$list_text ($list_email)" , |
| 216 |
); |
); |
| 217 |
} |
} |
| 218 |
} |
} |
| 219 |
|
// registration |
| 220 |
|
$form['ezmlm_reg'] = array( |
| 221 |
|
'#type' => 'fieldset', |
| 222 |
|
'#title' => t('Registration settings'), |
| 223 |
|
'#description' => t('Allow new users to select mailing lists on registration'), |
| 224 |
|
'#collapsible' => TRUE, |
| 225 |
|
); |
| 226 |
|
$form['ezmlm_reg']['ezmlm_register'] = array( |
| 227 |
|
'#type' => 'checkbox', |
| 228 |
|
'#title' => t('Display lists in registration form'), |
| 229 |
|
'#default_value' => variable_get('ezmlm_register', 1), |
| 230 |
|
); |
| 231 |
|
if (is_array($lists)) { |
| 232 |
|
$reglist = variable_get('ezmlm_register_list', ''); |
| 233 |
|
foreach ($lists as $list_text => $list_email) { |
| 234 |
|
$list_text2 = preg_replace('/\s/', '~', $list_text); |
| 235 |
|
$form['ezmlm_reg']["reg_$list_text2"] = array( |
| 236 |
|
'#type' => 'checkbox', |
| 237 |
|
'#title' => "$list_text ($list_email)" , |
| 238 |
|
'#default_value' => ((is_array($reglist) && in_array($list_email, $reglist)) ? 1 : 0), |
| 239 |
|
); |
| 240 |
|
} |
| 241 |
|
} |
| 242 |
|
$form['ezmlm_reg']['ezmlm_reg_display'] = array( |
| 243 |
|
'#type' => 'radios', |
| 244 |
|
'#title' => t('List display type'), |
| 245 |
|
'#default_value' => variable_get('ezmlm_reg_display', 'email'), |
| 246 |
|
'#options' => array('email' => 'List address', 'name' => 'List name'), |
| 247 |
|
'#description' => t('Display %listaddress or %listname on the registration page', array('%listaddress' => 'list address', '%listname' => 'list name')), |
| 248 |
|
); |
| 249 |
} |
} |
| 250 |
|
|
| 251 |
$form['ezmlm_misc'] = array( |
$form['ezmlm_misc'] = array( |
| 252 |
'#type' => 'fieldset', |
'#type' => 'fieldset', |
| 253 |
'#title' => t('Various settings'), |
'#title' => t('Various settings'), |
| 256 |
$form['ezmlm_misc']['ezmlm_title'] = array( |
$form['ezmlm_misc']['ezmlm_title'] = array( |
| 257 |
'#type' => 'textfield', |
'#type' => 'textfield', |
| 258 |
'#title' => t('List title'), |
'#title' => t('List title'), |
| 259 |
'#description' => t('Configure the title of the subscription list'), |
'#description' => t('Configure the title of the subscription page'), |
| 260 |
'#default_value' => variable_get('ezmlm_title', t('Mailing lists')), |
'#default_value' => variable_get('ezmlm_title', t('Mailing lists')), |
| 261 |
'#size' => 20, |
'#size' => 20, |
| 262 |
'#maxlength' => 20, |
'#maxlength' => 20, |
| 263 |
'#required' => FALSE, |
'#required' => FALSE, |
| 264 |
); |
); |
| 265 |
|
$form['ezmlm_misc']['ezmlm_display'] = array( |
| 266 |
|
'#type' => 'radios', |
| 267 |
|
'#title' => t('List display type'), |
| 268 |
|
'#default_value' => variable_get('ezmlm_display', 'email'), |
| 269 |
|
'#options' => array('email' => 'List address', 'name' => 'List name'), |
| 270 |
|
'#description' => t('Display %listaddress or %listname on the subscription page', array('%listaddress' => 'list address', '%listname' => 'list name')), |
| 271 |
|
); |
| 272 |
$form['ezmlm_misc']['ezmlm_block_title'] = array( |
$form['ezmlm_misc']['ezmlm_block_title'] = array( |
| 273 |
'#type' => 'textfield', |
'#type' => 'textfield', |
| 274 |
'#title' => t('Block title'), |
'#title' => t('Block title'), |
| 275 |
'#description' => t('Configure the title of the block subscription list'), |
'#description' => t('Configure the title of the block subscription page'), |
| 276 |
'#default_value' => variable_get('ezmlm_block_title', t('Subscriptions')), |
'#default_value' => variable_get('ezmlm_block_title', t('Subscriptions')), |
| 277 |
'#size' => 20, |
'#size' => 20, |
| 278 |
'#maxlength' => 20, |
'#maxlength' => 20, |
| 279 |
'#required' => FALSE, |
'#required' => FALSE, |
| 280 |
); |
); |
| 281 |
|
$form['ezmlm_misc']['ezmlm_block_display'] = array( |
| 282 |
|
'#type' => 'radios', |
| 283 |
|
'#title' => t('Block display type'), |
| 284 |
|
'#default_value' => variable_get('ezmlm_block_display', 'email'), |
| 285 |
|
'#options' => array('email' => 'List address', 'name' => 'List name'), |
| 286 |
|
'#description' => t('Display %listaddress or %listname on the block subscription page', array('%listaddress' => 'list address', '%listname' => 'list name')), |
| 287 |
|
); |
| 288 |
|
|
| 289 |
return system_settings_form($form); |
return system_settings_form($form); |
| 290 |
} |
} |
| 291 |
|
|
| 294 |
*/ |
*/ |
| 295 |
function ezmlm_settings_validate($form_id, $form_values) { |
function ezmlm_settings_validate($form_id, $form_values) { |
| 296 |
|
|
| 297 |
if (strlen($form_values['ezmlm_add_address'])) { |
if (drupal_strlen($form_values['ezmlm_add_address'])) { |
| 298 |
if ($error = user_validate_mail($form_values['ezmlm_add_address'])) { |
if ($error = user_validate_mail($form_values['ezmlm_add_address'])) { |
| 299 |
form_set_error('ezmlm_add_address', $error); |
form_set_error('ezmlm_add_address', $error); |
| 300 |
} |
} |
| 301 |
if (! strlen($form_values['ezmlm_add_name'])) { |
if (! drupal_strlen($form_values['ezmlm_add_name'])) { |
| 302 |
form_set_error('ezmlm_add_name', t('You must fill in the Name field')); |
form_set_error('ezmlm_add_name', t('You must fill in the Name field')); |
| 303 |
} |
} |
| 304 |
} |
} |
| 318 |
// look for deletes |
// look for deletes |
| 319 |
$lists = _ezmlm_get_lists(); |
$lists = _ezmlm_get_lists(); |
| 320 |
if (is_array($lists)) { |
if (is_array($lists)) { |
| 321 |
// deletions |
// deletions |
| 322 |
$newlists = array(); |
$newlists = array(); |
| 323 |
$delct = 0; |
$delct = 0; |
| 324 |
foreach ($lists as $list_text => $list_email) { |
foreach ($lists as $list_text => $list_email) { |
| 325 |
if (isset($form_values[$list_text]) && $form_values[$list_text] == 1) { |
$list_text = preg_replace('/\s/', '~', $list_text); |
| 326 |
$delct++; |
if (isset($form_values[$list_text]) && $form_values[$list_text] == 1) { |
| 327 |
continue; // skip copying this list to the new list |
$delct++; |
| 328 |
|
continue; // skip copying this list to the new list |
| 329 |
|
} |
| 330 |
|
else { |
| 331 |
|
$list_text = preg_replace('/~/', ' ', $list_text); |
| 332 |
|
$newlists[$list_text] = $list_email; // copy old list entry to new |
| 333 |
|
} |
| 334 |
} |
} |
| 335 |
else { |
if (count($newlists) < count($lists)) { |
| 336 |
$newlists[$list_text] = $list_email; // copy old list entry to new |
variable_set('ezmlmmailinglists', $newlists); |
| 337 |
|
drupal_set_message(t('Deletions done.')); |
| 338 |
} |
} |
| 339 |
} |
} |
|
if (count($newlists) < count($lists)) { |
|
|
variable_set('ezmlmmailinglists', $newlists); |
|
|
drupal_set_message(t('Deletions done.')); |
|
|
} |
|
|
} |
|
| 340 |
// add list |
// add list |
| 341 |
$lists = _ezmlm_get_lists(); |
$lists = _ezmlm_get_lists(); |
| 342 |
$count = _ezmlm_get_count(); |
$count = _ezmlm_get_count(); |
| 346 |
} |
} |
| 347 |
$list_text = trim($form_values['ezmlm_add_name']); |
$list_text = trim($form_values['ezmlm_add_name']); |
| 348 |
$list_email = trim($form_values['ezmlm_add_address']); |
$list_email = trim($form_values['ezmlm_add_address']); |
| 349 |
if (strlen($list_text) && strlen($list_email)) { |
if (drupal_strlen($list_text) && drupal_strlen($list_email)) { |
| 350 |
$lists[$list_text] = $list_email; |
$lists[$list_text] = $list_email; |
| 351 |
variable_set('ezmlmmailinglists', $lists); |
variable_set('ezmlmmailinglists', $lists); |
| 352 |
drupal_set_message( t('The mailing lists have been saved.')); |
drupal_set_message( t('The mailing lists have been saved.')); |
| 353 |
} |
} |
| 354 |
|
// registration |
| 355 |
|
if ($form_values['ezmlm_register']) { |
| 356 |
|
variable_set('ezmlm_register', 1); |
| 357 |
|
} |
| 358 |
|
else { |
| 359 |
|
variable_set('ezmlm_register', 0); |
| 360 |
|
} |
| 361 |
|
if ( variable_get('ezmlm_register', 0) ) { |
| 362 |
|
// reg list |
| 363 |
|
if (is_array($lists) && $count > 0) { |
| 364 |
|
variable_del('ezmlm_register_list'); |
| 365 |
|
$arr = array(); |
| 366 |
|
foreach ($lists as $list_text => $list_email) { |
| 367 |
|
$list_text = preg_replace('/\s/', '~', $list_text); |
| 368 |
|
if ( isset($form_values["reg_$list_text"]) && $form_values["reg_$list_text"] == 1 ) { |
| 369 |
|
$list_text = preg_replace('/~/', ' ', $list_text); |
| 370 |
|
$arr[$list_text] = $list_email; |
| 371 |
|
} |
| 372 |
|
} |
| 373 |
|
if ( count($arr) ) { |
| 374 |
|
variable_set('ezmlm_register_list', $arr); |
| 375 |
|
} |
| 376 |
|
} |
| 377 |
|
} |
| 378 |
|
// display |
| 379 |
|
if ( $form_values['ezmlm_display'] ) { |
| 380 |
|
variable_set('ezmlm_display', $form_values['ezmlm_display']); |
| 381 |
|
} |
| 382 |
|
if ( $form_values['ezmlm_block_display'] ) { |
| 383 |
|
variable_set('ezmlm_block_display', $form_values['ezmlm_block_display']); |
| 384 |
|
} |
| 385 |
|
if ( $form_values['ezmlm_reg_display'] ) { |
| 386 |
|
variable_set('ezmlm_reg_display', $form_values['ezmlm_reg_display']); |
| 387 |
|
} |
| 388 |
} |
} |
| 389 |
|
|
| 390 |
// internal functions |
// internal functions |
| 394 |
* @return |
* @return |
| 395 |
* HTML form. |
* HTML form. |
| 396 |
*/ |
*/ |
| 397 |
function _ezmlm_subscribe_form() { |
function _ezmlm_subscribe_form($type='DEFAULT', $display='email') { |
| 398 |
global $user; |
global $user; |
| 399 |
|
|
| 400 |
$listct = _ezmlm_get_count(); |
$listct = _ezmlm_get_count($type); |
| 401 |
if ($listct == 0) { |
if ($listct == 0) { |
| 402 |
return t('There are no lists available for subscription.'); // formatting? |
return t('There are no lists available for subscription.'); // formatting? |
| 403 |
} |
} |
| 404 |
$lists = _ezmlm_get_lists(); |
$lists = _ezmlm_get_lists($type); |
| 405 |
|
|
| 406 |
$form['subscribe'] = array( |
$form['subscribe'] = array( |
| 407 |
'#type' => 'markup', |
'#type' => 'markup', |
| 412 |
$list_email = trim($list_email); |
$list_email = trim($list_email); |
| 413 |
$form['ezmlm_subscribe']["ezmlm_list_$ct"] = array( |
$form['ezmlm_subscribe']["ezmlm_list_$ct"] = array( |
| 414 |
'#type' => 'checkbox', |
'#type' => 'checkbox', |
| 415 |
'#title' => $list_email, |
'#title' => ($display=='name' ? $list_text : $list_email), |
| 416 |
'#return_value' => $list_email, |
'#return_value' => $list_email, |
| 417 |
); |
); |
| 418 |
$ct++; |
$ct++; |
| 423 |
'#default_value' => ($user->mail ? $user->mail : ''), |
'#default_value' => ($user->mail ? $user->mail : ''), |
| 424 |
'#size' => 20, |
'#size' => 20, |
| 425 |
'#maxlength' => 80, |
'#maxlength' => 80, |
| 426 |
); |
); |
| 427 |
$form['submit'] = array( |
$form['submit'] = array( |
| 428 |
'#type' => 'submit', |
'#type' => 'submit', |
| 429 |
'#value' => t('Subscribe')); |
'#value' => t('Subscribe') |
| 430 |
|
); |
| 431 |
|
|
| 432 |
return $form; |
return $form; |
| 433 |
} |
} |
| 439 |
foreach ($form_values as $key => $address) { |
foreach ($form_values as $key => $address) { |
| 440 |
$address = trim($address); |
$address = trim($address); |
| 441 |
if ($key == "ezmlm_list_$ct" && $address && in_array($address, $lists)) { |
if ($key == "ezmlm_list_$ct" && $address && in_array($address, $lists)) { |
| 442 |
$arr[] = $address; |
$arr[] = $address; |
| 443 |
} |
} |
| 444 |
$ct++; |
$ct++; |
| 445 |
} |
} |
| 446 |
if (count($arr) < 1) { |
if (count($arr) < 1) { |
| 447 |
form_set_error('', t('No lists selected!')); |
form_set_error('', t('No lists selected!')); |
| 448 |
} |
} |
| 449 |
if ($error = user_validate_mail($form_values['ezmlm_email'])) { |
if ($error = user_validate_mail($form_values['ezmlm_email'])) { |
| 450 |
form_set_error('ezmlm_email', $error); |
form_set_error('ezmlm_email', $error); |
| 460 |
$address = trim($address); |
$address = trim($address); |
| 461 |
if ($key == "ezmlm_list_$ct" && $address && in_array($address, $lists)) { |
if ($key == "ezmlm_list_$ct" && $address && in_array($address, $lists)) { |
| 462 |
$arr[] = $address; |
$arr[] = $address; |
| 463 |
} |
} |
| 464 |
$ct++; |
$ct++; |
| 465 |
} |
} |
| 466 |
$email = trim($form_values['ezmlm_email']); |
$email = trim($form_values['ezmlm_email']); |
| 467 |
$ret = _ezmlm_subscribe_process($arr, $email); |
$ret = _ezmlm_subscribe_process($arr, $email); |
| 468 |
if (is_array($ret)) { |
if (is_array($ret)) { |
| 469 |
$output = (t('Please check your mail at %mail to confirm registration of:', array('%mail' => $email))); |
$output = (t('Please check your mail at %mail to confirm registration of:', array('%mail' => $email))); |
| 470 |
drupal_set_message($output ."<br>". implode('<br>', $ret)); |
drupal_set_message($output ."<br />". implode('<br />', $ret)); |
| 471 |
} |
} |
| 472 |
else { |
else { |
| 473 |
drupal_set_message($ret, 'error'); |
drupal_set_message($ret, 'error'); |
| 503 |
* Return current number of lists. |
* Return current number of lists. |
| 504 |
* Use this instead of count(_ezmlm_get_lists()) because non-array counts as 1. |
* Use this instead of count(_ezmlm_get_lists()) because non-array counts as 1. |
| 505 |
*/ |
*/ |
| 506 |
function _ezmlm_get_count() { |
function _ezmlm_get_count($type='DEFAULT') { |
| 507 |
$lists = _ezmlm_get_lists(); |
$lists = _ezmlm_get_lists($type); |
| 508 |
if (!is_array($lists)) { |
if (!is_array($lists)) { |
| 509 |
return 0; |
return 0; |
| 510 |
} |
} |
| 516 |
/** |
/** |
| 517 |
* Return array of current mailing lists. |
* Return array of current mailing lists. |
| 518 |
*/ |
*/ |
| 519 |
function _ezmlm_get_lists() { |
function _ezmlm_get_lists($type='DEFAULT') { |
| 520 |
return variable_get('ezmlmmailinglists', ''); |
if ($type=='DEFAULT') { |
| 521 |
|
return variable_get('ezmlmmailinglists', ''); |
| 522 |
|
} |
| 523 |
|
elseif ($type=='REG') { |
| 524 |
|
return variable_get('ezmlm_register_list', ''); |
| 525 |
|
} |
| 526 |
} |
} |
| 527 |
|
|