コード例 #1
0
 function test_imgix_extract_imgs_extracts_single_image_with_params_and_single_quotes()
 {
     $result = imgix_extract_imgs("<img src='https://google.com/cats.gif?party=1&bad-vibes=0' />");
     $expected = array(array('url' => 'cats.gif', 'params' => 'party=1&bad-vibes=0'));
     $this->assertEquals(count($expected), count($result));
     $this->assertEquals($expected[0], $result[0]);
 }
コード例 #2
0
function imgix_replace_content_cdn($content)
{
    global $imgix_options;
    $slink = ensure_valid_url($imgix_options['cdn_link']);
    $auto_format = $imgix_options['auto_format'];
    $auto_enhance = $imgix_options['auto_enhance'];
    if (!empty($slink)) {
        // 1) Apply imgix host
        // img src tags
        $content = str_replace('src="' . home_url('/') . 'wp-content/', 'src="' . $slink . 'wp-content/', $content);
        $content = str_replace('src=\'' . home_url('/') . 'wp-content/', 'src=\'' . $slink . 'wp-content/', $content);
        // img href tags
        $content = str_replace('href="' . home_url('/') . 'wp-content/', 'href="' . $slink . 'wp-content/', $content);
        $content = str_replace('href=\'' . home_url('/') . 'wp-content/', 'href=\'' . $slink . 'wp-content/', $content);
        $data_w_h = imgix_extract_img_details($content);
        // 2) Handle Auto options
        $autos = array();
        $auto_params = '';
        if ($auto_format === "1") {
            array_push($autos, "format");
        }
        if ($auto_enhance === "1") {
            array_push($autos, "enhance");
        }
        if (sizeof($autos) > 0) {
            $auto_params = 'auto=' . implode(',', $autos);
        }
        // 3) Apply the h/w img params and any that already existed (text html edits)
        foreach ($data_w_h as $k => $v) {
            $extra = strlen($v['extra']) > 0 ? '&' . $v['extra'] : '';
            $to_replace = $v['raw'];
            $new_url = '.' . $v['type'] . '?h=' . $v['h'] . '&w=' . $v['w'] . $extra;
            $content = str_replace($to_replace, $new_url, $content);
        }
        // 4) Apply the auto_params
        $imgs = imgix_extract_imgs($content);
        foreach ($imgs as $k => $v) {
            if (strlen($v['params']) > 0) {
                $new_url = $v['url'] . '?' . $auto_params . '&' . $v['params'];
                $to_replace = $v['url'] . '?' . $v['params'];
            } else {
                $to_replace = $v['url'];
                $new_url = $v['url'] . '?' . $auto_params;
            }
            $to_replace .= '"';
            $new_url .= '"';
            if (strlen($to_replace) > 0) {
                $content = str_replace($to_replace, $new_url, $content);
            }
        }
        return $content;
    }
    return $content;
}
コード例 #3
0
function imgix_replace_non_wp_images($content)
{
    list($content, $match) = replace_host($content, true);
    if ($match) {
        //Apply image-tag-encoded params for every image in $content.
        foreach (imgix_extract_img_details($content) as $img) {
            $to_replace = $img['raw'];
            $extra_params = $img['extra'] ? '&amp;' . $img['extra'] : '';
            $new_url = '.' . $img['type'] . '?h=' . $img['h'] . '&amp;w=' . $img['w'] . $extra_params;
            $content = str_replace($to_replace, $new_url, $content);
        }
        // Apply global parameters.
        $g_params = get_global_params_string();
        foreach (imgix_extract_imgs($content) as $img_url) {
            $content = apply_parameters_to_url($img_url, $g_params, $content);
        }
    }
    return $content;
}