Parses the source of a wp-config.php file.

@param string $src Config file source.

@return array
482039
protected function parse_wp_config( $src ) {
		$configs             = array();
		$configs['constant'] = array();
		$configs['variable'] = array();

		// Strip comments.
		foreach ( token_get_all( $src ) as $token ) {
			if ( in_array( $token[0], array( T_COMMENT, T_DOC_COMMENT ), true ) ) {
				$src = str_replace( $token[1], '', $src );
			}
		}

		preg_match_all( '/(?<=^|;|<\?php\s|<\?\s)(\h*define\s*\(\s*[\'"](\w*?)[\'"]\s*)(,\s*(\'\'|""|\'.*?[^\\\\]\'|".*?[^\\\\]"|.*?)\s*)((?:,\s*(?:true|false)\s*)?\)\s*;)/ims', $src, $constants );
		preg_match_all( '/(?<=^|;|<\?php\s|<\?\s)(\h*\$(\w+)\s*=)(\s*(\'\'|""|\'.*?[^\\\\]\'|".*?[^\\\\]"|.*?)\s*;)/ims', $src, $variables );

		if ( ! empty( $constants[0] ) && ! empty( $constants[1] ) && ! empty( $constants[2] ) && ! empty( $constants[3] ) && ! empty( $constants[4] ) && ! empty( $constants[5] ) ) {
			foreach ( $constants[2] as $index => $name ) {
				$configs['constant'][ $name ] = array(
					'src'   => $constants[0][ $index ],
					'value' => $constants[4][ $index ],
					'parts' => array(
						$constants[1][ $index ],
						$constants[3][ $index ],
						$constants[5][ $index ],
					),
				);
			}
		}

		if ( ! empty( $variables[0] ) && ! empty( $variables[1] ) && ! empty( $variables[2] ) && ! empty( $variables[3] ) && ! empty( $variables[4] ) ) {
			// Remove duplicate(s), last definition wins.
			$variables[2] = array_reverse( array_unique( array_reverse( $variables[2], true ) ), true );
			foreach ( $variables[2] as $index => $name ) {
				$configs['variable'][ $name ] = array(
					'src'   => $variables[0][ $index ],
					'value' => $variables[4][ $index ],
					'parts' => array(
						$variables[1][ $index ],
						$variables[3][ $index ],
					),
				);
			}
		}

		return $configs;
	}
995173
private function prepareHeaderData(string $src): array
    {
        $header_sep_position = strpos($src, "\r\n");

        $tmp = explode('/', $this->parsed_url['path'] ?? '');
        $path_lst_fragment = end($tmp);

        $res = [
            'status_raw'   => substr($src, 0, $header_sep_position),
            'headers_raw'  => $src,
            'headers'      => [],
            'content-type' => '',
            'status_code'  => '',
        ];

        if (substr($path_lst_fragment, -1) !== '/' && strpos($path_lst_fragment, '.') !== false) {
            $ext_tmp = explode('.', $path_lst_fragment);
            $res['extension'] = strtolower(end($ext_tmp));
        } else {
            $res['extension'] = '';
        }

        foreach (explode("\r\n", $res['headers_raw']) as $v) {
            if (!$v) {
                continue;
            }

            $v = explode(':', $v);
            if (count($v) < 2) {
                continue;
            }

            $res['headers'][strtolower(array_shift($v))] = trim(implode(':', $v));
        }

        if (isset($res['headers']['content-type']) && $res['headers']['content-type']) {
            preg_match_all('/^[a-z\/\-]+/', $res['headers']['content-type'], $cont_type);

            if (isset($cont_type[0][0]) && $cont_type[0][0]) {
                $res['content-type'] = $cont_type[0][0];
            }
        }

        $status = explode(' ', $res['status_raw']);
        if (isset($status[1]) && strlen($status[1]) === 3 && ctype_digit($status[1])) {
            $res['status_code'] = (int)$status[1];
        }

        return $res;
    }
756946
public function logged($src, $value = '') {
        if (isset($this->_config->config['firewall']['' . $src . ''])) {
            if ($value == '') {
                $logged = explode('.', $this->_config->config['firewall']['' . $src . '']['logged']['name']);

                $data = $this->_getSession($logged);

                if ($data != '') {
                    return $data;
                }
                else {
                    return false;
                }
            }
            else {
                $logged = explode('.', $this->_config->config['firewall']['' . $src . '']['logged']['name']);
                $this->_setSession($logged, $value);
            }
        }
        else {
            throw new MissingConfigException('the module ' . $src . ' doesn\'t exist');
        }

        return false;
    }
374236
public function sourceParsedownElement(array $attributes, $reset = true)
    {
        empty($attributes['src']) && $attributes['src'] = $this->url(false);

        $srcset = $this->srcset($reset);
        if ($srcset) {
            empty($attributes['srcset']) && $attributes['srcset'] = $srcset;
            $attributes['sizes'] = $this->sizes();
        }

        return ['name' => 'img', 'attributes' => $attributes];
    }
490232
public function info(string $src)
    {
        $image=$this->image($src);
        $info['width']=$image->getWidth();
        $info['height']=$image->getHeight();
        $info['orientation']=$image->getOrientation();
        $info['mime']=$image->getMimeType();
        $info['exif']=$image->getExif();
        return $info;
    }
1156051
protected function parseLocalResources(?array $compiled): ?array
    {
        if ($compiled === null) {
            return null;
        }

        $scripts = [
            'head'  => [],
            'body'  => [],
        ];

        foreach ($compiled as $themeName => $attr) {
            $theme = $this->getTheme($themeName);

            foreach ($attr as $type => $script) {
                $compiledFilename = sprintf('compiled_%s.js', $this->crc($type . $script));
                $compiledFilePath = $this->getResourcePath($compiledFilename, $theme);

                if (!is_file($compiledFilePath)) {
                    $this->mergeResources(
                        sprintf('scripts.local.%s.%s', $theme->getKey(), $type),
                        $compiledFilePath
                    );
                }

                $location = $this->getLocation(strpos($type, 'head') !== false);

                $scripts[$location][] = $this->createLocalResourceFileSettings($theme, $type, $compiledFilename);
            }
        }

        return $scripts;
    }
26420
private function parseConfigFile()
    {
        $activeConfig = $this->getOriginalConfig();
        $activeConfig = $this->beforeExplode($activeConfig);

        //convert into an array
        $activeConfig = explode("\n", $activeConfig);

        $this->activeConfig = $this->afterExplode($activeConfig);

        return !empty($this->activeConfig);
    }
45598
public function parseHeaders($src)
    {
        $headers = array();

        foreach ($src as $i) {
            $row = explode(':', $i, 2);

            // header with no key/value - HTTP response, get code and status
            if(!isset($row[1])){

                $matches = array();
                if(preg_match('#HTTP/[1-2]\.[0-1] ([0-9]{3})(.*)#si', $row[0], $matches)){
                    $headers['Code'] = $matches[1];
                    $headers['Status'] = trim($matches[2]);
                }

                continue;
            }

            $key = trim($row[0]);
            $val = trim($row[1]);
            $headers[$key] = $val;
        }
        return $headers;
    }
170774
protected function attr($src = null, array $attr = array())
    {
        if (null !== $src) {
            $attr['src'] = $src;
        }
        $attr['type'] = 'text/javascript';
        return $this->escaper->attr($attr);
    }
825341
public function import($src) {
		if(!file_exists(realpath($src)))
			throw new \Exception('File '.$src.' does not exist.');
		$host = $this->config['host'];
		$user = $this->config['user'];
		$pwd = $this->config['password'];
		$db = $this->config['database'];
		$cmd = 'mysql -h '.$host.' -u '.$user.($pwd ? ' -p'.$pwd:'').' '.$db.' < "'.realpath($src).'"';
		$process = proc_open($cmd,
			[
				0 => ["pipe", "r"],
				1 => ["pipe", "w"],
				2 => ["pipe", "w"],
			],
			$pipes
		);
		return proc_close($process) === 0;
	}
129968
public static function parseSource($source, $namespace = '')
    {
        $matches = [];
        preg_match_all('#use[^;()]+?;#im', $source, $matches);
        $source = '<?php ' . implode('', $matches[0]);

        $builder = new AliasesBuilder;

        $states = [
            self::STATE_WAITING_FOR_USE => function ($token) use ($builder) {
                if (is_array($token) and $token[0] === T_USE) {
                    $builder->resetCurrent();
                    return AliasesParser::STATE_GATHERING;
                }
                return AliasesParser::STATE_WAITING_FOR_USE;
            },
            self::STATE_GATHERING => function ($token) use ($builder) {
                if (is_array($token)) {
                    if ($token[0] === T_STRING) {
                        $builder->appendToCurrent($token[1]);
                    } elseif ($token[0] === T_AS) {
                        return AliasesParser::STATE_IN_AS_PART;
                    }
                } else {
                    if ($token === ';') {
                        $builder->finishCurrent();
                        return AliasesParser::STATE_WAITING_FOR_USE;
                    } elseif ($token === ',') {
                        $builder->finishCurrent();
                    }
                }
                return AliasesParser::STATE_GATHERING;
            },
            self::STATE_IN_AS_PART => function ($token) use ($builder) {
                if (is_array($token)) {
                    if ($token[0] === T_STRING) {
                        $builder->setLast($token[1]);
                        $builder->finishCurrent();
                        return AliasesParser::STATE_JUST_FINISHED;
                    }
                }
                return AliasesParser::STATE_IN_AS_PART;
            },
            self::STATE_JUST_FINISHED => function ($token) use ($builder) {
                if ($token === ';') {
                    return AliasesParser::STATE_WAITING_FOR_USE;
                }
                return AliasesParser::STATE_GATHERING;
            },
        ];

        $state = $states[self::STATE_WAITING_FOR_USE];
        foreach (token_get_all($source) as $token) {
            $state = $states[$state($token)];
            if (is_array($token)) {
                $token[3] = token_name($token[0]);
            }
        }

        return $builder->getAliases($namespace);
    }
375612
public static function src($src) {
        static $static_url = false;
        if ($static_url === false) {
            $static_url = App::cfg('static_base');
            if ($static_url) {
                $static_url = trailingslashit($static_url . WWWROOT_DIR);
            } else {
                $static_url = WWWROOT_DIR;
            }
        }
        if (preg_match('#^(/|https?://).+$#', $src)) {
            return $src;
        }

        return $static_url . $src . '?_ver=' . BUILD_NUMBER;
    }
841735
private function open_php( &$src ){
		if( ! $this->inphp ){
			$this->inphp = true;
			
			// this may result in back to back tags, which we can avoid with a bit of string manipulation.
			$makenice = $this->opt(COMPILER_OPTION_NICE_TAGS);
			
			if( $makenice && substr( $src, -2 ) === '?>' ){
				// trim trailing close tag, so no need to open one
				$src = substr_replace( $src, '', -2 );
			}
			else {
				$ws = $this->opt(COMPILER_OPTION_WHITESPACE) ? "\n" : ' ';
				$src .= '<?php'.$ws;
			}
		}
		return $src;	
	}
803009
protected function parseSource(
        $source,
        DocumentFactoryInterface $documentFactory,
        ElementProcessorInterface $elementProcessor,
        ContextInterface $context
    ) {
        try {
            $parser = new Parser($documentFactory, $elementProcessor, $context);
            $things = $parser->parse($source);
            $gateway = new ThingGateway($this->iri);
            return (object)['items' => $gateway->export($things)];
        } catch (\OutOfBoundsException $e) {
            throw new OutOfBoundsException($e->getMessage(), $e->getCode());
        } catch (\RuntimeException $e) {
            throw new RuntimeException($e->getMessage(), $e->getCode());
        }
    }
1071915
static public function image($src, $settings=null)
    {
        $isBase64 = $src && strpos($src, 'data:image') !== false;
        if (!empty($src)) {
            if (!$isBase64 && strpos($src, ',') !== false) {
                $srcs = StringHelper::toArray($src, ',');
                $src = empty($srcs[0]) ? $srcs[1] : $srcs[0];
            }
        }
        if (!$src) {
            $src = Config::getRootUrl(). '/images/nopic.gif';
        } else {
            if (strpos($src, 'http:') === false && !$isBase64 ) {
                if (strpos($src, '/images') === 0) {
                    $src = Config::getRootUrl() . $src;
                } elseif (strpos($src, ':') === false) {
                    $src = Config::getUploadFileUrl($src);
                }
            }
        }
        
        $ext = pathinfo($src, PATHINFO_EXTENSION);
        if (!$isBase64 && !in_array($ext, ['gif', 'jpe', 'jpeg', 'jpg', 'png'])) {
            return '<a href="' . $src . '" target="_blank">查看</a>';
        }
        
        $settings = static::formatSettings($settings);
        $class = isset($settings['class']) ? $settings['class'] : ''; // img-responsive
        $class && $class = ' class="' . $class . '"';
        $style = isset($settings['style']) && $settings['style'] ? $settings['style'] : ($class ? '' : 'max-width:100%;max-height:100%');
        $style && $style = ' style="' . $style . '"';
        
        $idstr = isset($settings['id']) && $settings['id'] ? ' id="' . $settings['id'] . '"' : '';
        
        $str = '<img src="' . $src . '"' . $idstr . $class . $style . '>';
        if (isset($settings['url'])) {
            $str = '<a href="' . $settings['url'] . '">' . $str . '</a>';
        }
        
        return $str;
    }
971173
function parse_contents($contents)
	{
		if($this->fix_newlines) {
			// fix mac/dos formatted newlines
			$contents = preg_replace('!\r\n?!', "\n", $contents);
		}

		$config_data = array();
		$config_data['sections'] = array();
		$config_data['vars'] = array();

		/* reference to fill with data */
		$vars =& $config_data['vars'];

		/* parse file line by line */
		preg_match_all('!^.*\r?\n?!m', $contents, $match);
		$lines = $match[0];
		for ($i=0, $count=count($lines); $i<$count; $i++) {
			$line = $lines[$i];
			if (empty($line)) continue;

			if ( substr($line, 0, 1) == '[' && preg_match('!^\[(.*?)\]!', $line, $match) ) {
				/* section found */
				if (substr($match[1], 0, 1) == '.') {
					/* hidden section */
					if ($this->read_hidden) {
						$section_name = substr($match[1], 1);
					} else {
						/* break reference to $vars to ignore hidden section */
						unset($vars);
						$vars = array();
						continue;
					}
				} else {
					$section_name = $match[1];
				}
				if (!isset($config_data['sections'][$section_name]))
				$config_data['sections'][$section_name] = array('vars' => array());
				$vars =& $config_data['sections'][$section_name]['vars'];
				continue;
			}

			if (preg_match('/^\s*(\.?\w+)\s*=\s*(.*)/s', $line, $match)) {
				/* variable found */
				$var_name = rtrim($match[1]);
				if (strpos($match[2], '"""') === 0) {
					/* handle multiline-value */
					$lines[$i] = substr($match[2], 3);
					$var_value = '';
					while ($i<$count) {
						if (($pos = strpos($lines[$i], '"""')) === false) {
							$var_value .= $lines[$i++];
						} else {
							/* end of multiline-value */
							$var_value .= substr($lines[$i], 0, $pos);
							break;
						}
					}
					$booleanize = false;

				} else {
					/* handle simple value */
					$var_value = preg_replace('/^([\'"])(.*)\1$/', '\2', rtrim($match[2]));
					$booleanize = $this->booleanize;

				}
				$this->_set_config_var($vars, $var_name, $var_value, $booleanize);
			}
			/* else unparsable line / means it is a comment / means ignore it */
		}
		return $config_data;
	}
737296
protected function &getSource($src)
	{
		if (!isset($this->sources[$src]))
		{
			if (is_readable($src))
			{
				$this->sources[$src] = self::splitLines(file_get_contents($src));
			}
			else
			{
				$this->sources[$src] = null;
			}
		}

		return $this->sources[$src];
	}