2020-04-22 22:48:56 +03:00
|
|
|
<?php defined('BASEPATH') or exit('No direct script access allowed');
|
2017-11-08 17:22:30 +03:00
|
|
|
|
|
|
|
/* ----------------------------------------------------------------------------
|
2022-01-18 15:05:42 +03:00
|
|
|
* Easy!Appointments - Online Appointment Scheduler
|
2017-11-08 17:22:30 +03:00
|
|
|
*
|
|
|
|
* @package EasyAppointments
|
|
|
|
* @author A.Tselegidis <alextselegidis@gmail.com>
|
2021-12-18 19:43:45 +03:00
|
|
|
* @copyright Copyright (c) Alex Tselegidis
|
|
|
|
* @license https://opensource.org/licenses/GPL-3.0 - GPLv3
|
|
|
|
* @link https://easyappointments.org
|
2017-11-08 17:22:30 +03:00
|
|
|
* @since v1.3.0
|
|
|
|
* ---------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Assets URL helper function.
|
|
|
|
*
|
|
|
|
* This function will create an asset file URL that includes a cache busting parameter in order
|
|
|
|
* to invalidate the browser cache in case of an update.
|
|
|
|
*
|
|
|
|
* @param string $uri Relative URI (just like the one used in the base_url helper).
|
|
|
|
* @param string|null $protocol Valid URI protocol.
|
|
|
|
*
|
|
|
|
* @return string Returns the final asset URL.
|
|
|
|
*/
|
2024-12-19 21:13:51 +03:00
|
|
|
function asset_url(string $uri = '', ?string $protocol = null): string
|
2018-01-23 12:08:37 +03:00
|
|
|
{
|
2020-12-02 23:12:54 +03:00
|
|
|
$debug = config('debug');
|
2018-01-02 15:34:13 +03:00
|
|
|
|
2023-11-29 12:24:09 +03:00
|
|
|
$cache_busting_token = !$debug ? '?' . config('cache_busting_token') : '';
|
2020-04-22 22:48:56 +03:00
|
|
|
|
2023-11-29 12:24:09 +03:00
|
|
|
if (str_contains(basename($uri), '.js') && !str_contains(basename($uri), '.min.js') && !$debug) {
|
2020-03-18 22:20:43 +03:00
|
|
|
$uri = str_replace('.js', '.min.js', $uri);
|
|
|
|
}
|
|
|
|
|
2023-11-29 12:24:09 +03:00
|
|
|
if (str_contains(basename($uri), '.css') && !str_contains(basename($uri), '.min.css') && !$debug) {
|
2020-03-18 22:20:43 +03:00
|
|
|
$uri = str_replace('.css', '.min.css', $uri);
|
|
|
|
}
|
|
|
|
|
2018-01-02 15:34:13 +03:00
|
|
|
return base_url($uri . $cache_busting_token, $protocol);
|
2017-11-08 17:22:30 +03:00
|
|
|
}
|