';
+ // Custom HTML output.
+ $form_fields['rtmedia_video_thumbnail'] = array(
+ 'label' => 'Video Thumbnails',
+ 'input' => 'html',
+ 'html' => $htmlString,
+ );
+ // Return parameter array value
return $form_fields;
}
/**
- * Save selected video thumbnail in attachment meta.
- * Selected thumbnail use as cover art for buddypress activity if video was uploaded in activity.
+ * this is a process function of show_video_thumbnail_in_attachment_edit_page() function.
+ * This function will process show_video_thumbnail_in_attachment_edit_page() selections and create thumbnail if necessary.
+ * This Function also Save selected video thumbnail in attachment meta in attached video file.
+ * This Function will also connected to rtMedia Plugin.
+ * Selected thumbnail use as cover art for buddyPress activity if video was uploaded in activity.
*
* @since 1.0.0
- *
- * @param array $post An array of post data.
- * @return array $form_fields
+ * @param array $post An array of post data.
+ * @return array $form_fields
*/
public function save_video_thumbnail( $post ) {
-
- $rtmedia_thumbnail = transcoder_filter_input( INPUT_POST, 'rtmedia-thumbnail', FILTER_SANITIZE_STRING );
- $id = ( ! empty( $post['ID'] ) && 0 < intval( $post['ID'] ) ) ? intval( $post['ID'] ) : 0;
-
- if ( isset( $rtmedia_thumbnail ) ) {
- if ( class_exists( 'rtMedia' ) ) {
- $file_url = $rtmedia_thumbnail;
- /* for WordPress backward compatibility */
- if ( function_exists( 'wp_get_upload_dir' ) ) {
- $uploads = wp_get_upload_dir();
- } else {
- $uploads = wp_upload_dir();
- }
- if ( 0 === strpos( $file_url, $uploads['baseurl'] ) ) {
- $final_file_url = $file_url;
- } else {
- $final_file_url = $uploads['baseurl'] . '/' . $file_url;
+ // Attachment edit page selected Thumbnail file name.
+ $rtMediaSelectedThumbnail = (isset($post['rtmedia-thumbnail']) AND !empty($post['rtmedia-thumbnail'])) ? sanitize_text_field($post['rtmedia-thumbnail']) : NULL;
+ // Video attachment ID.
+ $postId = (isset($post['ID']) AND !empty($post['ID'])) ? intval( sanitize_text_field($post['ID']) ) : NULL;
+ // Empty check for thumbnail image file name and post id
+ if(! $rtMediaSelectedThumbnail OR ! $postId){
+ return $post;
+ }
+ // === This is old code [legacy code starts] ===
+ // if rtMedia Plugin is exist Do this block
+ if (class_exists( 'rtMedia' )){
+ $uploads = function_exists('wp_get_upload_dir') ? wp_get_upload_dir() : wp_upload_dir();
+ $final_file_url = (strpos($rtMediaSelectedThumbnail, $uploads['baseurl']) === false) ? $rtMediaSelectedThumbnail : $uploads['baseurl'] . '/' . $rtMediaSelectedThumbnail;
+ $rtmedia_model = new RTMediaModel();
+ $media = $rtmedia_model->get(array('media_id' => $postId));
+ $media_id = $media[0]->id;
+ $rtmedia_model->update(array('cover_art' => $final_file_url ), array('media_id' => $postId));
+ rtt_update_activity_after_thumb_set( $media_id );
+ }
+ // Updating post meta.
+ update_post_meta($postId, '_rt_media_video_thumbnail', $rtMediaSelectedThumbnail);
+ // === This is old code [legacy code ends] ===
+ # I am creating thumbnail entry because when transcoder sent the data it create only first thumbnail of the video
+ // Getting all meta File name that was created by this Plugin
+ $thumbnailListArray = get_post_meta($postId, '_rt_media_thumbnails', true);
+ // Check is empty or not array.
+ if(! is_array($thumbnailListArray) OR empty($thumbnailListArray)){
+ return $post;
+ }
+ // Global database object
+ global $wpdb;
+ // Looping the thumbnails array
+ foreach ($thumbnailListArray as $fileLastHalfPath){
+ // Running database query to see thumbnail already exist in the database
+ $firstPreviousEntryID = $wpdb->get_var("SELECT * FROM ".$wpdb->prefix."posts WHERE post_type = 'attachment' AND post_title = '". pathinfo($fileLastHalfPath, PATHINFO_FILENAME) ."'");
+ // if Thumbnail is not in the database than insert the thubnail to the database
+ if(! $firstPreviousEntryID){
+ // Getting upload directory details.
+ $uploadsDir = function_exists('wp_get_upload_dir') ? wp_get_upload_dir() : wp_upload_dir();
+ // File Upload path
+ $filePath = (isset($uploadsDir['basedir']) AND !empty($uploadsDir['basedir'])) ? $uploadsDir['basedir'] .'/'. $fileLastHalfPath : "";
+ // sCheck to see File exist in the path if exist than create a thumbnail with that file, this file was uploaded by transcode but database was not updated
+ if(file_exists($filePath)){
+ // Prepare an array of post data for the attachment.
+ $attachment = array(
+ 'guid' => $uploadsDir['url'] . '/' . basename( $filePath ),
+ 'post_mime_type' => (isset(wp_check_filetype(basename($filePath), null)['type']) AND ! empty(wp_check_filetype(basename($filePath), null)['type'])) ? wp_check_filetype(basename($filePath), null)['type'] : "image/jpeg",
+ 'post_title' => pathinfo($filePath, PATHINFO_FILENAME),
+ 'post_content' => '',
+ 'post_status' => 'inherit'
+ );
+ // Insert the attachment to the database entry.
+ $new_attachment_id = wp_insert_attachment($attachment, $filePath, $postId);
+ // Make sure that this file is included, as wp_generate_attachment_metadata() depends on it.
+ require_once( ABSPATH . 'wp-admin/includes/image.php' );
+ // Generate the metadata for the attachment, and update the database record.
+ $attach_data = wp_generate_attachment_metadata($new_attachment_id, $filePath);
+ // Updating attachment Information
+ wp_update_attachment_metadata($new_attachment_id, $attach_data);
}
-
- $rtmedia_model = new RTMediaModel();
- $media = $rtmedia_model->get( array( 'media_id' => $id ) );
- $media_id = $media[0]->id;
- $rtmedia_model->update( array( 'cover_art' => $final_file_url ), array( 'media_id' => $id ) );
- rtt_update_activity_after_thumb_set( $media_id );
- }
- update_post_meta( $id, '_rt_media_video_thumbnail', $rtmedia_thumbnail );
+ }
+ }
+ // getting the selected image thumbnail database id for setting the thumbnail image
+ $selectedThumbnailsId = $wpdb->get_var("SELECT ID FROM ".$wpdb->prefix."posts WHERE post_type = 'attachment' AND post_title = '". pathinfo($rtMediaSelectedThumbnail, PATHINFO_FILENAME) ."'");
+ // Setting selected image to the Parent file featured image.
+ if( $selectedThumbnailsId AND ! is_float($selectedThumbnailsId)){
+ $post['_thumbnail_id'] = $selectedThumbnailsId;
}
return $post;
@@ -409,42 +365,40 @@ public function save_video_thumbnail( $post ) {
/**
* Display admin notice.
- *
* @since 1.0.0
- */
+ */
public function transcoder_admin_notice() {
+ // Getting site option data thats was saved before
$show_notice = get_site_option( 'transcoder_admin_notice', 1 );
-
- if ( '1' === $show_notice || 1 === $show_notice ) :
+ //
+ if ( '1' === $show_notice OR 1 === $show_notice ) :
?>
-
-
-
-
-
-
-
+
api_key ) ) {
+ if(! empty( $this->api_key )){
return false;
}
$settings_page_link = 'admin.php?page=rt-transcoder';
@@ -461,11 +415,10 @@ public function subscribe_transcoder_admin_notice() {
/**
* Set option to hide admin notice when user click on dismiss button.
- *
* @since 1.0.0
*/
public function transcoder_hide_admin_notice() {
- if ( check_ajax_referer( '_transcoder_hide_notice_', 'transcoder_notice_nonce' ) ) {
+ if(check_ajax_referer( '_transcoder_hide_notice_', 'transcoder_notice_nonce' )){
update_site_option( 'transcoder_admin_notice', '0' );
}
die();
@@ -473,7 +426,6 @@ public function transcoder_hide_admin_notice() {
/**
* Hide encoding tab in old rtMedia plugin.
- *
* @since 1.0.0
*/
public function rtmedia_hide_encoding_tab() {
@@ -487,16 +439,38 @@ public function rtmedia_hide_encoding_tab() {
}
/**
- * Filters the Mediaelement fallback output to add class.
- *
- * @since 1.0.0
- *
- * @param type $output Fallback output for no-JS.
- * @param type $url Media file URL.
- *
- * @return string return fallback output.
+ * Filters the MediaElement fallback output to add class
+ * @since 1.0.0
+ * @param type $output Fallback output for no-JS.
+ * @param type $url Media file URL.
+ * @return string return fallback output.
*/
public function mediaelement_add_class( $output, $url ) {
return sprintf( '%1$s', esc_url( $url ) );
}
+
+
+ /**
+ * This function will add JS to the admin Footer, if Thumbnail is selection is clicked then select the clicked one and deselect rest of the checkboxes.
+ * @since 1.0.0
+ * @param type $output Fallback output for no-JS.
+ * @param type $url Media file URL.
+ * @return string return fallback output.
+ */
+ public function admin_footer_for_attachment_edit_page(){
+ ?>
+
+