CFDBIntegrationWRContactForm

"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).

/CFDBIntegrationWRContactForm.php  
  1. class CFDBIntegrationWRContactForm { 
  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('wr_contactform_before_save_form', array(&$this, 'saveFormData'), 10, 7); 
  16.  
  17. /** 
  18. * @param $dataForms array 
  19. * @param $postID array 
  20. * @param $post array 
  21. * @param $submissionsData array 
  22. * @param $dataContentEmail array 
  23. * @param $nameFileByIdentifier array 
  24. * @param $requiredField array 
  25. * @param $fileAttach array 
  26. * @return bool 
  27. */ 
  28. public function saveFormData($dataForms, $postID, $post, $submissionsData, $dataContentEmail,  
  29. $nameFileByIdentifier, $requiredField, $fileAttach) { 
  30.  
  31. try { 
  32. $data = $this->convertData($dataForms, $postID, $post, $submissionsData, $dataContentEmail,  
  33. $nameFileByIdentifier, $requiredField, $fileAttach); 
  34. return $this->plugin->saveFormData($data); 
  35. } catch (Exception $ex) { 
  36. $this->plugin->getErrorLog()->logException($ex); 
  37. return true; 
  38.  
  39.  
  40. public function convertData($dataForms, $postID, $post, $submissionsData, $dataContentEmail,  
  41. $nameFileByIdentifier, $requiredField, $fileAttach) { 
  42.  
  43. $postedData = array(); 
  44. $uploadFiles = array(); 
  45.  
  46. foreach ($dataContentEmail as $fieldKey => $fieldValue) { 
  47. $fieldName = $nameFileByIdentifier[$fieldKey]; 
  48.  
  49. if (strpos($fieldKey, 'file_upload_') === 0) { 
  50. // Handle upload files 
  51. $href = array(); 
  52. preg_match('#<a href=\"([^\"]*)/wp-content/uploads/wr_contactform/([^\"]*)\">(.*)</a>#iU', $fieldValue, $href); 
  53. if (count($href) >= 3) { 
  54. // [0] => <a href="http://site.com/wp-content/uploads/wr_contactform/2015/01/icon-50x50.png">icon-50x50.png</a> 
  55. // [1] => http://site.com 
  56. // [2] => 2015/01/icon-50x50.png 
  57. // [3] => icon-50x50.png 
  58. $filePath = dirname(dirname(dirname(__FILE__))) . '/uploads/wr_contactform/' . $href[2]; 
  59. $uploadFiles[$fieldName] = $filePath; 
  60. $fieldValue = trim(preg_replace('#<[^>]+>#', ' ', $fieldValue)); 
  61. $postedData[$fieldName] = $fieldValue; 
  62.  
  63. $data = (object)array( 
  64. 'title' => get_the_title($postID),  
  65. 'posted_data' => $postedData,  
  66. 'uploaded_files' => $uploadFiles); 
  67. return $data; 
  68.