public static function execute()
 {
     if (!class_exists('Jetpack', false)) {
         return;
     }
     $jetpack_active_modules = get_option('jetpack_active_modules');
     if ($jetpack_active_modules && in_array('photon', $jetpack_active_modules) && class_exists('Jetpack_Photon', false)) {
         // deactivate photon
         remove_filter('image_downsize', array(Jetpack_Photon::instance(), 'filter_image_downsize'));
     }
 }
 function check_image_size($id, $size)
 {
     remove_filter('image_downsize', array(Jetpack_Photon::instance(), 'filter_image_downsize'));
     $imagedata = wp_get_attachment_image_src($id, $size);
     add_filter('image_downsize', array(Jetpack_Photon::instance(), 'filter_image_downsize'), 10, 3);
     if ($imagedata) {
         $size = $this->get_image_sizes($size);
         if ($imagedata[1] == $size['width'] and $imagedata[2] == $size['height']) {
             return $imagedata[0];
         }
     } else {
         return false;
     }
 }
 private function get_image_size_links($post)
 {
     /* Set up an empty array for the links. */
     $links = array();
     /* Get the intermediate image sizes and add the full size to the array. */
     $sizes = get_intermediate_image_sizes();
     $sizes[] = 'full';
     /* Loop through each of the image sizes. */
     $i = 0;
     foreach ($sizes as $size) {
         /* Get the image source, width, height, and whether it's intermediate. */
         remove_filter('image_downsize', array(Jetpack_Photon::instance(), 'filter_image_downsize'));
         if ($image = wp_get_attachment_image_src($post->ID, $size)) {
             $links[$i]['url'] = $image[0];
             $links[$i]['type'] = $size;
             $links[$i]['width'] = $image[1];
             $links[$i]['height'] = $image[2];
             $i++;
         }
         add_filter('image_downsize', array(Jetpack_Photon::instance(), 'filter_image_downsize'), 10, 3);
     }
     return $links;
 }
 /**
  * Provide an array of available image sizes and corresponding dimensions.
  * Similar to get_intermediate_image_sizes() except that it includes image sizes' dimensions, not just their names.
  *
  * @global $wp_additional_image_sizes
  * @uses get_option
  * @return array
  */
 protected static function image_sizes()
 {
     if (null == self::$image_sizes) {
         global $_wp_additional_image_sizes;
         // Populate an array matching the data structure of $_wp_additional_image_sizes so we have a consistent structure for image sizes
         $images = array('thumb' => array('width' => intval(get_option('thumbnail_size_w')), 'height' => intval(get_option('thumbnail_size_h')), 'crop' => (bool) get_option('thumbnail_crop')), 'medium' => array('width' => intval(get_option('medium_size_w')), 'height' => intval(get_option('medium_size_h')), 'crop' => false), 'large' => array('width' => intval(get_option('large_size_w')), 'height' => intval(get_option('large_size_h')), 'crop' => false), 'full' => array('width' => null, 'height' => null, 'crop' => false));
         // Compatibility mapping as found in wp-includes/media.php
         $images['thumbnail'] = $images['thumb'];
         // Update class variable, merging in $_wp_additional_image_sizes if any are set
         if (is_array($_wp_additional_image_sizes) && !empty($_wp_additional_image_sizes)) {
             self::$image_sizes = array_merge($images, $_wp_additional_image_sizes);
         } else {
             self::$image_sizes = $images;
         }
     }
     return is_array(self::$image_sizes) ? self::$image_sizes : array();
 }
Exemple #5
0
 public function gallery_shortcode($val, $atts)
 {
     if (!empty($val)) {
         // something else is overriding post_gallery, like a custom VIP shortcode
         return $val;
     }
     global $post;
     $this->set_atts($atts);
     $attachments = $this->get_attachments();
     if (empty($attachments)) {
         return '';
     }
     if (is_feed() || defined('IS_HTML_EMAIL')) {
         return '';
     }
     if (method_exists($this, $this->atts['type'] . '_talavera')) {
         // Enqueue styles and scripts
         $this->default_scripts_and_styles();
         $gallery_html = call_user_func_array(array($this, $this->atts['type'] . '_talavera'), array($attachments));
         if ($gallery_html && class_exists('Jetpack') && class_exists('Jetpack_Photon')) {
             // Tiled Galleries in Jetpack require that Photon be active.
             // If it's not active, run it just on the gallery output.
             if (!in_array('photon', Jetpack::get_active_modules())) {
                 $gallery_html = Jetpack_Photon::filter_the_content($gallery_html);
             }
         }
         return $gallery_html;
     }
     return '';
 }
Exemple #6
0
<?php

/**
 * Module Name: Photon
 * Module Description: Speed up images and photos.
 * Jumpstart Description: Mirrors and serves your images from our free and fast image CDN, improving your site’s performance with no additional load on your servers.
 * Sort Order: 25
 * Recommendation Order: 1
 * First Introduced: 2.0
 * Requires Connection: Yes
 * Auto Activate: No
 * Module Tags: Photos and Videos, Appearance, Recommended
 * Feature: Recommended, Jumpstart, Appearance
 * Additional Search Queries: photon, image, cdn, performance, speed
 */
Jetpack::dns_prefetch(array('//i0.wp.com', '//i1.wp.com', '//i2.wp.com'));
Jetpack_Photon::instance();
 public function gallery_shortcode($val, $atts)
 {
     if (!empty($val)) {
         // something else is overriding post_gallery, like a custom VIP shortcode
         return $val;
     }
     global $post;
     $this->set_atts($atts);
     $attachments = $this->get_attachments();
     if (empty($attachments)) {
         return '';
     }
     if (is_feed() || defined('IS_HTML_EMAIL')) {
         return '';
     }
     if (in_array($this->atts['type'], self::$talaveras)) {
         // Enqueue styles and scripts
         self::default_scripts_and_styles();
         // Generate gallery HTML
         $gallery_class = 'Jetpack_Tiled_Gallery_Layout_' . ucfirst($this->atts['type']);
         $gallery = new $gallery_class($attachments, $this->atts['link'], $this->atts['grayscale'], (int) $this->atts['columns']);
         $gallery_html = $gallery->HTML();
         if ($gallery_html && class_exists('Jetpack') && class_exists('Jetpack_Photon')) {
             // Tiled Galleries in Jetpack require that Photon be active.
             // If it's not active, run it just on the gallery output.
             if (!in_array('photon', Jetpack::get_active_modules()) && !Jetpack::is_development_mode()) {
                 $gallery_html = Jetpack_Photon::filter_the_content($gallery_html);
             }
         }
         return trim(preg_replace('/\\s+/', ' ', $gallery_html));
         // remove any new lines from the output so that the reader parses it better
     }
     return '';
 }
 /**
  * @author dereksmart
  * @covers Jetpack_Photon::filter_image_downsize
  * @since 3.9.0
  */
 public function test_photon_return_custom_size_array_dimensions_no_meta()
 {
     global $content_width;
     $content_width = 0;
     $test_image = $this->_get_image('large', false);
     // Declaring the size array directly, unknown size of 400 by 400. Scaled, it should be 400 by 300.
     $this->assertEquals('fit=400%2C400', $this->_get_query(Jetpack_Photon::instance()->filter_image_downsize(false, $test_image, array(400, 400))));
     wp_delete_attachment($test_image);
     $this->_remove_image_sizes();
 }
Exemple #9
0
function wallpaper_download_links($id)
{
    if (!wp_attachment_is_image(intval($id))) {
        return;
    }
    $wallpaper_afmetingen_links = array();
    $groottes = array();
    //get_intermediate_image_sizes();
    $groottes[] = 'wallpaper-1280x1024';
    $groottes[] = 'wallpaper-1600x1200';
    $groottes[] = 'wallpaper-1920x1080';
    $groottes[] = 'full';
    foreach ($groottes as $grootte) {
        $photon_uitzetten = remove_filter('image_downsize', array(Jetpack_Photon::instance(), 'filter_image_downsize'));
        //$wallpaper = wp_get_attachment_image_src( get_the_ID(), $grootte );
        $wallpaper = wp_get_attachment_image_src(intval($id), $grootte);
        if ($photon_uitzetten) {
            add_filter('image_downsize', array(Jetpack_Photon::instance(), 'filter_image_downsize'), 10, 3);
        }
        //if ( !empty( $wallpaper ) && ( '' == $wallpaper[3] || 'full' == $grootte ) ) {
        if (!empty($wallpaper)) {
            if (intval($wallpaper[1]) > 1024 && (intval($wallpaper[1]) == 1280 || intval($wallpaper[1]) == 1600 || intval($wallpaper[1]) == 1920)) {
                $wallpaper_afmetingen_links[] = '<a class="knop meer" title="Download deze wallpaper in formaat ' . $wallpaper[1] . '&times;' . $wallpaper[2] . ' pixels" target="_blank" href="' . $wallpaper[0] . '">' . $wallpaper[1] . '&times;' . $wallpaper[2] . '</a>';
            }
        }
    }
    return join('', $wallpaper_afmetingen_links);
}
 /**
  * Return image info for the pledge thumbnail.
  * This uses the provided image id, enabling the SharingMetadata class to call it
  * with the id set in its metadata.
  *
  * @param int $screenWidth - pass 0 for default screen width
  * @param int $imageId
  * @return array - URL, width, height
  */
 public static function getPledgeThumbnailById($screenWidth, $imageId)
 {
     $width = self::getPledgeThumbnailWidth($screenWidth);
     // disable photon - we don't want to serve those images from the CDN
     if (class_exists('Jetpack_Photon')) {
         $photon_removed = remove_filter('image_downsize', array(\Jetpack_Photon::instance(), 'filter_image_downsize'));
     }
     // use the "large" image size.  Picking a pre-determined size will allow us to watermark those specific images,
     // even though the selected size may be too large for the device
     $image = image_downsize($imageId, AWC_SOCIAL_PLEDGE_SHARE_IMAGE_SIZE);
     // re-enable photon
     if (!empty($photon_removed)) {
         add_filter('image_downsize', array(\Jetpack_Photon::instance(), 'filter_image_downsize'), 10, 3);
     }
     // scale the image via width / height
     $size = image_constrain_size_for_editor($image[1], $image[2], [$width, $width]);
     return [$image[0], $size[0], $size[1]];
 }
 /**
  * @author kraftbj
  * @covers Jetpack_Photon::filter_image_downsize
  * @since 3.9.0
  */
 public function test_photon_return_jetpack_soft_oversized_after_upload()
 {
     global $content_width;
     $content_width = 0;
     $test_image = $this->_get_image();
     // Using a custom size, declared after the file was uploaded
     // (thus unknown per WP, relying solely on Photon), hard crop defined 700 width.
     $this->assertEquals('fit=1600%2C1200', $this->_get_query(Jetpack_Photon::instance()->filter_image_downsize(false, $test_image, 'jetpack_soft_oversized_after_upload')));
     wp_delete_attachment($test_image);
     $this->_remove_image_sizes();
 }
 /**
  * @author unknown
  * @since pre-2.3.3
  * @dataProvider urls_and_dimensions
  */
 function test_parse_dimensions_from_filename($image_url, $expected_dimensions)
 {
     $this->assertEquals($expected_dimensions, Jetpack_Photon::parse_dimensions_from_filename($image_url));
 }
 /**
  * set and retreive variables for the featured image.
  * @return $item
  *
  * @since  1.1.0
  */
 public static function get_image_variables()
 {
     $item = new stdClass();
     // variables internal to this function
     $displaysetting = get_option('displayfeaturedimagegenesis');
     $fallback = $displaysetting['default'];
     // url only
     // sitewide variables used outside this function
     $item->backstretch = '';
     // turn Photon off so we can get the correct image
     $photon_removed = '';
     if (class_exists('Jetpack') && Jetpack::is_module_active('photon')) {
         $photon_removed = remove_filter('image_downsize', array(Jetpack_Photon::instance(), 'filter_image_downsize'));
     }
     /**
      * create a filter for user to optionally force post types to use the large image instead of backstretch
      * @var filter
      *
      * @since  2.0.0
      */
     $use_large_image = apply_filters('display_featured_image_genesis_use_large_image', array());
     $image_size = 'displayfeaturedimage_backstretch';
     if (in_array(get_post_type(), $use_large_image)) {
         $image_size = 'large';
     }
     $image_id = self::set_image_id();
     $item->backstretch = wp_get_attachment_image_src($image_id, $image_size);
     // set a content variable so backstretch doesn't show if full size image exists in post.
     $item->content = '';
     // declare this last so that $item->backstretch is set.
     if (!is_admin() && is_singular()) {
         $fullsize = wp_get_attachment_image_src($image_id, 'full');
         $post = get_post();
         $item->content = strpos($post->post_content, 'src="' . $fullsize[0]);
         if (false !== $item->content) {
             $source_id = '';
             $term_image = display_featured_image_genesis_get_term_image_id();
             $default_image = display_featured_image_genesis_get_default_image_id();
             // reset backstretch image source to term image if it exists and the featured image is being used in content.
             if (!empty($term_image)) {
                 $source_id = $term_image;
             } elseif (!empty($fallback)) {
                 // else, reset backstretch image source to fallback.
                 $source_id = $default_image;
             }
             $item->backstretch = wp_get_attachment_image_src($source_id, $image_size);
             $item->content = strpos($post->post_content, 'src="' . $item->backstretch[0]);
         }
     }
     // turn Photon back on
     if ($photon_removed) {
         add_filter('image_downsize', array(Jetpack_Photon::instance(), 'filter_image_downsize'), 10, 3);
     }
     // $title is set by new title function
     $title = self::set_item_title();
     /**
      * Optional filter to change the title text
      * @since 2.2.0
      */
     $item->title = apply_filters('display_featured_image_genesis_title', $title);
     return $item;
 }
 /**
  * @author scotchfield
  * @covers Jetpack_Photon::parse_dimensions_from_filename
  * @since 3.2
  */
 public function test_photon_parse_dimensions_from_filename_valid_large_dimensions()
 {
     $image_url = 'http://' . WP_TESTS_DOMAIN . '/no-dimensions-here-123456789x123456789.jpg';
     $this->assertEquals(array(123456789, 123456789), Jetpack_Photon::parse_dimensions_from_filename($image_url));
 }
 private static function getImageUrl($imageId, $network)
 {
     // disable photon - we don't want to serve those images from the CDN
     if (class_exists('Jetpack_Photon')) {
         $photon_removed = remove_filter('image_downsize', array(\Jetpack_Photon::instance(), 'filter_image_downsize'));
     }
     // use the "large" image size.  Picking a pre-determined size will allow us to watermark those specific images,
     // even though the selected size may be too large for the device
     $image = image_downsize($imageId, AWC_SOCIAL_PLEDGE_SHARE_IMAGE_SIZE);
     // re-enable photon
     if (!empty($photon_removed)) {
         add_filter('image_downsize', array(\Jetpack_Photon::instance(), 'filter_image_downsize'), 10, 3);
     }
     if ($network) {
         return SocialImages::resizeForNetwork($image[0], $imageId, [$image[1], $image[2]], $network);
     }
     return $image[0];
 }
<?php

/**
 * Jetpack compatibility file
 *
 * @since 4.2.0
 */
// File Security Check
if (!defined('ABSPATH')) {
    exit;
}
$jetpack_active_modules = get_option('jetpack_active_modules');
if ($jetpack_active_modules && in_array('photon', $jetpack_active_modules)) {
    // deactivate photon
    remove_filter('image_downsize', array(Jetpack_Photon::instance(), 'filter_image_downsize'));
}