'fade', 'slide' => 'slide', 'slideMultipleCaptions' => 'slide with multiple captions', 'gridFadeQueue' => 'Grid Fade', 'gridWaveBL2TR' => 'Grid Wave', 'gridRandomSlideDown' => 'Grid Random', 'zoomIn' => 'zoom in', 'shrink' => 'shrink slide', 'peek' => 'peek', )); $wpv_slider_resizing = apply_filters('wpv_slider_resizing', array( 'crop' => __('Crop', 'wpv'), 'fit' => __('Fit'), 'stretch' => __('Stretch'), )); $wpv_shortcode_slider_effects = apply_filters('wpv_shortcode_slider_effects', array( 'fade' => 'fade', 'slide' => 'slide', 'zoomIn' => 'zoom in', )); $wpv_slider_wavetypes = apply_filters('wpv_slider_wavetypes', array( 'R2L' => __('Right to left', 'wpv'), 'L2R' => __('Left to right', 'wpv'), 'B2T' => __('Bottom to top', 'wpv'), 'T2B' => __('Top to bottom', 'wpv'), 'R2L_SNAKE' => __('Right to left / snake', 'wpv'), 'L2R_SNAKE' => __('Left to right / snake', 'wpv'), 'B2T_SNAKE' => __('Bottom to top / snake', 'wpv'), 'T2B_SNAKE' => __('Top to bottom / snake', 'wpv'), 'BR2TL' => __('Bottom right to top left', 'wpv'), 'TL2BR' => __('Top left to bottom right', 'wpv'), 'BL2TR' => __('Bottom left to top right', 'wpv'), 'TR2BL' => __('Top right to bottom left', 'wpv'), 'RAND' => __('Random', 'wpv'), )); // most used template functions go here /** * get_option wrapper */ if(!function_exists('wpv_get_option')) { function wpv_get_option($name, $default = null, $stripslashes = true) { global $wpv_defaults; if($default === null) $default = isset($wpv_defaults[$name]) ? $wpv_defaults[$name] : false; $option = get_option('wpv_'.$name, $default); if($stripslashes) $option = stripslashes($option); return $option; } } /** * echo option */ function wpvge($name, $default = null, $stripslashes = true, $boolean = false) { $opt = wpv_get_option($name, $default, $stripslashes); if($boolean === true) { $opt = (bool)$opt; } echo $opt; } /** * set option */ function wpv_update_option($name, $new_value) { if($new_value == 'true') $new_value = true; elseif($new_value == 'false') $new_value = false; $rand = rand(); if(wpv_get_option($name, 'is_this_new'.$rand) != 'is_this_new'.$rand) { update_option('wpv_' . $name, $new_value); } else { add_option('wpv_' . $name, $new_value); } } /** * delete option */ function wpv_delete_option($name) { delete_option('wpv_' . $name); } /** * gets either a post meta value or a blog option */ function wpv_post_default($meta, $default, $default_is_value = false) { global $post; if(!$default_is_value) { $default = wpv_sanitize_bool(wpv_get_option($default)); } return (get_post_meta($post->ID, 'use-global-options', false) !== 'false') ? $default : wpv_sanitize_bool(get_post_meta($post->ID, $meta, false)); } function wpv_sanitize_bool($value) { if($value === '1' || $value === 'true') { $value = true; } else if($value === '0' || $value === 'false') { $value = false; } return $value; } /** * slider width */ function wpv_get_slider_width() { $width = (int)wpv_get_option('content-width'); return $width; } function wpv_slider_width() { echo wpv_get_slider_width(); } /** * helper function - returns second argument when the first is empty, otherwise returns the first */ function wpv_default($value, $default) { if(empty($value)) return $default; return $value; } /* * checks if current page is the blog page set in Settings->Reading */ function is_blog() { global $post; return $post->ID == get_option('page_for_posts'); } /* * "posted on" meta */ if ( ! function_exists( 'wpv_posted_on' ) ) : function wpv_posted_on() { printf( __( '%2$s | by %3$s', 'wpv' ), 'meta-prep meta-prep-author', sprintf( '%3$s', get_permalink(), esc_attr( get_the_time() ), get_the_date() ), sprintf( '%3$s', get_author_posts_url( get_the_author_meta( 'ID' ) ), sprintf( esc_attr__( 'View all posts by %s', 'wpv' ), get_the_author() ), get_the_author() ) ); } endif; /* * "posted in" meta */ if ( ! function_exists( 'wpv_posted_in' ) ) : function wpv_posted_in() { $tag_list = get_the_tag_list( '', ', ' ); if ( $tag_list ) $posted_in = __( 'Posted in %1$s | tags %2$s', 'wpv' ); elseif ( is_object_in_taxonomy( get_post_type(), 'category' ) ) $posted_in = __( 'Posted in %1$s', 'wpv' ); printf($posted_in, get_the_category_list( ', ' ), $tag_list ); } endif; /* * comments callback */ if ( ! function_exists( 'wpv_comments' ) ) : function wpv_comments($comment, $args, $depth) { $GLOBALS['comment'] = $comment; switch ( $comment->comment_type ) : case '' : ?>
  • id="li-comment-">
    comment_approved == '0' ) : ?>
    $depth, 'max_depth' => $args['max_depth'] ) ) ); ?>
  • | | | ', '' ); ?>
    ID, 'layout-type', 'left-only'); } else { $layout_type = 'full'; } if($layout_type == 'left-only' || $layout_type == 'left-right' || $layout_type == 'two-sidebars' || $layout_type == 'left-sidebar') { $central_width -= (int)wpv_get_option('left_sidebar_width'); } if($layout_type == 'right-only' || $layout_type == 'left-right' || $layout_type == 'two-sidebars' || $layout_type == 'right-sidebar') { $central_width -= (int)wpv_get_option('right_sidebar_width'); } return $central_width; } endif; // turns a string as four_fifths to a value in pixels, works only for the central column if(!function_exists('wpv_str_to_width')): function wpv_str_to_width($frac = 'full') { $width = wpv_get_central_column_width(); if($frac != 'full') { $frac = explode('_', $frac); $map = array( 'one' => 1, 'two' => 2, 'half' => 2, 'three' => 3, 'third' => 3, 'thirds' => 3, 'four' => 4, 'fourth' => 4, 'fourths' => 4, 'five' => 5, 'fifth' => 5, 'fifths' => 5, 'six' => 6, 'sixth' => 6, 'sixths' => 6, ); $frac[0] = $map[$frac[0]]; $frac[1] = $map[$frac[1]]; $width = ($width - ($frac[1]-1)*20)/$frac[1]*$frac[0] + ($frac[0]-1)*20; } return $width; } endif; /* * gets the correct post template depending on the post format */ if(!function_exists('wpv_post_template')): function wpv_post_template($post_formats = null) { global $wpv_post_formats; if(is_null($post_formats)) { $post_formats = $wpv_post_formats; } $standard_post_format = true; foreach($post_formats as $post_format) { if(has_post_format($post_format)) { $standard_post_format = false; get_template_part('single', $post_format); } } if($standard_post_format) { get_template_part('single', 'standard'); } } endif; /* * gets basic post settings */ if(!function_exists('wpv_post_info')): function wpv_post_info() { global $wpv_loop_vars, $post; $result = array(); if(is_array($wpv_loop_vars)) { extract($wpv_loop_vars); $result['show_image'] = ($image == 'true'); $result['img_style'] = $img_style; $result['meta'] = ($meta == 'true'); $result['fullpost'] = ($fullpost == 'true'); $result['width'] = $width; } else { $result['img_style'] = wpv_post_default('img_style', 'single-featured-image-position'); $result['show_image'] = true; $result['meta'] = true; $result['fullpost'] = true; $result['width'] = 'full'; } return $result; } endif; /* * echoes the post video for the video post type */ if(!function_exists('wpv_post_video')): function wpv_post_video($width, $height = null, $link = null) { global $post; if(!isset($link)) { $link = get_post_meta($post->ID, 'post-link', true); } $type = 'html5'; if(isset($height)) { $height = 'height="'.$height.'"'; } if(strpos($link, 'youtube') !== false || strpos($link, 'youtu.be') !== false) { $type = 'youtube'; } elseif(strpos($link, 'vimeo') !== false) { $type = 'vimeo'; } elseif(strpos($link, 'dailymotion') !== false) { $type = 'dailymotion'; } elseif(preg_match('/\.swf$/i', $link)) { $type = 'flash'; } elseif(preg_match('/\.(mp4|ogg|webm)$/i', $link)) { $type = 'html5'; } echo do_shortcode('[video type="'.$type.'" src="'.$link.'" width="'.$width.'" '.$height.']'); } endif; // lazy load images if(!function_exists('wpv_lazy_load')): function wpv_lazy_load($url, $alt='', $atts = array()) { echo wpv_get_lazy_load($url, $alt, $atts); } function wpv_get_lazy_load($url, $alt='', $atts = array()) { if(isset($atts['class'])) { $atts['class'] .= ' lazy'; } else { $atts['class'] = 'lazy'; } if(isset($atts['height']) && empty($atts['height'])) { unset($atts['height']); } $extended_atts = array(); foreach($atts as $att=>$val) { $extended_atts[] = "$att='$val'"; } $atts = implode(' ', $extended_atts); ob_start(); ?> <?php echo $alt?> /> ]*>\s*<\\/p[^>]*>/", '', $content); } add_filter('the_content', 'wpv_remove_empty_p', 100000); function wpv_get_portfolio_options($group, $rel_group) { $res = array(); $res['image'] = wp_get_attachment_image_src(get_post_thumbnail_id(get_the_id()), 'full', true); $res['type'] = wpv_default(get_post_meta(get_the_id(), 'portfolio_type', true), 'image'); $res['width'] = ''; $res['height'] = ''; $res['iframe'] = ''; // calculate some options depending on the portfolio item's type if($res['type'] == 'image') { $res['href'] = $res['image'][0]; $res['lightbox'] = ' lightbox'; $res['rel'] = ($group == 'true')? ' rel="'.$rel_group.'"' : ''; } elseif($res['type'] == 'video') { $res['href'] = get_post_meta(get_the_id(), 'portfolio_data_url', true); if(empty($res['href'])) { $res['href'] = $res['image'][0]; } $res['video_width'] = get_post_meta(get_the_id(), 'portfolio_video_width', true); $res['video_height'] = get_post_meta(get_the_id(), 'portfolio_video_height', true); $res['width'] = ' data-width="'.$res['video_width'].'"'; $res['height'] = ' data-height="'.$res['video_height'].'"'; $res['iframe'] = ' data-iframe="true"'; $res['lightbox'] = ' lightbox'; $res['rel'] = ($group == 'true')? ' rel="'.$rel_group.'"' : ''; } elseif($res['type'] == 'link') { $res['href'] = get_post_meta(get_the_ID(), 'portfolio_data_url', true); $res['link_target'] = get_post_meta(get_the_ID(), '_link_target', true); $res['link_target'] = $res['link_target'] ? $res['link_target'] : '_self'; $res['lightbox'] = ' no-lightbox'; $res['rel'] = ''; } elseif($res['type'] == 'gallery') { $res['image_ids_str'] = get_post_meta(get_the_id(), 'gallery_ids', true); $res['image_ids'] = array(); $res['rel'] = ($group == 'true')? ' rel="'.$rel_group.'"' : ''; if(!empty($res['image_ids_str'])) { $res['image_ids'] = explode(',',str_replace('image-','',$res['image_ids_str'])); $res['rel'] = 'rel="gallery-'.get_the_ID().'"'; $res['href'] = $res['image'][0]; } $res['lightbox'] = ' lightbox'; } elseif($res['type'] == 'document') { if(is_single()) { $res['href'] = $res['image'][0]; $res['lightbox'] = ' lightbox'; } else { $res['href'] = get_permalink(); $res['lightbox'] = ' no-lightbox'; } $res['rel'] = ''; } return $res; } /* standard post format filter */ add_filter('query_vars', 'format_filter' ); function format_filter( $qvars ) { $qvars[] = 'format_filter'; return $qvars; } // passes the code through do_shortcode and then removes [raw]...[/raw] wrappers function wpv_clean_do_shortcode($content) { return wpv_clean_raw(do_shortcode($content)); } function wpv_clean_raw($content) { return str_replace('[raw]', '', str_replace('[/raw]', '', $content)); } function wpv_static($option) { if(isset($option['static']) && $option['static']) { echo 'static'; } } function wpv_buttons() { ?>
    max_num_pages; $paged = ( get_query_var('paged') > 1 ) ? get_query_var('paged') : (get_query_var('page') ? get_query_var('page') : 1); if($max != $paged) { echo '
    '.__('Load more', 'wpv').'
    '; } } function wpv_custom_js() { $custom_js = wpv_get_option('custom_js'); if(!empty($custom_js)): ?> .*?)(?:\/)?\](?:(?P.+?)\[\/$name\])?/s", $content, $matches)) { return false; } $params = array(); $sub_contents = $matches['contents']; foreach($matches['params'] as $param_str) { $params[] = shortcode_parse_atts($param_str); } return true; } function wpv_post_siblings_links() { global $post; $same_cat = (count(wp_get_object_terms($post->ID, 'category', array('fields' => 'ids'))) > 0); echo ''; } function wpv_is_login() { return strpos($_SERVER['PHP_SELF'], 'wp-login.php') !== false; } /** * @see http://wordpress.stackexchange.com/a/7094/8344 */ function wpv_get_attachment_id( $url ) { $dir = wp_upload_dir(); $dir = trailingslashit($dir['baseurl']); if( false === strpos( $url, $dir ) ) return false; $file = basename($url); $query = array( 'post_type' => 'attachment', 'fields' => 'ids', 'meta_query' => array( array( 'value' => $file, 'compare' => 'LIKE', ) ) ); $query['meta_query'][0]['key'] = '_wp_attached_file'; $ids = get_posts( $query ); foreach( $ids as $id ) if( $url == array_shift( wp_get_attachment_image_src($id, 'full') ) ) return $id; $query['meta_query'][0]['key'] = '_wp_attachment_metadata'; $ids = get_posts( $query ); foreach( $ids as $id ) { $meta = wp_get_attachment_metadata($id); foreach( $meta['sizes'] as $size => $values ) if( $values['file'] == $file && $url == array_shift( wp_get_attachment_image_src($id, $size) ) ) { $this->attachment_size = $size; return $id; } } return false; } /** * This function check whether a given url is an image attachment and resizes it to $width x $height */ function wpv_resize_image($src, $width, $height, $quality=90) { $attachment_id = wpv_get_attachment_id($src); if( $attachment_id !== false && wp_attachment_is_image($attachment_id) ) { $uploads = wp_upload_dir(); $file = get_attached_file($attachment_id); $thumbnail = wpv_thumbnail_path($file, $width, $height); if(is_wp_error($thumbnail)) { return $src; } else { if(!file_exists($thumbnail)) $thumbnail = image_resize($file, $width, $height, true, null, null, $quality); return str_replace($uploads['basedir'], $uploads['baseurl'], $thumbnail); } } return $src; // not an image attachment, will not be resized } /** * Returns the possible file path for a scaled down version of an image * * Most of the code matches the parts of the image_resize() function, since it doesn't check if the file exists before overwriting it. * * @param string $file Image file path. * @param int $max_w Maximum width to resize to. * @param int $max_h Maximum height to resize to. * @return string Thumbnail file path */ function wpv_thumbnail_path($file, $max_w, $max_h) { $size = @getimagesize( $file ); if ( !$size ) return new WP_Error('invalid_image', __('Could not read image size'), $file); list($orig_w, $orig_h, $orig_type) = $size; $dims = image_resize_dimensions($orig_w, $orig_h, $max_w, $max_h, true); if ( !$dims ) return new WP_Error( 'error_getting_dimensions', __('Could not calculate resized image dimensions') ); list($dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h) = $dims; $info = pathinfo($file); $dir = $info['dirname']; $ext = $info['extension']; $name = wp_basename($file, ".$ext"); return "{$dir}/{$name}-{$dst_w}x{$dst_h}.{$ext}"; return file_exists($destfilename); }