Plugin Directory

Changeset 2762188


Ignore:
Timestamp:
07/27/2022 07:15:21 AM (4 years ago)
Author:
crowdaa
Message:

Added 1.3.0

Location:
crowdaa-sync
Files:
9 edited
30 copied

Legend:

Unmodified
Added
Removed
  • crowdaa-sync/tags/1.3.0/CHANGELOG

    r2757731 r2762188  
    66
    77## [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)
    818
    919## [1.2.4] - 2022-07-15
  • crowdaa-sync/tags/1.3.0/README.txt

    r2757731 r2762188  
    66Requires PHP: 7.3
    77Tested up to: 5.9
    8 Stable tag: 1.2.4
     8Stable tag: 1.3.0
    99License: GPLv2 or later
    1010License 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  
    145145    ];
    146146
     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
    147154    if (isset($term->rootParentId)) {
    148155      $data['rootParentId'] = $term->rootParentId;
     
    168175      'parentId' => $category->parentId,
    169176    ];
     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    }
    170187
    171188    if (Crowdaa_Sync_Utils::have_plugin('paid-memberships-pro')) {
     
    357374        }
    358375        $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        }
    359383        $categories_by_id[$category->_id] = $category;
    360384      }
     
    370394      foreach ($all_terms as $term) {
    371395        $term->perms = [];
     396        $term->image = null;
    372397
    373398        if (Crowdaa_Sync_Utils::have_plugin('paid-memberships-pro')) {
     
    382407          }
    383408          $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);
    384412        }
    385413
     
    493521                'parentId' => $term->rootParentId,
    494522                'perms' => $term->perms,
     523                'image' => $term->image,
    495524                'hash' => $term->hash,
    496525              ];
     
    503532                'parentId' => $term->rootParentId,
    504533                'perms' => $term->perms,
     534                'image' => $term->image,
    505535                'hash' => $term->hash,
    506536              ];
     
    532562                'parentId' => $category->parentId,
    533563                'badges' => $category->badges,
     564                'picture' => $category->pictureData,
    534565                'hash' => $category->hash,
    535566              ];
     
    542573                'parentId' => $category->parentId,
    543574                'badges' => $category->badges,
     575                'picture' => $category->pictureData,
    544576                'hash' => $category->hash,
    545577              ];
     
    11141146          }
    11151147
    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);
    11171153          $sync_db->create_entry($curTerm['wp_id'], $category->_id, [
    11181154            'category_hash' => self::hash_category($category),
     
    11321168          }
    11331169
    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);
    11351175          $sync_db->update_entry(['api_id' => $curTerm['api_id']], [
    11361176            'sync_data' => [
  • crowdaa-sync/tags/1.3.0/admin/class-crowdaa-sync-add-info-wp.php

    r2756893 r2762188  
    247247
    248248        $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        }
    249252        $term->rootParentId = $parentId;
    250253        $sync_db->create_entry($term->term_id, $curCategory['api_id'], [
     
    260263
    261264        $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        }
    262268        $term->rootParentId = $parentId;
    263269        $sync_db->update_entry(['wp_id' => $curCategory['wp_id']], [
     
    360366    update_post_meta($wp_post_id, 'api_post_id', $api_data->_id);
    361367
     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
    362374    wp_set_post_terms($wp_post_id, [$term], 'category');
    363375
     
    412424    update_post_meta($wp_post_id, 'api_post_id', $api_data->_id);
    413425
     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
    414432    $sync_errors = $this->post_sync_api_medias($api_data, $wp_post_id);
    415433    if ($sync_errors) {
     
    485503  }
    486504
     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
    487551  /**
    488552   * Feed picture processing from API to WP
     
    507571    else if ($api_data->pictures) $article_pic = $api_data->pictures[0];
    508572
    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)) {
    511575      $feed_pic_url = $api_data->feedPicture->pictureUrl;
    512       $feed_pic_id = $api_data->feedPicture->pictur_ideUrl;
     576      $feed_pic_id = $api_data->feedPicture->_id;
    513577    } else if ($article_vid) {
    514578      $feed_pic_url = $article_vid->thumbUrl;
     
    545609      } else {
    546610        $ext = pathinfo(parse_url($feed_pic_url, PHP_URL_PATH), PATHINFO_EXTENSION);
     611        if (!$ext) $ext = 'jpg';
    547612        $feed_pic_name = $feed_pic_id.'-thumbnail.'.$ext;
    548613        $fetch_err = false;
     
    600665        $image_url = $image->pictureUrl;
    601666        $ext = pathinfo(parse_url($image_url, PHP_URL_PATH), PATHINFO_EXTENSION);
     667        if (!$ext) $ext = 'jpg';
    602668        $image_name = $image_id.'.'.$ext;
    603669
     
    713779      return false;
    714780    }
     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);
    715809  }
    716810
  • crowdaa-sync/tags/1.3.0/admin/class-crowdaa-sync-api.php

    r2744975 r2762188  
    190190    }
    191191
     192    $fullscreen = (get_post_meta($wp_post_id, 'display_option_fullscreen', true) === 'yes');
    192193    $post_content = get_post_field('post_content', $wp_post_id);
    193194    $post_author = get_the_author_meta('display_name', get_post_field('post_author', $wp_post_id));
     
    197198    $wp_post_title = html_entity_decode($wp_post_title, ENT_QUOTES);
    198199    $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      ],
    212216    ];
    213217    $data = apply_filters('crowdaa_sync_api_update_article_payload', $data, $wp_post_id);
     
    451455    }
    452456
     457    $fullscreen = (get_post_meta($wp_post_id, 'display_option_fullscreen', true) === 'yes');
    453458    $post_content = get_post_field('post_content', $wp_post_id);
    454459    $post_author = get_the_author_meta('display_name', get_post_field('post_author', $wp_post_id));
     
    458463    $wp_post_title = html_entity_decode($wp_post_title, ENT_QUOTES);
    459464    $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      ],
    472480    ];
    473481    $data = apply_filters('crowdaa_sync_api_create_article_payload', $data, $wp_post_id);
     
    655663  }
    656664
    657   public function get_attachment_data($attachment_id, $wp_post_id) {
     665  public function get_attachment_data($attachment_id, $wp_post_id = null) {
    658666    $attachment_metadata = wp_get_attachment_metadata($attachment_id);
    659667    $file                = get_attached_file($attachment_id);
     
    764772        'attachment_id' => $attachment_id,
    765773        '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,
    766779      ]));
    767780    }
     
    909922  }
    910923
     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
    911962  /**
    912963   * Create category on the API
     
    918969   * @return boolean
    919970   */
    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) {
    921972    $data = [
    922973      'name'     => $cat_name,
     
    935986    }
    936987
     988    if ($picture_id) {
     989      $data['picture'][0] = $picture_id;
     990    }
     991
    937992    $data = apply_filters('crowdaa_sync_api_create_category_payload', $data);
    938993
     
    9691024   * @return boolean
    9701025   */
    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) {
    9721027    $data = [
    9731028      'name'     => $cat_name,
     
    9861041    }
    9871042
     1043    if ($picture_id !== false) {
     1044      if ($picture_id) $data['picture'] = [$picture_id];
     1045      else $data['picture'] = [];
     1046    }
     1047
    9881048    $data = apply_filters('crowdaa_sync_api_update_category_payload', $data);
    9891049
  • crowdaa-sync/tags/1.3.0/admin/class-crowdaa-sync-meta-box.php

    r2722017 r2762188  
    4545      'Crowdaa-sync: Send notifications when published?',
    4646      [$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'],
    4758      'post',
    4859      'advanced',
     
    206217  }
    207218
     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
    208247  function save_gallery_meta_box($post_id) {
    209248    if (!isset($_POST['feat_gallery_nonce'])) {
     
    251290  }
    252291
     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
    253310  /**
    254311   * Save meta boxes data
     
    261318    $this->save_gallery_meta_box($post_id);
    262319    $this->save_notifications_meta_box($post_id);
     320    $this->save_display_options_meta_box($post_id);
    263321  }
    264322}
  • crowdaa-sync/tags/1.3.0/crowdaa-sync.php

    r2757731 r2762188  
    1414 * Plugin URI:       
    1515 * Description:       Plugin for synchronizing WordPress site and Crowdaa CMS
    16  * Version:           1.2.4
     16 * Version:           1.3.0
    1717 * Requires at least: 5.5
    1818 * Requires PHP:      7.2
     
    3434 * Uses SemVer - https://semver.org
    3535 */
    36 define('CROWDAA_SYNC_VERSION', '1.2.4');
     36define('CROWDAA_SYNC_VERSION', '1.3.0');
    3737define('CROWDAA_SYNC_PLUGIN_DIR', __DIR__);
    3838define('CROWDAA_SYNC_PLUGIN_NAME', 'crowdaa-sync');
  • crowdaa-sync/tags/1.3.0/includes/class-crowdaa-sync-timer.php

    r2620193 r2762188  
    1515  private static $ini_was_set = false;
    1616  private const MARGIN_BEFORE_TIMEOUT = 120;
     17  private static $start = 0;
    1718
    1819  /**
     
    2223   */
    2324  public static function init() {
    24     if (!isset($_SERVER['REQUEST_TIME_FLOAT'])) {
    25       $_SERVER['REQUEST_TIME_FLOAT'] = microtime(true);
    26     }
     25    self::$start = microtime(true);
    2726  }
    2827
     
    3534    if (!self::$ini_was_set) {
    3635      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;
    3837      if ((int)ini_get('max_execution_time') < $sync_max_duration) {
    3938        @ini_set('max_execution_time', $sync_max_duration);
     
    5251    }
    5352
    54     $execution_time = (microtime(true) - $_SERVER['REQUEST_TIME_FLOAT']);
     53    $execution_time = (microtime(true) - self::$start);
    5554    $max_execution_time = (int)ini_get('max_execution_time');
    5655    if($execution_time >= $max_execution_time - self::MARGIN_BEFORE_TIMEOUT) {
  • crowdaa-sync/trunk/CHANGELOG

    r2757731 r2762188  
    66
    77## [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)
    818
    919## [1.2.4] - 2022-07-15
  • crowdaa-sync/trunk/README.txt

    r2757731 r2762188  
    66Requires PHP: 7.3
    77Tested up to: 5.9
    8 Stable tag: 1.2.4
     8Stable tag: 1.3.0
    99License: GPLv2 or later
    1010License URI: http://www.gnu.org/licenses/gpl-2.0.html
  • crowdaa-sync/trunk/admin/class-crowdaa-sync-add-info-api.php

    r2744975 r2762188  
    145145    ];
    146146
     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
    147154    if (isset($term->rootParentId)) {
    148155      $data['rootParentId'] = $term->rootParentId;
     
    168175      'parentId' => $category->parentId,
    169176    ];
     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    }
    170187
    171188    if (Crowdaa_Sync_Utils::have_plugin('paid-memberships-pro')) {
     
    357374        }
    358375        $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        }
    359383        $categories_by_id[$category->_id] = $category;
    360384      }
     
    370394      foreach ($all_terms as $term) {
    371395        $term->perms = [];
     396        $term->image = null;
    372397
    373398        if (Crowdaa_Sync_Utils::have_plugin('paid-memberships-pro')) {
     
    382407          }
    383408          $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);
    384412        }
    385413
     
    493521                'parentId' => $term->rootParentId,
    494522                'perms' => $term->perms,
     523                'image' => $term->image,
    495524                'hash' => $term->hash,
    496525              ];
     
    503532                'parentId' => $term->rootParentId,
    504533                'perms' => $term->perms,
     534                'image' => $term->image,
    505535                'hash' => $term->hash,
    506536              ];
     
    532562                'parentId' => $category->parentId,
    533563                'badges' => $category->badges,
     564                'picture' => $category->pictureData,
    534565                'hash' => $category->hash,
    535566              ];
     
    542573                'parentId' => $category->parentId,
    543574                'badges' => $category->badges,
     575                'picture' => $category->pictureData,
    544576                'hash' => $category->hash,
    545577              ];
     
    11141146          }
    11151147
    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);
    11171153          $sync_db->create_entry($curTerm['wp_id'], $category->_id, [
    11181154            'category_hash' => self::hash_category($category),
     
    11321168          }
    11331169
    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);
    11351175          $sync_db->update_entry(['api_id' => $curTerm['api_id']], [
    11361176            'sync_data' => [
  • crowdaa-sync/trunk/admin/class-crowdaa-sync-add-info-wp.php

    r2756893 r2762188  
    247247
    248248        $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        }
    249252        $term->rootParentId = $parentId;
    250253        $sync_db->create_entry($term->term_id, $curCategory['api_id'], [
     
    260263
    261264        $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        }
    262268        $term->rootParentId = $parentId;
    263269        $sync_db->update_entry(['wp_id' => $curCategory['wp_id']], [
     
    360366    update_post_meta($wp_post_id, 'api_post_id', $api_data->_id);
    361367
     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
    362374    wp_set_post_terms($wp_post_id, [$term], 'category');
    363375
     
    412424    update_post_meta($wp_post_id, 'api_post_id', $api_data->_id);
    413425
     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
    414432    $sync_errors = $this->post_sync_api_medias($api_data, $wp_post_id);
    415433    if ($sync_errors) {
     
    485503  }
    486504
     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
    487551  /**
    488552   * Feed picture processing from API to WP
     
    507571    else if ($api_data->pictures) $article_pic = $api_data->pictures[0];
    508572
    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)) {
    511575      $feed_pic_url = $api_data->feedPicture->pictureUrl;
    512       $feed_pic_id = $api_data->feedPicture->pictur_ideUrl;
     576      $feed_pic_id = $api_data->feedPicture->_id;
    513577    } else if ($article_vid) {
    514578      $feed_pic_url = $article_vid->thumbUrl;
     
    545609      } else {
    546610        $ext = pathinfo(parse_url($feed_pic_url, PHP_URL_PATH), PATHINFO_EXTENSION);
     611        if (!$ext) $ext = 'jpg';
    547612        $feed_pic_name = $feed_pic_id.'-thumbnail.'.$ext;
    548613        $fetch_err = false;
     
    600665        $image_url = $image->pictureUrl;
    601666        $ext = pathinfo(parse_url($image_url, PHP_URL_PATH), PATHINFO_EXTENSION);
     667        if (!$ext) $ext = 'jpg';
    602668        $image_name = $image_id.'.'.$ext;
    603669
     
    713779      return false;
    714780    }
     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);
    715809  }
    716810
  • crowdaa-sync/trunk/admin/class-crowdaa-sync-api.php

    r2744975 r2762188  
    190190    }
    191191
     192    $fullscreen = (get_post_meta($wp_post_id, 'display_option_fullscreen', true) === 'yes');
    192193    $post_content = get_post_field('post_content', $wp_post_id);
    193194    $post_author = get_the_author_meta('display_name', get_post_field('post_author', $wp_post_id));
     
    197198    $wp_post_title = html_entity_decode($wp_post_title, ENT_QUOTES);
    198199    $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      ],
    212216    ];
    213217    $data = apply_filters('crowdaa_sync_api_update_article_payload', $data, $wp_post_id);
     
    451455    }
    452456
     457    $fullscreen = (get_post_meta($wp_post_id, 'display_option_fullscreen', true) === 'yes');
    453458    $post_content = get_post_field('post_content', $wp_post_id);
    454459    $post_author = get_the_author_meta('display_name', get_post_field('post_author', $wp_post_id));
     
    458463    $wp_post_title = html_entity_decode($wp_post_title, ENT_QUOTES);
    459464    $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      ],
    472480    ];
    473481    $data = apply_filters('crowdaa_sync_api_create_article_payload', $data, $wp_post_id);
     
    655663  }
    656664
    657   public function get_attachment_data($attachment_id, $wp_post_id) {
     665  public function get_attachment_data($attachment_id, $wp_post_id = null) {
    658666    $attachment_metadata = wp_get_attachment_metadata($attachment_id);
    659667    $file                = get_attached_file($attachment_id);
     
    764772        'attachment_id' => $attachment_id,
    765773        '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,
    766779      ]));
    767780    }
     
    909922  }
    910923
     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
    911962  /**
    912963   * Create category on the API
     
    918969   * @return boolean
    919970   */
    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) {
    921972    $data = [
    922973      'name'     => $cat_name,
     
    935986    }
    936987
     988    if ($picture_id) {
     989      $data['picture'][0] = $picture_id;
     990    }
     991
    937992    $data = apply_filters('crowdaa_sync_api_create_category_payload', $data);
    938993
     
    9691024   * @return boolean
    9701025   */
    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) {
    9721027    $data = [
    9731028      'name'     => $cat_name,
     
    9861041    }
    9871042
     1043    if ($picture_id !== false) {
     1044      if ($picture_id) $data['picture'] = [$picture_id];
     1045      else $data['picture'] = [];
     1046    }
     1047
    9881048    $data = apply_filters('crowdaa_sync_api_update_category_payload', $data);
    9891049
  • crowdaa-sync/trunk/admin/class-crowdaa-sync-meta-box.php

    r2722017 r2762188  
    4545      'Crowdaa-sync: Send notifications when published?',
    4646      [$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'],
    4758      'post',
    4859      'advanced',
     
    206217  }
    207218
     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
    208247  function save_gallery_meta_box($post_id) {
    209248    if (!isset($_POST['feat_gallery_nonce'])) {
     
    251290  }
    252291
     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
    253310  /**
    254311   * Save meta boxes data
     
    261318    $this->save_gallery_meta_box($post_id);
    262319    $this->save_notifications_meta_box($post_id);
     320    $this->save_display_options_meta_box($post_id);
    263321  }
    264322}
  • crowdaa-sync/trunk/crowdaa-sync.php

    r2757731 r2762188  
    1414 * Plugin URI:       
    1515 * Description:       Plugin for synchronizing WordPress site and Crowdaa CMS
    16  * Version:           1.2.4
     16 * Version:           1.3.0
    1717 * Requires at least: 5.5
    1818 * Requires PHP:      7.2
     
    3434 * Uses SemVer - https://semver.org
    3535 */
    36 define('CROWDAA_SYNC_VERSION', '1.2.4');
     36define('CROWDAA_SYNC_VERSION', '1.3.0');
    3737define('CROWDAA_SYNC_PLUGIN_DIR', __DIR__);
    3838define('CROWDAA_SYNC_PLUGIN_NAME', 'crowdaa-sync');
  • crowdaa-sync/trunk/includes/class-crowdaa-sync-timer.php

    r2620193 r2762188  
    1515  private static $ini_was_set = false;
    1616  private const MARGIN_BEFORE_TIMEOUT = 120;
     17  private static $start = 0;
    1718
    1819  /**
     
    2223   */
    2324  public static function init() {
    24     if (!isset($_SERVER['REQUEST_TIME_FLOAT'])) {
    25       $_SERVER['REQUEST_TIME_FLOAT'] = microtime(true);
    26     }
     25    self::$start = microtime(true);
    2726  }
    2827
     
    3534    if (!self::$ini_was_set) {
    3635      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;
    3837      if ((int)ini_get('max_execution_time') < $sync_max_duration) {
    3938        @ini_set('max_execution_time', $sync_max_duration);
     
    5251    }
    5352
    54     $execution_time = (microtime(true) - $_SERVER['REQUEST_TIME_FLOAT']);
     53    $execution_time = (microtime(true) - self::$start);
    5554    $max_execution_time = (int)ini_get('max_execution_time');
    5655    if($execution_time >= $max_execution_time - self::MARGIN_BEFORE_TIMEOUT) {
Note: See TracChangeset for help on using the changeset viewer.