Implements hook_cron().

Fichier

advagg_relocate/advagg_relocate.module, line 237

Code

function advagg_relocate_cron() {
    // Get filenames in directory.
    $dir = rtrim(variable_get('advagg_relocate_directory', ADVAGG_RELOCATE_DIRECTORY), '/');
    $files = file_scan_directory($dir, '/.*/');
    // Get cached objects from filenames.
    $cids = array();
    foreach ($files as $info) {
        $ext = strtolower(pathinfo($info->filename, PATHINFO_EXTENSION));
        $cids["advagg_relocate_{$ext}_external:{$info->filename}"] = "advagg_relocate_{$ext}_external:{$info->filename}";
    }
    $cached_data = cache_get_multiple($cids, 'cache_advagg_info');
    // Build css and js arrays.
    $css = array();
    $js = array();
    foreach ($cached_data as $values) {
        $url = $values->data->url;
        $ext = strtolower(pathinfo($url, PATHINFO_EXTENSION));
        if ($ext === "css") {
            $css[$url]['data'] = $url;
            $css[$url]['type'] = 'external';
        }
        elseif ($ext === "js") {
            $js[$url]['data'] = $url;
            $js[$url]['type'] = 'external';
        }
        elseif (!empty($values->headers['content-type']) && stripos($values->headers['content-type'], 'css')) {
            $css[$url]['data'] = $url;
            $css[$url]['type'] = 'external';
        }
        elseif (!empty($values->headers['content-type']) && stripos($values->headers['content-type'], 'javascript')) {
            $js[$url]['data'] = $url;
            $js[$url]['type'] = 'external';
        }
    }
    // Refresh cached data.
    if (!empty($js)) {
        advagg_relocate_js_post_alter($js, TRUE);
    }
    if (!empty($css)) {
        advagg_relocate_css_post_alter($css, TRUE);
    }
}