Version Description
- Added Dailymotion
- fixed youtube 'start at specific time' embeds
- overhaul of the interaction between Featured Videos and Featured Images
- existing featured images will no longer be replaced by newly added featured videos in the administration interface
Download this release
Release Info
Developer | a.hoereth |
Plugin | Featured Video Plus |
Version | 1.1 |
Comparing to | |
See all releases |
Code changes from version 1.0 to 1.1
- css/backend.css +18 -5
- featured-video-plus.php +92 -90
- js/backend.js +27 -3
- php/backend.php +279 -179
- php/general.php +45 -36
- php/setup.php +33 -33
- readme.txt +87 -78
css/backend.css
CHANGED
@@ -6,15 +6,28 @@
|
|
6 |
box-shadow: 3px 3px 5px #ddd;
|
7 |
-webkit-box-sizing: border-box;
|
8 |
-moz-box-sizing: border-box;
|
9 |
-
box-sizing: border-box;
|
10 |
}
|
11 |
|
12 |
-
.defaultTextActive {
|
13 |
-
color: #a1a1a1;
|
14 |
-
font-style: italic;
|
15 |
}
|
16 |
|
17 |
#fvp_activation_notification {
|
18 |
border-color: #00adef;
|
19 |
-
background-color: whiteSmoke;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
20 |
}
|
6 |
box-shadow: 3px 3px 5px #ddd;
|
7 |
-webkit-box-sizing: border-box;
|
8 |
-moz-box-sizing: border-box;
|
9 |
+
box-sizing: border-box;
|
10 |
}
|
11 |
|
12 |
+
.defaultTextActive {
|
13 |
+
color: #a1a1a1;
|
14 |
+
font-style: italic;
|
15 |
}
|
16 |
|
17 |
#fvp_activation_notification {
|
18 |
border-color: #00adef;
|
19 |
+
background-color: whiteSmoke;
|
20 |
+
}
|
21 |
+
.fvp_hidden {
|
22 |
+
display: none;
|
23 |
+
}
|
24 |
+
.fvp_notice {
|
25 |
+
-webkit-border-radius: 3px;
|
26 |
+
border-radius: 3px;
|
27 |
+
border-width: 1px;
|
28 |
+
border-style: solid;
|
29 |
+
background-color: lightYellow;
|
30 |
+
border-color: #E6DB55;
|
31 |
+
margin: .5em 0;
|
32 |
+
padding: .4em .6em .2em;
|
33 |
}
|
featured-video-plus.php
CHANGED
@@ -1,91 +1,93 @@
|
|
1 |
-
<?php
|
2 |
-
/**
|
3 |
-
Plugin Name: Featured Video Plus
|
4 |
-
Plugin URI: https://github.com/ahoereth/featured-video-plus
|
5 |
-
Description: Featured Videos just like Featured Images.
|
6 |
-
Author: Alexander Höreth
|
7 |
-
Version: 1.
|
8 |
-
Author URI: http://ahoereth.yrnxt.com
|
9 |
-
License: GPL2
|
10 |
-
|
11 |
-
Copyright 2009-2012 Alexander Höreth (email: a.hoereth@gmail.com)
|
12 |
-
|
13 |
-
This program is free software; you can redistribute it and/or modify
|
14 |
-
it under the terms of the GNU General Public License version 2,
|
15 |
-
as published by the Free Software Foundation.
|
16 |
-
|
17 |
-
You may NOT assume that you can use any other version of the GPL.
|
18 |
-
|
19 |
-
This program is distributed in the hope that it will be useful,
|
20 |
-
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
21 |
-
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
22 |
-
GNU General Public License for more details.
|
23 |
-
|
24 |
-
The license for this software can likely be found here:
|
25 |
-
http://www.gnu.org/licenses/gpl-2.0.html
|
26 |
-
|
27 |
-
*/
|
28 |
-
|
29 |
-
require_once( plugin_dir_path(__FILE__) . 'php/general.php' );
|
30 |
-
require_once( plugin_dir_path(__FILE__) . 'php/backend.php' );
|
31 |
-
require_once( plugin_dir_path(__FILE__) . 'php/frontend.php' );
|
32 |
-
|
33 |
-
// init general class, located in php/general.php
|
34 |
-
$featured_video_plus = new featured_video_plus();
|
35 |
-
|
36 |
-
// shortcode
|
37 |
-
add_shortcode( 'featured-video-plus', array( &$featured_video_plus, 'shortcode' ) );
|
38 |
-
|
39 |
-
// only on backend / administration interface
|
40 |
-
if( is_admin() ) {
|
41 |
-
// init backend class, located in php/backend.php
|
42 |
-
$featured_video_plus_backend = new featured_video_plus_backend($featured_video_plus);
|
43 |
-
|
44 |
-
add_action('admin_menu', array( &$featured_video_plus_backend, 'metabox_register' ) );
|
45 |
-
add_action('save_post', array( &$featured_video_plus_backend, 'metabox_save' ) );
|
46 |
-
|
47 |
-
add_action('admin_init', array( &$featured_video_plus_backend, 'settings_init' ) );
|
48 |
-
|
49 |
-
// enqueue scripts and styles
|
50 |
-
add_action( 'admin_enqueue_scripts', array( &$featured_video_plus_backend, 'enqueue' ) );
|
51 |
-
|
52 |
-
add_action('admin_notices', array( &$featured_video_plus_backend, 'activation_notification' ) );
|
53 |
-
add_action('admin_init', array( &$featured_video_plus_backend, 'ignore_activation_notification' ) );
|
54 |
-
}
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
|
|
|
|
91 |
?>
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
Plugin Name: Featured Video Plus
|
4 |
+
Plugin URI: https://github.com/ahoereth/featured-video-plus
|
5 |
+
Description: Featured Videos just like Featured Images.
|
6 |
+
Author: Alexander Höreth
|
7 |
+
Version: 1.1
|
8 |
+
Author URI: http://ahoereth.yrnxt.com
|
9 |
+
License: GPL2
|
10 |
+
|
11 |
+
Copyright 2009-2012 Alexander Höreth (email: a.hoereth@gmail.com)
|
12 |
+
|
13 |
+
This program is free software; you can redistribute it and/or modify
|
14 |
+
it under the terms of the GNU General Public License version 2,
|
15 |
+
as published by the Free Software Foundation.
|
16 |
+
|
17 |
+
You may NOT assume that you can use any other version of the GPL.
|
18 |
+
|
19 |
+
This program is distributed in the hope that it will be useful,
|
20 |
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
21 |
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
22 |
+
GNU General Public License for more details.
|
23 |
+
|
24 |
+
The license for this software can likely be found here:
|
25 |
+
http://www.gnu.org/licenses/gpl-2.0.html
|
26 |
+
|
27 |
+
*/
|
28 |
+
|
29 |
+
require_once( plugin_dir_path(__FILE__) . 'php/general.php' );
|
30 |
+
require_once( plugin_dir_path(__FILE__) . 'php/backend.php' );
|
31 |
+
require_once( plugin_dir_path(__FILE__) . 'php/frontend.php' );
|
32 |
+
|
33 |
+
// init general class, located in php/general.php
|
34 |
+
$featured_video_plus = new featured_video_plus();
|
35 |
+
|
36 |
+
// shortcode
|
37 |
+
add_shortcode( 'featured-video-plus', array( &$featured_video_plus, 'shortcode' ) );
|
38 |
+
|
39 |
+
// only on backend / administration interface
|
40 |
+
if( is_admin() ) {
|
41 |
+
// init backend class, located in php/backend.php
|
42 |
+
$featured_video_plus_backend = new featured_video_plus_backend($featured_video_plus);
|
43 |
+
|
44 |
+
add_action('admin_menu', array( &$featured_video_plus_backend, 'metabox_register' ) );
|
45 |
+
add_action('save_post', array( &$featured_video_plus_backend, 'metabox_save' ) );
|
46 |
+
|
47 |
+
add_action('admin_init', array( &$featured_video_plus_backend, 'settings_init' ) );
|
48 |
+
|
49 |
+
// enqueue scripts and styles
|
50 |
+
add_action( 'admin_enqueue_scripts', array( &$featured_video_plus_backend, 'enqueue' ) );
|
51 |
+
|
52 |
+
add_action('admin_notices', array( &$featured_video_plus_backend, 'activation_notification' ) );
|
53 |
+
add_action('admin_init', array( &$featured_video_plus_backend, 'ignore_activation_notification' ) );
|
54 |
+
}
|
55 |
+
|
56 |
+
|
57 |
+
// only on frontend / page
|
58 |
+
if( !is_admin() ) {
|
59 |
+
// init frontend class, located in php/frontend.php
|
60 |
+
$featured_video_plus_frontend = new featured_video_plus_frontend($featured_video_plus);
|
61 |
+
|
62 |
+
// enqueue scripts and styles
|
63 |
+
add_action( 'wp_enqueue_scripts', array( &$featured_video_plus_frontend, 'enqueue' ) );
|
64 |
+
|
65 |
+
// filter get_post_thumbnail output
|
66 |
+
add_filter('post_thumbnail_html', array( &$featured_video_plus_frontend, 'filter_post_thumbnail'), 99, 5);
|
67 |
+
|
68 |
+
|
69 |
+
// functions which are available to theme developers follow here:
|
70 |
+
// echos the current posts featured video
|
71 |
+
function the_post_video($width = '560', $height = '315', $allowfullscreen = true) {
|
72 |
+
echo get_the_post_video(null, $width, $height, $allowfullscreen, true);
|
73 |
+
}
|
74 |
+
|
75 |
+
// returns the posts featured video
|
76 |
+
function get_the_post_video($post_id = null, $width = '560', $height = '315', $allowfullscreen = true) {
|
77 |
+
global $featured_video_plus;
|
78 |
+
return $featured_video_plus->get_the_post_video($post_id, $width, $height, $allowfullscreen);
|
79 |
+
}
|
80 |
+
|
81 |
+
// checks if post has a featured video
|
82 |
+
function has_post_video($post_id = null){
|
83 |
+
global $featured_video_plus;
|
84 |
+
return $featured_video_plus->has_post_video($post_id);
|
85 |
+
}
|
86 |
+
}
|
87 |
+
|
88 |
+
|
89 |
+
include_once( dirname( __FILE__ ) . '/php/setup.php' );
|
90 |
+
register_activation_hook( WP_PLUGIN_DIR . '/featured-video-plus/featured-video-plus.php', array( 'featured_video_plus_setup', 'on_activate' ) );
|
91 |
+
register_uninstall_hook( WP_PLUGIN_DIR . '/featured-video-plus/featured-video-plus.php', array( 'featured_video_plus_setup', 'on_uninstall' ) );
|
92 |
+
|
93 |
?>
|
js/backend.js
CHANGED
@@ -1,18 +1,42 @@
|
|
1 |
jQuery(document).ready(function($){
|
2 |
|
|
|
|
|
3 |
$("#fvp_video").focus(function(srcc) {
|
4 |
if ($(this).val() == $(this)[0].title) {
|
5 |
$(this).removeClass("defaultTextActive");
|
6 |
$(this).val("");
|
7 |
}
|
8 |
});
|
9 |
-
|
10 |
$("#fvp_video").blur(function() {
|
11 |
if ($(this).val() == "") {
|
12 |
$(this).addClass("defaultTextActive");
|
13 |
$(this).val($(this)[0].title);
|
14 |
}
|
15 |
});
|
16 |
-
|
17 |
-
$("#fvp_video").blur();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
18 |
});
|
1 |
jQuery(document).ready(function($){
|
2 |
|
3 |
+
// remove default value of input field on focus
|
4 |
+
// since 1.0
|
5 |
$("#fvp_video").focus(function(srcc) {
|
6 |
if ($(this).val() == $(this)[0].title) {
|
7 |
$(this).removeClass("defaultTextActive");
|
8 |
$(this).val("");
|
9 |
}
|
10 |
});
|
11 |
+
|
12 |
$("#fvp_video").blur(function() {
|
13 |
if ($(this).val() == "") {
|
14 |
$(this).addClass("defaultTextActive");
|
15 |
$(this).val($(this)[0].title);
|
16 |
}
|
17 |
});
|
18 |
+
|
19 |
+
$("#fvp_video").blur();
|
20 |
+
|
21 |
+
// replace current featured video link & checkbox
|
22 |
+
// since 1.1
|
23 |
+
$("#fvp_set_featimg_link").show();
|
24 |
+
$("#fvp_set_featimg_input").hide();
|
25 |
+
|
26 |
+
$("#fvp_set_featimg_link, #fvp_warning_set_featimg").click(function() {
|
27 |
+
$("#fvp_set_featimg").attr('checked', true);
|
28 |
+
$("#fvp_set_featimg").closest("form").submit();
|
29 |
+
return false;
|
30 |
+
});
|
31 |
+
|
32 |
+
$("#remove-post-thumbnail").click(function() {
|
33 |
+
$("#fvp_set_featimg_box").removeClass("fvp_hidden");
|
34 |
+
$("#fvp_featimg_box_warning").removeClass("fvp_hidden");
|
35 |
+
});
|
36 |
+
|
37 |
+
$("#set-post-thumbnail").click(function() {
|
38 |
+
$("#fvp_set_featimg_link").html('Replace current Featured Image');
|
39 |
+
$("#fvp_featimg_box_warning").addClass("fvp_hidden");
|
40 |
+
});
|
41 |
+
|
42 |
});
|
php/backend.php
CHANGED
@@ -13,7 +13,7 @@
|
|
13 |
class featured_video_plus_backend {
|
14 |
private $featured_video_plus;
|
15 |
private $default_value;
|
16 |
-
|
17 |
/**
|
18 |
* Creates a new instace of this class, saves the featured_video_instance and default value for the meta box input.
|
19 |
*
|
@@ -21,19 +21,20 @@ class featured_video_plus_backend {
|
|
21 |
*
|
22 |
* @param featured_video_plus_instance required, dies without
|
23 |
*/
|
24 |
-
function __construct( $featured_video_plus_instance )
|
25 |
-
|
26 |
wp_die( 'featured_video_plus general instance required!', 'Error!' );
|
27 |
-
|
28 |
$this->featured_video_plus = $featured_video_plus_instance;
|
29 |
$default_value = 'paste your YouTube or Vimeo URL here';
|
30 |
}
|
31 |
-
|
32 |
/**
|
33 |
* Enqueue all scripts and styles needed when viewing the backend.
|
34 |
*
|
35 |
* @see http://codex.wordpress.org/Function_Reference/wp_style_is
|
36 |
-
* @see http://make.wordpress.org/core/2012/11/30/new-color-picker-in-wp-3-5/
|
|
|
37 |
* @since 1.0
|
38 |
*/
|
39 |
public function enqueue($hook_suffix) {
|
@@ -50,58 +51,20 @@ class featured_video_plus_backend {
|
|
50 |
wp_enqueue_script( 'fvp_backend_pre35', plugins_url() . '/featured-video-plus/js/backend_pre35.js', array( 'jquery' ) );
|
51 |
}
|
52 |
}
|
53 |
-
|
54 |
// just required on post.php
|
55 |
-
if($hook_suffix == 'post.php') {
|
56 |
wp_enqueue_script( 'fvp_backend', plugins_url() . '/featured-video-plus/js/backend.js', array( 'jquery' ) );
|
57 |
-
|
58 |
// just required if width is set to auto
|
59 |
$options = get_option( 'fvp-settings' );
|
60 |
if($options['width'] == 'auto')
|
61 |
wp_enqueue_script('fvp_fitvids', plugins_url(). '/featured-video-plus/js/jquery.fitvids_fvp.js', array( 'jquery' ), '20121207', true );
|
62 |
}
|
63 |
-
|
64 |
wp_enqueue_style( 'fvp_backend', plugins_url() . '/featured-video-plus/css/backend.css' );
|
65 |
}
|
66 |
-
|
67 |
-
/**
|
68 |
-
* Notification shown when plugin is newly activated. Automatically hidden after 5x displayed.
|
69 |
-
*
|
70 |
-
* @see http://wptheming.com/2011/08/admin-notices-in-wordpress/
|
71 |
-
* @since 1.0
|
72 |
-
*/
|
73 |
-
public function activation_notification() {
|
74 |
-
if ( current_user_can( 'manage_options' ) ) {
|
75 |
-
global $current_user ;
|
76 |
-
|
77 |
-
$count = get_user_meta($current_user->ID, 'fvp_activation_notification_ignore', true);
|
78 |
-
if( empty($count) || ($count <= 5) ) {
|
79 |
-
$part = empty($count) ? 'There is a new box on post & page edit screens for you to add video URLs.' : '';
|
80 |
-
echo "\n" . '<div class="updated" id="fvp_activation_notification"><p>';
|
81 |
-
printf(__('Featured Video Plus is ready to use. %1$s<span style="font-weight: bold;">Take a look at your new <a href="%2$s" title="Media Settings">Media Settings</a></span> | <a href="%3$s">Hide Notice</a>'), $part . ' ', get_admin_url(null, '/options-media.php?fvp_activation_notification_ignore=0'), '?fvp_activation_notification_ignore=0');
|
82 |
-
echo "</p></div>\n";
|
83 |
-
|
84 |
-
$count = empty($count) ? 1 : $count+1;
|
85 |
-
update_user_meta($current_user->ID, 'fvp_activation_notification_ignore', $count);
|
86 |
-
}
|
87 |
-
}
|
88 |
-
}
|
89 |
|
90 |
-
/**
|
91 |
-
* Function fired when notification should be hidden manually. Hides it for the current user forever.
|
92 |
-
*
|
93 |
-
* @see http://wptheming.com/2011/08/admin-notices-in-wordpress/
|
94 |
-
* @see function activation_notification
|
95 |
-
* @since 1.0
|
96 |
-
*/
|
97 |
-
public function ignore_activation_notification() {
|
98 |
-
global $current_user;
|
99 |
-
|
100 |
-
// If user clicks to ignore the notice, add that to their user meta
|
101 |
-
if ( isset($_GET['fvp_activation_notification_ignore']) && '0' == $_GET['fvp_activation_notification_ignore'] )
|
102 |
-
update_user_meta($current_user->ID, 'fvp_activation_notification_ignore', 999);
|
103 |
-
}
|
104 |
-
|
105 |
/**
|
106 |
* Registers the metabox on post/page edit views.
|
107 |
*
|
@@ -112,10 +75,9 @@ class featured_video_plus_backend {
|
|
112 |
foreach ($post_types as $post_type) {
|
113 |
if($post_type != 'attachment')
|
114 |
add_meta_box("featured_video_plus-box", 'Featured Video', array( &$this, 'metabox_content' ), $post_type, 'side', 'core');
|
115 |
-
}
|
116 |
}
|
117 |
|
118 |
-
|
119 |
/**
|
120 |
* Callback function of the metabox; generates the HTML content.
|
121 |
*
|
@@ -124,50 +86,101 @@ class featured_video_plus_backend {
|
|
124 |
function metabox_content() {
|
125 |
wp_nonce_field( plugin_basename( __FILE__ ), 'fvp_nonce');
|
126 |
|
127 |
-
if( isset($_GET['post']) )
|
128 |
$post_id = $_GET['post'];
|
129 |
else
|
130 |
$post_id = $GLOBALS['post']->ID;
|
131 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
132 |
$meta = unserialize( get_post_meta($post_id, '_fvp_video', true) );
|
133 |
-
|
134 |
// displays the current featured video
|
135 |
-
if( $
|
136 |
echo "\n" . '<div id="featured_video_preview" class="featured_video_plus" style="display:block">' . $this->featured_video_plus->get_the_post_video( $post_id, array(256,144) ) . '</div>' . "\n";
|
137 |
-
|
138 |
// input box containing the featured video URL
|
139 |
echo "\n" . '<input id="fvp_video" name="fvp_video" type="text" value="' . $meta['full'] . '" style="width: 100%" title="' . $this->default_value . '" />' . "\n";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
140 |
}
|
141 |
|
142 |
/**
|
143 |
* Saves the changes made in the metabox: Splits URL in its parts, saves provider and id, pulls the screen capture, adds it to the gallery and as featured image.
|
144 |
-
*
|
145 |
* @since 1.0
|
146 |
-
*
|
147 |
* @param int $post_id
|
148 |
*/
|
149 |
-
public function metabox_save($post_id){
|
150 |
-
|
151 |
-
if (( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE )
|
152 |
-
( defined( 'DOING_AJAX' ) && DOING_AJAX )
|
153 |
-
( !current_user_can( 'edit_post', $post_id ) )
|
154 |
-
( false !== wp_is_post_revision( $post_id ) )
|
155 |
-
( !wp_verify_nonce( $_POST['fvp_nonce'], plugin_basename( __FILE__ ) ) )
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
$meta = unserialize( get_post_meta($post_id, '_fvp_video', true) );
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
|
|
|
|
|
|
|
|
|
|
165 |
}
|
166 |
-
|
167 |
|
168 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
169 |
return;
|
170 |
-
|
171 |
/*
|
172 |
REGEX tested using: http://www.rubular.com/
|
173 |
|
@@ -182,86 +195,119 @@ http://www.youtube.com/watch?v=9Tjg6V1Eoz4&t=2m29s
|
|
182 |
http://www.youtube.com/watch?v=G_Oj7UI0-pw
|
183 |
http://www.youtube.com/watch?feature=blub&v=G_Oj7UI0-pw
|
184 |
*/
|
185 |
-
|
186 |
$local = wp_upload_dir();
|
187 |
// match different provider(!)
|
188 |
-
preg_match('/(vimeo|youtu|
|
|
|
|
|
|
|
189 |
$video_prov = $video_provider[1] == "youtu" ? "youtube" : $video_provider[1];
|
190 |
-
/*if( $video_prov == $local['baseurl'] ) {
|
191 |
-
|
192 |
-
$video_id = $this->get_post_by_url($video);
|
193 |
-
$video_prov = 'local';
|
194 |
-
|
195 |
-
// get video from youtube
|
196 |
-
} else */
|
197 |
-
if( $video_prov == 'youtube' ) {
|
198 |
-
|
199 |
-
//match provider watch feature id(!) attr(!)
|
200 |
-
preg_match('/youtu(?:be\.com|\.be)\/(?:watch)?(?:\?feature=[^\?&]*)*(?:[\?&]v=)?([^\?&\s]+)(?:(?:[&\?]t=)(\d+m\d+s))?/', $video, $video_data);
|
201 |
-
$video_id = $video_data[1];
|
202 |
-
if( isset($video_data[2] ) )
|
203 |
-
$video_attr = $video_data[2];
|
204 |
-
|
205 |
-
// title, allow_embed 0/1, keywords, author, iurlmaxres, thumbnail_url, timestamp, avg_rating
|
206 |
-
$tmp = download_url( 'http://youtube.com/get_video_info?video_id=' . $video_id );
|
207 |
-
$data = file_get_contents($tmp);
|
208 |
-
parse_str($data, $data);
|
209 |
-
@unlink( $tmp );
|
210 |
-
|
211 |
-
// generate video metadata
|
212 |
-
$video_info = array(
|
213 |
-
'title' => $data['title'],
|
214 |
-
'description' => $data['keywords'],
|
215 |
-
'filename' => sanitize_file_name($data['title']),
|
216 |
-
'timestamp' => $data['timestamp'],
|
217 |
-
'author' => $data['author'],
|
218 |
-
'tags' => $data['keywords'],
|
219 |
-
'img' => ( isset($data['iurlmaxres']) ? $data['iurlmaxres'] : 'http://img.youtube.com/vi/' . $video_id . '/0.jpg' )
|
220 |
-
);
|
221 |
|
222 |
-
|
223 |
-
|
224 |
-
|
225 |
-
|
226 |
-
|
227 |
-
|
228 |
-
|
229 |
-
|
230 |
-
|
231 |
-
|
232 |
-
|
233 |
-
|
234 |
-
|
235 |
-
|
236 |
-
|
237 |
-
|
238 |
-
|
239 |
-
|
240 |
-
|
241 |
-
|
242 |
-
|
243 |
-
|
244 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
245 |
}
|
246 |
-
|
247 |
// do we have a screen capture to pull?
|
248 |
if( !empty($video_info['img']) ) {
|
249 |
-
|
250 |
// is this screen capture already existing in our media library?
|
251 |
$video_img = $this->get_post_by_custom_meta('_fvp_image', $video_prov . '?' . $video_id);
|
252 |
if( !isset($video_img) ) {
|
253 |
-
|
254 |
// generate attachment post metadata
|
255 |
$video_img_data = array(
|
256 |
'post_content' => $video_info['description'],
|
257 |
'post_title' => $video_info['title'],
|
258 |
'post_name' => $video_info['filename']
|
259 |
);
|
260 |
-
|
261 |
// pull external img to local server and add to media library
|
262 |
require_once( plugin_dir_path(__FILE__) . 'somatic_attach_external_image.php' );
|
263 |
$video_img = somatic_attach_external_image($video_info['img'], $post_id, false, $video_info['filename'], $video_img_data);
|
264 |
-
|
265 |
// generate picture metadata
|
266 |
$video_img_meta = wp_get_attachment_metadata( $video_img );
|
267 |
$video_img_meta['image_meta'] = array(
|
@@ -276,61 +322,64 @@ http://www.youtube.com/watch?feature=blub&v=G_Oj7UI0-pw
|
|
276 |
'shutter_speed' => 0,
|
277 |
'title' => $video_info['title']
|
278 |
);
|
279 |
-
|
280 |
// save picture metadata
|
281 |
wp_update_attachment_metadata($video_img, $video_img_meta);
|
282 |
-
update_post_meta($video_img, '_fvp_image', $video_prov . '?' . $video_id);
|
283 |
}
|
284 |
-
|
285 |
-
|
286 |
-
|
287 |
-
|
|
|
|
|
288 |
}
|
289 |
-
|
290 |
$meta = array(
|
291 |
-
'full' => $video,
|
292 |
'id' => $video_id,
|
293 |
'img' => $video_img,
|
294 |
'prov' => $video_prov,
|
295 |
-
'attr' => $video_attr
|
|
|
296 |
);
|
297 |
update_post_meta( $post_id, '_fvp_video', serialize($meta) );
|
298 |
-
|
299 |
return;
|
300 |
}
|
301 |
-
|
302 |
/**
|
303 |
* Initialises the plugin settings section, the settings fields and registers the options field and save function.
|
304 |
-
*
|
305 |
* @see http://codex.wordpress.org/Settings_API
|
306 |
* @since 1.0
|
307 |
*/
|
308 |
function settings_init() {
|
309 |
add_settings_section('fvp-settings-section', 'Featured Video', array( &$this, 'settings_content' ), 'media');
|
310 |
-
|
311 |
add_settings_field('fvp-settings-overwrite', 'Replace featured images', array( &$this, 'settings_overwrite' ), 'media', 'fvp-settings-section');
|
312 |
add_settings_field('fvp-settings-width', 'Video width', array( &$this, 'settings_width' ), 'media', 'fvp-settings-section');
|
313 |
add_settings_field('fvp-settings-height', 'Video height', array( &$this, 'settings_height' ), 'media', 'fvp-settings-section');
|
314 |
add_settings_field('fvp-settings-vimeo', 'Vimeo Player Design', array( &$this, 'settings_vimeo' ), 'media', 'fvp-settings-section');
|
315 |
add_settings_field('fvp-settings-rate', 'Support', array( &$this, 'settings_rate' ), 'media', 'fvp-settings-section');
|
316 |
-
|
317 |
register_setting('media', 'fvp-settings', array( &$this, 'settings_save' ));
|
318 |
}
|
319 |
-
|
320 |
/**
|
321 |
* The settings section content. Describes the plugin settings, the php functions and the WordPress shortcode.
|
322 |
*
|
323 |
* @since 1.0
|
324 |
*/
|
325 |
function settings_content() { ?>
|
326 |
-
|
327 |
<p>To display your featured videos you can either make use of the automatical replacement, use the <code>[featured-video]</code>-shortcode or manually edit your theme's source files to make use of the plugins PHP-functions.</p>
|
328 |
<table>
|
329 |
<tr style="vertical-align: top;">
|
330 |
<td style="width: 50%;">
|
331 |
<h4 style="margin-top: 0">WordPress Shortcode Usage</h4>
|
332 |
<table>
|
333 |
-
<tr style="vertical-align: top;">
|
334 |
<td><code>[featured-video]</code></td>
|
335 |
<td>Displays the video in its default size, if <code>width</code> below is set to <code>auto</code> 100%, elsewise 560px.</td>
|
336 |
</tr>
|
@@ -345,7 +394,7 @@ http://www.youtube.com/watch?feature=blub&v=G_Oj7UI0-pw
|
|
345 |
<ul>
|
346 |
<li><code>the_post_video(array(width, height), allow_fullscreen = true)</code></li>
|
347 |
<li><code>has_post_video(post_id = null)</code></li>
|
348 |
-
<li><code>get_the_post_video(post_id = null, array(width, height), allow_fullscreen = true)</code></li>
|
349 |
</ul>
|
350 |
<p class="description">
|
351 |
All parameters are optional. If <code>post_id == null</code> the current post's id will be used.
|
@@ -356,7 +405,7 @@ http://www.youtube.com/watch?feature=blub&v=G_Oj7UI0-pw
|
|
356 |
</table>
|
357 |
|
358 |
<?php }
|
359 |
-
|
360 |
/**
|
361 |
* Displays the setting if the plugin should display the featured video in place of featured images.
|
362 |
*
|
@@ -364,13 +413,13 @@ http://www.youtube.com/watch?feature=blub&v=G_Oj7UI0-pw
|
|
364 |
*/
|
365 |
function settings_overwrite() {
|
366 |
$options = get_option( 'fvp-settings' ); ?>
|
367 |
-
|
368 |
<input type="radio" name="fvp-settings[overwrite]" id="fvp-settings-overwrite-1" value="true" <?php checked( true, $options['overwrite'], true ) ?>/><label for="fvp-settings-overwrite-1"> yes <span style="font-style: italic;">(default)</span></label>
|
369 |
<input type="radio" name="fvp-settings[overwrite]" id="fvp-settings-overwrite-2" value="false" <?php checked( false, $options['overwrite'], true ) ?>/><label for="fvp-settings-overwrite-2"> no</label>
|
370 |
<p class="description">If a featured video is available, it can be displayed in place of the featured image.<br />For some themes this could result in displaying errors. When using this, try different <code>width</code> and <code>height</code> settings.</p>
|
371 |
|
372 |
<?php }
|
373 |
-
|
374 |
/**
|
375 |
* Displays the setting if the plugin should fit the width of the videos automatically or use fixed widths.
|
376 |
*
|
@@ -384,7 +433,7 @@ http://www.youtube.com/watch?feature=blub&v=G_Oj7UI0-pw
|
|
384 |
<p class="description">Using <code>auto</code> the video's width will be adjusted to fit the parent element. Works best in combination with height setted to <code>auto</code> as well.</p>
|
385 |
|
386 |
<?php }
|
387 |
-
|
388 |
/**
|
389 |
* Displays the setting if the plugin should fit the height of the videos automatically to their width/height ratio or use fixed heights, which might result in black bars.
|
390 |
*
|
@@ -413,31 +462,31 @@ http://www.youtube.com/watch?feature=blub&v=G_Oj7UI0-pw
|
|
413 |
<div style="position: relative; bottom: .6em;">
|
414 |
<input type="checkbox" name="fvp-settings[vimeo][portrait]" id="fvp-settings-vimeo-1" value="display" <?php checked( 1, $options['vimeo']['portrait'], 1 ) ?>/><label for="fvp-settings-vimeo-1"> Portrait</label>
|
415 |
<input type="checkbox" name="fvp-settings[vimeo][title]" id="fvp-settings-vimeo-2" value="display" <?php checked( 1, $options['vimeo']['title'], 1 ) ?>/><label for="fvp-settings-vimeo-2"> Title</label>
|
416 |
-
<input type="checkbox" name="fvp-settings[vimeo][byline]" id="fvp-settings-vimeo-3" value="display" <?php checked( 1, $options['vimeo']['byline'], 1 ) ?>/><label for="fvp-settings-vimeo-3"> Byline</label>
|
417 |
<span class="color-picker" style="position: relative;<?php if( wp_style_is( 'wp-color-picker', 'done' ) ) echo ' top: .6em;'; ?>" >
|
418 |
<input type="text" name="fvp-settings[vimeo][color]" id="fvp-settings-vimeo-color" value="#<?php echo isset($options['vimeo']['color']) ? $options['vimeo']['color'] : '00adef'; ?>" data-default-color="#00adef" />
|
419 |
<label for="fvp-settings-vimeo-color" style="display: none;"> Color</label>
|
420 |
-
<?php if( !wp_style_is(
|
421 |
</span>
|
422 |
</div>
|
423 |
<p class="description">These settings could be overwritten by videos from Vimeo Plus members.</p>
|
424 |
|
425 |
<?php }
|
426 |
-
|
427 |
/**
|
428 |
* Displays info about rating the plugin, giving feedback and requesting new features
|
429 |
*
|
430 |
* @since 1.0
|
431 |
*/
|
432 |
function settings_rate() { ?>
|
433 |
-
|
434 |
<p>
|
435 |
Found a bug or <span style="font-weight: bold;">missing a specific video service</span>? <a href="http://wordpress.org/extend/plugins/featured-video/" title="Featured Video Plus Support Forum on wordpress.org" style="font-weight: bold;">Leave a note</a> in the plugins support forum!<br />
|
436 |
No? Than please <a href="http://wordpress.org/extend/plugins/featured-video/" title="Featured Video Plus on wordpress.org" style="font-weight: bold;">rate it</a>.<br />
|
437 |
</p>
|
438 |
|
439 |
<?php }
|
440 |
-
|
441 |
/**
|
442 |
* Function through which all settings are passed before they are saved. Validate the data.
|
443 |
*
|
@@ -445,35 +494,86 @@ http://www.youtube.com/watch?feature=blub&v=G_Oj7UI0-pw
|
|
445 |
*/
|
446 |
function settings_save($input) {
|
447 |
$input['overwrite'] = $input['overwrite'] == 'true' ? true : false;
|
448 |
-
|
449 |
-
$input['vimeo']['portrait'] = $input['vimeo']['portrait']
|
450 |
-
$input['vimeo']['title'] = $input['vimeo']['title']
|
451 |
-
$input['vimeo']['byline'] = $input['vimeo']['byline'] == 'display' ? 1 : 0;
|
452 |
-
|
453 |
-
$input['vimeo']['color']
|
|
|
|
|
|
|
|
|
|
|
454 |
return $input;
|
455 |
}
|
456 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
457 |
/**
|
458 |
* Gets a post by an meta_key meta_value pair. Returns it's post_id.
|
459 |
*
|
460 |
* @see http://codex.wordpress.org/Class_Reference/wpdb
|
|
|
461 |
* @since 1.0
|
462 |
*
|
463 |
* @param string $meta_key which meta_key to look for
|
464 |
* @param string $meta_value which meta_value to look for
|
465 |
*/
|
466 |
-
function get_post_by_custom_meta($meta_key, $meta_value) {
|
467 |
global $wpdb;
|
468 |
-
$
|
469 |
-
|
470 |
-
|
471 |
-
|
472 |
-
|
473 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
474 |
return $id;
|
475 |
}
|
476 |
-
|
477 |
/**
|
478 |
* Gets post id by it's url / guid.
|
479 |
*
|
@@ -492,6 +592,6 @@ http://www.youtube.com/watch?feature=blub&v=G_Oj7UI0-pw
|
|
492 |
);
|
493 |
return $id;
|
494 |
}
|
495 |
-
|
496 |
}
|
497 |
?>
|
13 |
class featured_video_plus_backend {
|
14 |
private $featured_video_plus;
|
15 |
private $default_value;
|
16 |
+
|
17 |
/**
|
18 |
* Creates a new instace of this class, saves the featured_video_instance and default value for the meta box input.
|
19 |
*
|
21 |
*
|
22 |
* @param featured_video_plus_instance required, dies without
|
23 |
*/
|
24 |
+
function __construct( $featured_video_plus_instance ){
|
25 |
+
if ( !isset($featured_video_plus_instance) )
|
26 |
wp_die( 'featured_video_plus general instance required!', 'Error!' );
|
27 |
+
|
28 |
$this->featured_video_plus = $featured_video_plus_instance;
|
29 |
$default_value = 'paste your YouTube or Vimeo URL here';
|
30 |
}
|
31 |
+
|
32 |
/**
|
33 |
* Enqueue all scripts and styles needed when viewing the backend.
|
34 |
*
|
35 |
* @see http://codex.wordpress.org/Function_Reference/wp_style_is
|
36 |
+
* @see http://make.wordpress.org/core/2012/11/30/new-color-picker-in-wp-3-5/
|
37 |
+
* @see http://ottopress.com/2010/passing-parameters-from-php-to-javascripts-in-plugins/
|
38 |
* @since 1.0
|
39 |
*/
|
40 |
public function enqueue($hook_suffix) {
|
51 |
wp_enqueue_script( 'fvp_backend_pre35', plugins_url() . '/featured-video-plus/js/backend_pre35.js', array( 'jquery' ) );
|
52 |
}
|
53 |
}
|
54 |
+
|
55 |
// just required on post.php
|
56 |
+
if($hook_suffix == 'post.php' && isset($_GET['post']) ) {
|
57 |
wp_enqueue_script( 'fvp_backend', plugins_url() . '/featured-video-plus/js/backend.js', array( 'jquery' ) );
|
58 |
+
|
59 |
// just required if width is set to auto
|
60 |
$options = get_option( 'fvp-settings' );
|
61 |
if($options['width'] == 'auto')
|
62 |
wp_enqueue_script('fvp_fitvids', plugins_url(). '/featured-video-plus/js/jquery.fitvids_fvp.js', array( 'jquery' ), '20121207', true );
|
63 |
}
|
64 |
+
|
65 |
wp_enqueue_style( 'fvp_backend', plugins_url() . '/featured-video-plus/css/backend.css' );
|
66 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
67 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
68 |
/**
|
69 |
* Registers the metabox on post/page edit views.
|
70 |
*
|
75 |
foreach ($post_types as $post_type) {
|
76 |
if($post_type != 'attachment')
|
77 |
add_meta_box("featured_video_plus-box", 'Featured Video', array( &$this, 'metabox_content' ), $post_type, 'side', 'core');
|
78 |
+
}
|
79 |
}
|
80 |
|
|
|
81 |
/**
|
82 |
* Callback function of the metabox; generates the HTML content.
|
83 |
*
|
86 |
function metabox_content() {
|
87 |
wp_nonce_field( plugin_basename( __FILE__ ), 'fvp_nonce');
|
88 |
|
89 |
+
if( isset($_GET['post']) )
|
90 |
$post_id = $_GET['post'];
|
91 |
else
|
92 |
$post_id = $GLOBALS['post']->ID;
|
93 |
+
|
94 |
+
// required for conditionals
|
95 |
+
$tmp1 = get_post_thumbnail_id($post_id);
|
96 |
+
$tmp2 = get_post_meta( $tmp1, '_fvp_image', true);
|
97 |
+
$has_featimg = empty($tmp1) ? false : true;
|
98 |
+
$featimg_is_fvp = empty($tmp2) ? false : true;
|
99 |
+
$has_post_video = $this->featured_video_plus->has_post_video($post_id);
|
100 |
+
|
101 |
$meta = unserialize( get_post_meta($post_id, '_fvp_video', true) );
|
102 |
+
|
103 |
// displays the current featured video
|
104 |
+
if( $has_post_video )
|
105 |
echo "\n" . '<div id="featured_video_preview" class="featured_video_plus" style="display:block">' . $this->featured_video_plus->get_the_post_video( $post_id, array(256,144) ) . '</div>' . "\n";
|
106 |
+
|
107 |
// input box containing the featured video URL
|
108 |
echo "\n" . '<input id="fvp_video" name="fvp_video" type="text" value="' . $meta['full'] . '" style="width: 100%" title="' . $this->default_value . '" />' . "\n";
|
109 |
+
|
110 |
+
// link/input to set as featured image
|
111 |
+
$class = !$has_post_video || ($has_featimg && $featimg_is_fvp) ? ' class="fvp_hidden"' : '';
|
112 |
+
$text = 'Set as Featured Image';
|
113 |
+
echo '<p id="fvp_set_featimg_box"'.$class.'><span id="fvp_set_featimg_input"><input id="fvp_set_featimg" name="fvp_set_featimg" type="checkbox" value="set_featimg" /><label for="fvp_set_featimg"> '.$text.'</label></span>';
|
114 |
+
echo '<a style="display: none;" id="fvp_set_featimg_link" href="#">'.$text.'</a></p>';
|
115 |
+
|
116 |
+
$class = $has_featimg ? ' fvp_hidden' : '';
|
117 |
+
echo '<div id="fvp_featimg_box_warning" class="fvp_notice'.$class.'"><p class="description">In many themes to automatically display the Featured Video a Featured Image is required!</p></div>';
|
118 |
+
|
119 |
}
|
120 |
|
121 |
/**
|
122 |
* Saves the changes made in the metabox: Splits URL in its parts, saves provider and id, pulls the screen capture, adds it to the gallery and as featured image.
|
123 |
+
*
|
124 |
* @since 1.0
|
125 |
+
*
|
126 |
* @param int $post_id
|
127 |
*/
|
128 |
+
public function metabox_save($post_id, $set_featimg = false){
|
129 |
+
|
130 |
+
if (( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) || // Autosave, do nothing
|
131 |
+
( defined( 'DOING_AJAX' ) && DOING_AJAX ) || // AJAX? Not used here
|
132 |
+
( !current_user_can( 'edit_post', $post_id ) ) || // Check user permissions
|
133 |
+
( false !== wp_is_post_revision( $post_id ) ) || // Return if it's a post revision
|
134 |
+
( ( isset($_POST['fvp_nonce']) && !wp_verify_nonce( $_POST['fvp_nonce'], plugin_basename( __FILE__ ) ) ) &&
|
135 |
+
!is_string($set_featimg) )
|
136 |
+
) return;
|
137 |
+
|
138 |
$meta = unserialize( get_post_meta($post_id, '_fvp_video', true) );
|
139 |
+
if( is_string($set_featimg) ) {
|
140 |
+
$video = $set_featimg;
|
141 |
+
$set_featimg = true;
|
142 |
+
} else {
|
143 |
+
$set_featimg = isset($_POST['fvp_set_featimg']) && !empty($_POST['fvp_set_featimg']) ? true : $set_featimg;
|
144 |
+
|
145 |
+
if( !isset($_POST['fvp_video']) && isset( $meta ) )
|
146 |
+
$video = $meta['full'];
|
147 |
+
else
|
148 |
+
$video = trim($_POST['fvp_video']);
|
149 |
}
|
|
|
150 |
|
151 |
+
// something changed
|
152 |
+
if( ( empty($video) ) || // no video or
|
153 |
+
( isset($meta) && ($video != $meta['full'])) ) // different video?
|
154 |
+
{
|
155 |
+
|
156 |
+
if(!empty($meta)) { // different video!
|
157 |
+
|
158 |
+
// the current featured image is part of fvp
|
159 |
+
$tmp = get_post_meta( get_post_thumbnail_id($post_id), '_fvp_image', true);
|
160 |
+
if( !empty( $tmp ) ) {
|
161 |
+
|
162 |
+
// are there other posts with the same featured image?
|
163 |
+
$tmp2 = $this->get_post_by_custom_meta( '_thumbnail_id', $meta['img'], $post_id );
|
164 |
+
if( !empty( $tmp2 ) ) { // there aren't, so delete it
|
165 |
+
$img = $this->get_post_by_custom_meta('_fvp_image', $meta['prov'] . '?' . $meta['id'] );
|
166 |
+
wp_delete_attachment( $img );
|
167 |
+
delete_post_meta( $img, '_fvp_image', $meta['prov'] . '?' . $meta['id'] );
|
168 |
+
}
|
169 |
+
|
170 |
+
delete_post_meta( $post_id, '_thumbnail_id' );
|
171 |
+
}
|
172 |
+
|
173 |
+
delete_post_meta( $post_id, '_fvp_video' );
|
174 |
+
}
|
175 |
+
|
176 |
+
}
|
177 |
+
|
178 |
+
if( empty($video) )
|
179 |
+
return;
|
180 |
+
|
181 |
+
if( ($video == $meta['full']) && !$set_featimg )
|
182 |
return;
|
183 |
+
|
184 |
/*
|
185 |
REGEX tested using: http://www.rubular.com/
|
186 |
|
195 |
http://www.youtube.com/watch?v=G_Oj7UI0-pw
|
196 |
http://www.youtube.com/watch?feature=blub&v=G_Oj7UI0-pw
|
197 |
*/
|
198 |
+
|
199 |
$local = wp_upload_dir();
|
200 |
// match different provider(!)
|
201 |
+
preg_match('/(vimeo|youtu|dailymotion)/i', $video, $video_provider);
|
202 |
+
if(!isset($video_provider[1]))
|
203 |
+
return;
|
204 |
+
|
205 |
$video_prov = $video_provider[1] == "youtu" ? "youtube" : $video_provider[1];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
206 |
|
207 |
+
switch ($video_prov) {
|
208 |
+
/*case $local['baseurl'];
|
209 |
+
$video_id = $this->get_post_by_url($video);
|
210 |
+
$video_prov = 'local';
|
211 |
+
//'.preg_quote($local['baseurl'], '/').'
|
212 |
+
break;
|
213 |
+
*/
|
214 |
+
|
215 |
+
case 'youtube':
|
216 |
+
//match provider watch feature id(!) attr(!)
|
217 |
+
preg_match('/youtu(?:be\.com|\.be)\/(?:watch)?(?:\?feature=[^\?&]*)*(?:[\?&]v=)?([^\?&\s]+)(?:(?:[&\?]t=)(\d+m\d+s))?/', $video, $video_data);
|
218 |
+
$video_id = $video_data[1];
|
219 |
+
if( isset($video_data[2] ) )
|
220 |
+
$video_attr = $video_data[2];
|
221 |
+
|
222 |
+
// title, allow_embed 0/1, keywords, author, iurlmaxres, thumbnail_url, timestamp, avg_rating
|
223 |
+
$tmp = download_url( 'http://youtube.com/get_video_info?video_id=' . $video_id );
|
224 |
+
$data = file_get_contents($tmp);
|
225 |
+
parse_str($data, $data);
|
226 |
+
@unlink( $tmp );
|
227 |
+
|
228 |
+
// generate video metadata
|
229 |
+
$video_info = array(
|
230 |
+
'title' => $data['title'],
|
231 |
+
'description' => $data['keywords'],
|
232 |
+
'filename' => sanitize_file_name($data['title']),
|
233 |
+
'timestamp' => $data['timestamp'],
|
234 |
+
'author' => $data['author'],
|
235 |
+
'tags' => $data['keywords'],
|
236 |
+
'img' => ( isset($data['']) && !empty($data['iurlmaxres']) ) ? $data['iurlmaxres'] : 'http://img.youtube.com/vi/' . $video_id . '/0.jpg'
|
237 |
+
);
|
238 |
+
break;
|
239 |
+
|
240 |
+
case 'vimeo': // http://developer.vimeo.com/apis/simple
|
241 |
+
preg_match('/vimeo.com\/([^#]+)/', $video, $video_data);
|
242 |
+
$video_id = $video_data[1];
|
243 |
+
|
244 |
+
// title, description, upload_date, thumbnail_large, user_name, tags
|
245 |
+
$url = 'http://vimeo.com/api/v2/video/' . $video_id . '.php';
|
246 |
+
|
247 |
+
if( ini_get('allow_url_fopen') )
|
248 |
+
$data = unserialize(file_get_contents( $url ));
|
249 |
+
if( !isset( $data ) || empty( $data ) ) {
|
250 |
+
$tmp = download_url( $url );
|
251 |
+
$data = unserialize(file_get_contents($tmp));
|
252 |
+
@unlink( $tmp );
|
253 |
+
}
|
254 |
+
|
255 |
+
// generate video metadata
|
256 |
+
$video_info = array(
|
257 |
+
'title' => $data[0]['title'],
|
258 |
+
'description' => $data[0]['description'],
|
259 |
+
'filename' => sanitize_file_name( $data[0]['title'] ),
|
260 |
+
'timestamp' => strtotime( $data[0]['upload_date'] ),
|
261 |
+
'author' => $data[0]['user_name'],
|
262 |
+
'tags' => $data[0]['tags'],
|
263 |
+
'img' => $data[0]['thumbnail_large'],
|
264 |
+
'url' => $data[0]['url']
|
265 |
+
);
|
266 |
+
break;
|
267 |
+
|
268 |
+
case 'dailymotion': // http://www.dailymotion.com/doc/api/obj-video.html
|
269 |
+
preg_match('/dailymotion.com\/video\/([^_]+)/', $video, $video_data);
|
270 |
+
$video_id = $video_data[1];
|
271 |
+
|
272 |
+
// http://codex.wordpress.org/HTTP_API
|
273 |
+
//thumbnail_url,aspect_ratio,description,created_time,embed_url,owner (owner.screenname),tags,title,url
|
274 |
+
$url = 'https://api.dailymotion.com/video/'.$video_id.'?fields=title,description,created_time,owner.screenname,tags,thumbnail_url,thumbnail_large_url,url,aspect_ratio';
|
275 |
+
$request = new WP_Http;
|
276 |
+
$result = $request->request( $url, array( 'method' => 'GET', 'sslverify' => false) );
|
277 |
+
$data = json_decode($result['body'], true);
|
278 |
+
|
279 |
+
// generate video metadata
|
280 |
+
$video_info = array(
|
281 |
+
'title' => $data['title'],
|
282 |
+
'description' => $data['description'],
|
283 |
+
'filename' => sanitize_file_name($data['title']),
|
284 |
+
'timestamp' => $data['created_time'],
|
285 |
+
'author' => $data['owner.screenname'],
|
286 |
+
'tags' => $data['tags'],
|
287 |
+
'img' => ( isset($data['thumbnail_url']) && !empty($data['thumbnail_url']) ) ? $data['thumbnail_url'] : $data['thumbnail_large_url'],
|
288 |
+
'url' => $data['url']
|
289 |
+
);
|
290 |
+
break;
|
291 |
}
|
292 |
+
|
293 |
// do we have a screen capture to pull?
|
294 |
if( !empty($video_info['img']) ) {
|
295 |
+
|
296 |
// is this screen capture already existing in our media library?
|
297 |
$video_img = $this->get_post_by_custom_meta('_fvp_image', $video_prov . '?' . $video_id);
|
298 |
if( !isset($video_img) ) {
|
299 |
+
|
300 |
// generate attachment post metadata
|
301 |
$video_img_data = array(
|
302 |
'post_content' => $video_info['description'],
|
303 |
'post_title' => $video_info['title'],
|
304 |
'post_name' => $video_info['filename']
|
305 |
);
|
306 |
+
|
307 |
// pull external img to local server and add to media library
|
308 |
require_once( plugin_dir_path(__FILE__) . 'somatic_attach_external_image.php' );
|
309 |
$video_img = somatic_attach_external_image($video_info['img'], $post_id, false, $video_info['filename'], $video_img_data);
|
310 |
+
|
311 |
// generate picture metadata
|
312 |
$video_img_meta = wp_get_attachment_metadata( $video_img );
|
313 |
$video_img_meta['image_meta'] = array(
|
322 |
'shutter_speed' => 0,
|
323 |
'title' => $video_info['title']
|
324 |
);
|
325 |
+
|
326 |
// save picture metadata
|
327 |
wp_update_attachment_metadata($video_img, $video_img_meta);
|
328 |
+
update_post_meta( $video_img, '_fvp_image', $video_prov . '?' . $video_id );
|
329 |
}
|
330 |
+
|
331 |
+
if( (get_bloginfo('version') >= 3.1) && // set_post_thumbnail was added in 3.1
|
332 |
+
( (!has_post_thumbnail( $post_id )) ||
|
333 |
+
($set_featimg) ) )
|
334 |
+
set_post_thumbnail( $post_id, $video_img );
|
335 |
+
|
336 |
}
|
337 |
+
|
338 |
$meta = array(
|
339 |
+
'full' => ( isset($data['url']) && !empty($data['url']) ) ? $data['url'] : $video,
|
340 |
'id' => $video_id,
|
341 |
'img' => $video_img,
|
342 |
'prov' => $video_prov,
|
343 |
+
'attr' => isset($video_attr) ? $video_attr : '',
|
344 |
+
'warn_featimg' => true
|
345 |
);
|
346 |
update_post_meta( $post_id, '_fvp_video', serialize($meta) );
|
347 |
+
|
348 |
return;
|
349 |
}
|
350 |
+
|
351 |
/**
|
352 |
* Initialises the plugin settings section, the settings fields and registers the options field and save function.
|
353 |
+
*
|
354 |
* @see http://codex.wordpress.org/Settings_API
|
355 |
* @since 1.0
|
356 |
*/
|
357 |
function settings_init() {
|
358 |
add_settings_section('fvp-settings-section', 'Featured Video', array( &$this, 'settings_content' ), 'media');
|
359 |
+
|
360 |
add_settings_field('fvp-settings-overwrite', 'Replace featured images', array( &$this, 'settings_overwrite' ), 'media', 'fvp-settings-section');
|
361 |
add_settings_field('fvp-settings-width', 'Video width', array( &$this, 'settings_width' ), 'media', 'fvp-settings-section');
|
362 |
add_settings_field('fvp-settings-height', 'Video height', array( &$this, 'settings_height' ), 'media', 'fvp-settings-section');
|
363 |
add_settings_field('fvp-settings-vimeo', 'Vimeo Player Design', array( &$this, 'settings_vimeo' ), 'media', 'fvp-settings-section');
|
364 |
add_settings_field('fvp-settings-rate', 'Support', array( &$this, 'settings_rate' ), 'media', 'fvp-settings-section');
|
365 |
+
|
366 |
register_setting('media', 'fvp-settings', array( &$this, 'settings_save' ));
|
367 |
}
|
368 |
+
|
369 |
/**
|
370 |
* The settings section content. Describes the plugin settings, the php functions and the WordPress shortcode.
|
371 |
*
|
372 |
* @since 1.0
|
373 |
*/
|
374 |
function settings_content() { ?>
|
375 |
+
|
376 |
<p>To display your featured videos you can either make use of the automatical replacement, use the <code>[featured-video]</code>-shortcode or manually edit your theme's source files to make use of the plugins PHP-functions.</p>
|
377 |
<table>
|
378 |
<tr style="vertical-align: top;">
|
379 |
<td style="width: 50%;">
|
380 |
<h4 style="margin-top: 0">WordPress Shortcode Usage</h4>
|
381 |
<table>
|
382 |
+
<tr style="vertical-align: top;">
|
383 |
<td><code>[featured-video]</code></td>
|
384 |
<td>Displays the video in its default size, if <code>width</code> below is set to <code>auto</code> 100%, elsewise 560px.</td>
|
385 |
</tr>
|
394 |
<ul>
|
395 |
<li><code>the_post_video(array(width, height), allow_fullscreen = true)</code></li>
|
396 |
<li><code>has_post_video(post_id = null)</code></li>
|
397 |
+
<li><code>get_the_post_video(post_id = null, array(width, height), allow_fullscreen = true)</code></li>
|
398 |
</ul>
|
399 |
<p class="description">
|
400 |
All parameters are optional. If <code>post_id == null</code> the current post's id will be used.
|
405 |
</table>
|
406 |
|
407 |
<?php }
|
408 |
+
|
409 |
/**
|
410 |
* Displays the setting if the plugin should display the featured video in place of featured images.
|
411 |
*
|
413 |
*/
|
414 |
function settings_overwrite() {
|
415 |
$options = get_option( 'fvp-settings' ); ?>
|
416 |
+
|
417 |
<input type="radio" name="fvp-settings[overwrite]" id="fvp-settings-overwrite-1" value="true" <?php checked( true, $options['overwrite'], true ) ?>/><label for="fvp-settings-overwrite-1"> yes <span style="font-style: italic;">(default)</span></label>
|
418 |
<input type="radio" name="fvp-settings[overwrite]" id="fvp-settings-overwrite-2" value="false" <?php checked( false, $options['overwrite'], true ) ?>/><label for="fvp-settings-overwrite-2"> no</label>
|
419 |
<p class="description">If a featured video is available, it can be displayed in place of the featured image.<br />For some themes this could result in displaying errors. When using this, try different <code>width</code> and <code>height</code> settings.</p>
|
420 |
|
421 |
<?php }
|
422 |
+
|
423 |
/**
|
424 |
* Displays the setting if the plugin should fit the width of the videos automatically or use fixed widths.
|
425 |
*
|
433 |
<p class="description">Using <code>auto</code> the video's width will be adjusted to fit the parent element. Works best in combination with height setted to <code>auto</code> as well.</p>
|
434 |
|
435 |
<?php }
|
436 |
+
|
437 |
/**
|
438 |
* Displays the setting if the plugin should fit the height of the videos automatically to their width/height ratio or use fixed heights, which might result in black bars.
|
439 |
*
|
462 |
<div style="position: relative; bottom: .6em;">
|
463 |
<input type="checkbox" name="fvp-settings[vimeo][portrait]" id="fvp-settings-vimeo-1" value="display" <?php checked( 1, $options['vimeo']['portrait'], 1 ) ?>/><label for="fvp-settings-vimeo-1"> Portrait</label>
|
464 |
<input type="checkbox" name="fvp-settings[vimeo][title]" id="fvp-settings-vimeo-2" value="display" <?php checked( 1, $options['vimeo']['title'], 1 ) ?>/><label for="fvp-settings-vimeo-2"> Title</label>
|
465 |
+
<input type="checkbox" name="fvp-settings[vimeo][byline]" id="fvp-settings-vimeo-3" value="display" <?php checked( 1, $options['vimeo']['byline'], 1 ) ?>/><label for="fvp-settings-vimeo-3"> Byline</label>
|
466 |
<span class="color-picker" style="position: relative;<?php if( wp_style_is( 'wp-color-picker', 'done' ) ) echo ' top: .6em;'; ?>" >
|
467 |
<input type="text" name="fvp-settings[vimeo][color]" id="fvp-settings-vimeo-color" value="#<?php echo isset($options['vimeo']['color']) ? $options['vimeo']['color'] : '00adef'; ?>" data-default-color="#00adef" />
|
468 |
<label for="fvp-settings-vimeo-color" style="display: none;"> Color</label>
|
469 |
+
<?php if( !wp_style_is('wp-color-picker', 'registered' ) ) { ?><div style="position: absolute; bottom: 0; right: -197px; background-color: #fff; z-index: 100; border: 1px solid #ccc;" id="fvp-settings-vimeo-colorpicker"></div><?php } ?>
|
470 |
</span>
|
471 |
</div>
|
472 |
<p class="description">These settings could be overwritten by videos from Vimeo Plus members.</p>
|
473 |
|
474 |
<?php }
|
475 |
+
|
476 |
/**
|
477 |
* Displays info about rating the plugin, giving feedback and requesting new features
|
478 |
*
|
479 |
* @since 1.0
|
480 |
*/
|
481 |
function settings_rate() { ?>
|
482 |
+
|
483 |
<p>
|
484 |
Found a bug or <span style="font-weight: bold;">missing a specific video service</span>? <a href="http://wordpress.org/extend/plugins/featured-video/" title="Featured Video Plus Support Forum on wordpress.org" style="font-weight: bold;">Leave a note</a> in the plugins support forum!<br />
|
485 |
No? Than please <a href="http://wordpress.org/extend/plugins/featured-video/" title="Featured Video Plus on wordpress.org" style="font-weight: bold;">rate it</a>.<br />
|
486 |
</p>
|
487 |
|
488 |
<?php }
|
489 |
+
|
490 |
/**
|
491 |
* Function through which all settings are passed before they are saved. Validate the data.
|
492 |
*
|
494 |
*/
|
495 |
function settings_save($input) {
|
496 |
$input['overwrite'] = $input['overwrite'] == 'true' ? true : false;
|
497 |
+
|
498 |
+
$input['vimeo']['portrait'] = isset($input['vimeo']['portrait'])&& ( $input['vimeo']['portrait'] == 'display' ) ? 1 : 0;
|
499 |
+
$input['vimeo']['title'] = isset($input['vimeo']['title']) && ( $input['vimeo']['title'] == 'display' ) ? 1 : 0;
|
500 |
+
$input['vimeo']['byline'] = isset($input['vimeo']['byline']) && ( $input['vimeo']['byline'] == 'display' ) ? 1 : 0;
|
501 |
+
|
502 |
+
if( isset($input['vimeo']['color']) ) {
|
503 |
+
preg_match('/#?([0123456789abcdef]{3}[0123456789abcdef]{0,3})/i', $input['vimeo']['color'], $color);
|
504 |
+
$input['vimeo']['color'] = $color[1];
|
505 |
+
} else
|
506 |
+
$input['vimeo']['color'] = '00adef';
|
507 |
+
|
508 |
return $input;
|
509 |
}
|
510 |
+
|
511 |
+
/**
|
512 |
+
* Notification shown when plugin is newly activated. Automatically hidden after 5x displayed.
|
513 |
+
*
|
514 |
+
* @see http://wptheming.com/2011/08/admin-notices-in-wordpress/
|
515 |
+
* @since 1.0
|
516 |
+
*/
|
517 |
+
public function activation_notification() {
|
518 |
+
if ( current_user_can( 'manage_options' ) ) {
|
519 |
+
global $current_user;
|
520 |
+
|
521 |
+
$count = get_user_meta($current_user->ID, 'fvp_activation_notification_ignore', true);
|
522 |
+
if( empty($count) || ($count <= 5) ) {
|
523 |
+
$part = empty($count) ? 'There is a new box on post & page edit screens for you to add video URLs.' : '';
|
524 |
+
echo "\n" . '<div class="updated" id="fvp_activation_notification"><p>';
|
525 |
+
printf(__('Featured Video Plus is ready to use. %1$s<span style="font-weight: bold;">Take a look at your new <a href="%2$s" title="Media Settings">Media Settings</a></span> | <a href="%3$s">hide this notice</a>'), $part . ' ', get_admin_url(null, '/options-media.php?fvp_activation_notification_ignore=0'), '?fvp_activation_notification_ignore=0');
|
526 |
+
echo "</p></div>\n";
|
527 |
+
|
528 |
+
$count = empty($count) ? 1 : $count+1;
|
529 |
+
update_user_meta($current_user->ID, 'fvp_activation_notification_ignore', $count);
|
530 |
+
}
|
531 |
+
}
|
532 |
+
}
|
533 |
+
|
534 |
+
/**
|
535 |
+
* Function fired when notification should be hidden manually. Hides it for the current user forever.
|
536 |
+
*
|
537 |
+
* @see http://wptheming.com/2011/08/admin-notices-in-wordpress/
|
538 |
+
* @see function activation_notification
|
539 |
+
* @since 1.0
|
540 |
+
*/
|
541 |
+
public function ignore_activation_notification() {
|
542 |
+
global $current_user;
|
543 |
+
|
544 |
+
// If user clicks to ignore the notice, add that to their user meta
|
545 |
+
if ( isset($_GET['fvp_activation_notification_ignore']) && '0' == $_GET['fvp_activation_notification_ignore'] )
|
546 |
+
update_user_meta($current_user->ID, 'fvp_activation_notification_ignore', 999);
|
547 |
+
}
|
548 |
+
|
549 |
/**
|
550 |
* Gets a post by an meta_key meta_value pair. Returns it's post_id.
|
551 |
*
|
552 |
* @see http://codex.wordpress.org/Class_Reference/wpdb
|
553 |
+
* @see http://dev.mysql.com/doc/refman/5.0/en/regexp.html#operator_regexp
|
554 |
* @since 1.0
|
555 |
*
|
556 |
* @param string $meta_key which meta_key to look for
|
557 |
* @param string $meta_value which meta_value to look for
|
558 |
*/
|
559 |
+
function get_post_by_custom_meta($meta_key, $meta_value, $notThisId = 0) {
|
560 |
global $wpdb;
|
561 |
+
if( $notThisId > 0 )
|
562 |
+
$prepared = $wpdb->prepare(
|
563 |
+
"SELECT post_id FROM {$wpdb->postmeta} WHERE meta_key=%s AND meta_value=%s AND post_id!=%d;",
|
564 |
+
$meta_key, $meta_value, $notThisId
|
565 |
+
);
|
566 |
+
else
|
567 |
+
$prepared = $wpdb->prepare(
|
568 |
+
"SELECT post_id FROM {$wpdb->postmeta} WHERE meta_key=%s AND meta_value=%s;",
|
569 |
+
$meta_key, $meta_value
|
570 |
+
);
|
571 |
+
|
572 |
+
$id = $wpdb->get_var( $prepared );
|
573 |
+
//echo $ids;
|
574 |
return $id;
|
575 |
}
|
576 |
+
|
577 |
/**
|
578 |
* Gets post id by it's url / guid.
|
579 |
*
|
592 |
);
|
593 |
return $id;
|
594 |
}
|
595 |
+
|
596 |
}
|
597 |
?>
|
php/general.php
CHANGED
@@ -9,76 +9,85 @@
|
|
9 |
* @see featured_video_plus_frontend in frontend.php
|
10 |
* @since 1.0
|
11 |
*/
|
12 |
-
class featured_video_plus {
|
13 |
|
14 |
/**
|
15 |
* Returns the featured video html, ready to echo.
|
16 |
-
*
|
17 |
* @param int $post_id
|
18 |
* @param string|array $size
|
19 |
* @param bool $allowfullscreen
|
20 |
* @param bool $container
|
21 |
*/
|
22 |
public function get_the_post_video($post_id = null, $size = array( 560, 315 ), $allowfullscreen = true, $container = true) {
|
23 |
-
|
24 |
if($post_id == null)
|
25 |
$post_id = $GLOBALS['post']->ID;
|
26 |
-
|
27 |
if( !$this->has_post_video($post_id) )
|
28 |
return false;
|
29 |
-
|
30 |
$meta = unserialize( get_post_meta($post_id, '_fvp_video', true) );
|
31 |
$options = get_option( 'fvp-settings' );
|
32 |
-
|
33 |
$width = $size[0];
|
34 |
$height = ($options['height'] == 'auto') ? round($width / 16 * 9) : $size[1];
|
35 |
-
|
36 |
if( isset($meta['id']) && !empty($meta['id']) ) {
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
55 |
}
|
56 |
-
|
57 |
if($container)
|
58 |
$embed = '<div class="featured_video_plus">' . $embed . '</div>';
|
59 |
-
|
60 |
return $embed;
|
61 |
}
|
62 |
-
|
63 |
}
|
64 |
-
|
65 |
/**
|
66 |
* Checks if current post or post provided by parameter has a featured video.
|
67 |
*
|
68 |
* @param int $post_id id of post to check for featured video
|
69 |
*/
|
70 |
public function has_post_video($post_id = null){
|
71 |
-
|
72 |
if($post_id == null)
|
73 |
$post_id = $GLOBALS['post']->ID;
|
74 |
|
75 |
$meta = unserialize( get_post_meta( $post_id, '_fvp_video', true ) );
|
76 |
-
|
77 |
if( !isset($meta) || empty($meta['id']) )
|
78 |
return false;
|
79 |
-
|
80 |
return true;
|
81 |
-
|
82 |
}
|
83 |
|
84 |
/**
|
@@ -87,13 +96,13 @@ class featured_video_plus {
|
|
87 |
* @param array $atts can contain the width and/or height how the featured video should be displayed in px, optional
|
88 |
*/
|
89 |
function shortcode($atts){
|
90 |
-
|
91 |
$w = isset($atts['width']) ? $atts['width'] : '560';
|
92 |
$h = isset($atts['height']) ? $atts['height'] : '315';
|
93 |
-
|
94 |
if($this->has_post_video())
|
95 |
echo $this->get_the_post_video(null, $w, $h, true, false);
|
96 |
-
|
97 |
}
|
98 |
}
|
99 |
?>
|
9 |
* @see featured_video_plus_frontend in frontend.php
|
10 |
* @since 1.0
|
11 |
*/
|
12 |
+
class featured_video_plus {
|
13 |
|
14 |
/**
|
15 |
* Returns the featured video html, ready to echo.
|
16 |
+
*
|
17 |
* @param int $post_id
|
18 |
* @param string|array $size
|
19 |
* @param bool $allowfullscreen
|
20 |
* @param bool $container
|
21 |
*/
|
22 |
public function get_the_post_video($post_id = null, $size = array( 560, 315 ), $allowfullscreen = true, $container = true) {
|
23 |
+
|
24 |
if($post_id == null)
|
25 |
$post_id = $GLOBALS['post']->ID;
|
26 |
+
|
27 |
if( !$this->has_post_video($post_id) )
|
28 |
return false;
|
29 |
+
|
30 |
$meta = unserialize( get_post_meta($post_id, '_fvp_video', true) );
|
31 |
$options = get_option( 'fvp-settings' );
|
32 |
+
|
33 |
$width = $size[0];
|
34 |
$height = ($options['height'] == 'auto') ? round($width / 16 * 9) : $size[1];
|
35 |
+
|
36 |
if( isset($meta['id']) && !empty($meta['id']) ) {
|
37 |
+
switch( $meta['prov'] ) {
|
38 |
+
|
39 |
+
/*case 'local':
|
40 |
+
$ext = pathinfo($meta['full'], PATHINFO_EXTENSION);
|
41 |
+
//$embed = '<object width="' . $width . '" height="' . $height . '"><param name="movie" value="' . $meta['full'] . '" /> <embed type="video/flash" width=' . $width . ' height="' . $height . '" src="' . $meta['full'] . '"></embed></object>';
|
42 |
+
//$embed = '<video width="' . $width . '" height="' . $height . '" controls><source src="' . $meta['full'] . '" type="video/' . $ext . '">Your browser does not support the video tag.</video>' . "\n";
|
43 |
+
$embed = '<video src="' . $meta['full'] . '" controls="controls" width="' . $width . '" height="' . $height . '"></video>';
|
44 |
+
break;
|
45 |
+
*/
|
46 |
+
|
47 |
+
case 'vimeo':
|
48 |
+
$options = get_option( 'fvp-settings' );
|
49 |
+
$fs = $allowfullscreen ? ' webkitAllowFullScreen mozallowfullscreen allowFullScreen' : '';
|
50 |
+
$embed = "\n" . '<iframe src="http://player.vimeo.com/video/'.$meta['id'].'?badge=0&portrait='.$options['vimeo']['portrait'].'&title='.$options['vimeo']['title'].'&byline='.$options['vimeo']['byline'].'&color='.$options['vimeo']['color'].'" width="'.$width.'" height="'.$height.'" frameborder="0"'.$fs.'></iframe>' . "\n";
|
51 |
+
break;
|
52 |
+
|
53 |
+
case 'youtube':
|
54 |
+
$fs = $allowfullscreen ? 'allowfullscreen' : '';
|
55 |
+
$attr = '#t=' . $meta['attr'];
|
56 |
+
$embed = "\n" . '<iframe width="'.$width.'" height="'.$height.'" src="http://www.youtube.com/embed/'.$meta['id'].'?rel=0'.$attr.'" frameborder="0" ' . $fs . '></iframe>' . "\n";
|
57 |
+
break;
|
58 |
+
|
59 |
+
case 'dailymotion':
|
60 |
+
|
61 |
+
$embed = "\n" . '<iframe src="http://www.dailymotion.com/embed/video/'.$meta['id'].'?logo=1&info='.$options['vimeo']['title'].'" width="'.$width.'" height="'.$height.'" frameborder="0"></iframe>' . "\n";
|
62 |
+
|
63 |
+
break;
|
64 |
}
|
65 |
+
|
66 |
if($container)
|
67 |
$embed = '<div class="featured_video_plus">' . $embed . '</div>';
|
68 |
+
|
69 |
return $embed;
|
70 |
}
|
71 |
+
|
72 |
}
|
73 |
+
|
74 |
/**
|
75 |
* Checks if current post or post provided by parameter has a featured video.
|
76 |
*
|
77 |
* @param int $post_id id of post to check for featured video
|
78 |
*/
|
79 |
public function has_post_video($post_id = null){
|
80 |
+
|
81 |
if($post_id == null)
|
82 |
$post_id = $GLOBALS['post']->ID;
|
83 |
|
84 |
$meta = unserialize( get_post_meta( $post_id, '_fvp_video', true ) );
|
85 |
+
|
86 |
if( !isset($meta) || empty($meta['id']) )
|
87 |
return false;
|
88 |
+
|
89 |
return true;
|
90 |
+
|
91 |
}
|
92 |
|
93 |
/**
|
96 |
* @param array $atts can contain the width and/or height how the featured video should be displayed in px, optional
|
97 |
*/
|
98 |
function shortcode($atts){
|
99 |
+
|
100 |
$w = isset($atts['width']) ? $atts['width'] : '560';
|
101 |
$h = isset($atts['height']) ? $atts['height'] : '315';
|
102 |
+
|
103 |
if($this->has_post_video())
|
104 |
echo $this->get_the_post_video(null, $w, $h, true, false);
|
105 |
+
|
106 |
}
|
107 |
}
|
108 |
?>
|
php/setup.php
CHANGED
@@ -8,45 +8,46 @@
|
|
8 |
* @since 1.0
|
9 |
*/
|
10 |
class featured_video_plus_setup {
|
11 |
-
|
12 |
/**
|
13 |
* Just checks if the class was called directly, if yes: dies.
|
14 |
-
*
|
|
|
|
|
15 |
* @param $case = false test parameter
|
16 |
*/
|
17 |
function __construct( $case = false ) {
|
18 |
-
|
19 |
-
|
20 |
}
|
21 |
-
|
22 |
-
/**
|
23 |
* Runs on activation, writes default settings to database.
|
|
|
|
|
24 |
*/
|
25 |
-
function on_activate() {
|
26 |
-
$options =
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
'
|
32 |
-
'
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
|
|
|
|
|
|
38 |
}
|
39 |
-
|
40 |
-
|
41 |
-
/* *
|
42 |
-
* Runs on deactivation. Nothing to see here.
|
43 |
-
*
|
44 |
-
function on_deactivate() {
|
45 |
-
|
46 |
-
}*/
|
47 |
|
48 |
-
/**
|
49 |
* Runs on uninstallation, deletes all data including post&user metadata and video screen captures.
|
|
|
|
|
50 |
*/
|
51 |
function on_uninstall() {
|
52 |
// important: check if the file is the one that was registered with the uninstall hook (function)
|
@@ -54,26 +55,25 @@ class featured_video_plus_setup {
|
|
54 |
// return;
|
55 |
|
56 |
delete_option( 'fvp-settings' );
|
57 |
-
|
58 |
$post_types = get_post_types( array("public" => true) );
|
59 |
foreach( $post_types as $post_type ) {
|
60 |
if( $post_type != 'attachment' ) {
|
61 |
$allposts = get_posts('numberposts=-1&post_type=' . $post_type . '&post_status=any');
|
62 |
foreach( $allposts as $post ) {
|
63 |
$meta = unserialize(get_post_meta( $post->ID, '_fvp_video', true ));
|
64 |
-
|
65 |
wp_delete_attachment( $meta['img'] );
|
66 |
delete_post_meta($post->ID, '_fvp_video');
|
67 |
}
|
68 |
}
|
69 |
}
|
70 |
-
|
71 |
$users = array_merge( get_users( array( 'role' => 'Administrator' ) ), get_users( array( 'role' => 'Super Admin' ) ) );
|
72 |
foreach( $users as $user ) {
|
73 |
delete_user_meta( $user-ID, 'fvp_activation_notification_ignore' );
|
74 |
}
|
75 |
-
|
76 |
}
|
77 |
-
|
78 |
}
|
79 |
?>
|
8 |
* @since 1.0
|
9 |
*/
|
10 |
class featured_video_plus_setup {
|
11 |
+
|
12 |
/**
|
13 |
* Just checks if the class was called directly, if yes: dies.
|
14 |
+
*
|
15 |
+
* @since 1.0
|
16 |
+
*
|
17 |
* @param $case = false test parameter
|
18 |
*/
|
19 |
function __construct( $case = false ) {
|
20 |
+
if ( ! $case )
|
21 |
+
wp_die( 'You should not call this class directly!', 'Doing it wrong!' );
|
22 |
}
|
23 |
+
|
24 |
+
/**
|
25 |
* Runs on activation, writes default settings to database.
|
26 |
+
*
|
27 |
+
* @since 1.0
|
28 |
*/
|
29 |
+
public function on_activate() {
|
30 |
+
$options = get_option( 'fvp-settings' );
|
31 |
+
if( empty($options) ) {
|
32 |
+
$options = array(
|
33 |
+
'overwrite' => true,
|
34 |
+
'width' => 'auto',
|
35 |
+
'height' => 'auto',
|
36 |
+
'vimeo' => array(
|
37 |
+
'portrait' => 0,
|
38 |
+
'title' => 1,
|
39 |
+
'byline' => 1,
|
40 |
+
'color' => '00adef'
|
41 |
+
)
|
42 |
+
);
|
43 |
+
}
|
44 |
+
update_option( 'fvp-settings', $options );
|
45 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
46 |
|
47 |
+
/**
|
48 |
* Runs on uninstallation, deletes all data including post&user metadata and video screen captures.
|
49 |
+
*
|
50 |
+
* @since 1.0
|
51 |
*/
|
52 |
function on_uninstall() {
|
53 |
// important: check if the file is the one that was registered with the uninstall hook (function)
|
55 |
// return;
|
56 |
|
57 |
delete_option( 'fvp-settings' );
|
58 |
+
|
59 |
$post_types = get_post_types( array("public" => true) );
|
60 |
foreach( $post_types as $post_type ) {
|
61 |
if( $post_type != 'attachment' ) {
|
62 |
$allposts = get_posts('numberposts=-1&post_type=' . $post_type . '&post_status=any');
|
63 |
foreach( $allposts as $post ) {
|
64 |
$meta = unserialize(get_post_meta( $post->ID, '_fvp_video', true ));
|
65 |
+
|
66 |
wp_delete_attachment( $meta['img'] );
|
67 |
delete_post_meta($post->ID, '_fvp_video');
|
68 |
}
|
69 |
}
|
70 |
}
|
71 |
+
|
72 |
$users = array_merge( get_users( array( 'role' => 'Administrator' ) ), get_users( array( 'role' => 'Super Admin' ) ) );
|
73 |
foreach( $users as $user ) {
|
74 |
delete_user_meta( $user-ID, 'fvp_activation_notification_ignore' );
|
75 |
}
|
|
|
76 |
}
|
77 |
+
|
78 |
}
|
79 |
?>
|
readme.txt
CHANGED
@@ -1,78 +1,87 @@
|
|
1 |
-
=== Featured Video Plus ===
|
2 |
-
Contributors: a.hoereth
|
3 |
-
Plugin Name: Featured Video Plus
|
4 |
-
Plugin URI: https://github.com/ahoereth/featured-video-plus
|
5 |
-
Tags: featured video, featured,
|
6 |
-
Author: Alexander Höreth
|
7 |
-
Author URI: http://ahoereth.yrnxt.com/
|
8 |
-
Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=a%2ehoereth%40gmail%2ecom
|
9 |
-
License: GPLv2 or later
|
10 |
-
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
11 |
-
Requires at least: 3.1
|
12 |
-
Tested up to: 3.5
|
13 |
-
Stable tag: 1.
|
14 |
-
|
15 |
-
Add Featured Videos to your posts and pages, just like you add Featured Images. Works with every theme which supports Featured Images.
|
16 |
-
|
17 |
-
|
18 |
-
== Description ==
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
The
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
=== Featured Video Plus ===
|
2 |
+
Contributors: a.hoereth
|
3 |
+
Plugin Name: Featured Video Plus
|
4 |
+
Plugin URI: https://github.com/ahoereth/featured-video-plus
|
5 |
+
Tags: featured video, featured image, featured, post video, post thumbnail, video, thumbnail, html5, flash, youtube, vimeo, dailymotion
|
6 |
+
Author: Alexander Höreth
|
7 |
+
Author URI: http://ahoereth.yrnxt.com/
|
8 |
+
Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=a%2ehoereth%40gmail%2ecom
|
9 |
+
License: GPLv2 or later
|
10 |
+
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
11 |
+
Requires at least: 3.1
|
12 |
+
Tested up to: 3.5
|
13 |
+
Stable tag: 1.1
|
14 |
+
|
15 |
+
Add Featured Videos to your posts and pages, just like you add Featured Images. Works with every theme which supports Featured Images.
|
16 |
+
|
17 |
+
|
18 |
+
== Description ==
|
19 |
+
|
20 |
+
*A picture is worth a thousand words? What about a video then? How much more is it worth?*
|
21 |
+
|
22 |
+
This plugin enables you to define Featured Videos for your posts and pages. When Featured Images are supported by your theme the Featured Videos will automatically be displayed inplace if available. The Featured Image will be used as fallback.
|
23 |
+
The Featured Videos can either be displayed inplace of Featured Images, can be added to the theme by editing the theme's source files or inserted in your posts manually using the shortcode.
|
24 |
+
|
25 |
+
The plugin will add an box to the admin interface's post and pages edit page where you can paste your videos URL. At the moment the plugin supports __YouTube__ (including [time-links](http://support.google.com/youtube/bin/answer.py?hl=en&answer=116618 "Link to a specific time in a video")), __Vimeo__ and __Dailymotion__.
|
26 |
+
If you are missing a certain video platform: Leave a message in the supports forum.
|
27 |
+
|
28 |
+
After activating the plugin you will get some additions to your media settings. There you can choose how the videos will be sized and get some other individualisation properties - have a look at the [screenshots](http://wordpress.org/extend/plugins/featured-video-plus/screenshots/). If the theme you are using does not work with any combination of the width and height settings please contact me and I will look into it.
|
29 |
+
|
30 |
+
__Shortcode:__
|
31 |
+
|
32 |
+
[featured-video-plus]
|
33 |
+
[featured-video-plus width=300]
|
34 |
+
|
35 |
+
|
36 |
+
__PHP functions:__
|
37 |
+
|
38 |
+
the_post_video(array(width, height), fullscreen = true)
|
39 |
+
has_post_video(post_id)
|
40 |
+
get_the_post_video(post_id, size(width, height), fullscreen = true)
|
41 |
+
|
42 |
+
All parameters are optional. If no post_id is given the current post's id will be used.
|
43 |
+
|
44 |
+
|
45 |
+
This plugin was created after using the original [Featured Video](http://wordpress.org/extend/plugins/featured-video/) plugin. Featured Video Plus is complete remake with more features and a more seemless integration into WordPress in mind.
|
46 |
+
|
47 |
+
== Installation ==
|
48 |
+
|
49 |
+
1. Visit your WordPress Administration interface and go to Plugins -> Add New
|
50 |
+
2. Search for "Featured Video Plus", and click "Install Now" below the plugins name
|
51 |
+
3. When the installation finished, click "Activate Plugin"
|
52 |
+
|
53 |
+
The plugin is ready to go. Now edit your posts and add video links to the "Featured Video" box on the right!
|
54 |
+
If you want to change some settings have a look under Settings -> Media.
|
55 |
+
|
56 |
+
|
57 |
+
== Changelog ==
|
58 |
+
|
59 |
+
= 1.1 =
|
60 |
+
* __Added Dailymotion__
|
61 |
+
* fixed youtube 'start at specific time' embeds
|
62 |
+
* overhaul of the interaction between Featured Videos and Featured Images
|
63 |
+
* existing featured images will no longer be replaced by newly added featured videos in the administration interface
|
64 |
+
|
65 |
+
|
66 |
+
= 1.0 =
|
67 |
+
* Release
|
68 |
+
|
69 |
+
|
70 |
+
== Screenshots ==
|
71 |
+
|
72 |
+
1. Featured Video and Featured Image boxes on the post edit screen.
|
73 |
+
2. A Featured Video in the Twenty Twelve theme.
|
74 |
+
3. Settings -> Media screen
|
75 |
+
|
76 |
+
|
77 |
+
== Frequently Asked Questions ==
|
78 |
+
|
79 |
+
= After adding the URL and saving the post I do not get any video? =
|
80 |
+
Maybe the plugin does not recognize the URL. Try the URL you get when clicking on share below a youtube video or the simple vimeo URL, which should look something like this: http://vimeo.com/32071937
|
81 |
+
If you want to you can post the URL which is not working in the support forums and the plugin might work with it in the next release.
|
82 |
+
|
83 |
+
= What about other video portals? =
|
84 |
+
Leave me a note in the support forums which you would like and I will consider adding them in the next release.
|
85 |
+
|
86 |
+
= Are there translations available? =
|
87 |
+
Not yet, but I will add translation capabilities soon. Interested in translating the plugin? Contact me!
|