Пример #1
0
function get_wp_thumbnails_for_post($media = "", $video_thumb = "", $number = 6, $thumbsize = 75, $height = 75, $target = "_blank", $sort_images_randomly = true, $category_filter_way = "none", $category_filter = "", $articles = "random", $show_title = "true", $nofollow = "false", $link_target = "post", $pic_interval = 10, $title_pos = "bottom", $wrap = "false", $show_excerpt_limit = "", $titlewidth = 75, $id_list = "")
{
    global $thumbDir, $downloadDir, $siteurl, $rooturl, $destpath, $downloadpath;
    //申明全局变量
    $wp_thumbnails_options = get_option('thumbnails_anywhere_options');
    $rand_pic_from = $wp_thumbnails_options['rand_pic_from'];
    //表示每篇日志选第一张图片还是任选一张图片
    $releated_fill = $wp_thumbnails_options['releated_fill'];
    //是否用随机日志补足相关日志
    $disable_external = $wp_thumbnails_options['disable_external'];
    if ($media == "") {
        $media = $wp_thumbnails_options['media_post'];
    }
    if ($video_thumb == "") {
        $video_thumb = $wp_thumbnails_options['video_thumb'];
    }
    $video_link_target = $wp_thumbnails_options['video_link_target'];
    if ($titlewidth == "") {
        $titlewidth = $thumbsize;
    }
    // 访问数据库
    global $wpdb, $post;
    $now = current_time('mysql', 1);
    $custom_field_by_sql = "AND {$wpdb->postmeta}.meta_value NOT LIKE '%NoMediaFound%'\n\t\t\t\t\t\t\t\t\t AND {$wpdb->postmeta}.meta_value NOT LIKE '%NoPicturesFound%'\n\t\t\t\t\t\t\t\t\t ";
    // 显示缩略图
    if ($media == "image") {
        $media_by_sql = "AND {$wpdb->postmeta}.meta_value NOT LIKE 'ta_video%'";
        //排除以ta_video开头的
    } else {
        if ($media == "video") {
            $media_by_sql = "AND {$wpdb->postmeta}.meta_value LIKE '%ta_video%'";
            //包含视频的
        }
    }
    if ($articles == "single") {
        //单篇日志
        if ($post->post_status == 'publish' && $post->post_date_gmt < $now) {
            $sql = "SELECT distinct post_id, meta_value \n\t\t\tFROM {$wpdb->postmeta}\n\t\t\tWHERE meta_key IN ('ta-thumbnail')\n\t\t\tAND post_id = {$post->ID} \n\t\t\t{$custom_field_by_sql}\n\t\t\t{$media_by_sql}\n\t\t\t";
        } else {
            return "";
        }
        $rand_pic_from = "all";
    } else {
        //过滤标签
        $tags_filter = $wp_thumbnails_options['tags_filter'];
        if ($articles != "tag") {
            if (strstr($tags_filter, ',')) {
                $tags_array = explode(',', $tags_filter);
                //转化为数组
                $tags_num = count($tags_array);
                $tags_count = 0;
                $tags_filter = "";
                for ($tags_count = 0; $tags_count < $tags_num; $tags_count++) {
                    $tag_name = $tags_array[$tags_count];
                    $tags_id = $wpdb->get_var("SELECT term_id FROM {$wpdb->terms} WHERE name = '{$tag_name}'");
                    if ($tags_id == 0 || $tags_id === FALSE) {
                        continue;
                    }
                    $tags_filter = $tags_id . "," . $tags_filter;
                }
                if (substr($tags_filter, -1) == ",") {
                    $tags_filter = substr($tags_filter, 0, -1);
                }
                //去掉结尾的','
            } else {
                if ($tags_filter != "") {
                    $tags_filter = $wpdb->get_var("SELECT term_id FROM {$wpdb->terms} WHERE name = '{$tags_filter}'");
                }
            }
            if ($tags_filter == "") {
                $tags_filter = -1;
            }
        }
        //随机日志缩略图还是最新日志缩略图
        if ($sort_images_randomly) {
            $order_by_sql = "rand()";
        } else {
            $order_by_sql = "{$wpdb->postmeta}.post_id DESC";
        }
        //是否显示页面缩略图
        $show_page = $wp_thumbnails_options['show_page'];
        if ($show_page == "false") {
            $page_by_sql = "AND {$wpdb->posts}.post_type = 'post'";
        } else {
            $page_by_sql = "";
        }
        $related_num = 0;
        if ($articles == "tag") {
            //标签缩略图,注意sql中使用id_list
            $sql = "SELECT distinct {$wpdb->postmeta}.post_id, {$wpdb->postmeta}.meta_value\n\t\t\t\t\tFROM {$wpdb->postmeta},{$wpdb->term_relationships} r,{$wpdb->term_taxonomy} t,{$wpdb->posts} p\n\t\t\t\t\tWHERE t.taxonomy ='post_tag'\n\t\t\t\t\tAND {$wpdb->postmeta}.meta_key IN ('ta-thumbnail')\n\t\t\t\t\tAND {$wpdb->postmeta}.post_id = r.object_id \n\t\t\t\t\tAND r.term_taxonomy_id = t.term_taxonomy_id\n\t\t\t\t\tAND {$wpdb->postmeta}.post_id = p.ID\n\t\t\t\t\tAND (t.term_id IN ({$id_list})) \n\t\t\t\t\tAND p.post_status = 'publish' \n\t\t\t\t\tAND p.post_date_gmt < '{$now}' \n\t\t\t\t\t{$custom_field_by_sql}\n\t\t\t\t\t{$media_by_sql}\n\t\t\t\t\tORDER BY {$order_by_sql}\n\t\t\t\t\tLIMIT {$number}\n\t\t\t\t\t";
        } else {
            if ($articles == "related") {
                //相关日志缩略图,从tag寻找相关日志
                global $post;
                $tags = wp_get_post_tags($post->ID);
                //print_r($tags);
                $taglist = "'" . $tags[0]->term_id . "'";
                $tagcount = count($tags);
                if ($tagcount > 1) {
                    for ($i = 1; $i <= $tagcount; $i++) {
                        $taglist = $taglist . ", '" . $tags[$i]->term_id . "'";
                    }
                }
                $sql = "SELECT distinct {$wpdb->postmeta}.post_id, {$wpdb->postmeta}.meta_value\n\t\t\t\t\tFROM {$wpdb->postmeta},{$wpdb->term_relationships} r,{$wpdb->term_taxonomy} t,{$wpdb->posts} p\n\t\t\t\t\tWHERE t.taxonomy ='post_tag'\n\t\t\t\t\tAND {$wpdb->postmeta}.meta_key IN ('ta-thumbnail')\n\t\t\t\t\tAND {$wpdb->postmeta}.post_id = r.object_id \n\t\t\t\t\tAND r.term_taxonomy_id = t.term_taxonomy_id\n\t\t\t\t\tAND {$wpdb->postmeta}.post_id = p.ID\n\t\t\t\t\tAND (t.term_id IN ({$taglist})) \n\t\t\t\t\tAND p.ID != {$post->ID} \n\t\t\t\t\tAND p.post_status = 'publish' \n\t\t\t\t\tAND p.post_date_gmt < '{$now}' \n\t\t\t\t\t{$custom_field_by_sql}\n\t\t\t\t\t{$media_by_sql}\n\t\t\t\t\tORDER BY {$order_by_sql}\n\t\t\t\t\tLIMIT {$number}\n\t\t\t\t\t";
                $related_resultset = @mysql_query($sql, $wpdb->dbh);
                $related_num = @mysql_num_rows($related_resultset);
                if ($related_num < $number && $releated_fill == "true") {
                    // 补全随机缩略图
                    //排除相关日志,以免重复
                    $image_count = 0;
                    $postlist = "'" . $post->ID . "'";
                    while ($image_count++ < $related_num) {
                        $row = mysql_fetch_array($related_resultset);
                        $post_id = $row['post_id'];
                        $views = $row['views'];
                        $postlist = $postlist . ", '" . $post_id . "'";
                    }
                    $extra_num = $number - $related_num;
                    $limit_num = $extra_num + $extra_num;
                    $sql_related = "SELECT distinct {$wpdb->postmeta}.post_id, {$wpdb->postmeta}.meta_value\n\t\t\t\t\t\tFROM {$wpdb->postmeta}, {$wpdb->posts}\n\t\t\t\t\t\tWHERE meta_key IN ('ta-thumbnail')\n\t\t\t\t\t\tAND {$wpdb->postmeta}.post_id = {$wpdb->posts}.ID\n\t\t\t\t\t\tAND {$wpdb->posts}.post_status = 'publish' \n\t\t\t\t\t\tAND {$wpdb->posts}.post_date_gmt < '{$now}' \n\t\t\t\t\t\t{$custom_field_by_sql}\n\t\t\t\t\t\t{$media_by_sql}\n\t\t\t\t\t\t{$page_by_sql}\n\t\t\t\t\t\tAND {$wpdb->postmeta}.post_id NOT IN (SELECT p.ID\n\t\t\t\t\t\t\t\tFROM {$wpdb->term_relationships} r,{$wpdb->term_taxonomy} t,{$wpdb->posts} p\n\t\t\t\t\t\t\t\tWHERE t.taxonomy ='post_tag'\n\t\t\t\t\t\t\t\tAND p.ID = r.object_id \n\t\t\t\t\t\t\t\tAND r.term_taxonomy_id = t.term_taxonomy_id\n\t\t\t\t\t\t\t\tAND p.ID IN ({$postlist})\n\t\t\t\t\t\t)\n\t\t\t\t\t\tORDER BY {$order_by_sql}\n\t\t\t\t\t\tLIMIT {$limit_num}";
                    if ($related_num == 0) {
                        //无相关缩略图时
                        $sql = $sql_related;
                        $related_num = $number;
                        $extra_num = 0;
                        $releated_fill = "false";
                    }
                }
            } else {
                if ($category_filter != "" && $category_filter_way != "none") {
                    if ($articles == "popular") {
                        //最热日志,需要提取views
                        $sql = "SELECT distinct {$wpdb->postmeta}.post_id, {$wpdb->postmeta}.meta_value\n\t\t\t\t\t\t\t\tFROM {$wpdb->postmeta},{$wpdb->term_relationships},{$wpdb->term_taxonomy},{$wpdb->posts}\n\t\t\t\t\t\t\t\tWHERE {$wpdb->postmeta}.meta_key IN ('views')\n\t\t\t\t\t\t\t\tAND {$wpdb->postmeta}.post_id = {$wpdb->term_relationships}.object_id \n\t\t\t\t\t\t\t\tAND {$wpdb->term_relationships}.term_taxonomy_id = {$wpdb->term_taxonomy}.term_taxonomy_id\n\t\t\t\t\t\t\t\tAND {$wpdb->term_taxonomy}.term_id IN ({$category_filter})\n\t\t\t\t\t\t\t\tAND {$wpdb->postmeta}.post_id = {$wpdb->posts}.ID\n\t\t\t\t\t\t\t\tAND {$wpdb->posts}.post_status = 'publish' \n\t\t\t\t\t\t\t\tAND {$wpdb->posts}.post_date_gmt < '{$now}' \n\t\t\t\t\t\t\t\t{$page_by_sql}\n\t\t\t\t\t\t\t\t{$media_by_sql}\n\t\t\t\t\t\t\t\tAND {$wpdb->postmeta}.post_id NOT IN (SELECT p.ID\n\t\t\t\t\t\t\t\t\tFROM {$wpdb->term_relationships} r,{$wpdb->term_taxonomy} t,{$wpdb->posts} p\n\t\t\t\t\t\t\t\t\tWHERE t.taxonomy ='post_tag'\n\t\t\t\t\t\t\t\t\tAND p.ID = r.object_id \n\t\t\t\t\t\t\t\t\tAND r.term_taxonomy_id = t.term_taxonomy_id\n\t\t\t\t\t\t\t\t\tAND t.term_id IN ({$tags_filter})\n\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\tAND {$wpdb->postmeta}.post_id IN (SELECT q.post_id\n\t\t\t\t\t\t\t\t\tFROM {$wpdb->postmeta} q\n\t\t\t\t\t\t\t\t\tWHERE q.meta_key IN ('ta-thumbnail')\n\t\t\t\t\t\t\t\t\tAND (q.meta_value LIKE '%http%')\n\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\tORDER BY {$wpdb->postmeta}.meta_value DESC\n\t\t\t\t\t\t\t\tLIMIT {$number}";
                    } else {
                        $sql = "SELECT distinct {$wpdb->postmeta}.post_id, {$wpdb->postmeta}.meta_value\n\t\t\t\t\t\t\t\tFROM {$wpdb->postmeta},{$wpdb->term_relationships},{$wpdb->term_taxonomy},{$wpdb->posts}\n\t\t\t\t\t\t\t\tWHERE {$wpdb->postmeta}.meta_key IN ('ta-thumbnail')\n\t\t\t\t\t\t\t\tAND {$wpdb->postmeta}.post_id = {$wpdb->term_relationships}.object_id \n\t\t\t\t\t\t\t\tAND {$wpdb->term_relationships}.term_taxonomy_id = {$wpdb->term_taxonomy}.term_taxonomy_id\n\t\t\t\t\t\t\t\tAND {$wpdb->term_taxonomy}.term_id IN ({$category_filter})\n\t\t\t\t\t\t\t\tAND {$wpdb->postmeta}.post_id = {$wpdb->posts}.ID\n\t\t\t\t\t\t\t\tAND {$wpdb->posts}.post_status = 'publish' \n\t\t\t\t\t\t\t\tAND {$wpdb->posts}.post_date_gmt < '{$now}' \n\t\t\t\t\t\t\t\t{$custom_field_by_sql}\n\t\t\t\t\t\t\t\t{$media_by_sql}\n\t\t\t\t\t\t\t\t{$page_by_sql}\n\t\t\t\t\t\t\t\tAND {$wpdb->postmeta}.post_id NOT IN (SELECT p.ID\n\t\t\t\t\t\t\t\t\tFROM {$wpdb->term_relationships} r,{$wpdb->term_taxonomy} t,{$wpdb->posts} p\n\t\t\t\t\t\t\t\t\tWHERE t.taxonomy ='post_tag'\n\t\t\t\t\t\t\t\t\tAND p.ID = r.object_id \n\t\t\t\t\t\t\t\t\tAND r.term_taxonomy_id = t.term_taxonomy_id\n\t\t\t\t\t\t\t\t\tAND t.term_id IN ({$tags_filter})\n\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\tORDER BY {$order_by_sql}\n\t\t\t\t\t\t\t\tLIMIT {$number}";
                    }
                } else {
                    if ($articles == "popular") {
                        //最热日志,需要提取views
                        $sql = "SELECT distinct post_id, (meta_value+0) AS views\n\t\t\t\t\t\t\tFROM {$wpdb->postmeta}, {$wpdb->posts}\n\t\t\t\t\t\t\tWHERE meta_key IN ('views')\n\t\t\t\t\t\t\tAND post_id = ID\n\t\t\t\t\t\t\tAND post_status = 'publish' \n\t\t\t\t\t\t\tAND post_date_gmt < '{$now}' \n\t\t\t\t\t\t\t{$custom_field_by_sql}\n\t\t\t\t\t\t\t{$media_by_sql}\n\t\t\t\t\t\t\t{$page_by_sql}\n\t\t\t\t\t\t\tAND post_id NOT IN (SELECT p.ID\n\t\t\t\t\t\t\t\tFROM {$wpdb->term_relationships} r,{$wpdb->term_taxonomy} t,{$wpdb->posts} p\n\t\t\t\t\t\t\t\tWHERE t.taxonomy ='post_tag'\n\t\t\t\t\t\t\t\tAND p.ID = r.object_id \n\t\t\t\t\t\t\t\tAND r.term_taxonomy_id = t.term_taxonomy_id\n\t\t\t\t\t\t\t\tAND t.term_id IN ({$tags_filter})\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\tAND post_id IN (SELECT q.post_id\n\t\t\t\t\t\t\t\t\tFROM {$wpdb->postmeta} q\n\t\t\t\t\t\t\t\t\tWHERE q.meta_key IN ('ta-thumbnail')\n\t\t\t\t\t\t\t\t\tAND (q.meta_value LIKE '%http%')\n\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\tORDER BY views DESC\n\t\t\t\t\t\t\tLIMIT {$number}";
                    } else {
                        $sql = "SELECT distinct {$wpdb->postmeta}.post_id, {$wpdb->postmeta}.meta_value, (meta_value+0) AS views\n\t\t\t\t\t\t\tFROM {$wpdb->postmeta}, {$wpdb->posts}\n\t\t\t\t\t\t\tWHERE meta_key IN ('views')\n\t\t\t\t\t\t\tAND {$wpdb->postmeta}.post_id = {$wpdb->posts}.ID\n\t\t\t\t\t\t\tAND {$wpdb->posts}.post_status = 'publish' \n\t\t\t\t\t\t\tAND {$wpdb->posts}.post_date_gmt < '{$now}' \n\t\t\t\t\t\t\t{$custom_field_by_sql}\n\t\t\t\t\t\t\t{$media_by_sql}\n\t\t\t\t\t\t\t{$page_by_sql}\n\t\t\t\t\t\t\tAND {$wpdb->postmeta}.post_id NOT IN (SELECT p.ID\n\t\t\t\t\t\t\t\t\tFROM {$wpdb->term_relationships} r,{$wpdb->term_taxonomy} t,{$wpdb->posts} p\n\t\t\t\t\t\t\t\t\tWHERE t.taxonomy ='post_tag'\n\t\t\t\t\t\t\t\t\tAND p.ID = r.object_id \n\t\t\t\t\t\t\t\t\tAND r.term_taxonomy_id = t.term_taxonomy_id\n\t\t\t\t\t\t\t\t\tAND t.term_id IN ({$tags_filter})\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\tORDER BY {$order_by_sql}\n\t\t\t\t\t\t\tLIMIT {$number}";
                    }
                }
            }
        }
    }
    $resultset = @mysql_query($sql, $wpdb->dbh);
    $image_number = min($number, @mysql_num_rows($resultset));
    if ($articles == "single") {
        $image_number = min($image_number, 1);
    }
    //single只需要一个记录
    $image_count = 0;
    $output = '';
    while ($image_count++ < $image_number) {
        $row = mysql_fetch_array($resultset);
        $post_id = $row['post_id'];
        //获取年、月
        $the_post_date = $wpdb->get_row("SELECT DISTINCT MONTH(post_date) AS month, YEAR(post_date) AS year \n\t\t\tFROM {$wpdb->posts} \n\t\t\tWHERE ID = {$post_id}\n\t\t\tAND post_status = 'publish' \n\t\t\tAND post_date_gmt < '{$now}' \n\t\t\tLIMIT 1");
        $year = $the_post_date->year;
        $month = $the_post_date->month;
        $views = "";
        if ($articles == "popular" || $articles == "random") {
            $views = $row['views'];
            $thumbnail = get_post_meta($post_id, "ta-thumbnail", true);
        } else {
            $thumbnail = $row['meta_value'];
        }
        //$thumbnail = str_replace("@3@","",$thumbnail);
        $post_title = get_the_title($post_id);
        $post_permalink = get_permalink($post_id);
        $array = explode(";", $thumbnail);
        $iNumberOfPics = count($array) - 1;
        // 图片数量
        if ($articles == "single") {
            $seq = 0;
            $iNumberOfPics = min($iNumberOfPics, $number);
            // 图片数量
        } else {
            if ($rand_pic_from == "first") {
                //选取第一张图片
                $seq = 0;
            } else {
                //随机选取图片
                $seq = mt_rand(0, $iNumberOfPics - 1);
                //[0, iNumberOfPics-1]
            }
        }
        while ($seq < $iNumberOfPics) {
            $thumbnail = $array[$seq];
            // 符合picasa图片条件
            if (strstr($thumbnail, 'thumbnails_anywhere_picasa')) {
                if ($thumbsize <= 32) {
                    $realsize = 32;
                } else {
                    if ($thumbsize <= 48) {
                        $realsize = 48;
                    } else {
                        if ($thumbsize <= 64) {
                            $realsize = 64;
                        } else {
                            if ($thumbsize <= 72) {
                                $realsize = 72;
                            } else {
                                if ($thumbsize <= 144) {
                                    $realsize = 144;
                                } else {
                                    if ($thumbsize <= 160) {
                                        $realsize = 160;
                                    } else {
                                        $realsize = 160;
                                    }
                                }
                            }
                        }
                    }
                }
                $bigimage = str_replace("thumbnails_anywhere_picasa", '?imgmax=800', $thumbnail);
                $thumbnail = str_replace("thumbnails_anywhere_picasa", '?imgmax=' . $realsize . '&crop=1', $thumbnail);
            } else {
                if (strstr($thumbnail, 'picasa_thumbnails_anywhere')) {
                    if ($thumbsize <= 32) {
                        $realsize = 32;
                    } else {
                        if ($thumbsize <= 48) {
                            $realsize = 48;
                        } else {
                            if ($thumbsize <= 64) {
                                $realsize = 64;
                            } else {
                                if ($thumbsize <= 72) {
                                    $realsize = 72;
                                } else {
                                    if ($thumbsize <= 144) {
                                        $realsize = 144;
                                    } else {
                                        if ($thumbsize <= 160) {
                                            $realsize = 160;
                                        } else {
                                            $realsize = 160;
                                        }
                                    }
                                }
                            }
                        }
                    }
                    $bigimage = str_replace("picasa_thumbnails_anywhere", 's800', $thumbnail);
                    $thumbnail = str_replace("picasa_thumbnails_anywhere", 's' . $realsize . '-c', $thumbnail);
                } else {
                    if (strstr($thumbnail, 'yupoo_thumbnails_anywhere')) {
                        if ($thumbsize <= 75) {
                            $type = "square";
                        } else {
                            if ($thumbsize <= 100) {
                                $type = "thumb";
                            } else {
                                if ($thumbsize <= 240) {
                                    $type = "small";
                                } else {
                                    if ($thumbsize <= 500) {
                                        $type = "medium";
                                    } else {
                                        if ($thumbsize <= 1024) {
                                            $type = "big";
                                        } else {
                                            $type = "big";
                                        }
                                    }
                                }
                            }
                        }
                        // 原图无法获取
                        $bigimage = str_replace("yupoo_thumbnails_anywhere", 'big', $thumbnail);
                        $thumbnail = str_replace("yupoo_thumbnails_anywhere", $type, $thumbnail);
                    } else {
                        if (strstr($thumbnail, 'flickr_thumbnails_anywhere')) {
                            if ($thumbsize <= 75) {
                                $type = "_s";
                            } else {
                                if ($thumbsize <= 100) {
                                    $type = "_t";
                                } else {
                                    if ($thumbsize <= 240) {
                                        $type = "_m";
                                    } else {
                                        $type = "";
                                    }
                                }
                            }
                            $bigimage = str_replace("flickr_thumbnails_anywhere", '_m', $thumbnail);
                            $thumbnail = str_replace("flickr_thumbnails_anywhere", $type, $thumbnail);
                        } else {
                            if (!strstr($thumbnail, 'ta_video_')) {
                                //普通图片(非视频)
                                $bigimage = $thumbnail;
                                if (!strstr($thumbnail, $siteurl) and $disable_external != "false") {
                                    // 外链图片且不制作缩略图
                                    //什么也不做
                                } else {
                                    $thumbnailbackup = $thumbnail;
                                    $filename = $post_id . "-" . ($seq + 1);
                                    $thumbnail = ta_is_thumb_exist($filename, $thumbsize, $height, true, $year, $month);
                                    if ($thumbnail == false) {
                                        //如果图片不存在
                                        $thumbnail = $thumbnailbackup;
                                        $thumbnail = str_replace($siteurl, $rooturl, $thumbnail);
                                        //转换为绝对路径
                                        //将图片按照规格存放在不同子目录
                                        $subfolder = "{$thumbsize}x{$height}-c/";
                                        $subfolder = $destpath . $subfolder;
                                        if (!file_exists($subfolder)) {
                                            if (!@mkdir($subfolder, 0755)) {
                                                if (is_admin()) {
                                                    echo "提示:很抱歉,无法创建缩略图子目录,请手动创建目录" . $subfolder . ",权限设置为755。<br>";
                                                    return;
                                                }
                                            }
                                        }
                                        $subfolder .= "{$year}/";
                                        if (!file_exists($subfolder)) {
                                            if (!@mkdir($subfolder, 0755)) {
                                                if (is_admin()) {
                                                    echo "提示:很抱歉,无法创建缩略图子目录,请手动创建目录" . $subfolder . ",权限设置为755。<br>";
                                                    return;
                                                }
                                            }
                                        }
                                        $subfolder .= "{$month}/";
                                        if (!file_exists($subfolder)) {
                                            if (!@mkdir($subfolder, 0755)) {
                                                if (is_admin()) {
                                                    echo "提示:很抱歉,无法创建缩略图子目录,请手动创建目录" . $subfolder . ",权限设置为755。<br>";
                                                    return;
                                                }
                                            }
                                        }
                                        $thumbnail = ta_image_resize($thumbnail, $thumbsize, $height, true, null, $subfolder, 90, $filename);
                                        //制作缩略图
                                        $thumbnail = ta_is_thumb_exist($filename, $thumbsize, $height, true, $year, $month);
                                        if ($thumbnail == false) {
                                            $thumbnail = $thumbnailbackup;
                                        }
                                        //如果缩略图尺寸过大,只好显示原图
                                    }
                                }
                            } else {
                                if ($media != "image") {
                                    $result = wp_thumbnails_getvideo($thumbnail);
                                    if ($video_link_target == "video") {
                                        //点击打开视频
                                        $bigimage = $result['video'];
                                    } else {
                                        $bigimage = $result['imageurl'];
                                    }
                                    if ($video_thumb == "video") {
                                        //直接显示视频
                                        $video = $result['video'];
                                        $videowidth = $thumbsize;
                                        $videoheight = $height;
                                        //padding=4,因为图片padding3+border1
                                        $thumbnail_video = "<embed src=\"{$video}\" style=\"padding:4px;\"quality=\"high\" width=\"{$videowidth}\" height=\"{$videoheight}\" align=\"middle\" allowScriptAccess=\"sameDomain\" type=\"application/x-shockwave-flash\"></embed>";
                                        $thumbnail = "";
                                    } else {
                                        $thumbnail = $result['imageurl'];
                                    }
                                } else {
                                    $seq = $iNumberOfPics;
                                    //break
                                    continue;
                                }
                            }
                        }
                    }
                }
            }
            if ($articles == "single") {
                //全排列缩略图
                $single_position = $wp_thumbnails_options['single_position'];
                $single_row_limit = $wp_thumbnails_options['single_row_limit'];
                if ($seq > 0 && $seq % $single_row_limit == 0 && $single_position != "none") {
                    $output = $output . "\n\t\t\t\t\t<div class=\"clear-float\"> </div>\n\t\t\t\t\t";
                }
                $seq++;
            } else {
                $seq = $iNumberOfPics;
                //break
            }
            //------------- 输出 -----------------//
            /** 摘要 **/
            $outexcerpt = "";
            if ($show_excerpt_limit != "") {
                $queried_post = get_post($post_id);
                $post_content = $queried_post->post_content;
                $outexcerpt = wp_thumbnails_excerpt($post_content, false, $show_excerpt_limit, true, "");
            }
            /** 标题 **/
            if ($show_title == "false") {
                $out_title = "";
            } else {
                if ($title_pos == "bottom") {
                    $out_title = '<br />' . $post_title;
                } else {
                    if ($title_pos == "top") {
                        $out_title = $post_title . '<br />';
                    } else {
                        $out_title = $post_title;
                        $pic_interval = 0;
                    }
                }
            }
            //$out_title = $post_title;
            if ($nofollow == "true") {
                $outnofollow = "rel=\"nofollow\"";
            } else {
                $outnofollow = "";
            }
            if ($link_target == "post") {
                $outlink_target = "href=\"{$post_permalink}\"";
            } else {
                $outlink_target = "href='{$bigimage}'";
            }
            if ($title_pos == "bottom" || $title_pos == "top") {
                $pwidth = $thumbsize + $pic_interval;
            }
            //图片宽度间距
            $pwidth = "width:" . $pwidth . "px;";
            $twidth = "width:" . $titlewidth . "px;";
            $show_views = $wp_thumbnails_options['show_views'];
            //$show_views = 'true';
            if ($show_title != "false") {
                $out_title = "<a {$outlink_target} {$outnofollow} title=\"{$post_title}\" target=\"{$target}\">{$out_title}</a>";
            } else {
                //不显示标题时,规定高度间距
                $outexcerpt = "";
                $pheight = $height + $pic_interval;
                //图片高度间距
                if ($articles == "popular" && $out_title != "" && $show_views == "true") {
                    $pheight = $pheight + 14;
                    //保证字体高度
                }
                if ($title_pos == "bottom" || $title_pos == "top") {
                    $pwidth = $pwidth . "height:" . $pheight . "px;";
                }
            }
            $out_views = "";
            if (($articles == "popular" || $articles == "random") && $show_views == "true") {
                $views_text = $wp_thumbnails_options['views_text'];
                //$out_views = "<img style=\"display:none;\" class=\"img_fire\" src=\"".get_bloginfo('template_url')."/img/fire.png\" />".$views.$views_text;
                $out_views = $views . $views_text;
            }
            //$nowrap = " white-space:nowrap; overflow:hidden; text-overflow:ellipsis; ";
            $nowrap = " overflow:hidden; text-overflow:ellipsis; ";
            if ($articles == "single") {
                //全排列缩略图
                if ($single_position == "left" && $wrap == "true") {
                    $pwidth = $pwidth . "float:left; margin:0; padding:0;text-indent:0px;";
                    //列表内部float left
                } else {
                    if ($single_position == "right" && $wrap == "true") {
                        $pwidth = $pwidth . "float:right; margin:0; padding:0;text-indent:0px;";
                        //列表内部float right
                    } else {
                        $pwidth = $pwidth . "margin:0; padding:0;";
                        //不环绕
                    }
                }
            } else {
                if ($wrap == "false") {
                    //使用截断
                    //$pwidth = $pwidth.$nowrap;
                    $pheight = $height + $pic_interval + 67;
                    //图片高度间距
                    $pwidth = "height:" . $pheight . "px; " . $pwidth . $nowrap;
                    //echo $pwidth;
                }
            }
            if ($thumbnail) {
                $mouse_bottom = "onmouseover=\"this.style.backgroundColor='#E6E6E6'\" onmouseout=\"this.style.backgroundColor='#FFFFFF'\"";
                $thumbnail_bottom = "<img src=\"{$thumbnail}\" alt=\"{$post_title}\" width= \"{$thumbsize}\" height=\"{$height}\" />";
                $mouse = "onmouseover=\"this.style.backgroundColor='#A8B300'\" onmouseout=\"this.style.backgroundColor='#F0F0F0'\"";
                $thumbnail = "<img src=\"{$thumbnail}\" alt=\"{$post_title}\" width= \"{$thumbsize}\" height=\"{$height}\" {$mouse} />";
            } else {
                $thumbnail = $thumbnail_video;
            }
            if ($title_pos == "bottom") {
                $output = $output . "<p style=\"{$pwidth}\" {$mouse_bottom} >\n\t\t\t\t<a {$outlink_target} {$outnofollow} title=\"{$post_title}\" target=\"{$target}\">{$thumbnail_bottom}</a>\n\t\t\t\t{$out_title} {$out_views} \n\t\t\t\t</p>";
            } else {
                if ($title_pos == "top") {
                    $output = $output . "<p style=\"{$pwidth}\">\n\t\t\t\t{$out_title} {$out_views} \n\t\t\t\t<a {$outlink_target} {$outnofollow} title=\"{$post_title}\" target=\"{$target}\">{$thumbnail}</a>\n\t\t\t\t</p>";
                } else {
                    if ($title_pos == "right") {
                        $output = $output . "<div class=\"ta-entry-left-all\"> <div class=\"ta-entry-left\"> \n    \t<div class=\"img_holder\" style=\"{$pwidth}\"><a {$outlink_target} {$outnofollow} title=\"{$post_title}\" target=\"{$target}\"></a></div> \n        <div class=\"ta_info\" style=\"{$twidth}\"> \n            <table>\n\t\t\t\t<tr>\n\t\t\t\t\t<td><div class=\"ta_title\" style=\"{$twidth}\"><a {$outlink_target}><span>{$out_title}</span></a></div></td>\n\t\t\t\t</tr>\n\t\t\t\t<tr>\n\t\t\t\t\t<td align=\"right\"><span style=\"color:#4B4B4B;position:relative;right:-15px;\">{$out_views}</span></td>\n\t\t\t\t</tr>\n\t\t\t</table>\n            <div class=\"ta_text\" style=\"{$twidth}\">{$outexcerpt} </div> \n        </div> \n        <div class=\"clear-float\"></div> \n    </div></div><hr />\n    ";
                    } else {
                        if ($title_pos == "left") {
                            $output = $output . "<div> <div class=\"ta-entry-right\"> \n    \t<div class=\"img_holder\" style=\"{$pwidth}\"><a {$outlink_target} {$outnofollow} title=\"{$post_title}\" target=\"{$target}\">{$thumbnail}</a></div> \n        <div class=\"ta_info\" style=\"{$twidth}\"> \n            <div class=\"ta_title\" style=\"{$twidth}\">\n\t\t\t<table>\n\t\t\t\t<tr>\n\t\t\t\t\t<td><div class=\"ta_title\" style=\"{$twidth}\"><a {$outlink_target}><span>{$out_title}</span></a></div></td>\n\t\t\t\t</tr>\n\t\t\t\t<tr>\n\t\t\t\t\t<td align=\"right\"><span style=\"color:#B22222;position:relative;right:-15px;\">{$out_views}</span></td>\n\t\t\t\t</tr>\n\t\t\t</table> \n            <div class=\"ta_text\"  style=\"{$twidth}\">{$outexcerpt} </div> \n        </div> \n        <div class=\"clear-float\"></div> \n    </div></div>\n    ";
                        }
                    }
                }
            }
            if ($releated_fill == "true" && $articles == "related" && $image_count == $image_number && $related_num < $number) {
                $resultset = @mysql_query($sql_related, $wpdb->dbh);
                $image_number = min($extra_num, @mysql_num_rows($resultset));
                $image_count = 0;
                $articles = "none";
                //防止死循环
            }
        }
        //elihw
    }
    //elihw
    if ($articles == "single") {
        if ($single_position == "left" && $wrap == "true") {
            return "<div id=\"ta-single-list\" style=\"float:left; padding: 2px 8px 2px 2px; \">\n\t\t\t" . $output . "\n\t\t\t</div>\n\t\t\t";
        } else {
            if ($single_position == "right" && $wrap == "true") {
                return "<div id=\"ta-single-list\" style=\"float:right; padding: 2px 0px 2px 8px; \">\n\t\t\t" . $output . "\n\t\t\t</div>\n\t\t\t";
            } else {
                return "<div id=\"ta-post\" class=\"clearfix\" style=\"padding: 2px 0px 2px 8px; \">\n\t\t\t" . $output . "\n\t\t\t</div>\n\t\t\t";
            }
        }
    }
    if ($output) {
        if ($title_pos == "bottom" || $title_pos == "top") {
            $output = "<div id=\"ta-post\" class=\"clearfix\">\n\t\t\t" . $output . "\n\t\t\t</div>\n\t\t\t";
        }
    }
    return $output;
}
Пример #2
0
function get_wp_thumbnails_for_homepage($args = '')
{
    // 如果调用时没有指定参数,则采用后台设置的参数; 否则采用函数自身的默认参数。
    $wp_thumbnails_options = get_option('thumbnails_anywhere_options');
    //只允许传递参数:宽、高、位置、裁剪
    if (!empty($args)) {
        $args2 = array();
        $args2['width'] = $wp_thumbnails_options['width_of_home_images'];
        $args2['height'] = $wp_thumbnails_options['height_of_home_images'];
        $args2['position'] = $wp_thumbnails_options['homepage_position'];
        $args2['crop'] = $wp_thumbnails_options['crop_home_images'];
        $args = wp_parse_args($args, $args2);
        //合并参数,若args中无某参数,则以默认参数args2代替
        $post_preview_id = $args['id'];
        $wp_thumbnails_options['width_of_home_images'] = $args['width'];
        $wp_thumbnails_options['height_of_home_images'] = $args['height'];
        $wp_thumbnails_options['homepage_position'] = $args['position'];
        $wp_thumbnails_options['crop_home_images'] = $args['crop'];
    }
    $thumbsize = $wp_thumbnails_options['width_of_home_images'];
    $height = $wp_thumbnails_options['height_of_home_images'];
    $position = $wp_thumbnails_options['homepage_position'];
    $target = $wp_thumbnails_options['homepage_new_window'];
    $defaultimage = $wp_thumbnails_options['homepage_default_image'];
    $crop = $wp_thumbnails_options['crop_home_images'];
    $disable_external = $wp_thumbnails_options['disable_external'];
    $rand_pic_from = $wp_thumbnails_options['rand_pic_from'];
    //表示每篇日志选第一张图片还是任选一张图片
    $permalink = $wp_thumbnails_options['homepage_link_target'];
    $media = $wp_thumbnails_options['media_page'];
    $video_thumb = $wp_thumbnails_options['video_thumb'];
    $video_link_target = $wp_thumbnails_options['video_link_target'];
    if ($crop == "crop") {
        $crop = true;
    } else {
        $crop = false;
    }
    global $thumbDir, $downloadDir, $siteurl, $rooturl, $destpath, $downloadpath, $wpdb;
    //申明全局变量
    if ($post_preview_id) {
        //后台预览
        $post = get_post($post_preview_id);
        $post_id = $post_preview_id;
    } else {
        global $post;
        $post_id = $post->ID;
    }
    //获取年、月
    global $wpdb, $post;
    // 访问数据库
    $now = current_time('mysql', 1);
    $the_post_date = $wpdb->get_row("SELECT DISTINCT MONTH(post_date) AS month, YEAR(post_date) AS year \n\t\tFROM {$wpdb->posts} \n\t\tWHERE ID = {$post_id}\n\t\tAND post_status = 'publish' \n\t\tAND post_date_gmt < '{$now}' \n\t\tLIMIT 1");
    $year = $the_post_date->year;
    $month = $the_post_date->month;
    //---------- 从自定义域中获取图片地址
    $thumbnail = get_post_meta($post_id, "ta-thumbnail", true);
    if ($thumbnail == '' or strstr($thumbnail, 'NoPicturesFound')) {
        //这篇日志还没有扫描过
        update_wp_thumbnails_meta($post);
        // 自动填充自定义域
        $thumbnail = get_post_meta($post_id, "ta-thumbnail", true);
    }
    if ($thumbnail == '') {
        return;
    }
    if ($thumbnail == 'NoMediaFound') {
        //无图片
        if ($defaultimage == "") {
            return;
        }
        $thumbnail = $defaultimage;
    } else {
        $array = explode(";", $thumbnail);
        $iNumberOfPics = count($array) - 1;
        // 图片数量
        if ($rand_pic_from == "first") {
            //选取第一张图片
            $seq = 0;
        } else {
            //随机选取图片
            $seq = mt_rand(0, $iNumberOfPics - 1);
        }
        $thumbnail = $array[$seq];
    }
    $original = $thumbnail;
    //原始大图
    //---------- 对图片地址进一步解析,得到缩略图地址
    // 符合picasa图片条件
    if (strstr($thumbnail, 'thumbnails_anywhere_picasa')) {
        if ($crop == true) {
            if ($thumbsize <= 32) {
                $realsize = 32;
            } else {
                if ($thumbsize <= 48) {
                    $realsize = 48;
                } else {
                    if ($thumbsize <= 64) {
                        $realsize = 64;
                    } else {
                        if ($thumbsize <= 72) {
                            $realsize = 72;
                        } else {
                            if ($thumbsize <= 144) {
                                $realsize = 144;
                            } else {
                                if ($thumbsize <= 160) {
                                    $realsize = 160;
                                } else {
                                    $realsize = 160;
                                }
                            }
                        }
                    }
                }
            }
            $realsize = '?imgmax=' . $realsize . '&crop=1';
        } else {
            if ($thumbsize <= 32) {
                $realsize = 32;
            } else {
                if ($thumbsize <= 48) {
                    $realsize = 48;
                } else {
                    if ($thumbsize <= 64) {
                        $realsize = 64;
                    } else {
                        if ($thumbsize <= 72) {
                            $realsize = 72;
                        } else {
                            if ($thumbsize <= 144) {
                                $realsize = 144;
                            } else {
                                if ($thumbsize <= 160) {
                                    $realsize = 160;
                                } else {
                                    if ($thumbsize <= 200) {
                                        $realsize = 200;
                                    } else {
                                        if ($thumbsize <= 288) {
                                            $realsize = 288;
                                        } else {
                                            if ($thumbsize <= 320) {
                                                $realsize = 320;
                                            } else {
                                                if ($thumbsize <= 400) {
                                                    $realsize = 400;
                                                } else {
                                                    if ($thumbsize <= 512) {
                                                        $realsize = 512;
                                                    } else {
                                                        if ($thumbsize <= 576) {
                                                            $realsize = 576;
                                                        } else {
                                                            if ($thumbsize <= 640) {
                                                                $realsize = 640;
                                                            } else {
                                                                if ($thumbsize <= 720) {
                                                                    $realsize = 720;
                                                                } else {
                                                                    if ($thumbsize <= 800) {
                                                                        $realsize = 800;
                                                                    } else {
                                                                        if ($thumbsize <= 912) {
                                                                            $realsize = 912;
                                                                        } else {
                                                                            if ($thumbsize <= 1024) {
                                                                                $realsize = 1024;
                                                                            } else {
                                                                                if ($thumbsize <= 1152) {
                                                                                    $realsize = 1152;
                                                                                } else {
                                                                                    if ($thumbsize <= 1280) {
                                                                                        $realsize = 1280;
                                                                                    } else {
                                                                                        if ($thumbsize <= 1440) {
                                                                                            $realsize = 1440;
                                                                                        } else {
                                                                                            if ($thumbsize <= 1600) {
                                                                                                $realsize = 1600;
                                                                                            } else {
                                                                                                $realsize = 1600;
                                                                                            }
                                                                                        }
                                                                                    }
                                                                                }
                                                                            }
                                                                        }
                                                                    }
                                                                }
                                                            }
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            $realsize = '?imgmax=' . $realsize;
        }
        $original = str_replace("thumbnails_anywhere_picasa", "800", $thumbnail);
        //原始大图
        $thumbnail = str_replace("thumbnails_anywhere_picasa", $realsize, $thumbnail);
    } else {
        if (strstr($thumbnail, 'picasa_thumbnails_anywhere')) {
            if ($crop == true) {
                if ($thumbsize <= 32) {
                    $realsize = 32;
                } else {
                    if ($thumbsize <= 48) {
                        $realsize = 48;
                    } else {
                        if ($thumbsize <= 64) {
                            $realsize = 64;
                        } else {
                            if ($thumbsize <= 72) {
                                $realsize = 72;
                            } else {
                                if ($thumbsize <= 144) {
                                    $realsize = 144;
                                } else {
                                    if ($thumbsize <= 160) {
                                        $realsize = 160;
                                    } else {
                                        if ($thumbsize <= 200) {
                                            $realsize = 200;
                                        } else {
                                            if ($thumbsize <= 288) {
                                                $realsize = 288;
                                            } else {
                                                if ($thumbsize <= 320) {
                                                    $realsize = 320;
                                                } else {
                                                    if ($thumbsize <= 400) {
                                                        $realsize = 400;
                                                    } else {
                                                        if ($thumbsize <= 512) {
                                                            $realsize = 512;
                                                        } else {
                                                            if ($thumbsize <= 576) {
                                                                $realsize = 576;
                                                            } else {
                                                                if ($thumbsize <= 640) {
                                                                    $realsize = 640;
                                                                } else {
                                                                    if ($thumbsize <= 720) {
                                                                        $realsize = 720;
                                                                    } else {
                                                                        if ($thumbsize <= 800) {
                                                                            $realsize = 800;
                                                                        } else {
                                                                            $realsize = 800;
                                                                        }
                                                                    }
                                                                }
                                                            }
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                if ($thumbsize > 160) {
                    $realsize = 's' . $realsize;
                } else {
                    $realsize = 's' . $realsize . '-c';
                }
            } else {
                if ($thumbsize <= 32) {
                    $realsize = 32;
                } else {
                    if ($thumbsize <= 48) {
                        $realsize = 48;
                    } else {
                        if ($thumbsize <= 64) {
                            $realsize = 64;
                        } else {
                            if ($thumbsize <= 72) {
                                $realsize = 72;
                            } else {
                                if ($thumbsize <= 144) {
                                    $realsize = 144;
                                } else {
                                    if ($thumbsize <= 160) {
                                        $realsize = 160;
                                    } else {
                                        if ($thumbsize <= 200) {
                                            $realsize = 200;
                                        } else {
                                            if ($thumbsize <= 288) {
                                                $realsize = 288;
                                            } else {
                                                if ($thumbsize <= 320) {
                                                    $realsize = 320;
                                                } else {
                                                    if ($thumbsize <= 400) {
                                                        $realsize = 400;
                                                    } else {
                                                        if ($thumbsize <= 512) {
                                                            $realsize = 512;
                                                        } else {
                                                            if ($thumbsize <= 576) {
                                                                $realsize = 576;
                                                            } else {
                                                                if ($thumbsize <= 640) {
                                                                    $realsize = 640;
                                                                } else {
                                                                    if ($thumbsize <= 720) {
                                                                        $realsize = 720;
                                                                    } else {
                                                                        if ($thumbsize <= 800) {
                                                                            $realsize = 800;
                                                                        } else {
                                                                            $realsize = 800;
                                                                        }
                                                                    }
                                                                }
                                                            }
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                $realsize = 's' . $realsize;
            }
            $original = str_replace("picasa_thumbnails_anywhere", "800", $thumbnail);
            //原始大图
            $thumbnail = str_replace("picasa_thumbnails_anywhere", $realsize, $thumbnail);
        } else {
            if (strstr($thumbnail, 'yupoo_thumbnails_anywhere')) {
                if ($thumbsize <= 75) {
                    $type = "square";
                } else {
                    if ($thumbsize <= 100) {
                        $type = "thumb";
                    } else {
                        if ($thumbsize <= 240) {
                            $type = "small";
                        } else {
                            if ($thumbsize <= 500) {
                                $type = "medium";
                            } else {
                                if ($thumbsize <= 1024) {
                                    $type = "big";
                                } else {
                                    $type = "big";
                                }
                            }
                        }
                    }
                }
                // 原图无法获取
                $original = str_replace("yupoo_thumbnails_anywhere", "big", $thumbnail);
                //原始大图
                $thumbnail = str_replace("yupoo_thumbnails_anywhere", $type, $thumbnail);
            } else {
                if (strstr($thumbnail, 'flickr_thumbnails_anywhere')) {
                    if ($thumbsize <= 75) {
                        $type = "_s";
                    } else {
                        if ($thumbsize <= 100) {
                            $type = "_t";
                        } else {
                            if ($thumbsize <= 240) {
                                $type = "_m";
                            } else {
                                if ($thumbsize <= 500) {
                                    $type = "";
                                } else {
                                    $type = "";
                                }
                            }
                        }
                    }
                    // 1024大图和原图无法获取
                    $original = str_replace("flickr_thumbnails_anywhere", "_m", $thumbnail);
                    //原始大图
                    $thumbnail = str_replace("flickr_thumbnails_anywhere", $type, $thumbnail);
                } else {
                    if ($thumbnail == $defaultimage) {
                        //默认图片单独处理
                        $original = $thumbnail;
                        $filename = "default";
                        $thumbnail = ta_is_thumb_exist($filename, $thumbsize, $height, $crop, $year, $month);
                        if ($thumbnail == false) {
                            //如果图片不存在
                            $thumbnail = $original;
                            $thumbnail = str_replace($siteurl, $rooturl, $thumbnail);
                            //转换为绝对路径
                            //将图片按照规格存放在不同子目录
                            if ($crop == true) {
                                $subfolder = "{$thumbsize}x{$height}-c/";
                            } else {
                                $subfolder = "{$thumbsize}x{$height}-u/";
                            }
                            $subfolder = $destpath . $subfolder;
                            if (!file_exists($subfolder)) {
                                if (!@mkdir($subfolder, 0755)) {
                                    if (is_admin()) {
                                        echo "提示:很抱歉,无法创建缩略图子目录,请手动创建目录" . $subfolder . ",权限设置为755。<br>";
                                        return;
                                    }
                                }
                            }
                            $subfolder .= "{$year}/";
                            if (!file_exists($subfolder)) {
                                if (!@mkdir($subfolder, 0755)) {
                                    if (is_admin()) {
                                        echo "提示:很抱歉,无法创建缩略图子目录,请手动创建目录" . $subfolder . ",权限设置为755。<br>";
                                        return;
                                    }
                                }
                            }
                            $subfolder .= "{$month}/";
                            if (!file_exists($subfolder)) {
                                if (!@mkdir($subfolder, 0755)) {
                                    if (is_admin()) {
                                        echo "提示:很抱歉,无法创建缩略图子目录,请手动创建目录" . $subfolder . ",权限设置为755。<br>";
                                        return;
                                    }
                                }
                            }
                            $thumbnail = ta_image_resize($thumbnail, $thumbsize, $height, $crop, null, $subfolder, 90, $filename);
                            //制作缩略图
                            $thumbnail = ta_is_thumb_exist($filename, $thumbsize, $height, $crop, $year, $month);
                            if ($thumbnail == false) {
                                $thumbnail = $original;
                            }
                            //如果缩略图尺寸过大,只好显示原图
                        }
                    } else {
                        if (!strstr($thumbnail, 'ta_video_')) {
                            //普通图片(非视频)
                            if (!strstr($thumbnail, $siteurl)) {
                                // 图片
                                if ($disable_external == "true") {
                                    //禁止显示外链图片
                                    return;
                                }
                            } else {
                                if (strstr($thumbnail, $siteurl) or $disable_external == "false") {
                                    //本地图片或允许外链图片
                                    $original = $thumbnail;
                                    $filename = $post_id . "-" . ($seq + 1);
                                    $thumbnail = ta_is_thumb_exist($filename, $thumbsize, $height, $crop, $year, $month);
                                    if ($thumbnail == false) {
                                        //如果图片不存在
                                        $thumbnail = $original;
                                        $thumbnail = str_replace($siteurl, $rooturl, $thumbnail);
                                        //转换为绝对路径
                                        //将图片按照规格存放在不同子目录
                                        if ($crop == true) {
                                            $subfolder = "{$thumbsize}x{$height}-c/";
                                        } else {
                                            $subfolder = "{$thumbsize}x{$height}-u/";
                                        }
                                        $subfolder = $destpath . $subfolder;
                                        if (!file_exists($subfolder)) {
                                            if (!@mkdir($subfolder, 0755)) {
                                                if (is_admin()) {
                                                    echo "提示:很抱歉,无法创建缩略图子目录,请手动创建目录" . $subfolder . ",权限设置为755。<br>";
                                                    return;
                                                }
                                            }
                                        }
                                        $subfolder .= "{$year}/";
                                        if (!file_exists($subfolder)) {
                                            if (!@mkdir($subfolder, 0755)) {
                                                if (is_admin()) {
                                                    echo "提示:很抱歉,无法创建缩略图子目录,请手动创建目录" . $subfolder . ",权限设置为755。<br>";
                                                    return;
                                                }
                                            }
                                        }
                                        $subfolder .= "{$month}/";
                                        if (!file_exists($subfolder)) {
                                            if (!@mkdir($subfolder, 0755)) {
                                                if (is_admin()) {
                                                    echo "提示:很抱歉,无法创建缩略图子目录,请手动创建目录" . $subfolder . ",权限设置为755。<br>";
                                                    return;
                                                }
                                            }
                                        }
                                        $thumbnail = ta_image_resize($thumbnail, $thumbsize, $height, $crop, null, $subfolder, 90, $filename);
                                        //制作缩略图
                                        $thumbnail = ta_is_thumb_exist($filename, $thumbsize, $height, $crop, $year, $month);
                                        if ($thumbnail == false) {
                                            $thumbnail = $original;
                                        }
                                        //如果缩略图尺寸过大,只好显示原图
                                    }
                                }
                            }
                        } else {
                            if ($media != "image") {
                                $result = wp_thumbnails_getvideo($thumbnail);
                                $thumbnail = $result['imageurl'];
                                if ($video_link_target == "video") {
                                    //点击打开视频
                                    $permalink = $result['video'];
                                }
                                if ($video_thumb == "video") {
                                    //直接显示视频
                                    $video = $result['video'];
                                    $thumbnail_video = "<embed src=\"{$video}\" quality=\"high\" width=\"{$thumbsize}\" height=\"{$height}\" align=\"middle\" allowScriptAccess=\"sameDomain\" type=\"application/x-shockwave-flash\"></embed>";
                                    $thumbnail = "";
                                }
                            } else {
                                return;
                            }
                        }
                    }
                }
            }
        }
    }
    //控制显示位置
    if ($position == "random") {
        if (mt_rand(1, 100) < 50) {
            $css = "ta-pageimg-left";
        } else {
            $css = "ta-pageimg-right";
        }
    } else {
        $css = "ta-pageimg-" . $position;
    }
    $title = $post->post_title;
    if ($permalink == "post") {
        $permalink = get_permalink($post_id);
    } else {
        if ($permalink == "image") {
            $permalink = $original;
        }
    }
    $mouse = "onmouseover=\"this.style.backgroundColor='#A9A9A9'\" onmouseout=\"this.style.backgroundColor='#F0F0F0'\"";
    if ($thumbnail) {
        $output = "<div class=\"{$css}\">\n\t\t<a href=\"{$permalink}\"  rel=\"nofollow\"  title=\"{$title}\" target=\"{$target}\"><img alt=\"{$title}\" width=\"{$thumbsize}\" src=\"{$thumbnail}\" {$mouse} /></a>\n\t\t</div>";
    } else {
        //视频缩略图
        $output = "<div class=\"{$css}\">" . $thumbnail_video . "</div>";
    }
    return $output;
    // 显示日志中的第一张图片
}