/** *Ajax process files upload from the front end *@access public **/ public function wpvp_process_files() { require_once ABSPATH . 'wp-admin/includes/file.php'; $helper = new WPVP_Helper(); $options = $helper->wpvp_get_full_options(); $newMedia = new WPVP_Encode_Media($options); $upload_size_unit = WPVP_Helper::wpvp_max_upload_size(); $error = false; $errors = array(); $video_limit = WPVP_Helper::wpvp_return_bytes($upload_size_unit); $default_ext = array('video/mp4', 'video/x-flv'); $video_types = get_option('wpvp_allowed_extensions', $default_ext) ? get_option('wpvp_allowed_extensions', $default_ext) : $default_ext; $ext_list = implode(', ', $video_types); $post_id = isset($_POST['postid']) ? (int) $_POST['postid'] : 0; if (!$post_id) { echo json_encode(array('status' => 'error', 'errors' => array(0 => __('Invalid post id.')))); die; } foreach ($_FILES as $file) { if (in_array($file['type'], $video_types)) { if ($file['size'] > $video_limit) { $error = true; $errors[] = __('The file exceeds the maximum upload size.'); } else { //process file $override = array('test_form' => FALSE); $uploaded_file = wp_handle_upload($file, $override); if ($uploaded_file) { $attachment = array('post_title' => $file['name'], 'post_content' => '', 'post_type' => 'attachment', 'post_parent' => 0, 'post_mime_type' => $file['type'], 'guid' => $uploaded_file['url']); $id = wp_insert_attachment($attachment, $uploaded_file['file']); wp_update_attachment_metadata($id, wp_generate_attachment_metadata($id, $uploaded_file['file'])); $encodedVideoPost = $newMedia->wpvp_encode($id, $post_id); if (!$encodedVideoPost) { $errors[] = __('There was an error creating a video post.'); } else { $post_url = get_permalink($post_id); $msg = __('Successfully uploaded. You will be redirected in 5 seconds.'); $msg .= __('If you are not redirected in 5 seconds, go to ') . '<a href="' . $post_url . '">' . __('uploaded video') . '</a>.'; } $data = array(); $data['post_id'] = $post_id; $data['html'] = $msg; $data['url'] = $post_url; $data['status'] = 'success'; } else { $error = true; $errors[] = $uploaded_file['error']; } unset($file); } } else { $error = true; $errors[] = __('The file extension is not supported: ' . $file['type'] . '. Supported extensions are: ' . $ext_list . '.'); } } if ($error) { $data = array('status' => 'error', 'errors' => $errors); //delete tmp post if video errored out wp_delete_post($post_id, true); } else { // send email notification to an admin $admin = get_bloginfo('admin_email'); $subject = get_bloginfo('name') . ': New Video Submitted for Review'; $message = __('New video uploaded for review on ') . get_bloginfo('name') . '. ' . __('Moderate the ') . '<a href="' . get_bloginfo('url') . '/?post_type=videos&p=' . $post_id . '">' . __('uploaded video') . '</a>.'; $send_draft_notice = wp_mail($admin, $subject, $message); } echo json_encode($data); die; }
/** *insert short code into the video post *@access public */ public function wpvp_insert_video_into_post($html, $id, $attachment) { $helper = new WPVP_Helper(); $width = $this->options['video_width']; $height = $this->options['video_height']; $options = $helper->wpvp_get_full_options(); $ffmpeg_exists = $options['ffmpeg_exists']; $attachmentID = $id; $content = $html; $attachmentObj = get_post($attachmentID); $allowed_ext = array('mp4', 'flv'); if ($helper->is_video($attachmentObj->post_mime_type) == 'video') { $postParentID = $attachmentObj->post_parent; $postParentObj = get_post($postParentID); $attachmentURI = wp_get_attachment_url($attachmentID); $attachmentPathInfo = pathinfo($attachmentURI); $attachExt = $attachmentPathInfo['extension']; //check for allowed extensions without ffmpeg if (!in_array($attachExt, $allowed_ext) && !$ffmpeg_exists) { $content = __('WPVP_ERROR: FFMPEG is not found on the server. Allowed extensions for the upload are mp4 and flv. Please convert the video and re-upload.'); } else { //Video with attachment from Media Library $attachments = get_posts(array('post_type' => 'attachment', 'posts_per_page' => -1, 'post_parent' => $postParentID, 'post_mime_type' => 'image/jpeg')); if ($attachments) { $imgAttachmentID = $attachments[0]->ID; $imgAttachment = wp_get_attachment_url($imgAttachmentID); } else { $imgAttachment = plugins_url('/images/', dirname(__FILE__)) . 'default_image.jpg'; } $content = '[wpvp_player src=' . $attachmentURI . ' width=' . $width . ' height=' . $height . ' splash=' . $imgAttachment . ']'; } } //Check post mime type = video return $content; }
<?php $helper = new WPVP_Helper(); $options = $helper->wpvp_get_full_options(); $ffmpeg_ext = $options['ffmpeg_exists']; if ($_POST['wpvp_uploader_hidden'] == 'Y') { //Form data sent $wpvp_allow_guest = $_POST['wpvp_allow_guest']; $wpvp_guest_userid = $_POST['wpvp_guest_userid']; $wpvp_uploader_roles = $_POST['wpvp_uploader_roles']; $wpvp_denial_message = $_POST['wpvp_denial_message']; $wpvp_default_post_status = $_POST['wpvp_default_post_status']; $wpvp_published_notification = $_POST['wpvp_published_notification']; $wpvp_uploader_cats = $_POST['wpvp_uploader_cats']; $wpvp_uploader_tags = $_POST['wpvp_uploader_tags']; $wpvp_uploader_desc = (int) $_POST['wpvp_uploader_desc']; $wpvp_allowed_extensions = $_POST['wpvp_allowed_extensions']; update_option('wpvp_allow_guest', $wpvp_allow_guest); update_option('wpvp_guest_userid', $wpvp_guest_userid); update_option('wpvp_uploader_roles', $wpvp_uploader_roles); update_option('wpvp_denial_message', $wpvp_denial_message); update_option('wpvp_default_post_status', $wpvp_default_post_status); update_option('wpvp_published_notification', $wpvp_published_notification); update_option('wpvp_uploader_cats', $wpvp_uploader_cats); update_option('wpvp_uploader_tags', $wpvp_uploader_tags); update_option('wpvp_uploader_desc', $wpvp_uploader_desc); update_option('wpvp_allowed_extensions', $wpvp_allowed_extensions); ?> <div class="updated"><p><strong><?php _e('Options saved.'); ?>