| 1 |
<?php |
<?php |
| 2 |
// $Id: ezmlm.module,v 1.18.4.1.2.2 2007/12/29 15:59:07 hutch Exp $ |
// $Id: ezmlm.module,v 1.18.4.1.2.3 2008/07/01 15:14:55 hutch Exp $ |
| 3 |
// $Name: DRUPAL-6--1 $ |
// $Name: $ |
| 4 |
// for drupal 6.x |
// for drupal 6.x |
| 5 |
|
|
| 6 |
/** |
/** |
| 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($path, $arg) { |
function ezmlm_help($path, $arg) { |
| 108 |
); |
); |
| 109 |
$items['ezmlm'] = array( |
$items['ezmlm'] = array( |
| 110 |
'title' => 'Mailing lists', |
'title' => 'Mailing lists', |
| 111 |
'page callback' => 'drupal_get_form', |
'page callback' => 'ezmlm_page', |
|
'page arguments' => array('ezmlm_subscribe_form'), |
|
| 112 |
'access arguments' => array('access content'), |
'access arguments' => array('access content'), |
| 113 |
'type' => MENU_NORMAL_ITEM, |
'type' => MENU_NORMAL_ITEM, |
| 114 |
); |
); |
| 140 |
switch ($delta) { |
switch ($delta) { |
| 141 |
case 0: |
case 0: |
| 142 |
$block = ""; |
$block = ""; |
| 143 |
if (strlen(trim(variable_get('ezmlmmailinglists', '')))) { |
if (drupal_strlen(trim(variable_get('ezmlmmailinglists', '')))) { |
| 144 |
$block['subject'] = variable_get('ezmlm_block_title', t('Subscriptions')); |
$block['subject'] = variable_get('ezmlm_block_title', t('Subscriptions')); |
| 145 |
$block['content'] .= _ezmlm_page(); |
$block['content'] .= ezmlm_page(variable_get('ezmlm_block_display', 'email')); |
| 146 |
} |
} |
| 147 |
return $block; |
return $block; |
| 148 |
} |
} |
| 160 |
* @return |
* @return |
| 161 |
* HTML form. |
* HTML form. |
| 162 |
*/ |
*/ |
| 163 |
function ezmlm_subscribe_form() { |
function ezmlm_subscribe_form($form_state, $type = 'DEFAULT', $display = 'email') { |
| 164 |
global $user; |
global $user; |
| 165 |
|
|
| 166 |
if (_ezmlm_get_count()) { |
if (_ezmlm_get_count($type)) { |
| 167 |
$lists = _ezmlm_get_lists(); |
$lists = _ezmlm_get_lists($type); |
| 168 |
$form['subscribe'] = array( |
$form['subscribe'] = array( |
| 169 |
'#type' => 'markup', |
'#type' => 'markup', |
| 170 |
'#value' => variable_get('ezmlm_title', t('Mailing lists')), |
'#value' => variable_get('ezmlm_title', t('Mailing lists')), |
| 174 |
$list_email = trim($list_email); |
$list_email = trim($list_email); |
| 175 |
$form['ezmlm_subscribe']["ezmlm_list_$ct"] = array( |
$form['ezmlm_subscribe']["ezmlm_list_$ct"] = array( |
| 176 |
'#type' => 'checkbox', |
'#type' => 'checkbox', |
| 177 |
'#title' => $list_email, |
'#title' => ($display=='name' ? $list_text : $list_email), |
| 178 |
'#return_value' => $list_email, |
'#return_value' => $list_email, |
| 179 |
); |
); |
| 180 |
$ct++; |
$ct++; |
| 181 |
} |
} |
| 182 |
$form['ezmlm_email'] = array ( |
$form['ezmlm_email'] = array( |
| 183 |
'#type' => 'textfield', |
'#type' => 'textfield', |
| 184 |
'#title' => t('Your email address'), |
'#title' => t('Your email address'), |
| 185 |
'#default_value' => ($user->mail ? $user->mail : ''), |
'#default_value' => ($user->mail ? $user->mail : ''), |
| 191 |
'#value' => t('Subscribe')); |
'#value' => t('Subscribe')); |
| 192 |
} |
} |
| 193 |
else { |
else { |
| 194 |
$form['subscribe'] = array( |
$form['subscribe'] = array( |
| 195 |
'#type' => 'markup', |
'#type' => 'markup', |
| 196 |
'#value' => 'There are no lists available for subscription.', |
'#value' => 'There are no lists available for subscription.', |
| 197 |
); |
); |
| 206 |
$arr = array(); |
$arr = array(); |
| 207 |
$lists = _ezmlm_get_lists(); |
$lists = _ezmlm_get_lists(); |
| 208 |
$ct = 1; |
$ct = 1; |
| 209 |
foreach ($form_state['values'] as $key=>$address) { |
foreach ($form_state['values'] as $key => $address) { |
| 210 |
$address = trim($address); |
$address = trim($address); |
| 211 |
if( $key == "ezmlm_list_$ct" && $address && in_array($address, $lists)) { |
if ($key == "ezmlm_list_$ct" && $address && in_array($address, $lists)) { |
| 212 |
$arr[] = $address; |
$arr[] = $address; |
| 213 |
} |
} |
| 214 |
$ct++; |
$ct++; |
| 215 |
} |
} |
| 216 |
if ( count($arr) < 1 ) { |
if (count($arr) < 1) { |
| 217 |
form_set_error('', t('No lists selected!')); |
form_set_error('', t('No lists selected!')); |
| 218 |
} |
} |
| 219 |
if ( $error = user_validate_mail($form_state['values']['ezmlm_email'])) { |
if ( $error = user_validate_mail($form_state['values']['ezmlm_email'])) { |
| 229 |
$arr = array(); |
$arr = array(); |
| 230 |
$ct = 1; |
$ct = 1; |
| 231 |
// get the selected mailing list addresses |
// get the selected mailing list addresses |
| 232 |
foreach ($form_state['values'] as $key=>$address) { |
foreach ($form_state['values'] as $key => $address) { |
| 233 |
$address = trim($address); |
$address = trim($address); |
| 234 |
if( $key == "ezmlm_list_$ct" && $address && in_array($address, $lists)) { |
if ($key == "ezmlm_list_$ct" && $address && in_array($address, $lists)) { |
| 235 |
$arr[] = $address; |
$arr[] = $address; |
| 236 |
} |
} |
| 237 |
$ct++; |
$ct++; |
| 238 |
} |
} |
| 239 |
$email = trim($form_state['values']['ezmlm_email']); |
$email = trim($form_state['values']['ezmlm_email']); |
| 240 |
$ret = _ezmlm_subscribe_process($arr, $email); |
$ret = _ezmlm_subscribe_process($arr, $email); |
| 241 |
if ( is_array($ret)) { |
if ( is_array($ret)) { |
| 242 |
$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))); |
| 243 |
drupal_set_message($output . "<br>" . implode('<br>', $ret)); |
drupal_set_message($output ."<br />". implode('<br />', $ret)); |
| 244 |
} |
} |
| 245 |
else { |
else { |
| 246 |
drupal_set_message($ret, 'error'); |
drupal_set_message($ret, 'error'); |
| 252 |
* Menu callback; presents the subscription form on a page, or processes |
* Menu callback; presents the subscription form on a page, or processes |
| 253 |
* that form's input, whether from block or page. |
* that form's input, whether from block or page. |
| 254 |
*/ |
*/ |
| 255 |
function _ezmlm_page() { |
function ezmlm_page($display = FALSE) { |
| 256 |
$output = drupal_get_form('ezmlm_subscribe_form'); |
if (! $display) { |
| 257 |
|
$display = variable_get('ezmlm_display', 'email'); |
| 258 |
|
} |
| 259 |
|
$output = drupal_get_form('ezmlm_subscribe_form', 'DEFAULT', $display); |
| 260 |
return $output; |
return $output; |
| 261 |
} |
} |
| 262 |
|
|
| 282 |
} |
} |
| 283 |
} |
} |
| 284 |
} |
} |
| 285 |
return($mylists); |
return $mylists; |
| 286 |
} |
} |
| 287 |
|
|
|
|
|
| 288 |
/** |
/** |
| 289 |
* Return current number of lists. |
* Return current number of lists. |
| 290 |
* 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. |
| 291 |
*/ |
*/ |
| 292 |
function _ezmlm_get_count() { |
function _ezmlm_get_count($type='DEFAULT') { |
| 293 |
$lists = _ezmlm_get_lists(); |
$lists = _ezmlm_get_lists($type); |
| 294 |
if (!is_array($lists)) { |
if (!is_array($lists)) { |
| 295 |
return 0; |
return 0; |
| 296 |
} |
} |
| 302 |
/** |
/** |
| 303 |
* Return array of current mailing lists. |
* Return array of current mailing lists. |
| 304 |
*/ |
*/ |
| 305 |
function _ezmlm_get_lists() { |
function _ezmlm_get_lists($type='DEFAULT') { |
| 306 |
return variable_get('ezmlmmailinglists', ''); |
if (is_array($type)) { |
| 307 |
|
$type = 'DEFAULT'; |
| 308 |
|
} |
| 309 |
|
if ($type=='DEFAULT') { |
| 310 |
|
return variable_get('ezmlmmailinglists', ''); |
| 311 |
|
} |
| 312 |
|
elseif ($type=='REG') { |
| 313 |
|
return variable_get('ezmlm_register_list', ''); |
| 314 |
|
} |
| 315 |
} |
} |
| 316 |
|
|