Changeset 2722017
- Timestamp:
- 05/11/2022 01:36:27 PM (4 years ago)
- Location:
- crowdaa-sync
- Files:
-
- 2 added
- 21 edited
- 14 copied
-
tags/1.1.0 (copied) (copied from crowdaa-sync/trunk)
-
tags/1.1.0/CHANGELOG (copied) (copied from crowdaa-sync/trunk/CHANGELOG) (2 diffs)
-
tags/1.1.0/LICENSE.txt (copied) (copied from crowdaa-sync/trunk/LICENSE.txt)
-
tags/1.1.0/README.txt (copied) (copied from crowdaa-sync/trunk/README.txt) (1 diff)
-
tags/1.1.0/admin (copied) (copied from crowdaa-sync/trunk/admin)
-
tags/1.1.0/admin/class-crowdaa-sync-add-info-api.php (modified) (16 diffs)
-
tags/1.1.0/admin/class-crowdaa-sync-admin-display.php (modified) (1 diff)
-
tags/1.1.0/admin/class-crowdaa-sync-api.php (modified) (17 diffs)
-
tags/1.1.0/admin/class-crowdaa-sync-ext-hooks.php (added)
-
tags/1.1.0/admin/class-crowdaa-sync-meta-box.php (modified) (6 diffs)
-
tags/1.1.0/admin/css/crowdaa-sync-admin.css (modified) (6 diffs)
-
tags/1.1.0/admin/js/crowdaa-sync-admin.js (modified) (1 diff)
-
tags/1.1.0/admin/partials/crowdaa-sync-admin-display.php (modified) (5 diffs)
-
tags/1.1.0/cacert.pem (copied) (copied from crowdaa-sync/trunk/cacert.pem)
-
tags/1.1.0/composer.json (copied) (copied from crowdaa-sync/trunk/composer.json)
-
tags/1.1.0/crowdaa-sync.php (copied) (copied from crowdaa-sync/trunk/crowdaa-sync.php) (4 diffs)
-
tags/1.1.0/includes (copied) (copied from crowdaa-sync/trunk/includes)
-
tags/1.1.0/includes/class-crowdaa-sync-versions.php (modified) (2 diffs)
-
tags/1.1.0/includes/class-crowdaa-sync.php (modified) (1 diff)
-
tags/1.1.0/index.php (copied) (copied from crowdaa-sync/trunk/index.php)
-
tags/1.1.0/languages (copied) (copied from crowdaa-sync/trunk/languages)
-
tags/1.1.0/public (copied) (copied from crowdaa-sync/trunk/public)
-
tags/1.1.0/uninstall.php (copied) (copied from crowdaa-sync/trunk/uninstall.php)
-
tags/1.1.0/vendor (copied) (copied from crowdaa-sync/trunk/vendor)
-
trunk/CHANGELOG (modified) (2 diffs)
-
trunk/README.txt (modified) (1 diff)
-
trunk/admin/class-crowdaa-sync-add-info-api.php (modified) (16 diffs)
-
trunk/admin/class-crowdaa-sync-admin-display.php (modified) (1 diff)
-
trunk/admin/class-crowdaa-sync-api.php (modified) (17 diffs)
-
trunk/admin/class-crowdaa-sync-ext-hooks.php (added)
-
trunk/admin/class-crowdaa-sync-meta-box.php (modified) (6 diffs)
-
trunk/admin/css/crowdaa-sync-admin.css (modified) (6 diffs)
-
trunk/admin/js/crowdaa-sync-admin.js (modified) (1 diff)
-
trunk/admin/partials/crowdaa-sync-admin-display.php (modified) (5 diffs)
-
trunk/crowdaa-sync.php (modified) (4 diffs)
-
trunk/includes/class-crowdaa-sync-versions.php (modified) (2 diffs)
-
trunk/includes/class-crowdaa-sync.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
crowdaa-sync/tags/1.1.0/CHANGELOG
r2620193 r2722017 6 6 7 7 ## [Unreleased] 8 9 ## [1.1.0] - 2022-05-11 10 11 ### Added 12 - Some more internal actions & filters 13 - Blacklist & whitelist mode by categories 14 - A bit more logs & debug 15 - Media captions synchronization 16 - Post author name synchronization per post instead of a global shared name 17 - Notifications sending when publishing an article 18 - Automatic generation of auto-login tokens on JWT login token generation when both "Autologin Links" and "JWT Authentication for WP-API" are installed 19 20 ### Removed 21 - Several fields when synchronizing a category, to keep previous values from the API 22 23 ### Changed 24 - Minor code improvements (indentation) 25 - Some WP actions & filters names (to be more explicit) 8 26 9 27 ## [1.0.42] - 2020-09-06 … … 19 37 - Control to get the last plugin logs 20 38 - Control to run the synchronization manually 21 22 [Unreleased]: https://github.com/olivierlacan/keep-a-changelog/compare/v1.0.0...HEAD23 [1.0.0]: https://github.com/olivierlacan/keep-a-changelog/compare/v0.3.0...v1.0.024 [0.3.0]: https://github.com/olivierlacan/keep-a-changelog/compare/v0.2.0...v0.3.025 [0.2.0]: https://github.com/olivierlacan/keep-a-changelog/compare/v0.1.0...v0.2.026 [0.1.0]: https://github.com/olivierlacan/keep-a-changelog/compare/v0.0.8...v0.1.027 [0.0.8]: https://github.com/olivierlacan/keep-a-changelog/compare/v0.0.7...v0.0.828 [0.0.7]: https://github.com/olivierlacan/keep-a-changelog/compare/v0.0.6...v0.0.729 [0.0.6]: https://github.com/olivierlacan/keep-a-changelog/compare/v0.0.5...v0.0.630 [0.0.5]: https://github.com/olivierlacan/keep-a-changelog/compare/v0.0.4...v0.0.531 [0.0.4]: https://github.com/olivierlacan/keep-a-changelog/compare/v0.0.3...v0.0.432 [0.0.3]: https://github.com/olivierlacan/keep-a-changelog/compare/v0.0.2...v0.0.333 [0.0.2]: https://github.com/olivierlacan/keep-a-changelog/compare/v0.0.1...v0.0.234 [0.0.1]: https://github.com/olivierlacan/keep-a-changelog/releases/tag/v0.0.1 -
crowdaa-sync/tags/1.1.0/README.txt
r2620193 r2722017 2 2 Contributors: crowdaa 3 3 Donate link: https://www.crowdaa.com 4 Tags: crowdaa, app, application, mobile, sync, synchronization, api 4 Tags: crowdaa, app, application, mobile, sync, synchronization, api, cloud 5 5 Requires at least: 5.5.5 6 6 Requires PHP: 7.3 7 7 Tested up to: 5.8 8 Stable tag: 1. 0.508 Stable tag: 1.1.0 9 9 License: GPLv2 or later 10 10 License URI: http://www.gnu.org/licenses/gpl-2.0.html -
crowdaa-sync/tags/1.1.0/admin/class-crowdaa-sync-add-info-api.php
r2620193 r2722017 70 70 } 71 71 72 $api_to_wp_sync_from = get_option('crowdaa_sync_articles_api_to_wp_from', 0); 73 $wp_to_api_sync_from = get_option('crowdaa_sync_articles_wp_to_api_from', 0); 74 75 $result = $this->synchronization($api_to_wp_sync_from, $wp_to_api_sync_from); 72 $result = $this->synchronization(); 76 73 77 74 if (!$result['error']) { … … 103 100 */ 104 101 public function get_opqueue_ajax() { 105 $api_to_wp_sync_from = get_option('crowdaa_sync_articles_api_to_wp_from', 0); 106 $wp_to_api_sync_from = get_option('crowdaa_sync_articles_wp_to_api_from', 0); 107 108 $articles_opqueue = $this->get_articles_opqueue($api_to_wp_sync_from, $wp_to_api_sync_from); 102 $articles_opqueue = $this->get_articles_opqueue(); 109 103 110 104 wp_send_json([ … … 119 113 * @return array, object 120 114 */ 121 public function get_articles_opqueue($api_to_wp_sync_from = null, $wp_to_api_sync_from = null) { 115 public function get_articles_opqueue() { 116 $api_to_wp_sync_from = get_option('crowdaa_sync_articles_api_to_wp_from', 0); 117 $wp_to_api_sync_from = get_option('crowdaa_sync_articles_wp_to_api_from', 0); 118 122 119 Crowdaa_Sync_Logs::log('Syncing, Articles OpQueue fetching', 'API>WP from:', $api_to_wp_sync_from, 'WP>API from:', $wp_to_api_sync_from); 123 120 … … 296 293 } 297 294 298 do_action('crowdaa_sync_ opqueue_got');295 do_action('crowdaa_sync_articles_opqueue_built'); 299 296 300 297 return $result; … … 317 314 * @return boolean 318 315 */ 319 private function synchronization( $api_to_wp_sync_from, $wp_to_api_sync_from) {316 private function synchronization() { 320 317 $result = []; 321 318 … … 334 331 335 332 try { 333 do_action('crowdaa_sync_articles_synchronization_init'); 334 336 335 $info_wp = new Crowdaa_Sync_Add_Info_WP(); 337 $articles_opqueue = $this->get_articles_opqueue( $api_to_wp_sync_from, $wp_to_api_sync_from);336 $articles_opqueue = $this->get_articles_opqueue(); 338 337 339 338 if (isset($articles_opqueue['error']) && $articles_opqueue['error']) { … … 356 355 $api_errors = false; 357 356 357 do_action('crowdaa_sync_articles_synchronization_start'); 358 358 // Sync WP => API 359 359 if (is_array($articles_opqueue['wp_to_api']) && is_array($articles_opqueue['only_wp'])) { … … 370 370 } 371 371 372 do_action('crowdaa_sync_synchroniz ing');372 do_action('crowdaa_sync_synchronization_custom'); 373 373 374 374 if ($wp_errors || $api_errors) { … … 403 403 */ 404 404 public function ajax_synchronization() { 405 $api_to_wp_sync_from = get_option('crowdaa_sync_articles_api_to_wp_from', 0); 406 $wp_to_api_sync_from = get_option('crowdaa_sync_articles_wp_to_api_from', 0); 407 408 $result = $this->synchronization($api_to_wp_sync_from, $wp_to_api_sync_from); 405 $result = $this->synchronization(); 409 406 410 407 if (!isset($result['error'])) { … … 452 449 453 450 454 /** 455 * Check info for update or create 456 * 457 * @since 1.0.0 458 * @param $wp_to_api 459 * @param $only_wp 460 * @return boolean 461 */ 451 private function remove_already_synced_post($post_id) { 452 $sync_api = new Crowdaa_Sync_API(); 453 $api_post_id = get_post_meta($post_id, 'api_post_id', true); 454 455 if ($api_post_id) { 456 try { 457 $sync_api->delete_post_api($api_post_id); 458 } catch (Exception $e) { 459 /* Do nothing */ 460 } 461 } 462 463 delete_post_meta($post_id, 'crowdaa_need_sync'); 464 delete_post_meta($post_id, 'crowdaa_version'); 465 delete_post_meta($post_id, 'crowdaa_last_wp_to_api_sync'); 466 delete_post_meta($post_id, 'api_post_id'); 467 } 468 462 469 public function sync_info_api(&$wp_to_api, &$only_wp) { 463 470 $posts_add_to_api = array_merge($wp_to_api, $only_wp); … … 491 498 } 492 499 493 foreach ($terms_hash as $term) {494 $root_term = $term;495 while ($root_term->parent) {496 $root_term = $terms_hash[$root_term->parent];497 }498 499 if ($root_term->term_id !== $term->term_id) {500 $term->root_term_id = $root_term->term_id;501 } else {502 $term->root_term_id = $term->parent;503 }504 }505 506 500 $args = array( 507 501 'hide_empty' => false, … … 520 514 } 521 515 516 $sync_categories_mode = get_option('crowdaa_sync_categories_mode', 'blacklist'); 517 $sync_categories_list = get_option('crowdaa_sync_categories_list', ''); 518 if ($sync_categories_list === '') { 519 $sync_categories_list = []; 520 } else { 521 $sync_categories_list = explode(',', $sync_categories_list); 522 } 523 524 foreach ($terms_hash as $term) { 525 $root_term = $term; 526 while ($root_term->parent) { 527 $root_term = $terms_hash[$root_term->parent]; 528 } 529 530 if ($sync_categories_mode === 'whitelist' && !in_array($root_term->term_id, $sync_categories_list)) { 531 $term->root_term_id = null; 532 continue; 533 } else if ($sync_categories_mode === 'blacklist' && in_array($root_term->term_id, $sync_categories_list)) { 534 $term->root_term_id = null; 535 continue; 536 } 537 538 if ($root_term->term_id !== $term->term_id) { 539 $term->root_term_id = $root_term->term_id; 540 } else { 541 $term->root_term_id = $term->parent; 542 } 543 } 544 522 545 foreach ($posts_add_to_api as $postArrayId => $post) { 523 546 Crowdaa_Sync_Timer::check(); … … 531 554 Crowdaa_Sync_Logs::log('No categories for this post, skipping...'); 532 555 continue; 533 } else { 534 foreach ($post_terms as $term) { 535 if (in_array($term->term_id, $child_terms)) { 536 $child_term = true; 537 $post_term = [ 538 'id' => $term->term_id, 539 'slug' => $term->slug, 540 'name' => $term->name, 541 ]; 556 } 557 558 $whitelisted = ($sync_categories_mode !== 'whitelist'); 559 $blacklisted = false; 560 foreach ($post_terms as $term) { 561 $blacklisted_term = false; 562 563 if (in_array($term->term_id, $sync_categories_list)) { 564 if ($sync_categories_mode === 'blacklist') { 565 $blacklisted = $term->term_id; 566 } else { 567 $whitelisted = $term->term_id; 568 if (!$post_term) { 569 $child_term = true; // Lie here to avoid losing this term. 570 $post_term = [ 571 'id' => $term->term_id, 572 'slug' => $term->slug, 573 'name' => $term->name, 574 ]; 575 } 542 576 } 543 } 544 if ($child_term == false) { 577 } else if ( 578 $sync_categories_mode !== 'whitelist' && 579 !$blacklisted && 580 !$post_term && 581 in_array($term->term_id, $child_terms) 582 ) { 583 $child_term = true; 545 584 $post_term = [ 546 'id' => $post_terms[0]->term_id,547 'slug' => $post_terms[0]->slug,548 'name' => $post_terms[0]->name,549 ];550 }551 552 $term = $terms_hash[$post_term['id']];553 if ($term->root_term_id) {554 $term = $terms_hash[$term->root_term_id];555 $post_term['parent'] = [556 585 'id' => $term->term_id, 557 586 'slug' => $term->slug, … … 561 590 } 562 591 592 if (!$whitelisted) { 593 Crowdaa_Sync_Logs::log('Could not find a whitelisted category for this article, skipping'); 594 $api_post_id = get_post_meta($post['post_id'], 'api_post_id'); 595 if ($api_post_id) { 596 Crowdaa_Sync_Logs::log('Post was already synchronized, removing it from the API'); 597 $this->remove_already_synced_post($post['post_id']); 598 } 599 600 continue; 601 } else if ($blacklisted) { 602 Crowdaa_Sync_Logs::log('Blacklisted category', $blacklisted, 'skipping'); 603 $api_post_id = get_post_meta($post['post_id'], 'api_post_id'); 604 if ($api_post_id) { 605 Crowdaa_Sync_Logs::log('Post was already synchronized, removing it from the API'); 606 $this->remove_already_synced_post($post['post_id']); 607 } 608 609 continue; 610 } 611 612 if ($child_term == false) { 613 $post_term = [ 614 'id' => $post_terms[0]->term_id, 615 'slug' => $post_terms[0]->slug, 616 'name' => $post_terms[0]->name, 617 ]; 618 } 619 620 $term = $terms_hash[$post_term['id']]; 621 if ($term->root_term_id) { 622 $term = $terms_hash[$term->root_term_id]; 623 $post_term['parent'] = [ 624 'id' => $term->term_id, 625 'slug' => $term->slug, 626 'name' => $term->name, 627 ]; 628 } 629 563 630 try { 631 $can_sync = apply_filters('crowdaa_sync_can_sync_wp_post', true, $post['post_id']); 632 if (!$can_sync) { 633 Crowdaa_Sync_Logs::log('Post sync denied by "crowdaa_sync_can_sync_wp_post" filter'); 634 $api_post_id = get_post_meta($post['post_id'], 'api_post_id'); 635 if ($api_post_id) { 636 Crowdaa_Sync_Logs::log('Post was already synchronized, removing it from the API'); 637 $this->remove_already_synced_post($post['post_id']); 638 } 639 640 continue; 641 } 642 564 643 // Create or update parent category, if needed 565 644 $parent_api_term_id = false; … … 607 686 $img_errors = $sync_api->sync_post_images($post['post_id']); 608 687 if($img_errors) { 609 $errors += $img_errors;688 throw new Crowdaa_Sync_Post_Skip_Error('Medias sync errors, skipping ('.implode(', ', $img_errors).')'); 610 689 } 611 690 … … 625 704 continue; 626 705 } catch (Crowdaa_Sync_Post_Error $e) { 706 Crowdaa_Sync_Logs::log('Post sync error', $e->getMessage()); 627 707 $errors[] = $e->getMessage(); 628 708 continue; -
crowdaa-sync/tags/1.1.0/admin/class-crowdaa-sync-admin-display.php
r2620193 r2722017 268 268 269 269 /** 270 * Set which categories will be synchronized or not on the app 271 * 272 * @since 1.0.0 273 */ 274 public function choose_sync_categories() { 275 if(!isset($_POST['crowdaa_set_sync_categories']) || !wp_verify_nonce($_POST['crowdaa_set_sync_categories'], 'crowdaa_set_sync_categories_data')) { 276 return; 277 } 278 279 if(isset($_POST['sync_categories_mode_whitelist'])) { 280 update_option('crowdaa_sync_categories_mode', 'whitelist'); 281 } else { 282 update_option('crowdaa_sync_categories_mode', 'blacklist'); 283 } 284 285 $categories = array_filter($_POST['sync_categories'], function($v) { 286 if (empty($v)) return (false); 287 $v = (string) $v; 288 if (!preg_match('/^[0-9]+$/', $v)) return (false); 289 290 return (true); 291 }); 292 293 update_option('crowdaa_sync_categories_list', implode(',', $categories)); 294 295 Crowdaa_Sync_Versions::bump_version(); 296 } 297 298 /** 270 299 * Admin notices 271 300 * -
crowdaa-sync/tags/1.1.0/admin/class-crowdaa-sync-api.php
r2620193 r2722017 96 96 */ 97 97 private function fetch_post_api_medias($wp_post_id) { 98 $captions = []; 98 99 $api_feedpicture_id = get_post_meta($wp_post_id, 'api_feedpicture_id', true) ?: ''; 99 100 if ($api_feedpicture_id) { 100 101 $api_feedpicture_id = unserialize($api_feedpicture_id); 102 $captions[] = wp_get_attachment_caption($api_feedpicture_id['attachment_id']); 101 103 $api_feedpicture_id = $api_feedpicture_id['api_id']; 102 104 } … … 112 114 $pictures_id[] = $api_id; 113 115 } 114 } 116 $captions[] = wp_get_attachment_caption($data['attachment_id']); 117 } 118 119 $captions = array_filter($captions, 'strlen'); 115 120 116 121 return ([ 117 122 'api_feedpicture_id' => $api_feedpicture_id, 118 'videos_id' => $videos_id, 119 'pictures_id' => $pictures_id, 123 'videos_id' => $videos_id, 124 'pictures_id' => $pictures_id, 125 'captions' => $captions, 120 126 ]); 121 127 } … … 154 160 155 161 $post_content = get_post_field('post_content', $wp_post_id); 162 $post_author = get_the_author_meta('display_name', get_post_field('post_author', $wp_post_id)); 156 163 $publication_time = get_post_datetime($wp_post_id)->getTimestamp(); 157 164 … … 159 166 $wp_post_title = html_entity_decode($wp_post_title, ENT_QUOTES); 160 167 $data = [ 161 'articleId' => $api_post_id, 162 'actions' => [], 163 'categoryId' => $category_id, 164 'feedPicture' => $api_feedpicture_id, 165 'md' => $post_content ?: __('Without content', CROWDAA_SYNC_PLUGIN_NAME), 166 'pictures' => $pictures_id, 167 'summary' => $wp_post_title, 168 'hideFromFeed' => !$feed_display, 169 'productId' => '', 170 'title' => $wp_post_title, 171 'videos' => $videos_id, 168 'articleId' => $api_post_id, 169 'actions' => [], 170 'authorName' => $post_author, 171 'categoryId' => $category_id, 172 'feedPicture' => $api_feedpicture_id, 173 'md' => $post_content ?: __('Without content', CROWDAA_SYNC_PLUGIN_NAME), 174 'pictures' => $pictures_id, 175 'summary' => $wp_post_title, 176 'hideFromFeed' => !$feed_display, 177 'productId' => '', 178 'title' => $wp_post_title, 179 'videos' => $videos_id, 180 'mediaCaptions' => implode(' | ', $api_media_data['captions']), 172 181 ]; 182 $data = apply_filters('crowdaa_sync_api_update_article_payload', $data, $wp_post_id); 173 183 174 184 $response = $this->http_request('PUT', '/press/articles', $data); … … 187 197 } 188 198 189 $publish_error = $this->publish_post_draft_api($json->draftId, $api_post_id, $publication_time); 199 $send_notification = ( 200 get_post_meta($wp_post_id, 'crowdaa_notification_send', true) === 'yes' && 201 get_post_meta($wp_post_id, 'crowdaa_notification_sent', true) !== 'yes' 202 ); 203 $publish_error = $this->publish_post_draft_api( 204 $json->draftId, 205 $api_post_id, 206 $publication_time, 207 $send_notification, 208 (get_post_meta($wp_post_id, 'crowdaa_notification_content', true) ?: null), 209 (get_post_meta($wp_post_id, 'crowdaa_notification_title', true) ?: null), 210 ); 190 211 if ($publish_error) { 191 212 Crowdaa_Sync_Logs::log('Article publish error', $api_post_id, $publish_error); 192 213 throw new Crowdaa_Sync_Post_Error(__('Post publish error : ', CROWDAA_SYNC_PLUGIN_NAME).$publish_error); 214 } 215 216 if ($send_notification) { 217 update_post_meta($wp_post_id, 'crowdaa_notification_sent', 'yes'); 193 218 } 194 219 … … 206 231 * @return boolean 207 232 */ 208 public function publish_post_draft_api($draft_id, $api_post_id, $publication_time) { 233 public function publish_post_draft_api( 234 $draft_id, 235 $api_post_id, 236 $publication_time, 237 $send_notification = false, 238 $notification_content = null, 239 $notification_title = null 240 ) { 209 241 $data = [ 210 'draftId' => $draft_id, 211 'date' => gmdate(CROWDAA_SYNC_ISO_TIME_FORMAT, $publication_time), 212 'sendNotifications' => false, 242 'draftId' => $draft_id, 243 'date' => gmdate(CROWDAA_SYNC_ISO_TIME_FORMAT, $publication_time), 244 'sendNotifications' => $send_notification, 245 'notificationContent' => $notification_content, 246 'notificationTitle' => $notification_title, 213 247 ]; 214 248 … … 239 273 * @param $article_data 240 274 */ 241 public function create_custom_article_api($article_data, $publication_time ) {275 public function create_custom_article_api($article_data, $publication_time, $send_notification = false) { 242 276 $auth_token = get_option('crowdaa_auth_token'); 243 277 if (!$auth_token) { … … 277 311 } 278 312 279 $publish_error = $this->publish_post_draft_api($json->draftId, $json->articleId, $publication_time); 313 $publish_error = $this->publish_post_draft_api( 314 $json->draftId, 315 $json->articleId, 316 $publication_time, 317 $send_notification 318 ); 280 319 if ($publish_error) { 281 320 Crowdaa_Sync_Logs::log('Custom article first publish error', $json->articleId, $publish_error); … … 295 334 * @param $article_data 296 335 */ 297 public function update_custom_article_api($article_data, $publication_time ) {336 public function update_custom_article_api($article_data, $publication_time, $send_notification = false) { 298 337 $auth_token = get_option('crowdaa_auth_token'); 299 338 if (!$auth_token) { … … 333 372 } 334 373 335 $publish_error = $this->publish_post_draft_api($json->draftId, $json->articleId, $publication_time); 374 $publish_error = $this->publish_post_draft_api( 375 $json->draftId, 376 $json->articleId, 377 $publication_time, 378 $send_notification 379 ); 336 380 if ($publish_error) { 337 381 Crowdaa_Sync_Logs::log('Custom article publish error', $json->articleId, $publish_error); … … 377 421 378 422 $post_content = get_post_field('post_content', $wp_post_id); 423 $post_author = get_the_author_meta('display_name', get_post_field('post_author', $wp_post_id)); 379 424 $publication_time = get_post_datetime($wp_post_id)->getTimestamp(); 380 425 … … 382 427 $wp_post_title = html_entity_decode($wp_post_title, ENT_QUOTES); 383 428 $data = [ 384 'actions' => [], 385 'categoryId' => $category_id, 386 'feedPicture' => $api_feedpicture_id, 387 'md' => $post_content ?: __('Without content', CROWDAA_SYNC_PLUGIN_NAME), 388 'pictures' => $pictures_id, 389 'summary' => $wp_post_title, 390 'hideFromFeed' => !$feed_display, 391 'productId' => '', 392 'title' => $wp_post_title, 393 'videos' => $videos_id, 429 'actions' => [], 430 'authorName' => $post_author, 431 'categoryId' => $category_id, 432 'feedPicture' => $api_feedpicture_id, 433 'md' => $post_content ?: __('Without content', CROWDAA_SYNC_PLUGIN_NAME), 434 'pictures' => $pictures_id, 435 'summary' => $wp_post_title, 436 'hideFromFeed' => !$feed_display, 437 'productId' => '', 438 'title' => $wp_post_title, 439 'videos' => $videos_id, 440 'mediaCaptions' => implode(' | ', $api_media_data['captions']), 394 441 ]; 442 $data = apply_filters('crowdaa_sync_api_create_article_payload', $data, $wp_post_id); 395 443 396 444 Crowdaa_Sync_Logs::log('Creating API post', $wp_post_id, wp_json_encode($data)); … … 414 462 } 415 463 416 $publish_error = $this->publish_post_draft_api($json->draftId, $json->articleId, $publication_time); 464 $send_notification = ( 465 get_post_meta($wp_post_id, 'crowdaa_notification_send', true) === 'yes' && 466 get_post_meta($wp_post_id, 'crowdaa_notification_sent', true) !== 'yes' 467 ); 468 $publish_error = $this->publish_post_draft_api( 469 $json->draftId, 470 $json->articleId, 471 $publication_time, 472 $send_notification, 473 (get_post_meta($wp_post_id, 'crowdaa_notification_content', true) ?: null), 474 (get_post_meta($wp_post_id, 'crowdaa_notification_title', true) ?: null), 475 ); 417 476 if ($publish_error) { 418 477 Crowdaa_Sync_Logs::log('Article first publish error', $json->articleId, $json->draftId, $publish_error); … … 421 480 422 481 update_post_meta($wp_post_id, 'api_post_id', $json->articleId); 482 if ($send_notification) { 483 update_post_meta($wp_post_id, 'crowdaa_notification_sent', 'yes'); 484 } 423 485 Crowdaa_Sync_Logs::log('Created API post', $json->articleId); 424 486 } … … 747 809 'action' => '', 748 810 ]; 811 $data = apply_filters('crowdaa_sync_api_create_category_payload', $data); 749 812 750 813 $response = $this->http_request('POST', '/press/categories', $data); … … 789 852 'name' => $cat_name, 790 853 'pathName' => $cat_slug, 791 'color' => '',792 'order' => 1,793 854 'hidden' => false, 794 'picture' => [],795 855 'parentId' => $parent_category_id, 796 856 'action' => '', 857 // 'picture' => null, 858 // 'color' => null, 859 // 'order' => null, 797 860 ]; 861 $data = apply_filters('crowdaa_sync_api_update_category_payload', $data); 798 862 799 863 $response = $this->http_request('PUT', '/press/categories/'.$cat_id, $data); … … 829 893 */ 830 894 public function delete_post_api($api_post_id) { 831 $data = [ 832 'draftId' => $api_post_id, 833 ]; 834 835 $response = $this->http_request('DELETE', '/press/articles/'.$api_post_id, $data); 895 $response = $this->http_request('DELETE', '/press/articles/'.$api_post_id); 836 896 $err = is_wp_error($response) ? $response->get_error_message() : null; 837 897 if (!$err) { -
crowdaa-sync/tags/1.1.0/admin/class-crowdaa-sync-meta-box.php
r2620193 r2722017 18 18 */ 19 19 public function __construct() { 20 add_action('add_meta_boxes', [$this, ' meta_box_add'], 10, 2);21 add_action('save_post', [$this, ' img_gallery_save']);20 add_action('add_meta_boxes', [$this, 'add_meta_boxes'], 10, 2); 21 add_action('save_post', [$this, 'save_meta_boxes']); 22 22 } 23 23 … … 29 29 * @return boolean 30 30 */ 31 function meta_box_add() {31 function add_meta_boxes() { 32 32 add_meta_box( 33 33 'crowdaa_feat_img_slider', 34 'Featured Image Gallery', 35 [$this, 'print_box'], 34 'Crowdaa-sync: Featured Image Gallery', 35 [$this, 'print_feat_img_slider_box'], 36 'post', 37 'advanced', 38 'high', 39 array( 40 '__back_compat_meta_box' => false, 41 ) 42 ); 43 add_meta_box( 44 'crowdaa-sync-notification-send', 45 'Crowdaa-sync: Send notifications when published?', 46 [$this, 'print_send_notification_checkbox'], 36 47 'post', 37 48 'advanced', … … 124 135 125 136 /** 126 * Meta box html137 * Image selector meta box 127 138 * 128 139 * @since 1.0.0 … … 130 141 * @return string 131 142 */ 132 function print_ box($post) {143 function print_feat_img_slider_box($post) { 133 144 wp_nonce_field('save_feat_gallery', 'feat_gallery_nonce'); 134 145 … … 138 149 139 150 /** 140 * Save meta box data 141 * 142 * @since 1.0.0 143 * @param $post_id 144 * @return boolean 145 */ 146 function img_gallery_save($post_id) { 151 * Notification checkbox meta box 152 * 153 * @since 1.0.0 154 * @param $post 155 * @return string 156 */ 157 function print_send_notification_checkbox($post) { 158 $notification_content = get_post_meta($post->ID, 'crowdaa_notification_content', true) ?: ''; 159 $notification_title = get_post_meta($post->ID, 'crowdaa_notification_title', true) ?: ''; 160 wp_nonce_field('crowdaa_notification_checkbox', 'crowdaa_notification_checkbox_nonce'); 161 162 ?> 163 <p> 164 <i> 165 <?php 166 esc_html_e('Check this box if you want to send a notification when the article is published or right now if it is already published.', CROWDAA_SYNC_PLUGIN_NAME); 167 ?> 168 </i> 169 </p> 170 171 <div class="crowdaa-meta-box-input-row"> 172 <label> 173 <?php 174 esc_html_e('Send notification :', CROWDAA_SYNC_PLUGIN_NAME); 175 ?> 176 <input 177 type="checkbox" 178 name="crowdaa_send_post_notification" 179 /> 180 </label> 181 </div> 182 <div class="crowdaa-meta-box-input-row"> 183 <label> 184 <?php 185 esc_html_e('Notification text (When both are not set, defaults to the article title & first characters) :', CROWDAA_SYNC_PLUGIN_NAME); 186 ?> 187 <br /> 188 <input 189 style="display: inline-block; width: 500px;" 190 type="text" 191 name="crowdaa_send_post_notification_title" 192 placeholder="<?php esc_attr_e('Notification title', CROWDAA_SYNC_PLUGIN_NAME); ?>" 193 value="<?php echo esc_attr($notification_title); ?>" 194 /> 195 <br /> 196 <input 197 style="display: inline-block; width: 500px;" 198 type="text" 199 name="crowdaa_send_post_notification_content" 200 placeholder="<?php esc_attr_e('Notification content', CROWDAA_SYNC_PLUGIN_NAME); ?>" 201 value="<?php echo esc_attr($notification_content); ?>" 202 /> 203 </label> 204 </div> 205 <?php 206 } 207 208 function save_gallery_meta_box($post_id) { 147 209 if (!isset($_POST['feat_gallery_nonce'])) { 148 return $post_id; 149 } 150 151 if (!wp_verify_nonce($_POST['feat_gallery_nonce'], 'save_feat_gallery')) { 152 return $post_id; 210 return; 211 } else if (!wp_verify_nonce($_POST['feat_gallery_nonce'], 'save_feat_gallery')) { 212 return; 213 } else if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) { 214 return; 215 } else if (!current_user_can('edit_post', $post_id)) { 216 return; 153 217 } 154 218 … … 167 231 } 168 232 } 233 234 function save_notifications_meta_box($post_id) { 235 if (!isset($_POST['crowdaa_notification_checkbox_nonce'])) { 236 return; 237 } else if (!wp_verify_nonce($_POST['crowdaa_notification_checkbox_nonce'], 'crowdaa_notification_checkbox')) { 238 return; 239 } else if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) { 240 return; 241 } else if (!current_user_can('edit_post', $post_id)) { 242 return; 243 } 244 245 if (isset($_POST['crowdaa_send_post_notification'])) { 246 update_post_meta($post_id, 'crowdaa_notification_send', 'yes'); 247 update_post_meta($post_id, 'crowdaa_notification_sent', 'no'); 248 update_post_meta($post_id, 'crowdaa_notification_title', $_POST['crowdaa_send_post_notification_title'] ?: ''); 249 update_post_meta($post_id, 'crowdaa_notification_content', $_POST['crowdaa_send_post_notification_content'] ?: ''); 250 } 251 } 252 253 /** 254 * Save meta boxes data 255 * 256 * @since 1.0.0 257 * @param $post_id 258 * @return boolean 259 */ 260 function save_meta_boxes($post_id) { 261 $this->save_gallery_meta_box($post_id); 262 $this->save_notifications_meta_box($post_id); 263 } 169 264 } -
crowdaa-sync/tags/1.1.0/admin/css/crowdaa-sync-admin.css
r2620193 r2722017 31 31 display: flex; 32 32 flex-direction: row; 33 max-width: 310px; 33 justify-content: space-between; 34 max-width: 400px; 34 35 } 35 36 … … 39 40 40 41 .sync-form-label { 41 width: 250px;42 width: 300px; 42 43 display: inline-block; 43 44 } … … 47 48 } 48 49 49 .sync- feed-categories-select {50 .sync-categories-select { 50 51 min-height: 150px !important; 51 52 width: 600px; … … 69 70 position: absolute; 70 71 top: -7px; 72 right: 0px; 71 73 height: 30px; 72 74 line-height: 30px; … … 83 85 content: "ON"; 84 86 color: #0a0; 87 } 88 89 .sync-enable-checkbox-custom { 90 visibility: hidden; 91 cursor: pointer; 92 } 93 94 .sync-enable-checkbox-custom+.sync-enable-checkbox-custom-content { 95 display: block; 96 height: 30px; 97 line-height: 30px; 98 width: auto; 99 padding: 0 10px; 100 text-align: center; 101 border-radius: 4px; 102 background: #fff; 103 color: rgb(4, 174, 216); 104 font-weight: 600; 105 cursor: pointer; 106 } 107 108 .sync-enable-checkbox-custom:checked+.sync-enable-checkbox-custom-content { 109 color: rgb(255, 167, 0); 110 } 111 112 .sync-enable-checkbox-custom+.sync-enable-checkbox-custom-content .sync-enable-checkbox-custom-checked { 113 display: none; 114 } 115 116 .sync-enable-checkbox-custom+.sync-enable-checkbox-custom-content .sync-enable-checkbox-custom-unchecked { 117 display: inline; 118 } 119 120 .sync-enable-checkbox-custom:checked+.sync-enable-checkbox-custom-content .sync-enable-checkbox-custom-unchecked { 121 display: none; 122 } 123 124 .sync-enable-checkbox-custom:checked+.sync-enable-checkbox-custom-content .sync-enable-checkbox-custom-checked { 125 display: inline; 85 126 } 86 127 … … 177 218 padding: 5px 10px; 178 219 } 220 221 .crowdaa-meta-box-input-row { 222 display: block; 223 margin-bottom: 10px; 224 } -
crowdaa-sync/tags/1.1.0/admin/js/crowdaa-sync-admin.js
r2620193 r2722017 91 91 updateFeedCategoriesSelect(); 92 92 93 function updateSyncCategoriesSelect() { 94 const $field = $('#crowdaa-sync-categories-mode-whitelist-checkbox'); 95 const $whitelistText = $('#crowdaa-sync-categories-explanation-whitelist'); 96 const $blacklistText = $('#crowdaa-sync-categories-explanation-blacklist'); 97 if ($field.prop('checked')) { 98 $whitelistText.show(); 99 $blacklistText.hide(); 100 } else { 101 $whitelistText.hide(); 102 $blacklistText.show(); 103 } 104 } 105 $('#crowdaa-sync-categories-mode-whitelist-checkbox').on('change', updateSyncCategoriesSelect); 106 updateSyncCategoriesSelect(); 107 93 108 /** 94 109 * Ajax add posts and terms -
crowdaa-sync/tags/1.1.0/admin/partials/crowdaa-sync-admin-display.php
r2620193 r2722017 115 115 <?php do_action('crowdaa_sync_configuration_levers'); ?> 116 116 <label class="sync-form-checkbox-label"> 117 <span class="sync-form-label"><?php esc_html_e('Maximum synchronization duration '); ?></span> 117 <span class="sync-form-label"><?php esc_html_e('Maximum synchronization duration (minutes)'); ?></span> 118 118 <input type="number" name="sync_max_duration" min="2" id="sync-duration-field" 119 119 value="<?php echo esc_attr($sync_max_duration); ?>" 120 120 /> 121 <?php esc_html_e('minutes'); ?>122 121 </label> 123 122 <br /> … … 147 146 <?php 148 147 submit_button('Save picture'); 148 ?> 149 </form> 150 </div> 151 152 <hr/> 153 154 <div> 155 <h2><?php esc_html_e('Set categories to synchronize', CROWDAA_SYNC_PLUGIN_NAME) ?></h2> 156 <form method="post" action="<?php $admin_utils->choose_sync_categories(); ?>" enctype="multipart/form-data"> 157 <?php 158 $sync_categories_mode = get_option('crowdaa_sync_categories_mode', 'blacklist'); 159 $sync_categories_list = explode(',', get_option('crowdaa_sync_categories_list', '')); 160 ?> 161 <label class="sync-form-checkbox-label"> 162 <span class="sync-form-label"><?php esc_html_e('Categories sync mode', CROWDAA_SYNC_PLUGIN_NAME); ?></span> 163 <input 164 type="checkbox" 165 name="sync_categories_mode_whitelist" 166 class="sync-enable-checkbox-custom" 167 id="crowdaa-sync-categories-mode-whitelist-checkbox" 168 <?php echo ($sync_categories_mode === 'whitelist' ? 'checked="checked"' : ''); ?> 169 /> 170 <span class="sync-enable-checkbox-custom-content"> 171 <span class="sync-enable-checkbox-custom-checked">Whitelist</span> 172 <span class="sync-enable-checkbox-custom-unchecked">Blacklist</span> 173 </span> 174 </label> 175 <div id="crowdaa-sync-categories-select-area"> 176 <label> 177 <p> 178 <span id="crowdaa-sync-categories-explanation-whitelist"> 179 <?php esc_html_e('Select below the categories that you *want* to synchronize to the app.', CROWDAA_SYNC_PLUGIN_NAME); ?> 180 </span> 181 <span id="crowdaa-sync-categories-explanation-blacklist"> 182 <?php esc_html_e('Select below the categories that you *do not want* to synchronize to the app.', CROWDAA_SYNC_PLUGIN_NAME); ?> 183 </span> 184 <br /> 185 <?php esc_html_e('Use the Ctrl or Shift keys to select multiple categories.', CROWDAA_SYNC_PLUGIN_NAME); ?><br /> 186 </p> 187 <?php 188 $terms = get_terms([ 189 "hide_empty" => false, 190 "taxonomy" => "category", 191 ]); 192 ?> 193 <select class="sync-categories-select" name="sync_categories[]" multiple> 194 <option 195 value="" 196 <?php echo (array_search('', $sync_categories_list) !== false ? 'selected="selected"' : ''); ?> 197 > 198 <?php esc_html_e('---', CROWDAA_SYNC_PLUGIN_NAME); ?> 199 </option> 200 <?php foreach ($terms as $term) { ?> 201 <option 202 value="<?php echo esc_attr($term->term_id); ?>" 203 <?php echo (array_search($term->term_id, $sync_categories_list) !== false ? 'selected="selected"' : ''); ?> 204 > 205 <?php esc_html_e($term->name.' ('.$term->slug.')', CROWDAA_SYNC_PLUGIN_NAME); ?> 206 </option> 207 <?php } ?> 208 </select> 209 </label> 210 </div> 211 <?php wp_nonce_field('crowdaa_set_sync_categories_data', 'crowdaa_set_sync_categories'); ?> 212 <?php 213 submit_button('Save mode & categories'); 149 214 ?> 150 215 </form> … … 173 238 <p> 174 239 <?php esc_html_e('Select below the categories that you want to see on the feed page.', CROWDAA_SYNC_PLUGIN_NAME); ?><br /> 175 <?php esc_html_e('Use the Ctrl or Shift keys to select multiple categories ', CROWDAA_SYNC_PLUGIN_NAME); ?><br />240 <?php esc_html_e('Use the Ctrl or Shift keys to select multiple categories.', CROWDAA_SYNC_PLUGIN_NAME); ?><br /> 176 241 </p> 177 242 <?php … … 179 244 "hide_empty" => false, 180 245 "taxonomy" => "category", 181 "childless" => true182 246 ]); 183 247 if ($feed_categories === 'all') { … … 187 251 } 188 252 ?> 189 <select class="sync-feed-categories-select" name="sync_feed_categories[]" multiple> 190 <option value=""> 191 <?php esc_html_e('None', CROWDAA_SYNC_PLUGIN_NAME); ?> 253 <select class="sync-categories-select" name="sync_feed_categories[]" multiple> 254 <option 255 value="" 256 <?php echo (array_search('', $feed_categories) !== false ? 'selected="selected"' : ''); ?> 257 > 258 <?php esc_html_e('---', CROWDAA_SYNC_PLUGIN_NAME); ?> 192 259 </option> 193 260 <?php foreach ($terms as $term) { ?> -
crowdaa-sync/tags/1.1.0/crowdaa-sync.php
r2620193 r2722017 14 14 * Plugin URI: 15 15 * Description: Plugin for synchronizing WordPress site and Crowdaa CMS 16 * Version: 1. 0.5016 * Version: 1.1.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. 0.50');36 define('CROWDAA_SYNC_VERSION', '1.1.0'); 37 37 define('CROWDAA_SYNC_PLUGIN_DIR', __DIR__); 38 38 define('CROWDAA_SYNC_PLUGIN_NAME', 'crowdaa-sync'); … … 48 48 $last_version = get_option('crowdaa_last_version', false); 49 49 if (!$last_version || $last_version < CROWDAA_SYNC_META_VERSION) { 50 update_option('crowdaa_sync_ wp_to_api_from', 0);50 update_option('crowdaa_sync_articles_wp_to_api_from', 0); 51 51 update_option('crowdaa_last_version', CROWDAA_SYNC_META_VERSION); 52 52 } … … 111 111 } 112 112 113 if (class_exists('Crowdaa_Sync_Ext_Hooks')) { 114 new Crowdaa_Sync_Ext_Hooks; 115 } 116 113 117 if (class_exists('Crowdaa_Sync_Admin_Display')) { 114 118 new Crowdaa_Sync_Admin_Display; -
crowdaa-sync/tags/1.1.0/includes/class-crowdaa-sync-versions.php
r2620193 r2722017 19 19 if (!$last_version || $last_version < CROWDAA_SYNC_META_VERSION) { 20 20 update_option('crowdaa_last_version', CROWDAA_SYNC_META_VERSION); 21 update_option('crowdaa_sync_ wp_to_api_from', 0);21 update_option('crowdaa_sync_articles_wp_to_api_from', 0); 22 22 update_option('crowdaa_sync_internal_version', '0'); 23 23 } … … 36 36 update_option('crowdaa_sync_internal_version', "$ver"); 37 37 38 update_option('crowdaa_sync_ wp_to_api_from', 0);38 update_option('crowdaa_sync_articles_wp_to_api_from', 0); 39 39 40 40 self::update_versions(); -
crowdaa-sync/tags/1.1.0/includes/class-crowdaa-sync.php
r2620193 r2722017 180 180 require_once CROWDAA_SYNC_PLUGIN_DIR.'/admin/class-crowdaa-sync-wp-hooks.php'; 181 181 182 /** 183 * The class for other plugin hooks 184 */ 185 require_once CROWDAA_SYNC_PLUGIN_DIR.'/admin/class-crowdaa-sync-ext-hooks.php'; 186 182 187 $this->loader = new Crowdaa_Sync_Loader(); 183 188 } -
crowdaa-sync/trunk/CHANGELOG
r2620193 r2722017 6 6 7 7 ## [Unreleased] 8 9 ## [1.1.0] - 2022-05-11 10 11 ### Added 12 - Some more internal actions & filters 13 - Blacklist & whitelist mode by categories 14 - A bit more logs & debug 15 - Media captions synchronization 16 - Post author name synchronization per post instead of a global shared name 17 - Notifications sending when publishing an article 18 - Automatic generation of auto-login tokens on JWT login token generation when both "Autologin Links" and "JWT Authentication for WP-API" are installed 19 20 ### Removed 21 - Several fields when synchronizing a category, to keep previous values from the API 22 23 ### Changed 24 - Minor code improvements (indentation) 25 - Some WP actions & filters names (to be more explicit) 8 26 9 27 ## [1.0.42] - 2020-09-06 … … 19 37 - Control to get the last plugin logs 20 38 - Control to run the synchronization manually 21 22 [Unreleased]: https://github.com/olivierlacan/keep-a-changelog/compare/v1.0.0...HEAD23 [1.0.0]: https://github.com/olivierlacan/keep-a-changelog/compare/v0.3.0...v1.0.024 [0.3.0]: https://github.com/olivierlacan/keep-a-changelog/compare/v0.2.0...v0.3.025 [0.2.0]: https://github.com/olivierlacan/keep-a-changelog/compare/v0.1.0...v0.2.026 [0.1.0]: https://github.com/olivierlacan/keep-a-changelog/compare/v0.0.8...v0.1.027 [0.0.8]: https://github.com/olivierlacan/keep-a-changelog/compare/v0.0.7...v0.0.828 [0.0.7]: https://github.com/olivierlacan/keep-a-changelog/compare/v0.0.6...v0.0.729 [0.0.6]: https://github.com/olivierlacan/keep-a-changelog/compare/v0.0.5...v0.0.630 [0.0.5]: https://github.com/olivierlacan/keep-a-changelog/compare/v0.0.4...v0.0.531 [0.0.4]: https://github.com/olivierlacan/keep-a-changelog/compare/v0.0.3...v0.0.432 [0.0.3]: https://github.com/olivierlacan/keep-a-changelog/compare/v0.0.2...v0.0.333 [0.0.2]: https://github.com/olivierlacan/keep-a-changelog/compare/v0.0.1...v0.0.234 [0.0.1]: https://github.com/olivierlacan/keep-a-changelog/releases/tag/v0.0.1 -
crowdaa-sync/trunk/README.txt
r2620193 r2722017 2 2 Contributors: crowdaa 3 3 Donate link: https://www.crowdaa.com 4 Tags: crowdaa, app, application, mobile, sync, synchronization, api 4 Tags: crowdaa, app, application, mobile, sync, synchronization, api, cloud 5 5 Requires at least: 5.5.5 6 6 Requires PHP: 7.3 7 7 Tested up to: 5.8 8 Stable tag: 1. 0.508 Stable tag: 1.1.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
r2620193 r2722017 70 70 } 71 71 72 $api_to_wp_sync_from = get_option('crowdaa_sync_articles_api_to_wp_from', 0); 73 $wp_to_api_sync_from = get_option('crowdaa_sync_articles_wp_to_api_from', 0); 74 75 $result = $this->synchronization($api_to_wp_sync_from, $wp_to_api_sync_from); 72 $result = $this->synchronization(); 76 73 77 74 if (!$result['error']) { … … 103 100 */ 104 101 public function get_opqueue_ajax() { 105 $api_to_wp_sync_from = get_option('crowdaa_sync_articles_api_to_wp_from', 0); 106 $wp_to_api_sync_from = get_option('crowdaa_sync_articles_wp_to_api_from', 0); 107 108 $articles_opqueue = $this->get_articles_opqueue($api_to_wp_sync_from, $wp_to_api_sync_from); 102 $articles_opqueue = $this->get_articles_opqueue(); 109 103 110 104 wp_send_json([ … … 119 113 * @return array, object 120 114 */ 121 public function get_articles_opqueue($api_to_wp_sync_from = null, $wp_to_api_sync_from = null) { 115 public function get_articles_opqueue() { 116 $api_to_wp_sync_from = get_option('crowdaa_sync_articles_api_to_wp_from', 0); 117 $wp_to_api_sync_from = get_option('crowdaa_sync_articles_wp_to_api_from', 0); 118 122 119 Crowdaa_Sync_Logs::log('Syncing, Articles OpQueue fetching', 'API>WP from:', $api_to_wp_sync_from, 'WP>API from:', $wp_to_api_sync_from); 123 120 … … 296 293 } 297 294 298 do_action('crowdaa_sync_ opqueue_got');295 do_action('crowdaa_sync_articles_opqueue_built'); 299 296 300 297 return $result; … … 317 314 * @return boolean 318 315 */ 319 private function synchronization( $api_to_wp_sync_from, $wp_to_api_sync_from) {316 private function synchronization() { 320 317 $result = []; 321 318 … … 334 331 335 332 try { 333 do_action('crowdaa_sync_articles_synchronization_init'); 334 336 335 $info_wp = new Crowdaa_Sync_Add_Info_WP(); 337 $articles_opqueue = $this->get_articles_opqueue( $api_to_wp_sync_from, $wp_to_api_sync_from);336 $articles_opqueue = $this->get_articles_opqueue(); 338 337 339 338 if (isset($articles_opqueue['error']) && $articles_opqueue['error']) { … … 356 355 $api_errors = false; 357 356 357 do_action('crowdaa_sync_articles_synchronization_start'); 358 358 // Sync WP => API 359 359 if (is_array($articles_opqueue['wp_to_api']) && is_array($articles_opqueue['only_wp'])) { … … 370 370 } 371 371 372 do_action('crowdaa_sync_synchroniz ing');372 do_action('crowdaa_sync_synchronization_custom'); 373 373 374 374 if ($wp_errors || $api_errors) { … … 403 403 */ 404 404 public function ajax_synchronization() { 405 $api_to_wp_sync_from = get_option('crowdaa_sync_articles_api_to_wp_from', 0); 406 $wp_to_api_sync_from = get_option('crowdaa_sync_articles_wp_to_api_from', 0); 407 408 $result = $this->synchronization($api_to_wp_sync_from, $wp_to_api_sync_from); 405 $result = $this->synchronization(); 409 406 410 407 if (!isset($result['error'])) { … … 452 449 453 450 454 /** 455 * Check info for update or create 456 * 457 * @since 1.0.0 458 * @param $wp_to_api 459 * @param $only_wp 460 * @return boolean 461 */ 451 private function remove_already_synced_post($post_id) { 452 $sync_api = new Crowdaa_Sync_API(); 453 $api_post_id = get_post_meta($post_id, 'api_post_id', true); 454 455 if ($api_post_id) { 456 try { 457 $sync_api->delete_post_api($api_post_id); 458 } catch (Exception $e) { 459 /* Do nothing */ 460 } 461 } 462 463 delete_post_meta($post_id, 'crowdaa_need_sync'); 464 delete_post_meta($post_id, 'crowdaa_version'); 465 delete_post_meta($post_id, 'crowdaa_last_wp_to_api_sync'); 466 delete_post_meta($post_id, 'api_post_id'); 467 } 468 462 469 public function sync_info_api(&$wp_to_api, &$only_wp) { 463 470 $posts_add_to_api = array_merge($wp_to_api, $only_wp); … … 491 498 } 492 499 493 foreach ($terms_hash as $term) {494 $root_term = $term;495 while ($root_term->parent) {496 $root_term = $terms_hash[$root_term->parent];497 }498 499 if ($root_term->term_id !== $term->term_id) {500 $term->root_term_id = $root_term->term_id;501 } else {502 $term->root_term_id = $term->parent;503 }504 }505 506 500 $args = array( 507 501 'hide_empty' => false, … … 520 514 } 521 515 516 $sync_categories_mode = get_option('crowdaa_sync_categories_mode', 'blacklist'); 517 $sync_categories_list = get_option('crowdaa_sync_categories_list', ''); 518 if ($sync_categories_list === '') { 519 $sync_categories_list = []; 520 } else { 521 $sync_categories_list = explode(',', $sync_categories_list); 522 } 523 524 foreach ($terms_hash as $term) { 525 $root_term = $term; 526 while ($root_term->parent) { 527 $root_term = $terms_hash[$root_term->parent]; 528 } 529 530 if ($sync_categories_mode === 'whitelist' && !in_array($root_term->term_id, $sync_categories_list)) { 531 $term->root_term_id = null; 532 continue; 533 } else if ($sync_categories_mode === 'blacklist' && in_array($root_term->term_id, $sync_categories_list)) { 534 $term->root_term_id = null; 535 continue; 536 } 537 538 if ($root_term->term_id !== $term->term_id) { 539 $term->root_term_id = $root_term->term_id; 540 } else { 541 $term->root_term_id = $term->parent; 542 } 543 } 544 522 545 foreach ($posts_add_to_api as $postArrayId => $post) { 523 546 Crowdaa_Sync_Timer::check(); … … 531 554 Crowdaa_Sync_Logs::log('No categories for this post, skipping...'); 532 555 continue; 533 } else { 534 foreach ($post_terms as $term) { 535 if (in_array($term->term_id, $child_terms)) { 536 $child_term = true; 537 $post_term = [ 538 'id' => $term->term_id, 539 'slug' => $term->slug, 540 'name' => $term->name, 541 ]; 556 } 557 558 $whitelisted = ($sync_categories_mode !== 'whitelist'); 559 $blacklisted = false; 560 foreach ($post_terms as $term) { 561 $blacklisted_term = false; 562 563 if (in_array($term->term_id, $sync_categories_list)) { 564 if ($sync_categories_mode === 'blacklist') { 565 $blacklisted = $term->term_id; 566 } else { 567 $whitelisted = $term->term_id; 568 if (!$post_term) { 569 $child_term = true; // Lie here to avoid losing this term. 570 $post_term = [ 571 'id' => $term->term_id, 572 'slug' => $term->slug, 573 'name' => $term->name, 574 ]; 575 } 542 576 } 543 } 544 if ($child_term == false) { 577 } else if ( 578 $sync_categories_mode !== 'whitelist' && 579 !$blacklisted && 580 !$post_term && 581 in_array($term->term_id, $child_terms) 582 ) { 583 $child_term = true; 545 584 $post_term = [ 546 'id' => $post_terms[0]->term_id,547 'slug' => $post_terms[0]->slug,548 'name' => $post_terms[0]->name,549 ];550 }551 552 $term = $terms_hash[$post_term['id']];553 if ($term->root_term_id) {554 $term = $terms_hash[$term->root_term_id];555 $post_term['parent'] = [556 585 'id' => $term->term_id, 557 586 'slug' => $term->slug, … … 561 590 } 562 591 592 if (!$whitelisted) { 593 Crowdaa_Sync_Logs::log('Could not find a whitelisted category for this article, skipping'); 594 $api_post_id = get_post_meta($post['post_id'], 'api_post_id'); 595 if ($api_post_id) { 596 Crowdaa_Sync_Logs::log('Post was already synchronized, removing it from the API'); 597 $this->remove_already_synced_post($post['post_id']); 598 } 599 600 continue; 601 } else if ($blacklisted) { 602 Crowdaa_Sync_Logs::log('Blacklisted category', $blacklisted, 'skipping'); 603 $api_post_id = get_post_meta($post['post_id'], 'api_post_id'); 604 if ($api_post_id) { 605 Crowdaa_Sync_Logs::log('Post was already synchronized, removing it from the API'); 606 $this->remove_already_synced_post($post['post_id']); 607 } 608 609 continue; 610 } 611 612 if ($child_term == false) { 613 $post_term = [ 614 'id' => $post_terms[0]->term_id, 615 'slug' => $post_terms[0]->slug, 616 'name' => $post_terms[0]->name, 617 ]; 618 } 619 620 $term = $terms_hash[$post_term['id']]; 621 if ($term->root_term_id) { 622 $term = $terms_hash[$term->root_term_id]; 623 $post_term['parent'] = [ 624 'id' => $term->term_id, 625 'slug' => $term->slug, 626 'name' => $term->name, 627 ]; 628 } 629 563 630 try { 631 $can_sync = apply_filters('crowdaa_sync_can_sync_wp_post', true, $post['post_id']); 632 if (!$can_sync) { 633 Crowdaa_Sync_Logs::log('Post sync denied by "crowdaa_sync_can_sync_wp_post" filter'); 634 $api_post_id = get_post_meta($post['post_id'], 'api_post_id'); 635 if ($api_post_id) { 636 Crowdaa_Sync_Logs::log('Post was already synchronized, removing it from the API'); 637 $this->remove_already_synced_post($post['post_id']); 638 } 639 640 continue; 641 } 642 564 643 // Create or update parent category, if needed 565 644 $parent_api_term_id = false; … … 607 686 $img_errors = $sync_api->sync_post_images($post['post_id']); 608 687 if($img_errors) { 609 $errors += $img_errors;688 throw new Crowdaa_Sync_Post_Skip_Error('Medias sync errors, skipping ('.implode(', ', $img_errors).')'); 610 689 } 611 690 … … 625 704 continue; 626 705 } catch (Crowdaa_Sync_Post_Error $e) { 706 Crowdaa_Sync_Logs::log('Post sync error', $e->getMessage()); 627 707 $errors[] = $e->getMessage(); 628 708 continue; -
crowdaa-sync/trunk/admin/class-crowdaa-sync-admin-display.php
r2620193 r2722017 268 268 269 269 /** 270 * Set which categories will be synchronized or not on the app 271 * 272 * @since 1.0.0 273 */ 274 public function choose_sync_categories() { 275 if(!isset($_POST['crowdaa_set_sync_categories']) || !wp_verify_nonce($_POST['crowdaa_set_sync_categories'], 'crowdaa_set_sync_categories_data')) { 276 return; 277 } 278 279 if(isset($_POST['sync_categories_mode_whitelist'])) { 280 update_option('crowdaa_sync_categories_mode', 'whitelist'); 281 } else { 282 update_option('crowdaa_sync_categories_mode', 'blacklist'); 283 } 284 285 $categories = array_filter($_POST['sync_categories'], function($v) { 286 if (empty($v)) return (false); 287 $v = (string) $v; 288 if (!preg_match('/^[0-9]+$/', $v)) return (false); 289 290 return (true); 291 }); 292 293 update_option('crowdaa_sync_categories_list', implode(',', $categories)); 294 295 Crowdaa_Sync_Versions::bump_version(); 296 } 297 298 /** 270 299 * Admin notices 271 300 * -
crowdaa-sync/trunk/admin/class-crowdaa-sync-api.php
r2620193 r2722017 96 96 */ 97 97 private function fetch_post_api_medias($wp_post_id) { 98 $captions = []; 98 99 $api_feedpicture_id = get_post_meta($wp_post_id, 'api_feedpicture_id', true) ?: ''; 99 100 if ($api_feedpicture_id) { 100 101 $api_feedpicture_id = unserialize($api_feedpicture_id); 102 $captions[] = wp_get_attachment_caption($api_feedpicture_id['attachment_id']); 101 103 $api_feedpicture_id = $api_feedpicture_id['api_id']; 102 104 } … … 112 114 $pictures_id[] = $api_id; 113 115 } 114 } 116 $captions[] = wp_get_attachment_caption($data['attachment_id']); 117 } 118 119 $captions = array_filter($captions, 'strlen'); 115 120 116 121 return ([ 117 122 'api_feedpicture_id' => $api_feedpicture_id, 118 'videos_id' => $videos_id, 119 'pictures_id' => $pictures_id, 123 'videos_id' => $videos_id, 124 'pictures_id' => $pictures_id, 125 'captions' => $captions, 120 126 ]); 121 127 } … … 154 160 155 161 $post_content = get_post_field('post_content', $wp_post_id); 162 $post_author = get_the_author_meta('display_name', get_post_field('post_author', $wp_post_id)); 156 163 $publication_time = get_post_datetime($wp_post_id)->getTimestamp(); 157 164 … … 159 166 $wp_post_title = html_entity_decode($wp_post_title, ENT_QUOTES); 160 167 $data = [ 161 'articleId' => $api_post_id, 162 'actions' => [], 163 'categoryId' => $category_id, 164 'feedPicture' => $api_feedpicture_id, 165 'md' => $post_content ?: __('Without content', CROWDAA_SYNC_PLUGIN_NAME), 166 'pictures' => $pictures_id, 167 'summary' => $wp_post_title, 168 'hideFromFeed' => !$feed_display, 169 'productId' => '', 170 'title' => $wp_post_title, 171 'videos' => $videos_id, 168 'articleId' => $api_post_id, 169 'actions' => [], 170 'authorName' => $post_author, 171 'categoryId' => $category_id, 172 'feedPicture' => $api_feedpicture_id, 173 'md' => $post_content ?: __('Without content', CROWDAA_SYNC_PLUGIN_NAME), 174 'pictures' => $pictures_id, 175 'summary' => $wp_post_title, 176 'hideFromFeed' => !$feed_display, 177 'productId' => '', 178 'title' => $wp_post_title, 179 'videos' => $videos_id, 180 'mediaCaptions' => implode(' | ', $api_media_data['captions']), 172 181 ]; 182 $data = apply_filters('crowdaa_sync_api_update_article_payload', $data, $wp_post_id); 173 183 174 184 $response = $this->http_request('PUT', '/press/articles', $data); … … 187 197 } 188 198 189 $publish_error = $this->publish_post_draft_api($json->draftId, $api_post_id, $publication_time); 199 $send_notification = ( 200 get_post_meta($wp_post_id, 'crowdaa_notification_send', true) === 'yes' && 201 get_post_meta($wp_post_id, 'crowdaa_notification_sent', true) !== 'yes' 202 ); 203 $publish_error = $this->publish_post_draft_api( 204 $json->draftId, 205 $api_post_id, 206 $publication_time, 207 $send_notification, 208 (get_post_meta($wp_post_id, 'crowdaa_notification_content', true) ?: null), 209 (get_post_meta($wp_post_id, 'crowdaa_notification_title', true) ?: null), 210 ); 190 211 if ($publish_error) { 191 212 Crowdaa_Sync_Logs::log('Article publish error', $api_post_id, $publish_error); 192 213 throw new Crowdaa_Sync_Post_Error(__('Post publish error : ', CROWDAA_SYNC_PLUGIN_NAME).$publish_error); 214 } 215 216 if ($send_notification) { 217 update_post_meta($wp_post_id, 'crowdaa_notification_sent', 'yes'); 193 218 } 194 219 … … 206 231 * @return boolean 207 232 */ 208 public function publish_post_draft_api($draft_id, $api_post_id, $publication_time) { 233 public function publish_post_draft_api( 234 $draft_id, 235 $api_post_id, 236 $publication_time, 237 $send_notification = false, 238 $notification_content = null, 239 $notification_title = null 240 ) { 209 241 $data = [ 210 'draftId' => $draft_id, 211 'date' => gmdate(CROWDAA_SYNC_ISO_TIME_FORMAT, $publication_time), 212 'sendNotifications' => false, 242 'draftId' => $draft_id, 243 'date' => gmdate(CROWDAA_SYNC_ISO_TIME_FORMAT, $publication_time), 244 'sendNotifications' => $send_notification, 245 'notificationContent' => $notification_content, 246 'notificationTitle' => $notification_title, 213 247 ]; 214 248 … … 239 273 * @param $article_data 240 274 */ 241 public function create_custom_article_api($article_data, $publication_time ) {275 public function create_custom_article_api($article_data, $publication_time, $send_notification = false) { 242 276 $auth_token = get_option('crowdaa_auth_token'); 243 277 if (!$auth_token) { … … 277 311 } 278 312 279 $publish_error = $this->publish_post_draft_api($json->draftId, $json->articleId, $publication_time); 313 $publish_error = $this->publish_post_draft_api( 314 $json->draftId, 315 $json->articleId, 316 $publication_time, 317 $send_notification 318 ); 280 319 if ($publish_error) { 281 320 Crowdaa_Sync_Logs::log('Custom article first publish error', $json->articleId, $publish_error); … … 295 334 * @param $article_data 296 335 */ 297 public function update_custom_article_api($article_data, $publication_time ) {336 public function update_custom_article_api($article_data, $publication_time, $send_notification = false) { 298 337 $auth_token = get_option('crowdaa_auth_token'); 299 338 if (!$auth_token) { … … 333 372 } 334 373 335 $publish_error = $this->publish_post_draft_api($json->draftId, $json->articleId, $publication_time); 374 $publish_error = $this->publish_post_draft_api( 375 $json->draftId, 376 $json->articleId, 377 $publication_time, 378 $send_notification 379 ); 336 380 if ($publish_error) { 337 381 Crowdaa_Sync_Logs::log('Custom article publish error', $json->articleId, $publish_error); … … 377 421 378 422 $post_content = get_post_field('post_content', $wp_post_id); 423 $post_author = get_the_author_meta('display_name', get_post_field('post_author', $wp_post_id)); 379 424 $publication_time = get_post_datetime($wp_post_id)->getTimestamp(); 380 425 … … 382 427 $wp_post_title = html_entity_decode($wp_post_title, ENT_QUOTES); 383 428 $data = [ 384 'actions' => [], 385 'categoryId' => $category_id, 386 'feedPicture' => $api_feedpicture_id, 387 'md' => $post_content ?: __('Without content', CROWDAA_SYNC_PLUGIN_NAME), 388 'pictures' => $pictures_id, 389 'summary' => $wp_post_title, 390 'hideFromFeed' => !$feed_display, 391 'productId' => '', 392 'title' => $wp_post_title, 393 'videos' => $videos_id, 429 'actions' => [], 430 'authorName' => $post_author, 431 'categoryId' => $category_id, 432 'feedPicture' => $api_feedpicture_id, 433 'md' => $post_content ?: __('Without content', CROWDAA_SYNC_PLUGIN_NAME), 434 'pictures' => $pictures_id, 435 'summary' => $wp_post_title, 436 'hideFromFeed' => !$feed_display, 437 'productId' => '', 438 'title' => $wp_post_title, 439 'videos' => $videos_id, 440 'mediaCaptions' => implode(' | ', $api_media_data['captions']), 394 441 ]; 442 $data = apply_filters('crowdaa_sync_api_create_article_payload', $data, $wp_post_id); 395 443 396 444 Crowdaa_Sync_Logs::log('Creating API post', $wp_post_id, wp_json_encode($data)); … … 414 462 } 415 463 416 $publish_error = $this->publish_post_draft_api($json->draftId, $json->articleId, $publication_time); 464 $send_notification = ( 465 get_post_meta($wp_post_id, 'crowdaa_notification_send', true) === 'yes' && 466 get_post_meta($wp_post_id, 'crowdaa_notification_sent', true) !== 'yes' 467 ); 468 $publish_error = $this->publish_post_draft_api( 469 $json->draftId, 470 $json->articleId, 471 $publication_time, 472 $send_notification, 473 (get_post_meta($wp_post_id, 'crowdaa_notification_content', true) ?: null), 474 (get_post_meta($wp_post_id, 'crowdaa_notification_title', true) ?: null), 475 ); 417 476 if ($publish_error) { 418 477 Crowdaa_Sync_Logs::log('Article first publish error', $json->articleId, $json->draftId, $publish_error); … … 421 480 422 481 update_post_meta($wp_post_id, 'api_post_id', $json->articleId); 482 if ($send_notification) { 483 update_post_meta($wp_post_id, 'crowdaa_notification_sent', 'yes'); 484 } 423 485 Crowdaa_Sync_Logs::log('Created API post', $json->articleId); 424 486 } … … 747 809 'action' => '', 748 810 ]; 811 $data = apply_filters('crowdaa_sync_api_create_category_payload', $data); 749 812 750 813 $response = $this->http_request('POST', '/press/categories', $data); … … 789 852 'name' => $cat_name, 790 853 'pathName' => $cat_slug, 791 'color' => '',792 'order' => 1,793 854 'hidden' => false, 794 'picture' => [],795 855 'parentId' => $parent_category_id, 796 856 'action' => '', 857 // 'picture' => null, 858 // 'color' => null, 859 // 'order' => null, 797 860 ]; 861 $data = apply_filters('crowdaa_sync_api_update_category_payload', $data); 798 862 799 863 $response = $this->http_request('PUT', '/press/categories/'.$cat_id, $data); … … 829 893 */ 830 894 public function delete_post_api($api_post_id) { 831 $data = [ 832 'draftId' => $api_post_id, 833 ]; 834 835 $response = $this->http_request('DELETE', '/press/articles/'.$api_post_id, $data); 895 $response = $this->http_request('DELETE', '/press/articles/'.$api_post_id); 836 896 $err = is_wp_error($response) ? $response->get_error_message() : null; 837 897 if (!$err) { -
crowdaa-sync/trunk/admin/class-crowdaa-sync-meta-box.php
r2620193 r2722017 18 18 */ 19 19 public function __construct() { 20 add_action('add_meta_boxes', [$this, ' meta_box_add'], 10, 2);21 add_action('save_post', [$this, ' img_gallery_save']);20 add_action('add_meta_boxes', [$this, 'add_meta_boxes'], 10, 2); 21 add_action('save_post', [$this, 'save_meta_boxes']); 22 22 } 23 23 … … 29 29 * @return boolean 30 30 */ 31 function meta_box_add() {31 function add_meta_boxes() { 32 32 add_meta_box( 33 33 'crowdaa_feat_img_slider', 34 'Featured Image Gallery', 35 [$this, 'print_box'], 34 'Crowdaa-sync: Featured Image Gallery', 35 [$this, 'print_feat_img_slider_box'], 36 'post', 37 'advanced', 38 'high', 39 array( 40 '__back_compat_meta_box' => false, 41 ) 42 ); 43 add_meta_box( 44 'crowdaa-sync-notification-send', 45 'Crowdaa-sync: Send notifications when published?', 46 [$this, 'print_send_notification_checkbox'], 36 47 'post', 37 48 'advanced', … … 124 135 125 136 /** 126 * Meta box html137 * Image selector meta box 127 138 * 128 139 * @since 1.0.0 … … 130 141 * @return string 131 142 */ 132 function print_ box($post) {143 function print_feat_img_slider_box($post) { 133 144 wp_nonce_field('save_feat_gallery', 'feat_gallery_nonce'); 134 145 … … 138 149 139 150 /** 140 * Save meta box data 141 * 142 * @since 1.0.0 143 * @param $post_id 144 * @return boolean 145 */ 146 function img_gallery_save($post_id) { 151 * Notification checkbox meta box 152 * 153 * @since 1.0.0 154 * @param $post 155 * @return string 156 */ 157 function print_send_notification_checkbox($post) { 158 $notification_content = get_post_meta($post->ID, 'crowdaa_notification_content', true) ?: ''; 159 $notification_title = get_post_meta($post->ID, 'crowdaa_notification_title', true) ?: ''; 160 wp_nonce_field('crowdaa_notification_checkbox', 'crowdaa_notification_checkbox_nonce'); 161 162 ?> 163 <p> 164 <i> 165 <?php 166 esc_html_e('Check this box if you want to send a notification when the article is published or right now if it is already published.', CROWDAA_SYNC_PLUGIN_NAME); 167 ?> 168 </i> 169 </p> 170 171 <div class="crowdaa-meta-box-input-row"> 172 <label> 173 <?php 174 esc_html_e('Send notification :', CROWDAA_SYNC_PLUGIN_NAME); 175 ?> 176 <input 177 type="checkbox" 178 name="crowdaa_send_post_notification" 179 /> 180 </label> 181 </div> 182 <div class="crowdaa-meta-box-input-row"> 183 <label> 184 <?php 185 esc_html_e('Notification text (When both are not set, defaults to the article title & first characters) :', CROWDAA_SYNC_PLUGIN_NAME); 186 ?> 187 <br /> 188 <input 189 style="display: inline-block; width: 500px;" 190 type="text" 191 name="crowdaa_send_post_notification_title" 192 placeholder="<?php esc_attr_e('Notification title', CROWDAA_SYNC_PLUGIN_NAME); ?>" 193 value="<?php echo esc_attr($notification_title); ?>" 194 /> 195 <br /> 196 <input 197 style="display: inline-block; width: 500px;" 198 type="text" 199 name="crowdaa_send_post_notification_content" 200 placeholder="<?php esc_attr_e('Notification content', CROWDAA_SYNC_PLUGIN_NAME); ?>" 201 value="<?php echo esc_attr($notification_content); ?>" 202 /> 203 </label> 204 </div> 205 <?php 206 } 207 208 function save_gallery_meta_box($post_id) { 147 209 if (!isset($_POST['feat_gallery_nonce'])) { 148 return $post_id; 149 } 150 151 if (!wp_verify_nonce($_POST['feat_gallery_nonce'], 'save_feat_gallery')) { 152 return $post_id; 210 return; 211 } else if (!wp_verify_nonce($_POST['feat_gallery_nonce'], 'save_feat_gallery')) { 212 return; 213 } else if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) { 214 return; 215 } else if (!current_user_can('edit_post', $post_id)) { 216 return; 153 217 } 154 218 … … 167 231 } 168 232 } 233 234 function save_notifications_meta_box($post_id) { 235 if (!isset($_POST['crowdaa_notification_checkbox_nonce'])) { 236 return; 237 } else if (!wp_verify_nonce($_POST['crowdaa_notification_checkbox_nonce'], 'crowdaa_notification_checkbox')) { 238 return; 239 } else if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) { 240 return; 241 } else if (!current_user_can('edit_post', $post_id)) { 242 return; 243 } 244 245 if (isset($_POST['crowdaa_send_post_notification'])) { 246 update_post_meta($post_id, 'crowdaa_notification_send', 'yes'); 247 update_post_meta($post_id, 'crowdaa_notification_sent', 'no'); 248 update_post_meta($post_id, 'crowdaa_notification_title', $_POST['crowdaa_send_post_notification_title'] ?: ''); 249 update_post_meta($post_id, 'crowdaa_notification_content', $_POST['crowdaa_send_post_notification_content'] ?: ''); 250 } 251 } 252 253 /** 254 * Save meta boxes data 255 * 256 * @since 1.0.0 257 * @param $post_id 258 * @return boolean 259 */ 260 function save_meta_boxes($post_id) { 261 $this->save_gallery_meta_box($post_id); 262 $this->save_notifications_meta_box($post_id); 263 } 169 264 } -
crowdaa-sync/trunk/admin/css/crowdaa-sync-admin.css
r2620193 r2722017 31 31 display: flex; 32 32 flex-direction: row; 33 max-width: 310px; 33 justify-content: space-between; 34 max-width: 400px; 34 35 } 35 36 … … 39 40 40 41 .sync-form-label { 41 width: 250px;42 width: 300px; 42 43 display: inline-block; 43 44 } … … 47 48 } 48 49 49 .sync- feed-categories-select {50 .sync-categories-select { 50 51 min-height: 150px !important; 51 52 width: 600px; … … 69 70 position: absolute; 70 71 top: -7px; 72 right: 0px; 71 73 height: 30px; 72 74 line-height: 30px; … … 83 85 content: "ON"; 84 86 color: #0a0; 87 } 88 89 .sync-enable-checkbox-custom { 90 visibility: hidden; 91 cursor: pointer; 92 } 93 94 .sync-enable-checkbox-custom+.sync-enable-checkbox-custom-content { 95 display: block; 96 height: 30px; 97 line-height: 30px; 98 width: auto; 99 padding: 0 10px; 100 text-align: center; 101 border-radius: 4px; 102 background: #fff; 103 color: rgb(4, 174, 216); 104 font-weight: 600; 105 cursor: pointer; 106 } 107 108 .sync-enable-checkbox-custom:checked+.sync-enable-checkbox-custom-content { 109 color: rgb(255, 167, 0); 110 } 111 112 .sync-enable-checkbox-custom+.sync-enable-checkbox-custom-content .sync-enable-checkbox-custom-checked { 113 display: none; 114 } 115 116 .sync-enable-checkbox-custom+.sync-enable-checkbox-custom-content .sync-enable-checkbox-custom-unchecked { 117 display: inline; 118 } 119 120 .sync-enable-checkbox-custom:checked+.sync-enable-checkbox-custom-content .sync-enable-checkbox-custom-unchecked { 121 display: none; 122 } 123 124 .sync-enable-checkbox-custom:checked+.sync-enable-checkbox-custom-content .sync-enable-checkbox-custom-checked { 125 display: inline; 85 126 } 86 127 … … 177 218 padding: 5px 10px; 178 219 } 220 221 .crowdaa-meta-box-input-row { 222 display: block; 223 margin-bottom: 10px; 224 } -
crowdaa-sync/trunk/admin/js/crowdaa-sync-admin.js
r2620193 r2722017 91 91 updateFeedCategoriesSelect(); 92 92 93 function updateSyncCategoriesSelect() { 94 const $field = $('#crowdaa-sync-categories-mode-whitelist-checkbox'); 95 const $whitelistText = $('#crowdaa-sync-categories-explanation-whitelist'); 96 const $blacklistText = $('#crowdaa-sync-categories-explanation-blacklist'); 97 if ($field.prop('checked')) { 98 $whitelistText.show(); 99 $blacklistText.hide(); 100 } else { 101 $whitelistText.hide(); 102 $blacklistText.show(); 103 } 104 } 105 $('#crowdaa-sync-categories-mode-whitelist-checkbox').on('change', updateSyncCategoriesSelect); 106 updateSyncCategoriesSelect(); 107 93 108 /** 94 109 * Ajax add posts and terms -
crowdaa-sync/trunk/admin/partials/crowdaa-sync-admin-display.php
r2620193 r2722017 115 115 <?php do_action('crowdaa_sync_configuration_levers'); ?> 116 116 <label class="sync-form-checkbox-label"> 117 <span class="sync-form-label"><?php esc_html_e('Maximum synchronization duration '); ?></span> 117 <span class="sync-form-label"><?php esc_html_e('Maximum synchronization duration (minutes)'); ?></span> 118 118 <input type="number" name="sync_max_duration" min="2" id="sync-duration-field" 119 119 value="<?php echo esc_attr($sync_max_duration); ?>" 120 120 /> 121 <?php esc_html_e('minutes'); ?>122 121 </label> 123 122 <br /> … … 147 146 <?php 148 147 submit_button('Save picture'); 148 ?> 149 </form> 150 </div> 151 152 <hr/> 153 154 <div> 155 <h2><?php esc_html_e('Set categories to synchronize', CROWDAA_SYNC_PLUGIN_NAME) ?></h2> 156 <form method="post" action="<?php $admin_utils->choose_sync_categories(); ?>" enctype="multipart/form-data"> 157 <?php 158 $sync_categories_mode = get_option('crowdaa_sync_categories_mode', 'blacklist'); 159 $sync_categories_list = explode(',', get_option('crowdaa_sync_categories_list', '')); 160 ?> 161 <label class="sync-form-checkbox-label"> 162 <span class="sync-form-label"><?php esc_html_e('Categories sync mode', CROWDAA_SYNC_PLUGIN_NAME); ?></span> 163 <input 164 type="checkbox" 165 name="sync_categories_mode_whitelist" 166 class="sync-enable-checkbox-custom" 167 id="crowdaa-sync-categories-mode-whitelist-checkbox" 168 <?php echo ($sync_categories_mode === 'whitelist' ? 'checked="checked"' : ''); ?> 169 /> 170 <span class="sync-enable-checkbox-custom-content"> 171 <span class="sync-enable-checkbox-custom-checked">Whitelist</span> 172 <span class="sync-enable-checkbox-custom-unchecked">Blacklist</span> 173 </span> 174 </label> 175 <div id="crowdaa-sync-categories-select-area"> 176 <label> 177 <p> 178 <span id="crowdaa-sync-categories-explanation-whitelist"> 179 <?php esc_html_e('Select below the categories that you *want* to synchronize to the app.', CROWDAA_SYNC_PLUGIN_NAME); ?> 180 </span> 181 <span id="crowdaa-sync-categories-explanation-blacklist"> 182 <?php esc_html_e('Select below the categories that you *do not want* to synchronize to the app.', CROWDAA_SYNC_PLUGIN_NAME); ?> 183 </span> 184 <br /> 185 <?php esc_html_e('Use the Ctrl or Shift keys to select multiple categories.', CROWDAA_SYNC_PLUGIN_NAME); ?><br /> 186 </p> 187 <?php 188 $terms = get_terms([ 189 "hide_empty" => false, 190 "taxonomy" => "category", 191 ]); 192 ?> 193 <select class="sync-categories-select" name="sync_categories[]" multiple> 194 <option 195 value="" 196 <?php echo (array_search('', $sync_categories_list) !== false ? 'selected="selected"' : ''); ?> 197 > 198 <?php esc_html_e('---', CROWDAA_SYNC_PLUGIN_NAME); ?> 199 </option> 200 <?php foreach ($terms as $term) { ?> 201 <option 202 value="<?php echo esc_attr($term->term_id); ?>" 203 <?php echo (array_search($term->term_id, $sync_categories_list) !== false ? 'selected="selected"' : ''); ?> 204 > 205 <?php esc_html_e($term->name.' ('.$term->slug.')', CROWDAA_SYNC_PLUGIN_NAME); ?> 206 </option> 207 <?php } ?> 208 </select> 209 </label> 210 </div> 211 <?php wp_nonce_field('crowdaa_set_sync_categories_data', 'crowdaa_set_sync_categories'); ?> 212 <?php 213 submit_button('Save mode & categories'); 149 214 ?> 150 215 </form> … … 173 238 <p> 174 239 <?php esc_html_e('Select below the categories that you want to see on the feed page.', CROWDAA_SYNC_PLUGIN_NAME); ?><br /> 175 <?php esc_html_e('Use the Ctrl or Shift keys to select multiple categories ', CROWDAA_SYNC_PLUGIN_NAME); ?><br />240 <?php esc_html_e('Use the Ctrl or Shift keys to select multiple categories.', CROWDAA_SYNC_PLUGIN_NAME); ?><br /> 176 241 </p> 177 242 <?php … … 179 244 "hide_empty" => false, 180 245 "taxonomy" => "category", 181 "childless" => true182 246 ]); 183 247 if ($feed_categories === 'all') { … … 187 251 } 188 252 ?> 189 <select class="sync-feed-categories-select" name="sync_feed_categories[]" multiple> 190 <option value=""> 191 <?php esc_html_e('None', CROWDAA_SYNC_PLUGIN_NAME); ?> 253 <select class="sync-categories-select" name="sync_feed_categories[]" multiple> 254 <option 255 value="" 256 <?php echo (array_search('', $feed_categories) !== false ? 'selected="selected"' : ''); ?> 257 > 258 <?php esc_html_e('---', CROWDAA_SYNC_PLUGIN_NAME); ?> 192 259 </option> 193 260 <?php foreach ($terms as $term) { ?> -
crowdaa-sync/trunk/crowdaa-sync.php
r2620193 r2722017 14 14 * Plugin URI: 15 15 * Description: Plugin for synchronizing WordPress site and Crowdaa CMS 16 * Version: 1. 0.5016 * Version: 1.1.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. 0.50');36 define('CROWDAA_SYNC_VERSION', '1.1.0'); 37 37 define('CROWDAA_SYNC_PLUGIN_DIR', __DIR__); 38 38 define('CROWDAA_SYNC_PLUGIN_NAME', 'crowdaa-sync'); … … 48 48 $last_version = get_option('crowdaa_last_version', false); 49 49 if (!$last_version || $last_version < CROWDAA_SYNC_META_VERSION) { 50 update_option('crowdaa_sync_ wp_to_api_from', 0);50 update_option('crowdaa_sync_articles_wp_to_api_from', 0); 51 51 update_option('crowdaa_last_version', CROWDAA_SYNC_META_VERSION); 52 52 } … … 111 111 } 112 112 113 if (class_exists('Crowdaa_Sync_Ext_Hooks')) { 114 new Crowdaa_Sync_Ext_Hooks; 115 } 116 113 117 if (class_exists('Crowdaa_Sync_Admin_Display')) { 114 118 new Crowdaa_Sync_Admin_Display; -
crowdaa-sync/trunk/includes/class-crowdaa-sync-versions.php
r2620193 r2722017 19 19 if (!$last_version || $last_version < CROWDAA_SYNC_META_VERSION) { 20 20 update_option('crowdaa_last_version', CROWDAA_SYNC_META_VERSION); 21 update_option('crowdaa_sync_ wp_to_api_from', 0);21 update_option('crowdaa_sync_articles_wp_to_api_from', 0); 22 22 update_option('crowdaa_sync_internal_version', '0'); 23 23 } … … 36 36 update_option('crowdaa_sync_internal_version', "$ver"); 37 37 38 update_option('crowdaa_sync_ wp_to_api_from', 0);38 update_option('crowdaa_sync_articles_wp_to_api_from', 0); 39 39 40 40 self::update_versions(); -
crowdaa-sync/trunk/includes/class-crowdaa-sync.php
r2620193 r2722017 180 180 require_once CROWDAA_SYNC_PLUGIN_DIR.'/admin/class-crowdaa-sync-wp-hooks.php'; 181 181 182 /** 183 * The class for other plugin hooks 184 */ 185 require_once CROWDAA_SYNC_PLUGIN_DIR.'/admin/class-crowdaa-sync-ext-hooks.php'; 186 182 187 $this->loader = new Crowdaa_Sync_Loader(); 183 188 }
Note: See TracChangeset
for help on using the changeset viewer.