BuyButton.php
1 year ago
CollectionTag.php
1 year ago
CollectionTags.php
1 year ago
Media.php
1 year ago
PriceChoiceTemplate.php
1 year ago
PriceChooser.php
1 year ago
PriceData.php
1 year ago
Product.php
1 year ago
ProductCard.php
1 year ago
ProductData.php
1 year ago
Quantity.php
1 year ago
SaleBadge.php
1 year ago
SelectedPriceAdHocAmount.php
1 year ago
VariantPill.php
1 year ago
VariantPills.php
1 year ago
Media.php
133 lines
| 1 | <?php |
| 2 | |
| 3 | namespace SureCart\Integrations\Bricks\Elements; |
| 4 | |
| 5 | use SureCart\Integrations\Bricks\Concerns\ConvertsBlocks; |
| 6 | |
| 7 | if ( ! defined( 'ABSPATH' ) ) { |
| 8 | exit; // Exit if accessed directly. |
| 9 | } |
| 10 | |
| 11 | /** |
| 12 | * Media element. |
| 13 | */ |
| 14 | class Media extends \Bricks\Element { |
| 15 | use ConvertsBlocks; // we have to use a trait since we can't extend the surecart class. |
| 16 | |
| 17 | /** |
| 18 | * Element category. |
| 19 | * |
| 20 | * @var string |
| 21 | */ |
| 22 | public $category = 'SureCart Elements'; |
| 23 | |
| 24 | /** |
| 25 | * Element name. |
| 26 | * |
| 27 | * @var string |
| 28 | */ |
| 29 | public $name = 'surecart-product-media'; |
| 30 | |
| 31 | /** |
| 32 | * Element block name. |
| 33 | * |
| 34 | * @var string |
| 35 | */ |
| 36 | public $block_name = 'surecart/product-media'; |
| 37 | |
| 38 | /** |
| 39 | * Element icon. |
| 40 | * |
| 41 | * @var string |
| 42 | */ |
| 43 | public $icon = 'ti-layout-slider-alt'; |
| 44 | |
| 45 | /** |
| 46 | * Get element label. |
| 47 | * |
| 48 | * @return string |
| 49 | */ |
| 50 | public function get_label() { |
| 51 | return esc_html__( 'Product media', 'surecart' ); |
| 52 | } |
| 53 | |
| 54 | /** |
| 55 | * Set controls. |
| 56 | * |
| 57 | * @return void |
| 58 | */ |
| 59 | public function set_controls() { |
| 60 | $this->controls['auto_height'] = [ |
| 61 | 'tab' => 'content', |
| 62 | 'label' => esc_html__( 'Auto height', 'surecart' ), |
| 63 | 'type' => 'checkbox', |
| 64 | 'inline' => true, |
| 65 | 'fullAccess' => true, |
| 66 | 'default' => true, |
| 67 | ]; |
| 68 | |
| 69 | $this->controls['height'] = [ |
| 70 | 'tab' => 'content', |
| 71 | 'label' => esc_html__( 'Height', 'surecart' ), |
| 72 | 'type' => 'number', |
| 73 | 'units' => true, |
| 74 | 'default' => '310px', |
| 75 | 'placeholder' => '310px', |
| 76 | 'required' => [ |
| 77 | [ 'auto_height', '!=', true ], |
| 78 | ], |
| 79 | 'fullAccess' => true, |
| 80 | ]; |
| 81 | |
| 82 | $this->controls['max_image_width'] = [ |
| 83 | 'tab' => 'content', |
| 84 | 'label' => esc_html__( 'Max image width', 'surecart' ), |
| 85 | 'type' => 'number', |
| 86 | 'units' => true, |
| 87 | 'placeholder' => esc_html__( 'Unlimited', 'surecart' ), |
| 88 | ]; |
| 89 | |
| 90 | $this->controls['thumbnails_per_page'] = [ |
| 91 | 'tab' => 'content', |
| 92 | 'label' => esc_html__( 'Thumbs per page', 'surecart' ), |
| 93 | 'type' => 'number', |
| 94 | 'default' => 5, |
| 95 | 'min' => 2, |
| 96 | 'placeholder' => 5, |
| 97 | ]; |
| 98 | } |
| 99 | |
| 100 | /** |
| 101 | * Render element. |
| 102 | * |
| 103 | * @return void |
| 104 | */ |
| 105 | public function render() { |
| 106 | $product = sc_get_product(); |
| 107 | |
| 108 | if ( $this->is_admin_editor() && 1 < count( ( $product->gallery ?? [] ) ) ) { |
| 109 | $content = '<img src="' . esc_url( trailingslashit( \SureCart::core()->assets()->getUrl() ) . 'images/placeholder.jpg' ) . '"'; |
| 110 | $content .= ' style="' . ( ! empty( $this->settings['max_image_width'] ) ? 'max-width:' . esc_attr( $this->settings['max_image_width'] ) : '' ) . '"'; |
| 111 | $content .= ' alt="' . esc_attr( get_the_title() ) . '" />'; |
| 112 | $content .= '<div class="bricks-element-placeholder" data-type="info" draggable="false"><i class="ti-layout-slider-alt"></i><div class="placeholder-inner"><div class="placeholder-description">' . __( 'The accurate preview for this element is only available on frontend due to compatibility issues.', 'surecart' ) . '</div></div></div>'; |
| 113 | |
| 114 | echo $this->preview( // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 115 | $content, |
| 116 | '', |
| 117 | 'figure' |
| 118 | ); |
| 119 | |
| 120 | return; |
| 121 | } |
| 122 | |
| 123 | echo $this->html( // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 124 | [ |
| 125 | 'auto_height' => (bool) ! empty( $this->settings['auto_height'] ), |
| 126 | 'height' => esc_html( $this->settings['height'] ), |
| 127 | 'width' => esc_html( $this->settings['max_image_width'] ?? null ), |
| 128 | 'thumbnails_per_page' => ! empty( $this->settings['thumbnails_per_page'] ) ? (int) $this->settings['thumbnails_per_page'] : null, |
| 129 | ] |
| 130 | ); |
| 131 | } |
| 132 | } |
| 133 |