| Current Path : /home/digilove/public_html/plugins/content/aimyindexnow/ |
| Current File : /home/digilove/public_html/plugins/content/aimyindexnow/sitemap.php |
<?php
/* Copyright (c) 2022-2024 Aimy Extensions, Netzum Sorglos Software GmbH
*
* https://www.aimy-extensions.com/
*
* License: GNU GPLv2, see LICENSE.txt within distribution and/or
* http://www.aimy-extensions.com/software-license.html
*/
namespace Aimy\IndexNow; defined( '_JEXEC' ) or die(); use Joomla\CMS\Language\Text; use Joomla\CMS\Factory; abstract class Sitemap { static private $smLoaded = false; static private $robTxt = null; const REQUIRED_VERSION = '31.0'; const URL_ADDED = 1; const URL_UPDATED = 2; public static function loadAimySitemap() { $basedir = JPATH_ADMINISTRATOR . '/components/com_aimysitemap/'; $classes = array( 'helpers/info.php', 'Sitemap.php', 'Uri.php', 'RobotsTxt.php', 'ExcludePatterns.php' ); foreach ( $classes as $class ) { $path = $basedir . '/' . $class; if ( ! file_exists( $path ) ) { throw new \RuntimeException( '<b>Aimy IndexNow</b>: ' . Text::sprintf( 'AIMY_IN_ERR_AIMY_SITEMAP_NOT_FOUND_X', self::REQUIRED_VERSION ) ); } require_once( $path ); } $v = \AimySitemapInfo::getVersion(); if ( version_compare( $v, self::REQUIRED_VERSION, '<' ) ) { throw new \RuntimeException( '<b>Aimy IndexNow</b>: ' . Text::sprintf( 'AIMY_IN_ERR_AIMY_SITEMAP_NEEDS_UPDATE_XY', self::REQUIRED_VERSION, $v ) ); } } public static function writeXMLSitemap() { if ( ! self::$smLoaded ) { self::loadAimySitemap(); } try { $sm = new \AimySitemapSitemap(); Factory::getLanguage()->load( 'com_aimysitemap', JPATH_ADMINISTRATOR ); $rv = $sm->write_sitemap_file(); } catch ( \Exception $e ) { throw new \RuntimeException( '<b>Aimy IndexNow → Aimy Sitemap</b>: ' . $e->getMessage() ); } } public static function addOrUpdateURL( $page ) { if ( ! self::$smLoaded ) { self::loadAimySitemap(); } try { $rt = new \AimySitemapRobotsTxt( self::$robTxt ); self::$robTxt = $rt->get_txt(); if ( $rt->disallowed( $page->path ) ) { throw new \RuntimeException( Text::sprintf( 'AIMY_IN_AIMY_SITEMAP_FORBIDDEN_BY_ROBOTS_TXT_X', $page->path ) ); } if ( \AimySitemapExcludePatterns::is_excluded( $page->path ) ) { throw new \RuntimeException( Text::sprintf( 'AIMY_IN_AIMY_SITEMAP_EXCLUDED_BY_PATTERN_XY', $page->path, \AimySitemapExcludePatterns::get_last_matching_pattern() ) ); } } catch ( \Exception $e ) { throw new \RuntimeException( '<b>Aimy IndexNow → Aimy Sitemap</b>: ' . $e->getMessage() ); } $o = new \StdClass(); $u = new \AimySitemapURI( $page->path ); $o->url = $u->getResource(); $o->lang = isset( $page->lang ) ? $page->lang : '*'; $o->title = isset( $page->title ) ? $page->title : ''; $o->mtime = time(); $rv = false; try { $sm = new \AimySitemapSitemap(); $rv = $sm->add_or_update_url( $o ); } catch ( \Exception $e ) { throw new \RuntimeException( '<b>Aimy IndexNow → Aimy Sitemap</b>: ' . $e->getMessage() ); } return $rv; } }