Changeset 677
- Timestamp:
- 06/05/2014 09:46:52 PM (10 years ago)
- Location:
- sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/content-reference.php
r676 r677 29 29 ?> 30 30 <section class="source"> 31 <p><strong><?php _e( 'Source file:', 'wporg' ); ?> </strong><a href="<?php echo get_source_file_archive_link( $source_file ); ?>"><?php echo esc_html( $source_file ); ?></a></p> 32 <p><a href="<?php echo get_source_file_link(); ?>"><?php _e( 'View source…', 'wporg' ); ?></a></p> 31 <p> 32 <strong><?php _e( 'Source file:', 'wporg' ); ?></strong> 33 <a href="<?php echo get_source_file_archive_link( $source_file ); ?>"><?php echo esc_html( $source_file ); ?></a><br /> 34 <strong><?php _e( 'View source code:', 'wporg' ); ?></strong> 35 <?php if ( post_type_has_source_code() ) { ?> 36 <a href="#source-code"><?php _e( 'below', 'wporg' ); ?></a> or 37 <?php } ?> 38 <a href="<?php echo get_source_file_link(); ?>"><?php _e( 'on the WP Trac code browser…', 'wporg' ); ?></a> 39 </p> 33 40 </section> 34 41 <?php endif; ?> … … 117 124 endif; ?> 118 125 119 <?php if ( 'wp-parser-function' === get_post_type() || 'wp-parser-method' === get_post_type() ) : ?>126 <?php if ( post_type_has_source_code() ) : ?> 120 127 <hr /> 128 <a id="source-code"></a> 121 129 <section class="source-content"> 122 130 <h2><?php _e( 'Source', 'wporg' ); ?></h2> … … 124 132 <pre class="brush: php; toolbar: false;"><?php echo esc_html( get_source_code() ); ?></pre> 125 133 </div> 126 <p><a href="#" class="show-complete-source"><?php _e( 'View full source code…', 'wporg -developer' ); ?></a></p>134 <p><a href="#" class="show-complete-source"><?php _e( 'View full source code…', 'wporg' ); ?></a></p> 127 135 </section> 128 136 <?php endif; ?> -
sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/content-wp-parser-hook.php
r657 r677 27 27 ?> 28 28 <section class="source"> 29 <p><strong><?php _e( 'Source file:', 'wporg' ); ?> </strong><a href="<?php echo get_source_file_archive_link( $source_file ); ?>"><?php echo esc_html( $source_file ); ?></a></p> 30 <p><a href="<?php echo get_source_file_link(); ?>"><?php _e( 'View source…', 'wporg' ); ?></a></p> 29 <p> 30 <strong><?php _e( 'Source file:', 'wporg' ); ?></strong> 31 <a href="<?php echo get_source_file_archive_link( $source_file ); ?>"><?php echo esc_html( $source_file ); ?></a><br /> 32 <strong><?php _e( 'View source code:', 'wporg' ); ?></strong> 33 <a href="<?php echo get_source_file_link(); ?>"><?php _e( 'on the WP Trac code browser…', 'wporg' ); ?></a> 34 </p> 31 35 </section> 32 36 <?php endif; ?> -
sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/functions.php
r676 r677 344 344 wp_enqueue_script( 'wporg-developer-skip-link-focus-fix', get_template_directory_uri() . '/js/skip-link-focus-fix.js', array(), '20130115', true ); 345 345 346 if ( 'wp-parser-function' === get_post_type() || 'wp-parser-method' === get_post_type() ) {346 if ( post_type_has_source_code() ) { 347 347 wp_enqueue_script( 'wporg-developer-function-reference', get_template_directory_uri() . '/js/function-reference.js', array( 'jquery', 'syntaxhighlighter-core', 'syntaxhighlighter-brush-php' ), '20140515', true ); 348 348 wp_enqueue_style( 'syntaxhighlighter-core' ); -
sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/inc/template-tags.php
r676 r677 640 640 641 641 /** 642 * Retrieve source code for a function 643 * 644 * @param int $post_id 645 * 646 * @return string The sourc 647 */ 648 function get_source_code( $post_id = null ) { 642 * Does the post type have source code? 643 * 644 * @param string Optional. The post type name. If blank, assumes current post type. 645 * 646 * @return boolean 647 */ 648 function post_type_has_source_code( $post_type = null ) { 649 $post_type = $post_type ? $post_type : get_post_type(); 650 $post_types_with_source_code = array( 'wp-parser-method', 'wp-parser-function' ); 651 652 return in_array( $post_type, $post_types_with_source_code ); 653 } 654 655 /** 656 * Retrieve the root directory of the parsed WP code. 657 * 658 * If the option 'wp_parser_root_import_dir' (as set by the parser) is not 659 * set, then assume ABSPATH. 660 * 661 * @return string 662 */ 663 function get_source_code_root_dir() { 664 $root_dir = get_option( 'wp_parser_root_import_dir' ); 665 666 return $root_dir ? trailingslashit( $root_dir ) : ABSPATH; 667 } 668 669 /** 670 * Retrieve source code for a function or method. 671 * 672 * @param int $post_id Optional. The post ID. 673 * @param bool $force_parse Optional. Ignore potential value in post meta and reparse source file for source code? 674 * 675 * @return string The source code. 676 */ 677 function get_source_code( $post_id = null, $force_parse = false ) { 649 678 650 679 if ( empty( $post_id ) ) { … … 652 681 } 653 682 654 // Get the total file sourcecode. 683 // Get the source code stored in post meta. 684 $meta_key = '_wp-parser_source_code'; 685 if ( ! $force_parse && $source_code = get_post_meta( $post_id, $meta_key, true ) ) { 686 return $source_code; 687 } 688 689 /* Source code hasn't been stored in post meta, so parse source file to get it. */ 690 691 // Get the name of the source file. 655 692 $source_file = get_source_file( $post_id ); 656 693 657 // Put the total source code in an array.658 $total_source_code = file_get_contents( ABSPATH . $source_file );659 $total_source_code = explode( "\n", $total_source_code );660 661 694 // Get the start and end lines. 662 $start_line = get_post_meta( $post_id, '_wp-parser_line_num', true ) - 1; 663 $end_line = get_post_meta( $post_id, '_wp-parser_end_line_num', true ); 664 665 // Get the correct source code. 666 $source_code = array_slice( $total_source_code, $start_line, $end_line - $start_line ); 667 668 return implode( "\n", $source_code ); 695 $start_line = intval( get_post_meta( $post_id, '_wp-parser_line_num', true ) ) - 1; 696 $end_line = intval( get_post_meta( $post_id, '_wp-parser_end_line_num', true ) ); 697 698 // Sanity check to ensure proper conditions exist for parsing 699 if ( ! $source_file || ! $start_line || ! $end_line || ( $start_line > $end_line ) ) { 700 return ''; 701 } 702 703 // Find just the relevant source code 704 $source_code = ''; 705 $handle = @fopen( get_source_code_root_dir() . $source_file, 'r' ); 706 if ( $handle ) { 707 $line = -1; 708 while ( ! feof( $handle ) ) { 709 $line++; 710 $source_line = fgets( $handle ); 711 if ( $line > $end_line ) { 712 break; 713 } 714 if ( $line < $start_line ) { 715 continue; 716 } 717 $source_code .= $source_line; 718 } 719 fclose( $handle ); 720 } 721 722 update_post_meta( $post_id, $meta_key, $source_code ); 723 724 return $source_code; 669 725 } 670 726 -
sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/js/function-reference.js
r676 r677 10 10 e.preventDefault(); 11 11 12 var heightGoal = $sourceCodeTable.height() + 17;12 var heightGoal = $sourceCodeTable.height() + 47; // takes into consideration potential x-scrollbar 13 13 14 14 $sourceCodeContainer.animate( { height: heightGoal + 'px' } ); … … 28 28 $sourceCodeTable = $sourceContent.find( 'table' ); 29 29 30 if ( 18 6< $sourceCodeTable.height() ) {30 if ( 188 < $sourceCodeTable.height() ) { 31 31 32 32 // Do this with javascript so javascript-less can enjoy the total sourcecode 33 // 1em (margin) + 10 * 17px. Lines are 1.1em which rounds to 17px: calc( 1em + 17px * 10 ). 34 $sourceCodeContainer.css( { height: '186px' } ); 33 // 1em (margin) + 20 * 17px. Lines are 1.1em which rounds to 17px: calc( 1em + 17px * 20 ). 34 // Extra 10px added to partially show next line so it's clear there is more. 35 $( '.source-code-container' ).css( { height: '196px' } ); 35 36 36 37 $showCompleteSource = $( '.show-complete-source' ); … … 39 40 $showCompleteSource.on( 'click', showCompleteSource ); 40 41 } 42 41 43 } 42 44 -
sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/scss/main.scss
r676 r677 857 857 858 858 .source-code-container { 859 overflow: hidden; 859 border-right: 1px solid #dfdfdf; 860 overflow-x: auto; 861 overflow-y: hidden; 860 862 } 861 863 -
sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/stylesheets/main.css
r676 r677 1069 1069 } 1070 1070 .devhub-wrap .source-code-container { 1071 overflow: hidden; 1071 border-right: 1px solid #dfdfdf; 1072 overflow-x: auto; 1073 overflow-y: hidden; 1072 1074 } 1073 1075 .devhub-wrap .show-complete-source {
Note: See TracChangeset
for help on using the changeset viewer.