示例#1
0
function cdn($asset)
{
    // Verify if KeyCDN URLs are present in the config file
    if (!Config::get('app.cdn')) {
        return asset($asset);
    }
    // Get file name incl extension and CDN URLs
    $cdns = Config::get('app.cdn');
    $assetName = basename($asset);
    // Remove query string
    $assetName = explode("?", $assetName);
    $assetName = $assetName[0];
    // Select the CDN URL based on the extension
    foreach ($cdns as $cdn => $types) {
        if (preg_match('/^.*\\.(' . $types . ')$/i', $assetName)) {
            return cdnPath($cdn, $asset);
        }
    }
    // In case of no match use the last in the array
    end($cdns);
    return cdnPath(key($cdns), $asset);
}
示例#2
0
文件: helpers.php 项目: flgx/htdocs
/**
 * Use Cdn for files
 * @param  string $asset    
 */
function cdn($asset)
{
    //Check if we added cdn's to the config file
    if (!Config::get('app.image.cdn')) {
        return asset($asset);
    }
    //Get file name & cdn's
    $cdns = Config::get('app.image.cdn');
    $assetName = basename($asset);
    //remove any query string for matching
    $assetName = explode("?", $assetName);
    $assetName = $assetName[0];
    //Find the correct cdn to use
    foreach ($cdns as $cdn => $types) {
        if (preg_match('/^.*\\.(' . $types . ')$/i', $assetName)) {
            return cdnPath($cdn, $asset);
        }
    }
    //If we couldnt match a cdn, use the last in the list.
    end($cdns);
    return cdnPath(key($cdns), $asset);
}