예제 #1
0
function _wptoolset_forms_test_fields()
{
    global $_html_test;
    $fields = types_get_fields();
    //debug($fields);
    foreach ($fields as $field) {
        $config = wptoolset_forms_types_filter_field($field, 'testme');
        $_html_test .= wptoolset_form_field('post', $config);
    }
}
예제 #2
0
 /**
  * Returns element form as array.
  *
  * This is done per field.
  *
  * @param type $key Field key as stored
  * @return array
  */
 function field_form()
 {
     if (defined('WPTOOLSET_FORMS_VERSION')) {
         $field = $this->cf->cf;
         $meta = get_post_meta($this->child->ID, $field['meta_key']);
         $field['suffix'] = "-{$this->child->ID}";
         $config = wptoolset_form_filter_types_field($field, $this->child->ID);
         // Do not allow repetitive
         $config['repetitive'] = false;
         $config['name'] = $this->cf->alter_form_name('wpcf_post_relationship[' . $this->parent->ID . ']', $config['name']);
         if (!empty($config['options'])) {
             foreach ($config['options'] as &$v) {
                 if (isset($v['name'])) {
                     $v['name'] = $this->alter_form_name($v['name']);
                 }
             }
         }
         if ($config['type'] == 'wysiwyg') {
             $config['type'] = 'textarea';
         }
         return wptoolset_form_field('post', $config, $meta);
     }
     /*
      *
      * Get meta form for field
      */
     $form = $this->cf->_get_meta_form($this->cf->__meta, $this->cf->meta_object->meta_id, false);
     /*
      *
      * Filter form
      */
     $_filtered_form = $this->__filter_meta_form($form);
     return wpcf_form_simple(apply_filters('wpcf_relationship_child_meta_form', $_filtered_form, $this->cf));
 }
예제 #3
0
/**
 * Renders meta box content.
 *
 * Core function. Works and stable.
 * If required, add hooks only.
 *
 * @todo Revise this 1.1.5
 *
 * @param type $post
 * @param type $group
 * @param type $echo
 * @param type boolean $open_style_editor if true use code for open style editor when edit group
 */
function wpcf_admin_post_meta_box($post, $group, $echo = '', $open_style_editor = false)
{
    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(wpcf_translate('group ' . $group['args']['id'] . ' description', $group['args']['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(wpcf_translate('group ' . $group['args']['id'] . ' description', $group['args']['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;
    }
}
예제 #4
0
/**
 * Init functions for User profile edit pages.
*/
function wpcf_admin_userprofile_init($user_id)
{
    global $wpcf;
    if (!is_object($user_id)) {
        $user_id = new stdClass();
        $user_id->ID = 0;
    }
    $user_role = isset($user_id->roles) ? array_shift($user_id->roles) : 'subscriber';
    $groups = wpcf_admin_usermeta_get_groups_fields();
    $wpcf_active = false;
    $profile_only_preview = '';
    foreach ($groups as $group) {
        if (!empty($group['fields'])) {
            $wpcf_active = true;
            $for_users = wpcf_admin_get_groups_showfor_by_group($group['id']);
            $profile_only_preview = '';
            if (count($for_users) != 0) {
                if (!in_array($user_role, $for_users)) {
                    continue;
                } else {
                    //If Access plugin activated
                    if (function_exists('wpcf_access_register_caps')) {
                        //If user can't view own profile fields
                        if (!current_user_can('view_own_in_profile_' . $group['slug'])) {
                            continue;
                        }
                        //If user can modify current group in own profile
                        if (!current_user_can('modify_own_' . $group['slug'])) {
                            $profile_only_preview = 1;
                        }
                    }
                }
            } else {
                if (function_exists('wpcf_access_register_caps')) {
                    if (!current_user_can('view_own_in_profile_' . $group['slug'])) {
                        continue;
                    }
                    if (!current_user_can('modify_own_' . $group['slug'])) {
                        $profile_only_preview = 1;
                    }
                }
            }
            // Process fields
            if (empty($profile_only_preview)) {
                if (defined('WPTOOLSET_FORMS_VERSION')) {
                    $errors = get_user_meta($user_id->ID, '__wpcf-invalid-fields', true);
                    // OLD
                    delete_post_meta($user_id->ID, 'wpcf-invalid-fields');
                    delete_post_meta($user_id->ID, '__wpcf-invalid-fields');
                    if (empty($group['fields'])) {
                        continue;
                    }
                    $output = '<div class="wpcf-group-area wpcf-group-area_' . $group['slug'] . '">' . "\n\n" . '<h3>' . wpcf_translate('group ' . $group['id'] . ' name', $group['name']) . '</h3>' . "\n\n";
                    if (!empty($group['description'])) {
                        $output .= '<span>' . wpautop(wpcf_translate('group ' . $group['id'] . ' description', $group['description'])) . '</span>' . "\n\n";
                    }
                    $output .= '<div class="wpcf-profile-field-line">' . "\n\n";
                    foreach ($group['fields'] as $field) {
                        $config = wptoolset_form_filter_types_field($field, $user_id->ID);
                        $config = array_map('fix_fields_config_output_for_display', $config);
                        $meta = get_user_meta($user_id->ID, $field['meta_key']);
                        if ($errors) {
                            $config['validate'] = true;
                        }
                        if (isset($config['validation']['required'])) {
                            $config['title'] .= '&#42;';
                        }
                        $config['_title'] = $config['title'];
                        $output .= '
<div class="wpcf-profile-field-line">
	<div class="wpcf-profile-line-left">
        ' . $config['title'] . '
    </div>
	<div class="wpcf-profile-line-right">
    ';
                        $description = false;
                        if (!empty($config['description'])) {
                            $description = sprintf('<span class="description">%s</span>', $config['description']);
                        }
                        $config['title'] = $config['description'] = '';
                        $form_name = $user_id->ID ? 'your-profile' : 'createuser';
                        $output .= wptoolset_form_field($form_name, $config, $meta);
                        if ($description) {
                            $output .= $description;
                        }
                        $output .= '
    </div>
</div>';
                    }
                    $output .= '</div></div>';
                    echo $output;
                } else {
                    $group['fields'] = wpcf_admin_usermeta_process_fields($user_id, $group['fields'], true);
                    wpcf_admin_render_fields($group, $user_id);
                }
            } else {
                // Render profile fields (text only)
                wpcf_usermeta_preview_profile($user_id, $group);
            }
        }
    }
    // Activate scripts
    if ($wpcf_active) {
        wp_enqueue_script('wpcf-fields-post', WPCF_EMBEDDED_RES_RELPATH . '/js/fields-post.js', array('jquery'), WPCF_VERSION);
        wp_enqueue_script('wpcf-form-validation', WPCF_EMBEDDED_RES_RELPATH . '/js/' . 'jquery-form-validation/jquery.validate.min.js', array('jquery'), WPCF_VERSION);
        wp_enqueue_script('wpcf-form-validation-additional', WPCF_EMBEDDED_RES_RELPATH . '/js/' . 'jquery-form-validation/additional-methods.min.js', array('jquery'), WPCF_VERSION);
        wp_enqueue_style('wpcf-css-embedded', WPCF_EMBEDDED_RES_RELPATH . '/css/basic.css', array(), WPCF_VERSION);
        wp_enqueue_style('wpcf-fields-post', WPCF_EMBEDDED_RES_RELPATH . '/css/fields-post.css', array('wpcf-css-embedded'), WPCF_VERSION);
        wp_enqueue_style('wpcf-usermeta', WPCF_EMBEDDED_RES_RELPATH . '/css/usermeta.css', array('wpcf-css-embedded'), WPCF_VERSION);
        wpcf_enqueue_scripts();
        wpcf_field_enqueue_scripts('date');
        wpcf_field_enqueue_scripts('image');
        wpcf_field_enqueue_scripts('file');
        wpcf_field_enqueue_scripts('skype');
        wpcf_field_enqueue_scripts('numeric');
        add_action('admin_footer', 'wpcf_admin_profile_js_validation');
    }
}
예제 #5
0
 /**
  * This function render the single field
  * @global type $post
  * @param type $field
  * @param type $add2form_content
  * @return type
  */
 public function renderField($field, $add2form_content = false)
 {
     global $post;
     //echo "<br>{$field['name']}";
     if (defined('WPTOOLSET_FORMS_ABSPATH') && function_exists('wptoolset_form_field')) {
         require_once WPTOOLSET_FORMS_ABSPATH . '/api.php';
         require_once WPTOOLSET_FORMS_ABSPATH . '/classes/class.fieldconfig.php';
         require_once WPTOOLSET_FORMS_ABSPATH . '/classes/class.types.php';
         require_once WPTOOLSET_FORMS_ABSPATH . '/classes/class.cred.php';
         $id = $this->form_id;
         $field['id'] = $id;
         if ($field['type'] == 'messages') {
             $this->isForm = true;
             return;
         }
         if ($this->form_type == 'edit' && $field['name'] == 'user_login') {
             $field['attr']['readonly'] = "readonly";
             $field['attr']['style'] = "background-color:#ddd;";
             $field['attr']['onclick'] = "blur();";
         }
         if ($field['type'] == 'credfile' || $field['type'] == 'credaudio' || $field['type'] == 'credvideo' || $field['type'] == 'credimage' || $field['type'] == 'file') {
             $this->isUploadForm = true;
             //$field['type'] = 'credfile';
         }
         /* $validation = array(
            'validation' => array(
            'required' => array(
            'args' => array($field['value'], true),
            'message' => 'Required'),
            'maxlength' => array(
            'args' => array($field['value'], 12),
            'message' => 'maxlength of 12 exceeded'
            ),
            'rangelength' => array(
            'args' => array($field['value'], 3, 25),
            'message' => 'input range from 3 to 25'
            ),
            )); */
         //#############################################################################################################################################################
         //Client-side validation is not using the custom messages provided in CRED forms for CRED custom fields
         //https://icanlocalize.basecamphq.com/projects/7393061-toolset/todo_items/187800735/comments
         $this->fixCredCustomFieldMessages($field);
         //#############################################################################################################################################################
         $mytype = $this->transType($field['type']);
         $fieldConfig = new FieldConfig();
         $fieldConfig->setDefaultValue($field['type'], $field);
         $fieldConfig->setOptions($field['name'], $field['type'], $field['value'], $field['attr']);
         $fieldConfig->setId($this->form_properties['name'] . "_" . $field['name']);
         $fieldConfig->setName($field['name']);
         $this->cleanAttr($field['attr']);
         $fieldConfig->setAttr($field['attr']);
         $_curr_value = "";
         //#############################################################################################################################################################
         //Fix https://icanlocalize.basecamphq.com/projects/7393061-toolset/todo_items/192427784/comments#300129108
         //losting filled data if using hook validate system
         if (isset($this->controls[$field['name']]) && !empty($this->controls[$field['name']])) {
             $_curr_value = $this->controls[$field['name']];
         } else {
             if (isset($field['value']) && !empty($field['value'])) {
                 $_curr_value = $field['value'];
             }
         }
         //#############################################################################################################################################################
         if (!$this->is_submit_success && ($mytype != 'credfile' && $mytype != 'credaudio' && $mytype != 'credvideo' && $mytype != 'credimage')) {
             $_curr_value = isset($this->controls[$field['name']]) ? $this->controls[$field['name']] : $field['value'];
         } else {
             if (isset($field['attr']['preset_value']) && !empty($field['attr']['preset_value'])) {
                 $_curr_value = $field['attr']['preset_value'];
             }
         }
         $fieldConfig->setValue($_curr_value);
         $fieldConfig->setDescription(!empty($field['description']) ? $field['description'] : "");
         $fieldConfig->setTitle($field['title']);
         $fieldConfig->setType($mytype);
         if (isset($field['data']) && isset($field['data']['repetitive'])) {
             $fieldConfig->setRepetitive((bool) $field['data']['repetitive']);
         }
         if (isset($field['attr']) && isset($field['attr']['type'])) {
             $fieldConfig->setDisplay($field['attr']['type']);
         }
         $config = $fieldConfig->createConfig();
         // Modified by Srdjan
         // Validation and conditional filtering
         if (isset($field['plugin_type']) && $field['plugin_type'] == 'types') {
             // This is not set in DB
             $field['meta_key'] = WPToolset_Types::getMetakey($field);
             $config['validation'] = WPToolset_Types::filterValidation($field);
             if ($post) {
                 $config['conditional'] = WPToolset_Types::filterConditional($field, $post->ID);
             }
         } else {
             $config['validation'] = WPToolset_Cred::filterValidation($field);
         }
         // Modified by Srdjan END
         $_values = array();
         if (isset($field['data']['repetitive']) && $field['data']['repetitive'] == 1) {
             //$_values = $field['value'];
             $_values = $_curr_value;
         } else {
             //$_values = array($field['value']);
             $_values = array($_curr_value);
         }
         // Added by Srdjan
         /*
          * Use $_validation_errors
          * set in $this::validate()
          */
         if (isset($this->_validation_errors['fields'][$config['id']])) {
             $config['validation_error'] = $this->_validation_errors['fields'][$config['id']];
         }
         if ($this->form_type == 'edit' && $mytype == 'checkbox') {
             unset($config['default_value']);
         }
         // Added by Srdjan END
         $html = wptoolset_form_field($this->form_id, $config, $_values);
         if ($add2form_content) {
             $this->_form_content .= $html;
         } else {
             return $html;
         }
         /*
          <input id="cred_form_853_1__cred_cred_wpnonce" type="hidden" user_defined="" value="d9f46d7082" name="_cred_cred_wpnonce">
          <input id="cred_form_853_1__cred_cred_prefix_form_id" type="hidden" user_defined="" value="853" name="_cred_cred_prefix_form_id">
          <input id="cred_form_853_1__cred_cred_prefix_form_count" type="hidden" user_defined="" value="1" name="_cred_cred_prefix_form_count">
          <input id="cred_form_853_1_name_cred_form_853_1" type="hidden" user_defined="" value="cred_form_853_1" name="name_cred_form_853_1">
         */
     }
 }