Determines if the request is an event notification,
and returns the corresponding format identifier.

@static
@param  array  $requestData  = null
@param  array  $contentTypes = null
@return string
480179
public static function is_event_request($requestData = null, $contentTypes = null)
    {
        if (!$requestData) {
            $requestData = $_SERVER;
        }

        if (!$contentTypes) {
            $contentTypes = static::$eventContentTypes;
        }

        switch (false) { // All of these things must be true
            case isset($requestData['REQUEST_METHOD']):
            case $requestData['REQUEST_METHOD'] == 'POST':
            case isset($requestData['CONTENT_TYPE']):
            case in_array($requestData['CONTENT_TYPE'], $contentTypes):
                return false;
        }

        return array_search($requestData['CONTENT_TYPE'], $contentTypes);
    }
863816
private static function extractCharset(array $contentTypeParts)
    {
        foreach ($contentTypeParts as $part) {
            $elements = explode('=', $part);
            $key = trim(array_shift($elements));
            if (strtolower($key) === 'charset') {
                $value = trim(reset($elements));
                return $value ?: null;
            }
        }
        return null;
    }
987481
public function search(Request $request, array $contenttypes = null)
    {
        $q = '';
        $context = __FUNCTION__;

        if ($request->query->has('q')) {
            $q = $request->query->get('q');
        } elseif ($request->query->has($context)) {
            $q = $request->query->get($context);
        }
        $q = Input::cleanPostedData($q, false);

        $page = $this->app['pager']->getCurrentPage($context);

        // Theme value takes precedence over default config @see https://github.com/bolt/bolt/issues/3951
        $pageSize = $this->getOption('theme/search_results_records', false);
        if ($pageSize === false && !$pageSize = $this->getOption('general/search_results_records', false)) {
            $pageSize = $this->getOption('theme/listing_records', false) ?: $this->getOption('general/listing_records', 10);
        }

        $offset = ($page - 1) * $pageSize;
        $limit = $pageSize;

        // set-up filters from URL
        $filters = [];
        foreach ($request->query->all() as $key => $value) {
            if (strpos($key, '_') > 0) {
                list($contenttypeslug, $field) = explode('_', $key, 2);
                if (isset($filters[$contenttypeslug])) {
                    $filters[$contenttypeslug][$field] = $value;
                } else {
                    $contenttype = $this->getContentType($contenttypeslug);
                    if (is_array($contenttype)) {
                        $filters[$contenttypeslug] = [
                            $field => $value,
                        ];
                    }
                }
            }
        }
        if (count($filters) == 0) {
            $filters = null;
        }

        $isLegacy = $this->getOption('general/compatibility/setcontent_legacy', true);
        if ($isLegacy) {
            $result = $this->storage()->searchContent($q, $contenttypes, $filters, $limit, $offset);

            /** @var \Bolt\Pager\PagerManager $manager */
            $manager = $this->app['pager'];
            $manager
                ->createPager($context)
                ->setCount($result['no_of_results'])
                ->setTotalpages(ceil($result['no_of_results'] / $pageSize))
                ->setCurrent($page)
                ->setShowingFrom($offset + 1)
                ->setShowingTo($offset + ($result ? count($result['results']) : 0));
            ;

            $manager->setLink($this->generateUrl('search', ['q' => $q]) . '&page_search=');
        } else {
            $appCt = array_keys($this->app['query.search_config']->getSearchableTypes());
            $textQuery = '(' . join(',', $appCt) . ')/search';
            $params = [
                'filter' => $q,
                'page'   => $page,
                'limit'  => $pageSize,
            ];
            $searchResult = $this->getContent($textQuery, $params);

            $result = [
                'results' => $searchResult->getSortedResults(),
                'query'   => [
                    'sanitized_q' => strip_tags($q),
                ],
            ];
        }

        $globals = [
            'records'      => $result['results'],
            $context       => $result['query']['sanitized_q'],
            'searchresult' => $result,
        ];

        $template = $this->templateChooser()->search();

        return $this->render($template, [], $globals);
    }
1083799
public function findEmailEventType(array $eventData)
    {
        if (empty($eventData['EVENT_NAME'])) {
            throw new Exception('Empty email event type name');
        }
        $filter = ['TYPE_ID' => $eventData['EVENT_NAME']];
        if (!empty($eventData['LID'])) {
            $filter['LID'] = $eventData['LID'];
        }

        return CEventType::getList($filter)->fetch();
    }
175817
private function getLastmodifiedByContentLog($contenttypeslug, $contentid)
    {
        // Get the proper ContentType.
        $contenttype = $this->getContentType($contenttypeslug);

        // get the changelog for the requested ContentType.
        $options = ['limit' => 5, 'order' => 'date', 'direction' => 'DESC'];

        if ((int) $contentid == 0) {
            $isFiltered = false;
        } else {
            $isFiltered = true;
            $options['contentid'] = (int) $contentid;
        }

        /** @var Repository\LogChangeRepository $repo */
        $repo = $this->storage()->getRepository(Entity\LogChange::class);
        $changelog = $repo->getChangeLogByContentType($contenttype['slug'], $options);

        $context = [
            'changelog'   => $changelog,
            'contenttype' => $contenttype,
            'contentid'   => $contentid,
            'filtered'    => $isFiltered,
        ];

        return $this->render('@bolt/components/panel-lastmodified.twig', ['context' => $context]);
    }
610058
static public function contentTypeToSuffix($contentType)
    {
        $types = self::byContentType();
        return isset($types[$contentType]) ? $types[$contentType]['suffix'] : null;
    }
1277933
public function getContentType($contenttypeslug)
    {
        // Return false if empty, can't find it.
        if (empty($contenttypeslug)) {
            return false;
        }

        $contenttype = $this->app['config']->get('contenttypes/' . $contenttypeslug);

        // See if we've either given the correct contenttype, or try to find it by name or singular_name.
        if (!$contenttype) {
            // Also check for the slugified version of the content type
            $slugifiedContentType = $this->app['slugify']->slugify($contenttypeslug);
            $contenttype = $this->app['config']->get('contenttypes/' . $slugifiedContentType);

            if (!$contenttype) {
                foreach ($this->app['config']->get('contenttypes') as $key => $ct) {
                    if (
                        (isset($ct['slug']) &&
                            (($contenttypeslug === $ct['slug']) || ($slugifiedContentType === $ct['slug']))
                        ) ||
                        (isset($ct['singular_slug']) &&
                            (($contenttypeslug === $ct['singular_slug']) || ($slugifiedContentType === $ct['singular_slug']))
                        ) ||
                        $slugifiedContentType === $this->app['slugify']->slugify($ct['name']) ||
                        $slugifiedContentType === $this->app['slugify']->slugify($ct['singular_name'])
                    ) {
                        $contenttype = $ct;
                        $contenttype['key'] = $key;
                        break;
                    }
                }
            }
        }

        if (!empty($contenttype)) {
            return $contenttype;
        } else {
            return false;
        }
    }
704458
private function getContentTypeIds(array $contentTypeIdentifiers): array
    {
        $idList = [];

        foreach ($contentTypeIdentifiers as $identifier) {
            try {
                $contentType = $this->contentTypeHandler->loadByIdentifier($identifier);
                $idList[] = $contentType->id;
            } catch (APINotFoundException $e) {
                continue;
            }
        }

        return $idList;
    }
536308
public function selectHeaderContentType($contentType) {
		if (count($contentType) === 0 or (count($contentType) === 1 and $contentType[0] === '')) {
			return 'application/json';
		} elseif (preg_grep("/application\/json/i", $contentType)) {
			return 'application/json';
		} else {
			return implode(',', $contentType);
		}
	}
999992
protected function doVerifyWithPayPal($requestData)
    {
        $callerService = $this->getCommunicationService();
        $payPalPayPalRequest = $this->getPayPalRequest();
        foreach ($requestData as $requestParameterName => $requestParameterValue) {
            $payPalPayPalRequest->setParameter($requestParameterName, $requestParameterValue);
        }
        $responseDoVerifyWithPayPal = $callerService->doVerifyWithPayPal($payPalPayPalRequest, $requestData['charset']);

        return $responseDoVerifyWithPayPal;
    }
118150
public function getContentTypeDefinition($contentTypeName)
    {
        if ($this->getConfiguration()->hasContentType($contentTypeName))
        {
            $cacheKey = '[cmdl][content][' . $contentTypeName . ']';
            if ($this->repository)
            {
                $cacheKey = '[' . $this->repository->getName() . ']' . $cacheKey;
            }

            if ($this->cmdlCachingCheckLastModifiedDate)
            {
                $cacheKey .= '[' . $this->getCMDLLastModifiedDate($contentTypeName) . ']';
            }

            if ($this->getCMDLCache()->contains($cacheKey))
            {
                return unserialize($this->getCMDLCache()->fetch($cacheKey));
            }

            $cmdl = $this->getCMDLForContentType($contentTypeName);

            if ($cmdl)
            {

                $parser = $this->getParser();

                $definition = $parser->parseCMDLString($cmdl, $contentTypeName);

                if ($definition)
                {
                    $this->contentTypeDefinitions[$contentTypeName]['definition'] = $definition;
                    $this->getCMDLCache()->save($cacheKey, serialize($definition), (int)$this->cmdlCaching);

                    return $definition;
                }
            }

        }

        throw new AnyContentClientException ('Unknown content type ' . $contentTypeName);
    }
45814
public function resolveUrlAliasSchema(Content $content, ContentType $contentType = null)
    {
        if ($contentType === null) {
            $contentType = $this->contentTypeHandler->load($content->contentInfo->contentTypeId);
        }

        return $this->resolve(
            strlen($contentType->urlAliasSchema) === 0 ? $contentType->nameSchema : $contentType->urlAliasSchema,
            $contentType,
            $content->fields,
            $content->versionInfo->languageCodes
        );
    }
1234871
public function withContentType($contentType, $charset = null)
    {
        if (is_null($charset)) {
            return $this->withHeader('Content-Type', $contentType);
        }

        return $this->withHeader('Content-Type', $contentType . '; charset=' . $charset);
    }
1226190
private function getResponseType($contentType)
    {
        $length = strpos($contentType, ';') ?: null;
        $type = $length
            ? substr($contentType, 0, $length)
            : $contentType;

        return strtolower(trim($type));
    }
864546
private String getMediaType(String contentType) {
        if (contentType == null) {
            return null;
        }
        String result = contentType.toLowerCase(Locale.ENGLISH);
        int firstSemiColonIndex = result.indexOf(';');
        if (firstSemiColonIndex > -1) {
            result = result.substring(0, firstSemiColonIndex);
        }
        result = result.trim();
        return result;
    }
551384
public function getContentTypeName($contentType)
    {
        if (!$contentType instanceof ContentType) {
            try {
                $contentType = $this->contentTypeService->loadContentType($contentType);
            } catch (NotFoundException $e) {
                return '';
            }
        }

        return $contentType->getName();
    }
738360
public function getContentTypeDefinition($contentTypeName = null)
    {

        if ($contentTypeName == null) {
            $contentTypeName = $this->getCurrentContentTypeName();
        }

        return $this->readConnection->getContentTypeDefinition($contentTypeName);
    }