Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 35 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 1 |
| VideoPress_Divi_Module | |
0.00% |
0 / 33 |
|
0.00% |
0 / 3 |
30 | |
0.00% |
0 / 1 |
| init | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
| get_fields | |
0.00% |
0 / 9 |
|
0.00% |
0 / 1 |
2 | |||
| render | |
0.00% |
0 / 22 |
|
0.00% |
0 / 1 |
12 | |||
| 1 | <?php |
| 2 | /** |
| 3 | * VideoPress Divi Editor module. |
| 4 | * |
| 5 | * @package VideoPress |
| 6 | */ |
| 7 | |
| 8 | use Automattic\Jetpack\VideoPress\Jwt_Token_Bridge; |
| 9 | |
| 10 | if ( ! defined( 'ABSPATH' ) ) { |
| 11 | exit( 0 ); |
| 12 | } |
| 13 | |
| 14 | /** |
| 15 | * VideoPress Divi module |
| 16 | **/ |
| 17 | class VideoPress_Divi_Module extends ET_Builder_Module { |
| 18 | |
| 19 | /** |
| 20 | * Module slug |
| 21 | * |
| 22 | * @var string |
| 23 | */ |
| 24 | public $slug = 'divi_videopress'; |
| 25 | |
| 26 | /** |
| 27 | * For matching VideoPress urls or guids. |
| 28 | * |
| 29 | * @var string |
| 30 | */ |
| 31 | const VIDEOPRESS_REGEX = '/^(?:(?:http(?:s)?:\/\/)?(?:www\.)?video(?:\.word)?press\.com\/(?:v|embed)\/)?([a-zA-Z\d]+)(?:.*)?/i'; |
| 32 | |
| 33 | /** |
| 34 | * Vd support. |
| 35 | * |
| 36 | * @var string |
| 37 | */ |
| 38 | public $vb_support = 'on'; |
| 39 | |
| 40 | /** |
| 41 | * Credits. |
| 42 | * |
| 43 | * @var array |
| 44 | */ |
| 45 | protected $module_credits = array( |
| 46 | 'module_uri' => 'https://automattic.com', |
| 47 | 'author' => 'Automattic Inc', |
| 48 | 'author_uri' => 'https://automattic.com', |
| 49 | ); |
| 50 | |
| 51 | /** |
| 52 | * Name. |
| 53 | * |
| 54 | * @var string |
| 55 | */ |
| 56 | public $name; |
| 57 | |
| 58 | /** |
| 59 | * Icon. |
| 60 | * |
| 61 | * @var string |
| 62 | */ |
| 63 | public $icon; |
| 64 | |
| 65 | /** |
| 66 | * Properties. |
| 67 | * |
| 68 | * @var array |
| 69 | */ |
| 70 | public $props; |
| 71 | |
| 72 | /** |
| 73 | * Initialize the thing. |
| 74 | */ |
| 75 | public function init() { |
| 76 | $this->name = esc_html__( 'VideoPress', 'jetpack-videopress-pkg' ); |
| 77 | $this->icon = 'q'; |
| 78 | } |
| 79 | |
| 80 | /** |
| 81 | * Get the fields of the block. |
| 82 | * |
| 83 | * @return array |
| 84 | */ |
| 85 | public function get_fields() { |
| 86 | return array( |
| 87 | 'guid' => array( |
| 88 | 'label' => esc_html__( 'URL or Video ID', 'jetpack-videopress-pkg' ), |
| 89 | 'type' => 'text', |
| 90 | 'option_category' => 'basic_option', |
| 91 | 'description' => esc_html__( 'Paste a VideoPress URL or Video ID', 'jetpack-videopress-pkg' ), |
| 92 | 'toggle_slug' => 'main_content', |
| 93 | ), |
| 94 | ); |
| 95 | } |
| 96 | |
| 97 | /** |
| 98 | * Render. |
| 99 | * |
| 100 | * Note: while phpcs complains about unused vars in the method signature, they SHOULD be there. We override an existing method. |
| 101 | * |
| 102 | * @param array $attrs The attributes. |
| 103 | * @param string|null $content The content. |
| 104 | * @param string|null $render_slug The render slug. |
| 105 | * |
| 106 | * @return string |
| 107 | */ |
| 108 | public function render( $attrs, $content = null, $render_slug = null ) { // phpcs:disable VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable |
| 109 | $matches = array(); |
| 110 | |
| 111 | if ( ! preg_match( self::VIDEOPRESS_REGEX, $this->props['guid'], $matches ) ) { |
| 112 | return ''; |
| 113 | } |
| 114 | |
| 115 | if ( ! isset( $matches[1] ) ) { |
| 116 | return ''; |
| 117 | } |
| 118 | |
| 119 | Jwt_Token_Bridge::enqueue_jwt_token_bridge(); |
| 120 | |
| 121 | $guid = $matches[1]; |
| 122 | $iframe_title = sprintf( |
| 123 | /* translators: %s: Video title. */ |
| 124 | esc_html__( 'Video player for %s', 'jetpack-videopress-pkg' ), |
| 125 | esc_html( $guid ) |
| 126 | ); |
| 127 | |
| 128 | $iframe_src = sprintf( |
| 129 | 'https://videopress.com/embed/%s?autoPlay=0&permalink=0&loop=0&embedder=divi-builder', |
| 130 | esc_attr( $guid ) |
| 131 | ); |
| 132 | $format_string = '<div class="vidi-videopress-wrapper"><iframe title="' . |
| 133 | esc_attr( $iframe_title ) . |
| 134 | '" src="' . |
| 135 | $iframe_src . |
| 136 | '" width="100%" height="100%" frameborder="0" allowfullscreen></iframe>' . |
| 137 | // phpcs:disable WordPress.WP.EnqueuedResources.NonEnqueuedScript |
| 138 | '<script src="https://en.wordpress.com/wp-content/plugins/video/assets/js/next/videopress-iframe.js?m=1658739239"></script></div>'; |
| 139 | |
| 140 | return $format_string; |
| 141 | } |
| 142 | } |