private function saveData($id = null) { $thisform = array('id' => $this->_form_id, 'post_type' => $this->_post_type, 'form_type' => $this->_form_type); // do custom actions on post save do_action('cred_before_save_data_' . $this->_form_id, $thisform); do_action('cred_before_save_data', $thisform); // reference to the form submission method global ${'_' . self::METHOD}, $user_ID; $method =& ${'_' . self::METHOD}; // cred form data $_cred_form_data = array(); // main post fields $post = new stdClass(); // if an ID is already generated previously if (($id === null || $id === false || !isset($id) || empty($id)) && (isset($method[self::PREFIX . 'post_id']) && is_numeric($method[self::PREFIX . 'post_id']))) { $post->ID = intval($method[self::PREFIX . 'post_id']); } elseif (isset($id) && !empty($id) && is_numeric($id)) { $post->ID = intval($id); } else { $post->ID = ''; } if ($this->_form->fields['form_settings']->form_type == 'new') { $post->post_author = $user_ID; } // post title if (array_key_exists('post_title', $this->_form_fields) && array_key_exists('post_title', $method) && !$this->_myzebra_form->controls[$this->_form_fields['post_title'][0]]->isDiscarded()) { $post->post_title = array_key_exists('post_title', $method) ? stripslashes($method['post_title']) : ''; unset($method['post_title']); } // post content if (array_key_exists('post_content', $this->_form_fields) && array_key_exists('post_content', $method) && !$this->_myzebra_form->controls[$this->_form_fields['post_content'][0]]->isDiscarded()) { //cred_log($method['post_content']); $post->post_content = array_key_exists('post_content', $method) ? stripslashes($method['post_content']) : ''; unset($method['post_content']); } // post excerpt if (array_key_exists('post_excerpt', $this->_form_fields) && array_key_exists('post_excerpt', $method) && !$this->_myzebra_form->controls[$this->_form_fields['post_excerpt'][0]]->isDiscarded()) { $post->post_excerpt = array_key_exists('post_excerpt', $method) ? stripslashes($method['post_excerpt']) : ''; unset($method['post_excerpt']); } // post parent if (array_key_exists('post_parent', $this->_form_fields) && array_key_exists('post_parent', $method) && !$this->_myzebra_form->controls[$this->_form_fields['post_parent'][0]]->isDiscarded() && isset($this->_fields['parents']) && isset($this->_fields['parents']['post_parent']) && intval($method['post_parent']) >= 0) { $post->post_parent = intval($method['post_parent']); unset($method['post_parent']); } // post type $post->post_type = $this->_form->fields['form_settings']->post_type; // post status if (!isset($this->_form->fields['form_settings']->post_status) || !in_array($this->_form->fields['form_settings']->post_status, array('draft', 'private', 'publish', 'original'))) { $this->_form->fields['form_settings']->post_status = 'draft'; } if (isset($this->_form->fields['form_settings']->post_status) && $this->_form->fields['form_settings']->post_status == 'original' && $this->_form_type != 'edit') { $this->_form->fields['form_settings']->post_status = 'draft'; } if ($this->_form->fields['form_settings']->post_status != 'original') { $post->post_status = isset($this->_form->fields['form_settings']->post_status) ? $this->_form->fields['form_settings']->post_status : 'draft'; } // track form data for notification mail if (isset($this->_form->fields['notification']->enable) && $this->_form->fields['notification']->enable) { if (isset($post->post_title)) { $_cred_form_data[] = 'Post Title: ' . $post->post_title; } if (isset($post->post_content)) { $_cred_form_data[] = 'Post Content: ' . $post->post_content; } } // custom fields $fields = array(); $fieldsInfo = array(); $files = array(); foreach ($this->_fields['post_fields'] as $key => $field) { $field_label = $field['name']; $done_data = false; // if this field was not rendered in this specific form, bypass it if (!array_key_exists($key, $this->_form_fields)) { continue; } // if this field was discarded due to some conditional logic, bypass it if ($this->_myzebra_form->controls[$this->_form_fields[$key][0]]->isDiscarded()) { continue; } $key11 = $key; if (isset($field['plugin_type_prefix'])) { $key = $field['plugin_type_prefix'] . $key; } $fieldsInfo[$key] = array('save_single' => false); if ($field['type'] == 'checkboxes' && isset($field['data']['save_empty']) && $field['data']['save_empty'] == 'yes' && !array_key_exists($key, $method)) { $values = array(); foreach ($field['data']['options'] as $optionkey => $optiondata) { $values[$optionkey] = '0'; } // let model serialize once, fix Types-CRED mapping issue with checkboxes $fieldsInfo[$key]['save_single'] = true; $fields[$key] = $values; } elseif ($field['type'] == 'checkbox' && isset($field['data']['save_empty']) && $field['data']['save_empty'] == 'yes' && !array_key_exists($key, $method)) { $fields[$key] = '0'; } elseif (array_key_exists($key, $method)) { $values = $method[$key]; if ($field['type'] == 'file' || $field['type'] == 'image') { $files[$key] = $this->_myzebra_form->controls[$this->_form_fields[$key11][0]]->get_values(); $files[$key]['name_orig'] = $key11; $files[$key]['label'] = $field['name']; if ($this->_form_fields_qualia[$key11]['repetitive']) { $files[$key]['repetitive'] = true; } else { $files[$key]['repetitive'] = false; } } if ($field['type'] == 'textarea' || $field['type'] == 'wysiwyg') { // stripslashes for textarea, wysiwyg fields if (is_array($values)) { $values = array_map('stripslashes', $values); } else { $values = stripslashes($values); } } if ($field['type'] == 'textfield' || $field['type'] == 'text' || $field['type'] == 'date') { // stripslashes for textarea, wysiwyg fields if (is_array($values)) { $values = array_map('stripslashes', $values); } else { $values = stripslashes($values); } } // track form data for notification mail if (isset($this->_form->fields['notification']->enable) && $this->_form->fields['notification']->enable && isset($field['plugin_type']) && ($field['plugin_type'] = 'types')) { $tmp_data = null; if ($field['type'] == 'checkbox') { if ($field['data']['display'] == 'db') { $tmp_data = $values; } else { $tmp_data = $field['data']['display_value_selected']; } } elseif ($field['type'] == 'radio' || $field['type'] == 'select') { $tmp_data = $field['data']['options'][$values]['title']; } elseif ($field['type'] == 'checkboxes') { $tmp_data = array(); foreach ($values as $tmp_val) { $tmp_data[] = $field['data']['options'][$tmp_val]['title']; } $tmp_data = implode(', ', $tmp_data); unset($tmp_val); } if ($tmp_data !== null) { $_cred_form_data[] = $field_label . ': ' . $tmp_data; $done_data = true; } } if ($field['type'] == 'checkboxes' || $field['type'] == 'multiselect') { $result = array(); //foreach ($values as $val) foreach ($field['data']['options'] as $optionkey => $optiondata) { if (isset($field['data']['save_empty']) && $field['data']['save_empty'] == 'yes' && !in_array($optionkey, $values)) { $result[$optionkey] = '0'; } elseif (in_array($optionkey, $values)) { $result[$optionkey] = $optiondata['set_value']; } } $values = $result; $fieldsInfo[$key]['save_single'] = true; } elseif ($field['type'] == 'radio' || $field['type'] == 'select') { $values = $field['data']['options'][$values]['value']; } elseif ($field['type'] == 'date') { $date_format = ''; if (isset($field['data']) && isset($field['data']['validate'])) { $date_format = $field['data']['validate']['date']['format']; } if (!in_array($date_format, $this->supported_date_formats)) { $date_format = 'F j, Y'; } if (!is_array($values)) { $tmp = array($values); } else { $tmp = $values; } // track form data for notification mail if (isset($this->_form->fields['notification']->enable) && $this->_form->fields['notification']->enable) { $tmp_data = ''; $tmp_data .= $field_label . ': '; } MyZebra_DateParser::setDateLocaleStrings(self::$localized_strings['days'], self::$localized_strings['months']); foreach ($tmp as $ii => $val) { // track form data for notification mail if (isset($this->_form->fields['notification']->enable) && $this->_form->fields['notification']->enable) { $tmp_data .= '[' . $val . '] '; } /*if ($date_format == 'd/m/Y') { // strtotime requires a dash or dot separator to determine dd/mm/yyyy format $val = str_replace('/', '-', $val); } $val=strtotime(strval($val));*/ $val = MyZebra_DateParser::parseDate($val, $date_format); if ($val !== false) { // succesfull $val = $val->getNormalizedTimestamp(); } else { continue; } $tmp[$ii] = $val; } if (!is_array($values)) { $values = $tmp[0]; } else { $values = $tmp; } // track form data for notification mail if (isset($this->_form->fields['notification']->enable) && $this->_form->fields['notification']->enable) { $_cred_form_data[] = $tmp_data; $done_data = true; } } elseif ($field['type'] == 'skype') { if (array_key_exists('skypename', $values) && array_key_exists('style', $values)) { $tmp_data = array(); $new_values = array(); $values['skypename'] = (array) $values['skypename']; $values['style'] = (array) $values['style']; foreach ($values['skypename'] as $ii => $val) { $new_values[] = array('skypename' => $values['skypename'][$ii], 'style' => $values['style'][$ii]); if (isset($this->_form->fields['notification']->enable) && $this->_form->fields['notification']->enable) { $tmp_data[] = '{' . $values['skypename'][$ii] . ',' . $values['style'][$ii] . '}'; } } $values = $new_values; unset($new_values); if (isset($this->_form->fields['notification']->enable) && $this->_form->fields['notification']->enable) { $_cred_form_data[] = $field_label . ': ' . implode(' ', $tmp_data); $done_data = true; } } } // track form data for notification mail if (isset($this->_form->fields['notification']->enable) && $this->_form->fields['notification']->enable) { // dont track file/image data now but after we upload them.. if (!$done_data && $field['type'] != 'file' && $field['type'] != 'image') { if (is_array($values)) { $_cred_form_data[] = $field_label . ': ' . implode(', ', $values); } else { $_cred_form_data[] = $field_label . ': ' . $values; } } } $fields[$key] = $values; } } // custom parents (Types feature) foreach ($this->_fields['parents'] as $key => $field) { $field_label = $field['name']; // overwrite parent setting by url, even though no fields might be set if (!array_key_exists($key, $this->_form_fields) && array_key_exists('parent_' . $field['data']['post_type'] . '_id', $_GET) && is_numeric($_GET['parent_' . $field['data']['post_type'] . '_id'])) { $fieldsInfo[$key] = array('save_single' => false); $fields[$key] = intval($_GET['parent_' . $field['data']['post_type'] . '_id']); continue; } // if this field was not rendered in this specific form, bypass it if (!array_key_exists($key, $this->_form_fields)) { continue; } // if this field was discarded due to some conditional logic, bypass it if ($this->_myzebra_form->controls[$this->_form_fields[$key][0]]->isDiscarded()) { continue; } if (array_key_exists($key, $method) && intval($method[$key]) >= 0) { $fieldsInfo[$key] = array('save_single' => false); $fields[$key] = intval($method[$key]); } } // taxonomies $taxonomies = array('flat' => array(), 'hierarchical' => array()); foreach ($this->_fields['taxonomies'] as $key => $field) { // if this field was not rendered in this specific form, bypass it if (!array_key_exists($key, $this->_form_fields)) { continue; } // if this field was discarded due to some conditional logic, bypass it if ($this->_myzebra_form->controls[$this->_form_fields[$key][0]]->isDiscarded()) { continue; } if (array_key_exists($key, $method) || $field['hierarchical'] && isset($method[$key . '_hierarchy'])) { if ($field['hierarchical']) { $values = isset($method[$key]) ? $method[$key] : array(); if (isset($method[$key . '_hierarchy'])) { $add_new = array(); preg_match_all("/\\{([^\\{\\}]+?),([^\\{\\}]+?)\\}/", $method[$key . '_hierarchy'], $tmp_a_n); for ($ii = 0; $ii < count($tmp_a_n[1]); $ii++) { $add_new[] = array('parent' => $tmp_a_n[1][$ii], 'term' => $tmp_a_n[2][$ii]); } unset($tmp_a_n); } else { $add_new = array(); } //cred_log(print_r($add_new,true)); $taxonomies['hierarchical'][] = array('name' => $key, 'terms' => $values, 'add_new' => $add_new); // track form data for notification mail if (isset($this->_form->fields['notification']->enable) && $this->_form->fields['notification']->enable) { $tmp_data = array(); foreach ($field['all'] as $tmp_tax) { if (in_array($tmp_tax['term_taxonomy_id'], $values)) { $tmp_data[] = $tmp_tax['name']; } } // add also new terms created foreach ($values as $val) { if (is_string($val) && !is_numeric($val)) { $tmp_data[] = $val; } } $_cred_form_data[] = $field['label'] . ': ' . implode(', ', $tmp_data); unset($tmp_data); } } elseif (!$field['hierarchical']) { $values = $method[$key]; // find which to add and which to remove //$sanit=create_function('$a', 'return preg_replace("/[\*\(\)\{\}\[\]\+\,\.]|\s+/g","",$a);'); preg_match("/^add\\{(.*?)\\}remove\\{(.*?)\\}\$/i", $values, $matches); // allow white space in tax terms $tax_add = !empty($matches[1]) ? preg_replace("/[\\*\\(\\)\\{\\}\\[\\]\\+\\,\\.]|[\f\n\r\t\v\\x{00A0}\\x{2028}\\x{2029}]+/u", "", explode(',', $matches[1])) : array(); $tax_remove = !empty($matches[2]) ? preg_replace("/[\\*\\(\\)\\{\\}\\[\\]\\+\\,\\.]|[\f\n\r\t\v\\x{00A0}\\x{2028}\\x{2029}]+/u", "", explode(',', $matches[2])) : array(); $taxonomies['flat'][] = array('name' => $key, 'add' => $tax_add, 'remove' => $tax_remove); // track form data for notification mail if (isset($this->_form->fields['notification']->enable)) { $_cred_form_data[] = $field['label'] . ': ' . 'added=>(' . implode(', ', $tax_add) . ') removed=>(' . implode(', ', $tax_remove) . ')'; } } } } // upload data $all_ok = true; require_once ABSPATH . '/wp-admin/includes/file.php'; // set featured image only if uploaded $fkey = '_featured_image'; $extra_files = array(); if (array_key_exists($fkey, $this->_form_fields) && array_key_exists($fkey, $_FILES) && isset($_FILES[$fkey]['name']) && $_FILES[$fkey]['name'] != '') { $upload = wp_handle_upload($_FILES[$fkey], array('test_form' => false, 'test_upload' => false)); if (!isset($upload['error']) && isset($upload['file'])) { $extra_files[$fkey]['wp_upload'] = $upload; $tmp_data = __('Featured Image') . ': ' . $upload['url']; $this->_myzebra_form->controls[$this->_form_fields[$fkey][0]]->set_values(array('value' => '')); //$this->_myzebra_form->controls[$this->_form_fields[$fkey][0]]->set_values(array('value'=>$upload['url'])); } else { $all_ok = false; $tmp_data = __('Featured Image') . ': ' . $_FILES[$fkey]['name'] . ' (' . $this->getLocalisedMessage('upload_failed') . ')'; $fields[$fkey] = ''; $extra_files[$fkey]['upload_fail'] = true; $this->_myzebra_form->controls[$this->_form_fields[$fkey][0]]->set_values(array('value' => '')); $this->_myzebra_form->controls[$this->_form_fields[$fkey][0]]->addError($upload['error']); } } foreach ($files as $fkey => $fdata) { if ($fdata['repetitive']) { $tmp_data = $files[$fkey]['label'] . ': '; $tmp_first = true; foreach ($fdata as $ii => $fdata2) { if (!isset($fdata2['file_data'][$fkey]) || !is_array($fdata2['file_data'][$fkey])) { continue; } $file_data = $fdata2['file_data'][$fkey]; $upload = wp_handle_upload($file_data, array('test_form' => false, 'test_upload' => false)); if (!isset($upload['error']) && isset($upload['file'])) { $files[$fkey][$ii]['wp_upload'] = $upload; $fields[$fkey][$ii] = $upload['url']; $tmp_data .= ($tmp_first ? ' ' : ', ') . $upload['url']; $tmp_first = false; $this->_myzebra_form->controls[$this->_form_fields[$files[$fkey]['name_orig']][0]]->set_values(array($ii => array('value' => $upload['url']))); } else { $all_ok = false; $files[$fkey]['upload_fail'] = true; $tmp_data .= ($tmp_first ? ' ' : ', ') . $fields[$fkey][$ii] . ' (' . $this->getLocalisedMessage('upload_failed') . ')'; $tmp_first = false; $fields[$fkey][$ii] = ''; $files[$fkey][$ii]['upload_fail'] = true; $this->_myzebra_form->controls[$this->_form_fields[$files[$fkey]['name_orig']][0]]->set_values(array($ii => array('value' => ''))); $this->_myzebra_form->controls[$this->_form_fields[$files[$fkey]['name_orig']][0]]->addError(array($ii => $upload['error'])); } } } else { if (!isset($fdata['file_data'][$fkey]) || !is_array($fdata['file_data'][$fkey])) { continue; } $file_data = $fdata['file_data'][$fkey]; $upload = wp_handle_upload($file_data, array('test_form' => false, 'test_upload' => false)); if (!isset($upload['error']) && isset($upload['file'])) { $files[$fkey]['wp_upload'] = $upload; $fields[$fkey] = $upload['url']; $tmp_data = $files[$fkey]['label'] . ': ' . $upload['url']; $this->_myzebra_form->controls[$this->_form_fields[$files[$fkey]['name_orig']][0]]->set_values(array('value' => $upload['url'])); } else { $all_ok = false; $tmp_data = $files[$fkey]['label'] . ': ' . $fields[$fkey] . ' (' . $this->getLocalisedMessage('upload_failed') . ')'; $fields[$fkey] = ''; $files[$fkey]['upload_fail'] = true; $this->_myzebra_form->controls[$this->_form_fields[$files[$fkey]['name_orig']][0]]->set_values(array('value' => '')); $this->_myzebra_form->controls[$this->_form_fields[$files[$fkey]['name_orig']][0]]->addError($upload['error']); } } // track file/image upload data for notifications if (isset($this->_form->fields['notification']->enable) && $this->_form->fields['notification']->enable) { $_cred_form_data[] = $tmp_data; } } // save them if ($all_ok) { $model = CRED_Loader::get('MODEL/Forms'); if (empty($post->ID)) { $result = $model->addPost($post, array('fields' => $fields, 'info' => $fieldsInfo), $taxonomies); } else { $result = $model->updatePost($post, array('fields' => $fields, 'info' => $fieldsInfo), $taxonomies, $fieldsInfo); } } else { $result = false; } if (is_int($result) && $all_ok) { foreach ($files as $fkey => $fdata) { if ($files[$fkey]['repetitive']) { foreach ($fdata as $ii => $fdata2) { if (!isset($fdata2['file_data'][$fkey]) || !is_array($fdata2['file_data'][$fkey])) { continue; } if (!isset($files[$fkey][$ii]['upload_fail']) || !$files[$fkey][$ii]['upload_fail']) { $filetype = wp_check_filetype(basename($files[$fkey][$ii]['wp_upload']['file']), null); $title = $files[$fkey][$ii]['file_data'][$fkey]['name']; $ext = strrchr($title, '.'); $title = $ext !== false ? substr($title, 0, -strlen($ext)) : $title; $attachment = array('post_mime_type' => $filetype['type'], 'post_title' => addslashes($title), 'post_content' => '', 'post_status' => 'inherit', 'post_parent' => $result, 'post_type' => 'attachment', 'guid' => $files[$fkey][$ii]['wp_upload']['url']); $attach_id = wp_insert_attachment($attachment, $files[$fkey][$ii]['wp_upload']['file']); // you must first include the image.php file // for the function wp_generate_attachment_metadata() to work require_once ABSPATH . 'wp-admin/includes/image.php'; $attach_data = wp_generate_attachment_metadata($attach_id, $files[$fkey][$ii]['wp_upload']['file']); wp_update_attachment_metadata($attach_id, $attach_data); } } } else { if (!isset($fdata['file_data'][$fkey]) || !is_array($fdata['file_data'][$fkey])) { continue; } if (!isset($files[$fkey]['upload_fail']) || !$files[$fkey]['upload_fail']) { $filetype = wp_check_filetype(basename($files[$fkey]['wp_upload']['file']), null); $title = $files[$fkey]['file_data'][$fkey]['name']; $ext = strrchr($title, '.'); $title = $ext !== false ? substr($title, 0, -strlen($ext)) : $title; $attachment = array('post_mime_type' => $filetype['type'], 'post_title' => addslashes($title), 'post_content' => '', 'post_status' => 'inherit', 'post_parent' => $result, 'post_type' => 'attachment', 'guid' => $files[$fkey]['wp_upload']['url']); $attach_id = wp_insert_attachment($attachment, $files[$fkey]['wp_upload']['file']); // you must first include the image.php file // for the function wp_generate_attachment_metadata() to work require_once ABSPATH . 'wp-admin/includes/image.php'; $attach_data = wp_generate_attachment_metadata($attach_id, $files[$fkey]['wp_upload']['file']); wp_update_attachment_metadata($attach_id, $attach_data); } } } foreach ($extra_files as $fkey => $fdata) { if (!isset($extra_files[$fkey]['upload_fail']) || !$extra_files[$fkey]['upload_fail']) { $filetype = wp_check_filetype(basename($extra_files[$fkey]['wp_upload']['file']), null); $title = $_FILES[$fkey]['name']; $ext = strrchr($title, '.'); $title = $ext !== false ? substr($title, 0, -strlen($ext)) : $title; $attachment = array('post_mime_type' => $filetype['type'], 'post_title' => addslashes($title), 'post_content' => '', 'post_status' => 'inherit', 'post_parent' => $result, 'post_type' => 'attachment', 'guid' => $extra_files[$fkey]['wp_upload']['url']); $attach_id = wp_insert_attachment($attachment, $extra_files[$fkey]['wp_upload']['file']); // you must first include the image.php file // for the function wp_generate_attachment_metadata() to work require_once ABSPATH . 'wp-admin/includes/image.php'; $attach_data = wp_generate_attachment_metadata($attach_id, $extra_files[$fkey]['wp_upload']['file']); wp_update_attachment_metadata($attach_id, $attach_data); if ($fkey == '_featured_image') { // set current thumbnail update_post_meta($result, '_thumbnail_id', $attach_id); // get current thumbnail //if (isset($this->_form_fields['_featured_image']) && isset($this->_myzebra_form->controls[$this->_form_fields['_featured_image'][0]])) $this->_myzebra_form->controls[$this->_form_fields['_featured_image'][0]]->set_attributes(array('display_featured_html' => get_the_post_thumbnail($result, 'thumbnail'))); } } } // track form data for notification mail if (isset($this->_form->fields['notification']->enable) && $this->_form->fields['notification']->enable) { $this->_notification_data = '<hr />' . implode('<br /><hr /><br />', $_cred_form_data) . '<hr />'; } $thisform = array('id' => $this->_form_id, 'post_type' => $this->_post_type, 'form_type' => $this->_form_type); // do custom actions on post save do_action('cred_save_data_' . $this->_form_id, $result, $thisform); do_action('cred_save_data', $result, $thisform); } // return saved post_id return $result; }
private function _AddNewVariable($varObj, &$varArr = null) { if (!isset($varArr)) { $varArr =& $this->arrVars; } if (!isset($varArr)) { $varArr = array(); } $varName = $varObj['name']; $varToken = null; if (isset($varObj['withType'])) { switch ($varObj['withType']) { case 'boolean': $varToken = MyZebra_Tokenizer::makeToken($varObj['val'], MyZebra_Tokenizer::$TOKEN_TYPE['BOOLEAN']); break; case 'number': $varToken = MyZebra_Tokenizer::makeToken($varObj['val'], MyZebra_Tokenizer::$TOKEN_TYPE['NUMBER']); break; case 'array': $varToken = MyZebra_Tokenizer::makeToken($varObj['val'], MyZebra_Tokenizer::$TOKEN_TYPE['ARRAY']); break; case 'date': if (isset($varObj['format'])) { $format = $varObj['format']; } else { $format = $this->dtFormat; } $varToken = MyZebra_Tokenizer::makeToken(MyZebra_DateParser::parseDate($varObj['val'], $format), MyZebra_Tokenizer::$TOKEN_TYPE['DATE']); break; case 'string': default: $varToken = MyZebra_Tokenizer::makeToken($varObj['val'], MyZebra_Tokenizer::$TOKEN_TYPE['STRING_LITERAL']); break; } } else { $varToken = MyZebra_Tokenizer::makeToken($varObj['val'], MyZebra_Tokenizer::$TOKEN_TYPE['STRING_LITERAL']); } $varArr[$varName] = $varToken; }
public function extractCustomFields($post_id, $track = false) { global $user_ID; // reference to the form submission method global ${'_' . StaticClass::METHOD}; $method =& ${'_' . StaticClass::METHOD}; // get refs here $globals =& self::friendGetStatic('CRED_Form_Builder', '&_staticGlobal'); $form =& $this->friendGet($this->_formBuilder, '&_formData'); $out_ =& $this->friendGet($this->_formBuilder, '&out_'); $form_id = $form->getForm()->ID; $form_fields = $form->getFields(); $form_type = $form_fields['form_settings']->form['type']; $post_type = $form_fields['form_settings']->post['post_type']; $supported_date_formats = $this->friendGet($this->_formBuilder, '_supportedDateFormats'); $_fields = $out_['fields']; $_form_fields = $out_['form_fields']; $_form_fields_info = $out_['form_fields_info']; $zebraForm = $this->friendGet($this->_formBuilder, '_zebraForm'); // custom fields $fields = array(); $removed_fields = array(); // taxonomies $taxonomies = array('flat' => array(), 'hierarchical' => array()); $fieldsInfo = array(); // files, require extra care to upload correctly $files = array(); foreach ($_fields['post_fields'] as $key => $field) { $field_label = $field['name']; $done_data = false; // use the key as was rendered (with potential prefix) $key11 = $key; if (isset($field['plugin_type_prefix'])) { $key = $field['plugin_type_prefix'] . $key; } // if this field was not rendered in this specific form, bypass it if (!array_key_exists($key11, $_form_fields)) { continue; } // if this field was discarded due to some conditional logic, bypass it if (isset($zebraForm->controls) && $zebraForm->controls[$_form_fields[$key11][0]]->isDiscarded()) { continue; } $fieldsInfo[$key] = array('save_single' => false); if ('audio' == $field['type'] || 'video' == $field['type'] || 'file' == $field['type'] || 'image' == $field['type']) { if (!array_key_exists($key, $method)) { // remove the fields $removed_fields[] = $key; unset($fieldsInfo[$key]); } else { /* $_hasFile=false; foreach ($method[$key] as $_file_) { if (''!=trim($method[$key])) $_hasFile=true; } // repetitive field and all values are empty, remove if (!$_hasFile) { // remove the fields $removed_fields[]=$key; unset($fieldsInfo[$key]); } */ $fields[$key] = $method[$key]; } } if ('checkboxes' == $field['type'] && isset($field['data']['save_empty']) && 'yes' == $field['data']['save_empty'] && !array_key_exists($key, $method)) { $values = array(); foreach ($field['data']['options'] as $optionkey => $optiondata) { $values[$optionkey] = '0'; } // let model serialize once, fix Types-CRED mapping issue with checkboxes $fieldsInfo[$key]['save_single'] = true; $fields[$key] = $values; } elseif ('checkboxes' == $field['type'] && (!isset($field['data']['save_empty']) || 'yes' != $field['data']['save_empty']) && !array_key_exists($key, $method)) { // remove the fields $removed_fields[] = $key; unset($fieldsInfo[$key]); } elseif ('checkbox' == $field['type'] && isset($field['data']['save_empty']) && 'yes' == $field['data']['save_empty'] && !array_key_exists($key, $method)) { $fields[$key] = '0'; } elseif ('checkbox' == $field['type'] && (!isset($field['data']['save_empty']) || 'yes' != $field['data']['save_empty']) && !array_key_exists($key, $method)) { // remove the fields $removed_fields[] = $key; unset($fieldsInfo[$key]); } elseif (array_key_exists($key, $method)) { // normalize repetitive values out of sequence // NOTE this seems deprecated as we are using the method above... why is this still here? if ($_form_fields_info[$key11]['repetitive']) { if (is_array($method[$key])) { $values = array_values($method[$key]); } else { $aux_value_array = array($method[$key]); $values = array_values($aux_value_array); } } else { $values = $method[$key]; } if ('audio' == $field['type'] || 'video' == $field['type'] || 'file' == $field['type'] || 'image' == $field['type']) { $files[$key] = $zebraForm->controls[$_form_fields[$key11][0]]->get_values(); //cred_log($files[$key]); $files[$key]['name_orig'] = $key11; $files[$key]['label'] = $field['name']; $files[$key]['repetitive'] = $_form_fields_info[$key11]['repetitive']; } elseif ('textarea' == $field['type'] || 'wysiwyg' == $field['type']) { // stripslashes for textarea, wysiwyg fields if (is_array($values)) { $values = array_map('stripslashes', $values); } else { $values = stripslashes($values); } } elseif ('textfield' == $field['type'] || 'text' == $field['type'] || 'date' == $field['type']) { // stripslashes for text fields if (is_array($values)) { $values = array_map('stripslashes', $values); } else { $values = stripslashes($values); } } // track form data for notification mail if ($track) { $tmp_data = null; if ('checkbox' == $field['type']) { if ('db' == $field['data']['display']) { $tmp_data = $values; } else { $tmp_data = $field['data']['display_value_selected']; } } elseif ('radio' == $field['type'] || 'select' == $field['type']) { $tmp_data = $field['data']['options'][$values]['title']; } elseif ('checkboxes' == $field['type'] || 'multiselect' == $field['type']) { $tmp_data = array(); foreach ($values as $tmp_val) { $tmp_data[] = $field['data']['options'][$tmp_val]['title']; } //$tmp_data=implode(', ',$tmp_data); unset($tmp_val); } if (null !== $tmp_data) { $this->trackData(array($field_label => $tmp_data)); $done_data = true; } } if ('checkboxes' == $field['type'] || 'multiselect' == $field['type']) { $result = array(); foreach ($field['data']['options'] as $optionkey => $optiondata) { /* if ( isset($field['data']['save_empty']) && 'yes'==$field['data']['save_empty'] && !in_array($optionkey, $values) ) $result[$optionkey]='0'; else */ if (in_array($optionkey, $values) && isset($optiondata['set_value'])) { $result[$optionkey] = $optiondata['set_value']; } } $values = $result; $fieldsInfo[$key]['save_single'] = true; } elseif ('radio' == $field['type'] || 'select' == $field['type']) { $values = $field['data']['options'][$values]['value']; } elseif ('date' == $field['type']) { $date_format = null; if (isset($field['data']) && isset($field['data']['validate'])) { $date_format = $field['data']['validate']['date']['format']; } if (!in_array($date_format, $supported_date_formats)) { $date_format = 'F j, Y'; } if (!is_array($values)) { $tmp = array($values); } else { $tmp = $values; } // track form data for notification mail if ($track) { $this->trackData(array($field_label => $tmp)); $done_data = true; } MyZebra_DateParser::setDateLocaleStrings($globals['LOCALES']['days'], $globals['LOCALES']['months']); foreach ($tmp as $ii => $val) { $val = MyZebra_DateParser::parseDate($val, $date_format); if (false !== $val) { // succesfull $val = $val->getNormalizedTimestamp(); } else { continue; } $tmp[$ii] = $val; } if (!is_array($values)) { $values = $tmp[0]; } else { $values = $tmp; } } elseif ('skype' == $field['type']) { if (array_key_exists('skypename', $values) && array_key_exists('style', $values)) { $new_values = array(); $values['skypename'] = (array) $values['skypename']; $values['style'] = (array) $values['style']; foreach ($values['skypename'] as $ii => $val) { $new_values[] = array('skypename' => $values['skypename'][$ii], 'style' => $values['style'][$ii]); } $values = $new_values; unset($new_values); if ($track) { $this->trackData(array($field_label => $values)); $done_data = true; } } } // dont track file/image data now but after we upload them.. if ($track && !$done_data && 'file' != $field['type'] && 'image' != $field['type']) { $this->trackData(array($field_label => $values)); } $fields[$key] = $values; } } // custom parents (Types feature) foreach ($_fields['parents'] as $key => $field) { $field_label = $field['name']; // overwrite parent setting by url, even though no fields might be set if (!array_key_exists($key, $_form_fields) && array_key_exists('parent_' . $field['data']['post_type'] . '_id', $_GET) && is_numeric($_GET['parent_' . $field['data']['post_type'] . '_id'])) { $fieldsInfo[$key] = array('save_single' => false); $fields[$key] = intval($_GET['parent_' . $field['data']['post_type'] . '_id']); continue; } // if this field was not rendered in this specific form, bypass it if (!array_key_exists($key, $_form_fields)) { continue; } // if this field was discarded due to some conditional logic, bypass it if ($zebraForm->controls[$_form_fields[$key][0]]->isDiscarded()) { continue; } if (array_key_exists($key, $method) && intval($method[$key]) >= -1) { $fieldsInfo[$key] = array('save_single' => false); $fields[$key] = intval($method[$key]); } } // taxonomies foreach ($_fields['taxonomies'] as $key => $field) { // if this field was not rendered in this specific form, bypass it if (!array_key_exists($key, $_form_fields)) { continue; } if (array_key_exists($key, $method) || $field['hierarchical'] && isset($method[$key . '_hierarchy'])) { if ($field['hierarchical']) { $values = isset($method[$key]) ? $method[$key] : array(); if (isset($method[$key . '_hierarchy'])) { $add_new = array(); preg_match_all("/\\{([^\\{\\}]+?),([^\\{\\}]+?)\\}/", $method[$key . '_hierarchy'], $tmp_a_n); for ($ii = 0; $ii < count($tmp_a_n[1]); $ii++) { $add_new[] = array('parent' => $tmp_a_n[1][$ii], 'term' => $tmp_a_n[2][$ii]); } unset($tmp_a_n); } else { $add_new = array(); } $taxonomies['hierarchical'][] = array('name' => $key, 'terms' => $values, 'add_new' => $add_new); // track form data for notification mail if ($track) { $tmp_data = array(); foreach ($field['all'] as $tmp_tax) { //if (in_array($tmp_tax['term_taxonomy_id'],$values)) if (in_array($tmp_tax['term_id'], $values)) { $tmp_data[] = $tmp_tax['name']; } } // add also new terms created foreach ($values as $val) { if (is_string($val) && !is_numeric($val)) { $tmp_data[] = $val; } } $this->trackData(array($field['label'] => $tmp_data)); unset($tmp_data); } } elseif (!$field['hierarchical']) { $values = $method[$key]; // find which to add and which to remove $tax_add = $values; $tax_remove = ""; // allow white space in tax terms $taxonomies['flat'][] = array('name' => $key, 'add' => $tax_add, 'remove' => $tax_remove); // track form data for notification mail if ($track) { $this->trackData(array($field['label'] => array('added' => $tax_add, 'removed' => $tax_remove))); } } } } return array($fields, $fieldsInfo, $taxonomies, $files, $removed_fields); }