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. $filePath = $this->parseFileUrl($fieldValue); 
  52. if ($filePath) { 
  53. $uploadFiles[$fieldName] = $filePath; 
  54. $fieldValue = trim(preg_replace('#<[^>]+>#', ' ', $fieldValue)); 
  55. $postedData[$fieldName] = $fieldValue; 
  56.  
  57. $data = (object)array( 
  58. 'title' => get_the_title($postID),  
  59. 'posted_data' => $postedData,  
  60. 'uploaded_files' => $uploadFiles); 
  61. return $data; 
  62.  
  63. /** 
  64. * @param $fileUrl 
  65. * @return string 
  66. */ 
  67. public function parseFileUrl($fileUrl) { 
  68. $href = array(); 
  69. preg_match('#<a href=\"([^\"]*)/wp-content/([^\"]*)\">(.*)</a>#iU', $fileUrl, $href); 
  70. if (count($href) >= 3) { 
  71. // [0] => <a href="http://www.site.com/wp-content/uploads/2015/08/Amazon-icon1.png">Amazon.png</a> 
  72. // [1] => http://www.site.com 
  73. // [2] => uploads/2015/08/Amazon-icon1.png 
  74. // [3] => Amazon.png 
  75. $wpContentDirPath = dirname(dirname(dirname(__FILE__))); 
  76. return $wpContentDirPath . DIRECTORY_SEPARATOR . $href[2]; 
  77. return null; 
  78.