Version 4.5.0
This commit is contained in:
1 parent
1a0c7fd3c2
commit
f79dcf067a
3791 files changed
+248032
-76372
No files matched your search
+51
-28
@@ -11,7 +11,7 @@
|
||||
namespace IPS;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
{
|
||||
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
exit;
|
||||
@@ -25,7 +25,7 @@ class _Sitemap
|
||||
/**
|
||||
* @brief Maximum number of entries to include per file
|
||||
*/
|
||||
const MAX_PER_FILE = 500;
|
||||
const MAX_PER_FILE = 2000;
|
||||
|
||||
/**
|
||||
* @brief Count options
|
||||
@@ -58,38 +58,56 @@ class _Sitemap
|
||||
$this->sitemapUrl = ( \IPS\Settings::i()->sitemap_url ) ? rtrim( \IPS\Settings::i()->sitemap_url, '/' ) : rtrim( \IPS\Settings::i()->base_url, '/' ) . '/sitemap.php';
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Store the sitemap files we can build
|
||||
*/
|
||||
protected $sitemapFilesToBuild = NULL;
|
||||
|
||||
/**
|
||||
* Build the sitemap index file
|
||||
*
|
||||
* @return void
|
||||
* @return bool
|
||||
*/
|
||||
public function buildNextSitemap()
|
||||
{
|
||||
/* Figure out supported sitemap files */
|
||||
$files = array();
|
||||
/* Get our extensions */
|
||||
$extensions = \IPS\Application::allExtensions( 'core', 'Sitemap', new \IPS\Member, 'core' );
|
||||
foreach ( $extensions as $extension )
|
||||
{
|
||||
$files = array_merge( $files, $extension->getFilenames() );
|
||||
}
|
||||
|
||||
/* Delete any that aren't supported */
|
||||
\IPS\Db::i()->delete( 'core_sitemap', \IPS\Db::i()->in( 'sitemap', $files, TRUE ) );
|
||||
/* If we haven't figured out which files we can/should build, do that first */
|
||||
if( $this->sitemapFilesToBuild === NULL )
|
||||
{
|
||||
$this->sitemapFilesToBuild = array();
|
||||
|
||||
/* Now figure out which one hasn't run in the longest period of time. */
|
||||
$sitemapsNotBuilt = array_diff( $files, iterator_to_array( \IPS\Db::i()->select( 'sitemap', 'core_sitemap' ) ) );
|
||||
if ( count( $sitemapsNotBuilt ) )
|
||||
{
|
||||
$toBuild = array_shift( $sitemapsNotBuilt );
|
||||
}
|
||||
else
|
||||
{
|
||||
try
|
||||
/* Figure out supported sitemap files */
|
||||
$files = array();
|
||||
foreach ( $extensions as $extension )
|
||||
{
|
||||
$toBuild = \IPS\Db::i()->select( 'sitemap', 'core_sitemap', NULL, 'updated ASC', 1 )->first();
|
||||
$files = array_merge( $files, $extension->getFilenames() );
|
||||
}
|
||||
|
||||
/* Delete any that aren't supported */
|
||||
\IPS\Db::i()->delete( 'core_sitemap', \IPS\Db::i()->in( 'sitemap', $files, TRUE ) );
|
||||
|
||||
/* Now figure out which one hasn't run in the longest period of time. */
|
||||
$sitemapsNotBuilt = array_diff( $files, iterator_to_array( \IPS\Db::i()->select( 'sitemap', 'core_sitemap' ) ) );
|
||||
if ( \count( $sitemapsNotBuilt ) )
|
||||
{
|
||||
$this->sitemapFilesToBuild = $sitemapsNotBuilt;
|
||||
}
|
||||
|
||||
foreach( \IPS\Db::i()->select( 'sitemap', 'core_sitemap', array( 'updated < ?', ( new \IPS\DateTime )->sub( new \DateInterval( 'PT1H' ) )->getTimestamp() ), 'updated ASC' ) as $sitemapFile )
|
||||
{
|
||||
$this->sitemapFilesToBuild[] = $sitemapFile;
|
||||
}
|
||||
catch ( \UnderflowException $e ) { }
|
||||
}
|
||||
|
||||
/* If there are no files to build, return now */
|
||||
if( !\count( $this->sitemapFilesToBuild ) )
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
$toBuild = array_shift( $this->sitemapFilesToBuild );
|
||||
|
||||
/* Do it */
|
||||
if( $toBuild )
|
||||
@@ -97,7 +115,7 @@ class _Sitemap
|
||||
/* Call the plugin to generate this sitemap file */
|
||||
foreach( $extensions as $extension )
|
||||
{
|
||||
if( in_array( $toBuild, $extension->getFilenames() ) )
|
||||
if( \in_array( $toBuild, $extension->getFilenames() ) )
|
||||
{
|
||||
$extension->generateSitemap( $toBuild, $this );
|
||||
}
|
||||
@@ -105,6 +123,12 @@ class _Sitemap
|
||||
|
||||
/* And ping search engines */
|
||||
$this->pingSearchEngines();
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
else
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -127,7 +151,7 @@ class _Sitemap
|
||||
$xmlWriter->startDocument( '1.0', 'UTF-8' );
|
||||
$xmlWriter->startElementNS( NULL, 'urlset', "http://www.sitemaps.org/schemas/sitemap/0.9" );
|
||||
|
||||
if( count( $namespaces ) )
|
||||
if( \count( $namespaces ) )
|
||||
{
|
||||
foreach( $namespaces as $prefix => $urn )
|
||||
{
|
||||
@@ -137,7 +161,7 @@ class _Sitemap
|
||||
|
||||
$defaultLanguage = \IPS\Lang::load( \IPS\Lang::defaultLanguage() );
|
||||
|
||||
if( count( $entries ) )
|
||||
if( \count( $entries ) )
|
||||
{
|
||||
foreach( $entries as $entry )
|
||||
{
|
||||
@@ -168,7 +192,7 @@ class _Sitemap
|
||||
$xmlWriter->endElement();
|
||||
}
|
||||
|
||||
if( count( $namespaces ) )
|
||||
if( \count( $namespaces ) )
|
||||
{
|
||||
foreach( $entry as $key => $value )
|
||||
{
|
||||
@@ -184,7 +208,7 @@ class _Sitemap
|
||||
$pieces = explode( ':', $k );
|
||||
$xmlWriter->startElementNS( $pieces[0], $pieces[1], NULL );
|
||||
|
||||
if( is_array( $v ) )
|
||||
if( \is_array( $v ) )
|
||||
{
|
||||
foreach( $v as $index => $value )
|
||||
{
|
||||
@@ -243,7 +267,6 @@ class _Sitemap
|
||||
/* Search engines don't want to receive more than one ping in a 24 hour period */
|
||||
if( \IPS\Settings::i()->sitemap_last_ping > time() - 86400 )
|
||||
{
|
||||
$this->log[] = 'sitemap_ping_already24';
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user