/** * Returns a custom image size for the image attached to a given slide post. * @param object $post - a given slide post * @param array $size - image width ( as: array('width' => W, 'height' => H) ) or string ( ie: thumbnail ) * @return string - the image URL */ function fa_get_custom_image($post, $size = array('width' => 0, 'height' => 0)) { if (!$post) { return; } // slide can be attachment image, in this case the image ID is the actual post ID if ('attachment' == $post->post_type) { $image_id = $post->ID; } else { $image_id = get_the_fa_image_id($post->ID); if (!$image_id) { global $fa_slider; if ($fa_slider) { $slider_options = fa_get_slider_options($fa_slider->ID, 'content_image'); } if (!$image_id) { return false; } } } if (is_string($size)) { $imgsz = get_intermediate_image_sizes(); if (in_array($size, $imgsz)) { $width = get_option($size . '_size_w'); $height = get_option($size . '_size_h'); } } elseif (is_array($size)) { extract($size, EXTR_SKIP); } else { return; } $image_url = fa_get_custom_image_size($image_id, $width, $height); return $image_url; }
/** * Returns the image URL for a given slide ID ( $post_id ) that belongs to * a given slider id( $slider_id ). Will do all size checking and will return * an array with the image details or false if image isn't found. * * @param int $post_id - ID of slide * @param int $slider_id - ID of slider * @return array( 'url' => URL of image, 'width' => image width, 'height' => image height, 'id' => image ID if found in media gallery ) */ function get_the_fa_slide_image_url($post_id = false, $slider_id = false) { // set the post ID if (!$post_id) { global $post; if ($post) { $post_id = $post->ID; } else { _doing_it_wrong('get_the_fa_image_url()', __('Use this function inside a slide loop or pass the slide (post) ID to the function.', 'fapro'), '3.0'); } } else { $post = get_post($post_id); } // get the slider ID if (!$slider_id) { global $fa_slider; if ($fa_slider) { $slider_id = $fa_slider->ID; } else { _doing_it_wrong('get_the_fa_image_url()', __('Use this function inside a slide loop or pass the slider ID to the function.', 'fapro'), '3.0'); } } if (!$post || !$post_id || !$slider_id) { return false; } // get slider options and check if image is visible $slider_options = fa_get_slider_options($slider_id, 'content_image'); if (!$slider_options['show']) { return; } // slide options $options = fa_get_slide_options($post_id); // get the attached image ID $image_id = get_the_fa_image_id($post_id); // try to make the image url $image_url = false; if ('wp' == $slider_options['sizing'] && $image_id) { $wp_attachment = wp_get_attachment_image_src($image_id, $slider_options['wp_size']); if ($wp_attachment) { $image_url = $wp_attachment[0]; } } else { if ('custom' == $slider_options['sizing'] && $image_id) { $image_url = fa_get_custom_image_size($image_id, $slider_options['width'], $slider_options['height']); } } // last options, check on slide settings if an image URL is set if (!$image_url) { if (isset($options['temp_image_url']) && !empty($options['temp_image_url'])) { $image_url = $options['temp_image_url']; } } // if no image URL was detected, stop if (!$image_url) { return false; } $width = $height = false; // get the image size if ('custom' == $slider_options['sizing']) { $width = absint($slider_options['width']); $height = absint($slider_options['height']); } elseif ('wp' == $slider_options['sizing']) { if (isset($wp_attachment) && $wp_attachment) { $width = $wp_attachment[1]; $height = $wp_attachment[2]; } } // create the response return array('url' => $image_url, 'width' => $width, 'height' => $height, 'id' => $image_id); }
/** * Displays the HTML used in admin area to display the manually * selected mixed posts. * * @param int/obj $post */ function fa_slide_panel($post, $slider_id) { if (is_numeric($post)) { $post = get_post($post); } if (!$post) { return; } $options = fa_get_slide_options($post->ID); $slide_title = $post->post_title; $slide_content = $post->post_content; if (!empty($options['title']) && $post->post_title != $options['title']) { $slide_title = $options['title']; $post_title = $post->post_title; } if (!empty($options['content'])) { $slide_content = $options['content']; } ?> <div class="fa-slide <?php echo esc_attr($post->post_status); ?> " id="post-<?php echo $post->ID; ?> " data-post_id="<?php echo $post->ID; ?> "> <a href="<?php fa_iframe_admin_page_url('fa-post-slide-edit', array('post_id' => $post->ID, 'slider_id' => $slider_id)); ?> " id="fa-slide-edit-<?php echo $post->ID; ?> " class="fapro-modal-trigger fa-slide-edit" data-target="fapro-modal" data-slide_id="<?php echo $post->ID; ?> " data-slider_id="<?php echo $slider_id; ?> " data-type="mixed"><i class="dashicons dashicons-admin-generic"></i></a> <a href="#" id="fa-slide-remove-<?php echo $post->ID; ?> " class="fa-slide-remove"><i class="dashicons dashicons-dismiss"></i></a> <div class="slide-inside"> <h3> <a href="<?php echo get_edit_post_link($post->ID, ''); ?> " target="_blank"><?php echo wp_trim_words($slide_title, 6, '...'); ?> </a> </h3> <div class="slide-details"> <ul> <?php if (isset($post_title)) { ?> <li><strong><?php _e('Post title', 'fapro'); ?> :</strong> <?php echo wp_trim_words($post_title, 3, '...'); ?> </li> <?php } ?> <li><strong><?php _e('Post status', 'fapro'); ?> :</strong> <?php fa_output_post_status($post->post_status); ?> </li> <li><strong><?php _e('Post date', 'fapro'); ?> :</strong> <?php fa_output_post_date($post->post_date); ?> </li> <li><strong><?php _e('Post type', 'fapro'); ?> :</strong> <?php fa_output_post_type($post->post_type); ?> </li> <li> <strong><?php _e('Image', 'fapro'); ?> :</strong> <?php require_once fa_get_path('includes/templating.php'); $image_id = get_the_fa_image_id($post->ID); if (!$image_id) { if (!empty($options['temp_image_url'])) { $image_url = $options['temp_image_url']; } } else { $image = wp_get_attachment_image_src($image_id, 'thumbnail'); if ($image) { $image_url = $image[0]; } } if (isset($image_url) && $image_url) { ?> <img src="<?php echo $image_url; ?> " /> <?php } else { ?> <?php _e('none', 'fapro'); ?> <?php } ?> </li> <?php fa_post_status_message($post, '<li class="warning">', '</li>'); ?> </ul> <input type="hidden" name="slides[posts][]" value="<?php echo $post->ID; ?> " /> </div> </div> </div> <?php }