PageRenderTime 41ms CodeModel.GetById 15ms RepoModel.GetById 1ms app.codeStats 0ms

/wp-content/plugins/wp-responder-email-autoresponder-and-newsletter-plugin/controllers/new-broadcast.php

https://bitbucket.org/antonyravel/cape-resorts
PHP | 105 lines | 80 code | 21 blank | 4 comment | 9 complexity | 00072624c36fc3a7ef219b1150189bb3 MD5 | raw file
  1. <?php
  2. function _wpr_new_broadcast_handler()
  3. {
  4. $newsletters = _wpr_get_newsletters();
  5. _wpr_set("newsletterList",$newsletters);
  6. _wpr_set("send","immediately");
  7. _wpr_set("timezone","+00:00");
  8. }
  9. function _wpr_new_broadcast_post_handler()
  10. {
  11. //security check
  12. if (!check_admin_referer("new_broadcast_form"))
  13. {
  14. header('HTTP/1.0 404 Not Found');
  15. exit;
  16. }
  17. $errors = array();
  18. $newsletter = intval($_POST['newsletter']);
  19. $newsletter_obj = _wpr_get_newsletter($newsletter);
  20. //ensure that this newsleter exists.
  21. if (false == $newsletter_obj)
  22. {
  23. $errors[] = __("The selected newsletter doesn't exist.",'wpr_autoresponder');
  24. //then again.. what are the odds of the newsletter not existing..
  25. }
  26. $subject = wpr_sanitize($_POST['subject']);
  27. $content = wpr_sanitize($_POST['content'],false);
  28. $textbody = wpr_sanitize($_POST['textbody']);
  29. $send = $_POST['send'];
  30. if ("later"==$send)
  31. {
  32. $date = wpr_sanitize($_POST['send_date']);
  33. $date_parts = explode("/", $date);
  34. try
  35. {
  36. if (3 != count($date_parts))
  37. throw new Exception(__("The date is entered in an invalid format. Please enter a valid date in MM/DD/YYYY format.",'wpr_autoresponder'));
  38. foreach ($date_parts as $index=>$parts)
  39. $date_parts[$index] = intval($parts);
  40. if (in_array(0,$date_parts))
  41. throw new Exception(__("The date is entered in an invalid format. Please enter a valid date in MM/DD/YYYY format.",'wpr_autoresponder'));
  42. list($month,$date,$year) = split("/",$date);
  43. if (!checkdate($month,$date,$year))
  44. throw new Exception(__("The date entered in the date field is invalid. Please enter a valid date.",'wpr_autoresponder'));
  45. $send_hour = intval($_POST['send_hour']);
  46. $send_minutes = intval($_POST['send_minute']);
  47. //what follows is the most questionable piece of code i ever wrote. don't ask why, just run with it.
  48. //get the timezone offset in seconds
  49. $timezone = $_POST['timezone'];
  50. list($timezone_offset_hour, $timezone_offset_minute) = split(":",$timezone);
  51. $whetherToAddTimezoneOffset = strstr($timezone,"+");
  52. $timezoneOffsetInSeconds = abs($timezone_offset_hour)*3600+abs($timezone_offset_minute)*60;
  53. $timezoneOffsetInSeconds = (!$whetherToAddTimezoneOffset)?-$timezoneOffsetInSeconds:$timezoneOffsetInSeconds;
  54. $epoch_of_scheduled_time = mktime($send_hour,$send_minutes, 0,$month,$date,$year);
  55. if (false===$epoch_of_scheduled_time)
  56. throw new Exception("The date and time combination you have selected is invalid. Please enter a valid date-time.");
  57. $epoch_of_scheduled_time += $timezoneOffsetInSeconds;
  58. $epochNow = time();
  59. if ($epochNow >= $epoch_of_scheduled_time)
  60. throw new Exception("The date and time combination you have provided is in the past. Please specify a dispatch time in the future.");
  61. }
  62. catch (Exception $e)
  63. {
  64. $errors[] = $e->getMessage();
  65. }
  66. }
  67. if (empty($content) && empty($textbody))
  68. {
  69. $errors[] = __("Both the HTML and text body of the broadcast are empty. Atleast one of them must be filled to send a broadcast.",'wpr_autoresponder');
  70. }
  71. if (count($errors) == 0 )
  72. {
  73. //go to step two.
  74. }
  75. }