Make WordPress Core


Ignore:
Timestamp:
03/27/2013 08:31:12 AM (12 years ago)
Author:
markjaquith
Message:

Extract chats as structured data.

  • add_chat_detection_format() — to add a chat regex pattern
  • get_content_chat() — to grab a chat from content
  • get_the_chat() — grab the chat from the current (or passed) post
  • the_chat() — output the chat in formatted HTML
  • paginate_content() — puts the <!--nextpage--> splitting stuff into a function
  • get_paged_content() — grabs a page of raw content, needed to paginate chats properly

see #23625. props wonderboymusic, lancewillett.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/query.php

    r23554 r23804  
    36223622    endif;
    36233623}
     3624/**
     3625 * Split the passed content by <!--nextpage-->
     3626 *
     3627 * @since 3.6.0
     3628 *
     3629 * @param string $content Content to split
     3630 * @return array Paged content
     3631 */
     3632function paginate_content( $content ) {
     3633    $content = str_replace( "\n<!--nextpage-->\n", '<!--nextpage-->', $content );
     3634    $content = str_replace( "\n<!--nextpage-->", '<!--nextpage-->', $content );
     3635    $content = str_replace( "<!--nextpage-->\n", '<!--nextpage-->', $content );
     3636    return explode( '<!--nextpage-->', $content);
     3637}
     3638
     3639/**
     3640 * Return content offset by $page
     3641 *
     3642 * @since 3.6.0
     3643 *
     3644 * @param string $content
     3645 * @return string
     3646 */
     3647function get_paged_content( $content = null, $paged = null ) {
     3648    global $page;
     3649    if ( empty( $page ) )
     3650        $page = 1;
     3651
     3652    if ( empty( $paged ) )
     3653        $paged = $page;
     3654
     3655    if ( empty( $content ) ) {
     3656        $post = get_post();
     3657        if ( empty( $post ) )
     3658            return;
     3659
     3660        $content = $post->post_content;
     3661    }
     3662
     3663    $pages = paginate_content( $content );
     3664    if ( isset( $pages[$paged - 1] ) )
     3665        return $pages[$paged - 1];
     3666
     3667    return reset( $pages );
     3668}
    36243669
    36253670/**
Note: See TracChangeset for help on using the changeset viewer.