-
Notifications
You must be signed in to change notification settings - Fork 6
Sitemap Handler
Using the Sitemap Handler allows you to maintain a valid sitemap for your web application.
The sitemap handler is utilised via a set of static methods. The handler fully supports the sitemaps.org protocol. The handler supports sitemap index files, multiple domain sitemaps, gzip compression & search engine pinging. The handler works by loading the pages in to a database and then outputs compiled sitemap files. The sitemap handler has been used in projects with over 10 million pages so capable of scaling for large applications.
To utilise the Atsumi sitemap handler you must create the necessary table in your database. See the PostgreSQL Installation Query We will add MySQL & SQLite installation SQL queries in the near future.
To add a page to the sitemap use the wirteUrl static method. The only required fields is the database object & the url of the page. If the page is new it will be inserted, if it’s already in the db it will get updated.
sitemap_Handler::writeUrl ($db, $loc, $lastMod, $changeFreq, $priority, $tableName);
Parameter | Type | Required | Default | Description |
---|---|---|---|---|
$db | Database | Required | Database that contains sitemap table | |
$loc | String | Required | URL to add | |
$lastMod | Timestamp | Optional | null | Last modified timestamp |
$changeFreq | Timestamp | Optional | null | ‘hourly’, ‘weekly’, ‘monthly’, ‘yearly’, ‘never’ |
$priority | Float | Optional | null | 0-1 |
$tableName | String | Optional | ‘sitemap’ | Database table name |
Sitemap files are written to flat-files. All sitemaps are generated with a sitemap index file. If your $host is ‘www.yourdomain.com’ and your $xmlFileRoot is ‘/sitemap/’ your sitemap address would be: ‘http://www.yourdomain.com/sitemap/sitemap.xml’ – You would then need to make this URL work using mod-rewrite (mapping /sitemap/ to the $xmlFilePath) or having a controller catch the request and serving the neccessary sitemap file
sitemap_Handler::writeXml ($db, $host, $xmlFilePath, $xmlUrlRoot, $maxUrlsPerSitemap, $compress, $tablename);
Parameter | Type | Required | Default | Description |
---|---|---|---|---|
$db | Database | Required | ||
$host | String | Required | Which hostname to generate the sitemap for | |
$xmlFilePath | String | Required | Path the files will be saved to – must be writable by the web server | |
$xmlUrlRoot | String | Required | The path where the sitemap will be serverd from ie: ‘/sitemap/’ | |
$maxUrlsPerSitemap | Integer | Optional | null | 0 – 50000 |
$compress | Boolean | Optional | true | Gzip compression |
$tablename | String | Optional | ‘sitemap’ | Database table name |
Removes all URLs stored for a given hostname.
sitemap_Handler::purgeUrlsForHost ($db, $host);
Parameter | Type | Required | Default | Description |
---|---|---|---|---|
$db | Database | Required | ||
$host | String | Required | Hostname to purge URLs for ie: www.yourdomain.com |
Pings the search engines with the URL of the sitemap.
sitemap_Handler::pingSearchEngines ($sitemapUrl);
Parameter | Type | Required | Default | Description |
---|---|---|---|---|
$sitemapUrl | String | Required | Full URL of sitemap |