Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- function post_is_in_descendant_category( $cats, $_post = null ){
- foreach ( (array) $cats as $cat ) {
- // get_term_children() accepts integer ID only
- $descendants = get_term_children( (int) $cat, 'category');
- if ( $descendants && in_category( $descendants, $_post ) )
- return true;
- }
- return false;
- }
- function exposure_thumb_url($url,$width = 200, $height = null){
- // Check if WPMU and set correct path
- if ( function_exists('get_current_site') ) {
- global $blog_id;
- if ( !$blog_id ) {
- global $current_blog;
- $blog_id = $current_blog->blog_id;
- }
- if ( isset($blog_id) && $blog_id > 0 ) {
- $imageParts = explode( 'files/', $url );
- if ( isset($imageParts[1]) )
- $url = '/blogs.dir/' . $blog_id . '/files/' . $imageParts[1];
- }
- }
- $src = get_bloginfo('template_url') . '/thumb.php?src=' . $url . '&w=' .$width . '&h=' . $height . '&zc=1&q=90';
- return $src ;
- }
- function exposure_attachments($instance = null,$args = array()){
- extract( $args );
- $post_id = $instance['post_id'];
- $post_id_select = $instance['post_id_select'];
- $cat_id = $instance['cat_id'];
- $widget_title = $instance['title'];
- $image_title = $instance['image_title'];
- $image_caption = $instance['image_caption'];
- $size = $instance['size'];
- $rows = $instance['rows'];
- $max = $instance['max'];
- $l2p = $instance['l2p'];
- $lb = $instance['lb'];
- $auto = $instance['auto'];
- $speed = $instance['speed'];
- $post_content = $instance['post_content'];
- $wp_resized_image = get_option('woo_wp_attachment');
- $slider_id = $args['widget_id'];
- if($slider_id == ''){ $slider_id = $post_id; }
- if(!is_home()){
- $custom_size = get_post_meta($post_id,'thumbsize',true);
- $custom_title = get_post_meta($post_id,'title',true);
- $custom_caption = get_post_meta($post_id,'caption',true);
- $custom_rows = get_post_meta($post_id,'rows',true);
- $custom_lb = get_post_meta($post_id,'lb',true);
- }
- if($custom_size != 'default' AND !empty($custom_size)) {$size = $custom_size;}
- if($custom_title != 'default' AND !empty($custom_size)) {$image_title = $custom_title;}
- if($custom_caption != 'default' AND !empty($custom_size)) {$image_caption = $custom_caption;}
- if($custom_rows != 'default' AND !empty($custom_rows)) {$rows = $custom_rows;}
- if($custom_lb != 'default' AND !empty($custom_lb)) {$lb = $custom_lb;}
- $auto = intval($auto); // Validate int
- $speed = intval($speed); // Validate int
- $rows = intval($rows); // Validate int
- //Get the attachments for the Category posts.
- if(!empty($cat_id)){
- $category = true;
- //$post_id = str_replace(' ','-',strtolower(get_cat_name($cat_id)));
- $cat_data = get_category($cat_id, ARRAY_A);
- $post_id = $cat_data['slug'];
- }
- if($category == true){
- $posts = get_posts('cat='.$cat_id .'&numberposts=' . $max);
- $cat_counter = 0;
- $attachments = array();
- foreach($posts as $post){
- //print_r($posts);
- $cat_counter++;
- $single_attachment = get_children( array(
- 'post_parent' => $post->ID,
- 'post_status' => 'inherit',
- 'post_type' => 'attachment',
- 'post_mime_type' => 'image',
- 'order' => 'ASC',
- 'orderby' => 'menu_order date',
- 'numberposts' => 1,
- ));
- if(!empty($single_attachment)){
- if($cat_counter == 1){
- $attachments = $single_attachment;
- }else{
- $attachments = array_merge($attachments, $single_attachment);
- }
- }
- }
- }
- else {
- if($max == "") { $max = 999;}
- $attachments = get_children( array(
- 'post_parent' => $post_id,
- 'post_status' => 'inherit',
- 'post_type' => 'attachment',
- 'post_mime_type' => 'image',
- 'order' => 'ASC',
- 'orderby' => 'menu_order date',
- 'numberposts' => $max,
- ));
- }
- $items = count($attachments);
- //Slider
- if($rows > 0) { $slider = true;}
- if($slider == true){
- if($size == 'small'){ $viewable = 4 * $rows; }
- if($size == 'medium'){ $viewable = 3 * $rows; }
- if($size == 'large'){ $viewable = 2 * $rows; }
- if($size == 'full'){ $viewable = 1 * $rows; }
- }
- if($viewable >= $items) {$slider = false;}
- //Lightbox
- if ($lb == 'true' OR $lb == 'on'){$lightbox = true;}
- else {$lightbox = false;}
- //Link 2 Post
- if ($l2p == 'true' OR $l2p == 'on'){$link_to_post = true;}
- else {$link_to_post = false;}
- $counter = 3;
- $iter = 0;
- $loop = 0;
- if(empty($attachments)){
- return false; // Bail is there is no attachments
- }
- $items = count($attachments);
- foreach ( $attachments as $attachment ) {
- $counter++;
- $loop++;
- //print_r($attachment);
- $id = $attachment->ID;
- //Image Setup
- if($link_to_post == 'true') {
- $link = get_permalink($attachment->post_parent);
- } else {
- $link = get_attachment_link($id);
- }
- $src = wp_get_attachment_image_src($id, 'large', true); // Thumb.php makes use of the Largest wordpres image and not the source file.
- //print_r($src);
- $full_image = $src[0];
- //Content Setup
- $att_title = $attachment->post_title;
- $att_caption = $attachment->post_excerpt;
- $att_content = $attachment->post_content;
- $att_comments = $attachment->comment_count;
- //Setup what goes where
- if($image_title == 'off'){$title = '';}
- elseif($image_title == 'title'){$title = $att_title;}
- elseif ($image_title == 'caption'){$title = $att_caption;}
- elseif ($image_title == 'description'){$title = $att_content;}
- if($image_caption == 'off'){$content = '';}
- elseif($image_caption == 'title'){$content = $att_title;}
- elseif ($image_caption == 'caption'){$content = $att_caption;}
- elseif ($image_caption == 'description'){$content = $att_content;}
- //Size
- if($size == 'small'){$w = 200; $h = 200; $l = 7; $per_row = 4;}
- elseif($size == 'medium'){$w = 280; $h = 320; $l = 6; $per_row = 3;}
- elseif($size == 'large'){$w = 440; $h = 220; $l = 5; $per_row = 2;}
- elseif($size == 'full'){$w = 920; $h = 506; $l = 4; $per_row = 1;}
- //MOD
- if($l == 4) {$mod = ' full first last';}
- else {
- if($counter%4 == 0)
- {$mod = ' first';}
- elseif($counter%$l == 0)
- {$mod = ' last';}
- else{$mod = '';};
- if($counter == $l) $counter = 3;
- }
- if(($iter == 0 ) && $slider == true){$images .= '<div class="slide">' . "\n";}// Slider wrap
- $iter++;
- //$img_url = exposure_thumb_url($full_image,$w,$h);
- if($size == 'full' AND $wp_resized_image == 'true'){ $img_url = $full_image;}
- $img_url = woo_image('key=image&width='.$w.'&height='.$h.'&class=thumb&id='. $id .'&link=img&return=true&src='.$full_image.'&auto_meta=false&meta='.get_the_title($id));
- $images .= '<div class="image_box'. $mod .'">' . "\n";
- if($lightbox == false AND $att_comments != 0) $images .= '<span class="date"><a href="'.$link.'">'. $att_comments . '</a></span>' . "\n";
- if(($image_title == 'off' AND $image_caption == 'off') OR ($title == '' AND $content == '')){
- //When there is no content for image caption or both is turned off
- }
- else{
- $images .= '<div class="text">' . "\n";
- if($image_title != 'off')
- {
- if($lightbox) {
- $images .= '<h3><a title="'. $title .'" rel="lightbox['.$post_id.']" href="'. $full_image .'">'. $title .'</a></h3>'. "\n";;
- } else {
- $images .= '<h3><a title="'. $title .'" href="'. $link .'">'. $title .'</a></h3>' . "\n";
- }
- }
- if($image_caption != 'off') {
- if($lightbox) {
- $images .= '<p><a title="'. $content .'" rel="lightbox['.$post_id.']" href="'. $full_image .'">'. $content .'</a></p>' . "\n";
- } else {
- $images .= '<p><a title="'. $content .'" href="'. $link .'">'. $content .'</a></p>' . "\n";
- }
- }
- $images .= '</div>' . "\n";
- }
- if($lightbox){
- $images .= '<a class="next" title="' . get_the_title($id) .'" rel="lightbox['.$post_id.']" href="#">'. $img_url .'</a>';
- } else {
- $images .= '<a class="next" href="#">'. $img_url .'</a>';
- }
- $images .= '</div>' . "\n";
- if(($iter == $viewable || $loop == $items ) && $slider == true){$images .= '</div>'; $iter = 0;}// Slider wrap
- }
- //Start Output building
- $output = '';
- $output .= '<div class="picture_widget">';
- //Heading
- $output .= '<div class="heading">';
- if($widget_title == '' AND $category == false) { $widget_title = get_the_title($post_id);}
- //else { $widget_title = get_the_title($post_id);}
- if($category == true AND $widget_title == ''){
- $output .= '<h2><a href="'. get_category_link($cat_id).'">'. get_cat_name($cat_id) .'</a></h2>';
- }
- elseif ($widget_title != '' AND $category == true){
- $output .= '<h2><a href="'. get_category_link($cat_id).'">'. $widget_title .'</a></h2>';
- }
- elseif (!is_single() && !is_page()){
- $output .= '<h2><a href="'. get_permalink($post_id).'">'. $widget_title .'</a></h2>';
- }
- else {
- $output .= '<h2>'. $widget_title .'</h2>';
- }
- //$output .= '<a href="#" title="#" class="title_rss">RSS feed (optional)</a>'; ?
- $output .= '<div class="clear"></div>';
- $output .= '</div>' . "\n";
- if($slider == true){
- $output .= '<div id="slider_'. $slider_id .'">'. "\n" . '<div class="container">'. "\n" . '<div class="slides">'. "\n";
- }
- //Images
- $output .= $images;
- if($slider == true){
- $output .= "</div>\n</div>\n";
- $output .= '<a class="slider_left previous" href="#" title="Navigate left">PREV</a>';
- $output .= '<a class="slider_right next" href="#" title="Navigate right">NEXT</a>' . "\n";
- $output .= "</div>\n";
- }
- $output .= '<div class="clear"></div>' . "\n";
- if($post_content == 'true') {
- $exp_query = new WP_Query('p=' . $post_id);
- while ($exp_query->have_posts()) : $exp_query->the_post();
- $output .= '<div class="widget-post">' . wpautop(get_the_content()) . '</div>';
- endwhile;
- }
- //Category Archives
- if($category != true AND !is_page()) {
- $cats = get_the_category($post_id);
- foreach($cats as $category){
- $output .= '<a class="archive_link" href="'. get_category_link($category->term_id) .'" title="View '.$category->name .' Archives">' . $category->name . '</a>';
- }
- $output .= '<div class="clear"></div>' . "\n";
- }
- if($slider == true){
- $output .= '<script type="text/javascript">jQuery(window).load(function(){ jQuery("#slider_'. $slider_id . '").loopedSlider({autoStart:'.$auto.', slidespeed:'.$speed.'});});</script>'; // Init slider wth inline JS
- }
- $output .= '</div>';
- return $output;
- }
- /*-----------------------------------------------------------------------------------*/
- /* WordPress 3.0 New Features Support */
- /*-----------------------------------------------------------------------------------*/
- if ( function_exists('wp_nav_menu') ) {
- add_theme_support( 'nav-menus' );
- register_nav_menus( array( 'primary-menu' => __( 'Primary Menu' ) ) );
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement