Skip to:
Content

BuddyPress.org

Ticket #6921: 6921.03.patch

File 6921.03.patch, 12.2 KB (added by r-a-y, 7 years ago)
  • composer.json

     
    2828  },
    2929  "require": {
    3030    "composer/installers": "~1.0",
    31     "php": ">=5.3.0"
     31    "php": ">=5.3.0",
     32    "zordius/lightncandy": "~1.2.0"
     33  },
     34  "config": {
     35    "vendor-dir": "src/vendor"
    3236  }
    3337}
  • new file composer.lock

    new file mode 100644
    - +  
     1{
     2    "_readme": [
     3        "This file locks the dependencies of your project to a known state",
     4        "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
     5        "This file is @generated automatically"
     6    ],
     7    "content-hash": "1d6253895db52527fe0fb1009a6e5da4",
     8    "packages": [
     9        {
     10            "name": "composer/installers",
     11            "version": "v1.5.0",
     12            "source": {
     13                "type": "git",
     14                "url": "https://github.com/composer/installers.git",
     15                "reference": "049797d727261bf27f2690430d935067710049c2"
     16            },
     17            "dist": {
     18                "type": "zip",
     19                "url": "https://api.github.com/repos/composer/installers/zipball/049797d727261bf27f2690430d935067710049c2",
     20                "reference": "049797d727261bf27f2690430d935067710049c2",
     21                "shasum": ""
     22            },
     23            "require": {
     24                "composer-plugin-api": "^1.0"
     25            },
     26            "replace": {
     27                "roundcube/plugin-installer": "*",
     28                "shama/baton": "*"
     29            },
     30            "require-dev": {
     31                "composer/composer": "1.0.*@dev",
     32                "phpunit/phpunit": "^4.8.36"
     33            },
     34            "type": "composer-plugin",
     35            "extra": {
     36                "class": "Composer\\Installers\\Plugin",
     37                "branch-alias": {
     38                    "dev-master": "1.0-dev"
     39                }
     40            },
     41            "autoload": {
     42                "psr-4": {
     43                    "Composer\\Installers\\": "src/Composer/Installers"
     44                }
     45            },
     46            "notification-url": "https://packagist.org/downloads/",
     47            "license": [
     48                "MIT"
     49            ],
     50            "authors": [
     51                {
     52                    "name": "Kyle Robinson Young",
     53                    "email": "kyle@dontkry.com",
     54                    "homepage": "https://github.com/shama"
     55                }
     56            ],
     57            "description": "A multi-framework Composer library installer",
     58            "homepage": "https://composer.github.io/installers/",
     59            "keywords": [
     60                "Craft",
     61                "Dolibarr",
     62                "Eliasis",
     63                "Hurad",
     64                "ImageCMS",
     65                "Kanboard",
     66                "Lan Management System",
     67                "MODX Evo",
     68                "Mautic",
     69                "Maya",
     70                "OXID",
     71                "Plentymarkets",
     72                "Porto",
     73                "RadPHP",
     74                "SMF",
     75                "Thelia",
     76                "WolfCMS",
     77                "agl",
     78                "aimeos",
     79                "annotatecms",
     80                "attogram",
     81                "bitrix",
     82                "cakephp",
     83                "chef",
     84                "cockpit",
     85                "codeigniter",
     86                "concrete5",
     87                "croogo",
     88                "dokuwiki",
     89                "drupal",
     90                "eZ Platform",
     91                "elgg",
     92                "expressionengine",
     93                "fuelphp",
     94                "grav",
     95                "installer",
     96                "itop",
     97                "joomla",
     98                "kohana",
     99                "laravel",
     100                "lavalite",
     101                "lithium",
     102                "magento",
     103                "majima",
     104                "mako",
     105                "mediawiki",
     106                "modulework",
     107                "modx",
     108                "moodle",
     109                "osclass",
     110                "phpbb",
     111                "piwik",
     112                "ppi",
     113                "puppet",
     114                "pxcms",
     115                "reindex",
     116                "roundcube",
     117                "shopware",
     118                "silverstripe",
     119                "sydes",
     120                "symfony",
     121                "typo3",
     122                "wordpress",
     123                "yawik",
     124                "zend",
     125                "zikula"
     126            ],
     127            "time": "2017-12-29T09:13:20+00:00"
     128        },
     129        {
     130            "name": "zordius/lightncandy",
     131            "version": "v1.2.2",
     132            "source": {
     133                "type": "git",
     134                "url": "https://github.com/zordius/lightncandy.git",
     135                "reference": "448cb2855d7301fa5380d8228255d46e9be92903"
     136            },
     137            "dist": {
     138                "type": "zip",
     139                "url": "https://api.github.com/repos/zordius/lightncandy/zipball/448cb2855d7301fa5380d8228255d46e9be92903",
     140                "reference": "448cb2855d7301fa5380d8228255d46e9be92903",
     141                "shasum": ""
     142            },
     143            "require": {
     144                "php": ">=5.4.0"
     145            },
     146            "require-dev": {
     147                "phpunit/phpunit": "4.8.35"
     148            },
     149            "type": "library",
     150            "extra": {
     151                "branch-alias": {
     152                    "dev-master": "1.2.3-dev"
     153                }
     154            },
     155            "autoload": {
     156                "psr-4": {
     157                    "LightnCandy\\": "src"
     158                }
     159            },
     160            "notification-url": "https://packagist.org/downloads/",
     161            "license": [
     162                "MIT"
     163            ],
     164            "authors": [
     165                {
     166                    "name": "Zordius Chen",
     167                    "email": "zordius@gmail.com"
     168                }
     169            ],
     170            "description": "An extremely fast PHP implementation of handlebars ( http://handlebarsjs.com/ ) and mustache ( http://mustache.github.io/ ).",
     171            "homepage": "https://github.com/zordius/lightncandy",
     172            "keywords": [
     173                "handlebars",
     174                "logicless",
     175                "mustache",
     176                "php",
     177                "template"
     178            ],
     179            "time": "2018-03-19T07:06:10+00:00"
     180        }
     181    ],
     182    "packages-dev": [],
     183    "aliases": [],
     184    "minimum-stability": "stable",
     185    "stability-flags": [],
     186    "prefer-stable": false,
     187    "prefer-lowest": false,
     188    "platform": {
     189        "php": ">=5.3.0"
     190    },
     191    "platform-dev": []
     192}
  • src/bp-core/bp-core-functions.php

     
    33093309 * @return string
    33103310 */
    33113311function bp_core_replace_tokens_in_text( $text, $tokens ) {
    3312         $unescaped = array();
    3313         $escaped   = array();
     3312        // Use LightnCandy library to render mustache tags.
     3313        $render = \LightnCandy\LightnCandy::prepare(
     3314                \LightnCandy\LightnCandy::compile( $text )
     3315        );
    33143316
    3315         foreach ( $tokens as $token => $value ) {
    3316                 if ( ! is_string( $value ) && is_callable( $value ) ) {
    3317                         $value = call_user_func( $value );
    3318                 }
     3317        /*
     3318         * Dot notation backward-compatibilty parser.
     3319         *
     3320         * @see https://buddypress.trac.wordpress.org/ticket/6921#comment:8
     3321         */
     3322        foreach ( $tokens as $token => $val ) {
     3323                if ( false !== strpos( $token, '.' ) && ! is_array( $val ) ) {
     3324                        $split = explode( '.', $token );
     3325                        if ( empty( $split[1] ) ) {
     3326                                continue;
     3327                        }
    33193328
    3320                 // Tokens could be objects or arrays.
    3321                 if ( ! is_scalar( $value ) ) {
    3322                         continue;
    3323                 }
     3329                        if ( empty( $tokens[ $split[0] ] ) ) {
     3330                                $tokens[ $split[0] ] = array();
     3331                        }
    33243332
    3325                 $unescaped[ '{{{' . $token . '}}}' ] = $value;
    3326                 $escaped[ '{{' . $token . '}}' ]     = esc_html( $value );
     3333                        // We currently only handle one level of dot notation for conversion.
     3334                        $tokens[ $split[0] ][ $split[1] ] = $val;
     3335
     3336                        // Get rid of the old token.
     3337                        unset( $tokens[$token] );
     3338                }
    33273339        }
    33283340
    3329         $text = strtr( $text, $unescaped );  // Do first.
    3330         $text = strtr( $text, $escaped );
     3341        $text = $render( $tokens );
    33313342
    33323343        /**
    33333344         * Filters text that has had tokens replaced.
  • src/bp-loader.php

     
    7373        add_action( 'network_admin_notices', 'bp_php_requirements_notice' );
    7474        return;
    7575} else {
    76         require dirname( __FILE__ ) . '/class-buddypress.php';
     76        if ( file_exists( dirname( __FILE__ ) . '/vendor/autoload.php' ) ) {
     77                require_once dirname( __FILE__ ) . '/vendor/autoload.php';
     78        }
     79        require_once dirname( __FILE__ ) . '/class-buddypress.php';
    7780
    7881        /*
    7982         * Hook BuddyPress early onto the 'plugins_loaded' action.
  • src/bp-templates/bp-legacy/buddypress/assets/emails/single-bp-email.php

     
    215215                                                ?>
    216216
    217217                                                <span class="footer_text"><?php echo nl2br( stripslashes( $settings['footer_text'] ) ); ?></span>
    218                                                 <br><br>
    219                                                 <a href="{{{unsubscribe}}}" style="text-decoration: underline;"><?php _ex( 'unsubscribe', 'email', 'buddypress' ); ?></a>
     218
     219                                                {{#unsubscribe}}
     220                                                        <br><br>
     221                                                        <a href="{{{.}}}" style="text-decoration: underline;"><?php _ex( 'unsubscribe', 'email', 'buddypress' ); ?></a>
     222                                                {{/unsubscribe}}
    220223
    221224                                                <?php
    222225                                                /**
  • src/bp-templates/bp-nouveau/buddypress/assets/emails/single-bp-email.php

     
    215215                                                ?>
    216216
    217217                                                <span class="footer_text"><?php echo nl2br( stripslashes( $settings['footer_text'] ) ); ?></span>
    218                                                 <br><br>
    219                                                 <a href="{{{unsubscribe}}}" style="text-decoration: underline;"><?php _ex( 'unsubscribe', 'email', 'buddypress' ); ?></a>
     218
     219                                                {{#unsubscribe}}
     220                                                        <br><br>
     221                                                        <a href="{{{.}}}" style="text-decoration: underline;"><?php _ex( 'unsubscribe', 'email', 'buddypress' ); ?></a>
     222                                                {{/unsubscribe}}
    220223
    221224                                                <?php
    222225                                                /**
  • tests/phpunit/testcases/core/class-bp-email.php

     
    293293                $email->set_subject( '{{poster.name}}' )->set_tokens( array( 'poster.name' => $token ) );
    294294
    295295                // Subject always has to have tokens replaced before sending.
    296                 $this->assertSame( $name, $email->get_subject( 'replace-tokens' ) );
     296                $this->assertSame( $token, $email->get_subject( 'replace-tokens' ) );
    297297        }
    298298
    299299}
  • new file tests/phpunit/testcases/core/functions/bpCoreReplaceTokensInText.php

    new file mode 100644
    - +  
     1<?php
     2
     3/**
     4 * @group core
     5 * @group functions
     6 * @group bp_core_replace_tokens_in_text
     7 */
     8class BP_Tests_Core_Functions_BPCoreReplaceTokensInText extends BP_UnitTestCase {
     9        public function test_bp_core_replace_tokens_in_text_sections() {
     10                $text = '{{#person}}Show!{{/person}}';
     11
     12                $parsed = bp_core_replace_tokens_in_text( $text, array() );
     13                $this->assertEmpty( $parsed );
     14
     15                $parsed = bp_core_replace_tokens_in_text( $text, array( 'person' => 'I exist' ) );
     16                $this->assertEquals( 'Show!', $parsed );
     17        }
     18
     19        public function test_bp_core_replace_tokens_in_text_section_unescaped() {
     20                $text = '{{#person}}{{{.}}}{{/person}}';
     21
     22                $parsed = bp_core_replace_tokens_in_text( $text, array( 'person' => '<b>I am awesome</b>' ) );
     23                $this->assertEquals( '<b>I am awesome</b>', $parsed );
     24        }
     25
     26        public function test_bp_core_replace_tokens_in_text_section_escaped() {
     27                $text = '{{#person}}{{.}}{{/person}}';
     28
     29                $parsed = bp_core_replace_tokens_in_text( $text, array( 'person' => '<b>I am awesome</b>' ) );
     30                $this->assertEquals( '&lt;b&gt;I am awesome&lt;/b&gt;', $parsed );
     31        }
     32}