Beispiel #1
0
 /**
  *font end video edit processing
  *@access public
  */
 public function wpvp_front_video_editor()
 {
     if ($_REQUEST['video'] != '') {
         //get current user id and check if the video belongs to that user
         $curr_user = wp_get_current_user();
         $user_id = $curr_user->ID;
         //get post Object based on post id
         $post_id = (int) $_GET['video'];
         $postObj = get_post($post_id);
         $post_author = $postObj->post_author;
         if (!current_user_can('administrator') && $user_id != $post_author) {
             return __('Cheating, huh?!');
         } else {
             $video_data = get_post_meta($post_id, 'wpvp_fp_code', true);
             $video_shortcode = '';
             if (!empty($video_data)) {
                 $data = json_decode(stripslashes($video_data), true);
                 $src = isset($data['src']) ? $data['src'] : false;
                 $splash = isset($data['splash']) ? $data['splash'] : false;
                 $width = isset($data['width']) ? $data['width'] : false;
                 $height = isset($data['height']) ? $data['height'] : false;
                 if ($src) {
                     $video_shortcode = '[wpvp_player src="' . $src . '"';
                 }
                 if ($splash) {
                     $video_shortcode .= ' splash="' . $splash . '"';
                 }
                 if ($width) {
                     $video_shortcode .= ' width="' . $width . '"';
                 }
                 if ($height) {
                     $video_shortcode .= ' height="' . $height . '"';
                 }
                 if ($src) {
                     $video_shortcode .= ']';
                 }
             }
             $video_content = $this->wpvp_strip_shortcode('wpvp_player', $postObj->post_content);
             $video_content = $this->wpvp_strip_shortcode('wpvp_flowplayer', $video_content);
             $video_title = $postObj->post_title;
             $post_tags = wp_get_post_tags($post_id);
             if (!empty($post_tags)) {
                 $tag_count = count($post_tags);
                 $tags_list = array();
                 foreach ($post_tags as $key => $tag) {
                     $tags_list[] = $tag->name;
                 }
                 $tags_list = implode(', ', $tags_list);
             }
             $post_category = wp_get_post_categories($post_id);
             $post_cat = $post_category[0];
             $data = array();
             $data['post_id'] = $post_id;
             $data['video_shortcode'] = $video_shortcode;
             $data['content'] = $video_content;
             $data['title'] = $video_title;
             $data['tags'] = $tags_list;
             $data['category'] = $post_cat;
             WPVP_Helper::wpvp_load_template_file('wpvp-frontend-editor', true, $data);
         }
     } else {
         return __('Cheating, huh?!');
         exit;
     }
 }
Beispiel #2
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;
 }
}
?>
><?php 
echo $data['content'];
?>
</textarea>
		<div class="wpvp_desc_error wpvp_error"></div>
	</div>
	<div class="wpvp_block">
		<div class="wpvp_cat" style="float:left;width:50%;">
			<label><?php 
_e('Choose category');
?>
</label>
			<?php 
WPVP_Helper::wpvp_upload_categories_dropdown(true, $data['category']);
?>
		</div>
		<?php 
$hide_tags = get_option('wpvp_uploader_tags', '');
?>
		<?php 
if ($hide_tags == '') {
    ?>
		<div class="wpvp_tag" style="float:right;width:50%;text-align:right;">
			<label><?php 
    _e('Tags (comma separated)');
    ?>
</label>
			<input type="text" name="wpvp_tags" value="<?php 
    echo $data['tags'];
if (!$desc_status) {
    ?>
class="wpvp_require"<?php 
}
?>
></textarea>
		<div class="wpvp_desc_error wpvp_error"></div>
	</div>
	<div class="wpvp_block">
		<div class="wpvp_cat" style="float:left;width:50%;">
			<label><?php 
_e('Choose category');
?>
</label>
			<?php 
WPVP_Helper::wpvp_upload_categories_dropdown();
?>
		</div>
		<?php 
$hide_tags = get_option('wpvp_uploader_tags', '');
if ($hide_tags == '') {
    ?>
		<div class="wpvp_tag" style="float:right;width:50%;text-align:right;">
			<label><?php 
    _e('Tags (comma separated)');
    ?>
</label>
			<input type="text" name="wpvp_tags" value="" />
		</div>
		<?php 
}
<?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.');
    ?>