Skip to:
Content

bbPress.org

Ticket #1298: post-author-layout.diff

File post-author-layout.diff, 6.4 KB (added by Nightgunner5, 15 years ago)
  • 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        echo "\n\t\t\t\t\t<li class='post-author-layout-section' id='$section'>";
     88        bb_post_author_layout_section( $section );
     89        echo '</li>';
     90}
     91?>
     92
     93                                </ul>
     94                                <ul id="post-author-layout-inactive" class="post-author-layout">
     95<?php
     96foreach ( bb_get_inactive_post_author_layout_sections() as $section ) {
     97        echo "\n\t\t\t\t\t<li class='post-author-layout-section' id='$section'>";
     98        bb_post_author_layout_section( $section );
     99        echo '</li>';
     100}
     101?>
     102
     103                                </ul>
     104
     105                                <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>
     106
     107                                <input type="hidden" id="post_author_layout" name="post_author_layout" value="<?php
     108echo implode( '|', array_map( 'urlencode', bb_get_active_post_author_layout_sections() ) );
     109?>" />
     110                        </div>
     111                </div>
     112<script type="text/javascript">
     113jQuery(function($){
     114        $('#post-author-layout').show();
     115        $('.post-author-layout').Sortable({
     116                accept: 'post-author-layout-section',
     117                onStop: function(){
     118                        $('#post_author_layout').val($.map($.SortSerialize('post-author-layout-active').o['post-author-layout-active'], encodeURIComponent).join('|'));
     119                }
     120        }).find('* *').click(function(e){
     121                e.stopPropagation();
     122                e.preventDefault();
     123                return false;
     124        });
     125});
     126</script>
     127        </fieldset>
    66128        <fieldset class="submit">
    67129                <?php bb_nonce_field( 'options-reading-update' ); ?>
    68130                <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 ) {
     3612        call_user_func( $section );
     3613}
     3614
     3615function bb_post_author_layout( $args = array() ) {
     3616        $defaults = array(
     3617                'default' => array( 'avatar_link', 'name_link', 'title_link' )
     3618        );
     3619        $args = wp_parse_args( $args, $defaults );
     3620
     3621        if ( !$layout = bb_get_option( 'bb_post_author_layout' ) ) {
     3622                $layout = $args['default'];
     3623        }
     3624
     3625        foreach ( $layout as $section ) {
     3626                bb_post_author_layout_section( $section );
     3627                echo '<br />';
     3628        }
     3629}
     3630 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>