Automatic pass to convert with php-cs-fixer
This commit is contained in:
125
src/Sitemap.php
125
src/Sitemap.php
@@ -1,34 +1,37 @@
|
||||
<?php
|
||||
|
||||
/** DomFramework
|
||||
* @package domframework
|
||||
* @author Dominique Fournier <dominique@fournier38.fr>
|
||||
* @license BSD
|
||||
*/
|
||||
/**
|
||||
* DomFramework
|
||||
* @package domframework
|
||||
* @author Dominique Fournier <dominique@fournier38.fr>
|
||||
* @license BSD
|
||||
*/
|
||||
|
||||
namespace Domframework;
|
||||
|
||||
/** This class allow to read the sitemaps files available in websites, and give
|
||||
* the available URL and parameters
|
||||
*/
|
||||
/**
|
||||
* This class allow to read the sitemaps files available in websites, and give
|
||||
* the available URL and parameters
|
||||
*/
|
||||
class Sitemap
|
||||
{
|
||||
/** Return an array containing the URL in sitemap associated with the
|
||||
* information of priority and changefreq (in seconds)
|
||||
* array (
|
||||
* "urls" => array (
|
||||
* [http://domain.tld/path...] => array (
|
||||
* "changefreq" => XX,
|
||||
* "priority" => ZZ),
|
||||
* ),
|
||||
* "sitemaps" => array (
|
||||
* [http://domain.tld/sitemap2] => array ("lastmod" => XX)
|
||||
* ));
|
||||
* The lastmod is return in time() based on UTC
|
||||
* @param string $content The content file to analyze
|
||||
* @param string $url The website URL
|
||||
* @return array The content of the file if it is valid
|
||||
*/
|
||||
/**
|
||||
* Return an array containing the URL in sitemap associated with the
|
||||
* information of priority and changefreq (in seconds)
|
||||
* array (
|
||||
* "urls" => array (
|
||||
* [http://domain.tld/path...] => array (
|
||||
* "changefreq" => XX,
|
||||
* "priority" => ZZ),
|
||||
* ),
|
||||
* "sitemaps" => array (
|
||||
* [http://domain.tld/sitemap2] => array ("lastmod" => XX)
|
||||
* ));
|
||||
* The lastmod is return in time() based on UTC
|
||||
* @param string $content The content file to analyze
|
||||
* @param string $url The website URL
|
||||
* @return array The content of the file if it is valid
|
||||
*/
|
||||
public function analyze($content, $url)
|
||||
{
|
||||
$finfo = new \finfo(FILEINFO_MIME_TYPE);
|
||||
@@ -49,57 +52,59 @@ class Sitemap
|
||||
}
|
||||
}
|
||||
|
||||
/** Return an array containing the URL in sitemap associated with an empty
|
||||
* array, as the Text format provide only URL, so return empty array.
|
||||
* New sitemaps files can not be defined in text format.
|
||||
* array (
|
||||
* "urls" => array (
|
||||
* [http://domain.tld/path...] => array (),
|
||||
* ),
|
||||
* "sitemaps" => array ()
|
||||
* );
|
||||
* @param string $content The content file to analyze
|
||||
* @param string $url The website URL
|
||||
* @return array The content of the file if it is valid
|
||||
*/
|
||||
/**
|
||||
* Return an array containing the URL in sitemap associated with an empty
|
||||
* array, as the Text format provide only URL, so return empty array.
|
||||
* New sitemaps files can not be defined in text format.
|
||||
* array (
|
||||
* "urls" => array (
|
||||
* [http://domain.tld/path...] => array (),
|
||||
* ),
|
||||
* "sitemaps" => array ()
|
||||
* );
|
||||
* @param string $content The content file to analyze
|
||||
* @param string $url The website URL
|
||||
* @return array The content of the file if it is valid
|
||||
*/
|
||||
public function analyzeText($content, $url)
|
||||
{
|
||||
if (strlen($content) > 10000000) {
|
||||
trigger_error("Sitemap '$url' size is too big -> skip", E_USER_ERROR);
|
||||
return array("urls" => array(), "sitemaps" => array());
|
||||
return ["urls" => [], "sitemaps" => []];
|
||||
}
|
||||
$urls = preg_split('/\r\n|\r|\n/', trim($content));
|
||||
if ($urls === array("")) {
|
||||
$urls = array();
|
||||
if ($urls === [""]) {
|
||||
$urls = [];
|
||||
}
|
||||
$urls = array_fill_keys($urls, array());
|
||||
return array("urls" => $urls, "sitemaps" => array());
|
||||
$urls = array_fill_keys($urls, []);
|
||||
return ["urls" => $urls, "sitemaps" => []];
|
||||
}
|
||||
|
||||
/** Return an array containing the URL in sitemap associated with the
|
||||
* information of priority and changefreq (in seconds)
|
||||
* array (
|
||||
* "urls" => array (
|
||||
* [http://domain.tld/path...] => array (
|
||||
* "changefreq" => XX,
|
||||
* "priority" => ZZ),
|
||||
* ),
|
||||
* "sitemaps" => array (
|
||||
* [http://domain.tld/sitemap2] => array ("lastmod" => XX)
|
||||
* ));
|
||||
* @param string $content The content file to analyze
|
||||
* @param string $url The website URL
|
||||
* @return array The content of the file if it is valid
|
||||
*/
|
||||
/**
|
||||
* Return an array containing the URL in sitemap associated with the
|
||||
* information of priority and changefreq (in seconds)
|
||||
* array (
|
||||
* "urls" => array (
|
||||
* [http://domain.tld/path...] => array (
|
||||
* "changefreq" => XX,
|
||||
* "priority" => ZZ),
|
||||
* ),
|
||||
* "sitemaps" => array (
|
||||
* [http://domain.tld/sitemap2] => array ("lastmod" => XX)
|
||||
* ));
|
||||
* @param string $content The content file to analyze
|
||||
* @param string $url The website URL
|
||||
* @return array The content of the file if it is valid
|
||||
*/
|
||||
public function analyzeXML($content, $url)
|
||||
{
|
||||
if (strlen($content) > 10000000) {
|
||||
throw new \Exception("Sitemap '$url' size is too big -> skip", 406);
|
||||
}
|
||||
$xml = @simplexml_load_string($content);
|
||||
$res = array("urls" => [], "sitemaps" => []);
|
||||
$res = ["urls" => [], "sitemaps" => []];
|
||||
foreach ($xml->sitemap as $s) {
|
||||
$tmp = array();
|
||||
$tmp = [];
|
||||
if (! isset($s->loc)) {
|
||||
trigger_error("No location in sitemap '$url'", E_USER_WARNING);
|
||||
continue;
|
||||
@@ -130,7 +135,7 @@ class Sitemap
|
||||
$res["sitemaps"][$loc] = $tmp;
|
||||
}
|
||||
foreach ($xml->url as $u) {
|
||||
$tmp = array();
|
||||
$tmp = [];
|
||||
if (! isset($u->loc)) {
|
||||
trigger_error(
|
||||
"No location in sitemap '$url' for url",
|
||||
|
||||
Reference in New Issue
Block a user