/** * Output sitemap * * @return string */ public function main() { global $TSFE, $TYPO3_DB, $TYPO3_CONF_VARS; // INIT $this->tsSetup = $TSFE->tmpl->setup['plugin.']['tq_seo.']['sitemap.']; // check if sitemap is enabled in root if (!tx_tqseo_tools::getRootSettingValue('is_sitemap', true)) { $this->showError('Sitemap is not available, please check your configuration [control-center]'); } $ret .= $this->_build(); return $ret; }
/** * Execute task */ public function execute() { // Build sitemap $rootPageList = $this->_getRootPages(); $this->_cleanupDirectory(); $this->_initLanguages(); foreach ($rootPageList as $uid => $page) { $this->_initRootPage($uid); if (tx_tqseo_tools::getRootSettingValue('is_sitemap_language_lock', false, $uid)) { foreach ($this->_languageIdList as $languageId) { $this->_setRootPageLanguage($languageId); $this->_buildSitemap($uid, $languageId); } } else { $this->_buildSitemap($uid, null); } } return true; }
/** * Create Sitemap Page * * @return string XML Sitemap */ protected function createSitemapPage() { $ret = '<?xml version="1.0" encoding="UTF-8"?>'; $ret .= '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"'; $ret .= ' xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"'; $ret .= ' xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9'; $ret .= ' http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd">'; $pagePriorityDefaultValue = (double) tx_tqseo_tools::getRootSettingValue('sitemap_priorty', 0); $pagePriorityDepthMultiplier = (double) tx_tqseo_tools::getRootSettingValue('sitemap_priorty_depth_multiplier', 0); $pagePriorityDepthModificator = (double) tx_tqseo_tools::getRootSettingValue('sitemap_priorty_depth_modificator', 0); if ($pagePriorityDefaultValue == 0) { $pagePriorityDefaultValue = 1; } if ($pagePriorityDepthMultiplier == 0) { $pagePriorityDepthMultiplier = 1; } if ($pagePriorityDepthModificator == 0) { $pagePriorityDepthModificator = 1; } ##################### # SetupTS conf ##################### foreach ($this->sitemapPages as $sitemapPage) { if (empty($this->pages[$sitemapPage['page_uid']])) { // invalid page continue; } $page = $this->pages[$sitemapPage['page_uid']]; ##################################### # Page priority ##################################### $pageDepth = $sitemapPage['page_depth']; $pageDepthBase = 1; if (!empty($sitemapPage['page_hash'])) { // page has module-content - trade as subpage ++$pageDepth; } $pageDepth -= $pagePriorityDepthModificator; if ($pageDepth > 0.1) { $pageDepthBase = 1 / $pageDepth; } $pagePriority = $pagePriorityDefaultValue * ($pageDepthBase * $pagePriorityDepthMultiplier); if (!empty($page['tx_tqseo_priority'])) { $pagePriority = $page['tx_tqseo_priority'] / 100; } $pagePriority = number_format($pagePriority, 2); if ($pagePriority > 1) { $pagePriority = '1.00'; } elseif ($pagePriority <= 0) { $pagePriority = '0.00'; } ##################################### # Page informations ##################################### // page Url $pageUrl = tx_tqseo_tools::fullUrl($sitemapPage['page_url']); // Page modification date $pageModifictionDate = date('c', $sitemapPage['tstamp']); // Page change frequency $pageChangeFrequency = NULL; if (!empty($page['tx_tqseo_change_frequency'])) { $pageChangeFrequency = (int) $page['tx_tqseo_change_frequency']; } elseif (!empty($sitemapPage['page_change_frequency'])) { $pageChangeFrequency = (int) $sitemapPage['page_change_frequency']; } if (!empty($pageChangeFrequency) && !empty($this->pageChangeFrequency[$pageChangeFrequency])) { $pageChangeFrequency = $this->pageChangeFrequency[$pageChangeFrequency]; } else { $pageChangeFrequency = NULL; } ##################################### # Sitemal page output ##################################### $ret .= '<url>'; $ret .= '<loc>' . htmlspecialchars($pageUrl) . '</loc>'; $ret .= '<lastmod>' . $pageModifictionDate . '</lastmod>'; if (!empty($pageChangeFrequency)) { $ret .= '<changefreq>' . htmlspecialchars($pageChangeFrequency) . '</changefreq>'; } $ret .= '<priority>' . $pagePriority . '</priority>'; $ret .= '</url>'; } $ret .= '</urlset>'; // Call hook tx_tqseo_tools::callHook('sitemap-xml-page-output', $this, $ret); return $ret; }
/** * Fetch and build robots.txt */ public function main() { global $TSFE, $TYPO3_DB, $TYPO3_CONF_VARS; $settings = tx_tqseo_tools::getRootSetting(); // INIT $tsSetup = $TSFE->tmpl->setup; $cObj = $TSFE->cObj; $tsfePage = $TSFE->page; $rootPid = tx_tqseo_tools::getRootPid(); $ret = ''; $tsSetupSeo = null; if (!empty($tsSetup['plugin.']['tq_seo.']['robotsTxt.'])) { $tsSetupSeo = $tsSetup['plugin.']['tq_seo.']['robotsTxt.']; } if (!empty($tsSetup['plugin.']['tq_seo.']['sitemap.'])) { $tsSetupSeoSitemap = $tsSetup['plugin.']['tq_seo.']['sitemap.']; } // check if sitemap is enabled in root if (!tx_tqseo_tools::getRootSettingValue('is_robotstxt', true)) { return true; } $linkToStaticSitemap = tx_tqseo_tools::getRootSettingValue('is_robotstxt_sitemap_static', false); // Language lock $sitemapLanguageLock = tx_tqseo_tools::getRootSettingValue('is_sitemap_language_lock', false); $languageId = tx_tqseo_tools::getLanguageId(); ############################### # Fetch robots.txt content ############################### $settings['robotstxt'] = trim($settings['robotstxt']); if (!empty($settings['robotstxt'])) { // Custom Robots.txt $ret .= $settings['robotstxt']; } elseif ($tsSetupSeo) { // Default robots.txt $ret .= $cObj->cObjGetSingle($tsSetupSeo['default'], $tsSetupSeo['default.']); } ############################### # Fetch extra robots.txt content ############################### // User additional if (!empty($settings['robotstxt_additional'])) { $ret .= "\n\n" . $settings['robotstxt_additional']; } // Setup additional if ($tsSetupSeo) { // Default robots.txt $tmp = $cObj->cObjGetSingle($tsSetupSeo['extra'], $tsSetupSeo['extra.']); if (!empty($tmp)) { $ret .= "\n\n" . $tmp; } } ############################### # Marker ############################### if (!empty($tsSetupSeo['marker.'])) { // Init marker list $markerList = array(); $markerConfList = array(); foreach ($tsSetupSeo['marker.'] as $name => $data) { if (strpos($name, '.') === false) { $markerConfList[$name] = null; } } if ($linkToStaticSitemap) { // remove sitemap-marker because we link to static url unset($markerConfList['sitemap']); } // Fetch marker content foreach ($markerConfList as $name => $conf) { $markerList['%' . $name . '%'] = $cObj->cObjGetSingle($tsSetupSeo['marker.'][$name], $tsSetupSeo['marker.'][$name . '.']); } // generate sitemap-static marker if ($linkToStaticSitemap) { if ($sitemapLanguageLock) { $path = 'uploads/tx_tqseo/sitemap_xml/index-r' . (int) $rootPid . '-l' . (int) $languageId . '.xml.gz'; } else { $path = 'uploads/tx_tqseo/sitemap_xml/index-r' . (int) $rootPid . '.xml.gz'; } $conf = array('parameter' => $path); $markerList['%sitemap%'] = $cObj->typolink_URL($conf); } // Fix sitemap-marker url (add prefix if needed) $markerList['%sitemap%'] = tx_tqseo_tools::fullUrl($markerList['%sitemap%']); // Call hook tx_tqseo_tools::callHook('robotstxt-marker', $this, $markerList); // Apply marker list if (!empty($markerList)) { $ret = strtr($ret, $markerList); } } // Call hook tx_tqseo_tools::callHook('robotstxt-output', $this, $ret); return $ret; }
/** * Return page count * * @return integer */ public function pageCount() { $pageLimit = tx_tqseo_tools::getRootSettingValue('sitemap_page_limit', null); if (empty($pageLimit)) { $pageLimit = 1000; } $pageItems = count($this->sitemapPages); $pageCount = ceil($pageItems / $pageLimit); return $pageCount; }
/** * Hook: Link Parser * * @param object $pObj Object */ public static function hook_linkParse(&$pObj) { global $TSFE; // check if sitemap is enabled in root if (!tx_tqseo_tools::getRootSettingValue('is_sitemap', true) || !tx_tqseo_tools::getRootSettingValue('is_sitemap_typolink_indexer', true)) { return true; } // skip POST-calls and feuser login if ($_SERVER['REQUEST_METHOD'] !== 'GET' || !empty($TSFE->fe_user->user['uid'])) { return; } // Skip own sitemap tools if ($TSFE->type == 841131 || $TSFE->type == 841132) { return true; } // dont parse if page is not cacheable if (!$TSFE->isStaticCacheble()) { return; } // Check if (empty($pObj['finalTagParts']) || empty($pObj['conf']) || empty($pObj['finalTagParts']['url'])) { // no valid link return; } // Init link informations $linkConf = $pObj['conf']; $linkUrl = $pObj['finalTagParts']['url']; $linkUrl = self::_processLinkUrl($linkUrl); if (!is_numeric($linkConf['parameter'])) { // not valid internal link return; } ##################################### # Init ##################################### $uid = $linkConf['parameter']; $addParameters = array(); if (!empty($linkConf['additionalParams'])) { parse_str($linkConf['additionalParams'], $addParameters); } ##################################### # Check if link is cacheable ##################################### $isValid = false; // check if conf is valid if (!empty($linkConf['useCacheHash'])) { $isValid = true; } // check for typical typo3 params $addParamsCache = $addParameters; unset($addParamsCache['L']); unset($addParamsCache['type']); if (empty($addParamsCache)) { $isValid = true; } if (!$isValid) { // page is not cacheable, skip it return; } ##################################### # Rootline ##################################### $rootline = tx_tqseo_tools::getRootLine($uid); if (empty($rootline)) { return; } $page = reset($rootline); ##################################### # Build relative url ##################################### $linkParts = parse_url($linkUrl); $pageUrl = ltrim($linkParts['path'], '/'); if (!empty($linkParts['query'])) { $pageUrl .= '?' . $linkParts['query']; } ##################################### # Page settings ##################################### // Fetch page changeFrequency $pageChangeFrequency = 0; if (!empty($page['tx_tqseo_change_frequency'])) { $pageChangeFrequency = (int) $page['tx_tqseo_change_frequency']; } elseif (!empty($TSFE->tmpl->setup['plugin.']['tq_seo.']['sitemap.']['changeFrequency'])) { $pageChangeFrequency = (int) $TSFE->tmpl->setup['plugin.']['tq_seo.']['sitemap.']['changeFrequency']; } // Fetch sysLanguage $pageLanguage = 0; if (isset($addParameters['L'])) { $pageLanguage = (int) $addParameters['L']; } elseif (!empty($TSFE->tmpl->setup['config.']['sys_language_uid'])) { $pageLanguage = (int) $TSFE->tmpl->setup['config.']['sys_language_uid']; } ##################################### # Indexing ##################################### $tstamp = $_SERVER['REQUEST_TIME']; $pageData = array('tstamp' => $tstamp, 'crdate' => $tstamp, 'page_rootpid' => $rootline[0]['uid'], 'page_uid' => $linkConf['parameter'], 'page_language' => $pageLanguage, 'page_url' => $pageUrl, 'page_hash' => md5($pageUrl), 'page_depth' => count($rootline), 'page_change_frequency' => $pageChangeFrequency); // Call hook tx_tqseo_tools::callHook('sitemap-index-link', null, $pageData); if (!empty($pageData)) { tx_tqseo_sitemap::index($pageData, 'link'); } return true; }