Skip to:
Content

BuddyPress.org

Changeset 13002


Ignore:
Timestamp:
07/14/2021 04:44:28 PM (4 years ago)
Author:
imath
Message:

Merge the BP Blocks plugin's 'bp/friends' Block

  • introduce the bp_get_dynamic_template_part() function which let you use a JavaScript template inside PHP thanks to the bp_core_replace_tokens_in_text() function.
  • Adds a new assets/widgets/friends.php JavaScript template to our two template packs.
  • Adds a new Core JavaScript file which acts like a parent class to all dynamic widgets front-end scripts (friends, groups, members).
  • Add this front-end script to the Friends component.
  • Adapt Grunt sass tasks.
  • Add the Block JavaScript source files into src/js/bp-friends/js/blocks.
  • Add the Block Scss source file into src/bp-friends/sass.
  • Generate the development files to ease testing.

Fixes #8521

Location:
trunk
Files:
28 added
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/.jshintignore

    r12995 r13002  
    99src/**/js/block-*/**/*.js
    1010src/**/js/block-*.js
     11src/**/js/friends.js
     12src/**/js/dynamic-widget-block.js
  • trunk/Gruntfile.js

    r13001 r13002  
    2323            '!**/js/block-*/*.js',
    2424            '!**/js/block-*/**/*.js',
    25             '!**/js/block-*.js'
     25            '!**/js/block-*.js',
     26            '!**/js/friends.js',
     27            '!**/js/dynamic-widget-block.js'
    2628        ],
    2729
     
    4143            '!bp-groups/css/blocks/groups.css',
    4244            '!bp-core/css/blocks/login-form.css',
    43             '!bp-activity/css/blocks/latest-activities.css'
     45            '!bp-activity/css/blocks/latest-activities.css',
     46            '!bp-friends/css/blocks/friends.css'
    4447        ],
    4548
     
    169172                src: ['bp-activity/sass/blocks/*.scss'],
    170173                dest: SOURCE_DIR + 'bp-activity/css/blocks/'
     174            },
     175            friends_blocks: {
     176                cwd: SOURCE_DIR,
     177                extDot: 'last',
     178                expand: true,
     179                ext: '.css',
     180                flatten: true,
     181                src: ['bp-friends/sass/blocks/*.scss'],
     182                dest: SOURCE_DIR + 'bp-friends/css/blocks/'
    171183            }
    172184        },
  • trunk/package.json

    r12995 r13002  
    4141    },
    4242    "scripts": {
    43         "start": "npm run dev:components && parcel watch src/js/bp-*/*s/blocks/*.js --out-dir src --no-source-maps",
    44         "dev": "npm run dev:components && parcel build src/js/bp-*/*s/blocks/*.js --out-dir src --no-source-maps --no-minify",
    45         "build": "npm run build:components && parcel build src/js/bp-*/*s/blocks/*.js --out-dir build",
     43        "start": "npm run dev:components && npm run dev:assets && parcel watch src/js/bp-*/*s/blocks/*.js --out-dir src --no-source-maps",
     44        "dev": "npm run dev:components && npm run dev:assets && npm run dev:scripts && parcel build src/js/bp-*/*s/blocks/*.js --out-dir src --no-source-maps --no-minify",
     45        "build": "npm run build:components && npm run build:assets && npm run build:scripts && parcel build src/js/bp-*/*s/blocks/*.js --out-dir build",
    4646        "watch:components": "parcel watch src/js/bp-core/js/block-components/block-components.js --out-dir src/bp-core/js --out-file block-components.js --no-source-maps --global bpBlock",
    4747        "dev:components": "parcel build src/js/bp-core/js/block-components/block-components.js --out-dir src/bp-core/js --out-file block-components.js --no-source-maps --no-minify --global bpBlock",
     
    5050        "dev:assets": "parcel build src/js/bp-core/js/block-assets/*.js --out-dir src/bp-core/js --no-source-maps --no-minify --global bpBlock",
    5151        "build:assets": "parcel build src/js/bp-core/js/block-assets/*.js --out-dir build/bp-core/js --global bpBlock",
     52        "dev:scripts": "parcel build src/js/bp-*/*s/* --out-dir src --no-source-maps --no-minify",
     53        "build:scripts": "parcel build src/js/bp-*/*s/* --out-dir build",
    5254        "wp-env": "wp-env",
    5355        "test-php": "npm run wp-env run phpunit 'php /var/www/html/wp-content/plugins/buddypress/vendor/phpunit/phpunit/phpunit -c /var/www/html/wp-content/plugins/buddypress/tests/phpunit/env.xml'",
  • trunk/src/bp-activity/js/blocks/embed-activity.js

    r12996 r13002  
    118118
    119119  return newRequire;
    120 })({"dEOc":[function(require,module,exports) {
     120})({"DCTP":[function(require,module,exports) {
    121121function _arrayWithHoles(arr) {
    122122  if (Array.isArray(arr)) return arr;
     
    124124
    125125module.exports = _arrayWithHoles;
    126 },{}],"RonT":[function(require,module,exports) {
     126},{}],"LoeL":[function(require,module,exports) {
    127127function _iterableToArrayLimit(arr, i) {
    128128  if (typeof Symbol === "undefined" || !(Symbol.iterator in Object(arr))) return;
     
    153153
    154154module.exports = _iterableToArrayLimit;
    155 },{}],"LGpM":[function(require,module,exports) {
     155},{}],"jEQo":[function(require,module,exports) {
    156156function _arrayLikeToArray(arr, len) {
    157157  if (len == null || len > arr.length) len = arr.length;
     
    165165
    166166module.exports = _arrayLikeToArray;
    167 },{}],"Vzqv":[function(require,module,exports) {
     167},{}],"Dbv9":[function(require,module,exports) {
    168168var arrayLikeToArray = require("./arrayLikeToArray");
    169169
     
    178178
    179179module.exports = _unsupportedIterableToArray;
    180 },{"./arrayLikeToArray":"LGpM"}],"sa4T":[function(require,module,exports) {
     180},{"./arrayLikeToArray":"jEQo"}],"MWEO":[function(require,module,exports) {
    181181function _nonIterableRest() {
    182182  throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
     
    184184
    185185module.exports = _nonIterableRest;
    186 },{}],"xkYc":[function(require,module,exports) {
     186},{}],"DERy":[function(require,module,exports) {
    187187var arrayWithHoles = require("./arrayWithHoles");
    188188
     
    198198
    199199module.exports = _slicedToArray;
    200 },{"./arrayWithHoles":"dEOc","./iterableToArrayLimit":"RonT","./unsupportedIterableToArray":"Vzqv","./nonIterableRest":"sa4T"}],"Sjre":[function(require,module,exports) {
     200},{"./arrayWithHoles":"DCTP","./iterableToArrayLimit":"LoeL","./unsupportedIterableToArray":"Dbv9","./nonIterableRest":"MWEO"}],"Sjre":[function(require,module,exports) {
    201201"use strict";
    202202
     
    364364var _default = editEmbedActivityBlock;
    365365exports.default = _default;
    366 },{"@babel/runtime/helpers/slicedToArray":"xkYc"}],"zmBI":[function(require,module,exports) {
     366},{"@babel/runtime/helpers/slicedToArray":"DERy"}],"zmBI":[function(require,module,exports) {
    367367"use strict";
    368368
  • trunk/src/bp-core/bp-core-cssjs.php

    r12857 r13002  
    8686        'bp-moment'    => array( 'file' => "{$url}vendor/moment-js/moment{$min}.js", 'dependencies' => array(), 'footer' => true ),
    8787        'bp-livestamp' => array( 'file' => "{$url}vendor/livestamp{$min}.js", 'dependencies' => array( 'jquery', 'bp-moment' ), 'footer' => true ),
     88
     89        // Version 9.0.
     90        'bp-dynamic-widget-block-script' => array( 'file' => "{$url}dynamic-widget-block.js", 'dependencies' => array( 'lodash', 'wp-url' ), 'footer' => true ),
    8891    );
    8992
  • trunk/src/bp-core/bp-core-template-loader.php

    r12726 r13002  
    8686function bp_get_asset_template_part( $slug, $name = null, $args = array() ) {
    8787    return bp_get_template_part( "assets/{$slug}", $name, $args );
     88}
     89
     90/**
     91 * Get a dynamic template part.
     92 *
     93 * @since 9.0.0
     94 *
     95 * @param string $template     The Template Pack's relative path to the templata.
     96 *                             Optional.
     97 * @param string $type         Whether to use the template for JavaScript or PHP.
     98 *                             Optional. Defaults to `js`.
     99 * @param array  $tokens       The data to use to customize the template. Optional.
     100 * @param array  $allowed_tags The allowed tags to use. Optional.
     101 * @return string HTML/JS output.
     102 */
     103function bp_get_dynamic_template_part( $template = '', $type = 'js', $tokens = array(), $allowed_tags = array() ) {
     104    $template_string = '';
     105
     106    if ( ! $template ) {
     107        return '';
     108    }
     109
     110    // Use the BP Theme Compat API to allow template override.
     111    $template_path = bp_locate_template( $template );
     112    if ( $template_path ) {
     113        $template_string = file_get_contents( $template_path );
     114    }
     115
     116    if ( ! $template_string ) {
     117        return '';
     118    }
     119
     120    if ( ! $allowed_tags ) {
     121        $allowed_tags = array(
     122            'li'   => array( 'class' => true ),
     123            'div'  => array( 'class' => true ),
     124            'span' => array( 'class' => true ),
     125            'a'    => array(
     126                'href'            => true,
     127                'class'           => true,
     128                'data-bp-tooltip' => true,
     129            ),
     130            'img'  => array(
     131                'src'     => true,
     132                'class'   => true,
     133                'loading' => true,
     134            ),
     135        );
     136    }
     137
     138    if ( 'js' !== $type ) {
     139        $template_string = wp_kses( $template_string, $allowed_tags );
     140
     141        return bp_core_replace_tokens_in_text( $template_string, $tokens );
     142    }
     143
     144    return $template_string;
    88145}
    89146
  • trunk/src/bp-friends/classes/class-bp-friends-component.php

    r12994 r13002  
    4747    public function includes( $includes = array() ) {
    4848        $includes = array(
     49            'cssjs',
    4950            'cache',
    5051            'filters',
     
    5253            'functions',
    5354            'widgets',
     55            'blocks',
    5456        );
    5557
     
    134136            'search_string'         => __( 'Search Friends...', 'buddypress' ),
    135137            'notification_callback' => 'friends_format_notifications',
    136             'global_tables'         => $global_tables
     138            'global_tables'         => $global_tables,
     139            'block_globals'         => array(
     140                'bp/friends' => array(
     141                    'widget_classnames' => array( 'widget_bp_core_friends_widget', 'buddypress' ),
     142                )
     143            ),
    137144        );
    138145
     
    348355     */
    349356    public function blocks_init( $blocks = array() ) {
    350         parent::blocks_init( array() );
     357        parent::blocks_init(
     358            array(
     359                'bp/friends' => array(
     360                    'name'               => 'bp/friends',
     361                    'editor_script'      => 'bp-friends-block',
     362                    'editor_script_url'  => plugins_url( 'js/blocks/friends.js', dirname( __FILE__ ) ),
     363                    'editor_script_deps' => array(
     364                        'wp-blocks',
     365                        'wp-element',
     366                        'wp-components',
     367                        'wp-i18n',
     368                        'wp-block-editor',
     369                        'bp-block-data',
     370                        'bp-block-components',
     371                    ),
     372                    'style'              => 'bp-friends-block',
     373                    'style_url'          => plugins_url( 'css/blocks/friends.css', dirname( __FILE__ ) ),
     374                    'attributes'         => array(
     375                        'maxFriends'    => array(
     376                            'type'    => 'number',
     377                            'default' => 5,
     378                        ),
     379                        'friendDefault' => array(
     380                            'type'    => 'string',
     381                            'default' => 'active',
     382                        ),
     383                        'linkTitle'     => array(
     384                            'type'    => 'boolean',
     385                            'default' => false,
     386                        ),
     387                        'postId'        => array(
     388                            'type'    => 'number',
     389                            'default' => 0,
     390                        ),
     391                    ),
     392                    'render_callback'    => 'bp_friends_render_friends_block',
     393                ),
     394            )
     395        );
    351396    }
    352397}
  • trunk/src/bp-groups/js/blocks/groups.js

    r12996 r13002  
    118118
    119119  return newRequire;
    120 })({"LGpM":[function(require,module,exports) {
     120})({"jEQo":[function(require,module,exports) {
    121121function _arrayLikeToArray(arr, len) {
    122122  if (len == null || len > arr.length) len = arr.length;
     
    138138
    139139module.exports = _arrayWithoutHoles;
    140 },{"./arrayLikeToArray":"LGpM"}],"lZpU":[function(require,module,exports) {
     140},{"./arrayLikeToArray":"jEQo"}],"lZpU":[function(require,module,exports) {
    141141function _iterableToArray(iter) {
    142142  if (typeof Symbol !== "undefined" && Symbol.iterator in Object(iter)) return Array.from(iter);
     
    144144
    145145module.exports = _iterableToArray;
    146 },{}],"Vzqv":[function(require,module,exports) {
     146},{}],"Dbv9":[function(require,module,exports) {
    147147var arrayLikeToArray = require("./arrayLikeToArray");
    148148
     
    157157
    158158module.exports = _unsupportedIterableToArray;
    159 },{"./arrayLikeToArray":"LGpM"}],"NCaH":[function(require,module,exports) {
     159},{"./arrayLikeToArray":"jEQo"}],"NCaH":[function(require,module,exports) {
    160160function _nonIterableSpread() {
    161161  throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
     
    177177
    178178module.exports = _toConsumableArray;
    179 },{"./arrayWithoutHoles":"o3SL","./iterableToArray":"lZpU","./unsupportedIterableToArray":"Vzqv","./nonIterableSpread":"NCaH"}],"dEOc":[function(require,module,exports) {
     179},{"./arrayWithoutHoles":"o3SL","./iterableToArray":"lZpU","./unsupportedIterableToArray":"Dbv9","./nonIterableSpread":"NCaH"}],"DCTP":[function(require,module,exports) {
    180180function _arrayWithHoles(arr) {
    181181  if (Array.isArray(arr)) return arr;
     
    183183
    184184module.exports = _arrayWithHoles;
    185 },{}],"RonT":[function(require,module,exports) {
     185},{}],"LoeL":[function(require,module,exports) {
    186186function _iterableToArrayLimit(arr, i) {
    187187  if (typeof Symbol === "undefined" || !(Symbol.iterator in Object(arr))) return;
     
    212212
    213213module.exports = _iterableToArrayLimit;
    214 },{}],"sa4T":[function(require,module,exports) {
     214},{}],"MWEO":[function(require,module,exports) {
    215215function _nonIterableRest() {
    216216  throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
     
    218218
    219219module.exports = _nonIterableRest;
    220 },{}],"xkYc":[function(require,module,exports) {
     220},{}],"DERy":[function(require,module,exports) {
    221221var arrayWithHoles = require("./arrayWithHoles");
    222222
     
    232232
    233233module.exports = _slicedToArray;
    234 },{"./arrayWithHoles":"dEOc","./iterableToArrayLimit":"RonT","./unsupportedIterableToArray":"Vzqv","./nonIterableRest":"sa4T"}],"jS06":[function(require,module,exports) {
     234},{"./arrayWithHoles":"DCTP","./iterableToArrayLimit":"LoeL","./unsupportedIterableToArray":"Dbv9","./nonIterableRest":"MWEO"}],"jS06":[function(require,module,exports) {
    235235"use strict";
    236236
     
    567567var _default = editGroupsBlock;
    568568exports.default = _default;
    569 },{"@babel/runtime/helpers/toConsumableArray":"I9dH","@babel/runtime/helpers/slicedToArray":"xkYc","./constants":"jS06"}],"jcTh":[function(require,module,exports) {
     569},{"@babel/runtime/helpers/toConsumableArray":"I9dH","@babel/runtime/helpers/slicedToArray":"DERy","./constants":"jS06"}],"jcTh":[function(require,module,exports) {
    570570"use strict";
    571571
  • trunk/src/bp-members/js/blocks/members.js

    r12996 r13002  
    118118
    119119  return newRequire;
    120 })({"LGpM":[function(require,module,exports) {
     120})({"jEQo":[function(require,module,exports) {
    121121function _arrayLikeToArray(arr, len) {
    122122  if (len == null || len > arr.length) len = arr.length;
     
    138138
    139139module.exports = _arrayWithoutHoles;
    140 },{"./arrayLikeToArray":"LGpM"}],"lZpU":[function(require,module,exports) {
     140},{"./arrayLikeToArray":"jEQo"}],"lZpU":[function(require,module,exports) {
    141141function _iterableToArray(iter) {
    142142  if (typeof Symbol !== "undefined" && Symbol.iterator in Object(iter)) return Array.from(iter);
     
    144144
    145145module.exports = _iterableToArray;
    146 },{}],"Vzqv":[function(require,module,exports) {
     146},{}],"Dbv9":[function(require,module,exports) {
    147147var arrayLikeToArray = require("./arrayLikeToArray");
    148148
     
    157157
    158158module.exports = _unsupportedIterableToArray;
    159 },{"./arrayLikeToArray":"LGpM"}],"NCaH":[function(require,module,exports) {
     159},{"./arrayLikeToArray":"jEQo"}],"NCaH":[function(require,module,exports) {
    160160function _nonIterableSpread() {
    161161  throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
     
    177177
    178178module.exports = _toConsumableArray;
    179 },{"./arrayWithoutHoles":"o3SL","./iterableToArray":"lZpU","./unsupportedIterableToArray":"Vzqv","./nonIterableSpread":"NCaH"}],"dEOc":[function(require,module,exports) {
     179},{"./arrayWithoutHoles":"o3SL","./iterableToArray":"lZpU","./unsupportedIterableToArray":"Dbv9","./nonIterableSpread":"NCaH"}],"DCTP":[function(require,module,exports) {
    180180function _arrayWithHoles(arr) {
    181181  if (Array.isArray(arr)) return arr;
     
    183183
    184184module.exports = _arrayWithHoles;
    185 },{}],"RonT":[function(require,module,exports) {
     185},{}],"LoeL":[function(require,module,exports) {
    186186function _iterableToArrayLimit(arr, i) {
    187187  if (typeof Symbol === "undefined" || !(Symbol.iterator in Object(arr))) return;
     
    212212
    213213module.exports = _iterableToArrayLimit;
    214 },{}],"sa4T":[function(require,module,exports) {
     214},{}],"MWEO":[function(require,module,exports) {
    215215function _nonIterableRest() {
    216216  throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
     
    218218
    219219module.exports = _nonIterableRest;
    220 },{}],"xkYc":[function(require,module,exports) {
     220},{}],"DERy":[function(require,module,exports) {
    221221var arrayWithHoles = require("./arrayWithHoles");
    222222
     
    232232
    233233module.exports = _slicedToArray;
    234 },{"./arrayWithHoles":"dEOc","./iterableToArrayLimit":"RonT","./unsupportedIterableToArray":"Vzqv","./nonIterableRest":"sa4T"}],"gr8I":[function(require,module,exports) {
     234},{"./arrayWithHoles":"DCTP","./iterableToArrayLimit":"LoeL","./unsupportedIterableToArray":"Dbv9","./nonIterableRest":"MWEO"}],"gr8I":[function(require,module,exports) {
    235235"use strict";
    236236
     
    563563var _default = editMembersBlock;
    564564exports.default = _default;
    565 },{"@babel/runtime/helpers/toConsumableArray":"I9dH","@babel/runtime/helpers/slicedToArray":"xkYc","./constants":"gr8I"}],"XEHU":[function(require,module,exports) {
     565},{"@babel/runtime/helpers/toConsumableArray":"I9dH","@babel/runtime/helpers/slicedToArray":"DERy","./constants":"gr8I"}],"XEHU":[function(require,module,exports) {
    566566"use strict";
    567567
Note: See TracChangeset for help on using the changeset viewer.