Changeset 654798
- Timestamp:
- 01/18/2013 10:05:33 AM (13 years ago)
- Location:
- aeiou
- Files:
-
- 3 edited
- 5 copied
-
tags/0.2 (copied) (copied from aeiou/trunk)
-
tags/0.2/index.php (copied) (copied from aeiou/trunk/index.php) (19 diffs)
-
tags/0.2/languages (copied) (copied from aeiou/trunk/languages)
-
tags/0.2/parsers.php (copied) (copied from aeiou/trunk/parsers.php) (3 diffs)
-
tags/0.2/readme.txt (copied) (copied from aeiou/trunk/readme.txt) (5 diffs)
-
trunk/index.php (modified) (19 diffs)
-
trunk/parsers.php (modified) (3 diffs)
-
trunk/readme.txt (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
aeiou/tags/0.2/index.php
r648658 r654798 3 3 Plugin Name: AEIOU - Advanced Export/Import (WordPress) Object Users 4 4 Plugin URI: http://wordpress.org/extend/plugins/aeiou/ 5 Description: AEIOU is a powerfull plugin that export all wordpress users info into an XML file including user metadatas and allow to import the same xml file into a new wordpress keeping the metadata of each user. 5 Description: AEIOU is a powerfull plugin that export all wordpress users info into an XML file including user metadatas and allow to import the same xml file into a new wordpress keeping the metadata of each user. The plugin is able to export buddypress xprofile data too. 6 6 Author: toSend.it di Luisa Marra 7 Version: 0. 17 Version: 0.2 8 8 Author URI: http://tosend.it 9 9 */ … … 11 11 if(!class_exists('AEIOU')){ 12 12 class AEIOU{ 13 const VERSION = '0. 1';13 const VERSION = '0.2'; 14 14 const LANG_DOMAIN = 'AEIOU'; 15 16 private $verbose; 17 private $exists; 18 private $importMetadata; 19 private $importOptions; 20 private $importXProfile; 21 22 private $exportMetadata; 23 private $exportOptions; 24 private $exportXProfile; 15 25 16 26 public function __construct(){ 17 27 add_action('admin_init', array($this , 'init')); 18 28 add_action('admin_menu', array($this, 'createPages')); 19 #add_action('request', array($this, 'exportData'));29 20 30 } 21 31 … … 43 53 echo("\t\t<display_name><![CDATA[{$user->display_name}]]></display_name>\n"); 44 54 45 if( isset($_GET['metadata'])){55 if($this->exportMetadata || $this->exportOptions){ 46 56 /* 47 57 * I should export metadata (as requested by user) 48 58 */ 49 59 echo("\t\t<metadata>"); 50 60 global $wpdb; 51 61 $umeta = get_user_meta($user->ID); 52 62 foreach($umeta as $key => $value){ 63 $isOption = preg_match("#^" . preg_quote($wpdb->prefix) ."#", $key); 64 if( ($isOption && $this->exportOptions) || (!$isOption && $this->exportMetadata) ){ 53 65 54 echo("\t\t\t<meta key=\"$key\"><![CDATA["); 55 $value = $value[0]; 56 echo base64_encode($value); 57 echo("]]></meta>\n"); 66 echo("\t\t\t<meta "); 67 68 if(preg_match("#^" . preg_quote($wpdb->prefix) ."#", $key)){ 69 /* 70 * If the value is an option i should remove the db prefix from the option 71 * name and add the attribute option to allow the importer to understand 72 * when a node is an option or a setting. 73 */ 74 echo('option="true" '); 75 echo('global="false" '); 76 $key =substr($key, strlen($wpdb->prefix)); 77 } 78 echo("key=\"$key\"><![CDATA["); 79 $value = $value[0]; 80 echo base64_encode($value); 81 echo("]]></meta>\n"); 82 } 58 83 59 84 } 60 85 61 86 echo("\t\t</metadata>"); 87 } 88 if( class_exists('BuddyPress') ){ 89 if(class_exists('BP_XProfile_Group') && $this->exportXProfile ){ 90 /* 91 * I should export xprofile data too. 92 */ 93 $groups = BP_XProfile_Group::get( array( 94 'fetch_fields' => true 95 ) ); 96 /* 97 * Fetching all groups 98 */ 99 echo("\t\t<xprofile>"); 100 foreach($groups as $group){ 101 $groupName = $group->name; 102 if(!empty($group->fields)){ 103 104 /* 105 * Has fields in group 106 */ 107 foreach($group->fields as $field){ 108 $value = xprofile_get_field_data($field->id, $user->ID, 'array'); 109 echo("<field group=\"$groupName\" name=\"{$field->name}\">"); 110 $value = serialize($value); 111 #$value = base64_encode($value); 112 echo $value; 113 echo("</field>"); 114 } 115 } 116 } 117 echo("\t\t</xprofile>"); 118 } 119 62 120 } 63 121 … … 83 141 echo("<users version=\"". self::VERSION . "\">\n"); 84 142 143 $this->exportMetadata = isset($_GET['metadata']); 144 $this->exportOptions = isset($_GET['options']); 145 $this->exportXProfile = isset($_GET['xprofile']); 146 147 85 148 foreach($users as $user){ 86 149 … … 96 159 public function createPages(){ 97 160 add_users_page("AEIOU - Panel", 'AEIOU', 'add_users', 'aeiou', array($this, 'thePage')); 98 99 161 } 100 162 … … 172 234 ?> 173 235 <form method="get" action=""> 236 <?php do_action('aeiou_before_export_form'); ?> 174 237 <div> 175 238 <input type="hidden" name="page" value="aeiou" /> … … 185 248 </div> 186 249 <div> 187 <input type="checkbox" name="metadata" id="aeiou_md" /> 188 <label for="aeiou_md"><?php _e('Export users metadata', self::LANG_DOMAIN) ?></label> 250 <p> 251 <input type="checkbox" name="metadata" id="aeiou_md" /> 252 <label for="aeiou_md"><?php _e('Export users metadata', self::LANG_DOMAIN) ?></label> 253 </p> 254 <p> 255 <input type="checkbox" name="options" id="aeiou_opt" /> 256 <label for="aeiou_opt"><?php _e('Export users options', self::LANG_DOMAIN) ?></label> 257 </p> 189 258 </div> 259 <?php 260 if(class_exists('BuddyPress')){ 261 /* 262 * New in 0.2 version (export Buddy Press XPorfile Data) 263 */ 264 ?> 265 <div> 266 <p> 267 <input type="checkbox" name="xprofile" id="aeiou_xprofile" /> 268 <label for="aeiou_xprofile"><?php _e('Include the BuddyPress Extended Profile data too', self::LANG_DOMAIN) ?></label> 269 </p> 270 </div> 271 <?php 272 } 273 ?> 274 <?php do_action('aeiou_after_export_form'); ?> 190 275 <p> 191 192 276 <input type="submit" class="primary" value="<?php _e("Export users", self::LANG_DOMAIN); ?>" /> 193 277 </p> … … 196 280 } 197 281 198 199 282 private function decodeFileError($errorCode){ 200 283 … … 205 288 ?> 206 289 <form method="post" action="?page=aeiou&aeiou=import" enctype="multipart/form-data"> 290 <?php do_action('aeiou_before_import_form'); ?> 207 291 <div> 208 292 <p> … … 236 320 <input type="checkbox" name="metadata" id="aeiou_mdi" /> 237 321 <label for="aeiou_mdi"><?php _e('Import users metadata', self::LANG_DOMAIN); ?></label> 322 </p> 323 <p> 324 <input type="checkbox" name="options" id="aeiou_opti" /> 325 <label for="aeiou_opti"><?php _e('Import users options', self::LANG_DOMAIN); ?></label> 326 </p> 327 <p> 328 <input type="checkbox" name="xprofile" id="aeiou_xp" /> 329 <label for="aeiou_xp"><?php _e('Import BuddyPress XProfile user fields, data and groups', self::LANG_DOMAIN); ?></label> 238 330 </p> 239 331 <p> … … 246 338 <input type="file" name="the_file" id="the_file" /> 247 339 </p> 340 <?php do_action('aeiou_after_import_form'); ?> 248 341 <p> 249 342 <input type="submit" class="primary" value="<?php _e("Import users", self::LANG_DOMAIN); ?>" /> … … 251 344 </form> 252 345 <pre class="output"><?php 253 254 255 346 256 347 if(isset($_GET['aeiou']) && $_GET['aeiou'] =='import'){ 257 348 /* … … 266 357 $theFile = $_FILES['the_file']; 267 358 268 $verbose = isset($_POST['verbose']); 359 /* 360 * Setting the Class variables for import 361 */ 362 363 /* 364 * If the import should loud all it is doing 365 */ 366 $this->verbose = isset($_POST['verbose']); 367 368 /* 369 * The behavior when a wordpress user is found 370 * it could be: 371 * - skip 372 * - replace 373 * - update 374 */ 375 $this->exists = isset($_POST['exists'])?$_POST['exists']:'skip'; 376 377 378 $this->importMetadata = isset($_POST['metadata']); 379 $this->importOptions = isset($_POST['options']); 380 $this->importXProfile = isset($_POST['xprofile']); 381 269 382 270 383 if($theFile['error'] != 0){ … … 283 396 $users = $parser->parse($theFile['tmp_name']); 284 397 285 $exists = isset($_POST['exists'])?$_POST['exists']:'skip';286 287 398 foreach($users as $user){ 399 /* 400 * Increase the time limit up to 10 seconds per user 401 */ 402 set_time_limit(10); 403 288 404 $login = $user['user_login']; 289 405 echo("\n<strong>$login</strong> "); … … 292 408 $userID = 0; 293 409 294 $userMeta = (isset($user['metadata'])) ? $user['metadata'] : array(); 295 if(isset($user['metadata'])) unset($user['metadata']); 296 297 if($usr && $exists != 'skip'){ 410 $userMeta = (isset($user['metadata'])) ? $user['metadata'] : array(); 411 /* 412 * v0.2: Added user options and xprofile import 413 */ 414 $userOptions = (isset($user['options'])) ? $user['options'] : array(); 415 $xprofile = (isset($user['xprofile'])) ? $user['xprofile'] : array(); 416 417 /* 418 * Cleanup extra keys 419 */ 420 if(isset($user['metadata'])) unset($user['metadata']); 421 if(isset($user['options'])) unset($user['options']); 422 if(isset($user['xprofile'])) unset($user['xprofile']); 423 424 do_action('aeiou_before_import_user', $user); 425 426 if($usr && $this->exists != 'skip'){ 298 427 $usr = (array) $usr->data; 299 428 300 if($ exists == 'update'){429 if($this->exists == 'update'){ 301 430 302 431 /* … … 316 445 if(count($user)>0){ 317 446 $changes = array_keys($user); 318 $changes = "<code>".implode("</code>, <code>", $changes)."</code>";447 $changes = "<code>".implode("</code>, <code>", $changes)."</code>"; 319 448 320 449 echo sprintf(__("has new %s value(s).", self::LANG_DOMAIN),$changes) . "\n"; 321 450 $user['ID'] = $usr['ID']; 451 /* 452 * TODO: If password is defined in the XML file we should to import it 453 */ 322 454 wp_update_user($user); 323 455 }else{ … … 334 466 $userID = wp_insert_user($user); 335 467 $user['ID'] = $userID; 468 /* 469 * TODO: If password is defined in the XML file we should to import it 470 */ 336 471 wp_update_user($user); 337 472 echo sprintf(__("inserted with ID %d", self::LANG_DOMAIN),$userID) . "\n"; … … 339 474 echo __("skipped due it's already in the database", self::LANG_DOMAIN) . "\n"; 340 475 } 341 342 476 } 343 if(isset($_POST['metadata']) && $userID != 0){ 344 345 /* 346 * Admin asked for metadata import 347 */ 348 349 $count = 0; 350 foreach($userMeta as $key => $value){ 351 $metaKey = get_user_meta($userID, $key); 352 353 if(empty($metaKey[0])) $metaKey = false; 354 if(is_serialized($value)) $value = unserialize($value); 355 if(!$metaKey || $exists=='replace'){ 356 delete_user_meta($userID, $key); 357 if( !empty( $value ) ){ 358 359 $count+=1; 360 if($verbose) echo sprintf(__("Metadata <code>%s</code> updated for user <strong>%s</strong>", self::LANG_DOMAIN), $key, $login) . "\n"; 361 362 363 update_user_meta($userID, $key, $value ); 364 }else{ 365 if($metaKey && $verbose) echo sprintf(__("Metadata <code>%s</code> removed for user <strong>%s</strong>", self::LANG_DOMAIN), $key, $login) . "\n"; 366 } 367 } 368 } 369 if($count>0) 370 echo sprintf(__("Updated %d metadatas for user <strong>%s</strong>", self::LANG_DOMAIN), $count, $login) . "\n"; 371 477 478 if($this->importMetadata && $userID != 0){ 479 do_action('aeiou_before_import_metadata', $user); 480 $this->importUserMetaData($userMeta, $userID, $login); 372 481 } 373 482 483 if($this->importOptions && $userID != 0){ 484 do_action('aeiou_before_import_options', $user); 485 echo __("Importing user options\n", self::LANG_DOMAIN); 486 $this->importUserOptions($userOptions, $userID, $login); 487 } 488 489 if($this->importXProfile && $userID != 0 && class_exists('BP_XProfile_Component')){ 490 do_action('aeiou_before_import_xprofile', $user); 491 echo __("Importing XProfile data\n", self::LANG_DOMAIN); 492 $this->importXProfileData($xprofile, $userID); 493 } 494 do_action('aeiou_after_import_user', $user); 495 374 496 } 497 375 498 376 499 } … … 381 504 <?php 382 505 } 506 507 private function importUserMetaData($userMeta, $userID, $login){ 508 509 /* 510 * Admin asked for metadata import 511 */ 512 513 $count = 0; 514 foreach($userMeta as $key => $value){ 515 $metaKey = get_user_meta($userID, $key); 516 517 if(empty($metaKey[0])) $metaKey = false; 518 if(is_serialized($value)) $value = unserialize($value); 519 if(!$metaKey || $this->exists=='replace'){ 520 delete_user_meta($userID, $key); 521 if( !empty( $value ) ){ 522 523 $count+=1; 524 if($this->verbose) echo sprintf(__("Metadata <code>%s</code> updated for user <strong>%s</strong>", self::LANG_DOMAIN), $key, $login) . "\n"; 525 526 update_user_meta($userID, $key, $value ); 527 }else{ 528 if($metaKey && $this->verbose) echo sprintf(__("Metadata <code>%s</code> removed for user <strong>%s</strong>", self::LANG_DOMAIN), $key, $login) . "\n"; 529 } 530 } 531 } 532 533 if($count>0) 534 echo sprintf(__("Updated %d metadatas for user <strong>%s</strong>", self::LANG_DOMAIN), $count, $login) . "\n"; 535 536 } 537 538 private function importUserOptions($userOptions, $userID, $login){ 539 540 /* 541 * Admin asked for options import 542 */ 543 544 $count = 0; 545 foreach($userOptions as $key => $data){ 546 547 list($value, $global) = $data; 548 549 $option = get_user_option( $key, $userID); 550 551 $optExists = !empty($option); 552 if(is_serialized($option)) $option = unserialize($option); 553 if(!$optExists || $this->exists=='replace'){ 554 delete_user_option($userID, $key); 555 if( !empty( $value ) ){ 556 557 $count+=1; 558 if($this->verbose) echo sprintf(__("Option <code>%s</code> updated for user <strong>%s</strong>", self::LANG_DOMAIN), $key, $login) . "\n"; 559 560 561 update_user_option($userID, $key, $value, $global ); 562 }else{ 563 if($optExists && $this->verbose) echo sprintf(__("Option <code>%s</code> removed for user <strong>%s</strong>", self::LANG_DOMAIN), $key, $login) . "\n"; 564 } 565 } 566 } 567 568 if($count>0) 569 echo sprintf(__("Updated %d metadatas for user <strong>%s</strong>", self::LANG_DOMAIN), $count, $login) . "\n"; 570 571 } 572 573 574 575 private function importXProfileData($xprofile, $userID){ 576 /* 577 * Admin asked for xprofile import 578 */ 579 $count = 0; 580 581 foreach($xprofile as $name => $data){ 582 $value = $data[0]; 583 $group = $data[1]; 584 585 if($this->verbose) echo sprintf(__("Importing field <code>%s</code> of group <code>%s</code>", self::LANG_DOMAIN), $name, $group) . "\n"; 586 587 /* 588 * Get the XProfile Fields Group ID 589 * If it's not available the will be created as new. 590 */ 591 $groupId = $this->getXProfileGroupIDByName($group); 592 593 /* 594 * Get the XProfile Field ID 595 * If it's not available the will be created as new. 596 */ 597 $fieldId = $this->getXProfileFieldIDByName($name, $groupId); 598 $fieldData = is_serialized($value)? unserialize($value): $value; 599 $oldValue = BP_XProfile_ProfileData::get_value_byid($fieldId, $userID); 600 if(is_null($oldValue) || ($oldValue == '' && $this->exists == 'update') || ($this->exists == 'replace') ){ 601 /* 602 * Saving data if not exists or need to be updated 603 */ 604 $data = new BP_XProfile_ProfileData(); 605 $data->field_id = $fieldId; 606 $data->user_id = $userID; 607 $data->value = is_serialized($value)? unserialize($value): $value; 608 $data->save(); 609 610 } 611 } 612 } 613 private function getXProfileFieldIDByName($name, $groupId = 0, $create = true){ 614 $out = BP_XProfile_Field::get_id_from_name($name); 615 if(is_null($out) && $create){ 616 617 $field = new BP_XProfile_Field(); 618 $field->name = $name; 619 $field->group_id = $groupId; 620 /* 621 * TODO: Store in the XML the type. 622 * Aactually i will create a generic text type if the field is not available. 623 */ 624 $field->type = "text"; 625 $out = $field->save(); 626 } 627 return $out; 628 } 629 630 private function getXProfileGroupIDByName($name, $create = true){ 631 global $wpdb, $bp; 632 633 $sql = "select id from {$bp->profile->table_name_groups} where name = %s"; 634 $sql = $wpdb->prepare($sql, $name); 635 $out = $wpdb->get_var($sql); 636 637 if( is_null( $out ) && $create ){ 638 $newGroup = new BP_XProfile_Group(); 639 $newGroup->name = $name; 640 $out = $newGroup->save(); 641 } 642 return $out; 643 644 } 383 645 } 384 646 -
aeiou/tags/0.2/parsers.php
r648658 r654798 36 36 $count +=1; 37 37 $md = array(); 38 38 $opt = array(); 39 39 $user = $userArray->children( ); 40 40 if(isset($user->metadata)){ … … 45 45 $key = (string) $metaArr['@attributes']['key']; 46 46 $value = (string) $meta; 47 /* 48 * Make differences between options and settings 49 */ 50 if ( isset($metaArr['@attributes']['option']) ) { 51 $isGlobalOption = ((string)$metaArr['@attributes']['global']) == 'true'; 52 $isOption = true; 53 $opt[$key] = array(base64_decode( $value ), $isGlobalOption); 54 }else{ 55 $isOption = false; 56 $md[$key] =base64_decode( $value ); 57 } 47 58 48 $md[$key] =base64_decode( $value ); 59 } 60 61 } 62 /* 63 * Since ver. 0.2 (xprofile data extraction) 64 */ 65 $xp = array(); 66 if(isset($user->xprofile)){ 67 68 foreach($user->xprofile->field as $xField){ 69 70 $fieldArr = (array)$xField; 71 $name = (string) $fieldArr['@attributes']['name']; 72 $value = (string) $xField; 73 $group = (string) $fieldArr['@attributes']['group']; 74 75 $xp[$name] = array( base64_decode( $value ), $group ); 76 49 77 } 50 78 51 79 } 52 80 53 $user s[] =array(81 $userRow = array( 54 82 55 83 'user_login' => (string) $user->user_login, … … 62 90 'user_status' => (string) $user->user_status, 63 91 'display_name' => (string) $user->display_name, 64 'metadata' => $md 92 'metadata' => $md, 93 'options' => $opt, 94 'xprofile' => $xp, 65 95 ); 96 /* 97 * Since version 0.2 (can extend import object threating further informations from xml file) 98 */ 99 $userRow = apply_filters('aeiou_filter_row', $userRow, $user); 100 101 if(is_array($userRow)) 102 $users[] = $userRow; 66 103 } 67 104 -
aeiou/tags/0.2/readme.txt
r648658 r654798 2 2 Contributors: tosend.it 3 3 Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=CRB85JPKCSNZ6 4 Tags: user import, export, metadata4 Tags: user, users, import, export, metadata, settings, options, BuddyPress, xprofile, Extended Profile, fields 5 5 Requires at least: 3.4 6 6 Tested up to: 3.5 7 Stable tag: 0. 17 Stable tag: 0.2 8 8 License: GPLv2 9 9 … … 12 12 == Description == 13 13 14 AEIOU is a powerfull plugin that export all wordpress users info into an XML file including user metadatas and allow to import the same xml file into a new wordpress keeping the metadata of each user.14 AEIOU is a powerfull plugin that export all wordpress users info into an XML file including user metadatas and allow to import the same xml file into a new wordpress keeping the metadata and Buddypress XProfile data of each user. 15 15 16 16 **Note:** AEIOU requires SimpleXML PHP library to import data. Nothing more than wordpress is required for the export. … … 18 18 == Installation == 19 19 1. Install AEIOU either via the WordPress.org plugin directory, or by uploading the files to your server 20 1. That's it. You're ready to export !20 1. That's it. You're ready to export/import users! 21 21 22 22 … … 24 24 25 25 It's too simple to do what the plugin does... However, have you got a question? Please ask us on forum. 26 27 28 = Why my imported XProfile fields becomes all of text type? = 29 30 This is because the importer does not keep any information about the field except than Field Name, Field Group and Field Value. 31 Any other information is left behind. So the better way to make an import that grant the exact structure for xprofile field is 32 to create the XProfile Fields on the new Wordpress instance before the import is done then make the import. 33 34 = Why the user are unable to login after I done the Import? = 35 36 If you have imported the password field too then It was changed and you have to ensure that the same secret key is used in both old and new wordpress. 26 37 27 38 == Screenshots == … … 31 42 == Changelog == 32 43 44 = 0.2 (2013-01-18) = 45 * **New:** Now you can export and import BuddyPress XProfile data too. If fields or group does not exists they will be created and the field will become of generic type `text` 46 * **New:** Added action aeiou_before_import_user 47 * **New:** Added action aeiou_before_import_metadata 48 * **New:** Added action aeiou_before_import_xprofile 49 * **New:** Added action aeiou_after_import_user 50 * **New:** Added filter aeiou_filter_row 51 * **New:** Added action aeiou_before_import_form 52 * **New:** Added action aeiou_after_import_form 53 * **New:** Added action aeiou_before_export_form 54 * **New:** Added action aeiou_after_export_form 55 * **New:** Options exported with metadata 56 * **New:** Impoter allow import of options too 57 * **Update:** Better code organization. 58 * **Update:** Updated Italian translation file. 59 * **Update:** Updated translation template file. 60 * **Update:** Added FAQ to this page. 61 * **Bugfix:** Increased code execution timeout. 62 33 63 = 0.1 (2013-01-05) = 34 64 * First plugin release. -
aeiou/trunk/index.php
r648658 r654798 3 3 Plugin Name: AEIOU - Advanced Export/Import (WordPress) Object Users 4 4 Plugin URI: http://wordpress.org/extend/plugins/aeiou/ 5 Description: AEIOU is a powerfull plugin that export all wordpress users info into an XML file including user metadatas and allow to import the same xml file into a new wordpress keeping the metadata of each user. 5 Description: AEIOU is a powerfull plugin that export all wordpress users info into an XML file including user metadatas and allow to import the same xml file into a new wordpress keeping the metadata of each user. The plugin is able to export buddypress xprofile data too. 6 6 Author: toSend.it di Luisa Marra 7 Version: 0. 17 Version: 0.2 8 8 Author URI: http://tosend.it 9 9 */ … … 11 11 if(!class_exists('AEIOU')){ 12 12 class AEIOU{ 13 const VERSION = '0. 1';13 const VERSION = '0.2'; 14 14 const LANG_DOMAIN = 'AEIOU'; 15 16 private $verbose; 17 private $exists; 18 private $importMetadata; 19 private $importOptions; 20 private $importXProfile; 21 22 private $exportMetadata; 23 private $exportOptions; 24 private $exportXProfile; 15 25 16 26 public function __construct(){ 17 27 add_action('admin_init', array($this , 'init')); 18 28 add_action('admin_menu', array($this, 'createPages')); 19 #add_action('request', array($this, 'exportData'));29 20 30 } 21 31 … … 43 53 echo("\t\t<display_name><![CDATA[{$user->display_name}]]></display_name>\n"); 44 54 45 if( isset($_GET['metadata'])){55 if($this->exportMetadata || $this->exportOptions){ 46 56 /* 47 57 * I should export metadata (as requested by user) 48 58 */ 49 59 echo("\t\t<metadata>"); 50 60 global $wpdb; 51 61 $umeta = get_user_meta($user->ID); 52 62 foreach($umeta as $key => $value){ 63 $isOption = preg_match("#^" . preg_quote($wpdb->prefix) ."#", $key); 64 if( ($isOption && $this->exportOptions) || (!$isOption && $this->exportMetadata) ){ 53 65 54 echo("\t\t\t<meta key=\"$key\"><![CDATA["); 55 $value = $value[0]; 56 echo base64_encode($value); 57 echo("]]></meta>\n"); 66 echo("\t\t\t<meta "); 67 68 if(preg_match("#^" . preg_quote($wpdb->prefix) ."#", $key)){ 69 /* 70 * If the value is an option i should remove the db prefix from the option 71 * name and add the attribute option to allow the importer to understand 72 * when a node is an option or a setting. 73 */ 74 echo('option="true" '); 75 echo('global="false" '); 76 $key =substr($key, strlen($wpdb->prefix)); 77 } 78 echo("key=\"$key\"><![CDATA["); 79 $value = $value[0]; 80 echo base64_encode($value); 81 echo("]]></meta>\n"); 82 } 58 83 59 84 } 60 85 61 86 echo("\t\t</metadata>"); 87 } 88 if( class_exists('BuddyPress') ){ 89 if(class_exists('BP_XProfile_Group') && $this->exportXProfile ){ 90 /* 91 * I should export xprofile data too. 92 */ 93 $groups = BP_XProfile_Group::get( array( 94 'fetch_fields' => true 95 ) ); 96 /* 97 * Fetching all groups 98 */ 99 echo("\t\t<xprofile>"); 100 foreach($groups as $group){ 101 $groupName = $group->name; 102 if(!empty($group->fields)){ 103 104 /* 105 * Has fields in group 106 */ 107 foreach($group->fields as $field){ 108 $value = xprofile_get_field_data($field->id, $user->ID, 'array'); 109 echo("<field group=\"$groupName\" name=\"{$field->name}\">"); 110 $value = serialize($value); 111 #$value = base64_encode($value); 112 echo $value; 113 echo("</field>"); 114 } 115 } 116 } 117 echo("\t\t</xprofile>"); 118 } 119 62 120 } 63 121 … … 83 141 echo("<users version=\"". self::VERSION . "\">\n"); 84 142 143 $this->exportMetadata = isset($_GET['metadata']); 144 $this->exportOptions = isset($_GET['options']); 145 $this->exportXProfile = isset($_GET['xprofile']); 146 147 85 148 foreach($users as $user){ 86 149 … … 96 159 public function createPages(){ 97 160 add_users_page("AEIOU - Panel", 'AEIOU', 'add_users', 'aeiou', array($this, 'thePage')); 98 99 161 } 100 162 … … 172 234 ?> 173 235 <form method="get" action=""> 236 <?php do_action('aeiou_before_export_form'); ?> 174 237 <div> 175 238 <input type="hidden" name="page" value="aeiou" /> … … 185 248 </div> 186 249 <div> 187 <input type="checkbox" name="metadata" id="aeiou_md" /> 188 <label for="aeiou_md"><?php _e('Export users metadata', self::LANG_DOMAIN) ?></label> 250 <p> 251 <input type="checkbox" name="metadata" id="aeiou_md" /> 252 <label for="aeiou_md"><?php _e('Export users metadata', self::LANG_DOMAIN) ?></label> 253 </p> 254 <p> 255 <input type="checkbox" name="options" id="aeiou_opt" /> 256 <label for="aeiou_opt"><?php _e('Export users options', self::LANG_DOMAIN) ?></label> 257 </p> 189 258 </div> 259 <?php 260 if(class_exists('BuddyPress')){ 261 /* 262 * New in 0.2 version (export Buddy Press XPorfile Data) 263 */ 264 ?> 265 <div> 266 <p> 267 <input type="checkbox" name="xprofile" id="aeiou_xprofile" /> 268 <label for="aeiou_xprofile"><?php _e('Include the BuddyPress Extended Profile data too', self::LANG_DOMAIN) ?></label> 269 </p> 270 </div> 271 <?php 272 } 273 ?> 274 <?php do_action('aeiou_after_export_form'); ?> 190 275 <p> 191 192 276 <input type="submit" class="primary" value="<?php _e("Export users", self::LANG_DOMAIN); ?>" /> 193 277 </p> … … 196 280 } 197 281 198 199 282 private function decodeFileError($errorCode){ 200 283 … … 205 288 ?> 206 289 <form method="post" action="?page=aeiou&aeiou=import" enctype="multipart/form-data"> 290 <?php do_action('aeiou_before_import_form'); ?> 207 291 <div> 208 292 <p> … … 236 320 <input type="checkbox" name="metadata" id="aeiou_mdi" /> 237 321 <label for="aeiou_mdi"><?php _e('Import users metadata', self::LANG_DOMAIN); ?></label> 322 </p> 323 <p> 324 <input type="checkbox" name="options" id="aeiou_opti" /> 325 <label for="aeiou_opti"><?php _e('Import users options', self::LANG_DOMAIN); ?></label> 326 </p> 327 <p> 328 <input type="checkbox" name="xprofile" id="aeiou_xp" /> 329 <label for="aeiou_xp"><?php _e('Import BuddyPress XProfile user fields, data and groups', self::LANG_DOMAIN); ?></label> 238 330 </p> 239 331 <p> … … 246 338 <input type="file" name="the_file" id="the_file" /> 247 339 </p> 340 <?php do_action('aeiou_after_import_form'); ?> 248 341 <p> 249 342 <input type="submit" class="primary" value="<?php _e("Import users", self::LANG_DOMAIN); ?>" /> … … 251 344 </form> 252 345 <pre class="output"><?php 253 254 255 346 256 347 if(isset($_GET['aeiou']) && $_GET['aeiou'] =='import'){ 257 348 /* … … 266 357 $theFile = $_FILES['the_file']; 267 358 268 $verbose = isset($_POST['verbose']); 359 /* 360 * Setting the Class variables for import 361 */ 362 363 /* 364 * If the import should loud all it is doing 365 */ 366 $this->verbose = isset($_POST['verbose']); 367 368 /* 369 * The behavior when a wordpress user is found 370 * it could be: 371 * - skip 372 * - replace 373 * - update 374 */ 375 $this->exists = isset($_POST['exists'])?$_POST['exists']:'skip'; 376 377 378 $this->importMetadata = isset($_POST['metadata']); 379 $this->importOptions = isset($_POST['options']); 380 $this->importXProfile = isset($_POST['xprofile']); 381 269 382 270 383 if($theFile['error'] != 0){ … … 283 396 $users = $parser->parse($theFile['tmp_name']); 284 397 285 $exists = isset($_POST['exists'])?$_POST['exists']:'skip';286 287 398 foreach($users as $user){ 399 /* 400 * Increase the time limit up to 10 seconds per user 401 */ 402 set_time_limit(10); 403 288 404 $login = $user['user_login']; 289 405 echo("\n<strong>$login</strong> "); … … 292 408 $userID = 0; 293 409 294 $userMeta = (isset($user['metadata'])) ? $user['metadata'] : array(); 295 if(isset($user['metadata'])) unset($user['metadata']); 296 297 if($usr && $exists != 'skip'){ 410 $userMeta = (isset($user['metadata'])) ? $user['metadata'] : array(); 411 /* 412 * v0.2: Added user options and xprofile import 413 */ 414 $userOptions = (isset($user['options'])) ? $user['options'] : array(); 415 $xprofile = (isset($user['xprofile'])) ? $user['xprofile'] : array(); 416 417 /* 418 * Cleanup extra keys 419 */ 420 if(isset($user['metadata'])) unset($user['metadata']); 421 if(isset($user['options'])) unset($user['options']); 422 if(isset($user['xprofile'])) unset($user['xprofile']); 423 424 do_action('aeiou_before_import_user', $user); 425 426 if($usr && $this->exists != 'skip'){ 298 427 $usr = (array) $usr->data; 299 428 300 if($ exists == 'update'){429 if($this->exists == 'update'){ 301 430 302 431 /* … … 316 445 if(count($user)>0){ 317 446 $changes = array_keys($user); 318 $changes = "<code>".implode("</code>, <code>", $changes)."</code>";447 $changes = "<code>".implode("</code>, <code>", $changes)."</code>"; 319 448 320 449 echo sprintf(__("has new %s value(s).", self::LANG_DOMAIN),$changes) . "\n"; 321 450 $user['ID'] = $usr['ID']; 451 /* 452 * TODO: If password is defined in the XML file we should to import it 453 */ 322 454 wp_update_user($user); 323 455 }else{ … … 334 466 $userID = wp_insert_user($user); 335 467 $user['ID'] = $userID; 468 /* 469 * TODO: If password is defined in the XML file we should to import it 470 */ 336 471 wp_update_user($user); 337 472 echo sprintf(__("inserted with ID %d", self::LANG_DOMAIN),$userID) . "\n"; … … 339 474 echo __("skipped due it's already in the database", self::LANG_DOMAIN) . "\n"; 340 475 } 341 342 476 } 343 if(isset($_POST['metadata']) && $userID != 0){ 344 345 /* 346 * Admin asked for metadata import 347 */ 348 349 $count = 0; 350 foreach($userMeta as $key => $value){ 351 $metaKey = get_user_meta($userID, $key); 352 353 if(empty($metaKey[0])) $metaKey = false; 354 if(is_serialized($value)) $value = unserialize($value); 355 if(!$metaKey || $exists=='replace'){ 356 delete_user_meta($userID, $key); 357 if( !empty( $value ) ){ 358 359 $count+=1; 360 if($verbose) echo sprintf(__("Metadata <code>%s</code> updated for user <strong>%s</strong>", self::LANG_DOMAIN), $key, $login) . "\n"; 361 362 363 update_user_meta($userID, $key, $value ); 364 }else{ 365 if($metaKey && $verbose) echo sprintf(__("Metadata <code>%s</code> removed for user <strong>%s</strong>", self::LANG_DOMAIN), $key, $login) . "\n"; 366 } 367 } 368 } 369 if($count>0) 370 echo sprintf(__("Updated %d metadatas for user <strong>%s</strong>", self::LANG_DOMAIN), $count, $login) . "\n"; 371 477 478 if($this->importMetadata && $userID != 0){ 479 do_action('aeiou_before_import_metadata', $user); 480 $this->importUserMetaData($userMeta, $userID, $login); 372 481 } 373 482 483 if($this->importOptions && $userID != 0){ 484 do_action('aeiou_before_import_options', $user); 485 echo __("Importing user options\n", self::LANG_DOMAIN); 486 $this->importUserOptions($userOptions, $userID, $login); 487 } 488 489 if($this->importXProfile && $userID != 0 && class_exists('BP_XProfile_Component')){ 490 do_action('aeiou_before_import_xprofile', $user); 491 echo __("Importing XProfile data\n", self::LANG_DOMAIN); 492 $this->importXProfileData($xprofile, $userID); 493 } 494 do_action('aeiou_after_import_user', $user); 495 374 496 } 497 375 498 376 499 } … … 381 504 <?php 382 505 } 506 507 private function importUserMetaData($userMeta, $userID, $login){ 508 509 /* 510 * Admin asked for metadata import 511 */ 512 513 $count = 0; 514 foreach($userMeta as $key => $value){ 515 $metaKey = get_user_meta($userID, $key); 516 517 if(empty($metaKey[0])) $metaKey = false; 518 if(is_serialized($value)) $value = unserialize($value); 519 if(!$metaKey || $this->exists=='replace'){ 520 delete_user_meta($userID, $key); 521 if( !empty( $value ) ){ 522 523 $count+=1; 524 if($this->verbose) echo sprintf(__("Metadata <code>%s</code> updated for user <strong>%s</strong>", self::LANG_DOMAIN), $key, $login) . "\n"; 525 526 update_user_meta($userID, $key, $value ); 527 }else{ 528 if($metaKey && $this->verbose) echo sprintf(__("Metadata <code>%s</code> removed for user <strong>%s</strong>", self::LANG_DOMAIN), $key, $login) . "\n"; 529 } 530 } 531 } 532 533 if($count>0) 534 echo sprintf(__("Updated %d metadatas for user <strong>%s</strong>", self::LANG_DOMAIN), $count, $login) . "\n"; 535 536 } 537 538 private function importUserOptions($userOptions, $userID, $login){ 539 540 /* 541 * Admin asked for options import 542 */ 543 544 $count = 0; 545 foreach($userOptions as $key => $data){ 546 547 list($value, $global) = $data; 548 549 $option = get_user_option( $key, $userID); 550 551 $optExists = !empty($option); 552 if(is_serialized($option)) $option = unserialize($option); 553 if(!$optExists || $this->exists=='replace'){ 554 delete_user_option($userID, $key); 555 if( !empty( $value ) ){ 556 557 $count+=1; 558 if($this->verbose) echo sprintf(__("Option <code>%s</code> updated for user <strong>%s</strong>", self::LANG_DOMAIN), $key, $login) . "\n"; 559 560 561 update_user_option($userID, $key, $value, $global ); 562 }else{ 563 if($optExists && $this->verbose) echo sprintf(__("Option <code>%s</code> removed for user <strong>%s</strong>", self::LANG_DOMAIN), $key, $login) . "\n"; 564 } 565 } 566 } 567 568 if($count>0) 569 echo sprintf(__("Updated %d metadatas for user <strong>%s</strong>", self::LANG_DOMAIN), $count, $login) . "\n"; 570 571 } 572 573 574 575 private function importXProfileData($xprofile, $userID){ 576 /* 577 * Admin asked for xprofile import 578 */ 579 $count = 0; 580 581 foreach($xprofile as $name => $data){ 582 $value = $data[0]; 583 $group = $data[1]; 584 585 if($this->verbose) echo sprintf(__("Importing field <code>%s</code> of group <code>%s</code>", self::LANG_DOMAIN), $name, $group) . "\n"; 586 587 /* 588 * Get the XProfile Fields Group ID 589 * If it's not available the will be created as new. 590 */ 591 $groupId = $this->getXProfileGroupIDByName($group); 592 593 /* 594 * Get the XProfile Field ID 595 * If it's not available the will be created as new. 596 */ 597 $fieldId = $this->getXProfileFieldIDByName($name, $groupId); 598 $fieldData = is_serialized($value)? unserialize($value): $value; 599 $oldValue = BP_XProfile_ProfileData::get_value_byid($fieldId, $userID); 600 if(is_null($oldValue) || ($oldValue == '' && $this->exists == 'update') || ($this->exists == 'replace') ){ 601 /* 602 * Saving data if not exists or need to be updated 603 */ 604 $data = new BP_XProfile_ProfileData(); 605 $data->field_id = $fieldId; 606 $data->user_id = $userID; 607 $data->value = is_serialized($value)? unserialize($value): $value; 608 $data->save(); 609 610 } 611 } 612 } 613 private function getXProfileFieldIDByName($name, $groupId = 0, $create = true){ 614 $out = BP_XProfile_Field::get_id_from_name($name); 615 if(is_null($out) && $create){ 616 617 $field = new BP_XProfile_Field(); 618 $field->name = $name; 619 $field->group_id = $groupId; 620 /* 621 * TODO: Store in the XML the type. 622 * Aactually i will create a generic text type if the field is not available. 623 */ 624 $field->type = "text"; 625 $out = $field->save(); 626 } 627 return $out; 628 } 629 630 private function getXProfileGroupIDByName($name, $create = true){ 631 global $wpdb, $bp; 632 633 $sql = "select id from {$bp->profile->table_name_groups} where name = %s"; 634 $sql = $wpdb->prepare($sql, $name); 635 $out = $wpdb->get_var($sql); 636 637 if( is_null( $out ) && $create ){ 638 $newGroup = new BP_XProfile_Group(); 639 $newGroup->name = $name; 640 $out = $newGroup->save(); 641 } 642 return $out; 643 644 } 383 645 } 384 646 -
aeiou/trunk/parsers.php
r648658 r654798 36 36 $count +=1; 37 37 $md = array(); 38 38 $opt = array(); 39 39 $user = $userArray->children( ); 40 40 if(isset($user->metadata)){ … … 45 45 $key = (string) $metaArr['@attributes']['key']; 46 46 $value = (string) $meta; 47 /* 48 * Make differences between options and settings 49 */ 50 if ( isset($metaArr['@attributes']['option']) ) { 51 $isGlobalOption = ((string)$metaArr['@attributes']['global']) == 'true'; 52 $isOption = true; 53 $opt[$key] = array(base64_decode( $value ), $isGlobalOption); 54 }else{ 55 $isOption = false; 56 $md[$key] =base64_decode( $value ); 57 } 47 58 48 $md[$key] =base64_decode( $value ); 59 } 60 61 } 62 /* 63 * Since ver. 0.2 (xprofile data extraction) 64 */ 65 $xp = array(); 66 if(isset($user->xprofile)){ 67 68 foreach($user->xprofile->field as $xField){ 69 70 $fieldArr = (array)$xField; 71 $name = (string) $fieldArr['@attributes']['name']; 72 $value = (string) $xField; 73 $group = (string) $fieldArr['@attributes']['group']; 74 75 $xp[$name] = array( base64_decode( $value ), $group ); 76 49 77 } 50 78 51 79 } 52 80 53 $user s[] =array(81 $userRow = array( 54 82 55 83 'user_login' => (string) $user->user_login, … … 62 90 'user_status' => (string) $user->user_status, 63 91 'display_name' => (string) $user->display_name, 64 'metadata' => $md 92 'metadata' => $md, 93 'options' => $opt, 94 'xprofile' => $xp, 65 95 ); 96 /* 97 * Since version 0.2 (can extend import object threating further informations from xml file) 98 */ 99 $userRow = apply_filters('aeiou_filter_row', $userRow, $user); 100 101 if(is_array($userRow)) 102 $users[] = $userRow; 66 103 } 67 104 -
aeiou/trunk/readme.txt
r648658 r654798 2 2 Contributors: tosend.it 3 3 Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=CRB85JPKCSNZ6 4 Tags: user import, export, metadata4 Tags: user, users, import, export, metadata, settings, options, BuddyPress, xprofile, Extended Profile, fields 5 5 Requires at least: 3.4 6 6 Tested up to: 3.5 7 Stable tag: 0. 17 Stable tag: 0.2 8 8 License: GPLv2 9 9 … … 12 12 == Description == 13 13 14 AEIOU is a powerfull plugin that export all wordpress users info into an XML file including user metadatas and allow to import the same xml file into a new wordpress keeping the metadata of each user.14 AEIOU is a powerfull plugin that export all wordpress users info into an XML file including user metadatas and allow to import the same xml file into a new wordpress keeping the metadata and Buddypress XProfile data of each user. 15 15 16 16 **Note:** AEIOU requires SimpleXML PHP library to import data. Nothing more than wordpress is required for the export. … … 18 18 == Installation == 19 19 1. Install AEIOU either via the WordPress.org plugin directory, or by uploading the files to your server 20 1. That's it. You're ready to export !20 1. That's it. You're ready to export/import users! 21 21 22 22 … … 24 24 25 25 It's too simple to do what the plugin does... However, have you got a question? Please ask us on forum. 26 27 28 = Why my imported XProfile fields becomes all of text type? = 29 30 This is because the importer does not keep any information about the field except than Field Name, Field Group and Field Value. 31 Any other information is left behind. So the better way to make an import that grant the exact structure for xprofile field is 32 to create the XProfile Fields on the new Wordpress instance before the import is done then make the import. 33 34 = Why the user are unable to login after I done the Import? = 35 36 If you have imported the password field too then It was changed and you have to ensure that the same secret key is used in both old and new wordpress. 26 37 27 38 == Screenshots == … … 31 42 == Changelog == 32 43 44 = 0.2 (2013-01-18) = 45 * **New:** Now you can export and import BuddyPress XProfile data too. If fields or group does not exists they will be created and the field will become of generic type `text` 46 * **New:** Added action aeiou_before_import_user 47 * **New:** Added action aeiou_before_import_metadata 48 * **New:** Added action aeiou_before_import_xprofile 49 * **New:** Added action aeiou_after_import_user 50 * **New:** Added filter aeiou_filter_row 51 * **New:** Added action aeiou_before_import_form 52 * **New:** Added action aeiou_after_import_form 53 * **New:** Added action aeiou_before_export_form 54 * **New:** Added action aeiou_after_export_form 55 * **New:** Options exported with metadata 56 * **New:** Impoter allow import of options too 57 * **Update:** Better code organization. 58 * **Update:** Updated Italian translation file. 59 * **Update:** Updated translation template file. 60 * **Update:** Added FAQ to this page. 61 * **Bugfix:** Increased code execution timeout. 62 33 63 = 0.1 (2013-01-05) = 34 64 * First plugin release.
Note: See TracChangeset
for help on using the changeset viewer.