Making WordPress.org

Changeset 1724


Ignore:
Timestamp:
07/10/2015 08:32:01 PM (11 years ago)
Author:
iandunn
Message:

WordPress.tv: Give credit to video producers.

Fixes #986
Props BrashRebel

Location:
sites/trunk/wordpress.tv/public_html/wp-content/themes/wptv2
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.tv/public_html/wp-content/themes/wptv2/anon-upload-template.php

    r1723 r1724  
    6262    .video-upload p {
    6363        margin: 16px 0;
     64        overflow: auto;
    6465    }
    6566
     
    174175        case 1:
    175176            $message = 'Error: pleas select a video file.';
     177            // todo fix all the 'pleas' typos
    176178            break;
    177179        case 2:
     
    202204        case 13:
    203205            $message = "Error: please leave the first field empty. (It helps us know you're not a spammer.)";
     206            break;
     207        case 14:
     208            $message = "Error: please enter a valid WordPress.org username for the producer, or leave the field empty.";
    204209            break;
    205210    }
     
    303308
    304309    <p>
    305         <label for="wptv_video_producer"><?php esc_html_e( 'Video producer' ); ?></label>
    306         <input type="text" id="wptv_video_producer" name="wptv_video_producer" value="" />
     310        <label for="wptv_producer_username"><?php esc_html_e( 'Producer WordPress.org Username' ); ?></label>
     311        <input type="text" id="wptv_producer_username" name="wptv_producer_username" value="" />
    307312    </p>
    308313    <p>
  • sites/trunk/wordpress.tv/public_html/wp-content/themes/wptv2/functions.php

    r1712 r1724  
    7777            'args'     => array( 'orderby' => 'term_order' ),
    7878            'rewrite'  => array( 'slug' => 'producer' ),
     79        ) );
     80
     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' ),
    7988        ) );
    8089
     
    819828}
    820829add_filter( 'get_the_excerpt', 'wptv_excerpt_slides' );
     830
     831/**
     832 * Checks if the given username exists on WordPress.org
     833 *
     834 * grav-redirect.php will redirect to a Gravatar image URL. If the WordPress.org username exists, the `d` parameter
     835 * will be 'retro', and if it doesn't it'll be 'mm'.
     836 *
     837 * @param string $username
     838 *
     839 * @return bool
     840 */
     841function wporg_username_exists( $username ) {
     842    $username_exists = false;
     843    $validator_url   = add_query_arg( 'user', $username, 'https://wordpress.org/grav-redirect.php' );
     844    $response        = wp_remote_retrieve_headers( wp_remote_get( $validator_url, array( 'redirection' => 0 ) ) );
     845
     846    if ( array_key_exists( 'location', $response ) ) {
     847        if ( false === strpos( $response['location'], 'd=mm' ) ) {
     848            $username_exists = true;
     849        }
     850    }
     851
     852    return $username_exists;
     853}
  • sites/trunk/wordpress.tv/public_html/wp-content/themes/wptv2/plugins/wordpresstv-anon-upload/anon-upload.php

    r1650 r1724  
    4848        $text_fields = array(
    4949            'wptv_video_title',
    50             'wptv_video_producer',
     50            'wptv_producer_username',
    5151            'wptv_speakers',
    5252            'wptv_event',
     
    6161
    6262            return $this->error( 13 );
     63        }
     64
     65        if ( ! empty( $_POST['wptv_producer_username'] ) && ! wporg_username_exists( $_POST['wptv_producer_username'] ) ) {
     66            return $this->error( 14 );
    6367        }
    6468
     
    260264
    261265        $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'] );
    263267        $speakers       = $this->sanitize_text( $_posted['wptv_speakers'] );
    264268        $event          = $this->sanitize_text( $_posted['wptv_event'] );
     
    267271        $slides         = $this->sanitize_text( $_posted['wptv_slides_url'] );
    268272        $ip             = $_SERVER['REMOTE_ADDR'];
     273        // todo realign in separate commit
    269274
    270275        $categories = '';
     
    283288            'submitted_email' => $anon_author_email,
    284289            'title'           => $video_title,
    285             'producer'        => $video_producer,
     290            'producer_username' => $producer_username,
    286291            'speakers'        => $speakers,
    287292            'event'           => $event,
     
    291296            'slides'          => $slides,
    292297            'ip'              => $ip,
     298            // todo realign in separate commit
    293299        );
    294300
     
    325331        $embed_args['post_id'] = $meta['attachment_id'];
    326332
    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' );
     335        foreach ( $new_fields as $field ) {
     336            if ( ! array_key_exists( $field, $meta ) ) {
     337                $meta[ $field ] = '';
     338            }
    330339        }
    331340
     
    461470
    462471                    <div class="row">
    463                         <p class="label">Producer:</p>
    464                         <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>
     472                        <p class="label">Producer WordPress.org Username:</p>
     473
     474                        <p class="data">
     475                            <input type="text" value="<?php echo esc_attr( $meta['producer_username'] ); ?>"/>
     476                            <a class="button-secondary anon-approve" href="#new-tag-producer-username">Approve</a>
    467477                        </p>
    468478                    </div>
  • sites/trunk/wordpress.tv/public_html/wp-content/themes/wptv2/sidebar-single.php

    r1044 r1724  
    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_name     = get_the_terms( get_the_ID(), 'producer' );
     91            $producer_username = get_the_terms( get_the_ID(), 'producer-username' );
    8492            ?>
     93
     94            <?php if ( $producer_name || $producer_username ) : ?>
     95                <h5>Producer</h5>
     96
     97                <div class="video-producer">
     98                    <?php if ( $producer_username ) : ?>
     99
     100                        <a href="<?php echo esc_url( 'https://profiles.wordpress.org/' . rawurlencode( $producer_username[0]->name ) ); ?>">
     101                            <?php if ( $producer_name ) : ?>
     102                                <?php echo esc_html( $producer_name[0]->name ); ?>
     103                            <?php else : ?>
     104                                <?php echo esc_html( $producer_username[0]->name ); ?>
     105                            <?php endif; ?>
     106                        </a>
     107
     108                    <?php else : ?>
     109
     110                        <a href="<?php echo esc_url( get_term_link( $producer_name[0] ) ); ?>">
     111                            <?php echo esc_html( $producer_name[0]->name ); ?>
     112                        </a>
     113
     114                    <?php endif; ?>
     115                </div>
     116            <?php endif; ?>
     117
    85118</div><!-- .secondary-content -->
Note: See TracChangeset for help on using the changeset viewer.