function forum_get_content_delivery_path($file_path) { static $content_delivery_domain_index = -1; static $content_delivery_domains_array = false; static $content_delivery_files_array = array(); if (!is_array($content_delivery_domains_array)) { $content_delivery_domains_array = explode("\n", forum_get_setting('content_delivery_domains')); $content_delivery_domains_array = array_map('trim', $content_delivery_domains_array); $content_delivery_domains_array = array_values(array_filter($content_delivery_domains_array)); } if (sizeof($content_delivery_domains_array) < 1) { return false; } if (isset($content_delivery_files_array[$file_path])) { return $content_delivery_files_array[$file_path]; } $content_delivery_domain_index++; if (isset($content_delivery_domains_array[$content_delivery_domain_index])) { $content_delivery_files_array[$file_path] = $content_delivery_domains_array[$content_delivery_domain_index]; return preg_replace('/^http(s)?:\\/\\//', '', $content_delivery_files_array[$file_path]); } $content_delivery_domain_index = -1; return forum_get_content_delivery_path($file_path); }
function html_get_forum_file_path($file_path, $allow_cdn = true) { // Cache of requested file paths. static $file_path_cache_array = array(); // Check if the path is in the cache. if (!isset($file_path_cache_array[$file_path])) { // Get the BH_FORUM_PATH prefix. $forum_path = server_get_forum_path(); // HTTP schema $http_scheme = isset($_SERVER['HTTPS']) && mb_strtolower($_SERVER['HTTPS']) == 'on' ? 'https' : 'http'; // Disable CDN for everything but CSS, icons, images and Javascript if ($url_file_path = @parse_url($file_path, PHP_URL_PATH)) { $allow_cdn = preg_match('/\\.png$|\\.css$|\\.ico$|\\.js$/Diu', $url_file_path) > 0 ? $allow_cdn : false; } // If CDN is allowed, get the CDN path including the domain. if ($allow_cdn === true && ($cdn_domain = forum_get_content_delivery_path($file_path))) { $final_file_path = sprintf('%s://%s/%s', $http_scheme, trim($cdn_domain, '/'), ltrim($file_path, '/')); } else { $final_file_path = preg_replace('/^.\\//', '', sprintf('%s/%s', $forum_path, ltrim($file_path, '/'))); } // Add final file path to the cache. $file_path_cache_array[$file_path] = $final_file_path; } // Return the cached entry. return $file_path_cache_array[$file_path]; }