From de19b1c5a4324e86bc749bfd76f46233799a8faf Mon Sep 17 00:00:00 2001
From: Kyle Maurer <kyle@realbigmarketing.com>
Date: Thu, 11 Dec 2014 15:59:50 -0500
Subject: [PATCH] Added .gitignore. Also added working slides url field in a
 Video Info meta box.

---
 .gitignore    |  3 +++
 functions.php | 36 +++++++++++++++++++++++++++++++++++-
 2 files changed, 38 insertions(+), 1 deletion(-)
 create mode 100644 .gitignore

diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..194e312
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,3 @@
+.idea/
+.DS_Store
+i/
\ No newline at end of file
diff --git a/functions.php b/functions.php
index 87cb803..38789d7 100755
--- a/functions.php
+++ b/functions.php
@@ -27,6 +27,8 @@ class WordPressTV_Theme {
 		add_action( 'pre_get_posts', array( $this, 'posts_per_page' ) );
 		add_action( 'init', array( $this, 'improve_search' ) );
 		add_action( 'publish_post', array( $this, 'publish_post' ), 10, 1 );
+		add_action( 'add_meta_boxes', array( $this, 'add_meta_box' ) );
+		add_action( 'save_post', array( $this, 'save_slides' ), 10, 2);
 		add_action( 'wp_footer', array( $this, 'videopress_flash_params' ) );
 		add_action( 'transition_post_status', array( $this, 'transition_post_status' ), 10, 2 );
 
@@ -149,6 +151,38 @@ class WordPressTV_Theme {
 	}
 
 	/**
+	 * Adds meta box for additional video information to posts
+	 */
+	function add_meta_box() {
+		add_meta_box( 'video-info', 'Video Info', array( $this, 'metabox_video_info' ), 'post', 'normal', 'high' );
+	}
+
+	function metabox_video_info() {
+		global $post;
+
+		$slides_url = get_post_meta( $post->ID, '_wptv_slides_url', true );
+		wp_nonce_field( 'edit-video-info', 'wptv_slides_url' ); ?>
+		<p>
+			<label for="wptv-slides-url">Slides URL</label>
+			<input type="text" class="widefat" id="wptv-slides-url" name="_wptv_slides_url" value="<?php echo esc_url( $slides_url ); ?>" />
+		</p>
+	<?php
+	}
+
+	function save_slides( $post_id, $post ) {
+		if ( wp_is_post_revision( $post_id ) || ! current_user_can( 'edit_post', $post_id ) )
+			return;
+
+		if ( isset( $_POST['_wptv_slides_url'] ) && wp_verify_nonce( $_POST['wptv_slides_url'], 'edit-video-info' ) ) {
+			$slides = sanitize_text_field( $_POST['_wptv_slides_url'] );
+
+			if ( ! $slides )
+				delete_post_meta( $post_id, '_wptv_slides_url' );
+			else
+				update_post_meta( $post_id, '_wptv_slides_url', $slides );
+		}
+	}
+	/**
 	 * Activates the improved search, but not in admin.
 	 */
 	function improve_search() {
@@ -175,7 +209,7 @@ class WordPressTV_Theme {
 	}
 
 	/**
-	 * Improved Serach: posts_search filter
+	 * Improved Search: posts_search filter
 	 *
 	 * Recreates the search SQL by including a taxonomy search.
 	 * Relies on various other filters used once.
-- 
1.8.4.2

From 69c4b860f20f11c1d8ca64401d761e10569971aa Mon Sep 17 00:00:00 2001
From: Kyle Maurer <kyle@realbigmarketing.com>
Date: Thu, 11 Dec 2014 16:43:53 -0500
Subject: [PATCH] Added Link to Slides field on submit video form.

---
 anon-upload-template.php | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/anon-upload-template.php b/anon-upload-template.php
index c1118ed..6ce125f 100755
--- a/anon-upload-template.php
+++ b/anon-upload-template.php
@@ -330,6 +330,10 @@ if ( !empty($_REQUEST['error']) ) {
 		<textarea name="wptv_video_description" id="wptv_video_description" rows="8" cols="40"></textarea>
 	</p>
 	<p>
+		<label for="wptv_slides_url"><?php esc_html_e( 'Link to slides' ); ?></label>
+		<input type="text" name="wptv_slides_url" id="wptv_slides_url" value=""/>
+	</p>
+	<p>
 		<label for="wptv_file"><?php esc_html_e( 'Video file' ); ?><span class="required"> * </span></label>
 		<input type="file" name="wptv_file" id="wptv_file" />
 	</p>
-- 
1.8.4.2

From f393ee19015ec8ce05359f494107dbb08207b9b7 Mon Sep 17 00:00:00 2001
From: Kyle Maurer <kyle@realbigmarketing.com>
Date: Fri, 12 Dec 2014 13:06:30 -0500
Subject: [PATCH] Added slides to post.php upload form. Also had to add the
 'slides' key to $meta for posts that were uploaded before the slides field
 existed.

---
 plugins/wordpresstv-anon-upload/anon-upload.php | 18 +++++++++++++++++-
 1 file changed, 17 insertions(+), 1 deletion(-)

diff --git a/plugins/wordpresstv-anon-upload/anon-upload.php b/plugins/wordpresstv-anon-upload/anon-upload.php
index 5c1930b..e80d776 100755
--- a/plugins/wordpresstv-anon-upload/anon-upload.php
+++ b/plugins/wordpresstv-anon-upload/anon-upload.php
@@ -50,6 +50,7 @@ class WPTV_Anon_Upload {
 			'wptv_video_producer',
 			'wptv_speakers',
 			'wptv_event',
+			'wptv_slides_url'
 		);
 
 		// Normal users won't see the honeypot field, so if there's a value in it, then we can assume the submission is spam from a bot
@@ -274,6 +275,7 @@ class WPTV_Anon_Upload {
 		$event          = $this->sanitize_text( $_posted['wptv_event'] );
 		$description    = $this->sanitize_text( $_posted['wptv_video_description'], false );
 		$language       = $this->sanitize_text( $_posted['wptv_language'] );
+		$slides         = $this->sanitize_text( $_posted['wptv_slides_url'] );
 		$ip             = $_SERVER['REMOTE_ADDR'];
 
 		$categories = '';
@@ -297,6 +299,7 @@ class WPTV_Anon_Upload {
 			'language'        => $language,
 			'categories'      => $categories,
 			'description'     => $description,
+			'slides'          => $slides,
 			'ip'              => $ip,
 		);
 
@@ -332,6 +335,10 @@ class WPTV_Anon_Upload {
 		$embed_args['blog_id'] = get_current_blog_id();
 		$embed_args['post_id'] = $meta['attachment_id'];
 
+		// Add slides index to meta (necessary for posts that were uploaded before the field was added)
+		if ( ! array_key_exists( 'slides', $meta ) ) {
+			$meta['slides'] = '';
+		}
 		?>
 		<div class="stuffbox" id="review-video">
 			<style type="text/css" scoped="scoped">
@@ -385,7 +392,6 @@ class WPTV_Anon_Upload {
 				}
 			</style>
 			<h3 class="hndle"><span>Submitted video</span></h3>
-
 			<div id="anon-data-wrap" class="inside">
 
 				<p>To change the default thumbnail image, play the video and click "Capture Thumbnail" button.</p>
@@ -487,6 +493,14 @@ class WPTV_Anon_Upload {
 					</div>
 
 					<div class="row">
+						<p class="label">Slides:</p>
+						<p class="data">
+							<input type="text" value="<?php echo esc_attr( $meta['slides'] ); ?>"/>
+							<a class="button-secondary anon-approve" href="#wptv-slides-url">Approve</a>
+						</p>
+					</div>
+
+					<div class="row">
 						<p class="label">Edit attachment:</p>
 						<p class="data">
 							<a href="<?php echo esc_url( get_edit_post_link( $meta['attachment_id'] ) ); ?>" target="_blank"><?php echo esc_html( $attachment_post->post_title ); ?></a>
@@ -525,6 +539,8 @@ class WPTV_Anon_Upload {
 							el.siblings('.tagadd').click();
 						} else if (id == '#title') {
 							el.val(target.siblings('input[type="text"]').val());
+						} else if (id == '#wptv-slides-url') {
+							el.val(target.siblings('input[type="text"]').val());
 						} else if (id == '#excerpt') {
 							el.val(target.siblings('textarea').val());
 						} else if (target.is('a.anon-cat-link')) {
-- 
1.8.4.2

From 32b01a877b3b1d033cfc7fbfbd75cd8639eafc44 Mon Sep 17 00:00:00 2001
From: Kyle Maurer <kyle@realbigmarketing.com>
Date: Fri, 12 Dec 2014 13:26:01 -0500
Subject: [PATCH] Adjusted the URL escaping for the field. Appended the slides
 link to the_excerpt() if it isn't empty.

---
 functions.php | 21 +++++++++++++++++++--
 1 file changed, 19 insertions(+), 2 deletions(-)

diff --git a/functions.php b/functions.php
index 38789d7..f24b92f 100755
--- a/functions.php
+++ b/functions.php
@@ -164,7 +164,7 @@ class WordPressTV_Theme {
 		wp_nonce_field( 'edit-video-info', 'wptv_slides_url' ); ?>
 		<p>
 			<label for="wptv-slides-url">Slides URL</label>
-			<input type="text" class="widefat" id="wptv-slides-url" name="_wptv_slides_url" value="<?php echo esc_url( $slides_url ); ?>" />
+			<input type="text" class="widefat" id="wptv-slides-url" name="_wptv_slides_url" value="<?php echo $slides_url; ?>" />
 		</p>
 	<?php
 	}
@@ -174,7 +174,7 @@ class WordPressTV_Theme {
 			return;
 
 		if ( isset( $_POST['_wptv_slides_url'] ) && wp_verify_nonce( $_POST['wptv_slides_url'], 'edit-video-info' ) ) {
-			$slides = sanitize_text_field( $_POST['_wptv_slides_url'] );
+			$slides = esc_url( $_POST['_wptv_slides_url'] );
 
 			if ( ! $slides )
 				delete_post_meta( $post_id, '_wptv_slides_url' );
@@ -784,3 +784,20 @@ function wptv_wp_title( $title, $sep ) {
 	return $title;
 }
 add_filter( 'wp_title', 'wptv_wp_title', 10, 2 );
+
+/**
+ * If a slides URL has been entered, use it
+ *
+ * @param $excerpt
+ *
+ * @return string
+ */
+function wptv_excerpt_slides( $excerpt ) {
+	$slides = get_post_meta( get_the_ID(), '_wptv_slides_url', true );
+	if ( ! empty( $slides ) ) {
+		return $excerpt . '<a href="' . $slides . '" target="_blank">Presentation Slides &raquo;</a>';
+	} else {
+		return $excerpt;
+	}
+}
+add_filter( 'the_excerpt', 'wptv_excerpt_slides' );
\ No newline at end of file
-- 
1.8.4.2

