예제 #1
0
파일: functions.php 프로젝트: vrxm/htdocs
/**
 * 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)
{
    // 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');
        }
    }
    // set the post ID
    if (!$post_id) {
        if (isset($fa_slider)) {
            $post = get_current_slide();
        } else {
            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);
    }
    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'];
        } else {
            // try to autodetect the image URL in post content if option is enabled
            $plugin_options = fa_get_options('settings');
            if (isset($plugin_options['allow_image_autodetect']) && $plugin_options['allow_image_autodetect']) {
                $current_post = get_post($post_id);
                if ($current_post) {
                    $image = fa_detect_image($current_post->post_content);
                    if (!$image['id'] && $image['img']) {
                        $image_url = $image['img'];
                        fa_update_slide_options($post_id, array('temp_image_url' => $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);
}
예제 #2
0
 /**
  * Scans a given post content for images.
  * 
  * @param string $content - the post content to be scanned
  * @return array
  */
 private function find_image_in_post_content($content)
 {
     return fa_detect_image($content);
 }