Making WordPress.org

Ticket #986: 986.4.diff

File 986.4.diff, 13.4 KB (added by BrashRebel, 11 years ago)
  • anon-upload-template.php

    diff --git anon-upload-template.php anon-upload-template.php
    index 68be0b8..949d4b9 100644
    function anon_upload_css() { 
    6161
    6262        .video-upload p {
    6363                margin: 16px 0;
     64                overflow: auto;
    6465        }
    6566
    6667        .video-upload h3 {
    if ( !empty($_REQUEST['error']) ) { 
    214215                case 13:
    215216                        $message = "Error: please leave the first field empty. (It helps us know you're not a spammer.)";
    216217                        break;
     218                case 14:
     219                        $message = "Error: please enter a valid WordPress.org username for the producer, or leave the field empty.";
     220                        break;
    217221        }
    218222        $message = '<div class="error"><p>' . $message . '</p></div>';
    219223} elseif ( !empty($_REQUEST['success']) ) {
    if ( !empty($_REQUEST['error']) ) { 
    314318        </div>
    315319
    316320        <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="" />
    319323        </p>
    320324        <p>
    321325                <label for="wptv_speakers"><?php esc_html_e( 'Speakers' ); ?></label>
  • functions.php

    diff --git functions.php functions.php
    index 9f6d785..7007f48 100644
    class WordPressTV_Theme { 
    2828                add_action( 'init', array( $this, 'improve_search' ) );
    2929                add_action( 'publish_post', array( $this, 'publish_post' ), 10, 1 );
    3030                add_action( 'add_meta_boxes', array( $this, 'add_meta_boxes' ) );
    31                 add_action( 'save_post', array( $this, 'save_meta_box_fields' ), 10, 2);
     31                add_action( 'save_post', array( $this, 'save_meta_box_fields' ), 10, 2 );
    3232                add_action( 'wp_footer', array( $this, 'videopress_flash_params' ) );
    3333                add_action( 'transition_post_status', array( $this, 'transition_post_status' ), 10, 2 );
    3434
    class WordPressTV_Theme { 
    7878                        'rewrite'  => array( 'slug' => 'producer' ),
    7979                ) );
    8080
     81                register_taxonomy( 'producer-username', array( 'post' ), array(
     82                        'label'    => __( 'Producer Username', 'wptv' ),
     83                        'template' => __( 'Producer: %l.', 'wptv' ),
     84                        'helps'    => __( 'Separate producer usernames with commas.', 'wptv' ),
     85                        'sort'     => true,
     86                        'args'     => array( 'orderby' => 'term_order' ),
     87                        'rewrite'  => array( 'slug' => 'producer-username' ),
     88                ) );
     89
    8190                register_taxonomy( 'speakers', array( 'post' ), array(
    8291                        'label'    => __( 'Speakers', 'wptv' ),
    8392                        'template' => __( 'Speakers: %l.', 'wptv' ),
    class WordPressTV_Theme { 
    154163         * Register meta boxes
    155164         */
    156165        function add_meta_boxes() {
    157                 add_meta_box( 'video-info', 'Video Info', array( $this, 'render_video_info_metabox' ), 'post', 'normal', 'high' );
     166                add_meta_box( 'video-info', 'Video Info', array(
     167                                $this,
     168                                'render_video_info_metabox'
     169                        ), 'post', 'normal', 'high' );
    158170        }
    159171
    160172        /**
    class WordPressTV_Theme { 
    170182
    171183                <p>
    172184                        <label for="wptv-slides-url">Slides URL</label>
    173                         <input type="text" class="widefat" id="wptv-slides-url" name="_wptv_slides_url" value="<?php echo esc_url( $slides_url ); ?>" />
     185                        <input type="text" class="widefat" id="wptv-slides-url" name="_wptv_slides_url"
     186                               value="<?php echo esc_url( $slides_url ); ?>"/>
    174187                </p>
    175 
    176                 <?php
     188        <?php
    177189        }
    178190
    179191        /**
    class WordPressTV_Theme { 
    226238                 *
    227239                 * Maybe look at ways to do the sorting in PHP, or just use Elasticsearch instead.
    228240                 */
     241
    229242                return;
    230243
    231244                if ( ! $query->is_main_query() || ! $query->is_search ) {
    class WordPressTV_Theme { 
    405418                        <?php if ( $comment->comment_type != 'pingback' ) : ?>
    406419
    407420                                <small class="commentmetadata">
    408                                         <a href="#comment-<?php comment_ID() ?>" title=""><?php printf( __( '%1$s at %2$s', 'wptv' ), get_comment_date(), get_comment_time() ); ?></a>
     421                                        <a href="#comment-<?php comment_ID() ?>"
     422                                           title=""><?php printf( __( '%1$s at %2$s', 'wptv' ), get_comment_date(), get_comment_time() ); ?></a>
    409423                                        <?php
    410                                                 edit_comment_link( __( 'edit', 'wptv' ), '&nbsp;&nbsp;', '' );
    411                                                 echo comment_reply_link( array(
    412                                                         'depth'     => $depth,
    413                                                         'max_depth' => $args['max_depth'],
    414                                                         'before'    => ' | ',
    415                                                 ) );
     424                                        edit_comment_link( __( 'edit', 'wptv' ), '&nbsp;&nbsp;', '' );
     425                                        echo comment_reply_link( array(
     426                                                'depth'     => $depth,
     427                                                'max_depth' => $args['max_depth'],
     428                                                'before'    => ' | ',
     429                                        ) );
    416430                                        ?>
    417431                                </small>
    418432
    class WordPressTV_Theme { 
    514528                foreach ( $matches[1] as $key => $code ) {
    515529                        $code   = '[vodpod ' . $code . ']';
    516530                        $vodpod = apply_filters( 'the_content', $code );
    517                         $id     = trim( str_replace( '</div>','', preg_replace( '/.*key\=([^&]+)&.*/', '$1', $vodpod ) ) );
     531                        $id     = trim( str_replace( '</div>', '', preg_replace( '/.*key\=([^&]+)&.*/', '$1', $vodpod ) ) );
    518532
    519533                        $image = $this->get_vodpod_thumbnails( $code );
    520534                        $video = $vodpod;
    class WordPressTV_Theme { 
    548562                foreach ( $matches[1] as $key => $code ) {
    549563                        preg_match( '/([0-9A-Za-z]+)/i', $code, $m );
    550564                        $guid = $m[1];
    551                         $ret = video_image_url_by_guid( $guid, 'fmt_dvd' );
     565                        $ret  = video_image_url_by_guid( $guid, 'fmt_dvd' );
    552566                }
    553567
    554568                preg_match_all( '|\[wporg-screencast (.+?)]|ie', $post->post_content, $matches );
    class WordCampTV_Walker_Nav_Menu extends Walker { 
    745759                <div>
    746760                        <h3>
    747761                                <?php echo apply_filters( 'the_title', $item->title ); ?>
    748                                 <a href="<?php echo esc_url( $item->url ); ?>" class="view-more"><?php esc_html_e( 'More &rarr;' ); ?></a>
     762                                <a href="<?php echo esc_url( $item->url ); ?>"
     763                                   class="view-more"><?php esc_html_e( 'More &rarr;' ); ?></a>
    749764                        </h3>
    750765                        <ul class="video-list four-col">
    751766                                <?php while ( $query->have_posts() ) : $query->the_post(); ?>
    752                                 <li>
    753                                         <a href="<?php the_permalink(); ?>">
    754                                                 <span class="video-thumbnail"><?php $wptv->the_video_image( 50, null, false ); ?></span>
    755                                                 <span class="video-title"><?php the_title(); ?></span>
    756                                         </a>
    757                                 </li>
     767                                        <li>
     768                                                <a href="<?php the_permalink(); ?>">
     769                                                        <span class="video-thumbnail"><?php $wptv->the_video_image( 50, null, false ); ?></span>
     770                                                        <span class="video-title"><?php the_title(); ?></span>
     771                                                </a>
     772                                        </li>
    758773                                <?php endwhile; ?>
    759774                        </ul>
    760775                </div>
    function wptv_enqueue_scripts() { 
    776791                wp_enqueue_script( 'comment-reply' );
    777792        }
    778793}
     794
    779795add_action( 'wp_enqueue_scripts', 'wptv_enqueue_scripts' );
    780796
    781797/**
    function wptv_wp_title( $title, $sep ) { 
    810826
    811827        return $title;
    812828}
     829
    813830add_filter( 'wp_title', 'wptv_wp_title', 10, 2 );
    814831
    815832/**
    function wptv_excerpt_slides( $excerpt ) { 
    828845
    829846        return $excerpt;
    830847}
     848
    831849add_filter( 'get_the_excerpt', 'wptv_excerpt_slides' );
     850
     851/**
     852 * Checks if the given username exists on WordPress.org
     853 *
     854 * grav-redirect.php will redirect to a Gravatar image URL. If the WordPress.org username exists, the `d` parameter
     855 * will be 'retro', and if it doesn't it'll be 'mm'.
     856 *
     857 * @param string $username
     858 *
     859 * @return bool
     860 */
     861function wporg_username_exists( $username ) {
     862        $username_exists = false;
     863        $validator_url   = add_query_arg( 'user', $username, 'https://wordpress.org/grav-redirect.php' );
     864        $response        = wp_remote_retrieve_headers( wp_remote_get( $validator_url, array( 'redirection' => 0 ) ) );
     865
     866        if ( array_key_exists( 'location', $response ) ) {
     867                if ( false === strpos( $response['location'], 'd=mm' ) ) {
     868                        $username_exists = true;
     869                }
     870        }
     871
     872        return $username_exists;
     873}
  • plugins/wordpresstv-anon-upload/anon-upload.php

    diff --git plugins/wordpresstv-anon-upload/anon-upload.php plugins/wordpresstv-anon-upload/anon-upload.php
    index 18bca59..92390e0 100644
    class WPTV_Anon_Upload { 
    4747        function validate() {
    4848                $text_fields = array(
    4949                        'wptv_video_title',
    50                         'wptv_video_producer',
     50                        'wptv_producer_username',
    5151                        'wptv_speakers',
    5252                        'wptv_event',
    5353                        'wptv_slides_url'
    class WPTV_Anon_Upload { 
    6262                        return $this->error( 13 );
    6363                }
    6464
     65                if ( empty( $_POST['wptv_producer_username'] ) || ! wporg_username_exists( $_POST['wptv_producer_username'] ) ) {
     66                        return $this->error( 14 );
     67                }
     68
    6569                if ( ! is_user_logged_in() ) {
    6670                        if ( empty( $_POST['wptv_uploaded_by'] ) ) {
    6771                                return $this->error( 10 );
    class WPTV_Anon_Upload { 
    269273                        $anon_author_email = $this->sanitize_text( $_posted['wptv_email'] );
    270274                }
    271275
    272                 $video_title    = $this->sanitize_text( $_posted['wptv_video_title'] );
    273                 $video_producer = $this->sanitize_text( $_posted['wptv_video_producer'] );
    274                 $speakers       = $this->sanitize_text( $_posted['wptv_speakers'] );
    275                 $event          = $this->sanitize_text( $_posted['wptv_event'] );
    276                 $description    = $this->sanitize_text( $_posted['wptv_video_description'], false );
    277                 $language       = $this->sanitize_text( $_posted['wptv_language'] );
    278                 $slides         = $this->sanitize_text( $_posted['wptv_slides_url'] );
    279                 $ip             = $_SERVER['REMOTE_ADDR'];
     276                $video_title       = $this->sanitize_text( $_posted['wptv_video_title'] );
     277                $producer_username = $this->sanitize_text( $_posted['wptv_producer_username'] );
     278                $speakers          = $this->sanitize_text( $_posted['wptv_speakers'] );
     279                $event             = $this->sanitize_text( $_posted['wptv_event'] );
     280                $description       = $this->sanitize_text( $_posted['wptv_video_description'], false );
     281                $language          = $this->sanitize_text( $_posted['wptv_language'] );
     282                $slides            = $this->sanitize_text( $_posted['wptv_slides_url'] );
     283                $ip                = $_SERVER['REMOTE_ADDR'];
    280284
    281285                $categories = '';
    282286                if ( ! empty( $_posted['post_category'] ) && is_array( $_posted['post_category'] ) ) {
    class WPTV_Anon_Upload { 
    289293                }
    290294
    291295                $post_meta = array(
    292                         'attachment_id'   => $attachment_id,
    293                         'submitted_by'    => $anon_author,
    294                         'submitted_email' => $anon_author_email,
    295                         'title'           => $video_title,
    296                         'producer'        => $video_producer,
    297                         'speakers'        => $speakers,
    298                         'event'           => $event,
    299                         'language'        => $language,
    300                         'categories'      => $categories,
    301                         'description'     => $description,
    302                         'slides'          => $slides,
    303                         'ip'              => $ip,
     296                        'attachment_id'     => $attachment_id,
     297                        'submitted_by'      => $anon_author,
     298                        'submitted_email'   => $anon_author_email,
     299                        'title'             => $video_title,
     300                        'producer_username' => $producer_username,
     301                        'speakers'          => $speakers,
     302                        'event'             => $event,
     303                        'language'          => $language,
     304                        'categories'        => $categories,
     305                        'description'       => $description,
     306                        'slides'            => $slides,
     307                        'ip'                => $ip,
    304308                );
    305309
    306310                $post_meta['video_guid'] = $video_data->guid;
    class WPTV_Anon_Upload { 
    335339                $embed_args['blog_id'] = get_current_blog_id();
    336340                $embed_args['post_id'] = $meta['attachment_id'];
    337341
    338                 // Add slides index to meta (necessary for posts that were uploaded before the field was added)
    339                 if ( ! array_key_exists( 'slides', $meta ) ) {
    340                         $meta['slides'] = '';
     342                // Add missing indexes to $meta (necessary for posts that were uploaded before the fields were added)
     343                $new_fields = array( 'slides', 'producer_username' );
     344                foreach ( $new_fields as $field ) {
     345                        if ( ! array_key_exists( $field, $meta ) ) {
     346                                $meta[ $field ] = '';
     347                        }
    341348                }
    342349
    343350                ?>
    class WPTV_Anon_Upload { 
    471478                                        </div>
    472479
    473480                                        <div class="row">
    474                                                 <p class="label">Producer:</p>
     481                                                <p class="label">Producer WordPress.org Username:</p>
     482
    475483                                                <p class="data">
    476                                                         <input type="text" value="<?php echo esc_attr( $meta['producer'] ); ?>"/>
    477                                                         <a class="button-secondary anon-approve" href="#new-tag-producer">Approve</a>
     484                                                        <input type="text" value="<?php echo esc_attr( $meta['producer_username'] ); ?>"/>
     485                                                        <a class="button-secondary anon-approve" href="#new-tag-producer-username">Approve</a>
    478486                                                </p>
    479487                                        </div>
    480488
  • sidebar-single.php

    diff --git sidebar-single.php sidebar-single.php
    index 84a2fe6..deb288d 100644
     
    8181                                                printf( '<a href="%s">Subtitle this video &rarr;</a>', esc_url( add_query_arg( 'video', $video->post_id, home_url( 'subtitle/' ) ) ) );
    8282                                        }
    8383                                }
     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_the_terms( get_the_ID(), 'producer-username' );
     91                        $producer_name = get_the_terms( get_the_ID(), 'producer' );
    8492                        ?>
     93
     94                        <?php if ( $producer_name || $producer_username ) : ?>
     95                                <h5>Producer</h5>
     96
     97                                <div class="video-producer">
     98                                        <?php if ( $producer_username && $producer_name ) : ?>
     99                                                <?php $producer_username = $producer_username[0]->name; ?>
     100                                                <a href="<?php echo esc_url( 'https://profiles.wordpress.org/' . rawurlencode( $producer_username ) ); ?>">
     101                                                        <?php echo esc_html( $producer_name[0]->name ); ?>
     102                                                </a>
     103
     104                                        <?php elseif ( $producer_username ) : ?>
     105
     106                                                <?php $producer_username = $producer_username[0]->name; ?>
     107                                                <a href="<?php echo esc_url( 'https://profiles.wordpress.org/' . rawurlencode( $producer_username ) ); ?>">
     108                                                        <?php echo esc_html( $producer_username ); ?>
     109                                                </a>
     110
     111                                        <?php else : ?>
     112
     113                                                <a href="<?php echo esc_url( get_term_link( $producer_name[0] ) ); ?>">
     114                                                        <?php echo esc_html( $producer_name[0]->name ); ?>
     115                                                </a>
     116
     117                                        <?php endif; ?>
     118                                </div>
     119                        <?php endif; ?>
     120
    85121</div><!-- .secondary-content -->