/** * 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; }
/** * @param integer $pid PID * @param integer|NULL $sysLanguage System language id * @param string|array $metaTag MetaTag name * @param string $value MetaTag value * @param integer $tagGroup MetaTag group */ protected function _updateMetaTag($pid, $sysLanguage, $metaTag, $value, $tagGroup = NULL) { $tstamp = time(); $crdate = time(); $cruserId = $GLOBALS['BE_USER']->user['uid']; $subTagName = ''; if (is_array($metaTag)) { list($metaTag, $subTagName) = $metaTag; } if ($tagGroup === NULL) { $tagGroup = 1; } $query = 'INSERT INTO tx_metaseo_metatag (pid, tstamp, crdate, cruser_id, sys_language_uid, tag_name, tag_subname, tag_value, tag_group) VALUES ( ' . (int) $pid . ', ' . (int) $tstamp . ', ' . (int) $crdate . ', ' . (int) $cruserId . ', ' . (int) $sysLanguage . ', ' . DatabaseUtility::quote($metaTag) . ', ' . DatabaseUtility::quote($subTagName) . ', ' . DatabaseUtility::quote($value) . ', ' . (int) $tagGroup . ' ) ON DUPLICATE KEY UPDATE tstamp = VALUES(tstamp), tag_value = VALUES(tag_value)'; DatabaseUtility::execInsert($query); }
/** * Clear cache entry * * @param integer $pageId Page UID * @param string $section Cache section * @param string $identifier Cache identifier * @return boolean */ public static function remove($pageId, $section, $identifier) { $pageId = (int) $pageId; try { $query = 'DELETE 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'); DatabaseUtility::exec($query); } catch (\Exception $e) { return FALSE; } return TRUE; }