Make WordPress Core

Ticket #9184: 9184.diff

File 9184.diff, 5.8 KB (added by beaulebens, 17 years ago)

Made the for() loop more efficient. Props jacobsantos

  • wp-admin/includes/misc.php

     
    238238        echo "<p>$message</p>\n";
    239239}
    240240
     241function wp_doc_link_parse( $content ) {
     242        if ( !is_string( $content ) || empty( $content ) )
     243                return array();
     244               
     245        $tokens = token_get_all( $content );
     246        $functions = array();
     247        $ignore_functions = array();
     248        for ( $t = 0, $count = count( $tokens ); $t < $count; $t++ ) {
     249                if ( !is_array( $tokens[$t] ) ) continue;
     250                if ( T_STRING == $tokens[$t][0] && ( '(' == $tokens[ $t + 1 ] || '(' == $tokens[ $t + 2 ] ) ) {
     251                        // If it's a function or class defined locally, there's not going to be any docs available
     252                        if ( 'class' == $tokens[ $t - 2 ][1] || 'function' == $tokens[ $t - 2 ][1] || T_OBJECT_OPERATOR == $tokens[ $t - 1 ][0] ) {
     253                                $ignore_functions[] = $tokens[$t][1];
     254                        }
     255                        // Add this to our stack of unique references
     256                        $functions[] = $tokens[$t][1];
     257                }
     258        }
     259       
     260        $functions = array_unique( $functions );
     261        sort( $functions );
     262        $ignore_functions = apply_filters( 'documentation_ignore_functions', $ignore_functions );
     263        $ignore_functions = array_unique( $ignore_functions );
     264       
     265        $out = array();
     266        foreach ( $functions as $function ) {
     267                if ( in_array( $function, $ignore_functions ) )
     268                        continue;
     269                $out[] = $function;
     270        }
     271       
     272        return $out;
     273}
     274
    241275?>
  • wp-admin/theme-editor.php

     
    8787        if (!$error && filesize($real_file) > 0) {
    8888                $f = fopen($real_file, 'r');
    8989                $content = fread($f, filesize($real_file));
    90                 $content = htmlspecialchars($content);
     90
     91                if ( 'php' == mb_substr( $real_file, mb_strrpos( $real_file, '.' ) + 1 ) ) {
     92                        $functions = wp_doc_link_parse( $content );
     93                       
     94                        $docs_select = '<select name="docs-list" id="docs-list">';
     95                        $docs_select .= '<option value="">' . __( 'Function Name...' ) . '</option>';
     96                        foreach ( $functions as $function) {                                   
     97                                $docs_select .= '<option value="' . urlencode( $function ) . '">' . htmlspecialchars( $function ) . '()</option>';
     98                        }
     99                        $docs_select .= '</select>';
     100                }
     101
     102                $content = htmlspecialchars( $content );
    91103        }
    92104
    93105        ?>
     
    187199                 <input type="hidden" name="file" value="<?php echo $file ?>" />
    188200                 <input type="hidden" name="theme" value="<?php echo $theme ?>" />
    189201                 </div>
     202                <?php if ( count( $functions ) ) : ?>
     203                <div id="documentation"><label for="docs-list">Documentation:</label> <?php echo $docs_select ?> <input type="button" class="button" value=" <?php _e( 'Lookup' ) ?> " onclick="if ( '' != jQuery('#docs-list').val() ) { window.open( 'http://api.wordpress.org/core/handbook/1.0/?function=' + escape( jQuery( '#docs-list' ).val() ) + '&locale=<?php echo urlencode( get_locale() ) ?>&version=<?php echo urlencode( $wp_version ) ?>&redirect=true'); }" /></div>
     204                <?php endif; ?>
    190205
    191206                <div>
    192207<?php if ( is_writeable($real_file) ) : ?>
  • wp-admin/css/theme-editor.css

     
    6464div.tablenav {
    6565        margin-right: 210px;
    6666}
     67
     68#documentation {
     69        margin-top: 10px;
     70}
     71#documentation label {
     72        line-height: 22px;
     73        vertical-align: top;
     74        font-weight: bold;
     75}
     76 No newline at end of file
  • wp-admin/plugin-editor.php

     
    8181        if ( ! is_file($real_file) )
    8282                $error = 1;
    8383
    84         if ( ! $error )
    85                 $content = htmlspecialchars(file_get_contents($real_file));
     84        if ( ! $error ) {
     85                $content = file_get_contents( $real_file );
     86               
     87                if ( 'php' == mb_substr( $real_file, mb_strrpos( $real_file, '.' ) + 1 ) ) {
     88                        $functions = wp_doc_link_parse( $content );
     89                       
     90                        $docs_select = '<select name="docs-list" id="docs-list">';
     91                        $docs_select .= '<option value="">' . __( 'Function Name...' ) . '</option>';
     92                        foreach ( $functions as $function) {
     93                                $docs_select .= '<option value="' . urlencode( $function ) . '">' . htmlspecialchars( $function ) . '()</option>';
     94                        }
     95                        $docs_select .= '</select>';
     96                }
     97               
     98                $content = htmlspecialchars( $content );
     99        }
    86100
    87101        ?>
    88102<?php if (isset($_GET['a'])) : ?>
     
    124138        <h4><?php _e('Plugins'); ?></h4>
    125139        <ul>
    126140<?php foreach($plugin_files as $plugin_file) : ?>
    127                 <li><a href="plugin-editor.php?file=<?php echo $plugin_file; ?>"><?php echo $plugins[$plugin_file]['Name']; ?></a></li>
     141                <li<?php echo $file == $plugin_file ? ' class="highlight"' : ''; ?>><a href="plugin-editor.php?file=<?php echo $plugin_file; ?>"><?php echo $plugins[$plugin_file]['Name']; ?></a></li>
    128142<?php endforeach; ?>
    129143        </ul>
    130144        </div>
     
    135149                <input type="hidden" name="action" value="update" />
    136150                <input type="hidden" name="file" value="<?php echo $file ?>" />
    137151                </div>
     152                <?php if ( count( $functions ) ) : ?>
     153                <div id="documentation"><label for="docs-list">Documentation:</label> <?php echo $docs_select ?> <input type="button" class="button" value=" <?php _e( 'Lookup' ) ?> " onclick="if ( '' != jQuery('#docs-list').val() ) { window.open( 'http://api.wordpress.org/core/handbook/1.0/?function=' + escape( jQuery( '#docs-list' ).val() ) + '&locale=<?php echo urlencode( get_locale() ) ?>&version=<?php echo urlencode( $wp_version ) ?>&redirect=true'); }" /></div>
     154                <?php endif; ?>
    138155<?php if ( is_writeable($real_file) ) : ?>
    139156        <?php if ( in_array($file, (array) get_option('active_plugins')) ) { ?>
    140157                <p><?php _e('<strong>Warning:</strong> Making changes to active plugins is not recommended.  If your changes cause a fatal error, the plugin will be automatically deactivated.'); ?></p>