Пример #1
0
 /**
  * Build sitemap xml
  *
  * @return  string
  */
 public function main()
 {
     // INIT
     $this->tsSetup = $GLOBALS['TSFE']->tmpl->setup['plugin.']['metaseo.']['sitemap.'];
     // check if sitemap is enabled in root
     if (!\Metaseo\Metaseo\Utility\GeneralUtility::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 (\Metaseo\Metaseo\Utility\GeneralUtility::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;
 }
Пример #3
0
 /**
  * Hook: Link Parser
  *
  * @param   object          $pObj    Object
  * @return  boolean|null
  */
 public static function hook_linkParse(&$pObj)
 {
     // check if sitemap is enabled in root
     if (!\Metaseo\Metaseo\Utility\GeneralUtility::getRootSettingValue('is_sitemap', TRUE) || !\Metaseo\Metaseo\Utility\GeneralUtility::getRootSettingValue('is_sitemap_typolink_indexer', TRUE)) {
         return TRUE;
     }
     // check current page
     if (!self::_checkIfCurrentPageIsIndexable()) {
         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;
     }
     if (empty($linkUrl)) {
         // invalid url? should be never empty!
         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 = \Metaseo\Metaseo\Utility\GeneralUtility::getRootLine($uid);
     if (empty($rootline)) {
         return;
     }
     $page = reset($rootline);
     // #####################################
     // Build relative url
     // #####################################
     $linkParts = parse_url($linkUrl);
     // Remove left / (but only if not root page)
     if ($linkParts['path'] === '/') {
         // Link points to root page
         $pageUrl = '/';
     } else {
         // Link points to another page, strip left /
         $pageUrl = ltrim($linkParts['path'], '/');
     }
     // Add query
     if (!empty($linkParts['query'])) {
         $pageUrl .= '?' . $linkParts['query'];
     }
     // #####################################
     // Page settings
     // #####################################
     // Fetch page changeFrequency
     $pageChangeFrequency = 0;
     if (!empty($page['tx_metaseo_change_frequency'])) {
         $pageChangeFrequency = (int) $page['tx_metaseo_change_frequency'];
     } elseif (!empty($GLOBALS['TSFE']->tmpl->setup['plugin.']['metaseo.']['sitemap.']['changeFrequency'])) {
         $pageChangeFrequency = (int) $GLOBALS['TSFE']->tmpl->setup['plugin.']['metaseo.']['sitemap.']['changeFrequency'];
     }
     // Fetch sysLanguage
     $pageLanguage = 0;
     if (isset($addParameters['L'])) {
         $pageLanguage = (int) $addParameters['L'];
     } elseif (!empty($GLOBALS['TSFE']->tmpl->setup['config.']['sys_language_uid'])) {
         $pageLanguage = (int) $GLOBALS['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_depth' => count($rootline), 'page_change_frequency' => $pageChangeFrequency);
     // Call hook
     \Metaseo\Metaseo\Utility\GeneralUtility::callHook('sitemap-index-link', NULL, $pageData);
     if (!empty($pageData)) {
         \Metaseo\Metaseo\Utility\SitemapUtility::index($pageData, 'link');
     }
     return TRUE;
 }
Пример #4
0
 /**
  * Return page count
  *
  * @return integer
  */
 public function pageCount()
 {
     $pageLimit = \Metaseo\Metaseo\Utility\GeneralUtility::getRootSettingValue('sitemap_page_limit', NULL);
     if (empty($pageLimit)) {
         $pageLimit = 1000;
     }
     $pageItems = count($this->sitemapPages);
     $pageCount = ceil($pageItems / $pageLimit);
     return $pageCount;
 }
Пример #5
0
 /**
  * Fetch and build robots.txt
  */
 public function main()
 {
     $settings = \Metaseo\Metaseo\Utility\GeneralUtility::getRootSetting();
     // INIT
     $tsSetup = $GLOBALS['TSFE']->tmpl->setup;
     $cObj = $GLOBALS['TSFE']->cObj;
     $tsfePage = $GLOBALS['TSFE']->page;
     $rootPid = \Metaseo\Metaseo\Utility\GeneralUtility::getRootPid();
     $ret = '';
     $tsSetupSeo = NULL;
     if (!empty($tsSetup['plugin.']['metaseo.']['robotsTxt.'])) {
         $tsSetupSeo = $tsSetup['plugin.']['metaseo.']['robotsTxt.'];
     }
     if (!empty($tsSetup['plugin.']['metaseo.']['sitemap.'])) {
         $tsSetupSeoSitemap = $tsSetup['plugin.']['metaseo.']['sitemap.'];
     }
     // check if sitemap is enabled in root
     if (!\Metaseo\Metaseo\Utility\GeneralUtility::getRootSettingValue('is_robotstxt', TRUE)) {
         return TRUE;
     }
     $linkToStaticSitemap = \Metaseo\Metaseo\Utility\GeneralUtility::getRootSettingValue('is_robotstxt_sitemap_static', FALSE);
     // Language lock
     $sitemapLanguageLock = \Metaseo\Metaseo\Utility\GeneralUtility::getRootSettingValue('is_sitemap_language_lock', FALSE);
     $languageId = \Metaseo\Metaseo\Utility\GeneralUtility::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_metaseo/sitemap_xml/index-r' . (int) $rootPid . '-l' . (int) $languageId . '.xml.gz';
             } else {
                 $path = 'uploads/tx_metaseo/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%'] = \Metaseo\Metaseo\Utility\GeneralUtility::fullUrl($markerList['%sitemap%']);
         // Call hook
         \Metaseo\Metaseo\Utility\GeneralUtility::callHook('robotstxt-marker', $this, $markerList);
         // Apply marker list
         if (!empty($markerList)) {
             $ret = strtr($ret, $markerList);
         }
     }
     // Call hook
     \Metaseo\Metaseo\Utility\GeneralUtility::callHook('robotstxt-output', $this, $ret);
     return $ret;
 }
Пример #6
0
 /**
  * Create Sitemap Page
  *
  * @return string
  */
 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) \Metaseo\Metaseo\Utility\GeneralUtility::getRootSettingValue('sitemap_priorty', 0);
     $pagePriorityDepthMultiplier = (double) \Metaseo\Metaseo\Utility\GeneralUtility::getRootSettingValue('sitemap_priorty_depth_multiplier', 0);
     $pagePriorityDepthModificator = (double) \Metaseo\Metaseo\Utility\GeneralUtility::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_metaseo_priority'])) {
             $pagePriority = $page['tx_metaseo_priority'] / 100;
         }
         $pagePriority = number_format($pagePriority, 2);
         if ($pagePriority > 1) {
             $pagePriority = '1.00';
         } elseif ($pagePriority <= 0) {
             $pagePriority = '0.00';
         }
         // #####################################
         // Page informations
         // #####################################
         // page Url
         $pageUrl = \Metaseo\Metaseo\Utility\GeneralUtility::fullUrl($sitemapPage['page_url']);
         // Page modification date
         $pageModifictionDate = date('c', $sitemapPage['tstamp']);
         // Page change frequency
         $pageChangeFrequency = NULL;
         if (!empty($page['tx_metaseo_change_frequency'])) {
             $pageChangeFrequency = (int) $page['tx_metaseo_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
     \Metaseo\Metaseo\Utility\GeneralUtility::callHook('sitemap-xml-page-output', $this, $ret);
     return $ret;
 }