define('VERSION', '1.14'); // version number (to force a cache refresh) define('DIRECTORY_CACHE', './cache'); // cache directory define('DIRECTORY_TEMP', './temp'); // temp directory if (function_exists('imagefilter') && defined('IMG_FILTER_NEGATE')) { $imageFilters = array("1" => array(IMG_FILTER_NEGATE, 0), "2" => array(IMG_FILTER_GRAYSCALE, 0), "3" => array(IMG_FILTER_BRIGHTNESS, 1), "4" => array(IMG_FILTER_CONTRAST, 1), "5" => array(IMG_FILTER_COLORIZE, 4), "6" => array(IMG_FILTER_EDGEDETECT, 0), "7" => array(IMG_FILTER_EMBOSS, 0), "8" => array(IMG_FILTER_GAUSSIAN_BLUR, 0), "9" => array(IMG_FILTER_SELECTIVE_BLUR, 0), "10" => array(IMG_FILTER_MEAN_REMOVAL, 0), "11" => array(IMG_FILTER_SMOOTH, 0)); } // sort out image source $src = get_request("src", ""); if ($src == '' || strlen($src) <= 3) { displayError('no image specified'); } // clean params before use $src = cleanSource($src); // last modified time (for caching) $lastModified = filemtime($src); // get properties $new_width = preg_replace("/[^0-9]+/", '', get_request('w', 0)); $new_height = preg_replace("/[^0-9]+/", '', get_request('h', 0)); $zoom_crop = preg_replace("/[^0-9]+/", '', get_request('zc', 1)); $quality = preg_replace("/[^0-9]+/", '', get_request('q', 80)); $filters = get_request('f', ''); $sharpen = get_request('s', 0); if ($new_width == 0 && $new_height == 0) { $new_width = 100; $new_height = 100; } // get mime type of src $mime_type = mime_type($src);
/** * woothemes_uploader_custom_fields function. * * @access public * @param int $pID * @param string $id * @param string $std * @param string $desc * @return void */ function woothemes_uploader_custom_fields($pID, $id, $std, $desc) { // Start Uploader $upload = get_post_meta($pID, $id, true); $href = cleanSource($upload); $uploader = ''; $uploader .= '<input class="woo_input_text" name="' . $id . '" type="text" value="' . esc_attr($upload) . '" />'; $uploader .= '<div class="clear"></div>' . "\n"; $uploader .= '<input type="file" name="attachement_' . $id . '" />'; $uploader .= '<input type="submit" class="button button-highlighted" value="Save" name="save"/>'; if ($href) { $uploader .= '<span class="woo_metabox_desc">' . $desc . '</span></td>' . "\n" . '<td class="woo_metabox_image"><a href="' . $upload . '"><img src="' . get_template_directory_uri() . '/functions/thumb.php?src=' . $href . '&w=150&h=80&zc=1" alt="" /></a>'; } return $uploader; }
function woo_image($args) { /* ------------------------------------------------------------------------- */ /* SET VARIABLES */ /* ------------------------------------------------------------------------- */ global $post; global $woo_options; //Defaults $key = 'image'; $width = null; $height = null; $class = ''; $quality = 90; $id = null; $link = 'src'; $repeat = 1; $offset = 0; $before = ''; $after = ''; $single = false; $force = false; $return = false; $is_auto_image = false; $src = ''; $meta = ''; $alignment = ''; $size = ''; $noheight = ''; $alt = ''; $img_link = ''; $attachment_id = array(); $attachment_src = array(); if (!is_array($args)) { parse_str($args, $args); } extract($args); // Set post ID if (empty($id)) { $id = $post->ID; } $thumb_id = esc_html(get_post_meta($id, '_thumbnail_id', true)); // Set alignment if ($alignment == '') { $alignment = esc_html(get_post_meta($id, '_image_alignment', true)); } // Get standard sizes if (!$width && !$height) { $width = '100'; $height = '100'; } // Cast $width and $height to integer $width = intval($width); $height = intval($height); /* ------------------------------------------------------------------------- */ /* FIND IMAGE TO USE */ /* ------------------------------------------------------------------------- */ // When a custom image is sent through if ($src != '') { $custom_field = esc_url($src); $link = 'img'; // WP 2.9 Post Thumbnail support } elseif (get_option('woo_post_image_support') == 'true' && !empty($thumb_id)) { if (get_option('woo_pis_resize') == 'true') { if (0 == $height) { $img_data = wp_get_attachment_image_src($thumb_id, array(intval($width), 9999)); $height = $img_data[2]; } // Dynamically resize the post thumbnail $vt_crop = get_option('woo_pis_hard_crop'); if ($vt_crop == 'true') { $vt_crop = true; } else { $vt_crop = false; } $vt_image = vt_resize($thumb_id, '', $width, $height, $vt_crop); // Set fields for output $custom_field = esc_url($vt_image['url']); $width = $vt_image['width']; $height = $vt_image['height']; } else { // Use predefined size string if ($size) { $thumb_size = $size; } else { $thumb_size = array($width, $height); } $img_link = get_the_post_thumbnail($id, $thumb_size, array('class' => 'woo-image ' . esc_attr($class))); } // Grab the image from custom field } else { $custom_field = esc_url(get_post_meta($id, $key, true)); } // Automatic Image Thumbs - get first image from post attachment if (empty($custom_field) && get_option('woo_auto_img') == 'true' && empty($img_link) && !(is_singular() && in_the_loop() && $link == 'src')) { if ($offset >= 1) { $repeat = $repeat + $offset; } $attachments = get_children(array('post_parent' => $id, 'numberposts' => $repeat, 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => 'DESC', 'orderby' => 'menu_order date')); // Search for and get the post attachment if (!empty($attachments)) { $counter = -1; foreach ($attachments as $att_id => $attachment) { $counter++; if ($counter < $offset) { continue; } if (get_option('woo_post_image_support') == 'true' && get_option('woo_pis_resize') == 'true') { // Dynamically resize the post thumbnail $vt_crop = get_option('woo_pis_hard_crop'); if ($vt_crop == 'true') { $vt_crop = true; } else { $vt_crop = false; } $vt_image = vt_resize($att_id, '', $width, $height, $vt_crop); // Set fields for output $custom_field = esc_url($vt_image['url']); $width = $vt_image['width']; $height = $vt_image['height']; } else { $src = wp_get_attachment_image_src($att_id, 'large', true); $custom_field = esc_url($src[0]); $attachment_id[] = $att_id; $src_arr[] = $custom_field; } $thumb_id = $att_id; $is_auto_image = true; } // Get the first img tag from content } else { $first_img = ''; $post = get_post($id); ob_start(); ob_end_clean(); $output = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $post->post_content, $matches); if (!empty($matches[1][0])) { // Save Image URL $custom_field = esc_url($matches[1][0]); // Search for ALT tag $output = preg_match_all('/<img.+alt=[\'"]([^\'"]+)[\'"].*>/i', $post->post_content, $matches); if (!empty($matches[1][0])) { $alt = esc_attr($matches[1][0]); } } } } // Check if there is YouTube embed if (empty($custom_field) && empty($img_link)) { $embed = esc_html(get_post_meta($id, 'embed', true)); if ($embed) { $custom_field = esc_url(woo_get_video_image($embed)); } } // Return if there is no attachment or custom field set if (empty($custom_field) && empty($img_link)) { // Check if default placeholder image is uploaded // $placeholder = get_option( 'framework_woo_default_image' ); $placeholder = WF()->get_placeholder_image_url(); if ($placeholder && !(is_singular() && in_the_loop())) { $custom_field = esc_url($placeholder); // Resize the placeholder if if (get_option('woo_post_image_support') == 'true' && get_option('woo_pis_resize') == 'true') { // Dynamically resize the post thumbnail $vt_crop = get_option('woo_pis_hard_crop'); if ($vt_crop == 'true') { $vt_crop = true; } else { $vt_crop = false; } $vt_image = vt_resize('', $placeholder, $width, $height, $vt_crop); // Set fields for output $custom_field = esc_url($vt_image['url']); $width = $vt_image['width']; $height = $vt_image['height']; } } else { return; } } if (empty($src_arr) && empty($img_link)) { $src_arr[] = $custom_field; } /* ------------------------------------------------------------------------- */ /* BEGIN OUTPUT */ /* ------------------------------------------------------------------------- */ $output = ''; // Set output height and width $set_width = ' width="' . esc_attr($width) . '" '; $set_height = ''; if (!$noheight && 0 < $height) { $set_height = ' height="' . esc_attr($height) . '" '; } // Set standard class if ($class) { $class = 'woo-image ' . esc_attr($class); } else { $class = 'woo-image'; } // Do check to verify if images are smaller then specified. if ($force == true) { $set_width = ''; $set_height = ''; } // WP Post Thumbnail if (!empty($img_link)) { if ($link == 'img') { // Output the image without anchors $output .= wp_kses_post($before); $output .= $img_link; $output .= wp_kses_post($after); } elseif ($link == 'url') { // Output the large image $src = wp_get_attachment_image_src($thumb_id, 'large', true); $custom_field = esc_url($src[0]); $output .= $custom_field; } else { // Default - output with link if ((is_single() || is_page()) && $single == false) { $rel = 'rel="lightbox"'; $href = false; } else { $href = get_permalink($id); $rel = ''; } $title = 'title="' . esc_attr(get_the_title($id)) . '"'; $output .= wp_kses_post($before); if ($href == false) { $output .= $img_link; } else { $output .= '<a ' . $title . ' href="' . esc_url($href) . '" ' . $rel . '>' . $img_link . '</a>'; } $output .= wp_kses_post($after); } } elseif (get_option('woo_resize') == 'true' && empty($vt_image['url'])) { foreach ($src_arr as $key => $custom_field) { // Clean the image URL $href = esc_url($custom_field); $custom_field = cleanSource($custom_field); // Check if WPMU and set correct path AND that image isn't external if (function_exists('get_current_site')) { get_current_site(); //global $blog_id; Breaks with WP3 MS if (!$blog_id) { global $current_blog; $blog_id = $current_blog->blog_id; } if (isset($blog_id) && $blog_id > 0) { $imageParts = explode('files/', $custom_field); if (isset($imageParts[1])) { $custom_field = '/blogs.dir/' . $blog_id . '/files/' . $imageParts[1]; } } } //Set the ID to the Attachment's ID if it is an attachment if ($is_auto_image == true) { $quick_id = $attachment_id[$key]; } else { $quick_id = $id; } //Set custom meta if ($meta) { $alt = $meta; $title = 'title="' . esc_attr($meta) . '"'; } else { if ($alt != '' || !($alt = get_post_meta($thumb_id, '_wp_attachment_image_alt', true))) { $alt = esc_attr(get_post_meta($thumb_id, '_wp_attachment_image_alt', true)); } else { $alt = esc_attr(get_the_title($quick_id)); } $title = 'title="' . esc_attr(get_the_title($quick_id)) . '"'; } // Set alignment parameter if ($alignment != '') { $alignment = '&a=' . urlencode($alignment); } $img_url = esc_url(get_template_directory_uri() . '/functions/thumb.php?src=' . $custom_field . '&w=' . $width . '&h=' . $height . '&zc=1&q=' . $quality . $alignment); $img_link = '<img src="' . $img_url . '" alt="' . esc_attr($alt) . '" class="' . esc_attr(stripslashes($class)) . '" ' . $set_width . $set_height . ' />'; if ($link == 'img') { // Just output the image $output .= wp_kses_post($before); $output .= $img_link; $output .= wp_kses_post($after); } elseif ($link == 'url') { // Output the image without anchors if ($is_auto_image == true) { $src = wp_get_attachment_image_src($thumb_id, 'large', true); $custom_field = esc_url($src[0]); } $output .= $href; } else { // Default - output with link if ((is_single() || is_page()) && $single == false) { $rel = 'rel="lightbox"'; } else { $href = get_permalink($id); $rel = ''; } $output .= wp_kses_post($before); $output .= '<a ' . $title . ' href="' . esc_url($href) . '" ' . $rel . '>' . $img_link . '</a>'; $output .= wp_kses_post($after); } } // No dynamic resizing } else { foreach ($src_arr as $key => $custom_field) { //Set the ID to the Attachment's ID if it is an attachment if ($is_auto_image == true && isset($attachment_id[$key])) { $quick_id = $attachment_id[$key]; } else { $quick_id = $id; } //Set custom meta if ($meta) { $alt = esc_attr($meta); $title = 'title="' . esc_attr($meta) . '"'; } else { if (empty($alt)) { $alt = esc_attr(get_post_meta($thumb_id, '_wp_attachment_image_alt', true)); } $title = 'title="' . esc_attr(get_the_title($quick_id)) . '"'; } if (empty($alt)) { $alt = esc_attr(get_post($thumb_id)->post_excerpt); // If not, Use the Caption } if (empty($alt)) { $alt = esc_attr(get_post($thumb_id)->post_title); // Finally, use the title } $img_link = '<img src="' . esc_url($custom_field) . '" alt="' . esc_attr($alt) . '" ' . $set_width . $set_height . $title . ' class="' . esc_attr(stripslashes($class)) . '" />'; if ($link == 'img') { // Just output the image $output .= wp_kses_post($before); $output .= $img_link; $output .= wp_kses_post($after); } elseif ($link == 'url') { // Output the URL to original image if ($vt_image['url'] || $is_auto_image) { $src = wp_get_attachment_image_src($thumb_id, 'full', true); $custom_field = esc_url($src[0]); } $output .= $custom_field; } else { // Default - output with link if ((is_single() || is_page()) && $single == false) { // Link to the large image if single post if ($vt_image['url'] || $is_auto_image) { $src = wp_get_attachment_image_src($thumb_id, 'full', true); $custom_field = esc_url($src[0]); } $href = $custom_field; $rel = 'rel="lightbox"'; } else { $href = get_permalink($id); $rel = ''; } $output .= wp_kses_post($before); $output .= '<a href="' . esc_url($href) . '" ' . $rel . ' ' . $title . '>' . $img_link . '</a>'; $output .= wp_kses_post($after); } } } // Remove no height attribute - IE fix when no height is set $output = str_replace('height=""', '', $output); $output = str_replace('height="0"', '', $output); // Return or echo the output if ($return == TRUE) { return $output; } else { echo $output; } // Done }
function woo_image($args) { //Defaults $key = 'image'; $width = null; $height = null; $class = ''; $quality = 90; $id = null; $link = 'src'; $repeat = 1; $offset = 0; $before = ''; $after = ''; $single = false; $force = false; $return = false; $is_auto_image = false; $src = ''; $auto_meta = true; $meta = ''; if (!is_array($args)) { parse_str($args, $args); } extract($args); if (empty($id)) { global $post; $id = $post->ID; } if ($src != '') { // When a custom image is sent through $custom_field = $src; $link = 'img'; $auto_meta = false; } else { $custom_field = get_post_meta($id, $key, true); } if (empty($custom_field) && get_option('woo_auto_img') == 'true') { // Get the image from post attachments if ($offset >= 1) { $repeat = $repeat + $offset; } $attachments = get_children(array('post_parent' => $id, 'numberposts' => $repeat, 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => 'DESC', 'orderby' => 'menu_order date')); if (!empty($attachments)) { // Search for and get the post attachment $counter = -1; $size = 'large'; foreach ($attachments as $att_id => $attachment) { $counter++; if ($counter < $offset) { continue; } $src = wp_get_attachment_image_src($att_id, $size, true); $custom_field = $src[0]; $is_auto_image = true; $attachment_id = $att_id; } } else { // Get the first img tag from content $first_img = ''; $post = get_post($id); ob_start(); ob_end_clean(); $output = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $post->post_content, $matches); $first_img = $matches[1][0]; if (!empty($first_img)) { $custom_field = $first_img; } } } // Return if there is no attachment or custom field set if (empty($custom_field)) { return; } $output = ''; // Get standard sizes if (!$width && !$height) { $width = '100'; $height = '100'; } $set_width = ' width="' . $width . '" '; $set_height = ' height="' . $height . '" '; if ($height == null or $height == '') { $set_height = ''; } // Set standard class if ($class) { $class .= ' woo-image'; } else { $class = 'woo-image'; } // Do check to verify if images are smaller then specified. $force_all = get_option('woo_force_all'); $force_single = get_option('woo_force_single'); if ($force == true or $force_all == true or $force_single == true and is_single()) { $set_width = ''; $set_height = ''; } if (get_option('woo_resize') == 'true') { // Clean the image URL $href = $custom_field; $custom_field = cleanSource($custom_field); // Check if WPMU and set correct path global $blog_id; if (isset($blog_id) && $blog_id > 0) { $imageParts = explode('/files/', $custom_field); if (isset($imageParts[1])) { $custom_field = '/blogs.dir/' . $blog_id . '/files/' . $imageParts[1]; } else { // Try again $imageParts = explode('files/', $custom_field); if (isset($imageParts[1])) { $custom_field = '/blogs.dir/' . $blog_id . '/files/' . $imageParts[1]; } } } //Set the ID to the Attachent's ID if it is an attachment if ($is_auto_image == true) { $quick_id = $attachment_id; } else { $quick_id = $id; } if ($auto_meta == true) { $alt = 'alt="' . get_the_title($quick_id) . '"'; $title = 'title="' . get_the_title($quick_id) . '"'; } elseif ($auto_meta == false) { $alt = 'alt="' . $meta . '"'; $title = 'title="' . $meta . '"'; } else { $alt = 'alt=""'; $title = ''; } $img_link = '<img src="' . get_bloginfo('template_url') . '/thumb.php?src=' . $custom_field . '&w=' . $width . '&h=' . $height . '&zc=1&q=' . $quality . '" ' . $alt . ' class="' . $class . '" ' . $set_width . $set_height . ' />'; if ($link == 'img') { // Just output the image $output .= $before; $output .= $img_link; $output .= $after; } else { // Default - output with link if ((is_single() or is_page()) and $single == false) { $rel = 'rel="lightbox"'; } else { $href = get_permalink($id); $rel = ''; } $output .= $before; $output .= '<a ' . $title . ' href="' . $href . '" ' . $rel . '>' . $img_link . '</a>'; $output .= $after; } } else { // Not Resize $img_link = '<img src="' . $custom_field . ' ' . $alt . ' ' . $set_width . $set_height . ' class="' . $class . '" />'; if ($link == 'img') { // Just output the image $output .= $before; $output .= $img_link; $output .= $after; } else { // Default - output with link if ((is_single() or is_page()) and $single == false) { $href = $custom_field; $rel = 'rel="lightbox"'; } else { $href = get_permalink($id); $rel = ''; } $output .= $before; $output .= '<a ' . $alt . ' href="' . $href . '" ' . $rel . '>' . $img_link . '</a>'; $output .= $after; } } // Return or echo the output if ($return == TRUE) { return $output; } else { echo $output; } // Done }
/** * timthumb_deprecated handles legacy timthumb logic * @since 6.1.0 * @param array $args old timthumb arguments * @return html markup output */ function timthumb_deprecated($args = array()) { //Defaults $output = ''; $src_arr = array(); $attachment_id = array(); $id = null; $meta = ''; $alt = ''; $thumb_id = ''; $alignment = ''; $width = null; $height = null; $quality = 90; $class = ''; $set_width = ''; $set_height = ''; $before = ''; $after = ''; $link = 'src'; $is_auto_image = false; $single = false; if (!is_array($args)) { parse_str($args, $args); } extract($args); foreach ($src_arr as $key => $custom_field) { // Clean the image URL $href = esc_url($custom_field); $custom_field = cleanSource($custom_field); // Check if WPMU and set correct path AND that image isn't external if (function_exists('get_current_site')) { get_current_site(); //global $blog_id; Breaks with WP3 MS if (!isset($blog_id) || !$blog_id) { global $current_blog; $blog_id = $current_blog->blog_id; } if (isset($blog_id) && $blog_id > 0) { $imageParts = explode('files/', $custom_field); if (isset($imageParts[1])) { $custom_field = '/blogs.dir/' . $blog_id . '/files/' . $imageParts[1]; } } } //Set the ID to the Attachment's ID if it is an attachment if ($is_auto_image == true) { $quick_id = $attachment_id[$key]; } else { $quick_id = $id; } //Set custom meta if ($meta) { $alt = $meta; $title = 'title="' . esc_attr($meta) . '"'; } else { if ($alt != '' || !($alt = get_post_meta($thumb_id, '_wp_attachment_image_alt', true))) { $alt = esc_attr(get_post_meta($thumb_id, '_wp_attachment_image_alt', true)); } else { $alt = esc_attr(get_the_title($quick_id)); } $title = 'title="' . esc_attr(get_the_title($quick_id)) . '"'; } // Set alignment parameter if ($alignment != '') { $alignment = '&a=' . urlencode($alignment); } $img_url = esc_url(get_template_directory_uri() . '/functions/thumb.php?src=' . $custom_field . '&w=' . $width . '&h=' . $height . '&zc=1&q=' . $quality . $alignment); $img_link = '<img src="' . $img_url . '" alt="' . esc_attr($alt) . '" class="' . esc_attr(stripslashes($class)) . '" ' . $set_width . $set_height . ' />'; if ($link == 'img') { // Just output the image $output .= wp_kses_post($before); $output .= $img_link; $output .= wp_kses_post($after); } elseif ($link == 'url') { // Output the image without anchors if ($is_auto_image == true) { $src = wp_get_attachment_image_src($thumb_id, 'large', true); $custom_field = esc_url($src[0]); } $output .= $href; } else { // Default - output with link if ((is_single() || is_page()) && $single == false) { $rel = 'rel="lightbox"'; } else { $href = get_permalink($id); $rel = ''; } $output .= wp_kses_post($before); $output .= '<a ' . $title . ' href="' . esc_url($href) . '" ' . $rel . '>' . $img_link . '</a>'; $output .= wp_kses_post($after); } } return $output; }
function colabs_image($args) { /* ------------------------------------------------------------------------- */ /* SET VARIABLES */ /* ------------------------------------------------------------------------- */ global $post; global $colabs_options; //Defaults if (get_option('colabs_custom_field_image') != '') { $key = get_option('colabs_custom_field_image'); } else { $key = 'image'; } $width = null; $height = null; $class = ''; $quality = 90; $id = null; $link = 'src'; $repeat = 1; $offset = 0; $before = ''; $after = ''; $single = false; $force = true; $return = false; $is_auto_image = false; $src = ''; $meta = ''; $alignment = ''; $size = ''; $play = false; $alt = ''; $img_link = ''; $attachment_id = array(); $attachment_src = array(); if (!is_array($args)) { parse_str($args, $args); } extract($args); // Set Play Icon $playicon = ''; // Set post ID if (empty($id)) { $id = $post->ID; } $thumb_id = get_post_meta($id, '_thumbnail_id', true); // Set alignment if ('' == $alignment) { $alignment = get_post_meta($id, '_image_alignment', true); } // Get standard sizes if (!$width && !$height) { $width = '100'; $height = '100'; } /* ------------------------------------------------------------------------- */ /* FIND IMAGE TO USE */ /* ------------------------------------------------------------------------- */ // When a custom image is sent through if ($src != '') { $custom_field = $src; $link = 'img'; // WP 2.9 Post Thumbnail support } elseif ('true' == get_option('colabs_post_image_support') and !empty($thumb_id)) { if (get_option('colabs_pis_resize') == "true") { // Dynamically resize the post thumbnail $vt_crop = get_option('colabs_pis_hard_crop'); if ($vt_crop == "true") { $vt_crop = true; } else { $vt_crop = false; } $vt_image = vt_resize($thumb_id, '', $width, $height, $vt_crop); // Set fields for output $custom_field = $vt_image['url']; $width = $vt_image['width']; $height = $vt_image['height']; } else { // Use predefined size string if ($size) { $thumb_size = $size; } else { $thumb_size = array($width, $height); } $img_link = get_the_post_thumbnail($id, $thumb_size, array('class' => 'colabs-image ' . $class)); } // Grab the image from custom field } else { $custom_field = get_post_meta($id, $key, true); } // Automatic Image Thumbs - get first image from post attachment if (empty($custom_field) && 'true' == get_option('colabs_auto_img') && empty($img_link) && !(is_singular() and in_the_loop() and $link == "src")) { if ($offset >= 1) { $repeat = $repeat + $offset; } $attachments = get_children(array('post_parent' => $id, 'numberposts' => $repeat, 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => 'DESC', 'orderby' => 'menu_order date')); // Search for and get the post attachment if (!empty($attachments)) { $counter = -1; $size = 'large'; foreach ($attachments as $att_id => $attachment) { $counter++; if ($counter < $offset) { continue; } if ('true' == get_option('colabs_post_image_support') and get_option('colabs_pis_resize') == "true") { // Dynamically resize the post thumbnail $vt_crop = get_option('colabs_pis_hard_crop'); if ($vt_crop == "true") { $vt_crop = true; } else { $vt_crop = false; } $vt_image = vt_resize($att_id, '', $width, $height, $vt_crop); // Set fields for output $custom_field = $vt_image['url']; $width = $vt_image['width']; $height = $vt_image['height']; } else { $src = wp_get_attachment_image_src($att_id, $size, true); $custom_field = $src[0]; $attachment_id[] = $att_id; $src_arr[] = $custom_field; } $thumb_id = $att_id; $is_auto_image = true; } // Get the first img tag from content } else { $first_img = ''; $post = get_post($id); ob_start(); ob_end_clean(); $output = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $post->post_content, $matches); if (!empty($matches[1][0])) { // Save Image URL $custom_field = $matches[1][0]; // Search for ALT tag $output = preg_match_all('/<img.+alt=[\'"]([^\'"]+)[\'"].*>/i', $post->post_content, $matches); if (!empty($matches[1][0])) { $alt = $matches[1][0]; } } } } // Check if there is YouTube embed if (empty($custom_field) && empty($img_link)) { $embed = get_post_meta($id, "colabs_embed", true); if ($embed) { $custom_field = colabs_get_video_image($embed); // Set Play Icon if ($play == true) { $playicon = '<span class="playicon">Play</span>'; } } } // Return if there is no attachment or custom field set if (empty($custom_field) && empty($img_link)) { // Check if default placeholder image is uploaded $placeholder = get_option('framework_colabs_default_image'); if ($placeholder && !(is_singular() and in_the_loop())) { $custom_field = $placeholder; // Resize the placeholder if if ('true' == get_option('colabs_post_image_support') and get_option('colabs_pis_resize') == "true") { // Dynamically resize the post thumbnail $vt_crop = get_option('colabs_pis_hard_crop'); if ($vt_crop == "true") { $vt_crop = true; } else { $vt_crop = false; } $vt_image = vt_resize('', $placeholder, $width, $height, $vt_crop); // Set fields for output $custom_field = $vt_image['url']; $width = $vt_image['width']; $height = $vt_image['height']; } } else { return; } } if (empty($src_arr) && empty($img_link)) { $src_arr[] = $custom_field; } /* ------------------------------------------------------------------------- */ /* BEGIN OUTPUT */ /* ------------------------------------------------------------------------- */ $output = ''; // Set output height and width $set_width = ' width="' . $width . '" '; $set_height = ' height="' . $height . '" '; if ($height == null or '' == $height) { $set_height = ''; } // Set standard class if ($class) { $class = 'colabs-image ' . $class; } else { $class = 'colabs-image'; } // Do check to verify if images are smaller then specified. if ($force == true) { $set_width = ''; $set_height = ''; } // WP Post Thumbnail if (!empty($img_link)) { if ('img' == $link) { // Output the image without anchors $output .= $before; $output .= $img_link; $output .= $after; } elseif ('url' == $link) { // Output the large image $src = wp_get_attachment_image_src($thumb_id, 'large', true); $custom_field = $src[0]; $output .= $custom_field; } else { // Default - output with link if ((is_single() or is_page()) and $single == false) { $rel = 'rel="lightbox"'; $href = false; } else { $href = get_permalink($id); $rel = ''; } $title = 'title="' . get_the_title($id) . '"'; $output .= $before; if ($href == false) { $output .= $img_link; } else { $output .= '<a ' . $title . ' href="' . $href . '" ' . $rel . '>' . $img_link . '</a>'; } $output .= $after; } } elseif ('true' == get_option('colabs_resize') && empty($vt_image['url'])) { foreach ($src_arr as $key => $custom_field) { // Clean the image URL $href = $custom_field; $custom_field = cleanSource($custom_field); // Check if WPMU and set correct path AND that image isn't external if (function_exists('get_current_site') && strpos($custom_field, "http://") !== 0) { get_current_site(); //global $blog_id; Breaks with WP3 MS if (!$blog_id) { global $current_blog; $blog_id = $current_blog->blog_id; } if (isset($blog_id) && $blog_id > 0) { $imageParts = explode('files/', $custom_field); if (isset($imageParts[1])) { $custom_field = '/blogs.dir/' . $blog_id . '/files/' . $imageParts[1]; } } } //Set the ID to the Attachment's ID if it is an attachment if ($is_auto_image == true) { $quick_id = $attachment_id[$key]; } else { $quick_id = $id; } //Set custom meta if ($meta) { $alt = $meta; $title = 'title="' . $meta . '"'; } else { if ('' == $alt and get_post_meta($thumb_id, '_wp_attachment_image_alt', true)) { $alt = get_post_meta($thumb_id, '_wp_attachment_image_alt', true); } else { $alt = get_the_title($quick_id); } $title = 'title="' . get_the_title($quick_id) . '"'; } // Set alignment parameter if ($alignment != '') { $alignment = '&a=' . $alignment; } $img_link = '<img src="' . get_template_directory_uri() . '/functions/timthumb.php?src=' . $custom_field . '&w=' . $width . '&h=' . $height . '&zc=1&q=' . $quality . $alignment . '" alt="' . $alt . '" class="' . stripslashes($class) . '" ' . $set_width . $set_height . ' />'; if ('img' == $link) { // Just output the image $output .= $before; $output .= $img_link; $output .= $playicon; $output .= $after; } elseif ('url' == $link) { // Output the image without anchors if ($is_auto_image == true) { $src = wp_get_attachment_image_src($thumb_id, 'large', true); $custom_field = $src[0]; } $output .= $custom_field; } else { // Default - output with link if ((is_single() or is_page()) and $single == false) { $rel = 'rel="lightbox"'; } else { $href = get_permalink($id); $rel = ''; } $output .= $before; $output .= '<a ' . $title . ' href="' . $href . '" ' . $rel . '>' . $img_link . $playicon . '</a>'; $output .= $after; } } // No dynamic resizing } else { foreach ($src_arr as $key => $custom_field) { //Set the ID to the Attachment's ID if it is an attachment if ($is_auto_image == true and isset($attachment_id[$key])) { $quick_id = $attachment_id[$key]; } else { $quick_id = $id; } //Set custom meta if ($meta) { $alt = $meta; $title = 'title="' . $meta . '"'; } else { if ('' == $alt) { $alt = get_post_meta($thumb_id, '_wp_attachment_image_alt', true); } $title = 'title="' . get_the_title($quick_id) . '"'; } $img_link = '<img src="' . $custom_field . '" alt="' . $alt . '" ' . $set_width . $set_height . ' class="' . stripslashes($class) . '" />'; if ('img' == $link) { // Just output the image $output .= $before; $output .= $img_link; $output .= $after; } elseif ('url' == $link) { // Output the URL to original image if ($vt_image['url'] || $is_auto_image) { $src = wp_get_attachment_image_src($thumb_id, 'full', true); $custom_field = $src[0]; } $output .= $custom_field; } else { // Default - output with link if ((is_single() or is_page()) and $single == false) { // Link to the large image if single post if ($vt_image['url'] || $is_auto_image) { $src = wp_get_attachment_image_src($thumb_id, 'full', true); $custom_field = $src[0]; } $href = $custom_field; $rel = 'rel="lightbox"'; } else { $href = get_permalink($id); $rel = ''; } $output .= $before; $output .= '<a href="' . $href . '" ' . $rel . $title . '>' . $img_link . '</a>'; $output .= $after; } } } // Return or echo the output if ($return == TRUE) { return $output; } else { echo $output; } // Done }
function woo_image($args) { global $post; global $woo_options; //Defaults $key = 'image'; $width = null; $height = null; $class = ''; $quality = 90; $id = null; $link = 'src'; $repeat = 1; $offset = 0; $before = ''; $after = ''; $single = false; $force = false; $return = false; $is_auto_image = false; $src = ''; $auto_meta = true; $meta = ''; $alignment = ''; $alt = 'alt=""'; $img_link = ''; $attachment_id = array(); $attachment_src = array(); $thumb_id = get_post_meta($post->ID, '_thumbnail_id', true); if (!is_array($args)) { parse_str($args, $args); } extract($args); // Set post ID if (empty($id)) { $id = $post->ID; } // Set alignment if ($alignment == '') { $alignment = get_post_meta($id, '_image_alignment', $single = true); } if ($src != '') { // When a custom image is sent through $custom_field = $src; $link = 'img'; $auto_meta = false; } elseif (get_option('woo_post_image_support') == 'true' and !empty($thumb_id)) { if (is_singular() && $single == false) { $img_link = get_the_post_thumbnail($id, 'single-post-thumbnail', array('class' => 'woo-image ' . $class)); } else { if (is_singular() && $single == true) { $img_link = get_the_post_thumbnail($id, array($width, NULL), array('class' => 'woo-image ' . $class)); } else { if (!empty($width)) { $img_link = get_the_post_thumbnail($id, array($width, NULL), array('class' => 'woo-image ' . $class)); } else { $img_link = get_the_post_thumbnail($id, array(), array('class' => 'woo-image ' . $class)); } } } } else { $custom_field = get_post_meta($id, $key, true); } if (empty($custom_field) && get_option('woo_auto_img') == 'true' && empty($img_link)) { // Get the image from post attachments if ($offset >= 1) { $repeat = $repeat + $offset; } $attachments = get_children(array('post_parent' => $id, 'numberposts' => $repeat, 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => 'DESC', 'orderby' => 'menu_order date')); if (!empty($attachments)) { // Search for and get the post attachment $counter = -1; $size = 'large'; foreach ($attachments as $att_id => $attachment) { $counter++; if ($counter < $offset) { continue; } $src = wp_get_attachment_image_src($att_id, $size, true); $custom_field = $src[0]; $is_auto_image = true; $attachment_id[] = $att_id; $src_arr[] = $custom_field; } } else { // Get the first img tag from content $first_img = ''; $post = get_post($id); ob_start(); ob_end_clean(); $output = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $post->post_content, $matches); if (!empty($matches[1][0])) { $custom_field = $matches[1][0]; } } } // Return if there is no attachment or custom field set if (empty($custom_field) && empty($img_link)) { // Check if default placeholder image is uploaded $placeholder = get_option('framework_woo_default_image'); if ($placeholder) { $custom_field = $placeholder; } else { return; } } if (empty($src_arr) && empty($img_link)) { $src_arr[] = $custom_field; } $output = ''; // Get standard sizes if (!$width && !$height) { $width = '100'; $height = '100'; } $set_width = ' width="' . $width . '" '; $set_height = ' height="' . $height . '" '; if ($height == null or $height == '') { $set_height = ''; } // Set standard class if ($class) { $class = 'woo-image ' . $class; } else { $class = 'woo-image'; } // Do check to verify if images are smaller then specified. $force_all = get_option('woo_force_all'); $force_single = get_option('woo_force_single'); if ($force == true or $force_all == true or $force_single == true and is_single()) { $set_width = ''; $set_height = ''; } // WordPress's the_post_thumbnail if (!empty($img_link)) { if ($link == 'img') { // Just output the image $output .= $before; $output .= $img_link; $output .= $after; } else { // Default - output with link if ((is_single() or is_page()) and $single == false) { $rel = 'rel="lightbox"'; $href = false; } else { $href = get_permalink($id); $rel = ''; } $title = 'title="' . get_the_title($id) . '"'; $output .= $before; if ($href == false) { $output .= $img_link; } else { $output .= '<a ' . $title . ' href="' . $href . '" ' . $rel . '>' . $img_link . '</a>'; } $output .= $after; } } elseif (get_option('woo_resize') == 'true') { foreach ($src_arr as $key => $custom_field) { // Clean the image URL $href = $custom_field; $custom_field = cleanSource($custom_field); // Check if WPMU and set correct path AND that image isn't external if (function_exists('get_current_site') && strpos($custom_field, "http://") !== 0) { get_current_site(); //global $blog_id; Breaks with WP3 MS if (!$blog_id) { global $current_blog; $blog_id = $current_blog->blog_id; } if (isset($blog_id) && $blog_id > 0) { $imageParts = explode('files/', $custom_field); if (isset($imageParts[1])) { $custom_field = '/blogs.dir/' . $blog_id . '/files/' . $imageParts[1]; } } } // Set alignment if any //Set the ID to the Attachent's ID if it is an attachment if ($is_auto_image == true) { $quick_id = $attachment_id[$key]; } else { $quick_id = $id; } if ($auto_meta == true) { $alt = 'alt="' . get_the_title($quick_id) . '"'; $title = 'title="' . get_the_title($quick_id) . '"'; } elseif ($auto_meta == false) { $alt = 'alt="' . $meta . '"'; $title = 'title="' . $meta . '"'; } else { $alt = 'alt=""'; $title = ''; } // Set alignment parameter if ($alignment != '') { $alignment = '&a=' . $alignment; } $img_link = '<img src="' . get_bloginfo('template_url') . '/thumb.php?src=' . $custom_field . '&w=' . $width . '&h=' . $height . '&zc=1&q=' . $quality . $alignment . '" ' . $alt . ' class="' . stripslashes($class) . '" ' . $set_width . $set_height . ' />'; if ($link == 'img') { // Just output the image $output .= $before; $output .= $img_link; $output .= $after; } else { // Default - output with link if ((is_single() or is_page()) and $single == false) { $rel = 'rel="lightbox"'; } else { $href = get_permalink($id); $rel = ''; } $output .= $before; $output .= '<a ' . $title . ' href="' . $href . '" ' . $rel . '>' . $img_link . '</a>'; $output .= $after; } } } else { // Not Resize foreach ($src_arr as $key => $custom_field) { //Set the ID to the Attachent's ID if it is an attachment if ($is_auto_image == true) { $quick_id = $attachment_id[$key]; } else { $quick_id = $id; } if ($auto_meta == true) { $alt = 'alt="' . get_the_title($quick_id) . '"'; $title = 'title="' . get_the_title($quick_id) . '"'; } elseif ($auto_meta == false) { $alt = 'alt="' . $meta . '"'; $title = 'title="' . $meta . '"'; } else { $alt = 'alt=""'; $title = ''; } $img_link = '<img src="' . $custom_field . '" ' . $alt . ' ' . $set_width . $set_height . ' class="' . stripslashes($class) . '" />'; if ($link == 'img') { // Just output the image $output .= $before; $output .= $img_link; $output .= $after; } else { // Default - output with link if ((is_single() or is_page()) and $single == false) { $href = $custom_field; $rel = 'rel="lightbox"'; } else { $href = get_permalink($id); $rel = ''; } $output .= $before; $output .= '<a href="' . $href . '" ' . $rel . '>' . $img_link . '</a>'; $output .= $after; } } } // Return or echo the output if ($return == TRUE) { return $output; } else { echo $output; } // Done }