Changeset 331583
- Timestamp:
- 01/12/2011 05:28:30 AM (15 years ago)
- Location:
- mf-plus-wpml/trunk
- Files:
-
- 3 edited
-
Main.php (modified) (3 diffs)
-
README.markdown (modified) (1 diff)
-
readme.txt (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
mf-plus-wpml/trunk/Main.php
r315707 r331583 4 4 Plugin URI: http://magicfields.org 5 5 Description: This plugin provide a integration between magic fields and WPML 6 Version: 1. 06 Version: 1.1 7 7 Author: Magic Fields Team 8 8 Author URI: http://magicfields.org … … 120 120 121 121 if(in_array($writepanel_id."_".$name,$translatables)){ 122 //@todo use the GetMetaID for get the meta_id instead of this query 123 $meta_id = $wpdb->get_var($wpdb->prepare("SELECT id FROM ".MF_TABLE_POST_META." WHERE post_id = {$value->element_id} AND field_name = '{$name}' AND group_count = {$group_index} AND field_count = {$field_index} AND order_id = {$group_index}")); 124 //updating the field value 125 update_post_meta($value->element_id,$name,$value_field); 122 add_post_meta($value->element_id,$name,$value_field); 123 $meta_id = $wpdb->insert_id; 124 125 // Adding the referencie in the magic fields post meta table 126 $wpdb->query("INSERT INTO ". MF_TABLE_POST_META . 127 " (id, field_name, group_count, field_count, post_id,order_id) ". 128 " VALUES ({$meta_id}, '{$name}',{$group_index},{$field_index},{$value->element_id},{$group_index})" 129 ); 130 }else{ 131 $exists = $wpdb->get_var("SELECT count(1) FROM ". MF_TABLE_POST_META . 132 " WHERE field_name = '{$name}' AND group_count = {$group_index} AND field_count = {$field_index} AND post_id = {$value->element_id} AND order_id = {$group_index}"); 133 134 //if don exist we will insert this field with a black value 135 if(!$exists) { 136 add_post_meta($value->element_id,$name,""); 137 $meta_id = $wpdb->insert_id; 138 139 // Adding the referencie in the magic fields post meta table 140 $wpdb->query("INSERT INTO ". MF_TABLE_POST_META . 141 " (id, field_name, group_count, field_count, post_id,order_id) ". 142 " VALUES ({$meta_id}, '{$name}',{$group_index},{$field_index},{$value->element_id},{$group_index})" 143 ); 144 } 126 145 } 127 146 } … … 225 244 ); 226 245 } 246 247 248 add_action('save_post','mfpluswpml_delete_extras',11); 249 function mfpluswpml_delete_extras($postId) { 250 global $flag,$wpdb; 251 if($flag != 1) { 252 return $postId; 253 } 254 255 if ( $the_post = wp_is_post_revision($postId)) { 256 $postId = $the_post; 257 } 258 259 260 if(!empty($_REQUEST['rc-custom-write-panel-verify-key'])) { 261 if (!(current_user_can('edit_posts', $postId) || current_user_can('edit_published_pages', $postId))){ 262 return $postId; 263 } 264 } 265 266 //looking for the translated version of the post 267 $trid = $wpdb->get_var($wpdb->prepare("SELECT trid FROM {$wpdb->prefix}icl_translations WHERE element_id = {$postId} AND (element_type = 'post_post' OR element_type = 'post_page')")); 268 269 //Getting the ID's of the translatable fields 270 $ids = $wpdb->get_results("SELECT element_id FROM {$wpdb->prefix}icl_translations WHERE trid = {$trid} AND element_id != {$postId}"); 271 272 $extra_meta_ids = array(); 273 foreach($ids as $k => $v) { 274 $tmp = $wpdb->get_results("select id from wp_mf_post_meta c WHERE c.post_id in (".$postId.",".$v->element_id.") AND id NOT IN (select a.id from wp_mf_post_meta a , wp_mf_post_meta b WHERE a.post_id = ".$v->element_id." AND b.post_id = ".$postId." AND a.field_name = b.field_name AND a.group_count = b.group_count AND a.field_count = b.field_count AND a.order_id = b.order_id UNION select a.id from wp_mf_post_meta a , wp_mf_post_meta b WHERE a.post_id = ".$postId." AND b.post_id = ".$v->element_id." AND a.field_name = b.field_name AND a.group_count = b.group_count AND a.field_count = b.field_count AND a.order_id = b.order_id)"); 275 foreach($tmp as $z => $y) { 276 $extra_meta_ids[] = $y->id; 277 } 278 279 280 $meta_id = implode(",",$extra_meta_ids); 281 282 //deleting references for add the new data when the post be saved 283 $wpdb->query("DELETE FROM ".$wpdb->prefix."postmeta WHERE meta_id IN (".$meta_id.")"); 284 $wpdb->query("DELETE FROM ".MF_TABLE_POST_META." WHERE id iN (".$meta_id.")"); 285 286 287 } 288 } 289 290 add_action('save_post','mfpluswpml_save_post',9); 291 function mfpluswpml_save_post($postId) { 292 global $flag,$wpdb; 293 if($flag == 1) { 294 return $postId; 295 } 296 297 if ( $the_post = wp_is_post_revision($postId)) { 298 $postId = $the_post; 299 } 300 301 if(!empty($_REQUEST['rc-custom-write-panel-verify-key'])) { 302 //the user can edit posts? 303 if (!(current_user_can('edit_posts', $postId) || current_user_can('edit_published_pages', $postId))){ 304 return $postId; 305 } 306 //looking for the translated version of the post 307 $trid = $wpdb->get_var($wpdb->prepare("SELECT trid FROM {$wpdb->prefix}icl_translations WHERE element_id = {$postId} AND (element_type = 'post_post' OR element_type = 'post_page')")); 308 309 //Getting the ID's of the translatable fields 310 $ids = $wpdb->get_results("SELECT element_id FROM {$wpdb->prefix}icl_translations WHERE trid = {$trid} AND element_id != {$postId}"); 311 312 if(empty($ids)){ 313 return true; 314 } 315 316 /** getting the translatables fields **/ 317 if(!$translatables = get_option("mfplus_translatables")){ 318 $translatables = array(); 319 } 320 321 array_walk($translatables,'get_custom_field_name'); 322 $translatables_text = implode("','",$translatables); 323 324 $ids_text = array(); 325 foreach($ids as $k => $v) { 326 $ids_text[] = $v->element_id; 327 } 328 329 $ids_text = implode(",",$ids_text); 330 331 $meta_id = array(); 332 $mids = $wpdb->get_results("SELECT id FROM ".MF_TABLE_POST_META." WHERE field_name IN ('".$translatables_text."') AND post_id IN (".$ids_text.")"); 333 foreach($mids as $key => $value) { 334 $meta_id[] = $value->id; 335 } 336 337 $meta_id = implode(",",$meta_id); 338 339 //deleting references for add the new data when the post be saved 340 $wpdb->query("DELETE FROM ".$wpdb->prefix."postmeta WHERE meta_id IN (".$meta_id.")"); 341 $wpdb->query("DELETE FROM ".MF_TABLE_POST_META." WHERE id iN (".$meta_id.")"); 342 } 343 } 344 345 /** 346 * Return the custom field name from the translatable array 347 */ 348 function get_custom_field_name(&$item) { 349 $item = preg_replace("/[0-9]+\_/i","",$item); 350 } -
mf-plus-wpml/trunk/README.markdown
r315703 r331583 18 18 3. Activate the plugin through the 'Plugins' menu in Wordpress 19 19 20 ### 1.1 ### 21 22 * Fix in translations where exists a duplicable group and field 23 20 24 ### 1.0 ### 21 25 First release -
mf-plus-wpml/trunk/readme.txt
r315710 r331583 4 4 Tested up to: Wordpress 3.0 5 5 Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=edgar%40programador%2ecom&lc=GB&item_name=Donation%20Magic%20Fields¤cy_code=USD&bn=PP%2dDonationsBF%3abtn_donateCC_LG%2egif%3aNonHostedGuest 6 Stable tag: 1. 06 Stable tag: 1.1 7 7 Description: MF Plus WPML fixes compatibility issues that existed between Magic Fields (http://magicfields.org) and WPML (http://wpml.org) 8 8 … … 25 25 == Changelog == 26 26 27 = 1.1 = 28 29 * Fix in translations where exists a duplicable group and field 30 27 31 = 1.0 = 28 32
Note: See TracChangeset
for help on using the changeset viewer.