function index() { $sitemap = new google_sitemap(); //Create a new Sitemap Object $item = new google_sitemap_item(base_url(), date("Y-m-d"), 'weekly', '0.8'); //Create a new Item $sitemap->add_item($item); //Append the item to the sitemap object $sitemap->build("./sitemap.xml"); //Build it... //Let's compress it to gz $data = implode("", file("./sitemap.xml")); $gzdata = gzencode($data, 9); $fp = fopen("./sitemap.xml.gz", "w"); fwrite($fp, $gzdata); fclose($fp); //Let's Ping google //$this->_pingGoogleSitemaps(base_url()."/sitemap.xml.gz"); }
$sm->add_item($smi); } /* 商品 */ $sql = "SELECT goods_id, goods_name FROM " . $ecs->table('goods') . " WHERE is_delete = 0"; $res = $db->query($sql); while ($row = $db->fetchRow($res)) { $smi = new google_sitemap_item($domain . build_uri('goods', array('gid' => $row['goods_id']), $row['goods_name']), $today, $_POST['content_changefreq'], $_POST['content_priority']); $sm->add_item($smi); } /* 文章 */ $sql = "SELECT article_id,title,file_url,open_type FROM " . $ecs->table('article') . " WHERE is_open=1"; $res = $db->query($sql); while ($row = $db->fetchRow($res)) { $article_url = $row['open_type'] != 1 ? build_uri('article', array('aid' => $row['article_id']), $row['title']) : trim($row['file_url']); $smi = new google_sitemap_item($domain . $article_url, $today, $_POST['content_changefreq'], $_POST['content_priority']); $sm->add_item($smi); } clear_cache_files(); // 清除缓存 $sm_file = '../sitemaps.xml'; if ($sm->build($sm_file)) { sys_msg(sprintf($_LANG['generate_success'], $ecs->url() . "sitemaps.xml")); } else { $sm_file = '../' . DATA_DIR . '/sitemaps.xml'; if ($sm->build($sm_file)) { sys_msg(sprintf($_LANG['generate_success'], $ecs->url() . DATA_DIR . '/sitemaps.xml')); } else { sys_msg(sprintf($_LANG['generate_failed'])); } } }
$rs->execute(); $arrData = $rs->fetchAll(PDO::FETCH_COLUMN); foreach ($arrData as $key => $val) { $strDir = ceil($val / $arrGCache['cache_filenum']); if ($arrGWeb['URL_static']) { if ($arrGWeb['file_static']) { $strUrl = $domain . '/' . $arrGWeb['cache_url'] . '/' . $k . '-' . $strDir . '/' . $val . $arrGWeb['file_suffix']; } else { $strUrl = $domain . '/' . $k . '/detail/id-' . $val . $arrGWeb['file_suffix']; } } else { $strUrl = $domain . '/' . $k . '/detail.php?id=' . $val; } $smi = new google_sitemap_item($strUrl, $today, $_POST['content_changefreq'], $_POST['content_priority']); $sm->add_item($smi); } break; } } } $sm->build($sm_file); check::Alert('Google Sitemaps 生成成功,http://' . $arrGWeb['host'] . '/sitemap.xml'); } else { check::AlertExit("错误:文件 http://" . $arrGWeb['host'] . "/sitemap.xml 不可写!", -1); } } // 输出到模板 $arrMOutput["smarty_assign"]['strNav'] = 'Google Sitemaps'; $arrMOutput["template_file"] = "admin.html"; $arrMOutput["smarty_assign"]['MAIN'] = $arrGSmarty['admin_main_dir'] . 'seo/google_sitemap.htm'; $objWebInit->output($arrMOutput);
} //列出文章 for ($i = 0; $i < count($articlelist); $i++) { $value = $articlelist[$i]; $locobj = array("type" => "article", "name" => "{$value->filename}", "siteurl" => "{$siteurl}"); $loc = formaturl($locobj); $site_map_item = new google_sitemap_item($loc, date("c"), 'monthly', "0.5"); $site_map_container->add_item($site_map_item); } //列出产品分类 for ($i = 0; $i < count($productcategory); $i++) { $value = $productcategory[$i]; $locobj = array("type" => "category", "name" => "{$value->filename}", "siteurl" => "{$siteurl}"); $loc = formaturl($locobj); $site_map_item = new google_sitemap_item($loc, date("c"), 'weekly', "0.8"); $site_map_container->add_item($site_map_item); } //列出文章分类 for ($i = 0; $i < count($articlecategory); $i++) { $value = $articlecategory[$i]; $locobj = array("type" => "category", "name" => "{$value->filename}", "siteurl" => "{$siteurl}"); $loc = formaturl($locobj); $site_map_item = new google_sitemap_item($loc, date("c"), 'weekly', "0.8"); $site_map_container->add_item($site_map_item); } //列出首页 $site_map_item = new google_sitemap_item("{$siteurl}", date("c"), 'always', "1.0"); $site_map_container->add_item($site_map_item); header("Content-type: application/xml; charset=\"" . $site_map_container->charset . "\"", true); print $site_map_container->build();