Get the latest version number for the remote version.

Paramètres

string $name: Name of the library.

array $library: An associative array containing all information about the library.

bool $use_cache: TRUE try the cache first.

Return value

string The latest version number as a string or 0 on failure.

5 calls to advagg_get_remote_libraries_version()
advagg_font_admin_settings_form dans advagg_font/advagg_font.admin.inc
Form builder; Configure advagg settings.
advagg_font_libraries_info dans advagg_font/advagg_font.module
Implements hook_libraries_info().
advagg_get_remote_libraries_versions dans ./advagg.module
Update github version numbers to the latest.
advagg_mod_libraries_info dans advagg_mod/advagg_mod.module
Implements hook_libraries_info().
advagg_validator_libraries_info dans advagg_validator/advagg_validator.module
Implements hook_libraries_info().

Fichier

./advagg.module, line 5755

Code

function advagg_get_remote_libraries_version($name, array $library, $use_cache = TRUE) {
    if ($use_cache) {
        $cid = 'advagg_get_remote_libraries_versions';
        $versions = advagg_get_remote_libraries_versions_cache($cid);
        if (isset($versions[$name]['remote'])) {
            return $versions[$name]['remote'];
        }
    }
    // Remote url is not set, see if we can generate it given the current data.
    if (empty($library['remote']['url']) && !empty($library['version arguments'])) {
        if (!isset($library['version arguments']['file']) && isset($library['version arguments']['variants'])) {
            // Use the first variant.
            $file = reset($library['version arguments']['variants']);
            $library['version arguments']['file'] = $file['file'];
            $library['version arguments']['pattern'] = $file['pattern'];
        }
        if (!empty($library['version arguments']['file'])) {
            if (!empty($library['vendor url'])) {
                // Use vendor url if it's a github one.
                if (strpos($library['vendor url'], 'https://github.com/') === 0) {
                    $parsed_vendor = @parse_url($library['vendor url']);
                    // Previously: https://rawgit.com{$parsed_vendor['path']}/master/{$library['version arguments']['file']} .
                    $library['remote']['url'] = "https://cdn.jsdelivr.net/gh{$parsed_vendor['path']}@master/{$library['version arguments']['file']}";
                }
            }
            if (empty($library['remote']['url']) && !empty($library['download url'])) {
                // Use download url if it's a github one.
                if (strpos($library['download url'], 'https://github.com/') === 0) {
                    $parsed_download = @parse_url($library['download url']);
                    $paths = explode('/', $parsed_download['path']);
                    $parsed_download['path'] = "/{$paths[1]}/{$paths[2]}";
                    // Previously: https://rawgit.com{$parsed_download['path']}/master/{$library['version arguments']['file']} .
                    $library['remote']['url'] = "https://cdn.jsdelivr.net/gh{$parsed_download['path']}@master/{$library['version arguments']['file']}";
                }
            }
        }
    }
    // Remote callback is not set, try to generate it given the current data.
    if (empty($library['remote']['callback']) && isset($library['version arguments']['file'])) {
        if (!empty($library['version callback'])) {
            // Use defined parser.
            $library['remote']['callback'] = $library['version callback'];
        }
        else {
            if ($library['version arguments']['file'] === 'package.json') {
                // JSON parser.
                $library['remote']['callback'] = 'advagg_get_github_version_json';
            }
            else {
                // Text parser.
                $library['remote']['callback'] = 'advagg_get_github_version_txt';
            }
        }
    }
    // Get remote version.
    $return = 0;
    if (!empty($library['remote']) && !empty($library['remote']['callback']) && !empty($library['remote']['url']) && isset($library['version arguments']) && is_callable($library['remote']['callback']) && variable_get('advagg_remote_version_check', ADVAGG_REMOTE_VERSION_CHECK)) {
        $return = $library['remote']['callback']($library, $library['version arguments'], $library['remote']['url']);
        // Try package.json on failure.
        if (empty($return) && $library['version arguments']['file'] !== 'package.json') {
            $pos = strrpos($library['remote']['url'], $library['version arguments']['file']);
            $library['remote']['url'] = substr($library['remote']['url'], 0, $pos) . 'package.json';
            $library['remote']['callback'] = 'advagg_get_github_version_json';
            $return = $library['remote']['callback']($library, $library['version arguments'], $library['remote']['url']);
        }
    }
    if (empty($return) && !empty($library['version arguments']['default_version'])) {
        $return = $library['version arguments']['default_version'];
    }
    return $return;
}