/** * Prepares and fetches a responsive img tag for the tweet's media * @todo organise the size string filter * @return string image html */ public function responsive_media() { // if we have no images to show, return if (empty($this->media)) { return; } // get the entity $entity = $this->media[0]; // default image will be medium $src = "{$entity->media_url}:medium"; $sizes = array(); // list the available sizes foreach (array('small', 'medium', 'large') as $size) { $sizes[] = array('url' => "{$entity->media_url}:{$size}", 'w' => $entity->sizes->{$size}->w, 'h' => $entity->sizes->{$size}->h); } $size_string = "(max-width: {$entity->sizes->medium->w}px) 100vw, {$entity->sizes->medium->w}px"; // get the size string from the theme $size_string = \apply_filters('scoutwp_image_sizes', $size_string); // return the image html, encapsulated in a link return "<div class=\"media\"><a href=\"{$entity->expanded_url}\" target=\"_blank\">" . sp_responsive_img($sizes, $size_string, 1, $this->original_text) . "</a></div>"; }
/** * Constructs the <img> tag and link for a fLickr photo for a photo * @param StdClass $photo Photo object * @return string link and image HTML */ function flickr_thumbnail($user_id, $photo, $default) { $url = "https://farm{$photo->farm}.staticflickr.com/{$photo->server}/{$photo->id}_{$photo->secret}%s.jpg"; $thumbnail_w = get_option('thumbnail_size_w'); $thumbnail_h = get_option('thumbnail_size_h'); if ($photo->height_m < $photo->width_m) { $orientation = 'landscape'; $sizes = array(0 => array('url' => sprintf($url, '_t'), 'w' => 100, 'h' => intval($photo->height_m / $photo->width_m * 100)), 1 => array('url' => sprintf($url, '_m'), 'w' => 240, 'h' => intval($photo->height_m / $photo->width_m * 240)), 2 => array('url' => sprintf($url, '_n'), 'w' => 320, 'h' => intval($photo->height_m / $photo->width_m * 320)), 3 => array('url' => sprintf($url, ''), 'w' => 500, 'h' => intval($photo->height_m / $photo->width_m * 500))); // to fill a 150x150 box, we need a width of... $size_string = intval($photo->width_m / $photo->height_m * $thumbnail_h) . 'px'; } else { $orientation = 'portrait'; $sizes = array(0 => array('url' => sprintf($url, '_t'), 'w' => intval($photo->width_m / $photo->height_m * 100), 'h' => 100), 1 => array('url' => sprintf($url, '_m'), 'w' => intval($photo->width_m / $photo->height_m * 240), 'h' => 240), 2 => array('url' => sprintf($url, '_n'), 'w' => intval($photo->width_m / $photo->height_m * 320), 'h' => 320), 3 => array('url' => sprintf($url, ''), 'w' => intval($photo->width_m / $photo->height_m * 500), 'h' => 500)); // to fill a 150x150 box, we need a width of... $size_string = $thumbnail_w; } // allow the theme to over-write the size string $size_string = \apply_filters('sp_flickr_thumb_sizes', $size_string, $photo->width_m, $photo->height_m); $img = sp_responsive_img($sizes, $size_string, $default, $photo->title); $url = esc_url("https://www.flickr.com/photos/{$user_id}/{$photo->id}"); return "<div class='gallery-icon {$orientation}'><a href='{$url}' target='_blank'>{$img}</a></div>"; }