Initial commit
This commit is contained in:
@@ -0,0 +1,120 @@
|
||||
<?php
|
||||
/***************************************************************
|
||||
* Copyright notice
|
||||
*
|
||||
* (c) 2007-2014 Dmitry Dulepov <dmitry.dulepov@gmail.com>
|
||||
* All rights reserved
|
||||
*
|
||||
* This script is part of the TYPO3 project. The TYPO3 project is
|
||||
* free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* The GNU General Public License can be found at
|
||||
* http://www.gnu.org/copyleft/gpl.html.
|
||||
*
|
||||
* This script is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* This copyright notice MUST APPEAR in all copies of the script!
|
||||
***************************************************************/
|
||||
|
||||
namespace DmitryDulepov\DdGooglesitemap\Generator;
|
||||
|
||||
use DmitryDulepov\DdGooglesitemap\Renderers\AbstractSitemapRenderer;
|
||||
use \TYPO3\CMS\Core\Utility\GeneralUtility;
|
||||
|
||||
/**
|
||||
* This class is a base for all sitemap generators.
|
||||
*
|
||||
* @author Dmitry Dulepov <support@snowflake.ch>
|
||||
*/
|
||||
abstract class AbstractSitemapGenerator {
|
||||
/**
|
||||
* cObject to generate links
|
||||
*
|
||||
* @var \TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer
|
||||
*/
|
||||
protected $cObj;
|
||||
|
||||
/**
|
||||
* Maximum number of items to show.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $limit;
|
||||
|
||||
/**
|
||||
* Offset to start outputting from.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $offset;
|
||||
|
||||
/**
|
||||
* A sitemap renderer
|
||||
*
|
||||
* @var AbstractSitemapRenderer
|
||||
*/
|
||||
protected $renderer;
|
||||
|
||||
/**
|
||||
* Class name to instantiate the renderer.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $rendererClass = 'DmitryDulepov\\DdGooglesitemap\\Renderers\\StandardSitemapRenderer';
|
||||
|
||||
/**
|
||||
* Initializes the instance of this class. This constructir sets starting
|
||||
* point for the sitemap to the current page id
|
||||
*/
|
||||
public function __construct() {
|
||||
$this->cObj = GeneralUtility::makeInstance('TYPO3\\CMS\\Frontend\\ContentObject\\ContentObjectRenderer');
|
||||
$this->cObj->start(array());
|
||||
|
||||
$this->offset = max(0, (int)GeneralUtility::_GET('offset'));
|
||||
$this->limit = max(0, (int)GeneralUtility::_GET('limit'));
|
||||
if ($this->limit <= 0) {
|
||||
$this->limit = 50000;
|
||||
}
|
||||
|
||||
$this->createRenderer();
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes sitemap content to the output.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function main() {
|
||||
header('Content-type: text/xml');
|
||||
if ($this->renderer) {
|
||||
echo $this->renderer->getStartTags();
|
||||
}
|
||||
$this->generateSitemapContent();
|
||||
if ($this->renderer) {
|
||||
echo $this->renderer->getEndTags();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the renderer using $this->rendererClass. Subclasses can use a
|
||||
* more flexible logic if just setting the class is not enough.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function createRenderer() {
|
||||
$this->renderer = GeneralUtility::makeInstance($this->rendererClass);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates the sitemap and echoes it to the browser.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
abstract protected function generateSitemapContent();
|
||||
}
|
||||
@@ -0,0 +1,96 @@
|
||||
<?php
|
||||
/***************************************************************
|
||||
* Copyright notice
|
||||
*
|
||||
* (c) 2007-2014 Dmitry Dulepov <dmitry.dulepov@gmail.com>
|
||||
* All rights reserved
|
||||
*
|
||||
* This script is part of the TYPO3 project. The TYPO3 project is
|
||||
* free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* The GNU General Public License can be found at
|
||||
* http://www.gnu.org/copyleft/gpl.html.
|
||||
*
|
||||
* This script is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* This copyright notice MUST APPEAR in all copies of the script!
|
||||
***************************************************************/
|
||||
|
||||
namespace DmitryDulepov\DdGooglesitemap\Generator;
|
||||
|
||||
use \TYPO3\CMS\Core\Utility\GeneralUtility;
|
||||
|
||||
/**
|
||||
* This class implements a Google sitemap.
|
||||
*
|
||||
* @author Dmitry Dulepov <dmitry.dulepov@gmail.com>
|
||||
* @package TYPO3
|
||||
* @subpackage tx_ddgooglesitemap
|
||||
*/
|
||||
class EntryPoint {
|
||||
|
||||
const DEFAULT_SITEMAP_TYPE = 'pages';
|
||||
|
||||
public function __construct() {
|
||||
@set_time_limit(300);
|
||||
$this->initTSFE();
|
||||
}
|
||||
|
||||
/**
|
||||
* Main function of the class. Outputs sitemap.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function main() {
|
||||
$sitemapType = $this->getSitemapType();
|
||||
if (isset($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['dd_googlesitemap']['sitemap'][$sitemapType])) {
|
||||
$userFuncRef = $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['dd_googlesitemap']['sitemap'][$sitemapType];
|
||||
$params = array();
|
||||
GeneralUtility::callUserFunction($userFuncRef, $params, $this);
|
||||
}
|
||||
else {
|
||||
header('HTTP/1.0 400 Bad request', true, 400);
|
||||
header('Content-type: text/plain');
|
||||
echo 'No generator found for type \'' . $sitemapType . '\'';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines what sitemap we should send
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function getSitemapType() {
|
||||
$type = GeneralUtility::_GP('sitemap');
|
||||
return ($type ?: self::DEFAULT_SITEMAP_TYPE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes TSFE and sets $GLOBALS['TSFE']
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function initTSFE() {
|
||||
$GLOBALS['TSFE'] = $tsfe = GeneralUtility::makeInstance('TYPO3\\CMS\\Frontend\\Controller\\TypoScriptFrontendController', $GLOBALS['TYPO3_CONF_VARS'], GeneralUtility::_GP('id'), '');
|
||||
/** @var \TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController $tsfe */
|
||||
$tsfe->connectToDB();
|
||||
$tsfe->initFEuser();
|
||||
\TYPO3\CMS\Frontend\Utility\EidUtility::initTCA();
|
||||
$tsfe->determineId();
|
||||
$tsfe->initTemplate();
|
||||
$tsfe->getConfigArray();
|
||||
|
||||
// Get linkVars, absRefPrefix, etc
|
||||
\TYPO3\CMS\Frontend\Page\PageGenerator::pagegenInit();
|
||||
}
|
||||
}
|
||||
|
||||
$generator = GeneralUtility::makeInstance('DmitryDulepov\\DdGooglesitemap\\Generator\\EntryPoint');
|
||||
/* @var EntryPoint $generator */
|
||||
$generator->main();
|
||||
@@ -0,0 +1,265 @@
|
||||
<?php
|
||||
/***************************************************************
|
||||
* Copyright notice
|
||||
*
|
||||
* (c) 2007-2014 Dmitry Dulepov <dmitry.dulepov@gmail.com>
|
||||
* All rights reserved
|
||||
*
|
||||
* This script is part of the TYPO3 project. The TYPO3 project is
|
||||
* free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* The GNU General Public License can be found at
|
||||
* http://www.gnu.org/copyleft/gpl.html.
|
||||
*
|
||||
* This script is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* This copyright notice MUST APPEAR in all copies of the script!
|
||||
***************************************************************/
|
||||
|
||||
namespace DmitryDulepov\DdGooglesitemap\Generator;
|
||||
|
||||
use DmitryDulepov\DdGooglesitemap\Renderers\AbstractSitemapRenderer;
|
||||
use \TYPO3\CMS\Core\Utility\GeneralUtility;
|
||||
|
||||
/**
|
||||
* This class produces sitemap for pages
|
||||
*
|
||||
* @author Dmitry Dulepov <dmitry.dulepov@gmail.com>
|
||||
* @package TYPO3
|
||||
* @subpackage tx_ddgooglesitemap
|
||||
*/
|
||||
|
||||
class PagesSitemapGenerator extends AbstractSitemapGenerator {
|
||||
|
||||
/**
|
||||
* List of page uid values to generate entries for
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $pageList = array();
|
||||
|
||||
/**
|
||||
* Number of generated items.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $generatedItemCount = 0;
|
||||
|
||||
/**
|
||||
* A sitemap renderer
|
||||
*
|
||||
* @var AbstractSitemapRenderer
|
||||
*/
|
||||
protected $renderer;
|
||||
|
||||
/** @var array */
|
||||
protected $excludedPageTypes = array(0, 3, 4, 5, 6, 7, 199, 254, 255);
|
||||
|
||||
/**
|
||||
* Hook objects for post-processing
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $hookObjects;
|
||||
|
||||
/**
|
||||
* Initializes the instance of this class. This constructir sets starting
|
||||
* point for the sitemap to the current page id
|
||||
*/
|
||||
public function __construct() {
|
||||
parent::__construct();
|
||||
|
||||
$excludePageTypes = GeneralUtility::intExplode(',', $GLOBALS['TSFE']->tmpl->setup['tx_ddgooglesitemap.']['excludePageType'], TRUE);
|
||||
if (count($excludePageTypes) > 0) {
|
||||
$this->excludedPageTypes = $excludePageTypes;
|
||||
}
|
||||
|
||||
$pid = intval($GLOBALS['TSFE']->tmpl->setup['tx_ddgooglesitemap.']['forceStartPid']);
|
||||
if ($pid === 0 || $pid == $GLOBALS['TSFE']->id) {
|
||||
$this->pageList[$GLOBALS['TSFE']->id] = array(
|
||||
'uid' => $GLOBALS['TSFE']->id,
|
||||
'SYS_LASTCHANGED' => $GLOBALS['TSFE']->page['SYS_LASTCHANGED'],
|
||||
'tx_ddgooglesitemap_lastmod' => $GLOBALS['TSFE']->page['tx_ddgooglesitemap_lastmod'],
|
||||
'tx_ddgooglesitemap_priority' => $GLOBALS['TSFE']->page['tx_ddgooglesitemap_priority'],
|
||||
'doktype' => $GLOBALS['TSFE']->page['doktype'],
|
||||
'no_search' => $GLOBALS['TSFE']->page['no_search']
|
||||
);
|
||||
}
|
||||
else {
|
||||
$page = $GLOBALS['TSFE']->sys_page->getPage($pid);
|
||||
$this->pageList[$page['uid']] = array(
|
||||
'uid' => $page['uid'],
|
||||
'SYS_LASTCHANGED' => $page['SYS_LASTCHANGED'],
|
||||
'tx_ddgooglesitemap_lastmod' => $page['tx_ddgooglesitemap_lastmod'],
|
||||
'tx_ddgooglesitemap_priority' => $page['tx_ddgooglesitemap_priority'],
|
||||
'doktype' => $page['doktype'],
|
||||
'no_search' => $page['no_search']
|
||||
);
|
||||
}
|
||||
|
||||
$this->renderer = GeneralUtility::makeInstance('DmitryDulepov\\DdGooglesitemap\\Renderers\\StandardSitemapRenderer');
|
||||
|
||||
// Prepare user defined objects (if any)
|
||||
$this->hookObjects = array();
|
||||
if (is_array($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['dd_googlesitemap']['generateSitemapForPagesClass'])) {
|
||||
foreach ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['dd_googlesitemap']['generateSitemapForPagesClass'] as $classRef) {
|
||||
$this->hookObjects[] = GeneralUtility::getUserObj($classRef);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates sitemap for pages (<url> entries in the sitemap)
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function generateSitemapContent() {
|
||||
// Workaround: we want the sysfolders back into the menu list!
|
||||
// We also exclude "Backend user section" pages.
|
||||
$GLOBALS['TSFE']->sys_page->where_hid_del = str_replace(
|
||||
'pages.doktype<200',
|
||||
'pages.doktype<>255 AND pages.doktype<>6',
|
||||
$GLOBALS['TSFE']->sys_page->where_hid_del
|
||||
);
|
||||
|
||||
while (!empty($this->pageList) && $this->generatedItemCount - $this->offset <= $this->limit) {
|
||||
$pageInfo = array_shift($this->pageList);
|
||||
if ($this->generatedItemCount >= $this->offset) {
|
||||
$this->writeSingleUrl($pageInfo);
|
||||
}
|
||||
$this->generatedItemCount++;
|
||||
|
||||
// Add subpages of this page to the end of the page list. This way
|
||||
// we get top level pages in the sitemap first, then subpages of the
|
||||
// first, second, etc pages of the top level pages and so on.
|
||||
//
|
||||
// Notice: no sorting (for speed)!
|
||||
$GLOBALS['TSFE']->sys_page->sys_language_uid = $GLOBALS['TSFE']->config['config']['sys_language_uid'];
|
||||
$morePages = $GLOBALS['TSFE']->sys_page->getMenu($pageInfo['uid'],
|
||||
'uid,doktype,no_search,l18n_cfg,SYS_LASTCHANGED,tx_ddgooglesitemap_lastmod,tx_ddgooglesitemap_priority',
|
||||
'', '', false);
|
||||
$this->removeNonTranslatedPages($morePages);
|
||||
$this->pageList = array_merge($this->pageList, array_values($morePages));
|
||||
unset($morePages);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Obtains the last modification date of the page.
|
||||
*
|
||||
* @param array $pageInfo
|
||||
* @return int
|
||||
*/
|
||||
protected function getLastMod(array $pageInfo) {
|
||||
$lastModDates = GeneralUtility::intExplode(',', $pageInfo['tx_ddgooglesitemap_lastmod']);
|
||||
$lastModDates[] = intval($pageInfo['SYS_LASTCHANGED']);
|
||||
rsort($lastModDates, SORT_NUMERIC);
|
||||
reset($lastModDates);
|
||||
|
||||
return current($lastModDates);
|
||||
}
|
||||
|
||||
/**
|
||||
* Exclude pages from given list
|
||||
*
|
||||
* @param array $pages
|
||||
* @return void
|
||||
*/
|
||||
protected function removeNonTranslatedPages(array &$pages) {
|
||||
$language = (int)$GLOBALS['TSFE']->config['config']['sys_language_uid'];
|
||||
foreach ($pages as $pageUid => $page) {
|
||||
// Hide page in default language
|
||||
if ($language === 0 && GeneralUtility::hideIfDefaultLanguage($page['l18n_cfg'])) {
|
||||
unset($pages[$pageUid]);
|
||||
}
|
||||
elseif ($language !== 0 && !isset($page['_PAGES_OVERLAY']) && GeneralUtility::hideIfNotTranslated($page['l18n_cfg'])) {
|
||||
// Hide page if no translation is set
|
||||
unset($pages[$pageUid]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the page should be included into the sitemap.
|
||||
*
|
||||
* @param array $pageInfo
|
||||
* @return bool
|
||||
*/
|
||||
protected function shouldIncludePageInSitemap(array $pageInfo) {
|
||||
return !$pageInfo['no_search'] && !in_array($pageInfo['doktype'], $this->excludedPageTypes);
|
||||
}
|
||||
|
||||
/**
|
||||
* Outputs information about single page
|
||||
*
|
||||
* @param array $pageInfo Page information (needs 'uid' and 'SYS_LASTCHANGED' columns)
|
||||
* @return void
|
||||
*/
|
||||
protected function writeSingleUrl(array $pageInfo) {
|
||||
if ($this->shouldIncludePageInSitemap($pageInfo) && ($url = $this->getPageLink($pageInfo['uid']))) {
|
||||
echo $this->renderer->renderEntry($url, $pageInfo['title'],
|
||||
$this->getLastMod($pageInfo),
|
||||
$this->getChangeFrequency($pageInfo), '', $pageInfo['tx_ddgooglesitemap_priority']);
|
||||
|
||||
// Post-process current page and possibly append data
|
||||
// @see http://forge.typo3.org/issues/45637
|
||||
foreach ($this->hookObjects as $hookObject) {
|
||||
if (is_callable(array($hookObject, 'postProcessPageInfo'))) {
|
||||
$parameters = array(
|
||||
'pageInfo' => &$pageInfo,
|
||||
'generatedItemCount' => &$this->generatedItemCount,
|
||||
'offset' => $this->offset,
|
||||
'limit' => $this->limit,
|
||||
'renderer' => $this->renderer,
|
||||
'pObj' => $this
|
||||
);
|
||||
/** @noinspection PhpUndefinedMethodInspection */
|
||||
$hookObject->postProcessPageInfo($parameters);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected function getChangeFrequency(array $pageInfo) {
|
||||
$timeValues = GeneralUtility::intExplode(',', $pageInfo['tx_ddgooglesitemap_lastmod']);
|
||||
// Remove zeros
|
||||
foreach ($timeValues as $k => $v) {
|
||||
if ($v == 0) {
|
||||
unset($timeValues[$k]);
|
||||
}
|
||||
}
|
||||
$timeValues[] = $pageInfo['SYS_LASTCHANGED'];
|
||||
$timeValues[] = time();
|
||||
sort($timeValues, SORT_NUMERIC);
|
||||
$sum = 0;
|
||||
for ($i = count($timeValues) - 1; $i > 0; $i--) {
|
||||
$sum += ($timeValues[$i] - $timeValues[$i - 1]);
|
||||
}
|
||||
$average = ($sum/(count($timeValues) - 1));
|
||||
return ($average >= 180*24*60*60 ? 'yearly' :
|
||||
($average <= 24*60*60 ? 'daily' :
|
||||
($average <= 60*60 ? 'hourly' :
|
||||
($average <= 14*24*60*60 ? 'weekly' : 'monthly'))));
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a link to a single page
|
||||
*
|
||||
* @param array $pageId Page ID
|
||||
* @return string Full URL of the page including host name (escaped)
|
||||
*/
|
||||
protected function getPageLink($pageId) {
|
||||
$conf = array(
|
||||
'parameter' => $pageId,
|
||||
'returnLast' => 'url',
|
||||
);
|
||||
$link = htmlspecialchars($this->cObj->typoLink('', $conf));
|
||||
return GeneralUtility::locationHeaderUrl($link);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,246 @@
|
||||
<?php
|
||||
/***************************************************************
|
||||
* Copyright notice
|
||||
*
|
||||
* (c) 2007-2014 Dmitry Dulepov <dmitry.dulepov@gmail.com>
|
||||
* All rights reserved
|
||||
*
|
||||
* This script is part of the TYPO3 project. The TYPO3 project is
|
||||
* free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* The GNU General Public License can be found at
|
||||
* http://www.gnu.org/copyleft/gpl.html.
|
||||
*
|
||||
* This script is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* This copyright notice MUST APPEAR in all copies of the script!
|
||||
***************************************************************/
|
||||
|
||||
namespace DmitryDulepov\DdGooglesitemap\Generator;
|
||||
|
||||
use \TYPO3\CMS\Core\Utility\GeneralUtility;
|
||||
use \TYPO3\CMS\Core\Utility\MathUtility;
|
||||
|
||||
/**
|
||||
* This class implements news sitemap
|
||||
* (http://www.google.com/support/webmasters/bin/answer.py?hl=en-nz&answer=42738)
|
||||
* for Google.
|
||||
*
|
||||
* The following URL parameters are expected:
|
||||
* - sitemap=news
|
||||
* - singlePid=<uid of the "single" tt_news view>
|
||||
* - pidList=<comma-separated list of storage pids>
|
||||
* All pids must be in the rootline of the current pid. The safest way is to call
|
||||
* this site map from the root page of the site:
|
||||
* http://example.com/?eID=dd_googlesitemap&sitemap=news&singlePid=100&pidList=101,102,115
|
||||
*
|
||||
* If you need to show news on different single view pages, make several sitemaps
|
||||
* (it is possible with Google).
|
||||
*
|
||||
* @author Dmitry Dulepov <dmitry.dulepov@gmail.com>
|
||||
* @package TYPO3
|
||||
* @subpackage tx_ddgooglesitemap
|
||||
*/
|
||||
class TtNewsSitemapGenerator extends AbstractSitemapGenerator {
|
||||
|
||||
/**
|
||||
* List of storage pages where news items are located
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $pidList = array();
|
||||
|
||||
/**
|
||||
* Indicates sitemap type
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
protected $isNewsSitemap;
|
||||
|
||||
/**
|
||||
* Single view page
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $singlePid;
|
||||
|
||||
/**
|
||||
* If true, try to get the single pid for a news item from its (first) category with fallback to $this->singlePid
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
protected $useCategorySinglePid;
|
||||
|
||||
/**
|
||||
* Creates an instance of this class
|
||||
*/
|
||||
public function __construct() {
|
||||
$this->isNewsSitemap = (GeneralUtility::_GET('type') === 'news');
|
||||
if ($this->isNewsSitemap) {
|
||||
$this->rendererClass = 'DmitryDulepov\\DdGooglesitemap\\Renderers\\NewsSitemapRenderer';
|
||||
}
|
||||
|
||||
parent::__construct();
|
||||
|
||||
$singlePid = intval(GeneralUtility::_GP('singlePid'));
|
||||
$this->singlePid = $singlePid && $this->isInRootline($singlePid) ? $singlePid : $GLOBALS['TSFE']->id;
|
||||
$this->useCategorySinglePid = (bool) GeneralUtility::_GP('useCategorySinglePid');
|
||||
|
||||
$this->validateAndcreatePageList();
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates news site map.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function generateSitemapContent() {
|
||||
if (count($this->pidList) > 0) {
|
||||
$languageCondition = '';
|
||||
$language = GeneralUtility::_GP('L');
|
||||
if (MathUtility::canBeInterpretedAsInteger($language)) {
|
||||
$languageCondition = ' AND sys_language_uid=' . $language;
|
||||
}
|
||||
|
||||
/** @noinspection PhpUndefinedMethodInspection */
|
||||
$res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*',
|
||||
'tt_news', 'pid IN (' . implode(',', $this->pidList) . ')' .
|
||||
($this->isNewsSitemap ? ' AND crdate>=' . (time() - 48*60*60) : '') .
|
||||
$languageCondition .
|
||||
$this->cObj->enableFields('tt_news'), '', 'datetime DESC',
|
||||
$this->offset . ',' . $this->limit
|
||||
);
|
||||
/** @noinspection PhpUndefinedMethodInspection */
|
||||
$rowCount = $GLOBALS['TYPO3_DB']->sql_num_rows($res);
|
||||
/** @noinspection PhpUndefinedMethodInspection */
|
||||
while (false !== ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res))) {
|
||||
$forceSinglePid = NULL;
|
||||
if ($row['category'] && $this->useCategorySinglePid) {
|
||||
$forceSinglePid = $this->getSinglePidFromCategory($row['uid']);
|
||||
}
|
||||
if (($url = $this->getNewsItemUrl($row, $forceSinglePid))) {
|
||||
echo $this->renderer->renderEntry($url, $row['title'], $row['datetime'],
|
||||
'', $row['keywords']);
|
||||
}
|
||||
}
|
||||
/** @noinspection PhpUndefinedMethodInspection */
|
||||
$GLOBALS['TYPO3_DB']->sql_free_result($res);
|
||||
|
||||
if ($rowCount === 0) {
|
||||
echo '<!-- It appears that there are no tt_news entries. If your ' .
|
||||
'news storage sysfolder is outside of the rootline, you may ' .
|
||||
'want to use the dd_googlesitemap.skipRootlineCheck=1 TS ' .
|
||||
'setup option. Beware: it is insecure and may cause certain ' .
|
||||
'undesired effects! Better move your news sysfolder ' .
|
||||
'inside the rootline! -->';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Obtains a pid for the single view from the category.
|
||||
*
|
||||
* @param int $newsId
|
||||
* @return int|null
|
||||
*/
|
||||
protected function getSinglePidFromCategory($newsId) {
|
||||
/** @noinspection PhpUndefinedMethodInspection */
|
||||
$res = $GLOBALS['TYPO3_DB']->exec_SELECT_mm_query(
|
||||
'tt_news_cat.single_pid',
|
||||
'tt_news',
|
||||
'tt_news_cat_mm',
|
||||
'tt_news_cat',
|
||||
' AND tt_news_cat_mm.uid_local = ' . intval($newsId)
|
||||
);
|
||||
/** @noinspection PhpUndefinedMethodInspection */
|
||||
$categoryRecord = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res);
|
||||
|
||||
return $categoryRecord['single_pid'] ?: NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a link to the news item
|
||||
*
|
||||
* @param array $newsRow News item
|
||||
* @param int $forceSinglePid Single View page for this news item
|
||||
* @return string
|
||||
*/
|
||||
protected function getNewsItemUrl($newsRow, $forceSinglePid = NULL) {
|
||||
$link = '';
|
||||
if (is_string($GLOBALS['TSFE']->tmpl->setup['tx_ddgooglesitemap.']['newsLink']) && is_array($GLOBALS['TSFE']->tmpl->setup['tx_ddgooglesitemap.']['newsLink'])) {
|
||||
$cObj = GeneralUtility::makeInstance('TYPO3\\CMS\\Frontend\\ContentObject\\ContentObjectRenderer');
|
||||
/** @var \TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer $cObj */
|
||||
$cObj->start($newsRow, 'tt_news');
|
||||
$cObj->setCurrentVal($forceSinglePid ?: $this->singlePid);
|
||||
$link = $cObj->cObjGetSingle($GLOBALS['TSFE']->tmpl->setup['tx_ddgooglesitemap.']['newsLink'], $GLOBALS['TSFE']->tmpl->setup['tx_ddgooglesitemap.']['newsLink']);
|
||||
unset($cObj);
|
||||
}
|
||||
if ($link == '') {
|
||||
$conf = array(
|
||||
'additionalParams' => '&tx_ttnews[tt_news]=' . $newsRow['uid'],
|
||||
'forceAbsoluteUrl' => 1,
|
||||
'parameter' => $forceSinglePid ?: $this->singlePid,
|
||||
'returnLast' => 'url',
|
||||
'useCacheHash' => true,
|
||||
);
|
||||
$link = htmlspecialchars($this->cObj->typoLink('', $conf));
|
||||
}
|
||||
return $link;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks that page list is in the rootline of the current page and excludes
|
||||
* pages that are outside of the rootline.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function validateAndcreatePageList() {
|
||||
// Get pages
|
||||
$pidList = GeneralUtility::intExplode(',', GeneralUtility::_GP('pidList'));
|
||||
// Check pages
|
||||
foreach ($pidList as $pid) {
|
||||
if ($pid && $this->isInRootline($pid)) {
|
||||
$this->pidList[$pid] = $pid;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if supplied page id and current page are in the same root line
|
||||
*
|
||||
* @param int $pid Page id to check
|
||||
* @return boolean true if page is in the root line
|
||||
*/
|
||||
protected function isInRootline($pid) {
|
||||
if (isset($GLOBALS['TSFE']->config['config']['tx_ddgooglesitemap_skipRootlineCheck'])) {
|
||||
$skipRootlineCheck = $GLOBALS['TSFE']->config['config']['tx_ddgooglesitemap_skipRootlineCheck'];
|
||||
}
|
||||
else {
|
||||
$skipRootlineCheck = $GLOBALS['TSFE']->tmpl->setup['tx_ddgooglesitemap.']['skipRootlineCheck'];
|
||||
}
|
||||
if ($skipRootlineCheck) {
|
||||
$result = true;
|
||||
}
|
||||
else {
|
||||
$result = false;
|
||||
$rootPid = intval($GLOBALS['TSFE']->tmpl->setup['tx_ddgooglesitemap.']['forceStartPid']);
|
||||
if ($rootPid == 0) {
|
||||
$rootPid = $GLOBALS['TSFE']->id;
|
||||
}
|
||||
$rootline = $GLOBALS['TSFE']->sys_page->getRootLine($pid);
|
||||
foreach ($rootline as $row) {
|
||||
if ($row['uid'] == $rootPid) {
|
||||
$result = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user