示例#1
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'));*/
        }
    }
}
示例#2
0
function xml_file_exist()
{
    $array_baidu_sitemap_options = get_baidu_sitemap_options();
    $lc_blog_url = home_url();
    $fileName = LCZ_GetHomePath();
    $filename = $fileName . $array_baidu_sitemap_options['lc_XML_FileName'] . '.xml';
    echo '<div class="tool-box">';
    echo '<h3 class="title">';
    _e('XML File Status', 'baidu_sitemap');
    print '</h3>';
    if (file_exists($filename)) {
        //$filctime=date("Y-m-d H:i:s",filectime("$filename"));
        $filemtime = date("Y-m-d H:i:s", filemtime("{$filename}"));
        //$fileatime=date("Y-m-d H:i:s",fileatime("$filename"));
        echo "<p>";
        #_e('When you change Path of the XML file(Better not). please use 301 redirect to the new XML-file, or setting as 404 page.','baidu_sitemap');
        echo "</p>";
        echo '<p>';
        _e('Check XML-sitemap File: ', 'baidu_sitemap');
        echo '<a href="' . $lc_blog_url . '/' . $array_baidu_sitemap_options['lc_XML_FileName'] . '.xml' . '" target="_blank">' . $lc_blog_url . '/' . $array_baidu_sitemap_options['lc_XML_FileName'] . '.xml' . '</a></p>';
        #echo '<p>'; _e('Last updated: ','baidu_sitemap'); print $filemtime.'</p>';
        echo '';
    } else {
        _e('Baidu Sitemap File is not Exist, please Write a normal XML file.', 'baidu_sitemap');
    }
    $sitemap_html = LCZ_GetHomePath() . 'sitemap.html';
    if (file_exists($sitemap_html)) {
        echo '<p>';
        _e('Check SiteMap Html: ', 'baidu_sitemap');
        echo '<a href="' . $lc_blog_url . '/sitemap.html' . '" target="_blank">' . $lc_blog_url . '/sitemap.html' . '</a></p>';
    }
    echo '</div>';
}