/**
  * Main action
  */
 public function mainAction()
 {
     // #################
     // Root page list
     // #################
     $rootPageList = \Metaseo\Metaseo\Utility\BackendUtility::getRootPageList();
     $rootIdList = array_keys($rootPageList);
     $rootPidCondition = NULL;
     if (!empty($rootIdList)) {
         $rootPidCondition = 'p.uid IN (' . implode(',', $rootIdList) . ')';
     } else {
         $rootPidCondition = '1=0';
     }
     // #################
     // Root setting list (w/ automatic creation)
     // #################
     // check which root lages have no root settings
     $query = 'SELECT p.uid
                 FROM pages p
                      LEFT JOIN tx_metaseo_setting_root seosr
                         ON   seosr.pid = p.uid
                          AND seosr.deleted = 0
                 WHERE ' . $rootPidCondition . '
                   AND seosr.uid IS NULL';
     $uidList = DatabaseUtility::getCol($query);
     foreach ($uidList as $tmpUid) {
         $query = 'INSERT INTO tx_metaseo_setting_root (pid, tstamp, crdate, cruser_id)
                         VALUES (' . (int) $tmpUid . ',
                                 ' . (int) time() . ',
                                 ' . (int) time() . ',
                                 ' . (int) $GLOBALS['BE_USER']->user['uid'] . ')';
         DatabaseUtility::execInsert($query);
     }
     $rootSettingList = \Metaseo\Metaseo\Utility\BackendUtility::getRootPageSettingList();
     // #################
     // Domain list
     // ##################
     // Fetch domain name
     $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('uid, pid, domainName, forced', 'sys_domain', 'hidden = 0', '', 'forced DESC, sorting');
     $domainList = array();
     while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
         $domainList[$row['pid']][$row['uid']] = $row;
     }
     // #################
     // Build root page list
     // #################
     unset($page);
     foreach ($rootPageList as $pageId => &$page) {
         // Domain list
         $page['domainList'] = '';
         if (!empty($domainList[$pageId])) {
             $page['domainList'] = $domainList[$pageId];
         }
         // Settings
         $page['rootSettings'] = array();
         if (!empty($rootSettingList[$pageId])) {
             $page['rootSettings'] = $rootSettingList[$pageId];
         }
         // Settings available
         $page['settingsLink'] = \TYPO3\CMS\Backend\Utility\BackendUtility::editOnClick('&edit[tx_metaseo_setting_root][' . $rootSettingList[$pageId]['uid'] . ']=edit', $this->doc->backPath);
     }
     unset($page);
     // check if there is any root page
     if (empty($rootPageList)) {
         $message = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Messaging\\FlashMessage', $this->_translate('message.warning.noRootPage.message'), $this->_translate('message.warning.noRootPage.title'), \TYPO3\CMS\Core\Messaging\FlashMessage::WARNING);
         \TYPO3\CMS\Core\Messaging\FlashMessageQueue::addMessage($message);
     }
     // ############################
     // Page/JS
     // ############################
     // FIXME: do we really need a template engine here?
     $this->template = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Backend\\Template\\DocumentTemplate');
     $pageRenderer = $this->template->getPageRenderer();
     $basePathJs = \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extRelPath('metaseo') . 'Resources/Public/Backend/JavaScript';
     $basePathCss = \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extRelPath('metaseo') . 'Resources/Public/Backend/Css';
     $pageRenderer->addCssFile($basePathCss . '/Default.css');
     $this->view->assign('RootPageList', $rootPageList);
 }
Example #2
0
 /**
  * Return sitemap entry list for root tree
  *
  * @return    array
  */
 protected function _executeGetList()
 {
     // Init
     $rootPageList = \Metaseo\Metaseo\Utility\BackendUtility::getRootPageList();
     $rootPid = (int) $this->_postVar['pid'];
     $offset = (int) $this->_postVar['start'];
     $limit = (int) $this->_postVar['limit'];
     $itemsPerPage = (int) $this->_postVar['pagingSize'];
     $searchFulltext = trim((string) $this->_postVar['criteriaFulltext']);
     $searchPageUid = trim((int) $this->_postVar['criteriaPageUid']);
     $searchPageLanguage = trim((string) $this->_postVar['criteriaPageLanguage']);
     $searchPageDepth = trim((string) $this->_postVar['criteriaPageDepth']);
     $searchIsBlacklisted = (bool) trim((string) $this->_postVar['criteriaIsBlacklisted']);
     // ############################
     // Critera
     // ############################
     $where = array();
     // Root pid limit
     $where[] = 'page_rootpid = ' . (int) $rootPid;
     // Fulltext
     if (!empty($searchFulltext)) {
         $where[] = 'page_url LIKE ' . DatabaseUtility::quote('%' . $searchFulltext . '%', 'tx_metaseo_sitemap');
     }
     // Page id
     if (!empty($searchPageUid)) {
         $where[] = 'page_uid = ' . (int) $searchPageUid;
     }
     // Lannguage
     if ($searchPageLanguage != -1 && strlen($searchPageLanguage) >= 1) {
         $where[] = 'page_language = ' . (int) $searchPageLanguage;
     }
     // Depth
     if ($searchPageDepth != -1 && strlen($searchPageDepth) >= 1) {
         $where[] = 'page_depth = ' . (int) $searchPageDepth;
     }
     if ($searchIsBlacklisted) {
         $where[] = 'is_blacklisted = 1';
     }
     // Build where
     $where = '( ' . implode(' ) AND ( ', $where) . ' )';
     // ############################
     // Pager
     // ############################
     // Fetch total count of items with this filter settings
     $query = 'SELECT COUNT(*) as count
                 FROM tx_metaseo_sitemap
                WHERE ' . $where;
     $itemCount = DatabaseUtility::getOne($query);
     // ############################
     // Sort
     // ############################
     // default sort
     $sort = 'page_depth ASC, page_uid ASC';
     if (!empty($this->_sortField) && !empty($this->_sortDir)) {
         // already filered
         $sort = $this->_sortField . ' ' . $this->_sortDir;
     }
     // ############################
     // Fetch sitemap
     // ############################
     $list = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows('uid,
          page_rootpid,
          page_uid,
          page_language,
          page_url,
          page_depth,
          is_blacklisted,
          FROM_UNIXTIME(tstamp) as tstamp,
          FROM_UNIXTIME(crdate) as crdate', 'tx_metaseo_sitemap', $where, '', $sort, $offset . ', ' . $itemsPerPage);
     $ret = array('results' => $itemCount, 'rows' => $list);
     return $ret;
 }
 /**
  * Sitemap action
  */
 public function sitemapAction()
 {
     $params = \TYPO3\CMS\Core\Utility\GeneralUtility::_GP('tx_metaseo_metaseometaseo_metaseositemap');
     $rootPid = $params['pageId'];
     if (empty($rootPid)) {
         return '';
     }
     $rootPageList = \Metaseo\Metaseo\Utility\BackendUtility::getRootPageList();
     $rootPage = $rootPageList[$rootPid];
     // ###############################
     // Fetch
     // ###############################
     $pageTsConf = \TYPO3\CMS\Backend\Utility\BackendUtility::getPagesTSconfig($rootPid);
     $languageFullList = array(0 => array('label' => $this->_translate('default.language'), 'flag' => ''));
     if (!empty($pageTsConf['mod.']['SHARED.']['defaultLanguageFlag'])) {
         $languageFullList[0]['flag'] = $pageTsConf['mod.']['SHARED.']['defaultLanguageFlag'];
     }
     if (!empty($pageTsConf['mod.']['SHARED.']['defaultLanguageLabel'])) {
         $languageFullList[0]['label'] = $pageTsConf['mod.']['SHARED.']['defaultLanguageLabel'];
     }
     // Fetch other flags
     $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('uid, title, flag', 'sys_language', 'hidden = 0');
     while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
         $languageFullList[$row['uid']] = array('label' => htmlspecialchars($row['title']), 'flag' => htmlspecialchars($row['flag']));
     }
     // Langauges
     $languageList = array();
     $languageList[] = array(-1, $this->_translate('empty.search.page_language'));
     foreach ($languageFullList as $langId => $langRow) {
         $flag = '';
         // Flag (if available)
         if (!empty($langRow['flag'])) {
             $flag .= '<span class="t3-icon t3-icon-flags t3-icon-flags-' . $langRow['flag'] . ' t3-icon-' . $langRow['flag'] . '"></span>';
             $flag .= '&nbsp;';
         }
         // label
         $label = $langRow['label'];
         $languageList[] = array($langId, $label, $flag);
     }
     // Depth
     $depthList = array();
     $depthList[] = array(-1, $this->_translate('empty.search_page_depth'));
     $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('DISTINCT page_depth', 'tx_metaseo_sitemap', 'page_rootpid = ' . (int) $rootPid);
     while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
         $depth = $row['page_depth'];
         $depthList[] = array($depth, $depth);
     }
     // ###############################
     // Page/JS
     // ###############################
     // FIXME: do we really need a template engine here?
     $this->template = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Backend\\Template\\DocumentTemplate');
     $pageRenderer = $this->template->getPageRenderer();
     $basePathJs = \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extRelPath('metaseo') . 'Resources/Public/Backend/JavaScript';
     $basePathCss = \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extRelPath('metaseo') . 'Resources/Public/Backend/Css';
     $pageRenderer->addJsFile($basePathJs . '/MetaSeo.js');
     $pageRenderer->addJsFile($basePathJs . '/Ext.ux.plugin.FitToParent.js');
     $pageRenderer->addJsFile($basePathJs . '/MetaSeo.sitemap.js');
     $pageRenderer->addCssFile($basePathCss . '/Default.css');
     $metaSeoConf = array('sessionToken' => $this->_sessionToken('metaseo_metaseo_backend_ajax_sitemapajax'), 'ajaxController' => $this->_ajaxControllerUrl('tx_metaseo_backend_ajax::sitemap'), 'pid' => (int) $rootPid, 'renderTo' => 'tx-metaseo-sitemap-grid', 'pagingSize' => 50, 'sortField' => 'crdate', 'sortDir' => 'DESC', 'filterIcon' => \TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIcon('actions-system-tree-search-open'), 'dataLanguage' => $languageList, 'dataDepth' => $depthList, 'criteriaFulltext' => '', 'criteriaPageUid' => '', 'criteriaPageLanguage' => '', 'criteriaPageDepth' => '', 'criteriaIsBlacklisted' => 0, 'languageFullList' => $languageFullList);
     $metaSeoLang = array('title' => 'title.sitemap.list', 'pagingMessage' => 'pager.results', 'pagingEmpty' => 'pager.noresults', 'sitemap_page_uid' => 'header.sitemap.page_uid', 'sitemap_page_url' => 'header.sitemap.page_url', 'sitemap_page_type' => 'header.sitemap.page_type', 'sitemap_page_depth' => 'header.sitemap.page_depth', 'sitemap_page_language' => 'header.sitemap.page_language', 'sitemap_page_is_blacklisted' => 'header.sitemap.page_is_blacklisted', 'sitemap_tstamp' => 'header.sitemap.tstamp', 'sitemap_crdate' => 'header.sitemap.crdate', 'labelSearchFulltext' => 'label.search.fulltext', 'emptySearchFulltext' => 'empty.search.fulltext', 'labelSearchPageUid' => 'label.search.page_uid', 'emptySearchPageUid' => 'empty.search.page_uid', 'labelSearchPageLanguage' => 'label.search.page_language', 'emptySearchPageLanguage' => 'empty.search.page_language', 'labelSearchPageDepth' => 'label.search.page_depth', 'emptySearchPageDepth' => 'empty.search.page_depth', 'labelSearchIsBlacklisted' => 'label.search.is_blacklisted', 'labelYes' => 'label.yes', 'labelNo' => 'label.no', 'buttonYes' => 'button.yes', 'buttonNo' => 'button.no', 'buttonDelete' => 'button.delete', 'buttonDeleteHint' => 'button.delete.hint', 'buttonBlacklist' => 'button.blacklist', 'buttonBlacklistHint' => 'button.blacklist.hint', 'buttonWhitelist' => 'button.whitelist', 'buttonWhitelistHint' => 'button.whitelist.hint', 'buttonDeleteAll' => 'button.delete_all', 'messageDeleteTitle' => 'message.delete.title', 'messageDeleteQuestion' => 'message.delete.question', 'messageDeleteAllTitle' => 'message.delete_all.title', 'messageDeleteAllQuestion' => 'message.delete_all.question', 'messageBlacklistTitle' => 'message.blacklist.title', 'messageBlacklistQuestion' => 'message.blacklist.question', 'messageWhitelistTitle' => 'message.whitelist.title', 'messageWhitelistQuestion' => 'message.whitelist.question', 'errorDeleteFailedMessage' => 'message.delete.failed_body', 'errorNoSelectedItemsBody' => 'message.no_selected_items', 'today' => 'today', 'yesterday' => 'yesterday', 'sitemapPageType' => array(0 => 'sitemap.pagetype.0', 1 => 'sitemap.pagetype.1'));
     // translate list
     $metaSeoLang = $this->_translateList($metaSeoLang);
     $metaSeoLang['title'] = sprintf($metaSeoLang['title'], $rootPage['title'], $rootPid);
     // Include Ext JS inline code
     $pageRenderer->addJsInlineCode('MetaSeo.sitemap', 'Ext.namespace("MetaSeo.sitemap");
         MetaSeo.sitemap.conf = ' . json_encode($metaSeoConf) . ';
         MetaSeo.sitemap.conf.lang = ' . json_encode($metaSeoLang) . ';
     ');
 }