Changeset 2792490
- Timestamp:
- 09/30/2022 01:26:23 PM (3 years ago)
- Location:
- crowdaa-sync
- Files:
-
- 8 edited
- 74 copied
-
tags/1.6.0 (copied) (copied from crowdaa-sync/trunk)
-
tags/1.6.0/CHANGELOG (copied) (copied from crowdaa-sync/trunk/CHANGELOG)
-
tags/1.6.0/LICENSE.txt (copied) (copied from crowdaa-sync/trunk/LICENSE.txt)
-
tags/1.6.0/README.txt (copied) (copied from crowdaa-sync/trunk/README.txt) (1 diff)
-
tags/1.6.0/admin (copied) (copied from crowdaa-sync/trunk/admin)
-
tags/1.6.0/admin/class-crowdaa-sync-add-info-api.php (copied) (copied from crowdaa-sync/trunk/admin/class-crowdaa-sync-add-info-api.php) (1 diff)
-
tags/1.6.0/admin/class-crowdaa-sync-add-info-wp.php (copied) (copied from crowdaa-sync/trunk/admin/class-crowdaa-sync-add-info-wp.php)
-
tags/1.6.0/admin/class-crowdaa-sync-admin-display.php (copied) (copied from crowdaa-sync/trunk/admin/class-crowdaa-sync-admin-display.php)
-
tags/1.6.0/admin/class-crowdaa-sync-api.php (copied) (copied from crowdaa-sync/trunk/admin/class-crowdaa-sync-api.php)
-
tags/1.6.0/admin/class-crowdaa-sync-ext-hooks.php (copied) (copied from crowdaa-sync/trunk/admin/class-crowdaa-sync-ext-hooks.php) (2 diffs)
-
tags/1.6.0/admin/class-crowdaa-sync-meta-box.php (copied) (copied from crowdaa-sync/trunk/admin/class-crowdaa-sync-meta-box.php)
-
tags/1.6.0/admin/class-crowdaa-sync-rest-api.php (copied) (copied from crowdaa-sync/trunk/admin/class-crowdaa-sync-rest-api.php) (2 diffs)
-
tags/1.6.0/admin/class-crowdaa-sync-wp-hooks.php (copied) (copied from crowdaa-sync/trunk/admin/class-crowdaa-sync-wp-hooks.php)
-
tags/1.6.0/admin/css/crowdaa-sync-admin.css (copied) (copied from crowdaa-sync/trunk/admin/css/crowdaa-sync-admin.css)
-
tags/1.6.0/admin/js/crowdaa-sync-admin.js (copied) (copied from crowdaa-sync/trunk/admin/js/crowdaa-sync-admin.js)
-
tags/1.6.0/admin/partials/crowdaa-sync-admin-display.php (copied) (copied from crowdaa-sync/trunk/admin/partials/crowdaa-sync-admin-display.php)
-
tags/1.6.0/cacert.pem (copied) (copied from crowdaa-sync/trunk/cacert.pem)
-
tags/1.6.0/composer.json (copied) (copied from crowdaa-sync/trunk/composer.json)
-
tags/1.6.0/crowdaa-sync.php (copied) (copied from crowdaa-sync/trunk/crowdaa-sync.php) (2 diffs)
-
tags/1.6.0/includes (copied) (copied from crowdaa-sync/trunk/includes)
-
tags/1.6.0/includes/class-crowdaa-sync-exception.php (copied) (copied from crowdaa-sync/trunk/includes/class-crowdaa-sync-exception.php)
-
tags/1.6.0/includes/class-crowdaa-sync-permissions.php (copied) (copied from crowdaa-sync/trunk/includes/class-crowdaa-sync-permissions.php) (2 diffs)
-
tags/1.6.0/includes/class-crowdaa-sync-syncdb.php (copied) (copied from crowdaa-sync/trunk/includes/class-crowdaa-sync-syncdb.php) (2 diffs)
-
tags/1.6.0/includes/class-crowdaa-sync-timer.php (copied) (copied from crowdaa-sync/trunk/includes/class-crowdaa-sync-timer.php)
-
tags/1.6.0/includes/class-crowdaa-sync-utils.php (copied) (copied from crowdaa-sync/trunk/includes/class-crowdaa-sync-utils.php) (1 diff)
-
tags/1.6.0/includes/class-crowdaa-sync-versions.php (copied) (copied from crowdaa-sync/trunk/includes/class-crowdaa-sync-versions.php)
-
tags/1.6.0/includes/class-crowdaa-sync.php (copied) (copied from crowdaa-sync/trunk/includes/class-crowdaa-sync.php)
-
tags/1.6.0/index.php (copied) (copied from crowdaa-sync/trunk/index.php)
-
tags/1.6.0/languages (copied) (copied from crowdaa-sync/trunk/languages)
-
tags/1.6.0/public (copied) (copied from crowdaa-sync/trunk/public)
-
tags/1.6.0/uninstall.php (copied) (copied from crowdaa-sync/trunk/uninstall.php)
-
tags/1.6.0/vendor (copied) (copied from crowdaa-sync/trunk/vendor)
-
tags/1.6.0/vendor/bin (copied) (copied from crowdaa-sync/trunk/vendor/bin)
-
tags/1.6.0/vendor/composer/autoload_psr4.php (copied) (copied from crowdaa-sync/trunk/vendor/composer/autoload_psr4.php)
-
tags/1.6.0/vendor/composer/autoload_static.php (copied) (copied from crowdaa-sync/trunk/vendor/composer/autoload_static.php)
-
tags/1.6.0/vendor/composer/installed.json (copied) (copied from crowdaa-sync/trunk/vendor/composer/installed.json)
-
tags/1.6.0/vendor/firebase (copied) (copied from crowdaa-sync/trunk/vendor/firebase)
-
tags/1.6.0/vendor/guzzlehttp/guzzle/CHANGELOG.md (copied) (copied from crowdaa-sync/trunk/vendor/guzzlehttp/guzzle/CHANGELOG.md)
-
tags/1.6.0/vendor/guzzlehttp/guzzle/README.md (copied) (copied from crowdaa-sync/trunk/vendor/guzzlehttp/guzzle/README.md)
-
tags/1.6.0/vendor/guzzlehttp/guzzle/composer.json (copied) (copied from crowdaa-sync/trunk/vendor/guzzlehttp/guzzle/composer.json)
-
tags/1.6.0/vendor/guzzlehttp/guzzle/src/Cookie/CookieJar.php (copied) (copied from crowdaa-sync/trunk/vendor/guzzlehttp/guzzle/src/Cookie/CookieJar.php)
-
tags/1.6.0/vendor/guzzlehttp/guzzle/src/Cookie/SetCookie.php (copied) (copied from crowdaa-sync/trunk/vendor/guzzlehttp/guzzle/src/Cookie/SetCookie.php)
-
tags/1.6.0/vendor/guzzlehttp/guzzle/src/Exception/RequestException.php (copied) (copied from crowdaa-sync/trunk/vendor/guzzlehttp/guzzle/src/Exception/RequestException.php)
-
tags/1.6.0/vendor/guzzlehttp/guzzle/src/Handler/CurlMultiHandler.php (copied) (copied from crowdaa-sync/trunk/vendor/guzzlehttp/guzzle/src/Handler/CurlMultiHandler.php)
-
tags/1.6.0/vendor/guzzlehttp/guzzle/src/Handler/StreamHandler.php (copied) (copied from crowdaa-sync/trunk/vendor/guzzlehttp/guzzle/src/Handler/StreamHandler.php)
-
tags/1.6.0/vendor/guzzlehttp/guzzle/src/MessageFormatter.php (copied) (copied from crowdaa-sync/trunk/vendor/guzzlehttp/guzzle/src/MessageFormatter.php)
-
tags/1.6.0/vendor/guzzlehttp/guzzle/src/RedirectMiddleware.php (copied) (copied from crowdaa-sync/trunk/vendor/guzzlehttp/guzzle/src/RedirectMiddleware.php)
-
tags/1.6.0/vendor/guzzlehttp/promises/CHANGELOG.md (copied) (copied from crowdaa-sync/trunk/vendor/guzzlehttp/promises/CHANGELOG.md)
-
tags/1.6.0/vendor/guzzlehttp/promises/src/EachPromise.php (copied) (copied from crowdaa-sync/trunk/vendor/guzzlehttp/promises/src/EachPromise.php)
-
tags/1.6.0/vendor/guzzlehttp/promises/src/FulfilledPromise.php (copied) (copied from crowdaa-sync/trunk/vendor/guzzlehttp/promises/src/FulfilledPromise.php)
-
tags/1.6.0/vendor/guzzlehttp/promises/src/RejectedPromise.php (copied) (copied from crowdaa-sync/trunk/vendor/guzzlehttp/promises/src/RejectedPromise.php)
-
tags/1.6.0/vendor/guzzlehttp/psr7/CHANGELOG.md (copied) (copied from crowdaa-sync/trunk/vendor/guzzlehttp/psr7/CHANGELOG.md)
-
tags/1.6.0/vendor/guzzlehttp/psr7/README.md (copied) (copied from crowdaa-sync/trunk/vendor/guzzlehttp/psr7/README.md)
-
tags/1.6.0/vendor/guzzlehttp/psr7/composer.json (copied) (copied from crowdaa-sync/trunk/vendor/guzzlehttp/psr7/composer.json)
-
tags/1.6.0/vendor/guzzlehttp/psr7/src/CachingStream.php (copied) (copied from crowdaa-sync/trunk/vendor/guzzlehttp/psr7/src/CachingStream.php)
-
tags/1.6.0/vendor/guzzlehttp/psr7/src/DroppingStream.php (copied) (copied from crowdaa-sync/trunk/vendor/guzzlehttp/psr7/src/DroppingStream.php)
-
tags/1.6.0/vendor/guzzlehttp/psr7/src/FnStream.php (copied) (copied from crowdaa-sync/trunk/vendor/guzzlehttp/psr7/src/FnStream.php)
-
tags/1.6.0/vendor/guzzlehttp/psr7/src/Header.php (copied) (copied from crowdaa-sync/trunk/vendor/guzzlehttp/psr7/src/Header.php)
-
tags/1.6.0/vendor/guzzlehttp/psr7/src/InflateStream.php (copied) (copied from crowdaa-sync/trunk/vendor/guzzlehttp/psr7/src/InflateStream.php)
-
tags/1.6.0/vendor/guzzlehttp/psr7/src/LazyOpenStream.php (copied) (copied from crowdaa-sync/trunk/vendor/guzzlehttp/psr7/src/LazyOpenStream.php)
-
tags/1.6.0/vendor/guzzlehttp/psr7/src/LimitStream.php (copied) (copied from crowdaa-sync/trunk/vendor/guzzlehttp/psr7/src/LimitStream.php)
-
tags/1.6.0/vendor/guzzlehttp/psr7/src/Message.php (copied) (copied from crowdaa-sync/trunk/vendor/guzzlehttp/psr7/src/Message.php)
-
tags/1.6.0/vendor/guzzlehttp/psr7/src/MessageTrait.php (copied) (copied from crowdaa-sync/trunk/vendor/guzzlehttp/psr7/src/MessageTrait.php)
-
tags/1.6.0/vendor/guzzlehttp/psr7/src/MimeType.php (copied) (copied from crowdaa-sync/trunk/vendor/guzzlehttp/psr7/src/MimeType.php)
-
tags/1.6.0/vendor/guzzlehttp/psr7/src/MultipartStream.php (copied) (copied from crowdaa-sync/trunk/vendor/guzzlehttp/psr7/src/MultipartStream.php)
-
tags/1.6.0/vendor/guzzlehttp/psr7/src/NoSeekStream.php (copied) (copied from crowdaa-sync/trunk/vendor/guzzlehttp/psr7/src/NoSeekStream.php)
-
tags/1.6.0/vendor/guzzlehttp/psr7/src/Query.php (copied) (copied from crowdaa-sync/trunk/vendor/guzzlehttp/psr7/src/Query.php)
-
tags/1.6.0/vendor/guzzlehttp/psr7/src/ServerRequest.php (copied) (copied from crowdaa-sync/trunk/vendor/guzzlehttp/psr7/src/ServerRequest.php)
-
tags/1.6.0/vendor/guzzlehttp/psr7/src/Stream.php (copied) (copied from crowdaa-sync/trunk/vendor/guzzlehttp/psr7/src/Stream.php)
-
tags/1.6.0/vendor/guzzlehttp/psr7/src/Uri.php (copied) (copied from crowdaa-sync/trunk/vendor/guzzlehttp/psr7/src/Uri.php)
-
tags/1.6.0/vendor/guzzlehttp/psr7/src/UriComparator.php (copied) (copied from crowdaa-sync/trunk/vendor/guzzlehttp/psr7/src/UriComparator.php)
-
tags/1.6.0/vendor/guzzlehttp/psr7/src/Utils.php (copied) (copied from crowdaa-sync/trunk/vendor/guzzlehttp/psr7/src/Utils.php)
-
tags/1.6.0/vendor/symfony/deprecation-contracts/LICENSE (copied) (copied from crowdaa-sync/trunk/vendor/symfony/deprecation-contracts/LICENSE)
-
tags/1.6.0/vendor/symfony/deprecation-contracts/composer.json (copied) (copied from crowdaa-sync/trunk/vendor/symfony/deprecation-contracts/composer.json)
-
trunk/README.txt (modified) (1 diff)
-
trunk/admin/class-crowdaa-sync-add-info-api.php (modified) (1 diff)
-
trunk/admin/class-crowdaa-sync-ext-hooks.php (modified) (2 diffs)
-
trunk/admin/class-crowdaa-sync-rest-api.php (modified) (2 diffs)
-
trunk/crowdaa-sync.php (modified) (2 diffs)
-
trunk/includes/class-crowdaa-sync-permissions.php (modified) (2 diffs)
-
trunk/includes/class-crowdaa-sync-syncdb.php (modified) (2 diffs)
-
trunk/includes/class-crowdaa-sync-utils.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
crowdaa-sync/tags/1.6.0/README.txt
r2778685 r2792490 6 6 Requires PHP: 7.3 7 7 Tested up to: 5.9 8 Stable tag: 1. 5.08 Stable tag: 1.6.0 9 9 License: GPLv2 or later 10 10 License URI: http://www.gnu.org/licenses/gpl-2.0.html -
crowdaa-sync/tags/1.6.0/admin/class-crowdaa-sync-add-info-api.php
r2776976 r2792490 150 150 if (is_object($category->picture[0]) && isset($category->picture[0]->pictureUrl)) { 151 151 $data['picture'] = $category->picture[0]->_id; 152 } else if (is_string($category->picture)) { 153 $data['picture'] = $category->picture; 152 154 } else if (is_string($category->picture[0])) { 153 155 $data['picture'] = $category->picture[0]; -
crowdaa-sync/tags/1.6.0/admin/class-crowdaa-sync-ext-hooks.php
r2778685 r2792490 31 31 public function jwt_auth_token_before_dispatch($data, $user) { 32 32 if (Crowdaa_Sync_Utils::is_crowdaa_api_request()) { 33 $data['user_id'] = $user->data->ID; 33 34 if (function_exists('pkg_autologin_generate_code') && defined('PKG_AUTOLOGIN_STAGED_CODE_USER_META_KEY')) { 34 35 $code = get_user_meta($user->data->ID, PKG_AUTOLOGIN_USER_META_KEY, True); … … 41 42 42 43 if (Crowdaa_Sync_Permissions::plugin_get()) { 43 $user_memberships = Crowdaa_Sync_Permissions::get_user_perms($user->data->ID);44 $user_memberships_ids = Crowdaa_Sync_Permissions::get_user_perms($user->data->ID); 44 45 45 if (count($user_memberships ) > 0) {46 if (count($user_memberships_ids) > 0) { 46 47 $sync_db = Crowdaa_Sync_Permissions::sync_db(); 47 $wp_ids = Crowdaa_Sync_Utils::object_array_extract_field('id', $user_memberships); 48 $synced = $sync_db->get_entry_with_wp_id($wp_ids, 'api_id'); 48 $synced = $sync_db->get_entries_with_wp_ids($user_memberships_ids, 'api_id'); 49 49 $api_ids = Crowdaa_Sync_Utils::object_array_extract_field('api_id', $synced); 50 50 $data['user_badges'] = $api_ids; -
crowdaa-sync/tags/1.6.0/admin/class-crowdaa-sync-rest-api.php
r2778685 r2792490 49 49 'permission_callback' => array($this, 'permission_allow_auth_api'), 50 50 )); 51 } 51 register_rest_route($this->namespace, 'sync/badges/users', array( 52 'methods' => 'POST', 53 'callback' => array($this, 'sync_badges'), 54 'permission_callback' => array($this, 'permission_allow_all_api'), 55 )); 56 } 57 } 58 59 public function sync_badges($request) { 60 $response = array(); 61 $parameters = $request->get_json_params(); 62 $userId = $parameters['user_id']; 63 $badges = $parameters['badges']; 64 65 $response = ['updated' => false]; 66 67 $user = get_user_by('id', $userId); 68 if (!$user) { 69 Crowdaa_Sync_Logs::log('Crowdaa_Sync_Rest_Api::sync_badges() : User not found', $userId); 70 return new WP_REST_Response($response, 200); 71 } 72 73 if (!Crowdaa_Sync_Permissions::plugin_get() || !is_array($badges)) { 74 return new WP_REST_Response($response, 200); 75 } 76 77 Crowdaa_Sync_Permissions::set_user_perms($user->data->ID, $badges); 78 79 $response['updated'] = true; 80 return new WP_REST_Response($response, 200); 52 81 } 53 82 … … 164 193 165 194 $user = wp_get_current_user(); 195 196 if (Crowdaa_Sync_Permissions::plugin_get()) { 197 $user_memberships_ids = Crowdaa_Sync_Permissions::get_user_perms($user->data->ID); 198 199 if (count($user_memberships_ids) > 0) { 200 $sync_db = Crowdaa_Sync_Permissions::sync_db(); 201 $synced = $sync_db->get_entries_with_wp_ids($user_memberships_ids, 'api_id'); 202 $api_ids = Crowdaa_Sync_Utils::object_array_extract_field('api_id', $synced); 203 $response['user_badges'] = $api_ids; 204 } 205 } 206 207 $response['user_id'] = $user->data->ID; 208 166 209 $response = apply_filters('crowdaa_sync_api_session_checks', $response, $user); 167 210 -
crowdaa-sync/tags/1.6.0/crowdaa-sync.php
r2778685 r2792490 14 14 * Plugin URI: 15 15 * Description: Plugin for synchronizing WordPress site and Crowdaa CMS 16 * Version: 1. 5.016 * Version: 1.6.0 17 17 * Requires at least: 5.5 18 18 * Requires PHP: 7.2 … … 34 34 * Uses SemVer - https://semver.org 35 35 */ 36 define('CROWDAA_SYNC_VERSION', '1. 5.0');36 define('CROWDAA_SYNC_VERSION', '1.6.0'); 37 37 define('CROWDAA_SYNC_PLUGIN_DIR', __DIR__); 38 38 define('CROWDAA_SYNC_PLUGIN_NAME', 'crowdaa-sync'); -
crowdaa-sync/tags/1.6.0/includes/class-crowdaa-sync-permissions.php
r2776976 r2792490 566 566 ], 'id'); 567 567 568 return ($user_memberships); 569 } 570 571 public static function get_user_perms__swpm($userId) { 568 $memberships_ids = Crowdaa_Sync_Utils::object_array_extract_field('id', $user_memberships); 569 570 return ($memberships_ids); 571 } 572 573 private static function get_user_perms__swpm($userId) { 572 574 $user = get_user_by('id', $userId); 573 575 $memberships = Crowdaa_Sync_Utils::quick_select(self::swpm_members_table(), [ … … 576 578 ]); 577 579 578 $ret = Crowdaa_Sync_Utils::object_array_extract_field('membership_level', $memberships); 579 580 return ($ret); 580 $memberships_ids = Crowdaa_Sync_Utils::object_array_extract_field('membership_level', $memberships); 581 582 return ($memberships_ids); 583 } 584 585 public static function set_user_perms($userId, $badges) { 586 $plugin = self::plugin_get(); 587 if (!$plugin) throw new Crowdaa_Sync_Error('Missing plugin for Crowdaa_Sync_Permissions::set_user_perms()'); 588 589 $alias = self::$all_plugins[$plugin]['alias']; 590 $function = 'set_user_perms__'.$alias; 591 592 return(self::$function($userId)); 593 } 594 595 private static function set_user_perms__pmpro($userId, $badges) { 596 global $wpdb; 597 $sync_db = self::sync_db(); 598 $syncedIds = $sync_db->get_entries_with_api_ids($badges, 'wp_id'); 599 $syncedIds = Crowdaa_Sync_Utils::object_array_extract_field('wp_id', $syncedIds); 600 601 $memberships = Crowdaa_Sync_Utils::quick_select($wpdb->pmpro_memberships_users, [ 602 'user_id' => $userId, 603 'status' => 'active', 604 ], 'id'); 605 $membershipsIds = Crowdaa_Sync_Utils::object_array_extract_field('membership_id', $memberships); 606 607 $toAdd = []; 608 $toDelete = []; 609 610 foreach ($syncedIds as $id) { 611 if (array_search($id, $membershipsIds) === false) { 612 $toAdd[] = $id; 613 } 614 } 615 616 foreach ($membershipsIds as $id) { 617 if (array_search($id, $syncedIds) === false) { 618 $toDelete[] = $syncedId; 619 } 620 } 621 622 $user_registered = explode(' ', $user->data->user_registered); 623 foreach ($toAdd as $id) { 624 Crowdaa_Sync_Utils::quick_insert($wpdb->pmpro_memberships_users, [ 625 'user_id' => $userId, 626 'status' => 'active', 627 'membership_id' => $id, 628 'code_id' => 0, 629 'initial_payment' => 0.0, 630 'billing_amount' => 0.0, 631 'cycle_number' => 0, 632 'billing_limit' => 0, 633 'trial_amount' => 0.0, 634 'trial_limit' => 0, 635 'status' => 'active', 636 'startdate' => $user_registered[0], 637 ]); 638 } 639 640 foreach ($toDelete as $id) { 641 Crowdaa_Sync_Utils::quick_delete($wpdb->pmpro_memberships_users, [ 642 'user_id' => $userId, 643 'status' => 'active', 644 'membership_id' => $id, 645 ]); 646 } 647 } 648 649 private static function set_user_perms__swpm($userId, $badges) { 650 $user = get_user_by('id', $userId); 651 $sync_db = self::sync_db(); 652 653 $memberships = Crowdaa_Sync_Utils::quick_select(self::swpm_members_table(), [ 654 'username' => $user->data->user_login, 655 'account_state' => 'active', 656 ]); 657 658 if (count($badges) > 0 && count($memberships) > 0) { 659 $syncedIds = $sync_db->get_entries_with_api_ids($badges, 'wp_id'); 660 if ($count($syncedIds) > 0) { 661 $firstSyncedId = $syncedIds[0]->wp_id; 662 Crowdaa_Sync_Utils::quick_update(self::swpm_members_table(), [ 663 'ID' => $memberships->ID, 664 ], [ 665 'membership_level' => $firstSyncedId, 666 ]); 667 } 668 } else if (count($badges) == 0 && count($memberships) > 0) { 669 Crowdaa_Sync_Utils::quick_delete(self::swpm_members_table(), [ 670 'ID' => $memberships->ID, 671 ]); 672 } else if (count($badges) > 0 && count($memberships) == 0) { 673 $user_registered = explode(' ', $user->data->user_registered); 674 675 Crowdaa_Sync_Utils::quick_insert(self::swpm_members_table(), [ 676 "member_id" => 2, 677 "user_name" => $user->user_login, 678 "first_name" => '', 679 "last_name" => '', 680 "password" => $user->user_pass, 681 "member_since" => $user_registered[0], 682 "membership_level" => 2, 683 "more_membership_levels" => NULL, 684 "account_state" => 'active', 685 "last_accessed_from_ip" => '', 686 "email" => $user->data->user_email, 687 "phone" => '', 688 "address_street" => '', 689 "address_city" => '', 690 "address_state" => '', 691 "address_zipcode" => '', 692 "country" => '', 693 "gender" => 'not specified', 694 "subscription_starts" => $user_registered[0], 695 "txn_id" => '', 696 "subscr_id" => '', 697 "company_name" => '', 698 "flags" => 0, 699 "profile_image" => '', 700 ]); 701 } 702 703 return ($memberships_ids); 581 704 } 582 705 -
crowdaa-sync/tags/1.6.0/includes/class-crowdaa-sync-syncdb.php
r2744975 r2792490 161 161 if (is_array($whereData)) { 162 162 $whereINQuery = implode(', ', array_fill(0, count($whereData), '%s')); 163 $whereStr = $whereField.' in ['.$whereINQuery.']';163 $whereStr = $whereField.' in ('.$whereINQuery.')'; 164 164 $whereArg = $whereData; 165 165 } else { … … 204 204 205 205 /** 206 * Get entries with the specified WP IDs (as an araray). 207 */ 208 public function get_entries_with_wp_ids($wp_ids, $fields = null) { 209 global $wpdb; 210 211 list($whereStr, $whereArg) = self::prepare_wherein($wp_ids, 'wp_id'); 212 $fields = self::prepare_fields($fields); 213 214 $result = $wpdb->get_results($wpdb->prepare("SELECT $fields FROM `$this->tableName` WHERE $whereStr", ...$whereArg), OBJECT_K); 215 216 self::unserialize_data($result); 217 218 return ($result); 219 } 220 221 /** 222 * Get entries with the specified API IDs (as an araray). 223 */ 224 public function get_entries_with_api_ids($api_ids, $fields = null) { 225 global $wpdb; 226 227 list($whereStr, $whereArg) = self::prepare_wherein($api_ids, 'api_id'); 228 $fields = self::prepare_fields($fields); 229 230 $result = $wpdb->get_results($wpdb->prepare("SELECT $fields FROM `$this->tableName` WHERE $whereStr", ...$whereArg), OBJECT_K); 231 232 self::unserialize_data($result); 233 234 return ($result); 235 } 236 237 /** 206 238 * Get an entry with the specified internal ID. 207 239 */ -
crowdaa-sync/tags/1.6.0/includes/class-crowdaa-sync-utils.php
r2778568 r2792490 156 156 */ 157 157 public static function object_array_extract_field($field, $array) { 158 $ret = array_map(function($item) {159 return ($item->$field);160 }, $array);161 158 $ret = []; 159 foreach ($array as $item) { 160 $ret[] = $item->$field; 161 } 162 162 return ($ret); 163 163 } -
crowdaa-sync/trunk/README.txt
r2778685 r2792490 6 6 Requires PHP: 7.3 7 7 Tested up to: 5.9 8 Stable tag: 1. 5.08 Stable tag: 1.6.0 9 9 License: GPLv2 or later 10 10 License URI: http://www.gnu.org/licenses/gpl-2.0.html -
crowdaa-sync/trunk/admin/class-crowdaa-sync-add-info-api.php
r2776976 r2792490 150 150 if (is_object($category->picture[0]) && isset($category->picture[0]->pictureUrl)) { 151 151 $data['picture'] = $category->picture[0]->_id; 152 } else if (is_string($category->picture)) { 153 $data['picture'] = $category->picture; 152 154 } else if (is_string($category->picture[0])) { 153 155 $data['picture'] = $category->picture[0]; -
crowdaa-sync/trunk/admin/class-crowdaa-sync-ext-hooks.php
r2778685 r2792490 31 31 public function jwt_auth_token_before_dispatch($data, $user) { 32 32 if (Crowdaa_Sync_Utils::is_crowdaa_api_request()) { 33 $data['user_id'] = $user->data->ID; 33 34 if (function_exists('pkg_autologin_generate_code') && defined('PKG_AUTOLOGIN_STAGED_CODE_USER_META_KEY')) { 34 35 $code = get_user_meta($user->data->ID, PKG_AUTOLOGIN_USER_META_KEY, True); … … 41 42 42 43 if (Crowdaa_Sync_Permissions::plugin_get()) { 43 $user_memberships = Crowdaa_Sync_Permissions::get_user_perms($user->data->ID);44 $user_memberships_ids = Crowdaa_Sync_Permissions::get_user_perms($user->data->ID); 44 45 45 if (count($user_memberships ) > 0) {46 if (count($user_memberships_ids) > 0) { 46 47 $sync_db = Crowdaa_Sync_Permissions::sync_db(); 47 $wp_ids = Crowdaa_Sync_Utils::object_array_extract_field('id', $user_memberships); 48 $synced = $sync_db->get_entry_with_wp_id($wp_ids, 'api_id'); 48 $synced = $sync_db->get_entries_with_wp_ids($user_memberships_ids, 'api_id'); 49 49 $api_ids = Crowdaa_Sync_Utils::object_array_extract_field('api_id', $synced); 50 50 $data['user_badges'] = $api_ids; -
crowdaa-sync/trunk/admin/class-crowdaa-sync-rest-api.php
r2778685 r2792490 49 49 'permission_callback' => array($this, 'permission_allow_auth_api'), 50 50 )); 51 } 51 register_rest_route($this->namespace, 'sync/badges/users', array( 52 'methods' => 'POST', 53 'callback' => array($this, 'sync_badges'), 54 'permission_callback' => array($this, 'permission_allow_all_api'), 55 )); 56 } 57 } 58 59 public function sync_badges($request) { 60 $response = array(); 61 $parameters = $request->get_json_params(); 62 $userId = $parameters['user_id']; 63 $badges = $parameters['badges']; 64 65 $response = ['updated' => false]; 66 67 $user = get_user_by('id', $userId); 68 if (!$user) { 69 Crowdaa_Sync_Logs::log('Crowdaa_Sync_Rest_Api::sync_badges() : User not found', $userId); 70 return new WP_REST_Response($response, 200); 71 } 72 73 if (!Crowdaa_Sync_Permissions::plugin_get() || !is_array($badges)) { 74 return new WP_REST_Response($response, 200); 75 } 76 77 Crowdaa_Sync_Permissions::set_user_perms($user->data->ID, $badges); 78 79 $response['updated'] = true; 80 return new WP_REST_Response($response, 200); 52 81 } 53 82 … … 164 193 165 194 $user = wp_get_current_user(); 195 196 if (Crowdaa_Sync_Permissions::plugin_get()) { 197 $user_memberships_ids = Crowdaa_Sync_Permissions::get_user_perms($user->data->ID); 198 199 if (count($user_memberships_ids) > 0) { 200 $sync_db = Crowdaa_Sync_Permissions::sync_db(); 201 $synced = $sync_db->get_entries_with_wp_ids($user_memberships_ids, 'api_id'); 202 $api_ids = Crowdaa_Sync_Utils::object_array_extract_field('api_id', $synced); 203 $response['user_badges'] = $api_ids; 204 } 205 } 206 207 $response['user_id'] = $user->data->ID; 208 166 209 $response = apply_filters('crowdaa_sync_api_session_checks', $response, $user); 167 210 -
crowdaa-sync/trunk/crowdaa-sync.php
r2778685 r2792490 14 14 * Plugin URI: 15 15 * Description: Plugin for synchronizing WordPress site and Crowdaa CMS 16 * Version: 1. 5.016 * Version: 1.6.0 17 17 * Requires at least: 5.5 18 18 * Requires PHP: 7.2 … … 34 34 * Uses SemVer - https://semver.org 35 35 */ 36 define('CROWDAA_SYNC_VERSION', '1. 5.0');36 define('CROWDAA_SYNC_VERSION', '1.6.0'); 37 37 define('CROWDAA_SYNC_PLUGIN_DIR', __DIR__); 38 38 define('CROWDAA_SYNC_PLUGIN_NAME', 'crowdaa-sync'); -
crowdaa-sync/trunk/includes/class-crowdaa-sync-permissions.php
r2776976 r2792490 566 566 ], 'id'); 567 567 568 return ($user_memberships); 569 } 570 571 public static function get_user_perms__swpm($userId) { 568 $memberships_ids = Crowdaa_Sync_Utils::object_array_extract_field('id', $user_memberships); 569 570 return ($memberships_ids); 571 } 572 573 private static function get_user_perms__swpm($userId) { 572 574 $user = get_user_by('id', $userId); 573 575 $memberships = Crowdaa_Sync_Utils::quick_select(self::swpm_members_table(), [ … … 576 578 ]); 577 579 578 $ret = Crowdaa_Sync_Utils::object_array_extract_field('membership_level', $memberships); 579 580 return ($ret); 580 $memberships_ids = Crowdaa_Sync_Utils::object_array_extract_field('membership_level', $memberships); 581 582 return ($memberships_ids); 583 } 584 585 public static function set_user_perms($userId, $badges) { 586 $plugin = self::plugin_get(); 587 if (!$plugin) throw new Crowdaa_Sync_Error('Missing plugin for Crowdaa_Sync_Permissions::set_user_perms()'); 588 589 $alias = self::$all_plugins[$plugin]['alias']; 590 $function = 'set_user_perms__'.$alias; 591 592 return(self::$function($userId)); 593 } 594 595 private static function set_user_perms__pmpro($userId, $badges) { 596 global $wpdb; 597 $sync_db = self::sync_db(); 598 $syncedIds = $sync_db->get_entries_with_api_ids($badges, 'wp_id'); 599 $syncedIds = Crowdaa_Sync_Utils::object_array_extract_field('wp_id', $syncedIds); 600 601 $memberships = Crowdaa_Sync_Utils::quick_select($wpdb->pmpro_memberships_users, [ 602 'user_id' => $userId, 603 'status' => 'active', 604 ], 'id'); 605 $membershipsIds = Crowdaa_Sync_Utils::object_array_extract_field('membership_id', $memberships); 606 607 $toAdd = []; 608 $toDelete = []; 609 610 foreach ($syncedIds as $id) { 611 if (array_search($id, $membershipsIds) === false) { 612 $toAdd[] = $id; 613 } 614 } 615 616 foreach ($membershipsIds as $id) { 617 if (array_search($id, $syncedIds) === false) { 618 $toDelete[] = $syncedId; 619 } 620 } 621 622 $user_registered = explode(' ', $user->data->user_registered); 623 foreach ($toAdd as $id) { 624 Crowdaa_Sync_Utils::quick_insert($wpdb->pmpro_memberships_users, [ 625 'user_id' => $userId, 626 'status' => 'active', 627 'membership_id' => $id, 628 'code_id' => 0, 629 'initial_payment' => 0.0, 630 'billing_amount' => 0.0, 631 'cycle_number' => 0, 632 'billing_limit' => 0, 633 'trial_amount' => 0.0, 634 'trial_limit' => 0, 635 'status' => 'active', 636 'startdate' => $user_registered[0], 637 ]); 638 } 639 640 foreach ($toDelete as $id) { 641 Crowdaa_Sync_Utils::quick_delete($wpdb->pmpro_memberships_users, [ 642 'user_id' => $userId, 643 'status' => 'active', 644 'membership_id' => $id, 645 ]); 646 } 647 } 648 649 private static function set_user_perms__swpm($userId, $badges) { 650 $user = get_user_by('id', $userId); 651 $sync_db = self::sync_db(); 652 653 $memberships = Crowdaa_Sync_Utils::quick_select(self::swpm_members_table(), [ 654 'username' => $user->data->user_login, 655 'account_state' => 'active', 656 ]); 657 658 if (count($badges) > 0 && count($memberships) > 0) { 659 $syncedIds = $sync_db->get_entries_with_api_ids($badges, 'wp_id'); 660 if ($count($syncedIds) > 0) { 661 $firstSyncedId = $syncedIds[0]->wp_id; 662 Crowdaa_Sync_Utils::quick_update(self::swpm_members_table(), [ 663 'ID' => $memberships->ID, 664 ], [ 665 'membership_level' => $firstSyncedId, 666 ]); 667 } 668 } else if (count($badges) == 0 && count($memberships) > 0) { 669 Crowdaa_Sync_Utils::quick_delete(self::swpm_members_table(), [ 670 'ID' => $memberships->ID, 671 ]); 672 } else if (count($badges) > 0 && count($memberships) == 0) { 673 $user_registered = explode(' ', $user->data->user_registered); 674 675 Crowdaa_Sync_Utils::quick_insert(self::swpm_members_table(), [ 676 "member_id" => 2, 677 "user_name" => $user->user_login, 678 "first_name" => '', 679 "last_name" => '', 680 "password" => $user->user_pass, 681 "member_since" => $user_registered[0], 682 "membership_level" => 2, 683 "more_membership_levels" => NULL, 684 "account_state" => 'active', 685 "last_accessed_from_ip" => '', 686 "email" => $user->data->user_email, 687 "phone" => '', 688 "address_street" => '', 689 "address_city" => '', 690 "address_state" => '', 691 "address_zipcode" => '', 692 "country" => '', 693 "gender" => 'not specified', 694 "subscription_starts" => $user_registered[0], 695 "txn_id" => '', 696 "subscr_id" => '', 697 "company_name" => '', 698 "flags" => 0, 699 "profile_image" => '', 700 ]); 701 } 702 703 return ($memberships_ids); 581 704 } 582 705 -
crowdaa-sync/trunk/includes/class-crowdaa-sync-syncdb.php
r2744975 r2792490 161 161 if (is_array($whereData)) { 162 162 $whereINQuery = implode(', ', array_fill(0, count($whereData), '%s')); 163 $whereStr = $whereField.' in ['.$whereINQuery.']';163 $whereStr = $whereField.' in ('.$whereINQuery.')'; 164 164 $whereArg = $whereData; 165 165 } else { … … 204 204 205 205 /** 206 * Get entries with the specified WP IDs (as an araray). 207 */ 208 public function get_entries_with_wp_ids($wp_ids, $fields = null) { 209 global $wpdb; 210 211 list($whereStr, $whereArg) = self::prepare_wherein($wp_ids, 'wp_id'); 212 $fields = self::prepare_fields($fields); 213 214 $result = $wpdb->get_results($wpdb->prepare("SELECT $fields FROM `$this->tableName` WHERE $whereStr", ...$whereArg), OBJECT_K); 215 216 self::unserialize_data($result); 217 218 return ($result); 219 } 220 221 /** 222 * Get entries with the specified API IDs (as an araray). 223 */ 224 public function get_entries_with_api_ids($api_ids, $fields = null) { 225 global $wpdb; 226 227 list($whereStr, $whereArg) = self::prepare_wherein($api_ids, 'api_id'); 228 $fields = self::prepare_fields($fields); 229 230 $result = $wpdb->get_results($wpdb->prepare("SELECT $fields FROM `$this->tableName` WHERE $whereStr", ...$whereArg), OBJECT_K); 231 232 self::unserialize_data($result); 233 234 return ($result); 235 } 236 237 /** 206 238 * Get an entry with the specified internal ID. 207 239 */ -
crowdaa-sync/trunk/includes/class-crowdaa-sync-utils.php
r2778568 r2792490 156 156 */ 157 157 public static function object_array_extract_field($field, $array) { 158 $ret = array_map(function($item) {159 return ($item->$field);160 }, $array);161 158 $ret = []; 159 foreach ($array as $item) { 160 $ret[] = $item->$field; 161 } 162 162 return ($ret); 163 163 }
Note: See TracChangeset
for help on using the changeset viewer.