diff --git a/README.md b/README.md index 900725c..e4e3d0b 100644 --- a/README.md +++ b/README.md @@ -198,6 +198,12 @@ You should see that: ## Changelog +### 4.x-1.2.2 + +* Custom taxonomy support +* User mapping pagination +* Better detection for the installed version of ACF + ### 4.x-1.2.1 * Added Post Syncing - changes from Percolate automatically get picked up @@ -271,4 +277,4 @@ please refer to the original repository: *** _Please do not remove this version declaration_ -~Current Version:4.x-1.2.1~ +~Current Version:4.x-1.2.2~ diff --git a/api/models/percolate-acf-model.php b/api/models/percolate-acf-model.php index 6199a3a..8879139 100644 --- a/api/models/percolate-acf-model.php +++ b/api/models/percolate-acf-model.php @@ -19,12 +19,23 @@ public function __construct() { public function get_ACF_data() { - if ( is_plugin_active( 'advanced-custom-fields/acf.php' ) ) { - // Percolate_Log::log('ACF v4 active'); - $this->acf = 'v4'; - } else if ( is_plugin_active( 'advanced-custom-fields-pro/acf.php' ) ) { - // Percolate_Log::log('ACF v5 active'); - $this->acf = 'v5'; + global $acf; + + if (isset($acf)) + { + // Percolate_Log::log($acf->settings['version']); + $_ver = $acf->settings['version']; + + if (version_compare($_ver, '5.0.0') >= 0) { + $this->acf = 'v5'; + } + elseif (version_compare($_ver, '4.0.0') >= 0) { + $this->acf = 'v4'; + } else { + $this->acf = null; + } + // Percolate_Log::log('ACF version: ' . $this->acf); + } else { $this->acf = null; } @@ -35,11 +46,9 @@ public function get_ACF_data() */ public function getAcfStatus() { - // // We don't want ACF for now - // echo false; - // wp_die(); + global $acf; - if ( is_plugin_active( 'advanced-custom-fields/acf.php' ) || is_plugin_active( 'advanced-custom-fields-pro/acf.php' ) ) { + if ( isset($acf) ) { echo true; wp_die(); } else { @@ -63,13 +72,12 @@ public function getAcfData() public function getAcfGroups() { - if ($this->acf && $this->acf == 'v5'){ - $this->acfGroups = get_posts(array('posts_per_page' => -1, 'post_type' => 'acf-field-group')); - } - else - { - $this->acfGroups = get_posts(array('posts_per_page' => -1, 'post_type' => 'acf')); - } + if ($this->acf == 'v5') { + $this->acfGroups = get_posts(array('posts_per_page' => -1, 'post_type' => 'acf-field-group')); + } else { + $this->acfGroups = get_posts(array('posts_per_page' => -1, 'post_type' => 'acf')); + } + return $this->acfGroups; } @@ -83,10 +91,11 @@ public function getAcfFields() $all_existing_acf[$group->ID] = array(); - if ($this->acf == 'v5' ){ + if ($this->acf == 'v5' || $this->acf == 'v55' ){ $fields = get_posts(array('posts_per_page' => -1, 'post_type' => 'acf-field', 'post_parent' => $group->ID)); foreach ($fields as $field) { + // Percolate_Log::log('Fields: ' . print_r($field, true)); // Percolate_Log::log('Fields: ' . print_r(unserialize( $field->post_content ), true)); $all_existing_acf[$group->ID][] = array( 'key' => $field->post_name, diff --git a/api/models/percolate-post-model.php b/api/models/percolate-post-model.php index 6b95f4c..c84eeb4 100644 --- a/api/models/percolate-post-model.php +++ b/api/models/percolate-post-model.php @@ -591,6 +591,16 @@ public function importPost($post, $template, $schema, $channel, $wpPostID = null } } + // ----------- Custom Taxonomies -------------- + if ( isset($template->taxonomy) && $template->taxonomy == 'on' && isset($template->taxonomyField) && isset($template->taxonomyWP) ) { + $terms = $post['ext'][$template->taxonomyField]; + if (!is_array($terms)) { + $terms = explode(',', $terms); + } + Percolate_Log::log("Mapping {$template->taxonomyField} to {$template->taxonomyWP}, terms: " . print_r($terms, true)); + wp_set_object_terms($wpPostID, $terms, $template->taxonomyWP, false); + } + // ----------- Featured image -------------- if ( isset($template->image) && $template->image == 'on' && isset($template->postImage) && isset($importedFields[$template->postImage]) ) { // Gegt image ID from the imported fields array diff --git a/api/models/percolate-wp-model.php b/api/models/percolate-wp-model.php index 4d6529c..e60f8dc 100644 --- a/api/models/percolate-wp-model.php +++ b/api/models/percolate-wp-model.php @@ -116,6 +116,22 @@ public function getCategories() return $categories; } + /** + * Get custom taxonomies + * + * @return array|false Taxonomies + */ + public function getTaxonomies() + { + $args = array( + 'public' => true, + '_builtin' => false + + ); + $taxonomies = get_taxonomies( $args, 'objects', 'and' ); + return $taxonomies; + } + /** * Get WP users diff --git a/api/services/percolate-ajax-service.php b/api/services/percolate-ajax-service.php index c151ea8..e38542f 100644 --- a/api/services/percolate-ajax-service.php +++ b/api/services/percolate-ajax-service.php @@ -39,8 +39,10 @@ public function __construct( add_action( 'wp_ajax_set_data', array( $this, 'setData' ) ); // Get WP categories add_action( 'wp_ajax_get_cpts', array( $this, 'getCpts' ) ); - // Get WP post types + // Get WP categories add_action( 'wp_ajax_get_categories', array( $this, 'getCategories' ) ); + // Get WP taxonomies + add_action( 'wp_ajax_get_taxonomies', array( $this, 'getTaxonomies' ) ); // Get WP users add_action( 'wp_ajax_get_users', array( $this, 'getUsers' ) ); // Is ACF active @@ -115,6 +117,16 @@ public function getCategories() wp_die(); } + /** + * Get WP custom taxonomies + */ + public function getTaxonomies() + { + $categories = $this->Wp->getTaxonomies(); + echo json_encode($categories); + wp_die(); + } + /** * Get WP users */ diff --git a/frontend/scripts/api/api.js b/frontend/scripts/api/api.js index 9b3a1fb..1e41688 100644 --- a/frontend/scripts/api/api.js +++ b/frontend/scripts/api/api.js @@ -39,6 +39,14 @@ angular.module('wpApi', []) data : jQuery.param({ action : 'get_categories'}) }) }, + getTaxonomies: function () { + return $http({ + method : 'POST', + url : _url, + headers : {'Content-Type': 'application/x-www-form-urlencoded'}, + data : jQuery.param({ action : 'get_taxonomies'}) + }) + }, getUsers: function () { return $http({ method : 'POST', diff --git a/frontend/scripts/settings/controllers/add.templates.js b/frontend/scripts/settings/controllers/add.templates.js index ff26a57..b36b86f 100644 --- a/frontend/scripts/settings/controllers/add.templates.js +++ b/frontend/scripts/settings/controllers/add.templates.js @@ -57,7 +57,6 @@ angular.module('myApp') function getTemplateSchemas(res) { console.log('Schemas', res.data) - $scope.stopLoader() if( !res.data || !res.data.data ) { $scope.showError('There was an error.') @@ -109,6 +108,14 @@ angular.module('myApp') }) } } + return Api.getTaxonomies() + } + + function getTaxonomies(res) { + console.log('Taxonomies', res) + if (res.data) { + $scope.taxonomies = res.data + } return Api.getWpmlStatus() } @@ -124,6 +131,7 @@ angular.module('myApp') } function getMetaBoxData (res) { + $scope.stopLoader() if ($scope.isMetaBoxActive) { $scope.metaboxGroups = res.data.groups } @@ -214,6 +222,7 @@ angular.module('myApp') .then(getCpts, apiError) .then(getAcfStatus, apiError) .then(getAcfData, apiError) + .then(getTaxonomies, apiError) .then(getWpmlStatus, apiError) .then(getMetaBoxStatus, apiError) .then(getMetaBoxData, apiError) @@ -234,6 +243,9 @@ angular.module('myApp') }) .filter('filterType', function () { return function (list, type) { + if(Array.isArray(type)) { + return _.filter(list, function(obj){ return type.indexOf(obj.type) > -1 }) + } return _.filter(list, function(obj){ return obj.type === type }) } }) diff --git a/frontend/scripts/settings/controllers/add.topics.js b/frontend/scripts/settings/controllers/add.topics.js index d61897b..2ec850d 100644 --- a/frontend/scripts/settings/controllers/add.topics.js +++ b/frontend/scripts/settings/controllers/add.topics.js @@ -1,7 +1,9 @@ 'use strict'; +var PAGINATION_LIMIT = 10 + angular.module('myApp') - .controller('AddTopicsCtr', function ($scope, $state, Api, Percolate) { + .controller('AddTopicsCtr', function ($scope, $state, Api, Percolate, Pagination) { console.log('Add New Channel - Topics state') /* -------------------------------------- @@ -55,14 +57,27 @@ angular.module('myApp') function processPercolateTopics (res) { console.log('Topics', res.data) - if ($scope.percolateUsers) $scope.stopLoader() + if ($scope.percolateUsers) { $scope.stopLoader() } if( !res.data || !res.data.data ) { $scope.showError('There was an error.') return } - return $scope.topics = res.data.data + $scope.topics = res.data.data + } + + function fetchPercolatUsers(paginationData) { + $scope.showLoader('Loading users from Percolate...') + $scope.percolateUsers = null + return Percolate.getUsersByLicense({ + key : $scope.activeChannel.key, + license: $scope.activeChannel.license, + fields : { + limit: (paginationData && paginationData.limit) ? paginationData.limit : PAGINATION_LIMIT, + offset: (paginationData && paginationData.offset) ? paginationData.offset : 0 + } + }).then(processPercolateUsers, apiError) } function processPercolateUsers(res){ @@ -73,7 +88,7 @@ angular.module('myApp') $scope.showError('There was an error.') return } - + $scope.userPagination = Pagination.build(res.data.pagination) $scope.percolateUsers = res.data.data } @@ -156,6 +171,11 @@ angular.module('myApp') * Bootstrap * -------------------------------------- */ + + angular.extend($scope, { + fetchPercolatUsers: fetchPercolatUsers + }) + // Check if we have the active User if( !$scope.activeChannel.user ) { $scope.showError('No active user found.') @@ -163,7 +183,7 @@ angular.module('myApp') } // Get Percolate topics - $scope.showLoader('Getting data from Percolate...') + $scope.showLoader('Loading data from Percolate...') Percolate.getTopics({ key : $scope.activeChannel.key, fields : { @@ -171,14 +191,7 @@ angular.module('myApp') } }).then(processPercolateTopics, apiError) - Percolate.getUsersByLicense({ - key : $scope.activeChannel.key, - license: $scope.activeChannel.license, - fields : { - limit: 100, - offset: 0 - } - }).then(processPercolateUsers, apiError) + fetchPercolatUsers() // Get WP users Api.getUsers().then(processWpUsers, apiError) diff --git a/frontend/scripts/settings/services/pagination.service.js b/frontend/scripts/settings/services/pagination.service.js new file mode 100644 index 0000000..11e60ca --- /dev/null +++ b/frontend/scripts/settings/services/pagination.service.js @@ -0,0 +1,68 @@ +'use strict'; + +angular.module('myApp') + .service('Pagination', function() { + + function build(paginationData) { + if (!paginationData.total) { return false } + var _pagination = { + pages: Math.floor(paginationData.total/paginationData.limit) + 1, + offsets: [], + activePage: paginationData.offset / paginationData.limit, + } + + if (_pagination.pages > 10) { + var _start = 0 + if (_pagination.activePage - 4 > 0) { + _start = _pagination.activePage - 4 + } + + var _end = _start + 8 + if (_end > _pagination.pages - 1) { + _end = _pagination.pages - 1 + } + + for (var i = _start; i < _end; i++) { + _pagination.offsets.push({ + label: i+1, + offset: paginationData.limit * i, + limit: paginationData.limit, + active: paginationData.offset === paginationData.limit * i ? true : false + }) + } + + if ( _pagination.activePage > 4) { + _pagination.prev = { + label: _pagination.activePage - 1, + offset: _start, + limit: paginationData.limit + } + } + if (_pagination.activePage < _pagination.pages - 5) { + _pagination.next = { + label: _pagination.activePage + 1, + offset: _end, + limit: paginationData.limit + } + } + + } else { + + for (var i = 0; i <_pagination.pages; i++) { + _pagination.offsets.push({ + label: i+1, + offset: paginationData.limit * i, + limit: paginationData.limit, + active: paginationData.offset === paginationData.limit * i ? true : false + }) + } + + } + console.log(_pagination); + return _pagination + } + + return { + build : build + } + }) diff --git a/frontend/views/templates/new-channel-templates.php b/frontend/views/templates/new-channel-templates.php index 831ac9a..0b1504a 100644 --- a/frontend/views/templates/new-channel-templates.php +++ b/frontend/views/templates/new-channel-templates.php @@ -139,6 +139,40 @@ + +
Loading users from Percolate...
+
- Plugin version: 4.x-1.2.1 (Supported WordPress version - Plugin version)
+
+ Plugin version: 4.x-1.2.2 (Supported WordPress version - Plugin version)
+ PHP >= 5.6 required for the plugin to function properly
+