Пример #1
0
/** build the XML file, sitemap_baidu.xml **/
function build_baidu_sitemap()
{
    global $wpdb, $posts;
    $array_baidu_sitemap_options = get_baidu_sitemap_options();
    if ($array_baidu_sitemap_options['lc_post_limit1000']) {
        $lc_limit = '1000';
    } else {
        $lc_limit = '10000';
    }
    ## $lc_contents , $lc_limit = '1000'
    $sql_mini = "select ID,post_modified,post_date,post_type FROM {$wpdb->posts}\n\t        WHERE post_password = ''\n\t\t\tAND (post_type='post' or post_type='page')\n\t\t\tAND post_status = 'publish'\n\t\t\tORDER BY post_modified DESC\n\t\t\tLIMIT 0,{$lc_limit}\n\t       ";
    $recentposts_mini = $wpdb->get_results($sql_mini);
    if ($recentposts_mini) {
        foreach ($recentposts_mini as $post) {
            if ($post->post_type == 'page') {
                if (!$array_baidu_sitemap_options['lc_page_select']) {
                    continue;
                }
                ###跳过
                $loc = get_page_link($post->ID);
                $loc = LCZ_EscapeXML($loc);
                if (!$loc) {
                    continue;
                }
                if ($post->post_modified == '0000-00-00 00:00:00') {
                    $post_date = $post->post_date;
                } else {
                    $post_date = $post->post_modified;
                }
                $lastmod = date("Y-m-d\\TH:i:s+00:00", LCZ_GetTimestampFromMySql($post_date));
                $changefreq = 'weekly';
                $priority = '0.3';
                $xml_contents_page .= "<url>";
                $xml_contents_page .= "<loc>{$loc}</loc>";
                $xml_contents_page .= "<lastmod>{$lastmod}</lastmod>";
                $xml_contents_page .= "<changefreq>{$changefreq}</changefreq>";
                $xml_contents_page .= "<priority>{$priority}</priority>";
                $xml_contents_page .= "</url>";
            } else {
                if (!$array_baidu_sitemap_options['lc_post_select']) {
                    continue;
                }
                ###跳过
                $loc = get_permalink($post->ID);
                $loc = LCZ_EscapeXML($loc);
                if (!$loc) {
                    continue;
                }
                if ($post->post_modified == '0000-00-00 00:00:00') {
                    $post_date = $post->post_date;
                } else {
                    $post_date = $post->post_modified;
                }
                ##$post->post_date_gmt
                $lastmod = date("Y-m-d\\TH:i:s+00:00", LCZ_GetTimestampFromMySql($post_date));
                $changefreq = 'monthly';
                $priority = '0.6';
                $xml_contents_post .= "<url>";
                $xml_contents_post .= "<loc>{$loc}</loc>";
                $xml_contents_post .= "<lastmod>{$lastmod}</lastmod>";
                $xml_contents_post .= "<changefreq>{$changefreq}</changefreq>";
                $xml_contents_post .= "<priority>{$priority}</priority>";
                $xml_contents_post .= "</url>";
            }
        }
        ## get_category_link
        if ($array_baidu_sitemap_options['lc_category_select']) {
            $category_ids = get_all_category_ids();
            if ($category_ids) {
                foreach ($category_ids as $cat_id) {
                    $loc = get_category_link($cat_id);
                    $loc = LCZ_EscapeXML($loc);
                    if (!$loc) {
                        continue;
                    }
                    $lastmod = date("Y-m-d\\TH:i:s+00:00", current_time('timestamp', '1'));
                    $changefreq = 'Weekly';
                    $priority = '0.3';
                    $xml_contents_cat .= "<url>";
                    $xml_contents_cat .= "<loc>{$loc}</loc>";
                    $xml_contents_cat .= "<lastmod>{$lastmod}</lastmod>";
                    $xml_contents_cat .= "<changefreq>{$changefreq}</changefreq>";
                    $xml_contents_cat .= "<priority>{$priority}</priority>";
                    $xml_contents_cat .= "</url>";
                }
            }
        }
        ##
        ###tag
        if ($array_baidu_sitemap_options['lc_tag_select']) {
            $all_the_tags = get_tags();
            if ($all_the_tags) {
                foreach ($all_the_tags as $this_tag) {
                    $tag_id = $this_tag->term_id;
                    $loc = get_tag_link($tag_id);
                    $loc = LCZ_EscapeXML($loc);
                    if (!$loc) {
                        continue;
                    }
                    $lastmod = date("Y-m-d\\TH:i:s+00:00", current_time('timestamp', '1'));
                    $changefreq = 'Weekly';
                    $priority = '0.3';
                    $xml_contents_tag .= "<url>";
                    $xml_contents_tag .= "<loc>{$loc}</loc>";
                    $xml_contents_tag .= "<lastmod>{$lastmod}</lastmod>";
                    $xml_contents_tag .= "<changefreq>{$changefreq}</changefreq>";
                    $xml_contents_tag .= "<priority>{$priority}</priority>";
                    $xml_contents_tag .= "</url>";
                }
            }
        }
        ###end tag
        $xml_contents = $xml_contents_post . $xml_contents_page . $xml_contents_cat . $xml_contents_tag;
    }
    ## XML
    if ($array_baidu_sitemap_options['lc_is_Enabled_XML_Sitemap']) {
        build_baidu_sitemap_xml($xml_contents);
    }
    ## Html
    if ($array_baidu_sitemap_options['lc_is_Enabled_Html_Sitemap']) {
        build_baidu_sitemap_html();
    }
    if (function_exists('wp_clear_scheduled_hook')) {
        wp_clear_scheduled_hook('do_baidu_sitemap_by_post');
    }
    //baidu_sitemap_is_auto_daily();
}
/** build the XML file, sitemap_baidu.xml **/
function build_baidu_sitemap()
{
    global $wpdb, $posts;
    $array_baidu_sitemap_options = get_baidu_sitemap_options();
    if ($array_baidu_sitemap_options['lc_post_limit1000']) {
        $lc_limit = '1000';
    } else {
        $lc_limit = '10000';
    }
    ## $lc_contents , $lc_limit = '1000'
    $sql_mini = "select ID,post_modified_gmt,post_date_gmt,post_type FROM {$wpdb->posts}\n\t        WHERE post_password = ''\n\t\t\tAND (post_type != 'revision' AND post_type != 'attachment' AND post_type != 'nav_menu_item')\n\t\t\tAND post_status = 'publish'\n\t\t\tORDER BY post_modified_gmt DESC\n\t\t\tLIMIT 0,{$lc_limit}\n\t       ";
    $recentposts_mini = $wpdb->get_results($sql_mini);
    if ($recentposts_mini) {
        foreach ($recentposts_mini as $post) {
            if ($post->post_type == 'page') {
                $loc = get_page_link($post->ID);
                if ($post->post_modified_gmt == '0000-00-00 00:00:00') {
                    $post_date_gmt = $post->post_date_gmt;
                } else {
                    $post_date_gmt = $post->post_modified_gmt;
                }
                $lastmod = date("Y-m-d\\TH:i:s+00:00", LCZ_GetTimestampFromMySql($post_date_gmt));
                $changefreq = 'weekly';
                $priority = '0.3';
                $xml_contents_page .= "<url>";
                $xml_contents_page .= "<loc>{$loc}</loc>";
                $xml_contents_page .= "<lastmod>{$lastmod}</lastmod>";
                $xml_contents_page .= "<changefreq>{$changefreq}</changefreq>";
                $xml_contents_page .= "<priority>{$priority}</priority>";
                $xml_contents_page .= "</url>";
            } else {
                $loc = get_permalink($post->ID);
                if ($post->post_modified_gmt == '0000-00-00 00:00:00') {
                    $post_date_gmt = $post->post_date_gmt;
                } else {
                    $post_date_gmt = $post->post_modified_gmt;
                }
                $lastmod = date("Y-m-d\\TH:i:s+00:00", LCZ_GetTimestampFromMySql($post_date_gmt));
                $changefreq = 'monthly';
                $priority = '0.6';
                $xml_contents_post .= "<url>";
                $xml_contents_post .= "<loc>{$loc}</loc>";
                $xml_contents_post .= "<lastmod>{$lastmod}</lastmod>";
                $xml_contents_post .= "<changefreq>{$changefreq}</changefreq>";
                $xml_contents_post .= "<priority>{$priority}</priority>";
                $xml_contents_post .= "</url>";
            }
        }
        ## get_category_link
        $category_ids = get_all_category_ids();
        foreach ($category_ids as $cat_id) {
            $loc = get_category_link($cat_id);
            $lastmod = date("Y-m-d\\TH:i:s+00:00", current_time('timestamp', '1'));
            $changefreq = 'Weekly';
            $priority = '0.3';
            $xml_contents_cat .= "<url>";
            $xml_contents_cat .= "<loc>{$loc}</loc>";
            $xml_contents_cat .= "<lastmod>{$lastmod}</lastmod>";
            $xml_contents_cat .= "<changefreq>{$changefreq}</changefreq>";
            $xml_contents_cat .= "<priority>{$priority}</priority>";
            $xml_contents_cat .= "</url>";
        }
        ##
        $xml_contents = $xml_contents_post . $xml_contents_page . $xml_contents_cat;
    }
    ## XML
    if ($array_baidu_sitemap_options[lc_is_Enabled_XML_Sitemap]) {
        build_baidu_sitemap_xml($xml_contents);
    }
    ## Html
    if ($array_baidu_sitemap_options[lc_is_Enabled_Html_Sitemap]) {
        build_baidu_sitemap_html();
    }
    if (function_exists('wp_clear_scheduled_hook')) {
        wp_clear_scheduled_hook('do_baidu_sitemap_by_post');
    }
    //baidu_sitemap_is_auto_daily();
}