function get_widths_for_template($prefix, $sb_count, $template = null)
 {
     $wrapper_width_type_var = 'suf' . $prefix . '_wrapper_width_type';
     $wrapper_width_preset_var = 'suf' . $prefix . '_wrapper_width_preset';
     $wrapper_width_var = 'suf' . $prefix . '_wrapper_width';
     $wrapper_width_flex_var = 'suf' . $prefix . '_wrapper_width_flex';
     $wrapper_width_flex_max_var = 'suf' . $prefix . '_wrapper_width_flex_max';
     $wrapper_width_flex_min_var = 'suf' . $prefix . '_wrapper_width_flex_min';
     $main_col_width_var = 'suf' . $prefix . '_main_col_width';
     $sb_1_width_var = 'suf' . $prefix . '_sb_1_width';
     $sb_2_width_var = 'suf' . $prefix . '_sb_2_width';
     global ${$wrapper_width_preset_var}, ${$wrapper_width_var}, ${$main_col_width_var}, ${$sb_1_width_var}, ${$sb_2_width_var}, $suf_sidebar_count, ${$wrapper_width_type_var}, ${$wrapper_width_flex_var}, ${$wrapper_width_flex_max_var}, ${$wrapper_width_flex_min_var};
     $wrapper_width_preset = ${$wrapper_width_preset_var};
     $wrapper_width = ${$wrapper_width_var};
     if (isset(${$wrapper_width_flex_var})) {
         $wrapper_width_flex = ${$wrapper_width_flex_var};
     }
     if (isset(${$wrapper_width_flex_max_var})) {
         $wrapper_width_flex_max = ${$wrapper_width_flex_max_var};
     }
     if (isset(${$wrapper_width_flex_min_var})) {
         $wrapper_width_flex_min = ${$wrapper_width_flex_min_var};
     }
     $main_col_width = ${$main_col_width_var};
     if (isset(${$sb_1_width_var})) {
         $sb_1_width = ${$sb_1_width_var};
     }
     if (isset(${$sb_2_width_var})) {
         $sb_2_width = ${$sb_2_width_var};
     }
     if ($prefix) {
         $sidebar_count = $sb_count;
     } else {
         $sidebar_count = $suf_sidebar_count;
     }
     $wrapper_width_type = isset(${$wrapper_width_type_var}) ? ${$wrapper_width_type_var} : 'fixed';
     if ($wrapper_width_type == 'fluid') {
         $sb_1_width = isset($sb_1_width) ? suffusion_admin_get_size_from_field($sb_1_width, "260px", false) : "260px";
         $sb_2_width = isset($sb_2_width) ? suffusion_admin_get_size_from_field($sb_2_width, "260px", false) : "260px";
         $wrapper_width_flex = isset($wrapper_width_flex) ? $wrapper_width_flex : "75";
         $wrapper_width_flex_max = isset($wrapper_width_flex_max) ? suffusion_admin_get_size_from_field($wrapper_width_flex_max, "1200px", false) : "1200px";
         $wrapper_width_flex_min = isset($wrapper_width_flex_min) ? suffusion_admin_get_size_from_field($wrapper_width_flex_min, "600px", false) : "600px";
         $component_widths = array('wrapper' => $wrapper_width_flex, 'wrapper-max' => (int) substr($wrapper_width_flex_max, 0, strlen($wrapper_width_flex_max) - 2), 'wrapper-min' => (int) substr($wrapper_width_flex_min, 0, strlen($wrapper_width_flex_min) - 2), 'sidebar-1' => (int) substr($sb_1_width, 0, strlen($sb_1_width) - 2), 'sidebar-2' => (int) substr($sb_2_width, 0, strlen($sb_2_width) - 2));
         $widths = $this->get_fluid_widths($component_widths, $sidebar_count, $prefix);
     } else {
         // Fixed width
         if ($wrapper_width_preset != "custom" && $wrapper_width_preset != "custom-components") {
             $widths = $this->get_automatic_widths($wrapper_width_preset, $sidebar_count, $prefix);
         } else {
             if ($wrapper_width_preset == "custom") {
                 $wrapper_width = suffusion_admin_get_size_from_field($wrapper_width, "1000px");
                 $widths = $this->get_automatic_widths((int) substr($wrapper_width, 0, strlen($wrapper_width) - 2), $sidebar_count, $prefix);
             } else {
                 $main_col_width = suffusion_admin_get_size_from_field($main_col_width, "725px");
                 $sb_1_width = isset($sb_1_width) ? suffusion_admin_get_size_from_field($sb_1_width, "260px") : "260px";
                 $sb_2_width = isset($sb_2_width) ? suffusion_admin_get_size_from_field($sb_2_width, "260px") : "260px";
                 $component_widths = array('main-col' => (int) substr($main_col_width, 0, strlen($main_col_width) - 2), 'sidebar-1' => (int) substr($sb_1_width, 0, strlen($sb_1_width) - 2), 'sidebar-2' => (int) substr($sb_2_width, 0, strlen($sb_2_width) - 2));
                 $widths = $this->get_widths_from_components($component_widths, $sidebar_count, $prefix);
             }
         }
     }
     return apply_filters('suffusion_set_template_widths', $widths, $template);
 }
Example #2
0
/**
 * Retrieves the URL of the image to be shown for a post. This is loosely based on the "Get the Image" plugin by Justin
 * Tadlock (http://wordpress.org/extend/plugins/get-the-image/). It picks the URL from one of the following:
 *  1. Native WP "Featured Image"
 *  2. Custom "Featured Image" field
 *  3. Custom "Thumbnail" field
 *  4. Attachment for a post
 *  5. Embedded URL in a post.
 *
 * The sequence for determining what to pick varies by the content type. You can set your order of preference from the options.
 * So, for featured content you might choose to give higher preference to the Custom "Featured Image" field, while for an excerpt you
 * might give preference to the Native WP "Featured Image"
 *
 * @param array $options
 * @return string
 */
function suffusion_get_image($options = array())
{
    global $post, $suf_excerpt_thumbnail_alignment, $suf_excerpt_thumbnail_size, $suf_featured_image_size, $suf_featured_image_custom_width, $suf_featured_image_custom_height;
    global $suf_mag_headline_image_size, $suf_mag_excerpt_image_size, $suf_excerpt_tt_zc, $suf_excerpt_tt_quality;
    global $suf_mag_excerpt_img_pref, $suf_mag_headline_img_pref, $suf_featured_img_pref, $suf_excerpt_img_pref, $suf_tile_img_pref, $suf_tile_image_size;
    $sequence_arrays = array('featured' => $suf_featured_img_pref, 'featured-widget' => $suf_featured_img_pref, 'mag-headline' => $suf_mag_headline_img_pref, 'mag-excerpt' => $suf_mag_excerpt_img_pref, 'default' => $suf_excerpt_img_pref, 'widget-24' => $suf_excerpt_img_pref, 'widget-32' => $suf_excerpt_img_pref, 'widget-48' => $suf_excerpt_img_pref, 'widget-64' => $suf_excerpt_img_pref, 'widget-96' => $suf_excerpt_img_pref, 'tile-thumb' => $suf_tile_img_pref, 'gallery-thumb' => array('attachment'));
    $standard_sizes = array('thumbnail', 'medium', 'large');
    $full_size = false;
    $sequence = $sequence_arrays['default'];
    if ($suf_excerpt_thumbnail_size == 'custom') {
        $size = 'excerpt-thumbnail';
    } else {
        if (in_array($suf_excerpt_thumbnail_size, $standard_sizes)) {
            $size = $suf_excerpt_thumbnail_size;
        } else {
            $full_size = true;
            $size = 'full';
        }
    }
    if (isset($options['featured']) && $options['featured']) {
        $sequence = $sequence_arrays['featured'];
        if ($suf_featured_image_size == 'custom') {
            $full_size = false;
            $size = 'featured';
        } else {
            $full_size = true;
            $size = 'full';
        }
    } else {
        if (isset($options['featured-widget']) && $options['featured-widget']) {
            $sequence = $sequence_arrays['featured'];
            $size = 'full';
            if ($options['featured-image-custom-size']) {
                // This is not a registered size, as it is set from the widget. So we will set the $height and $width parameters appropriately, but retrieve the 'full' size image.
                // Hence $size will stay at 'full'. Also, we will set special variables here for the desired size: $featured_width and $featured_height.
                // This will ensure that if the full-sized post thumbnail (i.e. $img will have 4 return values) is retrieved, the new full image
                // can be resized according to $featured_width and $featured_height.
                // In addition we will make $width and $height equal to $featured_width and $featured_height. This will mean that for non-post-thumbnails
                // the sizes remain untarnished.
                $featured_width = isset($options['featured-width']) ? $options['featured-width'] : suffusion_admin_get_size_from_field($suf_featured_image_custom_width, '200px');
                $featured_width = (int) substr($featured_width, 0, strlen($featured_width) - 2);
                $featured_height = isset($options['featured-height']) ? $options['featured-height'] : suffusion_admin_get_size_from_field($suf_featured_image_custom_height, '200px');
                $featured_height = (int) substr($featured_height, 0, strlen($featured_height) - 2);
                $width = $featured_width;
                $height = $featured_height;
                $full_size = false;
            } else {
                $full_size = true;
            }
        } else {
            if (isset($options['mag-headline']) && $options['mag-headline']) {
                $sequence = $sequence_arrays['mag-headline'];
                if ($suf_mag_headline_image_size == 'custom') {
                    $size = 'mag-headline';
                    $full_size = false;
                }
            } else {
                if (isset($options['mag-excerpt']) && $options['mag-excerpt']) {
                    $sequence = $sequence_arrays['mag-excerpt'];
                    if ($suf_mag_excerpt_image_size == 'custom') {
                        $size = 'mag-excerpt';
                        $full_size = false;
                    }
                } else {
                    if (isset($options['tile-thumb']) && $options['tile-thumb']) {
                        $sequence = $sequence_arrays['tile-thumb'];
                        if ($suf_tile_image_size == 'custom') {
                            $size = 'tile-thumb';
                            $full_size = false;
                        }
                    } else {
                        if (isset($options['mosaic-thumb']) && $options['mosaic-thumb']) {
                            $size = 'mosaic-thumb';
                            $full_size = false;
                        } else {
                            if (isset($options['widget-thumb'])) {
                                $size = $options['widget-thumb'];
                                $full_size = false;
                            } else {
                                if (isset($options['gallery-thumb'])) {
                                    $size = 'gallery-thumb';
                                    $full_size = false;
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    if (is_array($size)) {
        $size = 'full';
    }
    if (!is_array($sequence)) {
        // Sequence has been explicitly set in the options. We need to break the string out into an array
        $sequence = explode(',', $sequence);
    } else {
        // Sequence has not been set explicitly and the default array exists. So we will retrieve its keys only.
        $sequence = array_keys($sequence);
    }
    $img = "";
    $original = array();
    if (isset($options['get-original']) && true === $options['get-original']) {
        $get_original = true;
    } else {
        $get_original = false;
    }
    foreach ($sequence as $position) {
        if (!is_null($img) && (is_array($img) || trim($img) != '')) {
            break;
        }
        switch ($position) {
            case 'native':
                $img = suffusion_get_image_by_post_thumbnail($size, $original, $get_original);
                continue;
            case 'custom-thumb':
                $img = suffusion_get_image_from_custom_field('suf_thumbnail');
                $original[0] = $img;
                continue;
            case 'attachment':
                if (isset($options['attachment-id'])) {
                    $attachment_id = $options['attachment-id'];
                } else {
                    $attachment_id = false;
                }
                $img = suffusion_get_image_from_attachment($size, $original, $get_original, $attachment_id, $options);
                if (isset($original['yapb']) && $original['yapb']) {
                    $full_size = true;
                }
                continue;
            case 'embedded':
                $img = suffusion_get_image_from_embedded_url();
                $original[0] = $img;
                continue;
            case 'custom-featured':
                $img = suffusion_get_image_from_custom_field('suf_featured_image');
                $original[0] = $img;
                continue;
        }
    }
    global $suffusion_original_image;
    $suffusion_original_image = $original;
    if (is_array($img)) {
        // This is either from an attachment or from a post thumbnail. If this is from the featured post widget, this is going to be a full-size image
        // (since we cannot use add_image_size() for the widget parameters). So we will set the $width and $height parameters to the desired
        // sizes and resize later. Otherwise we can set the $width and $height to the values returned with the $img url
        $width = isset($featured_width) ? $featured_width : $img[1];
        $height = isset($featured_height) ? $featured_height : $img[2];
        $intermediate = $img[3];
        $img = $img[0];
    }
    if (!isset($width) || !isset($height)) {
        // Retrieve the physical sizes from the named size.
        global $_wp_additional_image_sizes;
        if (isset($_wp_additional_image_sizes[$size])) {
            $size_array = $_wp_additional_image_sizes[$size];
            $width = $size_array['width'];
            $height = $size_array['height'];
            $crop = $size_array['crop'];
        } else {
            if (in_array($size, $standard_sizes)) {
                $width = get_option($size . '_size_w');
                $height = get_option($size . '_size_h');
            } else {
                $width = get_option('full_size_w');
                $height = get_option('full_size_h');
            }
        }
    }
    if (trim($img) != "") {
        // An image has been returned. Let us determine if we need to resize it. We will resize it if we don't want a full size image.
        // If the image returned is not an intermediate size (set only for thumbnails), we will do a physical resize.
        if (!$full_size && function_exists('imagecreatetruecolor') && (isset($intermediate) && !$intermediate || !isset($intermediate))) {
            if (is_multisite()) {
                // Special handling for rewrite rules in MS installations.
                global $blog_id;
                if (isset($blog_id) && $blog_id > 0) {
                    $imageParts = explode('/files/', $img);
                    if (isset($imageParts[1])) {
                        $img = '/wp-content/blogs.dir/' . $blog_id . '/files/' . $imageParts[1];
                    }
                }
            }
            $crop = isset($crop) ? $crop : $suf_excerpt_tt_zc == "0";
            $resized_img = suffusion_image_resize($img, $width, $height, $crop, $suf_excerpt_tt_quality);
            $img = $resized_img['url'];
        }
        if (isset($original['yapb'])) {
            $image_html = $img;
        } else {
            if (isset($options["featured"]) || isset($options['featured-widget'])) {
                $image_html = "<img src=\"" . $img . "\" alt=\"" . esc_html($post->post_title) . "\" class=\"featured-excerpt-" . $options["excerpt_position"] . "\"/>";
            } else {
                if (isset($options['mag-headline']) || isset($options['mag-excerpt']) || isset($options['tile-thumb'])) {
                    $a_class = 'fix';
                    $image_html = "<img src=\"" . $img . "\" alt=\"" . esc_html($post->post_title) . "\" />";
                } else {
                    if (isset($options['mosaic-thumb'])) {
                        $image_html = "<img src=\"" . $img . "\" alt=\"" . esc_html($post->post_title) . "\" class='suf-mosaic-img' />";
                    } else {
                        if (isset($options['widget-thumb'])) {
                            $image_html = "<img src=\"" . $img . "\" alt=\"" . esc_html($post->post_title) . "\" class='suf-widget-thumb' />";
                        } else {
                            $a_class = 'suf-thumbnail-anchor-' . $suf_excerpt_thumbnail_alignment;
                            $image_html = "<img src=\"" . $img . "\" alt=\"" . esc_html($post->post_title) . "\" class=\"{$suf_excerpt_thumbnail_alignment}-thumbnail\"/>";
                        }
                    }
                }
            }
        }
        if (isset($options['no-link']) && $options['no-link']) {
            return $image_html;
        } else {
            $title = "";
            $a_id = "";
            if (isset($options['show-title'])) {
                $title = "title=\"" . esc_attr($post->post_title) . "\"";
            }
            if (isset($options['mosaic-thumb'])) {
                $a_id = "id=\"suf-mosaic-thumb-" . $post->ID . "\"";
            }
            return "<a href=\"" . get_permalink($post->ID) . "\" {$a_id} {$title} class='" . (isset($a_class) ? $a_class : '') . "'>{$image_html}</a>";
        }
    } else {
        return "";
    }
}
Example #3
0
 function set_image_sizes()
 {
     global $suf_excerpt_thumbnail_size, $suf_excerpt_thumbnail_custom_width, $suf_excerpt_thumbnail_custom_height, $suf_excerpt_tt_zc;
     global $suf_featured_image_size, $suf_featured_image_custom_width, $suf_featured_image_custom_height, $suf_featured_zc;
     global $suf_mag_headline_image_size, $suf_mag_headline_image_custom_height, $suf_mag_headline_image_custom_width, $suf_mag_headline_zc;
     global $suf_mag_excerpt_image_size, $suf_mag_excerpt_image_custom_height, $suf_mag_excerpt_image_custom_width, $suf_mag_excerpt_zc;
     global $suf_mosaic_thumbnail_height, $suf_mosaic_thumbnail_width, $suf_mosaic_zc, $suf_tile_image_size, $suf_tile_image_settings, $suf_tile_image_custom_width, $suf_tile_image_custom_height, $suf_tile_zc;
     global $suf_gallery_format_thumbnail_width, $suf_gallery_format_thumbnail_height, $suf_gallery_format_zc;
     global $suf_disable_auto_thumbs;
     if ($suf_excerpt_thumbnail_size == "custom") {
         $width = suffusion_admin_get_size_from_field($suf_excerpt_thumbnail_custom_width, '200px');
         $width = (int) substr($width, 0, strlen($width) - 2);
         $height = suffusion_admin_get_size_from_field($suf_excerpt_thumbnail_custom_height, '200px');
         $height = (int) substr($height, 0, strlen($height) - 2);
         $zc = $suf_excerpt_tt_zc == "0" ? false : true;
         add_image_size('excerpt-thumbnail', $width, $height, $zc);
     }
     if ($suf_featured_image_size == "custom") {
         $width = suffusion_admin_get_size_from_field($suf_featured_image_custom_width, '200px');
         $width = (int) substr($width, 0, strlen($width) - 2);
         $height = suffusion_admin_get_size_from_field($suf_featured_image_custom_height, '200px');
         $height = (int) substr($height, 0, strlen($height) - 2);
         $zc = $suf_featured_zc == "default" ? $suf_excerpt_tt_zc : $suf_featured_zc;
         $zc = $zc == "0" ? false : true;
         add_image_size('featured', $width, $height, $zc);
     }
     if ($suf_mag_headline_image_size == "custom") {
         $width = suffusion_admin_get_size_from_field($suf_mag_headline_image_custom_width, '200px');
         $width = (int) substr($width, 0, strlen($width) - 2);
         $height = suffusion_admin_get_size_from_field($suf_mag_headline_image_custom_height, '200px');
         $height = (int) substr($height, 0, strlen($height) - 2);
         $zc = $suf_mag_headline_zc == "default" ? $suf_excerpt_tt_zc : $suf_mag_headline_zc;
         $zc = $zc == "0" ? false : true;
         add_image_size('mag-headline', $width, $height, $zc);
     }
     if ($suf_mag_excerpt_image_size == "custom") {
         $width = suffusion_admin_get_size_from_field($suf_mag_excerpt_image_custom_width, '200px');
         $width = (int) substr($width, 0, strlen($width) - 2);
         $height = suffusion_admin_get_size_from_field($suf_mag_excerpt_image_custom_height, '200px');
         $height = (int) substr($height, 0, strlen($height) - 2);
         $zc = $suf_mag_excerpt_zc == "default" ? $suf_excerpt_tt_zc : $suf_mag_excerpt_zc;
         $zc = $zc == "0" ? false : true;
         add_image_size('mag-excerpt', $width, $height, $zc);
     }
     if ($suf_tile_image_size == "custom" && $suf_tile_image_settings == 'native') {
         $width = suffusion_admin_get_size_from_field($suf_tile_image_custom_width, '200px');
         $width = (int) substr($width, 0, strlen($width) - 2);
         $height = suffusion_admin_get_size_from_field($suf_tile_image_custom_height, '200px');
         $height = (int) substr($height, 0, strlen($height) - 2);
         $zc = $suf_tile_zc == "default" ? $suf_excerpt_tt_zc : $suf_tile_zc;
         $zc = $zc == "0" ? false : true;
         add_image_size('tile-thumb', $width, $height, $zc);
     }
     if (isset($suf_disable_auto_thumbs) && trim($suf_disable_auto_thumbs) != '') {
         $disabled = explode(',', $suf_disable_auto_thumbs);
     } else {
         $disabled = array();
     }
     if (!in_array('mosaic-thumb', $disabled)) {
         add_image_size('mosaic-thumb', $suf_mosaic_thumbnail_width, $suf_mosaic_thumbnail_height, $suf_mosaic_zc);
     }
     if (!in_array('gallery-thumb', $disabled)) {
         add_image_size('gallery-thumb', $suf_gallery_format_thumbnail_width, $suf_gallery_format_thumbnail_height, $suf_gallery_format_zc);
     }
     if (!in_array('widget-24', $disabled)) {
         add_image_size('widget-24', 24, 24, true);
     }
     if (!in_array('widget-32', $disabled)) {
         add_image_size('widget-32', 36, 36, true);
     }
     if (!in_array('widget-48', $disabled)) {
         add_image_size('widget-48', 48, 48, true);
     }
     if (!in_array('widget-64', $disabled)) {
         add_image_size('widget-64', 64, 64, true);
     }
     if (!in_array('widget-96', $disabled)) {
         add_image_size('widget-96', 96, 96, true);
     }
 }
 function get_post_format_widths_css()
 {
     global $suf_gallery_format_thumb_panel_position, $suf_gallery_format_thumb_panel_width;
     $ret = "";
     if ($suf_gallery_format_thumb_panel_position == 'left' || $suf_gallery_format_thumb_panel_position == 'right') {
         $width = suffusion_admin_get_size_from_field($suf_gallery_format_thumb_panel_width, '250px');
         $mod_width = (int) substr($width, 0, strlen($width) - 2);
         $mod_width += 16;
         $mod_width = $mod_width . 'px';
         $ret .= ".gallery-container { padding-{$suf_gallery_format_thumb_panel_position}: {$mod_width} }";
         $ret .= ".gallery-contents { width: {$width} }";
         $ret .= ".gallery-contents.left { left: -{$mod_width} }";
         $ret .= ".gallery-contents.right { margin-right: -{$mod_width} }";
     }
     return $ret;
 }