/** * Get cache entry * * @param integer $pageId Page UID * @param string $section Cache section * @param string $identifier Cache identifier * @return string */ public static function get($pageId, $section, $identifier) { $ret = NULL; $query = 'SELECT cache_content FROM tx_metaseo_cache WHERE page_uid = ' . (int) $pageId . ' AND cache_section = ' . DatabaseUtility::quote($section, 'tx_metaseo_cache') . ' AND cache_identifier = ' . DatabaseUtility::quote($identifier, 'tx_metaseo_cache'); $ret = DatabaseUtility::getOne($query); return $ret; }
/** * Insert into sitemap * * @param array $pageData Page informations * @param string $type Parser type (page/link) */ public static function index($pageData, $type) { static $cache = array(); // do not index empty urls if (empty($pageData['page_url'])) { return; } // calc page hash $pageData['page_hash'] = md5($pageData['page_url']); $pageHash = $pageData['page_hash']; // Escape/Quote data unset($pageDataValue); foreach ($pageData as &$pageDataValue) { if ($pageDataValue === NULL) { $pageDataValue = 'NULL'; } elseif (is_int($pageDataValue) || is_numeric($pageDataValue)) { // Don't quote numeric/integers $pageDataValue = (int) $pageDataValue; } else { // String $pageDataValue = DatabaseUtility::quote($pageDataValue, 'tx_metaseo_sitemap'); } } unset($pageDataValue); // only process each page once to keep sql-statements at a normal level if (empty($cache[$pageHash])) { // $pageData is already quoted $query = 'SELECT uid FROM tx_metaseo_sitemap WHERE page_uid = ' . $pageData['page_uid'] . ' AND page_language = ' . $pageData['page_language'] . ' AND page_hash = ' . $pageData['page_hash']; $sitemapUid = DatabaseUtility::getOne($query); if (!empty($sitemapUid)) { $query = 'UPDATE tx_metaseo_sitemap SET tstamp = ' . $pageData['tstamp'] . ', page_rootpid = ' . $pageData['page_rootpid'] . ', page_language = ' . $pageData['page_language'] . ', page_url = ' . $pageData['page_url'] . ', page_depth = ' . $pageData['page_depth'] . ', page_change_frequency = ' . $pageData['page_change_frequency'] . ' WHERE uid = ' . (int) $sitemapUid; DatabaseUtility::exec($query); } else { // ##################################### // INSERT // ##################################### $GLOBALS['TYPO3_DB']->exec_INSERTquery('tx_metaseo_sitemap', $pageData, array_keys($pageData)); } $cache[$pageHash] = 1; } }
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; }
/** * 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; }
/** * 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; } }