Changeset 10169 for sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-learn/inc/class-shortcodes.php
- Timestamp:
- 08/13/2020 11:43:14 PM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-learn/inc/class-shortcodes.php
r10130 r10169 3 3 namespace WPOrg_Learn; 4 4 5 class Shortcodes {5 class Shortcodes { 6 6 7 7 private static $auth_token; … … 23 23 } 24 24 $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( 28 28 'per_page' => 100, 29 29 'labels' => $filter_label, 30 30 'filter' => 'all', 31 31 ) ), $url ); 32 $issues = self::github_request( $url );32 $issues = self::github_request( $url ); 33 33 if ( is_wp_error( $issues ) ) { 34 34 $out .= '<p>' . esc_html( $issues->get_error_message() ) . '</p>' . PHP_EOL; … … 60 60 $out .= '<li><a href="' . esc_url( $issue->html_url ) . '">' . esc_html( $issue->title ) . '</a><br />' . PHP_EOL; 61 61 if ( ! empty( $issue->labels ) ) { 62 foreach ( $issue->labels as $label ) {62 foreach ( $issue->labels as $label ) { 63 63 if ( $label->name === $filter_label ) { 64 64 continue; 65 65 } 66 $text_color = '#FFF';66 $text_color = '#FFF'; 67 67 $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 ) ); 71 71 // Light background means dark color 72 72 if ( ( ( ( $c_r * 299 ) + ( $c_g * 587 ) + ( $c_b * 114 ) ) / 1000 ) > 135 ) { … … 93 93 } 94 94 95 $out = '<h2>Repositories</h2>';95 $out = '<h2>Repositories</h2>'; 96 96 $repos = self::github_request( 'https://api.github.com/orgs/wptrainingteam/repos?per_page=100' ); 97 97 if ( is_wp_error( $repos ) ) { … … 100 100 } 101 101 $repo_list = array(); 102 foreach ( $repos as $repo ) {102 foreach ( $repos as $repo ) { 103 103 if ( ! preg_match( '#^wptrainingteam/.+-command$#', $repo->full_name ) ) { 104 104 continue; … … 116 116 $out .= '</tr>' . PHP_EOL; 117 117 $out .= '</thead>' . PHP_EOL; 118 foreach ( $repo_list as $i => $repo_name ) {118 foreach ( $repo_list as $i => $repo_name ) { 119 119 $out .= '<tr>' . PHP_EOL; 120 120 // Name … … 123 123 $out .= '<td><ul>' . PHP_EOL; 124 124 // 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 ); 127 127 $latest_milestone = '<em>None</em>'; 128 128 if ( is_wp_error( $milestones ) ) { 129 129 $latest_milestone = $milestones->get_error_message(); 130 130 } elseif ( ! empty( $milestones ) ) { 131 $milestones = array_shift( $milestones );131 $milestones = array_shift( $milestones ); 132 132 $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)'; 133 133 } 134 134 $out .= '<li>Active: ' . wp_kses_post( $latest_milestone ) . '</li>'; 135 135 // 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 ); 138 138 $latest_release = '<em>None</em>'; 139 139 if ( is_wp_error( $releases ) ) { 140 140 $latest_release = $releases->get_error_message(); 141 141 } elseif ( ! empty( $releases ) ) { 142 $releases = array_shift( $releases );142 $releases = array_shift( $releases ); 143 143 $latest_release = '<a href="' . esc_url( $releases->html_url ) . '">' . esc_html( $releases->tag_name ) . '</a>'; 144 144 } … … 149 149 if ( 'wp-cli/dist-archive-command' === $repo_name ) { 150 150 $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 ); 152 152 } else { 153 153 $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 ); 155 155 } 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; 157 157 $out .= '</tr>' . PHP_EOL; 158 158 } … … 165 165 */ 166 166 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 ) { 170 170 return $cache_value; 171 171 } … … 175 175 'Accept' => 'application/vnd.github.v3+json', 176 176 'User-Agent' => 'WordPress.org / WP-CLI', 177 ) 177 ), 178 178 ); 179 179 if ( isset( self::$auth_token ) ) { … … 193 193 return $data; 194 194 } 195 196 195 }
Note:
See TracChangeset
for help on using the changeset viewer.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)