. */ /** * Class CFDBPostDataConverter Converts $_POST and $_FILE into the standard format for * this plugin to save it */ class CFDBPostDataConverter { /** * @var array name of fiels not to save */ var $excludeFields = array(); public function addExcludeField($fieldName) { $this->excludeFields[] = $fieldName; } /** * @param $title string form title * @return object that can be passed to CF7DBPlugin::saveData() */ public function convert($title) { $data = null; if (is_array($_POST) && !empty($_POST)) { $posted_data = array(); $uploaded_files = array(); // Get posted values foreach ($_POST as $key => $val) { if (!in_array($key, $this->excludeFields)) { $posted_data[$key] = $val; } } // Deal with upload files // $_FILES = Array ( // [your-upload] => Array // ( // [name] => readme.txt // [type] => text/plain // [tmp_name] => /tmp/php3tQ1zg // [error] => 0 // [size] => 1557 // ) //) if (is_array($_FILES) && !empty($_FILES)) { foreach ($_FILES as $key => $file) { if (is_uploaded_file($file['tmp_name'])) { $posted_data[$key] = $file['name']; $uploaded_files[$key] = $file['tmp_name']; } } } if (!$title) { $title = 'Untitled'; } // Prepare data structure for call to hook $data = (object)array('title' => $title, 'posted_data' => $posted_data, 'uploaded_files' => $uploaded_files); } return $data; } }