Plugin Directory

Changeset 559854


Ignore:
Timestamp:
06/18/2012 12:14:58 PM (14 years ago)
Author:
reflectionmedia
Message:

version 1.0.2 changes to upload field and minor ui improvments. also fixed some minor bugs

Location:
custom-fields-creator/trunk
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • custom-fields-creator/trunk/css/wck-cfc.css

    r512346 r559854  
    1 #wck_cfc_fields .row-options{
     1#wck_cfc_fields .row-options, #wck_cfc_fields .row-attach-upload-to-post{
    22    display:none;
    33}
  • custom-fields-creator/trunk/js/wck-cfc.js

    r512346 r559854  
    88        else{
    99            jQuery( '#wck_cfc_fields .row-options' ).hide();
     10        }
     11       
     12        if( value == 'upload' ){
     13            jQuery( '#wck_cfc_fields .row-attach-upload-to-post' ).show();
     14        }
     15        else{
     16            jQuery( '#wck_cfc_fields .row-attach-upload-to-post' ).hide();
    1017        }
    1118    });
     
    1926            jQuery( '.hide-options', jQuery(this).parent().parent().parent() ).hide();
    2027        }
     28       
     29        if( value == 'upload' ){
     30            jQuery( '.hide-attach', jQuery(this).parent().parent().parent() ).show();
     31        }
     32        else{
     33            jQuery( '.hide-attach', jQuery(this).parent().parent().parent() ).hide();
     34        }
    2135    });
    2236});
  • custom-fields-creator/trunk/readme.txt

    r517828 r559854  
    55Tags: custom field, custom fields, custom fields creator, meta box, meta boxes, repeater fields, post meta, repeater
    66Requires at least: 3.1
    7 Tested up to: 3.3.1
    8 Stable tag: 1.0.1
     7Tested up to: 3.4
     8Stable tag: 1.0.2
    99
    1010WCK Custom Fields Creator - easily create custom meta boxes for WordPress. It supports normal custom fields and custom fields repeater groups.
     
    1414WCK Custom Fields Creator offers an UI for setting up custom meta boxes for your posts, pages or custom post types. Uses standard custom fields to store data.
    1515
    16 == Features ==
     16= Features =
    1717
    1818* Easy to create custom fields for any post type.
     
    8383== Changelog ==
    8484
     85= 1.0.2 =
     86* Major changes to the upload field. Now it stores the attachments ID instead of the url of the file. IMPORTANT: in the backend backwards compatibility has been taken care of but on the frontend the responsibility is yours.
     87* Added possibility to choose whether to attach or not the upload to the post.
     88* Various UI improvements.
     89* Fixed bug when CFC box had no title.
     90* Fixed label bug on edit form.
     91* Fixed bug that broke sorting after updating an element.
     92* Other small bug fixes and improvements.
     93
     94
    8595= 1.0.1 =
    8696* Added link to website and documentation in readme.
  • custom-fields-creator/trunk/wck-cfc.php

    r517836 r559854  
    44Description: Creates Custom Meta Box Fields for WordPress. It supports repeater fields and uses AJAX to handle data.
    55Author: Reflection Media, Madalin Ungureanu
    6 Version: 1.0.1
     6Version: 1.0.2
    77Author URI: http://www.reflectionmedia.ro
    88
     
    156156        array( 'type' => 'select', 'title' => 'Required', 'options' => array( 'false', 'true' ), 'default' => 'false', 'description' => 'Whether the field is required or not' ),
    157157        array( 'type' => 'text', 'title' => 'Default Value', 'description' => 'Default value of the field. For Checkboxes if there are multiple values separete them with a ","' ),
    158         array( 'type' => 'text', 'title' => 'Options', 'description' => 'Options for field types "select", "checkbox" and "radio". For multiple options separete them with a ","' )
     158        array( 'type' => 'text', 'title' => 'Options', 'description' => 'Options for field types "select", "checkbox" and "radio". For multiple options separete them with a ","' ),
     159        array( 'type' => 'radio', 'title' => 'Attach upload to post', 'description' => 'Whether or not the uploads should be attached to the post', 'options' => array( 'yes', 'no' ) )
    159160    ); 
    160161   
     
    201202}
    202203
     204/* attach to post show or hide based on field typr */
     205add_filter( "wck_before_update_form_wck_cfc_fields_element_6", 'wck_cfc_update_form_attach_wrapper_start', 10, 3 );
     206function wck_cfc_update_form_attach_wrapper_start( $form, $i, $value ){
     207    if( $GLOBALS['wck_cfc_update_field_type'] != 'upload' )
     208        $form .= '<div class="hide-attach" style="display:none;">';
     209    return $form;
     210}
     211
     212add_filter( "wck_after_update_form_wck_cfc_fields_element_6", 'wck_cfc_update_form_attach_wrapper_end', 10, 3 );
     213function wck_cfc_update_form_attach_wrapper_end( $form, $i, $value ){
     214    if( $GLOBALS['wck_cfc_update_field_type'] != 'upload' )
     215        $form .= '</div>';
     216    return $form;
     217}
     218
    203219
    204220/* display or show options based on the field type */
     
    219235function wck_cfc_display_label_wrapper_options_end( $form, $i, $value ){
    220236    if( !in_array( $GLOBALS['wck_cfc_field_type'], array( 'select', 'checkbox', 'radio' ) ) )
     237        $form .= '</div>';
     238    return $form;
     239}
     240
     241/* Show or hide attach field in list view */
     242add_filter( "wck_before_listed_wck_cfc_fields_element_6", 'wck_cfc_display_label_wrapper_attach_start', 10, 3 );
     243function wck_cfc_display_label_wrapper_attach_start( $form, $i, $value ){
     244    if( $GLOBALS['wck_cfc_field_type'] != 'upload' )
     245        $form .= '<div style="display:none;">';
     246    return $form;
     247}
     248
     249add_filter( "wck_after_listed_wck_cfc_fields_element_6", 'wck_cfc_display_label_wrapper_attach_end', 10, 3 );
     250function wck_cfc_display_label_wrapper_attach_end( $form, $i, $value ){
     251    if( $GLOBALS['wck_cfc_field_type'] != 'upload' )
    221252        $form .= '</div>';
    222253    return $form;
     
    254285       
    255286        $box_title = get_the_title( $meta_box->ID );
     287        /* treat case where the post has no title */
     288        if( empty( $box_title ) )
     289            $box_title = '(no title)';
    256290       
    257291        $fields_array = array();
     
    265299                if( !empty( $wck_cfc_field['default-value'] ) )
    266300                    $fields_inner_array['default'] = $wck_cfc_field['default-value'];
    267                 if( !empty( $wck_cfc_field['options'] ) )
     301                if( !empty( $wck_cfc_field['options'] ) ){
    268302                    $fields_inner_array['options'] = explode( ',', $wck_cfc_field['options'] );
     303                   
     304                    foreach( $fields_inner_array['options'] as  $key => $value ){
     305                        $fields_inner_array['options'][$key] = trim( $value );
     306                    }                   
     307                   
     308                }
     309                if( !empty( $wck_cfc_field['attach-upload-to-post'] ) )
     310                    $fields_inner_array['attach_to_post'] = $wck_cfc_field['attach-upload-to-post'] == 'yes' ? true : false;
    269311                   
    270312                $fields_array[] = $fields_inner_array;
     
    274316        if( !empty( $wck_cfc_args ) ){
    275317            foreach( $wck_cfc_args as $wck_cfc_arg ){
     318           
     319                /* metabox_id must be different from meta_name */
     320                $metabox_id = sanitize_title_with_dashes( remove_accents ( $box_title ) );             
     321                if( $wck_cfc_arg['meta-name'] == $metabox_id )
     322                    $metabox_id = 'wck-'. $metabox_id;
     323               
    276324                $box_args = array(
    277                                 'metabox_id' => sanitize_title_with_dashes( remove_accents ( $box_title ) ),
     325                                'metabox_id' => $metabox_id,
    278326                                'metabox_title' => $box_title,
    279327                                'post_type' => $wck_cfc_arg['post-type'],
  • custom-fields-creator/trunk/wordpress-creation-kit-api/wordpress-creation-kit.css

    r512346 r559854  
     1.wck-post-box{
     2    visibility:hidden;
     3    height:0;
     4    overflow:auto;
     5}
     6
    17.mb-list-entry-fields li{
    28    margin-bottom:15px;
     
    1016
    1117.field-label{
    12     width:190px;
     18    /* width:190px; */
    1319    float:left;
    1420    min-height:30px;
     
    2733
    2834.mb-right-column label{
    29     padding:0 6px 0 3px;
     35    padding:0 6px 0 0;
     36}
     37
     38.mb-right-column input[type="checkbox"], .mb-right-column input[type="radio"]{
     39    margin-right:3px;
    3040}
    3141
     
    5060}
    5161
     62
    5263.wck-edit, .wck-delete, .wck-number{
    5364    width:50px;
     
    5768td.wck-number{
    5869    cursor:move;
     70}
     71
     72.wck-content > ul{
     73    margin:0;
    5974}
    6075
     
    6782}
    6883
    69 .mbdelete{
     84.mbdelete, .wck-remove-upload{
    7085    color:#BC0B0B;
     86    cursor:pointer;
    7187}
    7288
    73 .mbdelete:hover{
    74     color:#FF0000;
     89.mbdelete:hover, .wck-remove-upload:hover{
     90    color:#FF0000; 
    7591}
    7692
     
    121137}
    122138
     139/* upload field */
     140.upload-field-details{
     141    display:inline-block;
     142    vertical-align:middle;
     143    min-height:24px;
     144    padding:2px 0;
     145}
     146
     147.upload-field-details p{
     148    margin:2px 0 0;
     149}
     150
     151.upload-field-details img{
     152    margin:0 5px;
     153    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
     154}
     155
     156.upload-field-details > *{
     157    float:left;
     158}
     159
     160.upload-field-details span{
     161    display:block;
     162}
     163
     164.upload-field-details .file-name{
     165    font-weight:bold;
     166    color:#21759B;
     167}
     168
     169
    123170/* Settings page. */
    124171.side .form-table th {
  • custom-fields-creator/trunk/wordpress-creation-kit-api/wordpress-creation-kit.js

    r512346 r559854  
    11/* Add width to elements at startup */
    22jQuery(function(){
    3     jQuery('.mb-table-container tbody td').css('width', function(){ return jQuery(this).width() });
    4    
    5    
    6    
     3    jQuery('.mb-table-container tbody td').css('width', function(){ return jQuery(this).width() });
    74});
     5
     6/* Add width to labels if the post box is closed at load */
     7jQuery(function(){
     8
     9    /* Callback version  */
     10    /* postboxes.pbshow = function(box){       
     11        jQuery('strong, .field-label',  jQuery('#'+box)).css( 'width', 'auto' );       
     12    } */
     13   
     14    jQuery( '.wck-post-box .hndle' ).click( function(){     
     15        jQuery('strong, .field-label',  jQuery(this).parent() ).css( 'width', 'auto' );     
     16    })
     17   
     18});
     19
     20
     21
    822
    923/* add reccord to the meta */
     
    5468                   
    5569                    jQuery('#container_'+value).replaceWith(response);
     70                   
     71                    /* set width of strong label */
     72                    wck_set_to_widest('strong', '#container_'+value );
    5673                   
    5774                    jQuery('.mb-table-container tbody td').css('width', function(){ return jQuery(this).width() });
     
    6582                        else
    6683                            jQuery(this).val('');                   
    67                     });             
     84                    });
     85
     86                    jQuery('#'+value+' .upload-field-details').each(function(){
     87                        jQuery(this).html('<p><span class="file-name"></span><span class="file-type"></span></p>');
     88                    });
     89                   
    6890                    jQuery('#'+value).parent().css('opacity','1'); 
    6991                   
     
    100122                    jQuery('#container_'+value).replaceWith(response);
    101123                   
     124                    /* set width of strong label */
     125                    wck_set_to_widest('strong', '#container_'+value );
     126                   
    102127                    jQuery('.mb-table-container tbody td').css('width', function(){ return jQuery(this).width() });
    103128                   
     
    145170                    jQuery.post( ajaxurl ,  { action:"wck_refresh_list"+value, meta:value, id:id}, function(response) {
    146171                            jQuery('#container_'+value).replaceWith(response);
     172                           
     173                            /* set width of strong label */
     174                            wck_set_to_widest('strong', '#container_'+value );
    147175                           
    148176                            jQuery('.mb-table-container tbody td').css('width', function(){ return jQuery(this).width() });
     
    177205                //jQuery('#container_'+value+' #element_'+element_id).append(response);
    178206                jQuery(response).insertAfter('#container_'+value+' #element_'+element_id);
     207               
     208                /* set width of field-label */
     209                wck_set_to_widest('.field-label', '#update_container_' + value + '_' + element_id );
     210               
    179211                jQuery('#container_'+value).parent().css('opacity','1');
    180212                jQuery('#mb-ajax-loading').remove();
     
    234266                    jQuery('#container_'+value+' #element_'+element_id).replaceWith(response);
    235267                   
     268                    /* set width of strong label */
     269                    wck_set_to_widest('strong', '#container_'+value+' #element_'+element_id );
     270                   
    236271                    jQuery('.mb-table-container tbody td').css('width', function(){ return jQuery(this).width() });
    237272                   
     
    256291        jQuery('html,body').animate({scrollTop: jQuery("#"+id).offset().top - 28},'slow');
    257292}
     293
     294/* Remove uploaded file */
     295jQuery(function(){
     296    jQuery('.wck-remove-upload').live('click', function(e){     
     297        jQuery(this).parent().parent().parent().children('.mb-field').val("");
     298        jQuery(this).parent().parent('.upload-field-details').html('<p><span class="file-name"></span><span class="file-type"></span></p>');
     299    });
     300});
     301
     302/* Set width for listing "label" equal to the widest */
     303jQuery( function(){
     304    jQuery('.mb-table-container').each(function(){
     305        wck_set_to_widest( 'strong', jQuery(this) );       
     306    });
     307   
     308    jQuery('.mb-list-entry-fields').each(function(){
     309        wck_set_to_widest( '.field-label', jQuery(this) );     
     310    });
     311   
     312    jQuery('.wck-post-box').css( {visibility: 'visible', height: 'auto'} );
     313});
     314
     315function wck_set_to_widest( element, parent ){
     316    if( jQuery( element, parent).length != 0 ){     
     317        var widest = null;
     318        jQuery( element, parent).each(function() {
     319          if (widest == null)
     320            widest = jQuery(this);
     321          else
     322          if ( jQuery(this).width() > widest.width() )
     323            widest = jQuery(this);
     324        });
     325       
     326        jQuery(element, parent).css( {display: 'inline-block', width: widest.width(), paddingRight: '5px'} );
     327    }
     328    else return;
     329}
     330
     331/* jQuery('.mb-table-container').ready(function(){     
     332        jQuery('.mb-table-container strong').css( {display: 'inline-block', width: 200, paddingRight: '5px'} );
     333}); */
  • custom-fields-creator/trunk/wordpress-creation-kit-api/wordpress-creation-kit.php

    r512346 r559854  
    113113       
    114114        if( $this->args['context'] == 'post_meta' ){
    115             if( $this->args['post_id'] == '' && $this->args['page_template'] == '' )
     115            if( $this->args['post_id'] == '' && $this->args['page_template'] == '' ){
    116116                add_meta_box($this->args['metabox_id'], $this->args['metabox_title'], array( &$this, 'wck_content' ), $this->args['post_type'], 'normal', 'low',  array( 'meta_name' => $this->args['meta_name'], 'meta_array' => $this->args['meta_array']) );
     117                /* add class to meta box */
     118                add_filter( "postbox_classes_".$this->args['post_type']."_".$this->args['metabox_id'], array( &$this, 'wck_add_metabox_classes' ) );
     119            }
    117120            else{
    118121                $post_id = $_GET['post'] ? $_GET['post'] : $_POST['post_ID'] ;
     
    122125                    if( $this->args['post_id'] == $post_id && $template_file == $this->args['page_template'] )
    123126                        add_meta_box($this->args['metabox_id'], $this->args['metabox_title'], array( &$this, 'wck_content' ), 'page', 'normal', 'low',  array( 'meta_name' => $this->args['meta_name'], 'meta_array' => $this->args['meta_array'] ) );
     127                       
     128                    /* add class to meta box */
     129                    add_filter( "postbox_classes_page_".$this->args['metabox_id'], array( &$this, 'wck_add_metabox_classes' ) );
    124130                }
    125131                else{
     
    129135                            $post_type = get_post_type( $post_id );
    130136                            add_meta_box($this->args['metabox_id'], $this->args['metabox_title'], array( &$this, 'wck_content' ), $post_type, 'normal', 'low',  array( 'meta_name' => $this->args['meta_name'], 'meta_array' => $this->args['meta_array'] ) );
     137                            /* add class to meta box */
     138                            add_filter( "postbox_classes_".$post_type."_".$this->args['metabox_id'], array( &$this, 'wck_add_metabox_classes' ) );
    131139                        }
    132140                    }
     
    134142                    if(  $this->args['page_template'] != '' ){
    135143                        $template_file = get_post_meta($post_id,'_wp_page_template',TRUE); 
    136                         if ( $template_file == $this->args['page_template'] )
     144                        if ( $template_file == $this->args['page_template'] ){
    137145                            add_meta_box($this->args['metabox_id'], $this->args['metabox_title'], array( &$this, 'wck_content' ), 'page', 'normal', 'low',  array( 'meta_name' => $this->args['meta_name'], 'meta_array' => $this->args['meta_array']) );
     146                            /* add class to meta box */
     147                            add_filter( "postbox_classes_page_".$this->args['metabox_id'], array( &$this, 'wck_add_metabox_classes' ) );
     148                        }
    138149                    }           
    139150                   
     
    144155        else if( $this->args['context'] == 'option' ){         
    145156            add_meta_box($this->args['metabox_id'], $this->args['metabox_title'], array( &$this, 'wck_content' ), $wck_pages_hooknames[$this->args['post_type']], 'normal', 'low',  array( 'meta_name' => $this->args['meta_name'], 'meta_array' => $this->args['meta_array']) );
     157            /* add class to meta box */
     158            add_filter( "postbox_classes_".$wck_pages_hooknames[$this->args['post_type']]."_".$this->args['metabox_id'], array( &$this, 'wck_add_metabox_classes' ) );
    146159        }
    147160    }   
     161   
     162    /* Function used to add classes to the wck meta boxes */
     163    function wck_add_metabox_classes( $classes ){
     164        array_push($classes,'wck-post-box');
     165        return $classes;
     166    }
    148167
    149168    function wck_content($post, $metabox){     
     
    198217       
    199218        if($details['type'] == 'text'){
    200             $element .= '<input type="text" name="'. esc_attr( sanitize_title_with_dashes( remove_accents( $details['title'] ) ) ) .'" id="'. esc_attr( sanitize_title_with_dashes( remove_accents( $details['title'] ) ) ) .'" value="'. $value .'" class="mb-text-input mb-field"/>';
     219            $element .= '<input type="text" name="'. esc_attr( sanitize_title_with_dashes( remove_accents( $details['title'] ) ) ) .'" id="'. esc_attr( sanitize_title_with_dashes( remove_accents( $details['title'] ) ) ) .'" value="'. esc_attr( $value ) .'" class="mb-text-input mb-field"/>';
    201220        }
    202221       
    203222        if($details['type'] == 'textarea'){
    204             $element .= '<textarea name="'. esc_attr( sanitize_title_with_dashes( remove_accents( $details['title'] ) ) ) .'" id="'. esc_attr( sanitize_title_with_dashes( remove_accents( $details['title'] ) ) ) .'" style="vertical-align:top;" class="mb-textarea mb-field">'. $value .'</textarea>';
     223            $element .= '<textarea name="'. esc_attr( sanitize_title_with_dashes( remove_accents( $details['title'] ) ) ) .'" id="'. esc_attr( sanitize_title_with_dashes( remove_accents( $details['title'] ) ) ) .'" style="vertical-align:top;" class="mb-textarea mb-field">'. esc_html( $value ) .'</textarea>';
    205224        }
    206225       
     
    213232            if( !empty( $details['options'] ) ){
    214233                    foreach( $details['options'] as $option ){
    215                         $element .= '<option value="'. $option .'"  '. selected( $option, $value, false ) .' >'. $option .'</option>';
     234                        $element .= '<option value="'. esc_attr( $option ) .'"  '. selected( $option, $value, false ) .' >'. esc_html( $option ) .'</option>';
    216235                    }
    217236            }               
     
    222241        if($details['type'] == 'checkbox'){
    223242           
     243            if( !empty( $details['options'] ) ){                   
     244                    foreach( $details['options'] as $option ){
     245                        $found = false;                     
     246                       
     247                        $values = explode( ', ', $value );                     
     248                        if ( in_array( $option, $values ) )
     249                            $found = true;
     250                           
     251                        $element .= '<div><label><input type="checkbox" name="'. esc_attr( sanitize_title_with_dashes( remove_accents( $details['title'] ) ) ) .'" id="'. esc_attr( sanitize_title_with_dashes( remove_accents( $details['title'] . '_' . $option ) ) ) .'" value="'. esc_attr( $option ) .'"  '. checked( $found, true, false ) .'class="mb-checkbox mb-field" />'. esc_html( $option ) .'</label></div>' ;
     252                    }
     253            }
     254           
     255        }
     256       
     257        if($details['type'] == 'radio'){
     258           
    224259            if( !empty( $details['options'] ) ){
    225                     foreach( $details['options'] as $option ){
    226                         $found = false;
    227                        
    228                         if ( strpos($value, $option) !== false )
    229                             $found = true;
    230                         $element .= '<div><input type="checkbox" name="'. esc_attr( sanitize_title_with_dashes( remove_accents( $details['title'] ) ) ) .'" id="'. esc_attr( sanitize_title_with_dashes( remove_accents( $details['title'] . '_' . $option ) ) ) .'" value="'. $option .'"  '. checked( $found, true, false ) .'class="mb-checkbox mb-field" /><label for="'. esc_attr( sanitize_title_with_dashes( remove_accents( $details['title'] . '_' .$option ) ) ) .'">'. $option .'</label></div>' ;
    231                     }
    232             }
    233            
    234         }
    235        
    236         if($details['type'] == 'radio'){
    237            
    238             if( !empty( $details['options'] ) ){
    239                     foreach( $details['options'] as $option ){
    240                         $found = false;
    241                        
    242                         if ( strpos($value, $option) !== false )
    243                             $found = true;
    244                         $element .= '<div><input type="radio" name="'. esc_attr( sanitize_title_with_dashes( remove_accents( $details['title'] ) ) ) .'" id="'. esc_attr( sanitize_title_with_dashes( remove_accents( $details['title'] . '_' . $option ) ) ) .'" value="'. $option .'"  '. checked( $found, true, false ) .'class="mb-radio mb-field" /><label for="'. esc_attr( sanitize_title_with_dashes( remove_accents( $details['title'] . '_' .$option ) ) ) .'">'. $option .'</label></div>';
    245                     }
     260                foreach( $details['options'] as $option ){
     261                    $found = false;
     262                   
     263                    $values = explode( ', ', $value );                     
     264                    if ( in_array( $option, $values ) )
     265                        $found = true;
     266                           
     267                    $element .= '<div><label><input type="radio" name="'. esc_attr( sanitize_title_with_dashes( remove_accents( $details['title'] ) ) ) .'" id="'. esc_attr( sanitize_title_with_dashes( remove_accents( $details['title'] . '_' . $option ) ) ) .'" value="'. esc_attr( $option ) .'"  '. checked( $found, true, false ) .'class="mb-radio mb-field" />'. esc_html( $option ) .'</label></div>';
     268                }
    246269            }
    247270           
     
    250273       
    251274        if($details['type'] == 'upload'){
    252             $element .= '<input id="'. esc_attr( str_replace( '-', '_', sanitize_title_with_dashes( remove_accents( $meta . $details['title'] ) ) ) ) .'" type="text" size="36" name="'. esc_attr( sanitize_title_with_dashes( remove_accents ( $details['title'] ) ) ) .'" value="'. $value .'" class="mb-text-input mb-field"/>';
    253             $element .= '<a id="upload_'. esc_attr(sanitize_title_with_dashes( remove_accents( $details['title'] ) )) .'_button" class="button" onclick="tb_show(\'\', \'media-upload.php?type=file&amp;mb_type='. $var_prefix  . esc_js(strtolower( str_replace( '-', '_', sanitize_title_with_dashes( remove_accents( $meta . $details['title'] ) ) ) ) ).'&amp;TB_iframe=true\');">Upload '. $details['title'] .' </a>';
     275            /* define id's for input and info div */
     276            $upload_input_id = str_replace( '-', '_', sanitize_title_with_dashes( remove_accents( $meta . $details['title'] ) ) );
     277            $upload_info_div_id = str_replace( '-', '_', sanitize_title_with_dashes( remove_accents( $meta .'_info_container_'. $details['title'] ) ) );
     278           
     279            /* hidden input that will hold the attachment id */
     280            $element .= '<input id="'. esc_attr( $upload_input_id ) .'" type="hidden" size="36" name="'. esc_attr( sanitize_title_with_dashes( remove_accents ( $details['title'] ) ) ) .'" value="'. $value .'" class="mb-text-input mb-field"/>';
     281           
     282            /* container for the image preview (or file ico) and name and file type */
     283            if( !empty ( $value ) ){
     284                $file_src = wp_get_attachment_url($value);
     285                $thumbnail = wp_get_attachment_image( $value, array( 80, 60 ), true );
     286                $file_name = get_the_title( $value );
     287               
     288                if ( preg_match( '/^.*?\.(\w+)$/', get_attached_file( $value ), $matches ) )
     289                    $file_type = esc_html( strtoupper( $matches[1] ) );
     290                else
     291                    $file_type = strtoupper( str_replace( 'image/', '', get_post_mime_type( $value ) ) );
     292            }
     293            $element .= '<div id="'. esc_attr( $upload_info_div_id ) .'" class="upload-field-details">'. $thumbnail .'<p><span class="file-name">'. $file_name .'</span><span class="file-type">'. $file_type . '</span>';
     294            if( !empty ( $value ) )
     295                $element .= '<span class="wck-remove-upload">'.__( 'Remove', 'wck' ).'</span>';
     296            $element .= '</p></div>';
     297            /* the upload link. we send through get the hidden input id, details div id and meta name */
     298            if( $details['attach_to_post'] )
     299                $attach_to_post = 'post_id='. get_the_id() .'&amp;';
     300            else
     301                $attach_to_post = '';
     302               
     303            $element .= '<a id="upload_'. esc_attr(sanitize_title_with_dashes( remove_accents( $details['title'] ) )) .'_button" class="button" onclick="tb_show(\'\', \'media-upload.php?'.$attach_to_post.'type=file&amp;mb_type='. $var_prefix  . esc_js(strtolower( $upload_input_id ) ).'&amp;mb_info_div='.$var_prefix  . esc_js(strtolower( $upload_info_div_id ) ).'&amp;meta_name='.$meta.'&amp;TB_iframe=1\');">Upload '. $details['title'] .' </a>';
     304           
     305            /* add js global var for the hidden input, and info container div */
    254306            $element .= '<script type="text/javascript">';             
    255                 $element .= 'window.'. $var_prefix . strtolower( str_replace( '-', '_', sanitize_title_with_dashes( remove_accents( $meta . $details['title'] ) ) ) ) .' = jQuery(\''.$edit_class.'#'. str_replace( '-', '_', sanitize_title_with_dashes( remove_accents( $meta . $details['title'] ) ) ).'\');';
     307                $element .= 'window.'. $var_prefix . strtolower( $upload_input_id ) .' = jQuery(\''.$edit_class.'#'. $upload_input_id.'\');';
     308                $element .= 'window.'. $var_prefix . strtolower( $upload_info_div_id ) .' = jQuery(\''.$edit_class.'#'. $upload_info_div_id.'\');';
    256309            $element .= '</script>';
    257310        }       
     
    358411           
    359412            $form .= '</ul>';
    360         }
    361         //var_dump($$fields);
     413        }       
    362414        $form .= '</td></tr>';
    363 
    364415       
    365416        return $form;
     
    389440        if( !$this->args['sortable'] ) $list .= ' not-sortable';
    390441       
    391         $list .= '" post="'.esc_attr($id).'">';     
     442        $list .= '" post="'.esc_attr($id).'" onload="alert(\'aaaaaaaaa\')">';       
    392443       
    393444       
    394445        if($results != null){
    395             $list .= '<thead><tr><th class="wck-number">#</th><th>Content</th><th class="wck-edit">Edit</th><th class="wck-delete">Delete</th></tr></thead>';
     446            $list .= '<thead><tr><th class="wck-number">#</th><th class="wck-content">Content</th><th class="wck-edit">Edit</th><th class="wck-delete">Delete</th></tr></thead>';
    396447            $i=0;
    397448            foreach ($results as $result){         
     
    414465        $list .= '<tr id="element_'.$element_id.'">';
    415466        $list .= '<td style="text-align:center;vertical-align:middle;" class="wck-number">'. $entry_nr .'</td>';
    416         $list .= '<td><ul>';
     467        $list .= '<td class="wck-content"><ul>';
    417468       
    418469        $j = 0;             
     
    420471        foreach( $fields as $field ){
    421472            $details = $field;
     473           
    422474            $value = $results[$element_id][sanitize_title_with_dashes( remove_accents( $details['title'] ) )];
    423             $display_value = '<pre>'.htmlspecialchars( $results[$element_id][sanitize_title_with_dashes( remove_accents( $details['title'] ) )] ) . '</pre>';
     475           
     476            /* for the upload field display it differently */
     477            if( $details['type'] == 'upload' && !empty ( $value ) && is_numeric( $value ) ){               
     478                $file_src = wp_get_attachment_url($value);
     479                $thumbnail = wp_get_attachment_image( $value, array( 80, 60 ), true );
     480                $file_name = get_the_title( $value );
     481               
     482                if ( preg_match( '/^.*?\.(\w+)$/', get_attached_file( $value ), $matches ) )
     483                    $file_type = esc_html( strtoupper( $matches[1] ) );
     484                else
     485                    $file_type = strtoupper( str_replace( 'image/', '', get_post_mime_type( $value ) ) );
     486               
     487                $display_value = '<div class="upload-field-details">'. $thumbnail .'<p><span class="file-name">'. $file_name .'</span><span class="file-type">'. $file_type . '</span></p></div>';
     488            }
     489            else{               
     490               
     491                $display_value = '<pre>'.htmlspecialchars( $value ) . '</pre>';
     492            }
    424493           
    425494            $list = apply_filters( "wck_before_listed_{$meta}_element_{$j}", $list, $element_id, $value );     
    426495           
    427             $list .= '<li class="row-'. esc_attr( sanitize_title_with_dashes( remove_accents( $details['title'] ) ) ) .'"><strong>'.$details['title'].': </strong>'.$display_value.' </li>';                           
     496            $list .= '<li class="row-'. esc_attr( sanitize_title_with_dashes( remove_accents( $details['title'] ) ) ) .'"><strong>'.$details['title'].': </strong>'.$display_value.' </li>';       
    428497           
    429498            $list = apply_filters( "wck_after_listed_{$meta}_element_{$j}", $list, $element_id, $value );
     
    459528                wp_enqueue_script( 'jquery-ui-droppable' );
    460529                wp_enqueue_script( 'jquery-ui-sortable' );
     530                wp_enqueue_script( 'thickbox' );
     531                wp_enqueue_style( 'thickbox' );
    461532                wp_enqueue_script('wordpress-creation-kit', plugins_url('/wordpress-creation-kit.js', __FILE__), array('jquery', 'jquery-ui-draggable', 'jquery-ui-droppable', 'jquery-ui-sortable' ) );
    462533                wp_register_style('wordpress-creation-kit-css', plugins_url('/wordpress-creation-kit.css', __FILE__));
     
    725796    /* modify Insert into post button */   
    726797    function wck_media_upload_popup_head()
    727     {
    728         if( ( isset( $_GET["mb_type"] ) ) )
    729         {
    730             ?>
    731             <style type="text/css">
    732                 #media-upload-header #sidemenu li#tab-type_url,
    733                 #media-upload-header #sidemenu li#tab-gallery {
    734                     display: none;
    735                 }
    736                
    737                 #media-items tr.url,
    738                 #media-items tr.align,
    739                 #media-items tr.image_alt,
    740                 #media-items tr.image-size,
    741                 #media-items tr.post_excerpt,
    742                 #media-items tr.post_content,
    743                 #media-items tr.image_alt p,
    744                 #media-items table thead input.button,
    745                 #media-items table thead img.imgedit-wait-spin,
    746                 #media-items tr.submit a.wp-post-thumbnail {
    747                     display: none;
    748                 }
    749 
    750                 .media-item table thead img {
    751                     border: #DFDFDF solid 1px;
    752                     margin-right: 10px;
    753                 }
    754 
    755             </style>
    756             <script type="text/javascript">
    757             (function($){
    758            
    759                 $(document).ready(function(){
    760                
    761                     $('#media-items').bind('DOMNodeInserted',function(){
    762                         $('input[value="Insert into Post"]').each(function(){
    763                             $(this).attr('value','<?php _e("Select File")?>');
     798    {   
     799        if( $this->args['meta_name'] == $_GET["meta_name"] ){           
     800            if( ( isset( $_GET["mb_type"] ) ) ){
     801                ?>
     802                <style type="text/css">
     803                    #media-upload-header #sidemenu li#tab-type_url,
     804                    #media-upload-header #sidemenu li#tab-gallery {
     805                        display: none;
     806                    }
     807                   
     808                    #media-items tr.url,
     809                    #media-items tr.align,
     810                    #media-items tr.image_alt,
     811                    #media-items tr.image-size,
     812                    #media-items tr.post_excerpt,
     813                    #media-items tr.post_content,
     814                    #media-items tr.image_alt p,
     815                    #media-items table thead input.button,
     816                    #media-items table thead img.imgedit-wait-spin,
     817                    #media-items tr.submit a.wp-post-thumbnail {
     818                        display: none;
     819                    }
     820
     821                    .media-item table thead img {
     822                        border: #DFDFDF solid 1px;
     823                        margin-right: 10px;
     824                    }
     825
     826                </style>
     827                <script type="text/javascript">
     828                (function($){
     829               
     830                    $(document).ready(function(){
     831                   
     832                        $('#media-items').bind('DOMNodeInserted',function(){
     833                            $('input[value="Insert into Post"]').each(function(){
     834                                $(this).attr('value','<?php _e("Select File")?>');
     835                            });
     836                        }).trigger('DOMNodeInserted');
     837                       
     838                        $('form#filter').each(function(){
     839                           
     840                            $(this).append('<input type="hidden" name="mb_type" value="<?php echo $_GET['mb_type']; ?>" />');
     841                            $(this).append('<input type="hidden" name="mb_info_div" value="<?php echo $_GET['mb_info_div']; ?>" />');
     842                           
    764843                        });
    765                     }).trigger('DOMNodeInserted');
    766                    
    767                     $('form#filter').each(function(){
    768                        
    769                         $(this).append('<input type="hidden" name="mb_type" value="<?php echo $_GET['mb_type']; ?>" />');
    770                        
    771844                    });
    772                 });
    773                            
    774             })(jQuery);
    775             </script>
    776             <?php
    777         }
    778     }
    779 
    780     /* custom functionality for upload video */
     845                               
     846                })(jQuery);
     847                </script>
     848                <?php
     849            }
     850        }
     851    }
     852
     853    /* custom functionality for upload button */
    781854
    782855    function wck_media_send_to_editor($html, $id)
     
    787860        {
    788861            $file_src = wp_get_attachment_url($id);
     862            $thumbnail = wp_get_attachment_image( $id, array( 80, 60 ), true );
     863            $file_name = get_the_title( $id );
     864           
     865            if ( preg_match( '/^.*?\.(\w+)$/', get_attached_file( $id ), $matches ) )
     866                $file_type = esc_html( strtoupper( $matches[1] ) );
     867            else
     868                $file_type = strtoupper( str_replace( 'image/', '', get_post_mime_type( $id ) ) );
    789869       
    790870            ?>
    791871            <script type="text/javascript">             
    792872               
    793                 self.parent.window. <?php echo $arr_postinfo["mb_type"];?> .val('<?php echo $file_src; ?>');
     873                self.parent.window. <?php echo $arr_postinfo["mb_type"];?> .val('<?php echo $id; ?>');
     874                self.parent.window. <?php echo $arr_postinfo["mb_info_div"];?> .html('<?php echo $thumbnail ?><p><span class="file-name"><?php echo $file_name; ?></span><span class="file-type"><?php echo $file_type; ?></span><span class="wck-remove-upload"><?php _e( 'Remove', 'wck' )?></span></p>');
    794875               
    795876                self.parent.tb_remove();
Note: See TracChangeset for help on using the changeset viewer.