PluginProbe
Booking Calendar / 11.7
Booking Calendar v11.7
11.8.1 11.8 11.7 11.6.1 11.6 11.5 11.4.3 11.4.2 11.4.1 11.4 11.3 11.2.1 11.2 11.1 11.0 10.15.7 10.15.6 10.1.3 10.10 10.10.1 10.10.2 10.11 10.11.2 10.11.3 10.11.4 All 201 releases
booking / includes / _functions / starter-assets.php

starter-assets.php in Booking Calendar 11.7, at includes/_functions/starter-assets.php

49 lines 1.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Starter-image URL resolution.
4 *
5 * @package Booking Calendar
6 * @since 11.6.0
7 */
8
9 if ( ! defined( 'ABSPATH' ) ) {
10 exit;
11 }
12
13 /**
14 * Resolve a bundled starter image from the configured local or remote source.
15 *
16 * The relative path is allow-listed to the plugin assets hierarchy. Absolute
17 * paths, parent traversal, query strings, and fragments are rejected so the
18 * helper cannot become an arbitrary URL proxy. Local URLs retain their plugin
19 * subdirectory; the remote source uses the filename in its flat asset folder.
20 *
21 * @param string $relative_path Path below the plugin `assets` directory.
22 *
23 * @return string Sanitized image URL, or an empty string for an invalid path.
24 */
25 function wpbc_get_starter_asset_url( $relative_path ) {
26 $relative_path = str_replace( '\\', '/', trim( (string) $relative_path ) );
27 $relative_path = ltrim( $relative_path, '/' );
28
29 if (
30 '' === $relative_path
31 || false !== strpos( $relative_path, '..' )
32 || false !== strpos( $relative_path, '?' )
33 || false !== strpos( $relative_path, '#' )
34 || 1 !== preg_match( '#^[a-zA-Z0-9_./-]+$#', $relative_path )
35 ) {
36 return '';
37 }
38
39 $is_remote_source = defined( 'WPBC_STARTER_ASSETS_SOURCE' )
40 && 'remote' === strtolower( (string) WPBC_STARTER_ASSETS_SOURCE );
41 $assets_base_url = $is_remote_source
42 ? 'https://wpbookingcalendar.com/assets/plugin/assets/'
43 : trailingslashit( WPBC_PLUGIN_URL ) . 'assets/';
44 // $asset_path = $is_remote_source ? wp_basename( $relative_path ) : $relative_path;
45 $asset_path = $relative_path;
46
47 return esc_url_raw( $assets_base_url . $asset_path );
48 }
49