| 16 |
/** |
/** |
| 17 |
* Implementation of hook_help(). |
* Implementation of hook_help(). |
| 18 |
*/ |
*/ |
| 19 |
function tellafriend_help($section) { |
function tellafriend_help($path, $arg) { |
| 20 |
switch ($section) { |
switch ($path) { |
| 21 |
case 'admin/help#poll': |
case 'admin/help#poll': |
| 22 |
return t("Access page at: tellafriend"); |
return t("Access page at: tellafriend"); |
| 23 |
case 'admin/modules#description': |
case 'admin/modules#description': |
| 42 |
function tellafriend_menu() { |
function tellafriend_menu() { |
| 43 |
$items = array(); |
$items = array(); |
| 44 |
|
|
| 45 |
$items[] = array( |
$items['admin/settings/tellafriend'] = array( |
| 46 |
'path' => 'admin/settings/tellafriend', |
'title' => 'Tell a friend', |
| 47 |
'title' => t('Tell a friend'), |
'description' => 'Control the contents of <em>Tell a friend</em> e-mail message.', |
| 48 |
'description' => t('Control the contents of <em>Tell a friend</em> e-mail message.'), |
'page callback' => 'drupal_get_form', |
| 49 |
'callback' => 'drupal_get_form', |
'page arguments' => 'tellafriend_settings', |
| 50 |
'callback arguments' => 'tellafriend_settings', |
'access arguments' => array('administer site configuration'), |
|
'access' => user_access('administer site configuration'), |
|
| 51 |
'type' => MENU_NORMAL_ITEM, |
'type' => MENU_NORMAL_ITEM, |
| 52 |
); |
); |
| 53 |
$items[] = array( |
$items['tellafriend'] = array( |
| 54 |
'path' => 'tellafriend', |
'title' => variable_get('tellafriend_pagetitle', 'Tell a friend'), |
| 55 |
'title' => variable_get('tellafriend_pagetitle', t('Tell a friend')), |
'page callback' => 'drupal_get_form', |
| 56 |
'callback' => 'drupal_get_form', |
'page arguments' => 'tellafriend_page', |
| 57 |
'callback arguments' => 'tellafriend_page', |
'access arguments' => array('access tellafriend form'), |
|
'access' => user_access('access tellafriend form'), |
|
| 58 |
'type' => MENU_CALLBACK, |
'type' => MENU_CALLBACK, |
| 59 |
); |
); |
| 60 |
|
|
| 281 |
/** |
/** |
| 282 |
* Implementation of hook_validate(). |
* Implementation of hook_validate(). |
| 283 |
*/ |
*/ |
| 284 |
function tellafriend_page_validate($form_id, $form_values) { |
function tellafriend_page_validate($form, &$form_state) { |
| 285 |
$tellafriend_personal = $form_values['tellafriend_personal']; |
$tellafriend_personal = $form_state['values']['tellafriend_personal']; |
| 286 |
|
|
| 287 |
if (!valid_email_address($form_values['tellafriend_email'])) { |
if (!valid_email_address($form_state['values']['tellafriend_email'])) { |
| 288 |
form_set_error("tellafriend_email", t('Email address is not valid!')); |
form_set_error("tellafriend_email", t('Email address is not valid!')); |
| 289 |
} |
} |
| 290 |
|
|
| 291 |
$addresses = explode(",", $form_values['tellafriend_addresses']); |
$addresses = explode(",", $form_state['values']['tellafriend_addresses']); |
| 292 |
|
|
| 293 |
if(count($addresses) > variable_get('tellafriend_address_limit', TELLAFRIEND_DEFAULT_MAX_EMAIL_ADDRESSES)) { |
if(count($addresses) > variable_get('tellafriend_address_limit', TELLAFRIEND_DEFAULT_MAX_EMAIL_ADDRESSES)) { |
| 294 |
form_set_error("tellafriend_addresses", |
form_set_error("tellafriend_addresses", |
| 313 |
if (!flood_is_allowed('tellafriend', $my_threshold)) { |
if (!flood_is_allowed('tellafriend', $my_threshold)) { |
| 314 |
$tellafriend_validated = 1; |
$tellafriend_validated = 1; |
| 315 |
form_set_error('', t("You can't make more than %number mail requests per hour. Please try again later.", array('%number' => variable_get('tellafriend_hourly_threshold', TELLAFRIEND_DEFAULT_HOURLY_THRESHOLD)))); |
form_set_error('', t("You can't make more than %number mail requests per hour. Please try again later.", array('%number' => variable_get('tellafriend_hourly_threshold', TELLAFRIEND_DEFAULT_HOURLY_THRESHOLD)))); |
| 316 |
watchdog('mail', t('%name has attempted to surpass the flood control for tellafriend.module', array('%name' => $user->name))); |
watchdog('mail', '%name has attempted to surpass the flood control for tellafriend.module', array('%name' => $user->name)); |
| 317 |
} |
} |
| 318 |
} |
} |
| 319 |
|
|
| 320 |
/** |
/** |
| 321 |
* Implementation of hook_submit().Process the personal contact page form submission. |
* Implementation of hook_submit().Process the personal contact page form submission. |
| 322 |
*/ |
*/ |
| 323 |
function tellafriend_page_submit($form_id, $form_values) { |
function tellafriend_page_submit($form, &$form_state) { |
| 324 |
global $base_url; |
global $base_url; |
| 325 |
$placeholder_values = array('!sitename' => variable_get('site_name', 'Drupal'),'!sitelink' => $base_url,'!sitemail' => variable_get('site_mail', ini_get('sendmail_from')), '!sendername' => $form_values['tellafriend_name'], '!sendermail' => $form_values['tellafriend_email']); |
$placeholder_values = array('!sitename' => variable_get('site_name', 'Drupal'),'!sitelink' => $base_url,'!sitemail' => variable_get('site_mail', ini_get('sendmail_from')), '!sendername' => $form_state['values']['tellafriend_name'], '!sendermail' => $form_state['values']['tellafriend_email']); |
| 326 |
$closing = variable_get('tellafriend_closing', 'Sincerely,'); |
$closing = variable_get('tellafriend_closing', 'Sincerely,'); |
| 327 |
//$from = variable_get('tellafriend_fromaddress', $form_values['tellafriend_email']); |
//$from = variable_get('tellafriend_fromaddress', $form_state['values']['tellafriend_email']); |
| 328 |
$from = $form_values['tellafriend_name']. "<".$form_values['tellafriend_email']. ">"; |
$from = $form_state['values']['tellafriend_name']. "<".$form_state['values']['tellafriend_email']. ">"; |
| 329 |
$addresses = explode(",", $form_values['tellafriend_addresses']); |
$addresses = explode(",", $form_state['values']['tellafriend_addresses']); |
| 330 |
$subject = stripslashes(t(variable_get('tellafriend_subject', t('!sendername has invited you to !sitename!')), $placeholder_values)); |
$subject = stripslashes(t(variable_get('tellafriend_subject', t('!sendername has invited you to !sitename!')), $placeholder_values)); |
| 331 |
|
|
| 332 |
if(strlen($form_values['tellafriend_personal'])) { |
if(strlen($form_state['values']['tellafriend_personal'])) { |
| 333 |
$body .= t("\nPersonal Message: ") . $form_values['tellafriend_personal'] . "\n----------------------\n\n"; |
$body .= t("\nPersonal Message: ") . $form_state['values']['tellafriend_personal'] . "\n----------------------\n\n"; |
| 334 |
} |
} |
| 335 |
$body .= t(variable_get('tellafriend_message', t('You are invited to check out !sitename at !sitelink')), $placeholder_values) ."\n$closing \n". $form_values['tellafriend_name'] ." - ". $form_values['tellafriend_email']; |
$body .= t(variable_get('tellafriend_message', t('You are invited to check out !sitename at !sitelink')), $placeholder_values) ."\n$closing \n". $form_state['values']['tellafriend_name'] ." - ". $form_state['values']['tellafriend_email']; |
| 336 |
|
|
| 337 |
foreach ($addresses as $key => $mail) { |
foreach ($addresses as $key => $mail) { |
| 338 |
$sendaddress[$key] = stripslashes(trim($mail)); |
$sendaddress[$key] = stripslashes(trim($mail)); |
| 339 |
drupal_mail('tellafriend-page-mail', $sendaddress[$key], $subject, $body, $from); |
|
| 340 |
|
// drupal_mail('tellafriend-page-mail', $sendaddress[$key], $subject, $body, $from); |
| 341 |
|
/* TODO Create a hook_mail($key, &$message, $params) function to generate |
| 342 |
|
the message body when called by drupal_mail. */ |
| 343 |
|
$account = array(); // Set this as needed |
| 344 |
|
$language = user_preferred_language($account); |
| 345 |
|
$object = array(); // Replace this as needed |
| 346 |
|
$context['subject'] = $subject; |
| 347 |
|
$context['body'] = $body; |
| 348 |
|
$params = array('account' => $account, 'object' => $object, 'context' => $context); |
| 349 |
|
drupal_mail('', 'tellafriend-page-mail', $sendaddress[$key], $language, $params, $from); |
| 350 |
} |
} |
| 351 |
if ($form_values['tellafriend_copy']) { |
if ($form_state['values']['tellafriend_copy']) { |
| 352 |
drupal_mail('tellafriend-page-copy', $form_values['tellafriend_email'], $subject, $body, $from); |
// drupal_mail('tellafriend-page-copy', $form_state['values']['tellafriend_email'], $subject, $body, $from); |
| 353 |
|
/* TODO Create a hook_mail($key, &$message, $params) function to generate |
| 354 |
|
the message body when called by drupal_mail. */ |
| 355 |
|
$account = array(); // Set this as needed |
| 356 |
|
$language = user_preferred_language($account); |
| 357 |
|
$object = array(); // Replace this as needed |
| 358 |
|
$context['subject'] = $subject; |
| 359 |
|
$context['body'] = $body; |
| 360 |
|
$params = array('account' => $account, 'object' => $object, 'context' => $context); |
| 361 |
|
drupal_mail('', 'tellafriend-page-copy', $form_state['values']['tellafriend_email'], $language, $params, $from); |
| 362 |
} |
} |
| 363 |
|
|
| 364 |
flood_register_event('tellafriend'); |
flood_register_event('tellafriend'); |
| 365 |
|
|
| 366 |
$addresses = implode(', ', $sendaddress); |
$addresses = implode(', ', $sendaddress); |
| 367 |
watchdog('mail', t('%sender sent an e-mail to %recepient using <em>Tell a friend</em> form.', array('%sender' => $form_values['tellafriend_name'], '%recepient' => $addresses))); |
watchdog('mail', '%sender sent an e-mail to %recepient using <em>Tell a friend</em> form.', array('%sender' => $form_state['values']['tellafriend_name'], '%recepient' => $addresses)); |
| 368 |
drupal_set_message(t('Thank you! Your message has been sent to: !recepient', array('!recepient' => $addresses))); |
drupal_set_message(t('Thank you! Your message has been sent to: !recepient', array('!recepient' => $addresses))); |
| 369 |
drupal_goto(variable_get('tellafriend_success', variable_get('site_frontpage', 'node'))); |
drupal_goto(variable_get('tellafriend_success', variable_get('site_frontpage', 'node'))); |
| 370 |
} |
} |