/** * Clears the URL cache according to parameters. * * @param array $parameters * @return void */ public function clearUrlCache(array $parameters) { $cacheCommand = $parameters['cacheCmd']; if (MathUtility::canBeInterpretedAsFloat($cacheCommand)) { $cacheInstance = CacheFactory::getCache(); $cacheInstance->clearUrlCacheForPage((int) $cacheCommand); } }
/** * Validates the given longitude value (between -180 and 180 degrees) * @see https://developers.google.com/maps/documentation/javascript/reference?hl=fr#LatLng * * @param mixed $value The value that has to be checked. * @param string $is_in Is-In String * @param int $set Determines if the field can be set (value correct) or not * * @return string The new value of the field */ public function evaluateFieldValue($value, $is_in, &$set) { $newValue = '0.000000'; $set = TRUE; if (MathUtility::canBeInterpretedAsFloat($value) && ((double) $value >= -180 && (double) $value <= 180)) { $newValue = number_format((double) $value, 6); } return $newValue; }
/** * @test * @dataProvider functionCanBeInterpretedAsFloatInvalidDataProvider */ public function canBeInterpretedAsFloatReturnsFalse($int) { $this->assertFalse(\TYPO3\CMS\Core\Utility\MathUtility::canBeInterpretedAsFloat($int)); }
/** * Updates the index entry for a given file. * * @param \TYPO3\CMS\Core\Resource\File $file * @param integer $width * @param integer $height * @param array $metadata EXIF metadata * @return void */ protected static function updateIndex(\TYPO3\CMS\Core\Resource\File $file = null, $width, $height, array $metadata = array()) { if (version_compare(TYPO3_version, '6.99.99', '<=')) { /** @var \TYPO3\CMS\Core\Resource\Service\IndexerService $indexerService */ $indexerService = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Resource\\Service\\IndexerService'); $indexerService->indexFile($file); } if (count($metadata) > 0) { /** @var \TYPO3\CMS\Core\Resource\Index\MetaDataRepository $metadataRepository */ $metadataRepository = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Resource\Index\MetaDataRepository::class); // Will take care of creating the record if it does not exist yet $currentMetadata = $metadataRepository->findByFile($file); $newMetadata = []; // Pre-populate with metadata coming from external extractors foreach ($currentMetadata as $key => $value) { if (!empty($metadata[$key])) { // Known issue with "creator_tool" having a software version sometimes if ($key === 'creator_tool' && MathUtility::canBeInterpretedAsFloat($metadata[$key])) { continue; } $newMetadata[$key] = $metadata[$key]; } } // Width and height are always wrong since we resized the image unset($newMetadata['width']); unset($newMetadata['height']); // We deal with resized images so unit is always pixels $newMetadata['unit'] = 'px'; // Mapping for the built-in PHP-based metadata extractor $mapping = ['color_space' => 'ColorSpace', 'content_creation_date' => 'DateTimeOriginal', 'creator' => 'IPTCCreator|Company', 'creator_tool' => 'Model|Make|Software', 'description' => 'ImageDescription', 'keywords' => 'IPTCKeywords', 'latitude' => 'GPSLatitudeDecimal', 'longitude' => 'GPSLongitudeDecimal', 'location_city' => 'IPTCCity', 'location_country' => 'IPTCCountry', 'location_region' => 'IPTCRegion', 'note' => 'IPTCLocation', 'publisher' => 'IPTCCredit', 'source' => 'IPTCSource', 'title' => 'IPTCTitle']; foreach ($mapping as $falKey => $metadataKeyMapping) { if (!empty($newMetadata[$falKey])) { // We already have a known-to-be-valid metadata for this FAL property continue; } $metatadaKeys = explode('|', $metadataKeyMapping); foreach ($metatadaKeys as $metadataKey) { $value = null; if (isset($metadata[$metadataKey])) { $value = trim($metadata[$metadataKey]); if (ord($value) === 1) { $value = null; } switch ($metadataKey) { case 'ColorSpace': if ($value == 1) { $value = 'RGB'; } else { // Unknown $value = null; } break; case 'DateTimeOriginal': $value = strtotime($value); break; } } if (!empty($value)) { $newMetadata[$falKey] = $value; break; } } } $metadataRepository->update($file->getUid(), $newMetadata); } }