From 4399d9f7f9a5f84bd62a2a4ee41e5e6a2383d913 Mon Sep 17 00:00:00 2001 From: ryan Date: Fri, 20 Feb 2009 20:00:09 +0000 Subject: [PATCH] Add documentation lookup shortcuts to Theme and Plugin Editors. Props beaulebens. fixes #9184 git-svn-id: http://svn.automattic.com/wordpress/trunk@10607 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-admin/css/theme-editor.css | 9 +++++++++ wp-admin/includes/misc.php | 34 ++++++++++++++++++++++++++++++++++ wp-admin/plugin-editor.php | 23 ++++++++++++++++++++--- wp-admin/theme-editor.php | 17 ++++++++++++++++- 4 files changed, 79 insertions(+), 4 deletions(-) diff --git a/wp-admin/css/theme-editor.css b/wp-admin/css/theme-editor.css index 486f5c192..2f938d84f 100644 --- a/wp-admin/css/theme-editor.css +++ b/wp-admin/css/theme-editor.css @@ -64,3 +64,12 @@ div.bordertitle h2 { div.tablenav { margin-right: 210px; } + +#documentation { + margin-top: 10px; +} +#documentation label { + line-height: 22px; + vertical-align: top; + font-weight: bold; +} \ No newline at end of file diff --git a/wp-admin/includes/misc.php b/wp-admin/includes/misc.php index ffb849704..f5c15df4c 100644 --- a/wp-admin/includes/misc.php +++ b/wp-admin/includes/misc.php @@ -238,4 +238,38 @@ function show_message($message) { echo "

$message

\n"; } +function wp_doc_link_parse( $content ) { + if ( !is_string( $content ) || empty( $content ) ) + return array(); + + $tokens = token_get_all( $content ); + $functions = array(); + $ignore_functions = array(); + for ( $t = 0, $count = count( $tokens ); $t < $count; $t++ ) { + if ( !is_array( $tokens[$t] ) ) continue; + if ( T_STRING == $tokens[$t][0] && ( '(' == $tokens[ $t + 1 ] || '(' == $tokens[ $t + 2 ] ) ) { + // If it's a function or class defined locally, there's not going to be any docs available + if ( 'class' == $tokens[ $t - 2 ][1] || 'function' == $tokens[ $t - 2 ][1] || T_OBJECT_OPERATOR == $tokens[ $t - 1 ][0] ) { + $ignore_functions[] = $tokens[$t][1]; + } + // Add this to our stack of unique references + $functions[] = $tokens[$t][1]; + } + } + + $functions = array_unique( $functions ); + sort( $functions ); + $ignore_functions = apply_filters( 'documentation_ignore_functions', $ignore_functions ); + $ignore_functions = array_unique( $ignore_functions ); + + $out = array(); + foreach ( $functions as $function ) { + if ( in_array( $function, $ignore_functions ) ) + continue; + $out[] = $function; + } + + return $out; +} + ?> diff --git a/wp-admin/plugin-editor.php b/wp-admin/plugin-editor.php index b807de895..9e34ff457 100644 --- a/wp-admin/plugin-editor.php +++ b/wp-admin/plugin-editor.php @@ -81,8 +81,22 @@ default: if ( ! is_file($real_file) ) $error = 1; - if ( ! $error ) - $content = htmlspecialchars(file_get_contents($real_file)); + if ( ! $error ) { + $content = file_get_contents( $real_file ); + + if ( 'php' == mb_substr( $real_file, mb_strrpos( $real_file, '.' ) + 1 ) ) { + $functions = wp_doc_link_parse( $content ); + + $docs_select = ''; + } + + $content = htmlspecialchars( $content ); + } ?> @@ -124,7 +138,7 @@ default:

@@ -135,6 +149,9 @@ default: + +
+

Warning: Making changes to active plugins is not recommended. If your changes cause a fatal error, the plugin will be automatically deactivated.'); ?>

diff --git a/wp-admin/theme-editor.php b/wp-admin/theme-editor.php index 361f26b61..c45576862 100644 --- a/wp-admin/theme-editor.php +++ b/wp-admin/theme-editor.php @@ -87,7 +87,19 @@ default: if (!$error && filesize($real_file) > 0) { $f = fopen($real_file, 'r'); $content = fread($f, filesize($real_file)); - $content = htmlspecialchars($content); + + if ( 'php' == mb_substr( $real_file, mb_strrpos( $real_file, '.' ) + 1 ) ) { + $functions = wp_doc_link_parse( $content ); + + $docs_select = ''; + } + + $content = htmlspecialchars( $content ); } ?> @@ -187,6 +199,9 @@ if ($allowed_files) : + +
+