Changeset 559854
- Timestamp:
- 06/18/2012 12:14:58 PM (14 years ago)
- Location:
- custom-fields-creator/trunk
- Files:
-
- 7 edited
-
css/wck-cfc.css (modified) (1 diff)
-
js/wck-cfc.js (modified) (2 diffs)
-
readme.txt (modified) (3 diffs)
-
wck-cfc.php (modified) (7 diffs)
-
wordpress-creation-kit-api/wordpress-creation-kit.css (modified) (7 diffs)
-
wordpress-creation-kit-api/wordpress-creation-kit.js (modified) (8 diffs)
-
wordpress-creation-kit-api/wordpress-creation-kit.php (modified) (16 diffs)
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{ 2 2 display:none; 3 3 } -
custom-fields-creator/trunk/js/wck-cfc.js
r512346 r559854 8 8 else{ 9 9 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(); 10 17 } 11 18 }); … … 19 26 jQuery( '.hide-options', jQuery(this).parent().parent().parent() ).hide(); 20 27 } 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 } 21 35 }); 22 36 }); -
custom-fields-creator/trunk/readme.txt
r517828 r559854 5 5 Tags: custom field, custom fields, custom fields creator, meta box, meta boxes, repeater fields, post meta, repeater 6 6 Requires at least: 3.1 7 Tested up to: 3. 3.18 Stable tag: 1.0. 17 Tested up to: 3.4 8 Stable tag: 1.0.2 9 9 10 10 WCK Custom Fields Creator - easily create custom meta boxes for WordPress. It supports normal custom fields and custom fields repeater groups. … … 14 14 WCK 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. 15 15 16 = = Features ==16 = Features = 17 17 18 18 * Easy to create custom fields for any post type. … … 83 83 == Changelog == 84 84 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 85 95 = 1.0.1 = 86 96 * Added link to website and documentation in readme. -
custom-fields-creator/trunk/wck-cfc.php
r517836 r559854 4 4 Description: Creates Custom Meta Box Fields for WordPress. It supports repeater fields and uses AJAX to handle data. 5 5 Author: Reflection Media, Madalin Ungureanu 6 Version: 1.0. 16 Version: 1.0.2 7 7 Author URI: http://www.reflectionmedia.ro 8 8 … … 156 156 array( 'type' => 'select', 'title' => 'Required', 'options' => array( 'false', 'true' ), 'default' => 'false', 'description' => 'Whether the field is required or not' ), 157 157 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' ) ) 159 160 ); 160 161 … … 201 202 } 202 203 204 /* attach to post show or hide based on field typr */ 205 add_filter( "wck_before_update_form_wck_cfc_fields_element_6", 'wck_cfc_update_form_attach_wrapper_start', 10, 3 ); 206 function 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 212 add_filter( "wck_after_update_form_wck_cfc_fields_element_6", 'wck_cfc_update_form_attach_wrapper_end', 10, 3 ); 213 function 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 203 219 204 220 /* display or show options based on the field type */ … … 219 235 function wck_cfc_display_label_wrapper_options_end( $form, $i, $value ){ 220 236 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 */ 242 add_filter( "wck_before_listed_wck_cfc_fields_element_6", 'wck_cfc_display_label_wrapper_attach_start', 10, 3 ); 243 function 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 249 add_filter( "wck_after_listed_wck_cfc_fields_element_6", 'wck_cfc_display_label_wrapper_attach_end', 10, 3 ); 250 function wck_cfc_display_label_wrapper_attach_end( $form, $i, $value ){ 251 if( $GLOBALS['wck_cfc_field_type'] != 'upload' ) 221 252 $form .= '</div>'; 222 253 return $form; … … 254 285 255 286 $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)'; 256 290 257 291 $fields_array = array(); … … 265 299 if( !empty( $wck_cfc_field['default-value'] ) ) 266 300 $fields_inner_array['default'] = $wck_cfc_field['default-value']; 267 if( !empty( $wck_cfc_field['options'] ) ) 301 if( !empty( $wck_cfc_field['options'] ) ){ 268 302 $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; 269 311 270 312 $fields_array[] = $fields_inner_array; … … 274 316 if( !empty( $wck_cfc_args ) ){ 275 317 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 276 324 $box_args = array( 277 'metabox_id' => sanitize_title_with_dashes( remove_accents ( $box_title ) ),325 'metabox_id' => $metabox_id, 278 326 'metabox_title' => $box_title, 279 327 '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 1 7 .mb-list-entry-fields li{ 2 8 margin-bottom:15px; … … 10 16 11 17 .field-label{ 12 width:190px;18 /* width:190px; */ 13 19 float:left; 14 20 min-height:30px; … … 27 33 28 34 .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; 30 40 } 31 41 … … 50 60 } 51 61 62 52 63 .wck-edit, .wck-delete, .wck-number{ 53 64 width:50px; … … 57 68 td.wck-number{ 58 69 cursor:move; 70 } 71 72 .wck-content > ul{ 73 margin:0; 59 74 } 60 75 … … 67 82 } 68 83 69 .mbdelete {84 .mbdelete, .wck-remove-upload{ 70 85 color:#BC0B0B; 86 cursor:pointer; 71 87 } 72 88 73 .mbdelete:hover {74 color:#FF0000; 89 .mbdelete:hover, .wck-remove-upload:hover{ 90 color:#FF0000; 75 91 } 76 92 … … 121 137 } 122 138 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 123 170 /* Settings page. */ 124 171 .side .form-table th { -
custom-fields-creator/trunk/wordpress-creation-kit-api/wordpress-creation-kit.js
r512346 r559854 1 1 /* Add width to elements at startup */ 2 2 jQuery(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() }); 7 4 }); 5 6 /* Add width to labels if the post box is closed at load */ 7 jQuery(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 8 22 9 23 /* add reccord to the meta */ … … 54 68 55 69 jQuery('#container_'+value).replaceWith(response); 70 71 /* set width of strong label */ 72 wck_set_to_widest('strong', '#container_'+value ); 56 73 57 74 jQuery('.mb-table-container tbody td').css('width', function(){ return jQuery(this).width() }); … … 65 82 else 66 83 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 68 90 jQuery('#'+value).parent().css('opacity','1'); 69 91 … … 100 122 jQuery('#container_'+value).replaceWith(response); 101 123 124 /* set width of strong label */ 125 wck_set_to_widest('strong', '#container_'+value ); 126 102 127 jQuery('.mb-table-container tbody td').css('width', function(){ return jQuery(this).width() }); 103 128 … … 145 170 jQuery.post( ajaxurl , { action:"wck_refresh_list"+value, meta:value, id:id}, function(response) { 146 171 jQuery('#container_'+value).replaceWith(response); 172 173 /* set width of strong label */ 174 wck_set_to_widest('strong', '#container_'+value ); 147 175 148 176 jQuery('.mb-table-container tbody td').css('width', function(){ return jQuery(this).width() }); … … 177 205 //jQuery('#container_'+value+' #element_'+element_id).append(response); 178 206 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 179 211 jQuery('#container_'+value).parent().css('opacity','1'); 180 212 jQuery('#mb-ajax-loading').remove(); … … 234 266 jQuery('#container_'+value+' #element_'+element_id).replaceWith(response); 235 267 268 /* set width of strong label */ 269 wck_set_to_widest('strong', '#container_'+value+' #element_'+element_id ); 270 236 271 jQuery('.mb-table-container tbody td').css('width', function(){ return jQuery(this).width() }); 237 272 … … 256 291 jQuery('html,body').animate({scrollTop: jQuery("#"+id).offset().top - 28},'slow'); 257 292 } 293 294 /* Remove uploaded file */ 295 jQuery(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 */ 303 jQuery( 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 315 function 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 113 113 114 114 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'] == '' ){ 116 116 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 } 117 120 else{ 118 121 $post_id = $_GET['post'] ? $_GET['post'] : $_POST['post_ID'] ; … … 122 125 if( $this->args['post_id'] == $post_id && $template_file == $this->args['page_template'] ) 123 126 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' ) ); 124 130 } 125 131 else{ … … 129 135 $post_type = get_post_type( $post_id ); 130 136 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' ) ); 131 139 } 132 140 } … … 134 142 if( $this->args['page_template'] != '' ){ 135 143 $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'] ){ 137 145 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 } 138 149 } 139 150 … … 144 155 else if( $this->args['context'] == 'option' ){ 145 156 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' ) ); 146 159 } 147 160 } 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 } 148 167 149 168 function wck_content($post, $metabox){ … … 198 217 199 218 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"/>'; 201 220 } 202 221 203 222 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>'; 205 224 } 206 225 … … 213 232 if( !empty( $details['options'] ) ){ 214 233 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>'; 216 235 } 217 236 } … … 222 241 if($details['type'] == 'checkbox'){ 223 242 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 224 259 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 } 246 269 } 247 270 … … 250 273 251 274 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&mb_type='. $var_prefix . esc_js(strtolower( str_replace( '-', '_', sanitize_title_with_dashes( remove_accents( $meta . $details['title'] ) ) ) ) ).'&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() .'&'; 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&mb_type='. $var_prefix . esc_js(strtolower( $upload_input_id ) ).'&mb_info_div='.$var_prefix . esc_js(strtolower( $upload_info_div_id ) ).'&meta_name='.$meta.'&TB_iframe=1\');">Upload '. $details['title'] .' </a>'; 304 305 /* add js global var for the hidden input, and info container div */ 254 306 $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.'\');'; 256 309 $element .= '</script>'; 257 310 } … … 358 411 359 412 $form .= '</ul>'; 360 } 361 //var_dump($$fields); 413 } 362 414 $form .= '</td></tr>'; 363 364 415 365 416 return $form; … … 389 440 if( !$this->args['sortable'] ) $list .= ' not-sortable'; 390 441 391 $list .= '" post="'.esc_attr($id).'" >';442 $list .= '" post="'.esc_attr($id).'" onload="alert(\'aaaaaaaaa\')">'; 392 443 393 444 394 445 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>'; 396 447 $i=0; 397 448 foreach ($results as $result){ … … 414 465 $list .= '<tr id="element_'.$element_id.'">'; 415 466 $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>'; 417 468 418 469 $j = 0; … … 420 471 foreach( $fields as $field ){ 421 472 $details = $field; 473 422 474 $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 } 424 493 425 494 $list = apply_filters( "wck_before_listed_{$meta}_element_{$j}", $list, $element_id, $value ); 426 495 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>'; 428 497 429 498 $list = apply_filters( "wck_after_listed_{$meta}_element_{$j}", $list, $element_id, $value ); … … 459 528 wp_enqueue_script( 'jquery-ui-droppable' ); 460 529 wp_enqueue_script( 'jquery-ui-sortable' ); 530 wp_enqueue_script( 'thickbox' ); 531 wp_enqueue_style( 'thickbox' ); 461 532 wp_enqueue_script('wordpress-creation-kit', plugins_url('/wordpress-creation-kit.js', __FILE__), array('jquery', 'jquery-ui-draggable', 'jquery-ui-droppable', 'jquery-ui-sortable' ) ); 462 533 wp_register_style('wordpress-creation-kit-css', plugins_url('/wordpress-creation-kit.css', __FILE__)); … … 725 796 /* modify Insert into post button */ 726 797 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 764 843 }); 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 771 844 }); 772 });773 774 })(jQuery);775 </script>776 <?php777 } 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 */ 781 854 782 855 function wck_media_send_to_editor($html, $id) … … 787 860 { 788 861 $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 ) ) ); 789 869 790 870 ?> 791 871 <script type="text/javascript"> 792 872 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>'); 794 875 795 876 self.parent.tb_remove();
Note: See TracChangeset
for help on using the changeset viewer.