Changeset 2762188
- Timestamp:
- 07/27/2022 07:15:21 AM (4 years ago)
- Location:
- crowdaa-sync
- Files:
-
- 9 edited
- 30 copied
-
tags/1.3.0 (copied) (copied from crowdaa-sync/trunk)
-
tags/1.3.0/CHANGELOG (copied) (copied from crowdaa-sync/trunk/CHANGELOG) (1 diff)
-
tags/1.3.0/LICENSE.txt (copied) (copied from crowdaa-sync/trunk/LICENSE.txt)
-
tags/1.3.0/README.txt (copied) (copied from crowdaa-sync/trunk/README.txt) (1 diff)
-
tags/1.3.0/admin (copied) (copied from crowdaa-sync/trunk/admin)
-
tags/1.3.0/admin/class-crowdaa-sync-add-info-api.php (copied) (copied from crowdaa-sync/trunk/admin/class-crowdaa-sync-add-info-api.php) (11 diffs)
-
tags/1.3.0/admin/class-crowdaa-sync-add-info-wp.php (copied) (copied from crowdaa-sync/trunk/admin/class-crowdaa-sync-add-info-wp.php) (9 diffs)
-
tags/1.3.0/admin/class-crowdaa-sync-admin-display.php (copied) (copied from crowdaa-sync/trunk/admin/class-crowdaa-sync-admin-display.php)
-
tags/1.3.0/admin/class-crowdaa-sync-api.php (copied) (copied from crowdaa-sync/trunk/admin/class-crowdaa-sync-api.php) (11 diffs)
-
tags/1.3.0/admin/class-crowdaa-sync-ext-hooks.php (copied) (copied from crowdaa-sync/trunk/admin/class-crowdaa-sync-ext-hooks.php)
-
tags/1.3.0/admin/class-crowdaa-sync-meta-box.php (copied) (copied from crowdaa-sync/trunk/admin/class-crowdaa-sync-meta-box.php) (4 diffs)
-
tags/1.3.0/admin/class-crowdaa-sync-wp-hooks.php (copied) (copied from crowdaa-sync/trunk/admin/class-crowdaa-sync-wp-hooks.php)
-
tags/1.3.0/admin/css/crowdaa-sync-admin.css (copied) (copied from crowdaa-sync/trunk/admin/css/crowdaa-sync-admin.css)
-
tags/1.3.0/admin/js/crowdaa-sync-admin.js (copied) (copied from crowdaa-sync/trunk/admin/js/crowdaa-sync-admin.js)
-
tags/1.3.0/admin/partials/crowdaa-sync-admin-display.php (copied) (copied from crowdaa-sync/trunk/admin/partials/crowdaa-sync-admin-display.php)
-
tags/1.3.0/cacert.pem (copied) (copied from crowdaa-sync/trunk/cacert.pem)
-
tags/1.3.0/composer.json (copied) (copied from crowdaa-sync/trunk/composer.json)
-
tags/1.3.0/crowdaa-sync.php (copied) (copied from crowdaa-sync/trunk/crowdaa-sync.php) (2 diffs)
-
tags/1.3.0/includes (copied) (copied from crowdaa-sync/trunk/includes)
-
tags/1.3.0/includes/class-crowdaa-sync-exception.php (copied) (copied from crowdaa-sync/trunk/includes/class-crowdaa-sync-exception.php)
-
tags/1.3.0/includes/class-crowdaa-sync-permissions.php (copied) (copied from crowdaa-sync/trunk/includes/class-crowdaa-sync-permissions.php)
-
tags/1.3.0/includes/class-crowdaa-sync-syncdb.php (copied) (copied from crowdaa-sync/trunk/includes/class-crowdaa-sync-syncdb.php)
-
tags/1.3.0/includes/class-crowdaa-sync-timer.php (modified) (4 diffs)
-
tags/1.3.0/includes/class-crowdaa-sync-utils.php (copied) (copied from crowdaa-sync/trunk/includes/class-crowdaa-sync-utils.php)
-
tags/1.3.0/includes/class-crowdaa-sync-versions.php (copied) (copied from crowdaa-sync/trunk/includes/class-crowdaa-sync-versions.php)
-
tags/1.3.0/includes/class-crowdaa-sync.php (copied) (copied from crowdaa-sync/trunk/includes/class-crowdaa-sync.php)
-
tags/1.3.0/index.php (copied) (copied from crowdaa-sync/trunk/index.php)
-
tags/1.3.0/languages (copied) (copied from crowdaa-sync/trunk/languages)
-
tags/1.3.0/public (copied) (copied from crowdaa-sync/trunk/public)
-
tags/1.3.0/uninstall.php (copied) (copied from crowdaa-sync/trunk/uninstall.php)
-
tags/1.3.0/vendor (copied) (copied from crowdaa-sync/trunk/vendor)
-
trunk/CHANGELOG (modified) (1 diff)
-
trunk/README.txt (modified) (1 diff)
-
trunk/admin/class-crowdaa-sync-add-info-api.php (modified) (11 diffs)
-
trunk/admin/class-crowdaa-sync-add-info-wp.php (modified) (9 diffs)
-
trunk/admin/class-crowdaa-sync-api.php (modified) (11 diffs)
-
trunk/admin/class-crowdaa-sync-meta-box.php (modified) (4 diffs)
-
trunk/crowdaa-sync.php (modified) (2 diffs)
-
trunk/includes/class-crowdaa-sync-timer.php (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
crowdaa-sync/tags/1.3.0/CHANGELOG
r2757731 r2762188 6 6 7 7 ## [Unreleased] 8 9 ## [1.3.0] - 2022-07-27 10 11 ### Added 12 - Synchronization of category images, using the `custom-category-image` plugin 13 - Added a `fullscreen` option on an article to display an article as fullscreen on the app 14 15 ### Changed 16 - Fixed a feedPicture synchronization issue from API to WP 17 - Fixed an execution timeout issue (was not stopping before the php execution timeout, as it should) 8 18 9 19 ## [1.2.4] - 2022-07-15 -
crowdaa-sync/tags/1.3.0/README.txt
r2757731 r2762188 6 6 Requires PHP: 7.3 7 7 Tested up to: 5.9 8 Stable tag: 1. 2.48 Stable tag: 1.3.0 9 9 License: GPLv2 or later 10 10 License URI: http://www.gnu.org/licenses/gpl-2.0.html -
crowdaa-sync/tags/1.3.0/admin/class-crowdaa-sync-add-info-api.php
r2744975 r2762188 145 145 ]; 146 146 147 if (Crowdaa_Sync_Utils::have_plugin('custom-category-image')) { 148 $id = get_term_meta($term->term_id, '_category_image_id', true); 149 if ($id) { 150 $data['picture'] = $id; 151 } 152 } 153 147 154 if (isset($term->rootParentId)) { 148 155 $data['rootParentId'] = $term->rootParentId; … … 168 175 'parentId' => $category->parentId, 169 176 ]; 177 178 if (Crowdaa_Sync_Utils::have_plugin('custom-category-image')) { 179 if ($category->picture) { 180 if (is_object($category->picture[0]) && isset($category->picture[0]->pictureUrl)) { 181 $data['picture'] = $category->picture[0]->_id; 182 } else if (is_string($category->picture[0])) { 183 $data['picture'] = $category->picture[0]; 184 } 185 } 186 } 170 187 171 188 if (Crowdaa_Sync_Utils::have_plugin('paid-memberships-pro')) { … … 357 374 } 358 375 $category->hash = self::hash_category($category); 376 $category->pictureData = null; 377 if ($category->picture && isset($category->picture[0]->pictureUrl)) { 378 $category->pictureData = [ 379 'id' => $category->picture[0]->_id, 380 'url' => $category->picture[0]->pictureUrl, 381 ]; 382 } 359 383 $categories_by_id[$category->_id] = $category; 360 384 } … … 370 394 foreach ($all_terms as $term) { 371 395 $term->perms = []; 396 $term->image = null; 372 397 373 398 if (Crowdaa_Sync_Utils::have_plugin('paid-memberships-pro')) { … … 382 407 } 383 408 $term->perms = $perms_array; 409 } 410 if (Crowdaa_Sync_Utils::have_plugin('custom-category-image')) { 411 $term->image = get_term_meta($term->term_id, '_category_image_id', true); 384 412 } 385 413 … … 493 521 'parentId' => $term->rootParentId, 494 522 'perms' => $term->perms, 523 'image' => $term->image, 495 524 'hash' => $term->hash, 496 525 ]; … … 503 532 'parentId' => $term->rootParentId, 504 533 'perms' => $term->perms, 534 'image' => $term->image, 505 535 'hash' => $term->hash, 506 536 ]; … … 532 562 'parentId' => $category->parentId, 533 563 'badges' => $category->badges, 564 'picture' => $category->pictureData, 534 565 'hash' => $category->hash, 535 566 ]; … … 542 573 'parentId' => $category->parentId, 543 574 'badges' => $category->badges, 575 'picture' => $category->pictureData, 544 576 'hash' => $category->hash, 545 577 ]; … … 1114 1146 } 1115 1147 1116 $category = $sync_api->create_category($curTerm['name'], $curTerm['slug'], $parentId, $badges); 1148 $category_picture_id = false; 1149 if (Crowdaa_Sync_Utils::have_plugin('custom-category-image')) { 1150 $category_picture_id = $sync_api->sync_term_images($curTerm['wp_id']); 1151 } 1152 $category = $sync_api->create_category($curTerm['name'], $curTerm['slug'], $parentId, $badges, $category_picture_id); 1117 1153 $sync_db->create_entry($curTerm['wp_id'], $category->_id, [ 1118 1154 'category_hash' => self::hash_category($category), … … 1132 1168 } 1133 1169 1134 $category = $sync_api->update_category($curTerm['api_id'], $curTerm['name'], $curTerm['slug'], $parentId, $badges); 1170 $category_picture_id = false; 1171 if (Crowdaa_Sync_Utils::have_plugin('custom-category-image')) { 1172 $category_picture_id = $sync_api->sync_term_images($curTerm['wp_id']); 1173 } 1174 $category = $sync_api->update_category($curTerm['api_id'], $curTerm['name'], $curTerm['slug'], $parentId, $badges, $category_picture_id); 1135 1175 $sync_db->update_entry(['api_id' => $curTerm['api_id']], [ 1136 1176 'sync_data' => [ -
crowdaa-sync/tags/1.3.0/admin/class-crowdaa-sync-add-info-wp.php
r2756893 r2762188 247 247 248 248 $term = $this->create_term($curCategory['name'], $curCategory['slug'], $parentId, $curCategory['badges']); 249 if (Crowdaa_Sync_Utils::have_plugin('custom-category-image')) { 250 $this->post_sync_api_term_picture($term->term_id, $curCategory['picture']); 251 } 249 252 $term->rootParentId = $parentId; 250 253 $sync_db->create_entry($term->term_id, $curCategory['api_id'], [ … … 260 263 261 264 $term = $this->update_term($curCategory['wp_id'], $curCategory['name'], $curCategory['slug'], $parentId, $curCategory['badges']); 265 if (Crowdaa_Sync_Utils::have_plugin('custom-category-image')) { 266 $this->post_sync_api_term_picture($term->term_id, $curCategory['picture']); 267 } 262 268 $term->rootParentId = $parentId; 263 269 $sync_db->update_entry(['wp_id' => $curCategory['wp_id']], [ … … 360 366 update_post_meta($wp_post_id, 'api_post_id', $api_data->_id); 361 367 368 $fullscreen = false; 369 if (isset($api_data->displayOptions) && isset($api_data->displayOptions->fullscreen)) { 370 $fullscreen = $api_data->displayOptions->fullscreen; 371 } 372 update_post_meta($wp_post_id, 'display_option_fullscreen', ($fullscreen ? 'yes' : 'no')); 373 362 374 wp_set_post_terms($wp_post_id, [$term], 'category'); 363 375 … … 412 424 update_post_meta($wp_post_id, 'api_post_id', $api_data->_id); 413 425 426 $fullscreen = false; 427 if (isset($api_data->displayOptions) && isset($api_data->displayOptions->fullscreen)) { 428 $fullscreen = $api_data->displayOptions->fullscreen; 429 } 430 update_post_meta($wp_post_id, 'display_option_fullscreen', ($fullscreen ? 'yes' : 'no')); 431 414 432 $sync_errors = $this->post_sync_api_medias($api_data, $wp_post_id); 415 433 if ($sync_errors) { … … 485 503 } 486 504 505 private function post_sync_api_term_picture($wp_term_id, $api_image) { 506 $synced_picture_prev_image = null; 507 $synced_picture_ids_raw = get_term_meta($wp_term_id, 'crowdaa_picture', true); 508 if ($synced_picture_ids_raw) { 509 $synced_picture_ids = unserialize($synced_picture_ids_raw); 510 $synced_picture_prev_image = $synced_picture_ids['api_id']; 511 } 512 513 $api_image_id = null; 514 $api_image_url = null; 515 if ($api_image) { 516 $api_image_id = $api_image['id']; 517 $api_image_url = $api_image['url']; 518 } 519 520 if ($synced_picture_prev_image !== $api_image_id) { 521 if ($api_image_id) { 522 $ext = pathinfo(parse_url($api_image_url, PHP_URL_PATH), PATHINFO_EXTENSION); 523 if (!$ext) $ext = 'jpg'; 524 $feed_pic_name = $api_image_id.'.'.$ext; 525 $fetch_err = false; 526 if(!$this->check_uploads($feed_pic_name)) { 527 $fetch_err = $this->get_uploads($api_image_url, $feed_pic_name); 528 if ($fetch_err) { 529 Crowdaa_Sync_Logs::log('Term image download error', $wp_term_id, $api_image_id, $fetch_err); 530 throw new Crowdaa_Sync_Category_Error(__('Errors when downloading term image for ', CROWDAA_SYNC_PLUGIN_NAME).$wp_term_id.' : '.$fetch_err); 531 } 532 } 533 534 try { 535 $attachment_id = $this->set_term_upload($wp_term_id, $feed_pic_name); 536 update_term_meta($wp_term_id, 'crowdaa_picture', serialize([ 537 'api_id' => $api_image_id, 538 'attachment_id' => $attachment_id, 539 ])); 540 } catch (Exception $e) { 541 Crowdaa_Sync_Logs::log('Set WP term feed picture error', $e->getMessage()); 542 throw new Crowdaa_Sync_Category_Error(__('Set WP term feed picture error : ', CROWDAA_SYNC_PLUGIN_NAME).$e->getMessage()); 543 } 544 } else { 545 delete_term_meta($wp_term_id, 'crowdaa_picture'); 546 delete_term_meta($wp_term_id, '_category_image_id'); 547 } 548 } 549 } 550 487 551 /** 488 552 * Feed picture processing from API to WP … … 507 571 else if ($api_data->pictures) $article_pic = $api_data->pictures[0]; 508 572 509 $have_a_picture = isset($api_data->feedPicture ) || $article_vid || $article_pic;510 if (isset($api_data->feedPicture )) {573 $have_a_picture = isset($api_data->feedPicture->_id) || $article_vid || $article_pic; 574 if (isset($api_data->feedPicture->_id)) { 511 575 $feed_pic_url = $api_data->feedPicture->pictureUrl; 512 $feed_pic_id = $api_data->feedPicture-> pictur_ideUrl;576 $feed_pic_id = $api_data->feedPicture->_id; 513 577 } else if ($article_vid) { 514 578 $feed_pic_url = $article_vid->thumbUrl; … … 545 609 } else { 546 610 $ext = pathinfo(parse_url($feed_pic_url, PHP_URL_PATH), PATHINFO_EXTENSION); 611 if (!$ext) $ext = 'jpg'; 547 612 $feed_pic_name = $feed_pic_id.'-thumbnail.'.$ext; 548 613 $fetch_err = false; … … 600 665 $image_url = $image->pictureUrl; 601 666 $ext = pathinfo(parse_url($image_url, PHP_URL_PATH), PATHINFO_EXTENSION); 667 if (!$ext) $ext = 'jpg'; 602 668 $image_name = $image_id.'.'.$ext; 603 669 … … 713 779 return false; 714 780 } 781 } 782 783 private function set_term_upload($wp_term_id, $img_name) { 784 $wp_upload_dir = wp_upload_dir(); 785 $upload_dir_path = $wp_upload_dir['basedir'].'/catalogue_images/'; 786 $img_full_path = $upload_dir_path.$img_name; 787 $post_mime_type = mime_content_type($img_full_path); 788 $attachment = [ 789 'guid' => $wp_upload_dir['url'].'/'.$upload_dir_path, 790 'post_mime_type' => $post_mime_type, 791 'post_title' => sanitize_file_name(pathinfo($img_name, PATHINFO_FILENAME)), 792 'post_content' => '', 793 'post_status' => 'inherit', 794 ]; 795 $attach_id = wp_insert_attachment($attachment, $img_name, $wp_term_id); 796 $attach_data = wp_generate_attachment_metadata($attach_id, $img_full_path); 797 wp_update_attachment_metadata($attach_id, $attach_data); 798 update_attached_file($attach_id, $img_full_path); 799 800 update_term_meta($wp_term_id, '_category_image_id', $attach_id); 801 802 Crowdaa_Sync_Logs::log('Added term media to Wordpress', wp_json_encode([ 803 'wp_term_id' => $wp_term_id, 804 'attach_id' => $attach_id, 805 'img_name' => $img_name, 806 ])); 807 808 return ($attach_id); 715 809 } 716 810 -
crowdaa-sync/tags/1.3.0/admin/class-crowdaa-sync-api.php
r2744975 r2762188 190 190 } 191 191 192 $fullscreen = (get_post_meta($wp_post_id, 'display_option_fullscreen', true) === 'yes'); 192 193 $post_content = get_post_field('post_content', $wp_post_id); 193 194 $post_author = get_the_author_meta('display_name', get_post_field('post_author', $wp_post_id)); … … 197 198 $wp_post_title = html_entity_decode($wp_post_title, ENT_QUOTES); 198 199 $data = [ 199 'articleId' => $api_post_id, 200 'actions' => [], 201 'authorName' => $post_author, 202 'categoryId' => $category_id, 203 'feedPicture' => $api_feedpicture_id, 204 'md' => $post_content ?: __('Without content', CROWDAA_SYNC_PLUGIN_NAME), 205 'pictures' => $pictures_id, 206 'summary' => $wp_post_title, 207 'hideFromFeed' => !$feed_display, 208 'productId' => '', 209 'title' => $wp_post_title, 210 'videos' => $videos_id, 211 'mediaCaptions' => implode(' | ', $api_media_data['captions']), 200 'articleId' => $api_post_id, 201 'actions' => [], 202 'authorName' => $post_author, 203 'categoryId' => $category_id, 204 'feedPicture' => $api_feedpicture_id, 205 'md' => $post_content ?: __('Without content', CROWDAA_SYNC_PLUGIN_NAME), 206 'pictures' => $pictures_id, 207 'summary' => $wp_post_title, 208 'hideFromFeed' => !$feed_display, 209 'productId' => '', 210 'title' => $wp_post_title, 211 'videos' => $videos_id, 212 'mediaCaptions' => implode(' | ', $api_media_data['captions']), 213 'displayOptions' => [ 214 'fullscreen' => $fullscreen, 215 ], 212 216 ]; 213 217 $data = apply_filters('crowdaa_sync_api_update_article_payload', $data, $wp_post_id); … … 451 455 } 452 456 457 $fullscreen = (get_post_meta($wp_post_id, 'display_option_fullscreen', true) === 'yes'); 453 458 $post_content = get_post_field('post_content', $wp_post_id); 454 459 $post_author = get_the_author_meta('display_name', get_post_field('post_author', $wp_post_id)); … … 458 463 $wp_post_title = html_entity_decode($wp_post_title, ENT_QUOTES); 459 464 $data = [ 460 'actions' => [], 461 'authorName' => $post_author, 462 'categoryId' => $category_id, 463 'feedPicture' => $api_feedpicture_id, 464 'md' => $post_content ?: __('Without content', CROWDAA_SYNC_PLUGIN_NAME), 465 'pictures' => $pictures_id, 466 'summary' => $wp_post_title, 467 'hideFromFeed' => !$feed_display, 468 'productId' => '', 469 'title' => $wp_post_title, 470 'videos' => $videos_id, 471 'mediaCaptions' => implode(' | ', $api_media_data['captions']), 465 'actions' => [], 466 'authorName' => $post_author, 467 'categoryId' => $category_id, 468 'feedPicture' => $api_feedpicture_id, 469 'md' => $post_content ?: __('Without content', CROWDAA_SYNC_PLUGIN_NAME), 470 'pictures' => $pictures_id, 471 'summary' => $wp_post_title, 472 'hideFromFeed' => !$feed_display, 473 'productId' => '', 474 'title' => $wp_post_title, 475 'videos' => $videos_id, 476 'mediaCaptions' => implode(' | ', $api_media_data['captions']), 477 'displayOptions' => [ 478 'fullscreen' => $fullscreen, 479 ], 472 480 ]; 473 481 $data = apply_filters('crowdaa_sync_api_create_article_payload', $data, $wp_post_id); … … 655 663 } 656 664 657 public function get_attachment_data($attachment_id, $wp_post_id ) {665 public function get_attachment_data($attachment_id, $wp_post_id = null) { 658 666 $attachment_metadata = wp_get_attachment_metadata($attachment_id); 659 667 $file = get_attached_file($attachment_id); … … 764 772 'attachment_id' => $attachment_id, 765 773 'url' => $image_url, 774 ])); 775 } else if ($img_type === 'term_picture') { 776 update_term_meta($wp_post_id, 'crowdaa_picture', serialize([ 777 'attachment_id' => $attachment_id, 778 'api_id' => $json->id, 766 779 ])); 767 780 } … … 909 922 } 910 923 924 public function sync_term_images($wp_term_id) { 925 $synced_picture_prev_attachment = null; 926 $synced_picture_ids_raw = get_term_meta($wp_term_id, 'crowdaa_picture', true); 927 if ($synced_picture_ids_raw) { 928 $synced_picture_ids = unserialize($synced_picture_ids_raw); 929 $synced_picture_prev_attachment = $synced_picture_ids['attachment_id']; 930 } 931 932 $picture_id = get_term_meta($wp_term_id, '_category_image_id', true); 933 if (!$picture_id) $picture_id = null; 934 else $picture_id = ''.$picture_id; 935 936 if ($synced_picture_prev_attachment !== $picture_id) { 937 if ($picture_id) { 938 $file_data = $this->get_attachment_data($picture_id, $wp_term_id); 939 if ($file_data) { 940 $api_id = null; 941 $errors = $this->create_image_api($file_data, 'term_picture', $api_id); 942 if ($errors) { 943 Crowdaa_Sync_Logs::log('Term image upload error', wp_json_encode($file_data), wp_json_encode($errors)); 944 throw new Crowdaa_Sync_Category_Error(__('Errors when uploading category image for ', CROWDAA_SYNC_PLUGIN_NAME).$wp_term_id.' : '.implode(' | ', $errors)); 945 } 946 } 947 } else { 948 delete_term_meta($wp_term_id, 'crowdaa_picture'); 949 } 950 } 951 952 $synced_picture_ids_raw = get_term_meta($wp_term_id, 'crowdaa_picture', true); 953 if ($synced_picture_ids_raw) { 954 $synced_picture_ids = unserialize($synced_picture_ids_raw); 955 $ret = $synced_picture_ids['api_id']; 956 return ($synced_picture_ids['api_id']); 957 } 958 959 return (null); 960 } 961 911 962 /** 912 963 * Create category on the API … … 918 969 * @return boolean 919 970 */ 920 public function create_category($cat_name, $cat_slug, $parent_category_id, $badges ) {971 public function create_category($cat_name, $cat_slug, $parent_category_id, $badges, $picture_id) { 921 972 $data = [ 922 973 'name' => $cat_name, … … 935 986 } 936 987 988 if ($picture_id) { 989 $data['picture'][0] = $picture_id; 990 } 991 937 992 $data = apply_filters('crowdaa_sync_api_create_category_payload', $data); 938 993 … … 969 1024 * @return boolean 970 1025 */ 971 public function update_category($cat_id, $cat_name, $cat_slug, $parent_category_id, $badges ) {1026 public function update_category($cat_id, $cat_name, $cat_slug, $parent_category_id, $badges, $picture_id = false) { 972 1027 $data = [ 973 1028 'name' => $cat_name, … … 986 1041 } 987 1042 1043 if ($picture_id !== false) { 1044 if ($picture_id) $data['picture'] = [$picture_id]; 1045 else $data['picture'] = []; 1046 } 1047 988 1048 $data = apply_filters('crowdaa_sync_api_update_category_payload', $data); 989 1049 -
crowdaa-sync/tags/1.3.0/admin/class-crowdaa-sync-meta-box.php
r2722017 r2762188 45 45 'Crowdaa-sync: Send notifications when published?', 46 46 [$this, 'print_send_notification_checkbox'], 47 'post', 48 'advanced', 49 'high', 50 array( 51 '__back_compat_meta_box' => false, 52 ) 53 ); 54 add_meta_box( 55 'crowdaa-sync-display-options', 56 'Crowdaa-sync: Mobile display options', 57 [$this, 'print_display_options_checkbox'], 47 58 'post', 48 59 'advanced', … … 206 217 } 207 218 219 function print_display_options_checkbox($post) { 220 $display_option_fullscreen = (get_post_meta($post->ID, 'display_option_fullscreen', true) === 'yes'); 221 wp_nonce_field('crowdaa_display_options_checkbox', 'crowdaa_display_options_checkboxes_nonce'); 222 223 ?> 224 <p> 225 <i> 226 <?php 227 esc_html_e('Display options for the mobile view of this article.', CROWDAA_SYNC_PLUGIN_NAME); 228 ?> 229 </i> 230 </p> 231 232 <div class="crowdaa-meta-box-input-row"> 233 <label> 234 <?php 235 esc_html_e('Display the article as full screen :', CROWDAA_SYNC_PLUGIN_NAME); 236 ?> 237 <input 238 type="checkbox" 239 name="crowdaa_display_option_fullscreen" 240 <?php if ($display_option_fullscreen) echo esc_attr('checked'); ?> 241 /> 242 </label> 243 </div> 244 <?php 245 } 246 208 247 function save_gallery_meta_box($post_id) { 209 248 if (!isset($_POST['feat_gallery_nonce'])) { … … 251 290 } 252 291 292 function save_display_options_meta_box($post_id) { 293 if (!isset($_POST['crowdaa_display_options_checkboxes_nonce'])) { 294 return; 295 } else if (!wp_verify_nonce($_POST['crowdaa_display_options_checkboxes_nonce'], 'crowdaa_display_options_checkbox')) { 296 return; 297 } else if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) { 298 return; 299 } else if (!current_user_can('edit_post', $post_id)) { 300 return; 301 } 302 303 if (isset($_POST['crowdaa_display_option_fullscreen'])) { 304 update_post_meta($post_id, 'display_option_fullscreen', 'yes'); 305 } else { 306 update_post_meta($post_id, 'display_option_fullscreen', 'no'); 307 } 308 } 309 253 310 /** 254 311 * Save meta boxes data … … 261 318 $this->save_gallery_meta_box($post_id); 262 319 $this->save_notifications_meta_box($post_id); 320 $this->save_display_options_meta_box($post_id); 263 321 } 264 322 } -
crowdaa-sync/tags/1.3.0/crowdaa-sync.php
r2757731 r2762188 14 14 * Plugin URI: 15 15 * Description: Plugin for synchronizing WordPress site and Crowdaa CMS 16 * Version: 1. 2.416 * Version: 1.3.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. 2.4');36 define('CROWDAA_SYNC_VERSION', '1.3.0'); 37 37 define('CROWDAA_SYNC_PLUGIN_DIR', __DIR__); 38 38 define('CROWDAA_SYNC_PLUGIN_NAME', 'crowdaa-sync'); -
crowdaa-sync/tags/1.3.0/includes/class-crowdaa-sync-timer.php
r2620193 r2762188 15 15 private static $ini_was_set = false; 16 16 private const MARGIN_BEFORE_TIMEOUT = 120; 17 private static $start = 0; 17 18 18 19 /** … … 22 23 */ 23 24 public static function init() { 24 if (!isset($_SERVER['REQUEST_TIME_FLOAT'])) { 25 $_SERVER['REQUEST_TIME_FLOAT'] = microtime(true); 26 } 25 self::$start = microtime(true); 27 26 } 28 27 … … 35 34 if (!self::$ini_was_set) { 36 35 self::$ini_was_set = true; 37 $sync_max_duration = get_option('crowdaa_sync_max_duration', 60) * 60 + self::MARGIN_BEFORE_TIMEOUT;36 $sync_max_duration = ((int)get_option('crowdaa_sync_max_duration', 60)) * 60 + self::MARGIN_BEFORE_TIMEOUT; 38 37 if ((int)ini_get('max_execution_time') < $sync_max_duration) { 39 38 @ini_set('max_execution_time', $sync_max_duration); … … 52 51 } 53 52 54 $execution_time = (microtime(true) - $_SERVER['REQUEST_TIME_FLOAT']);53 $execution_time = (microtime(true) - self::$start); 55 54 $max_execution_time = (int)ini_get('max_execution_time'); 56 55 if($execution_time >= $max_execution_time - self::MARGIN_BEFORE_TIMEOUT) { -
crowdaa-sync/trunk/CHANGELOG
r2757731 r2762188 6 6 7 7 ## [Unreleased] 8 9 ## [1.3.0] - 2022-07-27 10 11 ### Added 12 - Synchronization of category images, using the `custom-category-image` plugin 13 - Added a `fullscreen` option on an article to display an article as fullscreen on the app 14 15 ### Changed 16 - Fixed a feedPicture synchronization issue from API to WP 17 - Fixed an execution timeout issue (was not stopping before the php execution timeout, as it should) 8 18 9 19 ## [1.2.4] - 2022-07-15 -
crowdaa-sync/trunk/README.txt
r2757731 r2762188 6 6 Requires PHP: 7.3 7 7 Tested up to: 5.9 8 Stable tag: 1. 2.48 Stable tag: 1.3.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
r2744975 r2762188 145 145 ]; 146 146 147 if (Crowdaa_Sync_Utils::have_plugin('custom-category-image')) { 148 $id = get_term_meta($term->term_id, '_category_image_id', true); 149 if ($id) { 150 $data['picture'] = $id; 151 } 152 } 153 147 154 if (isset($term->rootParentId)) { 148 155 $data['rootParentId'] = $term->rootParentId; … … 168 175 'parentId' => $category->parentId, 169 176 ]; 177 178 if (Crowdaa_Sync_Utils::have_plugin('custom-category-image')) { 179 if ($category->picture) { 180 if (is_object($category->picture[0]) && isset($category->picture[0]->pictureUrl)) { 181 $data['picture'] = $category->picture[0]->_id; 182 } else if (is_string($category->picture[0])) { 183 $data['picture'] = $category->picture[0]; 184 } 185 } 186 } 170 187 171 188 if (Crowdaa_Sync_Utils::have_plugin('paid-memberships-pro')) { … … 357 374 } 358 375 $category->hash = self::hash_category($category); 376 $category->pictureData = null; 377 if ($category->picture && isset($category->picture[0]->pictureUrl)) { 378 $category->pictureData = [ 379 'id' => $category->picture[0]->_id, 380 'url' => $category->picture[0]->pictureUrl, 381 ]; 382 } 359 383 $categories_by_id[$category->_id] = $category; 360 384 } … … 370 394 foreach ($all_terms as $term) { 371 395 $term->perms = []; 396 $term->image = null; 372 397 373 398 if (Crowdaa_Sync_Utils::have_plugin('paid-memberships-pro')) { … … 382 407 } 383 408 $term->perms = $perms_array; 409 } 410 if (Crowdaa_Sync_Utils::have_plugin('custom-category-image')) { 411 $term->image = get_term_meta($term->term_id, '_category_image_id', true); 384 412 } 385 413 … … 493 521 'parentId' => $term->rootParentId, 494 522 'perms' => $term->perms, 523 'image' => $term->image, 495 524 'hash' => $term->hash, 496 525 ]; … … 503 532 'parentId' => $term->rootParentId, 504 533 'perms' => $term->perms, 534 'image' => $term->image, 505 535 'hash' => $term->hash, 506 536 ]; … … 532 562 'parentId' => $category->parentId, 533 563 'badges' => $category->badges, 564 'picture' => $category->pictureData, 534 565 'hash' => $category->hash, 535 566 ]; … … 542 573 'parentId' => $category->parentId, 543 574 'badges' => $category->badges, 575 'picture' => $category->pictureData, 544 576 'hash' => $category->hash, 545 577 ]; … … 1114 1146 } 1115 1147 1116 $category = $sync_api->create_category($curTerm['name'], $curTerm['slug'], $parentId, $badges); 1148 $category_picture_id = false; 1149 if (Crowdaa_Sync_Utils::have_plugin('custom-category-image')) { 1150 $category_picture_id = $sync_api->sync_term_images($curTerm['wp_id']); 1151 } 1152 $category = $sync_api->create_category($curTerm['name'], $curTerm['slug'], $parentId, $badges, $category_picture_id); 1117 1153 $sync_db->create_entry($curTerm['wp_id'], $category->_id, [ 1118 1154 'category_hash' => self::hash_category($category), … … 1132 1168 } 1133 1169 1134 $category = $sync_api->update_category($curTerm['api_id'], $curTerm['name'], $curTerm['slug'], $parentId, $badges); 1170 $category_picture_id = false; 1171 if (Crowdaa_Sync_Utils::have_plugin('custom-category-image')) { 1172 $category_picture_id = $sync_api->sync_term_images($curTerm['wp_id']); 1173 } 1174 $category = $sync_api->update_category($curTerm['api_id'], $curTerm['name'], $curTerm['slug'], $parentId, $badges, $category_picture_id); 1135 1175 $sync_db->update_entry(['api_id' => $curTerm['api_id']], [ 1136 1176 'sync_data' => [ -
crowdaa-sync/trunk/admin/class-crowdaa-sync-add-info-wp.php
r2756893 r2762188 247 247 248 248 $term = $this->create_term($curCategory['name'], $curCategory['slug'], $parentId, $curCategory['badges']); 249 if (Crowdaa_Sync_Utils::have_plugin('custom-category-image')) { 250 $this->post_sync_api_term_picture($term->term_id, $curCategory['picture']); 251 } 249 252 $term->rootParentId = $parentId; 250 253 $sync_db->create_entry($term->term_id, $curCategory['api_id'], [ … … 260 263 261 264 $term = $this->update_term($curCategory['wp_id'], $curCategory['name'], $curCategory['slug'], $parentId, $curCategory['badges']); 265 if (Crowdaa_Sync_Utils::have_plugin('custom-category-image')) { 266 $this->post_sync_api_term_picture($term->term_id, $curCategory['picture']); 267 } 262 268 $term->rootParentId = $parentId; 263 269 $sync_db->update_entry(['wp_id' => $curCategory['wp_id']], [ … … 360 366 update_post_meta($wp_post_id, 'api_post_id', $api_data->_id); 361 367 368 $fullscreen = false; 369 if (isset($api_data->displayOptions) && isset($api_data->displayOptions->fullscreen)) { 370 $fullscreen = $api_data->displayOptions->fullscreen; 371 } 372 update_post_meta($wp_post_id, 'display_option_fullscreen', ($fullscreen ? 'yes' : 'no')); 373 362 374 wp_set_post_terms($wp_post_id, [$term], 'category'); 363 375 … … 412 424 update_post_meta($wp_post_id, 'api_post_id', $api_data->_id); 413 425 426 $fullscreen = false; 427 if (isset($api_data->displayOptions) && isset($api_data->displayOptions->fullscreen)) { 428 $fullscreen = $api_data->displayOptions->fullscreen; 429 } 430 update_post_meta($wp_post_id, 'display_option_fullscreen', ($fullscreen ? 'yes' : 'no')); 431 414 432 $sync_errors = $this->post_sync_api_medias($api_data, $wp_post_id); 415 433 if ($sync_errors) { … … 485 503 } 486 504 505 private function post_sync_api_term_picture($wp_term_id, $api_image) { 506 $synced_picture_prev_image = null; 507 $synced_picture_ids_raw = get_term_meta($wp_term_id, 'crowdaa_picture', true); 508 if ($synced_picture_ids_raw) { 509 $synced_picture_ids = unserialize($synced_picture_ids_raw); 510 $synced_picture_prev_image = $synced_picture_ids['api_id']; 511 } 512 513 $api_image_id = null; 514 $api_image_url = null; 515 if ($api_image) { 516 $api_image_id = $api_image['id']; 517 $api_image_url = $api_image['url']; 518 } 519 520 if ($synced_picture_prev_image !== $api_image_id) { 521 if ($api_image_id) { 522 $ext = pathinfo(parse_url($api_image_url, PHP_URL_PATH), PATHINFO_EXTENSION); 523 if (!$ext) $ext = 'jpg'; 524 $feed_pic_name = $api_image_id.'.'.$ext; 525 $fetch_err = false; 526 if(!$this->check_uploads($feed_pic_name)) { 527 $fetch_err = $this->get_uploads($api_image_url, $feed_pic_name); 528 if ($fetch_err) { 529 Crowdaa_Sync_Logs::log('Term image download error', $wp_term_id, $api_image_id, $fetch_err); 530 throw new Crowdaa_Sync_Category_Error(__('Errors when downloading term image for ', CROWDAA_SYNC_PLUGIN_NAME).$wp_term_id.' : '.$fetch_err); 531 } 532 } 533 534 try { 535 $attachment_id = $this->set_term_upload($wp_term_id, $feed_pic_name); 536 update_term_meta($wp_term_id, 'crowdaa_picture', serialize([ 537 'api_id' => $api_image_id, 538 'attachment_id' => $attachment_id, 539 ])); 540 } catch (Exception $e) { 541 Crowdaa_Sync_Logs::log('Set WP term feed picture error', $e->getMessage()); 542 throw new Crowdaa_Sync_Category_Error(__('Set WP term feed picture error : ', CROWDAA_SYNC_PLUGIN_NAME).$e->getMessage()); 543 } 544 } else { 545 delete_term_meta($wp_term_id, 'crowdaa_picture'); 546 delete_term_meta($wp_term_id, '_category_image_id'); 547 } 548 } 549 } 550 487 551 /** 488 552 * Feed picture processing from API to WP … … 507 571 else if ($api_data->pictures) $article_pic = $api_data->pictures[0]; 508 572 509 $have_a_picture = isset($api_data->feedPicture ) || $article_vid || $article_pic;510 if (isset($api_data->feedPicture )) {573 $have_a_picture = isset($api_data->feedPicture->_id) || $article_vid || $article_pic; 574 if (isset($api_data->feedPicture->_id)) { 511 575 $feed_pic_url = $api_data->feedPicture->pictureUrl; 512 $feed_pic_id = $api_data->feedPicture-> pictur_ideUrl;576 $feed_pic_id = $api_data->feedPicture->_id; 513 577 } else if ($article_vid) { 514 578 $feed_pic_url = $article_vid->thumbUrl; … … 545 609 } else { 546 610 $ext = pathinfo(parse_url($feed_pic_url, PHP_URL_PATH), PATHINFO_EXTENSION); 611 if (!$ext) $ext = 'jpg'; 547 612 $feed_pic_name = $feed_pic_id.'-thumbnail.'.$ext; 548 613 $fetch_err = false; … … 600 665 $image_url = $image->pictureUrl; 601 666 $ext = pathinfo(parse_url($image_url, PHP_URL_PATH), PATHINFO_EXTENSION); 667 if (!$ext) $ext = 'jpg'; 602 668 $image_name = $image_id.'.'.$ext; 603 669 … … 713 779 return false; 714 780 } 781 } 782 783 private function set_term_upload($wp_term_id, $img_name) { 784 $wp_upload_dir = wp_upload_dir(); 785 $upload_dir_path = $wp_upload_dir['basedir'].'/catalogue_images/'; 786 $img_full_path = $upload_dir_path.$img_name; 787 $post_mime_type = mime_content_type($img_full_path); 788 $attachment = [ 789 'guid' => $wp_upload_dir['url'].'/'.$upload_dir_path, 790 'post_mime_type' => $post_mime_type, 791 'post_title' => sanitize_file_name(pathinfo($img_name, PATHINFO_FILENAME)), 792 'post_content' => '', 793 'post_status' => 'inherit', 794 ]; 795 $attach_id = wp_insert_attachment($attachment, $img_name, $wp_term_id); 796 $attach_data = wp_generate_attachment_metadata($attach_id, $img_full_path); 797 wp_update_attachment_metadata($attach_id, $attach_data); 798 update_attached_file($attach_id, $img_full_path); 799 800 update_term_meta($wp_term_id, '_category_image_id', $attach_id); 801 802 Crowdaa_Sync_Logs::log('Added term media to Wordpress', wp_json_encode([ 803 'wp_term_id' => $wp_term_id, 804 'attach_id' => $attach_id, 805 'img_name' => $img_name, 806 ])); 807 808 return ($attach_id); 715 809 } 716 810 -
crowdaa-sync/trunk/admin/class-crowdaa-sync-api.php
r2744975 r2762188 190 190 } 191 191 192 $fullscreen = (get_post_meta($wp_post_id, 'display_option_fullscreen', true) === 'yes'); 192 193 $post_content = get_post_field('post_content', $wp_post_id); 193 194 $post_author = get_the_author_meta('display_name', get_post_field('post_author', $wp_post_id)); … … 197 198 $wp_post_title = html_entity_decode($wp_post_title, ENT_QUOTES); 198 199 $data = [ 199 'articleId' => $api_post_id, 200 'actions' => [], 201 'authorName' => $post_author, 202 'categoryId' => $category_id, 203 'feedPicture' => $api_feedpicture_id, 204 'md' => $post_content ?: __('Without content', CROWDAA_SYNC_PLUGIN_NAME), 205 'pictures' => $pictures_id, 206 'summary' => $wp_post_title, 207 'hideFromFeed' => !$feed_display, 208 'productId' => '', 209 'title' => $wp_post_title, 210 'videos' => $videos_id, 211 'mediaCaptions' => implode(' | ', $api_media_data['captions']), 200 'articleId' => $api_post_id, 201 'actions' => [], 202 'authorName' => $post_author, 203 'categoryId' => $category_id, 204 'feedPicture' => $api_feedpicture_id, 205 'md' => $post_content ?: __('Without content', CROWDAA_SYNC_PLUGIN_NAME), 206 'pictures' => $pictures_id, 207 'summary' => $wp_post_title, 208 'hideFromFeed' => !$feed_display, 209 'productId' => '', 210 'title' => $wp_post_title, 211 'videos' => $videos_id, 212 'mediaCaptions' => implode(' | ', $api_media_data['captions']), 213 'displayOptions' => [ 214 'fullscreen' => $fullscreen, 215 ], 212 216 ]; 213 217 $data = apply_filters('crowdaa_sync_api_update_article_payload', $data, $wp_post_id); … … 451 455 } 452 456 457 $fullscreen = (get_post_meta($wp_post_id, 'display_option_fullscreen', true) === 'yes'); 453 458 $post_content = get_post_field('post_content', $wp_post_id); 454 459 $post_author = get_the_author_meta('display_name', get_post_field('post_author', $wp_post_id)); … … 458 463 $wp_post_title = html_entity_decode($wp_post_title, ENT_QUOTES); 459 464 $data = [ 460 'actions' => [], 461 'authorName' => $post_author, 462 'categoryId' => $category_id, 463 'feedPicture' => $api_feedpicture_id, 464 'md' => $post_content ?: __('Without content', CROWDAA_SYNC_PLUGIN_NAME), 465 'pictures' => $pictures_id, 466 'summary' => $wp_post_title, 467 'hideFromFeed' => !$feed_display, 468 'productId' => '', 469 'title' => $wp_post_title, 470 'videos' => $videos_id, 471 'mediaCaptions' => implode(' | ', $api_media_data['captions']), 465 'actions' => [], 466 'authorName' => $post_author, 467 'categoryId' => $category_id, 468 'feedPicture' => $api_feedpicture_id, 469 'md' => $post_content ?: __('Without content', CROWDAA_SYNC_PLUGIN_NAME), 470 'pictures' => $pictures_id, 471 'summary' => $wp_post_title, 472 'hideFromFeed' => !$feed_display, 473 'productId' => '', 474 'title' => $wp_post_title, 475 'videos' => $videos_id, 476 'mediaCaptions' => implode(' | ', $api_media_data['captions']), 477 'displayOptions' => [ 478 'fullscreen' => $fullscreen, 479 ], 472 480 ]; 473 481 $data = apply_filters('crowdaa_sync_api_create_article_payload', $data, $wp_post_id); … … 655 663 } 656 664 657 public function get_attachment_data($attachment_id, $wp_post_id ) {665 public function get_attachment_data($attachment_id, $wp_post_id = null) { 658 666 $attachment_metadata = wp_get_attachment_metadata($attachment_id); 659 667 $file = get_attached_file($attachment_id); … … 764 772 'attachment_id' => $attachment_id, 765 773 'url' => $image_url, 774 ])); 775 } else if ($img_type === 'term_picture') { 776 update_term_meta($wp_post_id, 'crowdaa_picture', serialize([ 777 'attachment_id' => $attachment_id, 778 'api_id' => $json->id, 766 779 ])); 767 780 } … … 909 922 } 910 923 924 public function sync_term_images($wp_term_id) { 925 $synced_picture_prev_attachment = null; 926 $synced_picture_ids_raw = get_term_meta($wp_term_id, 'crowdaa_picture', true); 927 if ($synced_picture_ids_raw) { 928 $synced_picture_ids = unserialize($synced_picture_ids_raw); 929 $synced_picture_prev_attachment = $synced_picture_ids['attachment_id']; 930 } 931 932 $picture_id = get_term_meta($wp_term_id, '_category_image_id', true); 933 if (!$picture_id) $picture_id = null; 934 else $picture_id = ''.$picture_id; 935 936 if ($synced_picture_prev_attachment !== $picture_id) { 937 if ($picture_id) { 938 $file_data = $this->get_attachment_data($picture_id, $wp_term_id); 939 if ($file_data) { 940 $api_id = null; 941 $errors = $this->create_image_api($file_data, 'term_picture', $api_id); 942 if ($errors) { 943 Crowdaa_Sync_Logs::log('Term image upload error', wp_json_encode($file_data), wp_json_encode($errors)); 944 throw new Crowdaa_Sync_Category_Error(__('Errors when uploading category image for ', CROWDAA_SYNC_PLUGIN_NAME).$wp_term_id.' : '.implode(' | ', $errors)); 945 } 946 } 947 } else { 948 delete_term_meta($wp_term_id, 'crowdaa_picture'); 949 } 950 } 951 952 $synced_picture_ids_raw = get_term_meta($wp_term_id, 'crowdaa_picture', true); 953 if ($synced_picture_ids_raw) { 954 $synced_picture_ids = unserialize($synced_picture_ids_raw); 955 $ret = $synced_picture_ids['api_id']; 956 return ($synced_picture_ids['api_id']); 957 } 958 959 return (null); 960 } 961 911 962 /** 912 963 * Create category on the API … … 918 969 * @return boolean 919 970 */ 920 public function create_category($cat_name, $cat_slug, $parent_category_id, $badges ) {971 public function create_category($cat_name, $cat_slug, $parent_category_id, $badges, $picture_id) { 921 972 $data = [ 922 973 'name' => $cat_name, … … 935 986 } 936 987 988 if ($picture_id) { 989 $data['picture'][0] = $picture_id; 990 } 991 937 992 $data = apply_filters('crowdaa_sync_api_create_category_payload', $data); 938 993 … … 969 1024 * @return boolean 970 1025 */ 971 public function update_category($cat_id, $cat_name, $cat_slug, $parent_category_id, $badges ) {1026 public function update_category($cat_id, $cat_name, $cat_slug, $parent_category_id, $badges, $picture_id = false) { 972 1027 $data = [ 973 1028 'name' => $cat_name, … … 986 1041 } 987 1042 1043 if ($picture_id !== false) { 1044 if ($picture_id) $data['picture'] = [$picture_id]; 1045 else $data['picture'] = []; 1046 } 1047 988 1048 $data = apply_filters('crowdaa_sync_api_update_category_payload', $data); 989 1049 -
crowdaa-sync/trunk/admin/class-crowdaa-sync-meta-box.php
r2722017 r2762188 45 45 'Crowdaa-sync: Send notifications when published?', 46 46 [$this, 'print_send_notification_checkbox'], 47 'post', 48 'advanced', 49 'high', 50 array( 51 '__back_compat_meta_box' => false, 52 ) 53 ); 54 add_meta_box( 55 'crowdaa-sync-display-options', 56 'Crowdaa-sync: Mobile display options', 57 [$this, 'print_display_options_checkbox'], 47 58 'post', 48 59 'advanced', … … 206 217 } 207 218 219 function print_display_options_checkbox($post) { 220 $display_option_fullscreen = (get_post_meta($post->ID, 'display_option_fullscreen', true) === 'yes'); 221 wp_nonce_field('crowdaa_display_options_checkbox', 'crowdaa_display_options_checkboxes_nonce'); 222 223 ?> 224 <p> 225 <i> 226 <?php 227 esc_html_e('Display options for the mobile view of this article.', CROWDAA_SYNC_PLUGIN_NAME); 228 ?> 229 </i> 230 </p> 231 232 <div class="crowdaa-meta-box-input-row"> 233 <label> 234 <?php 235 esc_html_e('Display the article as full screen :', CROWDAA_SYNC_PLUGIN_NAME); 236 ?> 237 <input 238 type="checkbox" 239 name="crowdaa_display_option_fullscreen" 240 <?php if ($display_option_fullscreen) echo esc_attr('checked'); ?> 241 /> 242 </label> 243 </div> 244 <?php 245 } 246 208 247 function save_gallery_meta_box($post_id) { 209 248 if (!isset($_POST['feat_gallery_nonce'])) { … … 251 290 } 252 291 292 function save_display_options_meta_box($post_id) { 293 if (!isset($_POST['crowdaa_display_options_checkboxes_nonce'])) { 294 return; 295 } else if (!wp_verify_nonce($_POST['crowdaa_display_options_checkboxes_nonce'], 'crowdaa_display_options_checkbox')) { 296 return; 297 } else if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) { 298 return; 299 } else if (!current_user_can('edit_post', $post_id)) { 300 return; 301 } 302 303 if (isset($_POST['crowdaa_display_option_fullscreen'])) { 304 update_post_meta($post_id, 'display_option_fullscreen', 'yes'); 305 } else { 306 update_post_meta($post_id, 'display_option_fullscreen', 'no'); 307 } 308 } 309 253 310 /** 254 311 * Save meta boxes data … … 261 318 $this->save_gallery_meta_box($post_id); 262 319 $this->save_notifications_meta_box($post_id); 320 $this->save_display_options_meta_box($post_id); 263 321 } 264 322 } -
crowdaa-sync/trunk/crowdaa-sync.php
r2757731 r2762188 14 14 * Plugin URI: 15 15 * Description: Plugin for synchronizing WordPress site and Crowdaa CMS 16 * Version: 1. 2.416 * Version: 1.3.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. 2.4');36 define('CROWDAA_SYNC_VERSION', '1.3.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-timer.php
r2620193 r2762188 15 15 private static $ini_was_set = false; 16 16 private const MARGIN_BEFORE_TIMEOUT = 120; 17 private static $start = 0; 17 18 18 19 /** … … 22 23 */ 23 24 public static function init() { 24 if (!isset($_SERVER['REQUEST_TIME_FLOAT'])) { 25 $_SERVER['REQUEST_TIME_FLOAT'] = microtime(true); 26 } 25 self::$start = microtime(true); 27 26 } 28 27 … … 35 34 if (!self::$ini_was_set) { 36 35 self::$ini_was_set = true; 37 $sync_max_duration = get_option('crowdaa_sync_max_duration', 60) * 60 + self::MARGIN_BEFORE_TIMEOUT;36 $sync_max_duration = ((int)get_option('crowdaa_sync_max_duration', 60)) * 60 + self::MARGIN_BEFORE_TIMEOUT; 38 37 if ((int)ini_get('max_execution_time') < $sync_max_duration) { 39 38 @ini_set('max_execution_time', $sync_max_duration); … … 52 51 } 53 52 54 $execution_time = (microtime(true) - $_SERVER['REQUEST_TIME_FLOAT']);53 $execution_time = (microtime(true) - self::$start); 55 54 $max_execution_time = (int)ini_get('max_execution_time'); 56 55 if($execution_time >= $max_execution_time - self::MARGIN_BEFORE_TIMEOUT) {
Note: See TracChangeset
for help on using the changeset viewer.