AddToCartButton
2 years ago
Address
3 years ago
BumpLineItem
3 years ago
Button
3 years ago
BuyButton
2 years ago
Card
3 years ago
Cart
3 years ago
CartBumpLineItem
3 years ago
CartCoupon
3 years ago
CartHeader
3 years ago
CartItems
3 years ago
CartMenuButton
3 years ago
CartMessage
3 years ago
CartSubmit
3 years ago
CartSubtotal
3 years ago
Checkbox
3 years ago
CheckoutErrors
3 years ago
CheckoutForm
3 years ago
CollapsibleRow
3 years ago
CollectionPage
2 years ago
Column
2 years ago
Columns
2 years ago
ConditionalForm
3 years ago
Confirmation
3 years ago
Coupon
3 years ago
CustomerDashboardButton
3 years ago
Dashboard
2 years ago
Divider
3 years ago
Donation
3 years ago
DonationAmount
3 years ago
Email
3 years ago
ExpressPayment
3 years ago
FirstName
3 years ago
Form
2 years ago
Heading
3 years ago
Input
3 years ago
LastName
3 years ago
LineItemShipping
3 years ago
LineItems
3 years ago
LogoutButton
3 years ago
Name
3 years ago
NameYourPrice
3 years ago
OrderBumps
2 years ago
OrderConfirmationCustomer
3 years ago
OrderConfirmationLineItems
3 years ago
Password
2 years ago
Payment
2 years ago
Phone
3 years ago
PriceChoice
2 years ago
PriceSelector
2 years ago
Product
2 years ago
ProductCollection
2 years ago
ProductCollectionDescription
2 years ago
ProductCollectionImage
2 years ago
ProductCollectionTitle
2 years ago
ProductItem
2 years ago
ProductItemImage
2 years ago
ProductItemList
2 years ago
ProductItemPrice
2 years ago
ProductItemTitle
2 years ago
Radio
3 years ago
RadioGroup
3 years ago
SessionDetail
3 years ago
ShippingChoices
3 years ago
StoreLogo
3 years ago
Submit
2 years ago
Subtotal
3 years ago
Switch
3 years ago
TaxIdInput
3 years ago
TaxLineItem
3 years ago
Textarea
3 years ago
Total
3 years ago
Totals
2 years ago
BaseBlock.php
3 years ago
BlockService.php
3 years ago
BlockServiceProvider.php
3 years ago
CartBlock.php
3 years ago
BlockServiceProvider.php
108 lines
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * Block Service Provider |
| 5 | */ |
| 6 | |
| 7 | namespace SureCartBlocks\Blocks; |
| 8 | |
| 9 | use SureCartBlocks\Blocks\BlockService; |
| 10 | use SureCartCore\ServiceProviders\ServiceProviderInterface; |
| 11 | |
| 12 | /** |
| 13 | * Block Service Provider Class |
| 14 | * Registers block service used throughout the plugin |
| 15 | * |
| 16 | * @author SureCart <andre@surecart.com> |
| 17 | * @since 1.0.0 |
| 18 | * @license GPL |
| 19 | */ |
| 20 | class BlockServiceProvider implements ServiceProviderInterface { |
| 21 | /** |
| 22 | * {@inheritDoc} |
| 23 | * |
| 24 | * @param \Pimple\Container $container Service Container. |
| 25 | */ |
| 26 | public function register( $container ) { |
| 27 | $app = $container[ SURECART_APPLICATION_KEY ]; |
| 28 | |
| 29 | $container['blocks'] = function () use ( $app ) { |
| 30 | return new BlockService( $app ); |
| 31 | }; |
| 32 | |
| 33 | $app->alias( 'blocks', 'blocks' ); |
| 34 | |
| 35 | $app->alias( |
| 36 | 'block', |
| 37 | function () use ( $app ) { |
| 38 | return call_user_func_array( [ $app->blocks(), 'render' ], func_get_args() ); |
| 39 | } |
| 40 | ); |
| 41 | } |
| 42 | |
| 43 | /** |
| 44 | * {@inheritDoc} |
| 45 | * |
| 46 | * @param \Pimple\Container $container Service Container. |
| 47 | * |
| 48 | * @return void |
| 49 | * |
| 50 | * phpcs:disable Generic.CodeAnalysis.UnusedFunctionParameter |
| 51 | */ |
| 52 | public function bootstrap( $container ) { |
| 53 | // allow our web components in wp_kses contexts. |
| 54 | add_filter( 'wp_kses_allowed_html', [ $this, 'ksesComponents' ] ); |
| 55 | add_filter( |
| 56 | 'safe_style_css', |
| 57 | function( $styles ) { |
| 58 | return array_merge( |
| 59 | [ |
| 60 | '--spacing', |
| 61 | '--font - weight', |
| 62 | '--line - height', |
| 63 | '--font - size', |
| 64 | '--color', |
| 65 | ], |
| 66 | $styles |
| 67 | ); |
| 68 | } |
| 69 | ); |
| 70 | |
| 71 | // register our blocks. |
| 72 | $this->registerBlocks( $container ); |
| 73 | } |
| 74 | |
| 75 | /** |
| 76 | * Add iFrame to allowed wp_kses_post tags |
| 77 | * |
| 78 | * @param array $tags Allowed tags, attributes, and/or entities. |
| 79 | * |
| 80 | * @return array |
| 81 | */ |
| 82 | public function ksesComponents( $tags ) { |
| 83 | $components = json_decode( file_get_contents( plugin_dir_path( SURECART_PLUGIN_FILE ) . 'app / src / Support / kses . json' ), true ); |
| 84 | |
| 85 | // add slot to defaults. |
| 86 | $tags['span']['slot'] = true; |
| 87 | $tags['div']['slot'] = true; |
| 88 | |
| 89 | return array_merge( $components, $tags ); |
| 90 | } |
| 91 | |
| 92 | /** |
| 93 | * Register blocks from config |
| 94 | * |
| 95 | * @param \Pimple\Container $container Service Container. |
| 96 | * |
| 97 | * @return void |
| 98 | */ |
| 99 | public function registerBlocks( $container ) { |
| 100 | $service = \SureCart::resolve( SURECART_CONFIG_KEY ); |
| 101 | if ( ! empty( $service['blocks'] ) ) { |
| 102 | foreach ( $service['blocks'] as $block ) { |
| 103 | ( new $block() )->register( $container ); |
| 104 | } |
| 105 | } |
| 106 | } |
| 107 | } |
| 108 |