escape(stripslashes(trim(RC_Format::GetFieldName($rawCustomFieldName)))); delete_post_meta($postId, $customFieldName); } } $wpdb->query("DELETE FROM ". RC_CWP_TABLE_POST_META . " WHERE post_id=$postId"); // --- Make sure all groups/fields duplicates are in sequence, // i.e. there is no gap due to removing items $arr = ARRAY(); foreach($customFieldKeys as $key=>$value) { list($customFieldId, $groupCounter, $fieldCounter, $rawCustomFieldName) = split("_", $value, 4); $arr[$key]->id = $customFieldId ; $arr[$key]->gc = $groupCounter ; $arr[$key]->fc = $fieldCounter ; $arr[$key]->fn = $rawCustomFieldName ; $arr[$key]->ov = $value ; } for($i=0;$i<$key;$i++){ for($j=0;$j<$key;$j++){ if( $arr[$i]->id == $arr[$j]->id ) { if( $arr[$i]->gc == $arr[$j]->gc ) { if( $arr[$i]->fc < $arr[$j]->fc ) { $t = $arr[$i] ; $arr[$i] = $arr[$j] ; $arr[$j] = $t ; } } else if( $arr[$i]->gc < $arr[$j]->gc ) { $t = $arr[$i] ; $arr[$i] = $arr[$j] ; $arr[$j] = $t ; } } else if( $arr[$i]->id < $arr[$j]->id ) { $t = $arr[$i] ; $arr[$i] = $arr[$j] ; $arr[$j] = $t ; } } } for($i=0;$i<$key;$i++) { if( $arr[$i]->id != $currentFieldID ) { $currentFieldID = $arr[$i]->id ; $currentG = $arr[$i]->gc ; $GC = 1 ; $FC = 1 ; } else if( $arr[$i]->gc != $currentG ) { $GC ++ ; $FC = 1 ; $currentG = $arr[$i]->gc ; } else $FC ++ ; $arr[$i]->fc = $FC ; $arr[$i]->gc = $GC ; } // --- Add new meta data foreach ($arr as $key) { if (!empty($key)) { // list($customFieldId, $groupCounter, $fieldCounter, $rawCustomFieldName) = split("_", $key, 4); $customFieldValue = $_POST[$key->ov]; $customFieldName = $wpdb->escape(stripslashes(trim(RC_Format::GetFieldName($key->fn)))); // Prepare field value if (is_array($customFieldValue)) { $finalValue = array(); foreach ($customFieldValue as $value) { $value = stripslashes(trim($value)); array_push($finalValue, $value); //add_post_meta($postId, $customFieldName, $value); } } else { $finalValue = stripslashes(trim($customFieldValue)); } // Add field value meta data add_post_meta($postId, $customFieldName, $finalValue); $fieldMetaID = $wpdb->insert_id; // Add field extended properties $wpdb->query("INSERT INTO ". RC_CWP_TABLE_POST_META . " (id, field_name, group_count, field_count, post_id) ". " VALUES ($fieldMetaID, '$customFieldName', ".$key->gc.", ".$key->fc.", $postId)"); } } } } /** * This function prepares some custom fields before saving it. It reads $_REQUEST and: * 1. Adds params to photos uploaded (Image field) * 2. Formats dates (Date Field) * */ function PrepareFieldsValues($postId) { // Add params to photos if( isset( $_REQUEST['rc_cwp_meta_photos'] ) ) { foreach( $_REQUEST['rc_cwp_meta_photos'] as $meta_name ) { $slashPos = strrpos($_POST[$meta_name], "/"); if (!($slashPos === FALSE)) $_POST[$meta_name] = substr($_POST[$meta_name], $slashPos+1); // if photo is new, add params /*if( isset( $_REQUEST[ $meta_name . '_params' ] ) && $_REQUEST[ $meta_name . '_params' ] ) { if( ! strpos( $_POST[$meta_name], $_REQUEST[ $meta_name . '_params' ] ) ) { $_POST[$meta_name] .= $_REQUEST[$meta_name . '_params']; } }*/ //Rename photo if it is edited using editnplace to avoid phpthumb cache if ($_POST[$meta_name.'_dorename'] == 1){ $oldFilename = $_POST[$meta_name]; $newFilename = time().substr($oldFilename, 10); rename(FLUTTER_UPLOAD_FILES_DIR.$oldFilename, FLUTTER_UPLOAD_FILES_DIR.$newFilename); $_POST[$meta_name] = $newFilename; } } } // Format Dates if( isset( $_REQUEST['rc_cwp_meta_date'] ) ) { foreach( $_REQUEST['rc_cwp_meta_date'] as $meta_name ) { $metaDate = strtotime($_POST[$meta_name]); $formatted_date = strftime("%Y-%m-%d", $metaDate); $_POST[$meta_name] = $formatted_date; } } } /** * Get a custom write panel by reading $_REQUEST['custom-write-panel-id'] or the * To see whether $_GET['post'] has a custom write panel associated to it. * * @return Custom Write Panel as an object, returns null if there is no write panels. */ function GetCustomWritePanel() { if (isset($_GET['post'])) { $customWritePanelId = get_post_meta((int)$_GET['post'], RC_CWP_POST_WRITE_PANEL_ID_META_KEY, true); if (empty($customWritePanelId)) { $customWritePanelId = (int)$_REQUEST['custom-write-panel-id']; } } else if (isset($_REQUEST['custom-write-panel-id'])) { $customWritePanelId = (int)$_REQUEST['custom-write-panel-id']; } if (isset($customWritePanelId)) { include_once('RCCWP_Application.php'); $customWritePanel = RCCWP_CustomWritePanel::Get($customWritePanelId); } return $customWritePanel; } /** * * */ function DeletePostMetaData($postId) { global $wpdb; $wpdb->query("DELETE FROM " . RC_CWP_TABLE_POST_META . " WHERE post_id =" . $postId) ; } } ?>