/** * Get list of root pages in current typo3 * * @return array */ protected function _initLanguages() { $this->_languageIdList[0] = 0; $query = 'SELECT uid FROM sys_language WHERE hidden = 0'; $this->_languageIdList = DatabaseUtility::getColWithIndex($query); }
/** * Fetch list of setting entries * * @return array */ public static function getRootPageSettingList() { static $cache = NULL; if ($cache === NULL) { $query = 'SELECT seosr.* FROM tx_metaseo_setting_root seosr INNER JOIN pages p ON p.uid = seosr.pid AND p.is_siteroot = 1 AND p.deleted = 0 WHERE seosr.deleted = 0'; $cache = DatabaseUtility::getAllWithIndex($query, 'pid'); } return $cache; }
protected function _getRootPageIdFromId($var) { global $TYPO3_DB; $ret = NULL; if (is_numeric($var)) { // TODO: check if var is a valid root page $ret = (int) $var; } else { $query = 'SELECT pid FROM sys_domain WHERE domainName = ' . DatabaseUtility::quote($var, 'sys_domain') . ' AND hidden = 0'; $pid = DatabaseUtility::getOne($query); if (!empty($pid)) { $ret = $pid; } } return $ret; }
/** * Delete sitemap entries * * @return boolean */ protected function _executeDelete() { $ret = FALSE; $uidList = $this->_postVar['uidList']; $rootPid = (int) $this->_postVar['pid']; $uidList = $GLOBALS['TYPO3_DB']->cleanIntArray($uidList); if (empty($uidList) || empty($rootPid)) { return FALSE; } $where = array(); $where[] = 'page_rootpid = ' . (int) $rootPid; $where[] = DatabaseUtility::conditionIn('uid', $uidList); $where = '( ' . implode(' ) AND ( ', $where) . ' )'; $res = $GLOBALS['TYPO3_DB']->exec_DELETEquery('tx_metaseo_sitemap', $where); if ($res) { $ret = TRUE; } return $ret; }
/** * 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); }
/** * Advanced meta tags * * @param array $metaTags MetaTags * @param array $tsfePage TSFE Page * @param integer $sysLanguageId Sys Language ID * @param array $customMetaTagList Custom Meta Tag list */ protected function _advMetaTags(&$metaTags, $tsfePage, $sysLanguageId, $customMetaTagList) { $tsfePageId = $tsfePage['uid']; $connector = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('Metaseo\\Metaseo\\Connector'); $storeMeta = $connector->getStore(); // ################# // Adv meta tags (from editor) // ################# $advMetaTagList = array(); $advMetaTagCondition = array(); if (!empty($storeMeta['flag']['meta:og:external'])) { // External OpenGraph support $advMetaTagCondition[] = 'tag_name NOT LIKE \'og:%\''; // Add external og-tags to adv meta tag list if (!empty($storeMeta['meta:og'])) { $advMetaTagList = array_merge($advMetaTagList, $storeMeta['meta:og']); } } if (!empty($advMetaTagCondition)) { $advMetaTagCondition = '( ' . implode(') AND (', $advMetaTagCondition) . ' )'; } else { $advMetaTagCondition = '1=1'; } // Fetch list of meta tags from database $query = 'SELECT tag_name, tag_value FROM tx_metaseo_metatag WHERE pid = ' . (int) $tsfePageId . ' AND sys_language_uid = ' . (int) $sysLanguageId . ' AND ' . $advMetaTagCondition; $advMetaTagList = DatabaseUtility::getList($query); // Add metadata to tag list foreach ($advMetaTagList as $tagName => $tagValue) { $metaTags['adv.' . $tagName] = '<meta name="' . htmlspecialchars($tagName) . '" content="' . htmlspecialchars($tagValue) . '">'; } // ################# // Custom meta tags (from connector) // ################# foreach ($customMetaTagList as $tagName => $tagValue) { $ret['adv.' . $tagName] = '<meta name="' . htmlspecialchars($tagName) . '" content="' . htmlspecialchars($tagValue) . '">'; } }
/** * Update field in page table * * @param integer $pid PID * @param integer|NULL $sysLanguage System language id * @param string $fieldName Field name * @param string $fieldValue Field value * @return array */ protected function _updatePageTableField($pid, $sysLanguage, $fieldName, $fieldValue) { $tableName = 'pages'; if (!empty($sysLanguage)) { // check if field is in overlay if ($this->_isFieldInTcaTable('pages_language_overlay', $fieldName)) { // Field is in pages language overlay $tableName = 'pages_language_overlay'; } } switch ($tableName) { case 'pages_language_overlay': // Update field in pages overlay (also logs update event and clear cache for this page) // check uid of pages language overlay $query = 'SELECT uid FROM pages_language_overlay WHERE pid = ' . (int) $pid . ' AND sys_language_uid = ' . (int) $sysLanguage; $overlayId = DatabaseUtility::getOne($query); if (!empty($overlayId)) { // ################ // UPDATE // ################ $this->_tce()->updateDB('pages_language_overlay', (int) $overlayId, array($fieldName => $fieldValue)); } else { // No access return array('error' => $GLOBALS['LANG']->getLL('error.no_language_overlay_found')); } break; case 'pages': // Update field in page (also logs update event and clear cache for this page) $this->_tce()->updateDB('pages', (int) $pid, array($fieldName => $fieldValue)); break; } }
/** * Return list of sitemap pages * * @param integer $rootPid Root page id of tree * @param integer $languageId Limit to language id * @return boolean|array */ public static function getList($rootPid, $languageId = NULL) { $sitemapList = array(); $pageList = array(); $typo3Pids = array(); $query = 'SELECT ts.* FROM tx_metaseo_sitemap ts INNER JOIN pages p ON p.uid = ts.page_uid AND p.deleted = 0 AND p.hidden = 0 AND p.tx_metaseo_is_exclude = 0 WHERE ts.page_rootpid = ' . (int) $rootPid . ' AND ts.is_blacklisted = 0'; if ($languageId !== NULL) { $query .= ' AND ts.page_language = ' . (int) $languageId; } $query .= ' ORDER BY ts.page_depth ASC, p.pid ASC, p.sorting ASC'; $resultRows = DatabaseUtility::getAll($query); if (!$resultRows) { return FALSE; } foreach ($resultRows as $row) { $sitemapList[] = $row; $sitemapPageId = $row['page_uid']; $typo3Pids[$sitemapPageId] = (int) $sitemapPageId; } if (!empty($typo3Pids)) { $query = 'SELECT * FROM pages WHERE ' . DatabaseUtility::conditionIn('uid', $typo3Pids); $pageList = DatabaseUtility::getAllWithIndex($query, 'uid'); if (empty($pageList)) { return FALSE; } } $ret = array('tx_metaseo_sitemap' => $sitemapList, 'pages' => $pageList); return $ret; }
/** * Clear all cache * * @return boolean */ public static function clearAll() { try { $query = 'TRUNCATE tx_metaseo_cache'; DatabaseUtility::exec($query); } catch (\Exception $e) { return FALSE; } return TRUE; }