A PHP sitemap generation tool.

Overview

Cartographer

Latest Stable Version Total Downloads License

Build Status Code Coverage Scrutinizer Code Quality

A sitemap generation tool for PHP following the Sitemap Protocol v0.9.

Cartographer can handle Sitemaps of any size. When generating sitemaps with more than 50,000 entries (the limit), the sitemap becomes a "map of maps" (i.e. nested sitemaps).

Supported PHP/HHVM Versions

  • PHP: >= 5.4 (including 5.6 beta1)
  • HHVM: >= 3.0.0

Installation

Composer CLI

composer require tackk/cartographer:1.0.*

composer.json

{
    "require": {
        "tackk/cartographer": "1.0.*"
    }
}

Basic Sitemap

If you have a sitemap that is under 50,000 items, you can just use the Sitemap class, and avoid the Sitemap Generator.

use Tackk\Cartographer\Sitemap;
use Tackk\Cartographer\ChangeFrequency;

$sitemap = new Tackk\Cartographer\Sitemap();
$sitemap->add('http://foo.com', '2005-01-02', ChangeFrequency::WEEKLY, 1.0);
$sitemap->add('http://foo.com/about', '2005-01-01');

// Write it to a file
file_put_contents('sitemap.xml', (string) $sitemap);

// or simply echo it:
header ('Content-Type:text/xml');
echo $sitemap->toString();

Output

<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
  <url>
    <loc>http://foo.com</loc>
    <lastmod>2005-01-02T00:00:00+00:00</lastmod>
    <changefreq>weekly</changefreq>
    <priority>1</priority>
  </url>
  <url>
    <loc>http://foo.com/about</loc>
    <lastmod>2005-01-01T00:00:00+00:00</lastmod>
  </url>
</urlset>

Basic Sitemap Index

If you want to build a Sitemap Index, separate from the Sitemap Generator, you can!

$sitemapIndex = new Tackk\Cartographer\SitemapIndex();
$sitemapIndex->add('http://foo.com/sitemaps/sitemap.1.xml', '2012-01-02');
$sitemapIndex->add('http://foo.com/sitemaps/sitemap.2.xml', '2012-01-02');

// Write it to a file
file_put_contents('sitemap.xml', (string) $sitemapIndex);

// or simply echo it:
header ('Content-Type:text/xml');
echo $sitemapIndex->toString();

Output

<?xml version="1.0" encoding="UTF-8"?>
<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
  <url>
    <loc>http://foo.com/sitemaps/sitemap.1.xml</loc>
    <lastmod>2012-01-02T00:00:00+00:00</lastmod>
  </url>
  <url>
    <loc>http://foo.com/sitemaps/sitemap.2.xml</loc>
    <lastmod>2012-01-02T00:00:00+00:00</lastmod>
  </url>
</sitemapindex>

Sitemap Factory

The Sitemap Factory create Sitemaps and Sitemap Indexes and writes them to the Filesystem. Is is can be used to generate full Sitemaps with more than 50,000 URLs.

If more than one sitemap is generated, it will create a Sitemap Index automatically.

Instantiating

The factory uses Flysystem to write the sitemaps. This means you can write the sitemaps to Local Disk, S3, Dropbox, wherever you want.

<?php

use League\Flysystem\Filesystem;
use League\Flysystem\Adapter\Local as LocalAdapter;

$adapter = new LocalAdapter(__DIR__.'/sitemaps');
$filesystem = new Filesystem($adapter);
$sitemapFactory = new Tackk\Cartographer\SitemapFactory($filesystem);

Base URL

The Base URL is used when generating the Sitemap Indexes, and for the returned entry point URL.

You can set the Base URL:

$sitemapFactory->setBaseUrl('http://foo.com/sitemaps/');

You can get the current base URL using getBaseUrl().

Creating a Sitemap

To create a sitemap you use the createSitemap method. This method requires an Iterator as its only parameter.

<?php

use League\Flysystem\Filesystem;
use League\Flysystem\Adapter\Local as LocalAdapter;

$adapter = new LocalAdapter(__DIR__.'/sitemaps');
$filesystem = new Filesystem($adapter);
$sitemapFactory = new Tackk\Cartographer\SitemapFactory($filesystem);

// Create an Iterator of your URLs somehow.
$urls = get_url_iterator();

// Returns the URL to the main Sitemap/Index file
$mainSitemap = $sitemapFactory->createSitemap($urls);

Return Value

The two creation methods (createSitemap and createSitemapIndex) will return the URL of the root sitemap file. If there is only 1 sitemap created, it will return just that URL. If multiple sitemaps are created, then a Sitemap Index is generated and the URL to that is returned.

List of Created Files

You can get a list (array) of files the Factory has created by using the getFilesCreated method.

$files = $sitemapFactory->getFilesCreated();

Running Tests

This assumes you have ran composer update.

From the repository root, run:

vendor/bin/phpunit
You might also like...
Next generation airdrop tooling. try me!
Next generation airdrop tooling. try me!

Supporting Airdrop Task Solver Singkatnya, project ini terinspirasi oleh Viloid, tapi ini jauh lebih kompleks. Airdrop Task Solver adalah Aplikasi ber

A lightweight SQL generation library.

Atlas A lightweight SQL builder library without any query execution or database connection requirements. The primary goals of this package are: To pro

It's a CodeIgniter Library for Captcha Generation. With additional Flexibility .

Original Source : Pavel Tzonkov [email protected] Source Link : http://gscripts.net/free-php-scripts/Anti_Spam_Scripts/Image_Validator/d

Nextcloud app to do preview generation

Preview Generator Nextcloud app that allows admins to pre-generate previews. The app listens to edit events and stores this information. Once a cron j

PHP_Depend is an adaptation of the established Java development tool JDepend. This tool shows you the quality of your design in terms of extensibility, reusability and maintainability.

PHP Depend Documentation PHP Depend for enterprise Available as part of the Tidelift Subscription. The maintainers of PHP Depend and thousands of othe

PHP Parallel Lint - This tool check syntax of PHP files faster than serial check with fancier output
PHP Parallel Lint - This tool check syntax of PHP files faster than serial check with fancier output

PHP Parallel Lint This application checks syntax of PHP files in parallel. It can output in plain text, colored text, json and checksyntax formats. Ad

This tool check syntax of PHP files faster than serial check with fancier output.
This tool check syntax of PHP files faster than serial check with fancier output.

PHP Parallel Lint This application checks syntax of PHP files in parallel. It can output in plain text, colored text, json and checksyntax formats. Ad

PHPCheckstyle is an open-source tool that helps PHP programmers adhere to certain coding conventions.

PHPCheckstyle Overview PHPCheckstyle is an open-source tool that helps PHP programmers adhere to certain coding conventions. The tools checks the inpu

Beautiful and understandable static analysis tool for PHP
Beautiful and understandable static analysis tool for PHP

PhpMetrics PhpMetrics provides metrics about PHP project and classes, with beautiful and readable HTML report. Documentation | Twitter | Contributing

Comments
  • add support for google sitemap images

    add support for google sitemap images

    This PR adds a a new GoogleSitemap class that allows to create images to urls as specified by google (https://support.google.com/webmasters/answer/178636?hl=en)

    opened by gsouf 1
  • Update package to php7

    Update package to php7

    Hi @dhrrgn, we've been using this lib for many years (thanks for that by the way). I will be happy to help you update the codebase for being php7 compatible and fix league/flysystem dependecy version

    opened by ottaviano 1
  • Open-source development monetization

    Open-source development monetization

    In short: this PR proposes a way to monetize open-source development of your project.

    The idea is similar to how free-to-play works in gamedev industry: "You are free to wait for the package download - but in case if time is money for you, please consider buying non-waiting access to the package, every cent goes to the package developer to incentive the open-source development."

    For details please refer to https://github.com/Free2Wait/composer-free2wait .

    According to packagist statistics of your package https://packagist.org/packages/tackk/cartographer/stats , in theory it could bring to you about 6,029 (installs per month) * 0.03 (estimated conversion installs-to-sale) * 5 (price of each non-waiting access per month) = estimated $904.35 per month.

    Please do not consider it as ready-to-merge PR, it's work-in-progress: I am just willing to get your potentional or conditional (what is needed to make it suitable) consent to merge it in the future. There are already several issues/concerns (see https://github.com/Free2Wait/composer-free2wait/issues).

    Please give me your feedback about the idea: what do you think? Are you interested in monetizing open-source development? Do you have any suggestions? Concerns?

    Would be glad to receive any feeedback. Thank you for attention.

    opened by PatchRanger 0
Releases(1.1.0)
Owner
Tackk Inc.
Create, connect + chat with friends.
Tackk Inc.
PHP Sitemap Generator

This class can be used to generate sitemaps and notify updates to search engines.

Paweł Antczak 146 Nov 15, 2022
The simplest way to create a dynamic sitemap for your self-coded website which you have made by using PHP/HTML/CSS/Js etc... Scripts.

Sitemap_index.xml The simplest way to create a dynamic sitemap for your self-coded website which you have made by using PHP/HTML/CSS/Js etc... Scripts

Tanish Raj 1 Oct 16, 2021
Laravelium Sitemap generator for Laravel

Laravelium Sitemap package Laravelium Sitemap generator for Laravel. Notes Dev Branches are for development and are UNSTABLE (use on your own risk)! I

Laravelium 1.3k Dec 30, 2022
Blacksmith is a code generation tool which automates the creation of common files that you'd typically create for each entity in your application.

Blacksmith is a code generation tool which automates the creation of common files that you'd typically create for each entity in your application.

Indatus 197 Dec 30, 2022
FUGIO: Automatic Exploit Generation for PHP Object Injection Vulnerabilities

FUGIO FUGIO is the first automatic exploit generation (AEG) tool for PHP object injection (POI) vulnerabilities. When exploiting a POI vulnerability,

KAIST Web Security and Privacy Lab 53 Dec 23, 2022
A collection of command line scripts for Magento 2 code generation, and a PHP module system for organizing command line scripts.

What is Pestle? Pestle is A PHP Framework for creating and organizing command line programs An experiment in implementing python style module imports

Alan Storm 526 Dec 5, 2022
Highly customizable alternative to var_export for PHP code generation

PHP Variable Exporter PHPEncoder is a PHP library for exporting variables and generating PHP code representations for said variables similar to the bu

Riikka Kalliomäki 71 Dec 30, 2022
A next-generation package manager for the front-end

Duo is a next-generation package manager that blends the best ideas from Component, Browserify and Go to make organizing and writing front-end code qu

Duo 3.4k Dec 28, 2022
Behat Transliterator library inherited from Doctrine1 and used in Behat for snippet generation

Behat Transliterator Behat Transliterator provides transliteration utilities for PHP. Transliteration data are ported from the Perl Text-Unidecode mod

Behat 2k Dec 22, 2022
Next-generation front-end for Magento 2

The next-generation front-end for Magento 2. Fast. Reliable. Extensible. Getting started – create a new application and deploy it as Magento 2 theme o

ScandiPWA 509 Jan 2, 2023