Exemplo n.º 1
0
/**
 * Callback function used to automatically parse assets and replace the image src with a CDN version.
 *
 * @param $matches
 *
 * @return string
 */
function filter_cb($matches)
{
    $manager = DomainManager::last();
    $upload_dir = wp_upload_dir();
    $upload_dir = $upload_dir['baseurl'];
    $upload_path = parse_url($upload_dir, PHP_URL_PATH);
    $domain = $manager->cdn_domain($matches[0]);
    $url = explode('://', get_bloginfo('url'));
    array_shift($url);
    /**
     * Modify the domain we're rewriting, should an aliasing plugin be used (for example)
     *
     * @param string $site_domain
     */
    $url = apply_filters('dynamic_cdn_site_domain', rtrim(implode('://', $url), '/'));
    $url = str_replace($manager->site_domain, $domain, $url);
    // Make sure to use https if the request is over SSL
    $scheme = apply_filters('dynamic_cdn_protocol', is_ssl() ? 'https' : 'http');
    // Append query string, if its available
    $query_string = isset($matches[5]) ? $matches[5] : '';
    // If backslashes were escaped, then they need to continue being escaped
    if (strpos($matches[0], '\\/') !== false) {
        $add_slashes = true;
    } else {
        $add_slashes = false;
    }
    $result = "={$matches[1]}{$scheme}:" . ($add_slashes ? addcslashes("//{$url}/", '/') : "//{$url}/") . "{$matches[3]}.{$matches[4]}{$query_string}{$matches[1]}";
    return $result;
}
Exemplo n.º 2
0
 public function test_last_manager()
 {
     $manager = DomainManager('http://test.com');
     $last = DomainManager::last();
     $this->assertSame($manager, $last);
 }