' ."\n";
echo '' ."\n";
if ($gdv = gdVersion()) {
if ($gdv >=2) {
echo '' ."\n";
} else {
echo '' ."\n";
}
} else {
echo '' ."\n";
}
}
add_action('wp_head','wr_version');
/*
Get values for custom field
This function gets the custom field image and uses timthumb.php to resize it
Parameters:
*/
function wr_get_image($key = 'image', $width = null, $height = null, $class = "thumbnail", $quality = 90,$id = null,$link = 'src',$repeat = 1,$offset = 0,$before = '', $after = '',$single = false, $force = false, $return = false) {
if(empty($id))
{
global $post;
$id = $post->ID;
}
$output = '';
$custom_field = get_post_meta($id, $key, true);
$set_width = ' width="' . $width .'" ';
$set_height = ' height="' . $height .'" ';
if(!empty($custom_field)) { // If user set a custom field
//check small images
if ($gdv = gdVersion()) {
$image_size = @getimagesize($custom_field);
$image_size_width = $image_size[0];
$image_size_height = $image_size[1];
}
if($force == false){ // check to verify if images are small then specified.
if($width == null or $width > $image_size_width ){ $set_width = '';}
if($height == null or $height > $image_size_height){ $set_height = '';}
}
if (get_option('wr_resize') == 'true') {
$img_link = '';
if($link == 'img'){ // output
$output .= $before;
$output .= $img_link;
$output .= $after;
}
else { //output with link
if ((is_single() OR is_page()) AND $single == false) {
$href = $custom_field;
}
else {
$href = get_permalink($id);
}
$output .= $before;
$output .= '' . $img_link . '';
$output .= $after;
}
}
else { // nore resize
$img_link = '
';
if($link == 'img'){ // output
$output .= $before;
$output .= $img_link;
$output .= $after;
}
else { //output with link
if ((is_single() OR is_page()) AND $single == false)
{
$href = $custom_field;
}
else {
$href = get_permalink($id);
}
$output .= $before;
$output .= '' . $img_link . '';
$output .= $after;
}
}
if($return == TRUE)
{
return $output;
}
else
{
echo $output; // complete
}
}
elseif(empty($custom_field) && get_option('wr_auto_img') == 'true'){
if($offset >= 1){$repeat = $repeat + $offset;}
$attachments = get_children( array(
'post_parent' => $id,
'numberposts' => $repeat,
'post_type' => 'attachment',
'post_mime_type' => 'image')
);
if ( empty($attachments) )
return;
$counter = -1;
$size = 'large';
foreach ( $attachments as $att_id => $attachment ) {
$counter++;
if($counter < $offset) { continue; }
$output = '';
$src = wp_get_attachment_image_src($att_id, $size, true);
$custom_field = $src[0];
//check small images
if ($gdv = gdVersion()) {
$image_size = @getimagesize($custom_field);
$image_size_width = $image_size[0];
$image_size_height = $image_size[1];
}
if($force == false){ // check to verify if images are small then specified.
if($width == null or $width > $image_size_width ){ $set_width = '';}
if($height == null or $height > $image_size_height){ $set_height = '';}
}
if (get_option('wr_resize') == 'true') {
$img_link = '
';
if($link == 'img' AND $single == false){ // output
$output .= $before;
$output .= $img_link;
$output .= $after;
}
else { //output with link
if ((is_single() OR is_page()) AND $single == false) {
$href = $custom_field; }
else {
$href = get_permalink($id);
}
$output .= $before;
$output .= '' . $img_link . '';
$output .= $after;
}
}
else { // nore resize
$img_link = '
';
if($link == 'img'){ // output
$output .= $before;
$output .= $img_link;
$output .= $after;
}
else { //output with link
if ((is_single() OR is_page()) AND $single == false) {
$href = $custom_field;
}
else {
$href = get_permalink($id);
}
$output .= $before;
$output .= '' . $img_link . '';
$output .= $after;
}
}
if($return == TRUE)
{
return $output;
}
else
{
echo $output; // complete
}
}
}
else {
return;
}
}
/*
Video
gets the embed code from the custom field
Parameters:
$key = Custom field key eg. "embed"
$width = Set width manually without using $type
$height = Set height manually without using $type
*/
function wr_get_embed($key, $width, $height, $class = 'video', $id = null) {
if(empty($id))
{
global $post;
$id = $post->ID;
}
$custom_field = get_post_meta($id, $key, true);
if ($custom_field) :
$org_width = $width;
$org_height = $height;
// Get custom width and height
$custom_width = get_post_meta($id, 'width', true);
$custom_height = get_post_meta($id, 'height', true);
// Set values: width="X", height="X"
if ( !$custom_width ) $width = 'width="'.$width.'"'; else $width = 'width="'.$custom_width.'"';
if ( !$custom_height ) $height = 'height="'.$height.'"'; else $height = 'height="'.$custom_height.'"';
$custom_field = stripslashes($custom_field);
$custom_field = preg_replace( '/width="([0-9]*)"/' , $width , $custom_field );
$custom_field = preg_replace( '/height="([0-9]*)"/' , $height , $custom_field );
// Set values: width:Xpx, height:Xpx
if ( !$custom_width ) $width = 'width:'.$org_width.'px'; else $width = 'width:'.$custom_width.'px';
if ( !$custom_height ) $height = 'height:'.$org_height.'px'; else $height = 'height:'.$custom_height.'px';
$custom_field = stripslashes($custom_field);
$custom_field = preg_replace( '/width:([0-9]*)px/' , $width , $custom_field );
$custom_field = preg_replace( '/height:([0-9]*)px/' , $height , $custom_field );
$output = '';
$output .= '