PluginProbe
Video Dashboard / 1.2.0
Video Dashboard v1.2.0
trunk 1.0 1.1 1.1.1 1.2.0 1.2.1 1.2.1.1 2.0.0
video-dashboard / video-dashboard.php

video-dashboard.php in Video Dashboard 1.2.0, at video-dashboard.php

179 lines 5.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /*
3 Plugin Name: Video Dashboard
4 Plugin URI: http://brianjohnsondesign.com/wordpress-plugins/video-dashboard
5 Description: A plugin to display embeddable media into the WordPress dashboard
6 Version: 1.1
7 Author: Brian Johnson
8 Author URI: http://brianjohnsondesign.com
9 License: GPLv2 or later
10 */
11
12
13 /* Global Variables */
14
15 $vdb_prefix = 'vdb_';
16 $vdb_plugin_name = 'Video Dashboard';
17 $vdb_options = get_option('vdb_settings');
18
19 /*Includes*/
20
21 include('includes/admin-page.php');
22
23
24
25
26 add_action('wp_dashboard_setup', 'vdb_dashboard'); //Run plugin when dashboard is loaded
27 register_activation_hook(__FILE__, 'vdb_set_up_options'); //Run function to load default values
28
29 function vdb_set_up_options() //Function to load default values
30 {
31 add_option('vdb_settings', array(
32 'minimum_role' => 'administrator',
33 'youtube_number' => '10'
34 ));
35 }
36
37
38 function vdb_load_scripts($hook) //Register our stylesheet
39 {
40
41 if ($hook != 'index.php') //Only if it's in the admin area
42 return;
43
44 wp_register_style('vdb-style', plugins_url('includes/video-dashboard.css', __FILE__));
45 wp_enqueue_style('vdb-style');
46 }
47 add_action('admin_enqueue_scripts', 'vdb_load_scripts');
48
49
50
51 function vdb_dashboard() //Display Videos
52 {
53
54 $vdb_options = get_option('vdb_settings');
55
56 //Specify which roles have permissions, given the minimum value
57 if ($vdb_options['minimum_role'] == 'subscriber') {
58 $roles = array(
59 'subscriber',
60 'contributor',
61 'author',
62 'editor'
63 );
64 }
65 if ($vdb_options['minimum_role'] == 'contributor') {
66 $roles = array(
67 'contributor',
68 'author',
69 'editor'
70 );
71 }
72 if ($vdb_options['minimum_role'] == 'author') {
73 $roles = array(
74 'author',
75 'editor'
76 );
77 }
78 if ($vdb_options['minimum_role'] == 'editor') {
79 $roles = array(
80 'editor'
81 );
82 }
83 if ($vdb_options['minimum_role'] == 'administrator') {
84 $roles = array(
85 'administrator'
86 );
87 }
88
89 //Check role
90 $in_role = vdb_check_user_role($roles);
91
92 //Load dashboard widget if they are an acceptable role
93 if ($in_role) {
94 wp_add_dashboard_widget('vdb_youtube_videos', 'Videos', 'vdb_display_youtube'); //Add YouTube Videos
95 } else {
96 // User not in role, do nothing
97 }
98 }
99
100 //Function to check user role
101 function vdb_check_user_role($roles, $user_id = NULL)
102 {
103 if ($user_id)
104 $user = get_userdata($user_id);
105 else
106 $user = wp_get_current_user();
107
108 if (empty($user))
109 return FALSE;
110
111 if (!in_array('administrator', $roles)) //Add admins even if they aren't specified
112 $roles[] = 'administrator';
113
114 foreach ($user->roles as $role) {
115 if (in_array($role, $roles)) {
116 return TRUE;
117 }
118 }
119 return FALSE;
120 }
121
122
123
124 function vdb_display_youtube()
125 {
126
127 global $vdb_options;
128
129 echo '<div class="wrap"></div>';
130
131 for ($i = 1; $i <= $vdb_options['youtube_number']; $i++) { //Loop through the number of videos
132
133 if (array_key_exists('youtube_id' . $i, $vdb_options)) { //Make sure there is something entered in the field, otherwise do nothing with it
134 $youtube_location = $vdb_options['youtube_id' . $i];
135
136 if (!empty($youtube_location)) {
137 if (strpos($youtube_location, 'v=') !== false) { //If it's the full url
138 $url = $youtube_location;
139 parse_str(parse_url($youtube_location, PHP_URL_QUERY), $my_array_of_vars); //Strip the video ID from the URL
140 $video_id = $my_array_of_vars['v'];
141 } else {
142 $video_id = $youtube_location; //Otherwise it must be the video ID, just display that
143 }
144
145 if (strlen($video_id) != '11') {
146
147 //It doesn't appear to be valid YouTube, so let's check and see if it's Vimeo.
148 //Start VIMEO Section
149 preg_match('/vimeo\.com\/([0-9]{1,10})/', $youtube_location, $matches);
150 $vimeo_id = $matches[1];
151 if ($vimeo_id) {
152
153 ?>
154 <div class="video-container">
155 <iframe src="https://player.vimeo.com/video/<?php echo $vimeo_id; ?>" width="640" height="360" frameborder="0" style="width:100%;" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe></div>
156 <?php
157
158 }
159 //END Vimeo Section
160
161 else { //It's not Vimeo either, so display error
162 echo '<p>Error: Video #' . $i . " does not appear to be a valid YouTube or Vimeo URL.</p>";
163 }
164 } //Make sure it's a valid 11-character string
165 else {
166 ?>
167
168 <div class="video-container"><iframe src="//www.youtube.com/embed/<?php
169 echo $video_id;
170 ?>" frameborder="0" allowfullscreen></iframe></div>
171
172 <?php
173 } //end else
174 } //End if !empty($youtube_location)
175 }
176 ;
177 } //End the Loop
178 }
179