Skip to:
Content

BuddyPress.org

Ticket #6570: 6570.first-step.patch

File 6570.first-step.patch, 13.4 KB (added by imath, 10 years ago)
  • src/bp-core/bp-core-actions.php

    diff --git src/bp-core/bp-core-actions.php src/bp-core/bp-core-actions.php
    index a9d9cea..d0aae9e 100644
    add_action( 'bp_template_redirect', 'bp_get_request', 10 ); 
    9898 * Add the BuddyPress functions file.
    9999 */
    100100add_action( 'bp_after_setup_theme', 'bp_load_theme_functions', 1 );
     101add_action( 'bp_after_setup_theme', 'bp_set_theme_support'   , 2 );
    101102
    102103// Load the admin
    103104if ( is_admin() ) {
  • src/bp-core/bp-core-cssjs.php

    diff --git src/bp-core/bp-core-cssjs.php src/bp-core/bp-core-cssjs.php
    index 392f926..a85a7b0 100644
    function bp_core_get_js_dependencies() { 
    337337                'bp-jquery-scroll-to'
    338338        ) );
    339339}
     340
     341/**
     342 * Add inline css to display the component's single item cover image
     343 *
     344 * @since BuddyPress (2.4.0)
     345 */
     346function bp_add_cover_image_inline_css() {
     347        // Find the component of the current item
     348        if ( bp_is_user() ) {
     349                $cover_component = 'members';
     350        } elseif ( bp_is_group() ) {
     351                $cover_component = 'groups';
     352        } else {
     353                $cover_component = apply_filters( 'bp_add_cover_image_inline_css_component', '' );
     354        }
     355
     356        // Bail if no component were found.
     357        if ( empty( $cover_component ) ) {
     358                return;
     359        }
     360
     361        // Check for theme support
     362        if ( current_theme_supports( 'buddypress-cover-images', $cover_component ) ) {
     363                // WordPress does not allow to directly get the sub feature if not a built-in one.
     364                $theme_support = get_theme_support( 'buddypress-cover-images' );
     365                $feature = reset( $theme_support );
     366
     367                // Try to call the callback
     368                if ( isset( $feature[ $cover_component ]['callback'] ) && is_callable( $feature[ $cover_component ]['callback'] ) ) {
     369                        /**
     370                         * Send the component's feature parameters to the callback to get an array informing about
     371                         * the handle to attach the inline css to and the inline css to add
     372                         *
     373                         * $css_data = array( 'handle' => 'handle_name', 'inline_css' => 'css rules to add' );
     374                         */
     375                        $css_data = call_user_func_array( $feature[ $cover_component ]['callback'], array( $feature[ $cover_component ] ) );
     376
     377                        // Finally add the inline css to the handle
     378                        if ( isset( $css_data['handle'] ) && isset( $css_data['inline_css'] ) ) {
     379                                wp_add_inline_style( $css_data['handle'], $css_data['inline_css'] );
     380                        }
     381                }
     382        }
     383}
     384add_action( 'bp_enqueue_scripts', 'bp_add_cover_image_inline_css', 11 );
  • src/bp-core/bp-core-filters.php

    diff --git src/bp-core/bp-core-filters.php src/bp-core/bp-core-filters.php
    index 334b6b9..8ad411c 100644
    function bp_maybe_load_mentions_scripts_for_blog_content( $load_mentions, $menti 
    10781078        return $load_mentions;
    10791079}
    10801080add_filter( 'bp_activity_maybe_load_mentions_scripts', 'bp_maybe_load_mentions_scripts_for_blog_content', 10, 2 );
     1081
     1082/**
     1083 * By default current_theme_supports() is returning true so if the feature is not active for a component,
     1084 * We need to override this default value. For instance:
     1085 * by using current_theme_supports( 'buddypress-cover-images', 'groups' ) you are able to know if the theme supports
     1086 * cover images for Groups single items.
     1087 *
     1088 * @since BuddyPress (2.4.0)
     1089 *
     1090 * @param  bool   $retval  Whether the current theme supports the given feature for the component. Default true.
     1091 * @param  array  $args    Array of arguments for the feature.
     1092 * @param  array  $feature The feature parameters.
     1093 * @return bool   True if the theme supports the feature for the given component, false otherwise
     1094 */
     1095function bp_current_theme_supports_feature( $retval, $args, $feature ) {
     1096        $bp_feature = reset( $feature );
     1097        $component  = reset( $args );
     1098
     1099        // We're using this to inform if BuddyPress is ready to support the feature
     1100        // so we need to return the value of it (should always be false, meaning it's active)
     1101        if ( 'inactive' === $component && isset( $bp_feature[ $component ] ) ) {
     1102                return (bool) $bp_feature[ $component ];
     1103        }
     1104
     1105        return isset( $bp_feature[ $component ] );
     1106}
     1107add_filter( 'current_theme_supports-buddypress-cover-images', 'bp_current_theme_supports_feature', 10, 3 );
  • src/bp-core/bp-core-template-loader.php

    diff --git src/bp-core/bp-core-template-loader.php src/bp-core/bp-core-template-loader.php
    index a4c6005..6c377cf 100644
    function bp_load_theme_functions() { 
    542542}
    543543
    544544/**
     545 * Checks if the current theme supports some BuddyPress features
     546 *
     547 * @since BuddyPress (2.4.0)
     548 *
     549 * @global string $_wp_theme_features
     550 */
     551function bp_set_theme_support() {
     552        global $_wp_theme_features;
     553
     554        /* Loop threw all features to find buddypress ones */
     555        foreach ( $_wp_theme_features as $key_feature => $data_feature ) {
     556                // Init params
     557                $params = array();
     558
     559                if ( 0 !== strpos( $key_feature, 'buddypress' ) ) {
     560                        continue;
     561                }
     562
     563                if ( is_array( $data_feature ) ) {
     564                        $theme_params = reset( $data_feature );
     565                } else {
     566                        $theme_params = $params;
     567                }
     568
     569                switch ( $key_feature ) {
     570                        case 'buddypress-cover-images' :
     571                                $supported_components = apply_filters( 'bp_cover_images_supported_single_items', array( 'members', 'groups' ) );
     572                                $theme_support        = array_diff( $supported_components, array_keys( $theme_params ) );
     573
     574                                /**
     575                                 * The theme can use params for any single items or choose to use different params for each single item.
     576                                 *
     577                                 * In this second case if one of the BuddyPress supported single items is not available in the theme
     578                                 * supported single items, then the cover image feature is not set for the corresponding item.
     579                                 */
     580                                if ( ! empty( $theme_support ) && count( $theme_support ) !== count( $supported_components ) ) {
     581                                        $supported_components = array_diff( $supported_components, $theme_support );
     582                                }
     583
     584                                foreach ( $supported_components as $component ) {
     585                                        // If avatar uploads are disabled for the component, do not allow cover images uploads.
     586                                        if ( ! bp_is_active( $component ) ) {
     587                                                continue;
     588                                        }
     589
     590                                        if ( ! isset( $theme_params[ $component ] ) ) {
     591                                                $params_component = $theme_params;
     592                                        } else {
     593                                                $params_component = $theme_params[ $component ];
     594                                        }
     595
     596                                        $params[ $component ] = bp_parse_args( $params_component, array(
     597                                                'width'                => 0,
     598                                                'height'               => 0,
     599                                                'default_cover'        => '',
     600                                                'callback'             => 'bp_legacy_theme_cover_image',
     601
     602                                        /**
     603                                         * This is a dynamic filter to override the single item cover image
     604                                         * parameters.
     605                                         * For the groups component, you can for instance use this filter:
     606                                         * 'bp_before_set_theme_support_groups_cover_images_parse_args'
     607                                         * @see bp_parse_args()
     608                                         *
     609                                         * @since BuddyPress (2.4.0)
     610                                         *
     611                                         * @param array $params a list of parameters for single item.
     612                                         */
     613                                        ), 'set_theme_support_' . $component . '_cover_images' );
     614                                }
     615                                break;
     616
     617                        default:
     618                                /**
     619                                 * Plugins can add specific BuddyPress features relative to the theme and use
     620                                 * this filter to build their params.
     621                                 *
     622                                 * @since BuddyPress (2.4.0)
     623                                 *
     624                                 * @param array  $theme_params a list of parameters for the feature.
     625                                 * @param string $key_feature  the unique identifier for the feature.
     626                                 */
     627                                $params = apply_filters( 'bp_set_theme_support_custom_params', $theme_params, $key_feature );
     628                                break;
     629                }
     630
     631                /**
     632                 * By default current_theme_supports() is returning true so if BuddyPress is not activated,
     633                 * using current_theme_supports( 'buddypress-cover-images', 'inactive' ) will return true.
     634                 * If BuddyPress is activated it will return false, meaning the functions are available to
     635                 * handle the cover images for single items.
     636                 */
     637                $_wp_theme_features[ $key_feature ] = array( array_merge( $params, array( 'inactive' => false ) ) );
     638        }
     639}
     640
     641/**
    545642 * Get the templates to use as the endpoint for BuddyPress template parts.
    546643 *
    547644 * @since BuddyPress (1.7.0)
  • src/bp-core/bp-core-theme-compatibility.php

    diff --git src/bp-core/bp-core-theme-compatibility.php src/bp-core/bp-core-theme-compatibility.php
    index 897b775..64f1891 100644
    class BP_Theme_Compat { 
    8383                // Setup methods
    8484                $this->setup_globals();
    8585                $this->setup_actions();
     86                $this->setup_supports();
    8687        }
    8788
    8889        /**
    class BP_Theme_Compat { 
    106107        protected function setup_actions() {}
    107108
    108109        /**
     110         * Set up theme supports for your template package.
     111         *
     112         * Meant to be overridden in your class. See
     113         * {@link BP_Legacy::setup_supports()} for an example.
     114         *
     115         * @since BuddyPress (2.4.0)
     116         */
     117        protected function setup_supports() {}
     118
     119        /**
    109120         * Set a theme's property.
    110121         *
    111122         * @since BuddyPress (1.7.0)
  • src/bp-templates/bp-legacy/buddypress-functions.php

    diff --git src/bp-templates/bp-legacy/buddypress-functions.php src/bp-templates/bp-legacy/buddypress-functions.php
    index 457e20d..787f893 100644
    class BP_Legacy extends BP_Theme_Compat { 
    597597
    598598                return $templates;
    599599        }
     600
     601        /**
     602         * Setup the theme hooks
     603         *
     604         * @since BuddyPress (2.4.0)
     605         * @access protected
     606         *
     607         * @global integer $content_width
     608         */
     609        protected function setup_supports() {
     610                global $content_width;
     611
     612                // The user has already set the cover images feature directly inside his theme's functions
     613                if ( current_theme_supports( 'buddypress-cover-images' ) ) {
     614                        return;
     615                }
     616
     617                // Let's check if it's a "twenty" or a "twenty" child
     618                $current_theme = wp_get_theme();
     619                $theme_handle  = $current_theme->get_stylesheet();
     620                $author        = $current_theme->get( 'Author' );
     621                $parent        = $current_theme->parent();
     622
     623                if ( $parent ) {
     624                        $author       = $parent->get( 'Author' );
     625                        $theme_handle = $parent->get_stylesheet();
     626                }
     627
     628                // It's not a "twenty" do not include default support
     629                if ( 'the WordPress team' !== $author ) {
     630                        return;
     631                }
     632
     633                /**
     634                 * Since Companion stylesheets, the $content_width is smaller
     635                 * than the item-header width, so we need to manually set the
     636                 * cover image width for the concerned themes.
     637                 *
     638                 * array( stylesheet => cover image width )
     639                 */
     640                $supported_companion_stylesheet = array(
     641                        'twentyfifteen'  => 830,
     642                        'twentyfourteen' => 955,
     643                        'twentythirteen' => 890,
     644                );
     645
     646                // Default values
     647                $cover_width     = (int) $content_width;
     648                $bp_theme_handle = 'bp-legacy-css';
     649
     650                // Specific to themes having companion stylesheets
     651                if ( isset( $supported_companion_stylesheet[ $theme_handle ] ) ) {
     652                        $cover_width     = $supported_companion_stylesheet[ $theme_handle ];
     653                        $bp_theme_handle = 'bp-' . $theme_handle;
     654                }
     655
     656                if ( is_rtl() ) {
     657                        $bp_theme_handle .= '-rtl';
     658                }
     659
     660                // Avatar constants are not yet defined
     661                $top_offset    = 150;
     662                $avatar_height = apply_filters( 'bp_core_avatar_full_height', $top_offset );
     663
     664                if ( $avatar_height > $top_offset ) {
     665                        $top_offset = $avatar_height;
     666                }
     667
     668                // Add the support to the current theme
     669                add_theme_support( 'buddypress-cover-images', array(
     670                        'width'        => $cover_width,
     671                        'height'       => $top_offset + round( $avatar_height / 2 ),
     672                        'theme_handle' => $bp_theme_handle,
     673                ) );
     674        }
    600675}
    601676new BP_Legacy();
    602677endif;
    function bp_legacy_theme_ajax_messages_star_handler() { 
    17581833        echo '-1';
    17591834        die();
    17601835}
     1836
     1837/**
     1838 * BP Legacy's callback for the cover image feature
     1839 *
     1840 * @since  BuddyPress (2.4.0)
     1841 *
     1842 * @param  array  $params the current component's feature parameters
     1843 * @return array          an array to inform about the css handle to attach the css rules to
     1844 */
     1845function bp_legacy_theme_cover_image( $params = array() ) {
     1846        if ( empty( $params ) ) {
     1847                return;
     1848        }
     1849
     1850        /**
     1851         * @todo create the attachment functions to manage cover
     1852         * uploads.
     1853         *
     1854         * For now we can test with these covers
     1855         */
     1856        $testing_covers = array(
     1857                /* twentytwelve */
     1858                'bp-legacy-css'     => 'https://cldup.com/BB4ZtZz-G8.jpg',
     1859                'bp-twentythirteen' => 'https://cldup.com/THkaA2U3-u.jpg',
     1860                'bp-twentyfourteen' => 'https://cldup.com/aL6CbN-hua.jpg',
     1861                'bp-twentyfifteen'  => 'https://cldup.com/DB-6lSS9Or.jpg',
     1862        );
     1863
     1864        $cover = $testing_covers[ $params['theme_handle'] ];
     1865
     1866        if ( ! $cover && ! empty( $params['default_cover'] ) ) {
     1867                $cover = esc_url( $params['default_cover'] );
     1868        }
     1869
     1870        // Bail if the single item has no cover images
     1871        if ( ! $cover || empty( $params['theme_handle'] ) ) {
     1872                return;
     1873        }
     1874
     1875        // feature's height - padding - 1/2 avatar height
     1876        $top_offset = $params['height'] - 5 - round( (int) bp_core_avatar_full_height() / 2 );
     1877
     1878        /**
     1879         * @todo  css media queries + groups single item rules
     1880         */
     1881        return array( 'handle' => $params['theme_handle'], 'inline_css' => '
     1882                /* Cover image */
     1883                .bp-user #buddypress #item-header,
     1884                body:not(.sidebar) #buddypress #item-header {
     1885                        background: #FFF url(' . $cover . ') no-repeat center top;
     1886                        padding:5px;
     1887                }
     1888
     1889                #buddypress #item-header #item-header-avatar,
     1890                #buddypress #item-header #item-header-content {
     1891                        margin-top:'. $top_offset .'px;
     1892                }
     1893
     1894                /* when the latest activity is too long */
     1895                #buddypress #item-header #item-header-content {
     1896                        width:60%;
     1897                }
     1898
     1899                /* This should only happen on regular screens */
     1900                #buddypress div#item-header h2 a,
     1901                #buddypress div#item-header h2 {
     1902                        color: #FFF;
     1903                        text-rendering: optimizelegibility;
     1904                        text-shadow: 0px 0px 3px rgba( 0, 0, 0, 0.8 );
     1905                        margin:25px 0;
     1906                        font-size:200%;
     1907                }
     1908
     1909                .bp-user #buddypress #item-header #item-header-avatar img.avatar {
     1910                        border: solid 2px #FFF;
     1911                        background: rgba( 255, 255, 255, 0.8 );
     1912                }
     1913        ' );
     1914}