/** * Renders meta box content. * * @param $post * @param array $group * @param string $echo * @param bool $open_style_editor if true use code for open style editor when edit group * * @return string */ function wpcf_admin_post_meta_box($post, $group, $echo = '', $open_style_editor = false) { $field_group = Types_Field_Group_Post_Factory::load($group['args']['slug']); // todo Handle null $field_group. $group_wpml = new Types_Wpml_Field_Group($field_group); if (false === $open_style_editor && defined('WPTOOLSET_FORMS_VERSION')) { if (isset($group['args']['html'])) { /** * show group description */ if (array_key_exists('description', $group['args']) && !empty($group['args']['description'])) { echo '<div class="wpcf-meta-box-description">'; echo wpautop($group_wpml->translate_description()); echo '</div>'; } foreach ($group['args']['html'] as $field) { echo is_array($field) ? wptoolset_form_field('post', $field['config'], $field['meta']) : $field; } } return; } global $wpcf; /** * fake post object if need */ $post = wpcf_admin_create_fake_post_if_need($post); static $nonce_added = false; $group_output = ''; if (!isset($group['title'])) { $temp = $group; $group = ''; $group['args'] = $temp; $group['id'] = $temp['slug']; $group['title'] = $temp['name']; $name = $temp['name']; } if (!empty($echo)) { $group_output = '<h3>This Preview generated for latest post "' . $post->post_title . '"</h3>' . "\n" . '<!-- Previous lines visible only in Admin Style Editor.-->' . "\n\n"; $group_output .= '<div id="wpcf-group-' . $group['id'] . '" class="postbox " > <h3 class=\'hndle\'><span>' . $name . '</span></h3> <div class="inside">' . "\n"; } /* * TODO Document where this is used */ if (!$nonce_added && empty($echo)) { $nonce_action = 'update-' . $post->post_type . '_' . $post->ID; wp_nonce_field($nonce_action, '_wpcf_post_wpnonce'); $nonce_added = true; } $group_output .= "\n\n" . '<div id="wpcf-group-metabox-id-' . $group['args']['slug'] . '">' . "\n"; /* * TODO Move to Conditional code * * This is already checked. Use hook to add wrapper DIVS and apply CSS. */ if (!empty($group['args']['_conditional_display'])) { if ($group['args']['_conditional_display'] == 'failed') { $group_output .= '<div class="wpcf-cd-group wpcf-cd-group-failed" style="display:none;">'; } else { $group_output .= '<div class="wpcf-cd-group wpcf-cd-group-passed">'; } } /* * TODO Move this into Field code * Process fields */ if (!empty($group['args']['fields'])) { // Display description if (!empty($group['args']['description'])) { $group_output .= '<div class="wpcf-meta-box-description">' . wpautop($group_wpml->translate_description()) . '</div>'; } foreach ($group['args']['fields'] as $field_slug => $field) { if (empty($field) || !is_array($field)) { continue; } $field = $wpcf->field->_parse_cf_form_element($field); if (isset($field['wpcf-type'])) { // May be ignored $field = apply_filters('wpcf_fields_' . $field['wpcf-type'] . '_meta_box_form_value_display', $field); } if (!isset($field['#id'])) { $field['#id'] = wpcf_unique_id(serialize($field)); } // Render form elements if (wpcf_compare_wp_version() && array_key_exists('#type', $field) && 'wysiwyg' == $field['#type'] && !isset($field['#attributes']['disabled'])) { // if ( isset( $field['#attributes']['disabled'] ) ) { // $field['#editor_settings']['tinymce'] = false; // $field['#editor_settings']['teeny'] = false; // $field['#editor_settings']['media_buttons'] = false; // $field['#editor_settings']['quicktags'] = false; // $field['#editor_settings']['dfw'] = false; // } // Especially for WYSIWYG $group_output .= '<div class="wpcf-wysiwyg">'; $group_output .= '<div id="wpcf-textarea-textarea-wrapper" class="form-item form-item-textarea wpcf-form-item wpcf-form-item-textarea">'; $group_output .= isset($field['#before']) ? $field['#before'] : ''; $group_output .= '<label class="wpcf-form-label wpcf-form-textarea-label">' . stripslashes($field['#title']) . '</label>'; $group_output .= '<div class="description wpcf-form-description wpcf-form-description-textarea description-textarea"> ' . wpautop($field['#description']) . '</div>'; ob_start(); wp_editor($field['#value'], $field['#id'], $field['#editor_settings']); $group_output .= ob_get_clean() . "\n\n"; $field['slug'] = str_replace(WPCF_META_PREFIX . 'wysiwyg-', '', $field_slug); $field['type'] = 'wysiwyg'; $group_output .= '</div>'; $group_output .= isset($field['#after']) ? $field['#after'] : ''; $group_output .= '</div>'; } else { if (array_key_exists('#type', $field) && 'wysiwyg' == $field['#type']) { $field['#type'] = 'textarea'; } if (!empty($echo)) { $field['#validate'] = ''; } $group_output .= wpcf_form_simple(array($field['#id'] => $field)); } do_action('wpcf_fields_' . $field_slug . '_meta_box_form', $field); if (isset($field['wpcf-type'])) { // May be ignored do_action('wpcf_fields_' . $field['wpcf-type'] . '_meta_box_form', $field); } } } /* * TODO Move to Conditional code * * This is already checked. Use hook to add wrapper DIVS and apply CSS. */ if (!empty($group['args']['_conditional_display'])) { $group_output .= '</div>'; } $group_output .= '</div>'; if (!empty($echo)) { $group_output .= "\n\n</div></div>"; return $group_output; } else { echo $group_output; } }
function wpcf_admin_render_fields($group, $user_id, $echo = '') { global $wpcf; $group_wpml = new Types_Wpml_Field_Group(Types_Field_Group_User_Factory::load($group['slug'])); $output = '<div class="wpcf-group-area wpcf-group-area_' . $group['slug'] . '">' . "\n\n"; $output .= '<h3>' . $group_wpml->translate_name() . '</h3>' . "\n\n"; if (!empty($group['fields'])) { // Display description if (!empty($group['description'])) { $output .= '<span>' . wpautop($group_wpml->translate_description()) . '</span>' . "\n\n"; } $output .= '<div class="wpcf-profile-field-line">' . "\n\n"; foreach ($group['fields'] as $field_slug => $field) { if (empty($field) || !is_array($field)) { continue; } $field = $wpcf->usermeta_field->_parse_cf_form_element($field); if (!isset($field['#id'])) { $field['#id'] = wpcf_unique_id(serialize($field)); } if (isset($field['wpcf-type'])) { // May be ignored $field = apply_filters('wpcf_fields_' . $field['wpcf-type'] . '_meta_box_form_value_display', $field); } // Render form elements if (wpcf_compare_wp_version() && $field['#type'] == 'wysiwyg') { $field['#editor_settings']['media_buttons'] = ''; if (!empty($echo)) { $field['#editor_settings']['wpautop'] = true; } // Especially for WYSIWYG $output .= "\n" . '<div class="wpcf-profile-field-line">' . "\n\n"; $output .= '<div class="wpcf-wysiwyg">' . "\n\n"; $output .= '<div id="wpcf-textarea-textarea-wrapper" class="form-item form-item-textarea wpcf-form-item wpcf-form-item-textarea">' . "\n\n"; $output .= isset($field['#before']) ? $field['#before'] : ''; $output .= '<label class="wpcf-form-label wpcf-form-textarea-label">' . $field['#title'] . '</label>' . "\n\n"; $output .= '<div class="description wpcf-form-description wpcf-form-description-textarea description-textarea">' . "\n\n" . wpautop($field['#description']) . '</div>' . "\n\n"; ob_start(); wp_editor($field['#value'], $field['#id'], $field['#editor_settings']); $output .= ob_get_clean() . "\n\n"; $field['slug'] = str_replace(WPCF_META_PREFIX . 'wysiwyg-', '', $field_slug); $field['type'] = 'wysiwyg'; $output .= '</div>' . "\n\n"; $output .= isset($field['#after']) ? $field['#after'] : ''; $output .= '</div>' . "\n\n"; $output .= '</div>' . "\n\n"; } else { if ($field['#type'] == 'wysiwyg') { $field['#type'] = 'textarea'; } $field['#pattern'] = "\n" . '<div class="wpcf-profile-field-line"> <div class="wpcf-profile-line-left"> <LABEL><DESCRIPTION> </div> <div class="wpcf-profile-line-right"><BEFORE><ERROR><PREFIX><ELEMENT><SUFFIX><AFTER></div> </div>' . "\n\n"; if (isset($field['#name']) && (strpos($field['#name'], '[hour]') !== false || strpos($field['#name'], '[minute]') !== false)) { if (isset($field['#attributes']) && $field['#attributes']['class'] == 'wpcf-repetitive') { $field['#pattern'] = strpos($field['#name'], '[hour]') !== false ? __('Hour', 'wpcf') : __('Minute', 'wpcf'); $field['#pattern'] .= '<LABEL><DESCRIPTION><ERROR><PREFIX><ELEMENT><SUFFIX><AFTER>' . "\n\n"; } else { if (strpos($field['#name'], '[hour]') !== false) { $field['#pattern'] = "\n" . '<div class="wpcf-profile-field-line"> <div class="wpcf-profile-line-left"> ' . __('Time', 'wpcf') . '</div> <div class="wpcf-profile-line-right"> <LABEL><DESCRIPTION><ERROR><PREFIX><ELEMENT><SUFFIX><AFTER>' . "\n"; } else { $field['#pattern'] = "\n" . ' <LABEL><DESCRIPTION><ERROR><PREFIX><ELEMENT><SUFFIX><AFTER></div> </div>' . "\n\n"; } } } if (!empty($echo)) { $field['#validate'] = ''; } $output .= wpcf_form_simple(array($field['#id'] => $field)); } } $output .= '</div>'; } /* * TODO Move to Conditional code * * This is already checked. Use hook to add wrapper DIVS and apply CSS. */ if (!empty($group['_conditional_display'])) { $output .= '</div>'; } $output .= "\n\n" . '</div>'; if (!empty($echo)) { return $output; } else { echo $output; } }