PluginProbe ʕ •ᴥ•ʔ
Music Player for WooCommerce / 1.8.3
Music Player for WooCommerce v1.8.3
1.8.3 1.8.2 1.8.1 1.1.10 1.1.11 1.1.2 1.1.3 1.1.4 1.1.5 1.1.6 1.1.7 1.1.8 1.1.9 1.2.0 1.2.1 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 1.3.0 1.3.1 1.3.10 1.3.11 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 1.3.7 1.3.8 1.3.9 1.4.0 1.4.1 1.4.2 1.4.3 1.4.4 1.4.5 1.5.0 1.5.1 1.6.0 1.6.1 1.6.2 1.6.3 1.7.0 1.7.1 1.7.2 1.7.3 1.7.4 1.7.5 1.7.6 1.7.7 1.7.8 1.7.9 1.8.0 trunk 1.0.173 1.0.174 1.0.175 1.0.176 1.0.177 1.0.178 1.0.179 1.0.180 1.0.181 1.0.182 1.0.183 1.0.184 1.0.185 1.0.186 1.0.187 1.0.188 1.0.189 1.0.190 1.0.191 1.0.192 1.0.193 1.0.194 1.0.195 1.0.196 1.0.197 1.1.0 1.1.1
music-player-for-woocommerce / inc / tools.inc.php
music-player-for-woocommerce / inc Last commit date
cache.inc.php 1 month ago landing.inc.php 1 month ago skingenerator.inc.php 1 month ago tools.inc.php 1 month ago
tools.inc.php
60 lines
1 <?php
2
3 if ( ! class_exists( 'WooCommerceMusicPlayerTools' ) ) {
4 class WooCommerceMusicPlayerTools {
5
6 public static function get_google_drive_download_url( $url ) {
7 // Match different possible Google Drive URL patterns
8 $patterns = [
9 '/drive\.google\.com\/file\/d\/([a-zA-Z0-9_-]+)/i', // format: /file/d/FILE_ID/
10 '/drive\.google\.com\/open\?id=([a-zA-Z0-9_-]+)/i', // format: /open?id=FILE_ID
11 '/drive\.google\.com\/uc\?id=([a-zA-Z0-9_-]+)/i' // format: /uc?id=FILE_ID
12 ];
13
14 foreach ($patterns as $pattern) {
15 if (preg_match($pattern, $url, $matches)) {
16 $fileId = $matches[1];
17 return "https://drive.google.com/uc?export=download&id={$fileId}";
18 }
19 }
20
21 // Return original URL if it's not a recognized format
22 return $url;
23 } // End preprocess_google_drive_url
24
25 public static function get_google_drive_file_name( $url ) {
26 $download_url = self::get_google_drive_download_url( $url );
27
28 $pattern = '/drive\.google\.com\/uc\?export\=download&id\=[a-zA-Z0-9_-]+/i';
29
30 try {
31 if (
32 preg_match( $pattern, $download_url, $matches )
33 ) {
34
35 // Trying to obtain the file information directly from Google Drive.
36 $response = wp_remote_head( $download_url, [
37 'redirection' => 5,
38 'timeout' => 15,
39 ]);
40
41 if ( ! is_wp_error( $response ) ) {
42 $headers = wp_remote_retrieve_headers($response);
43
44 // Check for Content-Disposition header
45 if ( ! empty( $headers['content-disposition'] ) ) {
46 if ( preg_match( '/filename="([^"]+)"/', $headers['content-disposition'], $matches ) ) {
47 return $matches[1];
48 }
49 }
50 }
51 }
52 } catch ( Exception $err ) {
53 error_log( $err );
54 }
55
56 return $url;
57 } // En get_google_drive_file_name
58
59 } // End WooCommerceMusicPlayerTools
60 }