/** * Checks peak memory usage and stores data in cache for use in the report module * * @return void */ public static function peakMemoryUsage() { $peakUsage = memory_get_peak_usage(true); $memoryLimit = GeneralUtility::getBytesFromSizeMeasurement(ini_get('memory_limit')); if (is_double($memoryLimit) && $memoryLimit != 0) { if ($peakUsage / $memoryLimit >= 0.9) { /** @var $registry \TYPO3\CMS\Core\Registry */ $registry = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Registry::class); $data = array('used' => $peakUsage, 'tstamp' => $GLOBALS['EXEC_TIME'], 'url' => GeneralUtility::getIndpEnv('TYPO3_REQUEST_URL')); $registry->set('core', 'reports-peakMemoryUsage', $data); } } }
/** * Get Frontend User Group * * @return array */ protected function getFrontendUserGroupIds() { if (!$this->objectManager) { $this->objectManager = GeneralUtility::makeInstance('TYPO3\\CMS\\Extbase\\Object\\ObjectManager'); } $feGroupIds = []; $feUserId = (int) $GLOBALS['TSFE']->fe_user->user['uid']; if ($feUserId) { $frontendUserRepository = $this->objectManager->get(\TYPO3\CMS\Extbase\Domain\Repository\FrontendUserRepository::class); $feUser = $frontendUserRepository->findByUid($feUserId); $feGroups = $feUser->getUsergroup(); if ($feGroups) { foreach ($feGroups as $feGroup) { $feGroupIds[] = $feGroup->getUid(); } } } return $feGroupIds; }
/** * @param $playlistId * @return bool|\Google_Service_YouTube_PlaylistItemListResponse */ public function getPlaylistVideos($playlistId) { try { $result = []; if (isset($playlistId)) { /** @var \Google_Service_YouTube_PlaylistItemListResponse $playlistItemsResponse */ $playlistItemsResponse = $this->apiService->playlistItems->listPlaylistItems('snippet,status', array('playlistId' => $playlistId, 'maxResults' => 50)); $result[] = $playlistItemsResponse; $nextPageToken = $playlistItemsResponse->getNextPageToken(); while ($nextPageToken) { $playlistItemsResponse = $this->apiService->playlistItems->listPlaylistItems('snippet,status', array('playlistId' => $playlistId, 'maxResults' => 50, 'pageToken' => $nextPageToken)); $result[] = $playlistItemsResponse; $nextPageToken = $playlistItemsResponse->getNextPageToken(); } } $realResult = []; foreach ($result as $_ => $collectionItem) { foreach ($collectionItem as $item) { $realResult[] = $item; } } /** @var \Google_Service_YouTube_PlaylistItemListResponse $response */ $response = GeneralUtility::makeInstance(Google_Service_YouTube_PlaylistItemListResponse::class); $response->setItems($realResult); return $response; } catch (\Google_Service_Exception $e) { error_log(sprintf('YouTube Playlist Extension: A service error occurred: %s', htmlspecialchars($e->getMessage()))); } catch (\Google_Exception $e) { error_log(sprintf('YouTube Playlist Extension: An client error occurred: %s', htmlspecialchars($e->getMessage()))); } return false; }
/** * Parses mailbox headers and turns them into an array. * * Mailbox headers are a comma separated list of 'name <*****@*****.**>' combinations * or plain email addresses (or a mix of these). * The resulting array has key-value pairs where the key is either a number * (no display name in the mailbox header) and the value is the email address, * or the key is the email address and the value is the display name. * * @param string $rawAddresses Comma separated list of email addresses (optionally with display name) * @return array Parsed list of addresses. */ public static function parseAddresses($rawAddresses) { /** @var $addressParser \TYPO3\CMS\Core\Mail\Rfc822AddressesParser */ $addressParser = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Mail\Rfc822AddressesParser::class, $rawAddresses); $addresses = $addressParser->parseAddressList(); $addressList = array(); foreach ($addresses as $address) { if ($address->mailbox === '') { continue; } if ($address->personal) { // item with name found ( name <*****@*****.**> ) $addressList[$address->mailbox . '@' . $address->host] = $address->personal; } else { // item without name found ( email@example.org ) $addressList[] = $address->mailbox . '@' . $address->host; } } return $addressList; }
/** * Makes a table categorizable by adding value into the category registry. * FOR USE IN ext_localconf.php FILES or files in Configuration/TCA/Overrides/*.php Use the latter to benefit from TCA caching! * * @param string $extensionKey Extension key to be used * @param string $tableName Name of the table to be categorized * @param string $fieldName Name of the field to be used to store categories * @param array $options Additional configuration options * @see addTCAcolumns * @see addToAllTCAtypes */ public static function makeCategorizable($extensionKey, $tableName, $fieldName = 'categories', array $options = array()) { // Update the category registry $result = \TYPO3\CMS\Core\Category\CategoryRegistry::getInstance()->add($extensionKey, $tableName, $fieldName, $options); if ($result === FALSE) { $message = '\\TYPO3\\CMS\\Core\\Category\\CategoryRegistry: no category registered for table "%s". Key was already registered.'; /** @var $logger \TYPO3\CMS\Core\Log\Logger */ $logger = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Log\\LogManager')->getLogger(__CLASS__); $logger->warning(sprintf($message, $tableName)); } }
/** * @return \TYPO3\CMS\Core\Encoder\JavaScriptEncoder */ protected static function getJavaScriptEncoder() { if (empty(self::$javaScriptEncoder)) { self::$javaScriptEncoder = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Encoder\\JavaScriptEncoder'); } return self::$javaScriptEncoder; }