Making WordPress.org

Changeset 12886


Ignore:
Timestamp:
09/14/2023 09:31:26 PM (17 months ago)
Author:
coffee2code
Message:

Photo Directory, Admin: Add 'Other Recent Photo Submissions by Contributor' metabox.

Provides a grid of contributor's recent photo submissions, particularly those still pending, to better assess if the submission being viewed is a variation of another of their photos.

See #7171.

Location:
sites/trunk/wordpress.org/public_html/wp-content/plugins/photo-directory
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/photo-directory/assets/css/admin.css

    r12841 r12886  
    4747}
    4848
     49.photos-grid {
     50    display: grid;
     51    grid-template-columns: repeat(auto-fill,minmax(300px, 1fr));
     52}
     53
     54.photos-grid > span {
     55    position: relative;
     56}
     57
    4958.photos-photo-link {
    5059    display: inline-block;
    5160    overflow: hidden;
    5261}
     62.photos-photo-link img {
     63    max-width: 100%;
     64}
    5365.photos-photo-link img.blurred {
    5466    filter: blur(4rem);
    5567}
     68.photos-grid .photos-photo-link img {
     69    height: 200px;
     70    width: 300px;
     71    object-fit: cover;
     72    transition: all .25s;
     73}
     74.view-all-contributor-photos {
     75    margin-bottom: 0.5rem;
     76    margin-top: 1rem;
     77    text-align: right;
     78}
     79.pending-notice {
     80    position: absolute;
     81    bottom: 8px;
     82    left: 0;
     83    background-color: rgba(102,6,0, 0.7);
     84    color: #fff;
     85    padding: 4px 10px;
     86    width: 280px;
     87    font-weight: bold;
     88}
     89
    5690.column-wporg-photo .photos-photo-link img.blurred {
    5791    filter: blur( 0.7rem );
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/photo-directory/inc/admin.php

    r12867 r12886  
    456456            if ( $show ) {
    457457                add_meta_box( 'photos_photo', __( 'Photo', 'wporg-photos' ), [ __CLASS__, 'meta_box_photo' ], $post_type, 'normal' );
     458                add_meta_box( 'photos_by_contributor', __( 'Other Recent Photo Submissions by Contributor', 'wporg-photos' ), [ __CLASS__, 'meta_box_photos_by_contributor' ], $post_type, 'normal' );
    458459            }
    459460            add_meta_box( 'photos_info', __( 'Photo Info', 'wporg-photos' ), [ __CLASS__, 'meta_box_info' ], $post_type, 'side' );
     
    642643            esc_attr( $classes ),
    643644            set_url_scheme( $thumb_url[0] )
     645        );
     646    }
     647
     648    /**
     649     * Outputs the contents for the Recent Photo Submissions by Contributor metabox.
     650     *
     651     * @param WP_Post $post Post object.
     652     * @param array   $args Associative array of additional data.
     653     */
     654    public static function meta_box_photos_by_contributor( $post, $args ) {
     655        $photos_in_grid = 24;
     656
     657        // Request one more photo than is intended to be shown to determine if the contributor
     658        // has more photos than will be shown. Also, as the current photo will be excluded from
     659        // the grid, this also allows for its slot in the grid to be replaced without coming up
     660        // short or making an additional query.
     661        $recent_subs = User::get_recent_photos( $post->post_author, $photos_in_grid + 1, true );
     662
     663        echo '<div class="photos-grid">' . "\n";
     664
     665        $shown_photos = 0;
     666        foreach ( $recent_subs as $photo ) {
     667            // Don't show more photos than intended.
     668            // An extra photo was requested to determine if the contributor has even more photos.
     669            if ( $shown_photos >= $photos_in_grid ) {
     670                break;
     671            }
     672
     673            // Don't show the current photo in the grid.
     674            if ( $photo->ID === $post->ID ) {
     675                continue;
     676            }
     677
     678            // Show the photo.
     679            self::output_photo_in_metabox( $photo, 'medium', false );
     680
     681            $shown_photos++;
     682        }
     683
     684        echo '</div>' . "\n";
     685
     686        if ( count( $recent_subs ) > $photos_in_grid ) {
     687            echo '<div class="view-all-contributor-photos">';
     688            $link = add_query_arg( [
     689                'post_type'   => Registrations::get_post_type(),
     690                'author'      => $post->post_author,
     691            ], 'edit.php' );
     692            printf(
     693                '<a href="%s">%s</a>',
     694                esc_url( $link ),
     695                __( "View all photos from this contributor &rarr;", 'wporg-photos' )
     696            );
     697            echo '</div>' . "\n";
     698        }
     699    }
     700
     701    /**
     702     * Outputs markup for a photo intended to be shown in an admin metabox.
     703     *
     704     * @param WP_Post      $post             Photo post object.
     705     * @param string|int[] $size             Image size. Accepts any registered image size name, or an
     706     *                                       array of width and height values in pixels (in that order).
     707     * @param bool         $link_to_fullsize Should the image link to its full-sized version? If not, it
     708     *                                       will link to edit the photo post. Default true;
     709     */
     710    protected static function output_photo_in_metabox( $post, $size, $link_to_fullsize = true ) {
     711        $image_id = get_post_thumbnail_id( $post );
     712        if ( ! $image_id ) {
     713            return;
     714        }
     715
     716        $pending_notice = '';
     717        $classes = 'photo-thumbnail';
     718
     719        if ( Photo::is_controversial( $image_id ) ) {
     720            $classes .= ' blurred';
     721        }
     722
     723        if ( 'pending' === $post->post_status ) {
     724            $classes .= ' pending';
     725            if ( ! $link_to_fullsize ) {
     726                $pending_notice = '<div class="pending-notice">' . __( 'Pending', 'wporg-photos' ) . '</div>';
     727            }
     728        }
     729
     730        if ( 'fullsize' === $link_to_fullsize ) {
     731            $link_url = wp_get_attachment_url( $image_id );
     732            $label = __( 'View full-sized version of the photo.', 'wporg-photos' );
     733        } else {
     734            $link_url = get_edit_post_link( $post );
     735            $label = sprintf( __( 'Edit photo post &#8220;%s&#8221;', 'wporg-photos' ), $post->post_title );
     736        }
     737
     738        printf(
     739            '<span><a class="photos-photo-link row-title" href="%s" target="_blank" aria-label="%s"><img class="%s" src="%s" alt="" /></a>%s</span>',
     740            esc_url( $link_url ),
     741            /* translators: %s: Post title. */
     742            esc_attr( $label ),
     743            esc_attr( $classes ),
     744            esc_url( get_the_post_thumbnail_url( $post->ID, $size ) ),
     745            $pending_notice
    644746        );
    645747    }
Note: See TracChangeset for help on using the changeset viewer.