Ejemplo n.º 1
0
/**
 * Editor callback form.
 */
function wpcf_fields_checkbox_editor_callback()
{
    $form = array();
    $value_not_selected = '';
    $value_selected = '';
    if (isset($_GET['field_id'])) {
        $field = wpcf_admin_fields_get_field($_GET['field_id']);
        if (!empty($field)) {
            if (isset($field['data']['display_value_not_selected'])) {
                $value_not_selected = $field['data']['display_value_not_selected'];
            }
            if (isset($field['data']['display_value_selected'])) {
                $value_selected = $field['data']['display_value_selected'];
            }
        }
    }
    $form['#form']['callback'] = 'wpcf_fields_checkbox_editor_submit';
    $form['display'] = array('#type' => 'radios', '#default_value' => 'db', '#name' => 'display', '#options' => array('display_from_db' => array('#title' => __('Display the value of this field from the database', 'wpcf'), '#name' => 'display', '#value' => 'db', '#inline' => true, '#after' => '<br />'), 'display_values' => array('#title' => __('Show one of these two values:', 'wpcf'), '#name' => 'display', '#value' => 'value')), '#inline' => true);
    $form['display-value-1'] = array('#type' => 'textfield', '#title' => '<td style="text-align:right;">' . __('Not selected:', 'wpcf') . '</td><td>', '#name' => 'display_value_not_selected', '#value' => $value_not_selected, '#inline' => true, '#before' => '<table><tr>', '#after' => '</td></tr>');
    $form['display-value-2'] = array('#type' => 'textfield', '#title' => '<td style="text-align:right;">' . __('Selected:', 'wpcf') . '</td><td>', '#name' => 'display_value_selected', '#value' => $value_selected, '#after' => '</tr></table>');
    $form['submit'] = array('#type' => 'submit', '#name' => 'submit', '#value' => __('Save Changes'), '#attributes' => array('class' => 'button-primary'));
    $f = wpcf_form('wpcf-form', $form);
    wpcf_admin_ajax_head('Insert checkbox', 'wpcf');
    echo '<form method="post" action="">';
    echo $f->renderForm();
    echo '</form>';
    wpcf_admin_ajax_footer();
}
Ejemplo n.º 2
0
/**
 * Editor callback form.
 */
function wpcf_fields_radio_editor_callback()
{
    wpcf_admin_ajax_head('Insert checkbox', 'wpcf');
    $field = wpcf_admin_fields_get_field($_GET['field_id']);
    if (empty($field)) {
        echo '<div class="message error"><p>' . __('Wrong field specified', 'wpcf') . '</p></div>';
        wpcf_admin_ajax_footer();
        return '';
    }
    $form = array();
    $form['#form']['callback'] = 'wpcf_fields_radio_editor_submit';
    $form['display'] = array('#type' => 'radios', '#default_value' => 'db', '#name' => 'display', '#options' => array('display_from_db' => array('#title' => __('Display the value of this field from the database', 'wpcf'), '#name' => 'display', '#value' => 'db', '#inline' => true, '#after' => '<br />'), 'display_values' => array('#title' => __('Show one of these values:', 'wpcf'), '#name' => 'display', '#value' => 'value')), '#inline' => true);
    if (!empty($field['data']['options'])) {
        $form['table-open'] = array('#type' => 'markup', '#markup' => '<table style="margin-top:20px;" cellpadding="0" cellspacing="8">');
        foreach ($field['data']['options'] as $option_id => $option) {
            if ($option_id == 'default') {
                continue;
            }
            $value = isset($option['display_value']) ? $option['display_value'] : $option['value'];
            $form['display-value-' . $option_id] = array('#type' => 'textfield', '#title' => $option['title'], '#name' => 'options[' . $option_id . ']', '#value' => $value, '#inline' => true, '#pattern' => '<tr><td style="text-align:right;"><LABEL></td><td><ELEMENT></td></tr>', '#attributes' => array('style' => 'width:200px;'));
        }
        $form['table-close'] = array('#type' => 'markup', '#markup' => '</table>');
    }
    $form['submit'] = array('#type' => 'markup', '#markup' => get_submit_button());
    $f = wpcf_form('wpcf-form', $form);
    echo '<form method="post" action="">';
    echo $f->renderForm();
    echo '</form>';
    wpcf_admin_ajax_footer();
}
Ejemplo n.º 3
0
/**
 * Editor callback form.
 */
function wpcf_fields_checkbox_editor_callback()
{
    wp_enqueue_script('jquery');
    $form = array();
    $value_not_selected = '';
    $value_selected = '';
    if (isset($_GET['field_id'])) {
        $field = wpcf_admin_fields_get_field($_GET['field_id']);
        if (!empty($field)) {
            if (isset($field['data']['display_value_not_selected'])) {
                $value_not_selected = $field['data']['display_value_not_selected'];
            }
            if (isset($field['data']['display_value_selected'])) {
                $value_selected = $field['data']['display_value_selected'];
            }
        }
    }
    $form['#form']['callback'] = 'wpcf_fields_checkbox_editor_submit';
    $form['display'] = array('#type' => 'radios', '#default_value' => 'db', '#name' => 'display', '#options' => array('display_from_db' => array('#title' => __('Display the value of this field from the database', 'wpcf'), '#name' => 'display', '#value' => 'db', '#inline' => true, '#after' => '<br />'), 'display_values' => array('#title' => __('Enter values for \'selected\' and \'not selected\' states', 'wpcf'), '#name' => 'display', '#value' => 'value')), '#inline' => true);
    $form['states-start'] = array('#type' => 'markup', '#markup' => '<div id="wpcf-checkbox-states" style="display:none;margin-left:20px">');
    $form['display-value-1'] = array('#type' => 'textfield', '#title' => '<td style="text-align:right;">' . __('Not selected:', 'wpcf') . '</td><td>', '#name' => 'display_value_not_selected', '#value' => $value_not_selected, '#inline' => true, '#before' => '<table><tr>', '#after' => '</td></tr>');
    $form['display-value-2'] = array('#type' => 'textfield', '#title' => '<td style="text-align:right;">' . __('Selected:', 'wpcf') . '</td><td>', '#name' => 'display_value_selected', '#value' => $value_selected, '#before' => '<tr>', '#after' => '</tr></table>');
    $form['states-end'] = array('#type' => 'markup', '#markup' => '</div>');
    $form = wpcf_form_popup_add_optional($form);
    $help = array('url' => "http://wp-types.com/documentation/functions/checkbox/", 'text' => __('Checkbox help', 'wpcf'));
    $form = wpcf_form_popup_helper($form, __('Insert', 'wpcf'), __('Cancel', 'wpcf'), $help);
    $f = wpcf_form('wpcf-form', $form);
    add_action('admin_head_wpcf_ajax', 'wpcf_fields_checkbox_form_script');
    wpcf_admin_ajax_head('Insert checkbox', 'wpcf');
    echo '<form method="post" action="">';
    echo $f->renderForm();
    echo '</form>';
    wpcf_admin_ajax_footer();
}
Ejemplo n.º 4
0
/**
 * Editor callback form.
 */
function wpcf_fields_url_editor_callback()
{
    $form = array();
    $form['#form']['callback'] = 'wpcf_fields_url_editor_submit';
    $form['title'] = array('#type' => 'textfield', '#title' => __('Title', 'wpcf'), '#description' => __('If set, this text will be displayed instead of raw data'), '#name' => 'title');
    $form['submit'] = array('#type' => 'submit', '#name' => 'submit', '#value' => __('Save Changes'), '#attributes' => array('class' => 'button-primary'));
    $f = wpcf_form('wpcf-form', $form);
    wpcf_admin_ajax_head('Insert URL', 'wpcf');
    echo '<form method="post" action="">';
    echo $f->renderForm();
    echo '</form>';
    wpcf_admin_ajax_footer();
}
Ejemplo n.º 5
0
/**
 * Editor callback form.
 */
function wpcf_fields_email_editor_callback()
{
    $last_settings = wpcf_admin_fields_get_field_last_settings($_GET['field_id']);
    $form = array();
    $form['#form']['callback'] = 'wpcf_fields_email_editor_submit';
    $form['title'] = array('#type' => 'textfield', '#title' => __('Title', 'wpcf'), '#description' => __('If set, this text will be displayed instead of raw data'), '#name' => 'title', '#value' => isset($last_settings['title']) ? $last_settings['title'] : '');
    $form['submit'] = array('#type' => 'markup', '#markup' => get_submit_button());
    $f = wpcf_form('wpcf-form', $form);
    wpcf_admin_ajax_head('Insert email', 'wpcf');
    echo '<form method="post" action="">';
    echo $f->renderForm();
    echo '</form>';
    wpcf_admin_ajax_footer();
}
Ejemplo n.º 6
0
/**
 * Adds editor popup callnack.
 * 
 * This form will be showed in editor popup
 */
function wpcf_fields_google_map_editor_callback()
{
    wp_enqueue_style('wpcf-fields-google_map', WPCF_EMBEDDED_RES_RELPATH . '/css/basic.css', array(), WPCF_VERSION);
    wp_enqueue_script('jquery');
    // Get field
    $field = wpcf_admin_fields_get_field($_GET['field_id']);
    if (empty($field)) {
        _e('Wrong field specified', 'wpcf');
        die;
    }
    $last_settings = wpcf_admin_fields_get_field_last_settings($_GET['field_id']);
    if (isset($_POST['_wpnonce_wpcf_form']) && wp_verify_nonce($_POST['_wpnonce_wpcf_form'], 'wpcf-form')) {
        add_action('admin_head_wpcf_ajax', 'wpcf_fields_google_map_editor_submit');
    }
    wpcf_admin_ajax_head(__('Insert Google Map', 'wpcf'));
    ?>
    <form method="post" action="">
        <h2><?php 
    _e('Google Maps');
    ?>
</h2>
        <?php 
    _e('Specify width and height for Google Map:');
    ?>
<br /><br />
        <?php 
    wp_nonce_field('wpcf-form', '_wpnonce_wpcf_form');
    ?>
        <input type="text" name="width" value="<?php 
    echo isset($last_settings['width']) ? $last_settings['width'] : '425';
    ?>
" />
        <br />
        <input type="text" name="height" value="<?php 
    echo isset($last_settings['height']) ? $last_settings['height'] : '350';
    ?>
" />
        <br /><br /><input type="submit" class="button-primary" value="<?php 
    _e('Insert Google Map');
    ?>
" />
    </form>
    <?php 
    wpcf_admin_ajax_footer();
}
Ejemplo n.º 7
0
/**
 * Editor callback form.
 */
function wpcf_fields_numeric_editor_callback()
{
    wp_enqueue_style('wpcf-fields', WPCF_EMBEDDED_RES_RELPATH . '/css/basic.css', array(), WPCF_VERSION);
    wp_enqueue_script('jquery');
    // Get field
    $field = wpcf_admin_fields_get_field($_GET['field_id']);
    if (empty($field)) {
        _e('Wrong field specified', 'wpcf');
        die;
    }
    $last_settings = wpcf_admin_fields_get_field_last_settings($_GET['field_id']);
    $form = array();
    $form['#form']['callback'] = 'wpcf_fields_numeric_editor_submit';
    $form['format'] = array('#type' => 'textfield', '#title' => __('Output format', 'wpcf'), '#description' => __("Similar to sprintf function. Default: 'FIELD_NAME: FIELD_VALUE'.", 'wpcf'), '#name' => 'format', '#value' => isset($last_settings['format']) ? $last_settings['format'] : 'FIELD_NAME: FIELD_VALUE');
    $form['submit'] = array('#type' => 'submit', '#name' => 'submit', '#value' => __('Insert shortcode', 'wpcf'), '#attributes' => array('class' => 'button-primary'));
    $f = wpcf_form('wpcf-form', $form);
    wpcf_admin_ajax_head('Insert numeric', 'wpcf');
    echo '<form method="post" action="">';
    echo $f->renderForm();
    echo '</form>';
}
Ejemplo n.º 8
0
/**
 * Editor callback form.
 */
function wpcf_fields_checkboxes_editor_callback()
{
    $form = array();
    $form['#form']['callback'] = 'wpcf_fields_checkboxes_editor_submit';
    $form['display'] = array('#type' => 'radios', '#default_value' => 'display_all', '#name' => 'display', '#options' => array('display_from_db' => array('#title' => __('Display the value of this field from the database', 'wpcf'), '#name' => 'display', '#value' => 'db', '#inline' => true, '#after' => '<br />'), 'display_all' => array('#title' => __('Display all values with separator', 'wpcf'), '#name' => 'display', '#value' => 'display_all', '#inline' => true, '#after' => '&nbsp;' . wpcf_form_simple(array('separator' => array('#type' => 'textfield', '#name' => 'separator', '#value' => ', ', '#inline' => true))) . '<br />'), 'display_values' => array('#title' => __('Show one of these two values:', 'wpcf'), '#name' => 'display', '#value' => 'value')), '#inline' => true);
    if (isset($_GET['field_id'])) {
        $field = wpcf_admin_fields_get_field($_GET['field_id']);
        if (!empty($field['data']['options'])) {
            foreach ($field['data']['options'] as $option_key => $option) {
                $form[$option_key . '-markup'] = array('#type' => 'markup', '#markup' => '<h3>' . $option['title'] . '</h3>');
                $form[$option_key . '-display-value-1'] = array('#type' => 'textfield', '#title' => '<td style="text-align:right;">' . __('Not selected:', 'wpcf') . '</td><td>', '#name' => 'options[' . $option_key . '][display_value_not_selected]', '#value' => $option['display_value_not_selected'], '#inline' => true, '#before' => '<table><tr>', '#after' => '</td></tr>');
                $form[$option_key . '-display-value-2'] = array('#type' => 'textfield', '#title' => '<td style="text-align:right;">' . __('Selected:', 'wpcf') . '</td><td>', '#name' => 'options[' . $option_key . '][display_value_selected]', '#value' => $option['display_value_selected'], '#after' => '</tr></table>');
            }
        }
    }
    $form['submit'] = array('#type' => 'submit', '#name' => 'submit', '#value' => __('Save Changes'), '#attributes' => array('class' => 'button-primary'));
    $f = wpcf_form('wpcf-form', $form);
    wpcf_admin_ajax_head('Insert checkbox', 'wpcf');
    echo '<form method="post" action="">';
    echo $f->renderForm();
    echo '</form>';
    wpcf_admin_ajax_footer();
}
Ejemplo n.º 9
0
/**
 * Editor callback form.
 */
function wpcf_fields_file_editor_callback()
{
    wp_enqueue_style('wpcf-fields-file', WPCF_EMBEDDED_RES_RELPATH . '/css/basic.css', array(), WPCF_VERSION);
    // Get field
    $field = wpcf_admin_fields_get_field($_GET['field_id']);
    if (empty($field)) {
        _e('Wrong field specified', 'wpcf');
        die;
    }
    // Get post_ID
    $post_ID = false;
    if (isset($_POST['post_id'])) {
        $post_ID = intval($_POST['post_id']);
    } else {
        $http_referer = explode('?', $_SERVER['HTTP_REFERER']);
        parse_str($http_referer[1], $http_referer);
        if (isset($http_referer['post'])) {
            $post_ID = $http_referer['post'];
        }
    }
    // Get attachment
    $attachment_id = false;
    if ($post_ID) {
        $file = get_post_meta($post_ID, wpcf_types_get_meta_prefix($field) . $field['slug'], true);
        if (!empty($file)) {
            // Get attachment by guid
            global $wpdb;
            $attachment_id = $wpdb->get_var($wpdb->prepare("SELECT ID FROM {$wpdb->posts}\r\n    WHERE post_type = 'attachment' AND guid=%s", $file));
        }
    }
    $last_settings = wpcf_admin_fields_get_field_last_settings($_GET['field_id']);
    $form = array();
    $form['#form']['callback'] = 'wpcf_fields_file_editor_submit';
    if ($attachment_id) {
        $form['preview'] = array('#type' => 'markup', '#markup' => '<div class="message updated" style="margin: 0 0 20px 0"><p>' . $file . '</p></div>');
    }
    $form['link'] = array('#type' => 'checkbox', '#title' => __('Display as link', 'wpcf'), '#name' => 'link', '#default_value' => isset($last_settings['link']) ? $last_settings['link'] : 1);
    $form['title'] = array('#type' => 'textfield', '#title' => __('Link title', 'wpcf'), '#name' => 'title', '#value' => isset($last_settings['title']) ? $last_settings['title'] : '');
    $form['class'] = array('#type' => 'textfield', '#title' => __('Class', 'wpcf'), '#name' => 'class', '#value' => isset($last_settings['class']) ? $last_settings['class'] : '');
    $form['style'] = array('#type' => 'textfield', '#title' => __('Style', 'wpcf'), '#name' => 'style', '#value' => isset($last_settings['style']) ? $last_settings['style'] : '');
    $form['submit'] = array('#type' => 'submit', '#name' => 'submit', '#value' => __('Insert shortcode', 'wpcf'), '#attributes' => array('class' => 'button-primary'));
    $f = wpcf_form('wpcf-form', $form);
    wpcf_admin_ajax_head('Insert email', 'wpcf');
    echo '<form method="post" action="">';
    echo $f->renderForm();
    echo '</form>';
    wpcf_admin_ajax_footer();
}
Ejemplo n.º 10
0
/**
 * Editor callback form.
 */
function wpcf_fields_image_editor_callback()
{
    wp_enqueue_style('wpcf-fields-image', WPCF_EMBEDDED_RES_RELPATH . '/css/basic.css', array(), WPCF_VERSION);
    wp_enqueue_script('jquery');
    // Get field
    $field = wpcf_admin_fields_get_field($_GET['field_id']);
    if (empty($field)) {
        _e('Wrong field specified', 'wpcf');
        die;
    }
    // Get post_ID
    $post_ID = false;
    if (isset($_POST['post_id'])) {
        $post_ID = intval($_POST['post_id']);
    } else {
        $http_referer = explode('?', $_SERVER['HTTP_REFERER']);
        if (isset($http_referer[1])) {
            parse_str($http_referer[1], $http_referer);
            if (isset($http_referer['post'])) {
                $post_ID = $http_referer['post'];
            }
        }
    }
    // Get attachment
    $image = false;
    $attachment_id = false;
    if ($post_ID) {
        $image = get_post_meta($post_ID, wpcf_types_get_meta_prefix($field) . $field['slug'], true);
        if (!empty($image)) {
            // Get attachment by guid
            global $wpdb;
            $attachment_id = $wpdb->get_var($wpdb->prepare("SELECT ID FROM {$wpdb->posts}\r\r\n    WHERE post_type = 'attachment' AND guid=%s", $image));
        }
    }
    // Get post type
    $post_type = '';
    if ($post_ID) {
        $post_type = get_post_type($post_ID);
    } else {
        $http_referer = explode('?', $_SERVER['HTTP_REFERER']);
        parse_str($http_referer[1], $http_referer);
        if (isset($http_referer['post_type'])) {
            $post_type = $http_referer['post_type'];
        }
    }
    $image_data = wpcf_fields_image_get_data($image);
    if (!in_array($post_type, array('view', 'view-template'))) {
        // We must ignore errors here and treat image as outsider
        if (!empty($image_data['error'])) {
            $image_data['is_outsider'] = 1;
            $image_data['is_attachment'] = 0;
        }
    } else {
        if (!empty($image_data['error'])) {
            $image_data['is_outsider'] = 0;
            $image_data['is_attachment'] = 0;
        }
    }
    $last_settings = wpcf_admin_fields_get_field_last_settings($_GET['field_id']);
    $form = array();
    $form['#form']['callback'] = 'wpcf_fields_image_editor_submit';
    if ($attachment_id) {
        $form['preview'] = array('#type' => 'markup', '#markup' => '<div style="position:absolute; margin-left:300px;">' . wp_get_attachment_image($attachment_id, 'thumbnail') . '</div>');
    }
    $alt = '';
    $title = '';
    if ($attachment_id) {
        $alt = trim(strip_tags(get_post_meta($attachment_id, '_wp_attachment_image_alt', true)));
        $attachment_post = get_post($attachment_id);
        if (!empty($attachment_post)) {
            $title = trim(strip_tags($attachment_post->post_title));
        } else {
            if (!empty($alt)) {
                $title = $alt;
            }
        }
        if (empty($alt)) {
            $alt = $title;
        }
    }
    $form['title'] = array('#type' => 'textfield', '#title' => __('Image title', 'wpcf'), '#description' => __('Title text for the image, e.g. &#8220;The Mona Lisa&#8221;', 'wpcf'), '#name' => 'title', '#value' => isset($last_settings['title']) ? $last_settings['title'] : $title);
    $form['alt'] = array('#type' => 'textfield', '#title' => __('Alternate Text', 'wpcf'), '#description' => __('Alt text for the image, e.g. &#8220;The Mona Lisa&#8221;', 'wpcf'), '#name' => 'alt', '#value' => isset($last_settings['alt']) ? $last_settings['alt'] : $alt);
    $form['alignment'] = array('#type' => 'radios', '#title' => __('Alignment', 'wpcf'), '#name' => 'alignment', '#default_value' => isset($last_settings['alignment']) ? $last_settings['alignment'] : 'none', '#options' => array(__('None', 'wpcf') => 'none', __('Left', 'wpcf') => 'left', __('Center', 'wpcf') => 'center', __('Right', 'wpcf') => 'right'));
    if (!in_array($post_type, array('view', 'view-template'))) {
        $attributes_outsider = $image_data['is_outsider'] ? array('disabled' => 'disabled') : array();
        $attributes_attachment = !$image_data['is_attachment'] ? array('disabled' => 'disabled') : array();
    } else {
        $attributes_outsider = array();
        $attributes_attachment = array();
    }
    if (!in_array($post_type, array('view', 'view-template')) && $image_data['is_outsider']) {
        $form['notice'] = array('#type' => 'markup', '#markup' => '<div class="message error" style="margin:0 0 20px 0;"><p>' . __('Types can only resize images that you upload to this site and not images from other domains.', 'wpcf') . '</p></div>');
    } else {
        if ($image_data['is_outsider']) {
            $form['notice'] = array('#type' => 'markup', '#markup' => '<div class="message error" style="margin:0 0 20px 0;"><p>' . __('Types will be able to resize images that are uploaded to the post. If you specify URLs of images on other sites, Types will not resize them.', 'wpcf') . '</p></div>');
        }
    }
    if ($image_data['is_attachment']) {
        $default_value = isset($last_settings['image-size']) ? $last_settings['image-size'] : 'thumbnail';
    } else {
        if (!$image_data['is_outsider']) {
            $default_value = 'wpcf-custom';
        } else {
            $default_value = 'thumbnail';
        }
    }
    $form['size'] = array('#type' => 'radios', '#title' => __('Pre-defined sizes', 'wpcf'), '#name' => 'image-size', '#default_value' => $default_value, '#options' => array('thumbnail' => array('#title' => __('Thumbnail', 'wpcf'), '#value' => 'thumbnail', '#attributes' => $attributes_attachment), 'medium' => array('#title' => __('Medium', 'wpcf'), '#value' => 'medium', '#attributes' => $attributes_attachment), 'large' => array('#title' => __('Large', 'wpcf'), '#value' => 'large', '#attributes' => $attributes_attachment), 'full' => array('#title' => __('Full Size', 'wpcf'), '#value' => 'full', '#attributes' => $attributes_attachment), 'wpcf-custom' => array('#title' => __('Custom size', 'wpcf'), '#value' => 'wpcf-custom', '#attributes' => $attributes_outsider)));
    $form['toggle-open'] = array('#type' => 'markup', '#markup' => '<div id="wpcf-toggle" style="display:none;">');
    $form['width'] = array('#type' => 'textfield', '#title' => __('Width', 'wpcf'), '#description' => __('Specify custom width', 'wpcf'), '#name' => 'width', '#value' => isset($last_settings['width']) ? $last_settings['width'] : '', '#suffix' => '&nbsp;px', '#attributes' => $attributes_outsider);
    $form['height'] = array('#type' => 'textfield', '#title' => __('Height', 'wpcf'), '#description' => __('Specify custom height', 'wpcf'), '#name' => 'height', '#value' => isset($last_settings['height']) ? $last_settings['height'] : '', '#suffix' => '&nbsp;px', '#attributes' => $attributes_outsider);
    $form['proportional'] = array('#type' => 'checkbox', '#title' => __('Keep proportional', 'wpcf'), '#name' => 'proportional', '#default_value' => 1, '#attributes' => $attributes_outsider);
    $form['toggle-close'] = array('#type' => 'markup', '#markup' => '</div>', '#attributes' => $attributes_outsider);
    if ($post_ID) {
        $form['post_id'] = array('#type' => 'hidden', '#name' => 'post_id', '#value' => $post_ID);
    }
    $form['submit'] = array('#type' => 'submit', '#name' => 'submit', '#value' => __('Insert shortcode', 'wpcf'), '#attributes' => array('class' => 'button-primary'));
    $f = wpcf_form('wpcf-form', $form);
    wpcf_admin_ajax_head('Insert email', 'wpcf');
    echo '<form method="post" action="">';
    echo $f->renderForm();
    echo '</form>';
    ?>

    <script type="text/javascript">
        //<![CDATA[
        jQuery(document).ready(function(){
            jQuery('input:radio[name="image-size"]').change(function(){
                if (jQuery(this).val() == 'wpcf-custom') {
                    jQuery('#wpcf-toggle').slideDown();
                } else {
                    jQuery('#wpcf-toggle').slideUp();
                }
            });
            if (jQuery('input:radio[name="image-size"]:checked').val() == 'wpcf-custom') {
                jQuery('#wpcf-toggle').show();
            }
        });
        //]]>
    </script>
    <?php 
    wpcf_admin_ajax_footer();
}
Ejemplo n.º 11
0
/**
 * TinyMCE editor form.
 */
function wpcf_fields_date_editor_callback()
{
    $last_settings = wpcf_admin_fields_get_field_last_settings($_GET['field_id']);
    wp_enqueue_script('jquery');
    $form = array();
    $form['#form']['callback'] = 'wpcf_fields_date_editor_form_submit';
    $form['style'] = array('#type' => 'radios', '#name' => 'wpcf[style]', '#options' => array(__('Show as calendar', 'wpcf') => 'calendar', __('Show as text', 'wpcf') => 'text'), '#default_value' => isset($last_settings['style']) ? $last_settings['style'] : 'text', '#after' => '<br />');
    $date_formats = apply_filters('date_formats', array(__('F j, Y'), 'Y/m/d', 'm/d/Y', 'd/m/Y'));
    $options = array();
    foreach ($date_formats as $format) {
        $title = date($format, time());
        $field['#title'] = $title;
        $field['#value'] = $format;
        $options[] = $field;
    }
    $custom_format = isset($last_settings['format-custom']) ? $last_settings['format-custom'] : get_option('date_format');
    $options[] = array('#title' => __('Custom', 'wpcf'), '#value' => 'custom', '#suffix' => wpcf_form_simple(array('custom' => array('#name' => 'wpcf[format-custom]', '#type' => 'textfield', '#value' => $custom_format, '#suffix' => '&nbsp;' . date($custom_format, time()), '#inline' => true))));
    $form['toggle-open'] = array('#type' => 'markup', '#markup' => '<div id="wpcf-toggle" style="display:none;">');
    $form['format'] = array('#type' => 'radios', '#name' => 'wpcf[format]', '#options' => $options, '#default_value' => isset($last_settings['format']) ? $last_settings['format'] : get_option('date_format'), '#after' => '<a href="http://codex.wordpress.org/Formatting_Date_and_Time" target="_blank">' . __('Documentation on date and time formatting', 'wpcf') . '</a>');
    $form['toggle-close'] = array('#type' => 'markup', '#markup' => '</div>');
    $form['field_id'] = array('#type' => 'hidden', '#name' => 'wpcf[field_id]', '#value' => $_GET['field_id']);
    $form['submit'] = array('#type' => 'submit', '#name' => 'submit', '#value' => __('Insert date', 'wpcf'), '#attributes' => array('class' => 'button-primary'));
    $f = wpcf_form('wpcf-fields-date-editor', $form);
    add_action('admin_head_wpcf_ajax', 'wpcf_fields_date_editor_form_script');
    wpcf_admin_ajax_head(__('Insert date', 'wpcf'));
    echo '<form id="wpcf-form" method="post" action="">';
    echo $f->renderForm();
    echo '</form>';
    wpcf_admin_ajax_footer();
}
Ejemplo n.º 12
0
/**
 * Edit fields form.
 * 
 * @global type $wpdb
 * @param type $parent
 * @param type $child 
 */
function wpcf_pr_admin_edit_fields($parent, $child)
{
    global $wpdb;
    $post_type_parent = get_post_type_object($parent);
    $post_type_child = get_post_type_object($child);
    if (empty($post_type_parent) || empty($post_type_child)) {
        die(__('Wrong post types'));
    }
    $relationships = get_option('wpcf_post_relationship', array());
    if (!isset($relationships[$parent][$child])) {
        die(__('Relationship do not exist'));
    }
    $data = $relationships[$parent][$child];
    wp_enqueue_script('jquery');
    wpcf_admin_ajax_head('Edit fields', 'wpcf');
    // Process submit
    if (isset($_POST['_wpnonce']) && wp_verify_nonce($_POST['_wpnonce'], 'pt_edit_fields')) {
        $relationships[$parent][$child]['fields_setting'] = $_POST['fields_setting'];
        $relationships[$parent][$child]['fields'] = isset($_POST['fields']) ? $_POST['fields'] : array();
        update_option('wpcf_post_relationship', $relationships);
        ?>
        <script type="text/javascript">
            window.parent.jQuery('#TB_closeWindowButton').trigger('click');
            window.parent.location.reload();
        </script>
        <?php 
        die;
    }
    $groups = wpcf_admin_get_groups_by_post_type($child);
    $options_cf = array();
    $repetitive_warning = false;
    $repetitive_warning_markup = array();
    $repetitive_warning_txt = __('Repeating fields should not be used in child posts. Types will update all field values.', 'wpcf');
    foreach ($groups as $group) {
        $fields = wpcf_admin_fields_get_fields_by_group($group['id']);
        foreach ($fields as $key => $cf) {
            $options_cf[WPCF_META_PREFIX . $key] = array();
            $options_cf[WPCF_META_PREFIX . $key]['#title'] = $cf['name'];
            $options_cf[WPCF_META_PREFIX . $key]['#name'] = 'fields[' . WPCF_META_PREFIX . $key . ']';
            $options_cf[WPCF_META_PREFIX . $key]['#default_value'] = isset($data['fields'][WPCF_META_PREFIX . $key]) ? 1 : 0;
            // Repetitive warning
            if (wpcf_admin_is_repetitive($cf)) {
                if (!$repetitive_warning) {
                    $repetitive_warning_markup = array('#type' => 'markup', '#markup' => '<div class="message error" style="display:none;" id="wpcf-repetitive-warning"><p>' . $repetitive_warning_txt . '</p></div>');
                }
                $repetitive_warning = true;
                $options_cf[WPCF_META_PREFIX . $key]['#after'] = !isset($data['fields'][WPCF_META_PREFIX . $key]) ? '<div class="message error" style="display:none;"><p>' : '<div class="message error"><p>';
                $options_cf[WPCF_META_PREFIX . $key]['#after'] .= $repetitive_warning_txt;
                $options_cf[WPCF_META_PREFIX . $key]['#after'] .= '</p></div>';
                $options_cf[WPCF_META_PREFIX . $key]['#attributes'] = array('onclick' => 'jQuery(this).parent().find(\'.message\').toggle();');
            }
        }
    }
    $form = array();
    $form['repetitive_warning_markup'] = $repetitive_warning_markup;
    $form['select'] = array('#type' => 'radios', '#name' => 'fields_setting', '#options' => array(__('Title, all custom fields and parents', 'wpcf') => 'all_cf', __('All fields, including the standard post fields', 'wpcf') => 'all_cf_standard', __('Specific fields', 'wpcf') => 'specific'), '#default_value' => empty($data['fields_setting']) ? 'all_cf' : $data['fields_setting']);
    $options = array();
    $options['_wp_title'] = array('#title' => __('Post title', 'wpcf'), '#name' => 'fields[_wp_title]', '#default_value' => isset($data['fields']['_wp_title']) ? 1 : 0);
    $options['_wp_body'] = array('#title' => __('Post body', 'wpcf'), '#name' => 'fields[_wp_body]', '#default_value' => isset($data['fields']['_wp_body']) ? 1 : 0);
    $options = $options + $options_cf;
    $temp_belongs = wpcf_pr_admin_get_belongs($child);
    foreach ($temp_belongs as $temp_parent => $temp_data) {
        if ($temp_parent == $parent) {
            continue;
        }
        $temp_parent_type = get_post_type_object($temp_parent);
        $options[$temp_parent] = array();
        $options[$temp_parent]['#title'] = $temp_parent_type->label;
        $options[$temp_parent]['#name'] = 'fields[_wpcf_pr_parents][' . $temp_parent . ']';
        $options[$temp_parent]['#default_value'] = isset($data['fields']['_wpcf_pr_parents'][$temp_parent]) ? 1 : 0;
    }
    $form['specific'] = array('#type' => 'checkboxes', '#name' => 'fields', '#options' => $options, '#default_value' => isset($data['fields']), '#before' => '<div id="wpcf-specific" style="display:none;margin:10px 0 0 20px;">', '#after' => '</div>');
    $form['submit'] = array('#type' => 'submit', '#name' => 'submit', '#value' => __('Save', 'wpcf'), '#attributes' => array('class' => 'button-primary'));
    echo '<form method="post" action="">';
    echo wpcf_form_simple($form);
    echo wp_nonce_field('pt_edit_fields');
    echo '</form>';
    ?>
    <script type="text/javascript">
        jQuery(document).ready(function(){
            if (jQuery('input[name="fields_setting"]:checked').val() == 'specific') {
                jQuery('#wpcf-specific').show();
            } else {
    <?php 
    if ($repetitive_warning) {
        ?>
                                    jQuery('#wpcf-repetitive-warning').show();
        <?php 
    }
    ?>
                            }
                            jQuery('input[name="fields_setting"]').change(function(){
                                if (jQuery(this).val() == 'specific') {
                                    jQuery('#wpcf-specific').slideDown();
                                } else {
                                    jQuery('#wpcf-specific').slideUp();
    <?php 
    if ($repetitive_warning) {
        ?>
                                        jQuery('#wpcf-repetitive-warning').show();
        <?php 
    }
    ?>
                                }
                            });
                        });
    </script>
    <?php 
    wpcf_admin_ajax_footer();
}
Ejemplo n.º 13
0
/**
 * Edit Skype button AJAX call.
 */
function wpcf_fields_skype_meta_box_ajax()
{
    if (isset($_POST['_wpnonce_wpcf_form']) && wp_verify_nonce($_POST['_wpnonce_wpcf_form'], 'wpcf-form')) {
        add_action('admin_head_wpcf_ajax', 'wpcf_fields_skype_meta_box_submit');
    }
    wp_enqueue_script('jquery');
    wpcf_admin_ajax_head(__('Insert skype button', 'wpcf'));
    ?>
    <form method="post" action="">
        <h2><?php 
    _e('Enter your Skype Name', 'wpcf');
    ?>
</h2>
        <p>
            <input id="btn-skypename" name="skypename" value="<?php 
    esc_attr_e($_GET['skypename']);
    ?>
" type="text" />
        </p>
        <?php 
    echo WPCF_Loader::template('skype-select-button', $_GET);
    ?>
        <?php 
    wp_nonce_field('wpcf-form', '_wpnonce_wpcf_form');
    ?>
        <br /><br />
        <input type="submit" class="button-primary" value="<?php 
    _e('Insert skype button', 'wpcf');
    ?>
" />
    </form>
    <?php 
    $update = esc_attr($_GET['update']);
    ?>
    <script type="text/javascript">
        //<![CDATA[
        jQuery(document).ready(function(){
            jQuery('#btn-skypename').val(window.parent.jQuery('#<?php 
    echo $update;
    ?>
-skypename').val());
        });
        //]]>
    </script>
    <?php 
    wpcf_admin_ajax_footer();
}
Ejemplo n.º 14
0
/**
 * Edit fields form.
 *
 * @param type $parent
 * @param type $child
 */
function wpcf_pr_admin_edit_fields($parent, $child)
{
    $post_type_parent = get_post_type_object($parent);
    $post_type_child = get_post_type_object($child);
    if (empty($post_type_parent) || empty($post_type_child)) {
        die(__('Wrong post types', 'wpcf'));
    }
    $relationships = get_option('wpcf_post_relationship', array());
    if (!isset($relationships[$parent][$child])) {
        die(__('Relationship do not exist', 'wpcf'));
    }
    $data = $relationships[$parent][$child];
    wp_enqueue_script('jquery');
    wp_enqueue_style('types');
    wpcf_admin_ajax_head('Edit fields', 'wpcf');
    // Process submit
    if (isset($_POST['_wpnonce']) && wp_verify_nonce($_POST['_wpnonce'], 'pt_edit_fields')) {
        $relationships[$parent][$child]['fields_setting'] = sanitize_text_field($_POST['fields_setting']);
        // @todo Maybe sanitization here
        $relationships[$parent][$child]['fields'] = isset($_POST['fields']) ? $_POST['fields'] : array();
        update_option('wpcf_post_relationship', $relationships);
        ?>
        <script type="text/javascript">
            window.parent.jQuery('#TB_closeWindowButton').trigger('click');
            window.parent.location.reload();
        </script>
        <?php 
        die;
    }
    $groups = wpcf_admin_get_groups_by_post_type($child);
    $options_cf = array();
    $repetitive_warning = false;
    $repetitive_warning_markup = array();
    $repetitive_warning_txt = __('Repeating fields should not be used in child posts. Types will update all field values.', 'wpcf');
    foreach ($groups as $group) {
        $fields = wpcf_admin_fields_get_fields_by_group($group['id']);
        foreach ($fields as $key => $cf) {
            $__key = wpcf_types_cf_under_control('check_outsider', $key) ? $key : WPCF_META_PREFIX . $key;
            $options_cf[$__key] = array();
            $options_cf[$__key]['#title'] = $cf['name'];
            $options_cf[$__key]['#name'] = 'fields[' . $__key . ']';
            $options_cf[$__key]['#default_value'] = isset($data['fields'][$__key]) ? 1 : 0;
            // Repetitive warning
            if (wpcf_admin_is_repetitive($cf)) {
                if (!$repetitive_warning) {
                    $repetitive_warning_markup = array('#type' => 'markup', '#markup' => '<div class="message error" style="display:none;" id="wpcf-repetitive-warning"><p>' . $repetitive_warning_txt . '</p></div>');
                }
                $repetitive_warning = true;
                $options_cf[$__key]['#after'] = !isset($data['fields'][$__key]) ? '<div class="message error" style="display:none;"><p>' : '<div class="message error"><p>';
                $options_cf[$__key]['#after'] .= $repetitive_warning_txt;
                $options_cf[$__key]['#after'] .= '</p></div>';
                $options_cf[$__key]['#attributes'] = array('onclick' => 'jQuery(this).parent().find(\'.message\').toggle();', 'disabled' => 'disabled');
            }
        }
    }
    $form = array();
    $form['repetitive_warning_markup'] = $repetitive_warning_markup;
    $form['select'] = array('#type' => 'radios', '#name' => 'fields_setting', '#options' => array(__('Title, all custom fields and parents', 'wpcf') => 'all_cf', __('Do not show management options for this post type', 'wpcf') => 'only_list', __('All fields, including the standard post fields', 'wpcf') => 'all_cf_standard', __('Specific fields', 'wpcf') => 'specific'), '#default_value' => empty($data['fields_setting']) ? 'all_cf' : $data['fields_setting']);
    /**
     * check default, to avoid missing configuration
     */
    if (!in_array($form['select']['#default_value'], $form['select']['#options'])) {
        $form['select']['#default_value'] = 'all_cf';
    }
    /**
     * build options for "Specific fields"
     */
    $options = array();
    /**
     * check and add build-in properites
     */
    $check_support = array('title' => array('name' => '_wp_title', 'title' => __('Post title', 'wpcf')), 'editor' => array('name' => '_wp_body', 'title' => __('Post body', 'wpcf')), 'excerpt' => array('name' => '_wp_excerpt', 'title' => __('Post excerpt', 'wpcf')), 'thumbnail' => array('name' => '_wp_featured_image', 'title' => __('Post featured image', 'wpcf')));
    foreach ($check_support as $child_field_key => $child_field_data) {
        if (!post_type_supports($child, $child_field_key)) {
            continue;
        }
        $options[$child_field_data['name']] = array('#title' => $child_field_data['title'], '#name' => sprintf('fields[%s]', $child_field_data['name']), '#default_value' => isset($data['fields'][$child_field_data['name']]) ? 1 : 0);
    }
    /**
     * add custom fields
     */
    $options = $options + $options_cf;
    $temp_belongs = wpcf_pr_admin_get_belongs($child);
    foreach ($temp_belongs as $temp_parent => $temp_data) {
        if ($temp_parent == $parent) {
            continue;
        }
        $temp_parent_type = get_post_type_object($temp_parent);
        $options[$temp_parent] = array();
        $options[$temp_parent]['#title'] = $temp_parent_type->label;
        $options[$temp_parent]['#name'] = 'fields[_wpcf_pr_parents][' . $temp_parent . ']';
        $options[$temp_parent]['#default_value'] = isset($data['fields']['_wpcf_pr_parents'][$temp_parent]) ? 1 : 0;
    }
    /**
     * remove "Specific fields" if there is no fields
     */
    if (empty($options)) {
        unset($form['select']['#options'][__('Specific fields', 'wpcf')]);
        if ('specific' == $form['select']['#default_value']) {
            $form['select']['#default_value'] = 'all_cf';
        }
    }
    // Taxonomies
    $taxonomies = get_object_taxonomies($post_type_child->name, 'objects');
    if (!empty($taxonomies)) {
        foreach ($taxonomies as $tax_id => $taxonomy) {
            $options[$tax_id] = array();
            $options[$tax_id]['#title'] = sprintf(__('Taxonomy - %s', 'wpcf'), $taxonomy->label);
            $options[$tax_id]['#name'] = 'fields[_wpcf_pr_taxonomies][' . $tax_id . ']';
            $options[$tax_id]['#default_value'] = isset($data['fields']['_wpcf_pr_taxonomies'][$tax_id]) ? 1 : 0;
        }
    }
    $form['specific'] = array('#type' => 'checkboxes', '#name' => 'fields', '#options' => $options, '#default_value' => isset($data['fields']), '#before' => '<div id="wpcf-specific" style="display:none;margin:10px 0 0 20px;">', '#after' => '</div>');
    $form['submit'] = array('#type' => 'submit', '#name' => 'submit', '#value' => __('Save', 'wpcf'), '#attributes' => array('class' => 'button-primary'));
    echo '<form method="post" action="" class="types-select-child-fields">';
    echo wpcf_form_simple($form);
    echo wp_nonce_field('pt_edit_fields');
    echo '</form>';
    ?>
    <script type="text/javascript">
        jQuery(document).ready(function(){
            if (jQuery('input[name="fields_setting"]:checked').val() == 'specific') {
                jQuery('#wpcf-specific').show();
            } else {
    <?php 
    if ($repetitive_warning && 'only_list' != $form['select']['#default_value']) {
        ?>
                    jQuery('#wpcf-repetitive-warning').show();
        <?php 
    }
    ?>
            }
            jQuery('input[name="fields_setting"]').change(function(){
                if (jQuery(this).val() == 'specific') {
                    jQuery('#wpcf-specific').slideDown();
                } else {
                    jQuery('#wpcf-specific').slideUp();
    <?php 
    if ($repetitive_warning) {
        ?>
                    if ( 'only_list' != jQuery('input[name="fields_setting"]:checked').val()) {
                        jQuery('#wpcf-repetitive-warning').show();
                    }
        <?php 
    }
    ?>
                }
            });
        });
    </script>
    <?php 
    wpcf_admin_ajax_footer();
}
Ejemplo n.º 15
0
/**
 * Edit Skype button AJAX call.
 */
function wpcf_fields_skype_meta_box_ajax()
{
    if (isset($_POST['_wpnonce_wpcf_form']) && wp_verify_nonce($_POST['_wpnonce_wpcf_form'], 'wpcf-form')) {
        add_action('admin_head_wpcf_ajax', 'wpcf_fields_skype_meta_box_submit');
    }
    wp_enqueue_script('jquery');
    wpcf_admin_ajax_head(__('Insert skype button', 'wpcf'));
    ?>

    <form method="post" action="">
        <div id="paddedContent"> 
            <div id="step1"> 
                <h2><?php 
    _e('Enter your Skype Name', 'wpcf');
    ?>
</h2>  
                <p> 
                    <input id="btn-skypename" name="skypename" value="<?php 
    echo $_GET['skypename'];
    ?>
" type="text" /> 
                </p> 
            </div>  
            <div id="step2"> 
                <h2><?php 
    _e('Select a button from below', 'wpcf');
    ?>
</h2>  
                <div id="static-buttons"> 
                    <table border="0" cellpadding="0" cellspacing="0" width="445">

                        <colgroup><col span="1" width="223">
                            <col span="1" width="222">
                        </colgroup><tbody><tr>
                                <td colspan="1" rowspan="1"> 
                                    <label for="btn1"> 
                                        <input <?php 
    if ($_GET['style'] == 'btn1') {
        echo 'checked="checked" ';
    }
    ?>
id="btn1" name="buttonstyle" tabindex="2" value="btn1" type="radio" />  
                                        <img alt="" id="btn1-img" src="http://www.skypeassets.com/i/legacy/images/share/buttons/call_green_white_153x63.png" height="63" width="153" /> 
                                    </label> 
                                </td>
                                <td colspan="1" rowspan="1"> 
                                    <label for="btn2"> 
                                        <input <?php 
    if ($_GET['style'] == 'btn2') {
        echo 'checked="checked" ';
    }
    ?>
id="btn2" name="buttonstyle" tabindex="3" value="btn2" type="radio" />  
                                        <img alt="" id="btn2-img" src="http://www.skypeassets.com/i/legacy/images/share/buttons/call_blue_white_124x52.png" height="52" width="125" /> 
                                    </label> 
                                </td>

                            </tr>
                            <tr>
                                <td colspan="1" rowspan="1"> 
                                    <label for="btn3"> 
                                        <input <?php 
    if ($_GET['style'] == 'btn3') {
        echo 'checked="checked" ';
    }
    ?>
id="btn3" name="buttonstyle" tabindex="4" value="btn3" type="radio" />  
                                        <img alt="" id="btn3-img" src="http://www.skypeassets.com/i/legacy/images/share/buttons/call_green_white_92x82.png" height="82" width="92" /> 
                                    </label> 
                                </td>
                                <td colspan="1" rowspan="1"> 
                                    <label for="btn4"> 
                                        <input <?php 
    if ($_GET['style'] == 'btn4') {
        echo 'checked="checked" ';
    }
    ?>
id="btn4" name="buttonstyle" tabindex="5" value="btn4" type="radio" />  
                                        <img alt="" id="btn4-img" src="http://www.skypeassets.com/i/legacy/images/share/buttons/call_blue_transparent_34x34.png" height="34" width="34" /> 
                                    </label> 
                                </td>

                            </tr>
                        </tbody></table> 
                </div>  
                <h2><?php 
    _e('Skype buttons with status', 'wpcf');
    ?>
</h2>  
                <p><?php 
    _e('If you choose to show your Skype status, your Skype button will always reflect your availability on Skype. This status will be shown to everyone, whether they’re in your contact list or not.', 'wpcf');
    ?>
</p>  
                <div id="status-buttons"> 
                    <table border="0" cellpadding="0" cellspacing="0" width="445">
                        <colgroup><col span="1" width="223">
                            <col span="1" width="222">
                        </colgroup><tbody><tr>

                                <td colspan="1" rowspan="1"> 
                                    <label for="btn5"> 
                                        <input <?php 
    if ($_GET['style'] == 'btn5') {
        echo 'checked="checked" ';
    }
    ?>
id="btn5" name="buttonstyle" tabindex="6" value="btn5" type="radio" />  
                                        <img alt="" id="btn5-img" src="http://www.skypeassets.com/i/legacy/images/share/buttons/anim_balloon.gif" height="60" width="150" /> 
                                    </label> 
                                </td>
                                <td colspan="1" rowspan="1"> 
                                    <label for="btn6"> 
                                        <input <?php 
    if ($_GET['style'] == 'btn6') {
        echo 'checked="checked" ';
    }
    ?>
id="btn6" name="buttonstyle" tabindex="7" value="btn6" type="radio" />  
                                        <img alt="" id="btn6-img" src="http://www.skypeassets.com/i/legacy/images/share/buttons/anim_rectangle.gif" height="44" width="182" /> 
                                    </label> 
                                </td>
                            </tr>
                        </tbody></table> 
                </div>
            </div>
                               <?php 
    wp_nonce_field('wpcf-form', '_wpnonce_wpcf_form');
    ?>

            <br /><br /><input type="submit" class="button-primary" value="<?php 
    _e('Insert skype button', 'wpcf');
    ?>
" />
    </form>
    <?php 
    $update = esc_attr($_GET['update']);
    ?>

    <script type="text/javascript">
        //<![CDATA[
        jQuery(document).ready(function(){
            jQuery('#btn-skypename').val(window.parent.jQuery('#<?php 
    echo $update;
    ?>
-skypename').val());
        });
        //]]>
    </script>
    <?php 
    wpcf_admin_ajax_footer();
}
Ejemplo n.º 16
0
/**
 * Edit fields form.
 * 
 * @global type $wpdb
 * @param type $parent
 * @param type $child 
 */
function wpcf_pr_admin_edit_fields($parent, $child)
{
    global $wpdb;
    $post_type_parent = get_post_type_object($parent);
    $post_type_child = get_post_type_object($child);
    if (empty($post_type_parent) || empty($post_type_child)) {
        die(__('Wrong post types'));
    }
    $relationships = get_option('wpcf_post_relationship', array());
    if (!isset($relationships[$parent][$child])) {
        die(__('Relationship do not exist'));
    }
    $data = $relationships[$parent][$child];
    wp_enqueue_script('jquery');
    wpcf_admin_ajax_head('Edit fields', 'wpcf');
    // Process submit
    if (isset($_POST['_wpnonce']) && wp_verify_nonce($_POST['_wpnonce'], 'pt_edit_fields')) {
        $relationships[$parent][$child]['fields_setting'] = $_POST['fields_setting'];
        $relationships[$parent][$child]['fields'] = isset($_POST['fields']) ? $_POST['fields'] : array();
        update_option('wpcf_post_relationship', $relationships);
        ?>
        <script type="text/javascript">
            window.parent.jQuery('#TB_closeWindowButton').trigger('click');
            window.parent.location.reload();
        </script>
        <?php 
        die;
    }
    $form = array();
    $form['select'] = array('#type' => 'radios', '#name' => 'fields_setting', '#options' => array(__('Title, all custom fields and parents', 'wpcf') => 'all_cf', __('All fields, including the standard post fields', 'wpcf') => 'all_cf_standard', __('Specific fields', 'wpcf') => 'specific'), '#default_value' => empty($data['fields_setting']) ? 'all_cf' : $data['fields_setting']);
    $options = array();
    $options['_wp_title'] = array('#title' => __('Post title', 'wpcf'), '#name' => 'fields[_wp_title]', '#default_value' => isset($data['fields']['_wp_title']) ? 1 : 0);
    $options['_wp_body'] = array('#title' => __('Post body', 'wpcf'), '#name' => 'fields[_wp_body]', '#default_value' => isset($data['fields']['_wp_body']) ? 1 : 0);
    //    $wpcf_fields = wpcf_admin_fields_get_fields(true);
    $groups = wpcf_admin_get_groups_by_post_type($child);
    foreach ($groups as $group) {
        $fields = wpcf_admin_fields_get_fields_by_group($group['id']);
        foreach ($fields as $key => $cf) {
            $options[WPCF_META_PREFIX . $key] = array();
            $options[WPCF_META_PREFIX . $key]['#title'] = $cf['name'];
            $options[WPCF_META_PREFIX . $key]['#name'] = 'fields[' . WPCF_META_PREFIX . $key . ']';
            $options[WPCF_META_PREFIX . $key]['#default_value'] = isset($data['fields'][WPCF_META_PREFIX . $key]) ? 1 : 0;
        }
    }
    $temp_belongs = wpcf_pr_admin_get_belongs($child);
    foreach ($temp_belongs as $temp_parent => $temp_data) {
        if ($temp_parent == $parent) {
            continue;
        }
        $temp_parent_type = get_post_type_object($temp_parent);
        $options[$temp_parent] = array();
        $options[$temp_parent]['#title'] = $temp_parent_type->label;
        $options[$temp_parent]['#name'] = 'fields[_wpcf_pr_parents][' . $temp_parent . ']';
        $options[$temp_parent]['#default_value'] = isset($data['fields']['_wpcf_pr_parents'][$temp_parent]) ? 1 : 0;
    }
    //    foreach ($wpcf_fields as $key => $cf) {
    //        $options[WPCF_META_PREFIX . $key] = array();
    //        $options[WPCF_META_PREFIX . $key]['#title'] = $cf['name'];
    //        $options[WPCF_META_PREFIX . $key]['#name'] = 'fields[' . WPCF_META_PREFIX . $key . ']';
    //        $options[WPCF_META_PREFIX . $key]['#default_value'] = isset($data['fields'][WPCF_META_PREFIX . $key]) ? 1 : 0;
    //    }
    //    $cf_all = $wpdb->get_results("
    //		SELECT meta_id, meta_key
    //		FROM $wpdb->postmeta
    //		GROUP BY meta_key
    //		HAVING meta_key NOT LIKE '\_%'
    //		ORDER BY meta_key");
    //    foreach ($cf_all as $key => $cf) {
    //        if (isset($options[$cf->meta_key])) {
    //            continue;
    //        }
    //        $options[$key] = array();
    //        $options[$key]['#title'] = $cf->meta_key;
    //        $options[$key]['#name'] = 'fields[' . $cf->meta_key . ']';
    //        $options[$key]['#default_value'] = isset($data['fields'][$cf->meta_key]) ? 1 : 0;
    //    }
    $form['specific'] = array('#type' => 'checkboxes', '#name' => 'fields', '#options' => $options, '#default_value' => isset($data['fields']), '#before' => '<div id="wpcf-specific" style="display:none;margin:10px 0 0 20px;">', '#after' => '</div>');
    $form['submit'] = array('#type' => 'submit', '#name' => 'submit', '#value' => __('Save'), '#attributes' => array('class' => 'button-primary'));
    echo '<form method="post" action="">';
    echo wpcf_form_simple($form);
    echo wp_nonce_field('pt_edit_fields');
    echo '</form>';
    ?>
    <script type="text/javascript">
        jQuery(document).ready(function(){
            if (jQuery('input[name="fields_setting"]:checked').val() == 'specific') {
                jQuery('#wpcf-specific').show();
            }
            jQuery('input[name="fields_setting"]').change(function(){
                if (jQuery(this).val() == 'specific') {
                    jQuery('#wpcf-specific').slideDown();
                } else {
                    jQuery('#wpcf-specific').slideUp();
                }
            });
        });
    </script>
    <?php 
    wpcf_admin_ajax_footer();
}
Ejemplo n.º 17
-1
 /**
  * Renders Thickbox content.
  *
  * Field should provide callback function
  * that will be called automatically.
  *
  * Function should be named like:
  * 'wpcf_fields_' . $field_type . '_editor_callback'
  * e.g. 'wpcf_fields_checkbox__editor_callback'
  *
  * Function should return array with elements:
  * 'supports' - parameters or other feature supported, e.g. 'styling' will
  *     enable 'Styling' options
  *
  * Tabs is array with elements:
  * 'menu_title' - used for menu title
  * 'title' - used for main title
  * 'content' - HTML content of tab
  *
  * @param type $field
  * @param type $meta_type
  * @param type $post_id
  * @param string $shortcode
  */
 function frame($field, $meta_type = 'postmeta', $post_id = -1, $shortcode = null, $callback = false, $views_usermeta = false)
 {
     global $wp_version, $wpcf;
     // Queue rendering JS settings
     add_action('admin_print_footer_scripts', array($this, 'renderTedSettings'), 1);
     wp_enqueue_script('types');
     wp_enqueue_script('types-knockout');
     wp_enqueue_script('types-editor');
     wp_enqueue_script('wp-pointer');
     wp_enqueue_style('types-editor');
     wp_enqueue_style('wp-pointer');
     wp_enqueue_style('toolset-font-awesome');
     // Load cloned WP Media Modal CSS
     if (version_compare($wp_version, '3.5', '<')) {
         wp_enqueue_style('types-editor-cloned');
     }
     $this->field = $field;
     $this->_meta_type = $meta_type;
     $this->_post = get_post($post_id);
     $this->_settings = is_null($shortcode) ? array() : $this->shortcodeToParameters($shortcode);
     $this->callback = $callback;
     $this->_data = array('meta_type' => $meta_type, 'field' => $field, 'field_type_data' => WPCF_Fields::getFieldTypeData($field['type']), 'settings' => array(), 'tabs' => array(), 'supports' => array(), 'post' => $this->_post, 'post_types' => get_post_types(array('show_ui' => true)), 'style' => isset($this->_settings['style']) ? $this->_settings['style'] : '', 'class' => isset($this->_settings['class']) ? $this->_settings['class'] : '', 'output' => 'html', 'user_form' => '');
     // Set title if updated
     if (!is_null($shortcode)) {
         $this->_data['title'] = sprintf(__('Update %s', 'wpcf'), $this->_data['field_type_data']['title']);
         $this->_data['submit_button_title'] = __('Update shortcode', 'wpcf');
     }
     // Exclude post types
     foreach ($wpcf->excluded_post_types as $_post_type) {
         unset($this->_data['post_types'][$_post_type]);
     }
     /*
      * Callback
      */
     $function = 'wpcf_fields_' . $field['type'] . '_editor_callback';
     if (function_exists($function)) {
         // Main callback
         $callback = call_user_func($function, $field, $this->_settings, $this->_meta_type, $this->_post);
         // Add supports
         if (!empty($callback['supports']) && is_array($callback['supports'])) {
             $this->_data['supports'] = $callback['supports'];
         }
         // Add tabs
         if (!empty($callback['tabs']) && is_array($callback['tabs'])) {
             $this->_data['tabs'] = $callback['tabs'];
         }
         // Unify settings
         if (!empty($callback['settings']) && is_array($callback['settings'])) {
             $this->_settings = array_merge($this->_settings, self::sanitizeParams($callback['settings'], 'array'));
         }
     }
     // If no tabs
     if (empty($this->_data['tabs'])) {
         $this->_data['tabs']['display'] = array('menu_title' => __('Display', 'wpcf'), 'title' => __('Display', 'wpcf'), 'content' => sprintf(__('There are no additional display options for the %s field.', 'wpcf'), $this->_data['field_type_data']['title']));
     }
     // Add User ID form
     if ($this->_meta_type == 'usermeta') {
         if (!$views_usermeta) {
             $this->_data['user_form'] = wpcf_form_simple(wpcf_get_usermeta_form_addon($this->_settings));
             $this->_data['supports'][] = 'user_id';
         }
     } else {
         // Add Post ID form
         $this->_data['supports'][] = 'post_id';
     }
     // Get parents
     if (!empty($this->_post->ID)) {
         $this->_data['parents'] = WPCF_Relationship::get_parents($this->_post);
     }
     // Set icons
     $icons = array('audio' => 'icon-music', 'checkbox' => 'icon-check', 'checkboxes' => 'icon-checkboxes', 'colorpicker' => 'icon-tint', 'date' => 'icon-calendar', 'email' => 'icon-envelope-alt', 'embed' => 'icon-youtube-play', 'file' => 'icon-file-alt', 'image' => 'icon-picture', 'map' => 'icon-map-marker', 'numeric' => 'icon-numeric', 'phone' => 'icon-phone', 'radio' => 'icon-radio-button', 'select' => 'icon-select-box', 'skype' => 'icon-skype', 'textarea' => 'icon-text-area', 'textfield' => 'icon-text-field', 'url' => 'icon-link', 'video' => 'icon-film', 'wysiwyg' => 'icon-wysiwyg');
     $this->_data['icon_class'] = isset($icons[$field['type']]) ? $icons[$field['type']] : 'icon-text-field';
     // Is repetitive
     $this->_data['is_repetitive'] = (bool) types_is_repetitive($field);
     if ($this->_data['is_repetitive']) {
         $this->_data['supports'][] = 'separator';
     }
     // Render header
     wpcf_admin_ajax_head();
     // Check if submitted
     $this->_thickbox_check_submit();
     // Render form
     echo '<form method="post" action="" id="types-editor-modal-form">';
     echo WPCF_Loader::view('editor-modal-window', $this->_data);
     wp_nonce_field('types_editor_frame', '__types_editor_nonce');
     echo '</form>';
     // Render footer
     wpcf_admin_ajax_footer();
 }