Returns the extracted directives of a passed string.

@param string $directive to look for
@param string $content   to look in

@author Benjamin Carl <opensource@clickalicious.de>

@return array Of found directives or empty one if no matches
438546
protected function extractDirectives($directive, $content)
    {
        $pattern = '/{{'.$directive.'\(?([\w\.]*)\)?}}/';
        preg_match_all($pattern, $content, $result);

        return $result;
    }
494412
protected function determineExtension($content)
    {
        $filename = \Yii::getAlias('@runtime/' . uniqid());
        file_put_contents($filename, $content);

        $mime = FileHelper::getMimeType($filename);

        $extensions = FileHelper::getExtensionsByMimeType($mime);

        unlink($filename);

        return ArrayHelper::getValue($extensions, max(count($extensions) - 1, 0));
    }
1050227
static function ContentMembergroups(Content $content)
    {
        if (!$content->Exists())
        {
            return array();
        }
        $sql = Access::SqlBuilder();
        $tblCmg = ContentMembergroup::Schema()->Table();
        $tblMg = Membergroup::Schema()->Table();
        $join = $sql->Join($tblCmg);
        $joinCondition = $sql->Equals($tblCmg->Field('MemberGroup'), $tblMg->Field('ID'));
        $where = $sql->Equals($tblCmg->Field('Content'), $sql->Value($content->GetID()));
        $orderBy = $sql->OrderList($sql->OrderAsc($tblMg->Field('Name')));
        
        return Membergroup::Schema()->Fetch(false, $where, $orderBy, null, 0, null, $join, JoinType::Inner(), $joinCondition);
    }
300555
public function parse($content)
    {
        if (!$content || strpos($content, '@view') === false) {
            return [];
        }
        $ret = [];

        if (preg_match(self::VIEW_RENDER, $content, $match)) {
            $ret[0] = array_pop($match);
        } else {
            $ret[0] = null;
        }

        if (preg_match(self::VIEW_TEMPLATE_FILE, $content, $match)) {
            $ret[1] = array_pop($match);
        } else {
            $ret[1] = null;
        }

        if (preg_match_all(self::VIEW_PARAMETERS, $content, $match, PREG_SET_ORDER)) {
            $set = [];
            // "all" is excluded
            foreach ($match as $position => $group) {
                $set[$group[1]] = $group[2];
            }

            if ($set){
                $ret[] = $set;
            }

        }

        return $ret;
    }
560629
protected function detectFormatByContent($content)
    {
        if (preg_match('/^(\\{|\\[\\{).*(\\}|\\}\\])$/is', $content)) {
            return Client::FORMAT_JSON;
        }
        if (preg_match('/^([^=&])+=[^=&]+(&[^=&]+=[^=&]+)*$/', $content)) {
            return Client::FORMAT_URLENCODED;
        }
        if (preg_match('/^<\?xml.*>$/s', $content)) {
            return Client::FORMAT_XML;
        }
        return null;
    }
1275546
protected function extractMediasFromContent(ContentInterface $content)
    {
        $references = array();

        /** @var ContentAttributeInterface $attribute */
        foreach ($content->getAttributes() as $attribute) {
            $references = array_merge($references, $this->extractMediasFromElement($attribute->getValue()));
        }

        return $references;
    }
330651
protected function _getEntityAnnotations($content) {
		$loopEntityAnnotations = $this->_parseLoopEntities($content);
		$formEntityAnnotations = $this->_parseFormEntities($content);
		$entityAnnotations = $this->_parseEntities($content);

		$entityAnnotations = $loopEntityAnnotations + $formEntityAnnotations + $entityAnnotations;

		return $entityAnnotations;
	}
1070066
private function parseCodeForMethods( $content )
	{
		$this->methods	= array();																	//  reset list of found methods
		$open		= FALSE;																		//  initial: no method found, yet
		$content	= preg_replace( "@/\*.*\*/@Us", "", $content );									//  remove all slash-star-comments
//		$content	= preg_replace( '@".*"@Us', "", $content );										//  remove all strings
		$content	= preg_replace( "@'.*'@Us", "", $content );										//  remove all strings
		$content	= preg_replace( "@#.+\n@U", "", $content );										//  remove all hash-comments
		$content	= preg_replace( "@\s+\n@U", "\n", $content );									//  trailing white space
		$content	= preg_replace( "@\n\n@U", "\n", $content );									//  remove double line breaks
		$content	= preg_replace( "@//\s*[\w|\s]*\n@U", "\n", $content );							//  remove comment lines
		$matches	= array();																		//  prepare empty matches array
		$count		= 0;																			//  initial: open bracket counter
		foreach( explode( "\n", $content ) as $nr => $line )										//  iterate code lines
		{
			$line	= trim( $line );																//  remove leading and trailing white space
			if( !$open )																			//  if no method found, yet
			{
				$regExp	= '@^(abstract )?(final )?(static )?(protected |private |public )?(static )?function ([\w]+)\((.*)\)(\s*{\s*)?;?\s*$@s';	//  prepare regular expression for method/function signature
				if( preg_match( $regExp, $line ) )													//  line is method/function signature
				{
					$regExp	= "@^.*function ([^(]+) ?\((.*)\).*$@i";								//  prepare regular expression for method/function name and parameters
					$name	= preg_replace( $regExp, "\\1@@\\2", $line );							//  find method/function name and parameters
					$parts	= explode( "@@", $name );												//  split name and parameters
					$open	= trim( $parts[0] );															//  note found method/function
					$matches[$open]['variables']	= array();										//  prepare empty method/function parameter list
					$matches[$open]['lines']		= array();										//  prepare empty method/function line list
					$parts[1]	= preg_replace( '@\(.*\)@U', "", $parts[1] );										//  remove all strings
					if( isset( $parts[1] ) && trim( $parts[1] ) )									//  parameters are defined
					{
						$params	= explode( ",", $parts[1] );										//  split parameters
						foreach( $params as $param )												//  iterate parameters
						{
							$regExp		= '@^([a-z0-9_]+ )?&?\$(.+)(\s?=\s?.*)?$@Ui';				//  prepare regular expression for parameter name
							$param		= preg_replace( $regExp, "\\2", trim( $param ) );			//  get clean parameter name
							$matches[$open]['variables'][$param]	= 0;							//  note parameter in method variable list
						}
					}
					if( preg_match( "/\{$/", $line ) )												//  signature line ends with opening bracket
						$count++;																	//  increase open bracket counter
				}
			}
			else																					//  inside method code lines
			{
				$matches[$open]['lines'][$nr]	= $line;											//  note method code line for inspection
				if( preg_match( "/^\{$/", $line ) || preg_match( "/\{$/", $line ) )					//  line contains opening bracket
					$count++;																		//  increase open bracket counter
				else if( preg_match( "/^\}/", $line ) || preg_match( "/\}$/", $line ) )				//  line contains closing bracket
					if( !( --$count ) )																//  decrease open bracket counter and if all open brackets are closed
						$open	= FALSE;															//  leave method code mode
			}
		}
		$this->methods	= $matches;																	//  note all found methods and their variables
	}
730106
public function parse($content)
    {
        $result = [];
        if (strpos($content, '@view') === false) {
            return $result;
        }

        if (preg_match_all($this->pattern, $content, $matches)) {

            for ($i = 0, $c = count($matches[0]); $i < $c; $i++) {
                $result[] = [
                    'property' => $matches[1][$i],
                    'value'    => $matches[2][$i],
                    'type'     => $this->getType($matches[2][$i])
                ];
            }

            return $result;
        }

        return $result;
    }
1239325
public function getSectionsText($content)
    {
        $sections    = array();
        $content     = ' ' . $content . ' ';
        $textCleaned = $this->cleanContent($content, '_');

        // Extract text blocks.
        if (preg_match_all('/\s+BT[\s|\(|\[]+(.*?)\s*ET/s', $textCleaned, $matches, PREG_OFFSET_CAPTURE)) {
            foreach ($matches[1] as $part) {
                $text    = $part[0];
                if ($text === '') {
                    continue;
                }
                $offset  = $part[1];
                $section = substr($content, $offset, strlen($text));

                // Removes BDC and EMC markup.
                $section = preg_replace('/(\/[A-Za-z0-9]+\s*<<.*?)(>>\s*BDC)(.*?)(EMC\s+)/s', '${3}', $section . ' ');

                $sections[] = $section;
            }
        }

        // Extract 'do' commands.
        if (preg_match_all('/(\/[A-Za-z0-9\.\-_]+\s+Do)\s/s', $textCleaned, $matches, PREG_OFFSET_CAPTURE)) {
            foreach ($matches[1] as $part) {
                $text    = $part[0];
                $offset  = $part[1];
                $section = substr($content, $offset, strlen($text));

                $sections[] = $section;
            }
        }

        return $sections;
    }
1025702
protected function getFullTextValues(Content $content)
    {
        $fullTextValues = [];
        foreach ($content->fields as $field) {
            $fieldDefinition = $this->contentTypeHandler->getFieldDefinition(
                $field->fieldDefinitionId, Content\Type::STATUS_DEFINED
            );
            if (!$fieldDefinition->isSearchable) {
                continue;
            }

            $value = $this->getFullTextFieldValue($field, $fieldDefinition);
            if (empty($value)) {
                continue;
            }

            $fullTextValues[] = new FullTextValue(
                [
                    'id' => $field->id,
                    'fieldDefinitionId' => $field->fieldDefinitionId,
                    'fieldDefinitionIdentifier' => $fieldDefinition->identifier,
                    'languageCode' => $field->languageCode,
                    'value' => !is_array($value) ? $value : implode(' ', $value),
                ]
            );
        }

        return $fullTextValues;
    }
987752
def extract_directives(header)
        processed_header = String.new("")
        directives = []

        header.lines.each_with_index do |line, index|
          if directive = line[DIRECTIVE_PATTERN, 1]
            name, *args = Shellwords.shellwords(directive)
            if respond_to?("process_#{name}_directive", true)
              directives << [index + 1, name, *args]
              # Replace directive line with a clean break
              line = "\n"
            end
          end
          processed_header << line
        end

        processed_header.chomp!
        # Ensure header ends in a new line like before it was processed
        processed_header << "\n" if processed_header.length > 0 && header[-1] == "\n"

        return processed_header, directives
      end
232552
public function parse($str): array
    {
        $definition = [];

        if (empty($str)) {
            // Return empty definition
            return $definition;
        }

        // Directives are delimited with a pipe operator
        foreach (preg_split('/\s*\|\s*/', $str) as $directive) {
            // May consist of "directive:value" or it may just be "directive".
            $parts = explode(':', $directive, 2);
            $key = $parts[0];
            $value = $parts[1] ?? null;

            if (isset($this->shortKeys[$key])) {
                if ($value !== null) {
                    // If a value was also provided, we'll store that in a separate entry.
                    $definition[$this->normalizeKey($key)] = $value;
                }
                $value = $key;
                $key = $this->shortKeys[$key];
            }

            if (!$this->isAllowedKey($key)) {
                throw new ParseDefinitionException("Unsupported key '$key'");
            }

            // Normalise our directive (as snake_case) and store the value.
            $definition[$this->normalizeKey($key)] = $value;
        }

        return $definition;
    }
1326987
public function parse($content)
    {
        // Pattern used to extract single blocks
        $pattern = "/\/\*\*[\s\S]*?@[a-zA-Z_0-9\-]+:.[^;]+;/";
        $match = preg_match_all($pattern, $content, $matches);
        $globalScope = array();
        $scopes = array();

        $globalVariables = array();
        $scopeVariables = array();
        $originalNames = array();
        $scopeLabels = array();

        if ($match > 0 && count($matches) > 0) {
            $all = $matches[0];
            foreach ($all as $block) {
                // Extract the property
                $pattern = "/@([a-zA-Z_0-9\-]+): ?(.[^;]+);/";
                $match = preg_match($pattern, $block, $matches);

                // Pattern used to extract doc blocks into the original doc comment
                $pattern = "/\ ?@([a-zA-Z]+ *.+)/";
                $match = preg_match_all($pattern, $block, $matches2);

                // We found some doc comments so that the variable is supposed to be exposed
                if (count($matches2) == 2 && count($matches) == 3) {
                    $fieldData = $this->extractField($matches2[1]);
                    if (count($fieldData) == 0) {
                        continue;
                    }

                    $property = trim($matches[1]);
                    $propertyName = $this->postProcessText($property, '_');
                    $value = trim($matches[2]);

                    $originalNames[$propertyName] = $property;

                    if (isset($fieldData['scope'])) {
                        $scopeLabel = $fieldData['scope'];
                        $scope = $this->postProcessText($scopeLabel, '_');
                        unset($fieldData['scope']);

                        $type = 'text';

                        if (isset($fieldData['type'])) {
                            $type = $fieldData['type'];
                            unset($fieldData['type']);
                        }

                        $widget = array(
                            'type' => $type,
                            'options' => $fieldData,
                            'attr' => array('data-original-name' => $property)
                        );

                        if ($scope != 'global' && $scope != 'Global') {
                            if (!isset($scopes[$scope])) {
                                $scopes[$scope] = array();
                                $scopeVariables[$scope] = array();
                                $scopeLabels[$scope] = $scopeLabel;
                            }

                            $scopes[$scope][$propertyName] = array(
                                'value' => $value,
                                'widget' => $widget,
                                'original_name' => $property,
                            );

                            $scopeVariables[$scope][$propertyName] = $value;
                        } else {
                            $globalScope[$propertyName] = array(
                                'value' => $value,
                                'widget' => $widget,
                                'original_name' => $property,
                            );

                            $globalVariables[$propertyName] = $value;
                        }
                    } else {
                        $globalScope[$propertyName] = array(
                            'value' => $value,
                            'widget' => $widget,
                            'original_name' => $property,
                        );

                        $globalVariables[$propertyName] = $value;
                    }
                }
            }
        }

        // finalize
        if (count($scopes) > 0) {
            $data = array();
            $defaults = array();

            if (count($globalScope) > 0) {
                $data['global'] = array(
                    'type' => 'group',
                    'fields' => $globalScope,
                    'options' => array(
                        'label' => 'Global',
                    ),
                );

                $defaults['global'] = $globalVariables;
            }

            foreach ($scopes as $name => $scope) {
                $data[$name] = array(
                    'type' => 'group',
                    'fields' => $scope,
                    'options' => array(
                        'label' => $scopeLabels[$name],
                    ),
                );

                $defaults[$name] = $scopeVariables[$name];
            }

            return array('model' => $data, 'default_data' => $defaults, 'original_names' => $originalNames);
        } elseif (count($globalScope) > 0) {
            return array('model' => $globalScope, 'default_data' => $globalVariables, 'original_names' => $originalNames);
        }

        // Nothing parsed
        return array('model' => array(), 'default_data' => array(), 'original_names' => array());
    }
49710
public function parse($content) {
        $this->_content = $content;

        $this->_parseExtends();

        if ($this->_parent != null) {
            $this->_parseExtendsMain();
        }

        $this->_parseDebugStart();
        $this->_parseExtend();
        $this->_parseInclude();
        $this->_parsePath();
        $this->_parseGravatar();
        $this->_parseAsset();
        $this->_parseUrl();
        $this->_parsePhp();
        $this->_parseLang();
        $this->_parseForeach();
        $this->_parseFor();
        $this->_parseVar();
        $this->_parseVarFunc();
        $this->_parseCondition();
        $this->_parseFunction();
        $this->_parseException();
        $this->_parseBlock();
        $this->_parseTemplate();
        $this->_parseCall();
        $this->_parseMinify();
        $this->_parseDebugEnd();

        return $this->_content;
    }
67824
public function generateSearchText($content)
    {
        $content = @unserialize($content) ?: [];
        $searchText = $this->_generateSearchText(...$content);
        return parent::generateSearchText($searchText);
    }
111005
static function FindContentRights(Content $content)
    {
        $result = null;
        $currContent = $content;
        do
        {
            $result = $currContent->GetUserGroupRights();
            $currContent = ContentTreeUtil::ParentOf($currContent);
        } 
        while (!$result && $currContent);
        if ($result)
        {
            return $result;
        }
        return self::GetUpperContentRights($content);
    }