/**
  * Gets the page title of the given page id
  *
  * @param int $pageId
  * @return string
  */
 protected function getPageTitle($pageId)
 {
     $cacheId = 'recycler-pagetitle-' . $pageId;
     if ($this->runtimeCache->has($cacheId)) {
         $pageTitle = $this->runtimeCache->get($cacheId);
     } else {
         if ($pageId === 0) {
             $pageTitle = $GLOBALS['TYPO3_CONF_VARS']['SYS']['sitename'];
         } else {
             $recordInfo = $this->tce->recordInfo('pages', $pageId, 'title');
             $pageTitle = $recordInfo['title'];
         }
         $this->runtimeCache->set($cacheId, $pageTitle);
     }
     return $pageTitle;
 }
 /**
  * Clears cache of pages where an object with the given identifier is shown
  * 
  * @param string $classIdentifier
  * @return int|mixed
  */
 public function getAutoId($classIdentifier)
 {
     $exclusiveLock = null;
     $objectIdentifier = 'autoid-' . $classIdentifier;
     $exclusiveLockAcquired = $this->acquireLock($exclusiveLock, $objectIdentifier, TRUE);
     $autoId = 0;
     if ($exclusiveLockAcquired) {
         if ($this->trackingCache->has($objectIdentifier)) {
             $autoId = $this->trackingCache->get($objectIdentifier);
         }
         $autoId++;
         $this->trackingCache->set($objectIdentifier, $autoId);
         $this->releaseLock($exclusiveLock);
     }
     return $autoId;
 }
 /**
  * Called by ajax.php / eID.php
  * Builds an extbase context and returns the response.
  * 
  * @return void
  */
 public function dispatch()
 {
     $src = \TYPO3\CMS\Core\Utility\GeneralUtility::_GP('src');
     $hash = \TYPO3\CMS\Core\Utility\GeneralUtility::_GP('hash');
     $conf = json_decode(rawurldecode(\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('conf')), true);
     /* @var $cacheHash \TYPO3\CMS\Frontend\Page\CacheHashCalculator */
     $cacheHash = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Frontend\\Page\\CacheHashCalculator');
     $calculatedHash = $cacheHash->calculateCacheHash(array('encryptionKey' => $GLOBALS['TYPO3_CONF_VARS']['SYS']['encryptionKey'], 'src' => $src, 'conf' => $conf));
     $allowProcessing = $hash == $calculatedHash;
     /**
      * check hash
      */
     if (!$allowProcessing) {
         header('HTTP/1.1 503 Service Unavailable');
         header('Status: 503 Service Unavailable');
         exit;
     }
     /**
      * check if source file exists
      */
     if (!@file_exists($src)) {
         header("HTTP/1.0 404 Not Found");
         header("Status: 404 Not Found");
         exit;
     }
     /**
      * check if target file exists and is up to date
      */
     if ($this->cache->has($hash)) {
         list($target, $sourceMDate) = $this->cache->get($hash);
         if (@file_exists($target) && @filemtime($src) === $sourceMDate) {
             header("Location:" . $target);
             exit;
         }
     }
     /**
      * generate image
      */
     $this->initialize();
     $target = $this->generateImage($src, $conf['width'], $conf['height'], $conf['minWidth'], $conf['minHeight'], $conf['maxWidth'], $conf['maxHeight']);
     $sourceMDate = @filemtime($src);
     $this->cache->set($hash, array($target, $sourceMDate));
     header("Location:" . $target);
     exit;
 }
 /**
  * @param string $id
  * @return object
  */
 public function findById($id)
 {
     $fullId = 'serialized-' . str_replace('\\', '_', get_class($this)) . '-' . $id;
     $object = null;
     if ($this->objectCache[$fullId]) {
         $object = $this->objectCache[$fullId];
     } elseif ($this->storage->has($fullId)) {
         $object = $this->unserialize($this->storage->get($fullId));
         $this->objectCache[$fullId] = $object;
     }
     return $object;
 }
Exemplo n.º 5
0
    /**
     * @param array $parameters
     * @param PageLayoutView|DatabaseRecordList $caller
     * @return string
     */
    public function addSubIcon(array $parameters, $caller = NULL)
    {
        $this->attachAssets();
        list($table, $uid, $record) = $parameters;
        $icon = NULL;
        if (NULL !== $caller) {
            $record = NULL === $record && 0 < $uid ? BackendUtility::getRecord($table, $uid) : $record;
            $cacheIdentity = $table . $uid . sha1(serialize($record));
            // filter 1: icon must not already be cached and both record and caller must be provided.
            if (TRUE === $this->cache->has($cacheIdentity)) {
                $icon = $this->cache->get($cacheIdentity);
            } elseif (NULL !== $record) {
                $field = $this->detectFirstFlexTypeFieldInTableFromPossibilities($table, array_keys($record));
                // filter 2: table must have one field defined as "flex" and record must include it.
                if (NULL !== $field && TRUE === isset($record[$field])) {
                    // we check the cache here because at this point, the cache key is decidedly
                    // unique and we have not yet consulted the (potentially costly) Provider.
                    $provider = $this->fluxService->resolvePrimaryConfigurationProvider($table, $field, $record);
                    // filter 3: a Provider must be resolved for the record.
                    if (NULL !== $provider) {
                        $form = $provider->getForm((array) $record);
                        if (NULL !== $form) {
                            $icon = MiscellaneousUtility::getIconForTemplate($form);
                            if (NULL !== $icon) {
                                $label = trim($form->getLabel());
                                $icon = '<img width="16" height="16" src="' . $icon . '" alt="' . $label . '"
									title="' . $label . '" class="" />';
                                $icon = sprintf($this->templates['iconWrapper'], $icon);
                            }
                        }
                    }
                }
                $this->cache->set($cacheIdentity, $icon);
            }
        }
        return $icon;
    }
Exemplo n.º 6
0
 /**
  * Tracks display of an object on a page
  * 
  * @param \TYPO3\CMS\Extbase\DomainObject\AbstractDomainObject $object Object to use
  * @param mixed $hash Hash or page id (depending on the type) for which the object display will be associated
  * @param string $type 'hash' (for only one hash) or 'id' (for complete page cache of a page, for all hash combinations)
  * @return void
  */
 public function trackObjectOnPage(\TYPO3\CMS\Extbase\DomainObject\AbstractDomainObject $object = NULL, $type = 'hash', $hash = false)
 {
     if ($object && !$this->ajaxDispatcher->getIsActive()) {
         $this->signalSlotDispatcher->dispatch(__CLASS__, self::SIGNAL_PreTrackObjectOnPage, array('object' => $object, 'type' => $type, 'hash' => $hash));
         if ($type) {
             switch ($type) {
                 case 'id':
                     if (!$hash) {
                         $hash = intval($this->fe->id);
                     }
                     $pageHash = 'id-' . $hash;
                     break;
                 case 'hash':
                 default:
                     if (!$hash) {
                         $hash = $this->fe->getHash();
                     }
                     $pageHash = 'hash-' . $hash;
                     break;
             }
             $objectIdentifier = $this->getObjectIdentifierForObject($object);
             $sharedLock = null;
             $sharedLockAcquired = $this->acquireLock($sharedLock, $objectIdentifier, FALSE);
             if ($sharedLockAcquired) {
                 if ($this->trackingCache->has($objectIdentifier)) {
                     $pageHashs = $this->trackingCache->get($objectIdentifier);
                     if (!in_array($pageHash, $pageHashs)) {
                         $exclusiveLock = null;
                         $exclusiveLockAcquired = $this->acquireLock($exclusiveLock, $objectIdentifier . '-e', TRUE);
                         if ($exclusiveLockAcquired) {
                             $pageHashs = $this->trackingCache->get($objectIdentifier);
                             if (!in_array($pageHash, $pageHashs)) {
                                 $pageHashs[] = $pageHash;
                                 $this->trackingCache->set($objectIdentifier, array_unique($pageHashs));
                             }
                             $this->releaseLock($exclusiveLock);
                         }
                     }
                 } else {
                     $this->trackingCache->set($objectIdentifier, array($pageHash));
                 }
                 $this->releaseLock($sharedLock);
             }
         }
     }
     return;
 }
Exemplo n.º 7
0
 /**
  * Returns array of arrays with an index of all references found in record from table/uid
  * If the result is used to update the sys_refindex table then ->WSOL must NOT be TRUE (no workspace overlay anywhere!)
  *
  * @param string $tableName Table name from $GLOBALS['TCA']
  * @param int $uid Record UID
  * @return array|NULL Index Rows
  * @todo Define visibility
  */
 public function generateRefIndexData($tableName, $uid)
 {
     if (!isset($GLOBALS['TCA'][$tableName])) {
         return NULL;
     }
     $this->relations = array();
     // Fetch tableRelationFields and save them in cache if not there yet
     $cacheId = static::$cachePrefixTableRelationFields . $tableName;
     if (!$this->runtimeCache->has($cacheId)) {
         $tableRelationFields = $this->fetchTableRelationFields($tableName);
         $this->runtimeCache->set($cacheId, $tableRelationFields);
     } else {
         $tableRelationFields = $this->runtimeCache->get($cacheId);
     }
     // Return if there are no fields which could contain relations
     if ($tableRelationFields === '') {
         return $this->relations;
     }
     $deleteField = $GLOBALS['TCA'][$tableName]['ctrl']['delete'];
     if ($tableRelationFields === '*') {
         // If one field of a record is of type flex, all fields have to be fetched to be passed to BackendUtility::getFlexFormDS
         $selectFields = '*';
     } else {
         // otherwise only fields that might contain relations are fetched
         $selectFields = 'uid,' . $tableRelationFields . ($deleteField ? ',' . $deleteField : '');
     }
     // Get raw record from DB:
     $record = $GLOBALS['TYPO3_DB']->exec_SELECTgetSingleRow($selectFields, $tableName, 'uid=' . (int) $uid);
     if (!is_array($record)) {
         return NULL;
     }
     // Initialize:
     $this->words_strings = array();
     $this->words = array();
     // Deleted:
     $deleted = $deleteField && $record[$deleteField] ? 1 : 0;
     // Get all relations from record:
     $recordRelations = $this->getRelations($tableName, $record);
     // Traverse those relations, compile records to insert in table:
     foreach ($recordRelations as $fieldName => $fieldRelations) {
         // Based on type,
         switch ((string) $fieldRelations['type']) {
             case 'db':
                 $this->createEntryData_dbRels($tableName, $uid, $fieldName, '', $deleted, $fieldRelations['itemArray']);
                 break;
             case 'file_reference':
                 // not used (see getRelations()), but fallback to file
             // not used (see getRelations()), but fallback to file
             case 'file':
                 $this->createEntryData_fileRels($tableName, $uid, $fieldName, '', $deleted, $fieldRelations['newValueFiles']);
                 break;
             case 'flex':
                 // DB references:
                 if (is_array($fieldRelations['flexFormRels']['db'])) {
                     foreach ($fieldRelations['flexFormRels']['db'] as $flexPointer => $subList) {
                         $this->createEntryData_dbRels($tableName, $uid, $fieldName, $flexPointer, $deleted, $subList);
                     }
                 }
                 // File references in flexforms
                 // @todo #65463 Test correct handling of file references in flexforms
                 if (is_array($fieldRelations['flexFormRels']['file'])) {
                     foreach ($fieldRelations['flexFormRels']['file'] as $flexPointer => $subList) {
                         $this->createEntryData_fileRels($tableName, $uid, $fieldName, $flexPointer, $deleted, $subList);
                     }
                 }
                 // Soft references in flexforms
                 // @todo #65464 Test correct handling of soft references in flexforms
                 if (is_array($fieldRelations['flexFormRels']['softrefs'])) {
                     foreach ($fieldRelations['flexFormRels']['softrefs'] as $flexPointer => $subList) {
                         $this->createEntryData_softreferences($tableName, $uid, $fieldName, $flexPointer, $deleted, $subList['keys']);
                     }
                 }
                 break;
         }
         // Soft references in the field:
         if (is_array($fieldRelations['softrefs'])) {
             $this->createEntryData_softreferences($tableName, $uid, $fieldName, '', $deleted, $fieldRelations['softrefs']['keys']);
         }
     }
     return $this->relations;
 }
Exemplo n.º 8
0
 /**
  * Evaluate "input" type values.
  *
  * @param string $value The value to set.
  * @param array $tcaFieldConf Field configuration from TCA
  * @param string $table Table name
  * @param int $id UID of record
  * @param int $realPid The real PID value of the record. For updates, this is just the pid of the record. For new records this is the PID of the page where it is inserted. If $realPid is -1 it means that a new version of the record is being inserted.
  * @param string $field Field name
  * @return array $res The result array. The processed value (if any!) is set in the "value" key.
  */
 protected function checkValueForInput($value, $tcaFieldConf, $table, $id, $realPid, $field)
 {
     // Handle native date/time fields
     $isDateOrDateTimeField = false;
     $format = '';
     $emptyValue = '';
     if (isset($tcaFieldConf['dbType']) && ($tcaFieldConf['dbType'] === 'date' || $tcaFieldConf['dbType'] === 'datetime')) {
         $isDateOrDateTimeField = true;
         $dateTimeFormats = $this->databaseConnection->getDateTimeFormats($table);
         // Convert the date/time into a timestamp for the sake of the checks
         $emptyValue = $dateTimeFormats[$tcaFieldConf['dbType']]['empty'];
         $format = $dateTimeFormats[$tcaFieldConf['dbType']]['format'];
         // At this point in the processing, the timestamps are still based on UTC
         $timeZone = new \DateTimeZone('UTC');
         $dateTime = \DateTime::createFromFormat('!' . $format, $value, $timeZone);
         $value = $value === $emptyValue ? 0 : $dateTime->getTimestamp();
     }
     // Secures the string-length to be less than max.
     if ((int) $tcaFieldConf['max'] > 0) {
         $value = $GLOBALS['LANG']->csConvObj->substr($GLOBALS['LANG']->charSet, (string) $value, 0, (int) $tcaFieldConf['max']);
     }
     // Checking range of value:
     // @todo: The "checkbox" option was removed for type=input, this check could be probably relaxed?
     if ($tcaFieldConf['range'] && $value != $tcaFieldConf['checkbox'] && (int) $value !== (int) $tcaFieldConf['default']) {
         if (isset($tcaFieldConf['range']['upper']) && (int) $value > (int) $tcaFieldConf['range']['upper']) {
             $value = $tcaFieldConf['range']['upper'];
         }
         if (isset($tcaFieldConf['range']['lower']) && (int) $value < (int) $tcaFieldConf['range']['lower']) {
             $value = $tcaFieldConf['range']['lower'];
         }
     }
     if (empty($tcaFieldConf['eval'])) {
         $res = array('value' => $value);
     } else {
         // Process evaluation settings:
         $cacheId = $this->getFieldEvalCacheIdentifier($tcaFieldConf['eval']);
         if ($this->runtimeCache->has($cacheId)) {
             $evalCodesArray = $this->runtimeCache->get($cacheId);
         } else {
             $evalCodesArray = GeneralUtility::trimExplode(',', $tcaFieldConf['eval'], true);
             $this->runtimeCache->set($cacheId, $evalCodesArray);
         }
         $res = $this->checkValue_input_Eval($value, $evalCodesArray, $tcaFieldConf['is_in']);
         // Process UNIQUE settings:
         // Field is NOT set for flexForms - which also means that uniqueInPid and unique is NOT available for flexForm fields! Also getUnique should not be done for versioning and if PID is -1 ($realPid<0) then versioning is happening...
         if ($field && $realPid >= 0 && !empty($res['value'])) {
             if (in_array('uniqueInPid', $evalCodesArray, true)) {
                 $res['value'] = $this->getUnique($table, $field, $res['value'], $id, $realPid);
             }
             if ($res['value'] && in_array('unique', $evalCodesArray, true)) {
                 $res['value'] = $this->getUnique($table, $field, $res['value'], $id);
             }
         }
     }
     // Handle native date/time fields
     if ($isDateOrDateTimeField) {
         // Convert the timestamp back to a date/time
         $res['value'] = $res['value'] ? date($format, $res['value']) : $emptyValue;
     }
     return $res;
 }
Exemplo n.º 9
0
 /**
  * checks if cacheentry exists for id
  *
  * @param string $id
  * @return bool
  */
 public function has($id)
 {
     return isset($this->level1Cache[$id]) || $this->level2Cache->has($id);
 }
Exemplo n.º 10
0
 /**
  * Creates a SELECT prepared SQL statement.
  *
  * @param string $select_fields See exec_SELECTquery()
  * @param string $from_table See exec_SELECTquery()
  * @param string $where_clause See exec_SELECTquery()
  * @param string $groupBy See exec_SELECTquery()
  * @param string $orderBy See exec_SELECTquery()
  * @param string $limit See exec_SELECTquery()
  * @param array $input_parameters An array of values with as many elements as there are bound parameters in the SQL statement being executed. All values are treated as \TYPO3\CMS\Core\Database\PreparedStatement::PARAM_AUTOTYPE.
  * @return \TYPO3\CMS\Core\Database\PreparedStatement Prepared statement
  */
 public function prepare_SELECTquery($select_fields, $from_table, $where_clause, $groupBy = '', $orderBy = '', $limit = '', array $input_parameters = array())
 {
     $pt = $this->debug ? GeneralUtility::milliseconds() : 0;
     $precompiledParts = array();
     if ($this->queryCache) {
         $cacheKey = 'prepare_SELECTquery-' . \TYPO3\CMS\Dbal\QueryCache::getCacheKey(array('selectFields' => $select_fields, 'fromTable' => $from_table, 'whereClause' => $where_clause, 'groupBy' => $groupBy, 'orderBy' => $orderBy, 'limit' => $limit));
         if ($this->queryCache->has($cacheKey)) {
             $precompiledParts = $this->queryCache->get($cacheKey);
             if ($this->debug) {
                 $data = array('args' => array($from_table, $select_fields, $where_clause, $groupBy, $orderBy, $limit, $input_parameters), 'precompiledParts' => $precompiledParts);
                 $this->debugHandler('prepare_SELECTquery (cache hit)', GeneralUtility::milliseconds() - $pt, $data);
             }
         }
     }
     $ORIG_tableName = '';
     if (empty($precompiledParts)) {
         // Map table / field names if needed:
         $ORIG_tableName = $from_table;
         // Saving table names in $ORIG_from_table since $from_table is transformed beneath:
         $parsedFromTable = array();
         $queryComponents = array();
         if ($tableArray = $this->map_needMapping($ORIG_tableName, FALSE, $parsedFromTable)) {
             $from = $parsedFromTable ? $parsedFromTable : $from_table;
             $components = $this->map_remapSELECTQueryParts($select_fields, $from, $where_clause, $groupBy, $orderBy);
             $queryComponents['SELECT'] = $components[0];
             $queryComponents['FROM'] = $components[1];
             $queryComponents['WHERE'] = $components[2];
             $queryComponents['GROUPBY'] = $components[3];
             $queryComponents['ORDERBY'] = $components[4];
             $queryComponents['parameters'] = $components[5];
         } else {
             $queryComponents = $this->getQueryComponents($select_fields, $from_table, $where_clause, $groupBy, $orderBy, $limit);
         }
         $queryComponents['ORIG_tableName'] = $ORIG_tableName;
         if (!$this->runningNative()) {
             // Quotes all fields
             $queryComponents['SELECT'] = $this->_quoteFieldNames($queryComponents['SELECT']);
             $queryComponents['FROM'] = $this->_quoteFromTables($queryComponents['FROM']);
             $queryComponents['WHERE'] = $this->_quoteWhereClause($queryComponents['WHERE']);
             $queryComponents['GROUPBY'] = $this->_quoteGroupBy($queryComponents['GROUPBY']);
             $queryComponents['ORDERBY'] = $this->_quoteOrderBy($queryComponents['ORDERBY']);
         }
         $precompiledParts = $this->precompileSELECTquery($queryComponents);
         if ($this->queryCache) {
             try {
                 $this->queryCache->set($cacheKey, $precompiledParts);
             } catch (\TYPO3\CMS\Core\Cache\Exception $e) {
                 if ($this->debug) {
                     GeneralUtility::devLog($e->getMessage(), 'dbal', 1);
                 }
             }
         }
     }
     $preparedStatement = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Database\PreparedStatement::class, '', $from_table, $precompiledParts);
     /* @var $preparedStatement \TYPO3\CMS\Core\Database\PreparedStatement */
     // Bind values to parameters
     foreach ($input_parameters as $key => $value) {
         $preparedStatement->bindValue($key, $value, \TYPO3\CMS\Core\Database\PreparedStatement::PARAM_AUTOTYPE);
     }
     if ($this->debug) {
         $data = array('args' => array($from_table, $select_fields, $where_clause, $groupBy, $orderBy, $limit, $input_parameters), 'ORIG_from_table' => $ORIG_tableName);
         $this->debugHandler('prepare_SELECTquery', GeneralUtility::milliseconds() - $pt, $data);
     }
     // Return prepared statement
     return $preparedStatement;
 }
Exemplo n.º 11
0
 /**
  * @param string $extensionKey
  * @param string $version
  * @param array $segments
  * @return array
  */
 protected function getSchemaData($extensionKey, $version, $segments)
 {
     if (FALSE === ExtensionManagementUtility::isLoaded($extensionKey)) {
         return array();
     }
     $baseCacheKey = $extensionKey . $version;
     $baseCacheKey = preg_replace('/[^a-z0-9]+/i', '-', $baseCacheKey);
     $cacheKey = $baseCacheKey . implode('', $segments);
     if (TRUE === $this->cache->has($cacheKey)) {
         return $this->cache->get($cacheKey);
     }
     $className = implode('/', $segments);
     $url = GeneralUtility::getIndpEnv('TYPO3_REQUEST_URL');
     $schemaFile = $this->getXsdStoragePathSetting() . $extensionKey . '-' . $version . '.xsd';
     $schemaFile = GeneralUtility::getFileAbsFileName($schemaFile);
     $schemaSource = shell_exec('cat ' . $schemaFile . ' | tr -cd \'[:print:]\\r\\n\\t\'');
     $document = new \DOMDocument();
     $document->validateOnParse = TRUE;
     $document->strictErrorChecking = TRUE;
     $document->loadXML($schemaSource);
     if (TRUE === $this->cache->has($baseCacheKey . 'tree')) {
         $tree = $this->cache->get($baseCacheKey . 'tree');
     } else {
         $tree = $this->buildTreeFromSchema($document);
         $this->cache->set($baseCacheKey . 'tree', $tree);
     }
     $node = $this->findCurrentViewHelperNode($document, $segments);
     $targetNamespaceUrl = $document->documentElement->getAttribute('targetNamespace');
     if (0 < count($segments)) {
         $viewHelperArguments = $this->makeArgumentDefinitions($node, $extensionKey, $className);
         $docComment = $node->getElementsByTagName('documentation')->item(0)->nodeValue;
         $additionalDocumentationFile = ExtensionManagementUtility::extPath($extensionKey, 'Documentation/Classes/ViewHelpers/' . $className . '/README.md');
         $nextDiv = FALSE;
         if (TRUE === file_exists($additionalDocumentationFile)) {
             $alerts = array('warning', 'danger', 'success', 'info');
             $additionalDocumentation = file_get_contents($additionalDocumentationFile);
             $parts = explode('```', $additionalDocumentation);
             foreach ($parts as $index => &$part) {
                 $firstText = substr($part, 0, strpos($part, LF));
                 if (TRUE === in_array($firstText, $alerts)) {
                     $part = '<span class="alert alert-' . $firstText . '"><span class="lead">' . ucfirst($firstText) . '</span><br />' . substr($part, strlen($firstText));
                     $nextDiv = TRUE;
                 } else {
                     if (TRUE === $nextDiv) {
                         $part = '</span>' . $part;
                         $nextDiv = FALSE;
                     } elseif (0 < $index) {
                         $part = '```' . $part;
                     }
                 }
             }
             $additionalDocumentation = implode('', $parts);
             $additionalDocumentation = preg_replace('/Arguments\\/([a-z0-9^\\s\\/]+)\\.md/i', $url . '#argument-$1', $additionalDocumentation);
             $additionalDocumentation = preg_replace('/(```)([a-z\\s]+)(.[\\`]{3})(```)/i', $url . '<div class="alert alert-$1">$2</div>', $additionalDocumentation);
             $docComment .= LF . LF . $additionalDocumentation;
         }
     }
     $data = array($tree, $node, $viewHelperArguments, $docComment, $targetNamespaceUrl);
     $this->cache->set($cacheKey, $data);
     return $data;
 }