Skip to:
Content

bbPress.org

Ticket #1298: post-author-layout-2.diff

File post-author-layout-2.diff, 6.8 KB (added by Nightgunner5, 14 years ago)

Allow plugins to return false, making the before and after not take up space.

  • bb-admin/options-reading.php

     
    33require_once( 'admin.php' );
    44
    55if ( 'post' == strtolower( $_SERVER['REQUEST_METHOD'] ) && $_POST['action'] == 'update') {
    6        
     6
    77        bb_check_admin_referer( 'options-reading-update' );
    8        
     8
    99        foreach ( (array) $_POST as $option => $value ) {
    1010                if ( !in_array( $option, array('_wpnonce', '_wp_http_referer', 'action', 'submit') ) ) {
    11                         $option = trim( $option );
    12                         $value = is_array( $value ) ? $value : trim( $value );
    13                         $value = stripslashes_deep( $value );
    14                         if ( $value ) {
    15                                 bb_update_option( $option, $value );
     11                        if ( $option == 'post_author_layout' ) {
     12                                bb_update_option( 'bb_post_author_layout', array_map( 'urldecode', explode( '|', stripslashes( $value ) ) ) );
    1613                        } else {
    17                                 bb_delete_option( $option );
     14                                $option = trim( $option );
     15                                $value = is_array( $value ) ? $value : trim( $value );
     16                                $value = stripslashes_deep( $value );
     17                                if ( $value ) {
     18                                        bb_update_option( $option, $value );
     19                                } else {
     20                                        bb_delete_option( $option );
     21                                }
    1822                        }
    1923                }
    2024        }
    21        
     25
    2226        $goback = add_query_arg('updated', 'true', wp_get_referer());
    2327        bb_safe_redirect($goback);
    2428        exit;
     
    4448        )
    4549);
    4650
     51function bb_admin_reading_post_author_filter() {
     52        return bb_get_current_user_info( 'ID' );
     53}
     54add_filter( 'get_post_author_id', 'bb_admin_reading_post_author_filter' );
     55
     56wp_enqueue_script( 'interface' );
     57
    4758$bb_admin_body_class = ' bb-admin-settings';
    4859
    4960bb_get_admin_header();
     
    6374}
    6475?>
    6576        </fieldset>
     77        <fieldset id="post-author-layout" style="display: none;">
     78                <div>
     79                        <div class="label">
     80                                <?php _e( 'Post author layout' ); ?>
     81                        </div>
     82
     83                        <div class="inputs">
     84                                <ul id="post-author-layout-active" class="post-author-layout">
     85<?php
     86foreach ( bb_get_active_post_author_layout_sections() as $section ) {
     87        bb_post_author_layout_section( $section, array(
     88                'before' => "\n\t\t\t\t\t<li class='post-author-layout-section' id='$section'>",
     89                'after'  => '</li>'
     90        ) );
     91}
     92?>
     93
     94                                </ul>
     95                                <ul id="post-author-layout-inactive" class="post-author-layout">
     96<?php
     97foreach ( bb_get_inactive_post_author_layout_sections() as $section ) {
     98        bb_post_author_layout_section( $section, array(
     99                'before' => "\n\t\t\t\t\t<li class='post-author-layout-section' id='$section'>",
     100                'after'  => '</li>'
     101        ) );
     102}
     103?>
     104
     105                                </ul>
     106
     107                                <p><?php _e( 'Arrange the elements you want next to each post by clicking and dragging. Elements in the left column will be shown.' ); ?></p>
     108
     109                                <input type="hidden" id="post_author_layout" name="post_author_layout" value="<?php
     110echo implode( '|', array_map( 'urlencode', bb_get_active_post_author_layout_sections() ) );
     111?>" />
     112                        </div>
     113                </div>
     114<script type="text/javascript">
     115jQuery(function($){
     116        $('#post-author-layout').show();
     117        $('.post-author-layout').Sortable({
     118                accept: 'post-author-layout-section',
     119                onStop: function(){
     120                        $('#post_author_layout').val($.map($.SortSerialize('post-author-layout-active').o['post-author-layout-active'], encodeURIComponent).join('|'));
     121                }
     122        }).find('* *').click(function(e){
     123                e.stopPropagation();
     124                e.preventDefault();
     125                return false;
     126        });
     127});
     128</script>
     129        </fieldset>
    66130        <fieldset class="submit">
    67131                <?php bb_nonce_field( 'options-reading-update' ); ?>
    68132                <input type="hidden" name="action" value="update" />
  • bb-admin/style.css

     
    18151815}
    18161816
    18171817
     1818/* Reading Settings */
    18181819
     1820form.settings .post-author-layout {
     1821        -moz-border-radius: 6px;
     1822        -khtml-border-radius: 6px;
     1823        -webkit-border-radius: 6px;
     1824        border-radius: 6px;
     1825        border: 1px solid #aaa;
     1826        padding: 2px;
     1827        margin: 0 5px 0 0;
     1828        float: left;
     1829        min-height: 100px;
     1830        width: 100px;
     1831}
    18191832
     1833form.settings .post-author-layout li {
     1834        list-style: none;
     1835}
    18201836
     1837#post-author-layout-active {
     1838        background-color: #fff;
     1839}
    18211840
     1841#post-author-layout-inactive {
     1842        background-color: #ccc;
     1843        opacity: .75;
     1844}
    18221845
     1846.post-author-layout + p {
     1847        clear: both;
     1848}
    18231849
    18241850/* Layout classes */
    18251851/*
  • bb-includes/functions.bb-template.php

     
    35843584                }
    35853585        }
    35863586}
     3587
     3588function bb_get_active_post_author_layout_sections() {
     3589        if ( is_array( $layout = bb_get_option( 'bb_post_author_layout' ) ) )
     3590                return array_intersect( $layout, bb_get_post_author_layout_sections() );
     3591        return array( 'post_author_avatar_link', 'post_author_link', 'post_author_title_link' );
     3592}
     3593
     3594function bb_get_inactive_post_author_layout_sections() {
     3595        if ( !is_array( $layout = bb_get_option( 'bb_post_author_layout' ) ) )
     3596                $layout = array( 'post_author_avatar_link', 'post_author_link', 'post_author_title_link' );
     3597        return array_diff( bb_get_post_author_layout_sections(), $layout );
     3598}
     3599
     3600function bb_get_post_author_layout_sections() {
     3601        return apply_filters( 'bb_post_author_layout_sections', array(
     3602                'post_author_avatar_link',
     3603                'post_author_avatar',
     3604                'post_author_link',
     3605                'post_author',
     3606                'post_author_title_link',
     3607                'post_author_title'
     3608        ) );
     3609}
     3610
     3611function bb_post_author_layout_section( $section, $args = '' ) {
     3612        extract( wp_parse_args( $args, array(
     3613                'before' => '',
     3614                'after'  => '',
     3615                'args'   => array()
     3616        ) ) );
     3617
     3618        if ( $before ) {
     3619                ob_start();
     3620        }
     3621        $result = false !== call_user_func_array( $section, $args );
     3622        if ( $before ) {
     3623                $data = ob_get_clean();
     3624                if ( $result )
     3625                        echo $before;
     3626                echo $data;
     3627        }
     3628        if ( $result )
     3629                echo $after;
     3630}
     3631
     3632function bb_post_author_layout( $args = array() ) {
     3633        $defaults = array(
     3634                'default' => array( 'post_author_avatar_link', 'post_author_link', 'post_author_title_link' )
     3635        );
     3636        $args = wp_parse_args( $args, $defaults );
     3637
     3638        if ( !$layout = bb_get_option( 'bb_post_author_layout' ) ) {
     3639                $layout = $args['default'];
     3640        }
     3641
     3642        foreach ( $layout as $section ) {
     3643                bb_post_author_layout_section( $section, array( 'after' => '<br/>' ) );
     3644        }
     3645}
     3646 No newline at end of file
  • bb-templates/kakumei/post.php

     
    11                <div id="position-<?php post_position(); ?>">
    22                        <div class="threadauthor">
     3<?php if ( function_exists( 'bb_post_author_layout' ) ) {
     4        bb_post_author_layout();
     5} else { ?>
    36                                <?php post_author_avatar_link(); ?>
    47                                <p>
    58                                        <strong><?php post_author_link(); ?></strong><br />
    69                                        <small><?php post_author_title_link(); ?></small>
    710                                </p>
     11<?php } ?>
    812                        </div>
    913                        <div class="threadpost">
    1014                                <div class="post"><?php post_text(); ?></div>