public static function preload_params() { global $bc_accounts; $tags = new BC_Tags(); $params = array(); // Fetch all preload vids/playlists as appropriate. $uri = $_SERVER['REQUEST_URI']; $type = 'videos'; if (BC_Utility::current_user_can_brightcove()) { $cms_api = new BC_CMS_API(); $admin_media_api = new BC_Admin_Media_API(); if (false !== strpos($uri, BC_Admin_Menu::get_playlists_page_uri_component())) { $type = 'playlists'; $params['playlists'] = $cms_api->playlist_list(); } } else { return false; } $params['dates'] = array($type => BC_Utility::get_video_playlist_dates_for_display($type)); $params['nonce'] = wp_create_nonce('_bc_ajax_search_nonce'); $params['tags'] = $tags->get_tags(); $params['plupload'] = array('runtimes' => 'html5,silverlight,flash,html4', 'browse_button' => 'brightcove-select-files-button', 'container' => 'drop-target', 'drop_element' => 'drop-target', 'multiple_queues' => true, 'max_file_size' => wp_max_upload_size() . 'b', 'url' => admin_url('admin-ajax.php?action=bc_media_upload'), 'flash_swf_url' => includes_url('js/plupload/plupload.flash.swf'), 'silverlight_xap_url' => includes_url('js/plupload/plupload.silverlight.xap'), 'filters' => array(array('title' => esc_html__('Allowed Files'), 'extensions' => '*')), 'multipart' => true, 'urlstream_upload' => true, 'multi_selection' => true, 'multipart_params' => array('action' => 'bc_media_upload')); $params['messages'] = array('confirmDelete' => esc_html__('Deleting this video will prevent it from showing in any existing posts. Are you sure you want to delete?', 'brightcove'), 'ongoingSync' => esc_html__('We are currently performing a sync of your new Brightcove source, you may not see all videos and playlists until that is complete.', 'brightcove'), 'successUpload' => esc_html__('Successfully uploaded file with name %%s%%.', 'brightcove'), 'unableToUpload' => esc_html__('We were unable to upload the file with name %%s%% Please try reuploading it again.', 'brightcove')); // Fetch all account hash/name combos. $params['accounts'] = $bc_accounts->get_sanitized_all_accounts(); // Fetch all supported mime types. $params['mimeTypes'] = BC_Utility::get_all_brightcove_mimetypes(); $defaultAccount = $bc_accounts->get_account_details_for_user(); $params['defaultAccount'] = $defaultAccount['hash']; $params['defaultAccountId'] = $defaultAccount['account_id']; return $params; }
public function handle_initial_sync($account_id, $start_time = false) { global $bc_accounts; if ($bc_accounts->is_initial_sync_complete($account_id)) { return true; } $max_time = (int) ini_get('max_execution_time'); if (!$start_time) { $start_time = time(); } else { $buffer_time_in_seconds = apply_filters('brightcove_buffer_time_in_seconds', 15); // We give around a 15s buffer for inserting one page of records if (!$this->have_enough_time($start_time, $buffer_time_in_seconds, $max_time)) { return; } } $transient_key_synching = '_brightcove_currently_synching'; $currently_syncing = get_transient($transient_key_synching); if ($currently_syncing) { return false; } // Prevent other syncs from occurring set_transient($transient_key_synching, $account_id, $max_time); $transient_key_number_of_videos = '_brightcove_video_count_' . $account_id; $number_of_videos = get_transient($transient_key_number_of_videos); if (false === $number_of_videos) { $number_of_videos = $this->cms_api->video_count(); } $transient_key_current_offset = '_brightcove_sync_offset_' . $account_id; $current_offset = get_transient($transient_key_current_offset); if (false === $current_offset) { $current_offset = 0; } $videos_per_page = apply_filters('brightcove_videos_per_page', 100); // Brightcove as of April 7th 2015 can only fetch 100 videos at a time $tags = $this->tags->get_tags(); $dates = BC_Utility::get_video_playlist_dates_for_display('videos'); $tags_count = count($tags); for ($offset = $current_offset; $offset < $number_of_videos; $offset += $videos_per_page) { $offset = min($offset, $number_of_videos); $current_video_list = $this->cms_api->video_list($videos_per_page, $offset); foreach ($current_video_list as $video) { $tags = array_merge($tags, $video['tags']); $yyyy_mm = substr(preg_replace('/[^0-9-]/', '', $video['created_at']), 0, 7); // Get YYYY-MM from created string $video_dates[$yyyy_mm] = $yyyy_mm; } $tags = array_unique($tags); if (count($tags) > $tags_count) { $this->tags->add_tags($tags); } ksort($video_dates); $video_dates = array_keys($video_dates); // Only interested in the dates BC_Utility::set_video_playlist_dates('videos', $video_dates, $bc_accounts->get_account_id()); set_transient($transient_key_current_offset, $offset += $videos_per_page, $max_time); delete_transient($transient_key_synching); if (!$this->have_enough_time($start_time)) { global $bc_accounts; $bc_accounts->trigger_sync_via_callback(); return; // trigger sync event; } else { return $this->handle_initial_sync($account_id, $start_time); } } $bc_accounts->set_initial_sync_status($account_id, true); }