' ."\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 = ''. get_the_title($id) .''; 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 = ''. get_the_title($id) .''; 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 = ''. get_the_title($id) .''; 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 = ''. get_the_title($id) .''; 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 .= '
' . $custom_field . '
'; return $output; endif; } // Show menu in header.php function wr_show_pagemenu( $exclude="" ) { // Split the featured pages from the options, and put in an array if ( get_option('wr_ex_featpages') ) { $menupages = get_option('wr_featpages'); $exclude = $menupages . ',' . $exclude; } $pages = wp_list_pages('sort_column=menu_order&title_li=&echo=0&depth=1&exclude='.$exclude); $pages = preg_replace('%]+)>%U','', $pages); $pages = str_replace('','', $pages); echo $pages; } // Get current path for selected style function wr_style_path() { $style = $_REQUEST[style]; if ($style != '') { $style_path = $style; } else { $stylesheet = get_option('wr_alt_stylesheet'); $style_path = str_replace(".css","",$stylesheet); } if ($style_path == "default") echo 'images'; else echo 'styles/'.$style_path; } // Get current path for selected style function get_page_id($page_name){ global $wpdb; $page_name = $wpdb->get_var("SELECT ID FROM $wpdb->posts WHERE post_name = '".$page_name."' AND post_status = 'publish' AND post_type = 'page'"); return $page_name; } /** * Returns the version (1 or 2) of the GD extension. */ function gdVersion($user_ver = 0) { if (! extension_loaded('gd')) { return; } static $gd_ver = 0; // Accept the specified setting if ($user_ver == 1) { $gd_ver = 1; return 1; } // use the static variable if ($user_ver !=2 && $gd_ver > 0 ) { return $gd_ver; } // Use gd_info() function if possible. if (function_exists('gd_info')) { $ver_info = gd_info(); preg_match('/\d/', $ver_info['GD Version'], $match); $gd_ver = $match[0]; return $match[0]; } // If phpinfo() is disabled use a specified if (preg_match('/phpinfo/', ini_get('disable_functions'))) { if ($user_ver == 2) { $gd_ver = 2; return 2; } else { $gd_ver = 1; return 1; } } // Otherwise use phpinfo() ob_start(); phpinfo(8); $info = ob_get_contents(); ob_end_clean(); $info = stristr($info, 'gd version'); preg_match('/\d/', $info, $match); $gd_ver = $match[0]; return $match[0]; } // End gdVersion() //Short Codes function wr_post_insert_shortcode($attr) { // Allow plugins/themes $output = apply_filters('insert', '', $attr); if ( $output != '' ) return $output; extract(shortcode_atts(array( 'name' => null, 'id' => null, 'before' => '', 'after' => '' ), $attr)); $id = intval($id); global $wpdb; if($name == ''){ $query = "SELECT post_content FROM $wpdb->posts WHERE id = $id"; } else { $query = "SELECT post_content FROM $wpdb->posts WHERE post_name = '$name'"; } $result = $wpdb->get_var($query); if(!empty($result)){ $result = wpautop( $result, $br = 1 ); return $before . $result . $after; } else return; } add_shortcode('insert', 'wr_post_insert_shortcode'); // use "[page]" as a post ?>