Changeset 1045
- Timestamp:
- 12/16/2014 08:15:00 PM (10 years ago)
- Location:
- sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer
- Files:
-
- 1 added
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/functions.php
r1039 r1045 55 55 */ 56 56 require __DIR__ . '/inc/redirects.php'; 57 58 /** 59 * Content formatting. 60 */ 61 require __DIR__ . '/inc/formatting.php'; 57 62 58 63 /** … … 80 85 add_theme_support( 'automatic-feed-links' ); 81 86 add_theme_support( 'post-thumbnails' ); 82 83 add_filter( 'the_excerpt', __NAMESPACE__ . '\\lowercase_P_dangit_just_once' );84 add_filter( 'the_content', __NAMESPACE__ . '\\make_doclink_clickable', 10, 5 );85 87 86 88 // Add the handbook's 'Watch' action link. … … 422 424 wp_enqueue_script( 'wporg-developer-search', get_template_directory_uri() . '/js/search.js', array(), '20141029', true ); 423 425 } 424 425 /**426 * Allows for "Wordpress" just for the excerpt value of the capital_P_dangit function.427 *428 * WP.org has a global output buffer that runs capital_P_dangit() over displayed429 * content. For this one field of this one post, circumvent that function to430 * to show the lowercase P.431 *432 * @param string $excerpt The post excerpt.433 * @return string434 */435 function lowercase_P_dangit_just_once( $excerpt ) {436 if ( 'wp-parser-function' == get_post_type() && 'capital_P_dangit' == get_the_title() ) {437 $excerpt = str_replace( 'Wordpress', 'Wordpress', $excerpt );438 }439 440 return $excerpt;441 }442 443 /**444 * Makes phpDoc @link references clickable.445 *446 * Handles these five different types of links:447 *448 * - {@link http://en.wikipedia.org/wiki/ISO_8601}449 * - {@link WP_Rewrite::$index}450 * - {@link WP_Query::query()}451 * - {@link esc_attr()}452 * - {@link http://codex.wordpress.org/The_Loop Use new WordPress Loop}453 *454 * @param string $content The content.455 * @return string456 */457 function make_doclink_clickable( $content ) {458 459 // Nothing to change unless a @link or @see reference is in the text.460 if ( false === strpos( $content, '{@link ' ) && false === strpos( $content, '{@see ' ) ) {461 return $content;462 }463 464 return preg_replace_callback(465 '/\{@(?:link|see) ([^\}]+)\}/',466 function ( $matches ) {467 468 $link = $matches[1];469 470 // Undo links made clickable during initial parsing471 if ( 0 === strpos( $link, '<a ' ) ) {472 473 if ( preg_match( '/^<a .*href=[\'\"]([^\'\"]+)[\'\"]>(.*)<\/a>(.*)$/', $link, $parts ) ) {474 $link = $parts[1];475 if ( $parts[3] ) {476 $link .= ' ' . $parts[3];477 }478 }479 480 }481 482 // Link to an external resource.483 if ( 0 === strpos( $link, 'http' ) ) {484 485 $parts = explode( ' ', $link, 2 );486 487 // Link without linked text: {@link http://en.wikipedia.org/wiki/ISO_8601}488 if ( 1 === count( $parts ) ) {489 $link = '<a href="' . esc_url( $link ) . '">' . esc_html( $link ) . '</a>';490 }491 492 // Link with linked text: {@link http://codex.wordpress.org/The_Loop Use new WordPress Loop}493 else {494 $link = '<a href="' . esc_url( $parts[0] ) . '">' . esc_html( $parts[1] ) . '</a>';495 }496 497 }498 499 // Link to an internal resource.500 else {501 502 // Link to class variable: {@link WP_Rewrite::$index}503 if ( false !== strpos( $link, '::$' ) ) {504 // Nothing to link to currently.505 }506 507 // Link to class method: {@link WP_Query::query()}508 elseif ( false !== strpos( $link, '::' ) ) {509 $link = '<a href="' .510 get_post_type_archive_link( 'wp-parser-class' ) .511 str_replace( array( '::', '()' ), array( '/', '' ), $link ) .512 '">' . esc_html( $link ) . '</a>';513 }514 515 // Link to hook: {@see 'pre_get_search_form'}516 elseif ( 1 === preg_match( '/^(‘)\w+(’)$/', $link, $hook ) ) {517 if ( ! empty( $hook[0] ) ) {518 $link = '<a href="' .519 get_post_type_archive_link( 'wp-parser-hook' ) .520 str_replace( array( '‘', '’' ), '', $link ) .521 '">' . esc_html( $link ) . '</a>';522 }523 }524 525 // Link to function: {@link esc_attr()}526 else {527 $link = '<a href="' .528 get_post_type_archive_link( 'wp-parser-function' ) .529 str_replace( '()', '', $link ) .530 '">' . esc_html( $link ) . '</a>';531 }532 533 }534 535 return $link;536 },537 $content538 );539 } -
sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/inc/template-tags.php
r1040 r1045 597 597 } 598 598 $params[ $tag['variable'] ]['content'] = htmlentities( $params[ $tag['variable'] ]['content'] ); 599 $params[ $tag['variable'] ]['content'] = make_doclink_clickable( $params[ $tag['variable'] ]['content'] );599 $params[ $tag['variable'] ]['content'] = \DevHub_Formatting::make_doclink_clickable( $params[ $tag['variable'] ]['content'] ); 600 600 } 601 601 }
Note: See TracChangeset
for help on using the changeset viewer.