API
2 years ago
Blocks
5 years ago
License
5 years ago
AdminNotice.php
5 years ago
AdminNotices.php
4 years ago
AjaxActions.php
2 years ago
Blocks.php
5 years ago
Compatibility.php
4 years ago
Menu.php
3 years ago
Migrations.php
5 years ago
Player.php
2 years ago
ProCompatibility.php
2 years ago
ReusableVideos.php
4 years ago
Scripts.php
2 years ago
Settings.php
4 years ago
Shortcodes.php
2 years ago
Streamer.php
4 years ago
Translation.php
2 years ago
VideoPostType.php
4 years ago
ReusableVideos.php
146 lines
| 1 | <?php |
| 2 | |
| 3 | namespace PrestoPlayer\Services; |
| 4 | |
| 5 | use PrestoPlayer\Services\Scripts; |
| 6 | |
| 7 | |
| 8 | class ReusableVideos |
| 9 | { |
| 10 | /** |
| 11 | * Register shortcode |
| 12 | * |
| 13 | * @return void |
| 14 | */ |
| 15 | public function register() |
| 16 | { |
| 17 | add_action('admin_notices', [$this, 'notice']); |
| 18 | add_action('admin_init', [$this, 'dismissNotice']); |
| 19 | } |
| 20 | |
| 21 | public function notice() |
| 22 | { |
| 23 | global $typenow, $current_screen; |
| 24 | |
| 25 | if (!($typenow === 'pp_video_block' && $current_screen->base === 'edit')) { |
| 26 | return; |
| 27 | } |
| 28 | |
| 29 | $notice_name = 'presto_player_reusable_notice'; |
| 30 | if (AdminNotices::isDismissed($notice_name)) { |
| 31 | return; |
| 32 | } |
| 33 | ?> |
| 34 | <div class="notice" style="border-left-color: #7c3aed;"> |
| 35 | <p><strong><?php _e('What is the media hub?', 'presto-player'); ?></strong></p> |
| 36 | <p><?php _e('The media hub is a more flexible way to add media to your site. It allows you to save audio and videos which you can later use in any post or page on your site - either through the Block Editor, a page builder, or by using a shortcode or php function.', 'presto-player'); ?></p> |
| 37 | <p><a href="<?php echo esc_url(add_query_arg(array('presto_action' => 'dismiss_notices', 'presto_notice' => $notice_name))); ?>"><?php _e('Dismiss Notice', 'presto-player'); ?></a></p> |
| 38 | </div> |
| 39 | <?php |
| 40 | } |
| 41 | |
| 42 | public function dismissNotice() |
| 43 | { |
| 44 | // permissions check |
| 45 | if (!current_user_can('update_options')) { |
| 46 | return; |
| 47 | } |
| 48 | |
| 49 | // not our notices, bail |
| 50 | if (!isset($_GET['presto_action']) || 'dismiss_notice' !== $_GET['presto_action']) { |
| 51 | return; |
| 52 | } |
| 53 | |
| 54 | $notice = !empty($_GET['presto_notice']) ? sanitize_text_field($_GET['presto_notice']) : ''; |
| 55 | |
| 56 | if (!$notice) { |
| 57 | return; |
| 58 | } |
| 59 | |
| 60 | // notice is dismissed |
| 61 | update_option("presto_player_dismissed_notice_" . sanitize_text_field($notice), 1); |
| 62 | } |
| 63 | |
| 64 | /** |
| 65 | * Get reusable video block function. |
| 66 | * |
| 67 | * @param mixed $id The ID of the reusable block. |
| 68 | * @return $content The content of the block. |
| 69 | */ |
| 70 | public static function get($id) |
| 71 | { |
| 72 | $content_post = get_post($id); |
| 73 | $content = $content_post->post_content; |
| 74 | return $content; |
| 75 | } |
| 76 | |
| 77 | public static function getBlock($id) |
| 78 | { |
| 79 | $blocks = parse_blocks(self::get($id)); |
| 80 | $out = ''; |
| 81 | if(is_feed()) { |
| 82 | foreach ($blocks as $block) { |
| 83 | foreach ($block['innerBlocks'] as $innerblock) { |
| 84 | $out .= self::getFeedHtml( $innerblock ); |
| 85 | } |
| 86 | } |
| 87 | return $out; |
| 88 | } |
| 89 | |
| 90 | foreach ($blocks as $block) { |
| 91 | $out .= render_block($block); |
| 92 | } |
| 93 | |
| 94 | return $out; |
| 95 | } |
| 96 | |
| 97 | /** |
| 98 | * Display block function. |
| 99 | * |
| 100 | * @param mixed $id The ID of the reusable block. |
| 101 | */ |
| 102 | public static function display($id) |
| 103 | { |
| 104 | echo self::getBlock($id); |
| 105 | } |
| 106 | |
| 107 | /** |
| 108 | * Return fallback html for feeds. |
| 109 | * |
| 110 | * @param array $block array of block attributes. |
| 111 | */ |
| 112 | public static function getFeedHtml( $block ) { |
| 113 | |
| 114 | $html = ''; |
| 115 | if( $block['blockName'] === 'presto-player/vimeo') { |
| 116 | ob_start(); |
| 117 | ?> |
| 118 | <div class="presto-iframe-fallback-container" > |
| 119 | <iframe style="width: 100%" class="presto-fallback-iframe" id="presto-iframe-fallback-<?php echo (int) $block['attrs']['id']; ?>" src="<?php echo esc_attr($block['attrs']['src']); ?>" ></iframe> |
| 120 | </div> |
| 121 | <?php |
| 122 | $html = ob_get_clean(); |
| 123 | } |
| 124 | elseif( $block['blockName'] === 'presto-player/youtube') { |
| 125 | ob_start(); |
| 126 | ?> |
| 127 | <div class="presto-iframe-fallback-container" > |
| 128 | <iframe style="width: 100%" class="presto-fallback-iframe" id="presto-iframe-fallback-<?php echo (int) $block['attrs']['id']; ?>" src="<?php echo esc_attr($block['attrs']['src']); ?>"></iframe> |
| 129 | </div> |
| 130 | <?php |
| 131 | $html = ob_get_clean(); |
| 132 | } |
| 133 | else { |
| 134 | ob_start(); |
| 135 | ?> |
| 136 | <video controls preload="none" > |
| 137 | <source src="<?php echo esc_attr( $block['attrs']['src'] ); ?>" /> |
| 138 | </video> |
| 139 | <?php |
| 140 | $html = ob_get_clean(); |
| 141 | } |
| 142 | return $html; |
| 143 | |
| 144 | } |
| 145 | } |
| 146 |