Exemplo n.º 1
0
function LCZ_IS_SAE()
{
    //[sae]判断是否运行在SAE上。
    /*$LCZ_IS_SAE = SAE_MYSQL_DB;
    	if($LCZ_IS_SAE && $LCZ_IS_SAE!='SAE_MYSQL_DB'){
    		return true;
    	}else{
    		return false;
    	}*/
    $array_baidu_sitemap_options = get_baidu_sitemap_options();
    if ($array_baidu_sitemap_options['is_sina_sae']) {
        return true;
    } else {
        return false;
    }
}
Exemplo n.º 2
0
function build_baidu_sitemap_html()
{
    global $wpdb;
    $array_baidu_sitemap_options = get_baidu_sitemap_options();
    /** Get the current time **/
    $blogtime = current_time('mysql');
    list($today_year, $today_month, $today_day, $hour, $minute, $second) = split('([^0-9])', $blogtime);
    ##文章
    $html_contents = '';
    $sql_html = "select ID FROM {$wpdb->posts}\n\t        WHERE post_password = ''\n\t\t\tAND post_type='post'\n\t\t\tAND post_status = 'publish'\n\t\t\tORDER BY post_modified DESC\n\t\t\tLIMIT 0,1000\n\t       ";
    $recentposts_html = $wpdb->get_results($sql_html);
    if ($recentposts_html) {
        foreach ($recentposts_html as $post) {
            $html_contents .= '<li><a href="' . get_permalink($post->ID) . '" title="' . get_the_title($post->ID) . '" target="_blank">' . get_the_title($post->ID) . '</a></li>';
        }
    }
    //$post = query_posts( 'ignore_sticky_posts=1&posts_per_page=1000' );
    //while (have_posts()) : the_post();
    //$html_contents .= '<li><a href="'.get_permalink().'" title="'.get_the_title().'" target="_blank">'.get_the_title().'</a></li>';
    //endwhile;
    if ($array_baidu_sitemap_options['lc_category_select']) {
        $html_category_contents = wp_list_categories('echo=0');
    }
    if ($array_baidu_sitemap_options['lc_page_select']) {
        $html_page_contents = wp_list_pages('echo=0');
    }
    if ($array_baidu_sitemap_options['lc_tag_select']) {
        $html_tag_contents = wp_tag_cloud('echo=0&number=245');
        $html_tag_contents = '<br /><h3>Tag Cloud</h3>' . $html_tag_contents;
    }
    $blog_title = __('SiteMap', 'baidu_sitemap');
    $blog_name = get_bloginfo('name');
    $blog_keywords = $blog_title . ',' . $blog_name;
    $lc_generator = 'Baidu SiteMap Generator';
    $lc_author = 'Liucheng.Name';
    $lc_copyright = 'Liucheng.Name';
    $blog_home = get_bloginfo('url');
    $sitemap_url = get_bloginfo('url') . '/sitemap.html';
    $recentpost = __('RecentPost', 'baidu_sitemap');
    $footnote = __('HomePage', 'baidu_sitemap');
    $updated_time = "{$today_year}-{$today_month}-{$today_day} {$hour}:{$minute}:{$second}";
    if ($html_contents) {
        $path_html = LCZ_GetPluginPath() . 'sitemap.html';
        $html = file_get_contents("{$path_html}");
        $html = str_replace("%blog_title%", $blog_title, $html);
        $html = str_replace("%blog_name%", $blog_name, $html);
        $html = str_replace("%blog_home%", $blog_home, $html);
        $html = str_replace("%blog_keywords%", $blog_keywords, $html);
        $html = str_replace("%lc_generator%", $lc_generator, $html);
        $html = str_replace("%lc_author%", $lc_author, $html);
        $html = str_replace("%lc_copyright%", $lc_copyright, $html);
        $html = str_replace("%sitemap_url%", $sitemap_url, $html);
        $html = str_replace("%footnote%", $footnote, $html);
        $html = str_replace("%RecentPost%", $recentpost, $html);
        $html = str_replace("%updated_time%", $updated_time, $html);
        $html = str_replace("%contents%", $html_contents, $html);
        $html = str_replace("%Lc_category_contents%", $html_category_contents, $html);
        $html = str_replace("%Lc_page_contents%", $html_page_contents, $html);
        $html = str_replace("%Lc_tag_contents%", $html_tag_contents, $html);
        $LCZ_GetHomePath = LCZ_GetHomePath();
        $filename_html = $LCZ_GetHomePath . 'sitemap.html';
        if (LCZ_IsFileWritable($LCZ_GetHomePath) || LCZ_IsFileWritable($filename_html)) {
            file_put_contents("{$filename_html}", "{$html}");
            @chmod($filename_html, 0777);
            /** Messages  **/
            /*baidu_sitemap_topbarmessage(__('Congratulate, Build the Html file success','baidu_sitemap'));*/
        }
    }
}
/** 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();
}