/** * * SUPPORT FOR WP 4.4 * */ function wr2x_wp_calculate_image_srcset($srcset, $size) { if (wr2x_getoption("disable_responsive", "wr2x_basics", false)) { return null; } $method = wr2x_getoption("method", "wr2x_advanced", 'Picturefill'); if ($method == "none") { return $srcset; } $count = 0; $total = 0; $retinized_srcset = $srcset; if (empty($srcset)) { return $srcset; } foreach ($srcset as $s => $cfg) { $total++; $retina = wr2x_get_retina_from_url($cfg['url']); if (!empty($retina)) { $count++; $retinized_srcset[(int) $s * 2] = array('url' => $retina, 'descriptor' => 'w', 'value' => (int) $s * 2); } } wr2x_log("WP's srcset: " . $count . " retina files added out of " . $total . " image sizes"); return $retinized_srcset; }
function wpr2x_html_get_details_retina_info($post, $retina_info) { if (!wr2x_is_pro()) { return __("PRO VERSION ONLY<br /><br />You can buy a serial from here: <a target='_blank' href='http://apps.meow.fr/wp-retina-2x/'>WP Retina 2x</a>.<br />Then add this serial in the settings. That's all! :)<br />Thanks a lot for your support.", 'wp-retina-2x'); } $sizes = wr2x_get_image_sizes(); $total = 0; $possible = 0; $issue = 0; $ignored = 0; $retina = 0; $postinfo = get_post($post, OBJECT); $meta = wp_get_attachment_metadata($post); $fullsize_file = get_attached_file($post); $pathinfo_system = pathinfo($fullsize_file); $pathinfo = pathinfo($meta['file']); $uploads = wp_upload_dir(); $basepath_url = trailingslashit($uploads['baseurl']) . $pathinfo['dirname']; if (wr2x_getoption("full_size", "wr2x_basics", false)) { $sizes['full-size']['file'] = $pathinfo['basename']; $sizes['full-size']['width'] = $meta['width']; $sizes['full-size']['height'] = $meta['height']; $meta['sizes']['full-size']['file'] = $pathinfo['basename']; $meta['sizes']['full-size']['width'] = $meta['width']; $meta['sizes']['full-size']['height'] = $meta['height']; } $result = "<p>This screen displays all the image sizes set-up by your WordPress configuration with the Retina details.</p>"; $result .= "<br /><a target='_blank' href='" . trailingslashit($uploads['baseurl']) . $meta['file'] . "'><img src='" . trailingslashit($uploads['baseurl']) . $meta['file'] . "' height='100px' style='float: left; margin-right: 10px;' /></a><div class='base-info'>"; $result .= "Title: <b>" . ($postinfo->post_title ? $postinfo->post_title : '<i>Untitled</i>') . "</b><br />"; $result .= "Full-size: <b>" . $meta['width'] . "×" . $meta['height'] . "</b><br />"; $result .= "Image URL: <a target='_blank' href='" . trailingslashit($uploads['baseurl']) . $meta['file'] . "'>" . trailingslashit($uploads['baseurl']) . $meta['file'] . "</a><br />"; $result .= "Image Path: " . $fullsize_file . "<br />"; $result .= "</div><div style='clear: both;'></div><br />"; $result .= "<div class='scrollable-info'>"; foreach ($sizes as $i => $sizemeta) { $total++; $normal_file_system = ""; $retina_file_system = ""; $normal_file = ""; $retina_file = ""; $width = ""; $height = ""; if (isset($retina_info[$i]) && $retina_info[$i] == 'IGNORED') { $status = "IGNORED"; } else { if (!isset($meta['sizes'])) { $statusText = __("The metadata is broken! This is not related to the retina plugin. You should probably use a plugin to re-generate the missing metadata and images.", 'wp-retina-2x'); $status = "MISSING"; } else { if (!isset($meta['sizes'][$i])) { $statusText = sprintf(__("The image size '%s' could not be found. You probably changed your image sizes but this specific image was not re-build. This is not related to the retina plugin. You should probably use a plugin to re-generate the missing metadata and images.", 'wp-retina-2x'), $i); $status = "MISSING"; } else { $normal_file_system = trailingslashit($pathinfo_system['dirname']) . $meta['sizes'][$i]['file']; $retina_file_system = wr2x_get_retina($normal_file_system); $normal_file = trailingslashit($basepath_url) . $meta['sizes'][$i]['file']; $retina_file = wr2x_get_retina_from_url($normal_file); $status = isset($retina_info) && isset($retina_info[$i]) ? $retina_info[$i] : null; $width = $meta['sizes'][$i]['width']; $height = $meta['sizes'][$i]['height']; } } } $result .= "<h3>"; // Status Icon if (is_array($status) && $i == 'full-size') { $result .= '<div class="retina-status-icon retina-missing"></div>'; $statusText = sprintf(__("The retina version of the Full-Size image is missing.<br />Full Size Retina has been checked in the Settings and this image is therefore required.<br />Please drag & drop an image of at least <b>%dx%d</b> in the <b>Full-Size Retina Upload</b> column.", 'wp-retina-2x'), $status['width'], $status['height']); } else { if (is_array($status)) { $result .= '<div class="retina-status-icon retina-issue"></div>'; $statusText = sprintf(__("The Full-Size image is too small (<b>%dx%d</b>) and this size cannot be generated.<br />Please upload an image of at least <b>%dx%d</b>.", 'wp-retina-2x'), $meta['width'], $meta['height'], $status['width'], $status['height']); $issue++; } else { if ($status == 'EXISTS') { $result .= '<div class="retina-status-icon retina-exists"></div>'; $statusText = ""; $retina++; } else { if ($status == 'PENDING') { $result .= '<div class="retina-status-icon retina-pending"></div>'; $statusText = __("The retina image can be created. Please use the 'GENERATE' button.", 'wp-retina-2x'); $possible++; } else { if ($status == 'MISSING') { $result .= '<div class="retina-status-icon retina-missing"></div>'; $statusText = __("The standard image normally created by WordPress is missing.", 'wp-retina-2x'); $total--; } else { if ($status == 'IGNORED') { $result .= '<div class="retina-status-icon retina-ignored"></div>'; $statusText = __("This size is ignored by your retina settings.", 'wp-retina-2x'); $ignored++; $total--; } } } } } } $result .= "Size: {$i}</h3><p>{$statusText}</p>"; if (!is_array($status) && $status !== 'IGNORED' && $status !== 'MISSING') { $result .= "<table><tr><th>Normal (" . $width . "×" . $height . ")</th><th>Retina 2x (" . $width * 2 . "×" . $height * 2 . ")</th></tr><tr><td><a target='_blank' href='{$normal_file}'><img src='{$normal_file}' width='100'></a></td><td><a target='_blank' href='{$retina_file}'><img src='{$retina_file}' width='100'></a></td></tr></table>"; $result .= "<p><small>"; $result .= "Image URL: <a target='_blank' href='{$normal_file}'>{$normal_file}</a><br />"; $result .= "Retina URL: <a target='_blank' href='{$retina_file}'>{$retina_file}</a><br />"; $result .= "Image Path: {$normal_file_system}<br />"; $result .= "Retina Path: {$retina_file_system}<br />"; $result .= "</small></p>"; } } $result .= "</table>"; $result .= "</div>"; return $result; }
public function get_all_image_sizes($image_ids) { global $jck_wt; $images = array(); if (!empty($image_ids)) { foreach ($image_ids as $image_id) { $transient_name = sprintf("%s_variation_image_sizes_%d", $this->slug, $image_id); if (false === ($image_sizes = get_transient($transient_name))) { $image_sizes = false; if ($image_id == 'placeholder') { $image_sizes = array('large' => array(wc_placeholder_img_src($jck_wt['largeImageSize'])), 'single' => array(wc_placeholder_img_src('shop_single')), 'thumb' => array(wc_placeholder_img_src('shop_thumbnail')), 'alt' => '', 'title' => ''); } else { if (!array_key_exists($image_id, $images)) { $attachment = $this->wp_get_attachment($image_id); if (!$attachment) { continue; } $large = wp_get_attachment_image_src($image_id, $jck_wt['largeImageSize']); $single = wp_get_attachment_image_src($image_id, 'shop_single'); $thumb = wp_get_attachment_image_src($image_id, 'shop_thumbnail'); $image_sizes = array('large' => $large, 'single' => $single, 'thumb' => $thumb, 'alt' => $attachment['alt'], 'title' => $attachment['title']); // Get retina images if (function_exists('wr2x_get_retina_from_url')) { foreach ($image_sizes as $key => $image_data) { if ($key == "alt" || $key == "title") { continue; } if ($image_data) { $retina_url = wr2x_get_retina_from_url($image_data[0]); if ($retina_url) { $image_sizes[$key]['retina'] = array($retina_url, $image_data[1] * 2, $image_data[2] * 2); } } } } } } set_transient($transient_name, $image_sizes, 12 * HOUR_IN_SECONDS); } if ($image_sizes) { $images[] = $image_sizes; } } } return $images; }