Beispiel #1
0
 /**
  *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;
 }
function wpvp_widget_function($instance)
{
    $media = new WPVP_Encode_Media();
    $video_posts = $media->wpvp_widget_latest_posts($instance);
    //$video_posts = wpvp_widget_latest_posts($instance);
    return $video_posts;
}