/libs/lib-formsubmit.php

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