AudioBlock.php
2 years ago
ReusableEditBlock.php
2 years ago
ReusableVideoBlock.php
5 years ago
SelfHostedBlock.php
2 years ago
VimeoBlock.php
2 years ago
YouTubeBlock.php
2 years ago
AudioBlock.php
69 lines
| 1 | <?php |
| 2 | |
| 3 | namespace PrestoPlayer\Blocks; |
| 4 | |
| 5 | use PrestoPlayer\Attachment; |
| 6 | use PrestoPlayer\Models\CurrentUser; |
| 7 | use PrestoPlayer\Support\Block; |
| 8 | |
| 9 | class AudioBlock extends Block |
| 10 | { |
| 11 | /** |
| 12 | * Block name |
| 13 | * |
| 14 | * @var string |
| 15 | */ |
| 16 | protected $name = 'audio'; |
| 17 | |
| 18 | /** |
| 19 | * Bail if user cannot access video |
| 20 | * |
| 21 | * @return void |
| 22 | */ |
| 23 | public function middleware($attributes, $content) |
| 24 | { |
| 25 | // if private and user cannot access video, don't load |
| 26 | if (!empty($attributes['visibility']) && 'private' === $attributes['visibility']) { |
| 27 | if (empty($attributes['id'])) { |
| 28 | return false; |
| 29 | } |
| 30 | if (!CurrentUser::canAccessVideo($attributes['id'])) { |
| 31 | return false; |
| 32 | } |
| 33 | } |
| 34 | |
| 35 | return parent::middleware($attributes, $content); |
| 36 | } |
| 37 | |
| 38 | /** |
| 39 | * Add curtain styles. |
| 40 | * |
| 41 | * @return void |
| 42 | */ |
| 43 | public function sanitizeAttributes($attributes, $default_config) |
| 44 | { |
| 45 | |
| 46 | $src = !empty($attributes['src']) ? $attributes['src'] : ''; |
| 47 | |
| 48 | return [ |
| 49 | 'src' => !empty($attributes['attachment_id']) ? Attachment::getSrc($attributes['attachment_id']) : $src, |
| 50 | 'styles' => $default_config['styles'] . ' --presto-curtain-size: 25%', |
| 51 | ]; |
| 52 | } |
| 53 | |
| 54 | /** |
| 55 | * Register the block type. |
| 56 | * |
| 57 | * @return void |
| 58 | */ |
| 59 | public function registerBlockType() |
| 60 | { |
| 61 | register_block_type( |
| 62 | PRESTO_PLAYER_PLUGIN_DIR . 'src/admin/blocks/blocks/audio', |
| 63 | array( |
| 64 | 'render_callback' => [$this, 'html'], |
| 65 | ) |
| 66 | ); |
| 67 | } |
| 68 | } |
| 69 |