Making WordPress.org

Changeset 10468


Ignore:
Timestamp:
11/25/2020 07:28:26 AM (6 years ago)
Author:
dd32
Message:

WordPress.tv: Split the big Category section into Date Recorded, Location, and Category.

The category section now excludes the Year & Location categories, which makes it easier to grok and select categories.

The year category is now not visible on the submit page, but set on the backend based on the date recorded option.

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

Legend:

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

    r10467 r10468  
    110110                        height: 150px;
    111111                        overflow: auto;
     112                        margin-top: 4px;
    112113                }
    113114
     
    211212                        $message = "Error: please enter a valid WordPress.org username for the producer, or leave the field empty.";
    212213                        break;
     214                case 15:
     215                        $message = 'Error: form nonce was missing or invalid.';
     216                        break;
    213217        }
    214218        $message = '<div class="error"><p>' . $message . '</p></div>';
    215219} elseif ( !empty($_REQUEST['success']) ) {
    216220        $message = '<div class="success"> <p>Thank you for submitting a video; it was uploaded successfully.</p> <p>Submit another?</p> </div>';
     221}
     222
     223$selected_cats = [];
     224if ( isset( $_GET['post_category'] ) ) {
     225        // [ selected Id => 0.. ]
     226        $selected_cats = array_flip( array_map( 'intval', $_GET['post_category'] ) );
    217227}
    218228
     
    304314                                        </p>
    305315
     316                                        <div class="location">
     317                                                <label for="wptv_location"><?php esc_html_e( 'Location' ); ?></label>
     318                                                <ul class="cats-checkboxes">
     319                                                        <?php
     320
     321                                                        foreach ( get_categories( [
     322                                                                'parent'     => get_term_by( 'slug', 'location', 'category' )->term_id,
     323                                                                'hide_empty' => false,
     324                                                        ] ) as $term ) {
     325                                                                printf(
     326                                                                        '<li id="category-%1$d"><label class="selectit"><input value="%1$d" type="checkbox" name="post_category[]" id="in-category-%1$d" %2$s> %3$s</label></li>',
     327                                                                        $term->term_id,
     328                                                                        isset( $selected_cats[ $term->term_id ] ) ? 'checked="checked" ' : '',
     329                                                                        $term->name,
     330                                                                );
     331                                                        }
     332                                                        ?>
     333                                                </ul>
     334                                        </div>
     335
    306336                                        <div class="cats">
    307337                                                <label for="post_category"><?php esc_html_e( 'Category' ); ?></label>
    308338                                                <ul class="cats-checkboxes">
    309339                                                        <?php
    310                                                         include_once( ABSPATH . '/wp-admin/includes/template.php' );
    311                                                         $selected_cats = false;
    312                                                         if ( isset( $_GET['post_category'] ) ) {
    313                                                                 $selected_cats = array_map( 'intval', $_GET['post_category'] );
     340                                                        foreach ( get_categories( [
     341                                                                'exclude_tree' => [
     342                                                                        get_term_by( 'slug', 'location', 'category' )->term_id,
     343                                                                        get_term_by( 'slug', 'year', 'category' )->term_id,
     344                                                                ],
     345                                                                'parent'       => 0,
     346                                                                'hide_empty'   => false,
     347                                                        ] ) as $term ) {
     348                                                                printf(
     349                                                                        '<li id="category-%1$d"><label class="selectit"><input value="%1$d" type="checkbox" name="post_category[]" id="in-category-%1$d" %2$s> %3$s</label></li>',
     350                                                                        $term->term_id,
     351                                                                        isset( $selected_cats[ $term->term_id ] ) ? 'checked="checked" ' : '',
     352                                                                        $term->name,
     353                                                                );
    314354                                                        }
    315                                                         wp_category_checklist( 0, 0, $selected_cats, false, null, false );
    316355                                                        ?>
    317356                                                </ul>
     
    373412                        $( 'ul.cats-checkboxes input' ).prop( 'disabled', false );
    374413
    375                         $( '#wptv_video_wordcamp, ul.cats-checkboxes input' ).on( 'change', function() {
     414                        // Float selected items to the start.
     415                        $( '.location ul.cats-checkboxes, .cats ul.cats-checkboxes' ).each( function() {
     416                                var list = $(this),
     417                                        selected = list.find( 'input:checked, #in-category-2648' ); // checked & World-Wide-Web
     418
     419                                selected.each( function() {
     420                                        var li = $(this).parents( 'li' );
     421                                        li.remove();
     422                                        list.prepend( li );
     423                                } );
     424                        } );
     425
     426                        // Generate the Event Name
     427                        $( '#wptv_video_wordcamp, .location ul.cats-checkboxes input, .cats ul.cats-checkboxes input, #wptv_date' ).on( 'change', function() {
    376428                                if ( $( '#wptv_event' ).data('user-altered') ) {
    377429                                        return;
     
    380432                                var title = '';
    381433                                // Get the Location
    382                                 title += $( '#category-6418 ul.children input:checked' ).parent().text().trim() + " ";
     434                                title += $( '.location input:checked' ).parent().text().trim() + " ";
    383435
    384436                                // .. and the Year
    385                                 title += $( '#category-91093 ul.children input:checked' ).parent().text().trim();
     437                                title += $( '#wptv_date' ).value.substring( 0, 4 );
    386438
    387439                                // If a location or year has been selected, build the Event Name.
     
    410462                        });
    411463
    412                         // Pre-select the date category.
    413                         $( '#wptv_date' ).on( 'change', function() {
    414                                 var year = parseInt( this.value.substring( 0, 4 ) );
    415 
    416                                 // Blank the year selections.
    417                                 $( '#category-91093 ul.children input' ).prop( 'checked', false );
    418 
    419                                 // Check the year
    420                                 $( '#category-91093 ul.children input' ).filter( function() {
    421                                         return parseInt( $(this).parent().text() ) === year;
    422                                 } ).prop( 'checked', true )
    423                         } );
     464                        $( '#wptv_video_wordcamp' ).on( 'change', function() {
     465                                // WordCampTV cat
     466                                $( '#in-category-12784353' ).prop( 'checked', $( this ).prop( 'checked' ) );
     467                        });
    424468
    425469                        $( '#video-upload-form' ).submit( function( e ) {
  • sites/trunk/wordpress.tv/public_html/wp-content/themes/wptv2/plugins/wordpresstv-anon-upload/anon-upload.php

    r10467 r10468  
    1111                $this->drafts_author = apply_filters( 'wptv_drafts_author_id', $this->drafts_author );  // this is filterable in order to support local development
    1212
    13                 add_action( 'admin_post_wptv_video_upload', array( &$this, 'init' ) );
    14                 add_action( 'admin_post_nopriv_wptv_video_upload', array( &$this, 'init' ) );
    15                 add_action( 'dbx_post_sidebar', array( &$this, 'display' ) );
     13                add_action( 'admin_post_wptv_video_upload', array( $this, 'init' ) );
     14                add_action( 'admin_post_nopriv_wptv_video_upload', array( $this, 'init' ) );
     15                add_action( 'dbx_post_sidebar', array( $this, 'display' ) );
    1616        }
    1717
    1818        function init() {
    19                 if ( ! empty( $_POST['wptvvideon'] ) && wp_verify_nonce( $_POST['wptvvideon'], 'wptv-upload-video' ) ) {
     19                $redir = home_url( '/submit-video/' );
     20
     21                if (
     22                        empty( $_POST['wptvvideon'] ) ||
     23                        (
     24                                empty( $_POST['wptv_uploaded_by'] ) &&
     25                                ! wp_verify_nonce( $_POST['wptvvideon'], 'wptv-upload-video' )
     26                        )
     27                ) {
     28                        $this->errors = 15; /* no-nonce / invalid nonce */
     29                } else {
    2030                        $this->validate();
    2131
     
    2333                                $this->success = $this->save();
    2434                        }
    25 
    26                         $redir = home_url( '/submit-video/' );
    27 
    28                         // Fields to prefill
    29                         $keep_fields = array(
    30                                 'wptv_video_wordcamp',
    31                                 'wptv_uploaded_by',
    32                                 'wptv_email',
    33                                 'wptv_language',
    34                                 'wptv_date',
    35                                 'post_category', // 'wptv_categories',
    36                                 'wptv_producer_username',
    37                                 'wptv_event',
     35                }
     36
     37                // Fields to prefill
     38                $keep_fields = array(
     39                        'wptv_video_wordcamp',
     40                        'wptv_uploaded_by',
     41                        'wptv_email',
     42                        'wptv_language',
     43                        'wptv_date',
     44                        'post_category', // 'wptv_categories',
     45                        'wptv_producer_username',
     46                        'wptv_event',
     47                );
     48
     49                if ( $this->success ) {
     50                        $redir = add_query_arg( array( 'success' => 1 ), $redir );
     51                } elseif ( $this->errors ) {
     52                        $redir = add_query_arg( array( 'error' => $this->errors ), $redir );
     53
     54                        // Video upload failed, include the video-specific fields in pre-fill.
     55                        $keep_fields[] = 'wptv_video_title';
     56                        $keep_fields[] = 'wptv_speakers';
     57                        $keep_fields[] = 'wptv_video_description';
     58                        $keep_fields[] = 'wptv_slides_url';
     59
     60                } else {
     61                        $keep_fields = array();
     62                        $redir = add_query_arg( array( 'error' => 5 ), $redir );
     63                }
     64
     65                // Keep some fields.
     66                if ( $keep_fields ) {
     67                        $redir = add_query_arg(
     68                                urlencode_deep(
     69                                        array_intersect_key(
     70                                                $_POST,
     71                                                array_flip( $keep_fields )
     72                                        )
     73                                ),
     74                                $redir
    3875                        );
    39 
    40                         if ( $this->success ) {
    41                                 $redir = add_query_arg( array( 'success' => 1 ), $redir );
    42                         } elseif ( $this->errors ) {
    43                                 $redir = add_query_arg( array( 'error' => $this->errors ), $redir );
    44 
    45                                 // Video upload failed, include the video-specific fields in pre-fill.
    46                                 $keep_fields[] = 'wptv_video_title';
    47                                 $keep_fields[] = 'wptv_speakers';
    48                                 $keep_fields[] = 'wptv_video_description';
    49                                 $keep_fields[] = 'wptv_slides_url';
    50 
    51                         } else {
    52                                 $keep_fields = array();
    53                                 $redir = add_query_arg( array( 'error' => 5 ), $redir );
    54                         }
    55 
    56                         // Keep some fields.
    57                         if ( $keep_fields ) {
    58                                 $redir = add_query_arg(
    59                                         urlencode_deep(
    60                                                 array_intersect_key(
    61                                                         $_POST,
    62                                                         array_flip( $keep_fields )
    63                                                 )
    64                                         ),
    65                                         $redir
    66                                 );
    67                         }
    68 
    69                         wp_redirect( $redir );
    70                 } else {
    71                         // no nonce, send them "home"?
    72                         wp_redirect( home_url() );
    73                 }
    74 
     76                }
     77
     78                wp_redirect( $redir );
    7579                exit;
    7680        }
     
    305309                $language          = $this->sanitize_text( $_posted['wptv_language'] );
    306310                $slides            = $this->sanitize_text( $_posted['wptv_slides_url'] );
    307                 $recorded          = $this->sanitize_tett( $_posted['wptv_date'] );
     311                $recorded          = $this->sanitize_text( $_posted['wptv_date'] ); // yyyy-mm-dd
    308312                $ip                = $_SERVER['REMOTE_ADDR'];
    309313
     
    315319                                        $categories .= "$cat,";
    316320                                }
     321                        }
     322                }
     323
     324                // Add the year category.
     325                if ( $recorded ) {
     326                        $year = substr( $recorded, 0, 4 );
     327                        if ( $term = get_term_by( 'name', $year, 'category' ) ) {
     328                                $categories .= $term->term_id;
    317329                        }
    318330                }
     
    481493                                                <p class="data">
    482494                                                        <input type="text" value="<?php echo esc_attr( $meta['recorded'] ); ?>"/>
     495                                                        <?php
     496                                                                // Find the year cat
     497                                                                $cat = get_term_by( 'name', substr( $meta['recorded'], 0, 4 ), 'category' );
     498                                                                if ( $cat ) {
     499                                                                        echo '<a href="#in-category-' . $cat->term_id . '" class="button-secondary anon-approve anon-cat-link" title="Click to approve">Approve</a>';
     500                                                                }
     501                                                        ?>
     502                                                       
    483503                                                </p>
    484504                                        </div>
Note: See TracChangeset for help on using the changeset viewer.