/libs/lib-formsubmit.php

  1. <?php 
  2.  
  3. // access wp functions externally 
  4. require_once('lib-bootstrap.php'); 
  5. include_once(ABSPATH . 'wp-includes/pluggable.php'); // required for wp_mail 
  6.  
  7. if ( ! function_exists('gde_activate') ) { 
  8. // no access if parent plugin is disabled 
  9. wp_die('<p>'.__('You do not have sufficient permissions to access this page.').'</p>'); 
  10. } elseif ( empty( $_POST ) || ! isset( $_POST['email'] ) || empty( $_POST['email'] ) ) { 
  11. // fail submit if email not completed 
  12. echo "fail"; 
  13. exit; 
  14. } else { 
  15.  
  16. function gde_change_phpmailer( $phpmailer ) { 
  17. // gather settings and profiles 
  18. $datasrc = GDE_PLUGIN_URL . 'libs/lib-service.php?json=all'; 
  19. $response = wp_remote_get( $datasrc ); 
  20. if ( is_wp_error( $response ) ) { 
  21. $contents = "Error attaching export data."; 
  22. $file = "export-error.txt"; 
  23. } else { 
  24. $contents = $response['body']; 
  25. $file = "gde-export.txt"; 
  26. $phpmailer->AddStringAttachment( $contents, $file, 'base64', 'text/plain' ); 
  27.  
  28. // gather dx log 
  29. $blogid = get_current_blog_id(); 
  30. $datasrc = GDE_PLUGIN_URL . 'libs/lib-service.php?viewlog=all&blogid=' . $blogid; 
  31. $response = wp_remote_get( $datasrc ); 
  32. if ( is_wp_error( $response ) ) { 
  33. $contents = "[InternetShortcut]\nURL=" . $datasrc ."\n"; 
  34. $file = "remote-dx-log.url"; 
  35. } else { 
  36. $contents = $response['body']; 
  37. $file = "dx-log.txt"; 
  38. $phpmailer->AddStringAttachment( $contents, $file, 'base64', 'text/plain' ); 
  39.  
  40.  
  41. function gde_change_mail( $mail ) { 
  42. return $_POST['email']; 
  43.  
  44. function gde_change_sender( $sendername ) { 
  45. if ($_POST['name']) { 
  46. return $_POST['name']; 
  47. } else { 
  48. return "GDE User"; 
  49.  
  50. add_filter( 'wp_mail_from', 'gde_change_mail', 1 ); 
  51. add_filter( 'wp_mail_from_name', 'gde_change_sender', 1 ); 
  52.  
  53. /**  
  54. * Note to self: wp_mail doesn't deliver to Google Apps (at least in this config). 
  55. * It does deliver to regular Gmail, if necessary. Why? Hours wasted. 
  56. * Instead, deliver to POP account and let GA pick it up. Boo. 
  57. */ 
  58. $to = "wpp@dev.davismetro.com"; 
  59.  
  60. $subject = "GDE Support Request"; 
  61.  
  62. $headers = ""; 
  63. if ($_POST['cc'] == "yes") { 
  64. $headers .= "CC: " . $_POST['email'] . "\n"; 
  65. $headers .= "Reply-To: <" . $_POST['email'] . ">\n"; 
  66.  
  67. $message = "A request was sent from the GDE Support Form.\n\n"; 
  68. if ( $_POST['msg'] ) { 
  69. $message .= stripslashes( $_POST['msg'] ) . "\n\n"; 
  70. } else { 
  71. $message .= "No message was included.\n\n"; 
  72.  
  73. if ( $_POST['sc'] ) { 
  74. $message .= "Shortcode: " . stripslashes( $_POST['sc'] ) . "\n\n"; 
  75. } else { 
  76. $message .= "No shortcode was included.\n\n"; 
  77.  
  78. if ( $_POST['url'] ) { 
  79. $message .= "URL: " . stripslashes( $_POST['url'] ) . "\n\n"; 
  80. } else { 
  81. $message .= "No URL was included.\n\n"; 
  82.  
  83. if ( $_POST['senddb'] ) { 
  84. $message .= $_POST['senddb']; 
  85.  
  86. // add debug attachment 
  87. add_filter( 'phpmailer_init', 'gde_change_phpmailer' ); 
  88. } else { 
  89. $message .= "No debug info was included."; 
  90.  
  91. if (wp_mail( $to, $subject, $message, $headers )) { 
  92. echo "success"; 
  93. } else { 
  94. echo "fail"; 
  95.  
  96. ?> 
.