Making WordPress.org


Ignore:
Timestamp:
08/13/2020 11:43:14 PM (6 years ago)
Author:
coreymckrill
Message:

WordPress.org Learn: Sync with GitHub

https://github.com/WordPress/learn/compare/1accd3db38a60230689bdc157f9e82081d35d163...38e7793fd20434d72ca898988d017ba2009fb677

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-learn/inc/class-shortcodes.php

    r10130 r10169  
    33namespace WPOrg_Learn;
    44
    5 class Shortcodes{
     5class Shortcodes {
    66
    77        private static $auth_token;
     
    2323                }
    2424                $filter_label = isset( $atts['label'] ) ? $atts['label'] : '';
    25                 $out = '<h2>' . sprintf( 'Issues labeled "%s"', esc_html( $filter_label ) ) . '</h2>';
    26                 $url = 'https://api.github.com/orgs/wptrainingteam/issues';
    27                 $url = add_query_arg( array_map( 'rawurlencode', array(
     25                $out          = '<h2>' . sprintf( 'Issues labeled "%s"', esc_html( $filter_label ) ) . '</h2>';
     26                $url          = 'https://api.github.com/orgs/wptrainingteam/issues';
     27                $url          = add_query_arg( array_map( 'rawurlencode', array(
    2828                        'per_page' => 100,
    2929                        'labels'   => $filter_label,
    3030                        'filter'   => 'all',
    3131                ) ), $url );
    32                 $issues = self::github_request( $url );
     32                $issues       = self::github_request( $url );
    3333                if ( is_wp_error( $issues ) ) {
    3434                        $out .= '<p>' . esc_html( $issues->get_error_message() ) . '</p>' . PHP_EOL;
     
    6060                                $out .= '<li><a href="' . esc_url( $issue->html_url ) . '">' . esc_html( $issue->title ) . '</a><br />' . PHP_EOL;
    6161                                if ( ! empty( $issue->labels ) ) {
    62                                         foreach( $issue->labels as $label ) {
     62                                        foreach ( $issue->labels as $label ) {
    6363                                                if ( $label->name === $filter_label ) {
    6464                                                        continue;
    6565                                                }
    66                                                 $text_color = '#FFF';
     66                                                $text_color       = '#FFF';
    6767                                                $background_color = $label->color;
    68                                                 $c_r = hexdec( substr( $background_color, 0, 2 ) );
    69                                                 $c_g = hexdec( substr( $background_color, 2, 2 ) );
    70                                                 $c_b = hexdec( substr( $background_color, 4, 2 ) );
     68                                                $c_r              = hexdec( substr( $background_color, 0, 2 ) );
     69                                                $c_g              = hexdec( substr( $background_color, 2, 2 ) );
     70                                                $c_b              = hexdec( substr( $background_color, 4, 2 ) );
    7171                                                // Light background means dark color
    7272                                                if ( ( ( ( $c_r * 299 ) + ( $c_g * 587 ) + ( $c_b * 114 ) ) / 1000 ) > 135 ) {
     
    9393                }
    9494
    95                 $out = '<h2>Repositories</h2>';
     95                $out   = '<h2>Repositories</h2>';
    9696                $repos = self::github_request( 'https://api.github.com/orgs/wptrainingteam/repos?per_page=100' );
    9797                if ( is_wp_error( $repos ) ) {
     
    100100                }
    101101                $repo_list = array();
    102                 foreach( $repos as $repo ) {
     102                foreach ( $repos as $repo ) {
    103103                        if ( ! preg_match( '#^wptrainingteam/.+-command$#', $repo->full_name ) ) {
    104104                                continue;
     
    116116                $out .= '</tr>' . PHP_EOL;
    117117                $out .= '</thead>' . PHP_EOL;
    118                 foreach( $repo_list as $i => $repo_name ) {
     118                foreach ( $repo_list as $i => $repo_name ) {
    119119                        $out .= '<tr>' . PHP_EOL;
    120120                        // Name
     
    123123                        $out .= '<td><ul>' . PHP_EOL;
    124124                        // Overview: Active milestone
    125                         $url = sprintf( 'https://api.github.com/repos/%s/milestones', $repo_name );
    126                         $milestones = self::github_request( $url );
     125                        $url              = sprintf( 'https://api.github.com/repos/%s/milestones', $repo_name );
     126                        $milestones       = self::github_request( $url );
    127127                        $latest_milestone = '<em>None</em>';
    128128                        if ( is_wp_error( $milestones ) ) {
    129129                                $latest_milestone = $milestones->get_error_message();
    130130                        } elseif ( ! empty( $milestones ) ) {
    131                                 $milestones = array_shift( $milestones );
     131                                $milestones       = array_shift( $milestones );
    132132                                $latest_milestone = '<a href="' . esc_url( $milestones->html_url ) . '">v' . esc_html( $milestones->title ) . '</a> (' . (int) $milestones->open_issues . ' open, ' . (int) $milestones->closed_issues . ' closed)';
    133133                        }
    134134                        $out .= '<li>Active: ' . wp_kses_post( $latest_milestone ) . '</li>';
    135135                        // Overview: Latest release
    136                         $url = sprintf( 'https://api.github.com/repos/%s/releases', $repo_name );
    137                         $releases = self::github_request( $url );
     136                        $url            = sprintf( 'https://api.github.com/repos/%s/releases', $repo_name );
     137                        $releases       = self::github_request( $url );
    138138                        $latest_release = '<em>None</em>';
    139139                        if ( is_wp_error( $releases ) ) {
    140140                                $latest_release = $releases->get_error_message();
    141141                        } elseif ( ! empty( $releases ) ) {
    142                                 $releases = array_shift( $releases );
     142                                $releases       = array_shift( $releases );
    143143                                $latest_release = '<a href="' . esc_url( $releases->html_url ) . '">' . esc_html( $releases->tag_name ) . '</a>';
    144144                        }
     
    149149                        if ( 'wp-cli/dist-archive-command' === $repo_name ) {
    150150                                $status_image = sprintf( 'https://circleci.com/gh/%s/tree/master.svg?style=svg', $repo_name );
    151                                 $status_link = sprintf( 'https://circleci.com/gh/%s/tree/master', $repo_name );
     151                                $status_link  = sprintf( 'https://circleci.com/gh/%s/tree/master', $repo_name );
    152152                        } else {
    153153                                $status_image = sprintf( 'https://travis-ci.org/%s.svg?branch=master', $repo_name );
    154                                 $status_link = sprintf( 'https://travis-ci.org/%s/branches', $repo_name );
     154                                $status_link  = sprintf( 'https://travis-ci.org/%s/branches', $repo_name );
    155155                        }
    156                         $out .= '<td><a href="' . esc_url( $status_link ) . '"><img src="' . esc_url( $status_image ) . '">' . '</a></td>' . PHP_EOL;
     156                        $out .= '<td><a href="' . esc_url( $status_link ) . '"><img src="' . esc_url( $status_image ) . '"></a></td>' . PHP_EOL;
    157157                        $out .= '</tr>' . PHP_EOL;
    158158                }
     
    165165         */
    166166        private static function github_request( $url ) {
    167 
    168                 $cache_key = 'cli_github_' . md5( $url );
    169                 if ( false !== ( $cache_value = get_transient( $cache_key ) ) ) {
     167                $cache_key   = 'cli_github_' . md5( $url );
     168                $cache_value = get_transient( $cache_key );
     169                if ( false !== $cache_value ) {
    170170                        return $cache_value;
    171171                }
     
    175175                                'Accept'     => 'application/vnd.github.v3+json',
    176176                                'User-Agent' => 'WordPress.org / WP-CLI',
    177                         )
     177                        ),
    178178                );
    179179                if ( isset( self::$auth_token ) ) {
     
    193193                return $data;
    194194        }
    195 
    196195}
Note: See TracChangeset for help on using the changeset viewer.