dev-master
9999999-devSitemap generator.
MIT
The Requires
- php >=7.0
- spiral/common ^1.0
- spiral/framework ^1.0
The Development Requires
by Valentin V / vvval
Sitemap generator.
Sitemaps generator tool for PHP, (*1)
Also includes sitemap generator, that can handle multiple sitemap files automatically in case of files count or file size limits reached., (*2)
Via composer, (*3)
composer require spiral/sitemaps
Below are some examples of how to use current package:, (*4)
/** * Constructor parameters are optional * * @param array $namespaces List of namespaces to be added. * Default one will be added anyway, add other ones when adding urls with images, video, alter langs, etc. * @param int $maxFilesLimit Limit of urls added, if not set - no files count limit. * @param int $maxFileSizeLimit Limit of uncompressed sitemap file size, if not set - no file size limit. */ $sitemap = new \Spiral\Sitemaps\Sitemaps\Sitemap( [ 'xmlns:image="http://www.google.com/schemas/sitemap-image/1.1"', 'xmlns:xhtml="http://www.w3.org/1999/xhtml"' ], $config->maxFiles('sitemap'), $config->maxFileSize('sitemap') ); //Or, just set parameters before opening sitemap: $sitemap = new Sitemap(); $sitemap->setFilesCountLimit($config->maxFiles('sitemap')); $sitemap->setFileSizeLimit($config->maxFileSize('sitemap')); $sitemap->setNamespaces([ 'xmlns:image="http://www.google.com/schemas/sitemap-image/1.1"', 'xmlns:xhtml="http://www.w3.org/1999/xhtml"' ]);
$config
is instance of\Spiral\Sitemaps\SitemapsConfig
class, you can use numbers directly., (*5)
\Spiral\Sitemaps\Namespaces
class is dedicated for using namespace aliases instead of passing full namespace strings:, (*6)
$sitemap->setNamespaces([ 'xmlns:image="http://www.google.com/schemas/sitemap-image/1.1"', 'xmlns:xhtml="http://www.w3.org/1999/xhtml"' ]); //Is equal to $sitemap->setNamespaces($namespaces->get(['image', 'lang']));
You can add your own aliases in config, (*7)
Adding items to sitemap:, (*8)
$item = new \Spiral\Sitemaps\Items\PageItem('location.com'); $item->addImage(new \Spiral\Sitemaps\Items\ImageItem('image-location.com')); $item->addAlterLang(new \Spiral\Sitemaps\Items\AlterLangItem('de', 'location.de')); $item->addVideo(new \Spiral\Sitemaps\Items\VideoItem('video-location.com')); $sitemap->open('sitemap.xml', 8); $sitemap->addItem(new \Spiral\Sitemaps\Items\PageItem('location.com')); $sitemap->close();
Output for, (*9)
$sitemap = new Sitemap( $namespaces->get(['image', 'lang']), $config->maxFiles('sitemap'), $config->maxFileSize('sitemap') ); $item = new \Spiral\Sitemaps\Items\PageItem('location.com'); $item->addImage(new \Spiral\Sitemaps\Items\ImageItem('image-location.com')); $item->addAlterLang(new \Spiral\Sitemaps\Items\AlterLangItem('de', 'location.de')); $sitemap->open('sitemap.xml', 8); $sitemap->addItem(new \Spiral\Sitemaps\Items\PageItem('location.com')); $sitemap->close();
will be:, (*10)
To enable gzip //Pass compression ration to enable .gz encoding, (*11)
Sitemap generator.
MIT