|
| 1 | +<?php |
| 2 | +/* |
| 3 | +Template Name: CLA Verification Results |
| 4 | +*/ |
| 5 | + |
| 6 | +$claData = getData(); |
| 7 | +validateData( $claData ); |
| 8 | + |
| 9 | +get_header(); |
| 10 | + |
| 11 | +?> |
| 12 | +<div class="content-right twelve columns"> |
| 13 | + <div id="content"> |
| 14 | + <h1 class="entry-title"><?php the_title(); ?></h1> |
| 15 | + <hr> |
| 16 | + |
| 17 | + <?php echo getProcessedPost( $claData ); ?> |
| 18 | + </div> |
| 19 | + <?php get_sidebar(); ?> |
| 20 | +</div> |
| 21 | +<?php |
| 22 | + |
| 23 | +get_footer(); |
| 24 | + |
| 25 | + |
| 26 | + |
| 27 | + |
| 28 | +function getData() { |
| 29 | + $repo = empty( $_GET[ 'repo' ] ) ? null : $_GET[ 'repo' ]; |
| 30 | + $sha = empty( $_GET[ 'sha' ] ) ? null : $_GET[ 'sha' ]; |
| 31 | + |
| 32 | + if ( is_null( $repo ) || is_null( $sha ) ) { |
| 33 | + return null; |
| 34 | + } |
| 35 | + |
| 36 | + $path = "output/$repo/" . substr( $sha, 0, 2 ) . "/$sha.json"; |
| 37 | + $data = @file_get_contents( JQUERY_CLA_SERVER_URL . "/$path" ); |
| 38 | + $data = json_decode( $data ); |
| 39 | + $data->repo = $repo; |
| 40 | + return $data; |
| 41 | +} |
| 42 | + |
| 43 | +function validateData( $data ) { |
| 44 | + if ( is_null( $data ) ) { |
| 45 | + global $wp_query; |
| 46 | + $wp_query->set_404(); |
| 47 | + status_header(404); |
| 48 | + get_template_part( 404 ); |
| 49 | + exit(); |
| 50 | + } |
| 51 | +} |
| 52 | + |
| 53 | +function getProcessedPost( $data ) { |
| 54 | + the_post(); |
| 55 | + $content = get_the_content(); |
| 56 | + |
| 57 | + if ( count( $data->neglectedAuthors ) ) { |
| 58 | + $content = preg_replace( "/<!-- ifsuccess -->.*<!-- endifsuccess -->/s", '', $content ); |
| 59 | + $content = preg_replace( "/<!-- neglected-authors -->/", neglectedAuthors( $data ), $content ); |
| 60 | + } else { |
| 61 | + $content = preg_replace( "/<!-- iferror -->.*<!-- endiferror -->/s", '', $content ); |
| 62 | + } |
| 63 | + |
| 64 | + $content = preg_replace( "/<!-- commit-log -->/", commitLog( $data ), $content ); |
| 65 | + |
| 66 | + return $content; |
| 67 | +} |
| 68 | + |
| 69 | +function neglectedAuthors( $data ) { |
| 70 | + $html = "<ul>\n"; |
| 71 | + foreach ( $data->neglectedAuthors as $author ) { |
| 72 | + $html .= "<li>" . htmlspecialchars( "$author->name <$author->email>" ) . "</li>\n"; |
| 73 | + } |
| 74 | + $html .= "</ul>\n"; |
| 75 | + return $html; |
| 76 | +} |
| 77 | + |
| 78 | +function commitLog( $data ) { |
| 79 | + $commitPrefix = "http://github.com/jquery/$data->repo/commit/"; |
| 80 | + |
| 81 | + $html = "<dl>\n"; |
| 82 | + foreach ( $data->commits as $commit ) { |
| 83 | + $html .= "<dt><a href='$commitPrefix$commit->hash'>$commit->hash</a></dt>\n"; |
| 84 | + $html .= "<dd>" . htmlspecialchars( "$commit->name <$commit->email>" ) . "</dd\n"; |
| 85 | + } |
| 86 | + $html .= "</dl>\n"; |
| 87 | + return $html; |
| 88 | +} |
0 commit comments