Changeset 786864
- Timestamp:
- 10/12/2013 10:26:10 AM (12 years ago)
- Location:
- youtube-comments/trunk
- Files:
-
- 7 edited
-
class-admin.php (modified) (4 diffs)
-
class-comments.php (modified) (10 diffs)
-
readme.txt (modified) (3 diffs)
-
template-comments.php (modified) (1 diff)
-
template-container.php (modified) (1 diff)
-
uninstall.php (modified) (1 diff)
-
youtube-comments.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
youtube-comments/trunk/class-admin.php
r759170 r786864 52 52 public function settings_help() { 53 53 $screen = get_current_screen(); 54 if ($screen->id != $this->settings_page) 54 if ($screen->id != $this->settings_page) { 55 55 return; 56 } 56 57 $screen->add_help_tab(array( 57 58 'id' => 'ppf-overview', … … 75 76 */ 76 77 public function settings_template() { 77 if (!current_user_can('manage_options')) 78 if (!current_user_can('manage_options')) { 78 79 wp_die( __('You do not have sufficient permissions to access this page.') ); 79 else80 } else { 80 81 include('template-settings.php'); 82 } 81 83 } 82 84 … … 97 99 add_settings_field('yc_settings_max_results', 'Request Comments', array($this, 'settings_max_results'), 'yc_settings_page', 'yc_settings_common'); 98 100 add_settings_field('yc_settings_post_comments', 'Post Comments', array($this, 'settings_post_comments'), 'yc_settings_page', 'yc_settings_common'); 101 add_settings_field('yc_settings_custom_fields', 'Custom Fields', array($this, 'settings_custom_fields'), 'yc_settings_page', 'yc_settings_common'); 99 102 add_settings_field('yc_settings_client_id', 'Client ID', array($this, 'settings_client_id'), 'yc_settings_page', 'yc_settings_api'); 100 103 add_settings_field('yc_settings_client_secret', 'Client Secret', array($this, 'settings_client_secret'), 'yc_settings_page', 'yc_settings_api'); … … 133 136 echo "<p class='description'>Allow users to post comments on YouTube.</p>" . PHP_EOL; 134 137 } 138 139 /** 140 * Setting field for custom fields 141 */ 142 public function settings_custom_fields() { 143 $settings = get_option('yc_settings'); 144 $value = empty($settings['custom_fields']) ? '' : $settings['custom_fields']; 145 echo "<input type='text' name='yc_settings[custom_fields]' class='regular-text' value='" . $value . "' />" . PHP_EOL; 146 echo "<p class='description'>Enter the names of custom fields for videos.<br />Separate multiple names with commas.</p>" . PHP_EOL; 147 } 135 148 136 149 /** -
youtube-comments/trunk/class-comments.php
r759170 r786864 6 6 7 7 protected static $instance = null; 8 const PLUGIN_VERSION = '1. 1.0';8 const PLUGIN_VERSION = '1.2.0'; 9 9 private $client = null; 10 10 private $youtube = null; 11 private $has_video = false; 11 12 12 13 /** … … 36 37 add_action('wp_ajax_nopriv_post_logoff', array($this, 'ajax_post_logoff')); 37 38 add_shortcode('youtube-comments', array($this, 'handle_shortcode')); 39 // Avoid adding container twice 38 40 if (!empty($settings['show_all'])) { 39 41 add_filter('the_content', array($this, 'filter_content')); … … 59 61 */ 60 62 public function filter_content($content) { 61 if (is_single() || is_page()) { 62 if ($this->get_first_video($content)) 63 $content .= $this->add_container(); 63 if ($this->has_video) { 64 $content .= $this->add_container(); 64 65 } 65 66 return $content; … … 68 69 /** 69 70 * Handle shortcode 71 * 72 * @return string 70 73 */ 71 74 public function handle_shortcode() { 72 75 if (is_single() || is_page()) { 73 76 $settings = get_option('yc_settings'); 74 if ( empty($settings['show_all']))77 if ($this->has_video && empty($settings['show_all'])) { 75 78 return $this->add_container(); 76 else 77 return ''; // Hide shortcode 79 } else { 80 return ''; // Hide shortcode 81 } 78 82 } 79 83 } … … 100 104 global $post; 101 105 if (is_single() || is_page()) { 106 $video_id = $this->get_first_video($post->ID); 107 if (empty($video_id)) { 108 return; 109 } 110 $this->has_video = true; 102 111 $settings = get_option('yc_settings'); 103 112 $results = empty($settings['max_results']) ? '10' : $settings['max_results']; 104 113 wp_enqueue_style('youtube-comments', plugins_url('style.css', __FILE__), array(), self::PLUGIN_VERSION); 105 114 wp_enqueue_script('youtube-comments', plugins_url('script.js', __FILE__), array('jquery'), self::PLUGIN_VERSION, true); 106 $content = get_post_field('post_content', $post->ID);107 $video_id = $this->get_first_video($content);108 115 $vars = array( 109 116 'ajaxURL' => admin_url('admin-ajax.php'), … … 129 136 */ 130 137 public function ajax_post_comment() { 131 if (!wp_verify_nonce($_POST['nonce'], 'post-comment')) 138 if (!wp_verify_nonce($_POST['nonce'], 'post-comment')) { 132 139 die('Error: Security check failed'); 133 if (empty($_SESSION['access-token'])) 140 } 141 if (empty($_SESSION['access-token'])) { 134 142 die('Error: No access token'); 143 } 135 144 // Validate access token 136 145 $token = json_decode($_SESSION['access-token']); 137 if (!$this->validate_token($token->access_token)) 146 if (!$this->validate_token($token->access_token)) { 138 147 die('Error: Access token invalid'); 148 } 139 149 $this->client->setAccessToken($_SESSION['access-token']); 140 150 if ($this->client->isAccessTokenExpired()) { … … 172 182 */ 173 183 public function ajax_post_logoff() { 174 if (!wp_verify_nonce($_POST['nonce'], 'post-comment')) 184 if (!wp_verify_nonce($_POST['nonce'], 'post-comment')) { 175 185 die('Error: Security check failed'); 186 } 176 187 unset($_SESSION['access-token']); 177 188 $this->client->revokeToken(); … … 192 203 if (empty($values->error)) { 193 204 $settings = get_option('yc_settings'); 194 if (!empty($values->audience) && $values->audience == $settings['client_id']) 205 if (!empty($values->audience) && $values->audience == $settings['client_id']) { 195 206 return true; 207 } 196 208 } 197 209 } … … 200 212 201 213 /** 202 * Parse content to get first video 203 * 204 * @param string $content 205 * @return string 206 */ 207 public function get_first_video($content) { 208 global $post; 209 // Check for "Automatic YouTube Video Posts" plugin 210 $video_id = get_post_meta($post->ID, '_tern_wp_youtube_video', true); 211 if (!empty($video_id)) 214 * Search for first video ID 215 * 216 * @param integer $post_id 217 * @return string 218 */ 219 public function get_first_video($post_id) { 220 // Custom field for "Automatic YouTube Video Posts" plugin 221 if (function_exists('WP_ayvpp_init')) { 222 $video_id = get_post_meta($post_id, '_tern_wp_youtube_video', true); 223 if (!empty($video_id)) { 224 return $video_id; 225 } 226 } 227 // Custom field for "deTube" premium theme 228 $video_url = get_post_meta($post_id, 'dp_video_url', true); 229 if (!empty($video_url)) { 230 $video_id = $this->parse_youtube_url($video_url); 231 if (!empty($video_id)) { 232 return $video_id; 233 } 234 } 235 // Other custom fields 236 $settings = get_option('yc_settings'); 237 $fields = empty($settings['custom_fields']) ? '' : trim($settings['custom_fields']); 238 if (!empty($fields)) { 239 $fields = explode(',', $settings['custom_fields']); 240 foreach ($fields as $key) { 241 $key = trim($key); 242 $value = get_post_meta($post_id, $key, true); 243 $value = trim($value); 244 if (!empty($value)) { 245 // Custom field may contain URL or ID, so assume ID if not valid URL 246 $video_id = $this->parse_youtube_url($value); 247 if (!empty($video_id)) { 248 return $video_id; 249 } else { 250 return $value; 251 } 252 } 253 } 254 } 255 // Otherwise, search post content for URL 256 $content = get_post_field('post_content', $post_id); 257 $video_id = $this->parse_youtube_url($content); 258 if (!empty($video_id)) { 212 259 return $video_id; 213 // Otherwise, search content for link 260 } 261 return false; 262 } 263 264 /** 265 * Parse YouTube URL to get video ID 266 * 267 * @param string $url 268 * @return string 269 */ 270 public function parse_youtube_url($url) { 214 271 $pattern = '%(?:youtube(?:-nocookie)?\.com/(?:[^/]+/.+/|(?:v|e(?:mbed)?)/|.*[?&]v=)|youtu\.be/)([^"&?/ ]{11})%i'; 215 preg_match($pattern, $content, $match); 216 if (empty($match[1])) 217 return false; 218 else 272 preg_match($pattern, $url, $match); 273 if (!empty($match[1])) { 219 274 return $match[1]; 220 } 275 } 276 return false; 277 } 221 278 222 279 /** … … 284 341 function template_redirect() { 285 342 if (isset($_GET['state']) && isset($_GET['code'])) { 286 if (strval($_SESSION['state']) !== strval($_GET['state'])) 343 if (strval($_SESSION['state']) !== strval($_GET['state'])) { 287 344 die('The session state did not match.'); 345 } 288 346 $this->client->authenticate($_GET['code']); 289 347 $_SESSION['access-token'] = $this->client->getAccessToken(); 290 if (isset($_SESSION['redirect_url'])) 348 if (isset($_SESSION['redirect_url'])) { 291 349 wp_safe_redirect($_SESSION['redirect_url']); 350 } 292 351 } 293 352 } -
youtube-comments/trunk/readme.txt
r759170 r786864 4 4 Tags: YouTube, video, comments 5 5 Requires at least: 3.3 6 Tested up to: 3. 5.27 Stable tag: 1. 1.06 Tested up to: 3.6.1 7 Stable tag: 1.2.0 8 8 License: GPLv3 or later 9 9 License URI: http://www.gnu.org/licenses/gpl-3.0.html … … 48 48 The redirect URI must exactly match your site's URL. An extra trailing slash is enough to cause that error. 49 49 50 = 5. Can I use a custom field for videos? = 51 52 Yes, a setting is provided for custom fields. YouTube Comments supports the "Automatic YouTube Video Posts" plugin, and the "deTube" premium theme. 53 50 54 == Upgrade Notice == 51 55 52 No upgrade s available.56 No upgrade notices. 53 57 54 58 == Changelog == … … 61 65 * Fixed bug in comment display. 62 66 * Updated the readme. 67 68 = 1.2.0 = 69 * Added support for "deTube" premium theme. 70 * Added setting for URL custom fields. 71 * Updated the readme. -
youtube-comments/trunk/template-comments.php
r759170 r786864 49 49 if (strpos($atts->rel, 'in-reply-to')) { 50 50 $reply = @simplexml_load_file($atts->href); // suppress errors 51 if (isset($reply->author)) 51 if (isset($reply->author)) { 52 52 $reply_link = sprintf("<a href='%s' title=''>%s</a>", $reply->author->uri, $reply->author->name); 53 } 53 54 break; 54 55 } -
youtube-comments/trunk/template-container.php
r743953 r786864 4 4 */ 5 5 ?> 6 6 7 <div id='youtube-comments'> 7 8 <div class='comments-loading'><img src='<?php echo plugins_url('loading.gif', __FILE__); ?>' />Loading...</div> -
youtube-comments/trunk/uninstall.php
r743953 r786864 4 4 */ 5 5 6 if (!defined('WP_UNINSTALL_PLUGIN')) 7 exit(); 6 if (!defined('WP_UNINSTALL_PLUGIN')) { 7 exit; 8 } 8 9 9 10 delete_option('yc_settings'); -
youtube-comments/trunk/youtube-comments.php
r759170 r786864 4 4 Plugin Name: YouTube Comments 5 5 Description: This plugin finds YouTube links in post content and imports the video comments. 6 Version: 1. 1.06 Version: 1.2.0 7 7 Author: sydcode 8 8 Author URI: http://profiles.wordpress.org/sydcode
Note: See TracChangeset
for help on using the changeset viewer.