Ticket #986: 986.3.diff
| File 986.3.diff, 9.1 KB (added by , 11 years ago) |
|---|
-
anon-upload-template.php
61 61 62 62 .video-upload p { 63 63 margin: 16px 0; 64 overflow: auto; 64 65 } 65 66 66 67 .video-upload h3 { … … 214 215 case 13: 215 216 $message = "Error: please leave the first field empty. (It helps us know you're not a spammer.)"; 216 217 break; 218 case 14: 219 $message = "Error: please enter a valid WordPress.org username for the producer, or leave the field empty."; 220 break; 217 221 } 218 222 $message = '<div class="error"><p>' . $message . '</p></div>'; 219 223 } elseif ( !empty($_REQUEST['success']) ) { … … 314 318 </div> 315 319 316 320 <p> 317 <label for="wptv_ video_producer"><?php esc_html_e( 'Video producer' ); ?></label>318 <input type="text" id="wptv_ video_producer" name="wptv_video_producer" value="" />321 <label for="wptv_producer_username"><?php esc_html_e( 'Producer WordPress.org Username' ); ?></label> 322 <input type="text" id="wptv_producer_username" name="wptv_producer_username" value="" /> 319 323 </p> 320 324 <p> 321 325 <label for="wptv_speakers"><?php esc_html_e( 'Speakers' ); ?></label> -
functions.php
164 164 global $post; 165 165 166 166 $slides_url = get_post_meta( $post->ID, '_wptv_slides_url', true ); 167 $producer_username = get_post_meta( $post->ID, '_wptv_producer_username', true ); 167 168 wp_nonce_field( 'edit-video-info', 'video_info_metabox_nonce' ); 168 169 169 170 ?> … … 173 174 <input type="text" class="widefat" id="wptv-slides-url" name="_wptv_slides_url" value="<?php echo esc_url( $slides_url ); ?>" /> 174 175 </p> 175 176 177 <p> 178 <label for="wptv-producer-username">Producer's WordPress.org Username</label> 179 <input type="text" class="widefat" id="wptv-producer-username" name="_wptv_producer_username" value="<?php echo esc_attr( $producer_username ); ?>" /> 180 </p> 176 181 <?php 177 182 } 178 183 … … 198 203 } else { 199 204 delete_post_meta( $post_id, '_wptv_slides_url' ); 200 205 } 206 207 $producer_username = sanitize_text_field( $_POST['_wptv_producer_username'] ); 208 209 if ( wporg_username_exists( $producer_username ) ) { 210 update_post_meta( $post_id, '_wptv_producer_username', $producer_username ); 211 } else { 212 delete_post_meta( $post_id, '_wptv_producer_username' ); 213 } 201 214 } 202 215 203 216 /** … … 829 842 return $excerpt; 830 843 } 831 844 add_filter( 'get_the_excerpt', 'wptv_excerpt_slides' ); 845 846 /** 847 * Checks if the given username exists on WordPress.org 848 * 849 * grav-redirect.php will redirect to a Gravatar image URL. If the WordPress.org username exists, the `d` parameter 850 * will be 'retro', and if it doesn't it'll be 'mm'. 851 * 852 * @param string $username 853 * 854 * @return bool 855 */ 856 function wporg_username_exists( $username ) { 857 $username_exists = false; 858 $validator_url = add_query_arg( 'user', $username, 'https://wordpress.org/grav-redirect.php' ); 859 $response = wp_remote_retrieve_headers( wp_remote_get( $validator_url, array( 'redirection' => 0 ) ) ); 860 861 if ( array_key_exists( 'location', $response ) ) { 862 if ( false === strpos( $response['location'], 'd=mm' ) ) { 863 $username_exists = true; 864 } 865 } 866 867 return $username_exists; 868 } 869 870 // todo temp 871 function test_wporg_username_exists() { 872 $valid_usernames = array( 'iandunn', 'iandunn-CapitalTest', 'Ian Dunn Space Capital Test', 'kovshenin', '.EXTRATER.', '_Skyn3t_' ); 873 $invalid_usernames = array( '', 252342, 'sfjj2fasdfaef', '#@(@%%@#&*(*&(', '.;.;.;' ); 874 875 foreach ( $valid_usernames as $username ) { 876 printf( "<p>Valid username %s was marked as %s</p>", $username, wporg_username_exists( $username ) ? 'valid' : 'invalid' ); 877 } 878 879 foreach ( $invalid_usernames as $username ) { 880 printf( "<p>Invalid username %s was marked as %s</p>", $username, wporg_username_exists( $username ) ? 'valid' : 'invalid' ); 881 } 882 } 883 //test_wporg_username_exists(); -
plugins/wordpresstv-anon-upload/anon-upload.php
47 47 function validate() { 48 48 $text_fields = array( 49 49 'wptv_video_title', 50 'wptv_ video_producer',50 'wptv_producer_username', 51 51 'wptv_speakers', 52 52 'wptv_event', 53 53 'wptv_slides_url' … … 62 62 return $this->error( 13 ); 63 63 } 64 64 65 if ( empty( $_POST['wptv_producer_username'] ) || ! wporg_username_exists( $_POST['wptv_producer_username'] ) ) { 66 return $this->error( 14 ); 67 } 68 65 69 if ( ! is_user_logged_in() ) { 66 70 if ( empty( $_POST['wptv_uploaded_by'] ) ) { 67 71 return $this->error( 10 ); … … 259 263 } 260 264 261 265 $video_title = $this->sanitize_text( $_posted['wptv_video_title'] ); 262 $ video_producer = $this->sanitize_text( $_posted['wptv_video_producer'] );266 $producer_username = $this->sanitize_text( $_posted['wptv_producer_username'] ); 263 267 $speakers = $this->sanitize_text( $_posted['wptv_speakers'] ); 264 268 $event = $this->sanitize_text( $_posted['wptv_event'] ); 265 269 $description = $this->sanitize_text( $_posted['wptv_video_description'], false ); … … 266 270 $language = $this->sanitize_text( $_posted['wptv_language'] ); 267 271 $slides = $this->sanitize_text( $_posted['wptv_slides_url'] ); 268 272 $ip = $_SERVER['REMOTE_ADDR']; 273 // todo re-align after this commit 269 274 270 275 $categories = ''; 271 276 if ( ! empty( $_posted['post_category'] ) && is_array( $_posted['post_category'] ) ) { … … 282 287 'submitted_by' => $anon_author, 283 288 'submitted_email' => $anon_author_email, 284 289 'title' => $video_title, 285 'producer ' => $video_producer,290 'producer_username' => $producer_username, 286 291 'speakers' => $speakers, 287 292 'event' => $event, 288 293 'language' => $language, … … 290 295 'description' => $description, 291 296 'slides' => $slides, 292 297 'ip' => $ip, 298 // todo re-align after this commit 293 299 ); 294 300 295 301 $post_meta['video_guid'] = $video_data->guid; … … 324 330 $embed_args['blog_id'] = get_current_blog_id(); 325 331 $embed_args['post_id'] = $meta['attachment_id']; 326 332 327 // Add slides index to meta (necessary for posts that were uploaded before the field was added) 328 if ( ! array_key_exists( 'slides', $meta ) ) { 329 $meta['slides'] = ''; 333 // Add missing indexes to meta (necessary for posts that were uploaded before the fields were added) 334 $new_fields = array( 'slides', 'producer_username' ); // todo username should be taxonomy like producer name, rather than meta 335 foreach ( $new_fields as $field ) { 336 if ( ! array_key_exists( $field, $meta ) ) { 337 $meta[ $field ] = ''; 338 } 330 339 } 331 340 332 341 ?> … … 460 469 </div> 461 470 462 471 <div class="row"> 463 <p class="label">Producer:</p> 472 <p class="label">Producer WordPress.org Username:</p> 473 464 474 <p class="data"> 465 <input type="text" value="<?php echo esc_attr( $meta['producer '] ); ?>"/>466 <a class="button-secondary anon-approve" href="# new-tag-producer">Approve</a>475 <input type="text" value="<?php echo esc_attr( $meta['producer_username'] ); ?>"/> 476 <a class="button-secondary anon-approve" href="#wptv-producer-username">Approve</a> 467 477 </p> 468 478 </div> 469 479 … … 528 538 if (id.indexOf('#new-tag-') != -1) { 529 539 el.val(target.siblings('input[type="text"]').val()); 530 540 el.siblings('.tagadd').click(); 541 } else if ('#title' == id || '#wptv-producer-username' == id) { 542 el.val(target.siblings('input[type="text"]').val()); 531 543 } else if ('#title' == id || '#wptv-slides-url' == id) { 532 544 el.val(target.siblings('input[type="text"]').val()); 533 545 } else if (id == '#excerpt') { -
sidebar-single.php
81 81 printf( '<a href="%s">Subtitle this video →</a>', esc_url( add_query_arg( 'video', $video->post_id, home_url( 'subtitle/' ) ) ) ); 82 82 } 83 83 } 84 85 /* 86 * Credit video producer with link to their WordPress.org profile 87 * 88 * In most cases we'll either have the producer name, or the username, but not both. 89 */ 90 $producer_username = get_post_meta( get_the_ID(), '_wptv_producer_username', true ); 91 92 if ( $producer_name = get_the_terms( get_the_ID(), 'producer' ) ) { 93 if ( ! is_wp_error( $producer_name ) && ! empty( $producer_name[0]->name ) ) { 94 $producer_name = $producer_name[0]->name; 95 } else { 96 $producer_name = false; 97 } 98 } 99 84 100 ?> 101 102 <?php if ( $producer_name || $producer_username ) : ?> 103 <h5>Producer</h5> 104 105 <div class="video-producer"> 106 <?php if ( $producer_username ) : ?> 107 108 <a href="<?php echo esc_url( 'https://profiles.wordpress.org/' . rawurlencode( $producer_username ) ); ?>"> 109 <?php echo esc_html( $producer_username ); ?> 110 </a> 111 112 <?php elseif ( $producer_name ) : ?> 113 114 <?php echo esc_html( $producer_name ); ?> 115 116 <?php endif; ?> 117 </div> 118 <?php endif; ?> 119 85 120 </div><!-- .secondary-content -->