代码拉取完成,页面将自动刷新
同步操作将从 mimvp/mimvp-sitemap-php 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
<?php
/**
* @author Sandy <sandy@mimvp.com>
* @copyright 2009-2017 mimvp.com
* @version 1.0.1 (2017.06.20)
*/
$xmlFile = 'sitemap_index.xml';
echo "<br> xmlFile : $xmlFile <br>";
$sitemap = new SitemapIndex($xmlFile);
// $sitemap->setUseGzip(true);
$sitemap->addSitemap('http://mimvp.com/sitemap.xml');
$sitemap->addSitemap('http://mimvp.com/sitemap-2.xml', time()-1000000);
$sitemap->addSitemap('http://mimvp.com/sitemap-3.xml', '2017-06-22
');
$sitemap->endSitemap();
echo "<script>window.open('" . $xmlFile . "')</script>";
echo "<br>Create SitemapIndex Success<br>";
/**
* SitemapIndex
*
* 生成 Google Sitemaps index (sitemap_index.xml)
*
* @package Sitemap
* @author Sandy <sandy@mimvp.com>
* @copyright 2009-2017 mimvp.com
* @license http://opensource.org/licenses/MIT MIT License
* @link http://github.com/mimvp/sitemap-php
*/
class SitemapIndex
{
private $writer;
private $filePath;
private $useGzip = false;
public function __construct($filePath)
{
$this->filePath = $filePath;
}
public function getFilePath()
{
return $this->filePath;
}
private function createSitemap()
{
$this->writer = new XMLWriter();
$this->writer->openMemory();
$this->writer->startDocument('1.0', 'UTF-8');
$this->writer->setIndent(true);
$this->writer->startElement('sitemapindex');
$this->writer->writeAttribute('xmlns', 'http://www.sitemaps.org/schemas/sitemap/0.9');
}
public function addSitemap($location, $lastModified = null)
{
if ($this->writer === null) {
$this->createSitemap();
}
$this->writer->startElement('sitemap');
$this->writer->writeElement('loc', $location);
$this->writer->writeElement('lastmod', $this->getLastModifiedDate($lastModified));
$this->writer->endElement();
}
public function endSitemap()
{
if ($this->writer instanceof XMLWriter) {
$this->writer->endElement();
$this->writer->endDocument();
$filePath = $this->getFilePath();
// if ($this->useGzip) {
// $filePath = 'compress.zlib://' . $filePath;
// }
file_put_contents($filePath, $this->writer->flush());
}
}
public function setUseGzip($value)
{
if ($value && !extension_loaded('zlib')) {
throw new \RuntimeException('Zlib extension must be installed to gzip the sitemap.');
}
$this->useGzip = $value;
}
private function getLastModifiedDate($date=null) {
if(null == $date) {
$date = time();
}
if (ctype_digit($date)) {
return date('c', $date);
} else {
$date = strtotime($date);
return date('c', $date); // Y-m-d
}
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。