Skip to content

Commit

Permalink
Merge branch '4.0.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
icamys committed Dec 29, 2020
2 parents 367eeea + eda4c4b commit b43cbc1
Show file tree
Hide file tree
Showing 13 changed files with 1,372 additions and 1,265 deletions.
39 changes: 22 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Library for sitemap generation and submission.
Features:
* Follows [sitemaps.org](https://sitemaps.org/) protocol
* Supports alternative links for multi-language pages (see [google docs](https://webmasters.googleblog.com/2012/05/multilingual-and-multinational-site.html))
* Fixed low memory usage for any amount of URLs

Installation with Composer:

Expand All @@ -29,46 +30,50 @@ $yourSiteUrl = 'https://example.com';

// Setting the current working directory to be output directory
// for generated sitemaps (and, if needed, robots.txt)
// The output directory setting is optional and provided for demonstration purpose.
// By default output is written to current directory.
// The output directory setting is optional and provided for demonstration purposes.
// The generator writes output to the current directory by default.
$outputDir = getcwd();

$generator = new \Icamys\SitemapGenerator\SitemapGenerator($yourSiteUrl, $outputDir);

// will create also compressed (gzipped) sitemap
$generator->toggleGZipFileCreation();
// Create a compressed sitemap
$generator->enableCompression();

// determine how many urls should be put into one file;
// Determine how many urls should be put into one file;
// this feature is useful in case if you have too large urls
// and your sitemap is out of allowed size (50Mb)
// according to the standard protocol 50000 is maximum value (see http://www.sitemaps.org/protocol.html)
$generator->setMaxURLsPerSitemap(50000);
// according to the standard protocol 50000 urls per sitemap
// is the maximum allowed value (see http://www.sitemaps.org/protocol.html)
$generator->setMaxUrlsPerSitemap(50000);

// sitemap file name
// Set the sitemap file name
$generator->setSitemapFileName("sitemap.xml");

// sitemap index file name
// Set the sitemap index file name
$generator->setSitemapIndexFileName("sitemap-index.xml");

// alternate languages
// Add alternate languages if needed
$alternates = [
['hreflang' => 'de', 'href' => "http://www.example.com/de"],
['hreflang' => 'fr', 'href' => "http://www.example.com/fr"],
];

// adding url `loc`, `lastmodified`, `changefreq`, `priority`, `alternates`
// Add url components: `loc`, `lastmodified`, `changefreq`, `priority`, `alternates`
// Instead of storing all urls in the memory, the generator will flush sets of added urls
// to the temporary files created on your disk.
// The file format is 'sm-{index}-{timestamp}.xml'
$generator->addURL('/path/to/page/', new DateTime(), 'always', 0.5, $alternates);

// generate internally a sitemap
$generator->createSitemap();
// Flush all stored urls from memory to the disk and close all necessary tags.
$generator->flush();

// write early generated sitemap to file(s)
$generator->writeSitemap();
// Move flushed files to their final location. Compress if the option is enabled.
$generator->finalize();

// update robots.txt file in output directory or create a new one
// Update robots.txt file in output directory or create a new one
$generator->updateRobots();

// submit your sitemaps to Google, Yahoo, Bing and Ask.com
// Submit your sitemaps to Google, Yahoo, Bing and Ask.com
$generator->submitSitemap();
```

Expand Down
5 changes: 3 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "icamys/php-sitemap-generator",
"version": "3.0.4",
"version": "4.0.0",
"description": "Simple PHP sitemap generator.",
"keywords": ["php", "sitemap", "generator", "psr-1", "psr-2", "psr-4"],
"homepage": "https://github.com/icamys/php-sitemap-generator",
Expand All @@ -22,7 +22,8 @@
"ext-simplexml": "*",
"ext-mbstring": "*",
"ext-zlib": "*",
"ext-curl": "*"
"ext-curl": "*",
"ext-xmlwriter": "*"
},
"autoload": {
"psr-4": {"Icamys\\SitemapGenerator\\": "src/"}
Expand Down
22 changes: 11 additions & 11 deletions src/FileSystem.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,35 @@

namespace Icamys\SitemapGenerator;

class FileSystem implements FileSystemInterface
class FileSystem
{
public function file_get_contents($filepath)
{
return file_get_contents($filepath);
}

public function file_put_contents($filepath, $content)
public function file_put_contents($filepath, $content, $flags = 0)
{
return file_put_contents($filepath, $content);
return file_put_contents($filepath, $content, $flags);
}

public function gzopen($filepath, $mode)
public function file_exists($filepath)
{
return gzopen($filepath, $mode);
return file_exists($filepath);
}

public function gzwrite($file, $content)
public function rename($oldname, $newname)
{
return gzwrite($file, $content);
return rename($oldname, $newname);
}

public function gzclose($file)
public function copy($source, $destination)
{
return gzclose($file);
return copy($source, $destination);
}

public function file_exists($filepath)
public function unlink($filepath)
{
return file_exists($filepath);
return unlink($filepath);
}
}
18 changes: 0 additions & 18 deletions src/FileSystemInterface.php

This file was deleted.

27 changes: 26 additions & 1 deletion src/Runtime.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,35 @@

namespace Icamys\SitemapGenerator;

class Runtime implements RuntimeInterface
class Runtime
{
public function extension_loaded($extname)
{
return extension_loaded($extname);
}

public function is_writable($filepath)
{
return is_writable($filepath);
}

public function curl_init($url)
{
return curl_init($url);
}

public function curl_setopt($handle, $option, $value)
{
return curl_setopt($handle, $option, $value);
}

public function curl_exec($handle)
{
return curl_exec($handle);
}

public function curl_getinfo($handle, $option = null)
{
return curl_getinfo($handle, $option);
}
}
8 changes: 0 additions & 8 deletions src/RuntimeInterface.php

This file was deleted.

Loading

0 comments on commit b43cbc1

Please sign in to comment.