Example #1
0
/**
 * Standardize paths for our various types of allowed path formats.
 * 
 * @param   string    File to process, in a variety of path formats
 * @param   string    Type of file we're working with: css, js, or img
 * @return  string    URL path to file, relative to root, with timestamp appended.
 */
function get_path($file, $type)
{
    global $document_root;
    // Don't do anything with complete URLs
    if (preg_match('|^https?://|', $file)) {
        return $file;
    }
    // Make sure DOCUMENT_ROOT does not have a trailing slash
    $document_root = preg_replace('|/$|', '', $document_root);
    if (strpos($file, '/') === 0) {
        // Path from site root
        $fs_path = $document_root . $file;
        $url_path = $file . asset_timestamp($fs_path);
    } else {
        // Get file subdirectory
        $subdir = get_file_subdir($type);
        // Is this a WordPress site?
        if (is_wordpress()) {
            // Path relative to WP theme directory
            $fs_path = TEMPLATEPATH . $subdir . '/' . $file;
            $url_path = str_replace($document_root, '', $fs_path) . asset_timestamp($fs_path);
        } else {
            // Path relative to site root
            $fs_path = $document_root . $subdir . '/' . $file;
            $url_path = $subdir . '/' . $file . asset_timestamp($fs_path);
        }
    }
    if (defined('ASSET_HOST')) {
        $url_path = asset_host_url($url_path);
    }
    return $url_path;
}
function get_path($file, $type = 'js')
{
    if (preg_match('|^https?://|', $file)) {
        return $file;
    }
    if (strpos($file, '/') === 0) {
        $fs_path = $_SERVER['DOCUMENT_ROOT'] . $file;
        $url_path = $file . asset_timestamp($fs_path);
    } else {
        $fs_path = $_SERVER['DOCUMENT_ROOT'] . dir_path_for($type) . $file;
        $url_path = str_replace($_SERVER['DOCUMENT_ROOT'], '', $fs_path) . asset_timestamp($fs_path);
    }
    return $url_path;
}