PluginProbe
Depicter — Popup & Slider Builder / 1.3.2
Depicter — Popup & Slider Builder v1.3.2
4.8.1 trunk 1.0.0 1.1.0 1.1.2 1.1.4 1.1.6 1.1.7 1.1.8 1.1.9 1.2.0 1.3.0 1.3.1 1.3.2 1.3.3 1.3.5 1.3.8 1.5.0 1.5.1 1.5.2 1.5.5 1.6.0 1.6.1 1.6.2 1.7.0 All 76 releases
depicter / vendor / averta / core / src / Utility / Embed.php

Embed.php in Depicter — Popup & Slider Builder 1.3.2, at vendor/averta/core/src/Utility/Embed.php

62 lines 1.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace Averta\Core\Utility;
3
4
5 class Embed
6 {
7 /**
8 * Extracts and returns YouTube video code from video url
9 *
10 * @param string $videoUrl YouTube url
11 *
12 * @return bool|mixed Returns the YouTube video code on success, and false on failure.
13 */
14 public static function getYouTubeCode( $videoUrl ){
15 if ( strpos( $videoUrl, 'youtu.be' ) !== false ) {
16 return pathinfo( $videoUrl, PATHINFO_FILENAME );
17 }
18 return Str::extractByRegex( $videoUrl, '/[\\?\\&]v=([^\\?\\&]+)/', 1 );
19 }
20
21 /**
22 * Converts YouTube url to embed url
23 *
24 * @param string $videoUrl YouTube url
25 *
26 * @return bool|mixed Returns the YouTube embed url on success, and false on failure.
27 */
28 public static function getYouTubeEmbedUrl( $videoUrl ){
29 if( $code = self::getYouTubeCode( $videoUrl ) ){
30 return 'https://www.youtube.com/embed/' . $code;
31 }
32
33 return $code;
34 }
35
36 /**
37 * Extracts and returns Vimeo video code from video url
38 *
39 * @param string $videoUrl Vimeo url
40 *
41 * @return bool|mixed Returns the Vimeo video code on success, and false on failure.
42 */
43 public static function getVimeoCode( $videoUrl ){
44 return Str::extractByRegex( $videoUrl, '/vimeo\.com\/([0-9]{1,10})/', 1 );
45 }
46
47 /**
48 * Converts Vimeo url to embed url
49 *
50 * @param string $videoUrl Vimeo url
51 *
52 * @return bool|mixed Returns the Vimeo embed url on success, and false on failure.
53 */
54 public static function getVimeoEmbedUrl( $videoUrl ){
55 if( $code = self::getVimeoCode( $videoUrl ) ){
56 return 'https://player.vimeo.com/video/' . $code;
57 }
58
59 return $code;
60 }
61 }
62