CFDBIntegrationContactForm7

"Contact Form to Database" Copyright (C) 2011-2015 Michael Simpson (email : michael.d.simpson@gmail.com).

Defined (1)

The class is defined in the following location(s).

/CFDBIntegrationContactForm7.php  
  1. class CFDBIntegrationContactForm7 { 
  2.  
  3. /** 
  4. * @var CF7DBPlugin 
  5. */ 
  6. var $plugin; 
  7.  
  8. /** 
  9. * @param $plugin CF7DBPlugin 
  10. */ 
  11. function __construct($plugin) { 
  12. $this->plugin = $plugin; 
  13.  
  14. public function registerHooks() { 
  15. add_action('wpcf7_before_send_mail', array(&$this, 'saveFormData')); 
  16. // Generate submit_time for CF7 mail. Some people complain this causes an error 
  17. // so this is now optional and off by default. Seems to be related to CF7 
  18. // checking its data against blacklist 
  19. if ($this->plugin->getOption('GenerateSubmitTimeInCF7Email', 'false') == 'true') { 
  20. add_action('wpcf7_posted_data', array(&$this, 'generateSubmitTimeForCF7')); 
  21.  
  22. /** 
  23. * Callback from Contact Form 7. CF7 passes an object with the posted data which is inserted into the database 
  24. * by this function. 
  25. * @param $cf7 WPCF7_ContactForm 
  26. * @return bool 
  27. */ 
  28. public function saveFormData($cf7) { 
  29. try { 
  30. $data = $this->convertData($cf7); 
  31. return $this->plugin->saveFormData($data); 
  32. } catch (Exception $ex) { 
  33. $this->plugin->getErrorLog()->logException($ex); 
  34. return true; 
  35.  
  36.  
  37. /** 
  38. * @param $cf7 WPCF7_ContactForm 
  39. * @return object 
  40. */ 
  41. public function convertData($cf7) { 
  42. if (!isset($cf7->posted_data) && class_exists('WPCF7_Submission')) { 
  43. // Contact Form 7 version 3.9 removed $cf7->posted_data and now 
  44. // we have to retrieve it from an API 
  45. $submission = WPCF7_Submission::get_instance(); 
  46. if ($submission) { 
  47. $data = array(); 
  48. $data['title'] = $cf7->title(); 
  49. $data['posted_data'] = $submission->get_posted_data(); 
  50. $data['uploaded_files'] = $submission->uploaded_files(); 
  51. $data['WPCF7_ContactForm'] = $cf7; 
  52. return (object) $data; 
  53. return $cf7; 
  54.  
  55. /** 
  56. * Generate the submit_time and submit_url so they can be added to CF7 mail 
  57. * @param $posted_data array 
  58. * @return array 
  59. */ 
  60. public function generateSubmitTimeForCF7($posted_data) { 
  61. try { 
  62. $time = $this->plugin->generateSubmitTime(); 
  63. $posted_data['submit_time'] = $time; 
  64.  
  65. // No longer generating submit_url because it seems to cause CF7 to think it is 
  66. // a spam submission and it drops it. 
  67. // $url = get_admin_url() . sprintf('admin.php?page=%s&submit_time=%s',  
  68. // 
  69. // $this->getDBPageSlug(),  
  70. // $time); 
  71. // $posted_data['submit_url'] = $url; 
  72. } catch (Exception $ex) { 
  73. $this->plugin->getErrorLog()->logException($ex); 
  74. return $posted_data; 
  75.  
  76.